source: NonGTP/include/fltk/Widget.h @ 769

Revision 769, 10.1 KB checked in by gumbau, 18 years ago (diff)

FLTK imported to SVN repository to be linked agains the GeoTool? application

Line 
1//
2// "$Id: Widget.h 4366 2005-05-23 05:11:51Z spitzak $"
3//
4// The base class of all widgets.
5//
6// Copyright 1998-2003 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 to "fltk-bugs@fltk.org".
24//
25
26#ifndef fltk_Widget_h
27#define fltk_Widget_h
28
29#include "Style.h"
30#include "Rectangle.h"
31
32namespace fltk {
33
34class FL_API Widget;
35class FL_API Window;
36class FL_API Symbol;
37class FL_API Group;
38struct Cursor;
39
40typedef void (Callback )(Widget*, void*);
41typedef Callback* Callback_p; // needed for BORLAND
42typedef void (Callback0)(Widget*);
43typedef void (Callback1)(Widget*, long);
44
45class FL_API Widget : public Rectangle {
46  // disable the copy assignment/constructors:
47  Widget & operator=(const Widget &);
48  Widget(const Widget &);
49
50public:
51
52  Widget(int,int,int,int,const char* =0);
53  virtual ~Widget();
54
55  virtual void draw();
56  virtual int handle(int);
57  int   send(int event);
58  virtual void layout();
59
60  const Style* style() const { return style_; }
61  void  style(const Style* s) { style_ = s; }
62  void  style(const Style& s) { style_ = &s; }
63  bool  copy_style(const Style* s);
64  static NamedStyle* default_style;
65  static void default_glyph(int, const Rectangle&);
66
67  Group* parent() const { return parent_; }
68  void  parent(Group* w)        { parent_ = w; }
69  Window* window() const        ;
70
71  enum { // values for type():
72    RESERVED_TYPE       = 0x64,
73    GROUP_TYPE          = 0xe0,
74    WINDOW_TYPE         = 0xf0
75  };
76  uchar type() const            { return type_; }
77  void  type(uchar t)           { type_ = t; }
78  bool  is_group() const        { return type_ >= GROUP_TYPE; }
79  bool  is_window() const       { return type_ >= WINDOW_TYPE; }
80
81  bool  resize(int x,int y,int w,int h);
82  bool  position(int x, int y)  ;
83  bool  resize(int w, int h)    ;
84
85  void  get_absolute_rect( Rectangle *rect ) const;
86
87  const char* label() const     { return label_; }
88  void  label(const char* a);
89  void  copy_label(const char* a);
90
91  const Symbol* image() const   { return image_; }
92  void  image(const Symbol* a)  { image_ = a; }
93  void  image(const Symbol& a)  { image_ = &a; }
94
95  const char *tooltip() const   { return tooltip_; }
96  void  tooltip(const char *t)  { tooltip_ = t; }
97
98  unsigned shortcut() const     ;
99  bool  shortcut(unsigned key)  ;
100  bool  add_shortcut(unsigned key);
101  bool  remove_shortcut(unsigned key);
102  bool  remove_shortcuts()      ;
103  unsigned label_shortcut() const;
104  bool  test_label_shortcut() const;
105  bool  test_shortcut() const   ;
106  bool  test_shortcut(bool) const;
107
108  Callback_p callback() const   { return callback_; }
109  void  callback(Callback* c, void* p) { callback_=c; user_data_=p; }
110  void  callback(Callback* c)   { callback_=c; }
111  void  callback(Callback0*c)   { callback_=(Callback*)c; }
112  void  callback(Callback1*c, long p=0) { callback_=(Callback*)c; user_data_=(void*)p; }
113  void* user_data() const       { return user_data_; }
114  void  user_data(void* v)      { user_data_ = v; }
115  long  argument() const        { return (long)user_data_; }
116  void  argument(long v)        { user_data_ = (void*)v; }
117  uchar when() const            { return when_; }
118  void  when(uchar i)           { when_ = i; }
119
120  static void default_callback(Widget*, void*);
121  void  do_callback()           { callback_(this,user_data_); }
122  void  do_callback(Widget* o,void* arg=0) { callback_(o,arg); }
123  void  do_callback(Widget* o,long arg) { callback_(o,(void*)arg); }
124  bool  contains(const Widget*) const;
125  bool  inside(const Widget* o) const { return o && o->contains(this); }
126  bool  pushed() const          ;
127  bool  focused() const         ;
128  bool  belowmouse() const      ;
129
130  Flags flags() const           { return flags_; }
131  Flags flags(Flags f)          { return flags_ = f; }
132  Flags set_flag(int c)         { return flags_ |= c; }
133  Flags clear_flag(int c)       { return flags_ &= ~c; }
134  Flags invert_flag(int c)      { return flags_ ^= c; }
135
136  Flags align() const           { return flags_&ALIGN_MASK; }
137  void  align(unsigned a)       { flags_ = (flags_ & (~ALIGN_MASK)) | a; }
138  bool  visible() const         { return !(flags_&INVISIBLE); }
139  bool  visible_r() const       ;
140  void  show()                  ;
141  void  hide()                  ;
142  void  set_visible()           { flags_ &= ~INVISIBLE; }
143  void  clear_visible()         { flags_ |= INVISIBLE; }
144  bool  active() const          { return !(flags_&NOTACTIVE); }
145  bool  active_r() const        ;
146  void  activate()              ;
147  void  activate(int b)         { if (b) activate(); else deactivate(); }
148  void  deactivate()            ;
149  bool  output() const          { return (flags_&OUTPUT)!=0; }
150  void  set_output()            { flags_ |= OUTPUT; }
151  void  clear_output()          { flags_ &= ~OUTPUT; }
152  bool  takesevents() const     { return !(flags_&(OUTPUT|INVISIBLE|NOTACTIVE)); }
153  bool  changed() const         { return (flags_&CHANGED)!=0; }
154  void  set_changed()           { flags_ |= CHANGED; }
155  void  clear_changed()         { flags_ &= ~CHANGED; }
156  bool  value() const           { return (flags_&VALUE)!=0; }
157  void  set_value()             { flags_ |= VALUE; }
158  void  clear_value()           { flags_ &= ~VALUE; }
159  bool  selected() const        { return (flags_&SELECTED)!=0; }
160  void  set_selected()          { flags_ |= SELECTED; }
161  void  clear_selected()        { flags_ &= ~SELECTED; }
162  bool  click_to_focus()        { return (flags_ & CLICK_TO_FOCUS) != 0; }
163  void  set_click_to_focus()    { flags_ |= CLICK_TO_FOCUS; }
164  void  clear_click_to_focus()  { flags_ &= ~CLICK_TO_FOCUS; }
165  bool  tab_to_focus()          { return (flags_ & TAB_TO_FOCUS) != 0; }
166  void  set_tab_to_focus()      { flags_ |= TAB_TO_FOCUS; }
167  void  clear_tab_to_focus()    { flags_ &= ~(TAB_TO_FOCUS|CLICK_TO_FOCUS); }
168  bool  horizontal() const      { return !(flags_&LAYOUT_VERTICAL);}
169  bool  vertical() const        { return (flags_&LAYOUT_VERTICAL)!=0;}
170  void  set_horizontal()        { flags_ &= ~LAYOUT_VERTICAL; }
171  void  set_vertical()          { flags_ |= LAYOUT_VERTICAL; }
172
173  bool  take_focus()            ;
174  void  throw_focus()           ;
175
176  void  redraw()                ;
177  void  redraw(uchar c)         ;
178  void  redraw_label()          ;
179  void  redraw_highlight()      ;
180  void  redraw(const Rectangle&);
181  uchar damage() const          { return damage_; }
182  void  set_damage(uchar c)     { damage_ = c; } // should be called damage(c)
183
184  void  relayout()              ;
185  void  relayout(uchar damage)  ;
186  uchar layout_damage() const   { return layout_damage_; }
187  void  layout_damage(uchar c)  { layout_damage_ = c; }
188
189  void  add_timeout(float)      ;
190  void  repeat_timeout(float)   ;
191  void  remove_timeout()        ;
192
193  void  make_current() const    ;
194  void  draw_background() const ;
195  void  draw_frame() const      ;
196  void  draw_box() const        ;
197  void  draw_glyph(int t, const Rectangle& r) const {glyph()(t,r);}
198  void  draw_label() const      ;
199  void  draw_label(const Rectangle&, Flags) const ;
200  void  cursor(Cursor*) const   ;
201
202  void  measure_label(int&, int&) const ;
203
204  Box*  box()                   const;
205  Box*  buttonbox()             const;
206  Box*  focusbox()              const;
207  GlyphStyle glyph()            const;
208  Font* labelfont()             const;
209  Font* textfont()              const;
210  LabelType* labeltype()        const;
211  Color color()                 const;
212  Color textcolor()             const;
213  Color selection_color()       const;
214  Color selection_textcolor()   const;
215  Color buttoncolor()           const;
216  Color labelcolor()            const;
217  Color highlight_color()       const;
218  Color highlight_textcolor()   const;
219  float labelsize()             const;
220  float textsize()              const;
221  float leading()               const;
222  unsigned char scrollbar_align() const;
223  unsigned char scrollbar_width() const;
224
225  void box(Box*)                ;
226  void buttonbox(Box*)          ;
227  void focusbox(Box*)           ;
228  void glyph(GlyphStyle)        ;
229  void labelfont(Font*)         ;
230  void textfont(Font*)          ;
231  void labeltype(LabelType*)    ;
232  void color(Color)             ;
233  void textcolor(Color a)       ;
234  void selection_color(Color)   ;
235  void selection_textcolor(Color);
236  void buttoncolor(Color)       ;
237  void labelcolor(Color)        ;
238  void highlight_color(Color)   ;
239  void highlight_textcolor(Color);
240  void labelsize(float a)       ;
241  void textsize(float a)        ;
242  void leading(float a)         ;
243  void scrollbar_align(unsigned char);
244  void scrollbar_width(unsigned char);
245
246#ifdef FLTK_1_WIDGET  // back-compatability section:
247
248  Box*  down_box()              const { return box(); }
249  Box*  slider()                const { return buttonbox(); }
250  Box*  box2()                  const { return box(); }
251  Box*  fly_box()               const { return box(); }
252  Color color2()                const { return selection_color(); }
253  Color color3()                const { return buttoncolor(); }
254  Color down_labelcolor()       const { return selection_textcolor(); }
255  Color fly_color()             const { return highlight_color(); }
256  Color selected_textcolor()    const { return selection_textcolor(); }
257  Color cursor_color()          const { return selection_color(); }
258  float text_size()             const { return textsize(); }
259  float label_size()            const { return labelsize(); }
260
261  void down_box(Box* a)         { box(a); }
262  void slider(Box* a)           { buttonbox(a); }
263  void fly_box(Box*)            { }
264  void color(Color a, Color b)  { color(a); selection_color(b); }
265  void color2(Color a)          { selection_color(a); }
266  void color3(Color a)          { buttoncolor(a); }
267  void down_labelcolor(Color a) { selection_textcolor(a); }
268  void labelfont(unsigned a)    { labelfont(font(a)); }
269  void fly_color(Color a)       { highlight_color(a); }
270  void textfont(unsigned a)     { textfont(font(a)); }
271  void selected_textcolor(Color a) { selection_textcolor(a); }
272  void cursor_color(Color a)    { selection_color(a); }
273  void text_size(float n)       { textsize(n); }
274  void label_size(float n)      { labelsize(n); }
275
276#endif
277
278private:
279
280  const char*           label_;
281  const Symbol*         image_;
282  unsigned              flags_;
283  const Style*          style_;
284  Callback*             callback_;
285  void*                 user_data_;
286  const char*           tooltip_; // make this into another widget?
287  Group*                parent_;
288  uchar                 type_;
289  uchar                 damage_;
290  uchar                 layout_damage_;
291  uchar                 when_;
292
293};
294
295enum { // Widget::when() values
296  WHEN_NEVER            = 0,
297  WHEN_CHANGED          = 1,
298  WHEN_RELEASE          = 4,
299  WHEN_RELEASE_ALWAYS   = 6,
300  WHEN_ENTER_KEY        = 8,
301  WHEN_ENTER_KEY_ALWAYS =10,
302  WHEN_ENTER_KEY_CHANGED=11,
303  WHEN_NOT_CHANGED      = 2 // modifier bit to disable changed() test
304};
305
306}
307
308#endif
309
310//
311// End of "$Id: Widget.h 4366 2005-05-23 05:11:51Z spitzak $".
312//
Note: See TracBrowser for help on using the repository browser.