Bug 1548612 Part 4 - Add a macro for converting dialog units to screen pixels. r=agashlin a=jcristau
authorMatt Howell <mhowell@mozilla.com>
Tue, 21 May 2019 16:12:45 +0000
changeset 536458 b1fc004020e57440833c6f3a58a001cf4dde5dff
parent 536457 a8f835eddb73d8f302b30efc97a4005fb43f5b31
child 536459 41b706ab3dac3cb1b2a640fbc29a2624caa1fa9c
push id2082
push userffxbld-merge
push dateMon, 01 Jul 2019 08:34:18 +0000
treeherdermozilla-release@2fb19d0466d2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersagashlin, jcristau
bugs1548612
milestone68.0
Bug 1548612 Part 4 - Add a macro for converting dialog units to screen pixels. r=agashlin a=jcristau We typically want to define sizes of elements in the stub installer in terms of dialog units because those are independent of DPI. But sometimes we need to do some calculations or invoke some API that needs pixels. So this function takes a number of dialog units and an axis (because dialog units are not square) and converts them to screen pixels using MapDialogRect. Depends on D31141 Differential Revision: https://phabricator.services.mozilla.com/D31142
toolkit/mozapps/installer/windows/nsis/common.nsh
--- a/toolkit/mozapps/installer/windows/nsis/common.nsh
+++ b/toolkit/mozapps/installer/windows/nsis/common.nsh
@@ -8346,16 +8346,50 @@ end:
 
     !undef _MOZFUNC_UN
     !define _MOZFUNC_UN
     !verbose pop
   !endif
 !macroend
 
 /**
+ * Convert a number of dialog units to a number of pixels.
+ *
+ * _DU    Number of dialog units to convert
+ * _AXIS  Which axis you want to convert a value along, X or Y
+ * _RV    Register or variable to return the number of pixels in
+ */
+!macro _DialogUnitsToPixels _DU _AXIS _RV
+  Push $0
+  Push $1
+
+  ; The dialog units value might be a string ending with a 'u',
+  ; so convert it to a number.
+  IntOp $0 "${_DU}" + 0
+
+  !if ${_AXIS} == 'Y'
+    System::Call '*(i 0, i 0, i 0, i r0) i .r1'
+    System::Call 'user32::MapDialogRect(p $HWNDPARENT, p r1)'
+    System::Call '*$1(i, i, i, i . r0)'
+  !else if ${_AXIS} == 'X'
+    System::Call '*(i 0, i 0, i r0, i 0) i .r1'
+    System::Call 'user32::MapDialogRect(p $HWNDPARENT, p r1)'
+    System::Call '*$1(i, i, i . r0, i)'
+  !else
+    !error "Invalid axis ${_AXIS} passed to DialogUnitsToPixels; please use X or Y"
+  !endif
+  System::Free $1
+
+  Pop $1
+  Exch $0
+  Pop ${_RV}
+!macroend
+!define DialogUnitsToPixels "!insertmacro _DialogUnitsToPixels"
+
+/**
  * Gets the elapsed time in seconds between two values in milliseconds stored as
  * an int64. The caller will typically get the millisecond values using
  * GetTickCount with a long return value as follows.
  * System::Call "kernel32::GetTickCount()l .s"
  * Pop $varname
  *
  * _START_TICK_COUNT
  * _FINISH_TICK_COUNT