Bug 1334786 - Support multiple text lines for stub installer checkbox labels; r?rstrong draft
authorMatt Howell <mhowell@mozilla.com>
Mon, 30 Jan 2017 10:21:55 -0800
changeset 468110 0a61684a7c0207f8b7e1f23f48689df70897fd0c
parent 468005 f7e1982a2582b14c5885d787b530f879da3a040e
child 543847 c2177a992fd444ed8a05e7b0a87520d174bbbb5a
push id43353
push usermhowell@mozilla.com
push dateMon, 30 Jan 2017 18:22:24 +0000
reviewersrstrong
bugs1334786
milestone54.0a1
Bug 1334786 - Support multiple text lines for stub installer checkbox labels; r?rstrong The bug only mentions the shortcuts checkbox, but the ping checkbox label looks precariously close to also being too long, so I handled it as well. This patch only supports up to two lines of text, and only the shortcuts and ping checkboxes can have multiple lines. Both of those limitations could be lifted without too much trouble, but it doesn't seem necessary for now. MozReview-Commit-ID: 9cm1scfrOY5
browser/installer/windows/nsis/stub.nsi
--- a/browser/installer/windows/nsis/stub.nsi
+++ b/browser/installer/windows/nsis/stub.nsi
@@ -106,16 +106,17 @@ Var DownloadRetryCount
 Var OpenedDownloadPage
 Var DownloadServerIP
 Var PostSigningData
 Var PreviousInstallDir
 Var PreviousInstallArch
 
 Var ControlHeightPX
 Var ControlRightPX
+Var ControlTopAdjustment
 
 ; Uncomment the following to prevent pinging the metrics server when testing
 ; the stub installer
 ;!define STUB_DEBUG
 
 !define StubURLVersion "v7"
 
 ; Successful install exit code
@@ -924,16 +925,17 @@ Function createOptions
   ${If} "$WasOptionsButtonClicked" != "1"
     ${If} "$CanWriteToInstallDir" == "true"
     ${AndIf} "$HasRequiredSpaceAvailable" == "true"
       Abort ; Skip the options page
     ${EndIf}
   ${EndIf}
 
   StrCpy $ExistingTopDir ""
+  StrCpy $ControlTopAdjustment 0
 
   nsDialogs::Create /NOUNLOAD 1018
   Pop $Dialog
   ; Since the text color for controls is set in this Dialog the foreground and
   ; background colors of the Dialog must also be hardcoded.
   SetCtlColors $Dialog ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
 
   ${NSD_CreateLabel} ${OPTIONS_ITEM_EDGE_DU} 25u ${OPTIONS_ITEM_WIDTH_DU} \
@@ -1014,28 +1016,52 @@ Function createOptions
 
   Call UpdateFreeSpaceLabel
 
   ${If} ${AtLeastWin7}
     StrCpy $0 "$(ADD_SC_DESKTOP_TASKBAR)"
   ${Else}
     StrCpy $0 "$(ADD_SC_DESKTOP_QUICKLAUNCHBAR)"
   ${EndIf}
+
+  ; In some locales, this string may be too long to fit on one line.
+  ; In that case, we'll need to give the control two lines worth of height.
+  StrCpy $1 12 ; single line height
+  ${GetTextExtent} $0 $FontNormal $R1 $R2
+  ${If} $R1 > ${OPTIONS_ITEM_WIDTH_DU}
+    ; Add a second line to the control height.
+    IntOp $1 $1 + 12
+    ; The rest of the controls will have to be lower to account for this label
+    ; needing two lines worth of height.
+    IntOp $ControlTopAdjustment $ControlTopAdjustment + 12
+  ${EndIf}
   ${NSD_CreateCheckbox} ${OPTIONS_ITEM_EDGE_DU} 100u \
