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