Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/movie_player/src/lib/gui/gui/gui_gtk.cc @ 4217

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

orxonox/branches/movie_player: merged the trunk back into the movie_player
merged with command:
svn merge -r 4014:HEAD ../trunk/ movie_player/
no conflicts

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