Pages.nsh 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /*
  2. NSIS Modern User Interface
  3. Support code for all pages
  4. */
  5. ;--------------------------------
  6. ;Page initialization
  7. !macro MUI_PAGE_INIT
  8. !ifdef MUI_INSERT
  9. !warning "MUI_PAGE_* inserted after MUI_LANGUAGE"
  10. !endif
  11. ;Include interface settings in neccesary
  12. !insertmacro MUI_INTERFACE
  13. ;Define settings for installer page
  14. !insertmacro MUI_UNSET MUI_PAGE_UNINSTALLER
  15. !insertmacro MUI_UNSET MUI_PAGE_UNINSTALLER_PREFIX
  16. !insertmacro MUI_UNSET MUI_PAGE_UNINSTALLER_FUNCPREFIX
  17. !insertmacro MUI_SET MUI_PAGE_UNINSTALLER_PREFIX ""
  18. !insertmacro MUI_SET MUI_PAGE_UNINSTALLER_FUNCPREFIX ""
  19. ;Generate unique ID
  20. !insertmacro MUI_UNSET MUI_UNIQUEID
  21. !define MUI_UNIQUEID ${__LINE__}
  22. !macroend
  23. !macro MUI_UNPAGE_INIT
  24. !ifdef MUI_INSERT
  25. !warning "MUI_UNPAGE_* inserted after MUI_LANGUAGE"
  26. !endif
  27. ;Include interface settings
  28. !insertmacro MUI_INTERFACE
  29. ;Define prefixes for uninstaller page
  30. !insertmacro MUI_SET MUI_UNINSTALLER ""
  31. !insertmacro MUI_SET MUI_PAGE_UNINSTALLER ""
  32. !insertmacro MUI_SET MUI_PAGE_UNINSTALLER_PREFIX "UN"
  33. !insertmacro MUI_SET MUI_PAGE_UNINSTALLER_FUNCPREFIX "un."
  34. ;Generate unique ID
  35. !insertmacro MUI_UNSET MUI_UNIQUEID
  36. !define MUI_UNIQUEID ${__LINE__}
  37. !macroend
  38. ;--------------------------------
  39. ;Header text for standard MUI page
  40. !macro MUI_HEADER_TEXT_PAGE TEXT SUBTEXT
  41. !ifdef MUI_PAGE_HEADER_TEXT & MUI_PAGE_HEADER_SUBTEXT
  42. !insertmacro MUI_HEADER_TEXT "${MUI_PAGE_HEADER_TEXT}" "${MUI_PAGE_HEADER_SUBTEXT}"
  43. !else ifdef MUI_PAGE_HEADER_TEXT
  44. !insertmacro MUI_HEADER_TEXT "${MUI_PAGE_HEADER_TEXT}" "${SUBTEXT}"
  45. !else ifdef MUI_PAGE_HEADER_SUBTEXT
  46. !insertmacro MUI_HEADER_TEXT "${TEXT}" "${MUI_PAGE_HEADER_SUBTEXT}"
  47. !else
  48. !insertmacro MUI_HEADER_TEXT "${TEXT}" "${SUBTEXT}"
  49. !endif
  50. !insertmacro MUI_UNSET MUI_PAGE_HEADER_TEXT
  51. !insertmacro MUI_UNSET MUI_PAGE_HEADER_SUBTEXT
  52. !macroend
  53. ;--------------------------------
  54. ;Header text for custom page
  55. !macro MUI_HEADER_TEXT TEXT SUBTEXT ;Called from script
  56. !verbose push
  57. !verbose ${MUI_VERBOSE}
  58. !ifdef MUI_HEADER_TRANSPARENT_TEXT
  59. LockWindow on
  60. !endif
  61. SendMessage $mui.Header.Text ${WM_SETTEXT} 0 "STR:${TEXT}"
  62. SendMessage $mui.Header.SubText ${WM_SETTEXT} 0 "STR:${SUBTEXT}"
  63. !ifdef MUI_HEADER_TRANSPARENT_TEXT
  64. LockWindow off
  65. !endif
  66. !verbose pop
  67. !macroend
  68. ;--------------------------------
  69. ;Custom page functions
  70. !macro MUI_PAGE_FUNCTION_CUSTOM TYPE
  71. !ifdef MUI_PAGE_CUSTOMFUNCTION_${TYPE}
  72. Call "${MUI_PAGE_CUSTOMFUNCTION_${TYPE}}"
  73. !undef MUI_PAGE_CUSTOMFUNCTION_${TYPE}
  74. !endif
  75. !macroend
  76. ;--------------------------------
  77. ;Support for full window pages (like welcome/finish page)
  78. !macro MUI_PAGE_FUNCTION_FULLWINDOW
  79. !ifndef MUI_${MUI_PAGE_UNINSTALLER_PREFIX}PAGE_FUNCTION_FULLWINDOW
  80. !define MUI_${MUI_PAGE_UNINSTALLER_PREFIX}PAGE_FUNCTION_FULLWINDOW
  81. Function ${MUI_PAGE_UNINSTALLER_FUNCPREFIX}muiPageLoadFullWindow
  82. LockWindow on
  83. ;The branding text needs to be hidden because the full windows page
  84. ;overlaps with it.
  85. ShowWindow $mui.Branding.Background ${SW_HIDE}
  86. ShowWindow $mui.Branding.Text ${SW_HIDE}
  87. ;The texts need to be hidden because otherwise they may show through
  88. ;the page above when the Alt key is pressed.
  89. ShowWindow $mui.Header.Text ${SW_HIDE}
  90. ShowWindow $mui.Header.SubText ${SW_HIDE}
  91. ShowWindow $mui.Header.Image ${SW_HIDE}
  92. ;Show line below full width of page
  93. ShowWindow $mui.Line.Standard ${SW_HIDE}
  94. ShowWindow $mui.Line.FullWindow ${SW_NORMAL}
  95. LockWindow off
  96. FunctionEnd
  97. Function ${MUI_PAGE_UNINSTALLER_FUNCPREFIX}muiPageUnloadFullWindow
  98. ;Set everything back to normal again
  99. LockWindow on
  100. ShowWindow $mui.Branding.Background ${SW_NORMAL}
  101. ShowWindow $mui.Branding.Text ${SW_NORMAL}
  102. ShowWindow $mui.Header.Text ${SW_NORMAL}
  103. ShowWindow $mui.Header.SubText ${SW_NORMAL}
  104. ShowWindow $mui.Header.Image ${SW_NORMAL}
  105. ShowWindow $mui.Line.Standard ${SW_NORMAL}
  106. ShowWindow $mui.Line.FullWindow ${SW_HIDE}
  107. LockWindow off
  108. FunctionEnd
  109. !endif
  110. !macroend
  111. !macro MUI_INTERNAL_FULLWINDOW_LOADWIZARDIMAGE _un _hwndImg _ImgPath _RetImgHandle
  112. !ifdef MUI_${_un}WELCOMEFINISHPAGE_BITMAP_NOSTRETCH
  113. !insertmacro MUI_DEFAULT MUI_${_un}WELCOMEFINISHPAGE_BITMAP_STRETCH NoStretchNoCropNoAlign ; Legacy compatibility
  114. !endif
  115. !insertmacro MUI_DEFAULT MUI_${_un}WELCOMEFINISHPAGE_BITMAP_STRETCH FitControl
  116. !if "${MUI_${_un}WELCOMEFINISHPAGE_BITMAP_STRETCH}" == "NoStretchNoCropNoAlign"
  117. ${NSD_SetImage} ${_hwndImg} "${_ImgPath}" "${_RetImgHandle}"
  118. !else if "${MUI_${_un}WELCOMEFINISHPAGE_BITMAP_STRETCH}" == "NoStretchNoCrop"
  119. !insertmacro MUI_LOADANDXALIGNIMAGE ${_hwndImg} "${_ImgPath}" Auto "${_RetImgHandle}"
  120. !else if "${MUI_${_un}WELCOMEFINISHPAGE_BITMAP_STRETCH}" == "AspectFitHeight"
  121. !insertmacro MUI_LOADANDASPECTSTRETCHIMAGETOCONTROLHEIGHT ${_hwndImg} "${_ImgPath}" Auto "${_RetImgHandle}"
  122. !else
  123. !if "${MUI_${_un}WELCOMEFINISHPAGE_BITMAP_STRETCH}" != "FitControl"
  124. !warning 'MUI_${_un}WELCOMEFINISHPAGE_BITMAP_STRETCH set to unknown value, defaulting to FitControl'
  125. !endif
  126. ${NSD_SetStretchedImage} ${_hwndImg} "${_ImgPath}" "${_RetImgHandle}"
  127. !endif
  128. !macroend
  129. ;--------------------------------
  130. ;Helper macros
  131. !include Util.nsh
  132. !macro MUI_INTERNAL_LOADANDSIZEIMAGE _macro _hwndImg _ImgPath _XAlign _RetImgHandle
  133. !if "${_XAlign}" == "Auto"
  134. ${if} $(^RTL) == 1
  135. Push "*${_ImgPath}"
  136. ${Else}
  137. Push "${_ImgPath}"
  138. ${EndIf}
  139. !else if "${_XAlign}" == "Right"
  140. Push "*${_ImgPath}"
  141. !else
  142. Push "${_ImgPath}"
  143. !endif
  144. Push "${_hwndImg}"
  145. ${CallArtificialFunction} ${_macro}
  146. !if "${_RetImgHandle}" == "Leak"
  147. !insertmacro _LOGICLIB_TEMP
  148. Pop $_LOGICLIB_TEMP
  149. !else if "${_RetImgHandle}" != "Stack"
  150. Pop ${_RetImgHandle}
  151. !endif
  152. !macroend
  153. !macro MUI_LOADANDXALIGNIMAGE _hwndImg _ImgPath _XAlign _RetImgHandle
  154. !insertmacro MUI_INTERNAL_LOADANDSIZEIMAGE \
  155. MUI_INTERNAL_LOADANDXALIGNIMAGE "${_hwndImg}" "${_ImgPath}" "${_XAlign}" "${_RetImgHandle}"
  156. !macroend
  157. !macro MUI_INTERNAL_LOADANDXALIGNIMAGE
  158. System::Store "S"
  159. System::Call 'USER32::GetWindowRect(psr0,@r1)'
  160. System::Call 'USER32::MapWindowPoints(p0,p$hwndparent,pr1,i2)' ; Note: Assuming control is not in inner dialog
  161. System::Call '*$1(i.r5,i.r6,i.r7,i.r8)'
  162. IntOp $7 $7 - $5
  163. IntOp $8 $8 - $6
  164. Pop $1
  165. StrCpy $3 $1 1
  166. ${If} $3 == "*" ; Move control to the right?
  167. StrCpy $1 $1 "" 1
  168. ${Endif}
  169. System::Call 'USER32::LoadImage(p0,tr1,i${IMAGE_BITMAP},i0,i0,i${LR_LOADFROMFILE})p.r2'
  170. SendMessage $0 ${STM_SETIMAGE} ${IMAGE_BITMAP} $2 $1
  171. Push $2 ; Return value
  172. System::Call 'GDI32::DeleteObject(pr1)' ; Note: Assuming the previous image (if any) was a bitmap
  173. System::Call 'USER32::GetClientRect(pr0,@r1)'
  174. System::Call '*$1(i,i,i.r1,i.r2)'
  175. ${If} $3 == "*"
  176. ${AndIf} $1 < $7 ; ImgW < CtlW
  177. IntOp $3 $7 - $1
  178. IntOp $5 $5 + $3
  179. System::Call 'USER32::SetWindowPos(pr0,p0,ir5,ir6,i,i,i0x15)'
  180. ${EndIf}
  181. System::Store "L"
  182. !macroend
  183. !macro MUI_LOADANDASPECTSTRETCHIMAGETOCONTROLHEIGHT _hwndImg _ImgPath _XAlign _RetImgHandle
  184. !insertmacro MUI_INTERNAL_LOADANDSIZEIMAGE \
  185. MUI_INTERNAL_LOADANDASPECTSTRETCHIMAGETOCONTROLHEIGHT "${_hwndImg}" "${_ImgPath}" "${_XAlign}" "${_RetImgHandle}"
  186. !macroend
  187. !macro MUI_INTERNAL_LOADANDASPECTSTRETCHIMAGETOCONTROLHEIGHT
  188. System::Store "S"
  189. System::Call 'USER32::GetWindowRect(psr0,@r1)'
  190. System::Call 'USER32::MapWindowPoints(p0,p$hwndparent,pr1,i2)' ; Note: Assuming control is not in inner dialog
  191. System::Call '*$1(i.r5,i.r6,i.r7,i.r8)'
  192. IntOp $7 $7 - $5
  193. IntOp $8 $8 - $6
  194. Pop $1
  195. StrCpy $3 $1 1
  196. ${If} $3 == "*" ; Move control to the right?
  197. StrCpy $1 $1 "" 1
  198. ${Endif}
  199. System::Call 'USER32::LoadImage(p0,tr1,i${IMAGE_BITMAP},i0,i0,i${LR_LOADFROMFILE})p.r2'
  200. SendMessage $0 ${STM_SETIMAGE} ${IMAGE_BITMAP} $2 $1
  201. Push $2 ; Return value
  202. System::Call 'GDI32::DeleteObject(pr1)' ; Note: Assuming the previous image (if any) was a bitmap
  203. System::Call 'USER32::GetClientRect(pr0,@r1)'
  204. System::Call '*$1(i,i,i.r1,i.r2)'
  205. IntOp $R7 $7 * 10000
  206. IntOp $R8 $8 * 10000
  207. IntOp $R1 $1 * 10000
  208. IntOp $R2 $2 * 10000
  209. IntOp $R3 $R1 / $2
  210. StrCpy $R4 10000
  211. ${If} $R1 > $R2
  212. StrCpy $R3 10000
  213. IntOp $R4 $R2 / $1
  214. ${EndIf}
  215. ${DoWhile} $R2 > $R8 ; ImgH > CtlH
  216. IntOp $R1 $R1 - $R3
  217. IntOp $R2 $R2 - $R4
  218. ${Loop}
  219. ${DoWhile} $R2 < $R8 ; ImgH < CtlH
  220. IntOp $R1 $R1 + $R3
  221. IntOp $R2 $R2 + $R4
  222. ${Loop}
  223. IntOp $1 $R1 / 10000
  224. IntOp $2 $R2 / 10000
  225. ${If} $1 < $7
  226. ${AndIf} $3 == "*"
  227. IntOp $R3 $7 - $1
  228. IntOp $5 $5 + $R3
  229. ${EndIf}
  230. ${DoWhile} $2 > $8 ; Non-aspect-maintained stretch to make it a pixel perfect match
  231. IntOp $2 $2 - 1
  232. IntOp $1 $1 - 1
  233. ${IfThen} $3 == "*" ${|} IntOp $5 $5 + 1 ${|}
  234. ${Loop}
  235. System::Call 'USER32::SetWindowPos(pr0,p0,ir5,ir6,ir1,ir2,i0x14)'
  236. System::Store "L"
  237. !macroend