From c4f69d2af7d995eb0dd4592c18dc2f6b930bd193 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sat, 19 Oct 2013 11:20:12 +0200 Subject: Make window fixed size. --- plugingui/nativewindow.h | 1 + plugingui/nativewindow_win32.cc | 8 ++++++++ plugingui/nativewindow_win32.h | 1 + plugingui/nativewindow_x11.cc | 25 +++++++++++++++++++++++++ plugingui/nativewindow_x11.h | 1 + plugingui/plugingui.cc | 2 +- plugingui/window.cc | 11 +++++++++-- plugingui/window.h | 1 + 8 files changed, 47 insertions(+), 3 deletions(-) diff --git a/plugingui/nativewindow.h b/plugingui/nativewindow.h index f27989f..d68909d 100644 --- a/plugingui/nativewindow.h +++ b/plugingui/nativewindow.h @@ -38,6 +38,7 @@ public: NativeWindow() {} virtual ~NativeWindow() {} + virtual void setFixedSize(int width, int height) = 0; virtual void resize(int width, int height) = 0; virtual void move(int x, int y) = 0; virtual void show() = 0; diff --git a/plugingui/nativewindow_win32.cc b/plugingui/nativewindow_win32.cc index 935cd04..89844da 100644 --- a/plugingui/nativewindow_win32.cc +++ b/plugingui/nativewindow_win32.cc @@ -320,6 +320,14 @@ GUI::NativeWindowWin32::~NativeWindowWin32() free(m_className); } +void GUI::NativeWindowWin32::setFixedSize(int width, int height) +{ + resize(width, height); + LONG style = GetWindowLong(m_hwnd, GWL_STYLE); + style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX); + SetWindowLong(m_hwnd, GWL_STYLE, style); +} + void GUI::NativeWindowWin32::resize(int width, int height) { SetWindowPos(m_hwnd, NULL, -1, -1, (int)width, (int)height, SWP_NOMOVE); diff --git a/plugingui/nativewindow_win32.h b/plugingui/nativewindow_win32.h index d8ba7b3..6afc7b1 100644 --- a/plugingui/nativewindow_win32.h +++ b/plugingui/nativewindow_win32.h @@ -44,6 +44,7 @@ public: NativeWindowWin32(GUI::Window *window); ~NativeWindowWin32(); + void setFixedSize(int width, int height); void resize(int width, int height); void move(int x, int y); void show(); diff --git a/plugingui/nativewindow_x11.cc b/plugingui/nativewindow_x11.cc index f8511a0..cb6cf73 100644 --- a/plugingui/nativewindow_x11.cc +++ b/plugingui/nativewindow_x11.cc @@ -82,6 +82,31 @@ GUI::NativeWindowX11::~NativeWindowX11() XCloseDisplay(display); } +void GUI::NativeWindowX11::setFixedSize(int width, int height) +{ + resize(width, height); + + XSizeHints *size_hints; + size_hints = XAllocSizeHints(); + + if(size_hints == NULL) { + //fprintf(stderr,"XMallocSizeHints() failed\n"); + //exit(1); + return; + } + + size_hints->flags = USPosition | PMinSize | PMaxSize; + size_hints->min_width = size_hints->max_width = width; + size_hints->min_height = size_hints->max_height = height; + /* + size_hints->min_aspect.x = window->width()/window->height(); + size_hints->max_aspect.x = window->width()/window->height(); + size_hints->min_aspect.y = window->width()/window->height(); + size_hints->max_aspect.y = size_hints->min_aspect.y; + */ + XSetWMNormalHints(display, xwindow, size_hints); +} + void GUI::NativeWindowX11::resize(int width, int height) { XResizeWindow(display, xwindow, width, height); diff --git a/plugingui/nativewindow_x11.h b/plugingui/nativewindow_x11.h index 84044de..3dcc0bb 100644 --- a/plugingui/nativewindow_x11.h +++ b/plugingui/nativewindow_x11.h @@ -41,6 +41,7 @@ public: NativeWindowX11(GUI::Window *window); ~NativeWindowX11(); + void setFixedSize(int width, int height); void resize(int width, int height); void move(int x, int y); void show(); diff --git a/plugingui/plugingui.cc b/plugingui/plugingui.cc index e452965..6601be7 100644 --- a/plugingui/plugingui.cc +++ b/plugingui/plugingui.cc @@ -284,7 +284,7 @@ void PluginGUI::init() window->eventHandler()->registerCloseHandler(closeEventHandler, (void*)&closing); - window->resize(370, 330); + window->setFixedSize(370, 330); window->setCaption("DrumGizmo v"VERSION); GUI::Label *lbl_title = new GUI::Label(window); diff --git a/plugingui/window.cc b/plugingui/window.cc index 0d11b17..41d4d82 100644 --- a/plugingui/window.cc +++ b/plugingui/window.cc @@ -92,16 +92,23 @@ void GUI::Window::repaintEvent(GUI::RepaintEvent *e) height() - logo.height(), &logo); } +void GUI::Window::setFixedSize(int w, int h) +{ + native->setFixedSize(w, h); + resize(w,h); +} + void GUI::Window::resize(int width, int height) { if(width < 1 || height < 1) return; -#ifdef WIN32 + // This needs to be done on all platoforms when setFixedSize is introduced. + //#ifdef WIN32 // Fix to force buffer size reallocation // FIXME: This should've been done indirectly through a WM_SIZE message in the // EventHandler... resized(width, height); -#endif + //#endif native->resize(width, height); Widget::resize(width, height); diff --git a/plugingui/window.h b/plugingui/window.h index 2e3d17c..f8deef0 100644 --- a/plugingui/window.h +++ b/plugingui/window.h @@ -44,6 +44,7 @@ public: void show(); void hide(); + void setFixedSize(int width, int height); void resize(int width, int height); void move(size_t x, size_t y); -- cgit v1.2.3