FLTK 1.3.0
Fl.H
Go to the documentation of this file.
1 //
2 // "$Id: Fl.H 8724 2011-05-23 18:01:29Z 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; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
17 //
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 // USA.
22 //
23 // Please report all bugs and problems on the following page:
24 //
25 // http://www.fltk.org/str.php
26 //
27 
32 #ifndef Fl_H
33 # define Fl_H
34 
35 #ifdef FLTK_HAVE_CAIRO
36 # include <FL/Fl_Cairo.H>
37 #endif
38 
39 # include "fl_utf8.h"
40 # include "Enumerations.H"
41 # ifndef Fl_Object
42 # define Fl_Object Fl_Widget
43 # endif
44 
45 # ifdef check
46 # undef check
47 # endif
48 
49 
50 class Fl_Widget;
51 class Fl_Window;
52 class Fl_Image;
53 struct Fl_Label;
54 
55 
72 typedef void (Fl_Label_Draw_F)(const Fl_Label *label, int x, int y, int w, int h, Fl_Align align);
73 
75 typedef void (Fl_Label_Measure_F)(const Fl_Label *label, int &width, int &height);
76 
78 typedef void (Fl_Box_Draw_F)(int x, int y, int w, int h, Fl_Color color);
79 
81 typedef void (*Fl_Timeout_Handler)(void *data);
82 
84 typedef void (*Fl_Awake_Handler)(void *data);
85 
87 typedef void (*Fl_Idle_Handler)(void *data);
88 
90 typedef void (*Fl_Old_Idle_Handler)();
91 
93 typedef void (*Fl_FD_Handler)(int fd, void *data);
94 
96 typedef int (*Fl_Event_Handler)(int event);
97 
99 typedef void (*Fl_Abort_Handler)(const char *format,...);
100 
102 typedef void (*Fl_Atclose_Handler)(Fl_Window *window, void *data);
103 
105 typedef int (*Fl_Args_Handler)(int argc, char **argv, int &i);
106 
109 typedef int (*Fl_Event_Dispatch)(int event, Fl_Window *w);
110  /* group callback_functions */
112 
113 
118 class FL_EXPORT Fl {
119  Fl() {}; // no constructor!
120 
121 public: // should be private!
122 #ifndef FL_DOXYGEN
123  static int e_number;
124  static int e_x;
125  static int e_y;
126  static int e_x_root;
127  static int e_y_root;
128  static int e_dx;
129  static int e_dy;
130  static int e_state;
131  static int e_clicks;
132  static int e_is_click;
133  static int e_keysym;
134  static char* e_text;
135  static int e_length;
136  static Fl_Event_Dispatch e_dispatch;
137  static Fl_Widget* belowmouse_;
138  static Fl_Widget* pushed_;
139  static Fl_Widget* focus_;
140  static int damage_;
141  static Fl_Widget* selection_owner_;
142  static Fl_Window* modal_;
143  static Fl_Window* grab_;
144  static int compose_state;
145 #endif
146 
149  static void damage(int d) {damage_ = d;}
150 
151 public:
158  typedef enum {
163  OPTION_ARROW_FOCUS = 0,
164  // When switched on, FLTK will use the file chooser dialog that comes
165  // with your operating system whenever possible. When switched off, FLTK
166  // will present its own file chooser.
167  // \todo implement me
168  // OPTION_NATIVE_FILECHOOSER,
169  // When Filechooser Preview is enabled, the FLTK or native file chooser
170  // will show a preview of a selected file (if possible) before the user
171  // decides to choose the file.
172  // \todo implement me
173  //OPTION_FILECHOOSER_PREVIEW,
187  // don't change this, leave it always as the last element
189  OPTION_LAST
190  } Fl_Option;
191 
192 private:
193  static unsigned char options_[OPTION_LAST];
194  static unsigned char options_read_;
195 
196 public:
197  /*
198  Return a global setting for all FLTK applications, possibly overridden
199  by a setting specifically for this application.
200  */
201  static bool option(Fl_Option opt);
202 
203  /*
204  Override an option while the application is running.
205  */
206  static void option(Fl_Option opt, bool val);
207 
215  static void (*idle)();
216 
217 #ifndef FL_DOXYGEN
218  static Fl_Awake_Handler *awake_ring_;
219  static void **awake_data_;
220  static int awake_ring_size_;
221  static int awake_ring_head_;
222  static int awake_ring_tail_;
223  static const char* scheme_;
224  static Fl_Image* scheme_bg_;
225 
226  static int e_original_keysym; // late addition
227  static int scrollbar_size_;
228 #endif
229 
230 
231  static int add_awake_handler_(Fl_Awake_Handler, void*);
232  static int get_awake_handler_(Fl_Awake_Handler&, void*&);
233 
234 public:
235 
236  // API version number
237  static double version();
238 
239  // argument parsers:
240  static int arg(int argc, char **argv, int& i);
241  static int args(int argc, char **argv, int& i, Fl_Args_Handler cb = 0);
242  static void args(int argc, char **argv);
247  static const char* const help;
248 
249  // things called by initialization:
250  static void display(const char*);
251  static int visual(int);
261  static int gl_visual(int, int *alist=0); // platform dependent
262  static void own_colormap();
263  static void get_system_colors();
264  static void foreground(uchar, uchar, uchar);
265  static void background(uchar, uchar, uchar);
266  static void background2(uchar, uchar, uchar);
267 
268  // schemes:
269  static int scheme(const char*);
271  static const char* scheme() {return scheme_;}
277  static int reload_scheme(); // platform dependent
278  static int scrollbar_size();
279  static void scrollbar_size(int W);
280 
281  // execution:
282  static int wait();
283  static double wait(double time);
284  static int check();
285  static int ready();
286  static int run();
287  static Fl_Widget* readqueue();
314  static void add_timeout(double t, Fl_Timeout_Handler,void* = 0); // platform dependent
335  static void repeat_timeout(double t, Fl_Timeout_Handler, void* = 0); // platform dependent
336  static int has_timeout(Fl_Timeout_Handler, void* = 0);
337  static void remove_timeout(Fl_Timeout_Handler, void* = 0);
338  static void add_check(Fl_Timeout_Handler, void* = 0);
339  static int has_check(Fl_Timeout_Handler, void* = 0);
340  static void remove_check(Fl_Timeout_Handler, void* = 0);
360  static void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0); // platform dependent
362  static void add_fd(int fd, Fl_FD_Handler cb, void* = 0); // platform dependent
364  static void remove_fd(int, int when); // platform dependent
366  static void remove_fd(int); // platform dependent
367 
368  static void add_idle(Fl_Idle_Handler cb, void* data = 0);
369  static int has_idle(Fl_Idle_Handler cb, void* data = 0);
370  static void remove_idle(Fl_Idle_Handler cb, void* data = 0);
372  static int damage() {return damage_;}
373  static void redraw();
374  static void flush();
395  static void (*warning)(const char*, ...);
410  static void (*error)(const char*, ...);
427  static void (*fatal)(const char*, ...);
433  static Fl_Window* first_window();
434  static void first_window(Fl_Window*);
435  static Fl_Window* next_window(const Fl_Window*);
436 
446  static Fl_Window* modal() {return modal_;}
452  static Fl_Window* grab() {return grab_;}
477  static void grab(Fl_Window*); // platform dependent
484  // event information:
490  static int event() {return e_number;}
495  static int event_x() {return e_x;}
500  static int event_y() {return e_y;}
507  static int event_x_root() {return e_x_root;}
514  static int event_y_root() {return e_y_root;}
519  static int event_dx() {return e_dx;}
524  static int event_dy() {return e_dy;}
533  static void get_mouse(int &,int &); // platform dependent
542  static int event_clicks() {return e_clicks;}
550  static void event_clicks(int i) {e_clicks = i;}
558  static int event_is_click() {return e_is_click;}
565  static void event_is_click(int i) {e_is_click = i;}
572  static int event_button() {return e_keysym-FL_Button;}
596  static int event_state() {return e_state;}
598  static int event_state(int i) {return e_state&i;}
610  static int event_key() {return e_keysym;}
619  static int event_original_key(){return e_original_keysym;}
658  static int event_key(int key);
664  static int get_key(int key); // platform dependent
679  static const char* event_text() {return e_text;}
686  static int event_length() {return e_length;}
687 
688  static int compose(int &del);
689  static void compose_reset();
690  static int event_inside(int,int,int,int);
691  static int event_inside(const Fl_Widget*);
692  static int test_shortcut(Fl_Shortcut);
693 
694  // event destinations:
695  static int handle(int, Fl_Window*);
696  static int handle_(int, Fl_Window*);
699  static Fl_Widget* belowmouse() {return belowmouse_;}
700  static void belowmouse(Fl_Widget*);
703  static Fl_Widget* pushed() {return pushed_;}
704  static void pushed(Fl_Widget*);
706  static Fl_Widget* focus() {return focus_;}
707  static void focus(Fl_Widget*);
708  static void add_handler(Fl_Event_Handler h);
709  static void remove_handler(Fl_Event_Handler h);
710  static void event_dispatch(Fl_Event_Dispatch d);
711  static Fl_Event_Dispatch event_dispatch();
717  // cut/paste:
727  static void copy(const char* stuff, int len, int destination = 0); // platform dependent
745  static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent
755  static int dnd(); // platform dependent
756 
757  // These are for back-compatibility only:
760  static Fl_Widget* selection_owner() {return selection_owner_;}
761  static void selection_owner(Fl_Widget*);
762  static void selection(Fl_Widget &owner, const char*, int len);
763  static void paste(Fl_Widget &receiver);
768  // screen size:
770  static int x(); // platform dependent
772  static int y(); // platform dependent
774  static int w(); // platform dependent
776  static int h(); // platform dependent
777 
778  // multi-head support:
779  static int screen_count();
785  static void screen_xywh(int &X, int &Y, int &W, int &H) {
786  screen_xywh(X, Y, W, H, e_x_root, e_y_root);
787  }
788  static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
789  static void screen_xywh(int &X, int &Y, int &W, int &H, int n);
790  static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh);
791  static void screen_dpi(float &h, float &v, int n=0);
792 
800  // color map:
801  static void set_color(Fl_Color, uchar, uchar, uchar);
806  static void set_color(Fl_Color i, unsigned c); // platform dependent
807  static unsigned get_color(Fl_Color i);
808  static void get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue);
814  static void free_color(Fl_Color i, int overlay = 0); // platform dependent
815 
816  // fonts:
817  static const char* get_font(Fl_Font);
830  static const char* get_font_name(Fl_Font, int* attributes = 0);
842  static int get_font_sizes(Fl_Font, int*& sizep);
843  static void set_font(Fl_Font, const char*);
844  static void set_font(Fl_Font, Fl_Font);
863  static Fl_Font set_fonts(const char* = 0); // platform dependent
864 
871  // <Hack to re-order the 'Drawing functions' group>
874  // labeltypes:
875  static void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*);
877  static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined ?
878 
879  // boxtypes:
880  static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype);
881  static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar);
882  static void set_boxtype(Fl_Boxtype, Fl_Boxtype from);
883  static int box_dx(Fl_Boxtype);
884  static int box_dy(Fl_Boxtype);
885  static int box_dw(Fl_Boxtype);
886  static int box_dh(Fl_Boxtype);
887  static int draw_box_active();
888 
889  // back compatibility:
893  static void set_abort(Fl_Abort_Handler f) {fatal = f;}
894  static void (*atclose)(Fl_Window*,void*);
895  static void default_atclose(Fl_Window*,void*);
899  static void set_atclose(Fl_Atclose_Handler f) {atclose = f;}
905  static int event_shift() {return e_state&FL_SHIFT;}
907  static int event_ctrl() {return e_state&FL_CTRL;}
909  static int event_command() {return e_state&FL_COMMAND;}
911  static int event_alt() {return e_state&FL_ALT;}
920  static int event_buttons() {return e_state&0x7f000000;}
925  static int event_button1() {return e_state&FL_BUTTON1;}
930  static int event_button2() {return e_state&FL_BUTTON2;}
935  static int event_button3() {return e_state&FL_BUTTON3;}
943  static void set_idle(Fl_Old_Idle_Handler cb) {idle = cb;}
945  static void grab(Fl_Window& win) {grab(&win);}
949  static void release() {grab(0);}
950 
951  // Visible focus methods...
957  static void visible_focus(int v) { option(OPTION_VISIBLE_FOCUS, (v!=0)); }
963  static int visible_focus() { return option(OPTION_VISIBLE_FOCUS); }
964 
965  // Drag-n-drop text operation methods...
972  static void dnd_text_ops(int v) { option(OPTION_DND_TEXT, (v!=0)); }
979  static int dnd_text_ops() { return option(OPTION_DND_TEXT); }
984  // Multithreading support:
985  static int lock();
986  static void unlock();
987  static void awake(void* message = 0);
989  static int awake(Fl_Awake_Handler cb, void* message = 0);
996  static void* thread_message(); // platform dependent
1028  // Widget deletion:
1029  static void delete_widget(Fl_Widget *w);
1030  static void do_widget_deletion();
1031  static void watch_widget_pointer(Fl_Widget *&w);
1032  static void release_widget_pointer(Fl_Widget *&w);
1033  static void clear_widget_pointer(Fl_Widget const *w);
1036 #ifdef FLTK_HAVE_CAIRO
1037 
1040 public:
1041  // Cairo support API
1042  static cairo_t * cairo_make_current(Fl_Window* w);
1057  static void cairo_autolink_context(bool alink) {cairo_state_.autolink(alink);}
1065  static bool cairo_autolink_context() {return cairo_state_.autolink();}
1067  static cairo_t * cairo_cc() { return cairo_state_.cc(); }
1072  static void cairo_cc(cairo_t * c, bool own=false){ cairo_state_.cc(c, own); }
1073 
1074 private:
1075  static cairo_t * cairo_make_current(void* gc);
1076  static cairo_t * cairo_make_current(void* gc, int W, int H);
1077  static Fl_Cairo_State cairo_state_;
1078 public:
1081 #endif // FLTK_HAVE_CAIRO
1082 
1083 };
1084 
1125 class FL_EXPORT Fl_Widget_Tracker {
1126 
1127  Fl_Widget* wp_;
1128 
1129 public:
1130 
1132  ~Fl_Widget_Tracker();
1133 
1139  Fl_Widget *widget() {return wp_;}
1140 
1150  int deleted() {return wp_ == 0;}
1151 
1161  int exists() {return wp_ != 0;}
1162 
1163 };
1164 
1170 #endif // !Fl_H
1171 
1172 //
1173 // End of "$Id: Fl.H 8724 2011-05-23 18:01:29Z manolo $".
1174 //