You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1173 lines
43KB

  1. //
  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. /** \file
  28. Fl static class.
  29. */
  30. #ifndef Fl_H
  31. # define Fl_H
  32. # include <FL/Fl_Cairo.H>
  33. # include "fl_utf8.h"
  34. # include "Enumerations.H"
  35. # ifndef Fl_Object
  36. # define Fl_Object Fl_Widget /**< for back compatibility - use Fl_Widget! */
  37. # endif
  38. # ifdef check
  39. # undef check
  40. # endif
  41. class Fl_Widget;
  42. class Fl_Window;
  43. class Fl_Image;
  44. struct Fl_Label;
  45. /** \defgroup callback_functions Callback function typedefs
  46. \brief Typedefs defined in <FL/Fl.H> for callback or handler functions passed as function parameters.
  47. FLTK uses callback functions as parameters for some function calls, e.g. to
  48. set up global event handlers (Fl::add_handler()), to add a timeout handler
  49. (Fl::add_timeout()), and many more.
  50. The typedefs defined in this group describe the function parameters used to set
  51. up or clear the callback functions and should also be referenced to define the
  52. callback function to handle such events in the user's code.
  53. \see Fl::add_handler(), Fl::add_timeout(), Fl::repeat_timeout(),
  54. Fl::remove_timeout() and others
  55. @{ */
  56. /** Signature of some label drawing functions passed as parameters */
  57. typedef void (Fl_Label_Draw_F)(const Fl_Label *label, int x, int y, int w, int h, Fl_Align align);
  58. /** Signature of some label measurement functions passed as parameters */
  59. typedef void (Fl_Label_Measure_F)(const Fl_Label *label, int &width, int &height);
  60. /** Signature of some box drawing functions passed as parameters */
  61. typedef void (Fl_Box_Draw_F)(int x, int y, int w, int h, Fl_Color color);
  62. /** Signature of some timeout callback functions passed as parameters */
  63. typedef void (*Fl_Timeout_Handler)(void *data);
  64. /** Signature of some wakeup callback functions passed as parameters */
  65. typedef void (*Fl_Awake_Handler)(void *data);
  66. /** Signature of add_idle callback functions passed as parameters */
  67. typedef void (*Fl_Idle_Handler)(void *data);
  68. /** Signature of set_idle callback functions passed as parameters */
  69. typedef void (*Fl_Old_Idle_Handler)();
  70. /** Signature of add_fd functions passed as parameters */
  71. typedef void (*Fl_FD_Handler)(int fd, void *data);
  72. /** Signature of add_handler functions passed as parameters */
  73. typedef int (*Fl_Event_Handler)(int event);
  74. /** Signature of set_abort functions passed as parameters */
  75. typedef void (*Fl_Abort_Handler)(const char *format,...);
  76. /** Signature of set_atclose functions passed as parameters */
  77. typedef void (*Fl_Atclose_Handler)(Fl_Window *window, void *data);
  78. /** Signature of args functions passed as parameters */
  79. typedef int (*Fl_Args_Handler)(int argc, char **argv, int &i);
  80. /** Signature of event_dispatch functions passed as parameters.
  81. \see Fl::event_dispatch(Fl_Event_Dispatch) */
  82. typedef int (*Fl_Event_Dispatch)(int event, Fl_Window *w);
  83. /** @} */ /* group callback_functions */
  84. /**
  85. The Fl is the FLTK global (static) class containing
  86. state information and global methods for the current application.
  87. */
  88. class FL_EXPORT Fl {
  89. Fl() {}; // no constructor!
  90. public: // should be private!
  91. #ifndef FL_DOXYGEN
  92. static int e_number;
  93. static int e_x;
  94. static int e_y;
  95. static int e_x_root;
  96. static int e_y_root;
  97. static int e_dx;
  98. static int e_dy;
  99. static int e_state;
  100. static int e_clicks;
  101. static int e_is_click;
  102. static int e_keysym;
  103. static char* e_text;
  104. static int e_length;
  105. static Fl_Event_Dispatch e_dispatch;
  106. static Fl_Widget* belowmouse_;
  107. static Fl_Widget* pushed_;
  108. static Fl_Widget* focus_;
  109. static int damage_;
  110. static Fl_Widget* selection_owner_;
  111. static Fl_Window* modal_;
  112. static Fl_Window* grab_;
  113. static int compose_state;
  114. #endif
  115. /**
  116. If true then flush() will do something.
  117. */
  118. static void damage(int d) {damage_ = d;}
  119. public:
  120. /** Enumerator for global FLTK options.
  121. These options can be set system wide, per user, or for the running
  122. application only.
  123. \see Fl::option(Fl_Option, bool)
  124. \see Fl::option(Fl_Option)
  125. */
  126. typedef enum {
  127. /// When switched on, moving the text cursor beyond the start or end of
  128. /// a text in a text widget will change focus to the next text widget.
  129. /// When switched off, the cursor will stop at the end of the text.
  130. /// Pressing Tab or Ctrl-Tab will advance the keyboard focus.
  131. OPTION_ARROW_FOCUS = 0,
  132. // When switched on, FLTK will use the file chooser dialog that comes
  133. // with your operating system whenever possible. When switched off, FLTK
  134. // will present its own file chooser.
  135. // \todo implement me
  136. // OPTION_NATIVE_FILECHOOSER,
  137. // When Filechooser Preview is enabled, the FLTK or native file chooser
  138. // will show a preview of a selected file (if possible) before the user
  139. // decides to choose the file.
  140. // \todo implement me
  141. //OPTION_FILECHOOSER_PREVIEW,
  142. /// If visible focus is switched on, FLTK will draw a dotted rectangle
  143. /// inside the widget that will receive the next keystroke. If switched
  144. /// off, no such indicator will be drawn and keyboard navigation
  145. /// is disabled.
  146. OPTION_VISIBLE_FOCUS,
  147. /// If text drag-and-drop is enabled, the user can select and drag text
  148. /// from any text widget. If disabled, no dragging is possible, however
  149. /// dropping text from other applications still works.
  150. OPTION_DND_TEXT,
  151. /// If tooltips are enabled, hovering the mouse over a widget with a
  152. /// tooltip text will open a little tooltip window until the mouse leaves
  153. /// the widget. If disabled, no tooltip is shown.
  154. OPTION_SHOW_TOOLTIPS,
  155. // don't change this, leave it always as the last element
  156. /// For internal use only.
  157. OPTION_LAST
  158. } Fl_Option;
  159. private:
  160. static unsigned char options_[OPTION_LAST];
  161. static unsigned char options_read_;
  162. public:
  163. /*
  164. Return a global setting for all FLTK applications, possibly overridden
  165. by a setting specifically for this application.
  166. */
  167. static bool option(Fl_Option opt);
  168. /*
  169. Override an option while the application is running.
  170. */
  171. static void option(Fl_Option opt, bool val);
  172. /**
  173. The currently executing idle callback function: DO NOT USE THIS DIRECTLY!
  174. This is now used as part of a higher level system allowing multiple
  175. idle callback functions to be called.
  176. \see add_idle(), remove_idle()
  177. */
  178. static void (*idle)();
  179. #ifndef FL_DOXYGEN
  180. static Fl_Awake_Handler *awake_ring_;
  181. static void **awake_data_;
  182. static int awake_ring_size_;
  183. static int awake_ring_head_;
  184. static int awake_ring_tail_;
  185. static const char* scheme_;
  186. static Fl_Image* scheme_bg_;
  187. static int e_original_keysym; // late addition
  188. static int scrollbar_size_;
  189. #endif
  190. static int add_awake_handler_(Fl_Awake_Handler, void*);
  191. static int get_awake_handler_(Fl_Awake_Handler&, void*&);
  192. public:
  193. // API version number
  194. static double version();
  195. // argument parsers:
  196. static int arg(int argc, char **argv, int& i);
  197. static int args(int argc, char **argv, int& i, Fl_Args_Handler cb = 0);
  198. static void args(int argc, char **argv);
  199. /**
  200. Usage string displayed if Fl::args() detects an invalid argument.
  201. This may be changed to point to customized text at run-time.
  202. */
  203. static const char* const help;
  204. // things called by initialization:
  205. static void display(const char*);
  206. static int visual(int);
  207. /**
  208. This does the same thing as Fl::visual(int) but also requires OpenGL
  209. drawing to work. This <I>must</I> be done if you want to draw in
  210. normal windows with OpenGL with gl_start() and gl_end().
  211. It may be useful to call this so your X windows use the same visual
  212. as an Fl_Gl_Window, which on some servers will reduce colormap flashing.
  213. See Fl_Gl_Window for a list of additional values for the argument.
  214. */
  215. static int gl_visual(int, int *alist=0); // platform dependent
  216. static void own_colormap();
  217. static void get_system_colors();
  218. static void foreground(uchar, uchar, uchar);
  219. static void background(uchar, uchar, uchar);
  220. static void background2(uchar, uchar, uchar);
  221. // schemes:
  222. static int scheme(const char*);
  223. /** See void scheme(const char *name) */
  224. static const char* scheme() {return scheme_;}
  225. /**
  226. Called by scheme according to scheme name.
  227. Loads or reloads the current scheme selection.
  228. See void scheme(const char *name)
  229. */
  230. static int reload_scheme(); // platform dependent
  231. static void scheme_bg ( Fl_Image *i ) { scheme_bg_ = i; }
  232. static int scrollbar_size();
  233. static void scrollbar_size(int W);
  234. // execution:
  235. static int wait();
  236. static double wait(double time);
  237. static int check();
  238. static int ready();
  239. static int run();
  240. static Fl_Widget* readqueue();
  241. /**
  242. Adds a one-shot timeout callback. The function will be called by
  243. Fl::wait() at <i>t</i> seconds after this function is called.
  244. The optional void* argument is passed to the callback.
  245. You can have multiple timeout callbacks. To remove a timeout
  246. callback use Fl::remove_timeout().
  247. If you need more accurate, repeated timeouts, use Fl::repeat_timeout() to
  248. reschedule the subsequent timeouts.
  249. The following code will print "TICK" each second on
  250. stdout with a fair degree of accuracy:
  251. \code
  252. void callback(void*) {
  253. puts("TICK");
  254. Fl::repeat_timeout(1.0, callback);
  255. }
  256. int main() {
  257. Fl::add_timeout(1.0, callback);
  258. return Fl::run();
  259. }
  260. \endcode
  261. */
  262. static void add_timeout(double t, Fl_Timeout_Handler,void* = 0); // platform dependent
  263. /**
  264. Repeats a timeout callback from the expiration of the
  265. previous timeout, allowing for more accurate timing. You may only call
  266. this method inside a timeout callback.
  267. The following code will print "TICK" each second on
  268. stdout with a fair degree of accuracy:
  269. \code
  270. void callback(void*) {
  271. puts("TICK");
  272. Fl::repeat_timeout(1.0, callback);
  273. }
  274. int main() {
  275. Fl::add_timeout(1.0, callback);
  276. return Fl::run();
  277. }
  278. \endcode
  279. */
  280. static void repeat_timeout(double t, Fl_Timeout_Handler, void* = 0); // platform dependent
  281. static int has_timeout(Fl_Timeout_Handler, void* = 0);
  282. static void remove_timeout(Fl_Timeout_Handler, void* = 0);
  283. static void add_check(Fl_Timeout_Handler, void* = 0);
  284. static int has_check(Fl_Timeout_Handler, void* = 0);
  285. static void remove_check(Fl_Timeout_Handler, void* = 0);
  286. /**
  287. Adds file descriptor fd to listen to.
  288. When the fd becomes ready for reading Fl::wait() will call the
  289. callback and then return. The callback is passed the fd and the
  290. arbitrary void* argument.
  291. The second version takes a when bitfield, with the bits
  292. FL_READ, FL_WRITE, and FL_EXCEPT defined,
  293. to indicate when the callback should be done.
  294. There can only be one callback of each type for a file descriptor.
  295. Fl::remove_fd() gets rid of <I>all</I> the callbacks for a given
  296. file descriptor.
  297. Under UNIX <I>any</I> file descriptor can be monitored (files,
  298. devices, pipes, sockets, etc.). Due to limitations in Microsoft Windows,
  299. WIN32 applications can only monitor sockets.
  300. */
  301. static void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0); // platform dependent
  302. /** See void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0) */
  303. static void add_fd(int fd, Fl_FD_Handler cb, void* = 0); // platform dependent
  304. /** Removes a file descriptor handler. */
  305. static void remove_fd(int, int when); // platform dependent
  306. /** Removes a file descriptor handler. */
  307. static void remove_fd(int); // platform dependent
  308. static void add_idle(Fl_Idle_Handler cb, void* data = 0);
  309. static int has_idle(Fl_Idle_Handler cb, void* data = 0);
  310. static void remove_idle(Fl_Idle_Handler cb, void* data = 0);
  311. /** If true then flush() will do something. */
  312. static int damage() {return damage_;}
  313. static void redraw();
  314. static void flush();
  315. /** \addtogroup group_comdlg
  316. @{ */
  317. /**
  318. FLTK calls Fl::warning() to output a warning message.
  319. The default version on Windows returns \e without printing a warning
  320. message, because Windows programs normally don't have stderr (a console
  321. window) enabled.
  322. The default version on all other platforms prints the warning message to stderr.
  323. You can override the behavior by setting the function pointer to your
  324. own routine.
  325. Fl::warning() means that there was a recoverable problem, the display may
  326. be messed up, but the user can probably keep working - all X protocol
  327. errors call this, for example. The default implementation returns after
  328. displaying the message.
  329. \note \#include <FL/Fl.H>
  330. */
  331. static void (*warning)(const char*, ...);
  332. /**
  333. FLTK calls Fl::error() to output a normal error message.
  334. The default version on Windows displays the error message in a MessageBox window.
  335. The default version on all other platforms prints the error message to stderr.
  336. You can override the behavior by setting the function pointer to your
  337. own routine.
  338. Fl::error() means there is a recoverable error such as the inability to read
  339. an image file. The default implementation returns after displaying the message.
  340. \note \#include <FL/Fl.H>
  341. */
  342. static void (*error)(const char*, ...);
  343. /**
  344. FLTK calls Fl::fatal() to output a fatal error message.
  345. The default version on Windows displays the error message in a MessageBox window.
  346. The default version on all other platforms prints the error message to stderr.
  347. You can override the behavior by setting the function pointer to your
  348. own routine.
  349. Fl::fatal() must not return, as FLTK is in an unusable state, however your
  350. version may be able to use longjmp or an exception to continue, as long as
  351. it does not call FLTK again. The default implementation exits with status 1
  352. after displaying the message.
  353. \note \#include <FL/Fl.H>
  354. */
  355. static void (*fatal)(const char*, ...);
  356. /** @} */
  357. /** \defgroup fl_windows Windows handling functions
  358. \brief Windows and standard dialogs handling declared in <FL/Fl.H>
  359. @{ */
  360. static Fl_Window* first_window();
  361. static void first_window(Fl_Window*);
  362. static Fl_Window* next_window(const Fl_Window*);
  363. /**
  364. Returns the top-most modal() window currently shown.
  365. This is the most recently shown() window with modal() true, or NULL
  366. if there are no modal() windows shown().
  367. The modal() window has its handle() method called
  368. for all events, and no other windows will have handle()
  369. called (grab() overrides this).
  370. */
  371. static Fl_Window* modal() {return modal_;}
  372. /** Returns the window that currently receives all events.
  373. \return The window that currently receives all events,
  374. or NULL if event grabbing is currently OFF.
  375. */
  376. static Fl_Window* grab() {return grab_;}
  377. /** Selects the window to grab.
  378. This is used when pop-up menu systems are active.
  379. Send all events to the passed window no matter where the pointer or
  380. focus is (including in other programs). The window <I>does not have
  381. to be shown()</I> , this lets the handle() method of a
  382. "dummy" window override all event handling and allows you to
  383. map and unmap a complex set of windows (under both X and WIN32
  384. <I>some</I> window must be mapped because the system interface needs a
  385. window id).
  386. If grab() is on it will also affect show() of windows by doing
  387. system-specific operations (on X it turns on override-redirect).
  388. These are designed to make menus popup reliably
  389. and faster on the system.
  390. To turn off grabbing do Fl::grab(0).
  391. <I>Be careful that your program does not enter an infinite loop
  392. while grab() is on. On X this will lock up your screen!</I>
  393. To avoid this potential lockup, all newer operating systems seem to
  394. limit mouse pointer grabbing to the time during which a mouse button
  395. is held down. Some OS's may not support grabbing at all.
  396. */
  397. static void grab(Fl_Window*); // platform dependent
  398. /** @} */
  399. /** \defgroup fl_events Events handling functions
  400. Fl class events handling API declared in <FL/Fl.H>
  401. @{
  402. */
  403. // event information:
  404. /**
  405. Returns the last event that was processed. This can be used
  406. to determine if a callback is being done in response to a
  407. keypress, mouse click, etc.
  408. */
  409. static int event() {return e_number;}
  410. /**
  411. Returns the mouse position of the event relative to the Fl_Window
  412. it was passed to.
  413. */
  414. static int event_x() {return e_x;}
  415. /**
  416. Returns the mouse position of the event relative to the Fl_Window
  417. it was passed to.
  418. */
  419. static int event_y() {return e_y;}
  420. /**
  421. Returns the mouse position on the screen of the event. To find the
  422. absolute position of an Fl_Window on the screen, use the
  423. difference between event_x_root(),event_y_root() and
  424. event_x(),event_y().
  425. */
  426. static int event_x_root() {return e_x_root;}
  427. /**
  428. Returns the mouse position on the screen of the event. To find the
  429. absolute position of an Fl_Window on the screen, use the
  430. difference between event_x_root(),event_y_root() and
  431. event_x(),event_y().
  432. */
  433. static int event_y_root() {return e_y_root;}
  434. /**
  435. Returns the current horizontal mouse scrolling associated with the
  436. FL_MOUSEWHEEL event. Right is positive.
  437. */
  438. static int event_dx() {return e_dx;}
  439. /**
  440. Returns the current vertical mouse scrolling associated with the
  441. FL_MOUSEWHEEL event. Down is positive.
  442. */
  443. static int event_dy() {return e_dy;}
  444. /**
  445. Return where the mouse is on the screen by doing a round-trip query to
  446. the server. You should use Fl::event_x_root() and
  447. Fl::event_y_root() if possible, but this is necessary if you are
  448. not sure if a mouse event has been processed recently (such as to
  449. position your first window). If the display is not open, this will
  450. open it.
  451. */
  452. static void get_mouse(int &,int &); // platform dependent
  453. /**
  454. Returns non zero if we had a double click event.
  455. \retval Non-zero if the most recent FL_PUSH or FL_KEYBOARD was a "double click".
  456. \retval N-1 for N clicks.
  457. A double click is counted if the same button is pressed
  458. again while event_is_click() is true.
  459. */
  460. static int event_clicks() {return e_clicks;}
  461. /**
  462. Manually sets the number returned by Fl::event_clicks().
  463. This can be used to set it to zero so that
  464. later code does not think an item was double-clicked.
  465. \param[in] i corresponds to no double-click if 0, i+1 mouse clicks otherwise
  466. \see int event_clicks()
  467. */
  468. static void event_clicks(int i) {e_clicks = i;}
  469. /**
  470. Returns non-zero if the mouse has not moved far enough
  471. and not enough time has passed since the last FL_PUSH or
  472. FL_KEYBOARD event for it to be considered a "drag" rather than a
  473. "click". You can test this on FL_DRAG, FL_RELEASE,
  474. and FL_MOVE events.
  475. */
  476. static int event_is_click() {return e_is_click;}
  477. /**
  478. Clears the value returned by Fl::event_is_click().
  479. Useful to prevent the <I>next</I>
  480. click from being counted as a double-click or to make a popup menu
  481. pick an item with a single click. Don't pass non-zero to this.
  482. */
  483. static void event_is_click(int i) {e_is_click = i;}
  484. /**
  485. Gets which particular mouse button caused the current event.
  486. This returns garbage if the most recent event was not a FL_PUSH or FL_RELEASE event.
  487. \retval FL_LEFT_MOUSE \retval FL_MIDDLE_MOUSE \retval FL_RIGHT_MOUSE.
  488. \see Fl::event_buttons()
  489. */
  490. static int event_button() {return e_keysym-FL_Button;}
  491. /**
  492. This is a bitfield of what shift states were on and what mouse buttons
  493. were held down during the most recent event. The second version
  494. returns non-zero if any of the passed bits are turned on.
  495. The legal bits are:
  496. \li FL_SHIFT
  497. \li FL_CAPS_LOCK
  498. \li FL_CTRL
  499. \li FL_ALT
  500. \li FL_NUM_LOCK
  501. \li FL_META
  502. \li FL_SCROLL_LOCK
  503. \li FL_BUTTON1
  504. \li FL_BUTTON2
  505. \li FL_BUTTON3
  506. X servers do not agree on shift states, and FL_NUM_LOCK, FL_META, and
  507. FL_SCROLL_LOCK may not work. The values were selected to match the
  508. XFree86 server on Linux. In addition there is a bug in the way X works
  509. so that the shift state is not correctly reported until the first event
  510. <I>after</I> the shift key is pressed or released.
  511. */
  512. static int event_state() {return e_state;}
  513. /** See int event_state() */
  514. static int event_state(int i) {return e_state&i;}
  515. /**
  516. Gets which key on the keyboard was last pushed.
  517. The returned integer 'key code' is not necessarily a text
  518. equivalent for the keystroke. For instance: if someone presses '5' on the
  519. numeric keypad with numlock on, Fl::event_key() may return the 'key code'
  520. for this key, and NOT the character '5'. To always get the '5', use Fl::event_text() instead.
  521. \returns an integer 'key code', or 0 if the last event was not a key press or release.
  522. \see int event_key(int), event_text(), compose(int&).
  523. */
  524. static int event_key() {return e_keysym;}
  525. /**
  526. Returns the keycode of the last key event, regardless of the NumLock state.
  527. If NumLock is deactivated, FLTK translates events from the
  528. numeric keypad into the corresponding arrow key events.
  529. event_key() returns the translated key code, whereas
  530. event_original_key() returns the keycode before NumLock translation.
  531. */
  532. static int event_original_key(){return e_original_keysym;}
  533. /**
  534. Returns true if the given \p key was held
  535. down (or pressed) <I>during</I> the last event. This is constant until
  536. the next event is read from the server.
  537. Fl::get_key(int) returns true if the given key is held down <I>now</I>.
  538. Under X this requires a round-trip to the server and is <I>much</I>
  539. slower than Fl::event_key(int).
  540. Keys are identified by the <I>unshifted</I> values. FLTK defines a
  541. set of symbols that should work on most modern machines for every key
  542. on the keyboard:
  543. \li All keys on the main keyboard producing a printable ASCII
  544. character use the value of that ASCII character (as though shift,
  545. ctrl, and caps lock were not on). The space bar is 32.
  546. \li All keys on the numeric keypad producing a printable ASCII
  547. character use the value of that ASCII character plus FL_KP.
  548. The highest possible value is FL_KP_Last so you can
  549. range-check to see if something is on the keypad.
  550. \li All numbered function keys use the number on the function key plus
  551. FL_F. The highest possible number is FL_F_Last, so you
  552. can range-check a value.
  553. \li Buttons on the mouse are considered keys, and use the button
  554. number (where the left button is 1) plus FL_Button.
  555. \li All other keys on the keypad have a symbol: FL_Escape,
  556. FL_BackSpace, FL_Tab, FL_Enter, FL_Print, FL_Scroll_Lock, FL_Pause,
  557. FL_Insert, FL_Home, FL_Page_Up, FL_Delete, FL_End, FL_Page_Down,
  558. FL_Left, FL_Up, FL_Right, FL_Down, FL_Shift_L, FL_Shift_R,
  559. FL_Control_L, FL_Control_R, FL_Caps_Lock, FL_Alt_L, FL_Alt_R,
  560. FL_Meta_L, FL_Meta_R, FL_Menu, FL_Num_Lock, FL_KP_Enter. Be
  561. careful not to confuse these with the very similar, but all-caps,
  562. symbols used by Fl::event_state().
  563. On X Fl::get_key(FL_Button+n) does not work.
  564. On WIN32 Fl::get_key(FL_KP_Enter) and Fl::event_key(FL_KP_Enter) do not work.
  565. */
  566. static int event_key(int key);
  567. /**
  568. Returns true if the given \p key is held down <I>now</I>.
  569. Under X this requires a round-trip to the server and is <I>much</I>
  570. slower than Fl::event_key(int). \see event_key(int)
  571. */
  572. static int get_key(int key); // platform dependent
  573. /**
  574. Returns the text associated with the current event, including FL_PASTE or FL_DND_RELEASE events.
  575. This can be used in response to FL_KEYUP, FL_KEYDOWN, FL_PASTE, FL_DND_RELEASE.
  576. When responding to FL_KEYUP/FL_KEYDOWN, use this function instead of Fl::event_key()
  577. to get the text equivalent of keystrokes suitable for inserting into strings
  578. and text widgets.
  579. The returned string is guaranteed to be be NULL terminated.
  580. However, see Fl::event_length() for the actual length of the string,
  581. in case the string itself contains NULLs that are part of the text data.
  582. \returns A NULL terminated text string equivalent of the last keystroke.
  583. */
  584. static const char* event_text() {return e_text;}
  585. /**
  586. Returns the length of the text in Fl::event_text(). There
  587. will always be a nul at this position in the text. However there may
  588. be a nul before that if the keystroke translates to a nul character or
  589. you paste a nul character.
  590. */
  591. static int event_length() {return e_length;}
  592. static int compose(int &del);
  593. static void compose_reset();
  594. static int event_inside(int,int,int,int);
  595. static int event_inside(const Fl_Widget*);
  596. static int test_shortcut(Fl_Shortcut);
  597. // event destinations:
  598. static int handle(int, Fl_Window*);
  599. static int handle_(int, Fl_Window*);
  600. /** Gets the widget that is below the mouse.
  601. \see belowmouse(Fl_Widget*) */
  602. static Fl_Widget* belowmouse() {return belowmouse_;}
  603. static void belowmouse(Fl_Widget*);
  604. /** Gets the widget that is being pushed.
  605. \see void pushed(Fl_Widget*) */
  606. static Fl_Widget* pushed() {return pushed_;}
  607. static void pushed(Fl_Widget*);
  608. /** Gets the current Fl::focus() widget. \sa Fl::focus(Fl_Widget*) */
  609. static Fl_Widget* focus() {return focus_;}
  610. static void focus(Fl_Widget*);
  611. static void add_handler(Fl_Event_Handler h);
  612. static void remove_handler(Fl_Event_Handler h);
  613. static void event_dispatch(Fl_Event_Dispatch d);
  614. static Fl_Event_Dispatch event_dispatch();
  615. /** @} */
  616. /** \defgroup fl_clipboard Selection & Clipboard functions
  617. FLTK global copy/cut/paste functions declared in <FL/Fl.H>
  618. @{ */
  619. // cut/paste:
  620. /**
  621. Copies the data pointed to by \p stuff to the selection buffer
  622. (\p destination is 0) or
  623. the clipboard (\p destination is 1); \p len is the number of relevant
  624. bytes in \p stuff.
  625. The selection buffer is used for
  626. middle-mouse pastes and for drag-and-drop selections. The
  627. clipboard is used for traditional copy/cut/paste operations.
  628. */
  629. static void copy(const char* stuff, int len, int destination = 0); // platform dependent
  630. /**
  631. Pastes the data from the selection buffer (\p source is 0) or the clipboard
  632. (\p source is 1) into \p receiver.
  633. Set things up so the receiver widget will be called with an FL_PASTE event some
  634. time in the future with the data from the specified \p source in Fl::event_text()
  635. and the number of characters in Fl::event_length().
  636. The receiver
  637. should be prepared to be called \e directly by this, or for
  638. it to happen \e later, or possibly <i>not at all</i>. This
  639. allows the window system to take as long as necessary to retrieve
  640. the paste buffer (or even to screw up completely) without complex
  641. and error-prone synchronization code in FLTK.
  642. The selection buffer is used for middle-mouse pastes and for
  643. drag-and-drop selections. The clipboard is used for traditional
  644. copy/cut/paste operations.
  645. */
  646. static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent
  647. /**
  648. Initiate a Drag And Drop operation. The selection buffer should be
  649. filled with relevant data before calling this method. FLTK will
  650. then initiate the system wide drag and drop handling. Dropped data
  651. will be marked as <i>text</i>.
  652. Create a selection first using:
  653. Fl::copy(const char *stuff, int len, 0)
  654. */
  655. static int dnd(); // platform dependent
  656. // These are for back-compatibility only:
  657. /** back-compatibility only: Gets the widget owning the current selection
  658. \see Fl_Widget* selection_owner(Fl_Widget*) */
  659. static Fl_Widget* selection_owner() {return selection_owner_;}
  660. static void selection_owner(Fl_Widget*);
  661. static void selection(Fl_Widget &owner, const char*, int len);
  662. static void paste(Fl_Widget &receiver);
  663. /** @} */
  664. /** \defgroup fl_screen Screen functions
  665. fl global screen functions declared in <FL/Fl.H>
  666. @{ */
  667. // screen size:
  668. /** Returns the origin of the current screen work area, where 0 indicates the left side of the screen. */
  669. static int x(); // platform dependent
  670. /** Returns the origin of the current screen work area, where 0 indicates the top edge of the screen. */
  671. static int y(); // platform dependent
  672. /** Returns the width of the screen work area in pixels. */
  673. static int w(); // platform dependent
  674. /** Returns the height of the screen work area in pixels. */
  675. static int h(); // platform dependent
  676. // multi-head support:
  677. static int screen_count();
  678. /**
  679. Gets the bounding box of a screen that contains the mouse pointer.
  680. \param[out] X,Y,W,H the corresponding screen bounding box
  681. \see void screen_xywh(int &x, int &y, int &w, int &h, int mx, int my)
  682. */
  683. static void screen_xywh(int &X, int &Y, int &W, int &H) {
  684. screen_xywh(X, Y, W, H, e_x_root, e_y_root);
  685. }
  686. static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
  687. static void screen_xywh(int &X, int &Y, int &W, int &H, int n);
  688. static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh);
  689. static void screen_dpi(float &h, float &v, int n=0);
  690. /** @} */
  691. /** \defgroup fl_attributes Color & Font functions
  692. fl global color, font functions.
  693. These functions are declared in <FL/Fl.H> or <FL/fl_draw.H>.
  694. @{ */
  695. // color map:
  696. static void set_color(Fl_Color, uchar, uchar, uchar);
  697. /**
  698. Sets an entry in the fl_color index table. You can set it to any
  699. 8-bit RGB color. The color is not allocated until fl_color(i) is used.
  700. */
  701. static void set_color(Fl_Color i, unsigned c); // platform dependent
  702. static unsigned get_color(Fl_Color i);
  703. static void get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue);
  704. /**
  705. Frees the specified color from the colormap, if applicable.
  706. If overlay is non-zero then the color is freed from the
  707. overlay colormap.
  708. */
  709. static void free_color(Fl_Color i, int overlay = 0); // platform dependent
  710. // fonts:
  711. static const char* get_font(Fl_Font);
  712. /**
  713. Get a human-readable string describing the family of this face. This
  714. is useful if you are presenting a choice to the user. There is no
  715. guarantee that each face has a different name. The return value points
  716. to a static buffer that is overwritten each call.
  717. The integer pointed to by \p attributes (if the pointer is not
  718. zero) is set to zero, FL_BOLD or FL_ITALIC or
  719. FL_BOLD | FL_ITALIC. To locate a "family" of fonts, search
  720. forward and back for a set with non-zero attributes, these faces along
  721. with the face with a zero attribute before them constitute a family.
  722. */
  723. static const char* get_font_name(Fl_Font, int* attributes = 0);
  724. /**
  725. Return an array of sizes in \p sizep. The return value is the
  726. length of this array. The sizes are sorted from smallest to largest
  727. and indicate what sizes can be given to fl_font() that will
  728. be matched exactly (fl_font() will pick the closest size for
  729. other sizes). A zero in the first location of the array indicates a
  730. scalable font, where any size works, although the array may list sizes
  731. that work "better" than others. Warning: the returned array
  732. points at a static buffer that is overwritten each call. Under X this
  733. will open the display.
  734. */
  735. static int get_font_sizes(Fl_Font, int*& sizep);
  736. static void set_font(Fl_Font, const char*);
  737. static void set_font(Fl_Font, Fl_Font);
  738. /**
  739. FLTK will open the display, and add every fonts on the server to the
  740. face table. It will attempt to put "families" of faces together, so
  741. that the normal one is first, followed by bold, italic, and bold
  742. italic.
  743. The optional argument is a string to describe the set of fonts to
  744. add. Passing NULL will select only fonts that have the
  745. ISO8859-1 character set (and are thus usable by normal text). Passing
  746. "-*" will select all fonts with any encoding as long as they have
  747. normal X font names with dashes in them. Passing "*" will list every
  748. font that exists (on X this may produce some strange output). Other
  749. values may be useful but are system dependent. With WIN32 NULL
  750. selects fonts with ISO8859-1 encoding and non-NULL selects
  751. all fonts.
  752. The return value is how many faces are in the table after this is done.
  753. */
  754. static Fl_Font set_fonts(const char* = 0); // platform dependent
  755. /** @} */
  756. /** \defgroup fl_drawings Drawing functions
  757. FLTK global graphics and GUI drawing functions.
  758. These functions are declared in <FL/fl_draw.H>,
  759. and in <FL/x.H> for offscreen buffer-related ones.
  760. @{ */
  761. // <Hack to re-order the 'Drawing functions' group>
  762. /** @} */
  763. // labeltypes:
  764. static void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*);
  765. /** Sets the functions to call to draw and measure a specific labeltype. */
  766. static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined ?
  767. // boxtypes:
  768. static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype);
  769. static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar);
  770. static void set_boxtype(Fl_Boxtype, Fl_Boxtype from);
  771. static int box_dx(Fl_Boxtype);
  772. static int box_dy(Fl_Boxtype);
  773. static int box_dw(Fl_Boxtype);
  774. static int box_dh(Fl_Boxtype);
  775. static int draw_box_active();
  776. // back compatibility:
  777. /** \addtogroup fl_windows
  778. @{ */
  779. /** For back compatibility, sets the void Fl::fatal handler callback */
  780. static void set_abort(Fl_Abort_Handler f) {fatal = f;}
  781. static void (*atclose)(Fl_Window*,void*);
  782. static void default_atclose(Fl_Window*,void*);
  783. /** For back compatibility, sets the Fl::atclose handler callback. You
  784. can now simply change the callback for the window instead.
  785. \see Fl_Window::callback(Fl_Callback*) */
  786. static void set_atclose(Fl_Atclose_Handler f) {atclose = f;}
  787. /** @} */
  788. /** \addtogroup fl_events
  789. @{ */
  790. /** Returns non-zero if the Shift key is pressed. */
  791. static int event_shift() {return e_state&FL_SHIFT;}
  792. /** Returns non-zero if the Control key is pressed. */
  793. static int event_ctrl() {return e_state&FL_CTRL;}
  794. /** Returns non-zero if the FL_COMMAND key is pressed, either FL_CTRL or on OSX FL_META. */
  795. static int event_command() {return e_state&FL_COMMAND;}
  796. /** Returns non-zero if the Alt key is pressed. */
  797. static int event_alt() {return e_state&FL_ALT;}
  798. /**
  799. Returns the mouse buttons state bits; if non-zero, then at least one
  800. button is pressed now. This function returns the button state at the
  801. time of the event. During an FL_RELEASE event, the state
  802. of the released button will be 0. To find out, which button
  803. caused an FL_RELEASE event, you can use Fl::event_button() instead.
  804. \return a bit mask value like { [FL_BUTTON1] | [FL_BUTTON2] | [FL_BUTTON3] }
  805. */
  806. static int event_buttons() {return e_state&0x7f000000;}
  807. /**
  808. Returns non-zero if mouse button 1 is currently held down.
  809. For more details, see Fl::event_buttons().
  810. */
  811. static int event_button1() {return e_state&FL_BUTTON1;}
  812. /**
  813. Returns non-zero if button 2 is currently held down.
  814. For more details, see Fl::event_buttons().
  815. */
  816. static int event_button2() {return e_state&FL_BUTTON2;}
  817. /**
  818. Returns non-zero if button 3 is currently held down.
  819. For more details, see Fl::event_buttons().
  820. */
  821. static int event_button3() {return e_state&FL_BUTTON3;}
  822. /** @} */
  823. /**
  824. Sets an idle callback.
  825. \deprecated This method is obsolete - use the add_idle() method instead.
  826. */
  827. static void set_idle(Fl_Old_Idle_Handler cb) {idle = cb;}
  828. /** See grab(Fl_Window*) */
  829. static void grab(Fl_Window& win) {grab(&win);}
  830. /** Releases the current grabbed window, equals grab(0).
  831. \deprecated Use Fl::grab(0) instead.
  832. \see grab(Fl_Window*) */
  833. static void release() {grab(0);}
  834. // Visible focus methods...
  835. /**
  836. Gets or sets the visible keyboard focus on buttons and other
  837. non-text widgets. The default mode is to enable keyboard focus
  838. for all widgets.
  839. */
  840. static void visible_focus(int v) { option(OPTION_VISIBLE_FOCUS, (v!=0)); }
  841. /**
  842. Gets or sets the visible keyboard focus on buttons and other
  843. non-text widgets. The default mode is to enable keyboard focus
  844. for all widgets.
  845. */
  846. static int visible_focus() { return option(OPTION_VISIBLE_FOCUS); }
  847. // Drag-n-drop text operation methods...
  848. /**
  849. Gets or sets whether drag and drop text operations are supported.
  850. This specifically affects whether selected text can
  851. be dragged from text fields or dragged within a text field as a
  852. cut/paste shortcut.
  853. */
  854. static void dnd_text_ops(int v) { option(OPTION_DND_TEXT, (v!=0)); }
  855. /**
  856. Gets or sets whether drag and drop text operations are
  857. supported. This specifically affects whether selected text can
  858. be dragged from text fields or dragged within a text field as a
  859. cut/paste shortcut.
  860. */
  861. static int dnd_text_ops() { return option(OPTION_DND_TEXT); }
  862. /** \defgroup fl_multithread Multithreading support functions
  863. fl multithreading support functions declared in <FL/Fl.H>
  864. @{ */
  865. // Multithreading support:
  866. static int lock();
  867. static void unlock();
  868. static void awake(void* message = 0);
  869. /** See void awake(void* message=0). */
  870. static int awake(Fl_Awake_Handler cb, void* message = 0);
  871. /**
  872. The thread_message() method returns the last message
  873. that was sent from a child by the awake() method.
  874. See also: \ref advanced_multithreading
  875. */
  876. static void* thread_message(); // platform dependent
  877. /** @} */
  878. /** \defgroup fl_del_widget Safe widget deletion support functions
  879. These functions, declared in <FL/Fl.H>, support deletion of widgets inside callbacks.
  880. Fl::delete_widget() should be called when deleting widgets
  881. or complete widget trees (Fl_Group, Fl_Window, ...) inside
  882. callbacks.
  883. The other functions are intended for internal use. The preferred
  884. way to use them is by using the helper class Fl_Widget_Tracker.
  885. The following is to show how it works ...
  886. There are three groups of related methods:
  887. -# scheduled widget deletion
  888. - Fl::delete_widget() schedules widgets for deletion
  889. - Fl::do_widget_deletion() deletes all scheduled widgets
  890. -# widget watch list ("smart pointers")
  891. - Fl::watch_widget_pointer() adds a widget pointer to the watch list
  892. - Fl::release_widget_pointer() removes a widget pointer from the watch list
  893. - Fl::clear_widget_pointer() clears a widget pointer \e in the watch list
  894. -# the class Fl_Widget_Tracker:
  895. - the constructor calls Fl::watch_widget_pointer()
  896. - the destructor calls Fl::release_widget_pointer()
  897. - the access methods can be used to test, if a widget has been deleted
  898. \see Fl_Widget_Tracker.
  899. @{ */
  900. // Widget deletion:
  901. static void delete_widget(Fl_Widget *w);
  902. static void do_widget_deletion();
  903. static void watch_widget_pointer(Fl_Widget *&w);
  904. static void release_widget_pointer(Fl_Widget *&w);
  905. static void clear_widget_pointer(Fl_Widget const *w);
  906. /** @} */
  907. /** \defgroup group_cairo Cairo support functions and classes
  908. @{
  909. */
  910. public:
  911. static cairo_surface_t * cairo_create_surface ( Window xid, int W, int H );
  912. // Cairo support API
  913. static cairo_t * cairo_make_current( cairo_t *cc );
  914. /** when FLTK_HAVE_CAIRO is defined and cairo_autolink_context() is true,
  915. any current window dc is linked to a current context.
  916. This is not the default, because it may not be necessary
  917. to add cairo support to all fltk supported windows.
  918. When you wish to associate a cairo context in this mode,
  919. you need to call explicitly in your draw() overridden method,
  920. FL::cairo_make_current(Fl_Window*). This will create a cairo context
  921. but only for this Window.
  922. Still in custom cairo application it is possible to handle
  923. completely this process automatically by setting \p alink to true.
  924. In this last case, you don't need anymore to call Fl::cairo_make_current().
  925. You can use Fl::cairo_cc() to get the current cairo context anytime.
  926. \note Only available when configure has the --enable-cairo option
  927. */
  928. /** Gets the current cairo context linked with a fltk window. */
  929. static cairo_t * cairo_cc() { return fl_cairo_context; }
  930. /** Sets the current cairo context to \p c.
  931. Set \p own to true if you want fltk to handle this cc deletion.
  932. \note Only available when configure has the --enable-cairo option
  933. */
  934. // static void cairo_cc(cairo_t * c, bool own=false){ cairo_state_.cc(c, own); }
  935. private:
  936. public:
  937. /** @} */
  938. };
  939. /**
  940. This class should be used to control safe widget deletion.
  941. You can use an Fl_Widget_Tracker object to watch another widget, if you
  942. need to know, if this widget has been deleted during a callback.
  943. This simplifies the use of the "safe widget deletion" methods
  944. Fl::watch_widget_pointer() and Fl::release_widget_pointer() and
  945. makes their use more reliable, because the destructor autmatically
  946. releases the widget pointer from the widget watch list.
  947. It is intended to be used as an automatic (local/stack) variable,
  948. such that the automatic destructor is called when the object's
  949. scope is left. This ensures that no stale widget pointers are
  950. left in the widget watch list (see example below).
  951. You can also create Fl_Widget_Tracker objects with \c new, but then it
  952. is your responsibility to delete the object (and thus remove the
  953. widget pointer from the watch list) when it is not needed any more.
  954. Example:
  955. \code
  956. int MyClass::handle (int event) {
  957. if (...) {
  958. Fl_Widget_Tracker wp(this); // watch myself
  959. do_callback(); // call the callback
  960. if (wp.deleted()) return 1; // exit, if deleted
  961. // Now we are sure that the widget has not been deleted.
  962. // It is safe to access the widget
  963. clear_changed(); // access the widget
  964. }
  965. }
  966. \endcode
  967. */
  968. class FL_EXPORT Fl_Widget_Tracker {
  969. Fl_Widget* wp_;
  970. public:
  971. Fl_Widget_Tracker(Fl_Widget *wi);
  972. ~Fl_Widget_Tracker();
  973. /**
  974. Returns a pointer to the watched widget.
  975. This pointer is \c NULL, if the widget has been deleted.
  976. */
  977. Fl_Widget *widget() {return wp_;}
  978. /**
  979. Returns 1, if the watched widget has been deleted.
  980. This is a convenience method. You can also use something like
  981. <tt> if (wp.widget() == 0) // ...</tt>
  982. where \p wp is an Fl_Widget_Tracker object.
  983. */
  984. int deleted() {return wp_ == 0;}
  985. /**
  986. Returns 1, if the watched widget exists (has not been deleted).
  987. This is a convenience method. You can also use something like
  988. <tt> if (wp.widget() != 0) // ...</tt>
  989. where \p wp is an Fl_Widget_Tracker object.
  990. */
  991. int exists() {return wp_ != 0;}
  992. };
  993. /** \defgroup fl_unicode Unicode and UTF-8 functions
  994. fl global Unicode and UTF-8 handling functions declared in <FL/fl_utf8.h>
  995. @{ */
  996. /** @} */
  997. /* 0 default, 1 off 2 on */
  998. enum
  999. {
  1000. FL_ANTIALIAS_DEFAULT,
  1001. FL_ANTIALIAS_OFF,
  1002. FL_ANTIALIAS_ON
  1003. };
  1004. void fl_set_antialias ( int v );
  1005. #endif // !Fl_H
  1006. //
  1007. // End of "$Id: Fl.H 8724 2011-05-23 18:01:29Z manolo $".
  1008. //