2 // "$Id: Fl_Widget.H,v 1.2 2002/12/01 15:38:37 neurosurg Exp $"
4 // Widget header file for the Fast Light Tool Kit (FLTK).
6 // Copyright 1998-2002 by Bill Spitzak and others.
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.
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.
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
23 // Please report all bugs and problems to "fltk-bugs@fltk.org".
29 #include "Enumerations.H"
36 typedef void (Fl_Callback )(Fl_Widget*, void*);
37 typedef Fl_Callback* Fl_Callback_p; // needed for BORLAND
38 typedef void (Fl_Callback0)(Fl_Widget*);
39 typedef void (Fl_Callback1)(Fl_Widget*, long);
41 struct FL_EXPORT Fl_Label {
49 void draw(int,int,int,int, Fl_Align) const ;
50 void measure(int&, int&) const ;
53 class FL_EXPORT Fl_Widget {
54 friend class Fl_Group;
57 Fl_Callback* callback_;
72 # if defined(WIN32) && !defined(FL_DLL)
73 // "de-implement" the copy constructors, EXCEPT for when we are using the WIN32 DLL
74 // interface, in which case we can't hide them because Microsoft requires the copy
75 // constructors to implement subclassing...
76 Fl_Widget & operator=(const Fl_Widget &);
77 Fl_Widget(const Fl_Widget &);
78 # endif // WIN32 && !FL_DLL
82 Fl_Widget(int,int,int,int,const char* =0);
84 void x(int v) {x_ = v;}
85 void y(int v) {y_ = v;}
86 void w(int v) {w_ = v;}
87 void h(int v) {h_ = v;}
89 int flags() const {return flags_;}
90 void set_flag(int c) {flags_ |= c;}
91 void clear_flag(int c) {flags_ &= ~c;}
92 enum {INACTIVE=1, INVISIBLE=2, OUTPUT=4, SHORTCUT_LABEL=64,
93 CHANGED=128, VISIBLE_FOCUS=512};
95 void draw_box() const;
96 void draw_box(Fl_Boxtype, Fl_Color) const;
97 void draw_box(Fl_Boxtype, int,int,int,int, Fl_Color) const;
98 void draw_focus() {draw_focus(box(),x(),y(),w(),h());}
99 void draw_focus(Fl_Boxtype, int,int,int,int) const;
100 void draw_label() const;
101 void draw_label(int, int, int, int) const;
105 virtual ~Fl_Widget();
107 virtual void draw() = 0;
108 virtual int handle(int);
109 Fl_Group* parent() const {return parent_;}
110 void parent(Fl_Group* p) {parent_ = p;} // for hacks only, Fl_Group::add()
112 uchar type() const {return type_;}
113 void type(uchar t) {type_ = t;}
115 int x() const {return x_;}
116 int y() const {return y_;}
117 int w() const {return w_;}
118 int h() const {return h_;}
119 virtual void resize(int,int,int,int);
120 int damage_resize(int,int,int,int);
121 void position(int X,int Y) {resize(X,Y,w_,h_);}
122 void size(int W,int H) {resize(x_,y_,W,H);}
124 Fl_Align align() const {return (Fl_Align)align_;}
125 void align(uchar a) {align_ = a;}
126 Fl_Boxtype box() const {return (Fl_Boxtype)box_;}
127 void box(Fl_Boxtype a) {box_ = a;}
128 Fl_Color color() const {return (Fl_Color)color_;}
129 void color(unsigned a) {color_ = a;}
130 Fl_Color selection_color() const {return (Fl_Color)color2_;}
131 void selection_color(unsigned a) {color2_ = a;}
132 void color(unsigned a, unsigned b) {color_=a; color2_=b;}
133 const char* label() const {return label_.value;}
134 void label(const char* a) {label_.value=a; redraw_label();}
135 void label(Fl_Labeltype a,const char* b) {label_.type = a; label_.value = b;}
136 Fl_Labeltype labeltype() const {return (Fl_Labeltype)label_.type;}
137 void labeltype(Fl_Labeltype a) {label_.type = a;}
138 Fl_Color labelcolor() const {return (Fl_Color)label_.color;}
139 void labelcolor(unsigned a) {label_.color=a;}
140 Fl_Font labelfont() const {return (Fl_Font)label_.font;}
141 void labelfont(uchar a) {label_.font=a;}
142 uchar labelsize() const {return label_.size;}
143 void labelsize(uchar a) {label_.size=a;}
144 Fl_Image* image() {return label_.image;}
145 void image(Fl_Image* a) {label_.image=a;}
146 void image(Fl_Image& a) {label_.image=&a;}
147 Fl_Image* deimage() {return label_.deimage;}
148 void deimage(Fl_Image* a) {label_.deimage=a;}
149 void deimage(Fl_Image& a) {label_.deimage=&a;}
150 const char *tooltip() const {return tooltip_;}
151 void tooltip(const char *t);
152 Fl_Callback_p callback() const {return callback_;}
153 void callback(Fl_Callback* c, void* p) {callback_=c; user_data_=p;}
154 void callback(Fl_Callback* c) {callback_=c;}
155 void callback(Fl_Callback0*c) {callback_=(Fl_Callback*)c;}
156 void callback(Fl_Callback1*c, long p=0) {callback_=(Fl_Callback*)c; user_data_=(void*)p;}
157 void* user_data() const {return user_data_;}
158 void user_data(void* v) {user_data_ = v;}
159 long argument() const {return (long)user_data_;}
160 void argument(long v) {user_data_ = (void*)v;}
161 Fl_When when() const {return (Fl_When)when_;}
162 void when(uchar i) {when_ = i;}
164 int visible() const {return !(flags_&INVISIBLE);}
165 int visible_r() const;
168 void set_visible() {flags_ &= ~INVISIBLE;}
169 void clear_visible() {flags_ |= INVISIBLE;}
170 int active() const {return !(flags_&INACTIVE);}
171 int active_r() const;
174 int output() const {return (flags_&OUTPUT);}
175 void set_output() {flags_ |= OUTPUT;}
176 void clear_output() {flags_ &= ~OUTPUT;}
177 int takesevents() const {return !(flags_&(INACTIVE|INVISIBLE|OUTPUT));}
178 int changed() const {return flags_&CHANGED;}
179 void set_changed() {flags_ |= CHANGED;}
180 void clear_changed() {flags_ &= ~CHANGED;}
182 void set_visible_focus() { flags_ |= VISIBLE_FOCUS; }
183 void clear_visible_focus() { flags_ &= ~VISIBLE_FOCUS; }
184 void visible_focus(int v) { if (v) set_visible_focus(); else clear_visible_focus(); }
185 int visible_focus() { return flags_ & VISIBLE_FOCUS; }
187 static void default_callback(Fl_Widget*, void*);
188 void do_callback() {callback_(this,user_data_);}
189 void do_callback(Fl_Widget* o,void* arg=0) {callback_(o,arg);}
190 void do_callback(Fl_Widget* o,long arg) {callback_(o,(void*)arg);}
192 static int test_shortcut(const char*);
193 int contains(const Fl_Widget*) const ;
194 int inside(const Fl_Widget* o) const {return o ? o->contains(this) : 0;}
198 uchar damage() const {return damage_;}
199 void clear_damage(uchar c = 0) {damage_ = c;}
200 void damage(uchar c);
201 void damage(uchar c,int,int,int,int);
202 void draw_label(int, int, int, int, Fl_Align) const;
203 void measure_label(int& xx, int& yy) {label_.measure(xx,yy);}
205 Fl_Window* window() const ;
207 // back compatability only:
208 Fl_Color color2() const {return (Fl_Color)color2_;}
209 void color2(unsigned a) {color2_ = a;}
212 // reserved type numbers (necessary for my cheapo RTTI) start here.
213 // grep the header files for "RESERVED_TYPE" to find the next available
215 #define FL_RESERVED_TYPE 100
220 // End of "$Id: Fl_Widget.H,v 1.2 2002/12/01 15:38:37 neurosurg Exp $".