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.

187 lines
4.8 KiB

  1. #include "stdafx.h"
  2. #include "Lava.h"
  3. #include "MsgHelp.h"
  4. /***************************************************************************\
  5. *
  6. * GdConvertMouseMessage (Public)
  7. *
  8. * GdConvertMouseMessage converts from an HWND mouse event into a Gadget
  9. * mouse event.
  10. *
  11. \***************************************************************************/
  12. void
  13. SetStandardInputFields(
  14. IN OUT GMSG_INPUT * pmsg,
  15. IN UINT cbSize)
  16. {
  17. ZeroMemory(pmsg, cbSize);
  18. pmsg->cbSize = cbSize;
  19. pmsg->lTime = GetMessageTime();
  20. pmsg->nModifiers = 0;
  21. //
  22. // todo -- measure perf
  23. //
  24. BYTE bKeys[256];
  25. if (GetKeyboardState(bKeys)) {
  26. if (bKeys[VK_LBUTTON] & 0x80) pmsg->nModifiers |= GMODIFIER_LBUTTON;
  27. if (bKeys[VK_RBUTTON] & 0x80) pmsg->nModifiers |= GMODIFIER_RBUTTON;
  28. if (bKeys[VK_MBUTTON] & 0x80) pmsg->nModifiers |= GMODIFIER_MBUTTON;
  29. if (bKeys[VK_LSHIFT] & 0x80) pmsg->nModifiers |= GMODIFIER_LSHIFT;
  30. if (bKeys[VK_RSHIFT] & 0x80) pmsg->nModifiers |= GMODIFIER_RSHIFT;
  31. if (bKeys[VK_LCONTROL] & 0x80) pmsg->nModifiers |= GMODIFIER_LCONTROL;
  32. if (bKeys[VK_RCONTROL] & 0x80) pmsg->nModifiers |= GMODIFIER_RCONTROL;
  33. if (bKeys[VK_LMENU] & 0x80) pmsg->nModifiers |= GMODIFIER_LALT;
  34. if (bKeys[VK_RMENU] & 0x80) pmsg->nModifiers |= GMODIFIER_RALT;
  35. }
  36. }
  37. void
  38. GdConvertMouseClickMessage(
  39. IN OUT GMSG_MOUSECLICK * pmsg,
  40. IN UINT nMsg,
  41. IN WPARAM wParam)
  42. {
  43. SetStandardInputFields(pmsg, sizeof(GMSG_MOUSECLICK));
  44. pmsg->nFlags = LOWORD(wParam);
  45. pmsg->cClicks = 0;
  46. switch (nMsg)
  47. {
  48. case WM_LBUTTONDBLCLK:
  49. case WM_LBUTTONDOWN:
  50. pmsg->bButton = GBUTTON_LEFT;
  51. pmsg->nCode = GMOUSE_DOWN;
  52. break;
  53. case WM_RBUTTONDBLCLK:
  54. case WM_RBUTTONDOWN:
  55. pmsg->bButton = GBUTTON_RIGHT;
  56. pmsg->nCode = GMOUSE_DOWN;
  57. break;
  58. case WM_MBUTTONDBLCLK:
  59. case WM_MBUTTONDOWN:
  60. pmsg->bButton = GBUTTON_MIDDLE;
  61. pmsg->nCode = GMOUSE_DOWN;
  62. break;
  63. case WM_LBUTTONUP:
  64. pmsg->bButton = GBUTTON_LEFT;
  65. pmsg->nCode = GMOUSE_UP;
  66. break;
  67. case WM_RBUTTONUP:
  68. pmsg->bButton = GBUTTON_RIGHT;
  69. pmsg->nCode = GMOUSE_UP;
  70. break;
  71. case WM_MBUTTONUP:
  72. pmsg->bButton = GBUTTON_MIDDLE;
  73. pmsg->nCode = GMOUSE_UP;
  74. break;
  75. default:
  76. AssertMsg(0, "Unknown message or should needs different convertor");
  77. }
  78. }
  79. void
  80. GdConvertMouseWheelMessage(
  81. IN OUT GMSG_MOUSEWHEEL * pmsg,
  82. IN WPARAM wParam)
  83. {
  84. SetStandardInputFields(pmsg, sizeof(GMSG_MOUSEWHEEL));
  85. pmsg->nCode = GMOUSE_WHEEL;
  86. pmsg->bButton = GBUTTON_NONE;
  87. pmsg->nFlags = LOWORD(wParam);
  88. pmsg->sWheel = GET_WHEEL_DELTA_WPARAM(wParam);
  89. }
  90. void
  91. GdConvertMouseMessage(
  92. IN OUT GMSG_MOUSE * pmsg,
  93. UINT nMsg,
  94. WPARAM wParam)
  95. {
  96. SetStandardInputFields(pmsg, sizeof(GMSG_MOUSE));
  97. pmsg->nFlags = LOWORD(wParam);
  98. switch (nMsg)
  99. {
  100. case WM_MOUSEMOVE:
  101. pmsg->bButton = GBUTTON_NONE;
  102. pmsg->nCode = GMOUSE_MOVE;
  103. break;
  104. case WM_MOUSEHOVER:
  105. pmsg->bButton = GBUTTON_NONE;
  106. pmsg->nCode = GMOUSE_HOVER;
  107. break;
  108. case WM_MOUSELEAVE:
  109. AssertMsg(0, "Must call RootGadget::xdHandleMouseLeaveMessage() directly");
  110. break;
  111. default:
  112. AssertMsg(0, "Unknown message or should needs different convertor");
  113. }
  114. }
  115. /***************************************************************************\
  116. *
  117. * GdConvertKeyboardMessage (Public)
  118. *
  119. * GdConvertKeyboardMessage converts from an HWND keyboard event into a
  120. * Gadget mouse event.
  121. *
  122. \***************************************************************************/
  123. void
  124. GdConvertKeyboardMessage(
  125. IN OUT GMSG_KEYBOARD * pmsg,
  126. IN UINT nMsg,
  127. IN WPARAM wParam,
  128. IN LPARAM lParam)
  129. {
  130. SetStandardInputFields(pmsg, sizeof(GMSG_KEYBOARD));
  131. pmsg->ch = (WCHAR) wParam;
  132. pmsg->cRep = LOWORD(lParam);
  133. pmsg->wFlags = HIWORD(lParam);
  134. switch (nMsg)
  135. {
  136. case WM_CHAR:
  137. pmsg->nCode = GKEY_CHAR;
  138. break;
  139. case WM_KEYDOWN:
  140. pmsg->nCode = GKEY_DOWN;
  141. break;
  142. case WM_KEYUP:
  143. pmsg->nCode = GKEY_UP;
  144. break;
  145. case WM_SYSCHAR:
  146. pmsg->nCode = GKEY_SYSCHAR;
  147. break;
  148. case WM_SYSKEYDOWN:
  149. pmsg->nCode = GKEY_SYSDOWN;
  150. break;
  151. case WM_SYSKEYUP:
  152. pmsg->nCode = GKEY_SYSUP;
  153. break;
  154. default:
  155. AssertMsg(0, "Unknown message or should needs different convertor");
  156. }
  157. }