Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

332 lines
8.5 KiB

  1. /*++
  2. *
  3. * WOW v1.0
  4. *
  5. * Copyright (c) 1991, Microsoft Corporation
  6. *
  7. * MSUTIL.C
  8. * WOW16 misc. routines
  9. *
  10. * History:
  11. *
  12. * Created 28-May-1991 by Jeff Parsons (jeffpar)
  13. * Copied from WIN31 and edited (as little as possible) for WOW16.
  14. * At this time, all we want is GetCharDimensions(), which the edit
  15. * controls use.
  16. --*/
  17. /****************************************************************************/
  18. /* */
  19. /* MSUTIL.C - */
  20. /* */
  21. /* Miscellaneous Messaging Routines */
  22. /* */
  23. /****************************************************************************/
  24. #include "user.h"
  25. #ifndef WOW
  26. #include "winmgr.h"
  27. /*--------------------------------------------------------------------------*/
  28. /* */
  29. /* CancelMode() - */
  30. /* */
  31. /*--------------------------------------------------------------------------*/
  32. void FAR PASCAL CancelMode(hwnd)
  33. register HWND hwnd;
  34. {
  35. if (hwnd != NULL)
  36. {
  37. if (hwnd != hwndCapture)
  38. CancelMode(hwndCapture);
  39. SendMessage(hwnd, WM_CANCELMODE, 0, 0L);
  40. }
  41. }
  42. /*--------------------------------------------------------------------------*/
  43. /* */
  44. /* BcastCopyString() - */
  45. /* */
  46. /*--------------------------------------------------------------------------*/
  47. /* Copy strings which are going to be Broadcast into USER's DS to prevent
  48. * EMS problems when switching tasks.
  49. */
  50. HANDLE FAR PASCAL BcastCopyString(lParam)
  51. LONG lParam;
  52. {
  53. LPSTR ptrbuf;
  54. register int len;
  55. register HANDLE hMem;
  56. len = lstrlen((LPSTR)lParam) + 1;
  57. if ((hMem = GlobalAlloc(GMEM_FIXED | GMEM_LOWER, (LONG)len)) == NULL)
  58. return(NULL);
  59. /* Get the address of the allocated block. */
  60. ptrbuf = GlobalLock(hMem);
  61. LCopyStruct((LPSTR)lParam, ptrbuf, len);
  62. return(hMem);
  63. }
  64. /*--------------------------------------------------------------------------*/
  65. /* */
  66. /* SendSizeMessages() - */
  67. /* */
  68. /*--------------------------------------------------------------------------*/
  69. void FAR PASCAL SendSizeMessage(hwnd, cmdSize)
  70. register HWND hwnd;
  71. WORD cmdSize;
  72. {
  73. DWORD lParam;
  74. lParam = MAKELONG(hwnd->rcClient.right - hwnd->rcClient.left,
  75. hwnd->rcClient.bottom - hwnd->rcClient.top);
  76. SendMessage(hwnd, WM_SIZE, cmdSize, lParam);
  77. }
  78. /*--------------------------------------------------------------------------*/
  79. /* */
  80. /* AdjustWindowRect() - */
  81. /* */
  82. /*--------------------------------------------------------------------------*/
  83. void USERENTRY AdjustWindowRect(lprc, style, fMenu)
  84. LPRECT lprc;
  85. LONG style;
  86. BOOL fMenu;
  87. {
  88. AdjustWindowRectEx(lprc, style, fMenu, (DWORD)0);
  89. }
  90. /*--------------------------------------------------------------------------*/
  91. /* */
  92. /* AdjustWindowRectEx() - */
  93. /* */
  94. /*--------------------------------------------------------------------------*/
  95. void USERENTRY AdjustWindowRectEx(lprc, style, fMenu, dwExStyle)
  96. LPRECT lprc;
  97. LONG style;
  98. BOOL fMenu;
  99. DWORD dwExStyle;
  100. {
  101. register int cx;
  102. register int cy;
  103. cx = cxBorder;
  104. cy = cyBorder;
  105. if (fMenu)
  106. lprc->top -= rgwSysMet[SM_CYMENU];
  107. /* Let us first decide if it is no-border, single border or dlg border */
  108. /* Check if the WS_EX_DLGMODALFRAME bit is set, if so Dlg border */
  109. if(dwExStyle & WS_EX_DLGMODALFRAME)
  110. {
  111. cx *= (CLDLGFRAME + 2*CLDLGFRAMEWHITE + 1);
  112. cy *= (CLDLGFRAME + 2*CLDLGFRAMEWHITE + 1);
  113. }
  114. else
  115. {
  116. /* C6.0 will not generate jump table for this switch because of the
  117. * range of values tested in case statemts;
  118. */
  119. switch (HIWORD(style) & HIWORD(WS_CAPTION))
  120. {
  121. case HIWORD(WS_CAPTION):
  122. case HIWORD(WS_BORDER):
  123. break; /* Single border */
  124. case HIWORD(WS_DLGFRAME):
  125. cx *= (CLDLGFRAME + 2*CLDLGFRAMEWHITE + 1);
  126. cy *= (CLDLGFRAME + 2*CLDLGFRAMEWHITE + 1);
  127. break; /* Dlg Border */
  128. default: /* case 0 */
  129. cx = 0; /* No border */
  130. cy = 0;
  131. break;
  132. }
  133. }
  134. if((HIWORD(style) & HIWORD(WS_CAPTION)) == HIWORD(WS_CAPTION))
  135. lprc->top -= (cyCaption - cyBorder);
  136. if(cx || cy)
  137. InflateRect(lprc, cx, cy);
  138. /* Shouldn't we check if it has DLG frame and if so skip the following ?? */
  139. if (style & WS_SIZEBOX)
  140. InflateRect(lprc, cxSzBorder, cySzBorder);
  141. }
  142. #endif // WOW
  143. /*----------------------------------------------------------------------*/
  144. /* */
  145. /* GetCharDimensions(hDC, lpTextMetrics) */
  146. /* */
  147. /* This function loads the Textmetrics of the font currently */
  148. /* selected into the hDC and returns the Average char width of the */
  149. /* font; Pl Note that the AveCharWidth value returned by the Text */
  150. /* metrics call is wrong for proportional fonts. So, we compute them */
  151. /* On return, lpTextMetrics contains the text metrics of the */
  152. /* currently selected font. */
  153. /* */
  154. /*----------------------------------------------------------------------*/
  155. int FAR PASCAL GetCharDimensions(HDC hDC, LPTEXTMETRIC lpTextMetrics)
  156. {
  157. int cxWidth;
  158. int i;
  159. char AveCharWidthData[52];
  160. /* Store the System Font metrics info. */
  161. GetTextMetrics(hDC, lpTextMetrics);
  162. if (!(lpTextMetrics -> tmPitchAndFamily & 1)) /* If !variable_width font */
  163. cxWidth = lpTextMetrics -> tmAveCharWidth;
  164. else
  165. {
  166. /* Change from tmAveCharWidth. We will calculate a true average as
  167. opposed to the one returned by tmAveCharWidth. This works better
  168. when dealing with proportional spaced fonts. */
  169. for (i=0;i<=25;i++)
  170. AveCharWidthData[i] = (char)(i+(int)'a');
  171. for (i=0;i<=25;i++)
  172. AveCharWidthData[i+26] = (char)(i+(int)'A');
  173. cxWidth = LOWORD(GetTextExtent(hDC,AveCharWidthData,52)) / 26;
  174. cxWidth = (cxWidth + 1) / 2; // round up
  175. #if 0
  176. {
  177. char buf[80];
  178. wsprintf(buf, "cxWidth = %d tmAveCharWidth %d\r\n", cxWidth, lpTextMetrics -> tmAveCharWidth);
  179. OutputDebugString(buf);
  180. }
  181. #endif
  182. }
  183. return(cxWidth);
  184. }
  185. #ifndef WOW
  186. /*----------------------------------------------------------------------*/
  187. /* */
  188. /* GetAveCharWidth(hDC) */
  189. /* */
  190. /* This function loads the Textmetrics of the font currently */
  191. /* selected into the hDC and returns the Average char width of the */
  192. /* font; Pl Note that the AveCharWidth value returned by the Text */
  193. /* metrics call is wrong for proportional fonts. So, we compute them */
  194. /* On return, lpTextMetrics contains the text metrics of the */
  195. /* currently selected font. */
  196. /* */
  197. /*----------------------------------------------------------------------*/
  198. int FAR PASCAL GetAveCharWidth(hDC)
  199. HDC hDC;
  200. {
  201. TEXTMETRIC TextMetric;
  202. return(GetCharDimensions(hDC, &TextMetric));
  203. }
  204. /*--------------------------------------------------------------------------*/
  205. /* */
  206. /* MB_FindLongestString() - */
  207. /* */
  208. /*--------------------------------------------------------------------------*/
  209. WORD FAR PASCAL MB_FindLongestString()
  210. {
  211. int i;
  212. int iMaxLen = 0;
  213. int iNewMaxLen;
  214. PSTR *pszCurStr;
  215. PSTR szMaxStr;
  216. HDC hdc;
  217. WORD wRetVal;
  218. hdc = (HDC)GetScreenDC();
  219. for(i = 0, pszCurStr = AllMBbtnStrings; i < MAX_SEB_STYLES; i++, pszCurStr++)
  220. {
  221. if((iNewMaxLen = lstrlen((LPSTR)*pszCurStr)) > iMaxLen)
  222. {
  223. iMaxLen = iNewMaxLen;
  224. szMaxStr = *pszCurStr;
  225. }
  226. }
  227. /* Find the longest string */
  228. wRetVal = ((WORD)PSMGetTextExtent(hdc, (LPSTR)szMaxStr, lstrlen((LPSTR)szMaxStr))
  229. + ((int)PSGetTextExtent(hdc, (LPSTR)szOneChar, 1) << 1));
  230. InternalReleaseDC(hdc);
  231. return(wRetVal);
  232. }
  233. /*--------------------------------------------------------------------------*/
  234. /* */
  235. /* InitPwSB() - */
  236. /* */
  237. /*--------------------------------------------------------------------------*/
  238. int * FAR PASCAL InitPwSB(hwnd)
  239. register HWND hwnd;
  240. {
  241. register int *pw;
  242. if (hwnd->rgwScroll)
  243. /* If memory is already allocated, don't bother to do it again.
  244. */
  245. return(hwnd->rgwScroll);
  246. if ((hwnd->rgwScroll = pw = (int *)UserLocalAlloc(ST_WND, LPTR, 7 * sizeof(int))) != NULL)
  247. {
  248. /* rgw[0] = 0; */ /* LPTR zeros all 6 words */
  249. /* rgw[1] = 0; */
  250. /* rgw[3] = 0; */
  251. /* rgw[4] = 0; */
  252. /* rgw[6] = 0; Enable/Disable Flags */
  253. pw[2] = pw[5] = 100;
  254. }
  255. return(pw);
  256. }
  257. #endif // WOW