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 Returns non zero if we had a double click event.
536 \retval Non-zero if the most recent FL_PUSH or FL_KEYBOARD was a "double click".
537 \retval N-1 for N clicks.
538 A double click is counted if the same button is pressed
539 again while event_is_click() is true.
542 static int event_clicks() {return e_clicks;}
544 Manually sets the number returned by Fl::event_clicks().
545 This can be used to set it to zero so that
546 later code does not think an item was double-clicked.
547 \param[in] i corresponds to no double-click if 0, i+1 mouse clicks otherwise
548 \see int event_clicks()
550 static void event_clicks(int i) {e_clicks = i;}
552 Returns non-zero if the mouse has not moved far enough
553 and not enough time has passed since the last FL_PUSH or
554 FL_KEYBOARD event for it to be considered a "drag" rather than a
555 "click". You can test this on FL_DRAG, FL_RELEASE,
558 static int event_is_click() {return e_is_click;}
560 Clears the value returned by Fl::event_is_click().
561 Useful to prevent the <I>next</I>
562 click from being counted as a double-click or to make a popup menu
563 pick an item with a single click. Don't pass non-zero to this.
565 static void event_is_click(int i) {e_is_click = i;}
567 Gets which particular mouse button caused the current event.
568 This returns garbage if the most recent event was not a FL_PUSH or FL_RELEASE event.
569 \retval FL_LEFT_MOUSE \retval FL_MIDDLE_MOUSE \retval FL_RIGHT_MOUSE.
570 \see Fl::event_buttons()
572 static int event_button() {return e_keysym-FL_Button;}
574 This is a bitfield of what shift states were on and what mouse buttons
575 were held down during the most recent event. The second version
576 returns non-zero if any of the passed bits are turned on.
590 X servers do not agree on shift states, and FL_NUM_LOCK, FL_META, and
591 FL_SCROLL_LOCK may not work. The values were selected to match the
592 XFree86 server on Linux. In addition there is a bug in the way X works
593 so that the shift state is not correctly reported until the first event
594 <I>after</I> the shift key is pressed or released.
596 static int event_state() {return e_state;}
597 /** See int event_state() */
598 static int event_state(int i) {return e_state&i;}
600 Gets which key on the keyboard was last pushed.
602 The returned integer 'key code' is not necessarily a text
603 equivalent for the keystroke. For instance: if someone presses '5' on the
604 numeric keypad with numlock on, Fl::event_key() may return the 'key code'
605 for this key, and NOT the character '5'. To always get the '5', use Fl::event_text() instead.
607 \returns an integer 'key code', or 0 if the last event was not a key press or release.
608 \see int event_key(int), event_text(), compose(int&).
610 static int event_key() {return e_keysym;}
612 Returns the keycode of the last key event, regardless of the NumLock state.
614 If NumLock is deactivated, FLTK translates events from the
615 numeric keypad into the corresponding arrow key events.
616 event_key() returns the translated key code, whereas
617 event_original_key() returns the keycode before NumLock translation.
619 static int event_original_key(){return e_original_keysym;}
621 Returns true if the given \p key was held
622 down (or pressed) <I>during</I> the last event. This is constant until
623 the next event is read from the server.
625 Fl::get_key(int) returns true if the given key is held down <I>now</I>.
626 Under X this requires a round-trip to the server and is <I>much</I>
627 slower than Fl::event_key(int).
629 Keys are identified by the <I>unshifted</I> values. FLTK defines a
630 set of symbols that should work on most modern machines for every key
633 \li All keys on the main keyboard producing a printable ASCII
634 character use the value of that ASCII character (as though shift,
635 ctrl, and caps lock were not on). The space bar is 32.
636 \li All keys on the numeric keypad producing a printable ASCII
637 character use the value of that ASCII character plus FL_KP.
638 The highest possible value is FL_KP_Last so you can
639 range-check to see if something is on the keypad.
640 \li All numbered function keys use the number on the function key plus
641 FL_F. The highest possible number is FL_F_Last, so you
642 can range-check a value.
643 \li Buttons on the mouse are considered keys, and use the button
644 number (where the left button is 1) plus FL_Button.
645 \li All other keys on the keypad have a symbol: FL_Escape,
646 FL_BackSpace, FL_Tab, FL_Enter, FL_Print, FL_Scroll_Lock, FL_Pause,
647 FL_Insert, FL_Home, FL_Page_Up, FL_Delete, FL_End, FL_Page_Down,
648 FL_Left, FL_Up, FL_Right, FL_Down, FL_Shift_L, FL_Shift_R,
649 FL_Control_L, FL_Control_R, FL_Caps_Lock, FL_Alt_L, FL_Alt_R,
650 FL_Meta_L, FL_Meta_R, FL_Menu, FL_Num_Lock, FL_KP_Enter. Be
651 careful not to confuse these with the very similar, but all-caps,
652 symbols used by Fl::event_state().
654 On X Fl::get_key(FL_Button+n) does not work.
656 On WIN32 Fl::get_key(FL_KP_Enter) and Fl::event_key(FL_KP_Enter) do not work.
658 static int event_key(int key);
660 Returns true if the given \p key is held down <I>now</I>.
661 Under X this requires a round-trip to the server and is <I>much</I>
662 slower than Fl::event_key(int). \see event_key(int)
664 static int get_key(int key); // platform dependent
666 Returns the text associated with the current event, including FL_PASTE or FL_DND_RELEASE events.
667 This can be used in response to FL_KEYUP, FL_KEYDOWN, FL_PASTE, FL_DND_RELEASE.
669 When responding to FL_KEYUP/FL_KEYDOWN, use this function instead of Fl::event_key()
670 to get the text equivalent of keystrokes suitable for inserting into strings
673 The returned string is guaranteed to be be NULL terminated.
674 However, see Fl::event_length() for the actual length of the string,
675 in case the string itself contains NULLs that are part of the text data.
677 \returns A NULL terminated text string equivalent of the last keystroke.
679 static const char* event_text() {return e_text;}
681 Returns the length of the text in Fl::event_text(). There
682 will always be a nul at this position in the text. However there may
683 be a nul before that if the keystroke translates to a nul character or
684 you paste a nul character.
686 static int event_length() {return e_length;}
688 static int compose(int &del);
689 static void compose_reset();
690 static int event_inside(int,int,int,int);
691 static int event_inside(const Fl_Widget*);
692 static int test_shortcut(Fl_Shortcut);
694 // event destinations:
695 static int handle(int, Fl_Window*);
696 static int handle_(int, Fl_Window*);
697 /** Gets the widget that is below the mouse.
698 \see belowmouse(Fl_Widget*) */
699 static Fl_Widget* belowmouse() {return belowmouse_;}
700 static void belowmouse(Fl_Widget*);
701 /** Gets the widget that is being pushed.
702 \see void pushed(Fl_Widget*) */
703 static Fl_Widget* pushed() {return pushed_;}
704 static void pushed(Fl_Widget*);
705 /** Gets the current Fl::focus() widget. \sa Fl::focus(Fl_Widget*) */
706 static Fl_Widget* focus() {return focus_;}
707 static void focus(Fl_Widget*);
708 static void add_handler(Fl_Event_Handler h);
709 static void remove_handler(Fl_Event_Handler h);
710 static void event_dispatch(Fl_Event_Dispatch d);
711 static Fl_Event_Dispatch event_dispatch();
714 /** \defgroup fl_clipboard Selection & Clipboard functions
715 FLTK global copy/cut/paste functions declared in <FL/Fl.H>
719 Copies the data pointed to by \p stuff to the selection buffer
720 (\p destination is 0) or
721 the clipboard (\p destination is 1); \p len is the number of relevant
723 The selection buffer is used for
724 middle-mouse pastes and for drag-and-drop selections. The
725 clipboard is used for traditional copy/cut/paste operations.
727 static void copy(const char* stuff, int len, int destination = 0); // platform dependent
729 Pastes the data from the selection buffer (\p source is 0) or the clipboard
730 (\p source is 1) into \p receiver.
731 Set things up so the receiver widget will be called with an FL_PASTE event some
732 time in the future with the data from the specified \p source in Fl::event_text()
733 and the number of characters in Fl::event_length().
735 should be prepared to be called \e directly by this, or for
736 it to happen \e later, or possibly <i>not at all</i>. This
737 allows the window system to take as long as necessary to retrieve
738 the paste buffer (or even to screw up completely) without complex
739 and error-prone synchronization code in FLTK.
741 The selection buffer is used for middle-mouse pastes and for
742 drag-and-drop selections. The clipboard is used for traditional
743 copy/cut/paste operations.
745 static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent
747 Initiate a Drag And Drop operation. The selection buffer should be
748 filled with relevant data before calling this method. FLTK will
749 then initiate the system wide drag and drop handling. Dropped data
750 will be marked as <i>text</i>.
752 Create a selection first using:
753 Fl::copy(const char *stuff, int len, 0)
755 static int dnd(); // platform dependent
757 // These are for back-compatibility only:
758 /** back-compatibility only: Gets the widget owning the current selection
759 \see Fl_Widget* selection_owner(Fl_Widget*) */
760 static Fl_Widget* selection_owner() {return selection_owner_;}
761 static void selection_owner(Fl_Widget*);
762 static void selection(Fl_Widget &owner, const char*, int len);
763 static void paste(Fl_Widget &receiver);
765 /** \defgroup fl_screen Screen functions
766 fl global screen functions declared in <FL/Fl.H>
769 /** Returns the origin of the current screen work area, where 0 indicates the left side of the screen. */
770 static int x(); // platform dependent
771 /** Returns the origin of the current screen work area, where 0 indicates the top edge of the screen. */
772 static int y(); // platform dependent
773 /** Returns the width of the screen work area in pixels. */
774 static int w(); // platform dependent
775 /** Returns the height of the screen work area in pixels. */
776 static int h(); // platform dependent
778 // multi-head support:
779 static int screen_count();
781 Gets the bounding box of a screen that contains the mouse pointer.
782 \param[out] X,Y,W,H the corresponding screen bounding box
783 \see void screen_xywh(int &x, int &y, int &w, int &h, int mx, int my)
785 static void screen_xywh(int &X, int &Y, int &W, int &H) {
786 screen_xywh(X, Y, W, H, e_x_root, e_y_root);
788 static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
789 static void screen_xywh(int &X, int &Y, int &W, int &H, int n);
790 static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh);
791 static void screen_dpi(float &h, float &v, int n=0);
795 /** \defgroup fl_attributes Color & Font functions
796 fl global color, font functions.
797 These functions are declared in <FL/Fl.H> or <FL/fl_draw.H>.
801 static void set_color(Fl_Color, uchar, uchar, uchar);
803 Sets an entry in the fl_color index table. You can set it to any
804 8-bit RGB color. The color is not allocated until fl_color(i) is used.
806 static void set_color(Fl_Color i, unsigned c); // platform dependent
807 static unsigned get_color(Fl_Color i);
808 static void get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue);
810 Frees the specified color from the colormap, if applicable.
811 If overlay is non-zero then the color is freed from the
814 static void free_color(Fl_Color i, int overlay = 0); // platform dependent
817 static const char* get_font(Fl_Font);
819 Get a human-readable string describing the family of this face. This
820 is useful if you are presenting a choice to the user. There is no
821 guarantee that each face has a different name. The return value points
822 to a static buffer that is overwritten each call.
824 The integer pointed to by \p attributes (if the pointer is not
825 zero) is set to zero, FL_BOLD or FL_ITALIC or
826 FL_BOLD | FL_ITALIC. To locate a "family" of fonts, search
827 forward and back for a set with non-zero attributes, these faces along
828 with the face with a zero attribute before them constitute a family.
830 static const char* get_font_name(Fl_Font, int* attributes = 0);
832 Return an array of sizes in \p sizep. The return value is the
833 length of this array. The sizes are sorted from smallest to largest
834 and indicate what sizes can be given to fl_font() that will
835 be matched exactly (fl_font() will pick the closest size for
836 other sizes). A zero in the first location of the array indicates a
837 scalable font, where any size works, although the array may list sizes
838 that work "better" than others. Warning: the returned array
839 points at a static buffer that is overwritten each call. Under X this
840 will open the display.
842 static int get_font_sizes(Fl_Font, int*& sizep);
843 static void set_font(Fl_Font, const char*);
844 static void set_font(Fl_Font, Fl_Font);
846 FLTK will open the display, and add every fonts on the server to the
847 face table. It will attempt to put "families" of faces together, so
848 that the normal one is first, followed by bold, italic, and bold
851 The optional argument is a string to describe the set of fonts to
852 add. Passing NULL will select only fonts that have the
853 ISO8859-1 character set (and are thus usable by normal text). Passing
854 "-*" will select all fonts with any encoding as long as they have
855 normal X font names with dashes in them. Passing "*" will list every
856 font that exists (on X this may produce some strange output). Other
857 values may be useful but are system dependent. With WIN32 NULL
858 selects fonts with ISO8859-1 encoding and non-NULL selects
861 The return value is how many faces are in the table after this is done.
863 static Fl_Font set_fonts(const char* = 0); // platform dependent
866 /** \defgroup fl_drawings Drawing functions
867 FLTK global graphics and GUI drawing functions.
868 These functions are declared in <FL/fl_draw.H>,
869 and in <FL/x.H> for offscreen buffer-related ones.
871 // <Hack to re-order the 'Drawing functions' group>
875 static void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*);
876 /** Sets the functions to call to draw and measure a specific labeltype. */
877 static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined ?
880 static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype);
881 static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar);
882 static void set_boxtype(Fl_Boxtype, Fl_Boxtype from);
883 static int box_dx(Fl_Boxtype);
884 static int box_dy(Fl_Boxtype);
885 static int box_dw(Fl_Boxtype);
886 static int box_dh(Fl_Boxtype);
887 static int draw_box_active();
889 // back compatibility:
890 /** \addtogroup fl_windows
892 /** For back compatibility, sets the void Fl::fatal handler callback */
893 static void set_abort(Fl_Abort_Handler f) {fatal = f;}
894 static void (*atclose)(Fl_Window*,void*);
895 static void default_atclose(Fl_Window*,void*);
896 /** For back compatibility, sets the Fl::atclose handler callback. You
897 can now simply change the callback for the window instead.
898 \see Fl_Window::callback(Fl_Callback*) */
899 static void set_atclose(Fl_Atclose_Handler f) {atclose = f;}
902 /** \addtogroup fl_events
904 /** Returns non-zero if the Shift key is pressed. */
905 static int event_shift() {return e_state&FL_SHIFT;}
906 /** Returns non-zero if the Control key is pressed. */
907 static int event_ctrl() {return e_state&FL_CTRL;}
908 /** Returns non-zero if the FL_COMMAND key is pressed, either FL_CTRL or on OSX FL_META. */
909 static int event_command() {return e_state&FL_COMMAND;}
910 /** Returns non-zero if the Alt key is pressed. */
911 static int event_alt() {return e_state&FL_ALT;}
913 Returns the mouse buttons state bits; if non-zero, then at least one
914 button is pressed now. This function returns the button state at the
915 time of the event. During an FL_RELEASE event, the state
916 of the released button will be 0. To find out, which button
917 caused an FL_RELEASE event, you can use Fl::event_button() instead.
918 \return a bit mask value like { [FL_BUTTON1] | [FL_BUTTON2] | [FL_BUTTON3] }
920 static int event_buttons() {return e_state&0x7f000000;}
922 Returns non-zero if mouse button 1 is currently held down.
923 For more details, see Fl::event_buttons().
925 static int event_button1() {return e_state&FL_BUTTON1;}
927 Returns non-zero if button 2 is currently held down.
928 For more details, see Fl::event_buttons().
930 static int event_button2() {return e_state&FL_BUTTON2;}
932 Returns non-zero if button 3 is currently held down.
933 For more details, see Fl::event_buttons().
935 static int event_button3() {return e_state&FL_BUTTON3;}
939 Sets an idle callback.
941 \deprecated This method is obsolete - use the add_idle() method instead.
943 static void set_idle(Fl_Old_Idle_Handler cb) {idle = cb;}
944 /** See grab(Fl_Window*) */
945 static void grab(Fl_Window& win) {grab(&win);}
946 /** Releases the current grabbed window, equals grab(0).
947 \deprecated Use Fl::grab(0) instead.
948 \see grab(Fl_Window*) */
949 static void release() {grab(0);}
951 // Visible focus methods...
953 Gets or sets the visible keyboard focus on buttons and other
954 non-text widgets. The default mode is to enable keyboard focus
957 static void visible_focus(int v) { option(OPTION_VISIBLE_FOCUS, (v!=0)); }
959 Gets or sets the visible keyboard focus on buttons and other
960 non-text widgets. The default mode is to enable keyboard focus
963 static int visible_focus() { return option(OPTION_VISIBLE_FOCUS); }
965 // Drag-n-drop text operation methods...
967 Gets or sets whether drag and drop text operations are supported.
968 This specifically affects whether selected text can
969 be dragged from text fields or dragged within a text field as a
972 static void dnd_text_ops(int v) { option(OPTION_DND_TEXT, (v!=0)); }
974 Gets or sets whether drag and drop text operations are
975 supported. This specifically affects whether selected text can
976 be dragged from text fields or dragged within a text field as a
979 static int dnd_text_ops() { return option(OPTION_DND_TEXT); }
980 /** \defgroup fl_multithread Multithreading support functions
981 fl multithreading support functions declared in <FL/Fl.H>
984 // Multithreading support:
986 static void unlock();
987 static void awake(void* message = 0);
988 /** See void awake(void* message=0). */
989 static int awake(Fl_Awake_Handler cb, void* message = 0);
991 The thread_message() method returns the last message
992 that was sent from a child by the awake() method.
994 See also: \ref advanced_multithreading
996 static void* thread_message(); // platform dependent
999 /** \defgroup fl_del_widget Safe widget deletion support functions
1001 These functions, declared in <FL/Fl.H>, support deletion of widgets inside callbacks.
1003 Fl::delete_widget() should be called when deleting widgets
1004 or complete widget trees (Fl_Group, Fl_Window, ...) inside
1007 The other functions are intended for internal use. The preferred
1008 way to use them is by using the helper class Fl_Widget_Tracker.
1010 The following is to show how it works ...
1012 There are three groups of related methods:
1014 -# scheduled widget deletion
1015 - Fl::delete_widget() schedules widgets for deletion
1016 - Fl::do_widget_deletion() deletes all scheduled widgets
1017 -# widget watch list ("smart pointers")
1018 - Fl::watch_widget_pointer() adds a widget pointer to the watch list
1019 - Fl::release_widget_pointer() removes a widget pointer from the watch list
1020 - Fl::clear_widget_pointer() clears a widget pointer \e in the watch list
1021 -# the class Fl_Widget_Tracker:
1022 - the constructor calls Fl::watch_widget_pointer()
1023 - the destructor calls Fl::release_widget_pointer()
1024 - the access methods can be used to test, if a widget has been deleted
1025 \see Fl_Widget_Tracker.
1029 static void delete_widget(Fl_Widget *w);
1030 static void do_widget_deletion();
1031 static void watch_widget_pointer(Fl_Widget *&w);
1032 static void release_widget_pointer(Fl_Widget *&w);
1033 static void clear_widget_pointer(Fl_Widget const *w);
1036 /** \defgroup group_cairo Cairo support functions and classes
1041 static cairo_surface_t * cairo_create_surface ( Window xid, int W, int H );
1043 // Cairo support API
1044 static cairo_t * cairo_make_current( cairo_t *cc );
1045 /** when FLTK_HAVE_CAIRO is defined and cairo_autolink_context() is true,
1046 any current window dc is linked to a current context.
1047 This is not the default, because it may not be necessary
1048 to add cairo support to all fltk supported windows.
1049 When you wish to associate a cairo context in this mode,
1050 you need to call explicitly in your draw() overridden method,
1051 FL::cairo_make_current(Fl_Window*). This will create a cairo context
1052 but only for this Window.
1053 Still in custom cairo application it is possible to handle
1054 completely this process automatically by setting \p alink to true.
1055 In this last case, you don't need anymore to call Fl::cairo_make_current().
1056 You can use Fl::cairo_cc() to get the current cairo context anytime.
1057 \note Only available when configure has the --enable-cairo option
1059 /** Gets the current cairo context linked with a fltk window. */
1060 static cairo_t * cairo_cc() { return fl_cairo_context; }
1061 /** Sets the current cairo context to \p c.
1062 Set \p own to true if you want fltk to handle this cc deletion.
1063 \note Only available when configure has the --enable-cairo option
1065 // static void cairo_cc(cairo_t * c, bool own=false){ cairo_state_.cc(c, own); }
1074 This class should be used to control safe widget deletion.
1076 You can use an Fl_Widget_Tracker object to watch another widget, if you
1077 need to know, if this widget has been deleted during a callback.
1079 This simplifies the use of the "safe widget deletion" methods
1080 Fl::watch_widget_pointer() and Fl::release_widget_pointer() and
1081 makes their use more reliable, because the destructor autmatically
1082 releases the widget pointer from the widget watch list.
1084 It is intended to be used as an automatic (local/stack) variable,
1085 such that the automatic destructor is called when the object's
1086 scope is left. This ensures that no stale widget pointers are
1087 left in the widget watch list (see example below).
1089 You can also create Fl_Widget_Tracker objects with \c new, but then it
1090 is your responsibility to delete the object (and thus remove the
1091 widget pointer from the watch list) when it is not needed any more.
1096 int MyClass::handle (int event) {
1099 Fl_Widget_Tracker wp(this); // watch myself
1100 do_callback(); // call the callback
1102 if (wp.deleted()) return 1; // exit, if deleted
1104 // Now we are sure that the widget has not been deleted.
1105 // It is safe to access the widget
1107 clear_changed(); // access the widget
1113 class FL_EXPORT Fl_Widget_Tracker {
1119 Fl_Widget_Tracker(Fl_Widget *wi);
1120 ~Fl_Widget_Tracker();
1123 Returns a pointer to the watched widget.
1125 This pointer is \c NULL, if the widget has been deleted.
1127 Fl_Widget *widget() {return wp_;}
1130 Returns 1, if the watched widget has been deleted.
1132 This is a convenience method. You can also use something like
1134 <tt> if (wp.widget() == 0) // ...</tt>
1136 where \p wp is an Fl_Widget_Tracker object.
1138 int deleted() {return wp_ == 0;}
1141 Returns 1, if the watched widget exists (has not been deleted).
1143 This is a convenience method. You can also use something like
1145 <tt> if (wp.widget() != 0) // ...</tt>
1147 where \p wp is an Fl_Widget_Tracker object.
1149 int exists() {return wp_ != 0;}
1153 /** \defgroup fl_unicode Unicode and UTF-8 functions
1154 fl global Unicode and UTF-8 handling functions declared in <FL/fl_utf8.h>
1158 /* 0 default, 1 off 2 on */
1161 FL_ANTIALIAS_DEFAULT,
1166 void fl_set_antialias ( int v );
1171 // End of "$Id: Fl.H 8724 2011-05-23 18:01:29Z manolo $".