Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 3162 was 3161, checked in by bensch, 20 years ago

orxonox/trunk/gui: OptionLabel now has a member cValue for saving its state beside its name

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