FLTK 1.3.2
Fl_Widget.H
Go to the documentation of this file.
00001 //
00002 // "$Id$"
00003 //
00004 // Widget header file for the Fast Light Tool Kit (FLTK).
00005 //
00006 // Copyright 1998-2012 by Bill Spitzak and others.
00007 //
00008 // This library is free software. Distribution and use rights are outlined in
00009 // the file "COPYING" which should have been included with this file.  If this
00010 // file is missing or damaged, see the license at:
00011 //
00012 //     http://www.fltk.org/COPYING.php
00013 //
00014 // Please report all bugs and problems on the following page:
00015 //
00016 //     http://www.fltk.org/str.php
00017 //
00018 
00022 #ifndef Fl_Widget_H
00023 #define Fl_Widget_H
00024 
00025 #include "Enumerations.H"
00026 
00030 #ifdef _WIN64
00031 #ifdef __GNUC__
00032 #include <stdint.h>
00033 #else
00034 #include <stddef.h>  // M$VC
00035 #endif
00036 typedef intptr_t fl_intptr_t;
00037 typedef uintptr_t fl_uintptr_t;
00038 #else
00039 typedef long fl_intptr_t;
00040 typedef unsigned long fl_uintptr_t;
00041 #endif
00042 
00043 class Fl_Widget;
00044 class Fl_Window;
00045 class Fl_Group;
00046 class Fl_Image;
00047 
00049 typedef void (Fl_Callback )(Fl_Widget*, void*);
00051 typedef Fl_Callback* Fl_Callback_p; // needed for BORLAND
00053 typedef void (Fl_Callback0)(Fl_Widget*);
00055 typedef void (Fl_Callback1)(Fl_Widget*, long);
00056 
00064 struct FL_EXPORT Fl_Label {
00066   const char* value;
00068   Fl_Image* image;
00070   Fl_Image* deimage;
00072   Fl_Font font;
00074   Fl_Fontsize size;
00076   Fl_Color color;
00078   Fl_Align align_;
00080   uchar type;
00081 
00083   void draw(int,int,int,int, Fl_Align) const ;
00084   void measure(int &w, int &h) const ;
00085 };
00086 
00087 
00100 class FL_EXPORT Fl_Widget {
00101   friend class Fl_Group;
00102 
00103   Fl_Group* parent_;
00104   Fl_Callback* callback_;
00105   void* user_data_;
00106   int x_,y_,w_,h_;
00107   Fl_Label label_;
00108   unsigned int flags_;
00109   Fl_Color color_;
00110   Fl_Color color2_;
00111   uchar type_;
00112   uchar damage_;
00113   uchar box_;
00114   uchar when_;
00115 
00116   const char *tooltip_;
00117 
00119   Fl_Widget(const Fl_Widget &);
00121   Fl_Widget& operator=(const Fl_Widget &);
00122 
00123 protected:
00124 
00135   Fl_Widget(int x, int y, int w, int h, const char *label=0L);
00136 
00138   void x(int v) {x_ = v;}
00140   void y(int v) {y_ = v;}
00142   void w(int v) {w_ = v;}
00144   void h(int v) {h_ = v;}
00146   unsigned int flags() const {return flags_;}
00148   void set_flag(unsigned int c) {flags_ |= c;}
00150   void clear_flag(unsigned int c) {flags_ &= ~c;}
00154   enum {
00155         INACTIVE        = 1<<0,   
00156         INVISIBLE       = 1<<1,   
00157         OUTPUT          = 1<<2,   
00158         NOBORDER        = 1<<3,   
00159         FORCE_POSITION  = 1<<4,   
00160         NON_MODAL       = 1<<5,   
00161         SHORTCUT_LABEL  = 1<<6,   
00162         CHANGED         = 1<<7,   
00163         OVERRIDE        = 1<<8,   
00164         VISIBLE_FOCUS   = 1<<9,   
00165         COPIED_LABEL    = 1<<10,  
00166         CLIP_CHILDREN   = 1<<11,  
00167         MENU_WINDOW     = 1<<12,  
00168         TOOLTIP_WINDOW  = 1<<13,  
00169         MODAL           = 1<<14,  
00170         NO_OVERLAY      = 1<<15,  
00171         GROUP_RELATIVE  = 1<<16,  
00172         COPIED_TOOLTIP  = 1<<17,  
00173         FULLSCREEN      = 1<<18,  
00174         MAC_USE_ACCENTS_MENU = 1<<19, 
00175         // (space for more flags)
00176         USERFLAG3       = 1<<29,  
00177         USERFLAG2       = 1<<30,  
00178         USERFLAG1       = 1<<31   
00179   };
00180   void draw_box() const;
00181   void draw_box(Fl_Boxtype t, Fl_Color c) const;
00182   void draw_box(Fl_Boxtype t, int x,int y,int w,int h, Fl_Color c) const;
00183   void draw_backdrop() const;
00185   void draw_focus() {draw_focus(box(),x(),y(),w(),h());}
00186   void draw_focus(Fl_Boxtype t, int x,int y,int w,int h) const;
00187   void draw_label() const;
00188   void draw_label(int, int, int, int) const;
00189 
00190 public:
00191 
00200   virtual ~Fl_Widget();
00201 
00218   virtual void draw() = 0;
00219 
00236   virtual int handle(int event);
00237 
00243   Fl_Group* parent() const {return parent_;}
00244 
00253   void parent(Fl_Group* p) {parent_ = p;} // for hacks only, use Fl_Group::add()
00254 
00263   uchar type() const {return type_;}
00264 
00268   void type(uchar t) {type_ = t;}
00269 
00273   int x() const {return x_;}
00274 
00278   int y() const {return y_;}
00279 
00283   int w() const {return w_;}
00284 
00288   int h() const {return h_;}
00289 
00309   virtual void resize(int x, int y, int w, int h);
00310 
00312   int damage_resize(int,int,int,int);
00313 
00321   void position(int X,int Y) {resize(X,Y,w_,h_);}
00322 
00330   void size(int W,int H) {resize(x_,y_,W,H);}
00331 
00337   Fl_Align align() const {return label_.align_;}
00338 
00346   void align(Fl_Align alignment) {label_.align_ = alignment;}
00347 
00352   Fl_Boxtype box() const {return (Fl_Boxtype)box_;}
00353   
00361   void box(Fl_Boxtype new_box) {box_ = new_box;}
00362 
00367   Fl_Color color() const {return color_;}
00368 
00379   void color(Fl_Color bg) {color_ = bg;}
00380 
00385   Fl_Color selection_color() const {return color2_;}
00386 
00395   void selection_color(Fl_Color a) {color2_ = a;}
00396 
00404   void color(Fl_Color bg, Fl_Color sel) {color_=bg; color2_=sel;}
00405 
00410   const char* label() const {return label_.value;}
00411 
00422   void label(const char* text);
00423 
00434   void copy_label(const char *new_label);
00435 
00439   void label(Fl_Labeltype a, const char* b) {label_.type = a; label_.value = b;}
00440 
00445   Fl_Labeltype labeltype() const {return (Fl_Labeltype)label_.type;}
00446 
00455   void labeltype(Fl_Labeltype a) {label_.type = a;}
00456 
00461   Fl_Color labelcolor() const {return label_.color;}
00462 
00467   void labelcolor(Fl_Color c) {label_.color=c;}
00468 
00476   Fl_Font labelfont() const {return label_.font;}
00477 
00485   void labelfont(Fl_Font f) {label_.font=f;}
00486 
00491   Fl_Fontsize labelsize() const {return label_.size;}
00492 
00497   void labelsize(Fl_Fontsize pix) {label_.size=pix;}
00498 
00503   Fl_Image* image() {return label_.image;}
00504   const Fl_Image* image() const {return label_.image;}
00505 
00510   void image(Fl_Image* img) {label_.image=img;}
00511 
00516   void image(Fl_Image& img) {label_.image=&img;}
00517 
00522   Fl_Image* deimage() {return label_.deimage;}
00523   const Fl_Image* deimage() const {return label_.deimage;}
00524 
00529   void deimage(Fl_Image* img) {label_.deimage=img;}
00530 
00535   void deimage(Fl_Image& img) {label_.deimage=&img;}
00536 
00541   const char *tooltip() const {return tooltip_;}
00542 
00543   void tooltip(const char *text);               // see Fl_Tooltip
00544   void copy_tooltip(const char *text);          // see Fl_Tooltip
00545 
00550   Fl_Callback_p callback() const {return callback_;}
00551 
00557   void callback(Fl_Callback* cb, void* p) {callback_=cb; user_data_=p;}
00558 
00563   void callback(Fl_Callback* cb) {callback_=cb;}
00564 
00569   void callback(Fl_Callback0*cb) {callback_=(Fl_Callback*)cb;}
00570 
00576   void callback(Fl_Callback1*cb, long p=0) {callback_=(Fl_Callback*)cb; user_data_=(void*)p;}
00577 
00582   void* user_data() const {return user_data_;}
00583 
00588   void user_data(void* v) {user_data_ = v;}
00589 
00592   long argument() const {return (long)(fl_intptr_t)user_data_;}
00593 
00598   void argument(long v) {user_data_ = (void*)v;}
00599 
00608   Fl_When when() const {return (Fl_When)when_;}
00609 
00641   void when(uchar i) {when_ = i;}
00642 
00647   unsigned int visible() const {return !(flags_&INVISIBLE);}
00648 
00653   int visible_r() const;
00654 
00672   virtual void show();
00673   
00677   virtual void hide();
00678 
00683   void set_visible() {flags_ &= ~INVISIBLE;}
00684 
00689   void clear_visible() {flags_ |= INVISIBLE;}
00690 
00695   unsigned int active() const {return !(flags_&INACTIVE);}
00696 
00701   int active_r() const;
00702 
00708   void activate();
00709 
00724   void deactivate();
00725 
00734   unsigned int output() const {return (flags_&OUTPUT);}
00735 
00739   void set_output() {flags_ |= OUTPUT;}
00740 
00744   void clear_output() {flags_ &= ~OUTPUT;}
00745 
00751   unsigned int takesevents() const {return !(flags_&(INACTIVE|INVISIBLE|OUTPUT));}
00752 
00768   unsigned int changed() const {return flags_&CHANGED;}
00769 
00773   void set_changed() {flags_ |= CHANGED;}
00774 
00778   void clear_changed() {flags_ &= ~CHANGED;}
00779 
00787   int take_focus();
00788 
00795   void set_visible_focus() { flags_ |= VISIBLE_FOCUS; }
00796 
00801   void clear_visible_focus() { flags_ &= ~VISIBLE_FOCUS; }
00802 
00807   void visible_focus(int v) { if (v) set_visible_focus(); else clear_visible_focus(); }
00808 
00813   unsigned int  visible_focus() { return flags_ & VISIBLE_FOCUS; }
00814 
00822   static void default_callback(Fl_Widget *cb, void *d);
00823 
00828   void do_callback() {do_callback(this,user_data_);}
00829 
00836   void do_callback(Fl_Widget* o,long arg) {do_callback(o,(void*)arg);}
00837 
00838   // Causes a widget to invoke its callback function with arbitrary arguments.
00839   // Documentation and implementation in Fl_Widget.cxx
00840   void do_callback(Fl_Widget* o,void* arg=0);
00841 
00842   /* Internal use only. */
00843   int test_shortcut();
00844   /* Internal use only. */
00845   static unsigned int label_shortcut(const char *t);
00846   /* Internal use only. */
00847   static int test_shortcut(const char*, const bool require_alt = false);
00848   /* Internal use only. */
00849   void _set_fullscreen() {flags_ |= FULLSCREEN;}
00850   void _clear_fullscreen() {flags_ &= ~FULLSCREEN;}
00851 
00857   int contains(const Fl_Widget *w) const ;
00858 
00865   int inside(const Fl_Widget* wgt) const {return wgt ? wgt->contains(this) : 0;}
00866 
00870   void redraw();
00871 
00876   void redraw_label();
00877 
00884   uchar damage() const {return damage_;}
00885 
00898   void clear_damage(uchar c = 0) {damage_ = c;}
00899 
00905   void damage(uchar c);
00906 
00913   void damage(uchar c, int x, int y, int w, int h);
00914 
00915   void draw_label(int, int, int, int, Fl_Align) const;
00916 
00920   void measure_label(int& ww, int& hh) const {label_.measure(ww, hh);}
00921 
00927   Fl_Window* window() const ;
00928 
00952   virtual Fl_Group* as_group() {return 0;}
00953 
00966   virtual Fl_Window* as_window() {return 0;}
00967 
00978   virtual class Fl_Gl_Window* as_gl_window() {return 0;}
00979   
00982   int use_accents_menu() { return flags() & MAC_USE_ACCENTS_MENU; }
00983   
00987   Fl_Color color2() const {return (Fl_Color)color2_;}
00988 
00992   void color2(unsigned a) {color2_ = a;}
00993 };
00994 
01000 #define FL_RESERVED_TYPE 100
01001 
01002 #endif
01003 
01004 //
01005 // End of "$Id$".
01006 //