FLTK 1.3.0
|
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 // (space for more flags) 00175 USERFLAG3 = 1<<29, 00176 USERFLAG2 = 1<<30, 00177 USERFLAG1 = 1<<31 00178 }; 00179 void draw_box() const; 00180 void draw_box(Fl_Boxtype t, Fl_Color c) const; 00181 void draw_box(Fl_Boxtype t, int x,int y,int w,int h, Fl_Color c) const; 00182 void draw_backdrop() const; 00184 void draw_focus() {draw_focus(box(),x(),y(),w(),h());} 00185 void draw_focus(Fl_Boxtype t, int x,int y,int w,int h) const; 00186 void draw_label() const; 00187 void draw_label(int, int, int, int) const; 00188 00189 public: 00190 00199 virtual ~Fl_Widget(); 00200 00217 virtual void draw() = 0; 00218 00235 virtual int handle(int event); 00236 00242 Fl_Group* parent() const {return parent_;} 00243 00252 void parent(Fl_Group* p) {parent_ = p;} // for hacks only, use Fl_Group::add() 00253 00262 uchar type() const {return type_;} 00263 00267 void type(uchar t) {type_ = t;} 00268 00272 int x() const {return x_;} 00273 00277 int y() const {return y_;} 00278 00282 int w() const {return w_;} 00283 00287 int h() const {return h_;} 00288 00308 virtual void resize(int x, int y, int w, int h); 00309 00311 int damage_resize(int,int,int,int); 00312 00320 void position(int X,int Y) {resize(X,Y,w_,h_);} 00321 00329 void size(int W,int H) {resize(x_,y_,W,H);} 00330 00336 Fl_Align align() const {return label_.align_;} 00337 00345 void align(Fl_Align alignment) {label_.align_ = alignment;} 00346 00351 Fl_Boxtype box() const {return (Fl_Boxtype)box_;} 00352 00360 void box(Fl_Boxtype new_box) {box_ = new_box;} 00361 00366 Fl_Color color() const {return color_;} 00367 00378 void color(Fl_Color bg) {color_ = bg;} 00379 00384 Fl_Color selection_color() const {return color2_;} 00385 00394 void selection_color(Fl_Color a) {color2_ = a;} 00395 00403 void color(Fl_Color bg, Fl_Color sel) {color_=bg; color2_=sel;} 00404 00409 const char* label() const {return label_.value;} 00410 00421 void label(const char* text); 00422 00433 void copy_label(const char *new_label); 00434 00438 void label(Fl_Labeltype a, const char* b) {label_.type = a; label_.value = b;} 00439 00444 Fl_Labeltype labeltype() const {return (Fl_Labeltype)label_.type;} 00445 00454 void labeltype(Fl_Labeltype a) {label_.type = a;} 00455 00460 Fl_Color labelcolor() const {return label_.color;} 00461 00466 void labelcolor(Fl_Color c) {label_.color=c;} 00467 00475 Fl_Font labelfont() const {return label_.font;} 00476 00484 void labelfont(Fl_Font f) {label_.font=f;} 00485 00490 Fl_Fontsize labelsize() const {return label_.size;} 00491 00496 void labelsize(Fl_Fontsize pix) {label_.size=pix;} 00497 00502 Fl_Image* image() {return label_.image;} 00503 const Fl_Image* image() const {return label_.image;} 00504 00509 void image(Fl_Image* img) {label_.image=img;} 00510 00515 void image(Fl_Image& img) {label_.image=&img;} 00516 00521 Fl_Image* deimage() {return label_.deimage;} 00522 const Fl_Image* deimage() const {return label_.deimage;} 00523 00528 void deimage(Fl_Image* img) {label_.deimage=img;} 00529 00534 void deimage(Fl_Image& img) {label_.deimage=&img;} 00535 00540 const char *tooltip() const {return tooltip_;} 00541 00542 void tooltip(const char *text); // see Fl_Tooltip 00543 void copy_tooltip(const char *text); // see Fl_Tooltip 00544 00549 Fl_Callback_p callback() const {return callback_;} 00550 00556 void callback(Fl_Callback* cb, void* p) {callback_=cb; user_data_=p;} 00557 00562 void callback(Fl_Callback* cb) {callback_=cb;} 00563 00568 void callback(Fl_Callback0*cb) {callback_=(Fl_Callback*)cb;} 00569 00575 void callback(Fl_Callback1*cb, long p=0) {callback_=(Fl_Callback*)cb; user_data_=(void*)p;} 00576 00581 void* user_data() const {return user_data_;} 00582 00587 void user_data(void* v) {user_data_ = v;} 00588 00591 long argument() const {return (long)(fl_intptr_t)user_data_;} 00592 00597 void argument(long v) {user_data_ = (void*)v;} 00598 00607 Fl_When when() const {return (Fl_When)when_;} 00608 00640 void when(uchar i) {when_ = i;} 00641 00646 unsigned int visible() const {return !(flags_&INVISIBLE);} 00647 00652 int visible_r() const; 00653 00671 virtual void show(); 00672 00676 virtual void hide(); 00677 00682 void set_visible() {flags_ &= ~INVISIBLE;} 00683 00688 void clear_visible() {flags_ |= INVISIBLE;} 00689 00694 unsigned int active() const {return !(flags_&INACTIVE);} 00695 00700 int active_r() const; 00701 00707 void activate(); 00708 00723 void deactivate(); 00724 00733 unsigned int output() const {return (flags_&OUTPUT);} 00734 00738 void set_output() {flags_ |= OUTPUT;} 00739 00743 void clear_output() {flags_ &= ~OUTPUT;} 00744 00750 unsigned int takesevents() const {return !(flags_&(INACTIVE|INVISIBLE|OUTPUT));} 00751 00767 unsigned int changed() const {return flags_&CHANGED;} 00768 00772 void set_changed() {flags_ |= CHANGED;} 00773 00777 void clear_changed() {flags_ &= ~CHANGED;} 00778 00786 int take_focus(); 00787 00794 void set_visible_focus() { flags_ |= VISIBLE_FOCUS; } 00795 00800 void clear_visible_focus() { flags_ &= ~VISIBLE_FOCUS; } 00801 00806 void visible_focus(int v) { if (v) set_visible_focus(); else clear_visible_focus(); } 00807 00812 unsigned int visible_focus() { return flags_ & VISIBLE_FOCUS; } 00813 00821 static void default_callback(Fl_Widget *cb, void *d); 00822 00827 void do_callback() {do_callback(this,user_data_);} 00828 00835 void do_callback(Fl_Widget* o,long arg) {do_callback(o,(void*)arg);} 00836 00837 // Causes a widget to invoke its callback function with arbitrary arguments. 00838 // Documentation and implementation in Fl_Widget.cxx 00839 void do_callback(Fl_Widget* o,void* arg=0); 00840 00841 /* Internal use only. */ 00842 int test_shortcut(); 00843 /* Internal use only. */ 00844 static unsigned int label_shortcut(const char *t); 00845 /* Internal use only. */ 00846 static int test_shortcut(const char*, const bool require_alt = false); 00847 /* Internal use only. */ 00848 void _set_fullscreen() {flags_ |= FULLSCREEN;} 00849 void _clear_fullscreen() {flags_ &= ~FULLSCREEN;} 00850 00856 int contains(const Fl_Widget *w) const ; 00857 00864 int inside(const Fl_Widget* wgt) const {return wgt ? wgt->contains(this) : 0;} 00865 00869 void redraw(); 00870 00875 void redraw_label(); 00876 00883 uchar damage() const {return damage_;} 00884 00897 void clear_damage(uchar c = 0) {damage_ = c;} 00898 00904 void damage(uchar c); 00905 00912 void damage(uchar c, int x, int y, int w, int h); 00913 00914 void draw_label(int, int, int, int, Fl_Align) const; 00915 00919 void measure_label(int& ww, int& hh) const {label_.measure(ww, hh);} 00920 00926 Fl_Window* window() const ; 00927 00951 virtual Fl_Group* as_group() {return 0;} 00952 00965 virtual Fl_Window* as_window() {return 0;} 00966 00977 virtual class Fl_Gl_Window* as_gl_window() {return 0;} 00978 00982 Fl_Color color2() const {return (Fl_Color)color2_;} 00983 00987 void color2(unsigned a) {color2_ = a;} 00988 }; 00989 00995 #define FL_RESERVED_TYPE 100 00996 00997 #endif 00998 00999 // 01000 // End of "$Id$". 01001 //