From 0e678d8a9ad33c013a2a6a373c243618393d138f Mon Sep 17 00:00:00 2001 From: Molly Howell Date: Wed, 29 Jan 2020 17:35:44 +0000 Subject: [PATCH] Bug 1515534 - Use nicer scaling for full installer images. r=agashlin This patch uses the `SetStretchedImageOLE` function that was developed for the stub installer background image and landed in bug 1337856 part 1 to also provide nicer scaling for the bitmap controls in the full installer dialogs, instead of GDI's default which produces undesirably jagged curved edges. Differential Revision: https://phabricator.services.mozilla.com/D61135 --HG-- extra : moz-landing-system : lando --- browser/installer/windows/nsis/installer.nsi | 12 ++- .../installer/windows/nsis/uninstaller.nsi | 12 ++- .../mozapps/installer/windows/nsis/common.nsh | 85 ++++++++++++++++++- 3 files changed, 102 insertions(+), 7 deletions(-) diff --git a/browser/installer/windows/nsis/installer.nsi b/browser/installer/windows/nsis/installer.nsi index 894f84156608..ecff93e41c85 100755 --- a/browser/installer/windows/nsis/installer.nsi +++ b/browser/installer/windows/nsis/installer.nsi @@ -93,6 +93,7 @@ VIAddVersionKey "OriginalFilename" "setup.exe" !insertmacro AddDisabledDDEHandlerValues !insertmacro ChangeMUIHeaderImage +!insertmacro ChangeMUISidebarImage !insertmacro CheckForFilesInUse !insertmacro CleanUpdateDirectories !insertmacro CopyFilesFromDir @@ -1179,6 +1180,10 @@ Function showWelcome SetCtlColors $0 SYSCLR:WINDOWTEXT SYSCLR:WINDOW ReadINIStr $0 "$PLUGINSDIR\ioSpecial.ini" "Field 3" "HWND" SetCtlColors $0 SYSCLR:WINDOWTEXT SYSCLR:WINDOW + + ; We need to overwrite the sidebar image so that we get it drawn with proper + ; scaling if the display is scaled at anything above 100%. + ${ChangeMUISidebarImage} "$PLUGINSDIR\modern-wizard.bmp" FunctionEnd Function leaveWelcome @@ -1200,11 +1205,10 @@ Function preOptions StrCpy $PageName "Options" ${If} ${FileExists} "$EXEDIR\core\distribution\modern-header.bmp" - ${AndIf} $hHeaderBitmap == "" Delete "$PLUGINSDIR\modern-header.bmp" CopyFiles /SILENT "$EXEDIR\core\distribution\modern-header.bmp" "$PLUGINSDIR\modern-header.bmp" - ${ChangeMUIHeaderImage} "$PLUGINSDIR\modern-header.bmp" ${EndIf} + ${ChangeMUIHeaderImage} "$PLUGINSDIR\modern-header.bmp" !insertmacro MUI_HEADER_TEXT "$(OPTIONS_PAGE_TITLE)" "$(OPTIONS_PAGE_SUBTITLE)" !insertmacro MUI_INSTALLOPTIONS_DISPLAY "options.ini" FunctionEnd @@ -1563,6 +1567,10 @@ Function showFinish ReadINIStr $0 "$PLUGINSDIR\ioSpecial.ini" "Field 3" "HWND" SetCtlColors $0 SYSCLR:WINDOWTEXT SYSCLR:WINDOW + ; We need to overwrite the sidebar image so that we get it drawn with proper + ; scaling if the display is scaled at anything above 100%. + ${ChangeMUISidebarImage} "$PLUGINSDIR\modern-wizard.bmp" + ; Field 4 is the launch checkbox. Since it's a checkbox, we need to ; clear the theme from it before we can set its background color. ReadINIStr $0 "$PLUGINSDIR\ioSpecial.ini" "Field 4" "HWND" diff --git a/browser/installer/windows/nsis/uninstaller.nsi b/browser/installer/windows/nsis/uninstaller.nsi index 4812e91279de..e945c48d2fc2 100755 --- a/browser/installer/windows/nsis/uninstaller.nsi +++ b/browser/installer/windows/nsis/uninstaller.nsi @@ -99,6 +99,7 @@ VIAddVersionKey "OriginalFilename" "helper.exe" !insertmacro GetInstallerRegistryPref !insertmacro un.ChangeMUIHeaderImage +!insertmacro un.ChangeMUISidebarImage !insertmacro un.CheckForFilesInUse !insertmacro un.CleanUpdateDirectories !insertmacro un.CleanVirtualStore @@ -580,6 +581,10 @@ Function un.ShowWelcome ReadINIStr $0 "$PLUGINSDIR\ioSpecial.ini" "Field 3" "HWND" SetCtlColors $0 SYSCLR:WINDOWTEXT SYSCLR:WINDOW + + ; We need to overwrite the sidebar image so that we get it drawn with proper + ; scaling if the display is scaled at anything above 100%. + ${un.ChangeMUISidebarImage} "$PLUGINSDIR\modern-wizard.bmp" FunctionEnd Function un.leaveWelcome @@ -625,11 +630,10 @@ Function un.preConfirm SetCtlColors $0 SYSCLR:WINDOWTEXT SYSCLR:WINDOW ${If} ${FileExists} "$INSTDIR\distribution\modern-header.bmp" - ${AndIf} $hHeaderBitmap == "" Delete "$PLUGINSDIR\modern-header.bmp" CopyFiles /SILENT "$INSTDIR\distribution\modern-header.bmp" "$PLUGINSDIR\modern-header.bmp" - ${un.ChangeMUIHeaderImage} "$PLUGINSDIR\modern-header.bmp" ${EndIf} + ${un.ChangeMUIHeaderImage} "$PLUGINSDIR\modern-header.bmp" ; Setup the unconfirm.ini file for the Custom Uninstall Confirm Page WriteINIStr "$PLUGINSDIR\unconfirm.ini" "Settings" NumFields "3" @@ -705,6 +709,10 @@ Function un.ShowFinish ReadINIStr $0 "$PLUGINSDIR\ioSpecial.ini" "Field 3" "HWND" SetCtlColors $0 SYSCLR:WINDOWTEXT SYSCLR:WINDOW + ; We need to overwrite the sidebar image so that we get it drawn with proper + ; scaling if the display is scaled at anything above 100%. + ${un.ChangeMUISidebarImage} "$PLUGINSDIR\modern-wizard.bmp" + ; Either Fields 4 and 5 are the reboot option radio buttons, or Field 4 is ; the survey checkbox and Field 5 doesn't exist. Either way, we need to ; clear the theme from them before we can set their background colors. diff --git a/toolkit/mozapps/installer/windows/nsis/common.nsh b/toolkit/mozapps/installer/windows/nsis/common.nsh index 5eb40f388185..e13820fc7954 100755 --- a/toolkit/mozapps/installer/windows/nsis/common.nsh +++ b/toolkit/mozapps/installer/windows/nsis/common.nsh @@ -5251,9 +5251,7 @@ end: Push $R8 GetDlgItem $R8 $HWNDPARENT 1046 - System::Call 'user32::LoadImageW(i 0, w "$R9", i 0, i 0, i 0, i 0x0010|0x2000) i.s' - Pop $hHeaderBitmap - SendMessage $R8 ${STM_SETIMAGE} 0 $hHeaderBitmap + ${SetStretchedImageOLE} $R8 "$R9" $hHeaderBitmap ; There is no way to specify a show function for a custom page so hide ; and then show the control to force the bitmap to redraw. ShowWindow $R8 ${SW_HIDE} @@ -5298,6 +5296,77 @@ end: !endif !macroend +/** + * Replaces the sidebar image on the wizard's welcome and finish pages. + * + * @param _PATH_TO_IMAGE + * Fully qualified path to the bitmap to use for the header image. + * + * $R8 = hwnd for the bitmap control + * $R9 = _PATH_TO_IMAGE + */ +!macro ChangeMUISidebarImage + + !ifndef ${_MOZFUNC_UN}ChangeMUISidebarImage + Var hSidebarBitmap + + !verbose push + !verbose ${_MOZFUNC_VERBOSE} + !define ${_MOZFUNC_UN}ChangeMUISidebarImage "!insertmacro ${_MOZFUNC_UN}ChangeMUISidebarImageCall" + + Function ${_MOZFUNC_UN}ChangeMUISidebarImage + Exch $R9 + Push $R8 + + ; Make sure we're not about to leak an existing handle. + ${If} $hSidebarBitmap <> 0 + System::Call "gdi32::DeleteObject(p $hSidebarBitmap)" + StrCpy $hSidebarBitmap 0 + ${EndIf} + ; The controls on the welcome and finish pages aren't in the dialog + ; template, they're always created manually from the INI file, so we need + ; to query it to find the right HWND. + ReadINIStr $R8 "$PLUGINSDIR\ioSpecial.ini" "Field 1" "HWND" + ${SetStretchedImageOLE} $R8 "$R9" $hSidebarBitmap + + Pop $R8 + Exch $R9 + FunctionEnd + + !verbose pop + !endif +!macroend + +!macro ChangeMUISidebarImageCall _PATH_TO_IMAGE + !verbose push + !verbose ${_MOZFUNC_VERBOSE} + Push "${_PATH_TO_IMAGE}" + Call ChangeMUISidebarImage + !verbose pop +!macroend + +!macro un.ChangeMUISidebarImageCall _PATH_TO_IMAGE + !verbose push + !verbose ${_MOZFUNC_VERBOSE} + Push "${_PATH_TO_IMAGE}" + Call un.ChangeMUISidebarImage + !verbose pop +!macroend + +!macro un.ChangeMUISidebarImage + !ifndef un.ChangeMUISidebarImage + !verbose push + !verbose ${_MOZFUNC_VERBOSE} + !undef _MOZFUNC_UN + !define _MOZFUNC_UN "un." + + !insertmacro ChangeMUISidebarImage + + !undef _MOZFUNC_UN + !define _MOZFUNC_UN + !verbose pop + !endif +!macroend ################################################################################ # User interface callback helper defines and macros @@ -5364,6 +5433,13 @@ end: StrCmp $hHeaderBitmap "" +3 +1 System::Call "gdi32::DeleteObject(i s)" $hHeaderBitmap StrCpy $hHeaderBitmap "" + ; If ChangeMUISidebarImage was called, then we also need to clean up the + ; GDI bitmap handle that it would have created. + !ifdef ${_MOZFUNC_UN}ChangeMUISidebarImage + StrCmp $hSidebarBitmap "" +3 +1 + System::Call "gdi32::DeleteObject(i s)" $hSidebarBitmap + StrCpy $hSidebarBitmap "" + !endif System::Free 0 @@ -7996,6 +8072,9 @@ end: !ifndef HALFTONE !define HALFTONE 4 !endif + !ifndef IMAGE_BITMAP + !define IMAGE_BITMAP 0 + !endif Push $0 ; HANDLE Push $1 ; memory DC