Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,12 @@ namespace Microsoft.UI.Xaml
Microsoft.UI.Xaml.Media.SystemBackdrop SystemBackdrop;
Microsoft.UI.Windowing.AppWindow AppWindow{ get; };
}

[contract(Microsoft.UI.Xaml.WinUIContract, 5)]
{
Double Width;
Double Height;
}
};

[contract(Microsoft.UI.Xaml.WinUIContract, 1)]
Expand Down
125 changes: 125 additions & 0 deletions src/dxaml/xcp/dxaml/lib/DesktopWindowImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,36 @@ _Check_return_ HRESULT DesktopWindowImpl::get_CompositorImpl(_Outptr_result_mayb
return S_OK;
}

_Check_return_ HRESULT DesktopWindowImpl::get_WidthImpl(_Out_ DOUBLE* pValue)
{
wf::Rect bounds{};
IFC_RETURN(get_BoundsImpl(&bounds));
*pValue = bounds.Width;
return S_OK;
}

_Check_return_ HRESULT DesktopWindowImpl::put_WidthImpl(DOUBLE value)
{
wf::Rect bounds{};
IFC_RETURN(get_BoundsImpl(&bounds));
return SetClientSizeInDips(value, bounds.Height);
}

_Check_return_ HRESULT DesktopWindowImpl::get_HeightImpl(_Out_ DOUBLE* pValue)
{
wf::Rect bounds{};
IFC_RETURN(get_BoundsImpl(&bounds));
*pValue = bounds.Height;
return S_OK;
}

_Check_return_ HRESULT DesktopWindowImpl::put_HeightImpl(DOUBLE value)
{
wf::Rect bounds{};
IFC_RETURN(get_BoundsImpl(&bounds));
return SetClientSizeInDips(bounds.Width, value);
}

// ----------------------------------------------------------------------
// IWindowPrivate
// ----------------------------------------------------------------------
Expand Down Expand Up @@ -555,6 +585,101 @@ _Check_return_ HRESULT DesktopWindowImpl::MoveWindowImpl(_In_ INT x, _In_ INT y,
return S_OK;
}

