From c02ec2e3d56e7120ea5e1ce0875227269124d58d Mon Sep 17 00:00:00 2001 From: reuk Date: Mon, 30 Sep 2024 12:39:47 +0100 Subject: [PATCH] DocumentWindow: Ensure button callbacks are called on Windows --- .../components/juce_Component.h | 23 +++++++++++++++++++ .../native/juce_Windowing_windows.cpp | 22 +++++++++++++++--- .../windows/juce_DocumentWindow.cpp | 15 ++++++++++++ .../windows/juce_DocumentWindow.h | 6 +++++ 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/modules/juce_gui_basics/components/juce_Component.h b/modules/juce_gui_basics/components/juce_Component.h index b2eb22ce8d..443a81dcaa 100644 --- a/modules/juce_gui_basics/components/juce_Component.h +++ b/modules/juce_gui_basics/components/juce_Component.h @@ -925,9 +925,32 @@ public: window's caption area to the edge of the screen), double-clicking a horizontal border to stretch a window vertically, and the window tiling flyout that appears when hovering the mouse over the maximise button. + + This is called by the peer. Component subclasses may override this but should not call it directly. */ virtual WindowControlKind findControlAtPoint (Point) const { return WindowControlKind::client; } + /** For components that are added to the desktop, this may be called to indicate that the mouse + was clicked inside the area of the "close" control. This is currently only called on Windows. + + This is called by the peer. Component subclasses may override this but should not call it directly. + */ + virtual void windowControlClickedClose() {} + + /** For components that are added to the desktop, this may be called to indicate that the mouse + was clicked inside the area of the "minimise" control. This is currently only called on Windows. + + This is called by the peer. Component subclasses may override this but should not call it directly. + */ + virtual void windowControlClickedMinimise() {} + + /** For components that are added to the desktop, this may be called to indicate that the mouse + was clicked inside the area of the "maximise" control. This is currently only called on Windows. + + This is called by the peer. Component subclasses may override this but should not call it directly. + */ + virtual void windowControlClickedMaximise() {} + /** Changes the default return value for the hitTest() method. Setting this to false is an easy way to make a component pass all its mouse events diff --git a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp index def48bfb7d..14341df7f1 100644 --- a/modules/juce_gui_basics/native/juce_Windowing_windows.cpp +++ b/modules/juce_gui_basics/native/juce_Windowing_windows.cpp @@ -4304,17 +4304,33 @@ private: switch (wParam) { case HTCLOSE: - PostMessage (h, WM_CLOSE, 0, 0); + if ((styleFlags & windowHasCloseButton) != 0 && ! sendInputAttemptWhenModalMessage()) + { + if (hasTitleBar()) + PostMessage (h, WM_CLOSE, 0, 0); + else + component.windowControlClickedClose(); + } return 0; case HTMAXBUTTON: if ((styleFlags & windowHasMaximiseButton) != 0 && ! sendInputAttemptWhenModalMessage()) - setFullScreen (! isFullScreen()); + { + if (hasTitleBar()) + setFullScreen (! isFullScreen()); + else + component.windowControlClickedMaximise(); + } return 0; case HTMINBUTTON: if ((styleFlags & windowHasMinimiseButton) != 0 && ! sendInputAttemptWhenModalMessage()) - setMinimised (true); + { + if (hasTitleBar()) + setMinimised (true); + else + component.windowControlClickedMinimise(); + } return 0; } break; diff --git a/modules/juce_gui_basics/windows/juce_DocumentWindow.cpp b/modules/juce_gui_basics/windows/juce_DocumentWindow.cpp index 43886ad981..ec330c1b14 100644 --- a/modules/juce_gui_basics/windows/juce_DocumentWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_DocumentWindow.cpp @@ -192,6 +192,21 @@ void DocumentWindow::maximiseButtonPressed() setFullScreen (! isFullScreen()); } +void DocumentWindow::windowControlClickedClose() +{ + closeButtonPressed(); +} + +void DocumentWindow::windowControlClickedMinimise() +{ + minimiseButtonPressed(); +} + +void DocumentWindow::windowControlClickedMaximise() +{ + maximiseButtonPressed(); +} + //============================================================================== void DocumentWindow::paint (Graphics& g) { diff --git a/modules/juce_gui_basics/windows/juce_DocumentWindow.h b/modules/juce_gui_basics/windows/juce_DocumentWindow.h index 09e4484ca4..8d5bae804e 100644 --- a/modules/juce_gui_basics/windows/juce_DocumentWindow.h +++ b/modules/juce_gui_basics/windows/juce_DocumentWindow.h @@ -294,6 +294,12 @@ public: Rectangle getTitleBarArea() const; /** @internal */ WindowControlKind findControlAtPoint (Point) const override; + /** @internal */ + void windowControlClickedClose() override; + /** @internal */ + void windowControlClickedMinimise() override; + /** @internal */ + void windowControlClickedMaximise() override; #endif private: