Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: no more iostream (for real)

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