1 // 2 // "$Id$" 3 // 4 // Main header file for the Fast Light Tool Kit (FLTK). 5 // 6 // Copyright 1998-2016 by Bill Spitzak and others. 7 // 8 // This library is free software. Distribution and use rights are outlined in 9 // the file "COPYING" which should have been included with this file. If this 10 // file is missing or damaged, see the license at: 11 // 12 // http://www.fltk.org/COPYING.php 13 // 14 // Please report all bugs and problems on the following page: 15 // 16 // http://www.fltk.org/str.php 17 // 18 19 /** \file 20 Fl static class. 21 */ 22 23 #ifndef Fl_H 24 # define Fl_H 25 26 #include <FL/Fl_Export.H> 27 28 #ifdef FLTK_HAVE_CAIRO 29 # include <FL/Fl_Cairo.H> 30 #endif 31 32 # include "fl_utf8.h" 33 # include "Enumerations.H" 34 # ifndef Fl_Object 35 # define Fl_Object Fl_Widget /**< for back compatibility - use Fl_Widget! */ 36 # endif 37 38 # ifdef check 39 # undef check 40 # endif 41 42 43 class Fl_Widget; 44 class Fl_Window; 45 class Fl_Image; 46 struct Fl_Label; 47 48 // Keep avoiding having the socket deps at that level but mke sure it will work in both 32 & 64 bit builds 49 #if defined(WIN32) && !defined(__CYGWIN__) 50 # if defined(_WIN64) 51 # define FL_SOCKET unsigned __int64 52 # else 53 # define FL_SOCKET int 54 # endif 55 #else 56 # define FL_SOCKET int 57 #endif 58 59 60 // Pointers you can use to change FLTK to a foreign language. 61 // Note: Similar pointers are defined in FL/fl_ask.H and src/fl_ask.cxx 62 extern FL_EXPORT const char* fl_local_ctrl; 63 extern FL_EXPORT const char* fl_local_meta; 64 extern FL_EXPORT const char* fl_local_alt; 65 extern FL_EXPORT const char* fl_local_shift; 66 67 /** \defgroup callback_functions Callback function typedefs 68 \brief Typedefs defined in <FL/Fl.H> for callback or handler functions passed as function parameters. 69 70 FLTK uses callback functions as parameters for some function calls, e.g. to 71 set up global event handlers (Fl::add_handler()), to add a timeout handler 72 (Fl::add_timeout()), and many more. 73 74 The typedefs defined in this group describe the function parameters used to set 75 up or clear the callback functions and should also be referenced to define the 76 callback function to handle such events in the user's code. 77 78 \see Fl::add_handler(), Fl::add_timeout(), Fl::repeat_timeout(), 79 Fl::remove_timeout() and others 80 @{ */ 81 82 /** Signature of some label drawing functions passed as parameters */ 83 typedef void (Fl_Label_Draw_F)(const Fl_Label *label, int x, int y, int w, int h, Fl_Align align); 84 85 /** Signature of some label measurement functions passed as parameters */ 86 typedef void (Fl_Label_Measure_F)(const Fl_Label *label, int &width, int &height); 87 88 /** Signature of some box drawing functions passed as parameters */ 89 typedef void (Fl_Box_Draw_F)(int x, int y, int w, int h, Fl_Color color); 90 91 /** Signature of some timeout callback functions passed as parameters */ 92 typedef void (*Fl_Timeout_Handler)(void *data); 93 94 /** Signature of some wakeup callback functions passed as parameters */ 95 typedef void (*Fl_Awake_Handler)(void *data); 96 97 /** Signature of add_idle callback functions passed as parameters */ 98 typedef void (*Fl_Idle_Handler)(void *data); 99 100 /** Signature of set_idle callback functions passed as parameters */ 101 typedef void (*Fl_Old_Idle_Handler)(); 102 103 /** Signature of add_fd functions passed as parameters */ 104 typedef void (*Fl_FD_Handler)(FL_SOCKET fd, void *data); 105 106 /** Signature of add_handler functions passed as parameters */ 107 typedef int (*Fl_Event_Handler)(int event); 108 109 /** Signature of add_system_handler functions passed as parameters */ 110 typedef int (*Fl_System_Handler)(void *event, void *data); 111 112 /** Signature of set_abort functions passed as parameters */ 113 typedef void (*Fl_Abort_Handler)(const char *format,...); 114 115 /** Signature of set_atclose functions passed as parameters */ 116 typedef void (*Fl_Atclose_Handler)(Fl_Window *window, void *data); 117 118 /** Signature of args functions passed as parameters */ 119 typedef int (*Fl_Args_Handler)(int argc, char **argv, int &i); 120 121 /** Signature of event_dispatch functions passed as parameters. 122 \see Fl::event_dispatch(Fl_Event_Dispatch) */ 123 typedef int (*Fl_Event_Dispatch)(int event, Fl_Window *w); 124 125 /** Signature of add_clipboard_notify functions passed as parameters */ 126 typedef void (*Fl_Clipboard_Notify_Handler)(int source, void *data); 127 128 /** @} */ /* group callback_functions */ 129 130 131 /** 132 The Fl is the FLTK global (static) class containing 133 state information and global methods for the current application. 134 */ 135 class FL_EXPORT Fl { Fl()136 Fl() {}; // no constructor! 137 138 private: 139 static int use_high_res_GL_; 140 141 public: // should be private! 142 #ifndef FL_DOXYGEN 143 static int e_number; 144 static int e_x; 145 static int e_y; 146 static int e_x_root; 147 static int e_y_root; 148 static int e_dx; 149 static int e_dy; 150 static int e_state; 151 static int e_clicks; 152 static int e_is_click; 153 static int e_keysym; 154 static char* e_text; 155 static int e_length; 156 static void *e_clipboard_data; 157 static const char *e_clipboard_type; 158 static Fl_Event_Dispatch e_dispatch; 159 static Fl_Widget* belowmouse_; 160 static Fl_Widget* pushed_; 161 static Fl_Widget* focus_; 162 static int damage_; 163 static Fl_Widget* selection_owner_; 164 static Fl_Window* modal_; 165 static Fl_Window* grab_; 166 static int compose_state; // used for dead keys (WIN32) or marked text (MacOS) 167 static void call_screen_init(); // recompute screen number and dimensions 168 #ifdef __APPLE__ 169 static void reset_marked_text(); // resets marked text 170 static void insertion_point_location(int x, int y, int height); // sets window coordinates & height of insertion point 171 #endif 172 #endif // FL_DOXYGEN 173 174 175 /** 176 If true then flush() will do something. 177 */ damage(int d)178 static void damage(int d) {damage_ = d;} 179 180 public: 181 /** Enumerator for global FLTK options. 182 These options can be set system wide, per user, or for the running 183 application only. 184 \see Fl::option(Fl_Option, bool) 185 \see Fl::option(Fl_Option) 186 */ 187 typedef enum { 188 /// When switched on, moving the text cursor beyond the start or end of 189 /// a text in a text widget will change focus to the next text widget. 190 /// (This is considered 'old' behavior) 191 /// 192 /// When switched off (default), the cursor will stop at the end of the text. 193 /// Pressing Tab or Ctrl-Tab will advance the keyboard focus. 194 /// 195 /// See also: Fl_Input_::tab_nav() 196 /// 197 OPTION_ARROW_FOCUS = 0, 198 // When switched on, FLTK will use the file chooser dialog that comes 199 // with your operating system whenever possible. When switched off, FLTK 200 // will present its own file chooser. 201 // \todo implement me 202 // OPTION_NATIVE_FILECHOOSER, 203 // When Filechooser Preview is enabled, the FLTK or native file chooser 204 // will show a preview of a selected file (if possible) before the user 205 // decides to choose the file. 206 // \todo implement me 207 //OPTION_FILECHOOSER_PREVIEW, 208 /// If visible focus is switched on (default), FLTK will draw a dotted rectangle 209 /// inside the widget that will receive the next keystroke. If switched 210 /// off, no such indicator will be drawn and keyboard navigation 211 /// is disabled. 212 OPTION_VISIBLE_FOCUS, 213 /// If text drag-and-drop is enabled (default), the user can select and drag text 214 /// from any text widget. If disabled, no dragging is possible, however 215 /// dropping text from other applications still works. 216 OPTION_DND_TEXT, 217 /// If tooltips are enabled (default), hovering the mouse over a widget with a 218 /// tooltip text will open a little tooltip window until the mouse leaves 219 /// the widget. If disabled, no tooltip is shown. 220 OPTION_SHOW_TOOLTIPS, 221 /// When switched on (default), Fl_Native_File_Chooser runs GTK file dialogs 222 /// if the GTK library is available on the platform (linux/unix only). 223 /// When switched off, GTK file dialogs aren't used even if the GTK library is available. 224 OPTION_FNFC_USES_GTK, 225 // don't change this, leave it always as the last element 226 /// For internal use only. 227 OPTION_LAST 228 } Fl_Option; 229 230 private: 231 static unsigned char options_[OPTION_LAST]; 232 static unsigned char options_read_; 233 234 public: 235 /* 236 Return a global setting for all FLTK applications, possibly overridden 237 by a setting specifically for this application. 238 */ 239 static bool option(Fl_Option opt); 240 241 /* 242 Override an option while the application is running. 243 */ 244 static void option(Fl_Option opt, bool val); 245 246 /** 247 The currently executing idle callback function: DO NOT USE THIS DIRECTLY! 248 249 This is now used as part of a higher level system allowing multiple 250 idle callback functions to be called. 251 \see add_idle(), remove_idle() 252 */ 253 static void (*idle)(); 254 255 #ifndef FL_DOXYGEN 256 static Fl_Awake_Handler *awake_ring_; 257 static void **awake_data_; 258 static int awake_ring_size_; 259 static int awake_ring_head_; 260 static int awake_ring_tail_; 261 static const char* scheme_; 262 static Fl_Image* scheme_bg_; 263 264 static int e_original_keysym; // late addition 265 static int scrollbar_size_; 266 #endif 267 268 269 static int add_awake_handler_(Fl_Awake_Handler, void*); 270 static int get_awake_handler_(Fl_Awake_Handler&, void*&); 271 272 public: 273 274 // API version number 275 static double version(); 276 static int api_version(); 277 278 // ABI version number 279 static int abi_version(); 280 281 /** 282 Returns whether the runtime library ABI version is correct. 283 284 This enables you to check the ABI version of the linked FLTK 285 library at runtime. 286 287 Returns 1 (true) if the compiled ABI version (in the header files) 288 and the linked library ABI version (used at runtime) are the same, 289 0 (false) otherwise. 290 291 Argument \p val can be used to query a particular library ABI version. 292 Use for instance 10303 to query if the runtime library is compatible 293 with FLTK ABI version 1.3.3. This is rarely useful. 294 295 The default \p val argument is FL_ABI_VERSION, which checks the version 296 defined at configure time (i.e. in the header files at program 297 compilation time) against the linked library version used at runtime. 298 This is particularly useful if you linked with a shared object library, 299 but it also concerns static linking. 300 301 \see Fl::abi_version() 302 */ 303 static inline int abi_check(const int val = FL_ABI_VERSION) { 304 return val == abi_version(); 305 } 306 307 // argument parsers: 308 static int arg(int argc, char **argv, int& i); 309 static int args(int argc, char **argv, int& i, Fl_Args_Handler cb = 0); 310 static void args(int argc, char **argv); 311 /** 312 Usage string displayed if Fl::args() detects an invalid argument. 313 This may be changed to point to customized text at run-time. 314 */ 315 static const char* const help; 316 317 // things called by initialization: 318 static void display(const char*); 319 static int visual(int); 320 /** 321 This does the same thing as Fl::visual(int) but also requires OpenGL 322 drawing to work. This <I>must</I> be done if you want to draw in 323 normal windows with OpenGL with gl_start() and gl_end(). 324 It may be useful to call this so your X windows use the same visual 325 as an Fl_Gl_Window, which on some servers will reduce colormap flashing. 326 327 See Fl_Gl_Window for a list of additional values for the argument. 328 */ 329 static int gl_visual(int, int *alist=0); // platform dependent 330 static void own_colormap(); 331 static void get_system_colors(); 332 static void foreground(uchar, uchar, uchar); 333 static void background(uchar, uchar, uchar); 334 static void background2(uchar, uchar, uchar); 335 336 // schemes: 337 static int scheme(const char *name); 338 /** See void scheme(const char *name) */ scheme()339 static const char* scheme() {return scheme_;} 340 341 /** Returns whether the current scheme is the given name. 342 343 This is a fast inline convenience function to support scheme-specific 344 code in widgets, e.g. in their draw() methods, if required. 345 346 Use a valid scheme name, not \p NULL (although \p NULL is allowed, 347 this is not a useful argument - see below). 348 349 If Fl::scheme() has not been set or has been set to the default 350 scheme ("none" or "base"), then this will always return 0 regardless 351 of the argument, because Fl::scheme() is \p NULL in this case. 352 353 \note The stored scheme name is always lowercase, and this method will 354 do a case-sensitive compare, so you \b must provide a lowercase string to 355 return the correct value. This is intentional for performance reasons. 356 357 Example: 358 \code 359 if (Fl::is_scheme("gtk+")) { your_code_here(); } 360 \endcode 361 362 \param[in] name \b lowercase string of requested scheme name. 363 364 \return 1 if the given scheme is active, 0 otherwise. 365 366 \see Fl::scheme(const char *name) 367 */ is_scheme(const char * name)368 static int is_scheme(const char *name) { 369 return (scheme_ && name && !strcmp(name,scheme_)); 370 } 371 /** 372 Called by scheme according to scheme name. 373 Loads or reloads the current scheme selection. 374 See void scheme(const char *name) 375 */ 376 static int reload_scheme(); // platform dependent 377 static int scrollbar_size(); 378 static void scrollbar_size(int W); 379 380 // execution: 381 static int wait(); 382 static double wait(double time); 383 static int check(); 384 static int ready(); 385 static int run(); 386 static Fl_Widget* readqueue(); 387 /** 388 Adds a one-shot timeout callback. The function will be called by 389 Fl::wait() at <i>t</i> seconds after this function is called. 390 The optional void* argument is passed to the callback. 391 392 You can have multiple timeout callbacks. To remove a timeout 393 callback use Fl::remove_timeout(). 394 395 If you need more accurate, repeated timeouts, use Fl::repeat_timeout() to 396 reschedule the subsequent timeouts. 397 398 The following code will print "TICK" each second on 399 stdout with a fair degree of accuracy: 400 401 \code 402 #include <stdio.h> 403 #include <FL/Fl.H> 404 #include <FL/Fl_Window.H> 405 void callback(void*) { 406 printf("TICK\n"); 407 Fl::repeat_timeout(1.0, callback); // retrigger timeout 408 } 409 int main() { 410 Fl_Window win(100,100); 411 win.show(); 412 Fl::add_timeout(1.0, callback); // set up first timeout 413 return Fl::run(); 414 } 415 \endcode 416 */ 417 static void add_timeout(double t, Fl_Timeout_Handler,void* = 0); // platform dependent 418 /** 419 Repeats a timeout callback from the expiration of the 420 previous timeout, allowing for more accurate timing. You may only call 421 this method inside a timeout callback. 422 423 The following code will print "TICK" each second on 424 stdout with a fair degree of accuracy: 425 426 \code 427 void callback(void*) { 428 puts("TICK"); 429 Fl::repeat_timeout(1.0, callback); 430 } 431 432 int main() { 433 Fl::add_timeout(1.0, callback); 434 return Fl::run(); 435 } 436 \endcode 437 */ 438 static void repeat_timeout(double t, Fl_Timeout_Handler, void* = 0); // platform dependent 439 static int has_timeout(Fl_Timeout_Handler, void* = 0); 440 static void remove_timeout(Fl_Timeout_Handler, void* = 0); 441 static void add_check(Fl_Timeout_Handler, void* = 0); 442 static int has_check(Fl_Timeout_Handler, void* = 0); 443 static void remove_check(Fl_Timeout_Handler, void* = 0); 444 /** 445 Adds file descriptor fd to listen to. 446 447 When the fd becomes ready for reading Fl::wait() will call the 448 callback and then return. The callback is passed the fd and the 449 arbitrary void* argument. 450 451 The second version takes a when bitfield, with the bits 452 FL_READ, FL_WRITE, and FL_EXCEPT defined, 453 to indicate when the callback should be done. 454 455 There can only be one callback of each type for a file descriptor. 456 Fl::remove_fd() gets rid of <I>all</I> the callbacks for a given 457 file descriptor. 458 459 Under UNIX <I>any</I> file descriptor can be monitored (files, 460 devices, pipes, sockets, etc.). Due to limitations in Microsoft Windows, 461 WIN32 applications can only monitor sockets. 462 */ 463 static void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0); // platform dependent 464 /** See void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0) */ 465 static void add_fd(int fd, Fl_FD_Handler cb, void* = 0); // platform dependent 466 /** Removes a file descriptor handler. */ 467 static void remove_fd(int, int when); // platform dependent 468 /** Removes a file descriptor handler. */ 469 static void remove_fd(int); // platform dependent 470 471 static void add_idle(Fl_Idle_Handler cb, void* data = 0); 472 static int has_idle(Fl_Idle_Handler cb, void* data = 0); 473 static void remove_idle(Fl_Idle_Handler cb, void* data = 0); 474 /** If true then flush() will do something. */ damage()475 static int damage() {return damage_;} 476 static void redraw(); 477 static void flush(); 478 /** \addtogroup group_comdlg 479 @{ */ 480 /** 481 FLTK calls Fl::warning() to output a warning message. 482 483 The default version on Windows returns \e without printing a warning 484 message, because Windows programs normally don't have stderr (a console 485 window) enabled. 486 487 The default version on all other platforms prints the warning message to stderr. 488 489 You can override the behavior by setting the function pointer to your 490 own routine. 491 492 Fl::warning() means that there was a recoverable problem, the display may 493 be messed up, but the user can probably keep working - all X protocol 494 errors call this, for example. The default implementation returns after 495 displaying the message. 496 \note \#include <FL/Fl.H> 497 */ 498 static void (*warning)(const char*, ...); 499 /** 500 FLTK calls Fl::error() to output a normal error message. 501 502 The default version on Windows displays the error message in a MessageBox window. 503 504 The default version on all other platforms prints the error message to stderr. 505 506 You can override the behavior by setting the function pointer to your 507 own routine. 508 509 Fl::error() means there is a recoverable error such as the inability to read 510 an image file. The default implementation returns after displaying the message. 511 \note \#include <FL/Fl.H> 512 */ 513 static void (*error)(const char*, ...); 514 /** 515 FLTK calls Fl::fatal() to output a fatal error message. 516 517 The default version on Windows displays the error message in a MessageBox window. 518 519 The default version on all other platforms prints the error message to stderr. 520 521 You can override the behavior by setting the function pointer to your 522 own routine. 523 524 Fl::fatal() must not return, as FLTK is in an unusable state, however your 525 version may be able to use longjmp or an exception to continue, as long as 526 it does not call FLTK again. The default implementation exits with status 1 527 after displaying the message. 528 \note \#include <FL/Fl.H> 529 */ 530 static void (*fatal)(const char*, ...); 531 /** @} */ 532 533 /** \defgroup fl_windows Windows handling functions 534 \brief Windows and standard dialogs handling declared in <FL/Fl.H> 535 @{ */ 536 static Fl_Window* first_window(); 537 static void first_window(Fl_Window*); 538 static Fl_Window* next_window(const Fl_Window*); 539 540 /** 541 Returns the top-most modal() window currently shown. 542 543 This is the most recently shown() window with modal() true, or NULL 544 if there are no modal() windows shown(). 545 The modal() window has its handle() method called 546 for all events, and no other windows will have handle() 547 called (grab() overrides this). 548 */ modal()549 static Fl_Window* modal() {return modal_;} 550 /** Returns the window that currently receives all events. 551 552 \return The window that currently receives all events, 553 or NULL if event grabbing is currently OFF. 554 */ grab()555 static Fl_Window* grab() {return grab_;} 556 /** Selects the window to grab. 557 This is used when pop-up menu systems are active. 558 559 Send all events to the passed window no matter where the pointer or 560 focus is (including in other programs). The window <I>does not have 561 to be shown()</I> , this lets the handle() method of a 562 "dummy" window override all event handling and allows you to 563 map and unmap a complex set of windows (under both X and WIN32 564 <I>some</I> window must be mapped because the system interface needs a 565 window id). 566 567 If grab() is on it will also affect show() of windows by doing 568 system-specific operations (on X it turns on override-redirect). 569 These are designed to make menus popup reliably 570 and faster on the system. 571 572 To turn off grabbing do Fl::grab(0). 573 574 <I>Be careful that your program does not enter an infinite loop 575 while grab() is on. On X this will lock up your screen!</I> 576 To avoid this potential lockup, all newer operating systems seem to 577 limit mouse pointer grabbing to the time during which a mouse button 578 is held down. Some OS's may not support grabbing at all. 579 */ 580 static void grab(Fl_Window*); // platform dependent 581 /** @} */ 582 583 /** \defgroup fl_events Events handling functions 584 Fl class events handling API declared in <FL/Fl.H> 585 @{ 586 */ 587 // event information: 588 /** 589 Returns the last event that was processed. This can be used 590 to determine if a callback is being done in response to a 591 keypress, mouse click, etc. 592 */ event()593 static int event() {return e_number;} 594 /** 595 Returns the mouse position of the event relative to the Fl_Window 596 it was passed to. 597 */ event_x()598 static int event_x() {return e_x;} 599 /** 600 Returns the mouse position of the event relative to the Fl_Window 601 it was passed to. 602 */ event_y()603 static int event_y() {return e_y;} 604 /** 605 Returns the mouse position on the screen of the event. To find the 606 absolute position of an Fl_Window on the screen, use the 607 difference between event_x_root(),event_y_root() and 608 event_x(),event_y(). 609 */ event_x_root()610 static int event_x_root() {return e_x_root;} 611 /** 612 Returns the mouse position on the screen of the event. To find the 613 absolute position of an Fl_Window on the screen, use the 614 difference between event_x_root(),event_y_root() and 615 event_x(),event_y(). 616 */ event_y_root()617 static int event_y_root() {return e_y_root;} 618 /** 619 Returns the current horizontal mouse scrolling associated with the 620 FL_MOUSEWHEEL event. Right is positive. 621 */ event_dx()622 static int event_dx() {return e_dx;} 623 /** 624 Returns the current vertical mouse scrolling associated with the 625 FL_MOUSEWHEEL event. Down is positive. 626 */ event_dy()627 static int event_dy() {return e_dy;} 628 /** 629 Return where the mouse is on the screen by doing a round-trip query to 630 the server. You should use Fl::event_x_root() and 631 Fl::event_y_root() if possible, but this is necessary if you are 632 not sure if a mouse event has been processed recently (such as to 633 position your first window). If the display is not open, this will 634 open it. 635 */ 636 static void get_mouse(int &,int &); // platform dependent 637 /** 638 Returns non zero if we had a double click event. 639 \retval Non-zero if the most recent FL_PUSH or FL_KEYBOARD was a "double click". 640 \retval N-1 for N clicks. 641 A double click is counted if the same button is pressed 642 again while event_is_click() is true. 643 644 */ event_clicks()645 static int event_clicks() {return e_clicks;} 646 /** 647 Manually sets the number returned by Fl::event_clicks(). 648 This can be used to set it to zero so that 649 later code does not think an item was double-clicked. 650 \param[in] i corresponds to no double-click if 0, i+1 mouse clicks otherwise 651 \see int event_clicks() 652 */ event_clicks(int i)653 static void event_clicks(int i) {e_clicks = i;} 654 /** 655 Returns non-zero if the mouse has not moved far enough 656 and not enough time has passed since the last FL_PUSH or 657 FL_KEYBOARD event for it to be considered a "drag" rather than a 658 "click". You can test this on FL_DRAG, FL_RELEASE, 659 and FL_MOVE events. 660 */ event_is_click()661 static int event_is_click() {return e_is_click;} 662 /** 663 Clears the value returned by Fl::event_is_click(). 664 Useful to prevent the <I>next</I> 665 click from being counted as a double-click or to make a popup menu 666 pick an item with a single click. Don't pass non-zero to this. 667 */ event_is_click(int i)668 static void event_is_click(int i) {e_is_click = i;} 669 /** 670 Gets which particular mouse button caused the current event. 671 672 This returns garbage if the most recent event was not a FL_PUSH or FL_RELEASE event. 673 \retval FL_LEFT_MOUSE 674 \retval FL_MIDDLE_MOUSE 675 \retval FL_RIGHT_MOUSE. 676 \see Fl::event_buttons() 677 */ event_button()678 static int event_button() {return e_keysym-FL_Button;} 679 /** 680 Returns the keyboard and mouse button states of the last event. 681 682 This is a bitfield of what shift states were on and what mouse buttons 683 were held down during the most recent event. 684 685 The legal event state bits are: 686 687 - FL_SHIFT 688 - FL_CAPS_LOCK 689 - FL_CTRL 690 - FL_ALT 691 - FL_NUM_LOCK 692 - FL_META 693 - FL_SCROLL_LOCK 694 - FL_BUTTON1 695 - FL_BUTTON2 696 - FL_BUTTON3 697 698 X servers do not agree on shift states, and FL_NUM_LOCK, FL_META, and 699 FL_SCROLL_LOCK may not work. The values were selected to match the 700 XFree86 server on Linux. In addition there is a bug in the way X works 701 so that the shift state is not correctly reported until the first event 702 <I>after</I> the shift key is pressed or released. 703 */ event_state()704 static int event_state() {return e_state;} 705 706 /** Returns non-zero if any of the passed event state bits are turned on. 707 708 Use \p mask to pass the event states you're interested in. 709 The legal event state bits are defined in Fl::event_state(). 710 */ event_state(int mask)711 static int event_state(int mask) {return e_state&mask;} 712 /** 713 Gets which key on the keyboard was last pushed. 714 715 The returned integer 'key code' is not necessarily a text 716 equivalent for the keystroke. For instance: if someone presses '5' on the 717 numeric keypad with numlock on, Fl::event_key() may return the 'key code' 718 for this key, and NOT the character '5'. To always get the '5', use Fl::event_text() instead. 719 720 \returns an integer 'key code', or 0 if the last event was not a key press or release. 721 \see int event_key(int), event_text(), compose(int&). 722 */ event_key()723 static int event_key() {return e_keysym;} 724 /** 725 Returns the keycode of the last key event, regardless of the NumLock state. 726 727 If NumLock is deactivated, FLTK translates events from the 728 numeric keypad into the corresponding arrow key events. 729 event_key() returns the translated key code, whereas 730 event_original_key() returns the keycode before NumLock translation. 731 */ event_original_key()732 static int event_original_key(){return e_original_keysym;} 733 /** 734 Returns true if the given \p key was held 735 down (or pressed) <I>during</I> the last event. This is constant until 736 the next event is read from the server. 737 738 Fl::get_key(int) returns true if the given key is held down <I>now</I>. 739 Under X this requires a round-trip to the server and is <I>much</I> 740 slower than Fl::event_key(int). 741 742 Keys are identified by the <I>unshifted</I> values. FLTK defines a 743 set of symbols that should work on most modern machines for every key 744 on the keyboard: 745 746 \li All keys on the main keyboard producing a printable ASCII 747 character use the value of that ASCII character (as though shift, 748 ctrl, and caps lock were not on). The space bar is 32. 749 \li All keys on the numeric keypad producing a printable ASCII 750 character use the value of that ASCII character plus FL_KP. 751 The highest possible value is FL_KP_Last so you can 752 range-check to see if something is on the keypad. 753 \li All numbered function keys use the number on the function key plus 754 FL_F. The highest possible number is FL_F_Last, so you 755 can range-check a value. 756 \li Buttons on the mouse are considered keys, and use the button 757 number (where the left button is 1) plus FL_Button. 758 \li All other keys on the keypad have a symbol: FL_Escape, 759 FL_BackSpace, FL_Tab, FL_Enter, FL_Print, FL_Scroll_Lock, FL_Pause, 760 FL_Insert, FL_Home, FL_Page_Up, FL_Delete, FL_End, FL_Page_Down, 761 FL_Left, FL_Up, FL_Right, FL_Down, FL_Iso_Key, FL_Shift_L, FL_Shift_R, 762 FL_Control_L, FL_Control_R, FL_Caps_Lock, FL_Alt_L, FL_Alt_R, 763 FL_Meta_L, FL_Meta_R, FL_Menu, FL_Num_Lock, FL_KP_Enter. Be 764 careful not to confuse these with the very similar, but all-caps, 765 symbols used by Fl::event_state(). 766 767 On X Fl::get_key(FL_Button+n) does not work. 768 769 On WIN32 Fl::get_key(FL_KP_Enter) and Fl::event_key(FL_KP_Enter) do not work. 770 */ 771 static int event_key(int key); 772 /** 773 Returns true if the given \p key is held down <I>now</I>. 774 Under X this requires a round-trip to the server and is <I>much</I> 775 slower than Fl::event_key(int). \see event_key(int) 776 */ 777 static int get_key(int key); // platform dependent 778 /** 779 Returns the text associated with the current event, including FL_PASTE or FL_DND_RELEASE events. 780 This can be used in response to FL_KEYUP, FL_KEYDOWN, FL_PASTE, and FL_DND_RELEASE. 781 782 When responding to FL_KEYUP/FL_KEYDOWN, use this function instead of Fl::event_key() 783 to get the text equivalent of keystrokes suitable for inserting into strings 784 and text widgets. 785 786 The returned string is guaranteed to be NULL terminated. 787 However, see Fl::event_length() for the actual length of the string, 788 in case the string itself contains NULLs that are part of the text data. 789 790 \returns A NULL terminated text string equivalent of the last keystroke. 791 */ event_text()792 static const char* event_text() {return e_text;} 793 /** 794 Returns the length of the text in Fl::event_text(). There 795 will always be a nul at this position in the text. However there may 796 be a nul before that if the keystroke translates to a nul character or 797 you paste a nul character. 798 */ event_length()799 static int event_length() {return e_length;} 800 801 /** During an FL_PASTE event of non-textual data, returns a pointer to the pasted data. 802 The returned data is an Fl_Image * when the result of Fl::event_clipboard_type() is Fl::clipboard_image. 803 */ event_clipboard()804 static void *event_clipboard() { return e_clipboard_data; } 805 /** Returns the type of the pasted data during an FL_PASTE event. 806 This type can be Fl::clipboard_plain_text or Fl::clipboard_image. 807 */ event_clipboard_type()808 static const char *event_clipboard_type() {return e_clipboard_type; } 809 810 811 static int compose(int &del); 812 static void compose_reset(); 813 static int event_inside(int,int,int,int); 814 static int event_inside(const Fl_Widget*); 815 static int test_shortcut(Fl_Shortcut); 816 817 /** 818 Enables the system input methods facilities. This is the default. 819 \see disable_im() 820 */ 821 static void enable_im(); 822 /** 823 Disables the system input methods facilities. 824 \see enable_im() 825 */ 826 static void disable_im(); 827 828 // event destinations: 829 static int handle(int, Fl_Window*); 830 static int handle_(int, Fl_Window*); 831 /** Gets the widget that is below the mouse. 832 \see belowmouse(Fl_Widget*) */ belowmouse()833 static Fl_Widget* belowmouse() {return belowmouse_;} 834 static void belowmouse(Fl_Widget*); 835 /** Gets the widget that is being pushed. 836 \see void pushed(Fl_Widget*) */ pushed()837 static Fl_Widget* pushed() {return pushed_;} 838 static void pushed(Fl_Widget*); 839 /** Gets the current Fl::focus() widget. \sa Fl::focus(Fl_Widget*) */ focus()840 static Fl_Widget* focus() {return focus_;} 841 static void focus(Fl_Widget*); 842 static void add_handler(Fl_Event_Handler h); 843 static void remove_handler(Fl_Event_Handler h); 844 static void add_system_handler(Fl_System_Handler h, void *data); 845 static void remove_system_handler(Fl_System_Handler h); 846 static void event_dispatch(Fl_Event_Dispatch d); 847 static Fl_Event_Dispatch event_dispatch(); 848 /** @} */ 849 850 /** \defgroup fl_clipboard Selection & Clipboard functions 851 FLTK global copy/cut/paste functions declared in <FL/Fl.H> 852 @{ */ 853 // cut/paste: 854 /** 855 Copies the data pointed to by \p stuff to the selection buffer 856 (\p destination is 0), the clipboard (\p destination is 1), or 857 both (\p destination is 2). Copying to both is only relevant on X11, 858 on other platforms it maps to the clipboard (1). 859 \p len is the number of relevant bytes in \p stuff. 860 \p type is always Fl::clipboard_plain_text. 861 The selection buffer is used for 862 middle-mouse pastes and for drag-and-drop selections. The 863 clipboard is used for traditional copy/cut/paste operations. 864 865 \note This function is, at present, intended only to copy UTF-8 encoded textual data. 866 To copy graphical data, use the Fl_Copy_Surface class. The \p type argument may allow 867 in the future to copy other kinds of data. 868 */ 869 #if FLTK_ABI_VERSION >= 10303 || defined(FL_DOXYGEN) 870 static void copy(const char* stuff, int len, int destination = 0, const char *type = Fl::clipboard_plain_text); // platform dependent 871 #else 872 static void copy(const char* stuff, int len, int destination, const char *type); 873 static void copy(const char* stuff, int len, int destination = 0); 874 #endif 875 876 #if !(defined(__APPLE__) || defined(WIN32) || defined(FL_DOXYGEN)) 877 static void copy_image(const unsigned char* data, int W, int H, int destination = 0); // platform dependent 878 #endif 879 /** 880 Pastes the data from the selection buffer (\p source is 0) or the clipboard 881 (\p source is 1) into \p receiver. 882 883 The selection buffer (\p source is 0) is used for middle-mouse pastes and for 884 drag-and-drop selections. The clipboard (\p source is 1) is used for 885 copy/cut/paste operations. 886 887 If \p source is 1, the optional \p type argument indicates what type of data is requested from the clipboard. 888 At present, Fl::clipboard_plain_text (requesting text data) and 889 Fl::clipboard_image (requesting image data) are possible. 890 Set things up so the handle function of the \p receiver widget will be called with an FL_PASTE event some 891 time in the future if the clipboard does contain data of the requested type. 892 While processing the FL_PASTE event: 893 \li if \p type is Fl::clipboard_plain_text, the text string from the specified \p source is in Fl::event_text() 894 with UTF-8 encoding, and the number of bytes in Fl::event_length(). 895 If Fl::paste() gets called during the drop step of a files-drag-and-drop operation, 896 Fl::event_text() contains a list of filenames (see \ref events_dnd). 897 \li if \p type is Fl::clipboard_image, the pointer returned by Fl::event_clipboard() can be safely cast to 898 type Fl_Image * to obtain a pointer to the pasted image. Furthermore, starting with FLTK 1.3.4, the image is 899 of type Fl_RGB_Image across all platforms. 900 If \p receiver accepts the clipboard image, receiver.handle() should return 1 and the 901 application should take ownership of this image (that is, delete it after use). 902 Conversely, if receiver.handle() returns 0, the application must not use the image. 903 904 The receiver should be prepared to be called \e directly by this, or for 905 it to happen \e later, or possibly <i>not at all</i>. This 906 allows the window system to take as long as necessary to retrieve 907 the paste buffer (or even to screw up completely) without complex 908 and error-prone synchronization code in FLTK. 909 910 \par Platform details for image data: 911 \li Unix/Linux platform: Clipboard images in PNG or BMP formats are recognized. Requires linking with the fltk_images library. 912 \li MSWindows platform: Both bitmap and vectorial (Enhanced metafile) data from clipboard 913 can be pasted as image data. 914 \li Mac OS X platform: Both bitmap (TIFF) and vectorial (PDF) data from clipboard 915 can be pasted as image data. 916 */ 917 #if FLTK_ABI_VERSION >= 10303 || defined(FL_DOXYGEN) 918 static void paste(Fl_Widget &receiver, int source, const char *type = Fl::clipboard_plain_text); // platform dependent 919 #else 920 static void paste(Fl_Widget &receiver, int source, const char *type); 921 static void paste(Fl_Widget &receiver, int source /*=0*/); 922 #endif 923 /** 924 FLTK will call the registered callback whenever there is a change to the 925 selection buffer or the clipboard. The source argument indicates which 926 of the two has changed. Only changes by other applications are reported. 927 928 Example: 929 \code 930 void clip_callback(int source, void *data) { 931 if ( source == 0 ) printf("CLIP CALLBACK: selection buffer changed\n"); 932 if ( source == 1 ) printf("CLIP CALLBACK: clipboard changed\n"); 933 } 934 [..] 935 int main() { 936 [..] 937 Fl::add_clipboard_notify(clip_callback); 938 [..] 939 } 940 \endcode 941 \note Some systems require polling to monitor the clipboard and may 942 therefore have some delay in detecting changes. 943 */ 944 static void add_clipboard_notify(Fl_Clipboard_Notify_Handler h, void *data = 0); 945 /** 946 Stop calling the specified callback when there are changes to the selection 947 buffer or the clipboard. 948 */ 949 static void remove_clipboard_notify(Fl_Clipboard_Notify_Handler h); 950 /** Returns non 0 if the clipboard contains data matching \p type. 951 \p type can be Fl::clipboard_plain_text or Fl::clipboard_image. 952 */ 953 static int clipboard_contains(const char *type); 954 /** Denotes plain textual data 955 */ 956 static char const * const clipboard_plain_text; 957 /** Denotes image data 958 */ 959 static char const * const clipboard_image; 960 961 /** 962 Initiate a Drag And Drop operation. The selection buffer should be 963 filled with relevant data before calling this method. FLTK will 964 then initiate the system wide drag and drop handling. Dropped data 965 will be marked as <i>text</i>. 966 967 Create a selection first using: 968 Fl::copy(const char *stuff, int len, 0) 969 */ 970 static int dnd(); // platform dependent 971 972 // These are for back-compatibility only: 973 /** back-compatibility only: Gets the widget owning the current selection 974 \see Fl_Widget* selection_owner(Fl_Widget*) */ selection_owner()975 static Fl_Widget* selection_owner() {return selection_owner_;} 976 static void selection_owner(Fl_Widget*); 977 static void selection(Fl_Widget &owner, const char*, int len); 978 static void paste(Fl_Widget &receiver); 979 /** @} */ 980 /** \defgroup fl_screen Screen functions 981 fl global screen functions declared in <FL/Fl.H> 982 @{ */ 983 // screen size: 984 /** Returns the leftmost x coordinate of the main screen work area. */ 985 static int x(); // platform dependent 986 /** Returns the topmost y coordinate of the main screen work area. */ 987 static int y(); // platform dependent 988 /** Returns the width in pixels of the main screen work area. */ 989 static int w(); // platform dependent 990 /** Returns the height in pixels of the main screen work area. */ 991 static int h(); // platform dependent 992 993 // multi-head support: 994 static int screen_count(); 995 /** 996 Gets the bounding box of a screen that contains the mouse pointer. 997 \param[out] X,Y,W,H the corresponding screen bounding box 998 \see void screen_xywh(int &x, int &y, int &w, int &h, int mx, int my) 999 */ screen_xywh(int & X,int & Y,int & W,int & H)1000 static void screen_xywh(int &X, int &Y, int &W, int &H) { 1001 int x, y; 1002 Fl::get_mouse(x, y); 1003 screen_xywh(X, Y, W, H, x, y); 1004 } 1005 static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my); 1006 static void screen_xywh(int &X, int &Y, int &W, int &H, int n); 1007 static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh); 1008 static int screen_num(int x, int y); 1009 static int screen_num(int x, int y, int w, int h); 1010 static void screen_dpi(float &h, float &v, int n=0); 1011 static void screen_work_area(int &X, int &Y, int &W, int &H, int mx, int my); 1012 static void screen_work_area(int &X, int &Y, int &W, int &H, int n); 1013 /** 1014 Gets the bounding box of the work area of the screen that contains the mouse pointer. 1015 \param[out] X,Y,W,H the work area bounding box 1016 \see void screen_work_area(int &x, int &y, int &w, int &h, int mx, int my) 1017 */ screen_work_area(int & X,int & Y,int & W,int & H)1018 static void screen_work_area(int &X, int &Y, int &W, int &H) { 1019 int x, y; 1020 Fl::get_mouse(x, y); 1021 screen_work_area(X, Y, W, H, x, y); 1022 } 1023 1024 /** @} */ 1025 1026 /** \defgroup fl_attributes Color & Font functions 1027 fl global color, font functions. 1028 These functions are declared in <FL/Fl.H> or <FL/fl_draw.H>. 1029 @{ */ 1030 1031 // color map: 1032 static void set_color(Fl_Color, uchar, uchar, uchar); 1033 /** 1034 Sets an entry in the fl_color index table. You can set it to any 1035 8-bit RGB color. The color is not allocated until fl_color(i) is used. 1036 */ 1037 static void set_color(Fl_Color i, unsigned c); // platform dependent 1038 static unsigned get_color(Fl_Color i); 1039 static void get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue); 1040 /** 1041 Frees the specified color from the colormap, if applicable. 1042 If overlay is non-zero then the color is freed from the 1043 overlay colormap. 1044 */ 1045 static void free_color(Fl_Color i, int overlay = 0); // platform dependent 1046 1047 // fonts: 1048 static const char* get_font(Fl_Font); 1049 /** 1050 Get a human-readable string describing the family of this face. This 1051 is useful if you are presenting a choice to the user. There is no 1052 guarantee that each face has a different name. The return value points 1053 to a static buffer that is overwritten each call. 1054 1055 The integer pointed to by \p attributes (if the pointer is not 1056 zero) is set to zero, FL_BOLD or FL_ITALIC or 1057 FL_BOLD | FL_ITALIC. To locate a "family" of fonts, search 1058 forward and back for a set with non-zero attributes, these faces along 1059 with the face with a zero attribute before them constitute a family. 1060 */ 1061 static const char* get_font_name(Fl_Font, int* attributes = 0); 1062 /** 1063 Return an array of sizes in \p sizep. The return value is the 1064 length of this array. The sizes are sorted from smallest to largest 1065 and indicate what sizes can be given to fl_font() that will 1066 be matched exactly (fl_font() will pick the closest size for 1067 other sizes). A zero in the first location of the array indicates a 1068 scalable font, where any size works, although the array may list sizes 1069 that work "better" than others. Warning: the returned array 1070 points at a static buffer that is overwritten each call. Under X this 1071 will open the display. 1072 */ 1073 static int get_font_sizes(Fl_Font, int*& sizep); 1074 static void set_font(Fl_Font, const char*); 1075 static void set_font(Fl_Font, Fl_Font); 1076 /** 1077 FLTK will open the display, and add every fonts on the server to the 1078 face table. It will attempt to put "families" of faces together, so 1079 that the normal one is first, followed by bold, italic, and bold 1080 italic. 1081 1082 The optional argument is a string to describe the set of fonts to 1083 add. Passing NULL will select only fonts that have the 1084 ISO8859-1 character set (and are thus usable by normal text). Passing 1085 "-*" will select all fonts with any encoding as long as they have 1086 normal X font names with dashes in them. Passing "*" will list every 1087 font that exists (on X this may produce some strange output). Other 1088 values may be useful but are system dependent. With WIN32 NULL 1089 selects fonts with ISO8859-1 encoding and non-NULL selects 1090 all fonts. 1091 1092 The return value is how many faces are in the table after this is done. 1093 */ 1094 static Fl_Font set_fonts(const char* = 0); // platform dependent 1095 1096 /** @} */ 1097 /** \defgroup fl_drawings Drawing functions 1098 FLTK global graphics and GUI drawing functions. 1099 These functions are declared in <FL/fl_draw.H>, 1100 and in <FL/x.H> for offscreen buffer-related ones. 1101 @{ */ 1102 // <Hack to re-order the 'Drawing functions' group> 1103 /** @} */ 1104 1105 // labeltypes: 1106 static void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*); 1107 /** Sets the functions to call to draw and measure a specific labeltype. */ 1108 static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined ? 1109 1110 // boxtypes: 1111 static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype); 1112 static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar); 1113 static void set_boxtype(Fl_Boxtype, Fl_Boxtype from); 1114 static int box_dx(Fl_Boxtype); 1115 static int box_dy(Fl_Boxtype); 1116 static int box_dw(Fl_Boxtype); 1117 static int box_dh(Fl_Boxtype); 1118 1119 static int draw_box_active(); 1120 static Fl_Color box_color(Fl_Color); 1121 static void set_box_color(Fl_Color); 1122 1123 // back compatibility: 1124 /** \addtogroup fl_windows 1125 @{ */ 1126 /** For back compatibility, sets the void Fl::fatal handler callback */ set_abort(Fl_Abort_Handler f)1127 static void set_abort(Fl_Abort_Handler f) {fatal = f;} 1128 static void (*atclose)(Fl_Window*,void*); 1129 static void default_atclose(Fl_Window*,void*); 1130 /** For back compatibility, sets the Fl::atclose handler callback. You 1131 can now simply change the callback for the window instead. 1132 \see Fl_Window::callback(Fl_Callback*) */ set_atclose(Fl_Atclose_Handler f)1133 static void set_atclose(Fl_Atclose_Handler f) {atclose = f;} 1134 /** @} */ 1135 1136 /** \addtogroup fl_events 1137 @{ */ 1138 /** Returns non-zero if the Shift key is pressed. */ event_shift()1139 static int event_shift() {return e_state&FL_SHIFT;} 1140 /** Returns non-zero if the Control key is pressed. */ event_ctrl()1141 static int event_ctrl() {return e_state&FL_CTRL;} 1142 /** Returns non-zero if the FL_COMMAND key is pressed, either FL_CTRL or on OSX FL_META. */ event_command()1143 static int event_command() {return e_state&FL_COMMAND;} 1144 /** Returns non-zero if the Alt key is pressed. */ event_alt()1145 static int event_alt() {return e_state&FL_ALT;} 1146 /** 1147 Returns the mouse buttons state bits; if non-zero, then at least one 1148 button is pressed now. This function returns the button state at the 1149 time of the event. During an FL_RELEASE event, the state 1150 of the released button will be 0. To find out, which button 1151 caused an FL_RELEASE event, you can use Fl::event_button() instead. 1152 \return a bit mask value like { [FL_BUTTON1] | [FL_BUTTON2] | [FL_BUTTON3] } 1153 */ event_buttons()1154 static int event_buttons() {return e_state&0x7f000000;} 1155 /** 1156 Returns non-zero if mouse button 1 is currently held down. 1157 For more details, see Fl::event_buttons(). 1158 */ event_button1()1159 static int event_button1() {return e_state&FL_BUTTON1;} 1160 /** 1161 Returns non-zero if button 2 is currently held down. 1162 For more details, see Fl::event_buttons(). 1163 */ event_button2()1164 static int event_button2() {return e_state&FL_BUTTON2;} 1165 /** 1166 Returns non-zero if button 3 is currently held down. 1167 For more details, see Fl::event_buttons(). 1168 */ event_button3()1169 static int event_button3() {return e_state&FL_BUTTON3;} 1170 /** @} */ 1171 1172 /** 1173 Sets an idle callback. 1174 1175 \deprecated This method is obsolete - use the add_idle() method instead. 1176 */ set_idle(Fl_Old_Idle_Handler cb)1177 static void set_idle(Fl_Old_Idle_Handler cb) {idle = cb;} 1178 /** See grab(Fl_Window*) */ grab(Fl_Window & win)1179 static void grab(Fl_Window& win) {grab(&win);} 1180 /** Releases the current grabbed window, equals grab(0). 1181 \deprecated Use Fl::grab(0) instead. 1182 \see grab(Fl_Window*) */ release()1183 static void release() {grab(0);} 1184 1185 // Visible focus methods... 1186 /** 1187 Gets or sets the visible keyboard focus on buttons and other 1188 non-text widgets. The default mode is to enable keyboard focus 1189 for all widgets. 1190 */ visible_focus(int v)1191 static void visible_focus(int v) { option(OPTION_VISIBLE_FOCUS, (v!=0)); } 1192 /** 1193 Gets or sets the visible keyboard focus on buttons and other 1194 non-text widgets. The default mode is to enable keyboard focus 1195 for all widgets. 1196 */ visible_focus()1197 static int visible_focus() { return option(OPTION_VISIBLE_FOCUS); } 1198 1199 // Drag-n-drop text operation methods... 1200 /** 1201 Gets or sets whether drag and drop text operations are supported. 1202 This specifically affects whether selected text can 1203 be dragged from text fields or dragged within a text field as a 1204 cut/paste shortcut. 1205 */ dnd_text_ops(int v)1206 static void dnd_text_ops(int v) { option(OPTION_DND_TEXT, (v!=0)); } 1207 /** 1208 Gets or sets whether drag and drop text operations are 1209 supported. This specifically affects whether selected text can 1210 be dragged from text fields or dragged within a text field as a 1211 cut/paste shortcut. 1212 */ dnd_text_ops()1213 static int dnd_text_ops() { return option(OPTION_DND_TEXT); } 1214 /** \defgroup fl_multithread Multithreading support functions 1215 fl multithreading support functions declared in <FL/Fl.H> 1216 @{ */ 1217 1218 // Multithreading support: 1219 static int lock(); 1220 static void unlock(); 1221 static void awake(void* message = 0); 1222 /** See void awake(void* message=0). */ 1223 static int awake(Fl_Awake_Handler cb, void* message = 0); 1224 /** 1225 The thread_message() method returns the last message 1226 that was sent from a child by the awake() method. 1227 1228 See also: \ref advanced_multithreading 1229 */ 1230 static void* thread_message(); // platform dependent 1231 /** @} */ 1232 1233 /** \defgroup fl_del_widget Safe widget deletion support functions 1234 1235 These functions, declared in <FL/Fl.H>, support deletion of widgets inside callbacks. 1236 1237 Fl::delete_widget() should be called when deleting widgets 1238 or complete widget trees (Fl_Group, Fl_Window, ...) inside 1239 callbacks. 1240 1241 The other functions are intended for internal use. The preferred 1242 way to use them is by using the helper class Fl_Widget_Tracker. 1243 1244 The following is to show how it works ... 1245 1246 There are three groups of related methods: 1247 1248 -# scheduled widget deletion 1249 - Fl::delete_widget() schedules widgets for deletion 1250 - Fl::do_widget_deletion() deletes all scheduled widgets 1251 -# widget watch list ("smart pointers") 1252 - Fl::watch_widget_pointer() adds a widget pointer to the watch list 1253 - Fl::release_widget_pointer() removes a widget pointer from the watch list 1254 - Fl::clear_widget_pointer() clears a widget pointer \e in the watch list 1255 -# the class Fl_Widget_Tracker: 1256 - the constructor calls Fl::watch_widget_pointer() 1257 - the destructor calls Fl::release_widget_pointer() 1258 - the access methods can be used to test, if a widget has been deleted 1259 \see Fl_Widget_Tracker. 1260 1261 @{ */ 1262 // Widget deletion: 1263 static void delete_widget(Fl_Widget *w); 1264 static void do_widget_deletion(); 1265 static void watch_widget_pointer(Fl_Widget *&w); 1266 static void release_widget_pointer(Fl_Widget *&w); 1267 static void clear_widget_pointer(Fl_Widget const *w); 1268 /** @} */ 1269 1270 /** sets whether GL windows should be drawn at high resolution on Apple 1271 computers with retina displays 1272 \version 1.3.4 1273 */ use_high_res_GL(int val)1274 static void use_high_res_GL(int val) { use_high_res_GL_ = val; } 1275 /** returns whether GL windows should be drawn at high resolution on Apple 1276 computers with retina displays. 1277 Default is no. 1278 \version 1.3.4 1279 */ use_high_res_GL()1280 static int use_high_res_GL() { return use_high_res_GL_; } 1281 1282 #ifdef FLTK_HAVE_CAIRO 1283 /** \defgroup group_cairo Cairo Support Functions and Classes 1284 @{ 1285 */ 1286 public: 1287 // Cairo support API 1288 static cairo_t * cairo_make_current(Fl_Window* w); 1289 /** when FLTK_HAVE_CAIRO is defined and cairo_autolink_context() is true, 1290 any current window dc is linked to a current cairo context. 1291 This is not the default, because it may not be necessary 1292 to add cairo support to all fltk supported windows. 1293 When you wish to associate a cairo context in this mode, 1294 you need to call explicitly in your draw() overridden method, 1295 Fl::cairo_make_current(Fl_Window*). This will create a cairo context 1296 but only for this Window. 1297 Still in custom cairo application it is possible to handle 1298 completely this process automatically by setting \p alink to true. 1299 In this last case, you don't need anymore to call Fl::cairo_make_current(). 1300 You can use Fl::cairo_cc() to get the current cairo context anytime. 1301 \note Only available when configure has the --enable-cairo option 1302 */ cairo_autolink_context(bool alink)1303 static void cairo_autolink_context(bool alink) {cairo_state_.autolink(alink);} 1304 /** 1305 Gets the current autolink mode for cairo support. 1306 \retval false if no cairo context autolink is made for each window. 1307 \retval true if any fltk window is attached a cairo context when it 1308 is current. \see void cairo_autolink_context(bool alink) 1309 \note Only available when configure has the --enable-cairo option 1310 */ cairo_autolink_context()1311 static bool cairo_autolink_context() {return cairo_state_.autolink();} 1312 /** Gets the current cairo context linked with a fltk window. */ cairo_cc()1313 static cairo_t * cairo_cc() { return cairo_state_.cc(); } 1314 /** Sets the current cairo context to \p c. 1315 Set \p own to true if you want fltk to handle this cc deletion. 1316 \note Only available when configure has the --enable-cairo option 1317 */ 1318 static void cairo_cc(cairo_t * c, bool own=false){ cairo_state_.cc(c, own); } 1319 1320 private: 1321 static cairo_t * cairo_make_current(void* gc); 1322 static cairo_t * cairo_make_current(void* gc, int W, int H); 1323 static Fl_Cairo_State cairo_state_; 1324 public: 1325 /** @} */ 1326 1327 #endif // FLTK_HAVE_CAIRO 1328 1329 }; 1330 1331 /** 1332 This class should be used to control safe widget deletion. 1333 1334 You can use an Fl_Widget_Tracker object to watch another widget, if you 1335 need to know, if this widget has been deleted during a callback. 1336 1337 This simplifies the use of the "safe widget deletion" methods 1338 Fl::watch_widget_pointer() and Fl::release_widget_pointer() and 1339 makes their use more reliable, because the destructor autmatically 1340 releases the widget pointer from the widget watch list. 1341 1342 It is intended to be used as an automatic (local/stack) variable, 1343 such that the automatic destructor is called when the object's 1344 scope is left. This ensures that no stale widget pointers are 1345 left in the widget watch list (see example below). 1346 1347 You can also create Fl_Widget_Tracker objects with \c new, but then it 1348 is your responsibility to delete the object (and thus remove the 1349 widget pointer from the watch list) when it is not needed any more. 1350 1351 Example: 1352 1353 \code 1354 int MyClass::handle (int event) { 1355 1356 if (...) { 1357 Fl_Widget_Tracker wp(this); // watch myself 1358 do_callback(); // call the callback 1359 1360 if (wp.deleted()) return 1; // exit, if deleted 1361 1362 // Now we are sure that the widget has not been deleted. 1363 // It is safe to access the widget 1364 1365 clear_changed(); // access the widget 1366 } 1367 } 1368 \endcode 1369 1370 */ 1371 class FL_EXPORT Fl_Widget_Tracker { 1372 1373 Fl_Widget* wp_; 1374 1375 public: 1376 1377 Fl_Widget_Tracker(Fl_Widget *wi); 1378 ~Fl_Widget_Tracker(); 1379 1380 /** 1381 Returns a pointer to the watched widget. 1382 1383 This pointer is \c NULL, if the widget has been deleted. 1384 */ widget()1385 Fl_Widget *widget() {return wp_;} 1386 1387 /** 1388 Returns 1, if the watched widget has been deleted. 1389 1390 This is a convenience method. You can also use something like 1391 1392 <tt> if (wp.widget() == 0) // ...</tt> 1393 1394 where \p wp is an Fl_Widget_Tracker object. 1395 */ deleted()1396 int deleted() {return wp_ == 0;} 1397 1398 /** 1399 Returns 1, if the watched widget exists (has not been deleted). 1400 1401 This is a convenience method. You can also use something like 1402 1403 <tt> if (wp.widget() != 0) // ...</tt> 1404 1405 where \p wp is an Fl_Widget_Tracker object. 1406 */ exists()1407 int exists() {return wp_ != 0;} 1408 1409 }; 1410 1411 /** \defgroup fl_unicode Unicode and UTF-8 functions 1412 fl global Unicode and UTF-8 handling functions declared in <FL/fl_utf8.h> 1413 @{ */ 1414 /** @} */ 1415 1416 #endif // !Fl_H 1417 1418 // 1419 // End of "$Id$". 1420 // 1421