Fl_Screen_Driver.H 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // "$Id: Fl_Screen_Driver.H 12628 2018-01-09 07:26:49Z manolo $"
  3. //
  4. // All screen related calls in a driver style class.
  5. //
  6. // Copyright 1998-2017 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. #ifndef FL_SCREEN_DRIVER_H
  19. #define FL_SCREEN_DRIVER_H
  20. #include <FL/Fl_Device.H>
  21. #include <FL/fl_types.h>
  22. #include <FL/Fl.H> // for Fl_Timeout_Handler
  23. #include <FL/Fl_Text_Editor.H>
  24. // TODO: add text composition?
  25. // TODO: add Fl::display
  26. // TODO: add copy/paste, drag/drop?
  27. // TODO: get key/get mouse?
  28. // TODO: system colors/colormaps
  29. // TODO: system menu?
  30. // TODO: native filechooser
  31. // TODO: native message boxes
  32. // TODO: read screen to image
  33. // TODO: application shortcuts
  34. class Fl_Window;
  35. class Fl_RGB_Image;
  36. class Fl_Group;
  37. class Fl_Input;
  38. /** A base class describing the interface between FLTK and screen-related operations.
  39. This class is only for internal use by the FLTK library.
  40. Each supported platform implements several of the virtual methods of this class.
  41. */
  42. class FL_EXPORT Fl_Screen_Driver {
  43. protected:
  44. Fl_Screen_Driver();
  45. virtual ~Fl_Screen_Driver();
  46. static const int MAX_SCREENS = 16;
  47. int num_screens;
  48. static float fl_intersection(int x1, int y1, int w1, int h1,
  49. int x2, int y2, int w2, int h2);
  50. public:
  51. static char bg_set;
  52. static char bg2_set;
  53. static char fg_set;
  54. public:
  55. virtual float scale(int n) {return 1;}
  56. virtual void scale(int n, float f) { }
  57. static Fl_Screen_Driver *newScreenDriver();
  58. // --- display management
  59. virtual void display(const char *disp);
  60. virtual int visual(int flags);
  61. // --- screen configuration
  62. virtual void init() = 0;
  63. virtual int x() = 0;
  64. virtual int y() = 0;
  65. virtual int w() = 0;
  66. virtual int h() = 0;
  67. virtual int screen_count();
  68. void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
  69. virtual void screen_xywh(int &X, int &Y, int &W, int &H, int n) = 0;
  70. void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh);
  71. virtual int screen_num(int x, int y);
  72. virtual int screen_num(int x, int y, int w, int h);
  73. virtual void screen_dpi(float &h, float &v, int n=0) = 0;
  74. void screen_work_area(int &X, int &Y, int &W, int &H, int mx, int my);
  75. virtual void screen_work_area(int &X, int &Y, int &W, int &H, int n) = 0;
  76. // --- audible output
  77. virtual void beep(int type) = 0;
  78. // --- global events
  79. virtual void flush() = 0;
  80. virtual double wait(double time_to_wait) = 0;
  81. virtual int ready() = 0;
  82. virtual void grab(Fl_Window* win) = 0;
  83. // --- global colors
  84. /* the default implementation of parse_color() may be enough */
  85. virtual int parse_color(const char* p, uchar& r, uchar& g, uchar& b);
  86. virtual void get_system_colors() = 0;
  87. virtual const char *get_system_scheme();
  88. // --- global timers
  89. virtual void add_timeout(double time, Fl_Timeout_Handler cb, void *argp) = 0;
  90. virtual void repeat_timeout(double time, Fl_Timeout_Handler cb, void *argp) = 0;
  91. virtual int has_timeout(Fl_Timeout_Handler cb, void *argp) = 0;
  92. virtual void remove_timeout(Fl_Timeout_Handler cb, void *argp) = 0;
  93. static int secret_input_character;
  94. /* Implement to indicate whether complex text input may involve marked text.
  95. When it does, has_marked_text returns non zero and reset_marked_text() and
  96. insertion_point_location() must also be implemented.
  97. */
  98. virtual int has_marked_text() { return 0; }
  99. virtual void reset_marked_text() {}
  100. virtual void insertion_point_location(int x, int y, int height) {}
  101. // implement so text-editing widgets support dead keys
  102. virtual int compose(int &del) {del = 0; return 0;}
  103. // default implementation may be enough
  104. virtual void compose_reset();
  105. // implement to support drag-n-drop. use_selection = 1 means the GUI is welcome to display
  106. // the selected text during the D&D operation
  107. virtual int dnd(int use_selection = 0) {return 0;}
  108. // null means no platform-specific key bindings for Fl_Text_Editor
  109. Fl_Text_Editor::Key_Binding *text_editor_extra_key_bindings;
  110. // default implementation may be enough
  111. virtual int text_display_can_leak() { return 0; }
  112. // read raw image from a window or an offscreen buffer
  113. #if defined(FL_PORTING)
  114. # pragma message "FL_PORTING: implement code to read RGB data from screen"
  115. #endif
  116. /* Both member functions read_image() and read_win_rectangle() support
  117. the public function fl_read_image() which captures pixel data either from
  118. the current window or from an offscreen buffer.
  119. A platform re-implements either read_image() or read_win_rectangle().
  120. In the 1st case and for capture from a window, the returned pixel array
  121. also contains data from any embedded sub-window.
  122. In the 2nd case and for capture from a window, only data from the current
  123. window is collected, and read_image()'s default implementation captures
  124. pixels from any subwindow.
  125. A platform may also use its read_win_rectangle() implementation to capture
  126. window decorations (e.g., title bar). In that case, it is called by
  127. Fl_XXX_Window_Driver::capture_titlebar_and_borders().
  128. */
  129. virtual uchar *read_image(uchar *p, int x, int y, int w, int h, int alpha);
  130. virtual Fl_RGB_Image *read_win_rectangle(uchar *p, int X, int Y, int w, int h, int alpha) {return NULL;}
  131. static void write_image_inside(Fl_RGB_Image *to, Fl_RGB_Image *from, int to_x, int to_y);
  132. static Fl_RGB_Image *traverse_to_gl_subwindows(Fl_Group *g, uchar *p, int x, int y, int w, int h, int alpha,
  133. Fl_RGB_Image *full_img);
  134. // optional platform-specific key handling for Fl_Input widget
  135. // the default implementation may be enough
  136. virtual int input_widget_handle_key(int key, unsigned mods, unsigned shift, Fl_Input *input);
  137. // implement to support Fl::get_mouse()
  138. virtual int get_mouse(int &x, int &y) {return 0;}
  139. // optional methods to enable/disable input methods for complex scripts
  140. virtual void enable_im() {}
  141. virtual void disable_im() {}
  142. // calls open_display_platform() and then does platform-independent work
  143. void open_display();
  144. // implement to open access to the display
  145. virtual void open_display_platform() {}
  146. // optional method to close display access
  147. virtual void close_display() {}
  148. // compute dimensions of an Fl_Offscreen
  149. virtual void offscreen_size(Fl_Offscreen off, int &width, int &height) {}
  150. void rescale_all_windows_from_screen(int screen, float f);
  151. static void transient_scale_display(float f, int nscreen);
  152. static int scale_handler(int event);
  153. virtual void init_workarea() {}
  154. virtual float desktop_scale_factor() {return 1;}
  155. void use_startup_scale_factor();
  156. enum APP_SCALING_CAPABILITY {
  157. NO_APP_SCALING = 0, ///< The platform does not support rescaling.
  158. SYSTEMWIDE_APP_SCALING, ///< The platform supports rescaling with the same factor for all screens.
  159. PER_SCREEN_APP_SCALING ///< The platform supports rescaling with one factor for each screen.
  160. };
  161. /** Returns the platform's support for rescaling the application with ctrl-/+/-/0/ keys.
  162. */
  163. virtual APP_SCALING_CAPABILITY rescalable() { return NO_APP_SCALING; }
  164. /* Number of pixels per drawing unit for the display.
  165. The default implementation may be enough. */
  166. virtual float retina_factor() { return 1; }
  167. };
  168. #endif // !FL_SCREEN_DRIVER_H
  169. //
  170. // End of "$Id: Fl_Screen_Driver.H 12628 2018-01-09 07:26:49Z manolo $".
  171. //