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