blob: e00735f648e14921205b2ed51faf1e09543d9fe3 [file] [log] [blame]
DRC2ff39b82011-07-28 08:38:59 +00001//
2// "$Id: Fl.H 8724 2011-05-23 18:01:29Z manolo $"
3//
4// Main header file for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2010 by Bill Spitzak and others.
7//
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.
12//
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.
17//
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
21// USA.
22//
23// Please report all bugs and problems on the following page:
24//
25// http://www.fltk.org/str.php
26//
27
28/** \file
29 Fl static class.
30 */
31
32#ifndef Fl_H
33# define Fl_H
34
35#ifdef FLTK_HAVE_CAIRO
36# include <FL/Fl_Cairo.H>
37#endif
38
39# include "fl_utf8.h"
40# include "Enumerations.H"
41# ifndef Fl_Object
42# define Fl_Object Fl_Widget /**< for back compatibility - use Fl_Widget! */
43# endif
44
45# ifdef check
46# undef check
47# endif
48
49
50class Fl_Widget;
51class Fl_Window;
52class Fl_Image;
53struct Fl_Label;
54
55
56/** \defgroup callback_functions Callback function typedefs
57 \brief Typedefs defined in <FL/Fl.H> for callback or handler functions passed as function parameters.
58
59 FLTK uses callback functions as parameters for some function calls, e.g. to
60 set up global event handlers (Fl::add_handler()), to add a timeout handler
61 (Fl::add_timeout()), and many more.
62
63 The typedefs defined in this group describe the function parameters used to set
64 up or clear the callback functions and should also be referenced to define the
65 callback function to handle such events in the user's code.
66
67 \see Fl::add_handler(), Fl::add_timeout(), Fl::repeat_timeout(),
68 Fl::remove_timeout() and others
69 @{ */
70
71/** Signature of some label drawing functions passed as parameters */
72typedef void (Fl_Label_Draw_F)(const Fl_Label *label, int x, int y, int w, int h, Fl_Align align);
73
74/** Signature of some label measurement functions passed as parameters */
75typedef void (Fl_Label_Measure_F)(const Fl_Label *label, int &width, int &height);
76
77/** Signature of some box drawing functions passed as parameters */
78typedef void (Fl_Box_Draw_F)(int x, int y, int w, int h, Fl_Color color);
79
80/** Signature of some timeout callback functions passed as parameters */
81typedef void (*Fl_Timeout_Handler)(void *data);
82
83/** Signature of some wakeup callback functions passed as parameters */
84typedef void (*Fl_Awake_Handler)(void *data);
85
86/** Signature of add_idle callback functions passed as parameters */
87typedef void (*Fl_Idle_Handler)(void *data);
88
89/** Signature of set_idle callback functions passed as parameters */
90typedef void (*Fl_Old_Idle_Handler)();
91
92/** Signature of add_fd functions passed as parameters */
93typedef void (*Fl_FD_Handler)(int fd, void *data);
94
95/** Signature of add_handler functions passed as parameters */
96typedef int (*Fl_Event_Handler)(int event);
97
98/** Signature of set_abort functions passed as parameters */
99typedef void (*Fl_Abort_Handler)(const char *format,...);
100
101/** Signature of set_atclose functions passed as parameters */
102typedef void (*Fl_Atclose_Handler)(Fl_Window *window, void *data);
103
104/** Signature of args functions passed as parameters */
105typedef int (*Fl_Args_Handler)(int argc, char **argv, int &i);
106
107/** Signature of event_dispatch functions passed as parameters.
108 \see Fl::event_dispatch(Fl_Event_Dispatch) */
109typedef int (*Fl_Event_Dispatch)(int event, Fl_Window *w);
110
DRC685f17e2011-07-28 09:23:00 +0000111/** Signature of add_clipboard_notify functions passed as parameters */
112typedef void (*Fl_Clipboard_Notify_Handler)(int source, void *data);
113
DRC2ff39b82011-07-28 08:38:59 +0000114/** @} */ /* group callback_functions */
115
116
117/**
118 The Fl is the FLTK global (static) class containing
119 state information and global methods for the current application.
120*/
121class FL_EXPORT Fl {
122 Fl() {}; // no constructor!
123
124public: // should be private!
125#ifndef FL_DOXYGEN
126 static int e_number;
127 static int e_x;
128 static int e_y;
129 static int e_x_root;
130 static int e_y_root;
131 static int e_dx;
132 static int e_dy;
133 static int e_state;
134 static int e_clicks;
135 static int e_is_click;
136 static int e_keysym;
137 static char* e_text;
138 static int e_length;
139 static Fl_Event_Dispatch e_dispatch;
140 static Fl_Widget* belowmouse_;
141 static Fl_Widget* pushed_;
142 static Fl_Widget* focus_;
143 static int damage_;
144 static Fl_Widget* selection_owner_;
145 static Fl_Window* modal_;
146 static Fl_Window* grab_;
147 static int compose_state;
148#endif
149 /**
150 If true then flush() will do something.
151 */
152 static void damage(int d) {damage_ = d;}
153
154public:
155 /** Enumerator for global FLTK options.
156 These options can be set system wide, per user, or for the running
157 application only.
158 \see Fl::option(Fl_Option, bool)
159 \see Fl::option(Fl_Option)
160 */
161 typedef enum {
162 /// When switched on, moving the text cursor beyond the start or end of
163 /// a text in a text widget will change focus to the next text widget.
164 /// When switched off, the cursor will stop at the end of the text.
165 /// Pressing Tab or Ctrl-Tab will advance the keyboard focus.
166 OPTION_ARROW_FOCUS = 0,
167 // When switched on, FLTK will use the file chooser dialog that comes
168 // with your operating system whenever possible. When switched off, FLTK
169 // will present its own file chooser.
170 // \todo implement me
171 // OPTION_NATIVE_FILECHOOSER,
172 // When Filechooser Preview is enabled, the FLTK or native file chooser
173 // will show a preview of a selected file (if possible) before the user
174 // decides to choose the file.
175 // \todo implement me
176 //OPTION_FILECHOOSER_PREVIEW,
177 /// If visible focus is switched on, FLTK will draw a dotted rectangle
178 /// inside the widget that will receive the next keystroke. If switched
179 /// off, no such indicator will be drawn and keyboard navigation
180 /// is disabled.
181 OPTION_VISIBLE_FOCUS,
182 /// If text drag-and-drop is enabled, the user can select and drag text
183 /// from any text widget. If disabled, no dragging is possible, however
184 /// dropping text from other applications still works.
185 OPTION_DND_TEXT,
186 /// If tooltips are enabled, hovering the mouse over a widget with a
187 /// tooltip text will open a little tooltip window until the mouse leaves
188 /// the widget. If disabled, no tooltip is shown.
189 OPTION_SHOW_TOOLTIPS,
190 // don't change this, leave it always as the last element
191 /// For internal use only.
192 OPTION_LAST
193 } Fl_Option;
194
195private:
196 static unsigned char options_[OPTION_LAST];
197 static unsigned char options_read_;
198
199public:
200 /*
201 Return a global setting for all FLTK applications, possibly overridden
202 by a setting specifically for this application.
203 */
204 static bool option(Fl_Option opt);
205
206 /*
207 Override an option while the application is running.
208 */
209 static void option(Fl_Option opt, bool val);
210
211 /**
212 The currently executing idle callback function: DO NOT USE THIS DIRECTLY!
213
214 This is now used as part of a higher level system allowing multiple
215 idle callback functions to be called.
216 \see add_idle(), remove_idle()
217 */
218 static void (*idle)();
219
220#ifndef FL_DOXYGEN
221 static Fl_Awake_Handler *awake_ring_;
222 static void **awake_data_;
223 static int awake_ring_size_;
224 static int awake_ring_head_;
225 static int awake_ring_tail_;
226 static const char* scheme_;
227 static Fl_Image* scheme_bg_;
228
229 static int e_original_keysym; // late addition
230 static int scrollbar_size_;
231#endif
232
233
234 static int add_awake_handler_(Fl_Awake_Handler, void*);
235 static int get_awake_handler_(Fl_Awake_Handler&, void*&);
236
237public:
238
239 // API version number
240 static double version();
241
242 // argument parsers:
243 static int arg(int argc, char **argv, int& i);
244 static int args(int argc, char **argv, int& i, Fl_Args_Handler cb = 0);
245 static void args(int argc, char **argv);
246 /**
247 Usage string displayed if Fl::args() detects an invalid argument.
248 This may be changed to point to customized text at run-time.
249 */
250 static const char* const help;
251
252 // things called by initialization:
253 static void display(const char*);
254 static int visual(int);
255 /**
256 This does the same thing as Fl::visual(int) but also requires OpenGL
257 drawing to work. This <I>must</I> be done if you want to draw in
258 normal windows with OpenGL with gl_start() and gl_end().
259 It may be useful to call this so your X windows use the same visual
260 as an Fl_Gl_Window, which on some servers will reduce colormap flashing.
261
262 See Fl_Gl_Window for a list of additional values for the argument.
263 */
264 static int gl_visual(int, int *alist=0); // platform dependent
265 static void own_colormap();
266 static void get_system_colors();
267 static void foreground(uchar, uchar, uchar);
268 static void background(uchar, uchar, uchar);
269 static void background2(uchar, uchar, uchar);
270
271 // schemes:
272 static int scheme(const char*);
273 /** See void scheme(const char *name) */
274 static const char* scheme() {return scheme_;}
275 /**
276 Called by scheme according to scheme name.
277 Loads or reloads the current scheme selection.
278 See void scheme(const char *name)
279 */
280 static int reload_scheme(); // platform dependent
281 static int scrollbar_size();
282 static void scrollbar_size(int W);
283
284 // execution:
285 static int wait();
286 static double wait(double time);
287 static int check();
288 static int ready();
289 static int run();
290 static Fl_Widget* readqueue();
291 /**
292 Adds a one-shot timeout callback. The function will be called by
293 Fl::wait() at <i>t</i> seconds after this function is called.
294 The optional void* argument is passed to the callback.
295
296 You can have multiple timeout callbacks. To remove a timeout
297 callback use Fl::remove_timeout().
298
299 If you need more accurate, repeated timeouts, use Fl::repeat_timeout() to
300 reschedule the subsequent timeouts.
301
302 The following code will print "TICK" each second on
303 stdout with a fair degree of accuracy:
304
305 \code
306 void callback(void*) {
307 puts("TICK");
308 Fl::repeat_timeout(1.0, callback);
309 }
310
311 int main() {
312 Fl::add_timeout(1.0, callback);
313 return Fl::run();
314 }
315 \endcode
316 */
317 static void add_timeout(double t, Fl_Timeout_Handler,void* = 0); // platform dependent
318 /**
319 Repeats a timeout callback from the expiration of the
320 previous timeout, allowing for more accurate timing. You may only call
321 this method inside a timeout callback.
322
323 The following code will print "TICK" each second on
324 stdout with a fair degree of accuracy:
325
326 \code
327 void callback(void*) {
328 puts("TICK");
329 Fl::repeat_timeout(1.0, callback);
330 }
331
332 int main() {
333 Fl::add_timeout(1.0, callback);
334 return Fl::run();
335 }
336 \endcode
337 */
338 static void repeat_timeout(double t, Fl_Timeout_Handler, void* = 0); // platform dependent
339 static int has_timeout(Fl_Timeout_Handler, void* = 0);
340 static void remove_timeout(Fl_Timeout_Handler, void* = 0);
341 static void add_check(Fl_Timeout_Handler, void* = 0);
342 static int has_check(Fl_Timeout_Handler, void* = 0);
343 static void remove_check(Fl_Timeout_Handler, void* = 0);
344 /**
345 Adds file descriptor fd to listen to.
346
347 When the fd becomes ready for reading Fl::wait() will call the
348 callback and then return. The callback is passed the fd and the
349 arbitrary void* argument.
350
351 The second version takes a when bitfield, with the bits
352 FL_READ, FL_WRITE, and FL_EXCEPT defined,
353 to indicate when the callback should be done.
354
355 There can only be one callback of each type for a file descriptor.
356 Fl::remove_fd() gets rid of <I>all</I> the callbacks for a given
357 file descriptor.
358
359 Under UNIX <I>any</I> file descriptor can be monitored (files,
360 devices, pipes, sockets, etc.). Due to limitations in Microsoft Windows,
361 WIN32 applications can only monitor sockets.
362 */
363 static void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0); // platform dependent
364 /** See void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0) */
365 static void add_fd(int fd, Fl_FD_Handler cb, void* = 0); // platform dependent
366 /** Removes a file descriptor handler. */
367 static void remove_fd(int, int when); // platform dependent
368 /** Removes a file descriptor handler. */
369 static void remove_fd(int); // platform dependent
370
371 static void add_idle(Fl_Idle_Handler cb, void* data = 0);
372 static int has_idle(Fl_Idle_Handler cb, void* data = 0);
373 static void remove_idle(Fl_Idle_Handler cb, void* data = 0);
374 /** If true then flush() will do something. */
375 static int damage() {return damage_;}
376 static void redraw();
377 static void flush();
378 /** \addtogroup group_comdlg
379 @{ */
380 /**
381 FLTK calls Fl::warning() to output a warning message.
382
383 The default version on Windows returns \e without printing a warning
384 message, because Windows programs normally don't have stderr (a console
385 window) enabled.
386
387 The default version on all other platforms prints the warning message to stderr.
388
389 You can override the behavior by setting the function pointer to your
390 own routine.
391
392 Fl::warning() means that there was a recoverable problem, the display may
393 be messed up, but the user can probably keep working - all X protocol
394 errors call this, for example. The default implementation returns after
395 displaying the message.
396 \note \#include <FL/Fl.H>
397 */
398 static void (*warning)(const char*, ...);
399 /**
400 FLTK calls Fl::error() to output a normal error message.
401
402 The default version on Windows displays the error message in a MessageBox window.
403
404 The default version on all other platforms prints the error message to stderr.
405
406 You can override the behavior by setting the function pointer to your
407 own routine.
408
409 Fl::error() means there is a recoverable error such as the inability to read
410 an image file. The default implementation returns after displaying the message.
411 \note \#include <FL/Fl.H>
412 */
413 static void (*error)(const char*, ...);
414 /**
415 FLTK calls Fl::fatal() to output a fatal error message.
416
417 The default version on Windows displays the error message in a MessageBox window.
418
419 The default version on all other platforms prints the error message to stderr.
420
421 You can override the behavior by setting the function pointer to your
422 own routine.
423
424 Fl::fatal() must not return, as FLTK is in an unusable state, however your
425 version may be able to use longjmp or an exception to continue, as long as
426 it does not call FLTK again. The default implementation exits with status 1
427 after displaying the message.
428 \note \#include <FL/Fl.H>
429 */
430 static void (*fatal)(const char*, ...);
431 /** @} */
432
433 /** \defgroup fl_windows Windows handling functions
434 \brief Windows and standard dialogs handling declared in <FL/Fl.H>
435 @{ */
436 static Fl_Window* first_window();
437 static void first_window(Fl_Window*);
438 static Fl_Window* next_window(const Fl_Window*);
439
440 /**
441 Returns the top-most modal() window currently shown.
442
443 This is the most recently shown() window with modal() true, or NULL
444 if there are no modal() windows shown().
445 The modal() window has its handle() method called
446 for all events, and no other windows will have handle()
447 called (grab() overrides this).
448 */
449 static Fl_Window* modal() {return modal_;}
450 /** Returns the window that currently receives all events.
451
452 \return The window that currently receives all events,
453 or NULL if event grabbing is currently OFF.
454 */
455 static Fl_Window* grab() {return grab_;}
456 /** Selects the window to grab.
457 This is used when pop-up menu systems are active.
458
459 Send all events to the passed window no matter where the pointer or
460 focus is (including in other programs). The window <I>does not have
461 to be shown()</I> , this lets the handle() method of a
462 "dummy" window override all event handling and allows you to
463 map and unmap a complex set of windows (under both X and WIN32
464 <I>some</I> window must be mapped because the system interface needs a
465 window id).
466
467 If grab() is on it will also affect show() of windows by doing
468 system-specific operations (on X it turns on override-redirect).
469 These are designed to make menus popup reliably
470 and faster on the system.
471
472 To turn off grabbing do Fl::grab(0).
473
474 <I>Be careful that your program does not enter an infinite loop
475 while grab() is on. On X this will lock up your screen!</I>
476 To avoid this potential lockup, all newer operating systems seem to
477 limit mouse pointer grabbing to the time during which a mouse button
478 is held down. Some OS's may not support grabbing at all.
479 */
480 static void grab(Fl_Window*); // platform dependent
481 /** @} */
482
483 /** \defgroup fl_events Events handling functions
484 Fl class events handling API declared in <FL/Fl.H>
485 @{
486 */
487 // event information:
488 /**
489 Returns the last event that was processed. This can be used
490 to determine if a callback is being done in response to a
491 keypress, mouse click, etc.
492 */
493 static int event() {return e_number;}
494 /**
495 Returns the mouse position of the event relative to the Fl_Window
496 it was passed to.
497 */
498 static int event_x() {return e_x;}
499 /**
500 Returns the mouse position of the event relative to the Fl_Window
501 it was passed to.
502 */
503 static int event_y() {return e_y;}
504 /**
505 Returns the mouse position on the screen of the event. To find the
506 absolute position of an Fl_Window on the screen, use the
507 difference between event_x_root(),event_y_root() and
508 event_x(),event_y().
509 */
510 static int event_x_root() {return e_x_root;}
511 /**
512 Returns the mouse position on the screen of the event. To find the
513 absolute position of an Fl_Window on the screen, use the
514 difference between event_x_root(),event_y_root() and
515 event_x(),event_y().
516 */
517 static int event_y_root() {return e_y_root;}
518 /**
519 Returns the current horizontal mouse scrolling associated with the
520 FL_MOUSEWHEEL event. Right is positive.
521 */
522 static int event_dx() {return e_dx;}
523 /**
524 Returns the current vertical mouse scrolling associated with the
525 FL_MOUSEWHEEL event. Down is positive.
526 */
527 static int event_dy() {return e_dy;}
528 /**
529 Return where the mouse is on the screen by doing a round-trip query to
530 the server. You should use Fl::event_x_root() and
531 Fl::event_y_root() if possible, but this is necessary if you are
532 not sure if a mouse event has been processed recently (such as to
533 position your first window). If the display is not open, this will
534 open it.
535 */
536 static void get_mouse(int &,int &); // platform dependent
537 /**
538 Returns non zero if we had a double click event.
539 \retval Non-zero if the most recent FL_PUSH or FL_KEYBOARD was a "double click".
540 \retval N-1 for N clicks.
541 A double click is counted if the same button is pressed
542 again while event_is_click() is true.
543
544 */
545 static int event_clicks() {return e_clicks;}
546 /**
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()
552 */
553 static void event_clicks(int i) {e_clicks = i;}
554 /**
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,
559 and FL_MOVE events.
560 */
561 static int event_is_click() {return e_is_click;}
562 /**
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.
567 */
568 static void event_is_click(int i) {e_is_click = i;}
569 /**
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()
574 */
575 static int event_button() {return e_keysym-FL_Button;}
576 /**
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.
580 The legal bits are:
581
582 \li FL_SHIFT
583 \li FL_CAPS_LOCK
584 \li FL_CTRL
585 \li FL_ALT
586 \li FL_NUM_LOCK
587 \li FL_META
588 \li FL_SCROLL_LOCK
589 \li FL_BUTTON1
590 \li FL_BUTTON2
591 \li FL_BUTTON3
592
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.
598 */
599 static int event_state() {return e_state;}
600 /** See int event_state() */
601 static int event_state(int i) {return e_state&i;}
602 /**
603 Gets which key on the keyboard was last pushed.
604
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.
609
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&).
612 */
613 static int event_key() {return e_keysym;}
614 /**
615 Returns the keycode of the last key event, regardless of the NumLock state.
616
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.
621 */
622 static int event_original_key(){return e_original_keysym;}
623 /**
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.
627
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).
631
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
634 on the keyboard:
635
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().
656
657 On X Fl::get_key(FL_Button+n) does not work.
658
659 On WIN32 Fl::get_key(FL_KP_Enter) and Fl::event_key(FL_KP_Enter) do not work.
660 */
661 static int event_key(int key);
662 /**
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)
666 */
667 static int get_key(int key); // platform dependent
668 /**
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.
671
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
674 and text widgets.
675
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.
679
680 \returns A NULL terminated text string equivalent of the last keystroke.
681 */
682 static const char* event_text() {return e_text;}
683 /**
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.
688 */
689 static int event_length() {return e_length;}
690
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);
696
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();
715 /** @} */
716
717 /** \defgroup fl_clipboard Selection & Clipboard functions
718 FLTK global copy/cut/paste functions declared in <FL/Fl.H>
719 @{ */
720 // cut/paste:
721 /**
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
725 bytes in \p stuff.
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.
729 */
730 static void copy(const char* stuff, int len, int destination = 0); // platform dependent
731 /**
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().
737 The receiver
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.
743
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.
747 */
748 static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent
749 /**
DRC685f17e2011-07-28 09:23:00 +0000750 FLTK will call the registered callback whenever there is a change to the
751 selection buffer or the clipboard. The source argument indicates which
752 of the two has changed. Only changes by other applications are reported.
753 \note Some systems require polling to monitor the clipboard and may
754 therefore have some delay in detecting changes.
755 */
756 static void add_clipboard_notify(Fl_Clipboard_Notify_Handler h, void *data);
757 /**
758 Stop calling the specified callback when there are changes to the selection
759 buffer or the clipboard.
760 */
761 static void remove_clipboard_notify(Fl_Clipboard_Notify_Handler h);
762 /**
DRC2ff39b82011-07-28 08:38:59 +0000763 Initiate a Drag And Drop operation. The selection buffer should be
764 filled with relevant data before calling this method. FLTK will
765 then initiate the system wide drag and drop handling. Dropped data
766 will be marked as <i>text</i>.
767
768 Create a selection first using:
769 Fl::copy(const char *stuff, int len, 0)
770 */
771 static int dnd(); // platform dependent
772
773 // These are for back-compatibility only:
774 /** back-compatibility only: Gets the widget owning the current selection
775 \see Fl_Widget* selection_owner(Fl_Widget*) */
776 static Fl_Widget* selection_owner() {return selection_owner_;}
777 static void selection_owner(Fl_Widget*);
778 static void selection(Fl_Widget &owner, const char*, int len);
779 static void paste(Fl_Widget &receiver);
780/** @} */
781/** \defgroup fl_screen Screen functions
782 fl global screen functions declared in <FL/Fl.H>
783 @{ */
784 // screen size:
785 /** Returns the origin of the current screen work area, where 0 indicates the left side of the screen. */
786 static int x(); // platform dependent
787 /** Returns the origin of the current screen work area, where 0 indicates the top edge of the screen. */
788 static int y(); // platform dependent
789 /** Returns the width of the screen work area in pixels. */
790 static int w(); // platform dependent
791 /** Returns the height of the screen work area in pixels. */
792 static int h(); // platform dependent
793
794 // multi-head support:
795 static int screen_count();
796 /**
797 Gets the bounding box of a screen that contains the mouse pointer.
798 \param[out] X,Y,W,H the corresponding screen bounding box
799 \see void screen_xywh(int &x, int &y, int &w, int &h, int mx, int my)
800 */
801 static void screen_xywh(int &X, int &Y, int &W, int &H) {
802 screen_xywh(X, Y, W, H, e_x_root, e_y_root);
803 }
804 static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
805 static void screen_xywh(int &X, int &Y, int &W, int &H, int n);
806 static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh);
807 static void screen_dpi(float &h, float &v, int n=0);
808
809 /** @} */
810
811 /** \defgroup fl_attributes Color & Font functions
812 fl global color, font functions.
813 These functions are declared in <FL/Fl.H> or <FL/fl_draw.H>.
814 @{ */
815
816 // color map:
817 static void set_color(Fl_Color, uchar, uchar, uchar);
818 /**
819 Sets an entry in the fl_color index table. You can set it to any
820 8-bit RGB color. The color is not allocated until fl_color(i) is used.
821 */
822 static void set_color(Fl_Color i, unsigned c); // platform dependent
823 static unsigned get_color(Fl_Color i);
824 static void get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue);
825 /**
826 Frees the specified color from the colormap, if applicable.
827 If overlay is non-zero then the color is freed from the
828 overlay colormap.
829 */
830 static void free_color(Fl_Color i, int overlay = 0); // platform dependent
831
832 // fonts:
833 static const char* get_font(Fl_Font);
834 /**
835 Get a human-readable string describing the family of this face. This
836 is useful if you are presenting a choice to the user. There is no
837 guarantee that each face has a different name. The return value points
838 to a static buffer that is overwritten each call.
839
840 The integer pointed to by \p attributes (if the pointer is not
841 zero) is set to zero, FL_BOLD or FL_ITALIC or
842 FL_BOLD | FL_ITALIC. To locate a "family" of fonts, search
843 forward and back for a set with non-zero attributes, these faces along
844 with the face with a zero attribute before them constitute a family.
845 */
846 static const char* get_font_name(Fl_Font, int* attributes = 0);
847 /**
848 Return an array of sizes in \p sizep. The return value is the
849 length of this array. The sizes are sorted from smallest to largest
850 and indicate what sizes can be given to fl_font() that will
851 be matched exactly (fl_font() will pick the closest size for
852 other sizes). A zero in the first location of the array indicates a
853 scalable font, where any size works, although the array may list sizes
854 that work "better" than others. Warning: the returned array
855 points at a static buffer that is overwritten each call. Under X this
856 will open the display.
857 */
858 static int get_font_sizes(Fl_Font, int*& sizep);
859 static void set_font(Fl_Font, const char*);
860 static void set_font(Fl_Font, Fl_Font);
861 /**
862 FLTK will open the display, and add every fonts on the server to the
863 face table. It will attempt to put "families" of faces together, so
864 that the normal one is first, followed by bold, italic, and bold
865 italic.
866
867 The optional argument is a string to describe the set of fonts to
868 add. Passing NULL will select only fonts that have the
869 ISO8859-1 character set (and are thus usable by normal text). Passing
870 "-*" will select all fonts with any encoding as long as they have
871 normal X font names with dashes in them. Passing "*" will list every
872 font that exists (on X this may produce some strange output). Other
873 values may be useful but are system dependent. With WIN32 NULL
874 selects fonts with ISO8859-1 encoding and non-NULL selects
875 all fonts.
876
877 The return value is how many faces are in the table after this is done.
878 */
879 static Fl_Font set_fonts(const char* = 0); // platform dependent
880
881 /** @} */
882 /** \defgroup fl_drawings Drawing functions
883 FLTK global graphics and GUI drawing functions.
884 These functions are declared in <FL/fl_draw.H>,
885 and in <FL/x.H> for offscreen buffer-related ones.
886 @{ */
887 // <Hack to re-order the 'Drawing functions' group>
888 /** @} */
889
890 // labeltypes:
891 static void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*);
892 /** Sets the functions to call to draw and measure a specific labeltype. */
893 static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined ?
894
895 // boxtypes:
896 static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype);
897 static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar);
898 static void set_boxtype(Fl_Boxtype, Fl_Boxtype from);
899 static int box_dx(Fl_Boxtype);
900 static int box_dy(Fl_Boxtype);
901 static int box_dw(Fl_Boxtype);
902 static int box_dh(Fl_Boxtype);
903 static int draw_box_active();
904
905 // back compatibility:
906 /** \addtogroup fl_windows
907 @{ */
908 /** For back compatibility, sets the void Fl::fatal handler callback */
909 static void set_abort(Fl_Abort_Handler f) {fatal = f;}
910 static void (*atclose)(Fl_Window*,void*);
911 static void default_atclose(Fl_Window*,void*);
912 /** For back compatibility, sets the Fl::atclose handler callback. You
913 can now simply change the callback for the window instead.
914 \see Fl_Window::callback(Fl_Callback*) */
915 static void set_atclose(Fl_Atclose_Handler f) {atclose = f;}
916 /** @} */
917
918 /** \addtogroup fl_events
919 @{ */
920 /** Returns non-zero if the Shift key is pressed. */
921 static int event_shift() {return e_state&FL_SHIFT;}
922 /** Returns non-zero if the Control key is pressed. */
923 static int event_ctrl() {return e_state&FL_CTRL;}
924 /** Returns non-zero if the FL_COMMAND key is pressed, either FL_CTRL or on OSX FL_META. */
925 static int event_command() {return e_state&FL_COMMAND;}
926 /** Returns non-zero if the Alt key is pressed. */
927 static int event_alt() {return e_state&FL_ALT;}
928 /**
929 Returns the mouse buttons state bits; if non-zero, then at least one
930 button is pressed now. This function returns the button state at the
931 time of the event. During an FL_RELEASE event, the state
932 of the released button will be 0. To find out, which button
933 caused an FL_RELEASE event, you can use Fl::event_button() instead.
934 \return a bit mask value like { [FL_BUTTON1] | [FL_BUTTON2] | [FL_BUTTON3] }
935 */
936 static int event_buttons() {return e_state&0x7f000000;}
937 /**
938 Returns non-zero if mouse button 1 is currently held down.
939 For more details, see Fl::event_buttons().
940 */
941 static int event_button1() {return e_state&FL_BUTTON1;}
942 /**
943 Returns non-zero if button 2 is currently held down.
944 For more details, see Fl::event_buttons().
945 */
946 static int event_button2() {return e_state&FL_BUTTON2;}
947 /**
948 Returns non-zero if button 3 is currently held down.
949 For more details, see Fl::event_buttons().
950 */
951 static int event_button3() {return e_state&FL_BUTTON3;}
952 /** @} */
953
954 /**
955 Sets an idle callback.
956
957 \deprecated This method is obsolete - use the add_idle() method instead.
958 */
959 static void set_idle(Fl_Old_Idle_Handler cb) {idle = cb;}
960 /** See grab(Fl_Window*) */
961 static void grab(Fl_Window& win) {grab(&win);}
962 /** Releases the current grabbed window, equals grab(0).
963 \deprecated Use Fl::grab(0) instead.
964 \see grab(Fl_Window*) */
965 static void release() {grab(0);}
966
967 // Visible focus methods...
968 /**
969 Gets or sets the visible keyboard focus on buttons and other
970 non-text widgets. The default mode is to enable keyboard focus
971 for all widgets.
972 */
973 static void visible_focus(int v) { option(OPTION_VISIBLE_FOCUS, (v!=0)); }
974 /**
975 Gets or sets the visible keyboard focus on buttons and other
976 non-text widgets. The default mode is to enable keyboard focus
977 for all widgets.
978 */
979 static int visible_focus() { return option(OPTION_VISIBLE_FOCUS); }
980
981 // Drag-n-drop text operation methods...
982 /**
983 Gets or sets whether drag and drop text operations are supported.
984 This specifically affects whether selected text can
985 be dragged from text fields or dragged within a text field as a
986 cut/paste shortcut.
987 */
988 static void dnd_text_ops(int v) { option(OPTION_DND_TEXT, (v!=0)); }
989 /**
990 Gets or sets whether drag and drop text operations are
991 supported. This specifically affects whether selected text can
992 be dragged from text fields or dragged within a text field as a
993 cut/paste shortcut.
994 */
995 static int dnd_text_ops() { return option(OPTION_DND_TEXT); }
996 /** \defgroup fl_multithread Multithreading support functions
997 fl multithreading support functions declared in <FL/Fl.H>
998 @{ */
999
1000 // Multithreading support:
1001 static int lock();
1002 static void unlock();
1003 static void awake(void* message = 0);
1004 /** See void awake(void* message=0). */
1005 static int awake(Fl_Awake_Handler cb, void* message = 0);
1006 /**
1007 The thread_message() method returns the last message
1008 that was sent from a child by the awake() method.
1009
1010 See also: \ref advanced_multithreading
1011 */
1012 static void* thread_message(); // platform dependent
1013 /** @} */
1014
1015 /** \defgroup fl_del_widget Safe widget deletion support functions
1016
1017 These functions, declared in <FL/Fl.H>, support deletion of widgets inside callbacks.
1018
1019 Fl::delete_widget() should be called when deleting widgets
1020 or complete widget trees (Fl_Group, Fl_Window, ...) inside
1021 callbacks.
1022
1023 The other functions are intended for internal use. The preferred
1024 way to use them is by using the helper class Fl_Widget_Tracker.
1025
1026 The following is to show how it works ...
1027
1028 There are three groups of related methods:
1029
1030 -# scheduled widget deletion
1031 - Fl::delete_widget() schedules widgets for deletion
1032 - Fl::do_widget_deletion() deletes all scheduled widgets
1033 -# widget watch list ("smart pointers")
1034 - Fl::watch_widget_pointer() adds a widget pointer to the watch list
1035 - Fl::release_widget_pointer() removes a widget pointer from the watch list
1036 - Fl::clear_widget_pointer() clears a widget pointer \e in the watch list
1037 -# the class Fl_Widget_Tracker:
1038 - the constructor calls Fl::watch_widget_pointer()
1039 - the destructor calls Fl::release_widget_pointer()
1040 - the access methods can be used to test, if a widget has been deleted
1041 \see Fl_Widget_Tracker.
1042
1043 @{ */
1044 // Widget deletion:
1045 static void delete_widget(Fl_Widget *w);
1046 static void do_widget_deletion();
1047 static void watch_widget_pointer(Fl_Widget *&w);
1048 static void release_widget_pointer(Fl_Widget *&w);
1049 static void clear_widget_pointer(Fl_Widget const *w);
1050 /** @} */
1051
1052#ifdef FLTK_HAVE_CAIRO
1053 /** \defgroup group_cairo Cairo support functions and classes
1054 @{
1055 */
1056public:
1057 // Cairo support API
1058 static cairo_t * cairo_make_current(Fl_Window* w);
1059 /** when FLTK_HAVE_CAIRO is defined and cairo_autolink_context() is true,
1060 any current window dc is linked to a current context.
1061 This is not the default, because it may not be necessary
1062 to add cairo support to all fltk supported windows.
1063 When you wish to associate a cairo context in this mode,
1064 you need to call explicitly in your draw() overridden method,
1065 FL::cairo_make_current(Fl_Window*). This will create a cairo context
1066 but only for this Window.
1067 Still in custom cairo application it is possible to handle
1068 completely this process automatically by setting \p alink to true.
1069 In this last case, you don't need anymore to call Fl::cairo_make_current().
1070 You can use Fl::cairo_cc() to get the current cairo context anytime.
1071 \note Only available when configure has the --enable-cairo option
1072 */
1073 static void cairo_autolink_context(bool alink) {cairo_state_.autolink(alink);}
1074 /**
1075 Gets the current autolink mode for cairo support.
1076 \retval false if no cairo context autolink is made for each window.
1077 \retval true if any fltk window is attached a cairo context when it
1078 is current. \see void cairo_autolink_context(bool alink)
1079 \note Only available when configure has the --enable-cairo option
1080 */
1081 static bool cairo_autolink_context() {return cairo_state_.autolink();}
1082 /** Gets the current cairo context linked with a fltk window. */
1083 static cairo_t * cairo_cc() { return cairo_state_.cc(); }
1084 /** Sets the current cairo context to \p c.
1085 Set \p own to true if you want fltk to handle this cc deletion.
1086 \note Only available when configure has the --enable-cairo option
1087*/
1088 static void cairo_cc(cairo_t * c, bool own=false){ cairo_state_.cc(c, own); }
1089
1090private:
1091 static cairo_t * cairo_make_current(void* gc);
1092 static cairo_t * cairo_make_current(void* gc, int W, int H);
1093 static Fl_Cairo_State cairo_state_;
1094public:
1095 /** @} */
1096
1097#endif // FLTK_HAVE_CAIRO
1098
1099};
1100
1101/**
1102 This class should be used to control safe widget deletion.
1103
1104 You can use an Fl_Widget_Tracker object to watch another widget, if you
1105 need to know, if this widget has been deleted during a callback.
1106
1107 This simplifies the use of the "safe widget deletion" methods
1108 Fl::watch_widget_pointer() and Fl::release_widget_pointer() and
1109 makes their use more reliable, because the destructor autmatically
1110 releases the widget pointer from the widget watch list.
1111
1112 It is intended to be used as an automatic (local/stack) variable,
1113 such that the automatic destructor is called when the object's
1114 scope is left. This ensures that no stale widget pointers are
1115 left in the widget watch list (see example below).
1116
1117 You can also create Fl_Widget_Tracker objects with \c new, but then it
1118 is your responsibility to delete the object (and thus remove the
1119 widget pointer from the watch list) when it is not needed any more.
1120
1121 Example:
1122
1123 \code
1124 int MyClass::handle (int event) {
1125
1126 if (...) {
1127 Fl_Widget_Tracker wp(this); // watch myself
1128 do_callback(); // call the callback
1129
1130 if (wp.deleted()) return 1; // exit, if deleted
1131
1132 // Now we are sure that the widget has not been deleted.
1133 // It is safe to access the widget
1134
1135 clear_changed(); // access the widget
1136 }
1137 }
1138 \endcode
1139
1140*/
1141class FL_EXPORT Fl_Widget_Tracker {
1142
1143 Fl_Widget* wp_;
1144
1145public:
1146
1147 Fl_Widget_Tracker(Fl_Widget *wi);
1148 ~Fl_Widget_Tracker();
1149
1150 /**
1151 Returns a pointer to the watched widget.
1152
1153 This pointer is \c NULL, if the widget has been deleted.
1154 */
1155 Fl_Widget *widget() {return wp_;}
1156
1157 /**
1158 Returns 1, if the watched widget has been deleted.
1159
1160 This is a convenience method. You can also use something like
1161
1162 <tt> if (wp.widget() == 0) // ...</tt>
1163
1164 where \p wp is an Fl_Widget_Tracker object.
1165 */
1166 int deleted() {return wp_ == 0;}
1167
1168 /**
1169 Returns 1, if the watched widget exists (has not been deleted).
1170
1171 This is a convenience method. You can also use something like
1172
1173 <tt> if (wp.widget() != 0) // ...</tt>
1174
1175 where \p wp is an Fl_Widget_Tracker object.
1176 */
1177 int exists() {return wp_ != 0;}
1178
1179};
1180
1181 /** \defgroup fl_unicode Unicode and UTF-8 functions
1182 fl global Unicode and UTF-8 handling functions declared in <FL/fl_utf8.h>
1183 @{ */
1184 /** @} */
1185
1186#endif // !Fl_H
1187
1188//
1189// End of "$Id: Fl.H 8724 2011-05-23 18:01:29Z manolo $".
1190//