Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk/gui: safer (char* initialization), nicer _n →N

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