Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/trunk/gui/orxonox_gui_gtk.cc @ 3164

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

orxonox/trunk/gui: moved some stuff to gui_gtk

File size: 22.0 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 <iostream>
28
29#include "orxonox_gui_gtk.h"
30
31
32using namespace std;
33
34// temporarily.
35#include "orxonox_gui_flags.h"
36#include "orxonox_gui_exec.h"
37extern Window* orxonoxGUI;
38extern OrxonoxGuiFlags* flags;
39extern OrxonoxGuiExec* exec;
40
41bool initGTK(int argc, char *argv[])
42{
43  gtk_init (&argc, &argv);
44  gtk_rc_parse( "rc" );
45}
46bool mainloopGTK(void)
47{
48  gtk_main();
49}
50/* WIDGET */
51
52/**
53   \brief deletes any given Widget
54   This is still pretty crappy.
55*/
56Widget::~Widget()
57{
58  //  cout << "hiding: " <<this->label <<"\n";
59  this->hide();
60  //  cout << "check if Packer: "<<this->label <<"\n";
61  if (this->isOption < 0)
62    {
63      //  cout << "get Down "<<this->label <<"\n";
64      static_cast<Packer*>(this)->down->~Widget();
65    }
66  //  cout << "next != NULL?: " <<this->label <<"\n";
67  if (this->next != NULL)
68    this->next->~Widget();
69  cout << "delete Widget: " <<this->label <<"\n";
70  //  delete widget;
71}
72
73/**
74   \brief Initializes a widget.
75   Initializes the next Pointer and the other Widget-specific Defaults.
76*/
77void Widget::init()
78{
79  next = NULL;
80  label = NULL;
81  return;
82}
83
84/**
85   \brief makes the widget visible.
86*/
87void Widget::show()
88{
89  gtk_widget_show (this->widget);
90}
91
92/**
93   \brief hides the widget.
94*/
95void Widget::hide()
96{
97  gtk_widget_hide (this->widget);
98}
99
100/**
101   \brief Sets the resolution of a specific widget to the given size.
102   \param width the width of the widget to set.
103   \param height the height of the widget to set.
104*/
105void Widget::setSize(int width, int height)
106{
107  gtk_widget_set_usize (this->widget, width, height);
108}
109
110/**
111    \brief Connect any signal to any given Sub-widget
112*/
113gulong Widget::connectSignal (char* event, gint (*signal)(GtkWidget*, GdkEvent*, void *))
114{
115  return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), NULL);
116}
117
118/**
119   \brief Connect a signal with additionally passing the whole Object
120*/
121gulong Widget::connectSignal (char* event, gint (*signal)( GtkWidget*, Widget *))
122{
123  return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), this);
124}
125
126/**
127   \brief Connect a signal with additionally passing a whole external Object
128*/
129gulong Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEvent*, void *))
130{
131  return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj);
132}
133
134/**
135   \brief Connect a signal with additionally passing a whole external Object
136*/
137gulong Widget::connectSignal (char* event, void* extObj, gint (*signal)(GtkWidget*, GdkEventKey*, void *))
138{
139  return g_signal_connect (G_OBJECT (this->widget), event, G_CALLBACK (signal), extObj);
140}
141
142void Widget::disconnectSignal (gulong signalID)
143{
144  g_signal_handler_disconnect (G_OBJECT (this->widget), signalID);
145}
146
147/**
148   \brief Moves through all the Widgets downwards from this and executes the function on them.
149   \param function must be of type void and takes a Widget* as an Input.
150*/
151void Widget::walkThrough (void (*function)(Widget*))
152{
153  function(this);
154  if (this->isOption < 0)
155    {
156      static_cast<Packer*>(this)->down->walkThrough (function);
157    } 
158
159  if (this->next != NULL)
160    this->next->walkThrough(function);
161}
162
163/**
164    \brief This is for listing the option of "widget"
165    \param widget specifies the widget that should be listed
166*/
167void Widget::listOptions (Widget* widget)
168{
169  if (widget->isOption >= 1)
170    cout << static_cast<Option*>(widget)->label <<" is : " << static_cast<Option*>(widget)->value <<endl;
171}
172
173/**
174    \brief This is for setting the option of "widget"
175    \param widget specifies the widget that should be set.
176*/
177void Widget::setOptions (Widget* widget)
178{
179  if (widget->isOption >= 1)
180    static_cast<Option*>(widget)->redraw();// <<" is : " << static_cast<Option*>(this)->value <<endl;
181}
182
183gint Widget::doNothingSignal (GtkWidget *widget, GdkEvent* event, void* nothing)
184{
185}
186
187//void deleteWidget(Widget* lastWidget)
188
189
190/* PACKERS */
191
192/**
193   \brief Initializes a Packer.
194   Sets the down-pinter to NULL and other PackerSpecific-values to their defaults.
195*/
196void Packer::init (void)
197{
198  down = NULL;
199  groupName = NULL;
200
201
202  static_cast<Widget*>(this)->init();
203  return;
204}
205
206/**
207   \brief Sets the group name under which all the lower widgets of this will be saved.
208   \param name The name of the group.
209*/
210void Packer::setGroupName (char* name)
211{
212  if (groupName)
213    delete groupName;
214  groupName = new char [strlen(name)+1];
215  strcpy(groupName, name);
216}
217
218/**
219   \brief Retrieves the group name under which all the lower widgets of this will be saved.
220   \returns name The name of the group.
221*/
222char* Packer::getGroupName (void)
223{
224  return groupName;
225}
226
227/* CONTAINERS */
228
229/**
230   \brief Initializes a Container.
231   sets the Container-Specific defaults.
232*/
233void Container::init (void)
234{
235  isOption = -1;
236
237  static_cast<Packer*>(this)->init();
238
239  return;
240}
241
242/**
243   \briefFills a Container with lowerWidget.
244   It does this by filling up the down pointer only if down points to NULL.
245   \param lowerWidget the Widget that should be filled into the Container.
246*/
247void Container::fill (Widget *lowerWidget)
248{
249  if (this->down == NULL)
250    {
251      gtk_container_add (GTK_CONTAINER (this->widget), lowerWidget->widget);
252      this->down = lowerWidget;
253    }
254  else
255    cout << "!!error!! You try to put more than one Widget into a Container. \nNot including this item.\nThis is only possible with Boxes.\n"<<endl;
256}
257
258// gtk_container_set_border_width (GTK_CONTAINER (widget), 5);
259
260/* WINDOW */
261
262Window* Window::mainWindow = NULL;
263
264void Window::addWindow(Window* windowToAdd)
265{
266  if (!mainWindow)
267    {
268      mainWindow = windowToAdd;
269      return;
270    }
271
272  Widget* tmpWindow = mainWindow;
273  while (tmpWindow->next)
274    tmpWindow = tmpWindow->next;
275  tmpWindow->next = windowToAdd;
276 
277  return;
278}
279     
280
281
282/**
283   \brief Creating a new Window without a Name
284*/
285Window::Window (void)
286{
287  this->init();
288}
289
290/**
291   \brief Creating a Window with a name
292   \param windowName the name the window should get.
293*/
294Window::Window (char* windowName)
295{
296  this->init();
297  this->setTitle (windowName);
298}
299
300/**
301   \brief initializes a new Window
302*/
303void Window::init()
304{
305  if (!mainWindow)
306    mainWindow = this;
307 
308  isOpen = false;
309
310  static_cast<Container*>(this)->init();
311
312  widget = gtk_window_new (GTK_WINDOW_TOPLEVEL);
313  gtk_window_set_policy (GTK_WINDOW(widget), TRUE, TRUE, TRUE);
314#if !defined(__WIN32__)
315  //  gtk_window_set_decorated (GTK_WINDOW (widget), FALSE);
316#endif
317  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
318
319}
320
321/**
322   \brief Shows all Widgets that are included within this->widget.
323*/
324void Window::showall ()
325{
326  if (!isOpen)
327    {
328      printf ("showall\n");
329      gtk_widget_show_all  (widget);
330      isOpen = true;
331    }
332  else
333    {
334      printf ("showone\n");
335      gtk_widget_show (widget);
336    }
337}
338
339/**
340   \brief Set The Window-title to title
341   \param title title the Window should get.
342*/
343void Window::setTitle (char* title)
344{
345  if (label)
346    delete label;
347  label = new char[strlen(title)+1];
348  strcpy(label, title);
349  gtk_window_set_title (GTK_WINDOW (widget), title);
350}
351
352/**
353   \brief opens up a Window and fixes the Focus to it
354*/
355void Window::open()
356{
357  if (this != mainWindow)
358    {
359      isOpen = true;
360      gtk_widget_show_all(widget);
361      gtk_grab_add(widget);
362    }
363}
364
365/**
366   \brief closes up a Window and removes the Focus from it
367*/
368void Window::close()
369{
370  if (this != mainWindow)
371    {
372      isOpen = false;
373      gtk_grab_remove(widget);
374      gtk_widget_hide (widget);
375    }
376}
377
378/**
379   \brief opens up a window (not topmost Window).
380   this is the Signal that does it. !!SIGNALS ARE STATIC!!
381   \param widget the widget that did it!
382   \param event the event that did it!
383   \param window the Window that should be opened
384*/
385gint Window::windowOpen (GtkWidget *widget, GdkEvent* event, void* window)
386{
387  static_cast<Window*>(window)->open();
388}
389
390/**
391   \brief closes a window (not topmost Window).
392   this is the Signal that does it. !!SIGNALS ARE STATIC!!
393   \param widget the widget that did it!
394   \param event the event that did it!
395   \param window the Window that should be closed
396*/
397gint Window::windowClose (GtkWidget *widget, GdkEvent* event, void* window)
398{
399  static_cast<Window*>(window)->close();
400}
401
402/**
403 * Quits the orxonox_GUI.
404 * This can be called as a Signal and is therefor static
405 \param widget The widget that called this function
406 \param event the event that happened to execute this function
407 \param data some data passed with the Signal
408 */
409gint Window::orxonox_gui_quit (GtkWidget *widget, GdkEvent *event, gpointer data)
410{
411  if (exec->shouldsave())
412    exec->writeToFile (Window::mainWindow);
413
414  gtk_main_quit();
415  return FALSE;
416}
417
418
419/* FRAME */
420
421/**
422    \brief Creates a new Frame without a name
423*/
424Frame::Frame (void)
425{
426  this->init();
427}
428
429/**
430   \brief Creates a new Frame with name title
431*/
432Frame::Frame (char* title)
433{
434  this->init();
435  this->setTitle(title);
436}
437
438/**
439    \brief Initializes a new Frame with default settings
440*/
441void Frame::init()
442{
443  static_cast<Container*>(this)->init();
444 
445  widget = gtk_frame_new ("");
446  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
447}
448
449/**
450   \brief Sets the Frames name to title
451   \param title The title the Frame should get.
452*/
453void Frame::setTitle (char* title)
454{
455  if (label)
456    delete label;
457  label = new char[strlen(title)+1];
458  strcpy(label, title);
459  gtk_frame_set_label (GTK_FRAME (widget), title);
460}
461
462// EVENTBOX //
463
464/**
465   \brief Creates a new EventBox with default settings.
466*/
467EventBox::EventBox ()
468{
469  this->init();
470}
471/**
472   \brief Creates a new EventBox with name title
473   \param title title the Eventbox should get (only data-structure-internal)
474*/
475EventBox::EventBox (char* title)
476{
477  this->init();
478  this->setTitle(title);
479}
480
481/**
482   \brief Initializes a new EventBox
483*/
484void EventBox::init(void)
485{
486  isOption = -1;
487
488  static_cast<Container*>(this)->init();
489
490  widget = gtk_event_box_new ();
491  gtk_container_set_border_width (GTK_CONTAINER (widget), 3);
492 
493}
494
495/**
496   \brief Sets the Title of the EventBox (not implemented)
497   \param title Name the EventBox should get (only datastructure-internal).
498*/
499void EventBox::setTitle (char* title)
500{
501  if (label)
502    delete label;
503  label = new char[strlen(title)+1];
504  strcpy(label, title);
505}
506
507/* BOX */
508
509/**
510   \brief Creates a new horizontal Box
511*/
512Box::Box (void)
513{
514  this->init('h');
515}
516
517/**
518   \brief Creates a new Box of type boxtype
519   \param boxtype if 'v' the Box will be vertically, if 'h' the Box will be horizontally
520*/
521Box::Box (char boxtype)
522{
523  this->init(boxtype);
524}
525
526/**
527   \brief Initializes a new Box with type boxtype
528   \param boxtype see Box(char boxtype)
529*/
530void Box::init(char boxtype)
531{
532  isOption = -2;
533
534  static_cast<Packer*>(this)->init();
535  if (boxtype == 'v')
536    {
537      widget = gtk_vbox_new (FALSE, 0);
538    }
539  else
540    {
541      widget = gtk_hbox_new (FALSE, 0);
542    }
543}
544
545/**
546    \brief Fills a box with a given Widget.
547    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
548    \param lowerWidget the next Widget that should be appendet to this Box
549*/
550void Box::fill (Widget *lowerWidget)
551{
552  gtk_box_pack_start (GTK_BOX (this->widget), lowerWidget->widget, TRUE, TRUE, 0);
553  if (this->down == NULL)
554    this->down = lowerWidget;
555  else
556    {
557      Widget* tmp;
558      tmp = this->down;
559      while (tmp->next != NULL)
560        {
561          tmp = tmp->next;
562        }
563      tmp->next = lowerWidget;
564    }
565}
566
567/* IMAGE */
568
569/**
570   \brief Creates a new Image
571   \param imagename the location of the Image on the Hard Disc
572*/
573Image::Image (char* imagename)
574{
575  if (label)
576    delete label;
577  label = new char[strlen(imagename)+1];
578  strcpy(label, imagename);
579
580  this->init();
581  widget = gtk_image_new_from_file (imagename);
582}
583
584/**
585    \brief Initializes a new Image
586*/
587void Image::init()
588{
589  isOption = 0;
590
591  static_cast<Widget*>(this)->init();
592}
593
594
595/* OPTION */
596
597/**
598   \brief Initializes a new Option.
599   sets all Option-Specific-Values to their defaults.
600*/
601void Option::init()
602{
603  value = 0;
604  flagName = NULL;
605  flagNameShort = NULL;
606  saveable = false;
607  defaultValue = 0;
608
609  static_cast<Widget*>(this)->init();
610
611  return;
612}
613
614/**
615   \brief This sets The FlagName of an Option and defines its default Values
616   !! Options will be saved if flagname is different from "" !!
617   \param flagname the Name that will be displayed in the output
618   \param defaultvalue the default Value for this Option (see definition of defaultvalue
619*/
620void Option::setFlagName (char* flagname, int defaultvalue)
621{
622  if (flagName)
623    delete flagName;
624  flagName = new char [strlen(flagname)+1];
625  strcpy(flagName, flagname);
626  defaultValue = defaultvalue;
627  cout << "Set Flagname of " << label << " to " << flagname << endl;
628}
629
630/**
631    \brief see Option::setFlagName (char* flagname, int defaultvalue)
632    \param flagname the Name that will be displayed in the output
633    \param defaultvalue the default Value for this Option (see definition of defaultvalue
634    \param flagnameshort a short flagname to be displayed in the output
635*/
636void Option::setFlagName (char* flagname, char* flagnameshort,  int defaultvalue)
637{
638  if (flagName)
639    delete flagName;
640  flagName = new char [strlen(flagname)+1];
641  strcpy(flagName, flagname);
642
643  if (flagNameShort)
644    delete flagNameShort;
645  flagNameShort = new char [strlen(flagnameshort)+1];
646  strcpy(flagNameShort, flagnameshort);
647  defaultValue = defaultvalue;
648  cout << "Set Flagname of " << label << " to " << flagname << endl;
649}
650
651
652/* BUTTON */
653
654/**
655   \brief Creates a new Button with a buttonname
656   \param buttonname sets the Name of the Button
657*/
658Button::Button(char* buttonname)
659{
660  this->init();
661  this->setTitle(buttonname);
662}
663
664/**
665   \brief Initializes a new Button
666*/
667void Button::init(void)
668{
669  isOption = 0;
670
671  static_cast<Option*>(this)->init();
672
673  widget = gtk_button_new_with_label ("");
674}
675
676/**
677   \brief Sets a new name to the Button
678   \param title The name the Button should get
679*/
680void Button::setTitle (char *title)
681{
682  if (label)
683    delete label;
684  label = new char[strlen(title)+1];
685  strcpy(label, title);
686  gtk_button_set_label (GTK_BUTTON(widget), title);
687}
688
689/**
690   \brief redraws the Button
691   not implemented yet
692*/
693void Button::redraw ()
694{
695}
696
697/* CHECKBUTTON */
698
699/**
700   \brief Creates a new CheckButton with an ame
701   \param buttonname The name the CheckButton should display.
702*/
703CheckButton::CheckButton (char* buttonname)
704{
705  this->init();
706  this->setTitle(buttonname);
707
708  this->connectSignal ("clicked", this->OptionChange);
709}
710
711/**
712   \brief Initialize a new CheckButton with default settings
713*/
714void CheckButton::init(void)
715{
716  isOption = 1;
717
718  static_cast<Option*>(this)->init();
719
720  widget = gtk_check_button_new_with_label ("");
721}
722
723/**
724   \brief Sets a new Title to a CheckButton
725   \param title The new Name the CheckButton should display.
726*/
727void CheckButton::setTitle(char* title)
728{
729  if (label)
730    delete label;
731  label = new char[strlen(title)+1];
732  strcpy(label, title);
733  gtk_button_set_label(GTK_BUTTON(widget), title);
734}
735
736bool CheckButton::isActive()
737{
738  return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
739}
740
741/**
742    \brief Signal OptionChange writes the Value from the CheckButton to its Object-Database.
743    \param widget The widget(CheckButton) that has a changed Value
744    \param checkbutton the CheckButton-Object that should receive the change.
745*/
746gint CheckButton::OptionChange (GtkWidget *widget, Widget* checkbutton)
747{
748  static_cast<CheckButton*>(checkbutton)->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ((CheckButton*)checkbutton->widget));
749  flags->setTextFromFlags(orxonoxGUI);   ////// must be different!!!
750  cout << static_cast<CheckButton*>(checkbutton)->label << " set to: " << static_cast<CheckButton*>(checkbutton)->value << endl;
751}
752
753/**
754   \brief Redraws the CheckButton (if option has changed).
755   Example: if new settings are loaded the Button must be redrawn for the GUI to display that Change
756*/
757void CheckButton::redraw ()
758{
759  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
760}
761
762/* SLIDER */
763
764/**
765   \brief Creates a new Slider
766   \param slidername The data-structure-name of the slider.
767   \param start The minimal Value of the slider.
768   \param end The maximal Value of the slider.
769*/
770Slider::Slider (char* slidername, int start, int end)
771{
772  this->init(start, end);
773  this->setValue(start);
774  this->setTitle(slidername);
775  this->connectSignal ("value_changed", this->OptionChange);
776}
777
778/**
779   \brief Initializes a Slider with start and end Values
780   params: see Slider::Slider (char* slidername, int start, int end)
781*/
782void Slider::init(int start, int end)
783{
784  isOption = 2;
785
786  static_cast<Option*>(this)->init();
787
788  widget = gtk_hscale_new_with_range (start, end, 5);
789}
790
791/**
792   \brief Sets a new Title to the Slider
793   \param title The new Name of the slider
794*/
795void Slider::setTitle(char* title)
796{
797  if (label)
798    delete label;
799  label = new char[strlen(title)+1];
800  strcpy(label, title);
801}
802
803/**
804   \brief Setting a new value to the Slider.
805   Maybe you also require a Slider::redraw() for this to display
806*/
807void Slider::setValue(int value)
808{
809  this->value = value;
810}
811
812/**
813    \brief Signal OptionChange writes the Value from the Slider to its Object-Database.
814    \param widget The widget(Slider) that has a changed Value
815    \param slider the Slider-Object that should receive the change.
816*/
817gint Slider::OptionChange (GtkWidget *widget, Widget* slider)
818{
819  static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget));
820  flags->setTextFromFlags(orxonoxGUI);  //// must be different !!!
821  cout << static_cast<Slider*>(slider)->label << " set to: "<< static_cast<Slider*>(slider)->value << endl;
822}
823
824/**
825   \brief Redraws the widget
826   Example: see void CheckButton::redraw ()
827*/
828void Slider::redraw ()
829{
830  gtk_range_set_value (GTK_RANGE (widget), value);
831}
832
833/* MENU */
834
835/**
836    \brief Creates a Menu-Item-list out of multiple input.
837    !! Consider, that the last input argument has to be "lastItem" for this to work!!
838    \param menuname The Database-Name of this Menu
839    \param ... items to be added to this Menu. !! Consider, that the last input argument has to be "lastItem" for this to work!!
840*/
841Menu::Menu (char* menuname, ...)
842{
843  this->init();
844  this->setTitle(menuname);
845   
846  char *itemName;
847 
848  va_start (itemlist, menuname);
849  while (strcmp (itemName = va_arg (itemlist, char*), "lastItem"))
850    {
851      this->addItem(itemName);
852    }
853  va_end(itemlist);
854
855  gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu);
856  this->connectSignal ("changed", this->OptionChange);
857}
858
859/**
860   \brief Initializes a new Menu with no items
861*/
862void Menu::init(void)
863{
864  isOption = 2;
865
866  static_cast<Option*>(this)->init();
867
868  widget = gtk_option_menu_new ();
869  menu = gtk_menu_new ();
870
871}
872
873/**
874 * Sets the Database-Name of this Menu
875 \param title Database-Name to be set.
876*/
877void Menu::setTitle(char* title)
878{
879  if (label)
880    delete label;
881  label = new char[strlen(title)+1];
882  strcpy(label, title);
883}
884
885/**
886   \brief appends a new Item to the Menu-List.
887   \param itemName the itemName to be appendet.
888*/
889void Menu::addItem (char* itemName)
890{
891  item = gtk_menu_item_new_with_label (itemName);
892  gtk_menu_shell_append(GTK_MENU_SHELL (menu), item);
893}
894
895/**
896    \brief Signal OptionChange writes the Value from the Menu to its Object-Database.
897    \param widget The widget(Menu) that has a changed Value
898    \param menu the Menu-Object that should receive the change.
899*/
900gint Menu::OptionChange (GtkWidget *widget, Widget* menu)
901{
902  static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget));
903  flags->setTextFromFlags(orxonoxGUI); //// must be different !!!
904  cout << static_cast<Menu*>(menu)->label << " changed to : " << static_cast<Menu*>(menu)->value << endl;
905}
906
907/**
908   \brief Redraws the widget
909   Example: see void CheckButton::redraw ()
910*/
911void Menu::redraw ()
912{
913  gtk_option_menu_set_history (GTK_OPTION_MENU (widget), value);
914}
915
916OptionLabel::OptionLabel(char* label, char* value)
917{
918  init();
919  setTitle(label);
920  setValue(value);
921}
922
923void OptionLabel::init(void)
924{
925  static_cast<Option*>(this)->init();
926  isOption = 5;
927  cValue = NULL;
928
929  widget = gtk_label_new ("");
930}
931void OptionLabel::setValue(char* newValue)
932{
933  if (cValue)
934    delete cValue;
935  cValue = new char [strlen(newValue)+1];
936  strcpy(cValue, newValue);
937  gtk_label_set_text (GTK_LABEL (widget), cValue);
938}
939
940void OptionLabel::setTitle(char* title)
941{
942  if (label)
943    delete label;
944  label = new char [strlen(title)+1];
945  strcpy(label, title);
946  gtk_label_set_text (GTK_LABEL (widget), title);
947}
948
949void OptionLabel::redraw(void)
950{
951 
952}
953
954/**
955   \brief Creates a new default Label with no Text.
956   You migth consider adding Label::setTitle with this.
957*/
958Label::Label ()
959{
960  this->init();
961}
962
963/**
964   \brief Creates a new Label with a Text.
965   \param text The text to be displayed.
966*/
967Label:: Label (char* text)
968{
969  this->init();
970  this->setText(text);
971}
972
973/**
974   \brief initializes a new Label
975*/
976void Label::init(void)
977{
978  isOption = 0;
979
980  static_cast<Widget*>(this)->init();
981
982  widget = gtk_label_new ("");
983  gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE);
984}
985
986/**
987   \brief Sets a new Text to a Label.
988   \param text The text to be inserted into the Label.
989*/
990void Label::setText (char* text)
991{
992  if (label)
993    delete label;
994  label = new char[strlen(text)+1];
995  strcpy(label, text);
996  gtk_label_set_text (GTK_LABEL (this->widget), text);
997}
998
999/**
1000   \brief get the Text of a Label
1001   \return The Text the Label holds.
1002*/
1003char* Label::getText ()
1004{
1005  return ((char*)gtk_label_get_text (GTK_LABEL (this->widget)));
1006}
Note: See TracBrowser for help on using the repository browser.