FLTK logo

[master] f94ed71 - Make non-const Fl_Screen_Driver methods const (#181)

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[master] f94ed71 - Make non-const Fl_Screen_Driver methods const (#181) "Albrecht Schlosser" Jun 16, 2021  
 
commit f94ed7116c2943c105faebb14798e2ac33bb37cd
Author:     Albrecht Schlosser <albrechts.fltk@online.de>
AuthorDate: Wed Jun 16 14:24:05 2021 +0200
Commit:     Albrecht Schlosser <albrechts.fltk@online.de>
CommitDate: Wed Jun 16 14:24:05 2021 +0200

    Make non-const Fl_Screen_Driver methods const (#181)
    
    As requested by issue #181:
      "Fl_Screen_Driver.H non-const functions should be const"
    
    Not all methods could be made 'const' because some screen related
    methods call init() internally.

 src/Fl_Screen_Driver.H   | 134 ++++++++++++++++++++++++++---------------------
 src/Fl_Screen_Driver.cxx |   2 +-
 2 files changed, 76 insertions(+), 60 deletions(-)

diff --git src/Fl_Screen_Driver.H src/Fl_Screen_Driver.H
index 1e1d904..7c19c35 100644
--- src/Fl_Screen_Driver.H
+++ src/Fl_Screen_Driver.H
@@ -1,7 +1,7 @@
 //
 // All screen related calls in a driver style class.
 //
-// Copyright 1998-2020 by Bill Spitzak and others.
+// Copyright 1998-2021 by Bill Spitzak and others.
 //
 // This library is free software. Distribution and use rights are outlined in
 // the file "COPYING" which should have been included with this file.  If this
@@ -45,12 +45,12 @@ class Fl_Group;
 class Fl_Input;
 
 /**
- A base class describing the interface between FLTK and screen-related operations.
+  A base class describing the interface between FLTK and screen-related operations.
 
- This class is only for internal use by the FLTK library.
+  This class is only for internal use by the FLTK library.
 
- Each supported platform implements several of the virtual methods of this class.
- */
+  Each supported platform implements several of the virtual methods of this class.
+*/
 class FL_EXPORT Fl_Screen_Driver {
 
 protected:
@@ -60,8 +60,8 @@ protected:
   static const int MAX_SCREENS = 16;
 
   int num_screens;
-  static  float fl_intersection(int x1, int y1, int w1, int h1,
-                                int x2, int y2, int w2, int h2);
+  static float fl_intersection(int x1, int y1, int w1, int h1,
+                               int x2, int y2, int w2, int h2);
 
 public:
   static int keyboard_screen_scaling; // true means ctrl/+/-/0/ resize windows
@@ -69,91 +69,108 @@ public:
   static char bg2_set;
   static char fg_set;
 
-  virtual float scale(int n) {return 1;}
-  virtual void scale(int n, float f) { }
+  virtual float scale(int n) const { return 1; }
+  virtual void scale(int n, float f) {}
   static Fl_Screen_Driver *newScreenDriver();
   // --- display management
   virtual void display(const char *disp);
   virtual int visual(int flags);
   // --- screen configuration
   virtual void init() {}
-  virtual int x() { return 0; }
-  virtual int y() { return 0; }
-  virtual int w() { return 800; } // default, override in driver!
-  virtual int h() { return 600; } // default, override in driver!
+  virtual int x() const { return 0; }
+  virtual int y() const { return 0; }
+  virtual int w() const { return 800; } // default, override in driver!
+  virtual int h() const { return 600; } // default, override in driver!
   virtual int screen_count();
   void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my);
-  virtual void screen_xywh(int &X, int &Y, int &W, int &H, int n) { X=0; Y=0; W=800; H=600; }
+  virtual void screen_xywh(int &X, int &Y, int &W, int &H, int n) const {
+    X = 0;
+    Y = 0;
+    W = 800;
+    H = 600;
+  }
   void screen_xywh(int &X, int &Y, int &W, int &H, int mx, int my, int mw, int mh);
   virtual int screen_num(int x, int y);
   virtual int screen_num(int x, int y, int w, int h);
-  virtual void screen_dpi(float &h, float &v, int n=0) { h=72; v=72; } // override in driver!
+  virtual void screen_dpi(float &h, float &v, int n = 0) { // override in driver!
+    h = 72;
+    v = 72;
+  }
   void screen_work_area(int &X, int &Y, int &W, int &H, int mx, int my);
-  virtual void screen_work_area(int &X, int &Y, int &W, int &H, int n) { screen_xywh(X, Y, W, H, n); }
+  virtual void screen_work_area(int &X, int &Y, int &W, int &H, int n) {
+    screen_xywh(X, Y, W, H, n);
+  }
   // --- audible output
-  virtual void beep(int type) { }
+  virtual void beep(int type) {}
   // --- global events
-  virtual void flush() { } // must override
+  virtual void flush() {}                                  // must override
   virtual double wait(double time_to_wait) { return 0.0; } // must override
-  virtual int ready() { return 0; } // must override
-  virtual void grab(Fl_Window* win) { }
+  virtual int ready() { return 0; }                        // must override
+  virtual void grab(Fl_Window *win) {}
   // --- global colors
   /* the default implementation of parse_color() may be enough */
-  virtual int parse_color(const char* p, uchar& r, uchar& g, uchar& b);
-  virtual void get_system_colors() { }
+  virtual int parse_color(const char *p, uchar &r, uchar &g, uchar &b) const;
+  virtual void get_system_colors() {}
   /* the default implementation of get_system_scheme() may be enough */
   virtual const char *get_system_scheme();
   // --- global timers
-  virtual void add_timeout(double time, Fl_Timeout_Handler cb, void *argp) { }
-  virtual void repeat_timeout(double time, Fl_Timeout_Handler cb, void *argp) { }
-  virtual int has_timeout(Fl_Timeout_Handler cb, void *argp) { return 0; }
-  virtual void remove_timeout(Fl_Timeout_Handler cb, void *argp) { }
+  virtual void add_timeout(double time, Fl_Timeout_Handler cb, void *argp) {}
+  virtual void repeat_timeout(double time, Fl_Timeout_Handler cb, void *argp) {}
+  virtual int has_timeout(Fl_Timeout_Handler cb, void *argp) const { return 0; }
+  virtual void remove_timeout(Fl_Timeout_Handler cb, void *argp) {}
 
   static int secret_input_character;
   /* Implement to indicate whether complex text input may involve marked text.
-   When it does, has_marked_text returns non zero and reset_marked_text() and
-   insertion_point_location() must also be implemented.
-   */
-  virtual int has_marked_text() { return 0; }
+    When it does, has_marked_text returns non zero and reset_marked_text() and
+    insertion_point_location() must also be implemented.
+  */
+  virtual int has_marked_text() const { return 0; }
   virtual void reset_marked_text() {}
   virtual void insertion_point_location(int x, int y, int height) {}
   // implement so text-editing widgets support dead keys
-  virtual int compose(int &del) {del = 0; return 0;}
+  virtual int compose(int &del) {
+    del = 0;
+    return 0;
+  }
   // default implementation may be enough
   virtual void compose_reset();
   // implement to support drag-n-drop. use_selection = 1 means the GUI is welcome to display
   // the selected text during the D&D operation
-  virtual int dnd(int use_selection = 0) {return 0;}
+  virtual int dnd(int use_selection = 0) { return 0; }
   // null means no platform-specific key bindings for Fl_Text_Editor
   Fl_Text_Editor::Key_Binding *text_editor_extra_key_bindings;
   // default implementation may be enough
-  virtual int text_display_can_leak() { return 0; }
+  virtual int text_display_can_leak() const { return 0; }
 
-  // if no keyboard is connected on a touch or pen device, the system on-screen keyboard is requested
-  virtual void request_keyboard() { }
+  // if no keyboard is connected on a touch or pen device, the system on-screen keyboard is
+  // requested
+  virtual void request_keyboard() {}
   // we no longer need the on-screen keyboard; it's up to the system to hide it
-  virtual void release_keyboard() { }
+  virtual void release_keyboard() {}
 
   /* Member function read_win_rectangle() supports public functions
-   fl_read_image() and fl_capture_window_part() which capture pixel data from
-   a window (or also from an offscreen buffer with fl_read_image).
-
-   If 'may_capture_subwins' is true, an implementation may or may not capture
-   also the content of subwindows embedded in 'win'. If subwindows were captured,
-   *'did_capture_subwins' is returned set to true. If read_win_rectangle()
-   is called with 'may_capture_subwins' set to true, 'did_capture_subwins' should
-   be set before the call to the address of a boolean set to false.
-   The implementation of this virtual function for the macOS platform has the
-   capability of capturing subwindows when asked for.
-
-   A platform may also use its read_win_rectangle() implementation to capture
-   window decorations (e.g., title bar). In that case, it is called by
-   Fl_XXX_Window_Driver::capture_titlebar_and_borders().
-
-   win is the window to capture from, or NULL to capture from the current offscreen
-   */
+    fl_read_image() and fl_capture_window_part() which capture pixel data from
+    a window (or also from an offscreen buffer with fl_read_image).
+
+    If 'may_capture_subwins' is true, an implementation may or may not capture
+    also the content of subwindows embedded in 'win'. If subwindows were captured,
+    *'did_capture_subwins' is returned set to true. If read_win_rectangle()
+    is called with 'may_capture_subwins' set to true, 'did_capture_subwins' should
+    be set before the call to the address of a boolean set to false.
+    The implementation of this virtual function for the macOS platform has the
+    capability of capturing subwindows when asked for.
+
+    A platform may also use its read_win_rectangle() implementation to capture
+    window decorations (e.g., title bar). In that case, it is called by
+    Fl_XXX_Window_Driver::capture_titlebar_and_borders().
+
+    win is the window to capture from, or NULL to capture from the current offscreen
+  */
   virtual Fl_RGB_Image *read_win_rectangle(int X, int Y, int w, int h, Fl_Window *win,
-                                           bool may_capture_subwins = false, bool *did_capture_subwins = NULL) {return NULL;}
+                                           bool may_capture_subwins = false,
+                                           bool *did_capture_subwins = NULL) {
+    return NULL;
+  }
   static void write_image_inside(Fl_RGB_Image *to, Fl_RGB_Image *from, int to_x, int to_y);
   static Fl_RGB_Image *traverse_to_gl_subwindows(Fl_Group *g, int x, int y, int w, int h,
                                                  Fl_RGB_Image *full_img);
@@ -161,7 +178,7 @@ public:
   // the default implementation may be enough
   virtual int input_widget_handle_key(int key, unsigned mods, unsigned shift, Fl_Input *input);
   // implement to support Fl::get_mouse()
-  virtual int get_mouse(int &x, int &y) {return 0;}
+  virtual int get_mouse(int &x, int &y) { return 0; }
   // optional methods to enable/disable input methods for complex scripts
   virtual void enable_im() {}
   virtual void disable_im() {}
@@ -180,18 +197,17 @@ public:
   virtual void desktop_scale_factor() {}
   void use_startup_scale_factor();
   enum APP_SCALING_CAPABILITY {
-    NO_APP_SCALING = 0, ///< The platform does not support rescaling.
+    NO_APP_SCALING = 0,     ///< The platform does not support rescaling.
     SYSTEMWIDE_APP_SCALING, ///< The platform supports rescaling with the same factor for all screens.
-    PER_SCREEN_APP_SCALING ///< The platform supports rescaling with one factor for each screen.
+    PER_SCREEN_APP_SCALING  ///< The platform supports rescaling with one factor for each screen.
   };
-  /** Returns the platform's support for rescaling the application with ctrl-/+/-/0/ keys.
+  /** Returns the platform's support for rescaling the application with ctrl/+/-/0 keys.
    */
   virtual APP_SCALING_CAPABILITY rescalable() { return NO_APP_SCALING; }
   // supports Fl_Window::default_icons()
   virtual void default_icons(const Fl_RGB_Image *icons[], int count);
 };
 
-
 #endif // !FL_SCREEN_DRIVER_H
 
 /**
diff --git src/Fl_Screen_Driver.cxx src/Fl_Screen_Driver.cxx
index de925ba..93d1800 100644
--- src/Fl_Screen_Driver.cxx
+++ src/Fl_Screen_Driver.cxx
@@ -488,7 +488,7 @@ void Fl_Screen_Driver::open_display()
 
 
 // simulation of XParseColor:
-int Fl_Screen_Driver::parse_color(const char* p, uchar& r, uchar& g, uchar& b)
+int Fl_Screen_Driver::parse_color(const char* p, uchar& r, uchar& g, uchar& b) const
 {
   if (*p == '#') p++;
   size_t n = strlen(p);
Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.