Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

Fl_Widget.h

00001 /*
00002  * $Id: Fl_Widget.h,v 1.45 2003/06/25 10:02:00 space2 Exp $
00003  *
00004  * Extended Fast Light Toolkit (EFLTK)
00005  * Copyright (C) 2002-2003 by EDE-Team
00006  * WWW: http://www.sourceforge.net/projects/ede
00007  *
00008  * Fast Light Toolkit (FLTK)
00009  * Copyright (C) 1998-2003 by Bill Spitzak and others.
00010  * WWW: http://www.fltk.org
00011  *
00012  * This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00013  * version 2. See COPYING for details.
00014  *
00015  * Author : Mikko Lahteenmaki
00016  * Email  : mikko@fltk.net
00017  *
00018  * Please report all bugs and problems to "efltk-bugs@fltk.net"
00019  *
00020  */
00021 
00022 #ifndef _FL_WIDGET_H_
00023 #define _FL_WIDGET_H_
00024 
00025 #include "Fl_Style.h"
00026 #include "Fl_Exception.h"
00027 #include "Fl_Data_Source.h"
00028 
00029 class FL_API Fl_Widget;
00030 class FL_API Fl_Window;
00031 class FL_API Fl_Image;
00032 class FL_API Fl_Group;
00033 class FL_API Fl_Device;
00034 
00035 typedef void (Fl_Callback )(Fl_Widget*, void*);
00036 typedef Fl_Callback* Fl_Callback_p; // needed for BORLAND
00037 typedef void (Fl_Callback0)(Fl_Widget*);
00038 typedef void (Fl_Callback1)(Fl_Widget*, long);
00039 
00040 // Callback
00041 //typedef void (Fl_Signal_Callback)(void*, void*, int);
00042 //void *caller, void *user_data, int event, void *opt_data, void *receiver 
00043 typedef void (Fl_Signal_Callback)(void *, void *, int, void *, void *);
00044 
00045 #include "Fl_Signal.h"
00046 
00057 class FL_API Fl_Widget {
00058     friend class Fl_Device;
00059 public:
00061     enum {
00062         RESERVED_TYPE = 0x64,       
00063         GROUP_TYPE  = 0xe0,         
00064         WINDOW_TYPE = 0xf0          
00065     };
00066 
00067     uchar   widget_type() const  { return widget_type_; }
00068     void    widget_type(uchar t) { widget_type_ = t; }
00069     bool    is_group() const     { return widget_type_ >= GROUP_TYPE; }
00070     bool    is_window() const    { return widget_type_ >= WINDOW_TYPE; }
00071 
00072     uchar   type() const         { return type_; }
00073     void    type(uchar t)        { type_ = t; }
00074 
00075     virtual void draw();
00076     virtual void layout();
00077     virtual void preferred_size(int& w, int& h) const;
00078 
00079     int send(int event);
00080     int dispatch_event(int event);
00081     virtual int handle(int event);
00082 
00083     static Fl_Named_Style* default_style;
00084 
00085     const Fl_Style* style() const { return style_; }
00086     void style(const Fl_Style* s) { style_ = s; }
00087     void style(const Fl_Style& s) { style_ = &s; }
00088     bool copy_style(const Fl_Style* s);
00089 
00090     static void default_glyph(const Fl_Widget *widget, int glyph, int x, int y, int w, int h, Fl_Flags flags);
00091 
00092     Fl_Group *parent() const    { return parent_; }
00093     void parent(Fl_Group* w) { parent_ = w; }
00094     
00095     Fl_Window *window() const;
00096 
00097     int  x() const       {return x_;}
00098     void x(int v)        {x_ = v;}
00099 
00100     int  y() const       {return y_;}
00101     void y(int v)        {y_ = v;}
00102 
00103     int  w() const       {return w_;}
00104     void w(int v)        {w_ = v;}
00105 
00106     int  h() const       {return h_;}
00107     void h(int v)        {h_ = v;}
00108 
00109     int width();
00110     int height();
00111 
00112     bool resize(int x, int y, int w, int h);
00113     bool position(int X,int Y) { return resize(X,Y,w_,h_); }
00114     bool size(int W,int H)     { return resize(x_,y_,W,H); }
00115 
00116     const Fl_String &label() const  { return label_; }
00117     void label(const Fl_String &l) { label_ = l; }
00118     void label(const char *l)      { label_ = l ? l : ""; }
00119 
00120     // Compatibility: REMOVE THESE!
00121     void copy_label(const char *a) { label(a); }
00122     void copy_label(const Fl_String &a) { label(a); }
00123 
00124     void measure_label(int& w, int& h) const;
00125 
00126     const Fl_String &tooltip() const    { return tooltip_; }
00127     void    tooltip(const char *t)      { tooltip_ = t ? t : ""; }
00128     void    tooltip(const Fl_String &t) { tooltip_ = t; }
00129 
00130     const Fl_String &field_name() const    { return field_name_; }
00131     void    field_name(const char *f)      { field_name_ = f ? f : ""; }
00132     void    field_name(const Fl_String &f) { field_name_ = f; }
00133 
00134     Fl_Image* image() const { return image_; }
00135     void image(Fl_Image* a)  { image_ = a; }
00136     void image(Fl_Image& a)  { image_ = &a; }
00137 
00138     int shortcut() const { return shortcut_; }
00139     void shortcut(int s) { shortcut_ = s; }
00140     int test_shortcut() const;
00141 
00142     // REMOVE THIS!
00143     static void default_callback(Fl_Widget *w, void *arg);
00144 
00145     // Remove these at some point in future!?
00146     // Use only signals/slots for new code!!
00147     Fl_Callback_p callback() const { return callback_; }
00148     void callback(Fl_Callback *c, void *p) { callback_=c; user_data_=p; }
00149     void callback(Fl_Callback *c) { callback_=c; }
00150     void callback(Fl_Callback0 *c) { callback_=(Fl_Callback*)c; }
00151     void callback(Fl_Callback1 *c, long p=0) { callback_=(Fl_Callback*)c; user_data_=(void*)p; }
00152 
00153     void *user_data() const  { return user_data_; }
00154     void user_data(void* v)  { user_data_ = v; }
00155 
00156     long argument() const    { return (long)user_data_; }
00157     void argument(long v)    { user_data_ = (void*)v; }
00158 
00159     // REMOVE THESE!?
00160     uchar when() const        { return when_; }
00161     void  when(uchar i)       { when_ = i; }
00162 
00163     void do_callback(Fl_Widget *o, void *arg, void * widget_data = 0)   { if (!emit_signal(FL_VALUE_CHANGED, widget_data)) do_callback_(o, arg); }
00164     void do_callback(Fl_Widget *o, long arg, void * widget_data = 0)    { if (!emit_signal(FL_VALUE_CHANGED, widget_data)) do_callback_(o, arg); }
00165     void do_callback(void * widget_data = 0)                            { if (!emit_signal(FL_VALUE_CHANGED, widget_data)) do_callback_(); }
00166 
00167     void connect(int event, void * obj, Fl_Signal_Callback *cb);
00168     void connect(int event, Fl_Signal_Callback *cb);
00169     int emit_signal(int event, void *opt_data=0){
00170     return signal_.emit(event, this, user_data_, opt_data);
00171     }
00172 
00173     Fl_Signal *signal() { return &signal_; }
00174 
00175     bool contains(const Fl_Widget*) const;
00176     bool inside(const Fl_Widget* o) const { return o && o->contains(this); }
00177     bool pushed() const;
00178     bool focused() const;
00179     bool belowmouse() const;
00180 
00181     Fl_Align layout_align() const { return (Fl_Align)layout_flags_; }
00182     void layout_align(Fl_Align f) { layout_flags_ = (uchar)f; }
00183 
00184     Fl_Flags flags() const      { return flags_; }
00185     Fl_Flags flags(Fl_Flags f)  { return flags_.flags(f); }
00186     Fl_Flags set_flag(int c)    { return flags_.set(c); }
00187     Fl_Flags clear_flag(int c)  { return flags_.clear(c); }
00188     Fl_Flags invert_flag(int c) { return flags_.invert(c); }
00189 
00190     Fl_Align align() const { return flags_.align(); }
00191     void align(int a)      { flags_.align(a); }
00192 
00193     bool visible_r() const;
00194     void show();
00195     void hide();
00196 
00197     bool visible() const     { return !flags_.is_set(FL_INVISIBLE);}
00198     void set_visible()       { flags_.clear(FL_INVISIBLE); }
00199     void clear_visible()     { flags_.set(FL_INVISIBLE); }
00200 
00201     bool active() const      { return !flags_.is_set(FL_INACTIVE); }
00202     bool active_r() const;
00203 
00204     void activate();
00205     void deactivate();
00206     void activate(int b)     { if (b) activate(); else deactivate(); }
00207 
00208     bool output() const      { return flags_.is_set(FL_OUTPUT); }
00209     void set_output()        { flags_.set(FL_OUTPUT); }
00210     void clear_output()      { flags_.clear(FL_OUTPUT); }
00211 
00212     bool takesevents() const { return !flags_.is_set(FL_OUTPUT|FL_INVISIBLE|FL_INACTIVE); }
00213 
00214     bool changed() const     { return flags_.is_set(FL_CHANGED); }
00215     void set_changed()       { flags_.set(FL_CHANGED); }
00216     void clear_changed()     { flags_.clear(FL_CHANGED); }
00217 
00218     bool value() const       { return flags_.is_set(FL_VALUE); }
00219     void set_value()         { flags_.set(FL_VALUE); }
00220     void clear_value()       { flags_.clear(FL_VALUE); }
00221 
00222     bool selected() const    { return flags_.is_set(FL_SELECTED); }
00223     void set_selected()      { flags_.set(FL_SELECTED); }
00224     void clear_selected()    { flags_.clear(FL_SELECTED); }
00225 
00226     bool focus_on_click()       { return flags_.is_set(FL_FOCUS_ON_CLICK); }
00227     void set_focus_on_click()   { flags_.set(FL_FOCUS_ON_CLICK); }
00228     void clear_focus_on_click() { flags_.clear(FL_FOCUS_ON_CLICK); }
00229 
00230     bool focus_on_key()       { return flags_.is_set(FL_FOCUS_ON_KEYBOARD); }
00231     void set_focus_on_key()   { flags_.set(FL_FOCUS_ON_KEYBOARD); }
00232     void clear_focus_on_key() { flags_.clear(FL_FOCUS_ON_KEYBOARD); }
00233 
00234     void accept_focus(bool v) { if(v) flags_.set(FL_FOCUS_ON_CLICK|FL_FOCUS_ON_KEYBOARD); else flags_.clear(FL_FOCUS_ON_CLICK|FL_FOCUS_ON_KEYBOARD); }
00235     bool accept_focus() { return flags_.is_set(FL_FOCUS_ON_CLICK|FL_FOCUS_ON_KEYBOARD); }
00236 
00237     bool take_focus();
00238     void throw_focus();
00239 
00240     void redraw();
00241     void redraw_label();
00242     void redraw(int x, int y, int w, int h);
00243     void redraw(uchar c);
00244 
00245     Fl_Damage damage() const { return (Fl_Damage)damage_; }
00246     void set_damage(uchar d) { damage_ = d; } // should be called damage(c)
00247     void clear_damage() { damage_ = FL_DAMAGE_NONE; }
00248 
00249     void relayout();
00250     void relayout(uchar damage);
00251     Fl_Layout_Damage layout_damage() const { return (Fl_Layout_Damage)layout_damage_; }
00252     void layout_damage(uchar d)  { layout_damage_ = d; }
00253 
00254     void make_current() const;
00255 
00256     void draw_frame() const;
00257     void draw_box() const;
00258     void draw_glyph(int t, int x,int y,int w,int h, Fl_Flags f) const { glyph()(this,t,x,y,w,h,f); }
00259     void draw_label(int x,int y,int w,int h, Fl_Flags) const;
00260 
00261     void draw_inside_label(int x,int y,int w,int h, Fl_Flags) const ;
00262     void draw_inside_label() const;
00263 
00264     Fl_Boxtype  box()               const;
00265     Fl_Boxtype  button_box()        const;
00266     Fl_Boxtype  focus_box()         const;
00267     Fl_Glyph    glyph()             const;
00268     Fl_Font     label_font()        const;
00269     Fl_Font     text_font()         const;
00270     Fl_Labeltype label_type()       const;
00271     Fl_Color    color()             const;
00272     Fl_Color    label_color()       const;
00273     Fl_Color    selection_color()   const;
00274     Fl_Color    selection_text_color()  const;
00275     Fl_Color    button_color()      const;
00276     Fl_Color    highlight_color()   const;
00277     Fl_Color    highlight_label_color() const;
00278     Fl_Color    text_color()        const;
00279     unsigned    label_size()        const;
00280     unsigned    text_size()         const;
00281     unsigned    leading()           const;
00282     Fl_Flags    scrollbar_align()   const { return style()->scrollbar_align; }
00283     unsigned    scrollbar_width()   const { return style()->scrollbar_width; }
00284 
00285     void box(Fl_Boxtype);
00286     void button_box(Fl_Boxtype);
00287     void focus_box(Fl_Boxtype);
00288     void glyph(Fl_Glyph);
00289     void label_font(Fl_Font);
00290     void text_font(Fl_Font);
00291     void label_type(Fl_Labeltype);
00292     void color(Fl_Color);
00293     void label_color(Fl_Color);
00294     void selection_color(Fl_Color);
00295     void selection_text_color(Fl_Color);
00296     void button_color(Fl_Color);
00297     void highlight_color(Fl_Color);
00298     void highlight_label_color(Fl_Color);
00299     void text_color(Fl_Color a);
00300     void label_size(unsigned a);
00301     void text_size(unsigned a);
00302     void leading(unsigned a);
00303 
00304     // Data source support
00305     virtual bool load_data(Fl_Data_Source *ds) { return true; }
00306     virtual bool save_data(Fl_Data_Source *ds) { return true; }
00307 
00308     // Dialog support
00309     virtual void reset() { }
00310 
00311     virtual ~Fl_Widget();
00312 
00313 protected:
00321     Fl_Widget(int x, int y, int w, int h, const char *l=0);
00322 
00330     Fl_Widget(const char *l=0, int layout_size=30, Fl_Align layout_al=FL_ALIGN_TOP, int label_w=-1);
00331 
00332 private:
00333     // disable the copy assignment/constructors:
00334     Fl_Widget & operator=(const Fl_Widget &);
00335     Fl_Widget(const Fl_Widget &);
00336 
00337     void ctor_init(int X, int Y, int W, int H, const char *L);
00338 
00339     void do_callback_() { do_callback_(this, user_data()); }
00340     void do_callback_(Fl_Widget *o, void *arg);
00341     void do_callback_(Fl_Widget *o, long arg);
00342 
00343     Fl_Flags        flags_;
00344     int             shortcut_; // encode in the label?
00345     int             x_,y_,w_,h_;
00346     uchar           type_, widget_type_;
00347     uchar           damage_;
00348     uchar           layout_damage_, layout_flags_;
00349     uchar           when_;  // REMOVE THIS!
00350 
00351     Fl_String field_name_;  // data source support
00352     Fl_String tooltip_;     // make this into another widget?
00353     Fl_String label_;
00354 
00355     Fl_Image *image_;
00356     Fl_Group *parent_;
00357     const Fl_Style* style_;
00358 
00359     Fl_Callback *callback_;
00360     void *user_data_;  
00361     Fl_Signal signal_;
00362 
00363 public:
00364     /* Define default slots */
00365     DEFSLOT_O(Fl_Widget, Fl_Widget, slot_label, const char *);
00366     DEFSLOT_O(Fl_Widget, Fl_Widget, slot_active, int);
00367     DEFSLOT_O(Fl_Widget, Fl_Widget, slot_visibility, int);
00368 
00374     void slot_label(const char *newlabel) { label(newlabel); redraw_label(); }
00375     
00381     void slot_active(int value) { if(value) activate(); else deactivate(); }
00382 
00388     void slot_visibility(int value) { if(value) show(); else hide(); }
00389 };
00390 
00391 #endif

Generated on Thu Jul 31 15:33:45 2003 for eFLTK by doxygen1.2.15