2 // "$Id: Fl.H 8724 2011-05-23 18:01:29Z manolo $"
4 // Main header file for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2010 by Bill Spitzak and others.
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
35 # include <FL/Fl_Cairo.H>
38 # include "Enumerations.H"
40 # define Fl_Object Fl_Widget /**< for back compatibility - use Fl_Widget! */
54 /** \defgroup callback_functions Callback function typedefs
55 \brief Typedefs defined in <FL/Fl.H> for callback or handler functions passed as function parameters.
57 FLTK uses callback functions as parameters for some function calls, e.g. to
58 set up global event handlers (Fl::add_handler()), to add a timeout handler
59 (Fl::add_timeout()), and many more.
61 The typedefs defined in this group describe the function parameters used to set
62 up or clear the callback functions and should also be referenced to define the
63 callback function to handle such events in the user's code.
65 \see Fl::add_handler(), Fl::add_timeout(), Fl::repeat_timeout(),
66 Fl::remove_timeout() and others
69 /** Signature of some label drawing functions passed as parameters */
70 typedef void (Fl_Label_Draw_F)(const Fl_Label *label, int x, int y, int w, int h, Fl_Align align);
72 /** Signature of some label measurement functions passed as parameters */
73 typedef void (Fl_Label_Measure_F)(const Fl_Label *label, int &width, int &height);
75 /** Signature of some box drawing functions passed as parameters */
76 typedef void (Fl_Box_Draw_F)(int x, int y, int w, int h, Fl_Color color);
78 /** Signature of some timeout callback functions passed as parameters */
79 typedef void (*Fl_Timeout_Handler)(void *data);
81 /** Signature of some wakeup callback functions passed as parameters */
82 typedef void (*Fl_Awake_Handler)(void *data);
84 /** Signature of add_idle callback functions passed as parameters */
85 typedef void (*Fl_Idle_Handler)(void *data);
87 /** Signature of set_idle callback functions passed as parameters */
88 typedef void (*Fl_Old_Idle_Handler)();
90 /** Signature of add_fd functions passed as parameters */
91 typedef void (*Fl_FD_Handler)(int fd, void *data);
93 /** Signature of add_handler functions passed as parameters */
94 typedef int (*Fl_Event_Handler)(int event);
96 /** Signature of set_abort functions passed as parameters */
97 typedef void (*Fl_Abort_Handler)(const char *format,...);
99 /** Signature of set_atclose functions passed as parameters */
100 typedef void (*Fl_Atclose_Handler)(Fl_Window *window, void *data);
102 /** Signature of args functions passed as parameters */
103 typedef int (*Fl_Args_Handler)(int argc, char **argv, int &i);
105 /** Signature of event_dispatch functions passed as parameters.
106 \see Fl::event_dispatch(Fl_Event_Dispatch) */
107 typedef int (*Fl_Event_Dispatch)(int event, Fl_Window *w);
109 /** @} */ /* group callback_functions */
113 The Fl is the FLTK global (static) class containing
114 state information and global methods for the current application.
117 Fl() {}; // no constructor!
119 public: // should be private!
130 static int e_is_click;
134 static Fl_Event_Dispatch e_dispatch;
135 static Fl_Widget* belowmouse_;
136 static Fl_Widget* pushed_;
137 static Fl_Widget* focus_;
139 static Fl_Widget* selection_owner_;
140 static Fl_Window* modal_;
141 static Fl_Window* grab_;
142 static int compose_state;
145 If true then flush() will do something.
147 static void damage(int d) {damage_ = d;}
150 /** Enumerator for global FLTK options.
151 These options can be set system wide, per user, or for the running
153 \see Fl::option(Fl_Option, bool)
154 \see Fl::option(Fl_Option)
157 /// When switched on, moving the text cursor beyond the start or end of
158 /// a text in a text widget will change focus to the next text widget.
159 /// When switched off, the cursor will stop at the end of the text.
160 /// Pressing Tab or Ctrl-Tab will advance the keyboard focus.
161 OPTION_ARROW_FOCUS = 0,
162 // When switched on, FLTK will use the file chooser dialog that comes
163 // with your operating system whenever possible. When switched off, FLTK
164 // will present its own file chooser.
165 // \todo implement me
166 // OPTION_NATIVE_FILECHOOSER,
167 // When Filechooser Preview is enabled, the FLTK or native file chooser
168 // will show a preview of a selected file (if possible) before the user
169 // decides to choose the file.
170 // \todo implement me
171 //OPTION_FILECHOOSER_PREVIEW,
172 /// If visible focus is switched on, FLTK will draw a dotted rectangle
173 /// inside the widget that will receive the next keystroke. If switched
174 /// off, no such indicator will be drawn and keyboard navigation
176 OPTION_VISIBLE_FOCUS,
177 /// If text drag-and-drop is enabled, the user can select and drag text
178 /// from any text widget. If disabled, no dragging is possible, however
179 /// dropping text from other applications still works.
181 /// If tooltips are enabled, hovering the mouse over a widget with a
182 /// tooltip text will open a little tooltip window until the mouse leaves
183 /// the widget. If disabled, no tooltip is shown.
184 OPTION_SHOW_TOOLTIPS,
185 // don't change this, leave it always as the last element
186 /// For internal use only.
191 static unsigned char options_[OPTION_LAST];
192 static unsigned char options_read_;
196 Return a global setting for all FLTK applications, possibly overridden
197 by a setting specifically for this application.
199 static bool option(Fl_Option opt);
202 Override an option while the application is running.
204 static void option(Fl_Option opt, bool val);
207 The currently executing idle callback function: DO NOT USE THIS DIRECTLY!
209 This is now used as part of a higher level system allowing multiple
210 idle callback functions to be called.
211 \see add_idle(), remove_idle()
213 static void (*idle)();
216 static Fl_Awake_Handler *awake_ring_;
217 static void **awake_data_;
218 static int awake_ring_size_;
219 static int awake_ring_head_;
220 static int awake_ring_tail_;
221 static const char* scheme_;
222 static Fl_Image* scheme_bg_;
224 static int e_original_keysym; // late addition
225 static int scrollbar_size_;
229 static int add_awake_handler_(Fl_Awake_Handler, void*);
230 static int get_awake_handler_(Fl_Awake_Handler&, void*&);
234 // API version number
235 static double version();
238 static int arg(int argc, char **argv, int& i);
239 static int args(int argc, char **argv, int& i, Fl_Args_Handler cb = 0);
240 static void args(int argc, char **argv);
242 Usage string displayed if Fl::args() detects an invalid argument.
243 This may be changed to point to customized text at run-time.
245 static const char* const help;
247 // things called by initialization:
248 static void display(const char*);
249 static int visual(int);
251 This does the same thing as Fl::visual(int) but also requires OpenGL
252 drawing to work. This <I>must</I> be done if you want to draw in
253 normal windows with OpenGL with gl_start() and gl_end().
254 It may be useful to call this so your X windows use the same visual
255 as an Fl_Gl_Window, which on some servers will reduce colormap flashing.
257 See Fl_Gl_Window for a list of additional values for the argument.
259 static int gl_visual(int, int *alist=0); // platform dependent
260 static void own_colormap();
261 static void get_system_colors();
262 static void foreground(uchar, uchar, uchar);
263 static void background(uchar, uchar, uchar);
264 static void background2(uchar, uchar, uchar);
267 static int scheme(const char*);
268 /** See void scheme(const char *name) */
269 static const char* scheme() {return scheme_;}
271 Called by scheme according to scheme name.
272 Loads or reloads the current scheme selection.
273 See void scheme(const char *name)
275 static int reload_scheme(); // platform dependent
277 static void scheme_bg ( Fl_Image *i ) { scheme_bg_ = i; }
278 static int scrollbar_size();
279 static void scrollbar_size(int W);
283 static double wait(double time);
287 static Fl_Widget* readqueue();
289 Adds a one-shot timeout callback. The function will be called by
290 Fl::wait() at <i>t</i> seconds after this function is called.
291 The optional void* argument is passed to the callback.
293 You can have multiple timeout callbacks. To remove a timeout
294 callback use Fl::remove_timeout().
296 If you need more accurate, repeated timeouts, use Fl::repeat_timeout() to
297 reschedule the subsequent timeouts.
299 The following code will print "TICK" each second on
300 stdout with a fair degree of accuracy:
303 void callback(void*) {
305 Fl::repeat_timeout(1.0, callback);
309 Fl::add_timeout(1.0, callback);
314 static void add_timeout(double t, Fl_Timeout_Handler,void* = 0); // platform dependent
316 Repeats a timeout callback from the expiration of the
317 previous timeout, allowing for more accurate timing. You may only call
318 this method inside a timeout callback.
320 The following code will print "TICK" each second on
321 stdout with a fair degree of accuracy:
324 void callback(void*) {
326 Fl::repeat_timeout(1.0, callback);
330 Fl::add_timeout(1.0, callback);
335 static void repeat_timeout(double t, Fl_Timeout_Handler, void* = 0); // platform dependent
336 static int has_timeout(Fl_Timeout_Handler, void* = 0);
337 static void remove_timeout(Fl_Timeout_Handler, void* = 0);
338 static void add_check(Fl_Timeout_Handler, void* = 0);
339 static int has_check(Fl_Timeout_Handler, void* = 0);
340 static void remove_check(Fl_Timeout_Handler, void* = 0);
342 Adds file descriptor fd to listen to.
344 When the fd becomes ready for reading Fl::wait() will call the
345 callback and then return. The callback is passed the fd and the
346 arbitrary void* argument.
348 The second version takes a when bitfield, with the bits
349 FL_READ, FL_WRITE, and FL_EXCEPT defined,
350 to indicate when the callback should be done.
352 There can only be one callback of each type for a file descriptor.
353 Fl::remove_fd() gets rid of <I>all</I> the callbacks for a given
356 Under UNIX <I>any</I> file descriptor can be monitored (files,
357 devices, pipes, sockets, etc.). Due to limitations in Microsoft Windows,
358 WIN32 applications can only monitor sockets.
360 static void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0); // platform dependent
361 /** See void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0) */
362 static void add_fd(int fd, Fl_FD_Handler cb, void* = 0); // platform dependent
363 /** Removes a file descriptor handler. */
364 static void remove_fd(int, int when); // platform dependent
365 /** Removes a file descriptor handler. */
366 static void remove_fd(int); // platform dependent
368 static void add_idle(Fl_Idle_Handler cb, void* data = 0);
369 static int has_idle(Fl_Idle_Handler cb, void* data = 0);
370 static void remove_idle(Fl_Idle_Handler cb, void* data = 0);
371 /** If true then flush() will do something. */
372 static int damage() {return damage_;}
373 static void redraw();
375 /** \addtogroup group_comdlg
378 FLTK calls Fl::warning() to output a warning message.
380 The default version on Windows returns \e without printing a warning
381 message, because Windows programs normally don't have stderr (a console
384 The default version on all other platforms prints the warning message to stderr.
386 You can override the behavior by setting the function pointer to your
389 Fl::warning() means that there was a recoverable problem, the display may
390 be messed up, but the user can probably keep working - all X protocol
391 errors call this, for example. The default implementation returns after
392 displaying the message.
393 \note \#include <FL/Fl.H>
395 static void (*warning)(const char*, ...);
397 FLTK calls Fl::error() to output a normal error message.
399 The default version on Windows displays the error message in a MessageBox window.
401 The default version on all other platforms prints the error message to stderr.
403 You can override the behavior by setting the function pointer to your
406 Fl::error() means there is a recoverable error such as the inability to read
407 an image file. The default implementation returns after displaying the message.
408 \note \#include <FL/Fl.H>
410 static void (*error)(const char*, ...);
412 FLTK calls Fl::fatal() to output a fatal error message.
414 The default version on Windows displays the error message in a MessageBox window.
416 The default version on all other platforms prints the error message to stderr.
418 You can override the behavior by setting the function pointer to your
421 Fl::fatal() must not return, as FLTK is in an unusable state, however your
422 version may be able to use longjmp or an exception to continue, as long as
423 it does not call FLTK again. The default implementation exits with status 1
424 after displaying the message.
425 \note \#include <FL/Fl.H>
427 static void (*fatal)(const char*, ...);
430 /** \defgroup fl_windows Windows handling functions
431 \brief Windows and standard dialogs handling declared in <FL/Fl.H>
433 static Fl_Window* first_window();
434 static void first_window(Fl_Window*);
435 static Fl_Window* next_window(const Fl_Window*);
438 Returns the top-most modal() window currently shown.
440 This is the most recently shown() window with modal() true, or NULL
441 if there are no modal() windows shown().
442 The modal() window has its handle() method called
443 for all events, and no other windows will have handle()
444 called (grab() overrides this).
446 static Fl_Window* modal() {return modal_;}
447 /** Returns the window that currently receives all events.
449 \return The window that currently receives all events,
450 or NULL if event grabbing is currently OFF.
452 static Fl_Window* grab() {return grab_;}
453 /** Selects the window to grab.
454 This is used when pop-up menu systems are active.
456 Send all events to the passed window no matter where the pointer or
457 focus is (including in other programs). The window <I>does not have
458 to be shown()</I> , this lets the handle() method of a
459 "dummy" window override all event handling and allows you to
460 map and unmap a complex set of windows (under both X and WIN32
461 <I>some</I> window must be mapped because the system interface needs a
464 If grab() is on it will also affect show() of windows by doing
465 system-specific operations (on X it turns on override-redirect).
466 These are designed to make menus popup reliably
467 and faster on the system.
469 To turn off grabbing do Fl::grab(0).
471 <I>Be careful that your program does not enter an infinite loop
472 while grab() is on. On X this will lock up your screen!</I>
473 To avoid this potential lockup, all newer operating systems seem to
474 limit mouse pointer grabbing to the time during which a mouse button
475 is held down. Some OS's may not support grabbing at all.
477 static void grab(Fl_Window*); // platform dependent
480 /** \defgroup fl_events Events handling functions
481 Fl class events handling API declared in <FL/Fl.H>
484 // event information:
486 Returns the last event that was processed. This can be used
487 to determine if a callback is being done in response to a
488 keypress, mouse click, etc.
490 static int event() {return e_number;}
492 Returns the mouse position of the event relative to the Fl_Window
495 static int event_x() {return e_x;}
497 Returns the mouse position of the event relative to the Fl_Window
500 static int event_y() {return e_y;}
502 Returns the mouse position on the screen of the event. To find the
503 absolute position of an Fl_Window on the screen, use the
504 difference between event_x_root(),event_y_root() and
507 static int event_x_root() {return e_x_root;}
509 Returns the mouse position on the screen of the event. To find the
510 absolute position of an Fl_Window on the screen, use the
511 difference between event_x_root(),event_y_root() and
514 static int event_y_root() {return e_y_root;}
516 Returns the current horizontal mouse scrolling associated with the
517 FL_MOUSEWHEEL event. Right is positive.
519 static int event_dx() {return e_dx;}
521 Returns the current vertical mouse scrolling associated with the
522 FL_MOUSEWHEEL event. Down is positive.
524 static int event_dy() {return e_dy;}
526 Return where the mouse is on the screen by doing a round-trip query to
527 the server. You should use Fl::event_x_root() and
528 Fl::event_y_root() if possible, but this is necessary if you are
529 not sure if a mouse event has been processed recently (such as to
530 position your first window). If the display is not open, this will
533 static void get_mouse(int &,int &); // platform dependent
535 Set the pointer position in screen relative coordinates
537 static void set_mouse(int x,int y); // platform dependent
539 Returns non zero if we had a double click event.
540 \retval Non-zero if the most recent FL_PUSH or FL_KEYBOARD was a "double click".
541 \retval N-1 for N clicks.
542 A double click is counted if the same button is pressed
543 again while event_is_click() is true.
545 static int event_clicks() {return e_clicks;}
547 Manually sets the number returned by Fl::event_clicks().
548 This can be used to set it to zero so that
549 later code does not think an item was double-clicked.
550 \param[in] i corresponds to no double-click if 0, i+1 mouse clicks otherwise
551 \see int event_clicks()
553 static void event_clicks(int i) {e_clicks = i;}
555 Returns non-zero if the mouse has not moved far enough
556 and not enough time has passed since the last FL_PUSH or
557 FL_KEYBOARD event for it to be considered a "drag" rather than a
558 "click". You can test this on FL_DRAG, FL_RELEASE,
561 static int event_is_click() {return e_is_click;}
563 Clears the value returned by Fl::event_is_click().
564 Useful to prevent the <I>next</I>
565 click from being counted as a double-click or to make a popup menu
566 pick an item with a single click. Don't pass non-zero to this.
568 static void event_is_click(int i) {e_is_click = i;}
570 Gets which particular mouse button caused the current event.
571 This returns garbage if the most recent event was not a FL_PUSH or FL_RELEASE event.
572 \retval FL_LEFT_MOUSE \retval FL_MIDDLE_MOUSE \retval FL_RIGHT_MOUSE.
573 \see Fl::event_buttons()
575 static int event_button() {return e_keysym-FL_Button;}
577 This is a bitfield of what shift states were on and what mouse buttons
578 were held down during the most recent event. The second version
579 returns non-zero if any of the passed bits are turned on.
593 X servers do not agree on shift states, and FL_NUM_LOCK, FL_META, and
594 FL_SCROLL_LOCK may not work. The values were selected to match the
595 XFree86 server on Linux. In addition there is a bug in the way X works
596 so that the shift state is not correctly reported until the first event
597 <I>after</I> the shift key is pressed or released.
599 static int event_state() {return e_state;}
600 /** See int event_state() */
601 static int event_state(int i) {return e_state&i;}
603 Gets which key on the keyboard was last pushed.
605 The returned integer 'key code' is not necessarily a text
606 equivalent for the keystroke. For instance: if someone presses '5' on the
607 numeric keypad with numlock on, Fl::event_key() may return the 'key code'
608 for this key, and NOT the character '5'. To always get the '5', use Fl::event_text() instead.
610 \returns an integer 'key code', or 0 if the last event was not a key press or release.
611 \see int event_key(int), event_text(), compose(int&).
613 static int event_key() {return e_keysym;}
615 Returns the keycode of the last key event, regardless of the NumLock state.
617 If NumLock is deactivated, FLTK translates events from the
618 numeric keypad into the corresponding arrow key events.
619 event_key() returns the translated key code, whereas
620 event_original_key() returns the keycode before NumLock translation.
622 static int event_original_key(){return e_original_keysym;}
624 Returns true if the given \p key was held
625 down (or pressed) <I>during</I> the last event. This is constant until
626 the next event is read from the server.
628 Fl::get_key(int) returns true if the given key is held down <I>now</I>.
629 Under X this requires a round-trip to the server and is <I>much</I>
630 slower than Fl::event_key(int).
632 Keys are identified by the <I>unshifted</I> values. FLTK defines a
633 set of symbols that should work on most modern machines for every key
636 \li All keys on the main keyboard producing a printable ASCII
637 character use the value of that ASCII character (as though shift,
638 ctrl, and caps lock were not on). The space bar is 32.
639 \li All keys on the numeric keypad producing a printable ASCII
640 character use the value of that ASCII character plus FL_KP.
641 The highest possible value is FL_KP_Last so you can
642 range-check to see if something is on the keypad.
643 \li All numbered function keys use the number on the function key plus
644 FL_F. The highest possible number is FL_F_Last, so you
645 can range-check a value.
646 \li Buttons on the mouse are considered keys, and use the button
647 number (where the left button is 1) plus FL_Button.
648 \li All other keys on the keypad have a symbol: FL_Escape,
649 FL_BackSpace, FL_Tab, FL_Enter, FL_Print, FL_Scroll_Lock, FL_Pause,
650 FL_Insert, FL_Home, FL_Page_Up, FL_Delete, FL_End, FL_Page_Down,
651 FL_Left, FL_Up, FL_Right, FL_Down, FL_Shift_L, FL_Shift_R,
652 FL_Control_L, FL_Control_R, FL_Caps_Lock, FL_Alt_L, FL_Alt_R,
653 FL_Meta_L, FL_Meta_R, FL_Menu, FL_Num_Lock, FL_KP_Enter. Be
654 careful not to confuse these with the very similar, but all-caps,
655 symbols used by Fl::event_state().
657 On X Fl::get_key(FL_Button+n) does not work.
659 On WIN32 Fl::get_key(FL_KP_Enter) and Fl::event_key(FL_KP_Enter) do not work.
661 static int event_key(int key);
663 Returns true if the given \p key is held down <I>now</I>.
664 Under X this requires a round-trip to the server and is <I>much</I>
665 slower than Fl::event_key(int). \see event_key(int)
667 static int get_key(int key); // platform dependent
669 Returns the text associated with the current event, including FL_PASTE or FL_DND_RELEASE events.
670 This can be used in response to FL_KEYUP, FL_KEYDOWN, FL_PASTE, FL_DND_RELEASE.
672 When responding to FL_KEYUP/FL_KEYDOWN, use this function instead of Fl::event_key()
673 to get the text equivalent of keystrokes suitable for inserting into strings
676 The returned string is guaranteed to be be NULL terminated.
677 However, see Fl::event_length() for the actual length of the string,
678 in case the string itself contains NULLs that are part of the text data.
680 \returns A NULL terminated text string equivalent of the last keystroke.
682 static const char* event_text() {return e_text;}
684 Returns the length of the text in Fl::event_text(). There
685 will always be a nul at this position in the text. However there may
686 be a nul before that if the keystroke translates to a nul character or
687 you paste a nul character.
689 static int event_length() {return e_length;}
691 static int compose(int &del);
692 static void compose_reset();
693 static int event_inside(int,int,int,int);
694 static int event_inside(const Fl_Widget*);
695 static int test_shortcut(Fl_Shortcut);
697 // event destinations:
698 static int handle(int, Fl_Window*);
699 static int handle_(int, Fl_Window*);
700 /** Gets the widget that is below the mouse.
701 \see belowmouse(Fl_Widget*) */
702 static Fl_Widget* belowmouse() {return belowmouse_;}
703 static void belowmouse(Fl_Widget*);
704 /** Gets the widget that is being pushed.
705 \see void pushed(Fl_Widget*) */
706 static Fl_Widget* pushed() {return pushed_;}
707 static void pushed(Fl_Widget*);
708 /** Gets the current Fl::focus() widget. \sa Fl::focus(Fl_Widget*) */
709 static Fl_Widget* focus() {return focus_;}
710 static void focus(Fl_Widget*);
711 static void add_handler(Fl_Event_Handler h);
712 static void remove_handler(Fl_Event_Handler h);
713 static void event_dispatch(Fl_Event_Dispatch d);
714 static Fl_Event_Dispatch event_dispatch();
717 /** \defgroup fl_clipboard Selection & Clipboard functions
718 FLTK global copy/cut/paste functions declared in <FL/Fl.H>
722 Copies the data pointed to by \p stuff to the selection buffer
723 (\p destination is 0) or
724 the clipboard (\p destination is 1); \p len is the number of relevant
726 The selection buffer is used for
727 middle-mouse pastes and for drag-and-drop selections. The
728 clipboard is used for traditional copy/cut/paste operations.
730 static void copy(const char* stuff, int len, int destination = 0); // platform dependent
732 Pastes the data from the selection buffer (\p source is 0) or the clipboard
733 (\p source is 1) into \p receiver.
734 Set things up so the receiver widget will be called with an FL_PASTE event some
735 time in the future with the data from the specified \p source in Fl::event_text()
736 and the number of characters in Fl::event_length().
738 should be prepared to be called \e directly by this, or for
739 it to happen \e later, or possibly <i>not at all</i>. This
740 allows the window system to take as long as necessary to retrieve
741 the paste buffer (or even to screw up completely) without complex
742 and error-prone synchronization code in FLTK.
744 The selection buffer is used for middle-mouse pastes and for
745 drag-and-drop selections. The clipboard is used for traditional
746 copy/cut/paste operations.
748 static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent
750 Initiate a Drag And Drop operation. The selection buffer should be
751 filled with relevant data before calling this method. FLTK will
752 then initiate the system wide drag and drop handling. Dropped data
753 will be marked as <i>text</i>.
755 Create a selection first using:
756 Fl::copy(const char *stuff, int len, 0)
758 static int dnd(); // platform dependent
760 // These are for back-compatibility only:
761 /** back-compatibility only: Gets the widget owning the current selection
762 \see Fl_Widget* selection_owner(Fl_Widget*) */
763 static Fl_Widget* selection_owner() {return selection_owner_;}
764 static void selection_owner(Fl_Widget*);
765 static void selection(Fl_Widget &owner, const char*, int len);
766 static void paste(Fl_Widget &receiver);
768 /** \defgroup fl_screen Screen functions
769 fl global screen functions declared in <FL/Fl.H>
772 /** Returns the origin of the current screen work area, where 0 indicates the left side of the screen. */
773 static int x(); // platform dependent
774 /** Returns the origin of the current screen work area, where 0 indicates the top edge of the screen. */
775 static int y(); // platform dependent
776 /** Returns the width of the screen work area in pixels. */
777 static int w(); // platform dependent
778 /** Returns the height of the screen work area in pixels. */
779 static int h(); // platform dependent
781 // multi-head support:
782 static int screen_count();
784 Gets the bounding box of a screen that contains the mouse pointer.
785 \param[out] X,Y,W,H the corresponding screen bounding box
786 \see void screen_xywh(int &x, int &y, int &w, int &h, int mx, int my)
788 static void screen_xywh(int &X, int &Y, int &W, int &H) {
789 screen_xywh(X, Y, W, H, e_x_root, e_y_root);
791 static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
792 static void screen_xywh(int &X, int &Y, int &W, int &H, int n);
793 static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh);
794 static void screen_dpi(float &h, float &v, int n=0);
798 /** \defgroup fl_attributes Color & Font functions
799 fl global color, font functions.
800 These functions are declared in <FL/Fl.H> or <FL/fl_draw.H>.
804 static void set_color(Fl_Color, uchar, uchar, uchar);
806 Sets an entry in the fl_color index table. You can set it to any
807 8-bit RGB color. The color is not allocated until fl_color(i) is used.
809 static void set_color(Fl_Color i, unsigned c); // platform dependent
810 static unsigned get_color(Fl_Color i);
811 static void get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue);
813 Frees the specified color from the colormap, if applicable.
814 If overlay is non-zero then the color is freed from the
817 static void free_color(Fl_Color i, int overlay = 0); // platform dependent
820 static const char* get_font(Fl_Font);
822 Get a human-readable string describing the family of this face. This
823 is useful if you are presenting a choice to the user. There is no
824 guarantee that each face has a different name. The return value points
825 to a static buffer that is overwritten each call.
827 The integer pointed to by \p attributes (if the pointer is not
828 zero) is set to zero, FL_BOLD or FL_ITALIC or
829 FL_BOLD | FL_ITALIC. To locate a "family" of fonts, search
830 forward and back for a set with non-zero attributes, these faces along
831 with the face with a zero attribute before them constitute a family.
833 static const char* get_font_name(Fl_Font, int* attributes = 0);
835 Return an array of sizes in \p sizep. The return value is the
836 length of this array. The sizes are sorted from smallest to largest
837 and indicate what sizes can be given to fl_font() that will
838 be matched exactly (fl_font() will pick the closest size for
839 other sizes). A zero in the first location of the array indicates a
840 scalable font, where any size works, although the array may list sizes
841 that work "better" than others. Warning: the returned array
842 points at a static buffer that is overwritten each call. Under X this
843 will open the display.
845 static int get_font_sizes(Fl_Font, int*& sizep);
846 static void set_font(Fl_Font, const char*);
847 static void set_font(Fl_Font, Fl_Font);
849 FLTK will open the display, and add every fonts on the server to the
850 face table. It will attempt to put "families" of faces together, so
851 that the normal one is first, followed by bold, italic, and bold
854 The optional argument is a string to describe the set of fonts to
855 add. Passing NULL will select only fonts that have the
856 ISO8859-1 character set (and are thus usable by normal text). Passing
857 "-*" will select all fonts with any encoding as long as they have
858 normal X font names with dashes in them. Passing "*" will list every
859 font that exists (on X this may produce some strange output). Other
860 values may be useful but are system dependent. With WIN32 NULL
861 selects fonts with ISO8859-1 encoding and non-NULL selects
864 The return value is how many faces are in the table after this is done.
866 static Fl_Font set_fonts(const char* = 0); // platform dependent
869 /** \defgroup fl_drawings Drawing functions
870 FLTK global graphics and GUI drawing functions.
871 These functions are declared in <FL/fl_draw.H>,
872 and in <FL/x.H> for offscreen buffer-related ones.
874 // <Hack to re-order the 'Drawing functions' group>
878 static void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*);
879 /** Sets the functions to call to draw and measure a specific labeltype. */
880 static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined ?
883 static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype);
884 static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar);
885 static void set_boxtype(Fl_Boxtype, Fl_Boxtype from);
886 static int box_dx(Fl_Boxtype);
887 static int box_dy(Fl_Boxtype);
888 static int box_dw(Fl_Boxtype);
889 static int box_dh(Fl_Boxtype);
890 static int draw_box_active();
892 // back compatibility:
893 /** \addtogroup fl_windows
895 /** For back compatibility, sets the void Fl::fatal handler callback */
896 static void set_abort(Fl_Abort_Handler f) {fatal = f;}
897 static void (*atclose)(Fl_Window*,void*);
898 static void default_atclose(Fl_Window*,void*);
899 /** For back compatibility, sets the Fl::atclose handler callback. You
900 can now simply change the callback for the window instead.
901 \see Fl_Window::callback(Fl_Callback*) */
902 static void set_atclose(Fl_Atclose_Handler f) {atclose = f;}
905 /** \addtogroup fl_events
907 /** Returns non-zero if the Shift key is pressed. */
908 static int event_shift() {return e_state&FL_SHIFT;}
909 /** Returns non-zero if the Control key is pressed. */
910 static int event_ctrl() {return e_state&FL_CTRL;}
911 /** Returns non-zero if the FL_COMMAND key is pressed, either FL_CTRL or on OSX FL_META. */
912 static int event_command() {return e_state&FL_COMMAND;}
913 /** Returns non-zero if the Alt key is pressed. */
914 static int event_alt() {return e_state&FL_ALT;}
916 Returns the mouse buttons state bits; if non-zero, then at least one
917 button is pressed now. This function returns the button state at the
918 time of the event. During an FL_RELEASE event, the state
919 of the released button will be 0. To find out, which button
920 caused an FL_RELEASE event, you can use Fl::event_button() instead.
921 \return a bit mask value like { [FL_BUTTON1] | [FL_BUTTON2] | [FL_BUTTON3] }
923 static int event_buttons() {return e_state&0x7f000000;}
925 Returns non-zero if mouse button 1 is currently held down.
926 For more details, see Fl::event_buttons().
928 static int event_button1() {return e_state&FL_BUTTON1;}
930 Returns non-zero if button 2 is currently held down.
931 For more details, see Fl::event_buttons().
933 static int event_button2() {return e_state&FL_BUTTON2;}
935 Returns non-zero if button 3 is currently held down.
936 For more details, see Fl::event_buttons().
938 static int event_button3() {return e_state&FL_BUTTON3;}
942 Sets an idle callback.
944 \deprecated This method is obsolete - use the add_idle() method instead.
946 static void set_idle(Fl_Old_Idle_Handler cb) {idle = cb;}
947 /** See grab(Fl_Window*) */
948 static void grab(Fl_Window& win) {grab(&win);}
949 /** Releases the current grabbed window, equals grab(0).
950 \deprecated Use Fl::grab(0) instead.
951 \see grab(Fl_Window*) */
952 static void release() {grab(0);}
954 // Visible focus methods...
956 Gets or sets the visible keyboard focus on buttons and other
957 non-text widgets. The default mode is to enable keyboard focus
960 static void visible_focus(int v) { option(OPTION_VISIBLE_FOCUS, (v!=0)); }
962 Gets or sets the visible keyboard focus on buttons and other
963 non-text widgets. The default mode is to enable keyboard focus
966 static int visible_focus() { return option(OPTION_VISIBLE_FOCUS); }
968 // Drag-n-drop text operation methods...
970 Gets or sets whether drag and drop text operations are supported.
971 This specifically affects whether selected text can
972 be dragged from text fields or dragged within a text field as a
975 static void dnd_text_ops(int v) { option(OPTION_DND_TEXT, (v!=0)); }
977 Gets or sets whether drag and drop text operations are
978 supported. This specifically affects whether selected text can
979 be dragged from text fields or dragged within a text field as a
982 static int dnd_text_ops() { return option(OPTION_DND_TEXT); }
983 /** \defgroup fl_multithread Multithreading support functions
984 fl multithreading support functions declared in <FL/Fl.H>
987 // Multithreading support:
989 static void unlock();
990 static void awake(void* message = 0);
991 /** See void awake(void* message=0). */
992 static int awake(Fl_Awake_Handler cb, void* message = 0);
994 The thread_message() method returns the last message
995 that was sent from a child by the awake() method.
997 See also: \ref advanced_multithreading
999 static void* thread_message(); // platform dependent
1002 /** \defgroup fl_del_widget Safe widget deletion support functions
1004 These functions, declared in <FL/Fl.H>, support deletion of widgets inside callbacks.
1006 Fl::delete_widget() should be called when deleting widgets
1007 or complete widget trees (Fl_Group, Fl_Window, ...) inside
1010 The other functions are intended for internal use. The preferred
1011 way to use them is by using the helper class Fl_Widget_Tracker.
1013 The following is to show how it works ...
1015 There are three groups of related methods:
1017 -# scheduled widget deletion
1018 - Fl::delete_widget() schedules widgets for deletion
1019 - Fl::do_widget_deletion() deletes all scheduled widgets
1020 -# widget watch list ("smart pointers")
1021 - Fl::watch_widget_pointer() adds a widget pointer to the watch list
1022 - Fl::release_widget_pointer() removes a widget pointer from the watch list
1023 - Fl::clear_widget_pointer() clears a widget pointer \e in the watch list
1024 -# the class Fl_Widget_Tracker:
1025 - the constructor calls Fl::watch_widget_pointer()
1026 - the destructor calls Fl::release_widget_pointer()
1027 - the access methods can be used to test, if a widget has been deleted
1028 \see Fl_Widget_Tracker.
1032 static void delete_widget(Fl_Widget *w);
1033 static void do_widget_deletion();
1034 static void watch_widget_pointer(Fl_Widget *&w);
1035 static void release_widget_pointer(Fl_Widget *&w);
1036 static void clear_widget_pointer(Fl_Widget const *w);
1039 /** \defgroup group_cairo Cairo support functions and classes
1044 static cairo_surface_t * cairo_create_surface ( Window xid, int W, int H );
1046 // Cairo support API
1047 static cairo_t * cairo_make_current( cairo_t *cc );
1048 /** when FLTK_HAVE_CAIRO is defined and cairo_autolink_context() is true,
1049 any current window dc is linked to a current context.
1050 This is not the default, because it may not be necessary
1051 to add cairo support to all fltk supported windows.
1052 When you wish to associate a cairo context in this mode,
1053 you need to call explicitly in your draw() overridden method,
1054 FL::cairo_make_current(Fl_Window*). This will create a cairo context
1055 but only for this Window.
1056 Still in custom cairo application it is possible to handle
1057 completely this process automatically by setting \p alink to true.
1058 In this last case, you don't need anymore to call Fl::cairo_make_current().
1059 You can use Fl::cairo_cc() to get the current cairo context anytime.
1060 \note Only available when configure has the --enable-cairo option
1062 /** Gets the current cairo context linked with a fltk window. */
1063 static cairo_t * cairo_cc() { return fl_cairo_context; }
1064 /** Sets the current cairo context to \p c.
1065 Set \p own to true if you want fltk to handle this cc deletion.
1066 \note Only available when configure has the --enable-cairo option
1068 // static void cairo_cc(cairo_t * c, bool own=false){ cairo_state_.cc(c, own); }
1077 This class should be used to control safe widget deletion.
1079 You can use an Fl_Widget_Tracker object to watch another widget, if you
1080 need to know, if this widget has been deleted during a callback.
1082 This simplifies the use of the "safe widget deletion" methods
1083 Fl::watch_widget_pointer() and Fl::release_widget_pointer() and
1084 makes their use more reliable, because the destructor autmatically
1085 releases the widget pointer from the widget watch list.
1087 It is intended to be used as an automatic (local/stack) variable,
1088 such that the automatic destructor is called when the object's
1089 scope is left. This ensures that no stale widget pointers are
1090 left in the widget watch list (see example below).
1092 You can also create Fl_Widget_Tracker objects with \c new, but then it
1093 is your responsibility to delete the object (and thus remove the
1094 widget pointer from the watch list) when it is not needed any more.
1099 int MyClass::handle (int event) {
1102 Fl_Widget_Tracker wp(this); // watch myself
1103 do_callback(); // call the callback
1105 if (wp.deleted()) return 1; // exit, if deleted
1107 // Now we are sure that the widget has not been deleted.
1108 // It is safe to access the widget
1110 clear_changed(); // access the widget
1116 class FL_EXPORT Fl_Widget_Tracker {
1122 Fl_Widget_Tracker(Fl_Widget *wi);
1123 ~Fl_Widget_Tracker();
1126 Returns a pointer to the watched widget.
1128 This pointer is \c NULL, if the widget has been deleted.
1130 Fl_Widget *widget() {return wp_;}
1133 Returns 1, if the watched widget has been deleted.
1135 This is a convenience method. You can also use something like
1137 <tt> if (wp.widget() == 0) // ...</tt>
1139 where \p wp is an Fl_Widget_Tracker object.
1141 int deleted() {return wp_ == 0;}
1144 Returns 1, if the watched widget exists (has not been deleted).
1146 This is a convenience method. You can also use something like
1148 <tt> if (wp.widget() != 0) // ...</tt>
1150 where \p wp is an Fl_Widget_Tracker object.
1152 int exists() {return wp_ != 0;}
1156 /** \defgroup fl_unicode Unicode and UTF-8 functions
1157 fl global Unicode and UTF-8 handling functions declared in <FL/fl_utf8.h>
1161 /* 0 default, 1 off 2 on */
1164 FL_ANTIALIAS_DEFAULT,
1169 void fl_set_antialias ( int v );
1174 // End of "$Id: Fl.H 8724 2011-05-23 18:01:29Z manolo $".