FLTK 1.3.0
Fl.H
Go to the documentation of this file.
00001 //
00002 // "$Id$"
00003 //
00004 // Main 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. 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 
00023 #ifndef Fl_H
00024 #  define Fl_H
00025 
00026 #ifdef FLTK_HAVE_CAIRO
00027 # include <FL/Fl_Cairo.H>
00028 #endif
00029 
00030 #  include "fl_utf8.h"
00031 #  include "Enumerations.H"
00032 #  ifndef Fl_Object
00033 #    define Fl_Object Fl_Widget 
00034 #  endif
00035 
00036 #  ifdef check
00037 #    undef check
00038 #  endif
00039 
00040 
00041 class Fl_Widget;
00042 class Fl_Window;
00043 class Fl_Image;
00044 struct Fl_Label;
00045 
00046 // Keep avoiding having the socket deps at that level but mke sure it will work in both 32 & 64 bit builds
00047 #if defined(WIN32) && !defined(__CYGWIN__)
00048 # if defined(_WIN64)
00049 #  define FL_SOCKET unsigned __int64
00050 # else
00051 #  define FL_SOCKET int
00052 # endif
00053 #else
00054 # define FL_SOCKET int
00055 #endif
00056 
00073 typedef void (Fl_Label_Draw_F)(const Fl_Label *label, int x, int y, int w, int h, Fl_Align align);
00074 
00076 typedef void (Fl_Label_Measure_F)(const Fl_Label *label, int &width, int &height);
00077 
00079 typedef void (Fl_Box_Draw_F)(int x, int y, int w, int h, Fl_Color color);
00080 
00082 typedef void (*Fl_Timeout_Handler)(void *data);
00083 
00085 typedef void (*Fl_Awake_Handler)(void *data);
00086 
00088 typedef void (*Fl_Idle_Handler)(void *data);
00089 
00091 typedef void (*Fl_Old_Idle_Handler)();
00092 
00094 typedef void (*Fl_FD_Handler)(FL_SOCKET fd, void *data);
00095 
00097 typedef int (*Fl_Event_Handler)(int event);
00098 
00100 typedef void (*Fl_Abort_Handler)(const char *format,...);
00101 
00103 typedef void (*Fl_Atclose_Handler)(Fl_Window *window, void *data);
00104 
00106 typedef int (*Fl_Args_Handler)(int argc, char **argv, int &i);
00107 
00110 typedef int (*Fl_Event_Dispatch)(int event, Fl_Window *w);
00111  /* group callback_functions */
00113 
00114 
00119 class FL_EXPORT Fl {
00120   Fl() {}; // no constructor!
00121   
00122 public: // should be private!
00123 #ifndef FL_DOXYGEN
00124   static int e_number;
00125   static int e_x;
00126   static int e_y;
00127   static int e_x_root;
00128   static int e_y_root;
00129   static int e_dx;
00130   static int e_dy;
00131   static int e_state;
00132   static int e_clicks;
00133   static int e_is_click;
00134   static int e_keysym;
00135   static char* e_text;
00136   static int e_length;
00137   static Fl_Event_Dispatch e_dispatch;
00138   static Fl_Widget* belowmouse_;
00139   static Fl_Widget* pushed_;
00140   static Fl_Widget* focus_;
00141   static int damage_;
00142   static Fl_Widget* selection_owner_;
00143   static Fl_Window* modal_;
00144   static Fl_Window* grab_;
00145   static int compose_state;
00146   static void call_screen_init(); // recompute screen number and dimensions
00147 #endif
00148 
00151   static void damage(int d) {damage_ = d;}
00152   
00153 public:
00160   typedef enum {
00165     OPTION_ARROW_FOCUS = 0,
00166       // When switched on, FLTK will use the file chooser dialog that comes 
00167       // with your operating system whenever possible. When switched off, FLTK
00168       // will present its own file chooser.
00169       // \todo implement me
00170     // OPTION_NATIVE_FILECHOOSER,
00171       // When Filechooser Preview is enabled, the FLTK or native file chooser
00172       // will show a preview of a selected file (if possible) before the user
00173       // decides to choose the file.
00174       // \todo implement me
00175     //OPTION_FILECHOOSER_PREVIEW,
00180     OPTION_VISIBLE_FOCUS,
00184     OPTION_DND_TEXT,
00188     OPTION_SHOW_TOOLTIPS,
00189       // don't change this, leave it always as the last element
00191     OPTION_LAST
00192   } Fl_Option;
00193 
00194 private:  
00195   static unsigned char options_[OPTION_LAST];
00196   static unsigned char options_read_;
00197   
00198 public:  
00199   /*
00200    Return a global setting for all FLTK applications, possibly overridden
00201    by a setting specifically for this application.
00202    */
00203   static bool option(Fl_Option opt);
00204   
00205   /*
00206    Override an option while the application is running.
00207    */
00208   static void option(Fl_Option opt, bool val);
00209   
00217   static void (*idle)();
00218 
00219 #ifndef FL_DOXYGEN
00220   static Fl_Awake_Handler *awake_ring_;
00221   static void **awake_data_;
00222   static int awake_ring_size_;
00223   static int awake_ring_head_;
00224   static int awake_ring_tail_;
00225   static const char* scheme_;
00226   static Fl_Image* scheme_bg_;
00227 
00228   static int e_original_keysym; // late addition
00229   static int scrollbar_size_;
00230 #endif
00231 
00232 
00233   static int add_awake_handler_(Fl_Awake_Handler, void*);
00234   static int get_awake_handler_(Fl_Awake_Handler&, void*&);
00235 
00236 public:
00237 
00238   // API version number
00239   static double version();
00240 
00241   // argument parsers:
00242   static int arg(int argc, char **argv, int& i);
00243   static int args(int argc, char **argv, int& i, Fl_Args_Handler cb = 0);
00244   static void args(int argc, char **argv);
00249   static const char* const help;
00250 
00251   // things called by initialization:
00252   static void display(const char*);
00253   static int visual(int);
00263   static int gl_visual(int, int *alist=0); // platform dependent
00264   static void own_colormap();
00265   static void get_system_colors();
00266   static void foreground(uchar, uchar, uchar);
00267   static void background(uchar, uchar, uchar);
00268   static void background2(uchar, uchar, uchar);
00269 
00270   // schemes:
00271   static int scheme(const char*);
00273   static const char* scheme() {return scheme_;}
00279   static int reload_scheme(); // platform dependent
00280   static int scrollbar_size();
00281   static void scrollbar_size(int W);
00282 
00283   // execution:
00284   static int wait();
00285   static double wait(double time);
00286   static int check();
00287   static int ready();
00288   static int run();
00289   static Fl_Widget* readqueue();
00316   static void add_timeout(double t, Fl_Timeout_Handler,void* = 0); // platform dependent
00337   static void repeat_timeout(double t, Fl_Timeout_Handler, void* = 0); // platform dependent
00338   static int  has_timeout(Fl_Timeout_Handler, void* = 0);
00339   static void remove_timeout(Fl_Timeout_Handler, void* = 0);
00340   static void add_check(Fl_Timeout_Handler, void* = 0);
00341   static int  has_check(Fl_Timeout_Handler, void* = 0);
00342   static void remove_check(Fl_Timeout_Handler, void* = 0);
00362   static void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0); // platform dependent
00364   static void add_fd(int fd, Fl_FD_Handler cb, void* = 0); // platform dependent
00366   static void remove_fd(int, int when); // platform dependent
00368   static void remove_fd(int); // platform dependent
00369 
00370   static void add_idle(Fl_Idle_Handler cb, void* data = 0);
00371   static int  has_idle(Fl_Idle_Handler cb, void* data = 0);
00372   static void remove_idle(Fl_Idle_Handler cb, void* data = 0);
00374   static int damage() {return damage_;}
00375   static void redraw();
00376   static void flush();
00397   static void (*warning)(const char*, ...);
00412   static void (*error)(const char*, ...);
00429   static void (*fatal)(const char*, ...);
00435   static Fl_Window* first_window();
00436   static void first_window(Fl_Window*);
00437   static Fl_Window* next_window(const Fl_Window*);
00438 
00448   static Fl_Window* modal() {return modal_;}
00454   static Fl_Window* grab() {return grab_;}
00479   static void grab(Fl_Window*); // platform dependent
00486   // event information:
00492   static int event()            {return e_number;}
00497   static int event_x()  {return e_x;}
00502   static int event_y()  {return e_y;}
00509   static int event_x_root()     {return e_x_root;}
00516   static int event_y_root()     {return e_y_root;}
00521   static int event_dx() {return e_dx;}
00526   static int event_dy() {return e_dy;}
00535   static void get_mouse(int &,int &); // platform dependent
00544   static int event_clicks()     {return e_clicks;}
00552   static void event_clicks(int i) {e_clicks = i;}
00560   static int event_is_click()   {return e_is_click;}
00567   static void event_is_click(int i) {e_is_click = i;}
00574   static int event_button()     {return e_keysym-FL_Button;}
00598   static int event_state()      {return e_state;}
00600   static int event_state(int i) {return e_state&i;}
00612   static int event_key()        {return e_keysym;}
00621   static int event_original_key(){return e_original_keysym;}
00660   static int event_key(int key);
00666   static int get_key(int key); // platform dependent
00681   static const char* event_text() {return e_text;}
00688   static int event_length() {return e_length;}
00689 
00690   static int compose(int &del);
00691   static void compose_reset();
00692   static int event_inside(int,int,int,int);
00693   static int event_inside(const Fl_Widget*);
00694   static int test_shortcut(Fl_Shortcut);
00695 
00696   // event destinations:
00697   static int handle(int, Fl_Window*);
00698   static int handle_(int, Fl_Window*);
00701   static Fl_Widget* belowmouse() {return belowmouse_;}
00702   static void belowmouse(Fl_Widget*);
00705   static Fl_Widget* pushed()    {return pushed_;}
00706   static void pushed(Fl_Widget*);
00708   static Fl_Widget* focus()     {return focus_;}
00709   static void focus(Fl_Widget*);
00710   static void add_handler(Fl_Event_Handler h);
00711   static void remove_handler(Fl_Event_Handler h);
00712   static void event_dispatch(Fl_Event_Dispatch d);
00713   static Fl_Event_Dispatch event_dispatch();
00719   // cut/paste:
00729   static void copy(const char* stuff, int len, int destination = 0); // platform dependent
00747   static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent
00757   static int dnd(); // platform dependent
00758 
00759   // These are for back-compatibility only:
00762   static Fl_Widget* selection_owner() {return selection_owner_;}
00763   static void selection_owner(Fl_Widget*);
00764   static void selection(Fl_Widget &owner, const char*, int len);
00765   static void paste(Fl_Widget &receiver);
00770   // screen size:
00772   static int x(); // platform dependent
00774   static int y(); // platform dependent
00776   static int w(); // platform dependent
00778   static int h(); // platform dependent
00779 
00780   // multi-head support:
00781   static int screen_count();
00787   static void screen_xywh(int &X, int &Y, int &W, int &H) {
00788     screen_xywh(X, Y, W, H, e_x_root, e_y_root);
00789   }
00790   static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
00791   static void screen_xywh(int &X, int &Y, int &W, int &H, int n); 
00792   static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh);
00793   static void screen_dpi(float &h, float &v, int n=0);
00794   static void screen_work_area(int &X, int &Y, int &W, int &H, int mx, int my);
00795   static void screen_work_area(int &X, int &Y, int &W, int &H, int n);
00801   static void screen_work_area(int &X, int &Y, int &W, int &H) {
00802     screen_work_area(X, Y, W, H, e_x_root, e_y_root);
00803   }
00804 
00812   // color map:
00813   static void   set_color(Fl_Color, uchar, uchar, uchar);
00818   static void   set_color(Fl_Color i, unsigned c); // platform dependent
00819   static unsigned get_color(Fl_Color i);
00820   static void   get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue);
00826   static void   free_color(Fl_Color i, int overlay = 0); // platform dependent
00827 
00828   // fonts:
00829   static const char* get_font(Fl_Font);
00842   static const char* get_font_name(Fl_Font, int* attributes = 0);
00854   static int get_font_sizes(Fl_Font, int*& sizep);
00855   static void set_font(Fl_Font, const char*);
00856   static void set_font(Fl_Font, Fl_Font);
00875   static Fl_Font set_fonts(const char* = 0); // platform dependent
00876 
00883   // <Hack to re-order the 'Drawing functions' group>
00886   // labeltypes:
00887   static void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*);
00889   static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined ?
00890 
00891   // boxtypes:
00892   static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype);
00893   static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar);
00894   static void set_boxtype(Fl_Boxtype, Fl_Boxtype from);
00895   static int box_dx(Fl_Boxtype);
00896   static int box_dy(Fl_Boxtype);
00897   static int box_dw(Fl_Boxtype);
00898   static int box_dh(Fl_Boxtype);
00899   static int draw_box_active();
00900 
00901   // back compatibility:
00905   static void set_abort(Fl_Abort_Handler f) {fatal = f;}
00906   static void (*atclose)(Fl_Window*,void*);
00907   static void default_atclose(Fl_Window*,void*);
00911   static void set_atclose(Fl_Atclose_Handler f) {atclose = f;}
00917   static int event_shift() {return e_state&FL_SHIFT;}
00919   static int event_ctrl() {return e_state&FL_CTRL;}
00921   static int event_command() {return e_state&FL_COMMAND;}
00923   static int event_alt() {return e_state&FL_ALT;}
00932   static int event_buttons() {return e_state&0x7f000000;}
00937   static int event_button1() {return e_state&FL_BUTTON1;}
00942   static int event_button2() {return e_state&FL_BUTTON2;}
00947   static int event_button3() {return e_state&FL_BUTTON3;}
00955   static void set_idle(Fl_Old_Idle_Handler cb) {idle = cb;}
00957   static void grab(Fl_Window& win) {grab(&win);}
00961   static void release() {grab(0);}
00962 
00963   // Visible focus methods...
00969   static void visible_focus(int v) { option(OPTION_VISIBLE_FOCUS, (v!=0)); }
00975   static int  visible_focus() { return option(OPTION_VISIBLE_FOCUS); }
00976 
00977   // Drag-n-drop text operation methods...
00984   static void dnd_text_ops(int v) { option(OPTION_DND_TEXT, (v!=0)); }
00991   static int  dnd_text_ops() { return option(OPTION_DND_TEXT); }
00996   // Multithreading support:
00997   static int lock();
00998   static void unlock();
00999   static void awake(void* message = 0);
01001   static int awake(Fl_Awake_Handler cb, void* message = 0);
01008   static void* thread_message(); // platform dependent
01040   // Widget deletion:
01041   static void delete_widget(Fl_Widget *w);
01042   static void do_widget_deletion();
01043   static void watch_widget_pointer(Fl_Widget *&w);
01044   static void release_widget_pointer(Fl_Widget *&w);
01045   static void clear_widget_pointer(Fl_Widget const *w);
01048 #ifdef FLTK_HAVE_CAIRO
01049 
01052 public:
01053   // Cairo support API
01054   static cairo_t * cairo_make_current(Fl_Window* w);
01069   static void cairo_autolink_context(bool alink) {cairo_state_.autolink(alink);}
01077   static bool cairo_autolink_context() {return cairo_state_.autolink();}
01079   static cairo_t * cairo_cc() { return cairo_state_.cc(); }
01084   static void cairo_cc(cairo_t * c, bool own=false){ cairo_state_.cc(c, own); } 
01085 
01086 private:
01087   static cairo_t * cairo_make_current(void* gc);
01088   static cairo_t * cairo_make_current(void* gc, int W, int H);
01089   static Fl_Cairo_State cairo_state_;
01090 public:
01093 #endif // FLTK_HAVE_CAIRO
01094 
01095 };
01096 
01137 class FL_EXPORT Fl_Widget_Tracker {
01138 
01139   Fl_Widget* wp_;
01140 
01141 public:
01142 
01143   Fl_Widget_Tracker(Fl_Widget *wi);
01144   ~Fl_Widget_Tracker();
01145 
01151   Fl_Widget *widget() {return wp_;}
01152 
01162   int deleted() {return wp_ == 0;}
01163 
01173   int exists()  {return wp_ != 0;}
01174 
01175 };
01176 
01182 #endif // !Fl_H
01183 
01184 //
01185 // End of "$Id$".
01186 //