From 12eef8e64d2518c140770529ce6e03f046b33ecf Mon Sep 17 00:00:00 2001 From: Matthias Melcher Date: Mon, 7 Mar 2016 21:15:25 +0000 Subject: Separating Fl_X and Fl_Window_Driver in Fl_Window. This was needed because Fl_X only exists if a window is mapped, but we need the driver from the very beginning. Adding Fl_X in the ctor would create hidden bugs. Strategy is now to remove system specific stuff from Fl_X and move it one-by-one to Fl_Window_Driver while maintaining a working code base. X11 and WIN32 fixups will follow in 15 minutes. git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3-porting@11308 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- FL/Fl_Window.H | 5 ++-- FL/Fl_Window_Driver.H | 6 +++-- FL/porting.H | 2 +- src/Fl_Double_Window.cxx | 31 +++++++++++++----------- src/Fl_Window.cxx | 12 ++++++--- src/Fl_Window_Driver.cxx | 6 ++++- src/Fl_cocoa.mm | 2 +- src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx | 2 +- src/drivers/PicoSDL/Fl_PicoSDL_Screen_Driver.cxx | 2 +- 9 files changed, 41 insertions(+), 27 deletions(-) diff --git a/FL/Fl_Window.H b/FL/Fl_Window.H index 9dd443e8e..659495f32 100644 --- a/FL/Fl_Window.H +++ b/FL/Fl_Window.H @@ -71,7 +71,8 @@ class FL_EXPORT Fl_Window : public Fl_Group { friend class Fl_X; friend class Fl_Window_Driver; - Fl_Window_Driver *i; // points at the system-specific stuff + Fl_X *i; // points at the system-specific stuff, but exists only after the window is mapped + Fl_Window_Driver *pWindowDriver; // points at the system-specific stuff at window creatino time struct icon_data { const void *legacy_icon; @@ -635,7 +636,7 @@ public: // Captures the titlebar and borders of the window, if they exist. void capture_titlebar_and_borders(Fl_Shared_Image*& top, Fl_Shared_Image*& left, Fl_Shared_Image*& bottom, Fl_Shared_Image*& right); - Fl_Window_Driver *driver() { return i; } + Fl_Window_Driver *driver() { return pWindowDriver; } /** Return non-null if this is an Fl_Overlay_Window object. diff --git a/FL/Fl_Window_Driver.H b/FL/Fl_Window_Driver.H index 540b6971f..9f938606f 100644 --- a/FL/Fl_Window_Driver.H +++ b/FL/Fl_Window_Driver.H @@ -33,7 +33,9 @@ class Fl_Window; /** \brief A base class for platform specific window handling code. */ -class FL_EXPORT Fl_Window_Driver : public Fl_X { +class FL_EXPORT Fl_Window_Driver { +protected: + Fl_Window *pWindow; public: Fl_Window_Driver(Fl_Window *); virtual ~Fl_Window_Driver(); @@ -42,7 +44,7 @@ public: virtual void take_focus() { } virtual int double_flush(int eraseoverlay); virtual void destroy_double_buffer(); - void draw() {w->draw();} + void draw(); }; diff --git a/FL/porting.H b/FL/porting.H index 7b0830189..776dd8779 100644 --- a/FL/porting.H +++ b/FL/porting.H @@ -78,7 +78,7 @@ public: int wait_for_expose; // NSCursor *cursor; static Fl_X* first; - static Fl_X* i(const Fl_Window* w) {return (Fl_X*)w->i;} + static Fl_X* i(const Fl_Window* w) {return w->i;} static int fake_X_wm(const Fl_Window*,int&,int&,int&,int&,int&); static Fl_X* make(Fl_Window*); void flush(); diff --git a/src/Fl_Double_Window.cxx b/src/Fl_Double_Window.cxx index be9b016cc..b517be2c3 100644 --- a/src/Fl_Double_Window.cxx +++ b/src/Fl_Double_Window.cxx @@ -81,9 +81,9 @@ void Fl_Double_Window::flush() {flush(0);} void Fl_Double_Window::flush(int eraseoverlay) { if (!shown()) return; make_current(); // make sure fl_gc is non-zero - Fl_Window_Driver *myi = (Fl_Window_Driver*)Fl_X::i(this); + Fl_X *myi = Fl_X::i(this); if (!myi) return; // window not yet created - int retval = myi->double_flush(eraseoverlay); + int retval = driver()->double_flush(eraseoverlay); if (retval) return; if (eraseoverlay) fl_clip_region(0); // on Irix (at least) it is faster to reduce the area copied to @@ -102,13 +102,15 @@ int Fl_Window_Driver::double_flush(int eraseoverlay) { Fl_Overlay_Window's which fall back on this implementation. - on Xlib, it is reimplemented if the Xdbe extension is available. */ - if (!other_xid) { - other_xid = fl_create_offscreen(w->w(), w->h()); - w->clear_damage(FL_DAMAGE_ALL); + Fl_X *i = Fl_X::i(pWindow); + + if (!i->other_xid) { + i->other_xid = fl_create_offscreen(pWindow->w(), pWindow->h()); + pWindow->clear_damage(FL_DAMAGE_ALL); } - if (w->damage() & ~FL_DAMAGE_EXPOSE) { - fl_clip_region(region); region = 0; - fl_begin_offscreen(other_xid); + if (pWindow->damage() & ~FL_DAMAGE_EXPOSE) { + fl_clip_region(i->region); i->region = 0; + fl_begin_offscreen(i->other_xid); fl_graphics_driver->clip_region( 0 ); draw(); fl_end_offscreen(); @@ -120,26 +122,27 @@ void Fl_Double_Window::resize(int X,int Y,int W,int H) { int ow = w(); int oh = h(); Fl_Window::resize(X,Y,W,H); - Fl_Window_Driver *myi = (Fl_Window_Driver*)Fl_X::i(this); + Fl_X *myi = Fl_X::i(this); if (myi && myi->other_xid && (ow < w() || oh < h())) - myi->destroy_double_buffer(); + driver()->destroy_double_buffer(); } void Fl_Double_Window::hide() { - Fl_Window_Driver *myi = (Fl_Window_Driver*)Fl_X::i(this); + Fl_X *myi = Fl_X::i(this); if (myi && myi->other_xid) { - myi->destroy_double_buffer(); + driver()->destroy_double_buffer(); } Fl_Window::hide(); } void Fl_Window_Driver::destroy_double_buffer() { + Fl_X *i = Fl_X::i(pWindow); /* This is a working, platform-independent implementation. Some platforms may re-implement it for their own logic: - on Xlib, it is reimplemented if the Xdbe extension is available. */ - fl_delete_offscreen(other_xid); - other_xid = 0; + fl_delete_offscreen(i->other_xid); + i->other_xid = 0; } diff --git a/src/Fl_Window.cxx b/src/Fl_Window.cxx index 54d6e9cc2..c3cb7f498 100644 --- a/src/Fl_Window.cxx +++ b/src/Fl_Window.cxx @@ -64,17 +64,21 @@ void Fl_Window::_Fl_Window() { callback((Fl_Callback*)default_callback); } -Fl_Window::Fl_Window(int X,int Y,int W, int H, const char *l) -: Fl_Group(X, Y, W, H, l) { +Fl_Window::Fl_Window(int X,int Y,int W, int H, const char *l) : +Fl_Group(X, Y, W, H, l), +pWindowDriver(Fl_Window_Driver::newWindowDriver(this)) +{ cursor_default = FL_CURSOR_DEFAULT; _Fl_Window(); set_flag(FORCE_POSITION); } -Fl_Window::Fl_Window(int W, int H, const char *l) +Fl_Window::Fl_Window(int W, int H, const char *l) : // fix common user error of a missing end() with current(0): - : Fl_Group((Fl_Group::current(0),0), 0, W, H, l) { +Fl_Group((Fl_Group::current(0),0), 0, W, H, l), +pWindowDriver(Fl_Window_Driver::newWindowDriver(this)) +{ cursor_default = FL_CURSOR_DEFAULT; _Fl_Window(); diff --git a/src/Fl_Window_Driver.cxx b/src/Fl_Window_Driver.cxx index 22517bfc7..37ce9637f 100644 --- a/src/Fl_Window_Driver.cxx +++ b/src/Fl_Window_Driver.cxx @@ -24,7 +24,8 @@ #include -Fl_Window_Driver::Fl_Window_Driver(Fl_Window *win) +Fl_Window_Driver::Fl_Window_Driver(Fl_Window *win) : +pWindow(win) { } @@ -33,6 +34,9 @@ Fl_Window_Driver::~Fl_Window_Driver() { } +void Fl_Window_Driver::draw() { + pWindow->draw(); +} // // End of "$Id$". diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index 2da202e7e..42e85fd69 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -2945,7 +2945,7 @@ void Fl_X::make(Fl_Window* w) yp -= by+bt; } - Fl_Window_Driver *x = Fl_Window_Driver::newWindowDriver(w); + Fl_X *x = new Fl_X; x->other_xid = 0; // room for doublebuffering image map. On OS X this is only used by overlay windows x->region = 0; x->subRect(0); diff --git a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx index 685aebbd3..5783187d6 100644 --- a/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx +++ b/src/drivers/Cocoa/Fl_Cocoa_Window_Driver.cxx @@ -52,7 +52,7 @@ extern Fl_Window *fl_xfocus; void Fl_Cocoa_Window_Driver::take_focus() { - set_key_window(); + Fl_X::i(pWindow)->set_key_window(); } // diff --git a/src/drivers/PicoSDL/Fl_PicoSDL_Screen_Driver.cxx b/src/drivers/PicoSDL/Fl_PicoSDL_Screen_Driver.cxx index 671ee7b6d..cf25d1091 100644 --- a/src/drivers/PicoSDL/Fl_PicoSDL_Screen_Driver.cxx +++ b/src/drivers/PicoSDL/Fl_PicoSDL_Screen_Driver.cxx @@ -124,7 +124,7 @@ Fl_X* Fl_X::make(Fl_Window *w) } else { parent = 0; } - Fl_Window_Driver *x = Fl_Window_Driver::newWindowDriver(w); + Fl_X *x = new Fl_X; x->other_xid = 0; x->w = w; x->region = 0; -- cgit v1.2.3