Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/src/lib/gui/gui/orxonox_gui_gtk.cc @ 3627

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

orxonox/trunk: gui: typo

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