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