FLTK 1.3.0
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-2010 by Bill Spitzak and others.
00007 //
00008 // This library is free software; you can redistribute it and/or
00009 // modify it under the terms of the GNU Library General Public
00010 // License as published by the Free Software Foundation; either
00011 // version 2 of the License, or (at your option) any later version.
00012 //
00013 // This library is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016 // Library General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU Library General Public
00019 // License along with this library; if not, write to the Free Software
00020 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00021 // USA.
00022 //
00023 // Please report all bugs and problems on the following page:
00024 //
00025 //     http://www.fltk.org/str.php
00026 //
00027 
00031 #ifndef Fl_Widget_H
00032 #define Fl_Widget_H
00033 
00034 #include "Enumerations.H"
00035 
00039 #ifdef _WIN64
00040 #ifdef __GNUC__
00041 #include <stdint.h>
00042 #else
00043 #include <stddef.h>  // M$VC
00044 #endif
00045 typedef intptr_t fl_intptr_t;
00046 typedef uintptr_t fl_uintptr_t;
00047 #else
00048 typedef long fl_intptr_t;
00049 typedef unsigned long fl_uintptr_t;
00050 #endif
00051 
00052 class Fl_Widget;
00053 class Fl_Window;
00054 class Fl_Group;
00055 class Fl_Image;
00056 
00058 typedef void (Fl_Callback )(Fl_Widget*, void*);
00060 typedef Fl_Callback* Fl_Callback_p; // needed for BORLAND
00062 typedef void (Fl_Callback0)(Fl_Widget*);
00064 typedef void (Fl_Callback1)(Fl_Widget*, long);
00065 
00073 struct FL_EXPORT Fl_Label {
00075   const char* value;
00077   Fl_Image* image;
00079   Fl_Image* deimage;
00081   Fl_Font font;
00083   Fl_Fontsize size;
00085   Fl_Color color;
00087   Fl_Align align_;
00089   uchar type;
00090 
00092   void draw(int,int,int,int, Fl_Align) const ;
00093   void measure(int &w, int &h) const ;
00094 };
00095 
00096 
00109 class FL_EXPORT Fl_Widget {
00110   friend class Fl_Group;
00111 
00112   Fl_Group* parent_;
00113   Fl_Callback* callback_;
00114   void* user_data_;
00115   int x_,y_,w_,h_;
00116   Fl_Label label_;
00117   unsigned int flags_;
00118   Fl_Color color_;
00119   Fl_Color color2_;
00120   uchar type_;
00121   uchar damage_;
00122   uchar box_;
00123   uchar when_;
00124 
00125   const char *tooltip_;
00126 
00128   Fl_Widget(const Fl_Widget &);
00130   Fl_Widget& operator=(const Fl_Widget &);
00131 
00132 protected:
00133 
00144   Fl_Widget(int x, int y, int w, int h, const char *label=0L);
00145 
00147   void x(int v) {x_ = v;}
00149   void y(int v) {y_ = v;}
00151   void w(int v) {w_ = v;}
00153   void h(int v) {h_ = v;}
00155   unsigned int flags() const {return flags_;}
00157   void set_flag(unsigned int c) {flags_ |= c;}
00159   void clear_flag(unsigned int c) {flags_ &= ~c;}
00163   enum {
00164         INACTIVE        = 1<<0,   
00165         INVISIBLE       = 1<<1,   
00166         OUTPUT          = 1<<2,   
00167         NOBORDER        = 1<<3,   
00168         FORCE_POSITION  = 1<<4,   
00169         NON_MODAL       = 1<<5,   
00170         SHORTCUT_LABEL  = 1<<6,   
00171         CHANGED         = 1<<7,   
00172         OVERRIDE        = 1<<8,   
00173         VISIBLE_FOCUS   = 1<<9,   
00174         COPIED_LABEL    = 1<<10,  
00175         CLIP_CHILDREN   = 1<<11,  
00176         MENU_WINDOW     = 1<<12,  
00177         TOOLTIP_WINDOW  = 1<<13,  
00178         MODAL           = 1<<14,  
00179         NO_OVERLAY      = 1<<15,  
00180         GROUP_RELATIVE  = 1<<16,  
00181         COPIED_TOOLTIP  = 1<<17,  
00182         // (space for more flags)
00183         USERFLAG3       = 1<<29,  
00184         USERFLAG2       = 1<<30,  
00185         USERFLAG1       = 1<<31   
00186   };
00187   void draw_box() const;
00188   void draw_box(Fl_Boxtype t, Fl_Color c) const;
00189   void draw_box(Fl_Boxtype t, int x,int y,int w,int h, Fl_Color c) const;
00190   void draw_backdrop() const;
00192   void draw_focus() {draw_focus(box(),x(),y(),w(),h());}
00193   void draw_focus(Fl_Boxtype t, int x,int y,int w,int h) const;
00194   void draw_label() const;
00195   void draw_label(int, int, int, int) const;
00196 
00197 public:
00198 
00207   virtual ~Fl_Widget();
00208 
00225   virtual void draw() = 0;
00226 
00243   virtual int handle(int event);
00244 
00250   Fl_Group* parent() const {return parent_;}
00251 
00260   void parent(Fl_Group* p) {parent_ = p;} // for hacks only, use Fl_Group::add()
00261 
00270   uchar type() const {return type_;}
00271 
00275   void type(uchar t) {type_ = t;}
00276 
00280   int x() const {return x_;}
00281 
00285   int y() const {return y_;}
00286 
00290   int w() const {return w_;}
00291 
00295   int h() const {return h_;}
00296 
00316   virtual void resize(int x, int y, int w, int h);
00317 
00319   int damage_resize(int,int,int,int);
00320 
00328   void position(int X,int Y) {resize(X,Y,w_,h_);}
00329 
00337   void size(int W,int H) {resize(x_,y_,W,H);}
00338 
00344   Fl_Align align() const {return label_.align_;}
00345 
00353   void align(Fl_Align alignment) {label_.align_ = alignment;}
00354 
00359   Fl_Boxtype box() const {return (Fl_Boxtype)box_;}
00360   
00368   void box(Fl_Boxtype new_box) {box_ = new_box;}
00369 
00374   Fl_Color color() const {return color_;}
00375 
00386   void color(Fl_Color bg) {color_ = bg;}
00387 
00392   Fl_Color selection_color() const {return color2_;}
00393 
00402   void selection_color(Fl_Color a) {color2_ = a;}
00403 
00411   void color(Fl_Color bg, Fl_Color sel) {color_=bg; color2_=sel;}
00412 
00417   const char* label() const {return label_.value;}
00418 
00429   void label(const char* text);
00430 
00441   void copy_label(const char *new_label);
00442 
00446   void label(Fl_Labeltype a, const char* b) {label_.type = a; label_.value = b;}
00447 
00452   Fl_Labeltype labeltype() const {return (Fl_Labeltype)label_.type;}
00453 
00462   void labeltype(Fl_Labeltype a) {label_.type = a;}
00463 
00468   Fl_Color labelcolor() const {return label_.color;}
00469 
00474   void labelcolor(Fl_Color c) {label_.color=c;}
00475 
00483   Fl_Font labelfont() const {return label_.font;}
00484 
00492   void labelfont(Fl_Font f) {label_.font=f;}
00493 
00498   Fl_Fontsize labelsize() const {return label_.size;}
00499 
00504   void labelsize(Fl_Fontsize pix) {label_.size=pix;}
00505 
00510   Fl_Image* image() {return label_.image;}
00511   const Fl_Image* image() const {return label_.image;}
00512 
00517   void image(Fl_Image* img) {label_.image=img;}
00518 
00523   void image(Fl_Image& img) {label_.image=&img;}
00524 
00529   Fl_Image* deimage() {return label_.deimage;}
00530   const Fl_Image* deimage() const {return label_.deimage;}
00531 
00536   void deimage(Fl_Image* img) {label_.deimage=img;}
00537 
00542   void deimage(Fl_Image& img) {label_.deimage=&img;}
00543 
00548   const char *tooltip() const {return tooltip_;}
00549 
00550   void tooltip(const char *text);               // see Fl_Tooltip
00551   void copy_tooltip(const char *text);          // see Fl_Tooltip
00552 
00557   Fl_Callback_p callback() const {return callback_;}
00558 
00564   void callback(Fl_Callback* cb, void* p) {callback_=cb; user_data_=p;}
00565 
00570   void callback(Fl_Callback* cb) {callback_=cb;}
00571 
00576   void callback(Fl_Callback0*cb) {callback_=(Fl_Callback*)cb;}
00577 
00583   void callback(Fl_Callback1*cb, long p=0) {callback_=(Fl_Callback*)cb; user_data_=(void*)p;}
00584 
00589   void* user_data() const {return user_data_;}
00590 
00595   void user_data(void* v) {user_data_ = v;}
00596 
00599   long argument() const {return (long)(fl_intptr_t)user_data_;}
00600 
00605   void argument(long v) {user_data_ = (void*)v;}
00606 
00615   Fl_When when() const {return (Fl_When)when_;}
00616 
00648   void when(uchar i) {when_ = i;}
00649 
00654   unsigned int visible() const {return !(flags_&INVISIBLE);}
00655 
00660   int visible_r() const;
00661 
00676   virtual void show();
00677   
00681   virtual void hide();
00682 
00687   void set_visible() {flags_ &= ~INVISIBLE;}
00688 
00693   void clear_visible() {flags_ |= INVISIBLE;}
00694 
00699   unsigned int active() const {return !(flags_&INACTIVE);}
00700 
00705   int active_r() const;
00706 
00712   void activate();
00713 
00728   void deactivate();
00729 
00738   unsigned int output() const {return (flags_&OUTPUT);}
00739 
00743   void set_output() {flags_ |= OUTPUT;}
00744 
00748   void clear_output() {flags_ &= ~OUTPUT;}
00749 
00755   unsigned int takesevents() const {
00756     return !output() && active_r() && visible_r();
00757   }
00758 
00774   unsigned int changed() const {return flags_&CHANGED;}
00775 
00779   void set_changed() {flags_ |= CHANGED;}
00780 
00784   void clear_changed() {flags_ &= ~CHANGED;}
00785 
00793   int take_focus();
00794 
00801   void set_visible_focus() { flags_ |= VISIBLE_FOCUS; }
00802 
00807   void clear_visible_focus() { flags_ &= ~VISIBLE_FOCUS; }
00808 
00813   void visible_focus(int v) { if (v) set_visible_focus(); else clear_visible_focus(); }
00814 
00819   unsigned int  visible_focus() { return flags_ & VISIBLE_FOCUS; }
00820 
00828   static void default_callback(Fl_Widget *cb, void *d);
00829 
00834   void do_callback() {do_callback(this,user_data_);}
00835 
00842   void do_callback(Fl_Widget* o,long arg) {do_callback(o,(void*)arg);}
00843 
00844   // Causes a widget to invoke its callback function with arbitrary arguments.
00845   // Documentation and implementation in Fl_Widget.cxx
00846   void do_callback(Fl_Widget* o,void* arg=0);
00847 
00848   /* Internal use only. */
00849   int test_shortcut();
00850   /* Internal use only. */
00851   static unsigned int label_shortcut(const char *t);
00852   /* Internal use only. */
00853   static int test_shortcut(const char*, const bool require_alt = false);
00854 
00860   int contains(const Fl_Widget *w) const ;
00861 
00868   int inside(const Fl_Widget* w) const {return w ? w->contains(this) : 0;}
00869 
00873   void redraw();
00874 
00879   void redraw_label();
00880 
00887   uchar damage() const {return damage_;}
00888 
00901   void clear_damage(uchar c = 0) {damage_ = c;}
00902 
00908   void damage(uchar c);
00909 
00916   void damage(uchar c, int x, int y, int w, int h);
00917 
00918   void draw_label(int, int, int, int, Fl_Align) const;
00919 
00923   void measure_label(int& ww, int& hh) const {label_.measure(ww, hh);}
00924 
00930   Fl_Window* window() const ;
00931 
00955   virtual Fl_Group* as_group() {return 0;}
00956 
00969   virtual Fl_Window* as_window() {return 0;}
00970 
00981   virtual class Fl_Gl_Window* as_gl_window() {return 0;}
00982   
00986   Fl_Color color2() const {return (Fl_Color)color2_;}
00987 
00991   void color2(unsigned a) {color2_ = a;}
00992 };
00993 
00999 #define FL_RESERVED_TYPE 100
01000 
01001 #endif
01002 
01003 //
01004 // End of "$Id$".
01005 //