aboutsummaryrefslogtreecommitdiff
path: root/src/dutil/thmutil.cpp
diff options
context:
space:
mode:
authorSean Hall <r.sean.hall@gmail.com>2020-07-06 16:03:23 +1000
committerSean Hall <r.sean.hall@gmail.com>2020-07-06 21:30:49 +1000
commita44cba1e241d0aa7d5c64595e9e7c95d0f06cced (patch)
treea72d182b4d65e7ebd623e04b18ab6db950721cd4 /src/dutil/thmutil.cpp
parente586152b76d62dbf38cd2882819e23eee2e0af7f (diff)
downloadwix-a44cba1e241d0aa7d5c64595e9e7c95d0f06cced.tar.gz
wix-a44cba1e241d0aa7d5c64595e9e7c95d0f06cced.tar.bz2
wix-a44cba1e241d0aa7d5c64595e9e7c95d0f06cced.zip
Start High-DPI support by scaling the parent window according to the DPI.
Diffstat (limited to 'src/dutil/thmutil.cpp')
-rw-r--r--src/dutil/thmutil.cpp90
1 files changed, 82 insertions, 8 deletions
diff --git a/src/dutil/thmutil.cpp b/src/dutil/thmutil.cpp
index 2050b420..4cc149c9 100644
--- a/src/dutil/thmutil.cpp
+++ b/src/dutil/thmutil.cpp
@@ -287,6 +287,11 @@ static BOOL OnButtonClicked(
287 __in HWND hWnd, 287 __in HWND hWnd,
288 __in const THEME_CONTROL* pControl 288 __in const THEME_CONTROL* pControl
289 ); 289 );
290static BOOL OnDpiChanged(
291 __in THEME* pTheme,
292 __in WPARAM wParam,
293 __in LPARAM lParam
294 );
290static void OnNcCreate( 295static void OnNcCreate(
291 __in THEME* pTheme, 296 __in THEME* pTheme,
292 __in HWND hWnd, 297 __in HWND hWnd,
@@ -353,6 +358,12 @@ static void ResizeControl(
353 __in THEME_CONTROL* pControl, 358 __in THEME_CONTROL* pControl,
354 __in const RECT* prcParent 359 __in const RECT* prcParent
355 ); 360 );
361static void ScaleTheme(
362 __in THEME* pTheme,
363 __in UINT nDpi,
364 __in int x,
365 __in int y
366 );
356static void GetControls( 367static void GetControls(
357 __in THEME* pTheme, 368 __in THEME* pTheme,
358 __in_opt THEME_CONTROL* pParentControl, 369 __in_opt THEME_CONTROL* pParentControl,
@@ -380,6 +391,8 @@ DAPI_(HRESULT) ThemeInitialize(
380 HRESULT hr = S_OK; 391 HRESULT hr = S_OK;
381 INITCOMMONCONTROLSEX icex = { }; 392 INITCOMMONCONTROLSEX icex = { };
382 393
394 DpiuInitialize();
395
383 hr = XmlInitialize(); 396 hr = XmlInitialize();
384 ThmExitOnFailure(hr, "Failed to initialize XML."); 397 ThmExitOnFailure(hr, "Failed to initialize XML.");
385 398
@@ -430,6 +443,7 @@ DAPI_(void) ThemeUninitialize()
430 } 443 }
431 444
432 XmlUninitialize(); 445 XmlUninitialize();
446 DpiuUninitialize();
433} 447}
434 448
435 449
@@ -797,10 +811,10 @@ extern "C" LRESULT CALLBACK ThemeDefWindowProc(
797 } 811 }
798 break; 812 break;
799 813
800 case WM_WINDOWPOSCHANGED: 814 case WM_DPICHANGED:
815 if (OnDpiChanged(pTheme, wParam, lParam))
801 { 816 {
802 //WINDOWPOS* pos = reinterpret_cast<LPWINDOWPOS>(lParam); 817 return 0;
803 //ThemeWindowPositionChanged(pTheme, pos);
804 } 818 }
805 break; 819 break;
806 820
@@ -1652,6 +1666,7 @@ static HRESULT ParseTheme(
1652 ThmExitOnNull(pTheme, hr, E_OUTOFMEMORY, "Failed to allocate memory for theme."); 1666 ThmExitOnNull(pTheme, hr, E_OUTOFMEMORY, "Failed to allocate memory for theme.");
1653 1667
1654 pTheme->wId = ++wThemeId; 1668 pTheme->wId = ++wThemeId;
1669 pTheme->nDpi = USER_DEFAULT_SCREEN_DPI;
1655 1670
1656 // Parse the optional background resource image. 1671 // Parse the optional background resource image.
1657 hr = ParseImage(hModule, wzRelativePath, pThemeElement, &pTheme->hImage); 1672 hr = ParseImage(hModule, wzRelativePath, pThemeElement, &pTheme->hImage);
@@ -1816,6 +1831,7 @@ static HRESULT ParseWindow(
1816{ 1831{
1817 HRESULT hr = S_OK; 1832 HRESULT hr = S_OK;
1818 IXMLDOMNode* pixn = NULL; 1833 IXMLDOMNode* pixn = NULL;
1834 DWORD dwValue = 0;
1819 BSTR bstr = NULL; 1835 BSTR bstr = NULL;
1820 LPWSTR sczIconFile = NULL; 1836 LPWSTR sczIconFile = NULL;
1821 1837
@@ -1833,7 +1849,7 @@ static HRESULT ParseWindow(
1833 } 1849 }
1834 ThmExitOnFailure(hr, "Failed to get window AutoResize attribute."); 1850 ThmExitOnFailure(hr, "Failed to get window AutoResize attribute.");
1835 1851
1836 hr = XmlGetAttributeNumber(pixn, L"Width", reinterpret_cast<DWORD*>(&pTheme->nWidth)); 1852 hr = XmlGetAttributeNumber(pixn, L"Width", &dwValue);
1837 if (S_FALSE == hr) 1853 if (S_FALSE == hr)
1838 { 1854 {
1839 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 1855 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
@@ -1841,7 +1857,9 @@ static HRESULT ParseWindow(
1841 } 1857 }
1842 ThmExitOnFailure(hr, "Failed to get window Width attribute."); 1858 ThmExitOnFailure(hr, "Failed to get window Width attribute.");
1843 1859
1844 hr = XmlGetAttributeNumber(pixn, L"Height", reinterpret_cast<DWORD*>(&pTheme->nHeight)); 1860 pTheme->nWidth = pTheme->nDefaultDpiWidth = dwValue;
1861
1862 hr = XmlGetAttributeNumber(pixn, L"Height", &dwValue);
1845 if (S_FALSE == hr) 1863 if (S_FALSE == hr)
1846 { 1864 {
1847 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA); 1865 hr = HRESULT_FROM_WIN32(ERROR_INVALID_DATA);
@@ -1849,20 +1867,28 @@ static HRESULT ParseWindow(
1849 } 1867 }
1850 ThmExitOnFailure(hr, "Failed to get window Height attribute."); 1868 ThmExitOnFailure(hr, "Failed to get window Height attribute.");
1851 1869
1852 hr = XmlGetAttributeNumber(pixn, L"MinimumWidth", reinterpret_cast<DWORD*>(&pTheme->nMinimumWidth)); 1870 pTheme->nHeight = pTheme->nDefaultDpiHeight = dwValue;
1871
1872 hr = XmlGetAttributeNumber(pixn, L"MinimumWidth", &dwValue);
1853 if (S_FALSE == hr) 1873 if (S_FALSE == hr)
1854 { 1874 {
1875 dwValue = 0;
1855 hr = S_OK; 1876 hr = S_OK;
1856 } 1877 }
1857 ThmExitOnFailure(hr, "Failed to get window MinimumWidth attribute."); 1878 ThmExitOnFailure(hr, "Failed to get window MinimumWidth attribute.");
1858 1879
1859 hr = XmlGetAttributeNumber(pixn, L"MinimumHeight", reinterpret_cast<DWORD*>(&pTheme->nMinimumHeight)); 1880 pTheme->nMinimumWidth = pTheme->nDefaultDpiMinimumWidth = dwValue;
1881
1882 hr = XmlGetAttributeNumber(pixn, L"MinimumHeight", &dwValue);
1860 if (S_FALSE == hr) 1883 if (S_FALSE == hr)
1861 { 1884 {
1885 dwValue = 0;
1862 hr = S_OK; 1886 hr = S_OK;
1863 } 1887 }
1864 ThmExitOnFailure(hr, "Failed to get window MinimumHeight attribute."); 1888 ThmExitOnFailure(hr, "Failed to get window MinimumHeight attribute.");
1865 1889
1890 pTheme->nMinimumHeight = pTheme->nDefaultDpiMinimumHeight = dwValue;
1891
1866 hr = XmlGetAttributeNumber(pixn, L"FontId", &pTheme->dwFontId); 1892 hr = XmlGetAttributeNumber(pixn, L"FontId", &pTheme->dwFontId);
1867 if (S_FALSE == hr) 1893 if (S_FALSE == hr)
1868 { 1894 {
@@ -4161,14 +4187,45 @@ static BOOL OnButtonClicked(
4161LExit: 4187LExit:
4162 return fHandled; 4188 return fHandled;
4163} 4189}
4190
4191static BOOL OnDpiChanged(
4192 __in THEME* pTheme,
4193 __in WPARAM wParam,
4194 __in LPARAM lParam
4195 )
4196{
4197 UINT nDpi = HIWORD(wParam);
4198 RECT* pRect = reinterpret_cast<RECT*>(lParam);
4199 BOOL fIgnored = pTheme->nDpi == nDpi;
4200
4201 if (fIgnored)
4202 {
4203 ExitFunction();
4204 }
4205
4206 ScaleTheme(pTheme, nDpi, pRect->left, pRect->top);
4207
4208LExit:
4209 return !fIgnored;
4210}
4164 4211
4165static void OnNcCreate( 4212static void OnNcCreate(
4166 __in THEME* pTheme, 4213 __in THEME* pTheme,
4167 __in HWND hWnd, 4214 __in HWND hWnd,
4168 __in LPARAM /*lParam*/ 4215 __in LPARAM lParam
4169 ) 4216 )
4170{ 4217{
4218 DPIU_WINDOW_CONTEXT windowContext = { };
4219 CREATESTRUCTW* pCreateStruct = reinterpret_cast<CREATESTRUCTW*>(lParam);
4220
4171 pTheme->hwndParent = hWnd; 4221 pTheme->hwndParent = hWnd;
4222
4223 DpiuGetWindowContext(pTheme->hwndParent, &windowContext);
4224
4225 if (windowContext.nDpi != pTheme->nDpi)
4226 {
4227 ScaleTheme(pTheme, windowContext.nDpi, pCreateStruct->x, pCreateStruct->y);
4228 }
4172} 4229}
4173 4230
4174static HRESULT OnRichEditEnLink( 4231static HRESULT OnRichEditEnLink(
@@ -5282,6 +5339,23 @@ static void ResizeControl(
5282 } 5339 }
5283} 5340}
5284 5341
5342static void ScaleTheme(
5343 __in THEME* pTheme,
5344 __in UINT nDpi,
5345 __in int x,
5346 __in int y
5347 )
5348{
5349 pTheme->nDpi = nDpi;
5350
5351 pTheme->nHeight = DpiuScaleValue(pTheme->nDefaultDpiHeight, pTheme->nDpi);
5352 pTheme->nWidth = DpiuScaleValue(pTheme->nDefaultDpiWidth, pTheme->nDpi);
5353 pTheme->nMinimumHeight = DpiuScaleValue(pTheme->nDefaultDpiMinimumHeight, pTheme->nDpi);
5354 pTheme->nMinimumWidth = DpiuScaleValue(pTheme->nDefaultDpiMinimumWidth, pTheme->nDpi);
5355
5356 ::SetWindowPos(pTheme->hwndParent, NULL, x, y, pTheme->nWidth, pTheme->nHeight, SWP_NOACTIVATE | SWP_NOZORDER);
5357}
5358
5285static void UnloadControls( 5359static void UnloadControls(
5286 __in DWORD cControls, 5360 __in DWORD cControls,
5287 __in THEME_CONTROL* rgControls 5361 __in THEME_CONTROL* rgControls