|
FLTK 1.3.2
|
00001 // 00002 // "$Id: Fl.H 9816 2013-02-08 11:58:19Z 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. 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; // used for dead keys (WIN32) or marked text (MacOS) 00146 static void call_screen_init(); // recompute screen number and dimensions 00147 #ifdef __APPLE__ 00148 static void reset_marked_text(); // resets marked text 00149 static void insertion_point_location(int x, int y, int height); // sets window coordinates & height of insertion point 00150 #endif 00151 #endif 00152 00155 static void damage(int d) {damage_ = d;} 00156 00157 public: 00164 typedef enum { 00169 OPTION_ARROW_FOCUS = 0, 00170 // When switched on, FLTK will use the file chooser dialog that comes 00171 // with your operating system whenever possible. When switched off, FLTK 00172 // will present its own file chooser. 00173 // \todo implement me 00174 // OPTION_NATIVE_FILECHOOSER, 00175 // When Filechooser Preview is enabled, the FLTK or native file chooser 00176 // will show a preview of a selected file (if possible) before the user 00177 // decides to choose the file. 00178 // \todo implement me 00179 //OPTION_FILECHOOSER_PREVIEW, 00184 OPTION_VISIBLE_FOCUS, 00188 OPTION_DND_TEXT, 00192 OPTION_SHOW_TOOLTIPS, 00193 // don't change this, leave it always as the last element 00195 OPTION_LAST 00196 } Fl_Option; 00197 00198 private: 00199 static unsigned char options_[OPTION_LAST]; 00200 static unsigned char options_read_; 00201 00202 public: 00203 /* 00204 Return a global setting for all FLTK applications, possibly overridden 00205 by a setting specifically for this application. 00206 */ 00207 static bool option(Fl_Option opt); 00208 00209 /* 00210 Override an option while the application is running. 00211 */ 00212 static void option(Fl_Option opt, bool val); 00213 00221 static void (*idle)(); 00222 00223 #ifndef FL_DOXYGEN 00224 static Fl_Awake_Handler *awake_ring_; 00225 static void **awake_data_; 00226 static int awake_ring_size_; 00227 static int awake_ring_head_; 00228 static int awake_ring_tail_; 00229 static const char* scheme_; 00230 static Fl_Image* scheme_bg_; 00231 00232 static int e_original_keysym; // late addition 00233 static int scrollbar_size_; 00234 #endif 00235 00236 00237 static int add_awake_handler_(Fl_Awake_Handler, void*); 00238 static int get_awake_handler_(Fl_Awake_Handler&, void*&); 00239 00240 public: 00241 00242 // API version number 00243 static double version(); 00244 00245 // argument parsers: 00246 static int arg(int argc, char **argv, int& i); 00247 static int args(int argc, char **argv, int& i, Fl_Args_Handler cb = 0); 00248 static void args(int argc, char **argv); 00253 static const char* const help; 00254 00255 // things called by initialization: 00256 static void display(const char*); 00257 static int visual(int); 00267 static int gl_visual(int, int *alist=0); // platform dependent 00268 static void own_colormap(); 00269 static void get_system_colors(); 00270 static void foreground(uchar, uchar, uchar); 00271 static void background(uchar, uchar, uchar); 00272 static void background2(uchar, uchar, uchar); 00273 00274 // schemes: 00275 static int scheme(const char*); 00277 static const char* scheme() {return scheme_;} 00283 static int reload_scheme(); // platform dependent 00284 static int scrollbar_size(); 00285 static void scrollbar_size(int W); 00286 00287 // execution: 00288 static int wait(); 00289 static double wait(double time); 00290 static int check(); 00291 static int ready(); 00292 static int run(); 00293 static Fl_Widget* readqueue(); 00320 static void add_timeout(double t, Fl_Timeout_Handler,void* = 0); // platform dependent 00341 static void repeat_timeout(double t, Fl_Timeout_Handler, void* = 0); // platform dependent 00342 static int has_timeout(Fl_Timeout_Handler, void* = 0); 00343 static void remove_timeout(Fl_Timeout_Handler, void* = 0); 00344 static void add_check(Fl_Timeout_Handler, void* = 0); 00345 static int has_check(Fl_Timeout_Handler, void* = 0); 00346 static void remove_check(Fl_Timeout_Handler, void* = 0); 00366 static void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0); // platform dependent 00368 static void add_fd(int fd, Fl_FD_Handler cb, void* = 0); // platform dependent 00370 static void remove_fd(int, int when); // platform dependent 00372 static void remove_fd(int); // platform dependent 00373 00374 static void add_idle(Fl_Idle_Handler cb, void* data = 0); 00375 static int has_idle(Fl_Idle_Handler cb, void* data = 0); 00376 static void remove_idle(Fl_Idle_Handler cb, void* data = 0); 00378 static int damage() {return damage_;} 00379 static void redraw(); 00380 static void flush(); 00401 static void (*warning)(const char*, ...); 00416 static void (*error)(const char*, ...); 00433 static void (*fatal)(const char*, ...); 00439 static Fl_Window* first_window(); 00440 static void first_window(Fl_Window*); 00441 static Fl_Window* next_window(const Fl_Window*); 00442 00452 static Fl_Window* modal() {return modal_;} 00458 static Fl_Window* grab() {return grab_;} 00483 static void grab(Fl_Window*); // platform dependent 00490 // event information: 00496 static int event() {return e_number;} 00501 static int event_x() {return e_x;} 00506 static int event_y() {return e_y;} 00513 static int event_x_root() {return e_x_root;} 00520 static int event_y_root() {return e_y_root;} 00525 static int event_dx() {return e_dx;} 00530 static int event_dy() {return e_dy;} 00539 static void get_mouse(int &,int &); // platform dependent 00548 static int event_clicks() {return e_clicks;} 00556 static void event_clicks(int i) {e_clicks = i;} 00564 static int event_is_click() {return e_is_click;} 00571 static void event_is_click(int i) {e_is_click = i;} 00578 static int event_button() {return e_keysym-FL_Button;} 00602 static int event_state() {return e_state;} 00604 static int event_state(int i) {return e_state&i;} 00616 static int event_key() {return e_keysym;} 00625 static int event_original_key(){return e_original_keysym;} 00664 static int event_key(int key); 00670 static int get_key(int key); // platform dependent 00685 static const char* event_text() {return e_text;} 00692 static int event_length() {return e_length;} 00693 00694 static int compose(int &del); 00695 static void compose_reset(); 00696 static int event_inside(int,int,int,int); 00697 static int event_inside(const Fl_Widget*); 00698 static int test_shortcut(Fl_Shortcut); 00699 00700 // event destinations: 00701 static int handle(int, Fl_Window*); 00702 static int handle_(int, Fl_Window*); 00705 static Fl_Widget* belowmouse() {return belowmouse_;} 00706 static void belowmouse(Fl_Widget*); 00709 static Fl_Widget* pushed() {return pushed_;} 00710 static void pushed(Fl_Widget*); 00712 static Fl_Widget* focus() {return focus_;} 00713 static void focus(Fl_Widget*); 00714 static void add_handler(Fl_Event_Handler h); 00715 static void remove_handler(Fl_Event_Handler h); 00716 static void event_dispatch(Fl_Event_Dispatch d); 00717 static Fl_Event_Dispatch event_dispatch(); 00723 // cut/paste: 00733 static void copy(const char* stuff, int len, int destination = 0); // platform dependent 00751 static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent 00761 static int dnd(); // platform dependent 00762 00763 // These are for back-compatibility only: 00766 static Fl_Widget* selection_owner() {return selection_owner_;} 00767 static void selection_owner(Fl_Widget*); 00768 static void selection(Fl_Widget &owner, const char*, int len); 00769 static void paste(Fl_Widget &receiver); 00774 // screen size: 00776 static int x(); // platform dependent 00778 static int y(); // platform dependent 00780 static int w(); // platform dependent 00782 static int h(); // platform dependent 00783 00784 // multi-head support: 00785 static int screen_count(); 00791 static void screen_xywh(int &X, int &Y, int &W, int &H) { 00792 int x, y; 00793 Fl::get_mouse(x, y); 00794 screen_xywh(X, Y, W, H, x, y); 00795 } 00796 static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my); 00797 static void screen_xywh(int &X, int &Y, int &W, int &H, int n); 00798 static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh); 00799 static void screen_dpi(float &h, float &v, int n=0); 00800 static void screen_work_area(int &X, int &Y, int &W, int &H, int mx, int my); 00801 static void screen_work_area(int &X, int &Y, int &W, int &H, int n); 00807 static void screen_work_area(int &X, int &Y, int &W, int &H) { 00808 int x, y; 00809 Fl::get_mouse(x, y); 00810 screen_work_area(X, Y, W, H, x, y); 00811 } 00812 00820 // color map: 00821 static void set_color(Fl_Color, uchar, uchar, uchar); 00826 static void set_color(Fl_Color i, unsigned c); // platform dependent 00827 static unsigned get_color(Fl_Color i); 00828 static void get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue); 00834 static void free_color(Fl_Color i, int overlay = 0); // platform dependent 00835 00836 // fonts: 00837 static const char* get_font(Fl_Font); 00850 static const char* get_font_name(Fl_Font, int* attributes = 0); 00862 static int get_font_sizes(Fl_Font, int*& sizep); 00863 static void set_font(Fl_Font, const char*); 00864 static void set_font(Fl_Font, Fl_Font); 00883 static Fl_Font set_fonts(const char* = 0); // platform dependent 00884 00891 // <Hack to re-order the 'Drawing functions' group> 00894 // labeltypes: 00895 static void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*); 00897 static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined ? 00898 00899 // boxtypes: 00900 static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype); 00901 static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar); 00902 static void set_boxtype(Fl_Boxtype, Fl_Boxtype from); 00903 static int box_dx(Fl_Boxtype); 00904 static int box_dy(Fl_Boxtype); 00905 static int box_dw(Fl_Boxtype); 00906 static int box_dh(Fl_Boxtype); 00907 static int draw_box_active(); 00908 00909 // back compatibility: 00913 static void set_abort(Fl_Abort_Handler f) {fatal = f;} 00914 static void (*atclose)(Fl_Window*,void*); 00915 static void default_atclose(Fl_Window*,void*); 00919 static void set_atclose(Fl_Atclose_Handler f) {atclose = f;} 00925 static int event_shift() {return e_state&FL_SHIFT;} 00927 static int event_ctrl() {return e_state&FL_CTRL;} 00929 static int event_command() {return e_state&FL_COMMAND;} 00931 static int event_alt() {return e_state&FL_ALT;} 00940 static int event_buttons() {return e_state&0x7f000000;} 00945 static int event_button1() {return e_state&FL_BUTTON1;} 00950 static int event_button2() {return e_state&FL_BUTTON2;} 00955 static int event_button3() {return e_state&FL_BUTTON3;} 00963 static void set_idle(Fl_Old_Idle_Handler cb) {idle = cb;} 00965 static void grab(Fl_Window& win) {grab(&win);} 00969 static void release() {grab(0);} 00970 00971 // Visible focus methods... 00977 static void visible_focus(int v) { option(OPTION_VISIBLE_FOCUS, (v!=0)); } 00983 static int visible_focus() { return option(OPTION_VISIBLE_FOCUS); } 00984 00985 // Drag-n-drop text operation methods... 00992 static void dnd_text_ops(int v) { option(OPTION_DND_TEXT, (v!=0)); } 00999 static int dnd_text_ops() { return option(OPTION_DND_TEXT); } 01004 // Multithreading support: 01005 static int lock(); 01006 static void unlock(); 01007 static void awake(void* message = 0); 01009 static int awake(Fl_Awake_Handler cb, void* message = 0); 01016 static void* thread_message(); // platform dependent 01048 // Widget deletion: 01049 static void delete_widget(Fl_Widget *w); 01050 static void do_widget_deletion(); 01051 static void watch_widget_pointer(Fl_Widget *&w); 01052 static void release_widget_pointer(Fl_Widget *&w); 01053 static void clear_widget_pointer(Fl_Widget const *w); 01056 #ifdef FLTK_HAVE_CAIRO 01057 01060 public: 01061 // Cairo support API 01062 static cairo_t * cairo_make_current(Fl_Window* w); 01077 static void cairo_autolink_context(bool alink) {cairo_state_.autolink(alink);} 01085 static bool cairo_autolink_context() {return cairo_state_.autolink();} 01087 static cairo_t * cairo_cc() { return cairo_state_.cc(); } 01092 static void cairo_cc(cairo_t * c, bool own=false){ cairo_state_.cc(c, own); } 01093 01094 private: 01095 static cairo_t * cairo_make_current(void* gc); 01096 static cairo_t * cairo_make_current(void* gc, int W, int H); 01097 static Fl_Cairo_State cairo_state_; 01098 public: 01101 #endif // FLTK_HAVE_CAIRO 01102 01103 }; 01104 01145 class FL_EXPORT Fl_Widget_Tracker { 01146 01147 Fl_Widget* wp_; 01148 01149 public: 01150 01151 Fl_Widget_Tracker(Fl_Widget *wi); 01152 ~Fl_Widget_Tracker(); 01153 01159 Fl_Widget *widget() {return wp_;} 01160 01170 int deleted() {return wp_ == 0;} 01171 01181 int exists() {return wp_ != 0;} 01182 01183 }; 01184 01190 #endif // !Fl_H 01191 01192 // 01193 // End of "$Id: Fl.H 9816 2013-02-08 11:58:19Z manolo $". 01194 //