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.

496 lines
16 KiB

  1. /*===========================================================================*/
  2. /* Copyright (c) 1987 - 1988, Future Soft Engineering, Inc. */
  3. /* Houston, Texas */
  4. /*===========================================================================*/
  5. #define NOGDICAPMASKS TRUE
  6. #define NOVIRTUALKEYCODES TRUE
  7. #define NOICONS TRUE
  8. #define NOKEYSTATES TRUE
  9. #define NOSYSCOMMANDS TRUE
  10. #define NOATOM TRUE
  11. #define NODRAWTEXT TRUE
  12. #define NOMINMAX TRUE
  13. #define NOOPENFILE TRUE
  14. #define NOSCROLL TRUE
  15. #define NOPROFILER TRUE
  16. #define NODEFERWINDOWPOS TRUE
  17. #define NOPEN TRUE
  18. #define NO_TASK_DEFINES TRUE
  19. #define NOLSTRING TRUE
  20. #define WIN31
  21. #include <stdarg.h>
  22. #include <windows.h>
  23. #include <shellapi.h>
  24. #include "port1632.h"
  25. #include "dcrc.h"
  26. #include "dynacomm.h"
  27. #include "task.h"
  28. #include "printfil.h"
  29. #include <commdlg.h>
  30. #include <cderr.h>
  31. /*---------------------------------------------------------------------------*/
  32. /* enableMenuList() - [mbb] */
  33. /*---------------------------------------------------------------------------*/
  34. VOID enableMenuList(HMENU hAppMenu,BOOL bEnable, ...)
  35. {
  36. va_list ap;
  37. INT ndx;
  38. UINT miList;
  39. HMENU hSubMenu;
  40. va_start(ap,bEnable);
  41. for(miList = va_arg(ap,UINT); miList; miList = va_arg(ap,UINT))
  42. {
  43. if(miList & 0x8000)
  44. {
  45. miList &= 0x000F;
  46. if(childZoomStatus(0x0001, 0))
  47. miList += 1;
  48. hSubMenu = GetSubMenu(hAppMenu, miList);
  49. for(ndx = GetMenuItemCount(hSubMenu)-1; ndx >= 0; ndx -= 1)
  50. EnableMenuItem(hSubMenu, ndx, (bEnable ? MF_ENABLED : MF_GRAYED) | MF_BYPOSITION);
  51. }
  52. else
  53. EnableMenuItem(hAppMenu, miList, bEnable ? MF_ENABLED : MF_GRAYED);
  54. }
  55. va_end(ap);
  56. }
  57. /*---------------------------------------------------------------------------*/
  58. /* initMenuPopup() - [mbb] */
  59. /*---------------------------------------------------------------------------*/
  60. VOID initMenuPopup(WORD menuIndex)
  61. {
  62. HMENU hAppMenu;
  63. WORD systemIndex;
  64. if(childZoomStatus(0x0001, 0))
  65. menuIndex -= 1;
  66. hAppMenu = hMenu;
  67. systemIndex = menuIndex;
  68. switch(menuIndex)
  69. {
  70. case FILEMENU:
  71. enableMenuList(hAppMenu, countChildWindows(FALSE), FMCLOSE, FMSAVE, FMSAVEAS, NULL);
  72. enableMenuList(hAppMenu, TRUE, FMPRINT, FMPRINTSETUP, NULL);
  73. enableMenuList(hAppMenu, (hPrintFile==NULL), FMPRINTSETUP, FMPRINTSETUP, NULL); /* jtf 3.20 check to see if chanel open */
  74. break;
  75. case EDITMENU:
  76. if(GetTopWindow(hItWnd) == hTermWnd)
  77. {
  78. enableMenuList(hAppMenu, TRUE, EMSELECTALL, EMCLEAR, NULL);
  79. enableMenuList(hAppMenu, (hTE.selStart != hTE.selEnd), EMCOPY, EMCOPYTHENPASTE, EMCOPYSPECIAL, NULL);
  80. enableMenuList(hAppMenu, IsClipboardFormatAvailable(CF_TEXT), EMPASTE, NULL);
  81. if (scrapSeq || ((xferFlag != XFRNONE) && (xferFlag != XFRRCV)) ) /* jtf 3.17 disable send if in transfer */
  82. {
  83. enableMenuList(hAppMenu, FALSE, EMCOPYTHENPASTE, NULL);
  84. enableMenuList(hAppMenu, FALSE, EMPASTE, NULL);
  85. enableMenuList(hAppMenu, FALSE, EMSELECTALL, NULL);
  86. enableMenuList(hAppMenu, FALSE, EMCOPY, NULL);
  87. }
  88. enableMenuList(hAppMenu, (curTopLine >= savTopLine), EMSAVESCREEN, NULL);
  89. }
  90. else
  91. enableMenuList(hAppMenu, FALSE, 0x8000 | systemIndex, NULL);
  92. break;
  93. case SETTINGSMENU:
  94. enableMenuList(hAppMenu, activTerm, SMPHONE, SMEMULATE, SMTERMINAL, SMFUNCTIONKEYS, SMMODEM, NULL);
  95. enableMenuList(hAppMenu, activTerm && (xferFlag == XFRNONE), SMTEXTXFERS, SMBINXFERS, SMCOMMUNICATIONS, NULL);
  96. break;
  97. case PHONEMENU: /* mbbx 2.00: network... */
  98. if((trmParams.comDevRef > ITMNOCOM) && (xferFlag == XFRNONE)) /* mbbx 1.10: carrier... */
  99. {
  100. enableMenuList(hAppMenu, TRUE, 0x8000 | systemIndex, NULL);
  101. enableMenuList(hAppMenu, !mdmOnLine, PMDIAL, NULL);
  102. }
  103. else
  104. enableMenuList(hAppMenu, FALSE, 0x8000 | systemIndex, NULL);
  105. break;
  106. case TRANSFERMENU:
  107. /* mbbx 1.10: answerMode... */
  108. enableMenuList(hAppMenu, (trmParams.comDevRef > ITMNOCOM) && (xferFlag == XFRNONE), /* mbbx 2.00: network... */
  109. TMSENDTEXTFILE, TMRCVTEXTFILE, NULL);
  110. enableMenuList(hAppMenu, (trmParams.comDevRef > ITMNOCOM) && (xferFlag == XFRNONE) && !answerMode,
  111. TMSENDBINFILE, TMRCVBINFILE, NULL);
  112. enableMenuList(hAppMenu, activTerm && (xferFlag == XFRNONE), TMVIEWTEXTFILE, NULL);
  113. enableMenuList(hAppMenu, (xferFlag > XFRNONE) && (xferFlag < XFRBSND) && !xferPaused, TMPAUSE, NULL);
  114. enableMenuList(hAppMenu, (xferFlag > XFRNONE) && (xferFlag < XFRBSND) && xferPaused, TMRESUME, NULL);
  115. enableMenuList(hAppMenu, (xferFlag > XFRNONE), TMSTOP, NULL);
  116. if (scrapSeq) /* jtf gold 045 */
  117. enableMenuList(hAppMenu, FALSE, TMSENDTEXTFILE, TMVIEWTEXTFILE, NULL); /* jtf 3.27 */
  118. break;
  119. case HELPMENU: /* mbbx 2.00: CUA... */
  120. break;
  121. }
  122. }
  123. /*---------------------------------------------------------------------------*/
  124. /* doEditMenu() - Edit memu commands happen here ! [scf] */
  125. /*---------------------------------------------------------------------------*/
  126. VOID doEditMenu(INT theItem)
  127. {
  128. DWORD scrapSize;
  129. HANDLE hText;
  130. HANDLE tmpScrapHandle;
  131. // -sdj unreferenced local var HDC theDC,newDC;
  132. // -sdj unreferenced local varRECT theClient;
  133. // -sdj unreferenced local varHANDLE newHdl;
  134. if(GetTopWindow(hItWnd) == hTermWnd)
  135. {
  136. hText = hTE.hText;
  137. switch(theItem)
  138. {
  139. case EMSELECTALL:
  140. termSetSelect(0l, (LONG) (savTopLine + maxScreenLine + 1) * (maxChars + 2));
  141. activSelect = TRUE; /* jtf 3.30 */
  142. noSelect = FALSE; /* rjs bugs 020 */
  143. break;
  144. case EMCOPY:
  145. case EMPASTE:
  146. case EMCOPYTABLE:
  147. case EMCOPYTHENPASTE:
  148. if((theItem == EMCOPY) || (theItem == EMCOPYTABLE) || (theItem == EMCOPYTHENPASTE))
  149. {
  150. copiedTable = FALSE;
  151. scrapSize = hTE.selEnd - hTE.selStart;
  152. if (scrapSize == 0)
  153. break; /* jtf 3.20 do not copy blank selection */
  154. /* the + 3 for possible <cr>,<lf>, NULL */
  155. if((tEScrapHandle = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, scrapSize + 3)) != NULL)
  156. {
  157. blockMove((LPBYTE) GlobalLock(hText) + hTE.selStart,
  158. (LPBYTE) GlobalLock(tEScrapHandle), scrapSize);
  159. GlobalUnlock(hText);
  160. GlobalUnlock(tEScrapHandle);
  161. stripBlanks(GlobalLock(tEScrapHandle), &scrapSize);
  162. GlobalUnlock(tEScrapHandle);
  163. if((tEScrapHandle = GlobalReAlloc(tEScrapHandle, scrapSize+1, GMEM_MOVEABLE | GMEM_ZEROINIT)) != NULL)
  164. if(OpenClipboard(hTermWnd))
  165. {
  166. EmptyClipboard();
  167. SetClipboardData(CF_TEXT, tEScrapHandle);
  168. CloseClipboard();
  169. }
  170. }
  171. }
  172. if((theItem == EMPASTE) || (theItem == EMCOPYTHENPASTE))
  173. if (IsClipboardFormatAvailable(CF_TEXT)) /* jtf 3.20 prevent protect violation */
  174. if(OpenClipboard(hTermWnd))
  175. {
  176. if((tmpScrapHandle = GetClipboardData(CF_TEXT)) != NULL)
  177. {
  178. scrapSize = (DWORD) lstrlen(GlobalLock(tmpScrapHandle));
  179. GlobalUnlock(tmpScrapHandle);
  180. if((tEScrapHandle = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, scrapSize+1)) != NULL)
  181. {
  182. blockMove(GlobalLock(tmpScrapHandle), GlobalLock(tEScrapHandle), scrapSize);
  183. GlobalUnlock(tmpScrapHandle);
  184. GlobalUnlock(tEScrapHandle);
  185. }
  186. }
  187. CloseClipboard();
  188. useScrap = TRUE;
  189. }
  190. break;
  191. case EMCLEAR:
  192. cursorAdjust();
  193. clearBuffer();
  194. break;
  195. }
  196. }
  197. }
  198. /*---------------------------------------------------------------------------*/
  199. /* doCommand() - [mbb] */
  200. /*---------------------------------------------------------------------------*/
  201. VOID doCommand(HWND hWnd, WPARAM wParam, LONG lParam)
  202. {
  203. /* this is called from within WM_COMMAND, so that wParam and lParam change as per*/
  204. /* win32. This is also called from another place with lParm set to zero */
  205. /* I'll fix the wParam references, and debug to see if any other fixes needed*/
  206. CHAR work[STR255];
  207. CHAR extrainfo[STR255]; // -sdj another buff to hold EXTRAINFO string of aboutbox;
  208. BOOL result;
  209. // -sdj unreferenced local var LPSTR lpEOS;
  210. INT rc;
  211. PRINTDLG PRN;
  212. offCursor();
  213. switch(GET_WM_COMMAND_ID(wParam, lParam))
  214. {
  215. case FMNEW:
  216. doFileNew();
  217. break;
  218. case FMOPEN:
  219. doFileOpen();
  220. break;
  221. case FMCLOSE:
  222. doFileClose();
  223. break;
  224. case FMSAVE:
  225. doFileSave();
  226. break;
  227. case FMSAVEAS:
  228. doFileSaveAs();
  229. break;
  230. case FMPRINTSETUP:
  231. /* initialize PRINTDLG structure */
  232. PRN.lStructSize = sizeof(PRINTDLG);
  233. PRN.hDevMode = hDevMode;
  234. PRN.hDevNames = hDevNames;
  235. PRN.Flags = PD_PRINTSETUP;
  236. PRN.hwndOwner = hWnd;
  237. PrintDlg(&PRN);
  238. rc = CommDlgExtendedError();
  239. /* Probable cause is low memory. */
  240. if(rc == CDERR_DIALOGFAILURE || rc == CDERR_INITIALIZATION ||
  241. rc == CDERR_LOADSTRFAILURE || rc == CDERR_LOADRESFAILURE ||
  242. rc == PDERR_LOADDRVFAILURE || rc == PDERR_GETDEVMODEFAIL)
  243. {
  244. testBox(hWnd,-(MB_ICONHAND|MB_SYSTEMMODAL|MB_OK),STR_ERRCAPTION,NoMemStr);
  245. }
  246. else
  247. {
  248. hDevMode = PRN.hDevMode;
  249. hDevNames= PRN.hDevNames;
  250. }
  251. break;
  252. case FMPRINTER:
  253. PrintFileComm(!prtFlag); /* mbbx 1.03: prAction(!prtFlag); */
  254. break;
  255. case FMTIMER:
  256. timerToggle(TRUE); /* mbbx 1.03 */
  257. break;
  258. case FMEXIT: /* mbbx 1.10: CUA... */
  259. CommThreadExit = TRUE; // we are exiting, so let the thread
  260. // exit on its own by ExitThread.
  261. PostMessage(hItWnd, WM_CLOSE, 0, 0L);
  262. break;
  263. case EMUNDO:
  264. case EMSELECTALL:
  265. case EMCUT:
  266. case EMCOPY:
  267. case EMPASTE:
  268. case EMCLEAR:
  269. case EMCOPYTHENPASTE:
  270. doEditMenu(GET_WM_COMMAND_ID(wParam, lParam));
  271. break;
  272. case SMPHONE: /* mbbx 1.04 ... */
  273. doSettings(IDDBPHON, dbPhon);
  274. break;
  275. case SMEMULATE:
  276. doSettings(IDDBEMUL, dbEmul);
  277. break;
  278. case SMTERMINAL:
  279. doSettings(IDDBTERM, dbTerm);
  280. break;
  281. case SMFUNCTIONKEYS:
  282. doSettings(IDDBFKEY, dbFkey);
  283. break;
  284. case SMTEXTXFERS:
  285. doSettings(IDDBTXTX, dbTxtX);
  286. break;
  287. case SMBINXFERS:
  288. doSettings(IDDBBINX, dbBinX);
  289. break;
  290. case SMCOMMUNICATIONS:
  291. doSettings(IDDBCOMM, dbComm);
  292. break;
  293. case SMMODEM: /* mbbx 1.10: CUA... */
  294. doSettings(IDDBMODEM, dbModem);
  295. break;
  296. case PMDIAL:
  297. dialPhone();
  298. break;
  299. case PMHANGUP:
  300. hangUpPhone();
  301. break;
  302. case TMSENDTEXTFILE:
  303. DEBOUT("doCommand: Got %s menu click\n","SENDTEXTFILE");
  304. *taskState.string = 0; /* mbbx 1.01... */
  305. sndTFile();
  306. break;
  307. case TMRCVTEXTFILE:
  308. DEBOUT("doCommand: Got %s menu click\n","RCVTEXTFILE");
  309. *taskState.string = 0; /* mbbx 1.01... */
  310. rcvTFile();
  311. break;
  312. case TMVIEWTEXTFILE:
  313. DEBOUT("doCommand: Got %s menu click\n","VIEWTEXTFILE");
  314. *taskState.string = 0; /* mbbx 1.01... */
  315. typTFile();
  316. break;
  317. case TMSENDBINFILE:
  318. DEBOUT("doCommand: Got %s menu click\n","SENDBINFILE");
  319. *taskState.string = 0; /* mbbx 1.01... */
  320. sndBFile();
  321. break;
  322. case TMRCVBINFILE:
  323. DEBOUT("doCommand: Got %s menu click\n","RCVBINFILE");
  324. *taskState.string = 0; /* mbbx 1.01... */
  325. rcvBFile();
  326. break;
  327. case TMPAUSE: /* mbbx 2.00: xfer ctrls... */
  328. xferPauseResume(TRUE, FALSE);
  329. break;
  330. case TMRESUME:
  331. xferPauseResume(FALSE, TRUE);
  332. break;
  333. case TMSTOP:
  334. xferStopBreak(TRUE);
  335. break;
  336. case WMFKEYS:
  337. showHidedbmyControls(!fKeysShown, TRUE); /* mbbx 2.00: bArrange... */
  338. break;
  339. case HMCOMMANDS:
  340. case HMPROCEDURES:
  341. case HMKEYBOARD:
  342. LoadString(hInst, STR_HELPFILE, work, STR255-1);
  343. result = WinHelp(hTermWnd, work, HELP_CONTEXT, wParam);
  344. if(!result)
  345. testBox(hTermWnd,-(MB_ICONHAND|MB_SYSTEMMODAL|MB_OK),STR_ERRCAPTION,NoMemStr);
  346. break;
  347. case HMINDEX: /* mbbx 2.00: CUA... */
  348. LoadString(hInst, STR_HELPFILE, work, STR255-1);
  349. result = WinHelp(hTermWnd,work,HELP_INDEX,0L);
  350. if(!result)
  351. testBox(hTermWnd,-(MB_ICONHAND|MB_SYSTEMMODAL|MB_OK),STR_ERRCAPTION,NoMemStr);
  352. break;
  353. case HMHELP:
  354. result = WinHelp(hTermWnd,NULL,HELP_HELPONHELP,0L);
  355. if(!result)
  356. testBox(hTermWnd,-(MB_ICONHAND|MB_SYSTEMMODAL|MB_OK),STR_ERRCAPTION,NoMemStr);
  357. break;
  358. case HMSEARCH:
  359. LoadString(hInst, STR_HELPFILE, work, STR255-1);
  360. if(!WinHelp(hTermWnd, work, HELP_PARTIALKEY, (DWORD_PTR)""))
  361. testBox(hTermWnd,-(MB_ICONHAND|MB_SYSTEMMODAL|MB_OK),STR_ERRCAPTION,NoMemStr);
  362. break;
  363. // case HMABOUT:
  364. // DialogBox(hInst, MAKEINTRESOURCE(IDDBABOUT), hItWnd, dbAbout);
  365. // break;
  366. // lets try to close one bugreport, by using shellabout again so that
  367. // the about box is consistent with the other shell applets and win31
  368. // -sdj 12/15/92
  369. case HMABOUT:
  370. LoadString(hInst, STR_APPNAME, work, STR255-1);
  371. LoadString(hInst, STR_EXTRAINFO, extrainfo, STR255-1);
  372. ShellAbout(hTermWnd, work, extrainfo,
  373. LoadIcon(hInst, MAKEINTRESOURCE(ICO_DYNACOMM)));
  374. break;
  375. default:
  376. DEBOUT("doCommand: %s\n","Got INTO default option");
  377. switch(GET_WM_COMMAND_ID(wParam, lParam) & 0xF000)
  378. {
  379. case 0xF000:
  380. /* NOTE under lParam may be zero and screw up under win32, since lParam*/
  381. /* is passed in sometimes == zero by another function*/
  382. DEBOUT("doCommand: %s\n","Got into default option: doing SendMsg");
  383. SendMessage(GetTopWindow(hItWnd), WM_SYSCOMMAND, wParam, lParam);
  384. DEBOUT("doCommand: %s\n","Got into default option: done SendMsg");
  385. break;
  386. }
  387. DEBOUT("doCommand: %s\n","Got OUT of default option");
  388. break;
  389. }
  390. DEBOUT("doCommand: %s\n","Doing UpdateWindow(hItWnd)");
  391. UpdateWindow(hItWnd);
  392. DEBOUT("doCommand: %s\n","Done UpdateWindow(hItWnd)");
  393. onCursor();
  394. }
  395. INT_PTR CALLBACK dbAbout(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  396. {
  397. switch (message)
  398. {
  399. case WM_INITDIALOG:
  400. return TRUE;
  401. case WM_COMMAND:
  402. if (wParam == IDOK)
  403. EndDialog(hDlg, GET_WM_COMMAND_ID(wParam, lParam));
  404. break;
  405. }
  406. return FALSE;
  407. }