FLTK 1.3.9
Loading...
Searching...
No Matches
Fl_Widget.H
Go to the documentation of this file.
1//
2// "$Id$"
3//
4// Widget header file for the Fast Light Tool Kit (FLTK).
5//
6// Copyright 1998-2015 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
22#ifndef Fl_Widget_H
23#define Fl_Widget_H
24
25#include "Enumerations.H"
26
30#ifdef _WIN64
31#if defined(__GNUC__) || defined(__clang__)
32#include <stdint.h>
33#else
34#include <stddef.h> // M$VC
35#endif
36typedef intptr_t fl_intptr_t;
37typedef uintptr_t fl_uintptr_t;
38#else
39typedef long fl_intptr_t;
40typedef unsigned long fl_uintptr_t;
41#endif
42
43class Fl_Widget;
44class Fl_Window;
45class Fl_Group;
46class Fl_Image;
47
49typedef void (Fl_Callback )(Fl_Widget*, void*);
51typedef Fl_Callback* Fl_Callback_p; // needed for BORLAND
53typedef void (Fl_Callback0)(Fl_Widget*);
55typedef void (Fl_Callback1)(Fl_Widget*, long);
56
65struct FL_EXPORT Fl_Label {
67 const char* value;
82
84 void draw(int,int,int,int, Fl_Align) const ;
85 void measure(int &w, int &h) const ;
86};
87
88
101class FL_EXPORT Fl_Widget {
102 friend class Fl_Group;
103
104 Fl_Group* parent_;
105 Fl_Callback* callback_;
106 void* user_data_;
107 int x_,y_,w_,h_;
108 Fl_Label label_;
109 unsigned int flags_;
110 Fl_Color color_;
111 Fl_Color color2_;
112 uchar type_;
113 uchar damage_;
114 uchar box_;
115 uchar when_;
116
117 const char *tooltip_;
118
120 Fl_Widget(const Fl_Widget &);
122 Fl_Widget& operator=(const Fl_Widget &);
123
124protected:
125
136 Fl_Widget(int x, int y, int w, int h, const char *label=0L);
137
139 void x(int v) {x_ = v;}
141 void y(int v) {y_ = v;}
143 void w(int v) {w_ = v;}
145 void h(int v) {h_ = v;}
147 unsigned int flags() const {return flags_;}
149 void set_flag(unsigned int c) {flags_ |= c;}
151 void clear_flag(unsigned int c) {flags_ &= ~c;}
155 enum {
156 INACTIVE = 1<<0,
157 INVISIBLE = 1<<1,
158 OUTPUT = 1<<2,
159 NOBORDER = 1<<3,
160 FORCE_POSITION = 1<<4,
161 NON_MODAL = 1<<5,
162 SHORTCUT_LABEL = 1<<6,
163 CHANGED = 1<<7,
164 OVERRIDE = 1<<8,
165 VISIBLE_FOCUS = 1<<9,
166 COPIED_LABEL = 1<<10,
167 CLIP_CHILDREN = 1<<11,
168 MENU_WINDOW = 1<<12,
169 TOOLTIP_WINDOW = 1<<13,
170 MODAL = 1<<14,
171 NO_OVERLAY = 1<<15,
172 GROUP_RELATIVE = 1<<16,
173 COPIED_TOOLTIP = 1<<17,
174 FULLSCREEN = 1<<18,
175 MAC_USE_ACCENTS_MENU = 1<<19,
176 // (space for more flags)
177 USERFLAG3 = 1<<29,
178 USERFLAG2 = 1<<30,
179 USERFLAG1 = 1<<31
180 };
181 void draw_box() const;
182 void draw_box(Fl_Boxtype t, Fl_Color c) const;
183 void draw_box(Fl_Boxtype t, int x,int y,int w,int h, Fl_Color c) const;
184 void draw_backdrop() const;
186 void draw_focus() {draw_focus(box(),x(),y(),w(),h());}
187 void draw_focus(Fl_Boxtype t, int x,int y,int w,int h) const;
188 void draw_label() const;
189 void draw_label(int, int, int, int) const;
190
191public:
192
201 virtual ~Fl_Widget();
202
219 virtual void draw() = 0;
220
237 virtual int handle(int event);
238
247 int is_label_copied() const {return ((flags_ & COPIED_LABEL) ? 1 : 0);}
248
254 Fl_Group* parent() const {return parent_;}
255
264 void parent(Fl_Group* p) {parent_ = p;} // for hacks only, use Fl_Group::add()
265
274 uchar type() const {return type_;}
275
279 void type(uchar t) {type_ = t;}
280
284 int x() const {return x_;}
285
289 int y() const {return y_;}
290
294 int w() const {return w_;}
295
299 int h() const {return h_;}
300
320 virtual void resize(int x, int y, int w, int h);
321
323 int damage_resize(int,int,int,int);
324
332 void position(int X,int Y) {resize(X,Y,w_,h_);}
333
341 void size(int W,int H) {resize(x_,y_,W,H);}
342
348 Fl_Align align() const {return label_.align_;}
349
357 void align(Fl_Align alignment) {label_.align_ = alignment;}
358
363 Fl_Boxtype box() const {return (Fl_Boxtype)box_;}
364
372 void box(Fl_Boxtype new_box) {box_ = new_box;}
373
378 Fl_Color color() const {return color_;}
379
390 void color(Fl_Color bg) {color_ = bg;}
391
396 Fl_Color selection_color() const {return color2_;}
397
406 void selection_color(Fl_Color a) {color2_ = a;}
407
415 void color(Fl_Color bg, Fl_Color sel) {color_=bg; color2_=sel;}
416
421 const char* label() const {return label_.value;}
422
433 void label(const char* text);
434
445 void copy_label(const char *new_label);
446
450 void label(Fl_Labeltype a, const char* b) {label_.type = a; label_.value = b;}
451
456 Fl_Labeltype labeltype() const {return (Fl_Labeltype)label_.type;}
457
466 void labeltype(Fl_Labeltype a) {label_.type = a;}
467
472 Fl_Color labelcolor() const {return label_.color;}
473
478 void labelcolor(Fl_Color c) {label_.color=c;}
479
487 Fl_Font labelfont() const {return label_.font;}
488
496 void labelfont(Fl_Font f) {label_.font=f;}
497
502 Fl_Fontsize labelsize() const {return label_.size;}
503
508 void labelsize(Fl_Fontsize pix) {label_.size=pix;}
509
514 Fl_Image* image() {return label_.image;}
515 const Fl_Image* image() const {return label_.image;}
516
521 void image(Fl_Image* img) {label_.image=img;}
522
527 void image(Fl_Image& img) {label_.image=&img;}
528
533 Fl_Image* deimage() {return label_.deimage;}
534 const Fl_Image* deimage() const {return label_.deimage;}
535
540 void deimage(Fl_Image* img) {label_.deimage=img;}
541
546 void deimage(Fl_Image& img) {label_.deimage=&img;}
547
552 const char *tooltip() const {return tooltip_;}
553
554 void tooltip(const char *text); // see Fl_Tooltip
555 void copy_tooltip(const char *text); // see Fl_Tooltip
556
561 Fl_Callback_p callback() const {return callback_;}
562
568 void callback(Fl_Callback* cb, void* p) {callback_=cb; user_data_=p;}
569
574 void callback(Fl_Callback* cb) {callback_=cb;}
575
580 void callback(Fl_Callback0*cb) {callback_=(Fl_Callback*)cb;}
581
587 void callback(Fl_Callback1*cb, long p=0) {callback_=(Fl_Callback*)cb; user_data_=(void*)(fl_intptr_t)p;}
588
593 void* user_data() const {return user_data_;}
594
599 void user_data(void* v) {user_data_ = v;}
600
605 long argument() const {return (long)(fl_intptr_t)user_data_;}
606
611 void argument(long v) {user_data_ = (void*)(fl_intptr_t)v;}
612
621 Fl_When when() const {return (Fl_When)when_;}
622
654 void when(uchar i) {when_ = i;}
655
660 unsigned int visible() const {return !(flags_&INVISIBLE);}
661
666 int visible_r() const;
667
685 virtual void show();
686
690 virtual void hide();
691
696 void set_visible() {flags_ &= ~INVISIBLE;}
697
702 void clear_visible() {flags_ |= INVISIBLE;}
703
708 unsigned int active() const {return !(flags_&INACTIVE);}
709
714 int active_r() const;
715
721 void activate();
722
737 void deactivate();
738
747 unsigned int output() const {return (flags_&OUTPUT);}
748
752 void set_output() {flags_ |= OUTPUT;}
753
757 void clear_output() {flags_ &= ~OUTPUT;}
758
764 unsigned int takesevents() const {return !(flags_&(INACTIVE|INVISIBLE|OUTPUT));}
765
781 unsigned int changed() const {return flags_&CHANGED;}
782
786 void set_changed() {flags_ |= CHANGED;}
787
791 void clear_changed() {flags_ &= ~CHANGED;}
792
797 void clear_active() {flags_ |= INACTIVE;}
798
803 void set_active() {flags_ &= ~INACTIVE;}
804
812 int take_focus();
813
820 void set_visible_focus() { flags_ |= VISIBLE_FOCUS; }
821
826 void clear_visible_focus() { flags_ &= ~VISIBLE_FOCUS; }
827
832 void visible_focus(int v) { if (v) set_visible_focus(); else clear_visible_focus(); }
833
838 unsigned int visible_focus() { return flags_ & VISIBLE_FOCUS; }
839
855 static void default_callback(Fl_Widget *cb, void *d);
856
861 void do_callback() {do_callback(this,user_data_);}
862
869 void do_callback(Fl_Widget* o,long arg) {do_callback(o,(void*)(fl_intptr_t)arg);}
870
871 // Causes a widget to invoke its callback function with arbitrary arguments.
872 // Documentation and implementation in Fl_Widget.cxx
873 void do_callback(Fl_Widget* o,void* arg=0);
874
875 /* Internal use only. */
876 int test_shortcut();
877 /* Internal use only. */
878 static unsigned int label_shortcut(const char *t);
879 /* Internal use only. */
880 static int test_shortcut(const char*, const bool require_alt = false);
881 /* Internal use only. */
882 void _set_fullscreen() {flags_ |= FULLSCREEN;}
883 void _clear_fullscreen() {flags_ &= ~FULLSCREEN;}
884
890 int contains(const Fl_Widget *w) const ;
891
898 int inside(const Fl_Widget* wgt) const {return wgt ? wgt->contains(this) : 0;}
899
903 void redraw();
904
909 void redraw_label();
910
917 uchar damage() const {return damage_;}
918
931 void clear_damage(uchar c = 0) {damage_ = c;}
932
938 void damage(uchar c);
939
946 void damage(uchar c, int x, int y, int w, int h);
947
948 void draw_label(int, int, int, int, Fl_Align) const;
949
957 void measure_label(int& ww, int& hh) const {label_.measure(ww, hh);}
958
959 Fl_Window* window() const ;
960 Fl_Window* top_window() const;
961 Fl_Window* top_window_offset(int& xoff, int& yoff) const;
962
986 virtual Fl_Group* as_group() {return 0;}
987
1000 virtual Fl_Window* as_window() {return 0;}
1001
1012 virtual class Fl_Gl_Window* as_gl_window() {return 0;}
1013
1016 int use_accents_menu() { return flags() & MAC_USE_ACCENTS_MENU; }
1017
1021 Fl_Color color2() const {return (Fl_Color)color2_;}
1022
1026 void color2(unsigned a) {color2_ = a;}
1027};
1028
1034#define FL_RESERVED_TYPE 100
1035
1036#endif
1037
1038//
1039// End of "$Id$".
1040//
This file contains type definitions and general enumerations.
int Fl_Font
A font number is an index into the internal font table.
Definition Enumerations.H:875
unsigned Fl_Align
FLTK type for alignment control.
Definition Enumerations.H:826
unsigned int Fl_Color
An FLTK color value; see also Colors
Definition Enumerations.H:932
Fl_Labeltype
The labeltype() method sets the type of the label.
Definition Enumerations.H:761
int Fl_Fontsize
Size of a font in pixels.
Definition Enumerations.H:904
Fl_When
These constants determine when a callback is performed.
Definition Enumerations.H:437
Fl_Boxtype
Definition Enumerations.H:601
void() Fl_Callback1(Fl_Widget *, long)
Callback type definition passing the widget and a long data value.
Definition Fl_Widget.H:55
void() Fl_Callback(Fl_Widget *, void *)
Default callback type definition for all fltk widgets (by far the most used)
Definition Fl_Widget.H:49
long fl_intptr_t
Definition Fl_Widget.H:39
void() Fl_Callback0(Fl_Widget *)
One parameter callback type definition passing only the widget.
Definition Fl_Widget.H:53
Fl_Callback * Fl_Callback_p
Default callback type pointer definition for all fltk widgets.
Definition Fl_Widget.H:51
The Fl_Gl_Window widget sets things up so OpenGL works.
Definition Fl_Gl_Window.H:56
The Fl_Group class is the FLTK container widget.
Definition Fl_Group.H:41
Base class for image caching and drawing.
Definition Fl_Image.H:55
Fl_Widget is the base class for all widgets in FLTK.
Definition Fl_Widget.H:101
Fl_Color labelcolor() const
Gets the label color.
Definition Fl_Widget.H:472
virtual class Fl_Gl_Window * as_gl_window()
Returns an Fl_Gl_Window pointer if this widget is an Fl_Gl_Window.
Definition Fl_Widget.H:1012
Fl_Font labelfont() const
Gets the font to use.
Definition Fl_Widget.H:487
Fl_Color color() const
Gets the background color of the widget.
Definition Fl_Widget.H:378
void clear_visible()
Hides the widget.
Definition Fl_Widget.H:702
unsigned int visible_focus()
Checks whether this widget has a visible focus.
Definition Fl_Widget.H:838
virtual void draw()=0
Draws the widget.
long argument() const
Gets the current user data (long) argument that is passed to the callback function.
Definition Fl_Widget.H:605
void user_data(void *v)
Sets the user data for this widget.
Definition Fl_Widget.H:599
void image(Fl_Image *img)
Sets the image to use as part of the widget label.
Definition Fl_Widget.H:521
int inside(const Fl_Widget *wgt) const
Checks if this widget is a child of wgt.
Definition Fl_Widget.H:898
int contains(const Fl_Widget *w) const
Checks if w is a child of this widget.
Definition Fl_Widget.cxx:303
void callback(Fl_Callback *cb)
Sets the current callback function for the widget.
Definition Fl_Widget.H:574
void deimage(Fl_Image *img)
Sets the image to use as part of the widget label.
Definition Fl_Widget.H:540
void do_callback()
Calls the widget callback.
Definition Fl_Widget.H:861
Fl_Image * deimage()
Gets the image that is used as part of the widget label.
Definition Fl_Widget.H:533
void argument(long v)
Sets the current user data (long) argument that is passed to the callback function.
Definition Fl_Widget.H:611
void clear_output()
Sets a widget to accept input.
Definition Fl_Widget.H:757
int is_label_copied() const
Returns whether the current label was assigned with copy_label().
Definition Fl_Widget.H:247
void box(Fl_Boxtype new_box)
Sets the box type for the widget.
Definition Fl_Widget.H:372
const char * label() const
Gets the current label text.
Definition Fl_Widget.H:421
int y() const
Gets the widget position in its window.
Definition Fl_Widget.H:289
void clear_visible_focus()
Disables keyboard focus navigation with this widget.
Definition Fl_Widget.H:826
int h() const
Gets the widget height.
Definition Fl_Widget.H:299
void color(Fl_Color bg, Fl_Color sel)
Sets the background and selection color of the widget.
Definition Fl_Widget.H:415
unsigned int flags() const
Gets the widget flags mask.
Definition Fl_Widget.H:147
void draw_focus()
draws a focus rectangle around the widget
Definition Fl_Widget.H:186
void visible_focus(int v)
Modifies keyboard focus navigation.
Definition Fl_Widget.H:832
Fl_Align align() const
Gets the label alignment.
Definition Fl_Widget.H:348
void parent(Fl_Group *p)
Internal use only - "for hacks only".
Definition Fl_Widget.H:264
virtual Fl_Group * as_group()
Returns an Fl_Group pointer if this widget is an Fl_Group.
Definition Fl_Widget.H:986
void set_flag(unsigned int c)
Sets a flag in the flags mask.
Definition Fl_Widget.H:149
void deimage(Fl_Image &img)
Sets the image to use as part of the widget label.
Definition Fl_Widget.H:546
const char * tooltip() const
Gets the current tooltip text.
Definition Fl_Widget.H:552
void color(Fl_Color bg)
Sets the background color of the widget.
Definition Fl_Widget.H:390
void align(Fl_Align alignment)
Sets the label alignment.
Definition Fl_Widget.H:357
void set_changed()
Marks the value of the widget as changed.
Definition Fl_Widget.H:786
void set_visible()
Makes the widget visible.
Definition Fl_Widget.H:696
void do_callback(Fl_Widget *o, long arg)
Calls the widget callback.
Definition Fl_Widget.H:869
void measure_label(int &ww, int &hh) const
Sets width ww and height hh accordingly with the label size.
Definition Fl_Widget.H:957
void callback(Fl_Callback1 *cb, long p=0)
Sets the current callback function for the widget.
Definition Fl_Widget.H:587
void clear_active()
Marks the widget as inactive without sending events or changing focus.
Definition Fl_Widget.H:797
void labeltype(Fl_Labeltype a)
Sets the label type.
Definition Fl_Widget.H:466
void set_output()
Sets a widget to output only.
Definition Fl_Widget.H:752
void * user_data() const
Gets the user data for this widget.
Definition Fl_Widget.H:593
void labelsize(Fl_Fontsize pix)
Sets the font size in pixels.
Definition Fl_Widget.H:508
int w() const
Gets the widget width.
Definition Fl_Widget.H:294
Fl_Boxtype box() const
Gets the box type of the widget.
Definition Fl_Widget.H:363
Fl_Fontsize labelsize() const
Gets the font size in pixels.
Definition Fl_Widget.H:502
Fl_Color selection_color() const
Gets the selection color.
Definition Fl_Widget.H:396
void label(Fl_Labeltype a, const char *b)
Shortcut to set the label text and type in one call.
Definition Fl_Widget.H:450
void labelcolor(Fl_Color c)
Sets the label color.
Definition Fl_Widget.H:478
virtual Fl_Window * as_window()
Returns an Fl_Window pointer if this widget is an Fl_Window.
Definition Fl_Widget.H:1000
void callback(Fl_Callback0 *cb)
Sets the current callback function for the widget.
Definition Fl_Widget.H:580
void selection_color(Fl_Color a)
Sets the selection color.
Definition Fl_Widget.H:406
void clear_changed()
Marks the value of the widget as unchanged.
Definition Fl_Widget.H:791
Fl_Labeltype labeltype() const
Gets the label type.
Definition Fl_Widget.H:456
void x(int v)
Internal use only.
Definition Fl_Widget.H:139
unsigned int visible() const
Returns whether a widget is visible.
Definition Fl_Widget.H:660
unsigned int output() const
Returns if a widget is used for output only.
Definition Fl_Widget.H:747
Fl_Callback_p callback() const
Gets the current callback function for the widget.
Definition Fl_Widget.H:561
void position(int X, int Y)
Repositions the window or widget.
Definition Fl_Widget.H:332
void when(uchar i)
Sets the flags used to decide when a callback is called.
Definition Fl_Widget.H:654
Fl_Group * parent() const
Returns a pointer to the parent widget.
Definition Fl_Widget.H:254
void set_visible_focus()
Enables keyboard focus navigation with this widget.
Definition Fl_Widget.H:820
void type(uchar t)
Sets the widget type.
Definition Fl_Widget.H:279
Fl_Color color2() const
For back compatibility only.
Definition Fl_Widget.H:1021
Fl_Image * image()
Gets the image that is used as part of the widget label.
Definition Fl_Widget.H:514
Fl_When when() const
Returns the conditions under which the callback is called.
Definition Fl_Widget.H:621
void w(int v)
Internal use only.
Definition Fl_Widget.H:143
void callback(Fl_Callback *cb, void *p)
Sets the current callback function for the widget.
Definition Fl_Widget.H:568
uchar damage() const
Returns non-zero if draw() needs to be called.
Definition Fl_Widget.H:917
void labelfont(Fl_Font f)
Sets the font to use.
Definition Fl_Widget.H:496
uchar type() const
Gets the widget type.
Definition Fl_Widget.H:274
void set_active()
Marks the widget as active without sending events or changing focus.
Definition Fl_Widget.H:803
unsigned int active() const
Returns whether the widget is active.
Definition Fl_Widget.H:708
void size(int W, int H)
Changes the size of the widget.
Definition Fl_Widget.H:341
unsigned int takesevents() const
Returns if the widget is able to take events.
Definition Fl_Widget.H:764
void color2(unsigned a)
For back compatibility only.
Definition Fl_Widget.H:1026
void y(int v)
Internal use only.
Definition Fl_Widget.H:141
void clear_flag(unsigned int c)
Clears a flag in the flags mask.
Definition Fl_Widget.H:151
void h(int v)
Internal use only.
Definition Fl_Widget.H:145
int x() const
Gets the widget position in its window.
Definition Fl_Widget.H:284
int use_accents_menu()
Returns non zero if MAC_USE_ACCENTS_MENU flag is set, 0 otherwise.
Definition Fl_Widget.H:1016
unsigned int changed() const
Checks if the widget value changed since the last callback.
Definition Fl_Widget.H:781
void clear_damage(uchar c=0)
Clears or sets the damage flags.
Definition Fl_Widget.H:931
void image(Fl_Image &img)
Sets the image to use as part of the widget label.
Definition Fl_Widget.H:527
This widget produces an actual window.
Definition Fl_Window.H:57
unsigned char uchar
unsigned char
Definition fl_types.h:30
This struct stores all information for a text or mixed graphics label.
Definition Fl_Widget.H:65
uchar type
type of label.
Definition Fl_Widget.H:81
Fl_Image * deimage
optional image for a deactivated label
Definition Fl_Widget.H:71
void measure(int &w, int &h) const
Measures the size of the label.
Definition fl_labeltype.cxx:86
Fl_Fontsize size
size of label font
Definition Fl_Widget.H:75
const char * value
label text
Definition Fl_Widget.H:67
Fl_Align align_
alignment of label
Definition Fl_Widget.H:79
Fl_Color color
text color
Definition Fl_Widget.H:77
Fl_Image * image
optional image for an active label
Definition Fl_Widget.H:69
Fl_Font font
label font used in text
Definition Fl_Widget.H:73