FLTK 1.3.0
Fl.H
Go to the documentation of this file.
00001 //
00002 // "$Id: Fl.H 8724 2011-05-23 18:01:29Z manolo $"
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 
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 
00109 typedef int (*Fl_Event_Dispatch)(int event, Fl_Window *w);
00110  /* group callback_functions */
00112 
00113 
00118 class FL_EXPORT Fl {
00119   Fl() {}; // no constructor!
00120   
00121 public: // should be private!
00122 #ifndef FL_DOXYGEN
00123   static int e_number;
00124   static int e_x;
00125   static int e_y;
00126   static int e_x_root;
00127   static int e_y_root;
00128   static int e_dx;
00129   static int e_dy;
00130   static int e_state;
00131   static int e_clicks;
00132   static int e_is_click;
00133   static int e_keysym;
00134   static char* e_text;
00135   static int e_length;
00136   static Fl_Event_Dispatch e_dispatch;
00137   static Fl_Widget* belowmouse_;
00138   static Fl_Widget* pushed_;
00139   static Fl_Widget* focus_;
00140   static int damage_;
00141   static Fl_Widget* selection_owner_;
00142   static Fl_Window* modal_;
00143   static Fl_Window* grab_;
00144   static int compose_state;
00145 #endif
00146 
00149   static void damage(int d) {damage_ = d;}
00150   
00151 public:
00158   typedef enum {
00163     OPTION_ARROW_FOCUS = 0,
00164       // When switched on, FLTK will use the file chooser dialog that comes 
00165       // with your operating system whenever possible. When switched off, FLTK
00166       // will present its own file chooser.
00167       // \todo implement me
00168     // OPTION_NATIVE_FILECHOOSER,
00169       // When Filechooser Preview is enabled, the FLTK or native file chooser
00170       // will show a preview of a selected file (if possible) before the user
00171       // decides to choose the file.
00172       // \todo implement me
00173     //OPTION_FILECHOOSER_PREVIEW,
00178     OPTION_VISIBLE_FOCUS,
00182     OPTION_DND_TEXT,
00186     OPTION_SHOW_TOOLTIPS,
00187       // don't change this, leave it always as the last element
00189     OPTION_LAST
00190   } Fl_Option;
00191 
00192 private:  
00193   static unsigned char options_[OPTION_LAST];
00194   static unsigned char options_read_;
00195   
00196 public:  
00197   /*
00198    Return a global setting for all FLTK applications, possibly overridden
00199    by a setting specifically for this application.
00200    */
00201   static bool option(Fl_Option opt);
00202   
00203   /*
00204    Override an option while the application is running.
00205    */
00206   static void option(Fl_Option opt, bool val);
00207   
00215   static void (*idle)();
00216 
00217 #ifndef FL_DOXYGEN
00218   static Fl_Awake_Handler *awake_ring_;
00219   static void **awake_data_;
00220   static int awake_ring_size_;
00221   static int awake_ring_head_;
00222   static int awake_ring_tail_;
00223   static const char* scheme_;
00224   static Fl_Image* scheme_bg_;
00225 
00226   static int e_original_keysym; // late addition
00227   static int scrollbar_size_;
00228 #endif
00229 
00230 
00231   static int add_awake_handler_(Fl_Awake_Handler, void*);
00232   static int get_awake_handler_(Fl_Awake_Handler&, void*&);
00233 
00234 public:
00235 
00236   // API version number
00237   static double version();
00238 
00239   // argument parsers:
00240   static int arg(int argc, char **argv, int& i);
00241   static int args(int argc, char **argv, int& i, Fl_Args_Handler cb = 0);
00242   static void args(int argc, char **argv);
00247   static const char* const help;
00248 
00249   // things called by initialization:
00250   static void display(const char*);
00251   static int visual(int);
00261   static int gl_visual(int, int *alist=0); // platform dependent
00262   static void own_colormap();
00263   static void get_system_colors();
00264   static void foreground(uchar, uchar, uchar);
00265   static void background(uchar, uchar, uchar);
00266   static void background2(uchar, uchar, uchar);
00267 
00268   // schemes:
00269   static int scheme(const char*);
00271   static const char* scheme() {return scheme_;}
00277   static int reload_scheme(); // platform dependent
00278   static int scrollbar_size();
00279   static void scrollbar_size(int W);
00280 
00281   // execution:
00282   static int wait();
00283   static double wait(double time);
00284   static int check();
00285   static int ready();
00286   static int run();
00287   static Fl_Widget* readqueue();
00314   static void add_timeout(double t, Fl_Timeout_Handler,void* = 0); // platform dependent
00335   static void repeat_timeout(double t, Fl_Timeout_Handler, void* = 0); // platform dependent
00336   static int  has_timeout(Fl_Timeout_Handler, void* = 0);
00337   static void remove_timeout(Fl_Timeout_Handler, void* = 0);
00338   static void add_check(Fl_Timeout_Handler, void* = 0);
00339   static int  has_check(Fl_Timeout_Handler, void* = 0);
00340   static void remove_check(Fl_Timeout_Handler, void* = 0);
00360   static void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0); // platform dependent
00362   static void add_fd(int fd, Fl_FD_Handler cb, void* = 0); // platform dependent
00364   static void remove_fd(int, int when); // platform dependent
00366   static void remove_fd(int); // platform dependent
00367 
00368   static void add_idle(Fl_Idle_Handler cb, void* data = 0);
00369   static int  has_idle(Fl_Idle_Handler cb, void* data = 0);
00370   static void remove_idle(Fl_Idle_Handler cb, void* data = 0);
00372   static int damage() {return damage_;}
00373   static void redraw();
00374   static void flush();
00395   static void (*warning)(const char*, ...);
00410   static void (*error)(const char*, ...);
00427   static void (*fatal)(const char*, ...);
00433   static Fl_Window* first_window();
00434   static void first_window(Fl_Window*);
00435   static Fl_Window* next_window(const Fl_Window*);
00436 
00446   static Fl_Window* modal() {return modal_;}
00452   static Fl_Window* grab() {return grab_;}
00477   static void grab(Fl_Window*); // platform dependent
00484   // event information:
00490   static int event()            {return e_number;}
00495   static int event_x()  {return e_x;}
00500   static int event_y()  {return e_y;}
00507   static int event_x_root()     {return e_x_root;}
00514   static int event_y_root()     {return e_y_root;}
00519   static int event_dx() {return e_dx;}
00524   static int event_dy() {return e_dy;}
00533   static void get_mouse(int &,int &); // platform dependent
00542   static int event_clicks()     {return e_clicks;}
00550   static void event_clicks(int i) {e_clicks = i;}
00558   static int event_is_click()   {return e_is_click;}
00565   static void event_is_click(int i) {e_is_click = i;}
00572   static int event_button()     {return e_keysym-FL_Button;}
00596   static int event_state()      {return e_state;}
00598   static int event_state(int i) {return e_state&i;}
00610   static int event_key()        {return e_keysym;}
00619   static int event_original_key(){return e_original_keysym;}
00658   static int event_key(int key);
00664   static int get_key(int key); // platform dependent
00679   static const char* event_text() {return e_text;}
00686   static int event_length() {return e_length;}
00687 
00688   static int compose(int &del);
00689   static void compose_reset();
00690   static int event_inside(int,int,int,int);
00691   static int event_inside(const Fl_Widget*);
00692   static int test_shortcut(Fl_Shortcut);
00693 
00694   // event destinations:
00695   static int handle(int, Fl_Window*);
00696   static int handle_(int, Fl_Window*);
00699   static Fl_Widget* belowmouse() {return belowmouse_;}
00700   static void belowmouse(Fl_Widget*);
00703   static Fl_Widget* pushed()    {return pushed_;}
00704   static void pushed(Fl_Widget*);
00706   static Fl_Widget* focus()     {return focus_;}
00707   static void focus(Fl_Widget*);
00708   static void add_handler(Fl_Event_Handler h);
00709   static void remove_handler(Fl_Event_Handler h);
00710   static void event_dispatch(Fl_Event_Dispatch d);
00711   static Fl_Event_Dispatch event_dispatch();
00717   // cut/paste:
00727   static void copy(const char* stuff, int len, int destination = 0); // platform dependent
00745   static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent
00755   static int dnd(); // platform dependent
00756 
00757   // These are for back-compatibility only:
00760   static Fl_Widget* selection_owner() {return selection_owner_;}
00761   static void selection_owner(Fl_Widget*);
00762   static void selection(Fl_Widget &owner, const char*, int len);
00763   static void paste(Fl_Widget &receiver);
00768   // screen size:
00770   static int x(); // platform dependent
00772   static int y(); // platform dependent
00774   static int w(); // platform dependent
00776   static int h(); // platform dependent
00777 
00778   // multi-head support:
00779   static int screen_count();
00785   static void screen_xywh(int &X, int &Y, int &W, int &H) {
00786     screen_xywh(X, Y, W, H, e_x_root, e_y_root);
00787   }
00788   static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
00789   static void screen_xywh(int &X, int &Y, int &W, int &H, int n); 
00790   static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh);
00791   static void screen_dpi(float &h, float &v, int n=0);
00792 
00800   // color map:
00801   static void   set_color(Fl_Color, uchar, uchar, uchar);
00806   static void   set_color(Fl_Color i, unsigned c); // platform dependent
00807   static unsigned get_color(Fl_Color i);
00808   static void   get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue);
00814   static void   free_color(Fl_Color i, int overlay = 0); // platform dependent
00815 
00816   // fonts:
00817   static const char* get_font(Fl_Font);
00830   static const char* get_font_name(Fl_Font, int* attributes = 0);
00842   static int get_font_sizes(Fl_Font, int*& sizep);
00843   static void set_font(Fl_Font, const char*);
00844   static void set_font(Fl_Font, Fl_Font);
00863   static Fl_Font set_fonts(const char* = 0); // platform dependent
00864 
00871   // <Hack to re-order the 'Drawing functions' group>
00874   // labeltypes:
00875   static void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*);
00877   static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined ?
00878 
00879   // boxtypes:
00880   static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype);
00881   static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar);
00882   static void set_boxtype(Fl_Boxtype, Fl_Boxtype from);
00883   static int box_dx(Fl_Boxtype);
00884   static int box_dy(Fl_Boxtype);
00885   static int box_dw(Fl_Boxtype);
00886   static int box_dh(Fl_Boxtype);
00887   static int draw_box_active();
00888 
00889   // back compatibility:
00893   static void set_abort(Fl_Abort_Handler f) {fatal = f;}
00894   static void (*atclose)(Fl_Window*,void*);
00895   static void default_atclose(Fl_Window*,void*);
00899   static void set_atclose(Fl_Atclose_Handler f) {atclose = f;}
00905   static int event_shift() {return e_state&FL_SHIFT;}
00907   static int event_ctrl() {return e_state&FL_CTRL;}
00909   static int event_command() {return e_state&FL_COMMAND;}
00911   static int event_alt() {return e_state&FL_ALT;}
00920   static int event_buttons() {return e_state&0x7f000000;}
00925   static int event_button1() {return e_state&FL_BUTTON1;}
00930   static int event_button2() {return e_state&FL_BUTTON2;}
00935   static int event_button3() {return e_state&FL_BUTTON3;}
00943   static void set_idle(Fl_Old_Idle_Handler cb) {idle = cb;}
00945   static void grab(Fl_Window& win) {grab(&win);}
00949   static void release() {grab(0);}
00950 
00951   // Visible focus methods...
00957   static void visible_focus(int v) { option(OPTION_VISIBLE_FOCUS, (v!=0)); }
00963   static int  visible_focus() { return option(OPTION_VISIBLE_FOCUS); }
00964 
00965   // Drag-n-drop text operation methods...
00972   static void dnd_text_ops(int v) { option(OPTION_DND_TEXT, (v!=0)); }
00979   static int  dnd_text_ops() { return option(OPTION_DND_TEXT); }
00984   // Multithreading support:
00985   static int lock();
00986   static void unlock();
00987   static void awake(void* message = 0);
00989   static int awake(Fl_Awake_Handler cb, void* message = 0);
00996   static void* thread_message(); // platform dependent
01028   // Widget deletion:
01029   static void delete_widget(Fl_Widget *w);
01030   static void do_widget_deletion();
01031   static void watch_widget_pointer(Fl_Widget *&w);
01032   static void release_widget_pointer(Fl_Widget *&w);
01033   static void clear_widget_pointer(Fl_Widget const *w);
01036 #ifdef FLTK_HAVE_CAIRO
01037 
01040 public:
01041   // Cairo support API
01042   static cairo_t * cairo_make_current(Fl_Window* w);
01057   static void cairo_autolink_context(bool alink) {cairo_state_.autolink(alink);}
01065   static bool cairo_autolink_context() {return cairo_state_.autolink();}
01067   static cairo_t * cairo_cc() { return cairo_state_.cc(); }
01072   static void cairo_cc(cairo_t * c, bool own=false){ cairo_state_.cc(c, own); } 
01073 
01074 private:
01075   static cairo_t * cairo_make_current(void* gc);
01076   static cairo_t * cairo_make_current(void* gc, int W, int H);
01077   static Fl_Cairo_State cairo_state_;
01078 public:
01081 #endif // FLTK_HAVE_CAIRO
01082 
01083 };
01084 
01125 class FL_EXPORT Fl_Widget_Tracker {
01126 
01127   Fl_Widget* wp_;
01128 
01129 public:
01130 
01131   Fl_Widget_Tracker(Fl_Widget *wi);
01132   ~Fl_Widget_Tracker();
01133 
01139   Fl_Widget *widget() {return wp_;}
01140 
01150   int deleted() {return wp_ == 0;}
01151 
01161   int exists()  {return wp_ != 0;}
01162 
01163 };
01164 
01170 #endif // !Fl_H
01171 
01172 //
01173 // End of "$Id: Fl.H 8724 2011-05-23 18:01:29Z manolo $".
01174 //