Fl.H 54 KB

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