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