Fl.H 58 KB

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