FLTK 1.3.0
Fl_Widget.H
Go to the documentation of this file.
1 //
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 
31 #ifndef Fl_Widget_H
32 #define Fl_Widget_H
33 
34 #include "Enumerations.H"
35 
39 #ifdef _WIN64
40 #ifdef __GNUC__
41 #include <stdint.h>
42 #else
43 #include <stddef.h> // M$VC
44 #endif
45 typedef intptr_t fl_intptr_t;
46 typedef uintptr_t fl_uintptr_t;
47 #else
48 typedef long fl_intptr_t;
49 typedef unsigned long fl_uintptr_t;
50 #endif
51 
52 class Fl_Widget;
53 class Fl_Window;
54 class Fl_Group;
55 class Fl_Image;
56 
58 typedef void (Fl_Callback )(Fl_Widget*, void*);
60 typedef Fl_Callback* Fl_Callback_p; // needed for BORLAND
62 typedef void (Fl_Callback0)(Fl_Widget*);
64 typedef void (Fl_Callback1)(Fl_Widget*, long);
65 
73 struct FL_EXPORT Fl_Label {
75  const char* value;
90 
92  void draw(int,int,int,int, Fl_Align) const ;
93  void measure(int &w, int &h) const ;
94 };
95 
96 
109 class 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 
128  Fl_Widget(const Fl_Widget &);
130  Fl_Widget& operator=(const Fl_Widget &);
131 
132 protected:
133 
144  Fl_Widget(int x, int y, int w, int h, const char *label=0L);
145 
147  void x(int v) {x_ = v;}
149  void y(int v) {y_ = v;}
151  void w(int v) {w_ = v;}
153  void h(int v) {h_ = v;}
155  unsigned int flags() const {return flags_;}
157  void set_flag(unsigned int c) {flags_ |= c;}
159  void clear_flag(unsigned int c) {flags_ &= ~c;}
163  enum {
164  INACTIVE = 1<<0,
165  INVISIBLE = 1<<1,
166  OUTPUT = 1<<2,
167  NOBORDER = 1<<3,
168  FORCE_POSITION = 1<<4,
169  NON_MODAL = 1<<5,
170  SHORTCUT_LABEL = 1<<6,
171  CHANGED = 1<<7,
172  OVERRIDE = 1<<8,
173  VISIBLE_FOCUS = 1<<9,
174  COPIED_LABEL = 1<<10,
175  CLIP_CHILDREN = 1<<11,
176  MENU_WINDOW = 1<<12,
177  TOOLTIP_WINDOW = 1<<13,
178  MODAL = 1<<14,
179  NO_OVERLAY = 1<<15,
180  GROUP_RELATIVE = 1<<16,
181  COPIED_TOOLTIP = 1<<17,
182  // (space for more flags)
183  USERFLAG3 = 1<<29,
184  USERFLAG2 = 1<<30,
185  USERFLAG1 = 1<<31
186  };
187  void draw_box() const;
188  void draw_box(Fl_Boxtype t, Fl_Color c) const;
189  void draw_box(Fl_Boxtype t, int x,int y,int w,int h, Fl_Color c) const;
190  void draw_backdrop() const;
192  void draw_focus() {draw_focus(box(),x(),y(),w(),h());}
193  void draw_focus(Fl_Boxtype t, int x,int y,int w,int h) const;
194  void draw_label() const;
195  void draw_label(int, int, int, int) const;
196 
197 public:
198 
207  virtual ~Fl_Widget();
208 
225  virtual void draw() = 0;
226 
243  virtual int handle(int event);
244 
250  Fl_Group* parent() const {return parent_;}
251 
260  void parent(Fl_Group* p) {parent_ = p;} // for hacks only, use Fl_Group::add()
261 
270  uchar type() const {return type_;}
271 
275  void type(uchar t) {type_ = t;}
276 
280  int x() const {return x_;}
281 
285  int y() const {return y_;}
286 
290  int w() const {return w_;}
291 
295  int h() const {return h_;}
296 
316  virtual void resize(int x, int y, int w, int h);
317 
319  int damage_resize(int,int,int,int);
320 
328  void position(int X,int Y) {resize(X,Y,w_,h_);}
329 
337  void size(int W,int H) {resize(x_,y_,W,H);}
338 
344  Fl_Align align() const {return label_.align_;}
345 
353  void align(Fl_Align alignment) {label_.align_ = alignment;}
354 
359  Fl_Boxtype box() const {return (Fl_Boxtype)box_;}
360 
368  void box(Fl_Boxtype new_box) {box_ = new_box;}
369 
374  Fl_Color color() const {return color_;}
375 
386  void color(Fl_Color bg) {color_ = bg;}
387 
392  Fl_Color selection_color() const {return color2_;}
393 
402  void selection_color(Fl_Color a) {color2_ = a;}
403 
411  void color(Fl_Color bg, Fl_Color sel) {color_=bg; color2_=sel;}
412 
417  const char* label() const {return label_.value;}
418 
429  void label(const char* text);
430 
441  void copy_label(const char *new_label);
442 
446  void label(Fl_Labeltype a, const char* b) {label_.type = a; label_.value = b;}
447 
452  Fl_Labeltype labeltype() const {return (Fl_Labeltype)label_.type;}
453 
462  void labeltype(Fl_Labeltype a) {label_.type = a;}
463 
468  Fl_Color labelcolor() const {return label_.color;}
469 
474  void labelcolor(Fl_Color c) {label_.color=c;}
475 
483  Fl_Font labelfont() const {return label_.font;}
484 
492  void labelfont(Fl_Font f) {label_.font=f;}
493 
498  Fl_Fontsize labelsize() const {return label_.size;}
499 
504  void labelsize(Fl_Fontsize pix) {label_.size=pix;}
505 
510  Fl_Image* image() {return label_.image;}
511  const Fl_Image* image() const {return label_.image;}
512 
517  void image(Fl_Image* img) {label_.image=img;}
518 
523  void image(Fl_Image& img) {label_.image=&img;}
524 
529  Fl_Image* deimage() {return label_.deimage;}
530  const Fl_Image* deimage() const {return label_.deimage;}
531 
536  void deimage(Fl_Image* img) {label_.deimage=img;}
537 
542  void deimage(Fl_Image& img) {label_.deimage=&img;}
543 
548  const char *tooltip() const {return tooltip_;}
549 
550  void tooltip(const char *text); // see Fl_Tooltip
551  void copy_tooltip(const char *text); // see Fl_Tooltip
552 
557  Fl_Callback_p callback() const {return callback_;}
558 
564  void callback(Fl_Callback* cb, void* p) {callback_=cb; user_data_=p;}
565 
570  void callback(Fl_Callback* cb) {callback_=cb;}
571 
576  void callback(Fl_Callback0*cb) {callback_=(Fl_Callback*)cb;}
577 
583  void callback(Fl_Callback1*cb, long p=0) {callback_=(Fl_Callback*)cb; user_data_=(void*)p;}
584 
589  void* user_data() const {return user_data_;}
590 
595  void user_data(void* v) {user_data_ = v;}
596 
599  long argument() const {return (long)(fl_intptr_t)user_data_;}
600 
605  void argument(long v) {user_data_ = (void*)v;}
606 
615  Fl_When when() const {return (Fl_When)when_;}
616 
648  void when(uchar i) {when_ = i;}
649 
654  unsigned int visible() const {return !(flags_&INVISIBLE);}
655 
660  int visible_r() const;
661 
679  virtual void show();
680 
684  virtual void hide();
685 
690  void set_visible() {flags_ &= ~INVISIBLE;}
691 
696  void clear_visible() {flags_ |= INVISIBLE;}
697 
702  unsigned int active() const {return !(flags_&INACTIVE);}
703 
708  int active_r() const;
709 
715  void activate();
716 
731  void deactivate();
732 
741  unsigned int output() const {return (flags_&OUTPUT);}
742 
746  void set_output() {flags_ |= OUTPUT;}
747 
751  void clear_output() {flags_ &= ~OUTPUT;}
752 
758  unsigned int takesevents() const {return !(flags_&(INACTIVE|INVISIBLE|OUTPUT));}
759 
775  unsigned int changed() const {return flags_&CHANGED;}
776 
780  void set_changed() {flags_ |= CHANGED;}
781 
785  void clear_changed() {flags_ &= ~CHANGED;}
786 
794  int take_focus();
795 
802  void set_visible_focus() { flags_ |= VISIBLE_FOCUS; }
803 
808  void clear_visible_focus() { flags_ &= ~VISIBLE_FOCUS; }
809 
814  void visible_focus(int v) { if (v) set_visible_focus(); else clear_visible_focus(); }
815 
820  unsigned int visible_focus() { return flags_ & VISIBLE_FOCUS; }
821 
829  static void default_callback(Fl_Widget *cb, void *d);
830 
835  void do_callback() {do_callback(this,user_data_);}
836 
843  void do_callback(Fl_Widget* o,long arg) {do_callback(o,(void*)arg);}
844 
845  // Causes a widget to invoke its callback function with arbitrary arguments.
846  // Documentation and implementation in Fl_Widget.cxx
847  void do_callback(Fl_Widget* o,void* arg=0);
848 
849  /* Internal use only. */
850  int test_shortcut();
851  /* Internal use only. */
852  static unsigned int label_shortcut(const char *t);
853  /* Internal use only. */
854  static int test_shortcut(const char*, const bool require_alt = false);
855 
861  int contains(const Fl_Widget *w) const ;
862 
869  int inside(const Fl_Widget* w) const {return w ? w->contains(this) : 0;}
870 
874  void redraw();
875 
880  void redraw_label();
881 
888  uchar damage() const {return damage_;}
889 
902  void clear_damage(uchar c = 0) {damage_ = c;}
903 
909  void damage(uchar c);
910 
917  void damage(uchar c, int x, int y, int w, int h);
918 
919  void draw_label(int, int, int, int, Fl_Align) const;
920 
924  void measure_label(int& ww, int& hh) const {label_.measure(ww, hh);}
925 
931  Fl_Window* window() const ;
932 
956  virtual Fl_Group* as_group() {return 0;}
957 
970  virtual Fl_Window* as_window() {return 0;}
971 
982  virtual class Fl_Gl_Window* as_gl_window() {return 0;}
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 8623 2011-04-24 17:09:41Z AlbrechtS $".
1006 //