diff --git a/lib/appbase/widgets/BaseWindow.cpp b/lib/appbase/widgets/BaseWindow.cpp index cfa6674d0..c670f25a2 100644 --- a/lib/appbase/widgets/BaseWindow.cpp +++ b/lib/appbase/widgets/BaseWindow.cpp @@ -79,6 +79,24 @@ BaseWindow::BaseWindow(QWidget *parent, Flags _flags) this->resize(300, 150); } +void BaseWindow::setInitialBounds(const QRect &bounds) +{ +#ifdef USEWINSDK + this->initalBounds_ = bounds; +#else + this->setGeometry(bounds); +#endif +} + +QRect BaseWindow::getBounds() +{ +#ifdef USEWINSDK + return this->currentBounds_; +#else + return this->geometry(); +#endif +} + float BaseWindow::scale() const { return this->overrideScale().value_or(this->scale_); @@ -579,6 +597,11 @@ bool BaseWindow::nativeEvent(const QByteArray &eventType, void *message, returnValue = this->handleSIZE(msg); break; + case WM_MOVE: + returnValue = this->handleMOVE(msg); + *result = 0; + break; + case WM_NCHITTEST: returnValue = this->handleNCHITTEST(msg, result); break; @@ -709,12 +732,23 @@ bool BaseWindow::handleSHOWWINDOW(MSG *msg) this->updateScale(); } - if (!this->shown_ && this->isVisible() && this->hasCustomWindowFrame()) + if (!this->shown_ && this->isVisible()) { - this->shown_ = true; + if (this->hasCustomWindowFrame()) + { + this->shown_ = true; - const MARGINS shadow = {8, 8, 8, 8}; - DwmExtendFrameIntoClientArea(HWND(this->winId()), &shadow); + const MARGINS shadow = {8, 8, 8, 8}; + DwmExtendFrameIntoClientArea(HWND(this->winId()), &shadow); + } + if (!this->initalBounds_.isNull()) + { + ::SetWindowPos(msg->hwnd, nullptr, this->initalBounds_.x(), + this->initalBounds_.y(), this->initalBounds_.width(), + this->initalBounds_.height(), + SWP_NOZORDER | SWP_NOACTIVATE); + this->currentBounds_ = this->initalBounds_; + } } this->calcButtonsSizes(); @@ -775,6 +809,15 @@ bool BaseWindow::handleSIZE(MSG *msg) { this->ui_.windowLayout->setContentsMargins(0, 1, 0, 0); } + if ((this->isNotMinimizedOrMaximized_ = + msg->wParam == SIZE_RESTORED)) + { + RECT rect; + ::GetWindowRect(msg->hwnd, &rect); + this->currentBounds_ = + QRect(QPoint(rect.left, rect.top), + QPoint(rect.right - 1, rect.bottom - 1)); + } } } return false; @@ -783,6 +826,18 @@ bool BaseWindow::handleSIZE(MSG *msg) #endif } +bool BaseWindow::handleMOVE(MSG *msg) +{ + if (this->isNotMinimizedOrMaximized_) + { + RECT rect; + ::GetWindowRect(msg->hwnd, &rect); + this->currentBounds_ = QRect(QPoint(rect.left, rect.top), + QPoint(rect.right - 1, rect.bottom - 1)); + } + return false; +} + bool BaseWindow::handleNCHITTEST(MSG *msg, long *result) { #ifdef USEWINSDK diff --git a/lib/appbase/widgets/BaseWindow.hpp b/lib/appbase/widgets/BaseWindow.hpp index 577e722c0..4f56204c7 100644 --- a/lib/appbase/widgets/BaseWindow.hpp +++ b/lib/appbase/widgets/BaseWindow.hpp @@ -34,6 +34,9 @@ public: explicit BaseWindow(QWidget *parent = nullptr, Flags flags_ = None); + void setInitialBounds(const QRect &bounds); + QRect getBounds(); + QWidget *getLayoutContainer(); bool hasCustomWindowFrame(); TitleBarButton *addTitleBarButton(const TitleBarButtonStyle &style, @@ -95,6 +98,7 @@ private: bool handleSHOWWINDOW(MSG *msg); bool handleNCCALCSIZE(MSG *msg, long *result); bool handleSIZE(MSG *msg); + bool handleMOVE(MSG *msg); bool handleNCHITTEST(MSG *msg, long *result); bool enableCustomFrame_; @@ -116,6 +120,12 @@ private: std::vector