-                        ${OPTIONS_ITEM_WIDTH_DU} 12u "$0"
+                        ${OPTIONS_ITEM_WIDTH_DU} "$1u" "$0"
   Pop $CheckboxShortcuts
   ; The uxtheme must be disabled on checkboxes in order to override the system
   ; font color.
   System::Call 'uxtheme::SetWindowTheme(i $CheckboxShortcuts, w " ", w " ")'
   SetCtlColors $CheckboxShortcuts ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
   SendMessage $CheckboxShortcuts ${WM_SETFONT} $FontNormal 0
   ${NSD_Check} $CheckboxShortcuts
 
-  ${NSD_CreateCheckbox} ${OPTIONS_ITEM_EDGE_DU} 116u ${OPTIONS_SUBITEM_WIDTH_DU} \
-                        12u "$(SEND_PING)"
+  IntOp $0 116 + $ControlTopAdjustment
+  ; In some locales, this string may be too long to fit on one line.
+  ; In that case, we'll need to give the control two lines worth of height.
+  StrCpy $1 12 ; single line height
+  ${GetTextExtent} "$(SEND_PING)" $FontNormal $R1 $R2
+  ${If} $R1 > ${OPTIONS_ITEM_WIDTH_DU}
+    ; Add a second line to the control height.
+    IntOp $1 $1 + 12
+    ; The rest of the controls will have to be lower to account for this label
+    ; needing two lines worth of height.
+    IntOp $ControlTopAdjustment $ControlTopAdjustment + 12
+  ${EndIf}
+  ${NSD_CreateCheckbox} ${OPTIONS_ITEM_EDGE_DU} "$0u" ${OPTIONS_SUBITEM_WIDTH_DU} \
+                        "$1u" "$(SEND_PING)"
   Pop $CheckboxSendPing
   ; The uxtheme must be disabled on checkboxes in order to override the system
   ; font color.
   System::Call 'uxtheme::SetWindowTheme(i $CheckboxSendPing, w " ", w " ")'
   SetCtlColors $CheckboxSendPing ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
   SendMessage $CheckboxSendPing ${WM_SETFONT} $FontNormal 0
   ${NSD_Check} $CheckboxSendPing
 
@@ -1061,23 +1087,27 @@ Function createOptions
                      "Write Test"
     ${IfNot} ${Errors}
       DeleteRegValue HKLM "Software\Mozilla" "${BrandShortName}InstallerTest"
       ; Read the registry instead of using ServicesHelper::IsInstalled so the
       ; plugin isn't included in the stub installer to lessen its size.
       ClearErrors
       ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\services\MozillaMaintenance" "ImagePath"
       ${If} ${Errors}
-        ${NSD_CreateCheckbox} ${OPTIONS_ITEM_EDGE_DU} 132u ${OPTIONS_ITEM_WIDTH_DU} \
+        IntOp $0 132 + $ControlTopAdjustment
+        ${NSD_CreateCheckbox} ${OPTIONS_ITEM_EDGE_DU} "$0u" ${OPTIONS_ITEM_WIDTH_DU} \
                               12u "$(INSTALL_MAINT_SERVICE)"
         Pop $CheckboxInstallMaintSvc
         System::Call 'uxtheme::SetWindowTheme(i $CheckboxInstallMaintSvc, w " ", w " ")'
         SetCtlColors $CheckboxInstallMaintSvc ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
         SendMessage $CheckboxInstallMaintSvc ${WM_SETFONT} $FontNormal 0
         ${NSD_Check} $CheckboxInstallMaintSvc
+        ; Since we're adding in an optional control, remember the lower the ones
+        ; that come after it.
+        IntOp $ControlTopAdjustment 20 + $ControlTopAdjustment
       ${EndIf}
     ${EndIf}
   ${EndIf}
 !endif
 
   ${If} ${RunningX64}
     ; Get the exact pixel width we're going to need for this label.
     ; The label string has a keyboard accelerator, which is an '&' that's in
