Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/updater: moved some stuff to gui-gtk.

File size: 41.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()
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()
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()
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()
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  down = NULL;
524  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 (groupName)
539    delete []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 (groupName)
556    delete groupName;
557  groupName = new char [strlen(name)+1];
558  strcpy(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 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  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()
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
702  this->hide();
703  static_cast<Container*>(this)->destroy();
704 
705}
706
707/**
708   \brief Shows all Widgets that are included within this->widget.
709*/
710void Window::showall ()
711{
712  if (!isOpen)
713    {
714      //      printf ("showall\n");
715#ifdef HAVE_GTK2
716      gtk_widget_show_all  (widget);
717#endif /* HAVE_GTK2 */ 
718     isOpen = true;
719    }
720  else
721    {
722      //      printf ("showone\n");
723#ifdef HAVE_GTK2
724      gtk_widget_show (widget);
725#endif /* HAVE_GTK2 */
726    }
727}
728
729/**
730   \brief Set The Window-title to title
731   \param title title the Window should get.
732*/
733void Window::setTitle (char* title)
734{
735  if (this->title)
736    delete []this->title;
737  this->title = new char[strlen(title)+1];
738  strcpy(this->title, title);
739#ifdef HAVE_GTK2
740  gtk_window_set_title (GTK_WINDOW (widget), title);
741#endif /* HAVE_GTK2 */
742}
743
744/**
745   \brief opens up a Window and fixes the Focus to it
746*/
747void Window::open()
748{
749  if (this != mainWindow)
750    {
751      isOpen = true;
752#ifdef HAVE_GTK2
753      gtk_widget_show_all(widget);
754      gtk_grab_add(widget);
755#endif /* HAVE_GTK2 */
756    }
757}
758
759/**
760   \brief closes up a Window and removes the Focus from it
761*/
762void Window::close()
763{
764  if (this != mainWindow)
765    {
766      isOpen = false;
767#ifdef HAVE_GTK2
768      gtk_grab_remove(widget);
769      gtk_widget_hide (widget);
770#endif /* HAVE_GTK2 */
771    }
772}
773
774#ifdef HAVE_GTK2
775/**
776   \brief opens up a window (not topmost Window).
777   this is the Signal that does it. !!SIGNALS ARE STATIC!!
778   \param widget the widget that did it.
779   \param event the event that did it.
780   \param window the Window that should be opened
781*/
782gint Window::windowOpen (GtkWidget *widget, GdkEvent* event, void* window)
783{
784  static_cast<Window*>(window)->open();
785}
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*/
794gint Window::windowClose (GtkWidget *widget, GdkEvent* event, void* window)
795{
796  static_cast<Window*>(window)->close();
797}
798
799#endif /* HAVE_GTK2 */
800
801
802/* FRAME */
803
804/**
805    \brief Creates a new Frame without a name
806*/
807Frame::Frame (void)
808{
809  this->init();
810}
811
812/**
813   \brief Creates a new Frame with name title
814*/
815Frame::Frame (char* title)
816{
817  this->init();
818  this->setTitle(title);
819}
820
821/**
822   \brief destrcucts a Frame
823*/
824Frame::~Frame()
825{
826  this->destroy();
827}
828
829/**
830    \brief Initializes a new Frame with default settings
831*/
832void Frame::init()
833{
834  static_cast<Container*>(this)->init();
835
836#ifdef HAVE_GTK2
837  widget = gtk_frame_new ("");
838  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
839#endif /* HAVE_GTK2 */
840}
841
842/**
843   \brief Destroys a Frame.
844*/
845void Frame::destroy(void)
846{ 
847  if (this->title)
848    PRINTF(3)("deleting the Frame: %s\n", this->title);
849  else 
850    PRINTF(3)("deleting the Frame.\n");
851
852   static_cast<Container*>(this)->destroy();
853}
854
855/**
856   \brief Sets the Frames name to title
857   \param title The title the Frame should get.
858*/
859void Frame::setTitle (char* title)
860{
861  if (this->title)
862    delete []this->title;
863  this->title = new char[strlen(title)+1];
864  strcpy(this->title, title);
865#ifdef HAVE_GTK2
866  gtk_frame_set_label (GTK_FRAME (widget), title);
867#endif /* HAVE_GTK2 */
868}
869
870// EVENTBOX //
871
872/**
873   \brief Creates a new EventBox with default settings.
874*/
875EventBox::EventBox (void)
876{
877  this->init();
878}
879
880/**
881   \brief Creates a new EventBox with name title
882   \param title title the Eventbox should get (only data-structure-internal)
883*/
884EventBox::EventBox (char* title)
885{
886  this->init();
887  this->setTitle(title);
888}
889
890/**
891   \brief destructs an EventBox.
892*/
893EventBox::~EventBox(void)
894{
895  this->destroy();
896
897}
898
899/**
900   \brief Initializes a new EventBox
901*/
902void EventBox::init(void)
903{
904  isOption = -1;
905
906  static_cast<Container*>(this)->init();
907
908#ifdef HAVE_GTK2
909  widget = gtk_event_box_new ();
910  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
911#endif /* HAVE_GTK2 */
912}
913
914/**
915   \brief Destroys an EventBox.
916*/
917void EventBox::destroy(void)
918{ 
919  if (this->title)
920    PRINTF(3)("deleting the EventBox: %s\n", this->title);
921  else 
922    PRINTF(3)("deleting the EventBox.\n");
923
924  static_cast<Container*>(this)->destroy();
925}
926
927/**
928   \brief Sets the Title of the EventBox (not implemented)
929   \param title Name the EventBox should get (only datastructure-internal).
930*/
931void EventBox::setTitle (char* title)
932{
933  if (this->title)
934    delete []this->title;
935  this->title = new char[strlen(title)+1];
936  strcpy(this->title, title);
937}
938
939/* BOX */
940
941/**
942   \brief Creates a new horizontal Box
943*/
944Box::Box (void)
945{
946  this->init('h');
947}
948
949/**
950   \brief Creates a new Box of type boxtype
951   \param boxtype if 'v' the Box will be vertically, if 'h' the Box will be horizontally
952*/
953Box::Box (char boxtype)
954{
955  this->init(boxtype);
956}
957
958/**
959   \brief destructs a Box.
960*/
961Box::~Box(void)
962{
963  this->destroy();
964}
965
966/**
967   \brief Initializes a new Box with type boxtype
968   \param boxtype see Box(char boxtype)
969*/
970void Box::init(char boxtype)
971{
972  isOption = -2;
973
974  static_cast<Packer*>(this)->init();
975#ifdef HAVE_GTK2
976  if (boxtype == 'v')
977    {
978      widget = gtk_vbox_new (FALSE, 0);
979    }
980  else
981    {
982      widget = gtk_hbox_new (FALSE, 0);
983    }
984#endif /* HAVE_GTK2 */
985}
986
987/**
988   \brief Destroys a Box.
989*/
990void Box::destroy(void)
991{ 
992  if (this->title)
993    PRINTF(3)("deleting the Box: %s\n", this->title);
994  else 
995    PRINTF(3)("deleting the Box.\n");
996
997  static_cast<Packer*>(this)->destroy();
998}
999
1000/**
1001    \brief Fills a box with a given Widget.
1002    \param lowerWidget the next Widget that should be appendet to this Box
1003
1004    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
1005*/
1006void Box::fill (Widget *lowerWidget)
1007{
1008#ifdef HAVE_GTK2
1009  gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0);
1010#endif /* HAVE_GTK2 */
1011  if (this->down == NULL)
1012    this->down = lowerWidget;
1013  else
1014    {
1015      Widget* tmp;
1016      tmp = this->down;
1017      while (tmp->next != NULL)
1018        {
1019          tmp = tmp->next;
1020        }
1021      tmp->next = lowerWidget;
1022    }
1023}
1024
1025/**
1026   \brief Sets the Title of a Box.
1027   \param title the new Title to set.
1028*/
1029void Box::setTitle(char* title)
1030{
1031  if (this->title)
1032    delete []this->title;
1033  this->title = new char[strlen(title)+1];
1034  strcpy(this->title, title);
1035}
1036
1037/* OPTION */
1038
1039/**
1040   \brief Initializes a new Option.
1041   sets all Option-Specific-Values to their defaults.
1042*/
1043void Option::init()
1044{
1045  value = 0;
1046  flagName = NULL;
1047  flagNameShort = NULL;
1048  saveable = false;
1049  defaultValue = 0;
1050
1051  static_cast<Widget*>(this)->init();
1052
1053  return;
1054}
1055
1056/**
1057   \brief Destroys an Option.
1058*/
1059void Option::destroy(void)
1060{ 
1061  PRINTF(4)("deleting the Option Part.\n");
1062  if (flagName)
1063    delete []flagName;
1064  if (flagNameShort)
1065    delete []flagNameShort;
1066
1067  static_cast<Widget*>(this)->destroy();
1068}
1069
1070/**
1071   \brief This sets The FlagName of an Option and defines its default Values
1072   !! Options will be saved if flagname is different from NULL !!
1073   \param flagname the Name that will be displayed in the output
1074   \param defaultvalue the default Value for this Option (see definition of defaultvalue
1075*/
1076void Option::setFlagName (char* flagname, int defaultvalue)
1077{
1078  if (flagName)
1079    delete flagName;
1080  flagName = new char [strlen(flagname)+1];
1081  strcpy(flagName, flagname);
1082  defaultValue = defaultvalue;
1083
1084  //  cout << "Set Flagname of " << this->title << " to " << flagname << endl;
1085}
1086
1087/**
1088    \brief see Option::setFlagName (char* flagname, int defaultvalue)
1089    \param flagname the Name that will be displayed in the output
1090    \param defaultvalue the default Value for this Option (see definition of defaultvalue
1091    \param flagnameshort a short flagname to be displayed in the output
1092*/
1093void Option::setFlagName (char* flagname, char* flagnameshort,  int defaultvalue)
1094{
1095  if (flagName)
1096    delete flagName;
1097  flagName = new char [strlen(flagname)+1];
1098  strcpy(flagName, flagname);
1099
1100  if (flagNameShort)
1101    delete flagNameShort;
1102  flagNameShort = new char [strlen(flagnameshort)+1];
1103  strcpy(flagNameShort, flagnameshort);
1104  defaultValue = defaultvalue;
1105  //  cout << "Set Flagname of " << this->title << " to " << flagname << endl;
1106}
1107
1108/**
1109   \brief Sets the saveable-state of the option to true.
1110*/
1111void Option::saveability(void)
1112{
1113  this->saveable = true;
1114}
1115
1116/**
1117   \brief Sets the saveable-state of the option.
1118   \param isSaveable the saveable-state to set.
1119*/
1120void Option::saveability(bool isSaveable)
1121{
1122  this->saveable = isSaveable;
1123}
1124
1125/**
1126   \returns The saveable-state.
1127*/
1128bool Option::isSaveable(void)
1129{
1130  return this->saveable;
1131}
1132
1133#ifdef HAVE_GTK2
1134/**
1135    \brief Signal OptionChange writes the Value from the Slider to its Object-Database.
1136    \param widget The widget(Slider) that has a changed Value
1137    \param slider the Slider-Object that should receive the change.
1138*/
1139gint Option::OptionChange (GtkWidget *widget, Widget* option)
1140{
1141  static_cast<Option*>(option)->changeOption();
1142  flags->setTextFromFlags(orxonoxGUI);  //// must be different !!!
1143}
1144#endif /* HAVE_GTK2 */
1145
1146
1147/* BUTTON */
1148
1149/**
1150   \brief Creates a new Button with a buttonname
1151   \param buttonname sets the Name of the Button
1152*/
1153Button::Button(char* buttonname)
1154{
1155  this->init();
1156  this->setTitle(buttonname);
1157}
1158
1159/**
1160   \brief destructs a Button.
1161*/
1162Button::~Button(void)
1163{
1164  this->destroy();
1165}
1166
1167/**
1168   \brief Initializes a new Button
1169*/
1170void Button::init(void)
1171{
1172  isOption = 0;
1173
1174  static_cast<Option*>(this)->init();
1175
1176#ifdef HAVE_GTK2
1177  widget = gtk_button_new_with_label ("");
1178#endif /* HAVE_GTK2 */
1179}
1180
1181/**
1182   \brief Destroys a Button.
1183*/
1184void Button::destroy(void)
1185{ 
1186  if (this->title)
1187    PRINTF(3)("deleting the Label: %s\n", this->title);
1188  else 
1189    PRINTF(3)("deleting the Label.\n");
1190
1191  static_cast<Option*>(this)->destroy();
1192}
1193
1194/**
1195   \brief Sets a new name to the Button
1196   \param title The name the Button should get
1197*/
1198void Button::setTitle (char *title)
1199{
1200  if (this->title)
1201    delete []this->title;
1202  this->title = new char[strlen(title)+1];
1203  strcpy(this->title, title);
1204#ifdef HAVE_GTK2
1205  gtk_button_set_label (GTK_BUTTON(widget), title);
1206#endif /* HAVE_GTK2 */
1207}
1208
1209/**
1210   \brief redraws the Button
1211   not implemented yet
1212*/
1213void Button::redraw (void)
1214{
1215}
1216
1217/**
1218   \brief Button can not be changed, optionChange is empty)
1219*/
1220void Button::changeOption(void)
1221{
1222  // This will possibly be used for ACTIONS !
1223}
1224
1225/* CHECKBUTTON */
1226
1227/**
1228   \brief Creates a new CheckButton with an ame
1229   \param buttonname The name the CheckButton should display.
1230*/
1231CheckButton::CheckButton (char* buttonname)
1232{
1233  this->init();
1234  this->setTitle(buttonname);
1235
1236#ifdef HAVE_GTK2
1237  this->connectSignal ("clicked", this->OptionChange);
1238#endif /* HAVE_GTK2 */
1239}
1240
1241/**
1242   \brief destructs a CheckButton.
1243*/
1244CheckButton::~CheckButton(void)
1245{
1246  this->destroy();
1247}
1248
1249/**
1250   \brief Initialize a new CheckButton with default settings
1251*/
1252void CheckButton::init(void)
1253{
1254  isOption = 1;
1255
1256  static_cast<Option*>(this)->init();
1257
1258#ifdef HAVE_GTK2
1259  widget = gtk_check_button_new_with_label ("");
1260#endif /* HAVE_GTK2 */
1261}
1262
1263/**
1264   \brief Destroys a CheckButton.
1265*/
1266void CheckButton::destroy(void)
1267{ 
1268  if (this->title)
1269    PRINTF(3)("deleting the CheckButton: %s\n", this->title);
1270  else 
1271    PRINTF(3)("deleting the CheckButton.\n");
1272
1273  static_cast<Option*>(this)->destroy();
1274}
1275
1276/**
1277   \brief Sets a new Title to a CheckButton
1278   \param title The new Name the CheckButton should display.
1279*/
1280void CheckButton::setTitle(char* title)
1281{
1282  if (this->title)
1283    delete []this->title;
1284  this->title = new char[strlen(title)+1];
1285  strcpy(this->title, title);
1286#ifdef HAVE_GTK2
1287  gtk_button_set_label(GTK_BUTTON(widget), title);
1288#endif /* HAVE_GTK2 */
1289}
1290
1291bool CheckButton::isActive()
1292{
1293#ifdef HAVE_GTK2
1294  return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1295#endif /* HAVE_GTK2 */
1296}
1297
1298/**
1299   \brief Changed the Option, call this Function
1300*/
1301void CheckButton::changeOption()
1302{
1303#ifdef HAVE_GTK2
1304  this->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (this->widget));
1305#else /* HAVE_GTK2 */
1306  char tmpChar[20];
1307  cout << "\nPlease give me a new value for " << this->title << " [0,1](defualt:" << this->defaultValue << "): ";
1308  cin >> tmpChar;
1309
1310  if ((this->value = atoi(tmpChar))=!0)
1311    this->value = 1;
1312#endif /* HAVE_GTK2 */
1313  cout << this->title << " set to: " << this->value << endl;
1314}
1315
1316
1317/**
1318   \brief Redraws the CheckButton (if option has changed).
1319   Example: if new settings are loaded the Button must be redrawn for the GUI to display that Change
1320*/
1321void CheckButton::redraw ()
1322{
1323#ifdef HAVE_GTK2
1324  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
1325#endif /* HAVE_GTK2 */
1326}
1327
1328/* SLIDER */
1329
1330/**
1331   \brief Creates a new Slider
1332   \param slidername The data-structure-name of the slider.
1333   \param start The minimal Value of the slider.
1334   \param end The maximal Value of the slider.
1335*/
1336Slider::Slider (char* slidername, int start, int end)
1337{
1338  this->init(start, end);
1339  this->setValue(start);
1340  this->setTitle(slidername);
1341#ifdef HAVE_GTK2
1342  this->connectSignal ("value_changed", this->OptionChange);
1343#endif /* HAVE_GTK2 */
1344}
1345
1346/**
1347   \brief destructs a Slider.
1348*/
1349Slider::~Slider(void)
1350{
1351  this->destroy();
1352}
1353
1354/**
1355   \brief Initializes a Slider with start and end Values
1356   params: see Slider::Slider (char* slidername, int start, int end)
1357*/
1358void Slider::init(int start, int end)
1359{
1360  isOption = 2;
1361
1362  static_cast<Option*>(this)->init();
1363
1364  this->start = start;
1365  this->end = end;
1366#ifdef HAVE_GTK2
1367 widget = gtk_hscale_new_with_range (start, end, 5);
1368#endif /* HAVE_GTK2 */
1369}
1370
1371/**
1372   \brief Destroys a Slider.
1373*/
1374void Slider::destroy(void)
1375{ 
1376  if (this->title)
1377    PRINTF(3)("deleting the Slider: %s\n", this->title);
1378  else 
1379    PRINTF(3)("deleting the Slider.\n");
1380
1381  static_cast<Option*>(this)->destroy();
1382
1383}
1384
1385/**
1386   \brief Sets a new Title to the Slider
1387   \param title The new Name of the slider
1388*/
1389void Slider::setTitle(char* title)
1390{
1391  if (this->title)
1392    delete []this->title;
1393  this->title = new char[strlen(title)+1];
1394  strcpy(this->title, title);
1395}
1396
1397/**
1398   \brief Setting a new value to the Slider.
1399   Maybe you also require a Slider::redraw() for this to display
1400*/
1401void Slider::setValue(int value)
1402{
1403  this->value = value;
1404}
1405
1406/**
1407   \brief Redraws the widget
1408   Example: see void CheckButton::redraw ()
1409*/
1410void Slider::redraw ()
1411{
1412#ifdef HAVE_GTK2
1413  gtk_range_set_value (GTK_RANGE (widget), value);
1414#endif /* HAVE_GTK2 */
1415}
1416
1417/**
1418   \brief Changed the Option, call this Function
1419*/
1420void Slider::changeOption()
1421{
1422#ifdef HAVE_GTK2
1423  this->value = (int)gtk_range_get_value(GTK_RANGE(this->widget));
1424#else /* HAVE_GTK2 */
1425  char tmpChar[20];
1426  cout << "\nPlease give me a new value for " << this->title << " [" <<this->start << "-" << this->end << "](defualt:" << this->defaultValue << "): ";
1427  cin >> tmpChar;
1428
1429  if ((this->value = atoi(tmpChar))> this->end)
1430    this->value = this->end;
1431  if (this->value <= this->start)
1432    this->value = this->start;
1433#endif /* HAVE_GTK2 */
1434  cout << this->title << " set to: " << this->value << endl;
1435}
1436
1437/* MENU */
1438
1439/**
1440    \brief Creates a Menu-Item-list out of multiple input.
1441    !! Consider, that the last input argument has to be "lastItem" for this to work!!
1442    \param menuname The Database-Name of this Menu
1443    \param ... items to be added to this Menu. !! Consider, that the last input argument has to be "lastItem" for this to work!!
1444*/
1445Menu::Menu (char* menuname, ...)
1446{
1447  this->init();
1448  this->setTitle(menuname);
1449   
1450  char *itemName;
1451
1452#ifdef HAVE_GTK2             /////////////////////// REINPLEMENT
1453  va_start (itemlist, menuname);
1454  while (strcmp (itemName = va_arg (itemlist, char*), "lastItem"))
1455    {
1456      this->addItem(itemName);
1457    }
1458  va_end(itemlist);
1459#endif /* HAVE_GTK2 */
1460
1461#ifdef HAVE_GTK2
1462  gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu);
1463  this->connectSignal ("changed", this->OptionChange);
1464#endif /* HAVE_GTK2 */
1465}
1466
1467/**
1468   \brief destructs a Menu.
1469*/
1470Menu::~Menu(void)
1471{
1472  this->destroy();
1473}
1474
1475/**
1476   \brief Initializes a new Menu with no items
1477*/
1478void Menu::init(void)
1479{
1480  isOption = 2;
1481
1482  static_cast<Option*>(this)->init();
1483
1484#ifdef HAVE_GTK2
1485  widget = gtk_option_menu_new ();
1486  menu = gtk_menu_new ();
1487#endif /* HAVE_GTK2 */
1488
1489}
1490
1491/**
1492   \brief Destroys a Menu.
1493*/
1494void Menu::destroy(void)
1495{ 
1496  if (this->title)
1497    PRINTF(3)("deleting the Menu: %s\n", this->title);
1498  else 
1499    PRINTF(3)("deleting the Menu.\n");
1500  //! \todo destroy menu
1501 
1502  static_cast<Option*>(this)->destroy();
1503}
1504
1505
1506/**
1507 * Sets the Database-Name of this Menu
1508 \param title Database-Name to be set.
1509*/
1510void Menu::setTitle(char* title)
1511{
1512  if (this->title)
1513    delete []this->title;
1514  this->title = new char[strlen(title)+1];
1515  strcpy(this->title, title);
1516}
1517
1518/**
1519   \brief appends a new Item to the Menu-List.
1520   \param itemName the itemName to be appendet.
1521*/
1522void Menu::addItem (char* itemName)
1523{
1524#ifdef HAVE_GTK2
1525  item = gtk_menu_item_new_with_label (itemName);
1526  gtk_menu_shell_append(GTK_MENU_SHELL (menu), item);
1527#endif /* HAVE_GTK2 */
1528}
1529
1530/**
1531   \brief Redraws the widget
1532   Example: see void CheckButton::redraw ()
1533*/
1534void Menu::redraw ()
1535{
1536#ifdef HAVE_GTK2
1537 gtk_option_menu_set_history (GTK_OPTION_MENU (widget), value);
1538#endif /* HAVE_GTK2 */
1539}
1540
1541/**
1542   \brief Changed the Option, call this Function
1543*/
1544void Menu::changeOption()
1545{
1546#ifdef HAVE_GTK2
1547  this->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (this->widget));
1548#else /* HAVE_GTK2 */
1549  char tmpChar[20];
1550  cout << "\nPlease give me a new value for " << this->title << " (defualt:" << this->defaultValue << "): ";
1551  cin >> tmpChar;
1552  this->value = atoi(tmpChar);
1553
1554#endif /* HAVE_GTK2 */
1555  cout << this->title << " set to: " << this->value << endl;
1556}
1557
1558/* OPTION LABEL */
1559
1560/**
1561   \brief Creates a new OptionLabel with a LabelName and a Value.
1562   \param label The name of the OptionLabel.
1563   \param value The Value of the OptionLabel (what will be displayed).
1564*/
1565OptionLabel::OptionLabel(char* label, char* value)
1566{
1567  init();
1568  setTitle(label);
1569  setValue(value);
1570}
1571
1572/**
1573   \brief destructs an OptionLabel.
1574*/
1575OptionLabel::~OptionLabel(void)
1576{
1577  this->destroy();
1578}
1579
1580/**
1581   \brief Initializes an OptionLabel
1582*/
1583void OptionLabel::init(void)
1584{
1585  static_cast<Option*>(this)->init();
1586  isOption = 5;
1587  cValue = NULL;
1588
1589#ifdef HAVE_GTK2
1590  widget = gtk_label_new ("");
1591#endif /* HAVE_GTK2 */
1592}
1593
1594/**
1595   \brief Destroys a OptionLabel.
1596*/
1597void OptionLabel::destroy(void)
1598{ 
1599  if (this->title)
1600    PRINTF(3)("deleting the OptionLabel: %s\n", this->title);
1601  else 
1602    PRINTF(3)("deleting the OptionLabel.\n");
1603  if (cValue)
1604    delete []cValue;
1605
1606  static_cast<Option*>(this)->destroy();
1607}
1608
1609
1610/**
1611   \brief Updates the value of an OptionLabel
1612   \param newValue The new Name that should be displayed.
1613*/
1614void OptionLabel::setValue(char* newValue)
1615{
1616  if (cValue)
1617    delete cValue;
1618  cValue = new char [strlen(newValue)+1];
1619  strcpy(cValue, newValue);
1620#ifdef HAVE_GTK2
1621  gtk_label_set_text (GTK_LABEL (widget), cValue);
1622#endif /* HAVE_GTK2 */
1623}
1624
1625/**
1626   \brief Sets a ned Title to the OptionLabel.
1627   \param title The now title of the OptionLabel.
1628*/
1629void OptionLabel::setTitle(char* title)
1630{
1631  if (this->title)
1632    delete []this->title;
1633  this->title = new char [strlen(title)+1];
1634  strcpy(this->title, title);
1635#ifdef HAVE_GTK2
1636  gtk_label_set_text (GTK_LABEL(widget), title);
1637#endif /* HAVE_GTK2 */
1638}
1639
1640/**
1641   \brief Redraws an OptionLabel (not implemented yet, but it works).
1642*/
1643void OptionLabel::redraw(void)
1644{
1645 
1646}
1647
1648/**
1649   \brief Changed the Option, call this Function
1650*/
1651void OptionLabel::changeOption()
1652{
1653#ifdef HAVE_GTK2
1654  this->cValue = (char*)gtk_label_get_text (GTK_LABEL(this->widget));
1655#else /* HAVE_GTK2 */
1656  cout << "\nPlease give me a new input for " << this->title << ": ";
1657  cin >> this->cValue;
1658#endif /* HAVE_GTK2 */
1659  cout << this->title << " set to: " << this->cValue << endl;
1660}
1661
1662
1663/**
1664   \brief Creates a new default Label with no Text.
1665   You migth consider adding Label::setTitle with this.
1666*/
1667Label::Label ()
1668{
1669  this->init();
1670}
1671
1672/**
1673   \brief Creates a new Label with a Text.
1674   \param text The text to be displayed.
1675*/
1676Label:: Label (char* text)
1677{
1678  this->init();
1679  this->setTitle(text);
1680}
1681
1682/**
1683   \brief destructs a Label.
1684*/
1685Label::~Label(void)
1686{
1687  this->destroy();
1688}
1689
1690/**
1691   \brief initializes a new Label
1692*/
1693void Label::init(void)
1694{
1695  isOption = 0;
1696
1697  static_cast<Widget*>(this)->init();
1698
1699#ifdef HAVE_GTK2
1700  widget = gtk_label_new ("");
1701  gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE);
1702#endif /* HAVE_GTK2 */
1703}
1704
1705/**
1706   \brief Destroys a Label.
1707*/
1708void Label::destroy(void)
1709{ 
1710  if (this->title)
1711    PRINTF(3)("deleting the Label: %s\n", this->title);
1712  else 
1713    PRINTF(3)("deleting the Label.\n");
1714
1715  static_cast<Widget*>(this)->destroy();
1716}
1717
1718/**
1719   \brief Sets a new Text to a Label.
1720   \param text The text to be inserted into the Label.
1721*/
1722void Label::setTitle(char* text)
1723{
1724  if (this->title)
1725    delete []this->title;
1726  this->title = new char[strlen(text)+1];
1727  strcpy(this->title, text);
1728#ifdef HAVE_GTK2
1729  gtk_label_set_text (GTK_LABEL (this->widget), text);
1730#endif /* HAVE_GTK2 */
1731}
1732
1733/**
1734   \brief ereases the Text of a Label
1735*/
1736void Label::ereaseText(void)
1737{
1738  this->setTitle("");
1739}
1740
1741/**
1742    \brief appends some Text to a Label
1743    \param textToAppend The text that will be appended to this Label
1744*/
1745void Label::appendText(char* textToAppend)
1746{
1747  if (this->title)
1748    {
1749      char* tmpTitle = new char[strlen(this->title)+strlen(textToAppend)+1];
1750      strcpy(tmpTitle, title); 
1751      strcat(tmpTitle, textToAppend);
1752      delete []this->title;
1753      this->title = tmpTitle;
1754    }
1755  else
1756    {
1757      this->title = new char[strlen(textToAppend)];
1758    }
1759 
1760#ifdef HAVE_GTK2
1761  gtk_label_set_text (GTK_LABEL (this->widget), title);
1762#endif /* HAVE_GTK2 */
1763}
1764
1765/**
1766    \brief Appends some integer to the Label
1767    \param intToAppend The Int that will be added.
1768   
1769    it does this by just converting the int into a char* and send it to appendText
1770*/
1771void Label::appendInt(int intToAppend)
1772{
1773  char append [20];
1774  sprintf(append, "%d", intToAppend);
1775  this->appendText(append);
1776}
1777
1778
1779/**
1780   \brief get the Text of a Label
1781   \return The Text the Label holds.
1782*/
1783char* Label::getText ()
1784{
1785  return this->title;
1786}
1787
1788/**
1789   \brief Creates a new ProgressBar.
1790*/
1791ProgressBar::ProgressBar (void)
1792{
1793  this->init ();
1794}
1795
1796/**
1797   \brief Creates a new ProgressBar.
1798   \param label The name you want to get the ProgressBar.
1799*/
1800ProgressBar::ProgressBar (char* label)
1801{
1802  this->init();
1803  this->setTitle (label);
1804}
1805
1806/**
1807   \brief destructs a ProgressBar
1808*/
1809ProgressBar::~ProgressBar ()
1810{
1811  this->destroy();
1812}
1813
1814/**
1815   \brief Initializes a ProgressBar
1816*/
1817void ProgressBar::init (void)
1818{
1819  isOption = 0;
1820  progress = 0.0;
1821  totalSize = 0.0;
1822
1823  static_cast<Widget*>(this)->init();
1824#ifdef HAVE_GTK2
1825  adjustment = (GtkAdjustment*)gtk_adjustment_new(0, 0, 100, 0, 0, 0);
1826  widget = gtk_progress_bar_new_with_adjustment(adjustment);
1827#endif /* HAVE_GTK2 */
1828}
1829
1830/**
1831   \brief Destroys a ProgressBar.
1832*/
1833void ProgressBar::destroy(void)
1834{ 
1835  if (this->title)
1836    PRINTF(3)("deleting the ProgressBar: %s\n", this->title);
1837  else 
1838    PRINTF(3)("deleting the ProgressBar.\n");
1839
1840  static_cast<Widget*>(this)->destroy();
1841}
1842
1843/**
1844   \brief Sets a ned Title to the ProgressBar.
1845   \param title The now title of the ProgressBar.
1846*/
1847void ProgressBar::setTitle(char* title)
1848{
1849  if (this->title)
1850    delete []this->title;
1851  this->title = new char [strlen(title)+1];
1852  strcpy(this->title, title);
1853}
1854
1855/**
1856   \brief Sets the Total size of the Bar. (ex. The maximum one can download)
1857*/
1858void ProgressBar::setTotalSize (double totalSize)
1859{
1860  this->totalSize = totalSize;
1861}
1862
1863/**
1864   \brief Sets the progress maximum is this->totalSize
1865*/
1866void ProgressBar::setProgress (double progress)
1867{
1868  this->progress = progress;
1869
1870  if (this->progress > this->totalSize)
1871    this->progress = this->totalSize;
1872
1873#ifdef HAVE_GTK2
1874  gtk_progress_set_value(GTK_PROGRESS(widget), this->progress*100.0/this->totalSize);
1875#endif /* HAVE_GTK2 */
1876  PRINTF(3)("Progress: %f\n", progress*100.0/totalSize);
1877}
1878
1879/**
1880    \brief returns the Progress Status
1881*/
1882double ProgressBar::getProgress (void)
1883{
1884  return this->progress;
1885}
1886
1887/* IMAGE */
1888
1889/**
1890   \brief Creates a new Image
1891   \param imagename the location of the Image on the Hard Disc
1892*/
1893Image::Image (char* imagename)
1894{
1895  this->init();
1896  if (this->title)
1897    delete []this->title;
1898  this->title = new char[strlen(imagename)+1];
1899  strcpy(this->title, imagename);
1900
1901#ifdef HAVE_GTK2
1902  widget = gtk_image_new_from_file (imagename);
1903#endif /* HAVE_GTK2 */
1904}
1905
1906/**
1907   \brief destructs an Image.
1908*/
1909Image::~Image(void)
1910{
1911  this->destroy();
1912}
1913
1914/**
1915    \brief Initializes a new Image
1916*/
1917void Image::init()
1918{
1919  isOption = 0;
1920
1921  static_cast<Widget*>(this)->init();
1922}
1923
1924/**
1925   \brief Destroys a Image.
1926*/
1927void Image::destroy(void)
1928{ 
1929  if (this->title)
1930    PRINTF(3)("deleting the Image: %s\n", this->title);
1931  else 
1932    PRINTF(3)("deleting the Image.\n");
1933
1934  static_cast<Widget*>(this)->destroy();
1935}
1936
1937/**
1938   \brief Sets a ned Title to the Image.
1939   \param title The now title of the OptionLabel.
1940*/
1941void Image::setTitle(char* title)
1942{
1943  if (this->title)
1944    delete []this->title;
1945  this->title = new char [strlen(title)+1];
1946  strcpy(this->title, title);
1947}
Note: See TracBrowser for help on using the repository browser.