Fl_Widget.H 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  1. //
  2. // "$Id: Fl_Widget.H 12345 2017-07-20 15:16:37Z AlbrechtS $"
  3. //
  4. // Widget 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_Widget, Fl_Label classes . */
  20. #ifndef Fl_Widget_H
  21. #define Fl_Widget_H
  22. #include "Enumerations.H"
  23. #include "Fl_Rectangle.H"
  24. class Fl_Widget;
  25. class Fl_Window;
  26. class Fl_Group;
  27. class Fl_Image;
  28. class Fl_Association_Type;
  29. /** Default callback type definition for all fltk widgets (by far the most used) */
  30. typedef void (Fl_Callback )(Fl_Widget*, void*);
  31. /** Default callback type pointer definition for all fltk widgets */
  32. typedef Fl_Callback* Fl_Callback_p; // needed for BORLAND
  33. /** One parameter callback type definition passing only the widget */
  34. typedef void (Fl_Callback0)(Fl_Widget*);
  35. /** Callback type definition passing the widget and a long data value */
  36. typedef void (Fl_Callback1)(Fl_Widget*, long);
  37. class Fl_AnyClass {};
  38. /** Default member callback type definition for all fltk widgets (by far the most used) */
  39. typedef void (Fl_AnyClass::*Fl_MCallback)(Fl_Widget*, void*);
  40. /** Default member callback type pointer definition for all fltk widgets */
  41. typedef Fl_MCallback* Fl_MCallback_p; // needed for BORLAND
  42. /** Zero parameter member callback type definition passing only the widget */
  43. typedef void (Fl_AnyClass::*Fl_MCallback0)();
  44. /** One parameter member callback type definition passing only the widget */
  45. typedef void (Fl_AnyClass::*Fl_MCallback1)(Fl_Widget*);
  46. /** Member callback type definition passing the widget and a long data value */
  47. typedef void (Fl_AnyClass::*Fl_MCallback2)(Fl_Widget*, long);
  48. /** Member callback type definition passing the widget and a long data value */
  49. typedef void (Fl_AnyClass::*Fl_MCallback3)(Fl_Widget*, double);
  50. #define MCALLBACK(wdg, mf) (wdg)->mcallback((Fl_AnyClass*)this, (Fl_MCallback)&mf)
  51. #define THISMBACK(wdg, mf) (wdg)->mcallback((Fl_AnyClass*)this, (Fl_MCallback)&THISCLASS::mf)
  52. /** This struct stores all information for a text or mixed graphics label.
  53. \todo There is an aspiration that the Fl_Label type will become a widget by itself.
  54. That way we will be avoiding a lot of code duplication by handling labels in
  55. a similar fashion to widgets containing text. We also provide an easy
  56. interface for very complex labels, containing html or vector graphics.
  57. However, this re-factoring is not in place in this release.
  58. */
  59. class FL_EXPORT Fl_Label {
  60. public:
  61. /** label text */
  62. const char* value;
  63. /** optional image for an active label */
  64. Fl_Image* image;
  65. /** optional image for a deactivated label */
  66. Fl_Image* deimage;
  67. /** label font used in text */
  68. Fl_Font font;
  69. /** size of label font */
  70. Fl_Fontsize size;
  71. /** text color */
  72. Fl_Color color;
  73. /** alignment of label */
  74. Fl_Align align_;
  75. /** type of label. \see Fl_Labeltype */
  76. uchar type;
  77. /** Draws the label aligned to the given box */
  78. void draw(int,int,int,int, Fl_Align) const ;
  79. void measure(int &w, int &h) const ;
  80. };
  81. //DAD Extensions
  82. struct st_cheap_rtti {
  83. const char *class_name;
  84. const st_cheap_rtti *(*cheap_rtti_info_func)(void);
  85. };
  86. #define DECLARE_CLASS_CHEAP_RTTI_1(a1class_name) DECLARE_CLASS_CHEAP_RTTI_00(a1class_name, 0)
  87. #define DECLARE_CLASS_CHEAP_RTTI_2(a2class_name, a2base_class) \
  88. DECLARE_CLASS_CHEAP_RTTI_00(a2class_name, &a2base_class::cheap_rtti_info)
  89. //DECLARE_CLASS_CHEAP_RTTI_00(a2class_name, : public a2base_class, &a2base_class::cheap_rtti_info)
  90. #define DECLARE_CLASS_CHEAP_RTTI_00(aclass_name, abase_class) \
  91. public:\
  92. static const st_cheap_rtti *cheap_rtti_info() {\
  93. static st_cheap_rtti scr = {#aclass_name, abase_class};\
  94. return &scr;\
  95. };\
  96. virtual const st_cheap_rtti *classRTTI(void) {return aclass_name::cheap_rtti_info();}; \
  97. static const char *className(void) {return aclass_name::cheap_rtti_info()->class_name;}; \
  98. virtual const char *classId(void) {return aclass_name::className();}; \
  99. virtual int inherits_from(const st_cheap_rtti *aclass_id) {\
  100. const st_cheap_rtti *cri = aclass_name::cheap_rtti_info();\
  101. while(cri) {\
  102. if (aclass_id == cri) return 1;\
  103. if(cri->cheap_rtti_info_func) \
  104. cri = (*cri->cheap_rtti_info_func)();\
  105. else break; \
  106. }\
  107. return 0;\
  108. }\
  109. typedef aclass_name THISCLASS; \
  110. private:
  111. /** Fl_Widget is the base class for all widgets in FLTK.
  112. You can't create one of these because the constructor is not public.
  113. However you can subclass it.
  114. All "property" accessing methods, such as color(), parent(), or argument()
  115. are implemented as trivial inline functions and thus are as fast and small
  116. as accessing fields in a structure. Unless otherwise noted, the property
  117. setting methods such as color(n) or label(s) are also trivial inline
  118. functions, even if they change the widget's appearance. It is up to the
  119. user code to call redraw() after these.
  120. */
  121. class FL_EXPORT Fl_Widget : public Fl_Rectangle {
  122. friend class Fl_Group;
  123. Fl_Group* parent_;
  124. union {
  125. Fl_Callback* callback_;
  126. Fl_MCallback mcallback_;
  127. };
  128. void* user_data_;
  129. //int x_,y_,w_,h_; //Using Fl_Rectangle
  130. Fl_AnyClass *any_class_mcb_;
  131. Fl_Label label_;
  132. unsigned int flags_;
  133. Fl_Color color_;
  134. Fl_Color color2_;
  135. uchar type_;
  136. uchar damage_;
  137. uchar box_;
  138. uchar when_;
  139. const char *tooltip_;
  140. /** unimplemented copy ctor */
  141. Fl_Widget(const Fl_Widget &);
  142. /** unimplemented assignment operator */
  143. Fl_Widget& operator=(const Fl_Widget &);
  144. protected:
  145. /** Creates a widget at the given position and size.
  146. The Fl_Widget is a protected constructor, but all derived widgets have a
  147. matching public constructor. It takes a value for x(), y(), w(), h(), and
  148. an optional value for label().
  149. \param[in] x, y the position of the widget relative to the enclosing window
  150. \param[in] w, h size of the widget in pixels
  151. \param[in] label optional text for the widget label
  152. */
  153. Fl_Widget(int x, int y, int w, int h, const char *label=0L);
  154. #if 0 //Using Fl_Rectangle as base class
  155. /** Internal use only. Use position(int,int), size(int,int) or resize(int,int,int,int) instead. */
  156. void x(int v) {x_ = v;}
  157. /** Internal use only. Use position(int,int), size(int,int) or resize(int,int,int,int) instead. */
  158. void y(int v) {y_ = v;}
  159. /** Internal use only. Use position(int,int), size(int,int) or resize(int,int,int,int) instead. */
  160. void w(int v) {w_ = v;}
  161. /** Internal use only. Use position(int,int), size(int,int) or resize(int,int,int,int) instead. */
  162. void h(int v) {h_ = v;}
  163. #endif
  164. /** Gets the widget flags mask */
  165. unsigned int flags() const {return flags_;}
  166. /** Sets a flag in the flags mask */
  167. void set_flag(unsigned int c) {flags_ |= c;}
  168. /** Clears a flag in the flags mask */
  169. void clear_flag(unsigned int c) {flags_ &= ~c;}
  170. /** flags possible values enumeration.
  171. See activate(), output(), visible(), changed(), set_visible_focus()
  172. */
  173. public:
  174. enum {
  175. INACTIVE = 1<<0, ///< the widget can't receive focus, and is disabled but potentially visible
  176. INVISIBLE = 1<<1, ///< the widget is not drawn, but can receive a few special events
  177. OUTPUT = 1<<2, ///< for output only
  178. NOBORDER = 1<<3, ///< don't draw a decoration (Fl_Window)
  179. FORCE_POSITION = 1<<4, ///< don't let the window manager position the window (Fl_Window)
  180. NON_MODAL = 1<<5, ///< this is a hovering toolbar window (Fl_Window)
  181. SHORTCUT_LABEL = 1<<6, ///< the label contains a shortcut we need to draw
  182. CHANGED = 1<<7, ///< the widget value changed
  183. OVERRIDE = 1<<8, ///< position window on top (Fl_Window)
  184. VISIBLE_FOCUS = 1<<9, ///< accepts keyboard focus navigation if the widget can have the focus
  185. COPIED_LABEL = 1<<10, ///< the widget label is internally copied, its destruction is handled by the widget
  186. CLIP_CHILDREN = 1<<11, ///< all drawing within this widget will be clipped (Fl_Group)
  187. MENU_WINDOW = 1<<12, ///< a temporary popup window, dismissed by clicking outside (Fl_Window)
  188. TOOLTIP_WINDOW = 1<<13, ///< a temporary popup, transparent to events, and dismissed easily (Fl_Window)
  189. MODAL = 1<<14, ///< a window blocking input to all other winows (Fl_Window)
  190. NO_OVERLAY = 1<<15, ///< window not using a hardware overlay plane (Fl_Menu_Window)
  191. GROUP_RELATIVE = 1<<16, ///< position this widget relative to the parent group, not to the window
  192. COPIED_TOOLTIP = 1<<17, ///< the widget tooltip is internally copied, its destruction is handled by the widget
  193. FULLSCREEN = 1<<18, ///< a fullscreen window (Fl_Window)
  194. MAC_USE_ACCENTS_MENU = 1<<19, ///< On the Mac OS platform, pressing and holding a key on the keyboard opens an accented-character menu window (Fl_Input_, Fl_Text_Editor)
  195. SELECT_ALL_ON_FOCUS = 1<<21, ///< when take focus select all text
  196. CHANGED2 = 1<<22, ///< the widget value changed and is not reseted by the callback call
  197. NUMERIC_RIGHT_TO_LEFT = 1 << 23, ///See bellow
  198. USE_NUMERIC_FORMAT = 1 << 24, ///Fl_Input and descendents used for numeric values with format
  199. ON_GROUP_ONLY_REMOVE = 1<<25, ///< Fl_Group should only remove this widget without apply free on it
  200. MY_MARK = 1 << 26,
  201. // (space for more flags)
  202. USERFLAG3 = 1<<29, ///< reserved for 3rd party extensions
  203. USERFLAG2 = 1<<30, ///< reserved for 3rd party extensions
  204. USERFLAG1 = 1<<31 ///< reserved for 3rd party extensions
  205. };
  206. protected:
  207. void draw_box() const;
  208. void draw_box(Fl_Boxtype t, Fl_Color c) const;
  209. void draw_box(Fl_Boxtype t, int x,int y,int w,int h, Fl_Color c) const;
  210. void draw_backdrop() const;
  211. /** draws a focus rectangle around the widget */
  212. void draw_focus() {draw_focus(box(),x(),y(),w(),h());}
  213. void draw_focus(Fl_Boxtype t, int x,int y,int w,int h) const;
  214. void draw_label() const;
  215. void draw_label(int, int, int, int) const;
  216. public:
  217. /** Destroys the widget.
  218. Destroying single widgets is not very common. You almost always want to
  219. destroy the parent group instead, which will destroy all of the child widgets
  220. and groups in that group.
  221. \since FLTK 1.3, the widget's destructor removes the widget from its parent
  222. group, if it is member of a group.
  223. */
  224. virtual ~Fl_Widget();
  225. /** Draws the widget.
  226. Never call this function directly. FLTK will schedule redrawing whenever
  227. needed. If your widget must be redrawn as soon as possible, call redraw()
  228. instead.
  229. Override this function to draw your own widgets.
  230. If you ever need to call another widget's draw method <I>from within your
  231. own draw() method</I>, e.g. for an embedded scrollbar, you can do it
  232. (because draw() is virtual) like this:
  233. \code
  234. Fl_Widget *s = &scroll; // scroll is an embedded Fl_Scrollbar
  235. s->draw(); // calls Fl_Scrollbar::draw()
  236. \endcode
  237. */
  238. virtual void draw() {}; //= 0;
  239. /** Handles the specified event.
  240. You normally don't call this method directly, but instead let FLTK do
  241. it when the user interacts with the widget.
  242. When implemented in a widget, this function must return 0 if the
  243. widget does not use the event or 1 otherwise.
  244. Most of the time, you want to call the inherited handle() method in
  245. your overridden method so that you don't short-circuit events that you
  246. don't handle. In this last case you should return the callee retval.
  247. \param[in] event the kind of event received
  248. \retval 0 if the event was not used or understood
  249. \retval 1 if the event was used and can be deleted
  250. \see Fl_Event
  251. */
  252. virtual int handle(int event);
  253. /** Returns a pointer to the root parent widget.
  254. Usually this is a Fl_Window.
  255. \retval NULL if the widget has no root parent
  256. */
  257. Fl_Group* parent_root() const;
  258. /** Returns whether the current label was assigned with copy_label().
  259. This can be useful for temporarily overwriting the widget's label
  260. and restoring it later.
  261. \retval 0 current label was assigned with label().
  262. \retval 1 current label was assigned with copy_label().
  263. */
  264. int is_label_copied() const {return ((flags_ & COPIED_LABEL) ? 1 : 0);}
  265. /** Returns a pointer to the parent widget.
  266. Usually this is a Fl_Group or Fl_Window.
  267. \retval NULL if the widget has no parent
  268. \see Fl_Group::add(Fl_Widget*)
  269. */
  270. Fl_Group* parent() const {return parent_;}
  271. /** Internal use only - "for hacks only".
  272. It is \em \b STRONGLY recommended not to use this method, because it
  273. short-circuits Fl_Group's normal widget adding and removing methods,
  274. if the widget is already a child widget of another Fl_Group.
  275. Use Fl_Group::add(Fl_Widget*) and/or Fl_Group::remove(Fl_Widget*) instead.
  276. */
  277. void parent(Fl_Group* p) {parent_ = p;} // for hacks only, use Fl_Group::add()
  278. /** Gets the widget type.
  279. Returns the widget type value, which is used for Forms compatibility
  280. and to simulate RTTI.
  281. \todo Explain "simulate RTTI" (currently only used to decide if a widget
  282. is a window, i.e. type()>=FL_WINDOW ?). Is type() really used in a way
  283. that ensures "Forms compatibility" ?
  284. */
  285. uchar type() const {return type_;}
  286. /** Sets the widget type.
  287. This is used for Forms compatibility.
  288. */
  289. void type(uchar t) {type_ = t;}
  290. #if 0 //Using Fl_Rectangle as base class
  291. /** Gets the widget position in its window.
  292. \return the x position relative to the window
  293. */
  294. int x() const {return x_;}
  295. /** Gets the widget position in its window.
  296. \return the y position relative to the window
  297. */
  298. int y() const {return y_;}
  299. /** Gets the widget width.
  300. \return the width of the widget in pixels.
  301. */
  302. int w() const {return w_;}
  303. /** Gets the widget height.
  304. \return the height of the widget in pixels.
  305. */
  306. int h() const {return h_;}
  307. #endif
  308. /**
  309. Returns the full rectangle occupied by a widget plus it's external label if any
  310. */
  311. void get_full_size(int &full_x, int &full_y, int &full_w, int &full_h);
  312. /** Changes the size or position of the widget.
  313. This is a virtual function so that the widget may implement its
  314. own handling of resizing. The default version does \e not
  315. call the redraw() method, but instead relies on the parent widget
  316. to do so because the parent may know a faster way to update the
  317. display, such as scrolling from the old position.
  318. Some window managers under X11 call resize() a lot more often
  319. than needed. Please verify that the position or size of a widget
  320. did actually change before doing any extensive calculations.
  321. position(X, Y) is a shortcut for resize(X, Y, w(), h()),
  322. and size(W, H) is a shortcut for resize(x(), y(), W, H).
  323. \param[in] x, y new position relative to the parent window
  324. \param[in] w, h new size
  325. \see position(int,int), size(int,int)
  326. */
  327. virtual void resize(int x, int y, int w, int h);
  328. /** Internal use only. */
  329. int damage_resize(int,int,int,int);
  330. /** Repositions the window or widget.
  331. position(X, Y) is a shortcut for resize(X, Y, w(), h()).
  332. \param[in] X, Y new position relative to the parent window
  333. \see resize(int,int,int,int), size(int,int)
  334. */
  335. void position(int X,int Y) {resize(X,Y,w_,h_);}
  336. /** Changes the size of the widget.
  337. size(W, H) is a shortcut for resize(x(), y(), W, H).
  338. \param[in] W, H new size
  339. \see position(int,int), resize(int,int,int,int)
  340. */
  341. void size(int W,int H) {resize(x_,y_,W,H);}
  342. /** Gets the label alignment.
  343. \return label alignment
  344. \see label(), align(Fl_Align), Fl_Align
  345. */
  346. Fl_Align align() const {return label_.align_;}
  347. /** Sets the label alignment.
  348. This controls how the label is displayed next to or inside the widget.
  349. The default value is FL_ALIGN_CENTER, which centers the label inside
  350. the widget.
  351. \param[in] alignment new label alignment
  352. \see align(), Fl_Align
  353. */
  354. void align(Fl_Align alignment) {label_.align_ = alignment;}
  355. /** Gets the box type of the widget.
  356. \return the current box type
  357. \see box(Fl_Boxtype), Fl_Boxtype
  358. */
  359. Fl_Boxtype box() const {return (Fl_Boxtype)box_;}
  360. /** Sets the box type for the widget.
  361. This identifies a routine that draws the background of the widget.
  362. See Fl_Boxtype for the available types. The default depends on the
  363. widget, but is usually FL_NO_BOX or FL_UP_BOX.
  364. \param[in] new_box the new box type
  365. \see box(), Fl_Boxtype
  366. */
  367. void box(Fl_Boxtype new_box) {box_ = new_box;}
  368. /** Gets the background color of the widget.
  369. \return current background color
  370. \see color(Fl_Color), color(Fl_Color, Fl_Color)
  371. */
  372. Fl_Color color() const {return color_;}
  373. /** Sets the background color of the widget.
  374. The color is passed to the box routine. The color is either an index into
  375. an internal table of RGB colors or an RGB color value generated using
  376. fl_rgb_color().
  377. The default for most widgets is FL_BACKGROUND_COLOR. Use Fl::set_color()
  378. to redefine colors in the color map.
  379. \param[in] bg background color
  380. \see color(), color(Fl_Color, Fl_Color), selection_color(Fl_Color)
  381. */
  382. void color(Fl_Color bg) {color_ = bg;}
  383. /** Gets the selection color.
  384. \return the current selection color
  385. \see selection_color(Fl_Color), color(Fl_Color, Fl_Color)
  386. */
  387. Fl_Color selection_color() const {return color2_;}
  388. /** Sets the selection color.
  389. The selection color is defined for Forms compatibility and is usually
  390. used to color the widget when it is selected, although some widgets
  391. use this color for other purposes. You can set both colors at once
  392. with color(Fl_Color bg, Fl_Color sel).
  393. \param[in] a the new selection color
  394. \see selection_color(), color(Fl_Color, Fl_Color)
  395. */
  396. void selection_color(Fl_Color a) {color2_ = a;}
  397. /** Sets the background and selection color of the widget.
  398. The two color form sets both the background and selection colors.
  399. \param[in] bg background color
  400. \param[in] sel selection color
  401. \see color(unsigned), selection_color(unsigned)
  402. */
  403. void color(Fl_Color bg, Fl_Color sel) {color_=bg; color2_=sel;}
  404. /** Gets the current label text.
  405. \return a pointer to the current label text
  406. \see label(const char *), copy_label(const char *)
  407. */
  408. const char* label() const {return label_.value;}
  409. /** Sets the current label pointer.
  410. The label is shown somewhere on or next to the widget. The passed pointer
  411. is stored unchanged in the widget (the string is \em not copied), so if
  412. you need to set the label to a formatted value, make sure the buffer is
  413. static, global, or allocated. The copy_label() method can be used
  414. to make a copy of the label string automatically.
  415. \param[in] text pointer to new label text
  416. \see copy_label()
  417. */
  418. void label(const char* text);
  419. /** Sets the current label.
  420. Unlike label(), this method allocates a copy of the label
  421. string instead of using the original string pointer.
  422. The internal copy will automatically be freed whenever you assign
  423. a new label or when the widget is destroyed.
  424. \param[in] new_label the new label text
  425. \see label()
  426. */
  427. void copy_label(const char *new_label);
  428. /** Shortcut to set the label text and type in one call.
  429. \see label(const char *), labeltype(Fl_Labeltype)
  430. */
  431. void label(Fl_Labeltype a, const char* b) {label_.type = a; label_.value = b;}
  432. /** Gets the label type.
  433. \return the current label type.
  434. \see Fl_Labeltype
  435. */
  436. Fl_Labeltype labeltype() const {return (Fl_Labeltype)label_.type;}
  437. /** Sets the label type.
  438. The label type identifies the function that draws the label of the widget.
  439. This is generally used for special effects such as embossing or for using
  440. the label() pointer as another form of data such as an icon. The value
  441. FL_NORMAL_LABEL prints the label as plain text.
  442. \param[in] a new label type
  443. \see Fl_Labeltype
  444. */
  445. void labeltype(Fl_Labeltype a) {label_.type = a;}
  446. /** Gets the label color.
  447. The default color is FL_FOREGROUND_COLOR.
  448. \return the current label color
  449. */
  450. Fl_Color labelcolor() const {return label_.color;}
  451. /** Sets the label color.
  452. The default color is FL_FOREGROUND_COLOR.
  453. \param[in] c the new label color
  454. */
  455. void labelcolor(Fl_Color c) {label_.color=c;}
  456. /** Gets the font to use.
  457. Fonts are identified by indexes into a table. The default value
  458. uses a Helvetica typeface (Arial for Microsoft&reg; Windows&reg;).
  459. The function Fl::set_font() can define new typefaces.
  460. \return current font used by the label
  461. \see Fl_Font
  462. */
  463. Fl_Font labelfont() const {return label_.font;}
  464. /** Sets the font to use.
  465. Fonts are identified by indexes into a table. The default value
  466. uses a Helvetica typeface (Arial for Microsoft&reg; Windows&reg;).
  467. The function Fl::set_font() can define new typefaces.
  468. \param[in] f the new font for the label
  469. \see Fl_Font
  470. */
  471. void labelfont(Fl_Font f) {label_.font=f;}
  472. /** Gets the font size in pixels.
  473. The default size is 14 pixels.
  474. \return the current font size
  475. */
  476. Fl_Fontsize labelsize() const {return label_.size;}
  477. /** Sets the font size in pixels.
  478. \param[in] pix the new font size
  479. \see Fl_Fontsize labelsize()
  480. */
  481. void labelsize(Fl_Fontsize pix) {label_.size=pix;}
  482. /** Gets the font of the text in derived
  483. classes like input field.
  484. \return the current Fl_Font index */
  485. virtual Fl_Font textfont() const {Fl_Font f = labelfont(); return f ? f : FL_HELVETICA;}
  486. /** Sets the font of the text in derived
  487. classes like input field.
  488. The text font defaults to \c FL_HELVETICA.
  489. \param [in] s the new text font */
  490. virtual void textfont(Fl_Font s) {}
  491. /** Gets the size of the text in derived
  492. classes like input field.
  493. \return the text height in pixels */
  494. virtual Fl_Fontsize textsize() const {Fl_Fontsize s = labelsize(); return s ? s : 10;}
  495. /** Sets the size of the text in derived
  496. classes like input field.
  497. The text height defaults to \c FL_NORMAL_SIZE.
  498. \param [in] s the new font height in pixel units */
  499. virtual void textsize(Fl_Fontsize s) {}
  500. /** Gets the image that is used as part of the widget label.
  501. This image is used when drawing the widget in the active state.
  502. \return the current image
  503. */
  504. Fl_Image* image() {return label_.image;}
  505. const Fl_Image* image() const {return label_.image;}
  506. /** Sets the image to use as part of the widget label.
  507. This image is used when drawing the widget in the active state.
  508. \param[in] img the new image for the label
  509. */
  510. void image(Fl_Image* img) {label_.image=img;}
  511. /** Sets the image to use as part of the widget label.
  512. This image is used when drawing the widget in the active state.
  513. \param[in] img the new image for the label
  514. */
  515. void image(Fl_Image& img) {label_.image=&img;}
  516. /** Gets the image that is used as part of the widget label.
  517. This image is used when drawing the widget in the inactive state.
  518. \return the current image for the deactivated widget
  519. */
  520. Fl_Image* deimage() {return label_.deimage;}
  521. const Fl_Image* deimage() const {return label_.deimage;}
  522. /** Sets the image to use as part of the widget label.
  523. This image is used when drawing the widget in the inactive state.
  524. \param[in] img the new image for the deactivated widget
  525. */
  526. void deimage(Fl_Image* img) {label_.deimage=img;}
  527. /** Sets the image to use as part of the widget label.
  528. This image is used when drawing the widget in the inactive state.
  529. \param[in] img the new image for the deactivated widget
  530. */
  531. void deimage(Fl_Image& img) {label_.deimage=&img;}
  532. /** Gets the current tooltip text.
  533. \return a pointer to the tooltip text or NULL
  534. \see tooltip(const char*), copy_tooltip(const char*)
  535. */
  536. const char *tooltip() const {return tooltip_;}
  537. void tooltip(const char *text); // see Fl_Tooltip
  538. void copy_tooltip(const char *text); // see Fl_Tooltip
  539. /** Gets the current callback function for the widget.
  540. Each widget has a single callback.
  541. \return current callback
  542. */
  543. Fl_Callback_p callback() const {return callback_;}
  544. /** Sets the current callback function for the widget.
  545. Each widget has a single callback.
  546. \param[in] cb new callback
  547. \param[in] p user data
  548. */
  549. void callback(Fl_Callback* cb, void* p) {callback_ = cb; user_data_ = p;}
  550. /** Sets the current callback function for the widget.
  551. Each widget has a single callback.
  552. \param[in] cb new callback
  553. */
  554. void callback(Fl_Callback* cb) {callback_ = cb;}
  555. /** Sets the current callback function for the widget.
  556. Each widget has a single callback.
  557. \param[in] cb new callback
  558. */
  559. void callback(Fl_Callback0* cb) {callback_ = (Fl_Callback*)cb;}
  560. /** Sets the current callback function for the widget.
  561. Each widget has a single callback.
  562. \param[in] cb new callback
  563. \param[in] p user data
  564. */
  565. void callback(Fl_Callback1* cb, long p = 0) {
  566. callback_ = (Fl_Callback*)cb;
  567. user_data_ = (void*)(fl_intptr_t)p;
  568. }
  569. /** Gets the user data for this widget.
  570. Gets the current user data (void *) argument that is passed to the callback function.
  571. \return user data as a pointer
  572. */
  573. void* user_data() const {return user_data_;}
  574. /** Sets the user data for this widget.
  575. Sets the new user data (void *) argument that is passed to the callback function.
  576. \param[in] v new user data
  577. */
  578. void user_data(void* v) {user_data_ = v;}
  579. /** Gets the current user data (long) argument that is passed to the callback function.
  580. \note On platforms with <tt>sizeof(long) \< sizeof(void*)</tt>, particularly
  581. on Windows 64-bit platforms, this method can truncate stored addresses
  582. \p (void*) to the size of a \p long value. Use with care and only
  583. if you are sure that the stored user_data value fits in a \p long
  584. value because it was stored with argument(long) or another method
  585. using only \p long values. You may want to use user_data() instead.
  586. \see user_data()
  587. \todo [Internal] The user_data value must be implemented using
  588. \p fl_intptr_t or similar to avoid 64-bit platform incompatibilities.
  589. */
  590. long argument() const {return (long)(fl_intptr_t)user_data_;}
  591. /** Sets the current user data (long) argument that is passed to the callback function.
  592. \see argument()
  593. */
  594. void argument(long v) {user_data_ = (void*)(fl_intptr_t)v;}
  595. /** Returns the conditions under which the callback is called.
  596. You can set the flags with when(uchar), the default value is
  597. FL_WHEN_RELEASE.
  598. \return set of flags
  599. \see when(uchar)
  600. */
  601. Fl_When when() const {return (Fl_When)when_;}
  602. /** Sets the flags used to decide when a callback is called.
  603. This controls when callbacks are done. The following values are useful,
  604. the default value is FL_WHEN_RELEASE:
  605. \li 0: The callback is not done, but changed() is turned on.
  606. \li FL_WHEN_CHANGED: The callback is done each time the text is
  607. changed by the user.
  608. \li FL_WHEN_RELEASE: The callback will be done when this widget loses
  609. the focus, including when the window is unmapped. This is a useful
  610. value for text fields in a panel where doing the callback on every
  611. change is wasteful. However the callback will also happen if the
  612. mouse is moved out of the window, which means it should not do
  613. anything visible (like pop up an error message).
  614. You might do better setting this to zero, and scanning all the
  615. items for changed() when the OK button on a panel is pressed.
  616. \li FL_WHEN_ENTER_KEY: If the user types the Enter key, the entire
  617. text is selected, and the callback is done if the text has changed.
  618. Normally the Enter key will navigate to the next field (or insert
  619. a newline for a Fl_Multiline_Input) - this changes the behavior.
  620. \li FL_WHEN_ENTER_KEY|FL_WHEN_NOT_CHANGED: The Enter key will do the
  621. callback even if the text has not changed. Useful for command fields.
  622. Fl_Widget::when() is a set of bitflags used by subclasses of
  623. Fl_Widget to decide when to do the callback.
  624. If the value is zero then the callback is never done. Other values
  625. are described in the individual widgets. This field is in the base
  626. class so that you can scan a panel and do_callback() on all the ones
  627. that don't do their own callbacks in response to an "OK" button.
  628. \param[in] i set of flags
  629. */
  630. void when(uchar i) {when_ = i;}
  631. /** Returns whether a widget is visible.
  632. \retval 0 if the widget is not drawn and hence invisible.
  633. \see show(), hide(), visible_r()
  634. */
  635. unsigned int visible() const {return !(flags_&INVISIBLE);}
  636. /** Returns whether a widget and all its parents are visible.
  637. \retval 0 if the widget or any of its parents are invisible.
  638. \see show(), hide(), visible()
  639. */
  640. int visible_r() const;
  641. /** Makes a widget visible.
  642. An invisible widget never gets redrawn and does not get keyboard
  643. or mouse events, but can receive a few other events like FL_SHOW.
  644. The visible() method returns true if the widget is set to be
  645. visible. The visible_r() method returns true if the widget and
  646. all of its parents are visible. A widget is only visible if
  647. visible() is true on it <I>and all of its parents</I>.
  648. Changing it will send FL_SHOW or FL_HIDE events to the widget.
  649. <I>Do not change it if the parent is not visible, as this
  650. will send false FL_SHOW or FL_HIDE events to the widget</I>.
  651. redraw() is called if necessary on this or the parent.
  652. \see hide(), visible(), visible_r()
  653. */
  654. virtual void show();
  655. /** Makes a widget invisible.
  656. \see show(), visible(), visible_r()
  657. */
  658. virtual void hide();
  659. /** Makes the widget visible.
  660. You must still redraw the parent widget to see a change in the
  661. window. Normally you want to use the show() method instead.
  662. */
  663. void set_visible() {flags_ &= ~INVISIBLE;}
  664. /** Hides the widget.
  665. You must still redraw the parent to see a change in the window.
  666. Normally you want to use the hide() method instead.
  667. */
  668. void clear_visible() {flags_ |= INVISIBLE;}
  669. /** Returns whether the widget is in full screen mode
  670. \retval non 0 if in full screen mode
  671. */
  672. unsigned int is_fullscreen() const {return (flags_ & FULLSCREEN);}
  673. /** Returns whether the widget is active.
  674. \retval 0 if the widget is inactive
  675. \see active_r(), activate(), deactivate()
  676. */
  677. unsigned int active() const {return !(flags_&INACTIVE);}
  678. /** Returns whether the widget and all of its parents are active.
  679. \retval 0 if this or any of the parent widgets are inactive
  680. \see active(), activate(), deactivate()
  681. */
  682. int active_r() const;
  683. /** Activates the widget.
  684. Changing this value will send FL_ACTIVATE to the widget if
  685. active_r() is true.
  686. \see active(), active_r(), deactivate()
  687. */
  688. void activate();
  689. /** Deactivates the widget.
  690. Inactive widgets will be drawn "grayed out", e.g. with less contrast
  691. than the active widget. Inactive widgets will not receive any keyboard
  692. or mouse button events. Other events (including FL_ENTER, FL_MOVE,
  693. FL_LEAVE, FL_SHORTCUT, and others) will still be sent. A widget is
  694. only active if active() is true on it <I>and all of its parents</I>.
  695. Changing this value will send FL_DEACTIVATE to the widget if
  696. active_r() is true.
  697. Currently you cannot deactivate Fl_Window widgets.
  698. \see activate(), active(), active_r()
  699. */
  700. void deactivate();
  701. /** Returns if a widget is used for output only.
  702. output() means the same as !active() except it does not change how the
  703. widget is drawn. The widget will not receive any events. This is useful
  704. for making scrollbars or buttons that work as displays rather than input
  705. devices.
  706. \retval 0 if the widget is used for input and output
  707. \see set_output(), clear_output()
  708. */
  709. unsigned int output() const {return (flags_&OUTPUT);}
  710. /** Sets a widget to output only.
  711. \see output(), clear_output()
  712. */
  713. void set_output() {flags_ |= OUTPUT;}
  714. /** Sets a widget to accept input.
  715. \see set_output(), output()
  716. */
  717. void clear_output() {flags_ &= ~OUTPUT;}
  718. /** Returns if the widget is able to take events.
  719. This is the same as (active() && !output() && visible())
  720. but is faster.
  721. \retval 0 if the widget takes no events
  722. */
  723. unsigned int takesevents() const {return !(flags_&(INACTIVE|INVISIBLE|OUTPUT));}
  724. /**
  725. Checks if the widget value changed since the last callback.
  726. "Changed" is a flag that is turned on when the user changes the value
  727. stored in the widget. This is only used by subclasses of Fl_Widget that
  728. store values, but is in the base class so it is easier to scan all the
  729. widgets in a panel and do_callback() on the changed ones in response
  730. to an "OK" button.
  731. Most widgets turn this flag off when they do the callback, and when
  732. the program sets the stored value.
  733. \note do_callback() turns this flag off after the callback.
  734. \retval 0 if the value did not change
  735. \see set_changed(), clear_changed()
  736. \see do_callback(Fl_Widget *widget, void *data)
  737. */
  738. unsigned int changed() const {return flags_&CHANGED;}
  739. unsigned int changed2() const {return flags_&CHANGED2;}
  740. /** Marks the value of the widget as changed.
  741. \see changed(), clear_changed()
  742. */
  743. void set_changed() {flags_ |= (CHANGED|CHANGED2);}
  744. void set_changed2() {flags_ |= CHANGED2;}
  745. /** Marks the value of the widget as unchanged.
  746. \see changed(), set_changed()
  747. */
  748. void clear_changed() {flags_ &= ~CHANGED;}
  749. void clear_changed2() {flags_ &= ~CHANGED2;}
  750. void clear_changed_all() {flags_ &= ~(CHANGED|CHANGED2);}
  751. /** Marks the widget as inactive without sending events or changing focus.
  752. This is mainly for specialized use, for normal cases you want deactivate().
  753. \see deactivate()
  754. */
  755. void clear_active() {flags_ |= INACTIVE;}
  756. /** Marks the widget as active without sending events or changing focus.
  757. This is mainly for specialized use, for normal cases you want activate().
  758. \see activate()
  759. */
  760. void set_active() {flags_ &= ~INACTIVE;}
  761. /** Gives the widget the keyboard focus.
  762. Tries to make this widget be the Fl::focus() widget, by first sending
  763. it an FL_FOCUS event, and if it returns non-zero, setting
  764. Fl::focus() to this widget. You should use this method to
  765. assign the focus to a widget.
  766. \return true if the widget accepted the focus.
  767. */
  768. int take_focus();
  769. int select_all_on_focus() {return flags_&SELECT_ALL_ON_FOCUS;}
  770. void select_all_on_focus(int bFlag) {
  771. if(bFlag) flags_|=SELECT_ALL_ON_FOCUS;
  772. else flags_ &= ~SELECT_ALL_ON_FOCUS;
  773. }
  774. void on_group_only_remove(int bFlag) {
  775. if(bFlag) flags_|=ON_GROUP_ONLY_REMOVE;
  776. else flags_ &= ~ON_GROUP_ONLY_REMOVE;
  777. }
  778. /** Enables keyboard focus navigation with this widget.
  779. Note, however, that this will not necessarily mean that the widget
  780. will accept focus, but for widgets that can accept focus, this method
  781. enables it if it has been disabled.
  782. \see visible_focus(), clear_visible_focus(), visible_focus(int)
  783. */
  784. void set_visible_focus() { flags_ |= VISIBLE_FOCUS; }
  785. /** Disables keyboard focus navigation with this widget.
  786. Normally, all widgets participate in keyboard focus navigation.
  787. \see set_visible_focus(), visible_focus(), visible_focus(int)
  788. */
  789. void clear_visible_focus() { flags_ &= ~VISIBLE_FOCUS; }
  790. /** Modifies keyboard focus navigation.
  791. \param[in] v set or clear visible focus
  792. \see set_visible_focus(), clear_visible_focus(), visible_focus()
  793. */
  794. void visible_focus(int v) { if (v) set_visible_focus(); else clear_visible_focus(); }
  795. /** Checks whether this widget has a visible focus.
  796. \retval 0 if this widget has no visible focus.
  797. \see visible_focus(int), set_visible_focus(), clear_visible_focus()
  798. */
  799. unsigned int visible_focus() const { return flags_ & VISIBLE_FOCUS; }
  800. /** The default callback for all widgets that don't set a callback.
  801. This callback function puts a pointer to the widget on the queue
  802. returned by Fl::readqueue(). This is the default for all widgets
  803. if you don't set a callback.
  804. You can avoid the overhead of this default handling if you set the
  805. callback to \p NULL explicitly.
  806. Relying on the default callback and reading the callback queue with
  807. Fl::readqueue() is not recommended. If you need a callback, you should
  808. set one with Fl_Widget::callback(Fl_Callback *cb, void *data)
  809. or one of its variants.
  810. \param[in] widget the Fl_Widget given to the callback
  811. \param[in] data user data associated with that callback
  812. \see callback(), Fl::readqueue()
  813. \see do_callback(Fl_Widget *widget, void *data)
  814. */
  815. static void default_callback(Fl_Widget *widget, void *data);
  816. /** Calls the widget callback function with default arguments.
  817. This is the same as calling
  818. \code
  819. do_callback(this, user_data());
  820. \endcode
  821. \see callback()
  822. \see do_callback(Fl_Widget *widget, void *data)
  823. */
  824. void do_callback() {do_callback(this, user_data_);}
  825. /** Calls the widget callback function with arbitrary arguments.
  826. \param[in] widget call the callback with \p widget as the first argument
  827. \param[in] arg call the callback with \p arg as the user data (second) argument
  828. \see callback()
  829. \see do_callback(Fl_Widget *widget, void *data)
  830. */
  831. void do_callback(Fl_Widget *widget, long arg) {
  832. do_callback(widget, (void*)(fl_intptr_t)arg);
  833. }
  834. // Causes a widget to invoke its callback function with arbitrary arguments.
  835. // Documentation and implementation in Fl_Widget.cxx
  836. virtual void do_callback(Fl_Widget *widget, void *arg = 0);
  837. /* Internal use only. */
  838. int test_shortcut();
  839. /* Internal use only. */
  840. static unsigned int label_shortcut(const char *t);
  841. /* Internal use only. */
  842. static int test_shortcut(const char*, const bool require_alt = false);
  843. /* Internal use only. */
  844. void _set_fullscreen() {flags_ |= FULLSCREEN;}
  845. void _clear_fullscreen() {flags_ &= ~FULLSCREEN;}
  846. /** Checks if w is a child of this widget.
  847. \param[in] w potential child widget
  848. \return Returns 1 if \p w is a child of this widget, or is
  849. equal to this widget. Returns 0 if \p w is NULL.
  850. */
  851. int contains(const Fl_Widget *w) const ;
  852. /** Checks if this widget is a child of \p wgt.
  853. Returns 1 if this widget is a child of \p wgt, or is
  854. equal to \p wgt. Returns 0 if \p wgt is NULL.
  855. \param[in] wgt the possible parent widget.
  856. \see contains()
  857. */
  858. int inside(const Fl_Widget *wgt) const {return wgt ? wgt->contains(this) : 0;}
  859. /** Schedules the drawing of the widget.
  860. Marks the widget as needing its draw() routine called.
  861. */
  862. void redraw();
  863. /** Schedules the drawing of the label.
  864. Marks the widget or the parent as needing a redraw for the label area
  865. of a widget.
  866. */
  867. void redraw_label();
  868. /** Returns non-zero if draw() needs to be called.
  869. The damage value is actually a bit field that the widget
  870. subclass can use to figure out what parts to draw.
  871. \return a bitmap of flags describing the kind of damage to the widget
  872. \see damage(uchar), clear_damage(uchar)
  873. */
  874. uchar damage() const {return damage_;}
  875. /** Clears or sets the damage flags.
  876. Damage flags are cleared when parts of the widget drawing is repaired.
  877. The optional argument \p c specifies the bits that <b>are set</b>
  878. after the call (default: 0) and \b not the bits that are cleared!
  879. \note Therefore it is possible to set damage bits with this method, but
  880. this should be avoided. Use damage(uchar) instead.
  881. \param[in] c new bitmask of damage flags (default: 0)
  882. \see damage(uchar), damage()
  883. */
  884. void clear_damage(uchar c = 0) {damage_ = c;}
  885. /** Sets the damage bits for the widget.
  886. Setting damage bits will schedule the widget for the next redraw.
  887. \param[in] c bitmask of flags to set
  888. \see damage(), clear_damage(uchar)
  889. */
  890. void damage(uchar c);
  891. /** Sets the damage bits for an area inside the widget.
  892. Setting damage bits will schedule the widget for the next redraw.
  893. \param[in] c bitmask of flags to set
  894. \param[in] x, y, w, h size of damaged area
  895. \see damage(), clear_damage(uchar)
  896. */
  897. void damage(uchar c, int x, int y, int w, int h);
  898. void draw_label(int, int, int, int, Fl_Align) const;
  899. /** Sets width ww and height hh accordingly with the label size.
  900. Labels with images will return w() and h() of the image.
  901. This calls fl_measure() internally. For more information about
  902. the arguments \p ww and \p hh and word wrapping
  903. \see fl_measure(const char*, int&, int&, int)
  904. */
  905. void measure_label(int& ww, int& hh) const {label_.measure(ww, hh);}
  906. Fl_Window* window() const ;
  907. Fl_Window* top_window() const;
  908. Fl_Window* top_window_offset(int& xoff, int& yoff) const;
  909. /** Returns an Fl_Group pointer if this widget is an Fl_Group.
  910. Use this method if you have a widget (pointer) and need to
  911. know whether this widget is derived from Fl_Group. If it returns
  912. non-NULL, then the widget in question is derived from Fl_Group,
  913. and you can use the returned pointer to access its children
  914. or other Fl_Group-specific methods.
  915. Example:
  916. \code
  917. void my_callback (Fl_Widget *w, void *) {
  918. Fl_Group *g = w->as_group();
  919. if (g)
  920. printf ("This group has %d children\n", g->children());
  921. else
  922. printf ("This widget is not a group!\n");
  923. }
  924. \endcode
  925. \retval NULL if this widget is not derived from Fl_Group.
  926. \note This method is provided to avoid dynamic_cast.
  927. \see Fl_Widget::as_window(), Fl_Widget::as_gl_window()
  928. */
  929. virtual Fl_Group* as_group() {return 0;}
  930. /** Returns an Fl_Window pointer if this widget is an Fl_Window.
  931. Use this method if you have a widget (pointer) and need to
  932. know whether this widget is derived from Fl_Window. If it returns
  933. non-NULL, then the widget in question is derived from Fl_Window,
  934. and you can use the returned pointer to access its children
  935. or other Fl_Window-specific methods.
  936. \retval NULL if this widget is not derived from Fl_Window.
  937. \note This method is provided to avoid dynamic_cast.
  938. \see Fl_Widget::as_group(), Fl_Widget::as_gl_window()
  939. */
  940. virtual Fl_Window* as_window() {return 0;}
  941. /** Returns an Fl_Gl_Window pointer if this widget is an Fl_Gl_Window.
  942. Use this method if you have a widget (pointer) and need to
  943. know whether this widget is derived from Fl_Gl_Window. If it returns
  944. non-NULL, then the widget in question is derived from Fl_Gl_Window.
  945. \retval NULL if this widget is not derived from Fl_Gl_Window.
  946. \note This method is provided to avoid dynamic_cast.
  947. \see Fl_Widget::as_group(), Fl_Widget::as_window()
  948. */
  949. virtual class Fl_Gl_Window* as_gl_window() {return 0;}
  950. /** Returns non zero if MAC_USE_ACCENTS_MENU flag is set, 0 otherwise.
  951. */
  952. int use_accents_menu() { return flags() & MAC_USE_ACCENTS_MENU; }
  953. /** For back compatibility only.
  954. \deprecated Use selection_color() instead.
  955. */
  956. Fl_Color color2() const {return (Fl_Color)color2_;}
  957. /** For back compatibility only.
  958. \deprecated Use selection_color(unsigned) instead.
  959. */
  960. void color2(unsigned a) {color2_ = a;}
  961. /** Set the associated data pointer for this widget.
  962. \param [in] at the data type of the association
  963. \param [in] data the actual pointer to set
  964. */
  965. void set_assoc(const Fl_Association_Type&, void* data) const;
  966. /** Get the data pointer for the given association type that is assigned to this widget.
  967. \param [in] at the data type of the association
  968. \retval pointer to the associated data or NULL if non is associated
  969. */
  970. void* get_assoc(const Fl_Association_Type&) const;
  971. /** Remove all associations of the given type.
  972. \param [in] at the data type of the association
  973. */
  974. void remove_assoc(const Fl_Association_Type&) const;
  975. /** class that holds a method for callbacks*/
  976. Fl_AnyClass *any_class_mcb() {return any_class_mcb_;};
  977. /** Gets the current class method callback function for the widget.
  978. Each widget has a single class method callback.
  979. \return current mcallback
  980. */
  981. Fl_MCallback mcallback() const {return mcallback_;}
  982. /** Sets the current class method callback function for the widget.
  983. Each widget has a single class method callback.
  984. \param[in] cb new class method callback
  985. \param[in] p user data
  986. */
  987. void mcallback(Fl_AnyClass *klass, Fl_MCallback cb, void* p) {
  988. any_class_mcb_ = klass;
  989. mcallback_=cb;
  990. user_data_=p;
  991. }
  992. /** Sets the current class method callback function for the widget.
  993. Each widget has a single callback.
  994. \param[in] cb new method callback
  995. */
  996. void mcallback(Fl_AnyClass *klass, Fl_MCallback cb) {
  997. any_class_mcb_ = klass;
  998. mcallback_=cb;
  999. }
  1000. /** Sets the current callback method function for the widget.
  1001. Each widget has a single method callback.
  1002. \param[in] cb new callback
  1003. */
  1004. void mcallback(Fl_AnyClass *klass, Fl_MCallback0 cb) {
  1005. any_class_mcb_ = klass;
  1006. mcallback_=(Fl_MCallback)cb;
  1007. }
  1008. /** Sets the current callback method function for the widget.
  1009. Each widget has a single method callback.
  1010. \param[in] cb new callback
  1011. */
  1012. void mcallback(Fl_AnyClass *klass, Fl_MCallback1 cb) {
  1013. any_class_mcb_ = klass;
  1014. mcallback_=(Fl_MCallback)cb;
  1015. }
  1016. /** Sets the current callback method function for the widget.
  1017. Each widget has a single method callback.
  1018. \param[in] cb new callback
  1019. \param[in] p user data
  1020. */
  1021. void mcallback(Fl_AnyClass *klass, Fl_MCallback2 cb, long p=0) {
  1022. any_class_mcb_ = klass;
  1023. mcallback_=(Fl_MCallback)cb;
  1024. user_data_=(void*)p;
  1025. }
  1026. /*! Fills the Rectangle pointed to by \a rect with the widget's
  1027. rectangle expressed in relative to parent coordinates.
  1028. */
  1029. void get_relative_rect( Fl_Rectangle &rect ) const;
  1030. /*Virtual function for any user purpose to extend FLTK*/
  1031. virtual void *user_callback(Fl_Widget *sender, int when, void *udata=0){return 0;}
  1032. //DAD Extensios
  1033. DECLARE_CLASS_CHEAP_RTTI_1(Fl_Widget)
  1034. };
  1035. /**
  1036. Reserved type numbers (necessary for my cheapo RTTI) start here.
  1037. Grep the header files for "RESERVED_TYPE" to find the next available
  1038. number.
  1039. */
  1040. #define FL_RESERVED_TYPE 100
  1041. #endif
  1042. //
  1043. // End of "$Id: Fl_Widget.H 12345 2017-07-20 15:16:37Z AlbrechtS $".
  1044. //