| @@ -37,12 +37,12 @@ public: | |||||
| sgc((Window&)*this) {} | sgc((Window&)*this) {} | ||||
| /** | /** | ||||
| Constructor with parent window, typically used to run as modal. | |||||
| Constructor with a transient parent window, typically used to run as modal. | |||||
| */ | */ | ||||
| StandaloneWindow(Application& app, Window& parentWindow) | |||||
| : Window(app, parentWindow), | |||||
| StandaloneWindow(Application& app, Window& transientParentWindow) | |||||
| : Window(app, transientParentWindow), | |||||
| TopLevelWidget((Window&)*this), | TopLevelWidget((Window&)*this), | ||||
| sgc((Window&)*this) {} | |||||
| sgc((Window&)*this, transientParentWindow) {} | |||||
| /** | /** | ||||
| Clear current graphics context. | Clear current graphics context. | ||||
| @@ -49,6 +49,8 @@ class TopLevelWidget; | |||||
| */ | */ | ||||
| class Window | class Window | ||||
| { | { | ||||
| struct PrivateData; | |||||
| public: | public: | ||||
| #ifndef DGL_FILE_BROWSER_DISABLED | #ifndef DGL_FILE_BROWSER_DISABLED | ||||
| /** | /** | ||||
| @@ -131,6 +133,9 @@ public: | |||||
| /** Constructor that will make the @a window graphics context the current one */ | /** Constructor that will make the @a window graphics context the current one */ | ||||
| explicit ScopedGraphicsContext(Window& window); | explicit ScopedGraphicsContext(Window& window); | ||||
| /** Overloaded constructor, gives back context to its transient parent when done */ | |||||
| explicit ScopedGraphicsContext(Window& window, Window& transientParentWindow); | |||||
| /** Desstructor for clearing current context, if not done yet */ | /** Desstructor for clearing current context, if not done yet */ | ||||
| ~ScopedGraphicsContext(); | ~ScopedGraphicsContext(); | ||||
| @@ -142,6 +147,7 @@ public: | |||||
| private: | private: | ||||
| Window& window; | Window& window; | ||||
| Window::PrivateData* ppData; | |||||
| bool active; | bool active; | ||||
| }; | }; | ||||
| @@ -451,7 +457,6 @@ protected: | |||||
| #endif | #endif | ||||
| private: | private: | ||||
| struct PrivateData; | |||||
| PrivateData* const pData; | PrivateData* const pData; | ||||
| friend class Application; | friend class Application; | ||||
| friend class PluginWindow; | friend class PluginWindow; | ||||
| @@ -25,20 +25,35 @@ START_NAMESPACE_DGL | |||||
| Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win) | Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win) | ||||
| : window(win), | : window(win), | ||||
| ppData(nullptr), | |||||
| active(puglBackendEnter(window.pData->view)) {} | active(puglBackendEnter(window.pData->view)) {} | ||||
| Window::ScopedGraphicsContext::ScopedGraphicsContext(Window& win, Window& transientWin) | |||||
| : window(win), | |||||
| ppData(transientWin.pData), | |||||
| active(false) | |||||
| { | |||||
| puglBackendLeave(ppData->view); | |||||
| active = puglBackendEnter(window.pData->view); | |||||
| } | |||||
| Window::ScopedGraphicsContext::~ScopedGraphicsContext() | Window::ScopedGraphicsContext::~ScopedGraphicsContext() | ||||
| { | { | ||||
| if (active) | |||||
| puglBackendLeave(window.pData->view); | |||||
| done(); | |||||
| } | } | ||||
| void Window::ScopedGraphicsContext::done() | void Window::ScopedGraphicsContext::done() | ||||
| { | { | ||||
| if (active) | if (active) | ||||
| { | { | ||||
| active = false; | |||||
| puglBackendLeave(window.pData->view); | puglBackendLeave(window.pData->view); | ||||
| active = false; | |||||
| } | |||||
| if (ppData != nullptr) | |||||
| { | |||||
| puglBackendEnter(ppData->view); | |||||
| ppData = nullptr; | |||||
| } | } | ||||
| } | } | ||||
| @@ -123,7 +123,6 @@ Window::PrivateData::PrivateData(Application& a, Window* const s, PrivateData* c | |||||
| #endif | #endif | ||||
| modal(ppData) | modal(ppData) | ||||
| { | { | ||||
| puglBackendLeave(transientParentView); | |||||
| puglSetTransientFor(view, puglGetNativeWindow(transientParentView)); | puglSetTransientFor(view, puglGetNativeWindow(transientParentView)); | ||||
| initPre(DEFAULT_WIDTH, DEFAULT_HEIGHT, false); | initPre(DEFAULT_WIDTH, DEFAULT_HEIGHT, false); | ||||
| @@ -266,10 +265,6 @@ bool Window::PrivateData::initPost() | |||||
| puglShow(view); | puglShow(view); | ||||
| } | } | ||||
| // give context back to transient parent window | |||||
| if (transientParentView != nullptr) | |||||
| puglBackendEnter(transientParentView); | |||||
| return true; | return true; | ||||
| } | } | ||||