[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 | |
---|
[4071] | 224 | if (this->optionType < GUI_NOTHING && static_cast<Packer*>(this)->down) |
---|
[3423] | 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); |
---|
[4071] | 245 | if (this->optionType < GUI_NOTHING) |
---|
[3423] | 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); |
---|
[4071] | 263 | if (this->optionType < GUI_NOTHING) |
---|
[3423] | 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 | { |
---|
[4071] | 277 | if (widget->optionType < GUI_NOTHING && static_cast<Packer*>(widget)->groupName) |
---|
[3628] | 278 | PRINT(0)("[%s]\n", static_cast<Packer*>(widget)->groupName); |
---|
[4071] | 279 | if (widget->optionType > GUI_NOTHING) |
---|
[3628] | 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 | { |
---|
[4071] | 291 | if(widget->optionType > GUI_NOTHING) |
---|
[3628] | 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 | |
---|
[4071] | 303 | if (widget->optionType > GUI_NOTHING) |
---|
[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 | /** |
---|
[4132] | 314 | \brief This is for listing the options of "widget" |
---|
| 315 | \param widget specifies the widget that should be listed |
---|
| 316 | \param data A Counter, that always knows how many Options have been found yet. |
---|
| 317 | */ |
---|
| 318 | void Widget::printHelp(Widget* widget) |
---|
| 319 | { |
---|
[4134] | 320 | int helpLen=0; |
---|
[4132] | 321 | |
---|
| 322 | if (widget->optionType > GUI_NOTHING) |
---|
| 323 | { |
---|
| 324 | Option* option = (Option*)widget; |
---|
| 325 | if (option->flagName || option->flagNameShort) |
---|
| 326 | { |
---|
| 327 | PRINT(0)(" "); |
---|
| 328 | if (option->flagNameShort) |
---|
| 329 | { |
---|
| 330 | PRINT(0)("-%s", option->flagNameShort); |
---|
[4134] | 331 | helpLen += strlen(option->flagNameShort)+1; |
---|
[4132] | 332 | } |
---|
| 333 | if (option->flagName) |
---|
| 334 | { |
---|
[4134] | 335 | if (helpLen > 0) |
---|
| 336 | { |
---|
| 337 | PRINT(0)("|"); |
---|
| 338 | helpLen++; |
---|
| 339 | } |
---|
[4132] | 340 | PRINT(0)("--%s:", option->flagName); |
---|
[4134] | 341 | helpLen += strlen(option->flagName)+2; |
---|
[4132] | 342 | } |
---|
[4134] | 343 | while ((helpLen ++) < 29) |
---|
| 344 | PRINT(0)(" "); |
---|
[4132] | 345 | if (option->shortDescription) |
---|
[4134] | 346 | PRINT(0)("%s\n", option->shortDescription); |
---|
[4132] | 347 | else |
---|
| 348 | PRINT(0)("\n"); |
---|
| 349 | } |
---|
| 350 | } |
---|
| 351 | } |
---|
| 352 | |
---|
| 353 | /** |
---|
[3423] | 354 | \brief Finds an Option by a given number(the n'th option found away from this Widget) |
---|
| 355 | \param number The Count of options to wait(by reference) |
---|
| 356 | \param depth The depth of the sarch. if 0 it will not search next pointer |
---|
| 357 | |
---|
| 358 | \todo should return Option* would be much sexier. |
---|
| 359 | */ |
---|
| 360 | Widget* Widget::findOptionByNumber(int* number, unsigned int depth) |
---|
| 361 | { |
---|
[4071] | 362 | if (optionType > GUI_NOTHING) |
---|
[3423] | 363 | { |
---|
| 364 | --*number; |
---|
| 365 | if (*number <= 0) |
---|
| 366 | { |
---|
| 367 | return this; |
---|
| 368 | } |
---|
| 369 | } |
---|
[4071] | 370 | if (this->optionType < GUI_NOTHING && static_cast<Packer*>(this)->down) |
---|
[3423] | 371 | { |
---|
| 372 | Widget* tmp = static_cast<Packer*>(this)->down->findOptionByNumber(number, depth+1); |
---|
| 373 | if (tmp) |
---|
| 374 | return tmp; |
---|
| 375 | } |
---|
| 376 | if (depth>0 && this->next) |
---|
| 377 | return this->next->findOptionByNumber(number, depth); |
---|
| 378 | |
---|
| 379 | return NULL; |
---|
[3144] | 380 | } |
---|
| 381 | |
---|
| 382 | /** |
---|
[3423] | 383 | \brief This is for listing the groups of "widget" |
---|
[3144] | 384 | \param widget specifies the widget that should be listed |
---|
| 385 | */ |
---|
[3423] | 386 | void Widget::listGroups(Widget* widget) |
---|
[3144] | 387 | { |
---|
[4071] | 388 | if (widget->optionType < GUI_NOTHING && static_cast<Packer*>(widget)->groupName) |
---|
[4026] | 389 | PRINT(0)("[%s]\n", static_cast<Packer*>(widget)->groupName); |
---|
[3144] | 390 | } |
---|
| 391 | |
---|
| 392 | /** |
---|
[3423] | 393 | \brief This is for listing the Groups of "widget". It also displays the n'th number found. |
---|
| 394 | \param widget specifies the widget that should be listed |
---|
| 395 | \param data the Counter, that will show the number(this function will raise it by one if a Group is fount. |
---|
| 396 | */ |
---|
| 397 | void Widget::listGroups(Widget* widget, void* data) |
---|
| 398 | { |
---|
[4029] | 399 | int* count = (int*)data; |
---|
[4071] | 400 | if (widget->optionType < GUI_NOTHING && static_cast<Packer*>(widget)->groupName) |
---|
[4029] | 401 | PRINT(0)("%d: [%s]\n", ++*count, static_cast<Packer*>(widget)->groupName); |
---|
[3423] | 402 | } |
---|
| 403 | |
---|
| 404 | /** |
---|
| 405 | \brief Finds a Group by a given number(the n'th Group found away from this Widget) |
---|
| 406 | \param number The Count of options to wait(by reference) |
---|
| 407 | \param depth The depth of the sarch. if 0 it will not search next pointer |
---|
| 408 | */ |
---|
| 409 | Widget* Widget::findGroupByNumber(int* number, unsigned int depth) |
---|
| 410 | { |
---|
[4071] | 411 | if (optionType < GUI_NOTHING && static_cast<Packer*>(this)->groupName) |
---|
[3423] | 412 | { |
---|
| 413 | --*number; |
---|
| 414 | if (*number <= 0) |
---|
| 415 | { |
---|
| 416 | return this; |
---|
| 417 | } |
---|
| 418 | } |
---|
[4071] | 419 | if (this->optionType < GUI_NOTHING && static_cast<Packer*>(this)->down) |
---|
[3423] | 420 | { |
---|
| 421 | Widget* tmp = static_cast<Packer*>(this)->down->findGroupByNumber(number, depth+1); |
---|
| 422 | if (tmp) |
---|
| 423 | return tmp; |
---|
| 424 | } |
---|
| 425 | if (depth>0 && this->next) |
---|
| 426 | return this->next->findGroupByNumber(number, depth); |
---|
| 427 | |
---|
| 428 | return NULL; |
---|
| 429 | } |
---|
[4058] | 430 | |
---|
| 431 | /** |
---|
[3144] | 432 | \brief This is for setting the option of "widget" |
---|
| 433 | \param widget specifies the widget that should be set. |
---|
| 434 | */ |
---|
[3423] | 435 | void Widget::setOptions(Widget* widget) |
---|
[3144] | 436 | { |
---|
[4071] | 437 | if (widget->optionType > GUI_NOTHING) |
---|
[3423] | 438 | static_cast<Option*>(widget)->redraw(); |
---|
[3144] | 439 | } |
---|
| 440 | |
---|
[3423] | 441 | /** |
---|
[4058] | 442 | \brief redraws all the Widgets down from widget |
---|
| 443 | \param widget The topmost Widget |
---|
| 444 | \param data ... |
---|
| 445 | */ |
---|
| 446 | void Widget::redrawOptions(Widget* widget) |
---|
| 447 | { |
---|
[4071] | 448 | if (widget->optionType > GUI_NOTHING) |
---|
[4058] | 449 | static_cast<Option*>(widget)->redraw(); |
---|
| 450 | } |
---|
| 451 | |
---|
| 452 | /** |
---|
[3423] | 453 | \brief Walks through all the Flags given at startuptime. |
---|
| 454 | */ |
---|
| 455 | void Widget::flagCheck(Widget* widget, void* flagName) |
---|
| 456 | { |
---|
[4071] | 457 | if (widget->optionType > GUI_NOTHING) |
---|
[3423] | 458 | { |
---|
| 459 | Option* option =(Option*)widget; |
---|
| 460 | char* name =(char*)flagName; |
---|
| 461 | char* value = NULL; |
---|
| 462 | bool found = false; |
---|
| 463 | // check if long flag matches |
---|
[4046] | 464 | if ((option->flagName && strlen(name) > 2 && |
---|
[4026] | 465 | !strncmp(name+2, option->flagName, strlen(option->flagName)) && |
---|
| 466 | (name[strlen(option->flagName)+2] == '\0' || name[strlen(option->flagName)+2] == '=') )) |
---|
[3423] | 467 | { |
---|
| 468 | found = true; |
---|
| 469 | if (name[strlen(option->flagName)+2] == '=') |
---|
| 470 | { |
---|
| 471 | value = name+strlen(option->flagName)+3; |
---|
| 472 | } |
---|
| 473 | } |
---|
[4026] | 474 | // check if short flag matches |
---|
| 475 | else if (option->flagNameShort && strlen(name)>1 && |
---|
| 476 | !strncmp(name+1, option->flagNameShort, strlen(option->flagNameShort)) && |
---|
| 477 | (name[strlen(option->flagNameShort)+1] == '\0' || name[strlen(option->flagNameShort)+1] == '=')) |
---|
[3423] | 478 | { |
---|
| 479 | found = true; |
---|
| 480 | if (name[strlen(option->flagNameShort)+1] == '=') |
---|
| 481 | { |
---|
| 482 | value = name+strlen(option->flagNameShort)+2; |
---|
| 483 | } |
---|
| 484 | } |
---|
| 485 | |
---|
| 486 | if (found) |
---|
| 487 | { |
---|
[4026] | 488 | PRINT(4)("found matching Flag %s\n", name); |
---|
[3423] | 489 | if (value) |
---|
| 490 | { |
---|
[4026] | 491 | PRINT(4)("with Value %s\n", value); |
---|
[3423] | 492 | option->value = atoi(value); |
---|
| 493 | } |
---|
| 494 | else |
---|
| 495 | { |
---|
| 496 | option->value = !option->defaultValue; |
---|
| 497 | } |
---|
| 498 | option->redraw(); |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | } |
---|
| 502 | } |
---|
| 503 | |
---|
[3165] | 504 | #ifdef HAVE_GTK2 |
---|
[3423] | 505 | /** |
---|
| 506 | \brief Connect any signal to any given Sub-widget |
---|
| 507 | */ |
---|
| 508 | gulong Widget::connectSignal(char* event, gint(*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
| 509 | { |
---|
| 510 | return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), NULL); |
---|
| 511 | } |
---|
[3187] | 512 | |
---|
| 513 | /** |
---|
[3423] | 514 | \brief Connect a signal with additionally passing the whole Object |
---|
| 515 | */ |
---|
| 516 | gulong Widget::connectSignal(char* event, gint(*signal)( GtkWidget*, Widget *)) |
---|
| 517 | { |
---|
| 518 | return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), this); |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | /** |
---|
| 522 | \brief Connect a signal with additionally passing a whole external Object |
---|
| 523 | */ |
---|
| 524 | gulong Widget::connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
| 525 | { |
---|
| 526 | return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), extObj); |
---|
| 527 | } |
---|
| 528 | |
---|
| 529 | /** |
---|
| 530 | \brief Connect a signal with additionally passing a whole external Object |
---|
| 531 | */ |
---|
| 532 | gulong Widget::connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, void *)) |
---|
| 533 | { |
---|
| 534 | return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), extObj); |
---|
| 535 | } |
---|
| 536 | |
---|
| 537 | /** |
---|
| 538 | \brief Connect a signal with additionally passing a whole external Object |
---|
| 539 | */ |
---|
| 540 | gulong Widget::connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, GdkEventKey*, void *)) |
---|
| 541 | { |
---|
| 542 | return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), extObj); |
---|
| 543 | } |
---|
| 544 | |
---|
| 545 | void Widget::disconnectSignal(gulong signalID) |
---|
| 546 | { |
---|
| 547 | g_signal_handler_disconnect(G_OBJECT(this->widget), signalID); |
---|
| 548 | } |
---|
| 549 | |
---|
| 550 | /** |
---|
[3187] | 551 | \brief Signal that does absolutely nothing |
---|
| 552 | \param widget The widget that initiated the Signal |
---|
| 553 | \param event The event-type. |
---|
| 554 | \param nothing nothin. |
---|
| 555 | */ |
---|
[3423] | 556 | gint Widget::doNothingSignal(GtkWidget *widget, GdkEvent* event, void* nothing) |
---|
[3157] | 557 | { |
---|
| 558 | } |
---|
[3165] | 559 | #endif /* HAVE_GTK2 */ |
---|
[3157] | 560 | |
---|
[4046] | 561 | ///////////// |
---|
[3144] | 562 | /* PACKERS */ |
---|
[4046] | 563 | ///////////// |
---|
[3144] | 564 | /** |
---|
[3623] | 565 | \brief Constructs a Packer |
---|
[3144] | 566 | */ |
---|
[3623] | 567 | Packer::Packer(void) |
---|
[3144] | 568 | { |
---|
[3423] | 569 | this->down = NULL; |
---|
| 570 | this->groupName = NULL; |
---|
[3144] | 571 | } |
---|
| 572 | |
---|
| 573 | /** |
---|
[3423] | 574 | \brief Destroys a Packer. |
---|
| 575 | */ |
---|
[3623] | 576 | Packer::~Packer(void) |
---|
[3423] | 577 | { |
---|
[4026] | 578 | PRINTF(5)("deleting the Packer part.\n"); |
---|
[3423] | 579 | if (this->groupName) |
---|
| 580 | delete []this->groupName; |
---|
[4046] | 581 | |
---|
[3423] | 582 | //deleting recursively. |
---|
| 583 | if (this->down) |
---|
| 584 | delete this->down; |
---|
| 585 | } |
---|
| 586 | |
---|
| 587 | /** |
---|
[3144] | 588 | \brief Sets the group name under which all the lower widgets of this will be saved. |
---|
| 589 | \param name The name of the group. |
---|
| 590 | */ |
---|
[4046] | 591 | void Packer::setGroupName(const char* name) |
---|
[3144] | 592 | { |
---|
[3423] | 593 | if (this->groupName) |
---|
| 594 | delete []this->groupName; |
---|
| 595 | this->groupName = new char[strlen(name)+1]; |
---|
| 596 | strcpy(this->groupName, name); |
---|
[3144] | 597 | } |
---|
| 598 | |
---|
[4046] | 599 | //////////////// |
---|
[3144] | 600 | /* CONTAINERS */ |
---|
[4046] | 601 | //////////////// |
---|
[3144] | 602 | /** |
---|
| 603 | \brief Initializes a Container. |
---|
[3187] | 604 | |
---|
[3144] | 605 | sets the Container-Specific defaults. |
---|
| 606 | */ |
---|
[3623] | 607 | Container::Container(void) |
---|
[3144] | 608 | { |
---|
[4071] | 609 | this->optionType = GUI_CONTAINER; |
---|
[3144] | 610 | } |
---|
| 611 | |
---|
| 612 | /** |
---|
[3423] | 613 | \brief Destroys a Container. |
---|
| 614 | */ |
---|
[3623] | 615 | Container::~Container(void) |
---|
[3423] | 616 | { |
---|
[4026] | 617 | PRINTF(5)("deleting the Container part.\n"); |
---|
[3423] | 618 | } |
---|
| 619 | |
---|
| 620 | /** |
---|
[3144] | 621 | \briefFills a Container with lowerWidget. |
---|
[3187] | 622 | \param lowerWidget the Widget that should be filled into the Container. |
---|
| 623 | |
---|
[3144] | 624 | It does this by filling up the down pointer only if down points to NULL. |
---|
| 625 | */ |
---|
[4046] | 626 | void Container::fill(Widget* lowerWidget) |
---|
[3144] | 627 | { |
---|
| 628 | if (this->down == NULL) |
---|
| 629 | { |
---|
[3165] | 630 | #ifdef HAVE_GTK2 |
---|
[3423] | 631 | gtk_container_add(GTK_CONTAINER(this->widget), lowerWidget->widget); |
---|
[3165] | 632 | #endif /* HAVE_GTK2 */ |
---|
[4046] | 633 | |
---|
[3144] | 634 | this->down = lowerWidget; |
---|
| 635 | } |
---|
| 636 | else |
---|
[4132] | 637 | PRINTF(2)("You tried to put more than one Widget into a Container. \nNot including this item.\nThis is only possible with Boxes.\n"); |
---|
[3144] | 638 | } |
---|
| 639 | |
---|
[3187] | 640 | /** |
---|
[4046] | 641 | \param borderwidth sets the Width of the border |
---|
[3187] | 642 | */ |
---|
[4046] | 643 | void Container::setBorderWidth(int borderwidth) |
---|
[3148] | 644 | { |
---|
[4046] | 645 | this->borderwidth = borderwidth; |
---|
[3148] | 646 | |
---|
[4046] | 647 | #ifdef HAVE_GTK2 |
---|
| 648 | gtk_container_set_border_width(GTK_CONTAINER(widget), borderwidth); |
---|
| 649 | #endif /* HAVE_GTK2 */ |
---|
[3148] | 650 | } |
---|
| 651 | |
---|
[4046] | 652 | //////////// |
---|
| 653 | /* WINDOW */ |
---|
| 654 | //////////// |
---|
| 655 | |
---|
[3144] | 656 | /** |
---|
[4046] | 657 | \brief The main Window of Th Gui |
---|
[3144] | 658 | */ |
---|
[4046] | 659 | Window* Window::mainWindow = NULL; |
---|
[3144] | 660 | |
---|
| 661 | /** |
---|
| 662 | \brief Creating a Window with a name |
---|
| 663 | \param windowName the name the window should get. |
---|
| 664 | */ |
---|
[4046] | 665 | Window::Window(const char* windowName) |
---|
| 666 | { |
---|
| 667 | if (!mainWindow) |
---|
| 668 | { |
---|
| 669 | mainWindow = this; |
---|
| 670 | this->isOpen = true; |
---|
| 671 | } |
---|
| 672 | isOpen = false; |
---|
[3423] | 673 | |
---|
[4046] | 674 | #ifdef HAVE_GTK2 |
---|
| 675 | widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
---|
| 676 | gtk_window_set_policy(GTK_WINDOW(widget), TRUE, TRUE, TRUE); |
---|
| 677 | #if !defined(__WIN32__) |
---|
| 678 | // gtk_window_set_decorated(GTK_WINDOW(widget), FALSE); |
---|
| 679 | #endif |
---|
| 680 | gtk_container_set_border_width(GTK_CONTAINER(widget), 3); |
---|
| 681 | #endif /* HAVE_GTK2 */ |
---|
| 682 | |
---|
| 683 | if (windowName) |
---|
| 684 | this->setTitle(windowName); |
---|
[3144] | 685 | } |
---|
| 686 | |
---|
| 687 | /** |
---|
[3423] | 688 | \brief Destructs a Window. |
---|
| 689 | */ |
---|
| 690 | Window::~Window(void) |
---|
| 691 | { |
---|
[4046] | 692 | PRINTF(5)("deleting the Window: %s\n", this->title); |
---|
[3423] | 693 | } |
---|
| 694 | |
---|
| 695 | /** |
---|
[4046] | 696 | \brief Adds a new Window Windows to the List of Windows. |
---|
| 697 | \param windowToAdd The Windows that should be added to the List |
---|
| 698 | \todo this instead of windowToAdd(possibly) |
---|
[3144] | 699 | */ |
---|
[4046] | 700 | void Window::addWindow(Window* windowToAdd) |
---|
[3144] | 701 | { |
---|
[3148] | 702 | if (!mainWindow) |
---|
[4046] | 703 | { |
---|
| 704 | mainWindow = windowToAdd; |
---|
| 705 | windowToAdd->isOpen = true; |
---|
| 706 | } |
---|
| 707 | else |
---|
| 708 | { |
---|
| 709 | Widget* tmpWindow = mainWindow; |
---|
| 710 | while(tmpWindow->next) |
---|
| 711 | tmpWindow = tmpWindow->next; |
---|
| 712 | tmpWindow->next = windowToAdd; |
---|
| 713 | windowToAdd->isOpen = false; |
---|
| 714 | } |
---|
| 715 | return; |
---|
[3144] | 716 | } |
---|
| 717 | |
---|
| 718 | /** |
---|
| 719 | \brief Shows all Widgets that are included within this->widget. |
---|
| 720 | */ |
---|
[3423] | 721 | void Window::showall(void) |
---|
[3144] | 722 | { |
---|
[4046] | 723 | #ifdef HAVE_GTK2 |
---|
[3423] | 724 | if (!this->isOpen) |
---|
[4046] | 725 | gtk_widget_show_all(this->widget); |
---|
[3144] | 726 | else |
---|
[4046] | 727 | gtk_widget_show(this->widget); |
---|
[3165] | 728 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 729 | } |
---|
| 730 | |
---|
| 731 | /** |
---|
| 732 | \brief Set The Window-title to title |
---|
| 733 | \param title title the Window should get. |
---|
| 734 | */ |
---|
[3624] | 735 | void Window::setTitle(const char* title) |
---|
[3144] | 736 | { |
---|
[3423] | 737 | if (this->title) |
---|
| 738 | delete []this->title; |
---|
| 739 | this->title = new char[strlen(title)+1]; |
---|
| 740 | strcpy(this->title, title); |
---|
[3165] | 741 | #ifdef HAVE_GTK2 |
---|
[3423] | 742 | gtk_window_set_title(GTK_WINDOW(widget), title); |
---|
[3165] | 743 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 744 | } |
---|
| 745 | |
---|
| 746 | /** |
---|
[3147] | 747 | \brief opens up a Window and fixes the Focus to it |
---|
| 748 | */ |
---|
[3423] | 749 | void Window::open(void) |
---|
[3147] | 750 | { |
---|
[3148] | 751 | if (this != mainWindow) |
---|
| 752 | { |
---|
| 753 | isOpen = true; |
---|
[3165] | 754 | #ifdef HAVE_GTK2 |
---|
[3423] | 755 | gtk_widget_show_all(this->widget); |
---|
| 756 | gtk_grab_add(this->widget); |
---|
[3165] | 757 | #endif /* HAVE_GTK2 */ |
---|
[3148] | 758 | } |
---|
[3147] | 759 | } |
---|
| 760 | |
---|
| 761 | /** |
---|
| 762 | \brief closes up a Window and removes the Focus from it |
---|
| 763 | */ |
---|
[3423] | 764 | void Window::close(void) |
---|
[3147] | 765 | { |
---|
[3148] | 766 | if (this != mainWindow) |
---|
| 767 | { |
---|
[3423] | 768 | this->isOpen = false; |
---|
[3165] | 769 | #ifdef HAVE_GTK2 |
---|
[3423] | 770 | gtk_grab_remove(this->widget); |
---|
| 771 | gtk_widget_hide(this->widget); |
---|
[3165] | 772 | #endif /* HAVE_GTK2 */ |
---|
[3148] | 773 | } |
---|
[3147] | 774 | } |
---|
| 775 | |
---|
| 776 | /** |
---|
[3423] | 777 | \brief opens up a window(not topmost Window). |
---|
[3153] | 778 | this is the Signal that does it. !!SIGNALS ARE STATIC!! |
---|
[3187] | 779 | \param widget the widget that did it. |
---|
| 780 | \param event the event that did it. |
---|
[3153] | 781 | \param window the Window that should be opened |
---|
| 782 | */ |
---|
[4046] | 783 | #ifdef HAVE_GTK2 |
---|
| 784 | gint Window::windowOpen(GtkWidget* widget, GdkEvent* event, void* window) |
---|
[3153] | 785 | { |
---|
| 786 | static_cast<Window*>(window)->open(); |
---|
| 787 | } |
---|
[4046] | 788 | #else /* HAVE_GTK2 */ |
---|
| 789 | int Window::windowOpen(void* widget, void* event, void* window){} |
---|
| 790 | #endif /* HAVE_GTK2 */ |
---|
[3153] | 791 | |
---|
| 792 | /** |
---|
[3423] | 793 | \brief closes a window(not topmost Window). |
---|
[3153] | 794 | this is the Signal that does it. !!SIGNALS ARE STATIC!! |
---|
| 795 | \param widget the widget that did it! |
---|
| 796 | \param event the event that did it! |
---|
| 797 | \param window the Window that should be closed |
---|
| 798 | */ |
---|
[4046] | 799 | #ifdef HAVE_GTK2 |
---|
| 800 | gint Window::windowClose(GtkWidget* widget, GdkEvent* event, void* window) |
---|
[3153] | 801 | { |
---|
| 802 | static_cast<Window*>(window)->close(); |
---|
| 803 | } |
---|
[4046] | 804 | #else /* HAVE_GTK2 */ |
---|
| 805 | int Window::windowClose(void* widget, void* event, void* window){} |
---|
[3165] | 806 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 807 | |
---|
[4046] | 808 | /////////// |
---|
[3144] | 809 | /* FRAME */ |
---|
[4046] | 810 | /////////// |
---|
[3144] | 811 | /** |
---|
| 812 | \brief Creates a new Frame with name title |
---|
| 813 | */ |
---|
[4068] | 814 | Frame::Frame(const char* frameName) |
---|
[3144] | 815 | { |
---|
[4046] | 816 | #ifdef HAVE_GTK2 |
---|
| 817 | this->widget = gtk_frame_new(""); |
---|
| 818 | gtk_container_set_border_width(GTK_CONTAINER(this->widget), 3); |
---|
| 819 | #endif /* HAVE_GTK2 */ |
---|
[4081] | 820 | if (frameName) |
---|
[4046] | 821 | this->setTitle(frameName); |
---|
[3144] | 822 | } |
---|
| 823 | |
---|
[3423] | 824 | /** |
---|
| 825 | \brief destrcucts a Frame |
---|
| 826 | */ |
---|
| 827 | Frame::~Frame(void) |
---|
| 828 | { |
---|
[4026] | 829 | PRINTF(5)("deleting the Frame: %s\n", this->title); |
---|
[3423] | 830 | } |
---|
| 831 | |
---|
[3144] | 832 | /** |
---|
| 833 | \brief Sets the Frames name to title |
---|
| 834 | \param title The title the Frame should get. |
---|
| 835 | */ |
---|
[3624] | 836 | void Frame::setTitle(const char* title) |
---|
[3144] | 837 | { |
---|
[3423] | 838 | if (this->title) |
---|
| 839 | delete []this->title; |
---|
| 840 | this->title = new char[strlen(title)+1]; |
---|
| 841 | strcpy(this->title, title); |
---|
[3165] | 842 | #ifdef HAVE_GTK2 |
---|
[4081] | 843 | gtk_frame_set_label(GTK_FRAME(widget), this->title); |
---|
[3165] | 844 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 845 | } |
---|
| 846 | |
---|
[4046] | 847 | ////////////// |
---|
| 848 | /* EVENTBOX */ |
---|
| 849 | ////////////// |
---|
[3144] | 850 | /** |
---|
| 851 | \brief Creates a new EventBox with name title |
---|
[4046] | 852 | \param eventBoxName title the Eventbox should get(only data-structure-internal) |
---|
[3144] | 853 | */ |
---|
[4046] | 854 | EventBox::EventBox(const char* eventBoxName) |
---|
[3144] | 855 | { |
---|
[3165] | 856 | #ifdef HAVE_GTK2 |
---|
[3423] | 857 | this->widget = gtk_event_box_new(); |
---|
| 858 | gtk_container_set_border_width(GTK_CONTAINER(this->widget), 3); |
---|
[3165] | 859 | #endif /* HAVE_GTK2 */ |
---|
[4046] | 860 | |
---|
| 861 | if (eventBoxName) |
---|
| 862 | this->setTitle(eventBoxName); |
---|
[3144] | 863 | } |
---|
| 864 | |
---|
| 865 | /** |
---|
[4046] | 866 | \brief destructs an EventBox. |
---|
[3144] | 867 | */ |
---|
[4046] | 868 | EventBox::~EventBox(void) |
---|
[3144] | 869 | { |
---|
[4046] | 870 | PRINTF(5)("deleting the EventBox: %s\n", this->title); |
---|
[3144] | 871 | } |
---|
| 872 | |
---|
[4046] | 873 | ///////// |
---|
| 874 | /* BOX */ |
---|
| 875 | ///////// |
---|
[3144] | 876 | /** |
---|
| 877 | \brief Creates a new Box of type boxtype |
---|
| 878 | \param boxtype if 'v' the Box will be vertically, if 'h' the Box will be horizontally |
---|
| 879 | */ |
---|
[3423] | 880 | Box::Box(char boxtype) |
---|
[3144] | 881 | { |
---|
[4071] | 882 | this->optionType = GUI_BOX; |
---|
[4046] | 883 | |
---|
| 884 | #ifdef HAVE_GTK2 |
---|
| 885 | if (boxtype == 'v') |
---|
| 886 | this->widget = gtk_vbox_new(FALSE, 0); |
---|
| 887 | else |
---|
| 888 | this->widget = gtk_hbox_new(FALSE, 0); |
---|
| 889 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 890 | } |
---|
| 891 | |
---|
| 892 | /** |
---|
[3423] | 893 | \brief destructs a Box. |
---|
| 894 | */ |
---|
| 895 | Box::~Box(void) |
---|
| 896 | { |
---|
[4026] | 897 | PRINTF(5)("deleting the Box: %s\n", this->title); |
---|
[3423] | 898 | } |
---|
| 899 | |
---|
[3144] | 900 | /** |
---|
| 901 | \brief Fills a box with a given Widget. |
---|
[3187] | 902 | \param lowerWidget the next Widget that should be appendet to this Box |
---|
| 903 | |
---|
[3144] | 904 | 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 |
---|
| 905 | */ |
---|
[3423] | 906 | void Box::fill(Widget* lowerWidget) |
---|
[3144] | 907 | { |
---|
[3165] | 908 | #ifdef HAVE_GTK2 |
---|
[3423] | 909 | gtk_box_pack_start(GTK_BOX(this->widget), lowerWidget->widget, TRUE, TRUE, 0); |
---|
[3165] | 910 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 911 | if (this->down == NULL) |
---|
| 912 | this->down = lowerWidget; |
---|
| 913 | else |
---|
| 914 | { |
---|
| 915 | Widget* tmp; |
---|
| 916 | tmp = this->down; |
---|
[3423] | 917 | while(tmp->next != NULL) |
---|
[4046] | 918 | tmp = tmp->next; |
---|
[3144] | 919 | tmp->next = lowerWidget; |
---|
| 920 | } |
---|
| 921 | } |
---|
| 922 | |
---|
[4046] | 923 | //////////// |
---|
[3144] | 924 | /* OPTION */ |
---|
[4046] | 925 | //////////// |
---|
[3144] | 926 | /** |
---|
| 927 | \brief Initializes a new Option. |
---|
| 928 | sets all Option-Specific-Values to their defaults. |
---|
| 929 | */ |
---|
[3623] | 930 | Option::Option(void) |
---|
[3144] | 931 | { |
---|
[3423] | 932 | this->value = 0; |
---|
| 933 | this->flagName = NULL; |
---|
| 934 | this->flagNameShort = NULL; |
---|
[4046] | 935 | |
---|
| 936 | this->shortDescription = NULL; |
---|
| 937 | this->longDescription = NULL; |
---|
| 938 | |
---|
[3423] | 939 | this->saveable = false; |
---|
| 940 | this->defaultValue = 0; |
---|
[3144] | 941 | } |
---|
| 942 | |
---|
| 943 | /** |
---|
[3423] | 944 | \brief Destroys an Option. |
---|
| 945 | */ |
---|
[3623] | 946 | Option::~Option(void) |
---|
[3423] | 947 | { |
---|
[4026] | 948 | PRINTF(5)("deleting the Option Part.\n"); |
---|
[3423] | 949 | if (this->flagName) |
---|
| 950 | delete []this->flagName; |
---|
| 951 | if (this->flagNameShort) |
---|
| 952 | delete []this->flagNameShort; |
---|
[4046] | 953 | if (this->shortDescription) |
---|
| 954 | delete []this->shortDescription; |
---|
| 955 | if (this->longDescription) |
---|
| 956 | delete []this->longDescription; |
---|
[3423] | 957 | } |
---|
| 958 | |
---|
| 959 | /** |
---|
[4058] | 960 | \param defaultValue new defaultValue for this option |
---|
| 961 | */ |
---|
| 962 | void Option::setDefaultValue(int defaultValue) |
---|
| 963 | { |
---|
| 964 | this->value = this->defaultValue = defaultValue; |
---|
| 965 | } |
---|
| 966 | |
---|
| 967 | /** |
---|
[3144] | 968 | \brief This sets The FlagName of an Option and defines its default Values |
---|
[3187] | 969 | !! Options will be saved if flagname is different from NULL !! |
---|
[3144] | 970 | \param flagname the Name that will be displayed in the output |
---|
[3423] | 971 | \param defaultvalue the default Value for this Option(see definition of defaultvalue |
---|
[3144] | 972 | */ |
---|
[4046] | 973 | void Option::setFlagName(const char* flagname, int defaultvalue) |
---|
[3144] | 974 | { |
---|
[3423] | 975 | if (this->flagName) |
---|
| 976 | delete this->flagName; |
---|
| 977 | this->flagName = new char [strlen(flagname)+1]; |
---|
| 978 | strcpy(this->flagName, flagname); |
---|
[4046] | 979 | |
---|
[4058] | 980 | this->setDefaultValue(defaultvalue); |
---|
[3166] | 981 | |
---|
[4046] | 982 | if (this->flagNameShort) |
---|
| 983 | { |
---|
| 984 | delete this->flagNameShort; |
---|
| 985 | this->flagNameShort = NULL; |
---|
| 986 | } |
---|
| 987 | |
---|
[3423] | 988 | // cout << "Set Flagname of " << this->title << " to " << flagname << endl; |
---|
[3144] | 989 | } |
---|
| 990 | |
---|
| 991 | /** |
---|
[3423] | 992 | \brief see Option::setFlagName(char* flagname, int defaultvalue) |
---|
[3144] | 993 | \param flagname the Name that will be displayed in the output |
---|
[3423] | 994 | \param defaultvalue the default Value for this Option(see definition of defaultvalue |
---|
[3144] | 995 | \param flagnameshort a short flagname to be displayed in the output |
---|
| 996 | */ |
---|
[4046] | 997 | void Option::setFlagName(const char* flagname, const char* flagnameshort, int defaultvalue) |
---|
[3144] | 998 | { |
---|
[3423] | 999 | if (this->flagName) |
---|
| 1000 | delete []this->flagName; |
---|
| 1001 | this->flagName = new char [strlen(flagname)+1]; |
---|
| 1002 | strcpy(this->flagName, flagname); |
---|
[3158] | 1003 | |
---|
[3423] | 1004 | if (this->flagNameShort) |
---|
| 1005 | delete []this->flagNameShort; |
---|
| 1006 | this->flagNameShort = new char [strlen(flagnameshort)+1]; |
---|
| 1007 | strcpy(this->flagNameShort, flagnameshort); |
---|
[4058] | 1008 | this->setDefaultValue(defaultvalue); |
---|
[3423] | 1009 | // cout << "Set Flagname of " << this->title << " to " << flagname << endl; |
---|
[3144] | 1010 | } |
---|
| 1011 | |
---|
[4046] | 1012 | void Option::setDescription(const char* shortDescription, const char* longDescription) |
---|
[3423] | 1013 | { |
---|
[4046] | 1014 | // setting up the short description |
---|
| 1015 | if (this->shortDescription) |
---|
| 1016 | delete []this->shortDescription; |
---|
| 1017 | this->shortDescription = new char [strlen(shortDescription)+1]; |
---|
| 1018 | strcpy(this->shortDescription, shortDescription); |
---|
| 1019 | |
---|
| 1020 | //setting up the long description |
---|
| 1021 | if (this->longDescription) |
---|
| 1022 | delete []this->longDescription; |
---|
| 1023 | if (longDescription) |
---|
| 1024 | { |
---|
| 1025 | this->longDescription = new char [strlen(longDescription)+1]; |
---|
| 1026 | strcpy(this->longDescription, longDescription); |
---|
| 1027 | } |
---|
| 1028 | else |
---|
| 1029 | this->longDescription = NULL; |
---|
[3423] | 1030 | } |
---|
[3144] | 1031 | |
---|
[3423] | 1032 | /** |
---|
| 1033 | \brief Sets the saveable-state of the option. |
---|
| 1034 | \param isSaveable the saveable-state to set. |
---|
| 1035 | */ |
---|
| 1036 | void Option::saveability(bool isSaveable) |
---|
| 1037 | { |
---|
| 1038 | this->saveable = isSaveable; |
---|
| 1039 | } |
---|
| 1040 | |
---|
| 1041 | /** |
---|
[3625] | 1042 | \brief saves an Option |
---|
[4046] | 1043 | \returns the String that should be saved. (this string __should__ be deleted) |
---|
[3625] | 1044 | |
---|
| 1045 | this is a default Option save |
---|
| 1046 | */ |
---|
| 1047 | char* Option::save(void) |
---|
| 1048 | { |
---|
[4046] | 1049 | char* value = new char [30]; |
---|
[3625] | 1050 | sprintf (value, "%d", this->value); |
---|
| 1051 | return value; |
---|
| 1052 | } |
---|
| 1053 | |
---|
| 1054 | /** |
---|
| 1055 | \brief loads an Option from of its loadString |
---|
| 1056 | \param loadString the string from which to load the data from |
---|
| 1057 | */ |
---|
| 1058 | void Option::load(char* loadString) |
---|
| 1059 | { |
---|
| 1060 | this->value = atoi(loadString); |
---|
[4026] | 1061 | PRINT(5)("Loading %s: %s %d\n", this->title, loadString, value); |
---|
[3625] | 1062 | this->redraw(); |
---|
| 1063 | } |
---|
| 1064 | |
---|
| 1065 | /** |
---|
[3423] | 1066 | \returns The saveable-state. |
---|
| 1067 | */ |
---|
| 1068 | bool Option::isSaveable(void) |
---|
| 1069 | { |
---|
| 1070 | return this->saveable; |
---|
| 1071 | } |
---|
| 1072 | |
---|
| 1073 | #ifdef HAVE_GTK2 |
---|
| 1074 | /** |
---|
| 1075 | \brief Signal OptionChange writes the Value from the Slider to its Object-Database. |
---|
| 1076 | \param widget The widget(Slider) that has a changed Value |
---|
| 1077 | \param slider the Slider-Object that should receive the change. |
---|
| 1078 | */ |
---|
| 1079 | gint Option::OptionChange(GtkWidget *widget, Widget* option) |
---|
| 1080 | { |
---|
| 1081 | static_cast<Option*>(option)->changeOption(); |
---|
| 1082 | flags->setTextFromFlags(Window::mainWindow); //// must be different !!! |
---|
| 1083 | } |
---|
| 1084 | #endif /* HAVE_GTK2 */ |
---|
| 1085 | |
---|
[4046] | 1086 | //////////// |
---|
[3144] | 1087 | /* BUTTON */ |
---|
[4046] | 1088 | //////////// |
---|
[3144] | 1089 | /** |
---|
| 1090 | \brief Creates a new Button with a buttonname |
---|
[4046] | 1091 | \param buttonName sets the Name of the Button |
---|
[3144] | 1092 | */ |
---|
[4089] | 1093 | Button::Button(const char* buttonName) |
---|
[3144] | 1094 | { |
---|
[4071] | 1095 | this->optionType = GUI_NOTHING; |
---|
[4046] | 1096 | |
---|
| 1097 | #ifdef HAVE_GTK2 |
---|
| 1098 | widget = gtk_button_new_with_label(""); |
---|
| 1099 | #endif /* HAVE_GTK2 */ |
---|
| 1100 | |
---|
| 1101 | if (buttonName) |
---|
| 1102 | this->setTitle(buttonName); |
---|
[3144] | 1103 | } |
---|
| 1104 | |
---|
| 1105 | /** |
---|
[3423] | 1106 | \brief destructs a Button. |
---|
| 1107 | */ |
---|
| 1108 | Button::~Button(void) |
---|
| 1109 | { |
---|
[4026] | 1110 | PRINTF(5)("deleting the Label: %s\n", this->title); |
---|
[3423] | 1111 | } |
---|
| 1112 | |
---|
| 1113 | /** |
---|
[3144] | 1114 | \brief Sets a new name to the Button |
---|
| 1115 | \param title The name the Button should get |
---|
| 1116 | */ |
---|
[3624] | 1117 | void Button::setTitle(const char *title) |
---|
[3144] | 1118 | { |
---|
[3423] | 1119 | if (this->title) |
---|
| 1120 | delete []this->title; |
---|
| 1121 | this->title = new char[strlen(title)+1]; |
---|
| 1122 | strcpy(this->title, title); |
---|
[3165] | 1123 | #ifdef HAVE_GTK2 |
---|
[3423] | 1124 | gtk_button_set_label(GTK_BUTTON(widget), title); |
---|
[3165] | 1125 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1126 | } |
---|
| 1127 | |
---|
| 1128 | /** |
---|
| 1129 | \brief redraws the Button |
---|
[4046] | 1130 | \todo not implemented yet |
---|
[3144] | 1131 | */ |
---|
[3423] | 1132 | void Button::redraw(void) |
---|
[3144] | 1133 | { |
---|
| 1134 | } |
---|
| 1135 | |
---|
[3423] | 1136 | /** |
---|
| 1137 | \brief Button can not be changed, optionChange is empty) |
---|
| 1138 | |
---|
| 1139 | \todo Actions for non-GTK-mode |
---|
| 1140 | */ |
---|
| 1141 | void Button::changeOption(void) |
---|
| 1142 | { |
---|
| 1143 | // This will possibly be used for ACTIONS ! |
---|
| 1144 | } |
---|
| 1145 | |
---|
[4046] | 1146 | ///////////////// |
---|
[3144] | 1147 | /* CHECKBUTTON */ |
---|
[4046] | 1148 | ///////////////// |
---|
[3144] | 1149 | /** |
---|
| 1150 | \brief Creates a new CheckButton with an ame |
---|
[4046] | 1151 | \param buttonName The name the CheckButton should display. |
---|
[3144] | 1152 | */ |
---|
[4046] | 1153 | CheckButton::CheckButton(const char* buttonName) |
---|
[3144] | 1154 | { |
---|
[4071] | 1155 | this->optionType = GUI_BOOL; |
---|
[3144] | 1156 | |
---|
[3165] | 1157 | #ifdef HAVE_GTK2 |
---|
[4046] | 1158 | this->widget = gtk_check_button_new_with_label(""); |
---|
| 1159 | #endif /* HAVE_GTK2 */ |
---|
| 1160 | |
---|
| 1161 | if (buttonName) |
---|
| 1162 | this->setTitle(buttonName); |
---|
| 1163 | |
---|
| 1164 | #ifdef HAVE_GTK2 |
---|
[3423] | 1165 | this->connectSignal("clicked", this->OptionChange); |
---|
[3165] | 1166 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1167 | } |
---|
| 1168 | |
---|
| 1169 | /** |
---|
[3423] | 1170 | \brief destructs a CheckButton. |
---|
| 1171 | */ |
---|
| 1172 | CheckButton::~CheckButton(void) |
---|
| 1173 | { |
---|
[3623] | 1174 | if (this->title) |
---|
[4026] | 1175 | PRINTF(5)("deleting the CheckButton: %s\n", this->title); |
---|
[3623] | 1176 | else |
---|
[4026] | 1177 | PRINTF(5)("deleting the CheckButton.\n"); |
---|
[3423] | 1178 | } |
---|
| 1179 | |
---|
| 1180 | /** |
---|
[3144] | 1181 | \brief Sets a new Title to a CheckButton |
---|
| 1182 | \param title The new Name the CheckButton should display. |
---|
| 1183 | */ |
---|
[3624] | 1184 | void CheckButton::setTitle(const char* title) |
---|
[3144] | 1185 | { |
---|
[3423] | 1186 | if (this->title) |
---|
| 1187 | delete []this->title; |
---|
| 1188 | this->title = new char[strlen(title)+1]; |
---|
| 1189 | strcpy(this->title, title); |
---|
[3165] | 1190 | #ifdef HAVE_GTK2 |
---|
[3144] | 1191 | gtk_button_set_label(GTK_BUTTON(widget), title); |
---|
[3165] | 1192 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1193 | } |
---|
| 1194 | |
---|
[4046] | 1195 | /** |
---|
| 1196 | \returns the Active state of the checkButton |
---|
| 1197 | */ |
---|
[3423] | 1198 | bool CheckButton::isActive(void) |
---|
[3146] | 1199 | { |
---|
[3165] | 1200 | #ifdef HAVE_GTK2 |
---|
[3146] | 1201 | return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); |
---|
[3165] | 1202 | #endif /* HAVE_GTK2 */ |
---|
[3146] | 1203 | } |
---|
[3144] | 1204 | |
---|
[3423] | 1205 | /** |
---|
| 1206 | \brief Changed the Option, call this Function |
---|
[3144] | 1207 | */ |
---|
[3423] | 1208 | void CheckButton::changeOption(void) |
---|
[3144] | 1209 | { |
---|
[3423] | 1210 | #ifdef HAVE_GTK2 |
---|
| 1211 | this->value =(int)gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(this->widget)); |
---|
| 1212 | #else /* HAVE_GTK2 */ |
---|
[4035] | 1213 | char tmpChar[200]; |
---|
[4026] | 1214 | PRINT(0)("\nPlease give me a new value for %s [0,1](default:%d): ",this->title, this->defaultValue); |
---|
[4035] | 1215 | scanf("%s", tmpChar); |
---|
[3423] | 1216 | |
---|
| 1217 | if ((this->value = atoi(tmpChar))=!0) |
---|
| 1218 | this->value = 1; |
---|
[4132] | 1219 | |
---|
| 1220 | PRINT(0)("%s set to: %d\n", this->title, this->value); |
---|
[3423] | 1221 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1222 | } |
---|
| 1223 | |
---|
| 1224 | /** |
---|
[3423] | 1225 | \brief Redraws the CheckButton(if option has changed). |
---|
[3144] | 1226 | Example: if new settings are loaded the Button must be redrawn for the GUI to display that Change |
---|
| 1227 | */ |
---|
[3423] | 1228 | void CheckButton::redraw(void) |
---|
[3144] | 1229 | { |
---|
[3165] | 1230 | #ifdef HAVE_GTK2 |
---|
[3423] | 1231 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->widget), value); |
---|
[3165] | 1232 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1233 | } |
---|
| 1234 | |
---|
[4046] | 1235 | //////////// |
---|
[3144] | 1236 | /* SLIDER */ |
---|
[4046] | 1237 | //////////// |
---|
[3144] | 1238 | /** |
---|
| 1239 | \brief Creates a new Slider |
---|
| 1240 | \param slidername The data-structure-name of the slider. |
---|
| 1241 | \param start The minimal Value of the slider. |
---|
| 1242 | \param end The maximal Value of the slider. |
---|
| 1243 | */ |
---|
[4046] | 1244 | Slider::Slider(const char* slidername, int start, int end) |
---|
[3144] | 1245 | { |
---|
[4071] | 1246 | this->optionType = GUI_INT; |
---|
[4046] | 1247 | |
---|
| 1248 | this->start = start; |
---|
| 1249 | this->end = end; |
---|
| 1250 | #ifdef HAVE_GTK2 |
---|
| 1251 | widget = gtk_hscale_new_with_range(this->start, this->end, 5); |
---|
| 1252 | #endif /* HAVE_GTK2 */ |
---|
| 1253 | |
---|
[3144] | 1254 | this->setValue(start); |
---|
| 1255 | this->setTitle(slidername); |
---|
[3165] | 1256 | #ifdef HAVE_GTK2 |
---|
[3423] | 1257 | this->connectSignal("value_changed", this->OptionChange); |
---|
[3165] | 1258 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1259 | } |
---|
| 1260 | |
---|
| 1261 | /** |
---|
[3423] | 1262 | \brief destructs a Slider. |
---|
| 1263 | */ |
---|
| 1264 | Slider::~Slider(void) |
---|
| 1265 | { |
---|
[4026] | 1266 | PRINTF(5)("deleting the Slider: %s\n", this->title); |
---|
[3423] | 1267 | } |
---|
| 1268 | |
---|
| 1269 | /** |
---|
[3144] | 1270 | \brief Setting a new value to the Slider. |
---|
| 1271 | Maybe you also require a Slider::redraw() for this to display |
---|
| 1272 | */ |
---|
| 1273 | void Slider::setValue(int value) |
---|
| 1274 | { |
---|
| 1275 | this->value = value; |
---|
| 1276 | } |
---|
| 1277 | |
---|
[3423] | 1278 | /** |
---|
| 1279 | \brief Redraws the widget |
---|
| 1280 | Example: see void CheckButton::redraw(void) |
---|
[3144] | 1281 | */ |
---|
[3423] | 1282 | void Slider::redraw(void) |
---|
[3144] | 1283 | { |
---|
[3423] | 1284 | #ifdef HAVE_GTK2 |
---|
[4046] | 1285 | gtk_range_set_value(GTK_RANGE(this->widget), this->value); |
---|
[3423] | 1286 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1287 | } |
---|
| 1288 | |
---|
| 1289 | /** |
---|
[3423] | 1290 | \brief Changed the Option, call this Function |
---|
[3144] | 1291 | */ |
---|
[3423] | 1292 | void Slider::changeOption(void) |
---|
[3144] | 1293 | { |
---|
[3165] | 1294 | #ifdef HAVE_GTK2 |
---|
[3423] | 1295 | this->value =(int)gtk_range_get_value(GTK_RANGE(this->widget)); |
---|
| 1296 | #else /* HAVE_GTK2 */ |
---|
| 1297 | char tmpChar[20]; |
---|
[4026] | 1298 | PRINT(0)("\nPlease give me a new value for %s [%d-%d] (default:%d): ", this->title, this->start, this->end, this->defaultValue); |
---|
[4035] | 1299 | scanf("%s", tmpChar); |
---|
[3423] | 1300 | |
---|
| 1301 | if ((this->value = atoi(tmpChar))> this->end) |
---|
| 1302 | this->value = this->end; |
---|
| 1303 | if (this->value <= this->start) |
---|
| 1304 | this->value = this->start; |
---|
[4132] | 1305 | |
---|
| 1306 | PRINT(0)("%s set to: %d\n",this->title, this->value); |
---|
[3165] | 1307 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1308 | } |
---|
| 1309 | |
---|
[4046] | 1310 | ////////// |
---|
[3144] | 1311 | /* MENU */ |
---|
[4046] | 1312 | ////////// |
---|
[3624] | 1313 | /** |
---|
| 1314 | \brief constructs a new Menu, without adding any items to it. |
---|
| 1315 | \param menuName the Name the Menu gets. |
---|
| 1316 | */ |
---|
| 1317 | Menu::Menu(const char* menuName) |
---|
| 1318 | { |
---|
| 1319 | this->init(); |
---|
| 1320 | this->setTitle(menuName); |
---|
| 1321 | } |
---|
| 1322 | |
---|
[3144] | 1323 | /** |
---|
| 1324 | \brief Creates a Menu-Item-list out of multiple input. |
---|
| 1325 | !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
| 1326 | \param menuname The Database-Name of this Menu |
---|
| 1327 | \param ... items to be added to this Menu. !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
| 1328 | */ |
---|
[3423] | 1329 | Menu::Menu(char* menuname, ...) |
---|
[3144] | 1330 | { |
---|
| 1331 | this->init(); |
---|
| 1332 | this->setTitle(menuname); |
---|
[3625] | 1333 | va_list itemlist; //!< The list to readin multiple Options. |
---|
| 1334 | |
---|
[3144] | 1335 | char *itemName; |
---|
[3165] | 1336 | |
---|
[3423] | 1337 | va_start(itemlist, menuname); |
---|
| 1338 | while(strcmp(itemName = va_arg(itemlist, char*), "lastItem")) |
---|
[3144] | 1339 | { |
---|
| 1340 | this->addItem(itemName); |
---|
| 1341 | } |
---|
| 1342 | va_end(itemlist); |
---|
| 1343 | } |
---|
| 1344 | |
---|
| 1345 | /** |
---|
[3423] | 1346 | \brief destructs a Menu. |
---|
| 1347 | */ |
---|
| 1348 | Menu::~Menu(void) |
---|
| 1349 | { |
---|
[4026] | 1350 | PRINTF(5)("deleting the Menu: %s\n", this->title); |
---|
[3624] | 1351 | this->currItem = this->firstItem; |
---|
| 1352 | while(this->currItem) |
---|
| 1353 | { |
---|
| 1354 | delete []this->currItem->name; |
---|
[4026] | 1355 | //! \todo destroy menu |
---|
[3624] | 1356 | /* |
---|
| 1357 | #ifdef HAVE_GTK2 |
---|
[4046] | 1358 | gtk_widget_destroy(this->currItem->item); |
---|
[3624] | 1359 | #endif /* HAVE_GTK2 */ |
---|
| 1360 | MenuItem* tmpItem = this->currItem; |
---|
| 1361 | this->currItem = this->currItem->next; |
---|
| 1362 | delete tmpItem; |
---|
| 1363 | } |
---|
[3423] | 1364 | } |
---|
| 1365 | |
---|
| 1366 | /** |
---|
[3144] | 1367 | \brief Initializes a new Menu with no items |
---|
| 1368 | */ |
---|
| 1369 | void Menu::init(void) |
---|
| 1370 | { |
---|
[4071] | 1371 | this->optionType = GUI_INT; |
---|
[3624] | 1372 | this->firstItem = NULL; |
---|
[3144] | 1373 | |
---|
[3165] | 1374 | #ifdef HAVE_GTK2 |
---|
[3423] | 1375 | this->widget = gtk_option_menu_new(); |
---|
| 1376 | this->menu = gtk_menu_new(); |
---|
[3624] | 1377 | gtk_option_menu_set_menu(GTK_OPTION_MENU(this->widget), menu); |
---|
| 1378 | this->connectSignal("changed", this->OptionChange); |
---|
[3165] | 1379 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1380 | } |
---|
| 1381 | |
---|
| 1382 | /** |
---|
[3625] | 1383 | \brief saves the Label of the Menu |
---|
| 1384 | \returns the name of the selected Menu-Item |
---|
| 1385 | */ |
---|
| 1386 | char* Menu::save(void) |
---|
| 1387 | { |
---|
| 1388 | MenuItem* tmpItem = this->firstItem; |
---|
| 1389 | for (int i = 0; i<this->value; i++) |
---|
| 1390 | tmpItem = tmpItem->next; |
---|
| 1391 | |
---|
| 1392 | return tmpItem->name; |
---|
| 1393 | } |
---|
| 1394 | |
---|
| 1395 | /** |
---|
| 1396 | \brief loads a Menu from of its loadString |
---|
| 1397 | \param loadString the string from which to load the data from |
---|
| 1398 | */ |
---|
| 1399 | void Menu::load(char* loadString) |
---|
| 1400 | { |
---|
| 1401 | MenuItem* tmpItem = firstItem; |
---|
| 1402 | bool foundItem = false; |
---|
| 1403 | while (tmpItem) |
---|
| 1404 | { |
---|
| 1405 | if (!strcmp(loadString, tmpItem->name)) |
---|
| 1406 | {foundItem = true; break;} |
---|
| 1407 | tmpItem = tmpItem->next; |
---|
| 1408 | } |
---|
| 1409 | if (foundItem) |
---|
| 1410 | this->value = tmpItem->itemNumber; |
---|
| 1411 | else |
---|
| 1412 | { |
---|
| 1413 | this->value = 0; |
---|
[4132] | 1414 | PRINTF(2)("%s has not been found in the Itemlist of %s\n", loadString, this->title); |
---|
[3625] | 1415 | } |
---|
[4133] | 1416 | PRINTF(5)( "Loading %s: setting to %d\n", this->title, this->value); |
---|
[3625] | 1417 | this->redraw(); |
---|
| 1418 | } |
---|
| 1419 | |
---|
| 1420 | /** |
---|
[3144] | 1421 | \brief appends a new Item to the Menu-List. |
---|
| 1422 | \param itemName the itemName to be appendet. |
---|
| 1423 | */ |
---|
[3423] | 1424 | void Menu::addItem(char* itemName) |
---|
[3144] | 1425 | { |
---|
[3624] | 1426 | if (!this->firstItem) |
---|
[3625] | 1427 | { |
---|
| 1428 | this->firstItem = this->currItem = new MenuItem; |
---|
| 1429 | this->currItem->itemNumber = 0; |
---|
| 1430 | } |
---|
[3624] | 1431 | else |
---|
[3625] | 1432 | { |
---|
| 1433 | int tmpI = this->currItem->itemNumber; |
---|
| 1434 | this->currItem = this->currItem->next = new MenuItem; |
---|
| 1435 | this->currItem->itemNumber = tmpI+1; |
---|
| 1436 | } |
---|
[3624] | 1437 | |
---|
| 1438 | this->currItem->name = new char[strlen(itemName)+1]; |
---|
| 1439 | strcpy(this->currItem->name, itemName); |
---|
[3625] | 1440 | |
---|
[3165] | 1441 | #ifdef HAVE_GTK2 |
---|
[3624] | 1442 | this->currItem->item = gtk_menu_item_new_with_label(itemName); |
---|
| 1443 | gtk_menu_shell_append(GTK_MENU_SHELL(this->menu), this->currItem->item); |
---|
[3165] | 1444 | #endif /* HAVE_GTK2 */ |
---|
[3624] | 1445 | this->currItem->next = NULL; |
---|
[3144] | 1446 | } |
---|
| 1447 | |
---|
[3423] | 1448 | /** |
---|
| 1449 | \brief Redraws the widget |
---|
| 1450 | Example: see void CheckButton::redraw(void) |
---|
[3144] | 1451 | */ |
---|
[3423] | 1452 | void Menu::redraw(void) |
---|
[3144] | 1453 | { |
---|
[3423] | 1454 | #ifdef HAVE_GTK2 |
---|
[4026] | 1455 | gtk_option_menu_set_history(GTK_OPTION_MENU(this->widget), this->value); |
---|
[3423] | 1456 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1457 | } |
---|
| 1458 | |
---|
| 1459 | /** |
---|
[3423] | 1460 | \brief Changed the Option, call this Function |
---|
[3156] | 1461 | */ |
---|
[3423] | 1462 | void Menu::changeOption(void) |
---|
[3144] | 1463 | { |
---|
[3165] | 1464 | #ifdef HAVE_GTK2 |
---|
[3423] | 1465 | this->value =(int)gtk_option_menu_get_history(GTK_OPTION_MENU(this->widget)); |
---|
| 1466 | #else /* HAVE_GTK2 */ |
---|
| 1467 | char tmpChar[20]; |
---|
[4026] | 1468 | PRINT(0)("\nPlease give me a new value for %s (default: %d): ", this->title, this->defaultValue); |
---|
[4035] | 1469 | scanf("%s",tmpChar); |
---|
[3423] | 1470 | this->value = atoi(tmpChar); |
---|
| 1471 | |
---|
[3165] | 1472 | #endif /* HAVE_GTK2 */ |
---|
[4133] | 1473 | PRINT(5)("%s set to: %d\n", this->title, this->value); |
---|
[3144] | 1474 | } |
---|
| 1475 | |
---|
[3423] | 1476 | /* OPTION LABEL */ |
---|
| 1477 | |
---|
[3187] | 1478 | /** |
---|
| 1479 | \brief Creates a new OptionLabel with a LabelName and a Value. |
---|
| 1480 | \param label The name of the OptionLabel. |
---|
[3423] | 1481 | \param value The Value of the OptionLabel(what will be displayed). |
---|
[3187] | 1482 | */ |
---|
[4046] | 1483 | OptionLabel::OptionLabel(const char* label, const char* value) |
---|
[3156] | 1484 | { |
---|
[4071] | 1485 | this->optionType = GUI_CHAR_ARRAY; |
---|
[4046] | 1486 | cValue = NULL; |
---|
| 1487 | |
---|
| 1488 | #ifdef HAVE_GTK2 |
---|
| 1489 | this->widget = gtk_label_new(""); |
---|
| 1490 | #endif /* HAVE_GTK2 */ |
---|
| 1491 | |
---|
[3423] | 1492 | this->setTitle(label); |
---|
| 1493 | this->setValue(value); |
---|
[3156] | 1494 | } |
---|
| 1495 | |
---|
[3187] | 1496 | /** |
---|
[3423] | 1497 | \brief destructs an OptionLabel. |
---|
| 1498 | */ |
---|
| 1499 | OptionLabel::~OptionLabel(void) |
---|
| 1500 | { |
---|
[4026] | 1501 | PRINTF(5)("deleting the OptionLabel: %s\n", this->title); |
---|
[3623] | 1502 | if (this->cValue) |
---|
| 1503 | delete []this->cValue; |
---|
[3423] | 1504 | } |
---|
| 1505 | |
---|
| 1506 | /** |
---|
[3187] | 1507 | \brief Updates the value of an OptionLabel |
---|
| 1508 | \param newValue The new Name that should be displayed. |
---|
| 1509 | */ |
---|
[4046] | 1510 | void OptionLabel::setValue(const char* newValue) |
---|
[3161] | 1511 | { |
---|
[3423] | 1512 | if (this->cValue) |
---|
| 1513 | delete []this->cValue; |
---|
| 1514 | this->cValue = new char [strlen(newValue)+1]; |
---|
| 1515 | strcpy(this->cValue, newValue); |
---|
[4069] | 1516 | |
---|
| 1517 | this->redraw(); |
---|
[3161] | 1518 | } |
---|
[3156] | 1519 | |
---|
[3187] | 1520 | /** |
---|
[3423] | 1521 | \brief Redraws an OptionLabel(not implemented yet, but it works). |
---|
| 1522 | */ |
---|
| 1523 | void OptionLabel::redraw(void) |
---|
| 1524 | { |
---|
[3165] | 1525 | #ifdef HAVE_GTK2 |
---|
[4069] | 1526 | gtk_label_set_text(GTK_LABEL(widget), cValue); |
---|
[3165] | 1527 | #endif /* HAVE_GTK2 */ |
---|
[3156] | 1528 | } |
---|
| 1529 | |
---|
[3187] | 1530 | /** |
---|
[3423] | 1531 | \brief Changed the Option, call this Function |
---|
[3187] | 1532 | */ |
---|
[3423] | 1533 | void OptionLabel::changeOption(void) |
---|
[3156] | 1534 | { |
---|
[3423] | 1535 | #ifdef HAVE_GTK2 |
---|
[4068] | 1536 | this->cValue = (char*)gtk_label_get_text(GTK_LABEL(this->widget)); |
---|
[3423] | 1537 | #else /* HAVE_GTK2 */ |
---|
[4026] | 1538 | PRINT(0)("\nPlease give me a new input for %s: ", this->title); |
---|
[4035] | 1539 | char tmpChar[100]; |
---|
| 1540 | scanf("%s",tmpChar); |
---|
| 1541 | this->setValue(tmpChar); |
---|
[3423] | 1542 | #endif /* HAVE_GTK2 */ |
---|
[4026] | 1543 | PRINT(4)("%s set to: %s\n", this->title, this->cValue); |
---|
[3156] | 1544 | } |
---|
| 1545 | |
---|
[3423] | 1546 | |
---|
[3144] | 1547 | /** |
---|
[3625] | 1548 | \brief creates the Optionlabel save-string |
---|
| 1549 | \returns the String to save. |
---|
| 1550 | */ |
---|
| 1551 | char* OptionLabel::save(void) |
---|
| 1552 | { |
---|
| 1553 | return cValue; |
---|
| 1554 | } |
---|
| 1555 | |
---|
| 1556 | /** |
---|
| 1557 | \brief loads an Option from of its loadString |
---|
| 1558 | \param loadString the string from which to load the data from |
---|
| 1559 | */ |
---|
| 1560 | void OptionLabel::load(char* loadString) |
---|
| 1561 | { |
---|
[4133] | 1562 | PRINTF(5)("Loading %s: setting to %s\n", this->title, loadString); |
---|
[3625] | 1563 | this->setValue(loadString); |
---|
| 1564 | } |
---|
| 1565 | |
---|
[4046] | 1566 | /////////// |
---|
| 1567 | /* LABEL */ |
---|
| 1568 | /////////// |
---|
[3625] | 1569 | /** |
---|
[3144] | 1570 | \brief Creates a new Label with a Text. |
---|
| 1571 | \param text The text to be displayed. |
---|
| 1572 | */ |
---|
[4046] | 1573 | Label:: Label(const char* text) |
---|
[3144] | 1574 | { |
---|
[4071] | 1575 | this->optionType = GUI_NOTHING; |
---|
[4046] | 1576 | |
---|
| 1577 | #ifdef HAVE_GTK2 |
---|
| 1578 | this->widget = gtk_label_new(""); |
---|
| 1579 | gtk_label_set_line_wrap(GTK_LABEL(this->widget), TRUE); |
---|
| 1580 | #endif /* HAVE_GTK2 */ |
---|
| 1581 | |
---|
| 1582 | if (text) |
---|
| 1583 | this->setTitle(text); |
---|
[3144] | 1584 | } |
---|
| 1585 | |
---|
| 1586 | /** |
---|
[3423] | 1587 | \brief destructs a Label. |
---|
| 1588 | */ |
---|
| 1589 | Label::~Label(void) |
---|
| 1590 | { |
---|
[4026] | 1591 | PRINTF(5)("deleting the Label: %s\n", this->title); |
---|
[3423] | 1592 | } |
---|
| 1593 | |
---|
| 1594 | /** |
---|
[3144] | 1595 | \brief Sets a new Text to a Label. |
---|
| 1596 | \param text The text to be inserted into the Label. |
---|
| 1597 | */ |
---|
[4046] | 1598 | void Label::setTitle(const char* text) |
---|
[3144] | 1599 | { |
---|
[3423] | 1600 | if (this->title) |
---|
| 1601 | delete []this->title; |
---|
| 1602 | this->title = new char[strlen(text)+1]; |
---|
| 1603 | strcpy(this->title, text); |
---|
[3165] | 1604 | #ifdef HAVE_GTK2 |
---|
[3423] | 1605 | gtk_label_set_text(GTK_LABEL(this->widget), this->title); |
---|
[3165] | 1606 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1607 | } |
---|
| 1608 | |
---|
| 1609 | /** |
---|
[3423] | 1610 | \brief ereases the Text of a Label |
---|
| 1611 | */ |
---|
| 1612 | void Label::ereaseText(void) |
---|
| 1613 | { |
---|
| 1614 | this->setTitle(""); |
---|
| 1615 | } |
---|
| 1616 | |
---|
| 1617 | /** |
---|
| 1618 | \brief appends some Text to a Label |
---|
| 1619 | \param textToAppend The text that will be appended to this Label |
---|
| 1620 | */ |
---|
| 1621 | void Label::appendText(char* textToAppend) |
---|
| 1622 | { |
---|
| 1623 | if (this->title) |
---|
| 1624 | { |
---|
| 1625 | char* tmpTitle = new char[strlen(this->title)+strlen(textToAppend)+1]; |
---|
| 1626 | strcpy(tmpTitle, title); |
---|
| 1627 | strcat(tmpTitle, textToAppend); |
---|
| 1628 | delete []this->title; |
---|
| 1629 | this->title = tmpTitle; |
---|
| 1630 | } |
---|
| 1631 | else |
---|
[4026] | 1632 | this->title = new char[strlen(textToAppend)]; |
---|
[3423] | 1633 | |
---|
| 1634 | #ifdef HAVE_GTK2 |
---|
| 1635 | gtk_label_set_text(GTK_LABEL(this->widget), title); |
---|
| 1636 | #endif /* HAVE_GTK2 */ |
---|
| 1637 | } |
---|
| 1638 | |
---|
| 1639 | /** |
---|
| 1640 | \brief Appends some integer to the Label |
---|
| 1641 | \param intToAppend The Int that will be added. |
---|
| 1642 | |
---|
| 1643 | it does this by just converting the int into a char* and send it to appendText |
---|
| 1644 | */ |
---|
| 1645 | void Label::appendInt(int intToAppend) |
---|
| 1646 | { |
---|
| 1647 | char append [32]; |
---|
| 1648 | sprintf(append, "%d", intToAppend); |
---|
| 1649 | this->appendText(append); |
---|
| 1650 | } |
---|
| 1651 | |
---|
| 1652 | |
---|
| 1653 | /** |
---|
[3144] | 1654 | \brief get the Text of a Label |
---|
| 1655 | \return The Text the Label holds. |
---|
| 1656 | */ |
---|
[4046] | 1657 | const char* Label::getText(void) |
---|
[3144] | 1658 | { |
---|
[3423] | 1659 | return this->title; |
---|
[3144] | 1660 | } |
---|
[3423] | 1661 | |
---|
[4046] | 1662 | ////////////////// |
---|
| 1663 | /* PROGRESS-BAR */ |
---|
| 1664 | ////////////////// |
---|
[3423] | 1665 | /** |
---|
| 1666 | \brief Creates a new ProgressBar. |
---|
[4046] | 1667 | \param label The name you want to get the ProgressBar. |
---|
[3423] | 1668 | */ |
---|
[4046] | 1669 | ProgressBar::ProgressBar(const char* label) |
---|
[3423] | 1670 | { |
---|
[4071] | 1671 | this->optionType = GUI_NOTHING; |
---|
[4046] | 1672 | this->progress = 0.0; |
---|
| 1673 | this->totalSize = 0.0; |
---|
[3423] | 1674 | |
---|
[4046] | 1675 | #ifdef HAVE_GTK2 |
---|
| 1676 | this->adjustment =(GtkAdjustment*)gtk_adjustment_new(0, 0, 100, 0, 0, 0); |
---|
| 1677 | this->widget = gtk_progress_bar_new_with_adjustment(this->adjustment); |
---|
| 1678 | #endif /* HAVE_GTK2 */ |
---|
| 1679 | |
---|
| 1680 | if (label) |
---|
| 1681 | this->setTitle(label); |
---|
[3423] | 1682 | } |
---|
| 1683 | |
---|
| 1684 | /** |
---|
| 1685 | \brief destructs a ProgressBar |
---|
| 1686 | */ |
---|
| 1687 | ProgressBar::~ProgressBar(void) |
---|
| 1688 | { |
---|
[4026] | 1689 | PRINTF(5)("deleting the ProgressBar: %s\n", this->title); |
---|
[3423] | 1690 | } |
---|
| 1691 | |
---|
| 1692 | /** |
---|
| 1693 | \brief Sets the Total size of the Bar.(ex. The maximum one can download) |
---|
| 1694 | */ |
---|
| 1695 | void ProgressBar::setTotalSize(double totalSize) |
---|
| 1696 | { |
---|
| 1697 | this->totalSize = totalSize; |
---|
| 1698 | } |
---|
| 1699 | |
---|
| 1700 | /** |
---|
| 1701 | \brief Sets the progress maximum is this->totalSize |
---|
| 1702 | */ |
---|
| 1703 | void ProgressBar::setProgress(double progress) |
---|
| 1704 | { |
---|
| 1705 | this->progress = progress; |
---|
| 1706 | |
---|
| 1707 | if (this->progress > this->totalSize) |
---|
| 1708 | this->progress = this->totalSize; |
---|
| 1709 | |
---|
| 1710 | #ifdef HAVE_GTK2 |
---|
| 1711 | gtk_progress_set_value(GTK_PROGRESS(widget), this->progress*100.0/this->totalSize); |
---|
[4133] | 1712 | PRINTF(5)("Progress: %f%%\n", this->progress*100.0/this->totalSize); |
---|
[4046] | 1713 | #else /* HVE_GTK2 */ |
---|
| 1714 | PRINT(0)("Progress: %f%%\n", this->progress*100.0/this->totalSize); |
---|
[3423] | 1715 | #endif /* HAVE_GTK2 */ |
---|
| 1716 | } |
---|
| 1717 | |
---|
| 1718 | /** |
---|
| 1719 | \brief returns the Progress Status |
---|
| 1720 | */ |
---|
| 1721 | double ProgressBar::getProgress(void) |
---|
| 1722 | { |
---|
| 1723 | return this->progress; |
---|
| 1724 | } |
---|
| 1725 | |
---|
[4046] | 1726 | /////////// |
---|
[3423] | 1727 | /* IMAGE */ |
---|
[4046] | 1728 | /////////// |
---|
[3423] | 1729 | /** |
---|
| 1730 | \brief Creates a new Image |
---|
[4030] | 1731 | \param imageName the location of the Image on the Hard Disc |
---|
[3423] | 1732 | */ |
---|
[4030] | 1733 | Image::Image(const char* imageName) |
---|
[3423] | 1734 | { |
---|
[4030] | 1735 | this->init(imageName); |
---|
[3423] | 1736 | |
---|
| 1737 | #ifdef HAVE_GTK2 |
---|
[4030] | 1738 | widget = gtk_image_new_from_file(imageName); |
---|
[3423] | 1739 | #endif /* HAVE_GTK2 */ |
---|
| 1740 | } |
---|
| 1741 | |
---|
| 1742 | /** |
---|
[4030] | 1743 | \brief Creates a new Image |
---|
| 1744 | \param imageData data to the PixBuff |
---|
| 1745 | */ |
---|
| 1746 | Image::Image(char** imageData) |
---|
| 1747 | { |
---|
| 1748 | this->init("pixBuffImage"); |
---|
| 1749 | |
---|
| 1750 | #ifdef HAVE_GTK2 |
---|
| 1751 | widget = gtk_image_new_from_pixbuf(gdk_pixbuf_new_from_xpm_data((const char**)imageData)); |
---|
| 1752 | #endif /* HAVE_GTK2 */ |
---|
| 1753 | } |
---|
| 1754 | |
---|
| 1755 | |
---|
| 1756 | /** |
---|
[3423] | 1757 | \brief destructs an Image. |
---|
| 1758 | */ |
---|
| 1759 | Image::~Image(void) |
---|
| 1760 | { |
---|
[4026] | 1761 | PRINTF(5)("deleting the Image: %s\n", this->title); |
---|
[3423] | 1762 | } |
---|
| 1763 | |
---|
| 1764 | /** |
---|
| 1765 | \brief Initializes a new Image |
---|
[4030] | 1766 | \param name the name to set to the Image |
---|
[3423] | 1767 | */ |
---|
[4030] | 1768 | void Image::init(const char* name) |
---|
[3423] | 1769 | { |
---|
[4071] | 1770 | optionType = GUI_NOTHING; |
---|
[4030] | 1771 | |
---|
| 1772 | if (this->title) |
---|
| 1773 | delete []this->title; |
---|
| 1774 | this->title = new char[strlen(name)+1]; |
---|
| 1775 | strcpy(this->title, name); |
---|
[3423] | 1776 | } |
---|
[4068] | 1777 | |
---|
| 1778 | |
---|
| 1779 | ///////////////// |
---|
| 1780 | /* FILE DIALOG */ |
---|
| 1781 | ///////////////// |
---|
| 1782 | /** |
---|
| 1783 | \brief Creates a new FileDialog |
---|
| 1784 | \param fileDialogName a Name for the Dialog |
---|
| 1785 | */ |
---|
| 1786 | FileDialog::FileDialog(const char* fileDialogName) |
---|
| 1787 | { |
---|
[4071] | 1788 | this->optionType = GUI_NOTHING; |
---|
[4068] | 1789 | this->isOpen = false; |
---|
| 1790 | this->changeOption = NULL; |
---|
| 1791 | this->openUpButton = NULL; |
---|
[4083] | 1792 | this->okObject = NULL; |
---|
| 1793 | this->okFunc = NULL; |
---|
[4068] | 1794 | |
---|
| 1795 | #ifdef HAVE_GTK2 |
---|
| 1796 | this->widget = gtk_file_selection_new(fileDialogName); |
---|
[4083] | 1797 | |
---|
| 1798 | gtk_file_selection_set_select_multiple(GTK_FILE_SELECTION (this->widget), FALSE); |
---|
| 1799 | |
---|
[4068] | 1800 | g_signal_connect(GTK_FILE_SELECTION (this->widget)->cancel_button, |
---|
| 1801 | "button_release_event", |
---|
| 1802 | G_CALLBACK (FileDialog::dialogClose), |
---|
| 1803 | this); |
---|
| 1804 | g_signal_connect(GTK_FILE_SELECTION (this->widget), |
---|
| 1805 | "delete_event", |
---|
| 1806 | G_CALLBACK (FileDialog::dialogClose), |
---|
| 1807 | this); |
---|
| 1808 | g_signal_connect(GTK_FILE_SELECTION (this->widget)->ok_button, |
---|
| 1809 | "button_release_event", |
---|
| 1810 | G_CALLBACK (FileDialog::dialogOK), |
---|
| 1811 | this); |
---|
| 1812 | #endif /* HAVE_GTK2 */ |
---|
| 1813 | if (fileDialogName) |
---|
| 1814 | this->setTitle(fileDialogName); |
---|
| 1815 | } |
---|
| 1816 | |
---|
| 1817 | /** |
---|
| 1818 | \brief destructs a FileDialog |
---|
| 1819 | */ |
---|
| 1820 | FileDialog::~FileDialog(void) |
---|
| 1821 | { |
---|
| 1822 | PRINTF(5)("deleting FileDialog %s\n", this->title); |
---|
| 1823 | } |
---|
| 1824 | |
---|
| 1825 | void FileDialog::setChangeOption(OptionLabel* changeOption) |
---|
| 1826 | { |
---|
| 1827 | this->changeOption = changeOption; |
---|
| 1828 | } |
---|
| 1829 | |
---|
[4083] | 1830 | void FileDialog::setOKFunc(void* okObject, bool(*function)(const char* , void*)) |
---|
| 1831 | { |
---|
| 1832 | this->okObject = okObject; |
---|
| 1833 | this->okFunc = function; |
---|
| 1834 | } |
---|
| 1835 | |
---|
| 1836 | |
---|
[4068] | 1837 | void FileDialog::setOpenUpButton(Button* openUpButton) |
---|
| 1838 | { |
---|
| 1839 | this->openUpButton = openUpButton; |
---|
| 1840 | |
---|
| 1841 | openUpButton->connectSignal("button_release_event", this, FileDialog::dialogOpen); |
---|
| 1842 | } |
---|
| 1843 | |
---|
| 1844 | |
---|
| 1845 | void FileDialog::setDefaultFileName(const char* defaultFileName) |
---|
| 1846 | { |
---|
| 1847 | #ifdef HAVE_GTK2 |
---|
| 1848 | gtk_file_selection_set_filename (GTK_FILE_SELECTION(this->widget), defaultFileName); |
---|
| 1849 | #endif /* HAVE_GTK2 */ |
---|
| 1850 | } |
---|
| 1851 | |
---|
| 1852 | void FileDialog::setMask(const char* mask) |
---|
| 1853 | { |
---|
| 1854 | #ifdef HAVE_GTK2 |
---|
| 1855 | gtk_file_selection_complete(GTK_FILE_SELECTION(this->widget), mask); |
---|
| 1856 | #endif /* HAVE_GTK2 */ |
---|
| 1857 | } |
---|
| 1858 | |
---|
[4083] | 1859 | /** |
---|
| 1860 | \brief disables the File Operator Buttons |
---|
| 1861 | */ |
---|
| 1862 | void FileDialog::disableFileOpts(void) |
---|
| 1863 | { |
---|
| 1864 | #ifdef HAVE_GTK2 |
---|
| 1865 | gtk_file_selection_hide_fileop_buttons(GTK_FILE_SELECTION(this->widget)); |
---|
| 1866 | #endif /* HAVE_GTK2 */ |
---|
| 1867 | } |
---|
| 1868 | |
---|
| 1869 | /** |
---|
| 1870 | \brief The ok-button has been pressed |
---|
| 1871 | */ |
---|
[4068] | 1872 | void FileDialog::okEvent(void) |
---|
| 1873 | { |
---|
[4083] | 1874 | if (this->okFunc) |
---|
| 1875 | { |
---|
[4068] | 1876 | #ifdef HAVE_GTK2 |
---|
[4083] | 1877 | if(this->okFunc((const char*)gtk_file_selection_get_filename(GTK_FILE_SELECTION(this->widget)), this->okObject)) |
---|
| 1878 | this->close(); |
---|
[4068] | 1879 | #endif /* HAVE_GTK2 */ |
---|
[4083] | 1880 | } |
---|
| 1881 | else if (this->changeOption) |
---|
| 1882 | { |
---|
| 1883 | #ifdef HAVE_GTK2 |
---|
| 1884 | changeOption->setValue(gtk_file_selection_get_filename(GTK_FILE_SELECTION(this->widget))); |
---|
| 1885 | #endif /* HAVE_GTK2 */ |
---|
| 1886 | this->close(); |
---|
| 1887 | } |
---|
| 1888 | else |
---|
| 1889 | this->close(); |
---|
[4068] | 1890 | } |
---|
| 1891 | |
---|
[4083] | 1892 | /** |
---|
| 1893 | \biref opens up the FileDialog-Window |
---|
| 1894 | */ |
---|
[4068] | 1895 | void FileDialog::open(void) |
---|
| 1896 | { |
---|
| 1897 | isOpen = true; |
---|
| 1898 | #ifdef HAVE_GTK2 |
---|
| 1899 | gtk_widget_show_all(this->widget); |
---|
| 1900 | gtk_grab_add(this->widget); |
---|
| 1901 | #endif /* HAVE_GTK2 */ |
---|
| 1902 | } |
---|
| 1903 | |
---|
[4083] | 1904 | /** |
---|
| 1905 | \closes the FileDialog-Window |
---|
| 1906 | */ |
---|
[4068] | 1907 | void FileDialog::close(void) |
---|
| 1908 | { |
---|
| 1909 | this->isOpen = false; |
---|
| 1910 | #ifdef HAVE_GTK2 |
---|
| 1911 | gtk_grab_remove(this->widget); |
---|
| 1912 | gtk_widget_hide(this->widget); |
---|
| 1913 | #endif /* HAVE_GTK2 */ |
---|
| 1914 | } |
---|
| 1915 | |
---|
| 1916 | #ifdef HAVE_GTK2 |
---|
| 1917 | gint FileDialog::dialogOK(GtkWidget* widget, GdkEvent* event, void* dialog) |
---|
| 1918 | { |
---|
| 1919 | static_cast<FileDialog*>(dialog)->okEvent(); |
---|
| 1920 | } |
---|
| 1921 | #else /* HAVE_GTK2 */ |
---|
| 1922 | int FileDialog::dialogOK(void* widget, void* event, void* dialog){} |
---|
| 1923 | #endif /* HAVE_GTK2 */ |
---|
| 1924 | |
---|
| 1925 | #ifdef HAVE_GTK2 |
---|
| 1926 | gint FileDialog::dialogOpen(GtkWidget* widget, GdkEvent* event, void* dialog) |
---|
| 1927 | { |
---|
| 1928 | static_cast<FileDialog*>(dialog)->open(); |
---|
| 1929 | } |
---|
| 1930 | #else /* HAVE_GTK2 */ |
---|
| 1931 | int FileDialog::dialogOpen(void* widget, void* event, void* dialog){} |
---|
| 1932 | #endif /* HAVE_GTK2 */ |
---|
| 1933 | |
---|
| 1934 | #ifdef HAVE_GTK2 |
---|
| 1935 | gint FileDialog::dialogClose(GtkWidget* widget, GdkEvent* event, void* dialog) |
---|
| 1936 | { |
---|
| 1937 | static_cast<FileDialog*>(dialog)->close(); |
---|
| 1938 | } |
---|
| 1939 | #else /* HAVE_GTK2 */ |
---|
| 1940 | int FileDialog::dialogClose(void* widget, void* event, void* dialog){} |
---|
| 1941 | #endif /* HAVE_GTK2 */ |
---|