From b382c7e3c6645c977cd9a7bf28b639a349d5bbde Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 18 Apr 2017 14:58:49 +0200 Subject: Make visible() call into nativewindow and make Win32 windows invisible on creation. --- plugingui/nativewindow.h | 3 +++ plugingui/nativewindow_win32.cc | 7 ++++++- plugingui/nativewindow_win32.h | 3 ++- plugingui/nativewindow_x11.cc | 12 ++++++++++++ plugingui/nativewindow_x11.h | 1 + plugingui/widget.h | 2 +- plugingui/window.cc | 9 +++++---- plugingui/window.h | 1 + 8 files changed, 31 insertions(+), 7 deletions(-) (limited to 'plugingui') diff --git a/plugingui/nativewindow.h b/plugingui/nativewindow.h index b4429af..6dcb308 100644 --- a/plugingui/nativewindow.h +++ b/plugingui/nativewindow.h @@ -68,6 +68,9 @@ public: //! Hides the window. virtual void hide() = 0; + //! Return visibility state of the native window. + virtual bool visible() const = 0; + //! Sets the window caption in the title bar (if it has one). virtual void setCaption(const std::string &caption) = 0; diff --git a/plugingui/nativewindow_win32.cc b/plugingui/nativewindow_win32.cc index 01a2fa8..f2387c7 100644 --- a/plugingui/nativewindow_win32.cc +++ b/plugingui/nativewindow_win32.cc @@ -367,7 +367,7 @@ NativeWindowWin32::NativeWindowWin32(void* native_window, Window& window) m_hwnd = CreateWindowEx(0/*ex_style*/, m_className, "DGBasisWidget", - (native_window?WS_CHILD:WS_OVERLAPPEDWINDOW) | WS_VISIBLE, + (native_window?WS_CHILD:WS_OVERLAPPEDWINDOW), 0, 0, //window.x(), window.y(), 1, 1, //window.width(), window.height(), parent_window, nullptr, @@ -455,6 +455,11 @@ void NativeWindowWin32::hide() ShowWindow(m_hwnd, SW_HIDE); } +bool NativeWindowWin32::visible() const +{ + return IsWindowVisible(m_hwnd); +} + void NativeWindowWin32::redraw(const Rect& dirty_rect) { // Send WM_PAINT message. Buffer transfering is handled in MessageHandler. diff --git a/plugingui/nativewindow_win32.h b/plugingui/nativewindow_win32.h index c7d412a..bb407d8 100644 --- a/plugingui/nativewindow_win32.h +++ b/plugingui/nativewindow_win32.h @@ -50,9 +50,10 @@ public: void move(int x, int y) override; std::pair getPosition() override; void show() override; - void setCaption(const std::string &caption) override; + bool visible() const override; void hide() override; void redraw(const Rect& dirty_rect) override; + void setCaption(const std::string &caption) override; void grabMouse(bool grab) override; EventQueue getEvents() override; void* getNativeWindowHandle() const override; diff --git a/plugingui/nativewindow_x11.cc b/plugingui/nativewindow_x11.cc index af2f4a6..ae8ad2c 100644 --- a/plugingui/nativewindow_x11.cc +++ b/plugingui/nativewindow_x11.cc @@ -225,6 +225,18 @@ void NativeWindowX11::hide() XUnmapWindow(display, xwindow); } +bool NativeWindowX11::visible() const +{ + if(display == nullptr) + { + return false; + } + + XWindowAttributes xwa; + XGetWindowAttributes(display, xwindow, &xwa); + return (xwa.map_state == IsViewable); +} + void NativeWindowX11::redraw(const Rect& dirty_rect) { if(display == nullptr) diff --git a/plugingui/nativewindow_x11.h b/plugingui/nativewindow_x11.h index c850318..c6c038e 100644 --- a/plugingui/nativewindow_x11.h +++ b/plugingui/nativewindow_x11.h @@ -53,6 +53,7 @@ public: std::pair getPosition() override; void show() override; void hide() override; + bool visible() const override; void setCaption(const std::string &caption) override; void redraw(const Rect& dirty_rect) override; void grabMouse(bool grab) override; diff --git a/plugingui/widget.h b/plugingui/widget.h index 0485c32..3b17f1f 100644 --- a/plugingui/widget.h +++ b/plugingui/widget.h @@ -53,7 +53,7 @@ public: virtual void show(); virtual void hide(); void setVisible(bool visible); - bool visible() const; + virtual bool visible() const; //! Mark widget dirty and shedule redraw on next window redraw. void redraw(); diff --git a/plugingui/window.cc b/plugingui/window.cc index a38eeea..3840643 100644 --- a/plugingui/window.cc +++ b/plugingui/window.cc @@ -51,10 +51,6 @@ Window::Window(void* native_window) : Widget(nullptr) , wpixbuf(1, 1) { - // Defaults to true for widgets but the window should be considered invisble - // until show is called. - _visible = false; - // Make sure we have a valid size when initialising the NativeWindow _width = wpixbuf.width; _height = wpixbuf.height; @@ -122,6 +118,11 @@ void Window::hide() Widget::hide(); } +bool Window::visible() const +{ + return native->visible(); +} + Window* Window::window() { return this; diff --git a/plugingui/window.h b/plugingui/window.h index 218beec..e248b69 100644 --- a/plugingui/window.h +++ b/plugingui/window.h @@ -52,6 +52,7 @@ public: void move(int x, int y) override; void show() override; void hide() override; + bool visible() const override; Window* window() override; ImageCache& getImageCache() override; -- cgit v1.2.3