uioptns.c
上传用户:xiaoan1112
上传日期:2013-04-11
资源大小:19621k
文件大小:15k
源码类别:

操作系统开发

开发平台:

Visual C++

  1. /***
  2. *uioptn.c - Support Options menu items.
  3. *
  4. * Copyright <C> 1985-1988, Microsoft Corporation
  5. *
  6. *Purpose:
  7. * All Options menu support routines, and other routines that modify
  8. * the screen's appearance.
  9. *
  10. *******************************************************************************/
  11. /* First, include version definition header */
  12. #include <version.h>
  13. /* Next, include TextWin's interface headers */
  14. #include <cw/version.h>
  15. #include <cw/windows.h>
  16. #include <cw/edityp.h>
  17. #include <cw/color.h>
  18. #include <uiext.h>
  19. /* include dialog information */
  20. #include <cw/dlg.h>
  21. #include "uioptns.hs"
  22. #include "uioptns.sdm"
  23. /* Next, include QBI's headers */
  24. #ifndef CONTEXT_H
  25. #include <context.h>
  26. #endif
  27. #ifndef QBIMSGS_H
  28. #include <qbimsgs.h>
  29. #endif
  30. #ifndef UI_H
  31. #include <ui.h>
  32. #endif
  33. #ifndef UIINT_H
  34. #include <uiint.h>
  35. #endif
  36. #ifndef UTIL_H
  37. #include <util.h>
  38. #endif
  39. #ifndef RTPS_H /* [10] */
  40. #include <rtps.h> /* [10] */
  41. #endif /* [10] */
  42. #ifndef HEAP_H /* [10] */
  43. #include <heap.h> /* [10] */
  44. #endif /* [10] */
  45. void near ColorResolution (void); // [36]
  46. void near SetFullMenus(void);
  47. /* options have been changed with CmdViewOptions => write qb ini file */
  48. boolean fOptionsChanged;
  49. bool fSyntaxCheck = TRUE;  /* enabled by default */
  50. BYTE fMono = FALSE; // [25]
  51. /********* View Options ******************************************************/
  52. uchar rgMsgColors[] = { //[30] change from word to byte
  53.     MSG_Black,
  54.     MSG_Blue,
  55.     MSG_Green,
  56.     MSG_Cyan,
  57.     MSG_Red,
  58.     MSG_Magenta,
  59.     MSG_Brown,
  60.     MSG_White,
  61.     MSG_Gray, /* [9] Add Bright colors */
  62.     MSG_BrBlue,  /* [9] */
  63.     MSG_BrGreen, /* [9] */
  64.     MSG_BrCyan,  /* [9] */
  65.     MSG_BrRed, /* [9] */
  66.     MSG_Pink, /* [9] */
  67.     MSG_Yellow,  /* [9] */
  68.     MSG_BrWhite  /* [9] */
  69. };
  70. #define rgMsgColorsMax (sizeof (rgMsgColors) / sizeof (BYTE)) //[30]
  71. /* [9] Separate array is smaller than moving array around */
  72. uchar rgMsgMono[] = { //[30] change from word to byte
  73.     MSG_Black,
  74.     MSG_White,
  75.     MSG_Gray,
  76.     MSG_BrWhite
  77. };
  78. #define rgMsgMonoMax (sizeof (rgMsgMono) / sizeof (BYTE)) //[30]
  79. /***
  80. *WORD FAR WListProcColor (tmm, sz, isz, tmc, wParam, bArg)
  81. *Purpose:
  82. * ListBox filling support procedure.
  83. *
  84. *Entry:
  85. * tmm Dialog item message type.
  86. * sz String pointer to return text in.
  87. * isz Listbox item to return text for.
  88. * tmc Unreferenced.
  89. * wParam Unreferenced.
  90. * bArg Unreferenced.
  91. *
  92. *Exit:
  93. * tmm = tmmCount, size of array of colors.
  94. *       tmmText or
  95. *       tmmEditText, Text of isz'th element of color array in sz.
  96. *
  97. *Exceptions:
  98. * None.
  99. *******************************************************************************/
  100. WORD FAR
  101. WListProcColor (tmm, sz, isz, tmc, wParam, bArg)
  102. WORD tmm;
  103. char *sz;
  104. WORD isz;
  105. TMC tmc;
  106. WORD wParam, bArg;
  107. {
  108.     Unreferenced (tmc);
  109.     Unreferenced (wParam);
  110.     Unreferenced (bArg);
  111.     switch (tmm) {
  112. case tmmCount:
  113.     /* [5] [25] if fMono, use rgMsgMono */
  114.     return ((fMono ? rgMsgMonoMax : rgMsgColorsMax) // [30]
  115.     >> ((cmdSwitches & CMD_SW_NOH) != 0) // [21]
  116.    );
  117. case tmmText:
  118. case tmmEditText:
  119.     {
  120.     /* [5] [25] if fMono, use rgMsgMono */
  121.     DbAssert (fMono ? (isz<rgMsgMonoMax) : (isz<rgMsgColorsMax)); //[30]
  122.     ListStdMsg (fMono ? rgMsgMono[isz] : rgMsgColors[isz]); //[30]
  123.     }
  124.     strcpy (sz, bufStdMsg);
  125.     break;
  126.     }
  127.     return (TRUE); //[31] Was depending on return value of strcpy
  128. //[31] to be non-zero.
  129. }
  130. /* [7] Make MenuBarMain, rgMenuMain, and rgMenuMainEZ accessible */
  131. extern MENUBAR MenuBarMain;
  132. extern MENU rgMenuMain[], rgMenuMainEZ[];
  133. /* [5] Array of colors for OptnsDisplay dialog */
  134. static struct {
  135.     WORD coFore, coBack;
  136. } rgco[3];
  137. /*** 
  138. *BOOL FAR FDlgOptnsDisplay (dlm, tmc, wNew, wOld, wParam)
  139. *Purpose:
  140. * Dialog procedure for dlgOptnsDisplay.
  141. *
  142. * dlmInit:
  143. * Initialize the array of temporary colors for Normal Text,
  144. * Current Statement, and Breakpoint Line in rgco.
  145. *
  146. * dlmClick:
  147. * If Changing foreground or background color, change
  148. * color array element, and redisplay the general picture
  149. * box for this element.
  150. *
  151. * Else, get the color from the array, and change the
  152. * foreground and background listbox indices.
  153. *
  154. *Entry:
  155. * dlm Dialog message.
  156. * tmc Item code of action.
  157. * wNew Unreferenced.
  158. * wOld Unreferenced.
  159. * wParam Unreferenced.
  160. *
  161. *Exit:
  162. * None.
  163. *
  164. *Exceptions:
  165. * None.
  166. *******************************************************************************/
  167. BOOL FAR
  168. FDlgOptnsDisplay (dlm, tmc, wNew, wOld, wParam)
  169. WORD dlm;
  170. TMC tmc;
  171. WORD wNew, wOld, wParam;
  172. {
  173.     ISA isa;
  174.     register WORD oColor, i;
  175.     WORD coFore, coBack;
  176.     Unreferenced (wNew);
  177.     Unreferenced (wOld);
  178.     Unreferenced (wParam);
  179.     if (dlm == dlmInit) {
  180. for (i = 0; i < 3; i++) {
  181.     GetIsaColor ((ISA) isaEditWindow+i, &rgco[i].coFore, &rgco[i].coBack);
  182. }
  183.     }
  184.     if (dlm == dlmInit || dlm == dlmClick) {
  185. oColor = (cmdSwitches & CMD_SW_ED) ? 0 : GetTmcVal (tmcColor);  //[38]
  186. DbAssert (oColor < 3);
  187. isa = (ISA) isaEditWindow + oColor;
  188. if (tmc == tmcCoFore || tmc == tmcCoBack) {
  189.     coFore = GetTmcVal (tmcCoFore);
  190.     coBack = GetTmcVal (tmcCoBack);
  191.     // [15] [25] If monochrome, translate index to attribute.
  192.     if (fMono) {
  193. rgco[oColor].coFore = ((coFore & 1) ? coWhite : coBlack) |
  194.       ((coFore >= 2) << 3);
  195. rgco[oColor].coBack = ((coBack & 1) ? coWhite : coBlack) |
  196.       ((coBack >= 2) << 3);
  197.     }
  198.     else {
  199. rgco[oColor].coFore = coFore;
  200. rgco[oColor].coBack = coBack;
  201.     }
  202.             if (cmdSwitches & CMD_SW_ED)        //[38]
  203.                 RedisplayTmc (tmcQeditText);    //[38]
  204.             else                                //[38]
  205.         RedisplayTmc (tmcNormalText + oColor);
  206. }
  207. else {
  208.     coFore = rgco[oColor].coFore;
  209.     coBack = rgco[oColor].coBack;
  210.     // [25] If no highlight bit, clear it for proper index
  211.     if (cmdSwitches & CMD_SW_NOH) {
  212. coFore &= 7;
  213. coBack &= 7;
  214.     }
  215.     // [15] [25] If monochrome, translate color to index.
  216.     if (fMono) {
  217. SetTmcVal (tmcCoFore, ((coFore & 7) == coWhite) |
  218.       ((coFore >= 8) << 1));
  219. SetTmcVal (tmcCoBack, ((coBack & 7) == coWhite) |
  220.       ((coBack >= 8) << 1));
  221.     }
  222.     else {
  223. SetTmcVal (tmcCoFore, coFore);
  224. SetTmcVal (tmcCoBack, coBack);
  225.    }
  226. }
  227.     }
  228.     return (TRUE);
  229. }
  230. #define QeditTextLen    24      //[38] length of " Set colors for the ",
  231.                                            //[38]       and " text editor window:"
  232. #define ColoredTextLen 19    //[12] length of " Normal Text       ",
  233.            //[12]           " Current Statement ",
  234.            //[12]       and " Breakpoint Lines  "
  235. /***
  236. *WORD FAR PASCAL DisplayQeditTextWndProc (tmm, pv, hObj, tmc, bArg, wParam)
  237. *Purpose:
  238. * Display the the "QEDIT Text" color item in the appropriate color.
  239. *
  240. *Entry:
  241. * tmm Unreferenced.
  242. * pv pointer to general picture window.
  243. * hObj Unreferenced.
  244. * tmc Unreferenced.
  245. * bArg Unreferenced.
  246. * wParam Unreferenced.
  247. *
  248. *Exit:
  249. * returns TRUE.
  250. *
  251. *Exceptions:
  252. * None.
  253. *******************************************************************************/
  254. WORD FAR PASCAL
  255. DisplayQeditTextWndProc (tmm, pv, hObj, tmc, bArg, wParam)      //[38]
  256. TMM tmm;
  257. char * pv; /* really a pwnd */
  258. WORD hObj, bArg; /* not used */
  259. TMC tmc;
  260. WORD wParam;
  261. {
  262.     REG1 PWND pwnd = (PWND) pv;
  263.     Unreferenced (tmm);
  264.     Unreferenced (hObj);
  265.     Unreferenced (bArg);
  266.     Unreferenced (tmc);
  267.     Unreferenced (wParam);
  268.     SetIsaColor (isaUserMax-1, rgco[0].coFore, rgco[0].coBack);
  269.     ListStdMsg (MSG_QeditText1);
  270.     TextOut (pwnd, 0, 0, bufStdMsg, QeditTextLen, isaUserMax-1);
  271.     ListStdMsg (MSG_QeditText2);
  272.     TextOut (pwnd, 0, 1, bufStdMsg, QeditTextLen, isaUserMax-1);
  273.     return (TRUE);
  274. }
  275. /***
  276. *WORD FAR PASCAL DisplayNormalTextWndProc (tmm, pv, hObj, tmc, bArg, wParam)
  277. *Purpose:
  278. * Display the the "Normal Text" color item in the appropriate color.
  279. *
  280. *Entry:
  281. * tmm Unreferenced.
  282. * pv pointer to general picture window.
  283. * hObj Unreferenced.
  284. * tmc Unreferenced.
  285. * bArg Unreferenced.
  286. * wParam Unreferenced.
  287. *
  288. *Exit:
  289. * returns TRUE.
  290. *
  291. *Exceptions:
  292. * None.
  293. *******************************************************************************/
  294. WORD FAR PASCAL
  295. DisplayNormalTextWndProc (tmm, pv, hObj, tmc, bArg, wParam)
  296. TMM tmm;
  297. char * pv; /* really a pwnd */
  298. WORD hObj, bArg; /* not used */
  299. TMC tmc;
  300. WORD wParam;
  301. {
  302.     REG1 PWND pwnd = (PWND) pv;
  303.     Unreferenced (tmm);
  304.     Unreferenced (hObj);
  305.     Unreferenced (bArg);
  306.     Unreferenced (tmc);
  307.     Unreferenced (wParam);
  308.     ListStdMsg (MSG_NormalText);
  309.     SetIsaColor (isaUserMax-1, rgco[0].coFore, rgco[0].coBack);
  310.     TextOut (pwnd, 0, 0, bufStdMsg, ColoredTextLen, isaUserMax-1); //[12]
  311.     return (TRUE);
  312. }
  313. /***
  314. *WORD FAR PASCAL DisplayCurStmtWndProc (tmm, pv, hObj, tmc, bArg, wParam)
  315. *Purpose:
  316. * Display the the "Current Statement" color item in the appropriate color.
  317. *
  318. *Entry:
  319. * tmm Unreferenced.
  320. * pv pointer to general picture window.
  321. * hObj Unreferenced.
  322. * tmc Unreferenced.
  323. * bArg Unreferenced.
  324. * wParam Unreferenced.
  325. *
  326. *Exit:
  327. * returns TRUE.
  328. *
  329. *Exceptions:
  330. * None.
  331. *******************************************************************************/
  332. WORD FAR PASCAL
  333. DisplayCurStmtTextWndProc (tmm, pv, hObj, tmc, bArg, wParam)
  334. TMM tmm;
  335. char * pv; /* really a pwnd */
  336. WORD hObj, bArg; /* not used */
  337. TMC tmc;
  338. WORD wParam;
  339. {
  340.     REG1 PWND pwnd = (PWND) pv;
  341.     Unreferenced (tmm);
  342.     Unreferenced (hObj);
  343.     Unreferenced (bArg);
  344.     Unreferenced (tmc);
  345.     Unreferenced (wParam);
  346.     ListStdMsg (MSG_CurStmt);
  347.     SetIsaColor (isaUserMax-1, rgco[1].coFore, rgco[1].coBack);
  348.     TextOut (pwnd, 0, 0, bufStdMsg, ColoredTextLen, isaUserMax-1); //[12]
  349.     return (TRUE);
  350. }
  351. /*** 
  352. *WORD FAR PASCAL DisplayBreakpointTextWndProc (tmm, pv, hObj, tmc, bArg, wParam)
  353. *Purpose:
  354. * Display the the "Breakpoint Lines" color item in the appropriate color.
  355. *
  356. *Entry:
  357. * tmm Unreferenced.
  358. * pv pointer to general picture window.
  359. * hObj Unreferenced.
  360. * tmc Unreferenced.
  361. * bArg Unreferenced.
  362. * wParam Unreferenced.
  363. *
  364. *Exit:
  365. * returns TRUE.
  366. *
  367. *Exceptions:
  368. * None.
  369. *******************************************************************************/
  370. WORD FAR PASCAL
  371. DisplayBreakpointTextWndProc (tmm, pv, hObj, tmc, bArg, wParam)
  372. TMM tmm;
  373. char * pv; /* really a pwnd */
  374. WORD hObj, bArg; /* not used */
  375. TMC tmc;
  376. WORD wParam;
  377. {
  378.     REG1 PWND pwnd = (PWND) pv;
  379.     Unreferenced (tmm);
  380.     Unreferenced (hObj);
  381.     Unreferenced (bArg);
  382.     Unreferenced (tmc);
  383.     Unreferenced (wParam);
  384.     ListStdMsg (MSG_Breakpoint);
  385.     SetIsaColor (isaUserMax-1, rgco[2].coFore, rgco[2].coBack);
  386.     TextOut (pwnd, 0, 0, bufStdMsg, ColoredTextLen, isaUserMax-1); //[12]
  387.     return (TRUE);
  388. }
  389. /*** 
  390. *VOID NEAR CmdOptnsDisplay ()
  391. *Purpose:
  392. * Called when OPTIONS/DISPLAY menu item is selected.
  393. *
  394. *Entry:
  395. * None.
  396. *
  397. *Exit:
  398. * None.
  399. *
  400. *Exceptions:
  401. * None.
  402. *******************************************************************************/
  403. VOID NEAR CmdOptnsDisplay ()
  404. {
  405.     ushort tabs;
  406.     WORD i;
  407.     HCABOptnsDisplay hcabOptnsDisplay;
  408.     tabs = 0;
  409.     DbAssert (uierr == 0); //[24]
  410.     hcabOptnsDisplay = (HCABOptnsDisplay) HcabAlloc (cabiCABOptnsDisplay);
  411.     /* [5] Catch HcabAlloc errors */
  412.     if (uierr)
  413. return;
  414.     (*hcabOptnsDisplay)->oColor = 0;
  415.     (*hcabOptnsDisplay)->oCoFore = (*hcabOptnsDisplay)->oCoBack = 0;
  416.     itoa (GetTabs (), bufStdMsg, 10);
  417.     SzToCab (hcabOptnsDisplay, bufStdMsg, Iag (CABOptnsDisplay, szTabStops));
  418.     // [26] if SzToCab memory allocation failed, free cab and exit.
  419.     if (uierr)
  420. goto EndCmdOptnsDisplay;
  421.     (*hcabOptnsDisplay)->fScrollBars = fScrollBars; /* [4] */
  422.     (*hcabOptnsDisplay)->u.sab = (cmdSwitches & CMD_SW_ED) ? sabOptnsQedit : sabOptnsQbas;      //[38]
  423.     if (TmcDoDlgFar (&dlgOptnsDisplay, sizeof (dlgOptnsDisplay), hcabOptnsDisplay) == tmcOk) {
  424. fOptionsChanged = TRUE;
  425. for (i = 0; i < 3; i++) {
  426.     SetIsaColor ((ISA) isaEditWindow+i, rgco[i].coFore, rgco[i].coBack);
  427. }
  428. ColorResolution (); // [36]
  429. fScrollBars = (*hcabOptnsDisplay)->fScrollBars;
  430. // [21] Either RemoveScrollBars() or AddScrollBars() will have no effect
  431. // [21] (depending on the setting of fScrollBars).
  432. RemoveScrollBars ();
  433. AddScrollBars ();
  434.       
  435. /* SetTabs only if greater than zero */
  436. SzFromCab (hcabOptnsDisplay, bufStdMsg, CB_bufStdMsg,
  437.    Iag (CABOptnsDisplay, szTabStops));
  438. /* [22] if user specified -1 convert to -2 so erroneous
  439.    [22] Can't Set Tabs dialog is not displayed.         */
  440. if ((tabs = atoi (bufStdMsg)) == -1) //[22]
  441.      tabs--; //[22]
  442. if (tabs != GetTabs()) {
  443.     /* user wants to change tab stop setting.
  444.      * Don't let them if any loaded files had tabs in them.
  445.      * Otherwise, the user won't get what was expected.  If the
  446.      * reload the file after changing TABs, everything is fine.
  447.      * QB doesn't keep TABs in its pcode.
  448.      */
  449.     UiRsActivate(UNDEFINED);
  450.     while (NextMrsFile() != UNDEFINED) {
  451. if (mrsCur.flags2 & FM2_EntabSource)
  452.     tabs = UNDEFINED;
  453.     }
  454. }
  455. DrawDebugScr();
  456.     }
  457.     if (tabs == UNDEFINED)
  458. MsgBoxStd (MB_OK, MSG_CantSetTabs);
  459.     else if (tabs <= 99 && tabs > 0)
  460. SetTabs (tabs);
  461. EndCmdOptnsDisplay: // [26]
  462.     FreeCab (hcabOptnsDisplay);
  463. }
  464. /*** 
  465. *VOID NEAR CmdOptnsPaths ()
  466. *Purpose:
  467. * Called when OPTIONS/PATHS menu item is selected.
  468. *
  469. *Entry:
  470. * None.
  471. *
  472. *Exit:
  473. * None.
  474. *
  475. *Exceptions:
  476. * None.
  477. *******************************************************************************/
  478. VOID NEAR CmdOptnsPaths ()
  479. {
  480.     extern bd bdLibPath, bdExePath, bdInclPath, bdHelpPath;
  481.     extern char b$buf1;  //[32]
  482.     if (!BdRealloc (&bdHelpPath, MAX_SEARCH_PATH )) {
  483. SetUiErrOm ();
  484. goto CmdOptnsPathsEnd;
  485.     } 
  486.     DbChkHoldBuf1();
  487.     strcpy (&b$buf1, bdHelpPath.pb);
  488.     if (PromptForString (cmdSwitches & CMD_SW_ED ? MSG_SearchPathEdit : MSG_SearchPathInterp, //[39]
  489.  (char far *) &b$buf1, //[39]
  490.  MAX_SEARCH_PATH) != tmcCancel) { //[39]
  491. fOptionsChanged = TRUE;
  492.         strcpy (bdHelpPath.pb, &b$buf1);
  493.         bdHelpPath.cbLogical = (CbSzUi(&b$buf1)) + 1;
  494.     }
  495.     DbChkFreeBuf1();
  496. CmdOptnsPathsEnd:
  497.     return;
  498. }
  499. bool fRightMouseHelp = TRUE; // [14] default to right mouse help
  500. /*** 
  501. *void near ColorResolution ()
  502. *Purpose:
  503. * Resolve all color dependencies.
  504. *
  505. *Entry:
  506. * Global isa's have been just set to their proper values.
  507. *
  508. *Exit:
  509. * Sets isaCurBreakpoint based on isaCurStmt and isaBreakpoint, and
  510. * isaIncludeFileHilite based on isaIncludeFileHilite, and isaEditWindow.
  511. *
  512. *Exceptions:
  513. * None.
  514. *******************************************************************************/
  515. void near ColorResolution () // [36]
  516. {
  517.     WORD coFore, coBack, dummy;
  518.     /* for those statements that are both Current & Breakpoint, use:
  519.      *    the Current statement forground,
  520.      *    the Breakpoint statement background
  521.      */
  522.     GetIsaColor (isaCurStmt, &coFore, &dummy);
  523.     GetIsaColor (isaBreakpoint, &dummy, &coBack);
  524.     SetIsaColor (isaCurBreakpoint, coFore, coBack);
  525.     /* for those statements that are Highlighted Include file lines, use:
  526.      *    the Include File Line foreground,
  527.      *    the Edit Window background
  528.      */
  529.     GetIsaColor (isaIncludeFileHilite, &coFore, &dummy);
  530.     GetIsaColor (isaEditWindow, &dummy, &coBack);
  531.     SetIsaColor (isaIncludeFileHilite, coFore, coBack);
  532. }