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.

224 lines
4.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1994.
  5. //
  6. // File: inplace.cxx
  7. //
  8. // Contents: Stripped-down OLE2 inplace.cpp
  9. //
  10. // History: 11-Apr-94 DrewB Copied from OLE2
  11. //
  12. //----------------------------------------------------------------------------
  13. #include "headers.cxx"
  14. #pragma hdrstop
  15. #include <ole2int.h>
  16. #ifndef _MAC
  17. #include "inplace.h"
  18. #endif
  19. #ifndef _MAC
  20. WORD wSignature; // = (WORD) {'S', 'K'};
  21. UINT uOleMessage;
  22. #define OM_CLEAR_MENU_STATE 0 // lParam is NULL
  23. #define OM_COMMAND_ID 1 // LOWORD(lParam) contains the command ID
  24. OLEAPI OleTranslateAccelerator
  25. (LPOLEINPLACEFRAME lpFrame, LPOLEINPLACEFRAMEINFO lpFrameInfo, LPMSG lpMsg)
  26. {
  27. WORD cmd;
  28. BOOL fFound;
  29. fFound = IsAccelerator(lpFrameInfo->haccel, lpFrameInfo->cAccelEntries,
  30. lpMsg, &cmd);
  31. if (!fFound && lpFrameInfo->fMDIApp)
  32. fFound = IsMDIAccelerator(lpMsg, &cmd);
  33. if (fFound) {
  34. AssertSz(lpFrameInfo->hwndFrame,
  35. "OleTranslateAccelerator: Invalid lpFrameInfo->hwndFrame");
  36. SendMessage(lpFrameInfo->hwndFrame, uOleMessage, OM_COMMAND_ID,
  37. MAKELONG(cmd, 0));
  38. #ifdef _DEBUG
  39. OutputDebugString((LPSTR)"IOleInPlaceFrame::TranslateAccelerator called\r\n");
  40. #endif
  41. return lpFrame->TranslateAccelerator(lpMsg, cmd);
  42. } else {
  43. if (wSysKeyToKey(lpMsg) == WM_SYSCHAR) {
  44. // Eat the message if it is "Alt -". This is supposed to bring
  45. // MDI system menu down. But we can not support it. And we also
  46. // don't want the message to be Translated by the object
  47. // application either. So, we return as if it has been accepted by
  48. // the container as an accelerator.
  49. // If the container wants to support this it can have an
  50. // accelerator for this. This is not an issue for SDI apps,
  51. // because it will be thrown away by USER anyway.
  52. if (lpMsg->wParam != '-')
  53. SendMessage(lpFrameInfo->hwndFrame, lpMsg->message,
  54. lpMsg->wParam, lpMsg->lParam);
  55. #ifdef _DEBUG
  56. else
  57. OutputDebugString((LPSTR)"OleTranslateAccelerator: Alt+ - key is discarded\r\n");
  58. #endif
  59. return NOERROR;
  60. }
  61. }
  62. return ResultFromScode(S_FALSE);
  63. }
  64. inline UINT wSysKeyToKey(LPMSG lpMsg)
  65. {
  66. UINT message = lpMsg->message;
  67. // if the ALT key is down when a key is pressed, then the 29th bit of the
  68. // LPARAM will be set
  69. // If the message was not made with the ALT key down, convert the message
  70. // from a WM_SYSKEY* to a WM_KEY* message.
  71. if (!(HIWORD(lpMsg->lParam) & 0x2000)
  72. && (message >= WM_SYSKEYDOWN && message <= WM_SYSDEADCHAR))
  73. message -= (WM_SYSKEYDOWN - WM_KEYDOWN);
  74. return message;
  75. }
  76. OLEAPI_(BOOL) IsAccelerator
  77. (HACCEL hAccel, int cAccelEntries, LPMSG lpMsg, WORD FAR* lpwCmd)
  78. {
  79. WORD cmd = NULL;
  80. WORD flags;
  81. BOOL fFound = FALSE;
  82. BOOL fVirt;
  83. LPACCEL lpAccel = NULL;
  84. UINT message;
  85. message = wSysKeyToKey(lpMsg);
  86. switch (message) {
  87. case WM_KEYDOWN:
  88. case WM_SYSKEYDOWN:
  89. fVirt = TRUE;
  90. break;
  91. case WM_CHAR:
  92. case WM_SYSCHAR:
  93. fVirt = FALSE;
  94. break;
  95. default:
  96. goto errRtn;
  97. }
  98. if (! (hAccel && (lpAccel = (LPACCEL) LockResource(hAccel))))
  99. goto errRtn;
  100. if (! cAccelEntries)
  101. goto errRtn;
  102. do {
  103. flags = lpAccel->fVirt;
  104. if ((lpAccel->key != (WORD) lpMsg->wParam) ||
  105. ((fVirt != 0) != ((flags & FVIRTKEY) != 0)))
  106. goto Next;
  107. if (fVirt) {
  108. if ((GetKeyState(VK_SHIFT) < 0) != ((flags & FSHIFT) != 0))
  109. goto Next;
  110. if ((GetKeyState(VK_CONTROL) < 0) != ((flags & FCONTROL) != 0))
  111. goto Next;
  112. }
  113. if ((GetKeyState(VK_MENU) < 0) != ((flags & FALT) != 0))
  114. goto Next;
  115. if (cmd = lpAccel->cmd)
  116. fFound = TRUE;
  117. goto errRtn;
  118. Next:
  119. lpAccel++;
  120. } while (--cAccelEntries);
  121. errRtn:
  122. if (lpAccel)
  123. UnlockResource(hAccel);
  124. if (lpwCmd)
  125. *lpwCmd = cmd;
  126. return fFound;
  127. }
  128. BOOL IsMDIAccelerator(LPMSG lpMsg, WORD FAR* lpCmd)
  129. {
  130. if (lpMsg->message != WM_KEYDOWN && lpMsg->message != WM_SYSKEYDOWN)
  131. return FALSE;
  132. /* All of these have the control key down */
  133. if (GetKeyState(VK_CONTROL) >= 0)
  134. return FALSE;
  135. if (GetKeyState(VK_MENU) < 0)
  136. return FALSE;
  137. switch ((WORD)lpMsg->wParam) {
  138. case VK_F4:
  139. *lpCmd = SC_CLOSE;
  140. case VK_F6:
  141. case VK_TAB:
  142. if (GetKeyState(VK_SHIFT) < 0)
  143. *lpCmd = SC_PREVWINDOW;
  144. else
  145. *lpCmd = SC_NEXTWINDOW;
  146. break;
  147. default:
  148. return FALSE;
  149. }
  150. return TRUE;
  151. }
  152. LPOLEMENU wGetOleMenuPtr(HOLEMENU holemenu)
  153. {
  154. LPOLEMENU lpOleMenu;
  155. if (! (holemenu
  156. && (lpOleMenu = (LPOLEMENU) GlobalLock((HGLOBAL) holemenu))))
  157. return NULL;
  158. if (lpOleMenu->wSignature != wSignature) {
  159. AssertSz(FALSE, "Error - handle is not a HOLEMENU");
  160. GlobalUnlock((HGLOBAL) holemenu);
  161. return NULL;
  162. }
  163. return lpOleMenu;
  164. }
  165. inline void wReleaseOleMenuPtr(HOLEMENU holemenu)
  166. {
  167. GlobalUnlock((HGLOBAL) holemenu);
  168. }
  169. #endif // !_MAC