From a114e3ab4d9fa408061003c04a95b293b3842f24 Mon Sep 17 00:00:00 2001 From: Manolo Gouy Date: Wed, 23 Mar 2016 13:13:00 +0000 Subject: Rewrite Fl_Window::handle(int) under the driver model. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11403 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/Fl.cxx | 58 -------------------------- src/Fl_Window.cxx | 40 ++++++++++++++++++ src/Fl_cocoa.mm | 22 ++++++---- src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H | 2 + src/drivers/WinAPI/Fl_WinAPI_Window_Driver.H | 2 + src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx | 12 +++++- src/drivers/X11/Fl_X11_Window_Driver.H | 2 + src/drivers/X11/Fl_X11_Window_Driver.cxx | 10 +++++ 8 files changed, 81 insertions(+), 67 deletions(-) (limited to 'src') diff --git a/src/Fl.cxx b/src/Fl.cxx index 11d0c62ce..ffee65687 100644 --- a/src/Fl.cxx +++ b/src/Fl.cxx @@ -1451,64 +1451,6 @@ int Fl::handle_(int e, Fl_Window* window) } -// FL_SHOW and FL_HIDE are called whenever the visibility of this widget -// or any parent changes. We must correctly map/unmap the system's window. - -// For top-level windows it is assumed the window has already been -// mapped or unmapped!!! This is because this should only happen when -// Fl_Window::show() or Fl_Window::hide() is called, or in response to -// iconize/deiconize events from the system. - -int Fl_Window::handle(int ev) -{ - if (parent()) { - switch (ev) { - case FL_SHOW: - if (!shown()) show(); - else { -#if defined(USE_X11) || defined(WIN32) - XMapWindow(fl_display, fl_xid(this)); // extra map calls are harmless -#elif defined(__APPLE_QUARTZ__) // PORTME: Fl_Window_Driver - platform window mapping - i->map(); -#elif defined(FL_PORTING) -# pragma message "FL_PORTING: code to show a window on screen" -#else -# error unsupported platform -#endif // __APPLE__ // PORTME: Fl_Window_Driver - platform window mapping - } - break; - case FL_HIDE: - if (shown()) { - // Find what really turned invisible, if it was a parent window - // we do nothing. We need to avoid unnecessary unmap calls - // because they cause the display to blink when the parent is - // remapped. However if this or any intermediate non-window - // widget has really had hide() called directly on it, we must - // unmap because when the parent window is remapped we don't - // want to reappear. - if (visible()) { - Fl_Widget* p = parent(); for (;p->visible();p = p->parent()) {} - if (p->type() >= FL_WINDOW) break; // don't do the unmap - } -#if defined(USE_X11) || defined(WIN32) - XUnmapWindow(fl_display, fl_xid(this)); -#elif defined(__APPLE_QUARTZ__) // PORTME: Fl_Window_Driver - platform window unmapping, again - i->unmap(); -#elif defined(FL_PORTING) -# pragma message "FL_PORTING: code to hide a window from screen" -#else -# error platform unsupported -#endif - } - break; - } -// } else if (ev == FL_FOCUS || ev == FL_UNFOCUS) { -// Fl_Tooltip::exit(Fl_Tooltip::current()); - } - - return Fl_Group::handle(ev); -} - //////////////////////////////////////////////////////////////// // Back compatibility cut & paste functions for fltk 1.1 only: diff --git a/src/Fl_Window.cxx b/src/Fl_Window.cxx index df6f97259..8cf091427 100644 --- a/src/Fl_Window.cxx +++ b/src/Fl_Window.cxx @@ -514,6 +514,46 @@ void Fl_Window::hide() { pWindowDriver->hide(); } + +// FL_SHOW and FL_HIDE are called whenever the visibility of this widget +// or any parent changes. We must correctly map/unmap the system's window. + +// For top-level windows it is assumed the window has already been +// mapped or unmapped!!! This is because this should only happen when +// Fl_Window::show() or Fl_Window::hide() is called, or in response to +// iconize/deiconize events from the system. +int Fl_Window::handle(int ev) +{ + if (parent()) { + switch (ev) { + case FL_SHOW: + if (!shown()) show(); + else { + pWindowDriver->map(); + } + break; + case FL_HIDE: + if (shown()) { + // Find what really turned invisible, if it was a parent window + // we do nothing. We need to avoid unnecessary unmap calls + // because they cause the display to blink when the parent is + // remapped. However if this or any intermediate non-window + // widget has really had hide() called directly on it, we must + // unmap because when the parent window is remapped we don't + // want to reappear. + if (visible()) { + Fl_Widget* p = parent(); for (;p->visible();p = p->parent()) {} + if (p->type() >= FL_WINDOW) break; // don't do the unmap + } + pWindowDriver->unmap(); + } + break; + } + } + + return Fl_Group::handle(ev); +} + // // End of "$Id$". // diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 68d1631d1..35239835e 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -3528,24 +3528,30 @@ void Fl_X::destroy() { delete subRect(); } -void Fl_X::map() { - if (w && xid && ![xid parentWindow]) { // 10.2 + +void Fl_Cocoa_Window_Driver::map() { + Window xid = fl_xid(pWindow); + if (pWindow && xid && ![xid parentWindow]) { // 10.2 // after a subwindow has been unmapped, it has lost its parent window and its frame may be wrong [xid setSubwindowFrame]; } - if (cursor) { - [(NSCursor*)cursor release]; - cursor = NULL; + Fl_X *i = Fl_X::i(pWindow); + if (i->cursor) { + [(NSCursor*)i->cursor release]; + i->cursor = NULL; } } -void Fl_X::unmap() { - if (w && xid) { - if (w->parent()) [[xid parentWindow] removeChildWindow:xid]; // necessary with at least 10.5 + +void Fl_Cocoa_Window_Driver::unmap() { + Window xid = fl_xid(pWindow); + if (pWindow && xid) { + if (pWindow->parent()) [[xid parentWindow] removeChildWindow:xid]; // necessary with at least 10.5 [xid orderOut:nil]; } } + // intersects current and x,y,w,h rectangle and returns result as a new Fl_Region Fl_Region Fl_X::intersect_region_and_rect(Fl_Region current, int x,int y,int w, int h) { diff --git a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H index bd5a0e79e..07a6dd8a3 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H +++ b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.H @@ -78,6 +78,8 @@ public: virtual void show(); virtual void resize(int X,int Y,int W,int H); virtual void hide(); + virtual void map(); + virtual void unmap(); virtual void shape(const Fl_Image* img); // that one is implemented in Fl_Cocoa.mm because it uses Objective-c diff --git a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.H b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.H index 4d7d8b490..27fb5bc7e 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.H +++ b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.H @@ -83,6 +83,8 @@ public: virtual void label(const char *name,const char *iname); virtual void resize(int X,int Y,int W,int H); virtual void hide(); + virtual void map(); + virtual void unmap(); virtual void shape(const Fl_Image* img); virtual void icons(const Fl_RGB_Image *icons[], int count); diff --git a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx index 70c254216..a14430af9 100644 --- a/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx +++ b/src/drivers/WinAPI/Fl_WinAPI_Window_Driver.cxx @@ -504,7 +504,7 @@ void Fl_WinAPI_Window_Driver::hide() { ShowWindow(ip->xid, SW_HIDE); ShowWindow(p, SW_SHOWNA); } - XDestroyWindow(fl_display, ip->xid); + DestroyWindow(ip->xid); // end of fix for STR#3079 if (count) { int ii; @@ -521,6 +521,16 @@ void Fl_WinAPI_Window_Driver::hide() { delete ip; } + +void Fl_WinAPI_Window_Driver::map() { + ShowWindow(fl_xid(pWindow), SW_RESTORE); // extra map calls are harmless +} + + +void Fl_WinAPI_Window_Driver::unmap() { + ShowWindow(fl_xid(pWindow), SW_HIDE); +} + // // End of "$Id$". // diff --git a/src/drivers/X11/Fl_X11_Window_Driver.H b/src/drivers/X11/Fl_X11_Window_Driver.H index 967b7d0fa..b2582a57b 100644 --- a/src/drivers/X11/Fl_X11_Window_Driver.H +++ b/src/drivers/X11/Fl_X11_Window_Driver.H @@ -92,6 +92,8 @@ public: virtual void label(const char *name, const char *mininame); virtual void destroy_double_buffer(); virtual void hide(); + virtual void map(); + virtual void unmap(); virtual void shape(const Fl_Image* img); virtual void icons(const Fl_RGB_Image *icons[], int count); diff --git a/src/drivers/X11/Fl_X11_Window_Driver.cxx b/src/drivers/X11/Fl_X11_Window_Driver.cxx index 4f04dba7f..59313cc42 100644 --- a/src/drivers/X11/Fl_X11_Window_Driver.cxx +++ b/src/drivers/X11/Fl_X11_Window_Driver.cxx @@ -475,6 +475,16 @@ void Fl_X11_Window_Driver::hide() { delete ip; } + +void Fl_X11_Window_Driver::map() { + XMapWindow(fl_display, fl_xid(pWindow)); // extra map calls are harmless +} + + +void Fl_X11_Window_Driver::unmap() { + XUnmapWindow(fl_display, fl_xid(pWindow)); +} + // // End of "$Id$". // -- cgit v1.2.3