Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/branches/guiMerge: minor

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"
36extern OrxonoxGuiFlags* flags;
37
38char* guiExecutable;
39char* progExecutable;
40
41/**
42   \brief Initializes the Guis GTK-stuff.
43   \param argc the argument count.
44   \param argv The Argument strings.
45*/
46bool initGUI(int argc, char *argv[])
47{
48  guiExecutable = new char[strlen(argv[0])+1];
49  strcpy(guiExecutable, argv[0]);
50  progExecutable = new char[strlen(guiExecutable)-2];
51  strncpy(progExecutable, guiExecutable, strlen(guiExecutable)-3);
52  progExecutable[strlen(progExecutable)]= '\0';
53
54#ifdef HAVE_GTK2
55#ifdef HAVE_GTHREAD
56  PRINTF(4)("Initializing the ThreadSystem of the GUI\n");
57  g_thread_init(NULL);
58  gdk_threads_init();
59#endif /* HAVE_GTHREAD */
60  gtk_init(&argc, &argv);
61#include "rc"
62  gtk_rc_parse_string( rc_string );
63#endif /* HAVE_GTK2 */
64}
65
66/**
67   \brief enters the GUI's main-loop
68*/
69bool mainloopGUI(void)
70{
71#ifdef HAVE_GTK2
72  gdk_threads_enter();
73  gtk_main();
74  gdk_threads_leave();
75  delete Window::mainWindow;
76#else /* HAVE_GTK2 */
77  char boolAns = 'y';
78  char ans[1000];
79  PRINT(0)("================================\n");
80  PRINT(0)("= ORXONOX CONFIGURATION WIZARD =\n");
81  PRINT(0)("================================    - version:" PACKAGE_VERSION "\n");
82
83  while(true)
84    {
85      PRINT(0)("\n Listing all the Orxonox Options: \n");
86      PRINT(0)("  #############################\n");
87      Window::mainWindow->walkThrough(Widget::listOptionsAndGroups, 1);
88     
89      PRINT(0)("\nDo you want change any of the above values now? [Yn] ");
90      scanf("%s", ans);
91      if (ans[0] =='n' || ans[0]=='N')
92        break;
93     
94      PRINT(0)("\n Listing all groups\n");
95      PRINT(0)("  #################\n");
96      int groupCount = 0;
97      Window::mainWindow->walkThrough(Widget::listGroups, &groupCount, 1);
98     
99      PRINT(0)("\nIn which Group? [1-%d] ", groupCount);
100      Packer* group;
101      while(true)
102        {
103          scanf("%s", ans);
104          int ansIp = atoi(ans);
105          if (ansIp <= groupCount)
106            {
107              group = static_cast<Packer*>(Window::mainWindow->findGroupByNumber(&ansIp, 1));
108              break;
109            }
110          else
111            PRINT(0)("\nChoose a smaller Number please: [1-%d] ", groupCount);
112        }
113      PRINT(0)("\n\nGroup: [%s]\n\n", group->groupName);
114      int optionCount = 0;
115      group->walkThrough(Widget::listOptions, &optionCount, 0);
116      PRINT(0)("\nWhich Option? [1-%d] ", optionCount);
117      Option* option;
118      while(true)
119        {
120          scanf("%s", ans);
121          int ansIp = atoi(ans);
122          if (ansIp <= groupCount)
123            {
124              option = static_cast<Option*>(group->findOptionByNumber(&ansIp, 0));
125              break;
126            }
127          else
128            PRINT(0)("\nChoose a smaler Number please: [1-%d] ", optionCount);
129        }
130      PRINT(0)("\n\n:: %s ::\n", option->title);
131      option->changeOption();
132     
133      // here follows the rest.... this will be nasty.
134      //! \todo move this into the gui-gtk-file
135      //! \todo finish it.
136      //! \todo memory leek at save(); and save is a BAD word, use saveString instead, or something like it.
137    }
138#endif /* HAVE_GTK2 */
139 
140}
141
142
143//////////////////////////////
144/// DEFINING WIDGET-CLASES ///
145//////////////////////////////
146
147////////////
148/* WIDGET */
149////////////
150/**
151   \brief constructs a Widget
152*/
153Widget::Widget(void)
154{
155  next = NULL;
156  this->title = NULL;
157}
158
159/**
160   \brief deletes any given Widget
161   This is still pretty crappy.
162*/
163Widget::~Widget(void)
164{
165  if (this->title)
166    {
167      delete []this->title;
168    }
169 
170  PRINTF(5)("deleting the Widget part.\n");
171
172  // deleting next item if existent
173  if (this->next)
174    delete this->next;
175  this->next = NULL;
176
177  //!  \todo not hiding widget, deleting.
178  //  this->hide();
179  // gtk_destroy_widget(this->widget);
180}
181
182/**
183   \brief sets a new Title to a Widget
184   \param title The new Title to set to the Widget
185*/
186void Widget::setTitle(const char* title)
187{
188  if (this->title)
189    delete []this->title;
190  this->title = new char[strlen(title)+1];
191  strcpy(this->title, title);
192}
193
194/**
195   \brief makes the widget visible.
196*/
197void Widget::show(void)
198{
199#ifdef HAVE_GTK2
200  gtk_widget_show(this->widget);
201#endif /* HAVE_GTK2 */
202}
203
204/**
205   \brief hides the widget.
206*/
207void Widget::hide(void)
208{
209#ifdef HAVE_GTK2
210  gtk_widget_hide(this->widget);
211#endif /* HAVE_GTK2 */
212}
213
214/**
215   \brief Sets the resolution of a specific widget to the given size.
216   \param width the width of the widget to set.
217   \param height the height of the widget to set.
218*/
219void Widget::setSize(int width, int height)
220{
221#ifdef HAVE_GTK2
222  gtk_widget_set_usize(this->widget, width, height);
223#endif /* HAVE_GTK2 */
224}
225
226/**
227   \brief searches through widgets for a Name.
228*/
229Widget* Widget::findWidgetByName(char* name, unsigned int depth)
230{
231
232  if (this->title && !strcmp(this->title, name))
233    return this;
234
235  if (this->isOption < 0 && static_cast<Packer*>(this)->down)
236    {
237      Widget* tmp = static_cast<Packer*>(this)->down->findWidgetByName(name, depth+1);
238      if (tmp)
239        return tmp;
240    }
241 
242  if (depth>0 && this->next)
243    return this->next->findWidgetByName(name, depth);
244
245  return NULL;
246}
247
248/**
249   \brief Moves through all the Widgets downwards from this and executes the function on them.
250   \param function must be of type void and takes a Widget* as an Input.
251   \param depth the current depth. if > 0 then the next Widget will also be walked through.
252*/
253void Widget::walkThrough(void(*function)(Widget*), unsigned int depth)
254{
255  function(this);
256  if (this->isOption < 0)
257    {
258      static_cast<Packer*>(this)->down->walkThrough(function, depth+1);
259    } 
260
261  if (this->next && depth != 0)
262    this->next->walkThrough(function, depth);
263}
264
265/**
266   \brief Moves through all the Widgets downwards from this and executes the function on them.
267   \param function must be of type void and takes a Widget* as an Input.
268   \param data Additional Data you want to pass to the function.
269   \param depth the current depth. if > 0 then the next Widget will also be walked through.
270*/
271void Widget::walkThrough(void(*function)(Widget*, void*), void* data, unsigned int depth)
272{
273  function(this, data);
274  if (this->isOption < 0)
275    {
276      static_cast<Packer*>(this)->down->walkThrough(function, data, depth+1);
277    }
278  if (this->next && depth != 0)
279    this->next->walkThrough(function, data, depth);
280}
281
282/**
283    \brief This is for listing the options of "widget"
284    \param widget specifies the widget that should be listed
285*/
286void Widget::listOptionsAndGroups(Widget* widget)
287{
288  if (widget->isOption < 0 && static_cast<Packer*>(widget)->groupName)
289    PRINT(0)("[%s]\n", static_cast<Packer*>(widget)->groupName);
290  if (widget->isOption >= 1)
291    {
292      Widget::listOptions(widget);
293    }
294}
295
296/**
297    \brief This is for listing the options of "widget"
298    \param widget specifies the widget that should be listed
299*/
300void Widget::listOptions(Widget* widget)
301{
302  if(widget->isOption >= 1)
303    PRINT(0)("  %s is %s\n", static_cast<Option*>(widget)->title, static_cast<Option*>(widget)->save());
304}
305
306/**
307    \brief This is for listing the options of "widget"
308    \param widget specifies the widget that should be listed
309    \param data A Counter, that always knows how many Options have been found yet.
310*/
311void Widget::listOptions(Widget* widget, void* data)
312{
313 
314  if (widget->isOption >= 1)
315    {
316      int* count =(int*)data;
317      *count = *count +1;
318      PRINT(0)(" %d:%s is %s\n", *count,
319               static_cast<Option*>(widget)->title,
320               static_cast<Option*>(widget)->save());
321    }
322}
323
324/**
325    \brief Finds an Option by a given number(the n'th option found away from this Widget)
326    \param number The Count of options to wait(by reference)
327    \param depth The depth of the sarch. if 0 it will not search next pointer
328   
329    \todo should return Option* would be much sexier.
330*/
331Widget* Widget::findOptionByNumber(int* number, unsigned int depth)
332{
333  if (isOption > 0)
334    {
335      --*number;
336      if (*number <= 0)
337        {
338          return this;
339        }
340    }
341  if (this->isOption < 0 && static_cast<Packer*>(this)->down)
342    {
343      Widget* tmp = static_cast<Packer*>(this)->down->findOptionByNumber(number, depth+1);
344      if (tmp)
345        return tmp;
346    }
347  if (depth>0 && this->next)
348    return this->next->findOptionByNumber(number, depth);
349
350  return NULL;
351}
352
353/**
354    \brief This is for listing the groups of "widget"
355    \param widget specifies the widget that should be listed
356*/
357void Widget::listGroups(Widget* widget)
358{
359  if (widget->isOption < 0 && static_cast<Packer*>(widget)->groupName)
360    PRINT(0)("[%s]\n", static_cast<Packer*>(widget)->groupName);
361}
362
363/**
364    \brief This is for listing the Groups of "widget". It also displays the n'th number found.
365    \param widget specifies the widget that should be listed
366    \param data the Counter, that will show the number(this function will raise it by one if a Group is fount.
367*/
368void Widget::listGroups(Widget* widget, void* data)
369{
370  int* count = (int*)data;
371  if (widget->isOption < 0 && static_cast<Packer*>(widget)->groupName)
372    PRINT(0)("%d: [%s]\n", ++*count, static_cast<Packer*>(widget)->groupName);
373}
374
375/**
376    \brief Finds a Group by a given number(the n'th Group found away from this Widget)
377    \param number The Count of options to wait(by reference)
378    \param depth The depth of the sarch. if 0 it will not search next pointer
379*/
380Widget* Widget::findGroupByNumber(int* number, unsigned int depth)
381{
382  if (isOption < 0 && static_cast<Packer*>(this)->groupName)
383    {
384      --*number;
385      if (*number <= 0)
386        {
387          return this;
388        }
389    }
390  if (this->isOption < 0 && static_cast<Packer*>(this)->down)
391    {
392      Widget* tmp = static_cast<Packer*>(this)->down->findGroupByNumber(number, depth+1);
393      if (tmp)
394        return tmp;
395    }
396  if (depth>0 && this->next)
397    return this->next->findGroupByNumber(number, depth);
398
399  return NULL;
400}
401 
402/**
403    \brief This is for setting the option of "widget"
404    \param widget specifies the widget that should be set.
405*/
406void Widget::setOptions(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   \brief This sets The FlagName of an Option and defines its default Values
923   !! Options will be saved if flagname is different from NULL !!
924   \param flagname the Name that will be displayed in the output
925   \param defaultvalue the default Value for this Option(see definition of defaultvalue
926*/
927void Option::setFlagName(const char* flagname, int defaultvalue)
928{
929  if (this->flagName)
930    delete this->flagName;
931  this->flagName = new char [strlen(flagname)+1];
932  strcpy(this->flagName, flagname);
933
934  this->defaultValue = defaultvalue;
935
936  if (this->flagNameShort)
937    {
938      delete this->flagNameShort;
939      this->flagNameShort = NULL;
940    }
941
942  //  cout << "Set Flagname of " << this->title << " to " << flagname << endl;
943}
944
945/**
946    \brief see Option::setFlagName(char* flagname, int defaultvalue)
947    \param flagname the Name that will be displayed in the output
948    \param defaultvalue the default Value for this Option(see definition of defaultvalue
949    \param flagnameshort a short flagname to be displayed in the output
950*/
951void Option::setFlagName(const char* flagname, const char* flagnameshort,  int defaultvalue)
952{
953  if (this->flagName)
954    delete []this->flagName;
955  this->flagName = new char [strlen(flagname)+1];
956  strcpy(this->flagName, flagname);
957
958  if (this->flagNameShort)
959    delete []this->flagNameShort;
960  this->flagNameShort = new char [strlen(flagnameshort)+1];
961  strcpy(this->flagNameShort, flagnameshort);
962  this->defaultValue = defaultvalue;
963  //  cout << "Set Flagname of " << this->title << " to " << flagname << endl;
964}
965
966void Option::setDescription(const char* shortDescription, const char* longDescription)
967{
968  // setting up the short description
969  if (this->shortDescription)
970    delete []this->shortDescription;
971  this->shortDescription = new char [strlen(shortDescription)+1];
972  strcpy(this->shortDescription, shortDescription);
973
974  //setting up the long description
975  if (this->longDescription)
976    delete []this->longDescription;
977  if (longDescription)
978    {
979      this->longDescription = new char [strlen(longDescription)+1];
980      strcpy(this->longDescription, longDescription);
981    }
982  else
983    this->longDescription = NULL;
984}
985
986/**
987   \brief Sets the saveable-state of the option.
988   \param isSaveable the saveable-state to set.
989*/
990void Option::saveability(bool isSaveable)
991{
992  this->saveable = isSaveable;
993}
994
995/**
996   \brief saves an Option
997   \returns the String that should be saved. (this string __should__ be deleted)
998
999   this is a default Option save
1000*/
1001char* Option::save(void)
1002{
1003  char* value = new char [30];
1004  sprintf (value, "%d", this->value);
1005  return value;
1006}
1007
1008/**
1009   \brief loads an Option from of its loadString
1010   \param loadString the string from which to load the data from
1011*/
1012void Option::load(char* loadString)
1013{
1014  this->value = atoi(loadString);
1015  PRINT(5)("Loading %s: %s %d\n", this->title, loadString, value); 
1016  this->redraw();
1017}
1018
1019/**
1020   \returns The saveable-state.
1021*/
1022bool Option::isSaveable(void)
1023{
1024  return this->saveable;
1025}
1026
1027#ifdef HAVE_GTK2
1028/**
1029    \brief Signal OptionChange writes the Value from the Slider to its Object-Database.
1030    \param widget The widget(Slider) that has a changed Value
1031    \param slider the Slider-Object that should receive the change.
1032*/
1033gint Option::OptionChange(GtkWidget *widget, Widget* option)
1034{
1035  static_cast<Option*>(option)->changeOption();
1036  flags->setTextFromFlags(Window::mainWindow);  //// must be different !!!
1037}
1038#endif /* HAVE_GTK2 */
1039
1040////////////
1041/* BUTTON */
1042////////////
1043/**
1044   \brief Creates a new Button with a buttonname
1045   \param buttonName sets the Name of the Button
1046*/
1047Button::Button(char* buttonName)
1048{
1049  isOption = 0;
1050
1051#ifdef HAVE_GTK2
1052  widget = gtk_button_new_with_label("");
1053#endif /* HAVE_GTK2 */
1054
1055  if (buttonName)
1056    this->setTitle(buttonName);
1057}
1058
1059/**
1060   \brief destructs a Button.
1061*/
1062Button::~Button(void)
1063{
1064  PRINTF(5)("deleting the Label: %s\n", this->title);
1065}
1066
1067/**
1068   \brief Sets a new name to the Button
1069   \param title The name the Button should get
1070*/
1071void Button::setTitle(const char *title)
1072{
1073  if (this->title)
1074    delete []this->title;
1075  this->title = new char[strlen(title)+1];
1076  strcpy(this->title, title);
1077#ifdef HAVE_GTK2
1078  gtk_button_set_label(GTK_BUTTON(widget), title);
1079#endif /* HAVE_GTK2 */
1080}
1081
1082/**
1083   \brief redraws the Button
1084   \todo not implemented yet
1085*/
1086void Button::redraw(void)
1087{
1088}
1089
1090/**
1091   \brief Button can not be changed, optionChange is empty)
1092
1093   \todo Actions for non-GTK-mode
1094*/
1095void Button::changeOption(void)
1096{
1097  // This will possibly be used for ACTIONS !
1098}
1099
1100/////////////////
1101/* CHECKBUTTON */
1102/////////////////
1103/**
1104   \brief Creates a new CheckButton with an ame
1105   \param buttonName The name the CheckButton should display.
1106*/
1107CheckButton::CheckButton(const char* buttonName)
1108{
1109  this->isOption = 1;
1110
1111#ifdef HAVE_GTK2
1112  this->widget = gtk_check_button_new_with_label("");
1113#endif /* HAVE_GTK2 */
1114
1115  if (buttonName)
1116    this->setTitle(buttonName);
1117
1118#ifdef HAVE_GTK2
1119  this->connectSignal("clicked", this->OptionChange);
1120#endif /* HAVE_GTK2 */
1121}
1122
1123/**
1124   \brief destructs a CheckButton.
1125*/
1126CheckButton::~CheckButton(void)
1127{
1128  if (this->title)
1129    PRINTF(5)("deleting the CheckButton: %s\n", this->title);
1130  else 
1131    PRINTF(5)("deleting the CheckButton.\n");
1132}
1133
1134/**
1135   \brief Sets a new Title to a CheckButton
1136   \param title The new Name the CheckButton should display.
1137*/
1138void CheckButton::setTitle(const char* title)
1139{
1140  if (this->title)
1141    delete []this->title;
1142  this->title = new char[strlen(title)+1];
1143  strcpy(this->title, title);
1144#ifdef HAVE_GTK2
1145  gtk_button_set_label(GTK_BUTTON(widget), title);
1146#endif /* HAVE_GTK2 */
1147}
1148
1149/**
1150   \returns the Active state of the checkButton
1151*/
1152bool CheckButton::isActive(void)
1153{
1154#ifdef HAVE_GTK2
1155  return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
1156#endif /* HAVE_GTK2 */
1157}
1158
1159/**
1160   \brief Changed the Option, call this Function
1161*/
1162void CheckButton::changeOption(void)
1163{
1164#ifdef HAVE_GTK2
1165  this->value =(int)gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(this->widget));
1166#else /* HAVE_GTK2 */
1167  char tmpChar[200];
1168  PRINT(0)("\nPlease give me a new value for %s [0,1](default:%d): ",this->title, this->defaultValue);
1169  scanf("%s", tmpChar);
1170
1171  if ((this->value = atoi(tmpChar))=!0)
1172    this->value = 1;
1173#endif /* HAVE_GTK2 */
1174  PRINT(0)("%s set to: %d\n", this->title, this->value);
1175}
1176
1177/**
1178   \brief Redraws the CheckButton(if option has changed).
1179   Example: if new settings are loaded the Button must be redrawn for the GUI to display that Change
1180*/
1181void CheckButton::redraw(void)
1182{
1183#ifdef HAVE_GTK2
1184  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->widget), value);
1185#endif /* HAVE_GTK2 */
1186}
1187
1188////////////
1189/* SLIDER */
1190////////////
1191/**
1192   \brief Creates a new Slider
1193   \param slidername The data-structure-name of the slider.
1194   \param start The minimal Value of the slider.
1195   \param end The maximal Value of the slider.
1196*/
1197Slider::Slider(const char* slidername, int start, int end)
1198{
1199  this->isOption = 2;
1200
1201  this->start = start;
1202  this->end = end;
1203#ifdef HAVE_GTK2
1204 widget = gtk_hscale_new_with_range(this->start, this->end, 5);
1205#endif /* HAVE_GTK2 */
1206
1207  this->setValue(start);
1208  this->setTitle(slidername);
1209#ifdef HAVE_GTK2
1210  this->connectSignal("value_changed", this->OptionChange);
1211#endif /* HAVE_GTK2 */
1212}
1213
1214/**
1215   \brief destructs a Slider.
1216*/
1217Slider::~Slider(void)
1218{
1219  PRINTF(5)("deleting the Slider: %s\n", this->title);
1220}
1221
1222/**
1223   \brief Setting a new value to the Slider.
1224   Maybe you also require a Slider::redraw() for this to display
1225*/
1226void Slider::setValue(int value)
1227{
1228  this->value = value;
1229}
1230
1231/**
1232   \brief Redraws the widget
1233   Example: see void CheckButton::redraw(void)
1234*/
1235void Slider::redraw(void)
1236{
1237#ifdef HAVE_GTK2
1238  gtk_range_set_value(GTK_RANGE(this->widget), this->value);
1239#endif /* HAVE_GTK2 */
1240}
1241
1242/**
1243   \brief Changed the Option, call this Function
1244*/
1245void Slider::changeOption(void)
1246{
1247#ifdef HAVE_GTK2
1248  this->value =(int)gtk_range_get_value(GTK_RANGE(this->widget));
1249#else /* HAVE_GTK2 */
1250  char tmpChar[20];
1251  PRINT(0)("\nPlease give me a new value for %s [%d-%d] (default:%d): ", this->title, this->start, this->end, this->defaultValue);
1252  scanf("%s", tmpChar);
1253
1254  if ((this->value = atoi(tmpChar))> this->end)
1255    this->value = this->end;
1256  if (this->value <= this->start)
1257    this->value = this->start;
1258#endif /* HAVE_GTK2 */
1259  PRINT(0)("%s set to: %d\n",this->title, this->value);
1260}
1261
1262//////////
1263/* MENU */
1264//////////
1265/**
1266   \brief constructs a new Menu, without adding any items to it.
1267   \param menuName the Name the Menu gets.
1268*/
1269Menu::Menu(const char* menuName)
1270{
1271  this->init();
1272  this->setTitle(menuName);
1273}
1274
1275/**
1276    \brief Creates a Menu-Item-list out of multiple input.
1277    !! Consider, that the last input argument has to be "lastItem" for this to work!!
1278    \param menuname The Database-Name of this Menu
1279    \param ... items to be added to this Menu. !! Consider, that the last input argument has to be "lastItem" for this to work!!
1280*/
1281Menu::Menu(char* menuname, ...)
1282{
1283  this->init();
1284  this->setTitle(menuname);
1285  va_list itemlist;                     //!< The list to readin multiple Options.
1286
1287  char *itemName;
1288
1289  va_start(itemlist, menuname);
1290  while(strcmp(itemName = va_arg(itemlist, char*), "lastItem"))
1291    {
1292      this->addItem(itemName);
1293    }
1294  va_end(itemlist);
1295}
1296
1297/**
1298   \brief destructs a Menu.
1299*/
1300Menu::~Menu(void)
1301{
1302  PRINTF(5)("deleting the Menu: %s\n", this->title);
1303  this->currItem = this->firstItem;
1304  while(this->currItem)
1305    {
1306      delete []this->currItem->name;
1307      //! \todo destroy menu
1308      /*
1309        #ifdef HAVE_GTK2
1310        gtk_widget_destroy(this->currItem->item);
1311        #endif /* HAVE_GTK2 */
1312      MenuItem* tmpItem = this->currItem;
1313      this->currItem = this->currItem->next;
1314      delete tmpItem;
1315    }
1316}
1317
1318/**
1319   \brief Initializes a new Menu with no items
1320*/
1321void Menu::init(void)
1322{
1323  this->isOption = 2;
1324  this->firstItem = NULL;
1325
1326#ifdef HAVE_GTK2
1327  this->widget = gtk_option_menu_new();
1328  this->menu = gtk_menu_new();
1329  gtk_option_menu_set_menu(GTK_OPTION_MENU(this->widget), menu);
1330  this->connectSignal("changed", this->OptionChange);
1331#endif /* HAVE_GTK2 */
1332}
1333
1334/**
1335   \brief saves the Label of the Menu
1336   \returns the name of the selected Menu-Item
1337*/
1338char* Menu::save(void)
1339{
1340  MenuItem* tmpItem = this->firstItem;
1341  for (int i = 0; i<this->value; i++)
1342    tmpItem = tmpItem->next;
1343     
1344  return tmpItem->name;
1345}
1346
1347/**
1348   \brief loads a Menu from of its loadString
1349   \param loadString the string from which to load the data from
1350*/
1351void Menu::load(char* loadString)
1352{
1353  MenuItem* tmpItem = firstItem;
1354  bool foundItem = false;
1355  while (tmpItem)
1356    {
1357      if (!strcmp(loadString, tmpItem->name))
1358        {foundItem = true; break;}
1359      tmpItem = tmpItem->next;
1360    }
1361  if (foundItem)
1362    this->value = tmpItem->itemNumber;
1363  else
1364    {
1365      this->value = 0;
1366      PRINTF(2)("Sorry, but %s has not been found in the Itemlist of %s\n", loadString, this->title);
1367    }
1368  PRINTF(4)( "Loading %s: setting to %d\n", this->title, this->value); 
1369  this->redraw();
1370}
1371
1372/**
1373   \brief appends a new Item to the Menu-List.
1374   \param itemName the itemName to be appendet.
1375*/
1376void Menu::addItem(char* itemName)
1377{
1378  if (!this->firstItem)
1379    {
1380      this->firstItem = this->currItem = new MenuItem;
1381      this->currItem->itemNumber = 0;
1382    }
1383  else
1384    {
1385      int tmpI = this->currItem->itemNumber;
1386      this->currItem = this->currItem->next = new MenuItem;
1387      this->currItem->itemNumber = tmpI+1;
1388    }
1389
1390  this->currItem->name = new char[strlen(itemName)+1];
1391  strcpy(this->currItem->name, itemName);
1392
1393#ifdef HAVE_GTK2
1394  this->currItem->item = gtk_menu_item_new_with_label(itemName);
1395  gtk_menu_shell_append(GTK_MENU_SHELL(this->menu), this->currItem->item);
1396#endif /* HAVE_GTK2 */
1397  this->currItem->next = NULL;
1398}
1399
1400/**
1401   \brief Redraws the widget
1402   Example: see void CheckButton::redraw(void)
1403*/
1404void Menu::redraw(void)
1405{
1406#ifdef HAVE_GTK2
1407  gtk_option_menu_set_history(GTK_OPTION_MENU(this->widget), this->value);
1408#endif /* HAVE_GTK2 */
1409}
1410
1411/**
1412   \brief Changed the Option, call this Function
1413*/
1414void Menu::changeOption(void)
1415{
1416#ifdef HAVE_GTK2
1417  this->value =(int)gtk_option_menu_get_history(GTK_OPTION_MENU(this->widget));
1418#else /* HAVE_GTK2 */
1419  char tmpChar[20];
1420  PRINT(0)("\nPlease give me a new value for %s (default: %d): ", this->title, this->defaultValue);
1421  scanf("%s",tmpChar);
1422  this->value = atoi(tmpChar);
1423
1424#endif /* HAVE_GTK2 */
1425  PRINT(4)("%s set to: %d\n", this->title, this->value);
1426}
1427
1428/* OPTION LABEL */
1429
1430/**
1431   \brief Creates a new OptionLabel with a LabelName and a Value.
1432   \param label The name of the OptionLabel.
1433   \param value The Value of the OptionLabel(what will be displayed).
1434*/
1435OptionLabel::OptionLabel(const char* label, const char* value)
1436{
1437  this->isOption = 5;
1438  cValue = NULL;
1439
1440#ifdef HAVE_GTK2
1441  this->widget = gtk_label_new("");
1442#endif /* HAVE_GTK2 */
1443
1444  this->setTitle(label);
1445  this->setValue(value);
1446}
1447
1448/**
1449   \brief destructs an OptionLabel.
1450*/
1451OptionLabel::~OptionLabel(void)
1452{
1453  PRINTF(5)("deleting the OptionLabel: %s\n", this->title);
1454  if (this->cValue)
1455    delete []this->cValue;
1456}
1457
1458/**
1459   \brief Updates the value of an OptionLabel
1460   \param newValue The new Name that should be displayed.
1461*/
1462void OptionLabel::setValue(const char* newValue)
1463{
1464  if (this->cValue)
1465    delete []this->cValue;
1466  this->cValue = new char [strlen(newValue)+1];
1467  strcpy(this->cValue, newValue);
1468#ifdef HAVE_GTK2
1469  gtk_label_set_text(GTK_LABEL(this->widget), this->cValue);
1470#endif /* HAVE_GTK2 */
1471}
1472
1473/**
1474   \brief Redraws an OptionLabel(not implemented yet, but it works).
1475*/
1476void OptionLabel::redraw(void)
1477{
1478#ifdef HAVE_GTK2
1479  gtk_label_set_text(GTK_LABEL(widget), title);
1480#endif /* HAVE_GTK2 */
1481}
1482
1483/**
1484   \brief Changed the Option, call this Function
1485*/
1486void OptionLabel::changeOption(void)
1487{
1488#ifdef HAVE_GTK2
1489  this->cValue =(char*)gtk_label_get_text(GTK_LABEL(this->widget));
1490#else /* HAVE_GTK2 */
1491  PRINT(0)("\nPlease give me a new input for %s: ", this->title);
1492  char tmpChar[100];
1493  scanf("%s",tmpChar);
1494  this->setValue(tmpChar);
1495#endif /* HAVE_GTK2 */
1496  PRINT(4)("%s set to: %s\n", this->title,  this->cValue);
1497}
1498
1499
1500/**
1501   \brief creates the Optionlabel save-string
1502   \returns the String to save.
1503*/
1504char* OptionLabel::save(void)
1505{
1506  return cValue;
1507}
1508
1509/**
1510   \brief loads an Option from of its loadString
1511   \param loadString the string from which to load the data from
1512*/
1513void OptionLabel::load(char* loadString)
1514{
1515  PRINTF(4)("Loading %s: setting to %s\n", this->title, loadString); 
1516  this->setValue(loadString);
1517}
1518
1519///////////
1520/* LABEL */
1521///////////
1522/**
1523   \brief Creates a new Label with a Text.
1524   \param text The text to be displayed.
1525*/
1526Label:: Label(const char* text)
1527{
1528  this->isOption = 0;
1529 
1530#ifdef HAVE_GTK2
1531  this->widget = gtk_label_new("");
1532  gtk_label_set_line_wrap(GTK_LABEL(this->widget), TRUE);
1533#endif /* HAVE_GTK2 */
1534 
1535  if (text)
1536    this->setTitle(text);
1537}
1538
1539/**
1540   \brief destructs a Label.
1541*/
1542Label::~Label(void)
1543{
1544  PRINTF(5)("deleting the Label: %s\n", this->title);
1545}
1546
1547/**
1548   \brief Sets a new Text to a Label.
1549   \param text The text to be inserted into the Label.
1550*/
1551void Label::setTitle(const char* text)
1552{
1553  if (this->title)
1554    delete []this->title;
1555  this->title = new char[strlen(text)+1];
1556  strcpy(this->title, text);
1557#ifdef HAVE_GTK2
1558  gtk_label_set_text(GTK_LABEL(this->widget), this->title);
1559#endif /* HAVE_GTK2 */
1560}
1561
1562/**
1563   \brief ereases the Text of a Label
1564*/
1565void Label::ereaseText(void)
1566{
1567  this->setTitle("");
1568}
1569
1570/**
1571    \brief appends some Text to a Label
1572    \param textToAppend The text that will be appended to this Label
1573*/
1574void Label::appendText(char* textToAppend)
1575{
1576  if (this->title)
1577    {
1578      char* tmpTitle = new char[strlen(this->title)+strlen(textToAppend)+1];
1579      strcpy(tmpTitle, title); 
1580      strcat(tmpTitle, textToAppend);
1581      delete []this->title;
1582      this->title = tmpTitle;
1583    }
1584  else
1585    this->title = new char[strlen(textToAppend)];
1586 
1587#ifdef HAVE_GTK2
1588  gtk_label_set_text(GTK_LABEL(this->widget), title);
1589#endif /* HAVE_GTK2 */
1590}
1591
1592/**
1593    \brief Appends some integer to the Label
1594    \param intToAppend The Int that will be added.
1595   
1596    it does this by just converting the int into a char* and send it to appendText
1597*/
1598void Label::appendInt(int intToAppend)
1599{
1600  char append [32];
1601  sprintf(append, "%d", intToAppend);
1602  this->appendText(append);
1603}
1604
1605
1606/**
1607   \brief get the Text of a Label
1608   \return The Text the Label holds.
1609*/
1610const char* Label::getText(void)
1611{
1612  return this->title;
1613}
1614
1615//////////////////
1616/* PROGRESS-BAR */
1617//////////////////
1618/**
1619   \brief Creates a new ProgressBar.
1620   \param label The name you want to get the ProgressBar.
1621*/
1622ProgressBar::ProgressBar(const char* label)
1623{
1624  this->isOption = 0;
1625  this->progress = 0.0;
1626  this->totalSize = 0.0;
1627
1628#ifdef HAVE_GTK2
1629  this->adjustment =(GtkAdjustment*)gtk_adjustment_new(0, 0, 100, 0, 0, 0);
1630  this->widget = gtk_progress_bar_new_with_adjustment(this->adjustment);
1631#endif /* HAVE_GTK2 */
1632
1633  if (label)
1634    this->setTitle(label);
1635}
1636
1637/**
1638   \brief destructs a ProgressBar
1639*/
1640ProgressBar::~ProgressBar(void)
1641{
1642  PRINTF(5)("deleting the ProgressBar: %s\n", this->title);
1643}
1644
1645/**
1646   \brief Sets the Total size of the Bar.(ex. The maximum one can download)
1647*/
1648void ProgressBar::setTotalSize(double totalSize)
1649{
1650  this->totalSize = totalSize;
1651}
1652
1653/**
1654   \brief Sets the progress maximum is this->totalSize
1655*/
1656void ProgressBar::setProgress(double progress)
1657{
1658  this->progress = progress;
1659
1660  if (this->progress > this->totalSize)
1661    this->progress = this->totalSize;
1662
1663#ifdef HAVE_GTK2
1664  gtk_progress_set_value(GTK_PROGRESS(widget), this->progress*100.0/this->totalSize);
1665  PRINTF(4)("Progress: %f%%\n", this->progress*100.0/this->totalSize);
1666#else /* HVE_GTK2 */
1667  PRINT(0)("Progress: %f%%\n", this->progress*100.0/this->totalSize);
1668#endif /* HAVE_GTK2 */
1669}
1670
1671/**
1672    \brief returns the Progress Status
1673*/
1674double ProgressBar::getProgress(void)
1675{
1676  return this->progress;
1677}
1678
1679///////////
1680/* IMAGE */
1681///////////
1682/**
1683   \brief Creates a new Image
1684   \param imageName the location of the Image on the Hard Disc
1685*/
1686Image::Image(const char* imageName)
1687{
1688  this->init(imageName);
1689
1690#ifdef HAVE_GTK2
1691  widget = gtk_image_new_from_file(imageName);
1692#endif /* HAVE_GTK2 */
1693}
1694
1695/**
1696   \brief Creates a new Image
1697   \param imageData data to the PixBuff
1698*/
1699Image::Image(char** imageData)
1700{
1701  this->init("pixBuffImage");
1702
1703#ifdef HAVE_GTK2
1704  widget = gtk_image_new_from_pixbuf(gdk_pixbuf_new_from_xpm_data((const char**)imageData));
1705#endif /* HAVE_GTK2 */
1706}
1707
1708
1709/**
1710   \brief destructs an Image.
1711*/
1712Image::~Image(void)
1713{
1714  PRINTF(5)("deleting the Image: %s\n", this->title);
1715}
1716
1717/**
1718    \brief Initializes a new Image
1719    \param name the name to set to the Image
1720*/
1721void Image::init(const char* name)
1722{
1723  isOption = 0;
1724
1725  if (this->title)
1726    delete []this->title;
1727  this->title = new char[strlen(name)+1];
1728  strcpy(this->title, name);
1729}
Note: See TracBrowser for help on using the repository browser.