Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/md2_loader/src/lib/gui/gui/gui_gtk.cc @ 4063

Last change on this file since 4063 was 4063, checked in by patrick, 19 years ago

orxonox/branche/md2_loader: merged trunk into my branche

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