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.

500 lines
11 KiB

  1. /* MOU.C */
  2. //#define WINVER 0x0300
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include "windows.h"
  6. //#include "winstric.h" /* added for win 3.1 compatibility 1/92 */
  7. #include "vars.h"
  8. #include "gide.h"
  9. #include "mou.h"
  10. #include "kbd.h"
  11. #include "sk_ex.h" // Serial Keys Interface Routines
  12. #include "w95trace.h"
  13. #if 0
  14. #define SF_MOVEMENT 0x0001
  15. #define SF_B1_DOWN 0x0002
  16. #define SF_B1_UP 0x0004
  17. #define SF_B2_DOWN 0x0008
  18. #define SF_B2_UP 0x0010
  19. #define SF_ABSOLUTE 0x8000
  20. #else
  21. #define SF_MOVEMENT MOUSEEVENTF_MOVE
  22. #define SF_B1_DOWN MOUSEEVENTF_LEFTDOWN
  23. #define SF_B1_UP MOUSEEVENTF_LEFTUP
  24. #define SF_B2_DOWN MOUSEEVENTF_RIGHTDOWN
  25. #define SF_B2_UP MOUSEEVENTF_RIGHTUP
  26. #define SF_ABSOLUTE MOUSEEVENTF_ABSOLUTE
  27. #endif
  28. void pressMouseButtonDown(void);
  29. void pressMouseButtonUp(void);
  30. void setTheMouseAbsolute(int PosX,int PosY);
  31. BOOL bmouseanchored = FALSE; /* flag, if false, mouse not pinned to a point */
  32. POINT mouseanchor;
  33. #ifndef SPI_GETMOUSESPEED
  34. #define SPI_GETMOUSESPEED 112
  35. #endif
  36. void SendMouseToQueue(MOUSEKEYSPARAM *p)
  37. {
  38. SkEx_SendMouse(p);
  39. }
  40. void processMouReset(unsigned char cGideiCode)
  41. {
  42. if (cGideiCode == TERMCODE)
  43. {
  44. // mouse_event treats button parameters as state changes not as state
  45. // setting; when resetting, only release a button if it is already down
  46. mouData.Status = SF_ABSOLUTE | SF_MOVEMENT;
  47. if(GetAsyncKeyState(VK_LBUTTON) > 1)
  48. mouData.Status |= GetSystemMetrics(SM_SWAPBUTTON) ? SF_B2_UP : SF_B1_UP;
  49. if(GetAsyncKeyState(VK_RBUTTON) > 1)
  50. mouData.Status |= GetSystemMetrics(SM_SWAPBUTTON) ? SF_B1_UP : SF_B2_UP;
  51. mouData.Delta_Y = 0;
  52. mouData.Delta_X = 0;
  53. SendMouseToQueue(mouseDataPtr);
  54. mouseX = mouseY = 0;
  55. }
  56. else
  57. {
  58. handleErrorReport();
  59. commandVector = noOpRoutine;
  60. }
  61. return;
  62. }
  63. void moveTheMouseAbsolute(void)
  64. {
  65. short tempX, tempY;
  66. tempX = tempList.list[1];
  67. tempX = (tempX << 8) + tempList.list[0];
  68. tempY = tempList.list[3];
  69. tempY = (tempY << 8) + tempList.list[2];
  70. mouseX = tempX;
  71. mouseY = tempY;
  72. setTheMouseAbsolute(tempX, tempY);
  73. return;
  74. }
  75. void setTheMouseAbsolute(int PosX,int PosY)
  76. {
  77. mouData.Status = SF_ABSOLUTE | SF_MOVEMENT;
  78. mouData.Delta_Y = (int) 0;
  79. mouData.Delta_X = (int) 0;
  80. SendMouseToQueue(mouseDataPtr);
  81. mouData.Status = SF_MOVEMENT;
  82. mouData.Delta_Y = (int) PosY;
  83. mouData.Delta_X = (int) PosX;
  84. SendMouseToQueue(mouseDataPtr);
  85. return;
  86. }
  87. void moveTheMouseRelative(void)
  88. {
  89. short xDist, yDist, newX, newY;
  90. xDist = tempList.list[1];
  91. xDist = (xDist << 8) + tempList.list[0];
  92. yDist = tempList.list[3];
  93. yDist = (yDist << 8) + tempList.list[2];
  94. newX = mouseX + xDist;
  95. newY = mouseY + yDist;
  96. if (newX < 0) newX = 0;
  97. if (newY < 0) newY = 0;
  98. mouseX = newX;
  99. mouseY = newY;
  100. mouData.Status = SF_MOVEMENT;
  101. mouData.Delta_Y = (int) yDist;
  102. mouData.Delta_X = (int) xDist;
  103. SendMouseToQueue(mouseDataPtr);
  104. return;
  105. }
  106. void processMouAnchor(unsigned char cGideiCode)
  107. {
  108. switch (cGideiCode) {
  109. case TERMCODE:
  110. // if (tempList.len < 4)
  111. // for ( ; tempList.len >= 4; tempList.list[tempList.len++] = 0);
  112. if (bmouseanchored) /* if true, need to release mouse */
  113. {
  114. bmouseanchored = FALSE;
  115. if (SkEx_GetAnchor(&mouseanchor))
  116. {
  117. setTheMouseAbsolute(mouseanchor.x,mouseanchor.y);
  118. mouseX = mouseanchor.x;
  119. mouseY = mouseanchor.y;
  120. }
  121. else
  122. SkEx_SendBeep();
  123. }
  124. else /* if false, need to pin the mouse */
  125. {
  126. SkEx_SetAnchor();
  127. bmouseanchored = TRUE;
  128. }
  129. tempList.len = 0;
  130. beginOK = TRUE;
  131. break;
  132. // case INTEGERCODE:
  133. // commandVector = collectGotoInteger;
  134. // beginOK = FALSE;
  135. // break;
  136. default:
  137. handleFatalError();
  138. break;
  139. }
  140. return;
  141. }
  142. void collectGotoInteger(unsigned char moveByte)
  143. {
  144. if (tempList.len >= 4) handleFatalError();
  145. else {
  146. tempList.list[tempList.len++] = moveByte;
  147. if ((tempList.len == 2) || (tempList.len == 4)) commandVector = processMouGoto;
  148. }
  149. return;
  150. }
  151. void collectGotoByte(unsigned char moveByte)
  152. {
  153. if (tempList.len >= 4) handleFatalError();
  154. else
  155. {
  156. tempList.list[tempList.len++] = moveByte;
  157. if (moveByte >127)
  158. {
  159. tempList.list[tempList.len++] = 0xFF;
  160. }
  161. else
  162. {
  163. tempList.list[tempList.len++] = 0;
  164. }
  165. commandVector = processMouGoto;
  166. }
  167. return;
  168. }
  169. void processMouGoto(unsigned char cGideiCode)
  170. {
  171. switch (cGideiCode) {
  172. case TERMCODE:
  173. if (tempList.len < 4)
  174. for ( ; tempList.len >= 4; tempList.list[tempList.len++] = 0);
  175. moveTheMouseAbsolute();
  176. tempList.len = 0;
  177. beginOK = TRUE;
  178. break;
  179. case BYTECODE:
  180. commandVector = collectGotoByte;
  181. beginOK = FALSE;
  182. break;
  183. case INTEGERCODE:
  184. commandVector = collectGotoInteger;
  185. beginOK = FALSE;
  186. break;
  187. default:
  188. handleFatalError();
  189. break;
  190. }
  191. return;
  192. }
  193. void collectMoveInteger(unsigned char moveByte)
  194. {
  195. if (tempList.len >= 4)
  196. {
  197. handleFatalError();
  198. }
  199. else
  200. {
  201. tempList.list[tempList.len++] = moveByte;
  202. if ((tempList.len == 2) || (tempList.len == 4))
  203. {
  204. commandVector = processMouMove;
  205. }
  206. }
  207. return;
  208. }
  209. void collectMoveByte(unsigned char moveByte)
  210. {
  211. if (tempList.len >= 4)
  212. {
  213. handleFatalError();
  214. }
  215. else
  216. {
  217. tempList.list[tempList.len++] = moveByte;
  218. if (moveByte >127)
  219. {
  220. tempList.list[tempList.len++] = 0xFF;
  221. }
  222. else
  223. {
  224. tempList.list[tempList.len++] = 0;
  225. }
  226. commandVector = processMouMove;
  227. }
  228. return;
  229. }
  230. void processMouMove(unsigned char cGideiCode)
  231. {
  232. switch (cGideiCode) {
  233. case TERMCODE:
  234. if (tempList.len < 4)
  235. for ( ; tempList.len >= 4; tempList.list[tempList.len++] = 0);
  236. moveTheMouseRelative();
  237. tempList.len = 0;
  238. beginOK = TRUE;
  239. break;
  240. case BYTECODE:
  241. commandVector = collectMoveByte;
  242. beginOK = FALSE;
  243. break;
  244. case INTEGERCODE:
  245. commandVector = collectMoveInteger;
  246. beginOK = FALSE;
  247. break;
  248. default:
  249. handleFatalError();
  250. break;
  251. }
  252. return;
  253. }
  254. void pressMouseButtonDown()
  255. {
  256. mouData.Status = 0;
  257. if (requestButton1) {
  258. if (!button1Status) {
  259. mouData.Status += SF_B1_DOWN;
  260. button1Status = TRUE;
  261. }
  262. }
  263. if (requestButton2) {
  264. if (!button2Status) {
  265. mouData.Status += SF_B2_DOWN;
  266. button2Status = TRUE;
  267. }
  268. }
  269. if (mouData.Status != 0)
  270. {
  271. SendMouseToQueue(mouseDataPtr);
  272. }
  273. return;
  274. }
  275. void pressMouseButtonUp()
  276. {
  277. mouData.Status = 0;
  278. if (requestButton1) {
  279. if (button1Status) {
  280. mouData.Status += SF_B1_UP;
  281. button1Status = FALSE;
  282. }
  283. }
  284. if (requestButton2) {
  285. if (button2Status) {
  286. mouData.Status += SF_B2_UP;
  287. button2Status = FALSE;
  288. }
  289. }
  290. if (mouData.Status != 0)
  291. {
  292. SendMouseToQueue(mouseDataPtr);
  293. }
  294. return;
  295. }
  296. void processMouRel(unsigned char cGideiCode)
  297. {
  298. switch (cGideiCode) {
  299. case TERMCODE:
  300. if ((!requestButton1) && (!requestButton2) && (!requestButton3))
  301. requestButton1 = requestButton2 = requestButton3 = TRUE;
  302. pressMouseButtonUp();
  303. requestButton1 = requestButton2 = requestButton3 = FALSE;
  304. beginOK = TRUE;
  305. break;
  306. case UNKNOWNCODE:
  307. handleErrorReport();
  308. commandVector = noOpRoutine;
  309. break;
  310. case DEFAULTCODE:
  311. case LEFTBUTTONCODE:
  312. requestButton1 = TRUE;
  313. beginOK = FALSE;
  314. break;
  315. case RIGHTBUTTONCODE:
  316. requestButton2 = TRUE;
  317. beginOK = FALSE;
  318. break;
  319. default:
  320. if (cGideiCode >= LOWESTGIDEICODE)
  321. {
  322. handleFatalError();
  323. break;
  324. }
  325. requestButton3 = TRUE;
  326. beginOK = FALSE;
  327. break;
  328. }
  329. return;
  330. }
  331. void processMouLock(unsigned char cGideiCode)
  332. {
  333. switch (cGideiCode)
  334. {
  335. case TERMCODE:
  336. if ((!requestButton1) && (!requestButton2) && (!requestButton3))
  337. requestButton1 = TRUE;
  338. pressMouseButtonDown();
  339. requestButton1 = requestButton2 = requestButton3 = FALSE;
  340. beginOK = TRUE;
  341. break;
  342. case UNKNOWNCODE:
  343. handleErrorReport();
  344. commandVector = noOpRoutine;
  345. break;
  346. case DEFAULTCODE:
  347. case LEFTBUTTONCODE:
  348. requestButton1 = TRUE;
  349. beginOK = FALSE;
  350. break;
  351. case RIGHTBUTTONCODE:
  352. requestButton2 = TRUE;
  353. beginOK = FALSE;
  354. break;
  355. default:
  356. if (cGideiCode >= LOWESTGIDEICODE)
  357. {
  358. handleFatalError();
  359. break;
  360. }
  361. requestButton3 = TRUE;
  362. beginOK = FALSE;
  363. break;
  364. }
  365. return;
  366. }
  367. void processMouDoubleClick(unsigned char cGideiCode)
  368. {
  369. if (cGideiCode == TERMCODE) {
  370. if ((!requestButton1) && (!requestButton2) && (!requestButton3 ))
  371. requestButton1 = TRUE;
  372. mouData.Status = 0;
  373. if ((requestButton1) && (button1Status)) {
  374. mouData.Status += SF_B1_UP;
  375. button1Status = FALSE;
  376. }
  377. if ((requestButton2) && (button2Status)) {
  378. mouData.Status += SF_B2_UP;
  379. button2Status = FALSE;
  380. }
  381. if (!mouData.Status)
  382. {
  383. SendMouseToQueue(mouseDataPtr);
  384. }
  385. pressMouseButtonDown();
  386. pressMouseButtonUp();
  387. pressMouseButtonDown();
  388. pressMouseButtonUp();
  389. requestButton1 = requestButton2 = requestButton3 = FALSE;
  390. beginOK = TRUE;
  391. }
  392. else
  393. processMouClick(cGideiCode);
  394. return;
  395. }
  396. void processMouClick(unsigned char cGideiCode)
  397. {
  398. switch (cGideiCode)
  399. {
  400. case TERMCODE:
  401. if ((!requestButton1) && (!requestButton2) && (!requestButton3 ))
  402. requestButton1 = TRUE;
  403. mouData.Status = 0;
  404. if ((requestButton1) && (button1Status)) {
  405. mouData.Status += SF_B1_UP;
  406. button1Status = FALSE;
  407. }
  408. if ((requestButton2) && (button2Status)) {
  409. mouData.Status += SF_B2_UP;
  410. button2Status = FALSE;
  411. }
  412. if (!mouData.Status)
  413. {
  414. SendMouseToQueue(mouseDataPtr);
  415. }
  416. pressMouseButtonDown();
  417. pressMouseButtonUp();
  418. requestButton1 = requestButton2 = requestButton3 = FALSE;
  419. beginOK = TRUE;
  420. break;
  421. case UNKNOWNCODE:
  422. handleErrorReport();
  423. commandVector = noOpRoutine;
  424. break;
  425. case DEFAULTCODE:
  426. case LEFTBUTTONCODE:
  427. requestButton1 = TRUE;
  428. beginOK = FALSE;
  429. break;
  430. case RIGHTBUTTONCODE:
  431. requestButton2 = TRUE;
  432. beginOK = FALSE;
  433. break;
  434. default:
  435. if (cGideiCode >= LOWESTGIDEICODE)
  436. {
  437. handleFatalError();
  438. break;
  439. }
  440. requestButton3 = TRUE;
  441. beginOK = FALSE;
  442. break;
  443. }
  444. return;
  445. }
  446. void processMou(unsigned char cGideiCode)
  447. {
  448. switch (cGideiCode) {
  449. case UNKNOWNCODE:
  450. handleErrorReport();
  451. commandVector = noOpRoutine;
  452. beginOK = TRUE;
  453. break;
  454. default:
  455. if (cGideiCode < LOWESTGIDEICODE) {
  456. handleErrorReport();
  457. commandVector = noOpRoutine;
  458. beginOK = TRUE;
  459. }
  460. else handleFatalError();
  461. }
  462. return;
  463. }