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.

538 lines
17 KiB

  1. /*===========================================================================*/
  2. /* Copyright (c) 1985 - 1986, 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. WORD fDisableMoreCtrl;
  12. /*---------------------------------------------------------------------------*/
  13. /* dbmyControls() - Function keys dialog box message processor. [mbb] */
  14. /*---------------------------------------------------------------------------*/
  15. INT_PTR APIENTRY dbmyControls(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  16. {
  17. BOOL result = FALSE;
  18. RECT clipRect;
  19. WORD wTemp;
  20. switch(message)
  21. {
  22. case WM_ACTIVATE:
  23. result = GET_WM_ACTIVATE_STATE(wParam, lParam);
  24. break;
  25. case WM_ERASEBKGND: /* mbbx 2.00: dlg & ctrl bkgd... */
  26. GetClipBox((HDC) wParam, &clipRect);
  27. FillRect((HDC) wParam, &clipRect, (HBRUSH) GetStockObject(GRAY_BRUSH));
  28. return(TRUE);
  29. case WM_CTLCOLOR:
  30. return((INT_PTR) GetStockObject(HOLLOW_BRUSH));
  31. case WM_COMMAND:
  32. switch(GET_WM_COMMAND_ID(wParam, lParam))
  33. {
  34. case IDSTOP: /* mbbx 2.00: xfer ctrls... */
  35. if(result = updateFKeyButton(wParam, lParam, FKB_UPDATE_BKGD))
  36. xferStopBreak(!xferBreak);
  37. break;
  38. case IDPAUSE: /* mbbx 2.00: xfer ctrls... */
  39. if(result = updateFKeyButton(wParam,lParam, FKB_UPDATE_BKGD))
  40. xferPauseResume(!xferPaused, xferPaused);
  41. break;
  42. case IDFK1:
  43. case IDFK2:
  44. case IDFK3:
  45. case IDFK4:
  46. case IDFK5:
  47. case IDFK6:
  48. case IDFK7:
  49. case IDFK8:
  50. #ifdef ORGCODE
  51. if(result = updateFKeyButton(lParam, FKB_UPDATE_BKGD |
  52. ((*trmParams.fKeyText[curLevel-1][wParam-IDFK1] != 0) ? 0 : FKB_DISABLE_CTRL)))
  53. #else
  54. wTemp = GET_WM_COMMAND_ID(wParam,lParam);
  55. if(result = updateFKeyButton(wParam, lParam,
  56. FKB_UPDATE_BKGD |
  57. ((*trmParams.fKeyText[curLevel-1][wTemp-IDFK1] != 0) ? 0 : FKB_DISABLE_CTRL)))
  58. #endif
  59. {
  60. selectFKey((UINT)wParam);
  61. }
  62. break;
  63. case IDMORE:
  64. case IDFK9:
  65. #ifdef ORGCODE
  66. if(result = updateFKeyButton(lParam, FKB_UPDATE_BKGD | fDisableMoreCtrl)) /* mbbx 2.00: fkeys */
  67. #else
  68. if(result = updateFKeyButton(wParam, lParam, FKB_UPDATE_BKGD | fDisableMoreCtrl)) /* mbbx 2.00: fkeys */
  69. #endif
  70. setFKeyLevel(-1, FALSE); /* mbbx 2.00: bReset */
  71. break;
  72. case IDTIMER:
  73. case IDFK10:
  74. #ifdef ORGCODE
  75. if(result = updateFKeyButton(lParam, FKB_UPDATE_BKGD | FKB_UPDATE_TIMER)) /* mbbx 2.00: fkeys */
  76. #else
  77. if(result = updateFKeyButton(wParam, lParam, FKB_UPDATE_BKGD | FKB_UPDATE_TIMER)) /* mbbx 2.00: fkeys */
  78. #endif
  79. timerToggle(FALSE); /* mbbx 1.03 */
  80. break;
  81. }
  82. if(result && (hDlg == hdbXferCtrls))
  83. BringWindowToTop(hTermWnd);
  84. break;
  85. }
  86. if(result)
  87. selectTopWindow();
  88. return(result);
  89. }
  90. /*---------------------------------------------------------------------------*/
  91. /* updateFKeyButton() - [mbb] */
  92. /*---------------------------------------------------------------------------*/
  93. BOOL fKeyStrBuffer(BYTE *str, WORD len)
  94. {
  95. if(fKeyNdx > *fKeyStr)
  96. {
  97. if(len == 1)
  98. return(sendKeyInput(*str));
  99. memcpy(fKeyStr+1, str, *fKeyStr = (BYTE)len);
  100. fKeyNdx = 1;
  101. return(TRUE);
  102. }
  103. if(fKeyNdx > 1)
  104. {
  105. memcpy(fKeyStr+1, fKeyStr+fKeyNdx, (*fKeyStr+1)-fKeyNdx);
  106. *fKeyStr -= (fKeyNdx-1);
  107. fKeyNdx = 1;
  108. }
  109. if(*fKeyStr+len >= STR255-1)
  110. return(FALSE);
  111. memcpy(fKeyStr+(*fKeyStr+1), str, len);
  112. *fKeyStr += len;
  113. return(TRUE);
  114. }
  115. void selectFKey(UINT wIDFKey)
  116. //WORD wIDFKey;
  117. {
  118. fKeyStrBuffer(trmParams.fKeyText[curLevel-1][wIDFKey-IDFK1],
  119. strlen(trmParams.fKeyText[curLevel-1][wIDFKey-IDFK1]));
  120. }
  121. /*---------------------------------------------------------------------------*/
  122. /* setFKeyTitles() - [mbb] */
  123. /*---------------------------------------------------------------------------*/
  124. VOID setFKeyTitles()
  125. {
  126. INT ndx;
  127. BYTE str[STR255];
  128. CHAR szBuffer[16];
  129. DEBOUT("setKKeyTitles: curLevel = %d\n",curLevel);
  130. DEBOUT("setKKeyTitles:%s\n","SetWindowText BUG? check this out, HACK return");
  131. for(ndx = 0; ndx < DCS_NUMFKEYS; ndx += 1)
  132. {
  133. DEBOUT("setFKeyTitles: fKH[ndx]=%lx\n",fKeyHandles[ndx]);
  134. DEBOUT("setFKeyTitles: fKT[curlevel-1][ndx]=%s\n",(LPSTR) trmParams.fKeyTitle[curLevel-1][ndx]);
  135. SetWindowText(fKeyHandles[ndx], (LPSTR) trmParams.fKeyTitle[curLevel-1][ndx]);
  136. }
  137. if(*trmParams.fKeyNext == 0)
  138. {
  139. LoadString(hInst, STR_LEVEL, szBuffer, 15);
  140. sprintf(str, szBuffer, curLevel);
  141. }
  142. else
  143. strcpy(str, trmParams.fKeyNext);
  144. SetWindowText(GetDlgItem(hdbmyControls, IDMORE), (LPSTR) str);
  145. }
  146. /*---------------------------------------------------------------------------*/
  147. /* testFkeyLevel() - [mbb] */
  148. /*---------------------------------------------------------------------------*/
  149. BOOL NEAR testFKeyLevel(INT level)
  150. //INT level;
  151. {
  152. INT ndx;
  153. for(ndx = 0; ndx < DCS_NUMFKEYS; ndx += 1)
  154. if((*trmParams.fKeyTitle[level][ndx] != 0) || (*trmParams.fKeyText[level][ndx] != 0))
  155. return(TRUE);
  156. return(FALSE);
  157. }
  158. /*---------------------------------------------------------------------------*/
  159. /* nextFkeyLevel() - [mbb] */
  160. /*---------------------------------------------------------------------------*/
  161. INT NEAR nextFKeyLevel(INT level)
  162. {
  163. INT ndx;
  164. for(ndx = 0; ndx < DCS_FKEYLEVELS; ndx += 1)
  165. {
  166. if(level >= DCS_FKEYLEVELS)
  167. level = 0;
  168. if(testFKeyLevel(level++))
  169. return(level);
  170. }
  171. return(FALSE);
  172. }
  173. /*---------------------------------------------------------------------------*/
  174. /* setFKeyLevel() - [mbb] */
  175. /*---------------------------------------------------------------------------*/
  176. VOID setFKeyLevel(INT newLevel, BOOL bReset)
  177. {
  178. if(newLevel == -1)
  179. newLevel = nextFKeyLevel(curLevel);
  180. if((newLevel < 1) || (newLevel > DCS_FKEYLEVELS))
  181. newLevel = bReset ? 1 : curLevel;
  182. if(bReset || (newLevel != curLevel))
  183. {
  184. fDisableMoreCtrl = ((newLevel = nextFKeyLevel(curLevel = newLevel)) &&
  185. (newLevel != curLevel)) ? 0 : FKB_DISABLE_CTRL;
  186. setFKeyTitles();
  187. }
  188. }
  189. /*---------------------------------------------------------------------------*/
  190. /* timerAction() - [mbb] */
  191. /*---------------------------------------------------------------------------*/
  192. VOID timerAction(BOOL bTimer, BOOL bReset)
  193. {
  194. DWORD tickCount;
  195. if(bTimer != timerActiv)
  196. {
  197. CheckMenuItem(hMenu, FMTIMER, timerActiv = bTimer ? MF_CHECKED : MF_UNCHECKED);
  198. PostMessage(hdbmyControls, WM_COMMAND, GET_WM_COMMAND_MPS(IDTIMER, GetDlgItem(hdbmyControls, IDTIMER), BN_PAINT));
  199. }
  200. if(bReset)
  201. readDateTime(startTimer);
  202. }
  203. /*---------------------------------------------------------------------------*/
  204. /* timerToggle() - [mbb] */
  205. /*---------------------------------------------------------------------------*/
  206. VOID timerToggle(BOOL bReset)
  207. {
  208. timerAction(!timerActiv, bReset);
  209. }
  210. /*---------------------------------------------------------------------------*/
  211. /* sizeFkeys() - Resize fkeys dialog [mbb] */
  212. /*---------------------------------------------------------------------------*/
  213. VOID sizeFkeys(LONG clientSize)
  214. {
  215. RECT fKeysRect, fCtrlRect;
  216. GetWindowRect(hdbmyControls, (LPRECT) &fKeysRect);
  217. /* --------------------------------------------------------------
  218. if ((HIWORD(clientSize) - fKeysRect.bottom) < 0) jtf 3.15
  219. clientSize = (LOWORD(clientSize),fKeysRect.bottom);
  220. -------------------------------------------------------------- */
  221. fKeysRect.top += (HIWORD(clientSize) - fKeysRect.bottom);
  222. MoveWindow(hdbmyControls, 0, fKeysRect.top,
  223. LOWORD(clientSize), HIWORD(clientSize) - fKeysRect.top, TRUE);
  224. GetWindowRect(fKeyHandles[1], (LPRECT) &fKeysRect);
  225. GetWindowRect(fKeyHandles[2], (LPRECT) &fCtrlRect);
  226. fKeysRect.left = fCtrlRect.left - fKeysRect.right;
  227. fKeysRect.top -= fCtrlRect.bottom;
  228. fCtrlRect.left = 0;
  229. fCtrlRect.bottom -= fCtrlRect.top;
  230. fCtrlRect.right = (LOWORD(clientSize) / ((DCS_NUMFKEYS/2)+1));
  231. for(fCtrlRect.top = 0; fCtrlRect.top < DCS_NUMFKEYS; fCtrlRect.top += 2)
  232. {
  233. MoveWindow(fKeyHandles[fCtrlRect.top], fCtrlRect.left, 0,
  234. fCtrlRect.right, fCtrlRect.bottom, TRUE);
  235. MoveWindow(fKeyHandles[fCtrlRect.top+1], fCtrlRect.left, fCtrlRect.bottom + fKeysRect.top,
  236. fCtrlRect.right, fCtrlRect.bottom, TRUE);
  237. fCtrlRect.left += (fCtrlRect.right + fKeysRect.left);
  238. }
  239. fCtrlRect.right = LOWORD(clientSize) - fCtrlRect.left;
  240. MoveWindow(GetDlgItem(hdbmyControls, IDMORE), fCtrlRect.left, 0,
  241. fCtrlRect.right, fCtrlRect.bottom, TRUE);
  242. MoveWindow(GetDlgItem(hdbmyControls, IDTIMER), fCtrlRect.left, fCtrlRect.bottom + fKeysRect.top,
  243. fCtrlRect.right, fCtrlRect.bottom, TRUE);
  244. }
  245. /*---------------------------------------------------------------------------*/
  246. /* initChildSize() - [mbb] */
  247. /*---------------------------------------------------------------------------*/
  248. VOID initChildSize(RECT *pRect)
  249. {
  250. if(IsIconic(hItWnd))
  251. {
  252. SetRectEmpty((LPRECT) pRect);
  253. pRect->right = GetSystemMetrics(SM_CXSCREEN);
  254. pRect->bottom = GetSystemMetrics(SM_CYSCREEN) - GetSystemMetrics(SM_CYCAPTION) -
  255. GetSystemMetrics(SM_CYMENU);
  256. }
  257. else
  258. {
  259. GetClientRect(hItWnd, (LPRECT) pRect);
  260. if(IsWindowVisible(hdbmyControls)) /* mbbx 1.04: fkeys... */
  261. pRect->bottom -= fKeysHeight;
  262. }
  263. }
  264. /*---------------------------------------------------------------------------*/
  265. /* childZoomSize() - [mbb] */
  266. /*---------------------------------------------------------------------------*/
  267. BOOL bZoomFlag = FALSE; /* prevents recursive calls */
  268. /*---------------------------------------------------------------------------*/
  269. /* childWindowZoom() - [mbb] */
  270. /*---------------------------------------------------------------------------*/
  271. #define ZC_NOTZOOMED 0x0000
  272. #define ZC_ZOOMED 0x0001
  273. #define ZC_ZOOMNEXT 0x4000
  274. #define ZC_NORESTORE 0x8000
  275. WORD fZoomChild = ZC_NOTZOOMED;
  276. WORD childZoomStatus(WORD wTest, WORD wSet)
  277. {
  278. WORD childZoomStatus = (fZoomChild & wTest);
  279. fZoomChild |= wSet;
  280. return(childZoomStatus);
  281. }
  282. VOID setAppTitle()
  283. {
  284. BYTE work[STR255];
  285. strcpy(work, szMessage);
  286. strcpy(work+strlen(work), " - ");
  287. GetWindowText(hTermWnd, (LPSTR) work+strlen(work), 80);
  288. SetWindowText(hItWnd, (LPSTR) work);
  289. }
  290. /*---------------------------------------------------------------------------*/
  291. /* sizeTerm() - Resize terminal window [mbb] */
  292. /*---------------------------------------------------------------------------*/
  293. VOID sizeTerm(LONG termSize)
  294. {
  295. RECT termRect, ctrlRect;
  296. GetClientRect(hItWnd, (LPRECT) &termRect);
  297. if(IsWindowVisible(hdbmyControls))
  298. termRect.bottom -= fKeysHeight;
  299. MoveWindow(hTermWnd, 0, 0, termRect.right,termRect.bottom,TRUE);
  300. GetClientRect(hTermWnd, (LPRECT) &termRect);
  301. CopyRect((LPRECT) &statusRect, (LPRECT) &termRect);
  302. statusRect.top = termRect.bottom - (chrHeight + STATUSRECTBORDER);
  303. CopyRect((LPRECT) &ctrlRect, (LPRECT) &statusRect);
  304. if((ctrlRect.bottom - ctrlRect.top) < ctrlsHeight)
  305. ctrlRect.top = termRect.bottom - ctrlsHeight;
  306. MoveWindow(hdbXferCtrls, 0, ctrlRect.top, ctrlRect.right - ctrlRect.left,
  307. ctrlRect.bottom - ctrlRect.top, FALSE);
  308. updateIndicators();
  309. if(chrHeight != 0)
  310. visScreenLine = (ctrlRect.top / chrHeight) - 1;
  311. CopyRect((LPRECT) &hTE.viewRect, (LPRECT) &termRect);
  312. hTE.viewRect.bottom = (visScreenLine + 1) * chrHeight;
  313. curTopLine = min(curTopLine, savTopLine + maxScreenLine - visScreenLine);
  314. if (curTopLine < 0)
  315. curTopLine = 0;
  316. if((nScrollRange.x = maxChars - (termRect.right / chrWidth)) < 0)
  317. nScrollRange.x = 0;
  318. if(nScrollPos.x > nScrollRange.x)
  319. nScrollPos.x = nScrollRange.x;
  320. updateTermScrollBars(TRUE);
  321. InvalidateRect(hTermWnd, NULL, FALSE); /* rjs swat - was TRUE */
  322. UpdateWindow(hTermWnd);
  323. }
  324. /*---------------------------------------------------------------------------*/
  325. /* countChildWindows() - [mbb] */
  326. /*---------------------------------------------------------------------------*/
  327. INT countChildWindows(BOOL bUnzoom)
  328. {
  329. INT nWndCount = 0;
  330. HWND hNextWnd;
  331. hNextWnd = hdbmyControls; /* mbb?: reasonable assumption? */
  332. while((hNextWnd = GetNextWindow(hNextWnd, GW_HWNDPREV)) != NULL)
  333. if(IsWindowVisible(hNextWnd))
  334. nWndCount++;
  335. if(bUnzoom && IsZoomed(hNextWnd = GetTopWindow(hItWnd))) /* AFTER count!!! */
  336. ShowWindow(hNextWnd, SW_RESTORE);
  337. return(nWndCount);
  338. }
  339. /*---------------------------------------------------------------------------*/
  340. /* showTerminal() - [mbb] */
  341. /*---------------------------------------------------------------------------*/
  342. VOID showTerminal(BOOL bShow, BOOL bReset)
  343. {
  344. if((bShow != (!(termData.flags & TF_HIDE) ? TRUE : FALSE)) || bReset)
  345. {
  346. if(bShow)
  347. {
  348. termData.flags &= ~TF_HIDE;
  349. if(activTerm)
  350. {
  351. SetWindowPos(hTermWnd, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_SHOWWINDOW);
  352. SetFocus(hTermWnd);
  353. }
  354. }
  355. else
  356. {
  357. termData.flags |= TF_HIDE;
  358. if(activTerm)
  359. {
  360. if(childZoomStatus(ZC_ZOOMED, 0) && (countChildWindows(FALSE) == 1))
  361. {
  362. childZoomStatus(0, ZC_ZOOMNEXT);
  363. ShowWindow(hTermWnd, SW_RESTORE);
  364. }
  365. /* typecasted the 2nd param to HWND -sdj*/
  366. SetWindowPos(hTermWnd,(HWND) 1, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_HIDEWINDOW);
  367. selectTopWindow(); /* mbbx 1.03 ... */
  368. }
  369. }
  370. }
  371. }
  372. /*---------------------------------------------------------------------------*/
  373. /* showHidedbmyControls() - */
  374. /*---------------------------------------------------------------------------*/
  375. VOID showHidedbmyControls(BOOL bShow, BOOL bArrange)
  376. {
  377. BYTE strShowHide[TMPNSTR+1];
  378. if(bShow != fKeysShown)
  379. {
  380. if(fKeysShown = bShow)
  381. {
  382. ShowWindow(hdbmyControls, SW_SHOW);
  383. LoadString(hInst, STR_HIDEFKEYS, (LPSTR) strShowHide, TMPNSTR);
  384. ChangeMenu(hMenu, WMFKEYS, (LPSTR) strShowHide, WMFKEYS, MF_CHANGE);
  385. }
  386. else
  387. {
  388. ShowWindow(hdbmyControls, SW_HIDE);
  389. LoadString(hInst, STR_SHOWFKEYS, (LPSTR) strShowHide, TMPNSTR);
  390. ChangeMenu(hMenu, WMFKEYS, (LPSTR) strShowHide, WMFKEYS, MF_CHANGE);
  391. }
  392. if(!IsIconic(hItWnd)) /* rjs bugs 015 */
  393. sizeTerm(0L); /* jtf 3.21 */
  394. // make sure hTermWnd gets cleaned so there's no
  395. // garbage left on hTermWnd.
  396. InvalidateRect (hTermWnd, NULL, TRUE);
  397. UpdateWindow (hTermWnd);
  398. }
  399. }
  400. /*---------------------------------------------------------------------------*/
  401. /* makeActiveNext() - [mbb] */
  402. /*---------------------------------------------------------------------------*/
  403. VOID makeActiveNext(BOOL bPrevWnd)
  404. {
  405. HWND hNextWnd, hTopWnd;
  406. if((hNextWnd = GetNextWindow(hdbmyControls, GW_HWNDPREV)) != (hTopWnd = GetTopWindow(hItWnd)))
  407. {
  408. if(childZoomStatus(ZC_ZOOMED, 0))
  409. {
  410. childZoomStatus(0, ZC_NORESTORE);
  411. ShowWindow(hTopWnd, SW_RESTORE);
  412. }
  413. if(bPrevWnd)
  414. BringWindowToTop(hNextWnd);
  415. else
  416. {
  417. SetWindowPos(hTopWnd, hNextWnd, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
  418. hNextWnd = GetTopWindow(hItWnd);
  419. }
  420. SetFocus(hNextWnd);
  421. }
  422. }