textRect.nsh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. !ifndef NULLSOFT_NX_TEXT_RECT_NSIS_HEADER
  2. !define NULLSOFT_NX_TEXT_RECT_NSIS_HEADER
  3. !include "util.nsh"
  4. !include "logicLib.nsh"
  5. !include "system.nsh"
  6. !macro NX_CalculateTextRectInternal
  7. !define hwnd_ $R0
  8. !define text_ $R1
  9. !define style_ $R2
  10. !define maxWidth_ $R3
  11. !define hdc_ $R4
  12. !define font_ $R5
  13. !define previousFont_ $R6
  14. !define width_ $R7
  15. !define height_ $R8
  16. !define averageCharWidth_ $R9
  17. Exch ${hwnd_}
  18. Exch 1
  19. Exch ${text_}
  20. Exch 2
  21. Exch ${style_}
  22. Exch 3
  23. Exch ${maxWidth_}
  24. Push ${hdc_}
  25. Push ${font_}
  26. Push ${previousFont_}
  27. Push ${width_}
  28. Push ${height_}
  29. Push ${averageCharWidth_}
  30. StrCpy ${width_} 0
  31. StrCpy ${height_} 0
  32. StrCpy ${averageCharWidth_} 0
  33. System::Call "${fnGetDCEx}(${hwnd_}, 0, ${DCX_CACHE}|${DCX_NORESETATTRS}).s"
  34. Pop ${hdc_}
  35. SendMessage ${hwnd_} ${WM_GETFONT} 0 0 ${font_}
  36. System::Call "${fnSelectObject}(${hdc_}, ${font_}).s"
  37. Pop ${previousFont_}
  38. ; Get Text Metrics (in case of empty line)
  39. Push $0
  40. Push $1
  41. System::Call "*${stTEXTMETRIC} .r1"
  42. System::Call "${fnGetTextMetrics}(${hdc_}, $1).r0"
  43. ${If} $0 != 0
  44. Push $2
  45. System::Call "*$1${stTEXTMETRIC}(.r0, ., ., ., ., .r2, _)"
  46. StrCpy ${height_} $0
  47. StrCpy ${averageCharWidth_} $2
  48. Pop $2
  49. ${EndIf}
  50. System::Free $1
  51. Pop $1
  52. Pop $0
  53. ; Calculate Text Rect
  54. Push $0
  55. StrLen $0 ${text_}
  56. ${If} $0 != 0
  57. Push $1 ; rect
  58. Push $2 ; text flags
  59. ; build text flags
  60. StrCpy $2 ${DT_CALCRECT}|${DT_LEFT}|${DT_TOP}
  61. IntOp $2 $2 | ${style_}
  62. System::Call "*${stRECT}(0, 0, ${maxWidth_}, $0) .r1"
  63. System::Call "${fnDrawText}(${hdc_}, '${text_}', -1, $1, $2).r0"
  64. ${if} $0 != 0
  65. Push $3
  66. Push $4
  67. Push $5
  68. System::Call "*$1${stRECT}(.r2, .r3, .r4, .r5)"
  69. IntOp ${width_} $4 - $2
  70. IntOp $3 $5 - $3
  71. ${if} $3 > ${height_}
  72. StrCpy ${height_} $3
  73. ${EndIf}
  74. IntOp $4 ${averageCharWidth_} / 2
  75. IntOp ${width_} ${width_} + $4
  76. Pop $5
  77. Pop $4
  78. Pop $3
  79. ${EndIf}
  80. System::Free $1
  81. Pop $2 ; text flags
  82. Pop $1 ; rect
  83. ${EndIf}
  84. Pop $0
  85. ${If} ${previousFont_} != 0
  86. System::Call "${fnSelectObject}(${hdc_}, ${previousFont_})"
  87. ${EndIf}
  88. System::Call "${fnReleaseDC}(${hwnd_}, ${hdc_})"
  89. StrCpy ${style_} ${width_}
  90. StrCpy ${text_} ${height_}
  91. Pop ${averageCharWidth_}
  92. Pop ${height_}
  93. Pop ${width_}
  94. Pop ${previousFont_}
  95. Pop ${font_}
  96. Pop ${hdc_}
  97. Pop ${maxWidth_}
  98. Pop ${hwnd_}
  99. Exch ${text_}
  100. Exch
  101. Exch ${style_}
  102. !undef hwnd_
  103. !undef text_
  104. !undef style_
  105. !undef maxWidth_
  106. !undef hdc_
  107. !undef font_
  108. !undef previousFont_
  109. !undef width_
  110. !undef height_
  111. !undef averageCharWidth_
  112. !macroend
  113. !macro NX_CalculateTextRect __hwnd __text __style __maxWidth __width __height
  114. Push "${__maxWidth}"
  115. Push "${__style}"
  116. Push "${__text}"
  117. Push "${__hwnd}"
  118. ${CallArtificialFunction} NX_CalculateTextRectInternal
  119. Pop "${__width}"
  120. Pop "${__height}"
  121. !macroend
  122. !define NX_CalculateTextRect `!insertmacro NX_CalculateTextRect`
  123. !macro NX_GetLabelIdealSize __hwnd __maxWidth __width __height
  124. Push "${__maxWidth}"
  125. System::Call "${fnGetWindowLong}(${__hwnd}, ${GWL_STYLE}).s"
  126. Exch $0
  127. Push $1
  128. Push $2
  129. StrCpy $2 0
  130. IntOp $1 $0 & ${SS_EDITCONTROL}
  131. ${If} $1 != 0
  132. IntOp $2 $2 | ${DT_EDITCONTROL}
  133. ${EndIf}
  134. IntOp $1 $0 & ${SS_NOPREFIX}
  135. ${If} $1 != 0
  136. IntOp $2 $2 | ${DT_NOPREFIX}
  137. ${EndIf}
  138. IntOp $1 $0 & ${SS_SIMPLE}
  139. ${If} $1 != 0
  140. IntOp $2 $2 | ${DT_SINGLELINE}
  141. ${Else}
  142. IntOp $2 $2 | ${DT_WORDBREAK}
  143. ${EndIf}
  144. StrCpy $0 $2
  145. Pop $2
  146. Pop $1
  147. Exch $0
  148. System::Call "${fnGetWindowText}(${__hwnd}, .s, ${NSIS_MAX_STRLEN})"
  149. Push "${__hwnd}"
  150. ${CallArtificialFunction} NX_CalculateTextRectInternal
  151. Pop "${__width}"
  152. Pop "${__height}"
  153. !macroend
  154. !define NX_GetLabelIdealSize `!insertmacro NX_GetLabelIdealSize`
  155. !endif ; defined(NULLSOFT_NX_TEXT_RECT_NSIS_HEADER)