FLTK 1.3.2
Fl_Widget.H
Go to the documentation of this file.
1 //
2 // "$Id: Fl_Widget.H 9792 2013-01-13 15:25:37Z manolo $"
3 //
4 // Widget header file for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2012 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 #ifdef __GNUC__
32 #include <stdint.h>
33 #else
34 #include <stddef.h> // M$VC
35 #endif
36 typedef intptr_t fl_intptr_t;
37 typedef uintptr_t fl_uintptr_t;
38 #else
39 typedef long fl_intptr_t;
40 typedef unsigned long fl_uintptr_t;
41 #endif
42 
43 class Fl_Widget;
44 class Fl_Window;
45 class Fl_Group;
46 class Fl_Image;
47 
49 typedef void (Fl_Callback )(Fl_Widget*, void*);
51 typedef Fl_Callback* Fl_Callback_p; // needed for BORLAND
53 typedef void (Fl_Callback0)(Fl_Widget*);
55 typedef void (Fl_Callback1)(Fl_Widget*, long);
56 
64 struct FL_EXPORT Fl_Label {
66  const char* value;
81 
83  void draw(int,int,int,int, Fl_Align) const ;
84  void measure(int &w, int &h) const ;
85 };
86 
87 
100 class FL_EXPORT Fl_Widget {
101  friend class Fl_Group;
102 
103  Fl_Group* parent_;
104  Fl_Callback* callback_;
105  void* user_data_;
106  int x_,y_,w_,h_;
107  Fl_Label label_;
108  unsigned int flags_;
109  Fl_Color color_;
110  Fl_Color color2_;
111  uchar type_;
112  uchar damage_;
113  uchar box_;
114  uchar when_;
115 
116  const char *tooltip_;
117 
119  Fl_Widget(const Fl_Widget &);
121  Fl_Widget& operator=(const Fl_Widget &);
122 
123 protected:
124 
135  Fl_Widget(int x, int y, int w, int h, const char *label=0L);
136 
138  void x(int v) {x_ = v;}
140  void y(int v) {y_ = v;}
142  void w(int v) {w_ = v;}
144  void h(int v) {h_ = v;}
146  unsigned int flags() const {return flags_;}
148  void set_flag(unsigned int c) {flags_ |= c;}
150  void clear_flag(unsigned int c) {flags_ &= ~c;}
154  enum {
155  INACTIVE = 1<<0,
156  INVISIBLE = 1<<1,
157  OUTPUT = 1<<2,
158  NOBORDER = 1<<3,
159  FORCE_POSITION = 1<<4,
160  NON_MODAL = 1<<5,
161  SHORTCUT_LABEL = 1<<6,
162  CHANGED = 1<<7,
163  OVERRIDE = 1<<8,
164  VISIBLE_FOCUS = 1<<9,
165  COPIED_LABEL = 1<<10,
166  CLIP_CHILDREN = 1<<11,
167  MENU_WINDOW = 1<<12,
168  TOOLTIP_WINDOW = 1<<13,
169  MODAL = 1<<14,
170  NO_OVERLAY = 1<<15,
171  GROUP_RELATIVE = 1<<16,
172  COPIED_TOOLTIP = 1<<17,
173  FULLSCREEN = 1<<18,
175  // (space for more flags)
176  USERFLAG3 = 1<<29,
177  USERFLAG2 = 1<<30,
178  USERFLAG1 = 1<<31
179  };
180  void draw_box() const;
181  void draw_box(Fl_Boxtype t, Fl_Color c) const;
182  void draw_box(Fl_Boxtype t, int x,int y,int w,int h, Fl_Color c) const;
183  void draw_backdrop() const;
185  void draw_focus() {draw_focus(box(),x(),y(),w(),h());}
186  void draw_focus(Fl_Boxtype t, int x,int y,int w,int h) const;
187  void draw_label() const;
188  void draw_label(int, int, int, int) const;
189 
190 public:
191 
200  virtual ~Fl_Widget();
201 
218  virtual void draw() = 0;
219 
236  virtual int handle(int event);
237 
243  Fl_Group* parent() const {return parent_;}
244 
253  void parent(Fl_Group* p) {parent_ = p;} // for hacks only, use Fl_Group::add()
254 
263  uchar type() const {return type_;}
264 
268  void type(uchar t) {type_ = t;}
269 
273  int x() const {return x_;}
274 
278  int y() const {return y_;}
279 
283  int w() const {return w_;}
284 
288  int h() const {return h_;}
289 
309  virtual void resize(int x, int y, int w, int h);
310 
312  int damage_resize(int,int,int,int);
313 
321  void position(int X,int Y) {resize(X,Y,w_,h_);}
322 
330  void size(int W,int H) {resize(x_,y_,W,H);}
331 
337  Fl_Align align() const {return label_.align_;}
338 
346  void align(Fl_Align alignment) {label_.align_ = alignment;}
347 
352  Fl_Boxtype box() const {return (Fl_Boxtype)box_;}
353 
361  void box(Fl_Boxtype new_box) {box_ = new_box;}
362 
367  Fl_Color color() const {return color_;}
368 
379  void color(Fl_Color bg) {color_ = bg;}
380 
385  Fl_Color selection_color() const {return color2_;}
386 
395  void selection_color(Fl_Color a) {color2_ = a;}
396 
404  void color(Fl_Color bg, Fl_Color sel) {color_=bg; color2_=sel;}
405 
410  const char* label() const {return label_.value;}
411 
422  void label(const char* text);
423 
434  void copy_label(const char *new_label);
435 
439  void label(Fl_Labeltype a, const char* b) {label_.type = a; label_.value = b;}
440 
445  Fl_Labeltype labeltype() const {return (Fl_Labeltype)label_.type;}
446 
455  void labeltype(Fl_Labeltype a) {label_.type = a;}
456 
461  Fl_Color labelcolor() const {return label_.color;}
462 
467  void labelcolor(Fl_Color c) {label_.color=c;}
468 
476  Fl_Font labelfont() const {return label_.font;}
477 
485  void labelfont(Fl_Font f) {label_.font=f;}
486 
491  Fl_Fontsize labelsize() const {return label_.size;}
492 
497  void labelsize(Fl_Fontsize pix) {label_.size=pix;}
498 
503  Fl_Image* image() {return label_.image;}
504  const Fl_Image* image() const {return label_.image;}
505 
510  void image(Fl_Image* img) {label_.image=img;}
511 
516  void image(Fl_Image& img) {label_.image=&img;}
517 
522  Fl_Image* deimage() {return label_.deimage;}
523  const Fl_Image* deimage() const {return label_.deimage;}
524 
529  void deimage(Fl_Image* img) {label_.deimage=img;}
530 
535  void deimage(Fl_Image& img) {label_.deimage=&img;}
536 
541  const char *tooltip() const {return tooltip_;}
542 
543  void tooltip(const char *text); // see Fl_Tooltip
544  void copy_tooltip(const char *text); // see Fl_Tooltip
545 
550  Fl_Callback_p callback() const {return callback_;}
551 
557  void callback(Fl_Callback* cb, void* p) {callback_=cb; user_data_=p;}
558 
563  void callback(Fl_Callback* cb) {callback_=cb;}
564 
569  void callback(Fl_Callback0*cb) {callback_=(Fl_Callback*)cb;}
570 
576  void callback(Fl_Callback1*cb, long p=0) {callback_=(Fl_Callback*)cb; user_data_=(void*)p;}
577 
582  void* user_data() const {return user_data_;}
583 
588  void user_data(void* v) {user_data_ = v;}
589 
592  long argument() const {return (long)(fl_intptr_t)user_data_;}
593 
598  void argument(long v) {user_data_ = (void*)v;}
599 
608  Fl_When when() const {return (Fl_When)when_;}
609 
641  void when(uchar i) {when_ = i;}
642 
647  unsigned int visible() const {return !(flags_&INVISIBLE);}
648 
653  int visible_r() const;
654 
672  virtual void show();
673 
677  virtual void hide();
678 
683  void set_visible() {flags_ &= ~INVISIBLE;}
684 
689  void clear_visible() {flags_ |= INVISIBLE;}
690 
695  unsigned int active() const {return !(flags_&INACTIVE);}
696 
701  int active_r() const;
702 
708  void activate();
709 
724  void deactivate();
725 
734  unsigned int output() const {return (flags_&OUTPUT);}
735 
739  void set_output() {flags_ |= OUTPUT;}
740 
744  void clear_output() {flags_ &= ~OUTPUT;}
745 
751  unsigned int takesevents() const {return !(flags_&(INACTIVE|INVISIBLE|OUTPUT));}
752 
768  unsigned int changed() const {return flags_&CHANGED;}
769 
773  void set_changed() {flags_ |= CHANGED;}
774 
778  void clear_changed() {flags_ &= ~CHANGED;}
779 
787  int take_focus();
788 
795  void set_visible_focus() { flags_ |= VISIBLE_FOCUS; }
796 
801  void clear_visible_focus() { flags_ &= ~VISIBLE_FOCUS; }
802 
807  void visible_focus(int v) { if (v) set_visible_focus(); else clear_visible_focus(); }
808 
813  unsigned int visible_focus() { return flags_ & VISIBLE_FOCUS; }
814 
822  static void default_callback(Fl_Widget *cb, void *d);
823 
828  void do_callback() {do_callback(this,user_data_);}
829 
836  void do_callback(Fl_Widget* o,long arg) {do_callback(o,(void*)arg);}
837 
838  // Causes a widget to invoke its callback function with arbitrary arguments.
839  // Documentation and implementation in Fl_Widget.cxx
840  void do_callback(Fl_Widget* o,void* arg=0);
841 
842  /* Internal use only. */
843  int test_shortcut();
844  /* Internal use only. */
845  static unsigned int label_shortcut(const char *t);
846  /* Internal use only. */
847  static int test_shortcut(const char*, const bool require_alt = false);
848  /* Internal use only. */
849  void _set_fullscreen() {flags_ |= FULLSCREEN;}
850  void _clear_fullscreen() {flags_ &= ~FULLSCREEN;}
851 
857  int contains(const Fl_Widget *w) const ;
858 
865  int inside(const Fl_Widget* wgt) const {return wgt ? wgt->contains(this) : 0;}
866 
870  void redraw();
871 
876  void redraw_label();
877 
884  uchar damage() const {return damage_;}
885 
898  void clear_damage(uchar c = 0) {damage_ = c;}
899 
905  void damage(uchar c);
906 
913  void damage(uchar c, int x, int y, int w, int h);
914 
915  void draw_label(int, int, int, int, Fl_Align) const;
916 
920  void measure_label(int& ww, int& hh) const {label_.measure(ww, hh);}
921 
927  Fl_Window* window() const ;
928 
952  virtual Fl_Group* as_group() {return 0;}
953 
966  virtual Fl_Window* as_window() {return 0;}
967 
978  virtual class Fl_Gl_Window* as_gl_window() {return 0;}
979 
983 
987  Fl_Color color2() const {return (Fl_Color)color2_;}
988 
992  void color2(unsigned a) {color2_ = a;}
993 };
994 
1000 #define FL_RESERVED_TYPE 100
1001 
1002 #endif
1003 
1004 //
1005 // End of "$Id: Fl_Widget.H 9792 2013-01-13 15:25:37Z manolo $".
1006 //