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