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.

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