From d344cef35f7fb054bc2975351cbf8daedff7f0b4 Mon Sep 17 00:00:00 2001 From: Valentin Radu Date: Mon, 21 Feb 2022 17:47:45 +0200 Subject: [PATCH] Weather: Option to limit width of the widget --- ExplorerPatcher/dllmain.c | 30 +++++++++++++++++++++++------- ExplorerPatcher/settings.reg | 5 +++-- ExplorerPatcher/settings10.reg | 5 +++-- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/ExplorerPatcher/dllmain.c b/ExplorerPatcher/dllmain.c index 8907845..e07ead5 100644 --- a/ExplorerPatcher/dllmain.c +++ b/ExplorerPatcher/dllmain.c @@ -3806,7 +3806,7 @@ void stub1(void* i) } HWND PeopleButton_LastHWND = NULL; - +#define WEATHER_FIXEDSIZE2_MAXWIDTH 192 BOOL explorer_DeleteMenu(HMENU hMenu, UINT uPosition, UINT uFlags) { if (uPosition == 621 && uFlags == 0) // when removing News and interests @@ -3895,6 +3895,7 @@ void RecomputeWeatherFlyoutLocation(HWND hWnd) } int prev_total_h = 0; +BOOL people_has_ellipsed = FALSE; SIZE (*PeopleButton_CalculateMinimumSizeFunc)(void*, SIZE*); SIZE WINAPI PeopleButton_CalculateMinimumSizeHook(void* _this, SIZE* pSz) { @@ -3902,7 +3903,7 @@ SIZE WINAPI PeopleButton_CalculateMinimumSizeHook(void* _this, SIZE* pSz) AcquireSRWLockShared(&lock_epw); if (epw) { - if (bWeatherFixedSize) + if (bWeatherFixedSize == 1) { int mul = 1; switch (dwWeatherViewMode) @@ -4041,7 +4042,7 @@ int PeopleBand_MulDivHook(int nNumber, int nNumerator, int nDenominator) AcquireSRWLockShared(&lock_epw); if (epw) { - if (bWeatherFixedSize) + if (bWeatherFixedSize == 1) { int mul = 1; switch (dwWeatherViewMode) @@ -4120,6 +4121,8 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( AcquireSRWLockShared(&lock_epw); if (a5 == 0x21 && epw) { + people_has_ellipsed = FALSE; + BOOL bUseCachedData = InSendMessage(); BOOL bIsThemeActive = TRUE; if (!IsThemeActive() || IsHighContrast()) @@ -4319,12 +4322,13 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( } int margin_v = (a4->bottom - rt) / 2; int total_h = (bIsIconMode ? ((margin_h - p) + rt + (margin_h - p)) : margin_h) + addend; - if (bWeatherFixedSize) + if (bWeatherFixedSize == 1) { if (total_h > a4->right) { int diff = total_h - a4->right; rcText2.right -= diff - 2; + people_has_ellipsed = TRUE; switch (dwWeatherViewMode) { case EP_WEATHER_VIEW_ICONTEXT: @@ -4343,10 +4347,17 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( } } int start_x = 0; // prev_total_h - total_h; - if (bWeatherFixedSize) + if (bWeatherFixedSize == 1) { start_x = (a4->right - total_h) / 2; } + if (bWeatherFixedSize == 2 && (total_h > MulDiv(192, dpiX, 96))) + { + int diff = total_h - MulDiv(WEATHER_FIXEDSIZE2_MAXWIDTH, dpiX, 96); + rcText2.right -= diff - 2; + total_h = MulDiv(WEATHER_FIXEDSIZE2_MAXWIDTH, dpiX, 96); + people_has_ellipsed = TRUE; + } HBITMAP hBitmap = NULL, hOldBitmap = NULL; void* pvBits = NULL; @@ -4432,7 +4443,7 @@ __int64 __fastcall PeopleBand_DrawTextWithGlowHook( } } - if (bWeatherFixedSize) + if (bWeatherFixedSize == 1) { } @@ -4525,7 +4536,12 @@ void WINAPI PeopleButton_ShowTooltipHook(__int64 _this, unsigned __int8 bShow) { WCHAR wszBuffer[MAX_PATH]; ZeroMemory(wszBuffer, sizeof(WCHAR) * MAX_PATH); - epw->lpVtbl->GetTitle(epw, sizeof(WCHAR) * MAX_PATH, wszBuffer, dwWeatherViewMode); + DWORD mode = dwWeatherViewMode; + if (bWeatherFixedSize && people_has_ellipsed) + { + mode = EP_WEATHER_VIEW_ICONTEMP; + } + epw->lpVtbl->GetTitle(epw, sizeof(WCHAR) * MAX_PATH, wszBuffer, mode); if (wcsstr(wszBuffer, L"(null)")) { HMODULE hModule = GetModuleHandleW(L"pnidui.dll"); diff --git a/ExplorerPatcher/settings.reg b/ExplorerPatcher/settings.reg index 0d8ff04..5fad909 100644 --- a/ExplorerPatcher/settings.reg +++ b/ExplorerPatcher/settings.reg @@ -370,8 +370,9 @@ ;x 4 Temperature only ;x 5 Temperature and description "WeatherViewMode"=dword:00000000 -;c 2 Widget size -;x 0 Enlarge/shrink to fit contents (default) +;c 3 Widget size +;x 0 Automatic (fit contents) (default) +;x 2 Automatic (fit contents) with threshold ;x 1 Fixed "WeatherFixedSize"=dword:00000000 ;c 7 Update frequency diff --git a/ExplorerPatcher/settings10.reg b/ExplorerPatcher/settings10.reg index 14429bd..d99479d 100644 --- a/ExplorerPatcher/settings10.reg +++ b/ExplorerPatcher/settings10.reg @@ -313,8 +313,9 @@ ;x 4 Temperature only ;x 5 Temperature and description "WeatherViewMode"=dword:00000000 -;c 2 Widget size -;x 0 Enlarge/shrink to fit contents (default) +;c 3 Widget size +;x 0 Automatic (fit contents) (default) +;x 2 Automatic (fit contents) with threshold ;x 1 Fixed "WeatherFixedSize"=dword:00000000 ;c 7 Update frequency