FLTK 1.3.2
|
00001 // 00002 // "$Id$" 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; 00146 static void call_screen_init(); // recompute screen number and dimensions 00147 #ifdef __APPLE__ 00148 static int marked_text_length(void); // returns length of marked text 00149 static void reset_marked_text(); // resets marked text 00150 static void insertion_point_location(int x, int y, int height); // sets window coordinates & height of insertion point 00151 #endif 00152 #endif 00153 00156 static void damage(int d) {damage_ = d;} 00157 00158 public: 00165 typedef enum { 00170 OPTION_ARROW_FOCUS = 0, 00171 // When switched on, FLTK will use the file chooser dialog that comes 00172 // with your operating system whenever possible. When switched off, FLTK 00173 // will present its own file chooser. 00174 // \todo implement me 00175 // OPTION_NATIVE_FILECHOOSER, 00176 // When Filechooser Preview is enabled, the FLTK or native file chooser 00177 // will show a preview of a selected file (if possible) before the user 00178 // decides to choose the file. 00179 // \todo implement me 00180 //OPTION_FILECHOOSER_PREVIEW, 00185 OPTION_VISIBLE_FOCUS, 00189 OPTION_DND_TEXT, 00193 OPTION_SHOW_TOOLTIPS, 00194 // don't change this, leave it always as the last element 00196 OPTION_LAST 00197 } Fl_Option; 00198 00199 private: 00200 static unsigned char options_[OPTION_LAST]; 00201 static unsigned char options_read_; 00202 00203 public: 00204 /* 00205 Return a global setting for all FLTK applications, possibly overridden 00206 by a setting specifically for this application. 00207 */ 00208 static bool option(Fl_Option opt); 00209 00210 /* 00211 Override an option while the application is running. 00212 */ 00213 static void option(Fl_Option opt, bool val); 00214 00222 static void (*idle)(); 00223 00224 #ifndef FL_DOXYGEN 00225 static Fl_Awake_Handler *awake_ring_; 00226 static void **awake_data_; 00227 static int awake_ring_size_; 00228 static int awake_ring_head_; 00229 static int awake_ring_tail_; 00230 static const char* scheme_; 00231 static Fl_Image* scheme_bg_; 00232 00233 static int e_original_keysym; // late addition 00234 static int scrollbar_size_; 00235 #endif 00236 00237 00238 static int add_awake_handler_(Fl_Awake_Handler, void*); 00239 static int get_awake_handler_(Fl_Awake_Handler&, void*&); 00240 00241 public: 00242 00243 // API version number 00244 static double version(); 00245 00246 // argument parsers: 00247 static int arg(int argc, char **argv, int& i); 00248 static int args(int argc, char **argv, int& i, Fl_Args_Handler cb = 0); 00249 static void args(int argc, char **argv); 00254 static const char* const help; 00255 00256 // things called by initialization: 00257 static void display(const char*); 00258 static int visual(int); 00268 static int gl_visual(int, int *alist=0); // platform dependent 00269 static void own_colormap(); 00270 static void get_system_colors(); 00271 static void foreground(uchar, uchar, uchar); 00272 static void background(uchar, uchar, uchar); 00273 static void background2(uchar, uchar, uchar); 00274 00275 // schemes: 00276 static int scheme(const char*); 00278 static const char* scheme() {return scheme_;} 00284 static int reload_scheme(); // platform dependent 00285 static int scrollbar_size(); 00286 static void scrollbar_size(int W); 00287 00288 // execution: 00289 static int wait(); 00290 static double wait(double time); 00291 static int check(); 00292 static int ready(); 00293 static int run(); 00294 static Fl_Widget* readqueue(); 00321 static void add_timeout(double t, Fl_Timeout_Handler,void* = 0); // platform dependent 00342 static void repeat_timeout(double t, Fl_Timeout_Handler, void* = 0); // platform dependent 00343 static int has_timeout(Fl_Timeout_Handler, void* = 0); 00344 static void remove_timeout(Fl_Timeout_Handler, void* = 0); 00345 static void add_check(Fl_Timeout_Handler, void* = 0); 00346 static int has_check(Fl_Timeout_Handler, void* = 0); 00347 static void remove_check(Fl_Timeout_Handler, void* = 0); 00367 static void add_fd(int fd, int when, Fl_FD_Handler cb, void* = 0); // platform dependent 00369 static void add_fd(int fd, Fl_FD_Handler cb, void* = 0); // platform dependent 00371 static void remove_fd(int, int when); // platform dependent 00373 static void remove_fd(int); // platform dependent 00374 00375 static void add_idle(Fl_Idle_Handler cb, void* data = 0); 00376 static int has_idle(Fl_Idle_Handler cb, void* data = 0); 00377 static void remove_idle(Fl_Idle_Handler cb, void* data = 0); 00379 static int damage() {return damage_;} 00380 static void redraw(); 00381 static void flush(); 00402 static void (*warning)(const char*, ...); 00417 static void (*error)(const char*, ...); 00434 static void (*fatal)(const char*, ...); 00440 static Fl_Window* first_window(); 00441 static void first_window(Fl_Window*); 00442 static Fl_Window* next_window(const Fl_Window*); 00443 00453 static Fl_Window* modal() {return modal_;} 00459 static Fl_Window* grab() {return grab_;} 00484 static void grab(Fl_Window*); // platform dependent 00491 // event information: 00497 static int event() {return e_number;} 00502 static int event_x() {return e_x;} 00507 static int event_y() {return e_y;} 00514 static int event_x_root() {return e_x_root;} 00521 static int event_y_root() {return e_y_root;} 00526 static int event_dx() {return e_dx;} 00531 static int event_dy() {return e_dy;} 00540 static void get_mouse(int &,int &); // platform dependent 00549 static int event_clicks() {return e_clicks;} 00557 static void event_clicks(int i) {e_clicks = i;} 00565 static int event_is_click() {return e_is_click;} 00572 static void event_is_click(int i) {e_is_click = i;} 00579 static int event_button() {return e_keysym-FL_Button;} 00603 static int event_state() {return e_state;} 00605 static int event_state(int i) {return e_state&i;} 00617 static int event_key() {return e_keysym;} 00626 static int event_original_key(){return e_original_keysym;} 00665 static int event_key(int key); 00671 static int get_key(int key); // platform dependent 00686 static const char* event_text() {return e_text;} 00693 static int event_length() {return e_length;} 00694 00695 static int compose(int &del); 00696 static void compose_reset(); 00697 static int event_inside(int,int,int,int); 00698 static int event_inside(const Fl_Widget*); 00699 static int test_shortcut(Fl_Shortcut); 00700 00701 // event destinations: 00702 static int handle(int, Fl_Window*); 00703 static int handle_(int, Fl_Window*); 00706 static Fl_Widget* belowmouse() {return belowmouse_;} 00707 static void belowmouse(Fl_Widget*); 00710 static Fl_Widget* pushed() {return pushed_;} 00711 static void pushed(Fl_Widget*); 00713 static Fl_Widget* focus() {return focus_;} 00714 static void focus(Fl_Widget*); 00715 static void add_handler(Fl_Event_Handler h); 00716 static void remove_handler(Fl_Event_Handler h); 00717 static void event_dispatch(Fl_Event_Dispatch d); 00718 static Fl_Event_Dispatch event_dispatch(); 00724 // cut/paste: 00734 static void copy(const char* stuff, int len, int destination = 0); // platform dependent 00752 static void paste(Fl_Widget &receiver, int source /*=0*/); // platform dependent 00762 static int dnd(); // platform dependent 00763 00764 // These are for back-compatibility only: 00767 static Fl_Widget* selection_owner() {return selection_owner_;} 00768 static void selection_owner(Fl_Widget*); 00769 static void selection(Fl_Widget &owner, const char*, int len); 00770 static void paste(Fl_Widget &receiver); 00775 // screen size: 00777 static int x(); // platform dependent 00779 static int y(); // platform dependent 00781 static int w(); // platform dependent 00783 static int h(); // platform dependent 00784 00785 // multi-head support: 00786 static int screen_count(); 00792 static void screen_xywh(int &X, int &Y, int &W, int &H) { 00793 int x, y; 00794 Fl::get_mouse(x, y); 00795 screen_xywh(X, Y, W, H, x, y); 00796 } 00797 static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my); 00798 static void screen_xywh(int &X, int &Y, int &W, int &H, int n); 00799 static void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh); 00800 static void screen_dpi(float &h, float &v, int n=0); 00801 static void screen_work_area(int &X, int &Y, int &W, int &H, int mx, int my); 00802 static void screen_work_area(int &X, int &Y, int &W, int &H, int n); 00808 static void screen_work_area(int &X, int &Y, int &W, int &H) { 00809 int x, y; 00810 Fl::get_mouse(x, y); 00811 screen_work_area(X, Y, W, H, x, y); 00812 } 00813 00821 // color map: 00822 static void set_color(Fl_Color, uchar, uchar, uchar); 00827 static void set_color(Fl_Color i, unsigned c); // platform dependent 00828 static unsigned get_color(Fl_Color i); 00829 static void get_color(Fl_Color i, uchar &red, uchar &green, uchar &blue); 00835 static void free_color(Fl_Color i, int overlay = 0); // platform dependent 00836 00837 // fonts: 00838 static const char* get_font(Fl_Font); 00851 static const char* get_font_name(Fl_Font, int* attributes = 0); 00863 static int get_font_sizes(Fl_Font, int*& sizep); 00864 static void set_font(Fl_Font, const char*); 00865 static void set_font(Fl_Font, Fl_Font); 00884 static Fl_Font set_fonts(const char* = 0); // platform dependent 00885 00892 // <Hack to re-order the 'Drawing functions' group> 00895 // labeltypes: 00896 static void set_labeltype(Fl_Labeltype,Fl_Label_Draw_F*,Fl_Label_Measure_F*); 00898 static void set_labeltype(Fl_Labeltype, Fl_Labeltype from); // is it defined ? 00899 00900 // boxtypes: 00901 static Fl_Box_Draw_F *get_boxtype(Fl_Boxtype); 00902 static void set_boxtype(Fl_Boxtype, Fl_Box_Draw_F*,uchar,uchar,uchar,uchar); 00903 static void set_boxtype(Fl_Boxtype, Fl_Boxtype from); 00904 static int box_dx(Fl_Boxtype); 00905 static int box_dy(Fl_Boxtype); 00906 static int box_dw(Fl_Boxtype); 00907 static int box_dh(Fl_Boxtype); 00908 static int draw_box_active(); 00909 00910 // back compatibility: 00914 static void set_abort(Fl_Abort_Handler f) {fatal = f;} 00915 static void (*atclose)(Fl_Window*,void*); 00916 static void default_atclose(Fl_Window*,void*); 00920 static void set_atclose(Fl_Atclose_Handler f) {atclose = f;} 00926 static int event_shift() {return e_state&FL_SHIFT;} 00928 static int event_ctrl() {return e_state&FL_CTRL;} 00930 static int event_command() {return e_state&FL_COMMAND;} 00932 static int event_alt() {return e_state&FL_ALT;} 00941 static int event_buttons() {return e_state&0x7f000000;} 00946 static int event_button1() {return e_state&FL_BUTTON1;} 00951 static int event_button2() {return e_state&FL_BUTTON2;} 00956 static int event_button3() {return e_state&FL_BUTTON3;} 00964 static void set_idle(Fl_Old_Idle_Handler cb) {idle = cb;} 00966 static void grab(Fl_Window& win) {grab(&win);} 00970 static void release() {grab(0);} 00971 00972 // Visible focus methods... 00978 static void visible_focus(int v) { option(OPTION_VISIBLE_FOCUS, (v!=0)); } 00984 static int visible_focus() { return option(OPTION_VISIBLE_FOCUS); } 00985 00986 // Drag-n-drop text operation methods... 00993 static void dnd_text_ops(int v) { option(OPTION_DND_TEXT, (v!=0)); } 01000 static int dnd_text_ops() { return option(OPTION_DND_TEXT); } 01005 // Multithreading support: 01006 static int lock(); 01007 static void unlock(); 01008 static void awake(void* message = 0); 01010 static int awake(Fl_Awake_Handler cb, void* message = 0); 01017 static void* thread_message(); // platform dependent 01049 // Widget deletion: 01050 static void delete_widget(Fl_Widget *w); 01051 static void do_widget_deletion(); 01052 static void watch_widget_pointer(Fl_Widget *&w); 01053 static void release_widget_pointer(Fl_Widget *&w); 01054 static void clear_widget_pointer(Fl_Widget const *w); 01057 #ifdef FLTK_HAVE_CAIRO 01058 01061 public: 01062 // Cairo support API 01063 static cairo_t * cairo_make_current(Fl_Window* w); 01078 static void cairo_autolink_context(bool alink) {cairo_state_.autolink(alink);} 01086 static bool cairo_autolink_context() {return cairo_state_.autolink();} 01088 static cairo_t * cairo_cc() { return cairo_state_.cc(); } 01093 static void cairo_cc(cairo_t * c, bool own=false){ cairo_state_.cc(c, own); } 01094 01095 private: 01096 static cairo_t * cairo_make_current(void* gc); 01097 static cairo_t * cairo_make_current(void* gc, int W, int H); 01098 static Fl_Cairo_State cairo_state_; 01099 public: 01102 #endif // FLTK_HAVE_CAIRO 01103 01104 }; 01105 01146 class FL_EXPORT Fl_Widget_Tracker { 01147 01148 Fl_Widget* wp_; 01149 01150 public: 01151 01152 Fl_Widget_Tracker(Fl_Widget *wi); 01153 ~Fl_Widget_Tracker(); 01154 01160 Fl_Widget *widget() {return wp_;} 01161 01171 int deleted() {return wp_ == 0;} 01172 01182 int exists() {return wp_ != 0;} 01183 01184 }; 01185 01191 #endif // !Fl_H 01192 01193 // 01194 // End of "$Id$". 01195 //