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