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.

120 lines
3.4 KiB

  1. /**************************** Module Header ********************************\
  2. * Module Name: mnsel.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * Menu Selection Routines
  7. *
  8. * History:
  9. * 10-10-90 JimA Cleanup.
  10. * 03-18-91 IanJa Window revalidation added
  11. \***************************************************************************/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. /***************************************************************************\
  15. * xxxSendMenuSelect
  16. *
  17. * !
  18. *
  19. * Revalidation notes:
  20. * o Assumes pMenuState->hwndMenu is non-NULL and valid
  21. *
  22. * Note: if pMenu==SMS_NOMENU, idx had better be MFMWFP_NOITEM!
  23. *
  24. * History:
  25. \***************************************************************************/
  26. void xxxSendMenuSelect(
  27. PWND pwndNotify,
  28. PWND pwndMenu,
  29. PMENU pMenu,
  30. int idx)
  31. {
  32. UINT cmd; // Menu ID if applicable.
  33. UINT flags; // MF_ values if any
  34. MSG msg;
  35. PMENUSTATE pMenuState;
  36. CheckLock(pwndNotify);
  37. CheckLock(pwndMenu);
  38. /*
  39. * We must be hacking or passing valid things.
  40. */
  41. UserAssert((pMenu != SMS_NOMENU) || (idx == MFMWFP_NOITEM));
  42. if ((idx >= 0) && (pMenu->cItems > (UINT)idx)) {
  43. PITEM pItem = &(pMenu->rgItems[idx]);
  44. flags = (pItem->fType & MFT_OLDAPI_MASK) |
  45. (pItem->fState & MFS_OLDAPI_MASK);
  46. if (pItem->spSubMenu != NULL)
  47. flags |= MF_POPUP;
  48. flags &= (~(MF_SYSMENU | MF_MOUSESELECT));
  49. /*
  50. * WARNING!
  51. * Under Windows the menu handle was always returned but additionally
  52. * if the menu was a pop-up the pop-up menu handle was returned
  53. * instead of the ID. In NT we don't have enough space for 2 handles
  54. * and flags so if it is a pop-up we return the pop-up index
  55. * and the main Menu handle.
  56. */
  57. if (flags & MF_POPUP)
  58. cmd = idx; // index of popup-menu
  59. else
  60. cmd = pItem->wID;
  61. pMenuState = GetpMenuState(pwndNotify);
  62. if (pMenuState != NULL) {
  63. if (pMenuState->mnFocus == MOUSEHOLD)
  64. flags |= MF_MOUSESELECT;
  65. if (pMenuState->fIsSysMenu)
  66. flags |= MF_SYSMENU;
  67. }
  68. } else {
  69. /*
  70. * idx assumed to be MFMWFP_NOITEM
  71. */
  72. if (pMenu == SMS_NOMENU) {
  73. /*
  74. * Hack so we can send MenuSelect messages with MFMWFP_MAINMENU
  75. * (loword(lparam)=-1) when the menu pops back up for the CBT people.
  76. */
  77. flags = MF_MAINMENU;
  78. } else {
  79. flags = 0;
  80. }
  81. cmd = 0; // so MAKELONG(cmd, flags) == MFMWFP_MAINMENU
  82. pMenu = 0;
  83. idx = -1; // so that idx+1 == 0, meaning nothing for zzzWindowEvent()
  84. }
  85. /*
  86. * Call msgfilter so help libraries can hook WM_MENUSELECT messages.
  87. */
  88. msg.hwnd = HW(pwndNotify);
  89. msg.message = WM_MENUSELECT;
  90. msg.wParam = (DWORD)MAKELONG(cmd, flags);
  91. msg.lParam = (LPARAM)PtoH(pMenu);
  92. if (!_CallMsgFilter((LPMSG)&msg, MSGF_MENU)) {
  93. xxxSendNotifyMessage(pwndNotify, WM_MENUSELECT, msg.wParam, msg.lParam);
  94. }
  95. if (pwndMenu) {
  96. xxxWindowEvent(EVENT_OBJECT_FOCUS, pwndMenu,
  97. ((pwndMenu != pwndNotify) ? OBJID_CLIENT : ((flags & MF_SYSMENU) ? OBJID_SYSMENU : OBJID_MENU)),
  98. idx+1, 0);
  99. }
  100. }