Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/gui/gui/orxonox_gui_gtk.cc @ 4034

Last change on this file since 4034 was 4034, checked in by bensch, 19 years ago

orxonox/trunk: no more iostrem

File size: 40.1 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software Foundation,
18   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
19
20
21   ### File Specific:
22   main-programmer: Benjamin Grauer
23
24*/
25
26
27#include "orxonox_gui_gtk.h"
28
29#include <stdarg.h>
30#include <string.h>
31
32using namespace std;
33
34// temporarily.
35#include "orxonox_gui_flags.h"
36extern Window* orxonoxGUI;
37extern OrxonoxGuiFlags* flags;
38
39/**
40   \brief Initializes the Guis GTK-stuff.
41   \param argc the argument count.
42   \param argv The Argument strings.
43*/
44bool initGUI(int argc, char *argv[])
45{
46#ifdef HAVE_GTK2
47#ifdef HAVE_GTHREAD
48  PRINTF(4)("Initializing the ThreadSystem of the GUI\n");
49  g_thread_init(NULL);
50  gdk_threads_init();
51#endif /* HAVE_GTHREAD */
52  gtk_init(&argc, &argv);
53#include "rc"
54  gtk_rc_parse_string( rc_string );
55#endif /* HAVE_GTK2 */
56}
57
58
59/**
60   \brief enters the GUI's main-loop
61*/
62bool mainloopGUI(void)
63{
64#ifdef HAVE_GTK2
65  gdk_threads_enter();
66  gtk_main();
67  gdk_threads_leave();
68  delete Window::mainWindow;
69#else /* HAVE_GTK2 */
70  char boolAns = 'y';
71  char ans[10];
72  PRINT(0)("================================\n");
73  PRINT(0)("= ORXONOX CONFIGURATION WIZARD =\n");
74  PRINT(0)("================================    - version:" PACKAGE_VERSION "\n");
75
76  while(true)
77    {
78      PRINT(0)("\n Listing all the Orxonox Options: \n");
79      PRINT(0)("  #############################\n");
80      Window::mainWindow->walkThrough(Widget::listOptionsAndGroups, 1);
81     
82      PRINT(0)("\nDo you want change any of the above values now? [Yn] ");
83      cin >> boolAns ;
84      if (boolAns =='n' || boolAns=='N')
85        break;
86     
87      PRINT(0)("\n Listing all groups\n");
88      PRINT(0)("  #################\n");
89      int groupCount = 0;
90      Window::mainWindow->walkThrough(Widget::listGroups, &groupCount, 1);
91     
92      PRINT(0)("\nIn which Group? [1-%d] ", groupCount);
93      Packer* group;
94      while(true)
95        {
96          cin >> ans;
97          int ansIp = atoi(ans);
98          if (ansIp <= groupCount)
99            {
100              group = static_cast<Packer*>(Window::mainWindow->findGroupByNumber(&ansIp, 1));
101              break;
102            }
103          else
104            PRINT(0)("\nChoose a smaller Number please: [1-%d] ", groupCount);
105        }
106      PRINT(0)("\n\nGroup: [%s]\n\n", group->groupName);
107      int optionCount = 0;
108      group->walkThrough(Widget::listOptions, &optionCount, 0);
109      PRINT(0)("\nWhich Option? [1-%d] ", optionCount);
110      Option* option;
111      while(true)
112        {
113          cin >> ans;
114          int ansIp = atoi(ans);
115          if (ansIp <= groupCount)
116            {
117              option = static_cast<Option*>(group->findOptionByNumber(&ansIp, 0));
118              break;
119            }
120          else
121            PRINT(0)("\nChoose a smaler Number please: [1-%d] ", optionCount);
122        }
123      PRINT(0)("\n\n:: %s ::\n", option->title);
124      option->changeOption();
125     
126      // here follows the rest.... this will be nasty.
127      //! \todo move this into the gui-gtk-file
128      //! \todo finish it.
129      //! \todo memory leek at save(); and save is a BAD word, use saveString instead, or something like it.
130    }
131#endif /* HAVE_GTK2 */
132 
133}
134
135
136//////////////////////////////
137/// DEFINING WIDGET-CLASES ///
138//////////////////////////////
139
140/* WIDGET */
141/**
142   \brief constructs a Widget
143*/
144Widget::Widget(void)
145{
146  next = NULL;
147  this->title = NULL;
148  return;
149}
150
151/**
152   \brief deletes any given Widget
153   This is still pretty crappy.
154*/
155Widget::~Widget(void)
156{
157    if (this->title)
158    {
159      delete []this->title;
160    }
161   
162    PRINTF(5)("deleting the Widget part.\n");
163   
164  PRINTF(5)("deleting recursively\n");
165
166  // deleting next item if existent
167  if (this->next)
168    delete this->next;
169  this->next = NULL;
170
171  //!  \todo not hiding widget, deleting.
172  //  this->hide();
173  //  delete this->widget;
174}
175
176/**
177   \brief sets a new Title to a Widget
178   \param title The new Title to set to the Widget
179*/
180void Widget::setTitle(const char* title)
181{
182  if (this->title)
183    delete []this->title;
184  this->title = new char[strlen(title)+1];
185  strcpy(this->title, title);
186}
187
188/**
189   \brief makes the widget visible.
190*/
191void Widget::show(void)
192{
193#ifdef HAVE_GTK2
194  gtk_widget_show(this->widget);
195#endif /* HAVE_GTK2 */
196}
197
198/**
199   \brief hides the widget.
200*/
201void Widget::hide(void)
202{
203#ifdef HAVE_GTK2
204  gtk_widget_hide(this->widget);
205#endif /* HAVE_GTK2 */
206}
207
208/**
209   \brief Sets the resolution of a specific widget to the given size.
210   \param width the width of the widget to set.
211   \param height the height of the widget to set.
212*/
213void Widget::setSize(int width, int height)
214{
215#ifdef HAVE_GTK2
216  gtk_widget_set_usize(this->widget, width, height);
217#endif /* HAVE_GTK2 */
218}
219
220/**
221   \brief searches through widgets for a Name.
222*/
223Widget* Widget::findWidgetByName(char* name, unsigned int depth)
224{
225
226  if (this->title && !strcmp(this->title, name))
227    return this;
228
229  if (this->isOption < 0 && static_cast<Packer*>(this)->down)
230    {
231      Widget* tmp = static_cast<Packer*>(this)->down->findWidgetByName(name, depth+1);
232      if (tmp)
233        return tmp;
234    }
235 
236  if (depth>0 && this->next)
237    return this->next->findWidgetByName(name, depth);
238
239  return NULL;
240}
241
242/**
243   \brief Moves through all the Widgets downwards from this and executes the function on them.
244   \param function must be of type void and takes a Widget* as an Input.
245   \param depth the current depth. if > 0 then the next Widget will also be walked through.
246*/
247void Widget::walkThrough(void(*function)(Widget*), unsigned int depth)
248{
249  function(this);
250  if (this->isOption < 0)
251    {
252      static_cast<Packer*>(this)->down->walkThrough(function, depth+1);
253    } 
254
255  if (this->next && depth != 0)
256    this->next->walkThrough(function, depth);
257}
258
259/**
260   \brief Moves through all the Widgets downwards from this and executes the function on them.
261   \param function must be of type void and takes a Widget* as an Input.
262   \param data Additional Data you want to pass to the function.
263   \param depth the current depth. if > 0 then the next Widget will also be walked through.
264*/
265void Widget::walkThrough(void(*function)(Widget*, void*), void* data, unsigned int depth)
266{
267  function(this, data);
268  if (this->isOption < 0)
269    {
270      static_cast<Packer*>(this)->down->walkThrough(function, data, depth+1);
271    }
272  if (this->next && depth != 0)
273    this->next->walkThrough(function, data, depth);
274}
275
276/**
277    \brief This is for listing the options of "widget"
278    \param widget specifies the widget that should be listed
279*/
280void Widget::listOptionsAndGroups(Widget* widget)
281{
282  if (widget->isOption < 0 && static_cast<Packer*>(widget)->groupName)
283    PRINT(0)("[%s]\n", static_cast<Packer*>(widget)->groupName);
284  if (widget->isOption >= 1)
285    {
286      Widget::listOptions(widget);
287    }
288}
289
290/**
291    \brief This is for listing the options of "widget"
292    \param widget specifies the widget that should be listed
293*/
294void Widget::listOptions(Widget* widget)
295{
296  if(widget->isOption >= 1)
297    PRINT(0)("  %s is %s\n", static_cast<Option*>(widget)->title, static_cast<Option*>(widget)->save());
298}
299
300/**
301    \brief This is for listing the options of "widget"
302    \param widget specifies the widget that should be listed
303    \param data A Counter, that always knows how many Options have been found yet.
304*/
305void Widget::listOptions(Widget* widget, void* data)
306{
307 
308  if (widget->isOption >= 1)
309    {
310      int* count =(int*)data;
311      *count = *count +1;
312      PRINT(0)(" %d:%s is %s\n", *count, static_cast<Option*>(widget)->title, static_cast<Option*>(widget)->save());
313    }
314}
315
316/**
317    \brief Finds an Option by a given number(the n'th option found away from this Widget)
318    \param number The Count of options to wait(by reference)
319    \param depth The depth of the sarch. if 0 it will not search next pointer
320   
321    \todo should return Option* would be much sexier.
322*/
323Widget* Widget::findOptionByNumber(int* number, unsigned int depth)
324{
325  if (isOption > 0)
326    {
327      --*number;
328      if (*number <= 0)
329        {
330          return this;
331        }
332    }
333  if (this->isOption < 0 && static_cast<Packer*>(this)->down)
334    {
335      Widget* tmp = static_cast<Packer*>(this)->down->findOptionByNumber(number, depth+1);
336      if (tmp)
337        return tmp;
338    }
339  if (depth>0 && this->next)
340    return this->next->findOptionByNumber(number, depth);
341
342  return NULL;
343}
344
345/**
346    \brief This is for listing the groups of "widget"
347    \param widget specifies the widget that should be listed
348*/
349void Widget::listGroups(Widget* widget)
350{
351  if (widget->isOption < 0 && static_cast<Packer*>(widget)->groupName)
352    PRINT(0)("[%s]\n", static_cast<Packer*>(widget)->groupName);
353}
354
355/**
356    \brief This is for listing the Groups of "widget". It also displays the n'th number found.
357    \param widget specifies the widget that should be listed
358    \param data the Counter, that will show the number(this function will raise it by one if a Group is fount.
359*/
360void Widget::listGroups(Widget* widget, void* data)
361{
362  int* count = (int*)data;
363  if (widget->isOption < 0 && static_cast<Packer*>(widget)->groupName)
364    PRINT(0)("%d: [%s]\n", ++*count, static_cast<Packer*>(widget)->groupName);
365}
366
367/**
368    \brief Finds a Group by a given number(the n'th Group found away from this Widget)
369    \param number The Count of options to wait(by reference)
370    \param depth The depth of the sarch. if 0 it will not search next pointer
371*/
372Widget* Widget::findGroupByNumber(int* number, unsigned int depth)
373{
374  if (isOption < 0 && static_cast<Packer*>(this)->groupName)
375    {
376      --*number;
377      if (*number <= 0)
378        {
379          return this;
380        }
381    }
382  if (this->isOption < 0 && static_cast<Packer*>(this)->down)
383    {
384      Widget* tmp = static_cast<Packer*>(this)->down->findGroupByNumber(number, depth+1);
385      if (tmp)
386        return tmp;
387    }
388  if (depth>0 && this->next)
389    return this->next->findGroupByNumber(number, depth);
390
391  return NULL;
392}
393 
394/**
395    \brief This is for setting the option of "widget"
396    \param widget specifies the widget that should be set.
397*/
398void Widget::setOptions(Widget* widget)
399{
400  if (widget->isOption >= 1)
401    static_cast<Option*>(widget)->redraw();
402}
403
404/**
405   \brief Walks through all the Flags given at startuptime.
406*/
407void Widget::flagCheck(Widget* widget, void* flagName)
408{
409  if (widget->isOption>=1)
410    {     
411      Option* option =(Option*)widget;
412      char* name =(char*)flagName;
413      char* value = NULL;
414      bool found = false;
415      // check if long flag matches
416      if ((option->flagName && strlen(name)>2 &&
417           !strncmp(name+2, option->flagName, strlen(option->flagName)) &&
418           (name[strlen(option->flagName)+2] == '\0' || name[strlen(option->flagName)+2] == '=') ))
419        {
420          found = true;
421          if (name[strlen(option->flagName)+2] == '=')
422            {
423              value = name+strlen(option->flagName)+3;
424            }
425        }
426      // check if short flag matches
427      else if (option->flagNameShort && strlen(name)>1 &&
428               !strncmp(name+1, option->flagNameShort, strlen(option->flagNameShort)) &&
429               (name[strlen(option->flagNameShort)+1] == '\0' || name[strlen(option->flagNameShort)+1] == '='))
430        {
431          found = true;
432          if (name[strlen(option->flagNameShort)+1] == '=')
433            {
434              value = name+strlen(option->flagNameShort)+2;
435            }     
436        }
437
438      if (found)
439        {
440          PRINT(4)("found matching Flag %s\n", name);
441          if (value)
442            {
443              PRINT(4)("with Value %s\n", value);
444              option->value = atoi(value);
445            }
446          else
447            {
448              option->value = !option->defaultValue;
449            }
450          option->redraw();
451        }
452
453    }
454}
455
456#ifdef HAVE_GTK2
457/**
458    \brief Connect any signal to any given Sub-widget
459*/
460gulong Widget::connectSignal(char* event, gint(*signal)(GtkWidget*, GdkEvent*, void *))
461{
462  return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), NULL);
463}
464
465/**
466   \brief Connect a signal with additionally passing the whole Object
467*/
468gulong Widget::connectSignal(char* event, gint(*signal)( GtkWidget*, Widget *))
469{
470  return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), this);
471}
472
473/**
474   \brief Connect a signal with additionally passing a whole external Object
475*/
476gulong Widget::connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, GdkEvent*, void *))
477{
478  return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), extObj);
479}
480
481/**
482   \brief Connect a signal with additionally passing a whole external Object
483*/
484gulong Widget::connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, void *))
485{
486  return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), extObj);
487}
488
489/**
490   \brief Connect a signal with additionally passing a whole external Object
491*/
492gulong Widget::connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, GdkEventKey*, void *))
493{
494  return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), extObj);
495}
496
497void Widget::disconnectSignal(gulong signalID)
498{
499  g_signal_handler_disconnect(G_OBJECT(this->widget), signalID);
500}
501
502/**
503   \brief Signal that does absolutely nothing
504   \param widget The widget that initiated the Signal
505   \param event The event-type.
506   \param nothing nothin.
507*/
508gint Widget::doNothingSignal(GtkWidget *widget, GdkEvent* event, void* nothing)
509{
510}
511#endif /* HAVE_GTK2 */
512
513//void deleteWidget(Widget* lastWidget)
514
515
516/* PACKERS */
517/**
518   \brief Constructs a Packer
519*/
520Packer::Packer(void)
521{
522  this->down = NULL;
523  this->groupName = NULL;
524}
525
526/**
527   \brief Destroys a Packer.
528*/
529Packer::~Packer(void)
530{ 
531  PRINTF(5)("deleting the Packer part.\n");
532 
533  if (this->groupName)
534    delete []this->groupName;
535
536  //deleting recursively.
537  if (this->down)
538    delete this->down;
539  this->down = NULL;
540}
541
542/**
543   \brief Sets the group name under which all the lower widgets of this will be saved.
544   \param name The name of the group.
545*/
546void Packer::setGroupName(char* name)
547{
548  if (this->groupName)
549    delete []this->groupName;
550  this->groupName = new char[strlen(name)+1];
551  strcpy(this->groupName, name);
552}
553
554/**
555   \brief Retrieves the group name under which all the lower widgets of this will be saved.
556   \returns name The name of the group.
557*/
558char* Packer::getGroupName(void)
559{
560  return this->groupName;
561}
562
563/* CONTAINERS */
564
565/**
566   \brief Initializes a Container.
567
568   sets the Container-Specific defaults.
569*/
570Container::Container(void)
571{
572  this->isOption = -1;
573}
574
575/**
576   \brief Destroys a Container.
577*/
578Container::~Container(void)
579{ 
580  PRINTF(5)("deleting the Container part.\n");
581}
582
583/**
584   \briefFills a Container with lowerWidget.
585   \param lowerWidget the Widget that should be filled into the Container.
586
587   It does this by filling up the down pointer only if down points to NULL.
588*/
589void Container::fill(Widget *lowerWidget)
590{
591  if (this->down == NULL)
592    {
593#ifdef HAVE_GTK2
594      gtk_container_add(GTK_CONTAINER(this->widget), lowerWidget->widget);
595#endif /* HAVE_GTK2 */
596      this->down = lowerWidget;
597    }
598  else
599    PRINTF(1)("!!error!! You try to put more than one Widget into a Container. \nNot including this item.\nThis is only possible with Boxes.\n");
600}
601
602// gtk_container_set_border_width(GTK_CONTAINER(widget), 5);
603
604/* WINDOW */
605
606Window* Window::mainWindow = NULL;
607
608/**
609   \brief Adds a new Window Windows to the List of Windows.
610   \param windowToAdd The Windows that should be added to the List
611   \todo this instead of windowToAdd(possibly)
612*/
613void Window::addWindow(Window* windowToAdd)
614{
615  if (!mainWindow)
616    {
617      mainWindow = windowToAdd;
618      return;
619    }
620
621  Widget* tmpWindow = mainWindow;
622  while(tmpWindow->next)
623    tmpWindow = tmpWindow->next;
624  tmpWindow->next = windowToAdd;
625 
626  return;
627}
628     
629
630/**
631   \brief Creating a new Window without a Name
632*/
633Window::Window(void)
634{
635  this->init();
636}
637
638/**
639   \brief Creating a Window with a name
640   \param windowName the name the window should get.
641*/
642
643Window::Window(char* windowName)
644{
645  this->init();
646  this->setTitle(windowName);
647}
648
649/**
650   \brief Destructs a Window.
651*/
652Window::~Window(void)
653{
654  if (this->title)
655    PRINTF(5)("deleting the Window: %s\n", this->title);
656  else 
657    PRINTF(5)("deleting the Window.\n");
658  //  this->hide();
659}
660
661/**
662   \brief initializes a new Window
663*/
664void Window::init(void)
665{
666  if (!mainWindow)
667    mainWindow = this;
668 
669  isOpen = false;
670
671#ifdef HAVE_GTK2
672  widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
673  gtk_window_set_policy(GTK_WINDOW(widget), TRUE, TRUE, TRUE);
674#if !defined(__WIN32__)
675  //  gtk_window_set_decorated(GTK_WINDOW(widget), FALSE);
676#endif
677  gtk_container_set_border_width(GTK_CONTAINER(widget), 3);
678#endif /* HAVE_GTK2 */
679}
680
681/**
682   \brief Shows all Widgets that are included within this->widget.
683*/
684void Window::showall(void)
685{
686  if (!this->isOpen)
687    {
688      //      printf("showall\n");
689#ifdef HAVE_GTK2
690      gtk_widget_show_all(this->widget);
691#endif /* HAVE_GTK2 */ 
692     this->isOpen = true;
693    }
694  else
695    {
696      //      printf("showone\n");
697#ifdef HAVE_GTK2
698      gtk_widget_show(this->widget);
699#endif /* HAVE_GTK2 */
700    }
701}
702
703/**
704   \brief Set The Window-title to title
705   \param title title the Window should get.
706*/
707void Window::setTitle(const char* title)
708{
709  if (this->title)
710    delete []this->title;
711  this->title = new char[strlen(title)+1];
712  strcpy(this->title, title);
713#ifdef HAVE_GTK2
714  gtk_window_set_title(GTK_WINDOW(widget), title);
715#endif /* HAVE_GTK2 */
716}
717
718/**
719   \brief opens up a Window and fixes the Focus to it
720*/
721void Window::open(void)
722{
723  if (this != mainWindow)
724    {
725      isOpen = true;
726#ifdef HAVE_GTK2
727      gtk_widget_show_all(this->widget);
728      gtk_grab_add(this->widget);
729#endif /* HAVE_GTK2 */
730    }
731}
732
733/**
734   \brief closes up a Window and removes the Focus from it
735*/
736void Window::close(void)
737{
738  if (this != mainWindow)
739    {
740      this->isOpen = false;
741#ifdef HAVE_GTK2
742      gtk_grab_remove(this->widget);
743      gtk_widget_hide(this->widget);
744#endif /* HAVE_GTK2 */
745    }
746}
747
748#ifdef HAVE_GTK2
749/**
750   \brief opens up a window(not topmost Window).
751   this is the Signal that does it. !!SIGNALS ARE STATIC!!
752   \param widget the widget that did it.
753   \param event the event that did it.
754   \param window the Window that should be opened
755*/
756gint Window::windowOpen(GtkWidget *widget, GdkEvent* event, void* window)
757{
758  static_cast<Window*>(window)->open();
759}
760
761/**
762   \brief closes a window(not topmost Window).
763   this is the Signal that does it. !!SIGNALS ARE STATIC!!
764   \param widget the widget that did it!
765   \param event the event that did it!
766   \param window the Window that should be closed
767*/
768gint Window::windowClose(GtkWidget *widget, GdkEvent* event, void* window)
769{
770  static_cast<Window*>(window)->close();
771}
772
773#endif /* HAVE_GTK2 */
774
775
776/* FRAME */
777
778/**
779    \brief Creates a new Frame without a name
780*/
781Frame::Frame(void)
782{
783  this->init();
784}
785
786/**
787   \brief Creates a new Frame with name title
788*/
789Frame::Frame(char* title)
790{
791  this->init();
792  this->setTitle(title);
793}
794
795/**
796   \brief destrcucts a Frame
797*/
798Frame::~Frame(void)
799{
800  PRINTF(5)("deleting the Frame: %s\n", this->title);
801}
802
803/**
804    \brief Initializes a new Frame with default settings
805*/
806void Frame::init(void)
807{
808#ifdef HAVE_GTK2
809  this->widget = gtk_frame_new("");
810  gtk_container_set_border_width(GTK_CONTAINER(this->widget), 3);
811#endif /* HAVE_GTK2 */
812}
813
814/**
815   \brief Sets the Frames name to title
816   \param title The title the Frame should get.
817*/
818void Frame::setTitle(const char* title)
819{
820  if (this->title)
821    delete []this->title;
822  this->title = new char[strlen(title)+1];
823  strcpy(this->title, title);
824#ifdef HAVE_GTK2
825  gtk_frame_set_label(GTK_FRAME(widget), title);
826#endif /* HAVE_GTK2 */
827}
828
829// EVENTBOX //
830
831/**
832   \brief Creates a new EventBox with default settings.
833*/
834EventBox::EventBox(void)
835{
836  this->init();
837}
838
839/**
840   \brief Creates a new EventBox with name title
841   \param title title the Eventbox should get(only data-structure-internal)
842*/
843EventBox::EventBox(char* title)
844{
845  this->init();
846  this->setTitle(title);
847}
848
849/**
850   \brief destructs an EventBox.
851*/
852EventBox::~EventBox(void)
853{
854  PRINTF(5)("deleting the EventBox: %s\n", this->title);
855}
856
857/**
858   \brief Initializes a new EventBox
859*/
860void EventBox::init(void)
861{
862  this->isOption = -1;
863
864#ifdef HAVE_GTK2
865  this->widget = gtk_event_box_new();
866  gtk_container_set_border_width(GTK_CONTAINER(this->widget), 3);
867#endif /* HAVE_GTK2 */
868}
869
870/* BOX */
871
872/**
873   \brief Creates a new horizontal Box
874*/
875Box::Box(void)
876{
877  this->init('h');
878}
879
880/**
881   \brief Creates a new Box of type boxtype
882   \param boxtype if 'v' the Box will be vertically, if 'h' the Box will be horizontally
883*/
884Box::Box(char boxtype)
885{
886  this->init(boxtype);
887}
888
889/**
890   \brief destructs a Box.
891*/
892Box::~Box(void)
893{
894  PRINTF(5)("deleting the Box: %s\n", this->title);
895}
896
897/**
898   \brief Initializes a new Box with type boxtype
899   \param boxtype see Box(char boxtype)
900*/
901void Box::init(char boxtype)
902{
903  this->isOption = -2;
904
905#ifdef HAVE_GTK2
906  if (boxtype == 'v')
907    this->widget = gtk_vbox_new(FALSE, 0);
908  else
909    this->widget = gtk_hbox_new(FALSE, 0);
910#endif /* HAVE_GTK2 */
911}
912
913/**
914    \brief Fills a box with a given Widget.
915    \param lowerWidget the next Widget that should be appendet to this Box
916
917    It does this by apending the first one to its down-pointer and all its following ones to the preceding next-pointer. The last one will receive a NULL pointer as Next
918*/
919void Box::fill(Widget* lowerWidget)
920{
921#ifdef HAVE_GTK2
922  gtk_box_pack_start(GTK_BOX(this->widget), lowerWidget->widget, TRUE, TRUE, 0);
923#endif /* HAVE_GTK2 */
924  if (this->down == NULL)
925    this->down = lowerWidget;
926  else
927    {
928      Widget* tmp;
929      tmp = this->down;
930      while(tmp->next != NULL)
931        {
932          tmp = tmp->next;
933        }
934      tmp->next = lowerWidget;
935    }
936}
937
938/* OPTION */
939
940/**
941   \brief Initializes a new Option.
942   sets all Option-Specific-Values to their defaults.
943*/
944Option::Option(void)
945{
946  this->value = 0;
947  this->flagName = NULL;
948  this->flagNameShort = NULL;
949  this->saveable = false;
950  this->defaultValue = 0;
951}
952
953/**
954   \brief Destroys an Option.
955*/
956Option::~Option(void)
957{ 
958  PRINTF(5)("deleting the Option Part.\n");
959  if (this->flagName)
960    delete []this->flagName;
961  if (this->flagNameShort)
962    delete []this->flagNameShort;
963}
964
965/**
966   \brief This sets The FlagName of an Option and defines its default Values
967   !! Options will be saved if flagname is different from NULL !!
968   \param flagname the Name that will be displayed in the output
969   \param defaultvalue the default Value for this Option(see definition of defaultvalue
970*/
971void Option::setFlagName(char* flagname, int defaultvalue)
972{
973  if (this->flagName)
974    delete this->flagName;
975  this->flagName = new char [strlen(flagname)+1];
976  strcpy(this->flagName, flagname);
977  this->defaultValue = defaultvalue;
978
979  //  cout << "Set Flagname of " << this->title << " to " << flagname << endl;
980}
981
982/**
983    \brief see Option::setFlagName(char* flagname, int defaultvalue)
984    \param flagname the Name that will be displayed in the output
985    \param defaultvalue the default Value for this Option(see definition of defaultvalue
986    \param flagnameshort a short flagname to be displayed in the output
987*/
988void Option::setFlagName(char* flagname, char* flagnameshort,  int defaultvalue)
989{
990  if (this->flagName)
991    delete []this->flagName;
992  this->flagName = new char [strlen(flagname)+1];
993  strcpy(this->flagName, flagname);
994
995  if (this->flagNameShort)
996    delete []this->flagNameShort;
997  this->flagNameShort = new char [strlen(flagnameshort)+1];
998  strcpy(this->flagNameShort, flagnameshort);
999  this->defaultValue = defaultvalue;
1000  //  cout << "Set Flagname of " << this->title << " to " << flagname << endl;
1001}
1002
1003/**
1004   \brief Sets the saveable-state of the option to true.
1005*/
1006void Option::saveability(void)
1007{
1008  this->saveable = true;
1009}
1010
1011/**
1012   \brief Sets the saveable-state of the option.
1013   \param isSaveable the saveable-state to set.
1014*/
1015void Option::saveability(bool isSaveable)
1016{
1017  this->saveable = isSaveable;
1018}
1019
1020/**
1021   \brief saves an Option
1022   \returns the String that should be saved.
1023
1024   this is a default Option save
1025*/
1026char* Option::save(void)
1027{
1028  char* value = new char [10];
1029  sprintf (value, "%d", this->value);
1030  return value;
1031}
1032
1033/**
1034   \brief loads an Option from of its loadString
1035   \param loadString the string from which to load the data from
1036*/
1037void Option::load(char* loadString)
1038{
1039  this->value = atoi(loadString);
1040  PRINT(5)("Loading %s: %s %d\n", this->title, loadString, value); 
1041  this->redraw();
1042}
1043
1044/**
1045   \returns The saveable-state.
1046*/
1047bool Option::isSaveable(void)
1048{
1049  return this->saveable;
1050}
1051
1052#ifdef HAVE_GTK2
1053/**
1054    \brief Signal OptionChange writes the Value from the Slider to its Object-Database.
1055    \param widget The widget(Slider) that has a changed Value
1056    \param slider the Slider-Object that should receive the change.
1057*/
1058gint Option::OptionChange(GtkWidget *widget, Widget* option)
1059{
1060  static_cast<Option*>(option)->changeOption();
1061  flags->setTextFromFlags(Window::mainWindow);  //// must be different !!!
1062}
1063#endif /* HAVE_GTK2 */
1064
1065
1066/* BUTTON */
1067
1068/**
1069   \brief Creates a new Button with a buttonname
1070   \param buttonname sets the Name of the Button
1071*/
1072Button::Button(char* buttonname)
1073{
1074  this->init();
1075  this->setTitle(buttonname);
1076}
1077
1078/**
1079   \brief destructs a Button.
1080*/
1081Button::~Button(void)
1082{
1083  PRINTF(5)("deleting the Label: %s\n", this->title);
1084}
1085
1086/**
1087   \brief Initializes a new Button
1088*/
1089void Button::init(void)
1090{
1091  isOption = 0;
1092
1093#ifdef HAVE_GTK2
1094  widget = gtk_button_new_with_label("");
1095#endif /* HAVE_GTK2 */
1096}
1097
1098/**
1099   \brief Sets a new name to the Button
1100   \param title The name the Button should get
1101*/
1102void Button::setTitle(const char *title)
1103{
1104  if (this->title)
1105    delete []this->title;
1106  this->title = new char[strlen(title)+1];
1107  strcpy(this->title, title);
1108#ifdef HAVE_GTK2
1109  gtk_button_set_label(GTK_BUTTON(widget), title);
1110#endif /* HAVE_GTK2 */
1111}
1112
1113/**
1114   \brief redraws the Button
1115   not implemented yet
1116*/
1117void Button::redraw(void)
1118{
1119}
1120
1121/**
1122   \brief Button can not be changed, optionChange is empty)
1123
1124   \todo Actions for non-GTK-mode
1125*/
1126void Button::changeOption(void)
1127{
1128  // This will possibly be used for ACTIONS !
1129}
1130
1131/* CHECKBUTTON */
1132
1133/**
1134   \brief Creates a new CheckButton with an ame
1135   \param buttonname The name the CheckButton should display.
1136*/
1137CheckButton::CheckButton(char* buttonname)
1138{
1139  this->init();
1140  this->setTitle(buttonname);
1141
1142#ifdef HAVE_GTK2
1143  this->connectSignal("clicked", this->OptionChange);
1144#endif /* HAVE_GTK2 */
1145}
1146
1147/**
1148   \brief destructs a CheckButton.
1149*/
1150CheckButton::~CheckButton(void)
1151{
1152  if (this->title)
1153    PRINTF(5)("deleting the CheckButton: %s\n", this->title);
1154  else 
1155    PRINTF(5)("deleting the CheckButton.\n");
1156}
1157
1158/**
1159   \brief Initialize a new CheckButton with default settings
1160*/
1161void CheckButton::init(void)
1162{
1163  this->isOption = 1;
1164
1165#ifdef HAVE_GTK2
1166  this->widget = gtk_check_button_new_with_label("");
1167#endif /* HAVE_GTK2 */
1168}
1169
1170/**
1171   \brief Sets a new Title to a CheckButton
1172   \param title The new Name the CheckButton should display.
1173*/
1174void CheckButton::setTitle(const char* title)
1175{
1176  if (this->title)
1177    delete []this->title;
1178  this->title = new char[strlen(title)+1];
1179  strcpy(this->title, title);
1180#ifdef HAVE_GTK2
1181  gtk_button_set_label(GTK_BUTTON(widget), title);
1182#endif /* HAVE_GTK2 */
1183}
1184
1185bool CheckButton::isActive(void)
1186{
1187#ifdef HAVE_GTK2
1188  return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1189#endif /* HAVE_GTK2 */
1190}
1191
1192/**
1193   \brief Changed the Option, call this Function
1194*/
1195void CheckButton::changeOption(void)
1196{
1197#ifdef HAVE_GTK2
1198  this->value =(int)gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(this->widget));
1199#else /* HAVE_GTK2 */
1200  char tmpChar[20];
1201  PRINT(0)("\nPlease give me a new value for %s [0,1](default:%d): ",this->title, this->defaultValue);
1202  cin >> tmpChar;
1203
1204  if ((this->value = atoi(tmpChar))=!0)
1205    this->value = 1;
1206#endif /* HAVE_GTK2 */
1207  PRINT(0)("%s set to: %d\n", this->title, this->value);
1208}
1209
1210
1211/**
1212   \brief Redraws the CheckButton(if option has changed).
1213   Example: if new settings are loaded the Button must be redrawn for the GUI to display that Change
1214*/
1215void CheckButton::redraw(void)
1216{
1217#ifdef HAVE_GTK2
1218  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->widget), value);
1219#endif /* HAVE_GTK2 */
1220}
1221
1222/* SLIDER */
1223
1224/**
1225   \brief Creates a new Slider
1226   \param slidername The data-structure-name of the slider.
1227   \param start The minimal Value of the slider.
1228   \param end The maximal Value of the slider.
1229*/
1230Slider::Slider(char* slidername, int start, int end)
1231{
1232  this->init(start, end);
1233  this->setValue(start);
1234  this->setTitle(slidername);
1235#ifdef HAVE_GTK2
1236  this->connectSignal("value_changed", this->OptionChange);
1237#endif /* HAVE_GTK2 */
1238}
1239
1240/**
1241   \brief destructs a Slider.
1242*/
1243Slider::~Slider(void)
1244{
1245  PRINTF(5)("deleting the Slider: %s\n", this->title);
1246}
1247
1248/**
1249   \brief Initializes a Slider with start and end Values
1250   params: see Slider::Slider(char* slidername, int start, int end)
1251*/
1252void Slider::init(int start, int end)
1253{
1254  this->isOption = 2;
1255
1256  this->start = start;
1257  this->end = end;
1258#ifdef HAVE_GTK2
1259 widget = gtk_hscale_new_with_range(this->start, this->end, 5);
1260#endif /* HAVE_GTK2 */
1261}
1262
1263/**
1264   \brief Setting a new value to the Slider.
1265   Maybe you also require a Slider::redraw() for this to display
1266*/
1267void Slider::setValue(int value)
1268{
1269  this->value = value;
1270}
1271
1272/**
1273   \brief Redraws the widget
1274   Example: see void CheckButton::redraw(void)
1275*/
1276void Slider::redraw(void)
1277{
1278#ifdef HAVE_GTK2
1279  gtk_range_set_value(GTK_RANGE(this->widget), value);
1280#endif /* HAVE_GTK2 */
1281}
1282
1283/**
1284   \brief Changed the Option, call this Function
1285*/
1286void Slider::changeOption(void)
1287{
1288#ifdef HAVE_GTK2
1289  this->value =(int)gtk_range_get_value(GTK_RANGE(this->widget));
1290#else /* HAVE_GTK2 */
1291  char tmpChar[20];
1292  PRINT(0)("\nPlease give me a new value for %s [%d-%d] (default:%d): ", this->title, this->start, this->end, this->defaultValue);
1293  cin >> tmpChar;
1294
1295  if ((this->value = atoi(tmpChar))> this->end)
1296    this->value = this->end;
1297  if (this->value <= this->start)
1298    this->value = this->start;
1299#endif /* HAVE_GTK2 */
1300  PRINT(0)("%s set to: %d\n",this->title, this->value);
1301}
1302
1303/* MENU */
1304
1305/**
1306   \brief constructs a new Menu, without adding any items to it.
1307   \param menuName the Name the Menu gets.
1308*/
1309Menu::Menu(const char* menuName)
1310{
1311  this->init();
1312  this->setTitle(menuName);
1313}
1314
1315/**
1316    \brief Creates a Menu-Item-list out of multiple input.
1317    !! Consider, that the last input argument has to be "lastItem" for this to work!!
1318    \param menuname The Database-Name of this Menu
1319    \param ... items to be added to this Menu. !! Consider, that the last input argument has to be "lastItem" for this to work!!
1320*/
1321Menu::Menu(char* menuname, ...)
1322{
1323  this->init();
1324  this->setTitle(menuname);
1325  va_list itemlist;                     //!< The list to readin multiple Options.
1326
1327  char *itemName;
1328
1329  va_start(itemlist, menuname);
1330  while(strcmp(itemName = va_arg(itemlist, char*), "lastItem"))
1331    {
1332      this->addItem(itemName);
1333    }
1334  va_end(itemlist);
1335}
1336
1337/**
1338   \brief destructs a Menu.
1339*/
1340Menu::~Menu(void)
1341{
1342  PRINTF(5)("deleting the Menu: %s\n", this->title);
1343  this->currItem = this->firstItem;
1344  while(this->currItem)
1345    {
1346      delete []this->currItem->name;
1347      //! \todo destroy menu
1348      /*
1349        #ifdef HAVE_GTK2
1350        free(this->currItem->item);
1351        #endif /* HAVE_GTK2 */
1352      MenuItem* tmpItem = this->currItem;
1353      this->currItem = this->currItem->next;
1354      delete tmpItem;
1355    }
1356}
1357
1358/**
1359   \brief Initializes a new Menu with no items
1360*/
1361void Menu::init(void)
1362{
1363  this->isOption = 2;
1364  this->firstItem = NULL;
1365
1366#ifdef HAVE_GTK2
1367  this->widget = gtk_option_menu_new();
1368  this->menu = gtk_menu_new();
1369  gtk_option_menu_set_menu(GTK_OPTION_MENU(this->widget), menu);
1370  this->connectSignal("changed", this->OptionChange);
1371#endif /* HAVE_GTK2 */
1372}
1373
1374/**
1375   \brief saves the Label of the Menu
1376   \returns the name of the selected Menu-Item
1377*/
1378char* Menu::save(void)
1379{
1380  MenuItem* tmpItem = this->firstItem;
1381  for (int i = 0; i<this->value; i++)
1382    tmpItem = tmpItem->next;
1383     
1384  return tmpItem->name;
1385}
1386
1387/**
1388   \brief loads a Menu from of its loadString
1389   \param loadString the string from which to load the data from
1390*/
1391void Menu::load(char* loadString)
1392{
1393  MenuItem* tmpItem = firstItem;
1394  bool foundItem = false;
1395  while (tmpItem)
1396    {
1397      if (!strcmp(loadString, tmpItem->name))
1398        {foundItem = true; break;}
1399      tmpItem = tmpItem->next;
1400    }
1401  if (foundItem)
1402    this->value = tmpItem->itemNumber;
1403  else
1404    {
1405      this->value = 0;
1406      PRINTF(2)("Sorry, but %s has not been found in the Itemlist of %s\n", loadString, this->title);
1407    }
1408  PRINTF(4)( "Loading %s: setting to %d\n", this->title, this->value); 
1409  this->redraw();
1410}
1411
1412/**
1413   \brief appends a new Item to the Menu-List.
1414   \param itemName the itemName to be appendet.
1415*/
1416void Menu::addItem(char* itemName)
1417{
1418  if (!this->firstItem)
1419    {
1420      this->firstItem = this->currItem = new MenuItem;
1421      this->currItem->itemNumber = 0;
1422    }
1423  else
1424    {
1425      int tmpI = this->currItem->itemNumber;
1426      this->currItem = this->currItem->next = new MenuItem;
1427      this->currItem->itemNumber = tmpI+1;
1428    }
1429
1430  this->currItem->name = new char[strlen(itemName)+1];
1431  strcpy(this->currItem->name, itemName);
1432
1433#ifdef HAVE_GTK2
1434  this->currItem->item = gtk_menu_item_new_with_label(itemName);
1435  gtk_menu_shell_append(GTK_MENU_SHELL(this->menu), this->currItem->item);
1436#endif /* HAVE_GTK2 */
1437  this->currItem->next = NULL;
1438}
1439
1440/**
1441   \brief Redraws the widget
1442   Example: see void CheckButton::redraw(void)
1443*/
1444void Menu::redraw(void)
1445{
1446#ifdef HAVE_GTK2
1447  gtk_option_menu_set_history(GTK_OPTION_MENU(this->widget), this->value);
1448#endif /* HAVE_GTK2 */
1449}
1450
1451/**
1452   \brief Changed the Option, call this Function
1453*/
1454void Menu::changeOption(void)
1455{
1456#ifdef HAVE_GTK2
1457  this->value =(int)gtk_option_menu_get_history(GTK_OPTION_MENU(this->widget));
1458#else /* HAVE_GTK2 */
1459  char tmpChar[20];
1460  PRINT(0)("\nPlease give me a new value for %s (default: %d): ", this->title, this->defaultValue);
1461  cin >> tmpChar;
1462  this->value = atoi(tmpChar);
1463
1464#endif /* HAVE_GTK2 */
1465  PRINT(4)("%s set to: %d\n", this->title, this->value);
1466}
1467
1468/* OPTION LABEL */
1469
1470/**
1471   \brief Creates a new OptionLabel with a LabelName and a Value.
1472   \param label The name of the OptionLabel.
1473   \param value The Value of the OptionLabel(what will be displayed).
1474*/
1475OptionLabel::OptionLabel(char* label, char* value)
1476{
1477  this->init();
1478  this->setTitle(label);
1479  this->setValue(value);
1480}
1481
1482/**
1483   \brief destructs an OptionLabel.
1484*/
1485OptionLabel::~OptionLabel(void)
1486{
1487  PRINTF(5)("deleting the OptionLabel: %s\n", this->title);
1488  if (this->cValue)
1489    delete []this->cValue;
1490}
1491
1492/**
1493   \brief Initializes an OptionLabel
1494*/
1495void OptionLabel::init(void)
1496{
1497  this->isOption = 5;
1498  cValue = NULL;
1499
1500#ifdef HAVE_GTK2
1501  this->widget = gtk_label_new("");
1502#endif /* HAVE_GTK2 */
1503}
1504
1505/**
1506   \brief Updates the value of an OptionLabel
1507   \param newValue The new Name that should be displayed.
1508*/
1509void OptionLabel::setValue(char* newValue)
1510{
1511  if (this->cValue)
1512    delete []this->cValue;
1513  this->cValue = new char [strlen(newValue)+1];
1514  strcpy(this->cValue, newValue);
1515#ifdef HAVE_GTK2
1516  gtk_label_set_text(GTK_LABEL(this->widget), this->cValue);
1517#endif /* HAVE_GTK2 */
1518}
1519
1520/**
1521   \brief Redraws an OptionLabel(not implemented yet, but it works).
1522*/
1523void OptionLabel::redraw(void)
1524{
1525#ifdef HAVE_GTK2
1526  gtk_label_set_text(GTK_LABEL(widget), title);
1527#endif /* HAVE_GTK2 */
1528}
1529
1530/**
1531   \brief Changed the Option, call this Function
1532*/
1533void OptionLabel::changeOption(void)
1534{
1535#ifdef HAVE_GTK2
1536  this->cValue =(char*)gtk_label_get_text(GTK_LABEL(this->widget));
1537#else /* HAVE_GTK2 */
1538  PRINT(0)("\nPlease give me a new input for %s: ", this->title);
1539  cin >> this->cValue;
1540#endif /* HAVE_GTK2 */
1541  PRINT(4)("%s set to: %s\n", this->title,  this->cValue);
1542}
1543
1544
1545/**
1546   \brief creates the Optionlabel save-string
1547   \returns the String to save.
1548*/
1549char* OptionLabel::save(void)
1550{
1551  return cValue;
1552}
1553
1554/**
1555   \brief loads an Option from of its loadString
1556   \param loadString the string from which to load the data from
1557*/
1558void OptionLabel::load(char* loadString)
1559{
1560  PRINTF(4)( "Loading %s: setting to %s\n", this->title, loadString); 
1561  this->setValue(loadString);
1562}
1563
1564/**
1565   \brief Creates a new default Label with no Text.
1566   You migth consider adding Label::setTitle with this.
1567*/
1568Label::Label(void)
1569{
1570  this->init();
1571}
1572
1573/**
1574   \brief Creates a new Label with a Text.
1575   \param text The text to be displayed.
1576*/
1577Label:: Label(char* text)
1578{
1579  this->init();
1580  this->setTitle(text);
1581}
1582
1583/**
1584   \brief destructs a Label.
1585*/
1586Label::~Label(void)
1587{
1588  PRINTF(5)("deleting the Label: %s\n", this->title);
1589}
1590
1591/**
1592   \brief initializes a new Label
1593*/
1594void Label::init(void)
1595{
1596  this->isOption = 0;
1597
1598#ifdef HAVE_GTK2
1599  this->widget = gtk_label_new("");
1600  gtk_label_set_line_wrap(GTK_LABEL(this->widget), TRUE);
1601#endif /* HAVE_GTK2 */
1602}
1603
1604/**
1605   \brief Sets a new Text to a Label.
1606   \param text The text to be inserted into the Label.
1607*/
1608void Label::setTitle(char* text)
1609{
1610  if (this->title)
1611    delete []this->title;
1612  this->title = new char[strlen(text)+1];
1613  strcpy(this->title, text);
1614#ifdef HAVE_GTK2
1615  gtk_label_set_text(GTK_LABEL(this->widget), this->title);
1616#endif /* HAVE_GTK2 */
1617}
1618
1619/**
1620   \brief ereases the Text of a Label
1621*/
1622void Label::ereaseText(void)
1623{
1624  this->setTitle("");
1625}
1626
1627/**
1628    \brief appends some Text to a Label
1629    \param textToAppend The text that will be appended to this Label
1630*/
1631void Label::appendText(char* textToAppend)
1632{
1633  if (this->title)
1634    {
1635      char* tmpTitle = new char[strlen(this->title)+strlen(textToAppend)+1];
1636      strcpy(tmpTitle, title); 
1637      strcat(tmpTitle, textToAppend);
1638      delete []this->title;
1639      this->title = tmpTitle;
1640    }
1641  else
1642    this->title = new char[strlen(textToAppend)];
1643 
1644#ifdef HAVE_GTK2
1645  gtk_label_set_text(GTK_LABEL(this->widget), title);
1646#endif /* HAVE_GTK2 */
1647}
1648
1649/**
1650    \brief Appends some integer to the Label
1651    \param intToAppend The Int that will be added.
1652   
1653    it does this by just converting the int into a char* and send it to appendText
1654*/
1655void Label::appendInt(int intToAppend)
1656{
1657  char append [32];
1658  sprintf(append, "%d", intToAppend);
1659  this->appendText(append);
1660}
1661
1662
1663/**
1664   \brief get the Text of a Label
1665   \return The Text the Label holds.
1666*/
1667char* Label::getText(void)
1668{
1669  return this->title;
1670}
1671
1672/**
1673   \brief Creates a new ProgressBar.
1674*/
1675ProgressBar::ProgressBar(void)
1676{
1677  this->init();
1678}
1679
1680/**
1681   \brief Creates a new ProgressBar.
1682   \param label The name you want to get the ProgressBar.
1683*/
1684ProgressBar::ProgressBar(char* label)
1685{
1686  this->init();
1687  this->setTitle(label);
1688}
1689
1690/**
1691   \brief destructs a ProgressBar
1692*/
1693ProgressBar::~ProgressBar(void)
1694{
1695  PRINTF(5)("deleting the ProgressBar: %s\n", this->title);
1696}
1697
1698/**
1699   \brief Initializes a ProgressBar
1700*/
1701void ProgressBar::init(void)
1702{
1703  this->isOption = 0;
1704  this->progress = 0.0;
1705  this->totalSize = 0.0;
1706
1707#ifdef HAVE_GTK2
1708  this->adjustment =(GtkAdjustment*)gtk_adjustment_new(0, 0, 100, 0, 0, 0);
1709  this->widget = gtk_progress_bar_new_with_adjustment(this->adjustment);
1710#endif /* HAVE_GTK2 */
1711}
1712
1713/**
1714   \brief Sets the Total size of the Bar.(ex. The maximum one can download)
1715*/
1716void ProgressBar::setTotalSize(double totalSize)
1717{
1718  this->totalSize = totalSize;
1719}
1720
1721/**
1722   \brief Sets the progress maximum is this->totalSize
1723*/
1724void ProgressBar::setProgress(double progress)
1725{
1726  this->progress = progress;
1727
1728  if (this->progress > this->totalSize)
1729    this->progress = this->totalSize;
1730
1731#ifdef HAVE_GTK2
1732  gtk_progress_set_value(GTK_PROGRESS(widget), this->progress*100.0/this->totalSize);
1733#endif /* HAVE_GTK2 */
1734  PRINTF(3)("Progress: %f\n", this->progress*100.0/this->totalSize);
1735}
1736
1737/**
1738    \brief returns the Progress Status
1739*/
1740double ProgressBar::getProgress(void)
1741{
1742  return this->progress;
1743}
1744
1745/* IMAGE */
1746
1747/**
1748   \brief Creates a new Image
1749   \param imageName the location of the Image on the Hard Disc
1750*/
1751Image::Image(const char* imageName)
1752{
1753  this->init(imageName);
1754
1755#ifdef HAVE_GTK2
1756  widget = gtk_image_new_from_file(imageName);
1757#endif /* HAVE_GTK2 */
1758}
1759
1760/**
1761   \brief Creates a new Image
1762   \param imageData data to the PixBuff
1763*/
1764Image::Image(char** imageData)
1765{
1766  this->init("pixBuffImage");
1767
1768#ifdef HAVE_GTK2
1769  widget = gtk_image_new_from_pixbuf(gdk_pixbuf_new_from_xpm_data((const char**)imageData));
1770#endif /* HAVE_GTK2 */
1771}
1772
1773
1774/**
1775   \brief destructs an Image.
1776*/
1777Image::~Image(void)
1778{
1779  PRINTF(5)("deleting the Image: %s\n", this->title);
1780}
1781
1782/**
1783    \brief Initializes a new Image
1784    \param name the name to set to the Image
1785*/
1786void Image::init(const char* name)
1787{
1788  isOption = 0;
1789
1790  if (this->title)
1791    delete []this->title;
1792  this->title = new char[strlen(name)+1];
1793  strcpy(this->title, name);
1794
1795}
Note: See TracBrowser for help on using the repository browser.