Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: orxonox —help now shows something more usefull… still cleaning up the GUI

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