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