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.

155 lines
4.7 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: keyconv.c
  3. *
  4. * Copyright (c) 1985 - 1999, Microsoft Corporation
  5. *
  6. * History:
  7. * 11-06-90 DavidPe Created.
  8. * 13-Feb-1991 mikeke Added Revalidation code (None)
  9. \***************************************************************************/
  10. #include "precomp.h"
  11. #pragma hdrstop
  12. /***************************************************************************\
  13. * _TranslateMessage (API)
  14. *
  15. * This routine translates virtual keystroke messages as follows:
  16. * WM_KEYDOWN/WM_KEYUP are translated into WM_CHAR and WM_DEADCHAR
  17. * WM_SYSKEYDOWN/WM_SYSKEYDOWN are translated into WM_SYSCHAR and
  18. * WM_SYSDEADCHAR. The WM_*CHAR messages are posted to the application
  19. * queue.
  20. *
  21. * History:
  22. * 11-06-90 DavidPe Created stub functionality.
  23. * 12-07-90 GregoryW Modified to call _ToAscii for translations.
  24. \***************************************************************************/
  25. BOOL xxxTranslateMessage(
  26. LPMSG pmsg,
  27. UINT uiTMFlags)
  28. {
  29. PTHREADINFO pti;
  30. UINT wMsgType;
  31. int cChar;
  32. BOOL fSysKey = FALSE;
  33. DWORD dwKeyFlags;
  34. LPARAM lParam;
  35. UINT uVirKey;
  36. PWND pwnd;
  37. WCHAR awch[16];
  38. WCHAR *pwch;
  39. switch (pmsg->message) {
  40. default:
  41. return FALSE;
  42. case WM_SYSKEYDOWN:
  43. /*
  44. * HACK carried over from Win3 code: system messages
  45. * only get posted during KEYDOWN processing - so
  46. * set fSysKey only for WM_SYSKEYDOWN.
  47. */
  48. fSysKey = TRUE;
  49. /*
  50. * Fall thru...
  51. */
  52. case WM_SYSKEYUP:
  53. case WM_KEYDOWN:
  54. case WM_KEYUP:
  55. pti = PtiCurrent();
  56. if ((pti->pMenuState != NULL) &&
  57. (HW(pti->pMenuState->pGlobalPopupMenu->spwndPopupMenu) ==
  58. pmsg->hwnd)) {
  59. uiTMFlags |= TM_INMENUMODE;
  60. } else {
  61. uiTMFlags &= ~TM_INMENUMODE;
  62. }
  63. /*
  64. * Don't change the contents of the passed in structure.
  65. */
  66. lParam = pmsg->lParam;
  67. /*
  68. * For backward compatibility, mask the virtual key value.
  69. */
  70. uVirKey = LOWORD(pmsg->wParam);
  71. cChar = xxxInternalToUnicode(uVirKey, // virtual key code
  72. HIWORD(lParam), // scan code, make/break bit
  73. pti->pq->afKeyState,
  74. awch, sizeof(awch)/sizeof(awch[0]),
  75. uiTMFlags, &dwKeyFlags, NULL);
  76. lParam |= (dwKeyFlags & ALTNUMPAD_BIT);
  77. /*
  78. * LATER 12/7/90 - GregoryW
  79. * Note: Win3.x TranslateMessage returns TRUE if ToAscii is called.
  80. * Proper behavior is to return TRUE if any translation is
  81. * performed by ToAscii. If we have to remain compatible
  82. * (even though apps clearly don't currently care about the
  83. * return value) then the following return should be changed
  84. * to TRUE. If we want the new 32-bit apps to have a meaningful
  85. * return value we should leave this as FALSE.
  86. *
  87. * If console is calling us with the TM_POSTCHARBREAKS flag then we
  88. * return FALSE if no char was actually posted
  89. *
  90. * !!! LATER get console to change so it does not need private API
  91. * TranslateMessageEx
  92. */
  93. if (!cChar) {
  94. if (uiTMFlags & TM_POSTCHARBREAKS)
  95. return FALSE;
  96. else
  97. return TRUE;
  98. }
  99. /*
  100. * Some translation performed. Figure out what type of
  101. * message to post.
  102. *
  103. */
  104. if (cChar > 0)
  105. wMsgType = (fSysKey) ? (UINT)WM_SYSCHAR : (UINT)WM_CHAR;
  106. else {
  107. wMsgType = (fSysKey) ? (UINT)WM_SYSDEADCHAR : (UINT)WM_DEADCHAR;
  108. cChar = -cChar; // want positive value
  109. }
  110. if (dwKeyFlags & KBDBREAK) {
  111. lParam |= 0x80000000;
  112. } else {
  113. lParam &= ~0x80000000;
  114. }
  115. /*
  116. * Since xxxInternalToUnicode can leave the crit sect, we need to
  117. * validate the message hwnd here.
  118. */
  119. pwnd = ValidateHwnd(pmsg->hwnd);
  120. if (!pwnd) {
  121. return FALSE;
  122. }
  123. for (pwch = awch; cChar > 0; cChar--) {
  124. /*
  125. * If this is a multi-character posting, all but the last one
  126. * should be marked as fake keystrokes for Console/VDM.
  127. */
  128. _PostMessage(pwnd, wMsgType, (WPARAM)*pwch,
  129. lParam | (cChar > 1 ? FAKE_KEYSTROKE : 0));
  130. *pwch = 0; // zero out old character (why?)
  131. pwch += 1;
  132. }
  133. return TRUE;
  134. }
  135. }