FLTK 1.3.x

Fl.H

00001 //
00002 // "$Id: Fl.H 8204 2011-01-07 01:01:04Z matt $"
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; 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 
00028 /* \file
00029     Fl static class.
00030  */
00031 
00032 #ifndef Fl_H
00033 #  define Fl_H
00034 
00035 #ifdef FLTK_HAVE_CAIRO
00036 # include <FL/Fl_Cairo.H>
00037 #endif
00038 
00039 #  include "fl_utf8.h"
00040 #  include "Enumerations.H"
00041 #  ifndef Fl_Object
00042 #    define Fl_Object Fl_Widget 
00043 #  endif
00044 
00045 #  ifdef check
00046 #    undef check
00047 #  endif
00048 
00049 
00050 class Fl_Widget;
00051 class Fl_Window;
00052 class Fl_Image;
00053 struct Fl_Label;
00054 
00055 
00072 typedef void (Fl_Label_Draw_F)(const Fl_Label *label, int x, int y, int w, int h, Fl_Align align);
00073 
00075 typedef void (Fl_Label_Measure_F)(const Fl_Label *label, int &width, int &height);
00076 
00078 typedef void (Fl_Box_Draw_F)(int x, int y, int w, int h, Fl_Color color);
00079 
00081 typedef void (*Fl_Timeout_Handler)(void *data);
00082 
00084 typedef void (*Fl_Awake_Handler)(void *data);
00085 
00087 typedef void (*Fl_Idle_Handler)(void *data);
00088 
00090 typedef void (*Fl_Old_Idle_Handler)();
00091 
00093 typedef void (*Fl_FD_Handler)(int fd, void *data);
00094 
00096 typedef int (*Fl_Event_Handler)(int event);
00097 
00099 typedef void (*Fl_Abort_Handler)(const char *format,...);
00100 
00102 typedef void (*Fl_Atclose_Handler)(Fl_Window *window, void *data);
00103 
00105 typedef int (*Fl_Args_Handler)(int argc, char **argv, int &i);
00106  /* group callback_functions */
00108 
00109 
00114 class FL_EXPORT Fl {
00115   Fl() {}; // no constructor!
00116   
00117 public: // should be private!
00118 #ifndef FL_DOXYGEN
00119   static int e_number;
00120   static int e_x;
00121   static int e_y;
00122   static int e_x_root;
00123   static int e_y_root;
00124   static int e_dx;
00125   static int e_dy;
00126   static int e_state;
00127   static int e_clicks;
00128   static int e_is_click;
00129   static int e_keysym;
00130   static char* e_text;
00131   static int e_length;
00132   static Fl_Widget* belowmouse_;
00133   static Fl_Widget* pushed_;
00134   static Fl_Widget* focus_;
00135   static int damage_;
00136   static Fl_Widget* selection_owner_;
00137   static Fl_Window* modal_;
00138   static Fl_Window* grab_;
00139   static int compose_state;
00140 #endif
00141 
00144   static void damage(int d) {damage_ = d;}
00145   
00146 public:
00147   typedef enum {
00152     OPTION_ARROW_FOCUS = 0,
00153       // When switched on, FLTK will use the file chooser dialog that comes 
00154       // with your operating system whenever possible. When switched off, FLTK
00155       // will present its own file chooser.
00156       // \todo implement me
00157     // OPTION_NATIVE_FILECHOOSER,
00158       // When Filechooser Preview is enabled, the FLTK or native file chooser
00159       // will show a preview of a selected file (if possible) before the user
00160       // decides to choose the file.
00161       // \todo implement me
00162     //OPTION_FILECHOOSER_PREVIEW,
00167     OPTION_VISIBLE_FOCUS,
00171     OPTION_DND_TEXT,
00175     OPTION_SHOW_TOOLTIPS,
00176       // don't change this, leave it always as the last element
00177     OPTION_LAST
00178   } Fl_Option;
00179   
00180 private:  
00181   static unsigned char options_[OPTION_LAST];
00182   static unsigned char options_read_;
00183   
00184 public:  
00185   /*
00186    Return a global setting for all FLTK applications, possibly overridden
00187    by a setting specifically for this application.
00188    */
00189   static bool option(Fl_Option opt);
00190   
00191   /*
00192    Override an option while the application is running.
00193    */
00194   static void option(Fl_Option opt, bool val);
00195   
00203   static void (*idle)();
00204 
00205 #ifndef FL_DOXYGEN
00206   static Fl_Awake_Handler *awake_ring_;
00207   static void **awake_data_;
00208   static int awake_ring_size_;
00209   static int awake_ring_head_;
00210   static int awake_ring_tail_;
00211   static const char* scheme_;
00212   static Fl_Image* scheme_bg_;
00213 
00214   static int e_original_keysym; // late addition
00215   static int scrollbar_size_;
00216 #endif
00217 
00218 
00219   static int add_awake_handler_(Fl_Awake_Handler, void*);
00220   static int get_awake_handler_(Fl_Awake_Handler&, void*&);
00221 
00222 public:
00223 
00224   // API version number
00225   static double version();
00226 
00227   // argument parsers:
00228   static int arg(int argc, char **argv, int& i);
00229   static int args(int argc, char **argv, int& i, Fl_Args_Handler cb = 0);
00230   static void args(int argc, char **argv);
00235   static const char* const help;
00236 
00237   // things called by initialization:
00238   static void display(const char*);
00239   static int visual(int);
00249   static int gl_visual(int, int *alist=0); // platform dependent
00250   static void own_colormap();
00251   static void get_system_colors();
00252   static void foreground(uchar, uchar, uchar);
00253   static void background(uchar, uchar, uchar);
00254   static void background2(uchar, uchar, uchar);
00255 
00256   // schemes:
00257   static int scheme(const char*);
00259   static const char* scheme() {return scheme_;}
00265   static int reload_scheme(); // platform dependent
00266   static int scrollbar_size();
00267   static void scrollbar_size(int W);
00268 
00269   // execution:
00270   static int wait();
00271   static double wait(double time);
00272   static int check();
00273   static int ready();
00274   static int run();
00275   static Fl_Widget* readqueue();
00302   static void add_timeout(double t, Fl_Timeout_Handler,void* = 0); // platform dependent
00323   static void repeat_timeout(double t, Fl_Timeout_Handler, void* = 0); // platform dependent
00324   static int  has_timeout(Fl_Timeout_Handler, void* = 0);
00325   static void remove_timeout(Fl_Timeout_Handler, void* = 0);
00326   static void add_check(Fl_Timeout_Handler, void* = 0);
00327   static int  has_check(Fl_Timeout_Handler, void* = 0);
00328   static void remove_check(Fl_Timeout_Handler, void* = 0);
00348   static void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0); // platform dependent
00350   static void add_fd(int fd, Fl_FD_Handler cb, void* = 0); // platform dependent
00352   static void remove_fd(int, int when); // platform dependent
00354   static void remove_fd(int); // platform dependent
00355 
00356   static void add_idle(Fl_Idle_Handler cb, void* data = 0);
00357   static int  has_idle(Fl_Idle_Handler cb, void* data = 0);
00358   static void remove_idle(Fl_Idle_Handler cb, void* data = 0);
00360   static int damage() {return damage_;}
00361   static void redraw();
00362   static void flush();
00383   static void (*warning)(const char*, ...);
00398   static void (*error)(const char*, ...);
00415   static void (*fatal)(const char*, ...);
00421   static Fl_Window* first_window();
00422   static void first_window(Fl_Window*);
00423   static Fl_Window* next_window(const Fl_Window*);
00424 
00434   static Fl_Window* modal() {return modal_;}
00459   static Fl_Window* grab() {return grab_;}
00461   static void grab(Fl_Window*); // platform dependent
00468   // event information:
00474   static int event()            {return e_number;}
00479   static int event_x()  {return e_x;}
00484   static int event_y()  {return e_y;}
00491   static int event_x_root()     {return e_x_root;}
00498   static int event_y_root()     {return e_y_root;}
00503   static int event_dx() {return e_dx;}
00508   static int event_dy() {return e_dy;}
00517   static void get_mouse(int &,int &); // platform dependent
00526   static int event_clicks()     {return e_clicks;}
00534   static void event_clicks(int i) {e_clicks = i;}
00545   static int event_is_click()   {return e_is_click;}
00549   static void event_is_click(int i) {e_is_click = i;}
00556   static int event_button()     {return e_keysym-FL_Button;}
00580   static int event_state()      {return e_state;}
00582   static int event_state(int i) {return e_state&i;}
00594   static int event_key()        {return e_keysym;}
00603   static int event_original_key(){return e_original_keysym;}
00642   static int event_key(int key);
00648   static int get_key(int key); // platform dependent
00663   static const char* event_text() {return e_text;}
00670   static int event_length() {return e_length;}
00671 
00672   static int compose(int &del);
00679   static void compose_reset() {compose_state = 0;}
00680   static int event_inside(int,int,int,int);
00681   static int event_inside(const Fl_Widget*);
00682   static int test_shortcut(Fl_Shortcut);
00683 
00684   // event destinations:
00685   static int handle(int, Fl_Window*);
00688   static Fl_Widget* belowmouse() {return belowmouse_;}
00689   static void belowmouse(Fl_Widget*);
00692   static Fl_Widget* pushed()    {return pushed_;}
00693   static void pushed(Fl_Widget*);
00695   static Fl_Widget* focus()     {return focus_;}
00696   static void focus(Fl_Widget*);
00697   static void add_handler(Fl_Event_Handler h);
00698   static void remove_handler(Fl_Event_Handler h);
00704   // cut/paste:
00714   static void copy(const char* stuff, int len, int destination = 0); // platform dependent
00732   static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent
00742   static int dnd(); // platform dependent
00743 
00744   // These are for back-compatibility only:
00747   static Fl_Widget* selection_owner() {return selection_owner_;}
00748   static void selection_owner(Fl_Widget*);
00749   static void selection(Fl_Widget &owner, const char*, int len);
00750   static void paste(Fl_Widget &receiver);
00755   // screen size:
00757   static int x(); // platform dependent
00759   static int y(); // platform dependent
00761   static int w(); // platform dependent
00763   static int h(); // platform dependent
00764 
00765   // multi-head support:
00766   static int screen_count();
00772   static void screen_xywh(int &X, int &Y, int &W, int &H) {
00773     screen_xywh(X, Y, W, H, e_x_root, e_y_root);
00774   }
00775   static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
00776   static void screen_xywh(int &X, int &Y, int &W, int &H, int n);  
00777   static void screen_dpi(float &h, float &v, int n=0);
00778 
00786   // color map:
00787   static void   set_color(Fl_Color, uchar, uchar, uchar);
00792   static void   set_color(Fl_Color i, unsigned c); // platform dependent
00793   static unsigned get_color(Fl_Color i);
00794   static void   get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue);
00800   static void   free_color(Fl_Color i, int overlay = 0); // platform dependent
00801 
00802   // fonts:
00803   static const char* get_font(Fl_Font);
00816   static const char* get_font_name(Fl_Font, int* attributes = 0);
00828   static int get_font_sizes(Fl_Font, int*& sizep);
00829   static void set_font(Fl_Font, const char*);
00830   static void set_font(Fl_Font, Fl_Font);
00849   static Fl_Font set_fonts(const char* = 0); // platform dependent
00850 
00857   // <Hack to re-order the 'Drawing functions' group>
00860   // labeltypes:
00861   static void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*);
00863   static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined ?
00864 
00865   // boxtypes:
00866   static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype);
00867   static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar);
00868   static void set_boxtype(Fl_Boxtype, Fl_Boxtype from);
00869   static int box_dx(Fl_Boxtype);
00870   static int box_dy(Fl_Boxtype);
00871   static int box_dw(Fl_Boxtype);
00872   static int box_dh(Fl_Boxtype);
00873   static int draw_box_active();
00874 
00875   // back compatibility:
00879   static void set_abort(Fl_Abort_Handler f) {fatal = f;}
00880   static void (*atclose)(Fl_Window*,void*);
00881   static void default_atclose(Fl_Window*,void*);
00885   static void set_atclose(Fl_Atclose_Handler f) {atclose = f;}
00891   static int event_shift() {return e_state&FL_SHIFT;}
00893   static int event_ctrl() {return e_state&FL_CTRL;}
00895   static int event_command() {return e_state&FL_COMMAND;}
00897   static int event_alt() {return e_state&FL_ALT;}
00906   static int event_buttons() {return e_state&0x7f000000;}
00911   static int event_button1() {return e_state&FL_BUTTON1;}
00916   static int event_button2() {return e_state&FL_BUTTON2;}
00921   static int event_button3() {return e_state&FL_BUTTON3;}
00929   static void set_idle(Fl_Old_Idle_Handler cb) {idle = cb;}
00931   static void grab(Fl_Window&win) {grab(&win);}
00935   static void release() {grab(0);}
00936 
00937   // Visible focus methods...
00943   static void visible_focus(int v) { option(OPTION_VISIBLE_FOCUS, v);  }
00949   static int  visible_focus() { return option(OPTION_VISIBLE_FOCUS); }
00950 
00951   // Drag-n-drop text operation methods...
00958   static void dnd_text_ops(int v) { option(OPTION_DND_TEXT, v); }
00965   static int  dnd_text_ops() { return option(OPTION_DND_TEXT); }
00970   // Multithreading support:
00971   static void lock();
00972   static void unlock();
00973   static void awake(void* message = 0);
00975   static int awake(Fl_Awake_Handler cb, void* message = 0);
00982   static void* thread_message(); // platform dependent
01014   // Widget deletion:
01015   static void delete_widget(Fl_Widget *w);
01016   static void do_widget_deletion();
01017   static void watch_widget_pointer(Fl_Widget *&w);
01018   static void release_widget_pointer(Fl_Widget *&w);
01019   static void clear_widget_pointer(Fl_Widget const *w);
01022 #ifdef FLTK_HAVE_CAIRO
01023 
01026 public:
01027   // Cairo support API
01028   static cairo_t * cairo_make_current(Fl_Window* w);
01043   static void cairo_autolink_context(bool alink) {cairo_state_.autolink(alink);}
01051   static bool cairo_autolink_context() {return cairo_state_.autolink();}
01053   static cairo_t * cairo_cc() { return cairo_state_.cc(); }
01058   static void cairo_cc(cairo_t * c, bool own=false){ cairo_state_.cc(c, own); } 
01059 
01060 private:
01061   static cairo_t * cairo_make_current(void* gc);
01062   static cairo_t * cairo_make_current(void* gc, int W, int H);
01063   static Fl_Cairo_State cairo_state_;
01064 public:
01067 #endif // FLTK_HAVE_CAIRO
01068 
01069 };
01070 
01111 class FL_EXPORT Fl_Widget_Tracker {
01112 
01113   Fl_Widget* wp_;
01114 
01115 public:
01116 
01117   Fl_Widget_Tracker(Fl_Widget *wi);
01118   ~Fl_Widget_Tracker();
01119 
01125   Fl_Widget *widget() {return wp_;}
01126 
01136   int deleted() {return wp_ == 0;}
01137 
01147   int exists()  {return wp_ != 0;}
01148 
01149 };
01150 
01156 #endif // !Fl_H
01157 
01158 //
01159 // End of "$Id: Fl.H 8204 2011-01-07 01:01:04Z matt $".
01160 //