Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/gui/gui/gui_gtk.cc @ 4071

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

orxonox/trunk/gui: new isOption-tag of Widgets: optionType

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