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.

229 lines
6.9 KiB

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