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
This commit is contained in:
Manolo Gouy 2016-03-23 13:13:00 +00:00
parent 270b437500
commit a114e3ab4d
11 changed files with 83 additions and 73 deletions

View File

@ -85,6 +85,8 @@ public:
virtual void resize(int X,int Y,int W,int H) {}
virtual void hide() {}
int hide_common();
virtual void map() {}
virtual void unmap() {}
// --- window shape stuff
void shape_pixmap_(Fl_Image* pixmap); // TODO: check

View File

@ -177,8 +177,6 @@ public:
static void GLcontext_makecurrent(NSOpenGLContext*);
static void GL_cleardrawable(void);
void destroy(void);
void map(void);
void unmap(void);
void collapse(void);
WindowRef window_ref(void); // useless with cocoa GL windows
void set_key_window(void);

View File

@ -57,10 +57,6 @@ inline void XClipBox(Fl_Region r,XRectangle* rect) {
rect->width=win_rect.right-win_rect.left;
rect->height=win_rect.bottom-win_rect.top;
}
#define XDestroyWindow(a,b) DestroyWindow(b)
#define XMapWindow(a,b) ShowWindow(b, SW_RESTORE)
#define XUnmapWindow(a,b) ShowWindow(b, SW_HIDE)
// this object contains all win32-specific stuff about a window:
// Warning: this object is highly subject to change!
class FL_EXPORT Fl_X {

View File

@ -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:

View File

@ -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$".
//

View File

@ -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)
{

View File

@ -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

View File

@ -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);

View File

@ -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$".
//

View File

@ -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);

View File

@ -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$".
//