@@ -1094,21 +1124,18 @@ Function createOptions
       StrCpy $R4 $R0 1
       ${If} $R4 == "&"
         StrCpy $R1 "$R1&"
         StrCpy $R0 $R0 "" 1
       ${EndIf}
     ${LoopUntil} $R0 == ""
 
     ${GetTextExtent} $R1 $FontNormal $R0 $R1
-    ${If} $CheckboxInstallMaintSvc == "0"
-      ${NSD_CreateLabel} ${OPTIONS_ITEM_EDGE_DU} 134u $R0 $R1 "$(ARCH_DROPLIST_LABEL)"
-    ${Else}
-      ${NSD_CreateLabel} ${OPTIONS_ITEM_EDGE_DU} 154u $R0 $R1 "$(ARCH_DROPLIST_LABEL)"
-    ${EndIf}
+    IntOp $0 134 + $ControlTopAdjustment
+    ${NSD_CreateLabel} ${OPTIONS_ITEM_EDGE_DU} "$0u" $R0 $R1 "$(ARCH_DROPLIST_LABEL)"
     Pop $0
     SetCtlColors $0 ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
     SendMessage $0 ${WM_SETFONT} $FontNormal 0
 
     ; Set the dropdown list size to the same as the larger of the two options.
     ${GetTextExtent} "$(VERSION_32BIT)" $FontNormal $R0 $R1
     ${GetTextExtent} "$(VERSION_64BIT)" $FontNormal $R2 $R3
     ${If} $R0 < $R2
@@ -1121,35 +1148,27 @@ Function createOptions
     ; on he system display scaling setting, which we cannot easily determine,
     ; so just use a value that works fine for a setting of 200% and adds a
     ; little too much padding for settings below that.
     IntOp $R0 $R0 + 56
 
     ; Put the droplist right after the label, with some padding.
     ${GetDlgItemEndPX} $0 $ControlRightPX
     IntOp $ControlRightPX $ControlRightPX + 4
-    ${If} $CheckboxInstallMaintSvc == "0"
-      ${NSD_CreateDropList} $ControlRightPX 132u $R0 $R3 ""
-    ${Else}
-      ${NSD_CreateDropList} $ControlRightPX 152u $R0 $R3 ""
-    ${EndIf}
+    IntOp $0 132 + $ControlTopAdjustment
+    ${NSD_CreateDropList} $ControlRightPX "$0u" $R0 $R3 ""
     Pop $DroplistArch
     ${NSD_CB_AddString} $DroplistArch "$(VERSION_32BIT)"
     ${NSD_CB_AddString} $DroplistArch "$(VERSION_64BIT)"
     ${NSD_OnChange} $DroplistArch OnChange_DroplistArch
     ; The uxtheme must be disabled in order to override the system colors.
     System::Call 'uxtheme::SetWindowTheme(i $DroplistArch, w " ", w " ")'
     SetCtlColors $DroplistArch ${COMMON_TEXT_COLOR_NORMAL} ${COMMON_BKGRD_COLOR}
     SendMessage $DroplistArch ${WM_SETFONT} $FontNormal 0
-
-    ${If} ${RunningX64}
-      ${NSD_CB_SelectString} $DroplistArch "$(VERSION_64BIT)"
-    ${Else}
-      ${NSD_CB_SelectString} $DroplistArch "$(VERSION_32BIT)"
-    ${EndIf}
+    ${NSD_CB_SelectString} $DroplistArch "$(VERSION_64BIT)"
   ${EndIf}
 
   GetDlgItem $0 $HWNDPARENT 1 ; Install button
   ${If} ${FileExists} "$INSTDIR\${FileMainEXE}"
     SendMessage $0 ${WM_SETTEXT} 0 "STR:$(UPGRADE_BUTTON)"
   ${Else}
     SendMessage $0 ${WM_SETTEXT} 0 "STR:$(INSTALL_BUTTON)"
   ${EndIf}