_Check_return_ HRESULT DesktopWindowImpl::SetClientSizeInDips(DOUBLE width, DOUBLE height)
{
IFC_RETURN(CheckIsWindowClosed());

if (width < 0.0 || height < 0.0 || DoubleUtil::IsNaN(width) || DoubleUtil::IsNaN(height) || DoubleUtil::IsInfinity(width) || DoubleUtil::IsInfinity(height))
{
IFC_RETURN(E_INVALIDARG);
}

RECT windowRect{};
if (::GetWindowRect(m_hwnd.get(), &windowRect) == 0)
{
HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
IFC_RETURN(ErrorHelper::OriginateErrorUsingResourceID(SUCCEEDED(hr) ? E_FAIL : hr, ERROR_WINDOW_DESKTOP_SIZE_OR_POSITION_FAILED));
}

const UINT dpi = ::GetDpiForWindow(m_hwnd.get());
const float scale = static_cast<float>(dpi) / static_cast<float>(USER_DEFAULT_SCREEN_DPI);

RECT desiredWindowRect
{
0,
0,
static_cast<LONG>(std::round(width * scale)),
static_cast<LONG>(std::round(height * scale))
};

const DWORD style = static_cast<DWORD>(::GetWindowLongPtrW(m_hwnd.get(), GWL_STYLE));
const DWORD exStyle = static_cast<DWORD>(::GetWindowLongPtrW(m_hwnd.get(), GWL_EXSTYLE));
if (::AdjustWindowRectExForDpi(&desiredWindowRect, style, ::GetMenu(m_hwnd.get()) != nullptr, exStyle, dpi) == 0)
{
HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
IFC_RETURN(ErrorHelper::OriginateErrorUsingResourceID(SUCCEEDED(hr) ? E_FAIL : hr, ERROR_WINDOW_DESKTOP_SIZE_OR_POSITION_FAILED));
}

const int windowWidth = desiredWindowRect.right - desiredWindowRect.left;
const int windowHeight = desiredWindowRect.bottom - desiredWindowRect.top;

WINDOWPLACEMENT placement = {};
placement.length = sizeof(placement);

bool updateRestoreBoundsOnly = false;
if (::GetWindowPlacement(m_hwnd.get(), &placement) != 0)
{
updateRestoreBoundsOnly = placement.showCmd == SW_SHOWMAXIMIZED;
}

if (!updateRestoreBoundsOnly)
{
ctl::ComPtr<ixp::IAppWindow> appWindow;
if (SUCCEEDED(get_AppWindowImpl(&appWindow)) && appWindow)
{
ctl::ComPtr<ixp::IAppWindowPresenter> presenter;
if (SUCCEEDED(appWindow->get_Presenter(&presenter)) && presenter)
{
ixp::AppWindowPresenterKind presenterKind = ixp::AppWindowPresenterKind_Default;
if (SUCCEEDED(presenter->get_Kind(&presenterKind)))
{
updateRestoreBoundsOnly = presenterKind == ixp::AppWindowPresenterKind_FullScreen;
}
}
}
}

if (updateRestoreBoundsOnly)
{
RECT restoreRect = placement.rcNormalPosition;
if (::IsRectEmpty(&restoreRect))
{
restoreRect = windowRect;
}

placement.rcNormalPosition.left = restoreRect.left;
placement.rcNormalPosition.top = restoreRect.top;
placement.rcNormalPosition.right = restoreRect.left + windowWidth;
placement.rcNormalPosition.bottom = restoreRect.top + windowHeight;

if (::SetWindowPlacement(m_hwnd.get(), &placement) == 0)
{
HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
IFC_RETURN(ErrorHelper::OriginateErrorUsingResourceID(SUCCEEDED(hr) ? E_FAIL : hr, ERROR_WINDOW_DESKTOP_SIZE_OR_POSITION_FAILED));
}

return S_OK;
}

if (::SetWindowPos(m_hwnd.get(), nullptr, windowRect.left, windowRect.top, windowWidth, windowHeight, SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER) == 0)
{
HRESULT hr = HRESULT_FROM_WIN32(GetLastError());
IFC_RETURN(ErrorHelper::OriginateErrorUsingResourceID(SUCCEEDED(hr) ? E_FAIL : hr, ERROR_WINDOW_DESKTOP_SIZE_OR_POSITION_FAILED));
}

return S_OK;
}

