Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trun/gui: forgot one

File size: 21.5 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(flagNameShort, 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  if (label)
671    delete label;
672  label = new char[strlen(title)+1];
673  strcpy(label, title);
674  gtk_button_set_label (GTK_BUTTON(widget), title);
675}
676
677/**
678   \brief redraws the Button
679   not implemented yet
680*/
681void Button::redraw ()
682{
683}
684
685/* CHECKBUTTON */
686
687/**
688   \brief Creates a new CheckButton with an ame
689   \param buttonname The name the CheckButton should display.
690*/
691CheckButton::CheckButton (char* buttonname)
692{
693  this->init();
694  this->setTitle(buttonname);
695
696  this->connectSignal ("clicked", this->OptionChange);
697}
698
699/**
700   \brief Initialize a new CheckButton with default settings
701*/
702void CheckButton::init(void)
703{
704  isOption = 1;
705
706  static_cast<Option*>(this)->init();
707
708  widget = gtk_check_button_new_with_label ("");
709}
710
711/**
712   \brief Sets a new Title to a CheckButton
713   \param title The new Name the CheckButton should display.
714*/
715void CheckButton::setTitle(char* title)
716{
717  if (label)
718    delete label;
719  label = new char[strlen(title)+1];
720  strcpy(label, title);
721  gtk_button_set_label(GTK_BUTTON(widget), title);
722}
723
724bool CheckButton::isActive()
725{
726  return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
727}
728
729/**
730    \brief Signal OptionChange writes the Value from the CheckButton to its Object-Database.
731    \param widget The widget(CheckButton) that has a changed Value
732    \param checkbutton the CheckButton-Object that should receive the change.
733*/
734gint CheckButton::OptionChange (GtkWidget *widget, Widget* checkbutton)
735{
736  static_cast<CheckButton*>(checkbutton)->value = (int)gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON ((CheckButton*)checkbutton->widget));
737  flags->setTextFromFlags(orxonoxGUI);   ////// must be different!!!
738  cout << static_cast<CheckButton*>(checkbutton)->label << " set to: " << static_cast<CheckButton*>(checkbutton)->value << endl;
739}
740
741/**
742   \brief Redraws the CheckButton (if option has changed).
743   Example: if new settings are loaded the Button must be redrawn for the GUI to display that Change
744*/
745void CheckButton::redraw ()
746{
747  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value);
748}
749
750/* SLIDER */
751
752/**
753   \brief Creates a new Slider
754   \param slidername The data-structure-name of the slider.
755   \param start The minimal Value of the slider.
756   \param end The maximal Value of the slider.
757*/
758Slider::Slider (char* slidername, int start, int end)
759{
760  this->init(start, end);
761  this->setValue(start);
762  this->setTitle(slidername);
763  this->connectSignal ("value_changed", this->OptionChange);
764}
765
766/**
767   \brief Initializes a Slider with start and end Values
768   params: see Slider::Slider (char* slidername, int start, int end)
769*/
770void Slider::init(int start, int end)
771{
772  isOption = 2;
773
774  static_cast<Option*>(this)->init();
775
776  widget = gtk_hscale_new_with_range (start, end, 5);
777}
778
779/**
780   \brief Sets a new Title to the Slider
781   \param title The new Name of the slider
782*/
783void Slider::setTitle(char* title)
784{
785  if (label)
786    delete label;
787  label = new char[strlen(title)+1];
788  strcpy(label, title);
789}
790
791/**
792   \brief Setting a new value to the Slider.
793   Maybe you also require a Slider::redraw() for this to display
794*/
795void Slider::setValue(int value)
796{
797  this->value = value;
798}
799
800/**
801    \brief Signal OptionChange writes the Value from the Slider to its Object-Database.
802    \param widget The widget(Slider) that has a changed Value
803    \param slider the Slider-Object that should receive the change.
804*/
805gint Slider::OptionChange (GtkWidget *widget, Widget* slider)
806{
807  static_cast<Slider*>(slider)->value = (int)gtk_range_get_value (GTK_RANGE ((Slider*)slider->widget));
808  flags->setTextFromFlags(orxonoxGUI);  //// must be different !!!
809  cout << static_cast<Slider*>(slider)->label << " set to: "<< static_cast<Slider*>(slider)->value << endl;
810}
811
812/**
813   \brief Redraws the widget
814   Example: see void CheckButton::redraw ()
815*/
816void Slider::redraw ()
817{
818  gtk_range_set_value (GTK_RANGE (widget), value);
819}
820
821/* MENU */
822
823/**
824    \brief Creates a Menu-Item-list out of multiple input.
825    !! Consider, that the last input argument has to be "lastItem" for this to work!!
826    \param menuname The Database-Name of this Menu
827    \param ... items to be added to this Menu. !! Consider, that the last input argument has to be "lastItem" for this to work!!
828*/
829Menu::Menu (char* menuname, ...)
830{
831  this->init();
832  this->setTitle(menuname);
833   
834  char *itemName;
835 
836  va_start (itemlist, menuname);
837  while (strcmp (itemName = va_arg (itemlist, char*), "lastItem"))
838    {
839      this->addItem(itemName);
840    }
841  va_end(itemlist);
842
843  gtk_option_menu_set_menu (GTK_OPTION_MENU (widget), menu);
844  this->connectSignal ("changed", this->OptionChange);
845}
846
847/**
848   \brief Initializes a new Menu with no items
849*/
850void Menu::init(void)
851{
852  isOption = 2;
853
854  static_cast<Option*>(this)->init();
855
856  widget = gtk_option_menu_new ();
857  menu = gtk_menu_new ();
858
859}
860
861/**
862 * Sets the Database-Name of this Menu
863 \param title Database-Name to be set.
864*/
865void Menu::setTitle(char* title)
866{
867  if (label)
868    delete label;
869  label = new char[strlen(title)+1];
870  strcpy(label, title);
871}
872
873/**
874   \brief appends a new Item to the Menu-List.
875   \param itemName the itemName to be appendet.
876*/
877void Menu::addItem (char* itemName)
878{
879  item = gtk_menu_item_new_with_label (itemName);
880  gtk_menu_shell_append(GTK_MENU_SHELL (menu), item);
881}
882
883/**
884    \brief Signal OptionChange writes the Value from the Menu to its Object-Database.
885    \param widget The widget(Menu) that has a changed Value
886    \param menu the Menu-Object that should receive the change.
887*/
888gint Menu::OptionChange (GtkWidget *widget, Widget* menu)
889{
890  static_cast<Menu*>(menu)->value = (int)gtk_option_menu_get_history (GTK_OPTION_MENU (menu->widget));
891  flags->setTextFromFlags(orxonoxGUI); //// must be different !!!
892  cout << static_cast<Menu*>(menu)->label << " changed to : " << static_cast<Menu*>(menu)->value << endl;
893}
894
895/**
896   \brief Redraws the widget
897   Example: see void CheckButton::redraw ()
898*/
899void Menu::redraw ()
900{
901  gtk_option_menu_set_history (GTK_OPTION_MENU (widget), value);
902}
903
904OptionLabel::OptionLabel(char* text)
905{
906  init();
907  setTitle(text);
908}
909
910void OptionLabel::init(void)
911{
912  isOption = 4;
913
914  static_cast<Option*>(this)->init();
915
916  widget = gtk_label_new ("");
917}
918
919void OptionLabel::setTitle(char* title)
920{
921  gtk_label_set_text (GTK_LABEL (widget), title);
922}
923
924void OptionLabel::redraw(void)
925{
926 
927}
928
929/**
930   \brief Creates a new default Label with no Text.
931   You migth consider adding Label::setTitle with this.
932*/
933Label::Label ()
934{
935  this->init();
936}
937
938/**
939   \brief Creates a new Label with a Text.
940   \param text The text to be displayed.
941*/
942Label:: Label (char* text)
943{
944  this->init();
945  this->setText(text);
946}
947
948/**
949   \brief initializes a new Label
950*/
951void Label::init(void)
952{
953  isOption = 0;
954
955  static_cast<Widget*>(this)->init();
956
957  widget = gtk_label_new ("");
958  gtk_label_set_line_wrap (GTK_LABEL(widget), TRUE);
959}
960
961/**
962   \brief Sets a new Text to a Label.
963   \param text The text to be inserted into the Label.
964*/
965void Label::setText (char* text)
966{
967  if (label)
968    delete label;
969  label = new char[strlen(text)+1];
970  strcpy(label, text);
971  gtk_label_set_text (GTK_LABEL (this->widget), text);
972}
973
974/**
975   \brief get the Text of a Label
976   \return The Text the Label holds.
977*/
978char* Label::getText ()
979{
980  return ((char*)gtk_label_get_text (GTK_LABEL (this->widget)));
981}
Note: See TracBrowser for help on using the repository browser.