[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 | */ |
---|
[3430] | 44 | bool initGUI(int argc, char *argv[]) |
---|
[3164] | 45 | { |
---|
[3430] | 46 | #ifdef HAVE_GTK2 |
---|
| 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 */ |
---|
| 52 | gtk_init(&argc, &argv); |
---|
[3164] | 53 | gtk_rc_parse( "rc" ); |
---|
[3430] | 54 | #endif /* HAVE_GTK2 */ |
---|
[3164] | 55 | } |
---|
[3187] | 56 | |
---|
[3430] | 57 | |
---|
[3187] | 58 | /** |
---|
[3430] | 59 | \brief enters the GUI's main-loop |
---|
[3187] | 60 | */ |
---|
[3430] | 61 | bool mainloopGUI(void) |
---|
[3164] | 62 | { |
---|
[3430] | 63 | #ifdef HAVE_GTK2 |
---|
| 64 | gdk_threads_enter(); |
---|
[3164] | 65 | gtk_main(); |
---|
[3430] | 66 | gdk_threads_leave(); |
---|
| 67 | delete Window::mainWindow; |
---|
| 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 | } |
---|
| 125 | #endif /* HAVE_GTK2 */ |
---|
| 126 | |
---|
[3164] | 127 | } |
---|
[3165] | 128 | |
---|
[3430] | 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 | */ |
---|
[3430] | 140 | Widget::~Widget(void) |
---|
[3144] | 141 | { |
---|
[3430] | 142 | this->destroy(); |
---|
[3144] | 143 | } |
---|
| 144 | |
---|
| 145 | /** |
---|
| 146 | \brief Initializes a widget. |
---|
| 147 | Initializes the next Pointer and the other Widget-specific Defaults. |
---|
| 148 | */ |
---|
[3430] | 149 | void Widget::init(void) |
---|
[3144] | 150 | { |
---|
| 151 | next = NULL; |
---|
[3430] | 152 | this->title = NULL; |
---|
[3144] | 153 | return; |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | /** |
---|
[3430] | 157 | \brief Destroys a Widget |
---|
| 158 | */ |
---|
| 159 | void Widget::destroy(void) |
---|
| 160 | { |
---|
| 161 | if (this->title) |
---|
| 162 | { |
---|
| 163 | delete []this->title; |
---|
| 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(); |
---|
| 177 | // delete this->widget; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | /** |
---|
[3144] | 181 | \brief makes the widget visible. |
---|
| 182 | */ |
---|
[3430] | 183 | void Widget::show(void) |
---|
[3144] | 184 | { |
---|
[3165] | 185 | #ifdef HAVE_GTK2 |
---|
[3430] | 186 | gtk_widget_show(this->widget); |
---|
[3165] | 187 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 188 | } |
---|
| 189 | |
---|
| 190 | /** |
---|
| 191 | \brief hides the widget. |
---|
| 192 | */ |
---|
[3430] | 193 | void Widget::hide(void) |
---|
[3144] | 194 | { |
---|
[3165] | 195 | #ifdef HAVE_GTK2 |
---|
[3430] | 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 |
---|
[3430] | 208 | gtk_widget_set_usize(this->widget, width, height); |
---|
[3165] | 209 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 210 | } |
---|
| 211 | |
---|
[3430] | 212 | /** |
---|
| 213 | \brief searches through widgets for a Name. |
---|
[3144] | 214 | */ |
---|
[3430] | 215 | Widget* Widget::findWidgetByName(char* name, unsigned int depth) |
---|
[3144] | 216 | { |
---|
[3430] | 217 | |
---|
| 218 | if (this->title && !strcmp(this->title, name)) |
---|
| 219 | return this; |
---|
| 220 | |
---|
| 221 | if (this->isOption < 0 && static_cast<Packer*>(this)->down) |
---|
| 222 | { |
---|
| 223 | Widget* tmp = static_cast<Packer*>(this)->down->findWidgetByName(name, depth+1); |
---|
| 224 | if (tmp) |
---|
| 225 | return tmp; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | if (depth>0 && this->next) |
---|
| 229 | return this->next->findWidgetByName(name, depth); |
---|
| 230 | |
---|
| 231 | return NULL; |
---|
[3144] | 232 | } |
---|
| 233 | |
---|
| 234 | /** |
---|
[3430] | 235 | \brief Moves through all the Widgets downwards from this and executes the function on them. |
---|
| 236 | \param function must be of type void and takes a Widget* as an Input. |
---|
| 237 | \param depth the current depth. if > 0 then the next Widget will also be walked through. |
---|
[3144] | 238 | */ |
---|
[3430] | 239 | void Widget::walkThrough(void(*function)(Widget*), unsigned int depth) |
---|
[3144] | 240 | { |
---|
[3430] | 241 | function(this); |
---|
| 242 | if (this->isOption < 0) |
---|
| 243 | { |
---|
| 244 | static_cast<Packer*>(this)->down->walkThrough(function, depth+1); |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | if (this->next && depth != 0) |
---|
| 248 | this->next->walkThrough(function, depth); |
---|
[3144] | 249 | } |
---|
| 250 | |
---|
| 251 | /** |
---|
[3430] | 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. |
---|
| 255 | \param depth the current depth. if > 0 then the next Widget will also be walked through. |
---|
[3144] | 256 | */ |
---|
[3430] | 257 | void Widget::walkThrough(void(*function)(Widget*, void*), void* data, unsigned int depth) |
---|
[3144] | 258 | { |
---|
[3430] | 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); |
---|
[3144] | 266 | } |
---|
| 267 | |
---|
[3430] | 268 | /** |
---|
| 269 | \brief This is for listing the options of "widget" |
---|
| 270 | \param widget specifies the widget that should be listed |
---|
[3144] | 271 | */ |
---|
[3430] | 272 | void Widget::listOptionsAndGroups(Widget* widget) |
---|
[3144] | 273 | { |
---|
[3430] | 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) |
---|
| 277 | cout << " " << static_cast<Option*>(widget)->title <<" is : " << static_cast<Option*>(widget)->value <<endl; |
---|
| 278 | else if (widget->isOption == 5) |
---|
| 279 | cout << " " << static_cast<Option*>(widget)->title <<" is : " << static_cast<OptionLabel*>(widget)->cValue <<endl; |
---|
[3144] | 280 | } |
---|
| 281 | |
---|
[3430] | 282 | /** |
---|
| 283 | \brief This is for listing the options of "widget" |
---|
| 284 | \param widget specifies the widget that should be listed |
---|
| 285 | */ |
---|
| 286 | void Widget::listOptions(Widget* widget) |
---|
[3156] | 287 | { |
---|
[3430] | 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; |
---|
[3156] | 292 | } |
---|
| 293 | |
---|
[3430] | 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. |
---|
[3144] | 298 | */ |
---|
[3430] | 299 | void Widget::listOptions(Widget* widget, void* data) |
---|
[3144] | 300 | { |
---|
[3430] | 301 | |
---|
| 302 | if (widget->isOption >= 1 && widget->isOption <= 3) |
---|
[3144] | 303 | { |
---|
[3430] | 304 | int* count =(int*)data; |
---|
| 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 | { |
---|
| 310 | int* count =(int*)data; |
---|
| 311 | *count = *count +1; |
---|
| 312 | cout << *count << ": " << static_cast<Option*>(widget)->title <<" is : " << static_cast<OptionLabel*>(widget)->cValue <<endl; |
---|
| 313 | } |
---|
| 314 | } |
---|
[3144] | 315 | |
---|
[3430] | 316 | /** |
---|
| 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) |
---|
| 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; |
---|
[3144] | 343 | } |
---|
| 344 | |
---|
| 345 | /** |
---|
[3430] | 346 | \brief This is for listing the groups of "widget" |
---|
[3144] | 347 | \param widget specifies the widget that should be listed |
---|
| 348 | */ |
---|
[3430] | 349 | void Widget::listGroups(Widget* widget) |
---|
[3144] | 350 | { |
---|
[3166] | 351 | if (widget->isOption < 0 && static_cast<Packer*>(widget)->groupName) |
---|
| 352 | cout << "[" << static_cast<Packer*>(widget)->groupName << "]\n"; |
---|
[3144] | 353 | } |
---|
| 354 | |
---|
| 355 | /** |
---|
[3430] | 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 |
---|
| 358 | \param data the Counter, that will show the number(this function will raise it by one if a Group is fount. |
---|
| 359 | */ |
---|
| 360 | void Widget::listGroups(Widget* widget, void* data) |
---|
| 361 | { |
---|
| 362 | if (widget->isOption < 0 && static_cast<Packer*>(widget)->groupName) |
---|
| 363 | { |
---|
| 364 | int* count =(int*)data; |
---|
| 365 | *count = *count +1; |
---|
| 366 | cout << *count <<": [" << static_cast<Packer*>(widget)->groupName << "]\n"; |
---|
| 367 | } |
---|
| 368 | } |
---|
| 369 | |
---|
| 370 | /** |
---|
| 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) |
---|
| 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 | */ |
---|
[3430] | 401 | void Widget::setOptions(Widget* widget) |
---|
[3144] | 402 | { |
---|
[3147] | 403 | if (widget->isOption >= 1) |
---|
[3430] | 404 | static_cast<Option*>(widget)->redraw(); |
---|
[3144] | 405 | } |
---|
| 406 | |
---|
[3430] | 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 | { |
---|
| 414 | Option* option =(Option*)widget; |
---|
| 415 | char* name =(char*)flagName; |
---|
| 416 | char* value = NULL; |
---|
| 417 | bool found = false; |
---|
| 418 | // check if long flag matches |
---|
| 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] == '=') )) |
---|
| 420 | { |
---|
| 421 | found = true; |
---|
| 422 | if (name[strlen(option->flagName)+2] == '=') |
---|
| 423 | { |
---|
| 424 | value = name+strlen(option->flagName)+3; |
---|
| 425 | } |
---|
| 426 | } |
---|
| 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 |
---|
| 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 |
---|
[3430] | 455 | /** |
---|
| 456 | \brief Connect any signal to any given Sub-widget |
---|
| 457 | */ |
---|
| 458 | gulong Widget::connectSignal(char* event, gint(*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
| 459 | { |
---|
| 460 | return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), NULL); |
---|
| 461 | } |
---|
[3187] | 462 | |
---|
| 463 | /** |
---|
[3430] | 464 | \brief Connect a signal with additionally passing the whole Object |
---|
| 465 | */ |
---|
| 466 | gulong Widget::connectSignal(char* event, gint(*signal)( GtkWidget*, Widget *)) |
---|
| 467 | { |
---|
| 468 | return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), this); |
---|
| 469 | } |
---|
| 470 | |
---|
| 471 | /** |
---|
| 472 | \brief Connect a signal with additionally passing a whole external Object |
---|
| 473 | */ |
---|
| 474 | gulong Widget::connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, GdkEvent*, void *)) |
---|
| 475 | { |
---|
| 476 | return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), extObj); |
---|
| 477 | } |
---|
| 478 | |
---|
| 479 | /** |
---|
| 480 | \brief Connect a signal with additionally passing a whole external Object |
---|
| 481 | */ |
---|
| 482 | gulong Widget::connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, void *)) |
---|
| 483 | { |
---|
| 484 | return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), extObj); |
---|
| 485 | } |
---|
| 486 | |
---|
| 487 | /** |
---|
| 488 | \brief Connect a signal with additionally passing a whole external Object |
---|
| 489 | */ |
---|
| 490 | gulong Widget::connectSignal(char* event, void* extObj, gint(*signal)(GtkWidget*, GdkEventKey*, void *)) |
---|
| 491 | { |
---|
| 492 | return g_signal_connect(G_OBJECT(this->widget), event, G_CALLBACK(signal), extObj); |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | void Widget::disconnectSignal(gulong signalID) |
---|
| 496 | { |
---|
| 497 | g_signal_handler_disconnect(G_OBJECT(this->widget), signalID); |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | /** |
---|
[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 | */ |
---|
[3430] | 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 | */ |
---|
[3430] | 521 | void Packer::init(void) |
---|
[3144] | 522 | { |
---|
[3430] | 523 | this->down = NULL; |
---|
| 524 | this->groupName = NULL; |
---|
[3144] | 525 | |
---|
| 526 | |
---|
| 527 | static_cast<Widget*>(this)->init(); |
---|
| 528 | return; |
---|
| 529 | } |
---|
| 530 | |
---|
| 531 | /** |
---|
[3430] | 532 | \brief Destroys a Packer. |
---|
| 533 | */ |
---|
| 534 | void Packer::destroy(void) |
---|
| 535 | { |
---|
| 536 | PRINTF(4)("deleting the Packer part.\n"); |
---|
| 537 | |
---|
| 538 | if (this->groupName) |
---|
| 539 | delete []this->groupName; |
---|
| 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 | */ |
---|
[3430] | 553 | void Packer::setGroupName(char* name) |
---|
[3144] | 554 | { |
---|
[3430] | 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 | */ |
---|
[3430] | 565 | char* Packer::getGroupName(void) |
---|
[3144] | 566 | { |
---|
[3430] | 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 | */ |
---|
[3430] | 577 | void Container::init(void) |
---|
[3144] | 578 | { |
---|
[3430] | 579 | this->isOption = -1; |
---|
[3144] | 580 | |
---|
| 581 | static_cast<Packer*>(this)->init(); |
---|
| 582 | |
---|
| 583 | return; |
---|
| 584 | } |
---|
| 585 | |
---|
| 586 | /** |
---|
[3430] | 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 | */ |
---|
[3430] | 602 | void Container::fill(Widget *lowerWidget) |
---|
[3144] | 603 | { |
---|
| 604 | if (this->down == NULL) |
---|
| 605 | { |
---|
[3165] | 606 | #ifdef HAVE_GTK2 |
---|
[3430] | 607 | gtk_container_add(GTK_CONTAINER(this->widget), lowerWidget->widget); |
---|
[3165] | 608 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 609 | this->down = lowerWidget; |
---|
| 610 | } |
---|
| 611 | else |
---|
[3430] | 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 | |
---|
[3430] | 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 |
---|
[3430] | 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; |
---|
[3430] | 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 | */ |
---|
[3430] | 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 | */ |
---|
[3430] | 655 | |
---|
| 656 | Window::Window(char* windowName) |
---|
[3144] | 657 | { |
---|
| 658 | this->init(); |
---|
[3430] | 659 | this->setTitle(windowName); |
---|
[3144] | 660 | } |
---|
| 661 | |
---|
| 662 | /** |
---|
[3430] | 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 | */ |
---|
[3430] | 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 |
---|
[3430] | 683 | widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); |
---|
| 684 | gtk_window_set_policy(GTK_WINDOW(widget), TRUE, TRUE, TRUE); |
---|
[3144] | 685 | #if !defined(__WIN32__) |
---|
[3430] | 686 | // gtk_window_set_decorated(GTK_WINDOW(widget), FALSE); |
---|
[3144] | 687 | #endif |
---|
[3430] | 688 | gtk_container_set_border_width(GTK_CONTAINER(widget), 3); |
---|
[3165] | 689 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 690 | } |
---|
| 691 | |
---|
| 692 | /** |
---|
[3430] | 693 | \brief Destroys a Window. |
---|
| 694 | */ |
---|
| 695 | void Window::destroy(void) |
---|
| 696 | { |
---|
| 697 | if (this->title) |
---|
| 698 | PRINTF(3)("deleting the Window: %s\n", this->title); |
---|
| 699 | else |
---|
| 700 | PRINTF(3)("deleting the Window.\n"); |
---|
| 701 | // this->hide(); |
---|
| 702 | static_cast<Container*>(this)->destroy(); |
---|
| 703 | |
---|
| 704 | } |
---|
| 705 | |
---|
| 706 | /** |
---|
[3144] | 707 | \brief Shows all Widgets that are included within this->widget. |
---|
| 708 | */ |
---|
[3430] | 709 | void Window::showall(void) |
---|
[3144] | 710 | { |
---|
[3430] | 711 | if (!this->isOpen) |
---|
[3144] | 712 | { |
---|
[3430] | 713 | // printf("showall\n"); |
---|
[3165] | 714 | #ifdef HAVE_GTK2 |
---|
[3430] | 715 | gtk_widget_show_all(this->widget); |
---|
[3165] | 716 | #endif /* HAVE_GTK2 */ |
---|
[3430] | 717 | this->isOpen = true; |
---|
[3144] | 718 | } |
---|
| 719 | else |
---|
| 720 | { |
---|
[3430] | 721 | // printf("showone\n"); |
---|
[3165] | 722 | #ifdef HAVE_GTK2 |
---|
[3430] | 723 | gtk_widget_show(this->widget); |
---|
[3165] | 724 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 725 | } |
---|
| 726 | } |
---|
| 727 | |
---|
| 728 | /** |
---|
| 729 | \brief Set The Window-title to title |
---|
| 730 | \param title title the Window should get. |
---|
| 731 | */ |
---|
[3430] | 732 | void Window::setTitle(char* title) |
---|
[3144] | 733 | { |
---|
[3430] | 734 | if (this->title) |
---|
| 735 | delete []this->title; |
---|
| 736 | this->title = new char[strlen(title)+1]; |
---|
| 737 | strcpy(this->title, title); |
---|
[3165] | 738 | #ifdef HAVE_GTK2 |
---|
[3430] | 739 | gtk_window_set_title(GTK_WINDOW(widget), title); |
---|
[3165] | 740 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 741 | } |
---|
| 742 | |
---|
| 743 | /** |
---|
[3147] | 744 | \brief opens up a Window and fixes the Focus to it |
---|
| 745 | */ |
---|
[3430] | 746 | void Window::open(void) |
---|
[3147] | 747 | { |
---|
[3148] | 748 | if (this != mainWindow) |
---|
| 749 | { |
---|
| 750 | isOpen = true; |
---|
[3165] | 751 | #ifdef HAVE_GTK2 |
---|
[3430] | 752 | gtk_widget_show_all(this->widget); |
---|
| 753 | gtk_grab_add(this->widget); |
---|
[3165] | 754 | #endif /* HAVE_GTK2 */ |
---|
[3148] | 755 | } |
---|
[3147] | 756 | } |
---|
| 757 | |
---|
| 758 | /** |
---|
| 759 | \brief closes up a Window and removes the Focus from it |
---|
| 760 | */ |
---|
[3430] | 761 | void Window::close(void) |
---|
[3147] | 762 | { |
---|
[3148] | 763 | if (this != mainWindow) |
---|
| 764 | { |
---|
[3430] | 765 | this->isOpen = false; |
---|
[3165] | 766 | #ifdef HAVE_GTK2 |
---|
[3430] | 767 | gtk_grab_remove(this->widget); |
---|
| 768 | gtk_widget_hide(this->widget); |
---|
[3165] | 769 | #endif /* HAVE_GTK2 */ |
---|
[3148] | 770 | } |
---|
[3147] | 771 | } |
---|
| 772 | |
---|
[3165] | 773 | #ifdef HAVE_GTK2 |
---|
[3147] | 774 | /** |
---|
[3430] | 775 | \brief opens up a window(not topmost Window). |
---|
[3153] | 776 | this is the Signal that does it. !!SIGNALS ARE STATIC!! |
---|
[3187] | 777 | \param widget the widget that did it. |
---|
| 778 | \param event the event that did it. |
---|
[3153] | 779 | \param window the Window that should be opened |
---|
| 780 | */ |
---|
[3430] | 781 | gint Window::windowOpen(GtkWidget *widget, GdkEvent* event, void* window) |
---|
[3153] | 782 | { |
---|
| 783 | static_cast<Window*>(window)->open(); |
---|
| 784 | } |
---|
| 785 | |
---|
| 786 | /** |
---|
[3430] | 787 | \brief closes a window(not topmost Window). |
---|
[3153] | 788 | this is the Signal that does it. !!SIGNALS ARE STATIC!! |
---|
| 789 | \param widget the widget that did it! |
---|
| 790 | \param event the event that did it! |
---|
| 791 | \param window the Window that should be closed |
---|
| 792 | */ |
---|
[3430] | 793 | gint Window::windowClose(GtkWidget *widget, GdkEvent* event, void* window) |
---|
[3153] | 794 | { |
---|
| 795 | static_cast<Window*>(window)->close(); |
---|
| 796 | } |
---|
[3156] | 797 | |
---|
[3165] | 798 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 799 | |
---|
| 800 | |
---|
| 801 | /* FRAME */ |
---|
| 802 | |
---|
| 803 | /** |
---|
| 804 | \brief Creates a new Frame without a name |
---|
| 805 | */ |
---|
[3430] | 806 | Frame::Frame(void) |
---|
[3144] | 807 | { |
---|
| 808 | this->init(); |
---|
| 809 | } |
---|
| 810 | |
---|
| 811 | /** |
---|
| 812 | \brief Creates a new Frame with name title |
---|
| 813 | */ |
---|
[3430] | 814 | Frame::Frame(char* title) |
---|
[3144] | 815 | { |
---|
| 816 | this->init(); |
---|
| 817 | this->setTitle(title); |
---|
| 818 | } |
---|
| 819 | |
---|
[3430] | 820 | /** |
---|
| 821 | \brief destrcucts a Frame |
---|
| 822 | */ |
---|
| 823 | Frame::~Frame(void) |
---|
| 824 | { |
---|
| 825 | this->destroy(); |
---|
| 826 | } |
---|
| 827 | |
---|
[3144] | 828 | /** |
---|
| 829 | \brief Initializes a new Frame with default settings |
---|
| 830 | */ |
---|
[3430] | 831 | void Frame::init(void) |
---|
[3144] | 832 | { |
---|
| 833 | static_cast<Container*>(this)->init(); |
---|
[3165] | 834 | |
---|
| 835 | #ifdef HAVE_GTK2 |
---|
[3430] | 836 | this->widget = gtk_frame_new(""); |
---|
| 837 | gtk_container_set_border_width(GTK_CONTAINER(this->widget), 3); |
---|
[3165] | 838 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 839 | } |
---|
| 840 | |
---|
| 841 | /** |
---|
[3430] | 842 | \brief Destroys a Frame. |
---|
| 843 | */ |
---|
| 844 | void Frame::destroy(void) |
---|
| 845 | { |
---|
| 846 | if (this->title) |
---|
| 847 | PRINTF(3)("deleting the Frame: %s\n", this->title); |
---|
| 848 | else |
---|
| 849 | PRINTF(3)("deleting the Frame.\n"); |
---|
| 850 | |
---|
| 851 | static_cast<Container*>(this)->destroy(); |
---|
| 852 | } |
---|
| 853 | |
---|
| 854 | /** |
---|
[3144] | 855 | \brief Sets the Frames name to title |
---|
| 856 | \param title The title the Frame should get. |
---|
| 857 | */ |
---|
[3430] | 858 | void Frame::setTitle(char* title) |
---|
[3144] | 859 | { |
---|
[3430] | 860 | if (this->title) |
---|
| 861 | delete []this->title; |
---|
| 862 | this->title = new char[strlen(title)+1]; |
---|
| 863 | strcpy(this->title, title); |
---|
[3165] | 864 | #ifdef HAVE_GTK2 |
---|
[3430] | 865 | gtk_frame_set_label(GTK_FRAME(widget), title); |
---|
[3165] | 866 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 867 | } |
---|
| 868 | |
---|
| 869 | // EVENTBOX // |
---|
| 870 | |
---|
| 871 | /** |
---|
| 872 | \brief Creates a new EventBox with default settings. |
---|
| 873 | */ |
---|
[3430] | 874 | EventBox::EventBox(void) |
---|
[3144] | 875 | { |
---|
| 876 | this->init(); |
---|
| 877 | } |
---|
[3430] | 878 | |
---|
[3144] | 879 | /** |
---|
| 880 | \brief Creates a new EventBox with name title |
---|
[3430] | 881 | \param title title the Eventbox should get(only data-structure-internal) |
---|
[3144] | 882 | */ |
---|
[3430] | 883 | EventBox::EventBox(char* title) |
---|
[3144] | 884 | { |
---|
| 885 | this->init(); |
---|
| 886 | this->setTitle(title); |
---|
| 887 | } |
---|
| 888 | |
---|
| 889 | /** |
---|
[3430] | 890 | \brief destructs an EventBox. |
---|
| 891 | */ |
---|
| 892 | EventBox::~EventBox(void) |
---|
| 893 | { |
---|
| 894 | this->destroy(); |
---|
| 895 | |
---|
| 896 | } |
---|
| 897 | |
---|
| 898 | /** |
---|
[3144] | 899 | \brief Initializes a new EventBox |
---|
| 900 | */ |
---|
| 901 | void EventBox::init(void) |
---|
| 902 | { |
---|
[3430] | 903 | this->isOption = -1; |
---|
[3144] | 904 | |
---|
| 905 | static_cast<Container*>(this)->init(); |
---|
| 906 | |
---|
[3165] | 907 | #ifdef HAVE_GTK2 |
---|
[3430] | 908 | this->widget = gtk_event_box_new(); |
---|
| 909 | gtk_container_set_border_width(GTK_CONTAINER(this->widget), 3); |
---|
[3165] | 910 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 911 | } |
---|
| 912 | |
---|
| 913 | /** |
---|
[3430] | 914 | \brief Destroys an EventBox. |
---|
[3144] | 915 | */ |
---|
[3430] | 916 | void EventBox::destroy(void) |
---|
| 917 | { |
---|
| 918 | if (this->title) |
---|
| 919 | PRINTF(3)("deleting the EventBox: %s\n", this->title); |
---|
| 920 | else |
---|
| 921 | PRINTF(3)("deleting the EventBox.\n"); |
---|
| 922 | |
---|
| 923 | static_cast<Container*>(this)->destroy(); |
---|
| 924 | } |
---|
| 925 | |
---|
| 926 | /** |
---|
| 927 | \brief Sets the Title of the EventBox(not implemented) |
---|
| 928 | \param title Name the EventBox should get(only datastructure-internal). |
---|
| 929 | */ |
---|
| 930 | void EventBox::setTitle(char* title) |
---|
[3144] | 931 | { |
---|
[3430] | 932 | if (this->title) |
---|
| 933 | delete []this->title; |
---|
| 934 | this->title = new char[strlen(title)+1]; |
---|
| 935 | strcpy(this->title, title); |
---|
[3144] | 936 | } |
---|
| 937 | |
---|
| 938 | /* BOX */ |
---|
| 939 | |
---|
| 940 | /** |
---|
| 941 | \brief Creates a new horizontal Box |
---|
| 942 | */ |
---|
[3430] | 943 | Box::Box(void) |
---|
[3144] | 944 | { |
---|
| 945 | this->init('h'); |
---|
| 946 | } |
---|
| 947 | |
---|
| 948 | /** |
---|
| 949 | \brief Creates a new Box of type boxtype |
---|
| 950 | \param boxtype if 'v' the Box will be vertically, if 'h' the Box will be horizontally |
---|
| 951 | */ |
---|
[3430] | 952 | Box::Box(char boxtype) |
---|
[3144] | 953 | { |
---|
| 954 | this->init(boxtype); |
---|
| 955 | } |
---|
| 956 | |
---|
| 957 | /** |
---|
[3430] | 958 | \brief destructs a Box. |
---|
| 959 | */ |
---|
| 960 | Box::~Box(void) |
---|
| 961 | { |
---|
| 962 | this->destroy(); |
---|
| 963 | } |
---|
| 964 | |
---|
| 965 | /** |
---|
[3144] | 966 | \brief Initializes a new Box with type boxtype |
---|
| 967 | \param boxtype see Box(char boxtype) |
---|
| 968 | */ |
---|
| 969 | void Box::init(char boxtype) |
---|
| 970 | { |
---|
[3430] | 971 | this->isOption = -2; |
---|
[3144] | 972 | |
---|
| 973 | static_cast<Packer*>(this)->init(); |
---|
[3165] | 974 | #ifdef HAVE_GTK2 |
---|
[3144] | 975 | if (boxtype == 'v') |
---|
| 976 | { |
---|
[3430] | 977 | this->widget = gtk_vbox_new(FALSE, 0); |
---|
[3144] | 978 | } |
---|
| 979 | else |
---|
| 980 | { |
---|
[3430] | 981 | this->widget = gtk_hbox_new(FALSE, 0); |
---|
[3144] | 982 | } |
---|
[3165] | 983 | #endif /* HAVE_GTK2 */ |
---|
[3430] | 984 | } |
---|
[3165] | 985 | |
---|
[3430] | 986 | /** |
---|
| 987 | \brief Destroys a Box. |
---|
| 988 | */ |
---|
| 989 | void Box::destroy(void) |
---|
| 990 | { |
---|
| 991 | if (this->title) |
---|
| 992 | PRINTF(3)("deleting the Box: %s\n", this->title); |
---|
| 993 | else |
---|
| 994 | PRINTF(3)("deleting the Box.\n"); |
---|
| 995 | |
---|
| 996 | static_cast<Packer*>(this)->destroy(); |
---|
[3144] | 997 | } |
---|
| 998 | |
---|
| 999 | /** |
---|
| 1000 | \brief Fills a box with a given Widget. |
---|
[3187] | 1001 | \param lowerWidget the next Widget that should be appendet to this Box |
---|
| 1002 | |
---|
[3144] | 1003 | 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 |
---|
| 1004 | */ |
---|
[3430] | 1005 | void Box::fill(Widget* lowerWidget) |
---|
[3144] | 1006 | { |
---|
[3165] | 1007 | #ifdef HAVE_GTK2 |
---|
[3430] | 1008 | gtk_box_pack_start(GTK_BOX(this->widget), lowerWidget->widget, TRUE, TRUE, 0); |
---|
[3165] | 1009 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1010 | if (this->down == NULL) |
---|
| 1011 | this->down = lowerWidget; |
---|
| 1012 | else |
---|
| 1013 | { |
---|
| 1014 | Widget* tmp; |
---|
| 1015 | tmp = this->down; |
---|
[3430] | 1016 | while(tmp->next != NULL) |
---|
[3144] | 1017 | { |
---|
| 1018 | tmp = tmp->next; |
---|
| 1019 | } |
---|
| 1020 | tmp->next = lowerWidget; |
---|
| 1021 | } |
---|
| 1022 | } |
---|
| 1023 | |
---|
| 1024 | /** |
---|
[3430] | 1025 | \brief Sets the Title of a Box. |
---|
| 1026 | \param title the new Title to set. |
---|
[3144] | 1027 | */ |
---|
[3430] | 1028 | void Box::setTitle(char* title) |
---|
[3144] | 1029 | { |
---|
[3430] | 1030 | if (this->title) |
---|
| 1031 | delete []this->title; |
---|
| 1032 | this->title = new char[strlen(title)+1]; |
---|
| 1033 | strcpy(this->title, title); |
---|
[3144] | 1034 | } |
---|
| 1035 | |
---|
| 1036 | /* OPTION */ |
---|
| 1037 | |
---|
| 1038 | /** |
---|
| 1039 | \brief Initializes a new Option. |
---|
| 1040 | sets all Option-Specific-Values to their defaults. |
---|
| 1041 | */ |
---|
[3430] | 1042 | void Option::init(void) |
---|
[3144] | 1043 | { |
---|
[3430] | 1044 | this->value = 0; |
---|
| 1045 | this->flagName = NULL; |
---|
| 1046 | this->flagNameShort = NULL; |
---|
| 1047 | this->saveable = false; |
---|
| 1048 | this->defaultValue = 0; |
---|
[3144] | 1049 | |
---|
| 1050 | static_cast<Widget*>(this)->init(); |
---|
| 1051 | |
---|
| 1052 | return; |
---|
| 1053 | } |
---|
| 1054 | |
---|
| 1055 | /** |
---|
[3430] | 1056 | \brief Destroys an Option. |
---|
| 1057 | */ |
---|
| 1058 | void Option::destroy(void) |
---|
| 1059 | { |
---|
| 1060 | PRINTF(4)("deleting the Option Part.\n"); |
---|
| 1061 | if (this->flagName) |
---|
| 1062 | delete []this->flagName; |
---|
| 1063 | if (this->flagNameShort) |
---|
| 1064 | delete []this->flagNameShort; |
---|
| 1065 | |
---|
| 1066 | static_cast<Widget*>(this)->destroy(); |
---|
| 1067 | } |
---|
| 1068 | |
---|
| 1069 | /** |
---|
[3144] | 1070 | \brief This sets The FlagName of an Option and defines its default Values |
---|
[3187] | 1071 | !! Options will be saved if flagname is different from NULL !! |
---|
[3144] | 1072 | \param flagname the Name that will be displayed in the output |
---|
[3430] | 1073 | \param defaultvalue the default Value for this Option(see definition of defaultvalue |
---|
[3144] | 1074 | */ |
---|
[3430] | 1075 | void Option::setFlagName(char* flagname, int defaultvalue) |
---|
[3144] | 1076 | { |
---|
[3430] | 1077 | if (this->flagName) |
---|
| 1078 | delete this->flagName; |
---|
| 1079 | this->flagName = new char [strlen(flagname)+1]; |
---|
| 1080 | strcpy(this->flagName, flagname); |
---|
| 1081 | this->defaultValue = defaultvalue; |
---|
[3166] | 1082 | |
---|
[3430] | 1083 | // cout << "Set Flagname of " << this->title << " to " << flagname << endl; |
---|
[3144] | 1084 | } |
---|
| 1085 | |
---|
| 1086 | /** |
---|
[3430] | 1087 | \brief see Option::setFlagName(char* flagname, int defaultvalue) |
---|
[3144] | 1088 | \param flagname the Name that will be displayed in the output |
---|
[3430] | 1089 | \param defaultvalue the default Value for this Option(see definition of defaultvalue |
---|
[3144] | 1090 | \param flagnameshort a short flagname to be displayed in the output |
---|
| 1091 | */ |
---|
[3430] | 1092 | void Option::setFlagName(char* flagname, char* flagnameshort, int defaultvalue) |
---|
[3144] | 1093 | { |
---|
[3430] | 1094 | if (this->flagName) |
---|
| 1095 | delete []this->flagName; |
---|
| 1096 | this->flagName = new char [strlen(flagname)+1]; |
---|
| 1097 | strcpy(this->flagName, flagname); |
---|
[3158] | 1098 | |
---|
[3430] | 1099 | if (this->flagNameShort) |
---|
| 1100 | delete []this->flagNameShort; |
---|
| 1101 | this->flagNameShort = new char [strlen(flagnameshort)+1]; |
---|
| 1102 | strcpy(this->flagNameShort, flagnameshort); |
---|
| 1103 | this->defaultValue = defaultvalue; |
---|
| 1104 | // cout << "Set Flagname of " << this->title << " to " << flagname << endl; |
---|
[3144] | 1105 | } |
---|
| 1106 | |
---|
[3430] | 1107 | /** |
---|
| 1108 | \brief Sets the saveable-state of the option to true. |
---|
| 1109 | */ |
---|
| 1110 | void Option::saveability(void) |
---|
| 1111 | { |
---|
| 1112 | this->saveable = true; |
---|
| 1113 | } |
---|
[3144] | 1114 | |
---|
[3430] | 1115 | /** |
---|
| 1116 | \brief Sets the saveable-state of the option. |
---|
| 1117 | \param isSaveable the saveable-state to set. |
---|
| 1118 | */ |
---|
| 1119 | void Option::saveability(bool isSaveable) |
---|
| 1120 | { |
---|
| 1121 | this->saveable = isSaveable; |
---|
| 1122 | } |
---|
| 1123 | |
---|
| 1124 | /** |
---|
| 1125 | \returns The saveable-state. |
---|
| 1126 | */ |
---|
| 1127 | bool Option::isSaveable(void) |
---|
| 1128 | { |
---|
| 1129 | return this->saveable; |
---|
| 1130 | } |
---|
| 1131 | |
---|
| 1132 | #ifdef HAVE_GTK2 |
---|
| 1133 | /** |
---|
| 1134 | \brief Signal OptionChange writes the Value from the Slider to its Object-Database. |
---|
| 1135 | \param widget The widget(Slider) that has a changed Value |
---|
| 1136 | \param slider the Slider-Object that should receive the change. |
---|
| 1137 | */ |
---|
| 1138 | gint Option::OptionChange(GtkWidget *widget, Widget* option) |
---|
| 1139 | { |
---|
| 1140 | static_cast<Option*>(option)->changeOption(); |
---|
| 1141 | flags->setTextFromFlags(Window::mainWindow); //// must be different !!! |
---|
| 1142 | } |
---|
| 1143 | #endif /* HAVE_GTK2 */ |
---|
| 1144 | |
---|
| 1145 | |
---|
[3144] | 1146 | /* BUTTON */ |
---|
| 1147 | |
---|
| 1148 | /** |
---|
| 1149 | \brief Creates a new Button with a buttonname |
---|
| 1150 | \param buttonname sets the Name of the Button |
---|
| 1151 | */ |
---|
| 1152 | Button::Button(char* buttonname) |
---|
| 1153 | { |
---|
| 1154 | this->init(); |
---|
| 1155 | this->setTitle(buttonname); |
---|
| 1156 | } |
---|
| 1157 | |
---|
| 1158 | /** |
---|
[3430] | 1159 | \brief destructs a Button. |
---|
| 1160 | */ |
---|
| 1161 | Button::~Button(void) |
---|
| 1162 | { |
---|
| 1163 | this->destroy(); |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | /** |
---|
[3144] | 1167 | \brief Initializes a new Button |
---|
| 1168 | */ |
---|
| 1169 | void Button::init(void) |
---|
| 1170 | { |
---|
[3147] | 1171 | isOption = 0; |
---|
[3144] | 1172 | |
---|
| 1173 | static_cast<Option*>(this)->init(); |
---|
| 1174 | |
---|
[3165] | 1175 | #ifdef HAVE_GTK2 |
---|
[3430] | 1176 | widget = gtk_button_new_with_label(""); |
---|
[3165] | 1177 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1178 | } |
---|
| 1179 | |
---|
| 1180 | /** |
---|
[3430] | 1181 | \brief Destroys a Button. |
---|
| 1182 | */ |
---|
| 1183 | void Button::destroy(void) |
---|
| 1184 | { |
---|
| 1185 | if (this->title) |
---|
| 1186 | PRINTF(3)("deleting the Label: %s\n", this->title); |
---|
| 1187 | else |
---|
| 1188 | PRINTF(3)("deleting the Label.\n"); |
---|
| 1189 | |
---|
| 1190 | static_cast<Option*>(this)->destroy(); |
---|
| 1191 | } |
---|
| 1192 | |
---|
| 1193 | /** |
---|
[3144] | 1194 | \brief Sets a new name to the Button |
---|
| 1195 | \param title The name the Button should get |
---|
| 1196 | */ |
---|
[3430] | 1197 | void Button::setTitle(char *title) |
---|
[3144] | 1198 | { |
---|
[3430] | 1199 | if (this->title) |
---|
| 1200 | delete []this->title; |
---|
| 1201 | this->title = new char[strlen(title)+1]; |
---|
| 1202 | strcpy(this->title, title); |
---|
[3165] | 1203 | #ifdef HAVE_GTK2 |
---|
[3430] | 1204 | gtk_button_set_label(GTK_BUTTON(widget), title); |
---|
[3165] | 1205 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1206 | } |
---|
| 1207 | |
---|
| 1208 | /** |
---|
| 1209 | \brief redraws the Button |
---|
| 1210 | not implemented yet |
---|
| 1211 | */ |
---|
[3430] | 1212 | void Button::redraw(void) |
---|
[3144] | 1213 | { |
---|
| 1214 | } |
---|
| 1215 | |
---|
[3430] | 1216 | /** |
---|
| 1217 | \brief Button can not be changed, optionChange is empty) |
---|
| 1218 | |
---|
| 1219 | \todo Actions for non-GTK-mode |
---|
| 1220 | */ |
---|
| 1221 | void Button::changeOption(void) |
---|
| 1222 | { |
---|
| 1223 | // This will possibly be used for ACTIONS ! |
---|
| 1224 | } |
---|
| 1225 | |
---|
[3144] | 1226 | /* CHECKBUTTON */ |
---|
| 1227 | |
---|
| 1228 | /** |
---|
| 1229 | \brief Creates a new CheckButton with an ame |
---|
| 1230 | \param buttonname The name the CheckButton should display. |
---|
| 1231 | */ |
---|
[3430] | 1232 | CheckButton::CheckButton(char* buttonname) |
---|
[3144] | 1233 | { |
---|
| 1234 | this->init(); |
---|
| 1235 | this->setTitle(buttonname); |
---|
| 1236 | |
---|
[3165] | 1237 | #ifdef HAVE_GTK2 |
---|
[3430] | 1238 | this->connectSignal("clicked", this->OptionChange); |
---|
[3165] | 1239 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1240 | } |
---|
| 1241 | |
---|
| 1242 | /** |
---|
[3430] | 1243 | \brief destructs a CheckButton. |
---|
| 1244 | */ |
---|
| 1245 | CheckButton::~CheckButton(void) |
---|
| 1246 | { |
---|
| 1247 | this->destroy(); |
---|
| 1248 | } |
---|
| 1249 | |
---|
| 1250 | /** |
---|
[3144] | 1251 | \brief Initialize a new CheckButton with default settings |
---|
| 1252 | */ |
---|
| 1253 | void CheckButton::init(void) |
---|
| 1254 | { |
---|
[3430] | 1255 | this->isOption = 1; |
---|
[3144] | 1256 | |
---|
| 1257 | static_cast<Option*>(this)->init(); |
---|
| 1258 | |
---|
[3165] | 1259 | #ifdef HAVE_GTK2 |
---|
[3430] | 1260 | this->widget = gtk_check_button_new_with_label(""); |
---|
[3165] | 1261 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1262 | } |
---|
| 1263 | |
---|
| 1264 | /** |
---|
[3430] | 1265 | \brief Destroys a CheckButton. |
---|
| 1266 | */ |
---|
| 1267 | void CheckButton::destroy(void) |
---|
| 1268 | { |
---|
| 1269 | if (this->title) |
---|
| 1270 | PRINTF(3)("deleting the CheckButton: %s\n", this->title); |
---|
| 1271 | else |
---|
| 1272 | PRINTF(3)("deleting the CheckButton.\n"); |
---|
| 1273 | |
---|
| 1274 | static_cast<Option*>(this)->destroy(); |
---|
| 1275 | } |
---|
| 1276 | |
---|
| 1277 | /** |
---|
[3144] | 1278 | \brief Sets a new Title to a CheckButton |
---|
| 1279 | \param title The new Name the CheckButton should display. |
---|
| 1280 | */ |
---|
| 1281 | void CheckButton::setTitle(char* title) |
---|
| 1282 | { |
---|
[3430] | 1283 | if (this->title) |
---|
| 1284 | delete []this->title; |
---|
| 1285 | this->title = new char[strlen(title)+1]; |
---|
| 1286 | strcpy(this->title, title); |
---|
[3165] | 1287 | #ifdef HAVE_GTK2 |
---|
[3144] | 1288 | gtk_button_set_label(GTK_BUTTON(widget), title); |
---|
[3165] | 1289 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1290 | } |
---|
| 1291 | |
---|
[3430] | 1292 | bool CheckButton::isActive(void) |
---|
[3146] | 1293 | { |
---|
[3165] | 1294 | #ifdef HAVE_GTK2 |
---|
[3146] | 1295 | return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); |
---|
[3165] | 1296 | #endif /* HAVE_GTK2 */ |
---|
[3146] | 1297 | } |
---|
[3144] | 1298 | |
---|
[3430] | 1299 | /** |
---|
| 1300 | \brief Changed the Option, call this Function |
---|
[3144] | 1301 | */ |
---|
[3430] | 1302 | void CheckButton::changeOption(void) |
---|
[3144] | 1303 | { |
---|
[3430] | 1304 | #ifdef HAVE_GTK2 |
---|
| 1305 | this->value =(int)gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(this->widget)); |
---|
| 1306 | #else /* HAVE_GTK2 */ |
---|
| 1307 | char tmpChar[20]; |
---|
| 1308 | cout << "\nPlease give me a new value for " << this->title << " [0,1](defualt:" << this->defaultValue << "): "; |
---|
| 1309 | cin >> tmpChar; |
---|
| 1310 | |
---|
| 1311 | if ((this->value = atoi(tmpChar))=!0) |
---|
| 1312 | this->value = 1; |
---|
| 1313 | #endif /* HAVE_GTK2 */ |
---|
| 1314 | cout << this->title << " set to: " << this->value << endl; |
---|
[3144] | 1315 | } |
---|
| 1316 | |
---|
[3430] | 1317 | |
---|
[3144] | 1318 | /** |
---|
[3430] | 1319 | \brief Redraws the CheckButton(if option has changed). |
---|
[3144] | 1320 | Example: if new settings are loaded the Button must be redrawn for the GUI to display that Change |
---|
| 1321 | */ |
---|
[3430] | 1322 | void CheckButton::redraw(void) |
---|
[3144] | 1323 | { |
---|
[3165] | 1324 | #ifdef HAVE_GTK2 |
---|
[3430] | 1325 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(this->widget), value); |
---|
[3165] | 1326 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1327 | } |
---|
| 1328 | |
---|
| 1329 | /* SLIDER */ |
---|
| 1330 | |
---|
| 1331 | /** |
---|
| 1332 | \brief Creates a new Slider |
---|
| 1333 | \param slidername The data-structure-name of the slider. |
---|
| 1334 | \param start The minimal Value of the slider. |
---|
| 1335 | \param end The maximal Value of the slider. |
---|
| 1336 | */ |
---|
[3430] | 1337 | Slider::Slider(char* slidername, int start, int end) |
---|
[3144] | 1338 | { |
---|
| 1339 | this->init(start, end); |
---|
| 1340 | this->setValue(start); |
---|
| 1341 | this->setTitle(slidername); |
---|
[3165] | 1342 | #ifdef HAVE_GTK2 |
---|
[3430] | 1343 | this->connectSignal("value_changed", this->OptionChange); |
---|
[3165] | 1344 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1345 | } |
---|
| 1346 | |
---|
| 1347 | /** |
---|
[3430] | 1348 | \brief destructs a Slider. |
---|
| 1349 | */ |
---|
| 1350 | Slider::~Slider(void) |
---|
| 1351 | { |
---|
| 1352 | this->destroy(); |
---|
| 1353 | } |
---|
| 1354 | |
---|
| 1355 | /** |
---|
[3144] | 1356 | \brief Initializes a Slider with start and end Values |
---|
[3430] | 1357 | params: see Slider::Slider(char* slidername, int start, int end) |
---|
[3144] | 1358 | */ |
---|
| 1359 | void Slider::init(int start, int end) |
---|
| 1360 | { |
---|
[3430] | 1361 | this->isOption = 2; |
---|
[3144] | 1362 | |
---|
| 1363 | static_cast<Option*>(this)->init(); |
---|
| 1364 | |
---|
[3430] | 1365 | this->start = start; |
---|
| 1366 | this->end = end; |
---|
[3165] | 1367 | #ifdef HAVE_GTK2 |
---|
[3430] | 1368 | widget = gtk_hscale_new_with_range(this->start, this->end, 5); |
---|
[3165] | 1369 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1370 | } |
---|
| 1371 | |
---|
| 1372 | /** |
---|
[3430] | 1373 | \brief Destroys a Slider. |
---|
| 1374 | */ |
---|
| 1375 | void Slider::destroy(void) |
---|
| 1376 | { |
---|
| 1377 | if (this->title) |
---|
| 1378 | PRINTF(3)("deleting the Slider: %s\n", this->title); |
---|
| 1379 | else |
---|
| 1380 | PRINTF(3)("deleting the Slider.\n"); |
---|
| 1381 | |
---|
| 1382 | static_cast<Option*>(this)->destroy(); |
---|
| 1383 | |
---|
| 1384 | } |
---|
| 1385 | |
---|
| 1386 | /** |
---|
[3144] | 1387 | \brief Sets a new Title to the Slider |
---|
| 1388 | \param title The new Name of the slider |
---|
| 1389 | */ |
---|
| 1390 | void Slider::setTitle(char* title) |
---|
| 1391 | { |
---|
[3430] | 1392 | if (this->title) |
---|
| 1393 | delete []this->title; |
---|
| 1394 | this->title = new char[strlen(title)+1]; |
---|
| 1395 | strcpy(this->title, title); |
---|
[3144] | 1396 | } |
---|
| 1397 | |
---|
| 1398 | /** |
---|
| 1399 | \brief Setting a new value to the Slider. |
---|
| 1400 | Maybe you also require a Slider::redraw() for this to display |
---|
| 1401 | */ |
---|
| 1402 | void Slider::setValue(int value) |
---|
| 1403 | { |
---|
| 1404 | this->value = value; |
---|
| 1405 | } |
---|
| 1406 | |
---|
[3430] | 1407 | /** |
---|
| 1408 | \brief Redraws the widget |
---|
| 1409 | Example: see void CheckButton::redraw(void) |
---|
[3144] | 1410 | */ |
---|
[3430] | 1411 | void Slider::redraw(void) |
---|
[3144] | 1412 | { |
---|
[3430] | 1413 | #ifdef HAVE_GTK2 |
---|
| 1414 | gtk_range_set_value(GTK_RANGE(this->widget), value); |
---|
| 1415 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1416 | } |
---|
| 1417 | |
---|
| 1418 | /** |
---|
[3430] | 1419 | \brief Changed the Option, call this Function |
---|
[3144] | 1420 | */ |
---|
[3430] | 1421 | void Slider::changeOption(void) |
---|
[3144] | 1422 | { |
---|
[3165] | 1423 | #ifdef HAVE_GTK2 |
---|
[3430] | 1424 | this->value =(int)gtk_range_get_value(GTK_RANGE(this->widget)); |
---|
| 1425 | #else /* HAVE_GTK2 */ |
---|
| 1426 | char tmpChar[20]; |
---|
| 1427 | cout << "\nPlease give me a new value for " << this->title << " [" <<this->start << "-" << this->end << "](defualt:" << this->defaultValue << "): "; |
---|
| 1428 | cin >> tmpChar; |
---|
| 1429 | |
---|
| 1430 | if ((this->value = atoi(tmpChar))> this->end) |
---|
| 1431 | this->value = this->end; |
---|
| 1432 | if (this->value <= this->start) |
---|
| 1433 | this->value = this->start; |
---|
[3165] | 1434 | #endif /* HAVE_GTK2 */ |
---|
[3430] | 1435 | cout << this->title << " set to: " << this->value << endl; |
---|
[3144] | 1436 | } |
---|
| 1437 | |
---|
| 1438 | /* MENU */ |
---|
| 1439 | |
---|
| 1440 | /** |
---|
| 1441 | \brief Creates a Menu-Item-list out of multiple input. |
---|
| 1442 | !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
| 1443 | \param menuname The Database-Name of this Menu |
---|
| 1444 | \param ... items to be added to this Menu. !! Consider, that the last input argument has to be "lastItem" for this to work!! |
---|
| 1445 | */ |
---|
[3430] | 1446 | Menu::Menu(char* menuname, ...) |
---|
[3144] | 1447 | { |
---|
| 1448 | this->init(); |
---|
| 1449 | this->setTitle(menuname); |
---|
| 1450 | |
---|
| 1451 | char *itemName; |
---|
[3165] | 1452 | |
---|
| 1453 | #ifdef HAVE_GTK2 /////////////////////// REINPLEMENT |
---|
[3430] | 1454 | va_start(itemlist, menuname); |
---|
| 1455 | while(strcmp(itemName = va_arg(itemlist, char*), "lastItem")) |
---|
[3144] | 1456 | { |
---|
| 1457 | this->addItem(itemName); |
---|
| 1458 | } |
---|
| 1459 | va_end(itemlist); |
---|
[3165] | 1460 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1461 | |
---|
[3165] | 1462 | #ifdef HAVE_GTK2 |
---|
[3430] | 1463 | gtk_option_menu_set_menu(GTK_OPTION_MENU(this->widget), menu); |
---|
| 1464 | this->connectSignal("changed", this->OptionChange); |
---|
[3165] | 1465 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1466 | } |
---|
| 1467 | |
---|
| 1468 | /** |
---|
[3430] | 1469 | \brief destructs a Menu. |
---|
| 1470 | */ |
---|
| 1471 | Menu::~Menu(void) |
---|
| 1472 | { |
---|
| 1473 | this->destroy(); |
---|
| 1474 | } |
---|
| 1475 | |
---|
| 1476 | /** |
---|
[3144] | 1477 | \brief Initializes a new Menu with no items |
---|
| 1478 | */ |
---|
| 1479 | void Menu::init(void) |
---|
| 1480 | { |
---|
[3430] | 1481 | this->isOption = 2; |
---|
[3144] | 1482 | |
---|
| 1483 | static_cast<Option*>(this)->init(); |
---|
| 1484 | |
---|
[3165] | 1485 | #ifdef HAVE_GTK2 |
---|
[3430] | 1486 | this->widget = gtk_option_menu_new(); |
---|
| 1487 | this->menu = gtk_menu_new(); |
---|
[3165] | 1488 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1489 | |
---|
| 1490 | } |
---|
| 1491 | |
---|
| 1492 | /** |
---|
[3430] | 1493 | \brief Destroys a Menu. |
---|
| 1494 | */ |
---|
| 1495 | void Menu::destroy(void) |
---|
| 1496 | { |
---|
| 1497 | if (this->title) |
---|
| 1498 | PRINTF(3)("deleting the Menu: %s\n", this->title); |
---|
| 1499 | else |
---|
| 1500 | PRINTF(3)("deleting the Menu.\n"); |
---|
| 1501 | //! \todo destroy menu |
---|
| 1502 | |
---|
| 1503 | static_cast<Option*>(this)->destroy(); |
---|
| 1504 | } |
---|
| 1505 | |
---|
| 1506 | |
---|
| 1507 | /** |
---|
[3144] | 1508 | * Sets the Database-Name of this Menu |
---|
| 1509 | \param title Database-Name to be set. |
---|
| 1510 | */ |
---|
| 1511 | void Menu::setTitle(char* title) |
---|
| 1512 | { |
---|
[3430] | 1513 | if (this->title) |
---|
| 1514 | delete []this->title; |
---|
| 1515 | this->title = new char[strlen(title)+1]; |
---|
| 1516 | strcpy(this->title, title); |
---|
[3144] | 1517 | } |
---|
| 1518 | |
---|
| 1519 | /** |
---|
| 1520 | \brief appends a new Item to the Menu-List. |
---|
| 1521 | \param itemName the itemName to be appendet. |
---|
[3430] | 1522 | |
---|
| 1523 | \todo make the item-list readable without GTK |
---|
[3144] | 1524 | */ |
---|
[3430] | 1525 | void Menu::addItem(char* itemName) |
---|
[3144] | 1526 | { |
---|
[3165] | 1527 | #ifdef HAVE_GTK2 |
---|
[3430] | 1528 | this->item = gtk_menu_item_new_with_label(itemName); |
---|
| 1529 | gtk_menu_shell_append(GTK_MENU_SHELL(this->menu), this->item); |
---|
[3165] | 1530 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1531 | } |
---|
| 1532 | |
---|
[3430] | 1533 | /** |
---|
| 1534 | \brief Redraws the widget |
---|
| 1535 | Example: see void CheckButton::redraw(void) |
---|
[3144] | 1536 | */ |
---|
[3430] | 1537 | void Menu::redraw(void) |
---|
[3144] | 1538 | { |
---|
[3430] | 1539 | #ifdef HAVE_GTK2 |
---|
| 1540 | gtk_option_menu_set_history(GTK_OPTION_MENU(this->widget), this->value); |
---|
| 1541 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1542 | } |
---|
| 1543 | |
---|
| 1544 | /** |
---|
[3430] | 1545 | \brief Changed the Option, call this Function |
---|
[3156] | 1546 | */ |
---|
[3430] | 1547 | void Menu::changeOption(void) |
---|
[3144] | 1548 | { |
---|
[3165] | 1549 | #ifdef HAVE_GTK2 |
---|
[3430] | 1550 | this->value =(int)gtk_option_menu_get_history(GTK_OPTION_MENU(this->widget)); |
---|
| 1551 | #else /* HAVE_GTK2 */ |
---|
| 1552 | char tmpChar[20]; |
---|
| 1553 | cout << "\nPlease give me a new value for " << this->title << "(defualt:" << this->defaultValue << "): "; |
---|
| 1554 | cin >> tmpChar; |
---|
| 1555 | this->value = atoi(tmpChar); |
---|
| 1556 | |
---|
[3165] | 1557 | #endif /* HAVE_GTK2 */ |
---|
[3430] | 1558 | cout << this->title << " set to: " << this->value << endl; |
---|
[3144] | 1559 | } |
---|
| 1560 | |
---|
[3430] | 1561 | /* OPTION LABEL */ |
---|
| 1562 | |
---|
[3187] | 1563 | /** |
---|
| 1564 | \brief Creates a new OptionLabel with a LabelName and a Value. |
---|
| 1565 | \param label The name of the OptionLabel. |
---|
[3430] | 1566 | \param value The Value of the OptionLabel(what will be displayed). |
---|
[3187] | 1567 | */ |
---|
[3161] | 1568 | OptionLabel::OptionLabel(char* label, char* value) |
---|
[3156] | 1569 | { |
---|
[3430] | 1570 | this->init(); |
---|
| 1571 | this->setTitle(label); |
---|
| 1572 | this->setValue(value); |
---|
[3156] | 1573 | } |
---|
| 1574 | |
---|
[3187] | 1575 | /** |
---|
[3430] | 1576 | \brief destructs an OptionLabel. |
---|
| 1577 | */ |
---|
| 1578 | OptionLabel::~OptionLabel(void) |
---|
| 1579 | { |
---|
| 1580 | this->destroy(); |
---|
| 1581 | } |
---|
| 1582 | |
---|
| 1583 | /** |
---|
[3187] | 1584 | \brief Initializes an OptionLabel |
---|
| 1585 | */ |
---|
[3156] | 1586 | void OptionLabel::init(void) |
---|
| 1587 | { |
---|
[3430] | 1588 | this->isOption = 5; |
---|
[3156] | 1589 | static_cast<Option*>(this)->init(); |
---|
[3430] | 1590 | |
---|
[3161] | 1591 | cValue = NULL; |
---|
[3156] | 1592 | |
---|
[3165] | 1593 | #ifdef HAVE_GTK2 |
---|
[3430] | 1594 | this->widget = gtk_label_new(""); |
---|
[3165] | 1595 | #endif /* HAVE_GTK2 */ |
---|
[3156] | 1596 | } |
---|
[3165] | 1597 | |
---|
[3187] | 1598 | /** |
---|
[3430] | 1599 | \brief Destroys a OptionLabel. |
---|
| 1600 | */ |
---|
| 1601 | void OptionLabel::destroy(void) |
---|
| 1602 | { |
---|
| 1603 | if (this->title) |
---|
| 1604 | PRINTF(3)("deleting the OptionLabel: %s\n", this->title); |
---|
| 1605 | else |
---|
| 1606 | PRINTF(3)("deleting the OptionLabel.\n"); |
---|
| 1607 | if (this->cValue) |
---|
| 1608 | delete []this->cValue; |
---|
| 1609 | |
---|
| 1610 | static_cast<Option*>(this)->destroy(); |
---|
| 1611 | } |
---|
| 1612 | |
---|
| 1613 | |
---|
| 1614 | /** |
---|
[3187] | 1615 | \brief Updates the value of an OptionLabel |
---|
| 1616 | \param newValue The new Name that should be displayed. |
---|
| 1617 | */ |
---|
[3161] | 1618 | void OptionLabel::setValue(char* newValue) |
---|
| 1619 | { |
---|
[3430] | 1620 | if (this->cValue) |
---|
| 1621 | delete []this->cValue; |
---|
| 1622 | this->cValue = new char [strlen(newValue)+1]; |
---|
| 1623 | strcpy(this->cValue, newValue); |
---|
[3165] | 1624 | #ifdef HAVE_GTK2 |
---|
[3430] | 1625 | gtk_label_set_text(GTK_LABEL(this->widget), this->cValue); |
---|
[3165] | 1626 | #endif /* HAVE_GTK2 */ |
---|
[3161] | 1627 | } |
---|
[3156] | 1628 | |
---|
[3187] | 1629 | /** |
---|
| 1630 | \brief Sets a ned Title to the OptionLabel. |
---|
| 1631 | \param title The now title of the OptionLabel. |
---|
| 1632 | */ |
---|
[3156] | 1633 | void OptionLabel::setTitle(char* title) |
---|
| 1634 | { |
---|
[3430] | 1635 | if (this->title) |
---|
| 1636 | delete []this->title; |
---|
| 1637 | this->title = new char [strlen(title)+1]; |
---|
| 1638 | strcpy(this->title, title); |
---|
| 1639 | this->redraw(); |
---|
| 1640 | } |
---|
| 1641 | |
---|
| 1642 | /** |
---|
| 1643 | \brief Redraws an OptionLabel(not implemented yet, but it works). |
---|
| 1644 | */ |
---|
| 1645 | void OptionLabel::redraw(void) |
---|
| 1646 | { |
---|
[3165] | 1647 | #ifdef HAVE_GTK2 |
---|
[3430] | 1648 | gtk_label_set_text(GTK_LABEL(widget), title); |
---|
[3165] | 1649 | #endif /* HAVE_GTK2 */ |
---|
[3156] | 1650 | } |
---|
| 1651 | |
---|
[3187] | 1652 | /** |
---|
[3430] | 1653 | \brief Changed the Option, call this Function |
---|
[3187] | 1654 | */ |
---|
[3430] | 1655 | void OptionLabel::changeOption(void) |
---|
[3156] | 1656 | { |
---|
[3430] | 1657 | #ifdef HAVE_GTK2 |
---|
| 1658 | this->cValue =(char*)gtk_label_get_text(GTK_LABEL(this->widget)); |
---|
| 1659 | #else /* HAVE_GTK2 */ |
---|
| 1660 | cout << "\nPlease give me a new input for " << this->title << ": "; |
---|
| 1661 | cin >> this->cValue; |
---|
| 1662 | #endif /* HAVE_GTK2 */ |
---|
| 1663 | cout << this->title << " set to: " << this->cValue << endl; |
---|
[3156] | 1664 | } |
---|
| 1665 | |
---|
[3430] | 1666 | |
---|
[3144] | 1667 | /** |
---|
| 1668 | \brief Creates a new default Label with no Text. |
---|
| 1669 | You migth consider adding Label::setTitle with this. |
---|
| 1670 | */ |
---|
[3430] | 1671 | Label::Label(void) |
---|
[3144] | 1672 | { |
---|
| 1673 | this->init(); |
---|
| 1674 | } |
---|
| 1675 | |
---|
| 1676 | /** |
---|
| 1677 | \brief Creates a new Label with a Text. |
---|
| 1678 | \param text The text to be displayed. |
---|
| 1679 | */ |
---|
[3430] | 1680 | Label:: Label(char* text) |
---|
[3144] | 1681 | { |
---|
| 1682 | this->init(); |
---|
[3430] | 1683 | this->setTitle(text); |
---|
[3144] | 1684 | } |
---|
| 1685 | |
---|
| 1686 | /** |
---|
[3430] | 1687 | \brief destructs a Label. |
---|
| 1688 | */ |
---|
| 1689 | Label::~Label(void) |
---|
| 1690 | { |
---|
| 1691 | this->destroy(); |
---|
| 1692 | } |
---|
| 1693 | |
---|
| 1694 | /** |
---|
[3144] | 1695 | \brief initializes a new Label |
---|
| 1696 | */ |
---|
| 1697 | void Label::init(void) |
---|
| 1698 | { |
---|
[3430] | 1699 | this->isOption = 0; |
---|
[3144] | 1700 | |
---|
| 1701 | static_cast<Widget*>(this)->init(); |
---|
| 1702 | |
---|
[3165] | 1703 | #ifdef HAVE_GTK2 |
---|
[3430] | 1704 | this->widget = gtk_label_new(""); |
---|
| 1705 | gtk_label_set_line_wrap(GTK_LABEL(this->widget), TRUE); |
---|
[3165] | 1706 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1707 | } |
---|
| 1708 | |
---|
| 1709 | /** |
---|
[3430] | 1710 | \brief Destroys a Label. |
---|
| 1711 | */ |
---|
| 1712 | void Label::destroy(void) |
---|
| 1713 | { |
---|
| 1714 | if (this->title) |
---|
| 1715 | PRINTF(3)("deleting the Label: %s\n", this->title); |
---|
| 1716 | else |
---|
| 1717 | PRINTF(3)("deleting the Label.\n"); |
---|
| 1718 | |
---|
| 1719 | static_cast<Widget*>(this)->destroy(); |
---|
| 1720 | } |
---|
| 1721 | |
---|
| 1722 | /** |
---|
[3144] | 1723 | \brief Sets a new Text to a Label. |
---|
| 1724 | \param text The text to be inserted into the Label. |
---|
| 1725 | */ |
---|
[3430] | 1726 | void Label::setTitle(char* text) |
---|
[3144] | 1727 | { |
---|
[3430] | 1728 | if (this->title) |
---|
| 1729 | delete []this->title; |
---|
| 1730 | this->title = new char[strlen(text)+1]; |
---|
| 1731 | strcpy(this->title, text); |
---|
[3165] | 1732 | #ifdef HAVE_GTK2 |
---|
[3430] | 1733 | gtk_label_set_text(GTK_LABEL(this->widget), this->title); |
---|
[3165] | 1734 | #endif /* HAVE_GTK2 */ |
---|
[3144] | 1735 | } |
---|
| 1736 | |
---|
| 1737 | /** |
---|
[3430] | 1738 | \brief ereases the Text of a Label |
---|
| 1739 | */ |
---|
| 1740 | void Label::ereaseText(void) |
---|
| 1741 | { |
---|
| 1742 | this->setTitle(""); |
---|
| 1743 | } |
---|
| 1744 | |
---|
| 1745 | /** |
---|
| 1746 | \brief appends some Text to a Label |
---|
| 1747 | \param textToAppend The text that will be appended to this Label |
---|
| 1748 | */ |
---|
| 1749 | void Label::appendText(char* textToAppend) |
---|
| 1750 | { |
---|
| 1751 | if (this->title) |
---|
| 1752 | { |
---|
| 1753 | char* tmpTitle = new char[strlen(this->title)+strlen(textToAppend)+1]; |
---|
| 1754 | strcpy(tmpTitle, title); |
---|
| 1755 | strcat(tmpTitle, textToAppend); |
---|
| 1756 | delete []this->title; |
---|
| 1757 | this->title = tmpTitle; |
---|
| 1758 | } |
---|
| 1759 | else |
---|
| 1760 | { |
---|
| 1761 | this->title = new char[strlen(textToAppend)]; |
---|
| 1762 | } |
---|
| 1763 | |
---|
| 1764 | #ifdef HAVE_GTK2 |
---|
| 1765 | gtk_label_set_text(GTK_LABEL(this->widget), title); |
---|
| 1766 | #endif /* HAVE_GTK2 */ |
---|
| 1767 | } |
---|
| 1768 | |
---|
| 1769 | /** |
---|
| 1770 | \brief Appends some integer to the Label |
---|
| 1771 | \param intToAppend The Int that will be added. |
---|
| 1772 | |
---|
| 1773 | it does this by just converting the int into a char* and send it to appendText |
---|
| 1774 | */ |
---|
| 1775 | void Label::appendInt(int intToAppend) |
---|
| 1776 | { |
---|
| 1777 | char append [32]; |
---|
| 1778 | sprintf(append, "%d", intToAppend); |
---|
| 1779 | this->appendText(append); |
---|
| 1780 | } |
---|
| 1781 | |
---|
| 1782 | |
---|
| 1783 | /** |
---|
[3144] | 1784 | \brief get the Text of a Label |
---|
| 1785 | \return The Text the Label holds. |
---|
| 1786 | */ |
---|
[3430] | 1787 | char* Label::getText(void) |
---|
[3144] | 1788 | { |
---|
[3430] | 1789 | return this->title; |
---|
[3144] | 1790 | } |
---|
[3430] | 1791 | |
---|
| 1792 | /** |
---|
| 1793 | \brief Creates a new ProgressBar. |
---|
| 1794 | */ |
---|
| 1795 | ProgressBar::ProgressBar(void) |
---|
| 1796 | { |
---|
| 1797 | this->init(); |
---|
| 1798 | } |
---|
| 1799 | |
---|
| 1800 | /** |
---|
| 1801 | \brief Creates a new ProgressBar. |
---|
| 1802 | \param label The name you want to get the ProgressBar. |
---|
| 1803 | */ |
---|
| 1804 | ProgressBar::ProgressBar(char* label) |
---|
| 1805 | { |
---|
| 1806 | this->init(); |
---|
| 1807 | this->setTitle(label); |
---|
| 1808 | } |
---|
| 1809 | |
---|
| 1810 | /** |
---|
| 1811 | \brief destructs a ProgressBar |
---|
| 1812 | */ |
---|
| 1813 | ProgressBar::~ProgressBar(void) |
---|
| 1814 | { |
---|
| 1815 | this->destroy(); |
---|
| 1816 | } |
---|
| 1817 | |
---|
| 1818 | /** |
---|
| 1819 | \brief Initializes a ProgressBar |
---|
| 1820 | */ |
---|
| 1821 | void ProgressBar::init(void) |
---|
| 1822 | { |
---|
| 1823 | this->isOption = 0; |
---|
| 1824 | this->progress = 0.0; |
---|
| 1825 | this->totalSize = 0.0; |
---|
| 1826 | |
---|
| 1827 | static_cast<Widget*>(this)->init(); |
---|
| 1828 | #ifdef HAVE_GTK2 |
---|
| 1829 | this->adjustment =(GtkAdjustment*)gtk_adjustment_new(0, 0, 100, 0, 0, 0); |
---|
| 1830 | this->widget = gtk_progress_bar_new_with_adjustment(this->adjustment); |
---|
| 1831 | #endif /* HAVE_GTK2 */ |
---|
| 1832 | } |
---|
| 1833 | |
---|
| 1834 | /** |
---|
| 1835 | \brief Destroys a ProgressBar. |
---|
| 1836 | */ |
---|
| 1837 | void ProgressBar::destroy(void) |
---|
| 1838 | { |
---|
| 1839 | if (this->title) |
---|
| 1840 | PRINTF(3)("deleting the ProgressBar: %s\n", this->title); |
---|
| 1841 | else |
---|
| 1842 | PRINTF(3)("deleting the ProgressBar.\n"); |
---|
| 1843 | |
---|
| 1844 | static_cast<Widget*>(this)->destroy(); |
---|
| 1845 | } |
---|
| 1846 | |
---|
| 1847 | /** |
---|
| 1848 | \brief Sets a ned Title to the ProgressBar. |
---|
| 1849 | \param title The now title of the ProgressBar. |
---|
| 1850 | */ |
---|
| 1851 | void ProgressBar::setTitle(char* title) |
---|
| 1852 | { |
---|
| 1853 | if (this->title) |
---|
| 1854 | delete []this->title; |
---|
| 1855 | this->title = new char [strlen(title)+1]; |
---|
| 1856 | strcpy(this->title, title); |
---|
| 1857 | } |
---|
| 1858 | |
---|
| 1859 | /** |
---|
| 1860 | \brief Sets the Total size of the Bar.(ex. The maximum one can download) |
---|
| 1861 | */ |
---|
| 1862 | void ProgressBar::setTotalSize(double totalSize) |
---|
| 1863 | { |
---|
| 1864 | this->totalSize = totalSize; |
---|
| 1865 | } |
---|
| 1866 | |
---|
| 1867 | /** |
---|
| 1868 | \brief Sets the progress maximum is this->totalSize |
---|
| 1869 | */ |
---|
| 1870 | void ProgressBar::setProgress(double progress) |
---|
| 1871 | { |
---|
| 1872 | this->progress = progress; |
---|
| 1873 | |
---|
| 1874 | if (this->progress > this->totalSize) |
---|
| 1875 | this->progress = this->totalSize; |
---|
| 1876 | |
---|
| 1877 | #ifdef HAVE_GTK2 |
---|
| 1878 | gtk_progress_set_value(GTK_PROGRESS(widget), this->progress*100.0/this->totalSize); |
---|
| 1879 | #endif /* HAVE_GTK2 */ |
---|
| 1880 | PRINTF(3)("Progress: %f\n", this->progress*100.0/this->totalSize); |
---|
| 1881 | } |
---|
| 1882 | |
---|
| 1883 | /** |
---|
| 1884 | \brief returns the Progress Status |
---|
| 1885 | */ |
---|
| 1886 | double ProgressBar::getProgress(void) |
---|
| 1887 | { |
---|
| 1888 | return this->progress; |
---|
| 1889 | } |
---|
| 1890 | |
---|
| 1891 | /* IMAGE */ |
---|
| 1892 | |
---|
| 1893 | /** |
---|
| 1894 | \brief Creates a new Image |
---|
| 1895 | \param imagename the location of the Image on the Hard Disc |
---|
| 1896 | */ |
---|
| 1897 | Image::Image(char* imagename) |
---|
| 1898 | { |
---|
| 1899 | this->init(); |
---|
| 1900 | if (this->title) |
---|
| 1901 | delete []this->title; |
---|
| 1902 | this->title = new char[strlen(imagename)+1]; |
---|
| 1903 | strcpy(this->title, imagename); |
---|
| 1904 | |
---|
| 1905 | #ifdef HAVE_GTK2 |
---|
| 1906 | widget = gtk_image_new_from_file(imagename); |
---|
| 1907 | #endif /* HAVE_GTK2 */ |
---|
| 1908 | } |
---|
| 1909 | |
---|
| 1910 | /** |
---|
| 1911 | \brief destructs an Image. |
---|
| 1912 | */ |
---|
| 1913 | Image::~Image(void) |
---|
| 1914 | { |
---|
| 1915 | this->destroy(); |
---|
| 1916 | } |
---|
| 1917 | |
---|
| 1918 | /** |
---|
| 1919 | \brief Initializes a new Image |
---|
| 1920 | */ |
---|
| 1921 | void Image::init(void) |
---|
| 1922 | { |
---|
| 1923 | isOption = 0; |
---|
| 1924 | |
---|
| 1925 | static_cast<Widget*>(this)->init(); |
---|
| 1926 | } |
---|
| 1927 | |
---|
| 1928 | /** |
---|
| 1929 | \brief Destroys a Image. |
---|
| 1930 | */ |
---|
| 1931 | void Image::destroy(void) |
---|
| 1932 | { |
---|
| 1933 | if (this->title) |
---|
| 1934 | PRINTF(3)("deleting the Image: %s\n", this->title); |
---|
| 1935 | else |
---|
| 1936 | PRINTF(3)("deleting the Image.\n"); |
---|
| 1937 | |
---|
| 1938 | static_cast<Widget*>(this)->destroy(); |
---|
| 1939 | } |
---|
| 1940 | |
---|
| 1941 | /** |
---|
| 1942 | \brief Sets a ned Title to the Image. |
---|
| 1943 | \param title The now title of the OptionLabel. |
---|
| 1944 | */ |
---|
| 1945 | void Image::setTitle(char* title) |
---|
| 1946 | { |
---|
| 1947 | if (this->title) |
---|
| 1948 | delete []this->title; |
---|
| 1949 | this->title = new char [strlen(title)+1]; |
---|
| 1950 | strcpy(this->title, title); |
---|
| 1951 | } |
---|