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