Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/guiMerge/src/lib/gui/gui/gui_gtk.cc @ 4047

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

orxonox/branches/guiMerge: nameSpace-changes

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