Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/updater: Now in non-gtk-mode, the Gui will ask questions for what Option to change… it is kind of sexy, but you can not change the Option yet. but this will follow.
I am now going into holydays till 1.1.2005: I hope you all have a good 'rutsch' into the new year.
cheers bensch

PS: I do not believe that anyone reads this, but anyways it was fun writing it :)

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