2019-05-03 00:29:04 +02:00
|
|
|
/*++
|
|
|
|
Copyright (c) Microsoft Corporation
|
|
|
|
|
|
|
|
Module Name:
|
|
|
|
- NonClientIslandWindow.h
|
|
|
|
|
|
|
|
Abstract:
|
|
|
|
- This class represents a window hosting two XAML Islands. One is in the client
|
|
|
|
area of the window, as it is in the base IslandWindow class. The second is in
|
|
|
|
the titlebar of the window, in the "non-client" area of the window. This
|
|
|
|
enables an app to place xaml content in the titlebar.
|
|
|
|
- Placing content in the frame is enabled with DwmExtendFrameIntoClientArea. See
|
|
|
|
https://docs.microsoft.com/en-us/windows/desktop/dwm/customframe
|
|
|
|
for information on how this is done.
|
|
|
|
|
|
|
|
Author(s):
|
|
|
|
Mike Griese (migrie) April-2019
|
|
|
|
--*/
|
|
|
|
|
|
|
|
#include "pch.h"
|
|
|
|
#include "IslandWindow.h"
|
|
|
|
#include "../../types/inc/Viewport.hpp"
|
|
|
|
#include <dwmapi.h>
|
2019-11-05 00:45:40 +01:00
|
|
|
#include <wil/resource.h>
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
class NonClientIslandWindow : public IslandWindow
|
|
|
|
{
|
|
|
|
public:
|
2019-11-05 00:45:40 +01:00
|
|
|
// this is the same for all DPIs
|
|
|
|
static constexpr const int topBorderVisibleHeight = 1;
|
|
|
|
|
|
|
|
NonClientIslandWindow(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme) noexcept;
|
2019-05-03 00:29:04 +02:00
|
|
|
virtual ~NonClientIslandWindow() override;
|
|
|
|
|
2020-04-25 00:22:40 +02:00
|
|
|
void MakeWindow() noexcept override;
|
2019-06-25 22:06:11 +02:00
|
|
|
virtual void OnSize(const UINT width, const UINT height) override;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
[[nodiscard]] virtual LRESULT MessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept override;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2021-08-09 20:27:20 +02:00
|
|
|
virtual RECT GetNonClientFrame(UINT dpi) const noexcept override;
|
2020-01-08 22:19:23 +01:00
|
|
|
virtual SIZE GetTotalNonClientExclusiveSize(UINT dpi) const noexcept override;
|
|
|
|
|
Enable dragging with the entire titlebar (#1948)
* This definitely works for getting shadow, pointy corners back
Don't do anything in NCPAINT. If you do, you have to do everything. But the
whole point of DwmExtendFrameIntoClientArea is to let you paint the NC area in
your normal paint. So just do that dummy.
* This doesn't transition across monitors.
* This has a window style change I think is wrong.
* I'm not sure the margins change is important.
* The window style was _not_ important
* Still getting a black xaml islands area (the HRGN) when we switch to high DPI
* I don't know if this affects anything.
* heyo this works.
I'm not entirely sure why. But if we only update the titlebar drag region when
that actually changes, it's a _lot_ smoother. I'm not super happy with the
duplicated work in _UpdateDragRegion and OnSize, but checking this in in case
I can't figure that out.
* Add more comments and cleanup
* Try making the button RightCustomContent
* * Make the MinMaxClose's drag bar's min size the same as a caption button
* Make the new tab button transparent, to see how that looks
* Make sure the TabView doesn't push the MMC off the window
* Create a TitlebarControl
* The TitlebarControl is owned by the NCIW. It consists of a Content, DragBar,
and MMCControl.
* The App instatntiates a TabRowControl at runtime, and either places it in
the UI (for tabs below titlebar) or hangs on to it, and gives it to the NCIW
when the NCIW creates its UI.
* When the NCIW is created, it creates a grid with two rows, one for the
titlebar and one for the app content.
* The MMCControl is only responsible for Min Max Close now, and is closer to
the window implementation.
* The drag bar takes up all the space from the right of the TabRow to the left
of the MMC
* Things that **DON'T** work:
- When you add tabs, the drag bar doesn't update it's size. It only updates
OnSize
- The MMCControl's Min and Max buttons don't seem to work anymore.
- They should probably just expose their OnMinimizeClick and
OnMaximizeClick events for the Titlebar to handle minimizing and
maximizing.
- The drag bar is Magenta (#ff00ff) currently.
- I'm not _sure_ we need a TabRowControl. We could probably get away with
removing it from the UI tree, I was just being dumb before.
* Fix the MMC buttons not working
I forgot to plumb the window handle through
* Make the titlebar less magenta
* Resize the drag region as we add/remove tabs
* Move the actual MMC handling to the TitlebarControl
* Some PR nits, fix the titlebar painting on maximize
* Put the TabRow in our XAML
* Remove dead code in preparation for review
* Horrifyingly try Gdi Plus as a solution, that is _wrong_ though
* Revert "Horrifyingly try Gdi Plus as a solution, that is _wrong_ though"
This reverts commit e038b5d9216c6710c2a7f81840d76f8130cd73b8.
* This fixes the bottom border but breaks the titlebar painting
* Fix the NC bottom border
* A bunch of the more minor PR nits
* Add a MinimizeClick event to the MMCControl
This works for Minimize. This is what I wanted to do originally.
* Add events for _all_ of the buttons, not just the Minimize btn
* Change hoe setting the titlebar content works
Now the app triggers a callcack on the host to set the content, instead of the host querying the app.
* Move the tab row to the bottom of it's available space
* Fix the theme reloading
* PR nits from @miniksa
* Update src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Co-Authored-By: Michael Niksa <miniksa@microsoft.com>
* This needed to be fixed, was missed in other PR nits
* runformat
wait _what_
* Does this fix the CI build?
2019-07-19 00:21:33 +02:00
|
|
|
void Initialize() override;
|
|
|
|
|
|
|
|
void OnAppInitialized() override;
|
|
|
|
void SetContent(winrt::Windows::UI::Xaml::UIElement content) override;
|
|
|
|
void SetTitlebarContent(winrt::Windows::UI::Xaml::UIElement content);
|
2019-11-05 00:45:40 +01:00
|
|
|
void OnApplicationThemeChanged(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme) override;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
private:
|
2019-11-05 00:45:40 +01:00
|
|
|
std::optional<COORD> _oldIslandPos;
|
|
|
|
|
Enable dragging with the entire titlebar (#1948)
* This definitely works for getting shadow, pointy corners back
Don't do anything in NCPAINT. If you do, you have to do everything. But the
whole point of DwmExtendFrameIntoClientArea is to let you paint the NC area in
your normal paint. So just do that dummy.
* This doesn't transition across monitors.
* This has a window style change I think is wrong.
* I'm not sure the margins change is important.
* The window style was _not_ important
* Still getting a black xaml islands area (the HRGN) when we switch to high DPI
* I don't know if this affects anything.
* heyo this works.
I'm not entirely sure why. But if we only update the titlebar drag region when
that actually changes, it's a _lot_ smoother. I'm not super happy with the
duplicated work in _UpdateDragRegion and OnSize, but checking this in in case
I can't figure that out.
* Add more comments and cleanup
* Try making the button RightCustomContent
* * Make the MinMaxClose's drag bar's min size the same as a caption button
* Make the new tab button transparent, to see how that looks
* Make sure the TabView doesn't push the MMC off the window
* Create a TitlebarControl
* The TitlebarControl is owned by the NCIW. It consists of a Content, DragBar,
and MMCControl.
* The App instatntiates a TabRowControl at runtime, and either places it in
the UI (for tabs below titlebar) or hangs on to it, and gives it to the NCIW
when the NCIW creates its UI.
* When the NCIW is created, it creates a grid with two rows, one for the
titlebar and one for the app content.
* The MMCControl is only responsible for Min Max Close now, and is closer to
the window implementation.
* The drag bar takes up all the space from the right of the TabRow to the left
of the MMC
* Things that **DON'T** work:
- When you add tabs, the drag bar doesn't update it's size. It only updates
OnSize
- The MMCControl's Min and Max buttons don't seem to work anymore.
- They should probably just expose their OnMinimizeClick and
OnMaximizeClick events for the Titlebar to handle minimizing and
maximizing.
- The drag bar is Magenta (#ff00ff) currently.
- I'm not _sure_ we need a TabRowControl. We could probably get away with
removing it from the UI tree, I was just being dumb before.
* Fix the MMC buttons not working
I forgot to plumb the window handle through
* Make the titlebar less magenta
* Resize the drag region as we add/remove tabs
* Move the actual MMC handling to the TitlebarControl
* Some PR nits, fix the titlebar painting on maximize
* Put the TabRow in our XAML
* Remove dead code in preparation for review
* Horrifyingly try Gdi Plus as a solution, that is _wrong_ though
* Revert "Horrifyingly try Gdi Plus as a solution, that is _wrong_ though"
This reverts commit e038b5d9216c6710c2a7f81840d76f8130cd73b8.
* This fixes the bottom border but breaks the titlebar painting
* Fix the NC bottom border
* A bunch of the more minor PR nits
* Add a MinimizeClick event to the MMCControl
This works for Minimize. This is what I wanted to do originally.
* Add events for _all_ of the buttons, not just the Minimize btn
* Change hoe setting the titlebar content works
Now the app triggers a callcack on the host to set the content, instead of the host querying the app.
* Move the tab row to the bottom of it's available space
* Fix the theme reloading
* PR nits from @miniksa
* Update src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Co-Authored-By: Michael Niksa <miniksa@microsoft.com>
* This needed to be fixed, was missed in other PR nits
* runformat
wait _what_
* Does this fix the CI build?
2019-07-19 00:21:33 +02:00
|
|
|
winrt::TerminalApp::TitlebarControl _titlebar{ nullptr };
|
|
|
|
winrt::Windows::UI::Xaml::UIElement _clientContent{ nullptr };
|
|
|
|
|
2019-06-25 22:06:11 +02:00
|
|
|
wil::unique_hbrush _backgroundBrush;
|
2020-05-16 00:43:00 +02:00
|
|
|
til::color _backgroundBrushColor;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2019-06-25 22:06:11 +02:00
|
|
|
winrt::Windows::UI::Xaml::Controls::Border _dragBar{ nullptr };
|
2020-04-25 00:22:40 +02:00
|
|
|
wil::unique_hwnd _dragBarWindow;
|
2019-06-25 22:06:11 +02:00
|
|
|
|
2019-11-05 00:45:40 +01:00
|
|
|
winrt::Windows::UI::Xaml::ElementTheme _theme;
|
2019-05-30 18:20:42 +02:00
|
|
|
|
2019-11-05 00:45:40 +01:00
|
|
|
bool _isMaximized;
|
2021-11-03 17:28:21 +01:00
|
|
|
bool _trackingMouse{ false };
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2020-04-25 00:22:40 +02:00
|
|
|
[[nodiscard]] static LRESULT __stdcall _StaticInputSinkWndProc(HWND const window, UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept;
|
|
|
|
[[nodiscard]] LRESULT _InputSinkMessageHandler(UINT const message, WPARAM const wparam, LPARAM const lparam) noexcept;
|
|
|
|
|
|
|
|
void _ResizeDragBarWindow() noexcept;
|
|
|
|
|
2019-11-05 00:45:40 +01:00
|
|
|
int _GetResizeHandleHeight() const noexcept;
|
|
|
|
RECT _GetDragAreaRect() const noexcept;
|
|
|
|
int _GetTopBorderHeight() const noexcept;
|
2021-11-03 15:11:55 +01:00
|
|
|
LRESULT _dragBarNcHitTest(const til::point& pointer);
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2019-11-05 00:45:40 +01:00
|
|
|
[[nodiscard]] LRESULT _OnNcCreate(WPARAM wParam, LPARAM lParam) noexcept override;
|
|
|
|
[[nodiscard]] LRESULT _OnNcCalcSize(const WPARAM wParam, const LPARAM lParam) noexcept;
|
|
|
|
[[nodiscard]] LRESULT _OnNcHitTest(POINT ptMouse) const noexcept;
|
|
|
|
[[nodiscard]] LRESULT _OnPaint() noexcept;
|
2020-04-25 00:22:40 +02:00
|
|
|
[[nodiscard]] LRESULT _OnSetCursor(WPARAM wParam, LPARAM lParam) const noexcept;
|
2019-11-05 00:45:40 +01:00
|
|
|
void _OnMaximizeChange() noexcept;
|
2020-04-25 00:22:40 +02:00
|
|
|
void _OnDragBarSizeChanged(winrt::Windows::Foundation::IInspectable sender, winrt::Windows::UI::Xaml::SizeChangedEventArgs eventArgs);
|
2019-06-25 22:06:11 +02:00
|
|
|
|
2020-07-13 19:40:20 +02:00
|
|
|
void _SetIsBorderless(const bool borderlessEnabled) override;
|
|
|
|
void _SetIsFullscreen(const bool fullscreenEnabled) override;
|
Enable fullscreen mode (#3408)
## Summary of the Pull Request
Enables the `toggleFullscreen` action to be able to enter fullscreen mode, bound by default to <kbd>alt+enter</kbd>.
The action is bubbled up to the WindowsTerminal (Win32) layer, where the window resizes itself to take the entire size of the monitor.
This largely reuses code from conhost. Conhost already had a fullscreen mode, so I figured I might as well re-use that.
## References
Unfortunately there are still very thin borders around the window when the NonClientIslandWindow is fullscreened. I think I know where the problem is. However, that area of code is about to get a massive overhaul with #3064, so I didn't want to necessarily make it worse right now.
A follow up should be filed to add support for "Always show / reveal / never show tabs in fullscreen mode". Currently, the only mode is "never show tabs".
Additionally, some of this code (particularily re:drawing the nonclient area) could be re-used for #2238.
## PR Checklist
* [x] Closes #531, #3411
* [x] I work here
* [n/a] Tests added/passed 😭
* [x] Requires documentation to be updated
## Validation Steps Performed
* Manually tested both the NonClientIslandWindow and the IslandWindow.
* Cherry-pick commit 8e56bfe
* Don't draw the tab strip when maximized
(cherry picked from commit bac4be7c0f3ed1cdcd4f9ae8980fc98103538613)
* Fix the vista window flash for the NCIW
(cherry picked from commit 7d3a18a893c02bd2ed75026f2aac52e20321a1cf)
* Some code cleanup for review
(cherry picked from commit 9e22b7730bba426adcbfd9e7025f192dbf8efb32)
* A tad bit more notes and cleanup
* Update schema, docs
* Most of the PR comments
* I'm not sure this actually works, so I'm committing it to revert it and check
* Update some comments that were lost.
* Fix a build break?
* oh no
2019-11-05 20:40:29 +01:00
|
|
|
bool _IsTitlebarVisible() const;
|
|
|
|
|
2019-11-06 19:56:54 +01:00
|
|
|
void _UpdateFrameMargins() const noexcept;
|
2019-11-05 00:45:40 +01:00
|
|
|
void _UpdateMaximizedState();
|
|
|
|
void _UpdateIslandPosition(const UINT windowWidth, const UINT windowHeight);
|
2019-05-03 00:29:04 +02:00
|
|
|
};
|