Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/updater/src/gui/orxonox_gui_gtk.cc @ 3465

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

orxonox/branches/updater: test

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