From 2fcb4f419217eb2895ad0e52b15aab252eb827ef Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Fri, 15 Apr 2016 15:36:10 +0000 Subject: [PATCH] Move platform-dependent implementations of fl_open/close_display() to the Fl_Screen_Driver class git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11619 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Fl.H | 8 -------- FL/Fl_Screen_Driver.H | 4 ++++ src/Fl.cxx | 18 ++++++++++++++++++ src/Fl_cocoa.mm | 14 ++++---------- src/Fl_win32.cxx | 6 +++--- src/Fl_x.cxx | 6 +++--- src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H | 1 + src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx | 2 +- src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H | 1 + src/drivers/X11/Fl_X11_Screen_Driver.H | 2 ++ src/drivers/X11/Fl_X11_Screen_Driver.cxx | 16 ++++++++-------- 11 files changed, 45 insertions(+), 33 deletions(-) diff --git a/FL/Fl.H b/FL/Fl.H index 40e845cdb..9c472a29b 100644 --- a/FL/Fl.H +++ b/FL/Fl.H @@ -842,15 +842,7 @@ int main() { static int event_inside(const Fl_Widget*); static int test_shortcut(Fl_Shortcut); - /** - Enables the system input methods facilities. This is the default. - \see disable_im() - */ static void enable_im(); - /** - Disables the system input methods facilities. - \see enable_im() - */ static void disable_im(); // event destinations: diff --git a/FL/Fl_Screen_Driver.H b/FL/Fl_Screen_Driver.H index 1d19c16ca..a96857bd1 100644 --- a/FL/Fl_Screen_Driver.H +++ b/FL/Fl_Screen_Driver.H @@ -138,6 +138,10 @@ public: // optional methods to enable/disable input methods for complex scripts virtual void enable_im() {} virtual void disable_im() {} + // implement to open access to the display + virtual void open_display() {} + // optional method to close display access + virtual void close_display() {} }; diff --git a/src/Fl.cxx b/src/Fl.cxx index 775a43837..26e7d4080 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -1941,16 +1941,34 @@ int Fl::clipboard_contains(const char *type) return Fl::system_driver()->clipboard_contains(type); } +/** + Enables the system input methods facilities. This is the default. + \see disable_im() + */ void Fl::enable_im() { Fl::screen_driver()->enable_im(); } +/** + Disables the system input methods facilities. + \see enable_im() + */ void Fl::disable_im() { Fl::screen_driver()->disable_im(); } +void fl_open_display() +{ + Fl::screen_driver()->open_display(); +} + +void fl_close_display() +{ + Fl::screen_driver()->close_display(); +} + // // End of "$Id$". // diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index faf59a8b4..9d3291220 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -1721,7 +1721,7 @@ void fl_open_callback(void (*cb)(const char *)) { } */ -void fl_open_display() { +void Fl_Cocoa_Screen_Driver::open_display() { static char beenHereDoneThat = 0; if ( !beenHereDoneThat ) { beenHereDoneThat = 1; @@ -1797,12 +1797,6 @@ void fl_open_display() { } -/* - * get rid of allocated resources - */ -void fl_close_display() { -} - // Force a "Roman" or "ASCII" keyboard, which both the Mozilla and // Safari people seem to think implies turning off advanced IME stuff // (see nsTSMManager::SyncKeyScript in Mozilla and enableSecureTextInput @@ -1883,7 +1877,7 @@ int Fl_Cocoa_Screen_Driver::x() { * smallest y coordinate in screen space of work area of menubar-containing display */ int Fl_Cocoa_Screen_Driver::y() { - fl_open_display(); + open_display(); NSRect visible = [[[NSScreen screens] objectAtIndex:0] visibleFrame]; return int(main_screen_height - (visible.origin.y + visible.size.height)); } @@ -1909,7 +1903,7 @@ void Fl_Cocoa_Screen_Driver::screen_work_area(int &X, int &Y, int &W, int &H, in { if (num_screens < 0) init(); if (n < 0 || n >= num_screens) n = 0; - fl_open_display(); + open_display(); NSRect r = [[[NSScreen screens] objectAtIndex:n] visibleFrame]; X = int(r.origin.x); Y = main_screen_height - int(r.origin.y + r.size.height); @@ -1922,7 +1916,7 @@ void Fl_Cocoa_Screen_Driver::screen_work_area(int &X, int &Y, int &W, int &H, in */ void Fl_Cocoa_Screen_Driver::get_mouse(int &x, int &y) { - fl_open_display(); + open_display(); NSPoint pt = [NSEvent mouseLocation]; x = int(pt.x); y = int(main_screen_height - pt.y); diff --git a/src/Fl_win32.cxx b/src/Fl_win32.cxx index b37f0994f..97e22e021 100644 --- a/src/Fl_win32.cxx +++ b/src/Fl_win32.cxx @@ -515,7 +515,7 @@ int fl_ready() { return get_wsock_mod() ? s_wsock_select(0,&fdt[0],&fdt[1],&fdt[2],&t) : 0; } -void fl_open_display() { +void Fl_WinAPI_Screen_Driver::open_display() { static char beenHereDoneThat = 0; if (beenHereDoneThat) @@ -549,7 +549,7 @@ static Fl_Win32_At_Exit win32_at_exit; static char im_enabled = 1; void Fl_WinAPI_Screen_Driver::enable_im() { - fl_open_display(); + open_display(); Fl_X* i = Fl_X::first; while (i) { @@ -561,7 +561,7 @@ void Fl_WinAPI_Screen_Driver::enable_im() { } void Fl_WinAPI_Screen_Driver::disable_im() { - fl_open_display(); + open_display(); Fl_X* i = Fl_X::first; while (i) { diff --git a/src/Fl_x.cxx b/src/Fl_x.cxx index 04e82abbc..47b984480 100644 --- a/src/Fl_x.cxx +++ b/src/Fl_x.cxx @@ -669,7 +669,7 @@ void Fl_X11_Screen_Driver::disable_im() { fl_xim_deactivate(); } -void fl_open_display() { +void Fl_X11_Screen_Driver::open_display() { if (fl_display) return; setlocale(LC_CTYPE, ""); @@ -782,14 +782,14 @@ void fl_open_display(Display* d) { XSelectInput(d, RootWindow(d, fl_screen), PropertyChangeMask); } -void fl_close_display() { +void Fl_X11_Screen_Driver::close_display() { Fl::remove_fd(ConnectionNumber(fl_display)); XCloseDisplay(fl_display); } void Fl_X11_Screen_Driver::get_mouse(int &xx, int &yy) { - fl_open_display(); + open_display(); Window root = RootWindow(fl_display, fl_screen); Window c; int mx,my,cx,cy; unsigned int mask; XQueryPointer(fl_display,root,&root,&c,&mx,&my,&cx,&cy,&mask); diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H index eea642760..4cde863d7 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H +++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.H @@ -93,6 +93,7 @@ public: virtual void get_mouse(int &x, int &y); virtual void enable_im(); virtual void disable_im(); + virtual void open_display(); }; diff --git a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx index 270660ea5..8c3f47d47 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx +++ b/src/drivers/Cocoa/Fl_Cocoa_Screen_Driver.cxx @@ -218,7 +218,7 @@ static void set_selection_color(uchar r, uchar g, uchar b) // look-n-feel... void Fl_Cocoa_Screen_Driver::get_system_colors() { - fl_open_display(); + open_display(); if (!bg2_set) Fl::background2(0xff, 0xff, 0xff); if (!fg_set) Fl::foreground(0, 0, 0); diff --git a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H index 80ced415b..0da03d780 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_Screen_Driver.H @@ -75,6 +75,7 @@ public: virtual void get_mouse(int &x, int &y); virtual void enable_im(); virtual void disable_im(); + virtual void open_display(); }; diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.H b/src/drivers/X11/Fl_X11_Screen_Driver.H index a2b8b628d..b974901c0 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.H +++ b/src/drivers/X11/Fl_X11_Screen_Driver.H @@ -81,6 +81,8 @@ public: virtual void get_mouse(int &x, int &y); virtual void enable_im(); virtual void disable_im(); + virtual void open_display(); + virtual void close_display(); }; diff --git a/src/drivers/X11/Fl_X11_Screen_Driver.cxx b/src/drivers/X11/Fl_X11_Screen_Driver.cxx index 7dccf0052..881cdcf57 100644 --- a/src/drivers/X11/Fl_X11_Screen_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Screen_Driver.cxx @@ -184,7 +184,7 @@ int Fl_X11_Screen_Driver::visual(int flags) #if USE_XDBE == 0 if (flags & FL_DOUBLE) return 0; #endif - fl_open_display(); + open_display(); // always use default if possible: if (test_visual(*fl_visual, flags)) return 1; // get all the visuals: @@ -210,7 +210,7 @@ static int fl_workarea_xywh[4] = { -1, -1, -1, -1 }; void Fl_X11_Screen_Driver::init_workarea() { - fl_open_display(); + open_display(); Atom actual; unsigned long count, remaining; @@ -267,7 +267,7 @@ int Fl_X11_Screen_Driver::h() { void Fl_X11_Screen_Driver::init() { - if (!fl_display) fl_open_display(); + if (!fl_display) open_display(); // FIXME: Rewrite using RandR instead #if HAVE_XINERAMA if (XineramaIsActive(fl_display)) { @@ -356,11 +356,11 @@ void Fl_X11_Screen_Driver::beep(int type) switch (type) { case FL_BEEP_DEFAULT : case FL_BEEP_ERROR : - if (!fl_display) fl_open_display(); + if (!fl_display) open_display(); XBell(fl_display, 100); break; default : - if (!fl_display) fl_open_display(); + if (!fl_display) open_display(); XBell(fl_display, 50); break; } @@ -493,7 +493,7 @@ void Fl_X11_Screen_Driver::grab(Fl_Window* win) int Fl_X11_Screen_Driver::parse_color(const char* p, uchar& r, uchar& g, uchar& b) { XColor x; - if (!fl_display) fl_open_display(); + if (!fl_display) open_display(); if (XParseColor(fl_display, fl_colormap, p, &x)) { r = (uchar)(x.red>>8); g = (uchar)(x.green>>8); @@ -533,7 +533,7 @@ static void getsyscolor(const char *key1, const char* key2, const char *arg, con void Fl_X11_Screen_Driver::get_system_colors() { - fl_open_display(); + open_display(); const char* key1 = 0; if (Fl::first_window()) key1 = Fl::first_window()->xclass(); if (!key1) key1 = "fltk"; @@ -554,7 +554,7 @@ const char *Fl_X11_Screen_Driver::get_system_scheme() const char* key = 0; if (Fl::first_window()) key = Fl::first_window()->xclass(); if (!key) key = "fltk"; - fl_open_display(); + open_display(); s = XGetDefault(fl_display, key, "scheme"); } return s;