FLTK 1.3.2
Fl.H
Go to the documentation of this file.
1 //
2 // "$Id: Fl.H 9816 2013-02-08 11:58:19Z manolo $"
3 //
4 // Main header file for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software. Distribution and use rights are outlined in
9 // the file "COPYING" which should have been included with this file. If this
10 // file is missing or damaged, see the license at:
11 //
12 // http://www.fltk.org/COPYING.php
13 //
14 // Please report all bugs and problems on the following page:
15 //
16 // http://www.fltk.org/str.php
17 //
18 
23 #ifndef Fl_H
24 # define Fl_H
25 
26 #ifdef FLTK_HAVE_CAIRO
27 # include <FL/Fl_Cairo.H>
28 #endif
29 
30 # include "fl_utf8.h"
31 # include "Enumerations.H"
32 # ifndef Fl_Object
33 # define Fl_Object Fl_Widget
34 # endif
35 
36 # ifdef check
37 # undef check
38 # endif
39 
40 
41 class Fl_Widget;
42 class Fl_Window;
43 class Fl_Image;
44 struct Fl_Label;
45 
46 // Keep avoiding having the socket deps at that level but mke sure it will work in both 32 & 64 bit builds
47 #if defined(WIN32) && !defined(__CYGWIN__)
48 # if defined(_WIN64)
49 # define FL_SOCKET unsigned __int64
50 # else
51 # define FL_SOCKET int
52 # endif
53 #else
54 # define FL_SOCKET int
55 #endif
56 
73 typedef void (Fl_Label_Draw_F)(const Fl_Label *label, int x, int y, int w, int h, Fl_Align align);
74 
76 typedef void (Fl_Label_Measure_F)(const Fl_Label *label, int &width, int &height);
77 
79 typedef void (Fl_Box_Draw_F)(int x, int y, int w, int h, Fl_Color color);
80 
82 typedef void (*Fl_Timeout_Handler)(void *data);
83 
85 typedef void (*Fl_Awake_Handler)(void *data);
86 
88 typedef void (*Fl_Idle_Handler)(void *data);
89 
91 typedef void (*Fl_Old_Idle_Handler)();
92 
94 typedef void (*Fl_FD_Handler)(FL_SOCKET fd, void *data);
95 
97 typedef int (*Fl_Event_Handler)(int event);
98 
100 typedef void (*Fl_Abort_Handler)(const char *format,...);
101 
103 typedef void (*Fl_Atclose_Handler)(Fl_Window *window, void *data);
104 
106 typedef int (*Fl_Args_Handler)(int argc, char **argv, int &i);
107 
110 typedef int (*Fl_Event_Dispatch)(int event, Fl_Window *w);
111  /* group callback_functions */
113 
114 
119 class FL_EXPORT Fl {
120  Fl() {}; // no constructor!
121 
122 public: // should be private!
123 #ifndef FL_DOXYGEN
124  static int e_number;
125  static int e_x;
126  static int e_y;
127  static int e_x_root;
128  static int e_y_root;
129  static int e_dx;
130  static int e_dy;
131  static int e_state;
132  static int e_clicks;
133  static int e_is_click;
134  static int e_keysym;
135  static char* e_text;
136  static int e_length;
137  static Fl_Event_Dispatch e_dispatch;
138  static Fl_Widget* belowmouse_;
139  static Fl_Widget* pushed_;
140  static Fl_Widget* focus_;
141  static int damage_;
142  static Fl_Widget* selection_owner_;
143  static Fl_Window* modal_;
144  static Fl_Window* grab_;
145  static int compose_state; // used for dead keys (WIN32) or marked text (MacOS)
146  static void call_screen_init(); // recompute screen number and dimensions
147 #ifdef __APPLE__
148  static void reset_marked_text(); // resets marked text
149  static void insertion_point_location(int x, int y, int height); // sets window coordinates & height of insertion point
150 #endif
151 #endif
152 
155  static void damage(int d) {damage_ = d;}
156 
157 public:
164  typedef enum {
169  OPTION_ARROW_FOCUS = 0,
170  // When switched on, FLTK will use the file chooser dialog that comes
171  // with your operating system whenever possible. When switched off, FLTK
172  // will present its own file chooser.
173  // \todo implement me
174  // OPTION_NATIVE_FILECHOOSER,
175  // When Filechooser Preview is enabled, the FLTK or native file chooser
176  // will show a preview of a selected file (if possible) before the user
177  // decides to choose the file.
178  // \todo implement me
179  //OPTION_FILECHOOSER_PREVIEW,
193  // don't change this, leave it always as the last element
195  OPTION_LAST
196  } Fl_Option;
197 
198 private:
199  static unsigned char options_[OPTION_LAST];
200  static unsigned char options_read_;
201 
202 public:
203  /*
204  Return a global setting for all FLTK applications, possibly overridden
205  by a setting specifically for this application.
206  */
207  static bool option(Fl_Option opt);
208 
209  /*
210  Override an option while the application is running.
211  */
212  static void option(Fl_Option opt, bool val);
213 
221  static void (*idle)();
222 
223 #ifndef FL_DOXYGEN
224  static Fl_Awake_Handler *awake_ring_;
225  static void **awake_data_;
226  static int awake_ring_size_;
227  static int awake_ring_head_;
228  static int awake_ring_tail_;
229  static const char* scheme_;
230  static Fl_Image* scheme_bg_;
231 
232  static int e_original_keysym; // late addition
233  static int scrollbar_size_;
234 #endif
235 
236 
237  static int add_awake_handler_(Fl_Awake_Handler, void*);
238  static int get_awake_handler_(Fl_Awake_Handler&, void*&);
239 
240 public:
241 
242  // API version number
243  static double version();
244 
245  // argument parsers:
246  static int arg(int argc, char **argv, int& i);
247  static int args(int argc, char **argv, int& i, Fl_Args_Handler cb = 0);
248  static void args(int argc, char **argv);
253  static const char* const help;
254 
255  // things called by initialization:
256  static void display(const char*);
257  static int visual(int);
267  static int gl_visual(int, int *alist=0); // platform dependent
268  static void own_colormap();
269  static void get_system_colors();
270  static void foreground(uchar, uchar, uchar);
271  static void background(uchar, uchar, uchar);
272  static void background2(uchar, uchar, uchar);
273 
274  // schemes:
275  static int scheme(const char*);
277  static const char* scheme() {return scheme_;}
283  static int reload_scheme(); // platform dependent
284  static int scrollbar_size();
285  static void scrollbar_size(int W);
286 
287  // execution:
288  static int wait();
289  static double wait(double time);
290  static int check();
291  static int ready();
292  static int run();
293  static Fl_Widget* readqueue();
320  static void add_timeout(double t, Fl_Timeout_Handler,void* = 0); // platform dependent
341  static void repeat_timeout(double t, Fl_Timeout_Handler, void* = 0); // platform dependent
342  static int has_timeout(Fl_Timeout_Handler, void* = 0);
343  static void remove_timeout(Fl_Timeout_Handler, void* = 0);
344  static void add_check(Fl_Timeout_Handler, void* = 0);
345  static int has_check(Fl_Timeout_Handler, void* = 0);
346  static void remove_check(Fl_Timeout_Handler, void* = 0);
366  static void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0); // platform dependent
368  static void add_fd(int fd, Fl_FD_Handler cb, void* = 0); // platform dependent
370  static void remove_fd(int, int when); // platform dependent
372  static void remove_fd(int); // platform dependent
373 
374  static void add_idle(Fl_Idle_Handler cb, void* data = 0);
375  static int has_idle(Fl_Idle_Handler cb, void* data = 0);
376  static void remove_idle(Fl_Idle_Handler cb, void* data = 0);
378  static int damage() {return damage_;}
379  static void redraw();
380  static void flush();
401  static void (*warning)(const char*, ...);
416  static void (*error)(const char*, ...);
433  static void (*fatal)(const char*, ...);
439  static Fl_Window* first_window();
440  static void first_window(Fl_Window*);
441  static Fl_Window* next_window(const Fl_Window*);
442 
452  static Fl_Window* modal() {return modal_;}
458  static Fl_Window* grab() {return grab_;}
483  static void grab(Fl_Window*); // platform dependent
490  // event information:
496  static int event() {return e_number;}
501  static int event_x() {return e_x;}
506  static int event_y() {return e_y;}
513  static int event_x_root() {return e_x_root;}
520  static int event_y_root() {return e_y_root;}
525  static int event_dx() {return e_dx;}
530  static int event_dy() {return e_dy;}
539  static void get_mouse(int &,int &); // platform dependent
548  static int event_clicks() {return e_clicks;}
556  static void event_clicks(int i) {e_clicks = i;}
564  static int event_is_click() {return e_is_click;}
571  static void event_is_click(int i) {e_is_click = i;}
578  static int event_button() {return e_keysym-FL_Button;}
602  static int event_state() {return e_state;}
604  static int event_state(int i) {return e_state&i;}
616  static int event_key() {return e_keysym;}
625  static int event_original_key(){return e_original_keysym;}
664  static int event_key(int key);
670  static int get_key(int key); // platform dependent
685  static const char* event_text() {return e_text;}
692  static int event_length() {return e_length;}
693 
694  static int compose(int &del);
695  static void compose_reset();
696  static int event_inside(int,int,int,int);
697  static int event_inside(const Fl_Widget*);
698  static int test_shortcut(Fl_Shortcut);
699 
700  // event destinations:
701  static int handle(int, Fl_Window*);
702  static int handle_(int, Fl_Window*);
705  static Fl_Widget* belowmouse() {return belowmouse_;}
706  static void belowmouse(Fl_Widget*);
709  static Fl_Widget* pushed() {return pushed_;}
710  static void pushed(Fl_Widget*);
712  static Fl_Widget* focus() {return focus_;}
713  static void focus(Fl_Widget*);
714  static void add_handler(Fl_Event_Handler h);
715  static void remove_handler(Fl_Event_Handler h);
716  static void event_dispatch(Fl_Event_Dispatch d);
717  static Fl_Event_Dispatch event_dispatch();
723  // cut/paste:
733  static void copy(const char* stuff, int len, int destination = 0); // platform dependent
751  static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent
761  static int dnd(); // platform dependent
762 
763  // These are for back-compatibility only:
766  static Fl_Widget* selection_owner() {return selection_owner_;}
767  static void selection_owner(Fl_Widget*);
768  static void selection(Fl_Widget &owner, const char*, int len);
769  static void paste(Fl_Widget &receiver);
774  // screen size:
776  static int x(); // platform dependent
778  static int y(); // platform dependent
780  static int w(); // platform dependent
782  static int h(); // platform dependent
783 
784  // multi-head support:
785  static int screen_count();
791  static void screen_xywh(int &X, int &Y, int &W, int &H) {
792  int x, y;
793  Fl::get_mouse(x, y);
794  screen_xywh(X, Y, W, H, x, y);
795  }
796  static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
797  static void screen_xywh(int &X, int &Y, int &W, int &H, int n);
798  static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh);
799  static void screen_dpi(float &h, float &v, int n=0);
800  static void screen_work_area(int &X, int &Y, int &W, int &H, int mx, int my);
801  static void screen_work_area(int &X, int &Y, int &W, int &H, int n);
807  static void screen_work_area(int &X, int &Y, int &W, int &H) {
808  int x, y;
809  Fl::get_mouse(x, y);
810  screen_work_area(X, Y, W, H, x, y);
811  }
812 
820  // color map:
821  static void set_color(Fl_Color, uchar, uchar, uchar);
826  static void set_color(Fl_Color i, unsigned c); // platform dependent
827  static unsigned get_color(Fl_Color i);
828  static void get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue);
834  static void free_color(Fl_Color i, int overlay = 0); // platform dependent
835 
836  // fonts:
837  static const char* get_font(Fl_Font);
850  static const char* get_font_name(Fl_Font, int* attributes = 0);
862  static int get_font_sizes(Fl_Font, int*& sizep);
863  static void set_font(Fl_Font, const char*);
864  static void set_font(Fl_Font, Fl_Font);
883  static Fl_Font set_fonts(const char* = 0); // platform dependent
884 
891  // <Hack to re-order the 'Drawing functions' group>
894  // labeltypes:
895  static void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*);
897  static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined ?
898 
899  // boxtypes:
900  static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype);
901  static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar);
902  static void set_boxtype(Fl_Boxtype, Fl_Boxtype from);
903  static int box_dx(Fl_Boxtype);
904  static int box_dy(Fl_Boxtype);
905  static int box_dw(Fl_Boxtype);
906  static int box_dh(Fl_Boxtype);
907  static int draw_box_active();
908 
909  // back compatibility:
913  static void set_abort(Fl_Abort_Handler f) {fatal = f;}
914  static void (*atclose)(Fl_Window*,void*);
915  static void default_atclose(Fl_Window*,void*);
919  static void set_atclose(Fl_Atclose_Handler f) {atclose = f;}
925  static int event_shift() {return e_state&FL_SHIFT;}
927  static int event_ctrl() {return e_state&FL_CTRL;}
929  static int event_command() {return e_state&FL_COMMAND;}
931  static int event_alt() {return e_state&FL_ALT;}
940  static int event_buttons() {return e_state&0x7f000000;}
945  static int event_button1() {return e_state&FL_BUTTON1;}
950  static int event_button2() {return e_state&FL_BUTTON2;}
955  static int event_button3() {return e_state&FL_BUTTON3;}
963  static void set_idle(Fl_Old_Idle_Handler cb) {idle = cb;}
965  static void grab(Fl_Window& win) {grab(&win);}
969  static void release() {grab(0);}
970 
971  // Visible focus methods...
977  static void visible_focus(int v) { option(OPTION_VISIBLE_FOCUS, (v!=0)); }
983  static int visible_focus() { return option(OPTION_VISIBLE_FOCUS); }
984 
985  // Drag-n-drop text operation methods...
992  static void dnd_text_ops(int v) { option(OPTION_DND_TEXT, (v!=0)); }
999  static int dnd_text_ops() { return option(OPTION_DND_TEXT); }
1004  // Multithreading support:
1005  static int lock();
1006  static void unlock();
1007  static void awake(void* message = 0);
1009  static int awake(Fl_Awake_Handler cb, void* message = 0);
1016  static void* thread_message(); // platform dependent
1048  // Widget deletion:
1049  static void delete_widget(Fl_Widget *w);
1050  static void do_widget_deletion();
1051  static void watch_widget_pointer(Fl_Widget *&w);
1052  static void release_widget_pointer(Fl_Widget *&w);
1053  static void clear_widget_pointer(Fl_Widget const *w);
1056 #ifdef FLTK_HAVE_CAIRO
1057 
1060 public:
1061  // Cairo support API
1062  static cairo_t * cairo_make_current(Fl_Window* w);
1077  static void cairo_autolink_context(bool alink) {cairo_state_.autolink(alink);}
1085  static bool cairo_autolink_context() {return cairo_state_.autolink();}
1087  static cairo_t * cairo_cc() { return cairo_state_.cc(); }
1092  static void cairo_cc(cairo_t * c, bool own=false){ cairo_state_.cc(c, own); }
1093 
1094 private:
1095  static cairo_t * cairo_make_current(void* gc);
1096  static cairo_t * cairo_make_current(void* gc, int W, int H);
1097  static Fl_Cairo_State cairo_state_;
1098 public:
1101 #endif // FLTK_HAVE_CAIRO
1102 
1103 };
1104 
1145 class FL_EXPORT Fl_Widget_Tracker {
1146 
1147  Fl_Widget* wp_;
1148 
1149 public:
1150 
1152  ~Fl_Widget_Tracker();
1153 
1159  Fl_Widget *widget() {return wp_;}
1160 
1170  int deleted() {return wp_ == 0;}
1171 
1181  int exists() {return wp_ != 0;}
1182 
1183 };
1184 
1190 #endif // !Fl_H
1191 
1192 //
1193 // End of "$Id: Fl.H 9816 2013-02-08 11:58:19Z manolo $".
1194 //