_Check_return_ HRESULT DesktopWindowImpl::SetAtlasSizeHintImpl(UINT width, UINT height)
{
IFC_RETURN(ErrorHelper::OriginateErrorUsingResourceID(E_NOTIMPL, ERROR_WINDOW_DESKTOP_NOT_IMPLEMENTED));
Expand Down
5 changes: 5 additions & 0 deletions src/dxaml/xcp/dxaml/lib/DesktopWindowImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ namespace DirectUI
_Check_return_ HRESULT CloseImpl() override;

_Check_return_ HRESULT get_CompositorImpl(_Outptr_result_maybenull_ WUComp::ICompositor** compositor) override;
_Check_return_ HRESULT get_WidthImpl(_Out_ DOUBLE* pValue) override;
_Check_return_ HRESULT put_WidthImpl(DOUBLE value) override;
_Check_return_ HRESULT get_HeightImpl(_Out_ DOUBLE* pValue) override;
_Check_return_ HRESULT put_HeightImpl(DOUBLE value) override;

_Check_return_ HRESULT get_ExtendsContentIntoTitleBarImpl(_Out_ BOOLEAN* pValue) final;
_Check_return_ HRESULT put_ExtendsContentIntoTitleBarImpl(_In_ BOOLEAN value) final;
Expand Down Expand Up @@ -130,6 +134,7 @@ namespace DirectUI
_Check_return_ HRESULT RaiseWindowSizeChangedEvent();
_Check_return_ HRESULT RaiseWindowActivatedEvent(_In_ const xaml::WindowActivationState state);
_Check_return_ HRESULT RaiseWindowVisibilityChangedEvent(_In_ const BOOLEAN visible);
_Check_return_ HRESULT SetClientSizeInDips(DOUBLE width, DOUBLE height);
void ResizeWindowToDesktopWindowXamlSourceWindowDimensions(WPARAM wParam, LPARAM lParam);
void RepositionWindowToDesktopWindowXamlSourceWindowDimensions(WPARAM wParam, LPARAM lParam);
void Shutdown();
Expand Down
67 changes: 67 additions & 0 deletions src/dxaml/xcp/dxaml/lib/UWPWindowImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,36 @@ _Check_return_ HRESULT UWPWindowImpl::get_CompositorImpl(_Outptr_result_maybenul
return S_OK;
}

_Check_return_ HRESULT UWPWindowImpl::get_WidthImpl(_Out_ DOUBLE* pValue)
{
wf::Rect bounds{};
IFC_RETURN(get_BoundsImpl(&bounds));
*pValue = bounds.Width;
return S_OK;
}

_Check_return_ HRESULT UWPWindowImpl::put_WidthImpl(DOUBLE value)
{
wf::Rect bounds{};
IFC_RETURN(get_BoundsImpl(&bounds));
return SetClientSizeInDips(value, bounds.Height);
}

_Check_return_ HRESULT UWPWindowImpl::get_HeightImpl(_Out_ DOUBLE* pValue)
{
wf::Rect bounds{};
IFC_RETURN(get_BoundsImpl(&bounds));
*pValue = bounds.Height;
return S_OK;
}

_Check_return_ HRESULT UWPWindowImpl::put_HeightImpl(DOUBLE value)
{
wf::Rect bounds{};
IFC_RETURN(get_BoundsImpl(&bounds));
return SetClientSizeInDips(bounds.Width, value);
}

_Check_return_ HRESULT UWPWindowImpl::get_TitleImpl(_Out_ HSTRING* pValue)
{
ctl::ComPtr<wuv::IApplicationViewStatics2> applicationViewStatics;
Expand Down Expand Up @@ -847,6 +877,43 @@ _Check_return_ HRESULT UWPWindowImpl::MoveWindowImpl(_In_ INT x, _In_ INT y, _In
return(hr);
}

_Check_return_ HRESULT UWPWindowImpl::SetClientSizeInDips(DOUBLE width, DOUBLE height)
{
IFCCHECK_RETURN(m_pCoreWindowWrapper);

if (width < 0.0 || height < 0.0 || DoubleUtil::IsNaN(width) || DoubleUtil::IsNaN(height) || DoubleUtil::IsInfinity(width) || DoubleUtil::IsInfinity(height))
{
IFC_RETURN(E_INVALIDARG);
}

const HWND hwnd = m_pCoreWindowWrapper->GetHWND();
IFCCHECK_RETURN(hwnd);

RECT windowRect{};
IFCW32_RETURN(::GetWindowRect(hwnd, &windowRect));

const UINT dpi = ::GetDpiForWindow(hwnd);
const float scale = static_cast<float>(dpi) / static_cast<float>(USER_DEFAULT_SCREEN_DPI);

RECT desiredWindowRect
{
0,
0,
static_cast<LONG>(std::round(width * scale)),
static_cast<LONG>(std::round(height * scale))
};

const DWORD style = static_cast<DWORD>(::GetWindowLongPtrW(hwnd, GWL_STYLE));
const DWORD exStyle = static_cast<DWORD>(::GetWindowLongPtrW(hwnd, GWL_EXSTYLE));
IFCW32_RETURN(::AdjustWindowRectExForDpi(&desiredWindowRect, style, ::GetMenu(hwnd) != nullptr, exStyle, dpi));

return m_pCoreWindowWrapper->SetPosition(
windowRect.left,
windowRect.top,
desiredWindowRect.right - desiredWindowRect.left,
desiredWindowRect.bottom - desiredWindowRect.top);
}

_Check_return_ HRESULT UWPWindowImpl::get_TransparentBackgroundImpl(_Out_ BOOLEAN* pValue)
{
bool backgroundTransparency = false;
Expand Down
5 changes: 5 additions & 0 deletions src/dxaml/xcp/dxaml/lib/UWPWindowImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ namespace DirectUI

_Check_return_ HRESULT get_CompositorImpl(_Outptr_result_maybenull_ WUComp::ICompositor** compositor) override;
_Check_return_ HRESULT get_AppWindowImpl(_Outptr_result_maybenull_ ixp::IAppWindow** ppValue) final;
_Check_return_ HRESULT get_WidthImpl(_Out_ DOUBLE* pValue) override;
_Check_return_ HRESULT put_WidthImpl(DOUBLE value) override;
_Check_return_ HRESULT get_HeightImpl(_Out_ DOUBLE* pValue) override;
_Check_return_ HRESULT put_HeightImpl(DOUBLE value) override;

_Check_return_ HRESULT get_SystemBackdropImpl(_Outptr_result_maybenull_ xaml::Media::ISystemBackdrop** systemBackdrop) override;
_Check_return_ HRESULT put_SystemBackdropImpl(_In_opt_ xaml::Media::ISystemBackdrop* systemBackdrop) override;
Expand Down Expand Up @@ -107,6 +111,7 @@ namespace DirectUI
void SetShrinkApplicationViewVisibleBounds(bool enabled) override;

private:
_Check_return_ HRESULT SetClientSizeInDips(DOUBLE width, DOUBLE height);

_Check_return_ HRESULT OnCoreWindowSizeChanged(_In_ wuc::ICoreWindow* pSender, _In_ wuc::IWindowSizeChangedEventArgs* pArgs);
_Check_return_ HRESULT OnApplicationViewVisibleBoundsChanged(_In_ wuv::IApplicationView* pSender, _In_ IInspectable* pArgs);
Expand Down
4 changes: 4 additions & 0 deletions src/dxaml/xcp/dxaml/lib/WindowImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ namespace DirectUI

virtual _Check_return_ HRESULT get_CompositorImpl(_Outptr_result_maybenull_ WUComp::ICompositor** compositor) = 0;
virtual _Check_return_ HRESULT get_AppWindowImpl(_Outptr_result_maybenull_ ixp::IAppWindow** ppValue) = 0;
virtual _Check_return_ HRESULT get_WidthImpl(_Out_ DOUBLE* pValue) = 0;
virtual _Check_return_ HRESULT put_WidthImpl(DOUBLE value) = 0;
virtual _Check_return_ HRESULT get_HeightImpl(_Out_ DOUBLE* pValue) = 0;
virtual _Check_return_ HRESULT put_HeightImpl(DOUBLE value) = 0;

virtual _Check_return_ HRESULT get_SystemBackdropImpl(_Outptr_result_maybenull_ xaml::Media::ISystemBackdrop** systemBackdrop) = 0;
virtual _Check_return_ HRESULT put_SystemBackdropImpl(_In_opt_ xaml::Media::ISystemBackdrop* systemBackdrop) = 0;
Expand Down
24 changes: 24 additions & 0 deletions src/dxaml/xcp/dxaml/lib/Window_Partial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -822,3 +822,27 @@ _Check_return_ HRESULT Window::get_AppWindowImpl(_Outptr_result_maybenull_ ixp::
return S_OK;
}

_Check_return_ HRESULT Window::get_WidthImpl(_Out_ DOUBLE* pValue)
{
IFC_RETURN(m_spWindowImpl->get_WidthImpl(pValue));
return S_OK;
}

_Check_return_ HRESULT Window::put_WidthImpl(DOUBLE value)
{
IFC_RETURN(m_spWindowImpl->put_WidthImpl(value));
return S_OK;
}

_Check_return_ HRESULT Window::get_HeightImpl(_Out_ DOUBLE* pValue)
{
IFC_RETURN(m_spWindowImpl->get_HeightImpl(pValue));
return S_OK;
}

_Check_return_ HRESULT Window::put_HeightImpl(DOUBLE value)
{
IFC_RETURN(m_spWindowImpl->put_HeightImpl(value));
return S_OK;
}

4 changes: 4 additions & 0 deletions src/dxaml/xcp/dxaml/lib/Window_Partial.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ namespace DirectUI
_Check_return_ HRESULT get_DispatcherQueueImpl(_Outptr_result_maybenull_ msy::IDispatcherQueue** ppValue);
_Check_return_ HRESULT get_CompositorImpl(_Outptr_result_maybenull_ WUComp::ICompositor** compositor);
_Check_return_ HRESULT get_AppWindowImpl(_Outptr_result_maybenull_ ixp::IAppWindow** ppValue);
_Check_return_ HRESULT get_WidthImpl(_Out_ DOUBLE* pValue);
_Check_return_ HRESULT put_WidthImpl(DOUBLE value);
_Check_return_ HRESULT get_HeightImpl(_Out_ DOUBLE* pValue);
_Check_return_ HRESULT put_HeightImpl(DOUBLE value);

_Check_return_ HRESULT get_SystemBackdropImpl(_Outptr_result_maybenull_ xaml::Media::ISystemBackdrop** iSystemBackdrop);
_Check_return_ HRESULT put_SystemBackdropImpl(_In_opt_ xaml::Media::ISystemBackdrop* iSystemBackdrop);
Expand Down
44 changes: 44 additions & 0 deletions src/dxaml/xcp/dxaml/lib/winrtgeneratedclasses/Window.g.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ HRESULT DirectUI::WindowGenerated::QueryInterfaceImpl(_In_ REFIID iid, _Outptr_
{
*ppObject = ctl::interface_cast<ABI::Microsoft::UI::Xaml::IWindow2>(this);
}
else if (InlineIsEqualGUID(iid, __uuidof(ABI::Microsoft::UI::Xaml::IWindow3)))
{
*ppObject = ctl::interface_cast<ABI::Microsoft::UI::Xaml::IWindow3>(this);
}
else
{
RRETURN(DirectUI::DependencyObject::QueryInterfaceImpl(iid, ppObject));
Expand Down Expand Up @@ -145,6 +149,26 @@ IFACEMETHODIMP DirectUI::WindowGenerated::get_ExtendsContentIntoTitleBar(_Out_ B
Cleanup:
RRETURN(hr);
}
IFACEMETHODIMP DirectUI::WindowGenerated::get_Height(_Out_ DOUBLE* pValue)
{
HRESULT hr = S_OK;
ARG_VALIDRETURNPOINTER(pValue);
*pValue={};
IFC(CheckThread());
IFC(static_cast<Window*>(this)->get_HeightImpl(pValue));
Cleanup:
RRETURN(hr);
}
IFACEMETHODIMP DirectUI::WindowGenerated::put_Height(DOUBLE value)
{
HRESULT hr = S_OK;

IFC(CheckThread());
IFC(DefaultStrictApiCheck(this));
IFC(static_cast<Window*>(this)->put_HeightImpl(value));
Cleanup:
RRETURN(hr);
}
IFACEMETHODIMP DirectUI::WindowGenerated::put_ExtendsContentIntoTitleBar(BOOLEAN value)
{
HRESULT hr = S_OK;
Expand Down Expand Up @@ -225,6 +249,26 @@ IFACEMETHODIMP DirectUI::WindowGenerated::get_Visible(_Out_ BOOLEAN* pValue)
Cleanup:
RRETURN(hr);
}
IFACEMETHODIMP DirectUI::WindowGenerated::get_Width(_Out_ DOUBLE* pValue)
{
HRESULT hr = S_OK;
ARG_VALIDRETURNPOINTER(pValue);
*pValue={};
IFC(CheckThread());
IFC(static_cast<Window*>(this)->get_WidthImpl(pValue));
Cleanup:
RRETURN(hr);
}
IFACEMETHODIMP DirectUI::WindowGenerated::put_Width(DOUBLE value)
{
HRESULT hr = S_OK;

IFC(CheckThread());
IFC(DefaultStrictApiCheck(this));
IFC(static_cast<Window*>(this)->put_WidthImpl(value));
Cleanup:
RRETURN(hr);
}

// Events.

Expand Down
Loading