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.

471 lines
12 KiB

  1. /*===========================================================================*/
  2. /* Copyright (c) 1987 - 1988, Future Soft Engineering, Inc. */
  3. /* Houston, Texas */
  4. /*===========================================================================*/
  5. #define NOLSTRING TRUE /* jtf win3 mod */
  6. #include <windows.h>
  7. #include "port1632.h"
  8. #include "dcrc.h"
  9. #include "dynacomm.h"
  10. #include "task.h"
  11. /*---------------------------------------------------------------------------*/
  12. /* KEYBOARD REMAPPING ROUTINES (and DATA) [mbb] */
  13. /*---------------------------------------------------------------------------*/
  14. #define KEYMAP struct tagKeyMap
  15. #define LPKEYMAP KEYMAP FAR *
  16. struct tagKeyMap
  17. {
  18. BYTE scanCode[256];
  19. INT virtKey[8][256];
  20. WORD dataBytes;
  21. };
  22. HANDLE hKeyMap;
  23. VOID keyMapInit() /* mbbx 1.04: all new... */
  24. {
  25. hKeyMap = NULL;
  26. keyMapState = 0;
  27. }
  28. VOID keyMapCancel()
  29. {
  30. if(hKeyMap != NULL)
  31. hKeyMap = GlobalFree(hKeyMap);
  32. }
  33. BOOL NEAR keyMapSetState(WPARAM wParam)
  34. {
  35. keyMapState = 0;
  36. if(GetKeyState(VK_SHIFT) & 0x8000)
  37. keyMapState |= VKS_SHIFT;
  38. if(GetKeyState(VK_CONTROL) & 0x8000)
  39. keyMapState |= VKS_CTRL;
  40. if(GetKeyState(VK_MENU) & 0x8000)
  41. keyMapState |= VKS_ALT;
  42. keyMapState |= (keyMapState >> 8);
  43. return(((wParam >= VK_SHIFT) && (wParam <= VK_MENU)) ? TRUE : FALSE);
  44. }
  45. BOOL keyMapTranslate(WPARAM *wParam, LPARAM *lParam, STRING *mapStr)
  46. {
  47. BOOL keyMapTranslate = FALSE;
  48. LPKEYMAP lpKeyMap;
  49. WORD wVirtKey;
  50. LPINT lpVirtKey;
  51. LPSTR lpKeyData;
  52. if(hKeyMap == NULL)
  53. {
  54. keyMapSetState(*wParam);
  55. return(FALSE);
  56. }
  57. if((lpKeyMap = (LPKEYMAP) GlobalLock(hKeyMap)) == NULL)
  58. {
  59. return(FALSE);
  60. }
  61. if((wVirtKey = lpKeyMap->scanCode[(*lParam >> 16) & 0x00FF]) != 0)
  62. *wParam = wVirtKey;
  63. if(keyMapSetState(*wParam))
  64. return(FALSE);
  65. lpVirtKey = &lpKeyMap->virtKey[keyMapState >> 8][*wParam & 0x00FF];
  66. if(*lpVirtKey != -1)
  67. {
  68. if((*lpVirtKey & 0xF000) == 0xF000)
  69. {
  70. keyMapState = (*lpVirtKey & 0x0700) | (keyMapState & 0x00FF);
  71. *wParam = (*lpVirtKey & 0x00FF);
  72. }
  73. else
  74. {
  75. if(mapStr != NULL)
  76. {
  77. if(*lpVirtKey & 0x8000)
  78. {
  79. *mapStr = 1;
  80. mapStr[1] = (BYTE) *lpVirtKey;
  81. }
  82. else
  83. {
  84. lpKeyData = ((LPSTR) lpKeyMap) + sizeof(KEYMAP) + *lpVirtKey;
  85. lmovmem(lpKeyData, (LPSTR) mapStr, *lpKeyData+1);
  86. }
  87. mapStr[*mapStr+1] = 0;
  88. }
  89. keyMapTranslate = TRUE;
  90. }
  91. }
  92. GlobalUnlock(hKeyMap);
  93. return(keyMapTranslate);
  94. }
  95. //
  96. // Brain Dead mucking with our lParam values or CHARS
  97. // Causes TranslateMessage to fail. -JohnHall for WLO
  98. //
  99. VOID NEAR keyMapSendMsg(MSG *msg, WPARAM wParam, BOOL bKeyDown)
  100. {
  101. /*
  102. msg->message = (bKeyDown ? WM_KEYDOWN : WM_KEYUP);
  103. if(keyMapState & VKS_ALT)
  104. {
  105. msg->message += (WM_SYSKEYDOWN - WM_KEYDOWN);
  106. }
  107. TranslateMessage(msg);
  108. DefWindowProc(msg->hwnd, msg->message, msg->wParam, msg->lParam);
  109. */
  110. if (bKeyDown) {
  111. msg->message &= ~0x0001;
  112. } else {
  113. msg->message |= 0x0001;
  114. }
  115. TranslateMessage(msg);
  116. //DbgPrint("msg.msg %x msg.wparam %x msg.lparam %lx\n",
  117. // msg->message, msg->wParam, msg->lParam);
  118. DefWindowProc(msg->hwnd, msg->message, msg->wParam, msg->lParam);
  119. }
  120. VOID keyMapKeyProc(HWND hWnd, WORD message, WPARAM wParam, LPARAM lParam) // sdj: AltGr
  121. {
  122. BOOL bSetState;
  123. BYTE keyState[256], newKeyState[256];
  124. MSG msg;
  125. if(bSetState = ((keyMapState & (VKS_SHIFT | VKS_CTRL | VKS_ALT)) !=
  126. ((keyMapState << 8) & (VKS_SHIFT | VKS_CTRL | VKS_ALT))))
  127. {
  128. GetKeyboardState((LPSTR) keyState);
  129. memcpy(newKeyState, keyState, 256);
  130. newKeyState[VK_SHIFT] = (keyMapState & VKS_SHIFT) ? 0x81 : 0x00;
  131. newKeyState[VK_CONTROL] = (keyMapState & VKS_CTRL) ? 0x81 : 0x00;
  132. newKeyState[VK_MENU] = (keyMapState & VKS_ALT) ? 0x81 : 0x00;
  133. SetKeyboardState((LPSTR) newKeyState);
  134. }
  135. msg.hwnd = hWnd;
  136. msg.wParam = wParam;
  137. msg.lParam = lParam;
  138. msg.message = message; //sdj AltGr
  139. keyMapSendMsg(&msg, wParam, (lParam & (1L << 31)) ? FALSE : TRUE);
  140. if(bSetState)
  141. SetKeyboardState((LPSTR) keyState);
  142. }
  143. BOOL keyMapSysKey(HWND hWnd, WORD message, WPARAM *wParam, LPARAM lParam) //sdj: AltGr
  144. {
  145. MSG msg;
  146. if((*wParam >= VK_SHIFT) && (*wParam <= VK_MENU))
  147. {
  148. msg.hwnd = hItWnd;
  149. msg.wParam = *wParam;
  150. msg.lParam = lParam;
  151. msg.message = message; //sdj: AltGr
  152. keyMapSendMsg(&msg, *wParam, (lParam & (1L << 31)) ? FALSE : TRUE);
  153. return(TRUE);
  154. }
  155. if(keyMapState & VKS_CTRL)
  156. {
  157. /* jtf 3.30 if(*wParam == VK_TAB)
  158. {
  159. return(TRUE);
  160. }
  161. else */
  162. if((*wParam >= VK_F1) && (*wParam <= VK_F10))
  163. {
  164. if(!(lParam & (1L << 31)))
  165. {
  166. if(keyMapState & VKS_ALT)
  167. selectFKey(IDFK1+((UINT)*wParam-VK_F1));
  168. /* jtf 3.30 else if(hWnd != hItWnd)
  169. {
  170. switch(*wParam)
  171. {
  172. case VK_F4:
  173. *wParam = SC_CLOSE;
  174. break;
  175. case VK_F5:
  176. *wParam = SC_RESTORE;
  177. break;
  178. case VK_F6:
  179. makeActiveNext(keyMapState & VKS_SHIFT);
  180. return(TRUE);
  181. case VK_F7:
  182. *wParam = SC_MOVE;
  183. break;
  184. case VK_F8:
  185. *wParam = SC_SIZE;
  186. break;
  187. case VK_F10:
  188. *wParam = SC_MAXIMIZE;
  189. break;
  190. }
  191. SendMessage(hWnd, WM_SYSCOMMAND, *wParam, 0L);
  192. }
  193. */
  194. }
  195. return(TRUE);
  196. }
  197. }
  198. else
  199. if(keyMapState & VKS_ALT)
  200. {
  201. switch(*wParam)
  202. {
  203. case VK_BACK: /* ALT BACK -> UNDO */
  204. keyMapKeyProc(hWnd, message , *wParam, lParam); //sdj: AltGr
  205. return(TRUE);
  206. case VK_F1:
  207. case VK_F2:
  208. *wParam += 10;
  209. keyMapState &= ~VKS_ALT;
  210. break;
  211. case VK_F4:
  212. case VK_F5:
  213. case VK_F6:
  214. case VK_F7:
  215. case VK_F8:
  216. case VK_F9:
  217. case VK_F10:
  218. DefWindowProc(hItWnd, !(lParam & (1L << 31)) ? WM_SYSKEYDOWN : WM_SYSKEYUP, *wParam, lParam);
  219. return(TRUE);
  220. default:
  221. keyMapKeyProc(hItWnd, message, *wParam, lParam); // sdj: AltGr
  222. return(TRUE);
  223. }
  224. }
  225. return(FALSE);
  226. }
  227. /*---------------------------------------------------------------------------*/
  228. /* classifyKey() - [mbb] */
  229. /*---------------------------------------------------------------------------*/
  230. #define TKS_IDPGUP 0 /* mbbx 2.00 ... */
  231. #define TKS_IDLEFT 4
  232. #define TKS_IDINSERT 8
  233. #define TKS_IDNUMERIC0 10
  234. #define TKS_IDF1 26
  235. #define TKS_IDSHIFTF1 38
  236. INT classifyKey(WORD vrtKey)
  237. {
  238. INT classifyKey = TERMINALFKEY;
  239. switch(vrtKey)
  240. {
  241. case VK_CANCEL:
  242. if(keyMapState & VKS_CTRL)
  243. classifyKey = ((keyMapState & VKS_SHIFT) ? LONGBREAK : SHORTBREAK);
  244. else
  245. classifyKey = STANDARDKEY;
  246. break;
  247. case VK_PRIOR:
  248. case VK_NEXT:
  249. case VK_END:
  250. case VK_HOME:
  251. case VK_LEFT:
  252. case VK_UP:
  253. case VK_RIGHT:
  254. case VK_DOWN:
  255. /* rjs - add test for trmParams.useWinCtrl */
  256. if(!((GetKeyState(0x91) & 0x0001) || trmParams.useWinCtrl))
  257. seqTableNdx = (vrtKey - VK_PRIOR) + TKS_IDPGUP;
  258. else
  259. classifyKey = SCROLLKEY;
  260. break;
  261. case VK_SELECT:
  262. seqTableNdx = (VK_END - VK_PRIOR) + TKS_IDPGUP;
  263. break;
  264. case VK_INSERT:
  265. classifyKey = (!(keyMapState & (VKS_CTRL | VKS_SHIFT)) ? TERMINALFKEY : STANDARDKEY);
  266. seqTableNdx = TKS_IDINSERT;
  267. break;
  268. case VK_DELETE:
  269. classifyKey = (!(keyMapState & VKS_SHIFT) ? TERMINALFKEY : STANDARDKEY);
  270. seqTableNdx = (VK_DELETE - VK_INSERT) + TKS_IDINSERT;
  271. break;
  272. case VK_NUMPAD0:
  273. case VK_NUMPAD1:
  274. case VK_NUMPAD2:
  275. case VK_NUMPAD3:
  276. case VK_NUMPAD4:
  277. case VK_NUMPAD5:
  278. case VK_NUMPAD6:
  279. case VK_NUMPAD7:
  280. case VK_NUMPAD8:
  281. case VK_NUMPAD9:
  282. case VK_MULTIPLY:
  283. case VK_ADD:
  284. case VK_SEPARATOR:
  285. case VK_SUBTRACT:
  286. case VK_DECIMAL:
  287. case VK_DIVIDE:
  288. seqTableNdx = (vrtKey - VK_NUMPAD0) + TKS_IDNUMERIC0;
  289. break;
  290. case VK_F1:
  291. case VK_F2:
  292. case VK_F3:
  293. case VK_F4:
  294. case VK_F5:
  295. case VK_F6:
  296. case VK_F7:
  297. case VK_F8:
  298. case VK_F9:
  299. case VK_F10:
  300. case VK_F11:
  301. case VK_F12:
  302. /* rjs - add test for trmParams.useWinCtrl */
  303. if(!((GetKeyState(0x91) & 0x0001) || trmParams.useWinCtrl))
  304. {
  305. if (vrtKey==VK_F1)
  306. doCommand(hTermWnd, HMINDEX, 0);
  307. classifyKey = STANDARDKEY;
  308. break;
  309. }
  310. seqTableNdx = (vrtKey - VK_F1) + (!(keyMapState & VKS_SHIFT) ? TKS_IDF1 : TKS_IDSHIFTF1);
  311. break;
  312. case VK_F13:
  313. case VK_F14:
  314. case VK_F15:
  315. case VK_F16:
  316. seqTableNdx = (vrtKey - VK_F13) + TKS_IDSHIFTF1;
  317. break;
  318. default:
  319. classifyKey = STANDARDKEY;
  320. break;
  321. }
  322. return(classifyKey);
  323. }
  324. /*---------------------------------------------------------------------------*/
  325. /* keyPadSequence() - [mbb] */
  326. /*---------------------------------------------------------------------------*/
  327. BOOL keyPadSequence()
  328. {
  329. INT ndx;
  330. LPBYTE emulKeyBase;
  331. BYTE keyPadByte;
  332. if(!(emulKeyBase = GlobalLock(hemulKeyInfo)))
  333. return(FALSE);
  334. emulKeyBase += (seqTableNdx * KEYSEQLEN);
  335. *keyPadString = 0;
  336. for(ndx = 0; *(emulKeyBase + ndx) != 0; ndx++)
  337. keyPadString[++(*keyPadString)] = *(emulKeyBase + ndx);
  338. GlobalUnlock(hemulKeyInfo);
  339. if((trmParams.emulate >= ITMVT52) && (trmParams.emulate <= ITMVT220))
  340. {
  341. if(((seqTableNdx >= TKS_IDLEFT) && (seqTableNdx < TKS_IDINSERT)) && cursorKeyMode)
  342. {
  343. switch(trmParams.emulate)
  344. {
  345. case ITMVT100:
  346. keyPadString[2] = 0x4F;
  347. break;
  348. }
  349. }
  350. else if(((seqTableNdx >= TKS_IDNUMERIC0) && (seqTableNdx < TKS_IDF1)) && !keyPadAppMode)
  351. {
  352. switch(seqTableNdx)
  353. {
  354. case TKS_IDNUMERIC0+10:
  355. keyPadByte = '-';
  356. break;
  357. case TKS_IDNUMERIC0+11:
  358. keyPadByte = CR;
  359. break;
  360. case TKS_IDNUMERIC0+12:
  361. keyPadByte = ' ';
  362. break;
  363. case TKS_IDNUMERIC0+13:
  364. keyPadByte = ',';
  365. break;
  366. case TKS_IDNUMERIC0+14:
  367. keyPadByte = '.';
  368. break;
  369. case TKS_IDNUMERIC0+15:
  370. keyPadByte = ' ';
  371. break;
  372. default:
  373. keyPadByte = (seqTableNdx - TKS_IDNUMERIC0) + '0';
  374. break;
  375. }
  376. keyPadString[*keyPadString = 1] = keyPadByte;
  377. }
  378. }
  379. return(TRUE);
  380. }
  381. /*---------------------------------------------------------------------------*/
  382. /* sendKeyInput() - [mbb] */
  383. /*---------------------------------------------------------------------------*/
  384. BOOL sendKeyInput(BYTE theByte)
  385. {
  386. switch(kbdLock)
  387. {
  388. case KBD_ECHO:
  389. modemInp(theByte, FALSE); /* mbbx 1.10 */
  390. break;
  391. default:
  392. modemWr(theByte);
  393. break;
  394. }
  395. return(TRUE);
  396. }