• Main Page
  • Related Pages
  • Modules
  • Classes
  • Files
  • File List
  • File Members

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-2015 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 #if defined(__GNUC__) || defined(__clang__)
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 
00065 struct FL_EXPORT Fl_Label {
00067   const char* value;
00069   Fl_Image* image;
00071   Fl_Image* deimage;
00073   Fl_Font font;
00075   Fl_Fontsize size;
00077   Fl_Color color;
00079   Fl_Align align_;
00081   uchar type;
00082 
00084   void draw(int,int,int,int, Fl_Align) const ;
00085   void measure(int &w, int &h) const ;
00086 };
00087 
00088 
00101 class FL_EXPORT Fl_Widget {
00102   friend class Fl_Group;
00103 
00104   Fl_Group* parent_;
00105   Fl_Callback* callback_;
00106   void* user_data_;
00107   int x_,y_,w_,h_;
00108   Fl_Label label_;
00109   unsigned int flags_;
00110   Fl_Color color_;
00111   Fl_Color color2_;
00112   uchar type_;
00113   uchar damage_;
00114   uchar box_;
00115   uchar when_;
00116 
00117   const char *tooltip_;
00118 
00120   Fl_Widget(const Fl_Widget &);
00122   Fl_Widget& operator=(const Fl_Widget &);
00123 
00124 protected:
00125 
00136   Fl_Widget(int x, int y, int w, int h, const char *label=0L);
00137 
00139   void x(int v) {x_ = v;}
00141   void y(int v) {y_ = v;}
00143   void w(int v) {w_ = v;}
00145   void h(int v) {h_ = v;}
00147   unsigned int flags() const {return flags_;}
00149   void set_flag(unsigned int c) {flags_ |= c;}
00151   void clear_flag(unsigned int c) {flags_ &= ~c;}
00155   enum {
00156         INACTIVE        = 1<<0,   
00157         INVISIBLE       = 1<<1,   
00158         OUTPUT          = 1<<2,   
00159         NOBORDER        = 1<<3,   
00160         FORCE_POSITION  = 1<<4,   
00161         NON_MODAL       = 1<<5,   
00162         SHORTCUT_LABEL  = 1<<6,   
00163         CHANGED         = 1<<7,   
00164         OVERRIDE        = 1<<8,   
00165         VISIBLE_FOCUS   = 1<<9,   
00166         COPIED_LABEL    = 1<<10,  
00167         CLIP_CHILDREN   = 1<<11,  
00168         MENU_WINDOW     = 1<<12,  
00169         TOOLTIP_WINDOW  = 1<<13,  
00170         MODAL           = 1<<14,  
00171         NO_OVERLAY      = 1<<15,  
00172         GROUP_RELATIVE  = 1<<16,  
00173         COPIED_TOOLTIP  = 1<<17,  
00174         FULLSCREEN      = 1<<18,  
00175         MAC_USE_ACCENTS_MENU = 1<<19, 
00176         // (space for more flags)
00177         USERFLAG3       = 1<<29,  
00178         USERFLAG2       = 1<<30,  
00179         USERFLAG1       = 1<<31   
00180   };
00181   void draw_box() const;
00182   void draw_box(Fl_Boxtype t, Fl_Color c) const;
00183   void draw_box(Fl_Boxtype t, int x,int y,int w,int h, Fl_Color c) const;
00184   void draw_backdrop() const;
00186   void draw_focus() {draw_focus(box(),x(),y(),w(),h());}
00187   void draw_focus(Fl_Boxtype t, int x,int y,int w,int h) const;
00188   void draw_label() const;
00189   void draw_label(int, int, int, int) const;
00190 
00191 public:
00192 
00201   virtual ~Fl_Widget();
00202 
00219   virtual void draw() = 0;
00220 
00237   virtual int handle(int event);
00238 
00247   int is_label_copied() const {return ((flags_ & COPIED_LABEL) ? 1 : 0);}
00248 
00254   Fl_Group* parent() const {return parent_;}
00255 
00264   void parent(Fl_Group* p) {parent_ = p;} // for hacks only, use Fl_Group::add()
00265 
00274   uchar type() const {return type_;}
00275 
00279   void type(uchar t) {type_ = t;}
00280 
00284   int x() const {return x_;}
00285 
00289   int y() const {return y_;}
00290 
00294   int w() const {return w_;}
00295 
00299   int h() const {return h_;}
00300 
00320   virtual void resize(int x, int y, int w, int h);
00321 
00323   int damage_resize(int,int,int,int);
00324 
00332   void position(int X,int Y) {resize(X,Y,w_,h_);}
00333 
00341   void size(int W,int H) {resize(x_,y_,W,H);}
00342 
00348   Fl_Align align() const {return label_.align_;}
00349 
00357   void align(Fl_Align alignment) {label_.align_ = alignment;}
00358 
00363   Fl_Boxtype box() const {return (Fl_Boxtype)box_;}
00364   
00372   void box(Fl_Boxtype new_box) {box_ = new_box;}
00373 
00378   Fl_Color color() const {return color_;}
00379 
00390   void color(Fl_Color bg) {color_ = bg;}
00391 
00396   Fl_Color selection_color() const {return color2_;}
00397 
00406   void selection_color(Fl_Color a) {color2_ = a;}
00407 
00415   void color(Fl_Color bg, Fl_Color sel) {color_=bg; color2_=sel;}
00416 
00421   const char* label() const {return label_.value;}
00422 
00433   void label(const char* text);
00434 
00445   void copy_label(const char *new_label);
00446 
00450   void label(Fl_Labeltype a, const char* b) {label_.type = a; label_.value = b;}
00451 
00456   Fl_Labeltype labeltype() const {return (Fl_Labeltype)label_.type;}
00457 
00466   void labeltype(Fl_Labeltype a) {label_.type = a;}
00467 
00472   Fl_Color labelcolor() const {return label_.color;}
00473 
00478   void labelcolor(Fl_Color c) {label_.color=c;}
00479 
00487   Fl_Font labelfont() const {return label_.font;}
00488 
00496   void labelfont(Fl_Font f) {label_.font=f;}
00497 
00502   Fl_Fontsize labelsize() const {return label_.size;}
00503 
00508   void labelsize(Fl_Fontsize pix) {label_.size=pix;}
00509 
00514   Fl_Image* image() {return label_.image;}
00515   const Fl_Image* image() const {return label_.image;}
00516 
00521   void image(Fl_Image* img) {label_.image=img;}
00522 
00527   void image(Fl_Image& img) {label_.image=&img;}
00528 
00533   Fl_Image* deimage() {return label_.deimage;}
00534   const Fl_Image* deimage() const {return label_.deimage;}
00535 
00540   void deimage(Fl_Image* img) {label_.deimage=img;}
00541 
00546   void deimage(Fl_Image& img) {label_.deimage=&img;}
00547 
00552   const char *tooltip() const {return tooltip_;}
00553 
00554   void tooltip(const char *text);               // see Fl_Tooltip
00555   void copy_tooltip(const char *text);          // see Fl_Tooltip
00556 
00561   Fl_Callback_p callback() const {return callback_;}
00562 
00568   void callback(Fl_Callback* cb, void* p) {callback_=cb; user_data_=p;}
00569 
00574   void callback(Fl_Callback* cb) {callback_=cb;}
00575 
00580   void callback(Fl_Callback0*cb) {callback_=(Fl_Callback*)cb;}
00581 
00587   void callback(Fl_Callback1*cb, long p=0) {callback_=(Fl_Callback*)cb; user_data_=(void*)(fl_intptr_t)p;}
00588 
00593   void* user_data() const {return user_data_;}
00594 
00599   void user_data(void* v) {user_data_ = v;}
00600 
00605   long argument() const {return (long)(fl_intptr_t)user_data_;}
00606 
00611   void argument(long v) {user_data_ = (void*)(fl_intptr_t)v;}
00612 
00621   Fl_When when() const {return (Fl_When)when_;}
00622 
00654   void when(uchar i) {when_ = i;}
00655 
00660   unsigned int visible() const {return !(flags_&INVISIBLE);}
00661 
00666   int visible_r() const;
00667 
00685   virtual void show();
00686   
00690   virtual void hide();
00691 
00696   void set_visible() {flags_ &= ~INVISIBLE;}
00697 
00702   void clear_visible() {flags_ |= INVISIBLE;}
00703 
00708   unsigned int active() const {return !(flags_&INACTIVE);}
00709 
00714   int active_r() const;
00715 
00721   void activate();
00722 
00737   void deactivate();
00738 
00747   unsigned int output() const {return (flags_&OUTPUT);}
00748 
00752   void set_output() {flags_ |= OUTPUT;}
00753 
00757   void clear_output() {flags_ &= ~OUTPUT;}
00758 
00764   unsigned int takesevents() const {return !(flags_&(INACTIVE|INVISIBLE|OUTPUT));}
00765 
00781   unsigned int changed() const {return flags_&CHANGED;}
00782 
00786   void set_changed() {flags_ |= CHANGED;}
00787 
00791   void clear_changed() {flags_ &= ~CHANGED;}
00792 
00797   void clear_active() {flags_ |= INACTIVE;}
00798 
00803   void set_active() {flags_ &= ~INACTIVE;}
00804 
00812   int take_focus();
00813 
00820   void set_visible_focus() { flags_ |= VISIBLE_FOCUS; }
00821 
00826   void clear_visible_focus() { flags_ &= ~VISIBLE_FOCUS; }
00827 
00832   void visible_focus(int v) { if (v) set_visible_focus(); else clear_visible_focus(); }
00833 
00838   unsigned int  visible_focus() { return flags_ & VISIBLE_FOCUS; }
00839 
00855   static void default_callback(Fl_Widget *cb, void *d);
00856 
00861   void do_callback() {do_callback(this,user_data_);}
00862 
00869   void do_callback(Fl_Widget* o,long arg) {do_callback(o,(void*)(fl_intptr_t)arg);}
00870 
00871   // Causes a widget to invoke its callback function with arbitrary arguments.
00872   // Documentation and implementation in Fl_Widget.cxx
00873   void do_callback(Fl_Widget* o,void* arg=0);
00874 
00875   /* Internal use only. */
00876   int test_shortcut();
00877   /* Internal use only. */
00878   static unsigned int label_shortcut(const char *t);
00879   /* Internal use only. */
00880   static int test_shortcut(const char*, const bool require_alt = false);
00881   /* Internal use only. */
00882   void _set_fullscreen() {flags_ |= FULLSCREEN;}
00883   void _clear_fullscreen() {flags_ &= ~FULLSCREEN;}
00884 
00890   int contains(const Fl_Widget *w) const ;
00891 
00898   int inside(const Fl_Widget* wgt) const {return wgt ? wgt->contains(this) : 0;}
00899 
00903   void redraw();
00904 
00909   void redraw_label();
00910 
00917   uchar damage() const {return damage_;}
00918 
00931   void clear_damage(uchar c = 0) {damage_ = c;}
00932 
00938   void damage(uchar c);
00939 
00946   void damage(uchar c, int x, int y, int w, int h);
00947 
00948   void draw_label(int, int, int, int, Fl_Align) const;
00949 
00957   void measure_label(int& ww, int& hh) const {label_.measure(ww, hh);}
00958 
00959   Fl_Window* window() const ;
00960   Fl_Window* top_window() const;
00961   Fl_Window* top_window_offset(int& xoff, int& yoff) const;
00962 
00986   virtual Fl_Group* as_group() {return 0;}
00987 
01000   virtual Fl_Window* as_window() {return 0;}
01001 
01012   virtual class Fl_Gl_Window* as_gl_window() {return 0;}
01013   
01016   int use_accents_menu() { return flags() & MAC_USE_ACCENTS_MENU; }
01017   
01021   Fl_Color color2() const {return (Fl_Color)color2_;}
01022 
01026   void color2(unsigned a) {color2_ = a;}
01027 };
01028 
01034 #define FL_RESERVED_TYPE 100
01035 
01036 #endif
01037 
01038 //
01039 // End of "$Id$".
01040 //
  • © 1998-2016 by Bill Spitzak and others.     FLTK

  • © 1998-2016 by Bill Spitzak and others.     FLTK

    Permission is granted to reproduce this manual or any portion for any purpose, provided this copyright and permission notice are preserved.