aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/thmutil.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/dutil/thmutil.cpp')
-rw-r--r--src/dutil/thmutil.cpp59
1 files changed, 48 insertions, 11 deletions
diff --git a/src/dutil/thmutil.cpp b/src/dutil/thmutil.cpp
index a1b101e8..75b0e4a0 100644
--- a/src/dutil/thmutil.cpp
+++ b/src/dutil/thmutil.cpp
@@ -367,12 +367,21 @@ static void ResizeControl(
367 __in THEME_CONTROL* pControl, 367 __in THEME_CONTROL* pControl,
368 __in const RECT* prcParent 368 __in const RECT* prcParent
369 ); 369 );
370static void ScaleTheme( 370static void ScaleThemeFromWindow(
371 __in THEME* pTheme, 371 __in THEME* pTheme,
372 __in UINT nDpi, 372 __in UINT nDpi,
373 __in int x, 373 __in int x,
374 __in int y 374 __in int y
375 ); 375 );
376static void ScaleTheme(
377 __in THEME* pTheme,
378 __in UINT nDpi,
379 __in int x,
380 __in int y,
381 __in DWORD dwStyle,
382 __in BOOL fMenu,
383 __in DWORD dwExStyle
384 );
376static void ScaleControls( 385static void ScaleControls(
377 __in THEME* pTheme, 386 __in THEME* pTheme,
378 __in DWORD cControls, 387 __in DWORD cControls,
@@ -611,6 +620,7 @@ DAPI_(HRESULT) ThemeCreateParentWindow(
611 DPIU_MONITOR_CONTEXT* pMonitorContext = NULL; 620 DPIU_MONITOR_CONTEXT* pMonitorContext = NULL;
612 POINT pt = { }; 621 POINT pt = { };
613 RECT* pMonitorRect = NULL; 622 RECT* pMonitorRect = NULL;
623 HMENU hMenu = NULL;
614 HWND hWnd = NULL; 624 HWND hWnd = NULL;
615 625
616 if (pTheme->hwndParent) 626 if (pTheme->hwndParent)
@@ -628,11 +638,11 @@ DAPI_(HRESULT) ThemeCreateParentWindow(
628 pMonitorRect = &pMonitorContext->mi.rcWork; 638 pMonitorRect = &pMonitorContext->mi.rcWork;
629 if (pMonitorContext->nDpi != pTheme->nDpi) 639 if (pMonitorContext->nDpi != pTheme->nDpi)
630 { 640 {
631 ScaleTheme(pTheme, pMonitorContext->nDpi, pMonitorRect->left, pMonitorRect->top); 641 ScaleTheme(pTheme, pMonitorContext->nDpi, pMonitorRect->left, pMonitorRect->top, dwStyle, NULL != hMenu, dwExStyle);
632 } 642 }
633 643
634 x = pMonitorRect->left + (pMonitorRect->right - pMonitorRect->left - pTheme->nWidth) / 2; 644 x = pMonitorRect->left + (pMonitorRect->right - pMonitorRect->left - pTheme->nWindowWidth) / 2;
635 y = pMonitorRect->top + (pMonitorRect->bottom - pMonitorRect->top - pTheme->nHeight) / 2; 645 y = pMonitorRect->top + (pMonitorRect->bottom - pMonitorRect->top - pTheme->nWindowHeight) / 2;
636 } 646 }
637 else 647 else
638 { 648 {
@@ -641,7 +651,7 @@ DAPI_(HRESULT) ThemeCreateParentWindow(
641 } 651 }
642 } 652 }
643 653
644 hWnd = ::CreateWindowExW(dwExStyle, szClassName, szWindowName, dwStyle, x, y, pTheme->nWidth, pTheme->nHeight, hwndParent, NULL, hInstance, lpParam); 654 hWnd = ::CreateWindowExW(dwExStyle, szClassName, szWindowName, dwStyle, x, y, pTheme->nWindowWidth, pTheme->nWindowHeight, hwndParent, hMenu, hInstance, lpParam);
645 ThmExitOnNullWithLastError(hWnd, hr, "Failed to create theme parent window."); 655 ThmExitOnNullWithLastError(hWnd, hr, "Failed to create theme parent window.");
646 ThmExitOnNull(pTheme->hwndParent, hr, E_INVALIDSTATE, "Theme parent window is not set, make sure ThemeDefWindowProc is called for WM_NCCREATE."); 656 ThmExitOnNull(pTheme->hwndParent, hr, E_INVALIDSTATE, "Theme parent window is not set, make sure ThemeDefWindowProc is called for WM_NCCREATE.");
647 AssertSz(hWnd == pTheme->hwndParent, "Theme parent window does not equal newly created window."); 657 AssertSz(hWnd == pTheme->hwndParent, "Theme parent window does not equal newly created window.");
@@ -1909,7 +1919,7 @@ static HRESULT ParseWindow(
1909 } 1919 }
1910 ThmExitOnFailure(hr, "Failed to get window Width attribute."); 1920 ThmExitOnFailure(hr, "Failed to get window Width attribute.");
1911 1921
1912 pTheme->nWidth = pTheme->nDefaultDpiWidth = dwValue; 1922 pTheme->nWidth = pTheme->nDefaultDpiWidth = pTheme->nWindowWidth = dwValue;
1913 1923
1914 hr = XmlGetAttributeNumber(pixn, L"Height", &dwValue); 1924 hr = XmlGetAttributeNumber(pixn, L"Height", &dwValue);
1915 if (S_FALSE == hr) 1925 if (S_FALSE == hr)
@@ -1919,7 +1929,7 @@ static HRESULT ParseWindow(
1919 } 1929 }
1920 ThmExitOnFailure(hr, "Failed to get window Height attribute."); 1930 ThmExitOnFailure(hr, "Failed to get window Height attribute.");
1921 1931
1922 pTheme->nHeight = pTheme->nDefaultDpiHeight = dwValue; 1932 pTheme->nHeight = pTheme->nDefaultDpiHeight = pTheme->nWindowHeight = dwValue;
1923 1933
1924 hr = XmlGetAttributeNumber(pixn, L"MinimumWidth", &dwValue); 1934 hr = XmlGetAttributeNumber(pixn, L"MinimumWidth", &dwValue);
1925 if (S_FALSE == hr) 1935 if (S_FALSE == hr)
@@ -4338,7 +4348,7 @@ static BOOL OnDpiChanged(
4338 4348
4339 4349
4340 pTheme->fForceResize = !pTheme->fAutoResize; 4350 pTheme->fForceResize = !pTheme->fAutoResize;
4341 ScaleTheme(pTheme, nDpi, pRect->left, pRect->top); 4351 ScaleThemeFromWindow(pTheme, nDpi, pRect->left, pRect->top);
4342 4352
4343LExit: 4353LExit:
4344 return !fIgnored; 4354 return !fIgnored;
@@ -4359,7 +4369,7 @@ static void OnNcCreate(
4359 4369
4360 if (windowContext.nDpi != pTheme->nDpi) 4370 if (windowContext.nDpi != pTheme->nDpi)
4361 { 4371 {
4362 ScaleTheme(pTheme, windowContext.nDpi, pCreateStruct->x, pCreateStruct->y); 4372 ScaleTheme(pTheme, windowContext.nDpi, pCreateStruct->x, pCreateStruct->y, pCreateStruct->style, NULL != pCreateStruct->hMenu, pCreateStruct->dwExStyle);
4363 } 4373 }
4364} 4374}
4365 4375
@@ -5484,13 +5494,32 @@ static void ResizeControl(
5484 } 5494 }
5485} 5495}
5486 5496
5487static void ScaleTheme( 5497static void ScaleThemeFromWindow(
5488 __in THEME* pTheme, 5498 __in THEME* pTheme,
5489 __in UINT nDpi, 5499 __in UINT nDpi,
5490 __in int x, 5500 __in int x,
5491 __in int y 5501 __in int y
5492 ) 5502 )
5493{ 5503{
5504 DWORD dwStyle = GetWindowStyle(pTheme->hwndParent);
5505 BOOL fMenu = NULL != ::GetMenu(pTheme->hwndParent);
5506 DWORD dwExStyle = GetWindowExStyle(pTheme->hwndParent);
5507
5508 ScaleTheme(pTheme, nDpi, x, y, dwStyle, fMenu, dwExStyle);
5509}
5510
5511static void ScaleTheme(
5512 __in THEME* pTheme,
5513 __in UINT nDpi,
5514 __in int x,
5515 __in int y,
5516 __in DWORD dwStyle,
5517 __in BOOL fMenu,
5518 __in DWORD dwExStyle
5519 )
5520{
5521 RECT rect = { };
5522
5494 pTheme->nDpi = nDpi; 5523 pTheme->nDpi = nDpi;
5495 5524
5496 pTheme->nHeight = DpiuScaleValue(pTheme->nDefaultDpiHeight, pTheme->nDpi); 5525 pTheme->nHeight = DpiuScaleValue(pTheme->nDefaultDpiHeight, pTheme->nDpi);
@@ -5498,11 +5527,19 @@ static void ScaleTheme(
5498 pTheme->nMinimumHeight = DpiuScaleValue(pTheme->nDefaultDpiMinimumHeight, pTheme->nDpi); 5527 pTheme->nMinimumHeight = DpiuScaleValue(pTheme->nDefaultDpiMinimumHeight, pTheme->nDpi);
5499 pTheme->nMinimumWidth = DpiuScaleValue(pTheme->nDefaultDpiMinimumWidth, pTheme->nDpi); 5528 pTheme->nMinimumWidth = DpiuScaleValue(pTheme->nDefaultDpiMinimumWidth, pTheme->nDpi);
5500 5529
5530 rect.left = x;
5531 rect.top = y;
5532 rect.right = x + pTheme->nWidth;
5533 rect.bottom = y + pTheme->nHeight;
5534 DpiuAdjustWindowRect(&rect, dwStyle, fMenu, dwExStyle, pTheme->nDpi);
5535 pTheme->nWindowWidth = rect.right - rect.left;
5536 pTheme->nWindowHeight = rect.bottom - rect.top;
5537
5501 ScaleControls(pTheme, pTheme->cControls, pTheme->rgControls, pTheme->nDpi); 5538 ScaleControls(pTheme, pTheme->cControls, pTheme->rgControls, pTheme->nDpi);
5502 5539
5503 if (pTheme->hwndParent) 5540 if (pTheme->hwndParent)
5504 { 5541 {
5505 ::SetWindowPos(pTheme->hwndParent, NULL, x, y, pTheme->nWidth, pTheme->nHeight, SWP_NOACTIVATE | SWP_NOZORDER); 5542 ::SetWindowPos(pTheme->hwndParent, NULL, x, y, pTheme->nWindowWidth, pTheme->nWindowHeight, SWP_NOACTIVATE | SWP_NOZORDER);
5506 } 5543 }
5507} 5544}
5508 5545