Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: gui: little patch, now only one resolution will be shown, if multiple bpp's are availiable

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