Leaked source code of windows server 2003
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.

232 lines
7.0 KiB

  1. #include "ctlspriv.h"
  2. #define MAININSYS
  3. BOOL NEAR PASCAL IsMaxedMDI(HMENU hMenu)
  4. {
  5. return(GetMenuItemID(hMenu, GetMenuItemCount(hMenu)-1) == SC_RESTORE);
  6. }
  7. /* Note that if iMessage is WM_COMMAND, it is assumed to have come from
  8. * a header bar or toolbar; do not pass in WM_COMMAND messages from any
  9. * other controls.
  10. */
  11. #define MS_ID GET_WM_MENUSELECT_CMD
  12. #define MS_FLAGS GET_WM_MENUSELECT_FLAGS
  13. #define MS_MENU GET_WM_MENUSELECT_HMENU
  14. #define CMD_NOTIFY GET_WM_COMMAND_CMD
  15. #define CMD_ID GET_WM_COMMAND_ID
  16. #define CMD_CTRL GET_WM_COMMAND_HWND
  17. void WINAPI MenuHelp(UINT iMessage, WPARAM wParam, LPARAM lParam,
  18. HMENU hMainMenu, HINSTANCE hAppInst, HWND hwndStatus, UINT FAR *lpwIDs)
  19. {
  20. UINT wID;
  21. UINT FAR *lpwPopups;
  22. int i;
  23. TCHAR szString[256];
  24. BOOL bUpdateNow = TRUE;
  25. MENUITEMINFO mii;
  26. switch (iMessage)
  27. {
  28. case WM_MENUSELECT:
  29. if ((WORD)MS_FLAGS(wParam, lParam)==(WORD)-1 && MS_MENU(wParam, lParam)==0)
  30. {
  31. SendMessage(hwndStatus, SB_SIMPLE, 0, 0L);
  32. break;
  33. }
  34. szString[0] = TEXT('\0');
  35. i = MS_ID(wParam, lParam);
  36. //BugBug: this line should be in
  37. //bByPos = (MS_FLAGS(wParam, lParam) & MF_POPUP);
  38. memset(&mii, 0, SIZEOF(mii));
  39. mii.cbSize = SIZEOF(mii);
  40. mii.fMask = MIIM_TYPE;
  41. mii.cch = 0; //If we ask for MIIM_TYPE, this must be set to zero!
  42. //Otherwise, win95 attempts to copy the string too!
  43. if (GetMenuItemInfo((HMENU)MS_MENU(wParam, lParam), i, TRUE /*bByPos*/, &mii))
  44. {
  45. mii.fState = mii.fType & MFT_RIGHTORDER ?SBT_RTLREADING :0;
  46. }
  47. if (!(MS_FLAGS(wParam, lParam)&MF_SEPARATOR))
  48. {
  49. if (MS_FLAGS(wParam, lParam)&MF_POPUP)
  50. {
  51. /* We don't want to update immediately in case the menu is
  52. * about to pop down, with an item selected. This gets rid
  53. * of some flashing text.
  54. */
  55. bUpdateNow = FALSE;
  56. /* First check if this popup is in our list of popup menus
  57. */
  58. for (lpwPopups=lpwIDs+2; *lpwPopups; lpwPopups+=2)
  59. {
  60. /* lpwPopups is a list of string ID/menu handle pairs
  61. * and MS_ID(wParam, lParam) is the menu handle of the selected popup
  62. */
  63. if (*(lpwPopups+1) == (UINT)MS_ID(wParam, lParam))
  64. {
  65. wID = *lpwPopups;
  66. goto LoadTheString;
  67. }
  68. }
  69. /* Check if the specified popup is in the main menu;
  70. * note that if the "main" menu is in the system menu,
  71. * we will be OK as long as the menu is passed in correctly.
  72. * In fact, an app could handle all popups by just passing in
  73. * the proper hMainMenu.
  74. */
  75. if ((HMENU)MS_MENU(wParam, lParam) == hMainMenu)
  76. {
  77. i = MS_ID(wParam, lParam);
  78. {
  79. if (IsMaxedMDI(hMainMenu))
  80. {
  81. if (!i)
  82. {
  83. wID = IDS_SYSMENU;
  84. hAppInst = HINST_THISDLL;
  85. goto LoadTheString;
  86. }
  87. else
  88. --i;
  89. }
  90. wID = (UINT)(i + lpwIDs[1]);
  91. goto LoadTheString;
  92. }
  93. }
  94. /* This assumes all app defined popups in the system menu
  95. * have been listed above
  96. */
  97. if ((MS_FLAGS(wParam, lParam)&MF_SYSMENU))
  98. {
  99. wID = IDS_SYSMENU;
  100. hAppInst = HINST_THISDLL;
  101. goto LoadTheString;
  102. }
  103. goto NoString;
  104. }
  105. else if (MS_ID(wParam, lParam) >= MINSYSCOMMAND)
  106. {
  107. wID = (UINT)(MS_ID(wParam, lParam) + MH_SYSMENU);
  108. hAppInst = HINST_THISDLL;
  109. }
  110. else
  111. {
  112. wID = (UINT)(MS_ID(wParam, lParam) + lpwIDs[0]);
  113. }
  114. LoadTheString:
  115. if (hAppInst == HINST_THISDLL)
  116. LocalizedLoadString(wID, szString, ARRAYSIZE(szString));
  117. else
  118. LoadString(hAppInst, wID, szString, ARRAYSIZE(szString));
  119. }
  120. NoString:
  121. SendMessage(hwndStatus, SB_SETTEXT, mii.fState|SBT_NOBORDERS|255,
  122. (LPARAM)(LPSTR)szString);
  123. SendMessage(hwndStatus, SB_SIMPLE, 1, 0L);
  124. if (bUpdateNow)
  125. UpdateWindow(hwndStatus);
  126. break;
  127. default:
  128. break;
  129. }
  130. }
  131. BOOL WINAPI ShowHideMenuCtl(HWND hWnd, WPARAM wParam, LPINT lpInfo)
  132. {
  133. HWND hCtl;
  134. UINT uTool, uShow = MF_UNCHECKED | MF_BYCOMMAND;
  135. HMENU hMainMenu;
  136. BOOL bRet = FALSE;
  137. hMainMenu = IntToPtr_(HMENU, lpInfo[1]);
  138. for (uTool=0; ; ++uTool, lpInfo+=2)
  139. {
  140. if ((WPARAM)lpInfo[0] == wParam)
  141. break;
  142. if (!lpInfo[0])
  143. goto DoTheCheck;
  144. }
  145. if (!(GetMenuState(hMainMenu, (UINT) wParam, MF_BYCOMMAND)&MF_CHECKED))
  146. uShow = MF_CHECKED | MF_BYCOMMAND;
  147. switch (uTool)
  148. {
  149. case 0:
  150. bRet = SetMenu(hWnd, (HMENU)((uShow&MF_CHECKED) ? hMainMenu : 0));
  151. break;
  152. default:
  153. hCtl = GetDlgItem(hWnd, lpInfo[1]);
  154. if (hCtl)
  155. {
  156. ShowWindow(hCtl, (uShow&MF_CHECKED) ? SW_SHOW : SW_HIDE);
  157. bRet = TRUE;
  158. }
  159. else
  160. uShow = MF_UNCHECKED | MF_BYCOMMAND;
  161. break;
  162. }
  163. DoTheCheck:
  164. CheckMenuItem(hMainMenu, (UINT) wParam, uShow);
  165. #ifdef MAININSYS
  166. hMainMenu = GetSubMenu(GetSystemMenu(hWnd, FALSE), 0);
  167. if (hMainMenu)
  168. CheckMenuItem(hMainMenu, (UINT) wParam, uShow);
  169. #endif
  170. return(bRet);
  171. }
  172. void WINAPI GetEffectiveClientRect(HWND hWnd, LPRECT lprc, LPINT lpInfo)
  173. {
  174. RECT rc;
  175. HWND hCtl;
  176. GetClientRect(hWnd, lprc);
  177. /* Get past the menu
  178. */
  179. for (lpInfo+=2; lpInfo[0]; lpInfo+=2)
  180. {
  181. hCtl = GetDlgItem(hWnd, lpInfo[1]);
  182. /* We check the style bit because the parent window may not be visible
  183. * yet (still in the create message)
  184. */
  185. if (!hCtl || !(GetWindowStyle(hCtl) & WS_VISIBLE))
  186. continue;
  187. GetWindowRect(hCtl, &rc);
  188. //
  189. // This will do the ScrrenToClient functionality, plus
  190. // it will return a good rect (left < right) when the
  191. // hWnd parent is RTL mirrored. [samera]
  192. //
  193. MapWindowPoints(HWND_DESKTOP, hWnd, (PPOINT)&rc, 2);
  194. SubtractRect(lprc, lprc, &rc);
  195. }
  196. }