home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / vrac / dflt20.zip / APPLICAT.C next >
Text File  |  1995-02-13  |  22KB  |  746 lines

  1. /* ------------- applicat.c ------------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. static int ScreenHeight;
  6. static BOOL DisplayModified = FALSE;
  7. WINDOW ApplicationWindow;
  8.  
  9. extern DBOX Display;
  10.  
  11. #ifdef INCLUDE_MULTI_WINDOWS
  12. extern DBOX Windows;
  13. #endif
  14.  
  15. #ifdef INCLUDE_LOGGING
  16. extern DBOX Log;
  17. #endif
  18.  
  19. #ifdef INCLUDE_SHELLDOS
  20. static void ShellDOS(WINDOW);
  21. #endif
  22. static void CreateMenu(WINDOW);
  23. static void CreateStatusBar(WINDOW);
  24. static void SelectColors(WINDOW);
  25. static void SetScreenHeight(int);
  26. static void SelectLines(WINDOW);
  27.  
  28. #ifdef INCLUDE_WINDOWOPTIONS
  29. static void SelectTexture(void);
  30. static void SelectBorder(WINDOW);
  31. static void SelectTitle(WINDOW);
  32. static void SelectStatusBar(WINDOW);
  33. #endif
  34.  
  35. static WINDOW oldFocus;
  36. #ifdef INCLUDE_MULTI_WINDOWS
  37. static void CloseAll(WINDOW, int);
  38. static void MoreWindows(WINDOW);
  39. static void ChooseWindow(WINDOW, int);
  40. static int WindowSel;
  41. static char *Menus[9] = {
  42.     "~1.                      ",
  43.     "~2.                      ",
  44.     "~3.                      ",
  45.     "~4.                      ",
  46.     "~5.                      ",
  47.     "~6.                      ",
  48.     "~7.                      ",
  49.     "~8.                      ",
  50.     "~9.                      "
  51. };
  52. #endif
  53.  
  54. static char Cwd[65];
  55.  
  56. char **Argv;
  57.  
  58. /* --------------- CREATE_WINDOW Message -------------- */
  59. static int CreateWindowMsg(WINDOW wnd)
  60. {
  61.     int rtn;
  62.     ApplicationWindow = wnd;
  63.     ScreenHeight = SCREENHEIGHT;
  64.     getcwd(Cwd, 64);
  65.     if (!DisplayModified)    {
  66.            int i;
  67.            CTLWINDOW *ct, *ct1;
  68.            ct = FindCommand(&Display, ID_SNOWY, CHECKBOX);
  69.         if (!isVGA())    {
  70.             /* ---- modify Display Dialog Box for EGA, CGA ---- */
  71.             if (isEGA())
  72.                 ct1 = FindCommand(&Display,ID_50LINES,RADIOBUTTON);
  73.             else    {
  74.                 CTLWINDOW *ct2;
  75.                 ct2 = FindCommand(&Display,ID_COLOR,RADIOBUTTON)-1;
  76.                 if (ct2)    {
  77.                     ct2->dwnd.w++;
  78.                     for (i = 0; i < 7; i++)
  79.                         (ct2+i)->dwnd.x += 8;
  80.                 }
  81.                 ct1 = FindCommand(&Display,ID_25LINES,RADIOBUTTON)-1;
  82.             }
  83.             if (ct && ct1)
  84.                 for (i = 0; i < 6; i++)
  85.                     *ct1++ = *ct++;
  86.         }
  87.         if (isVGA() || isEGA())    {
  88.             /* ------ eliminate the snowy check box ----- */
  89.                ct = FindCommand(&Display, ID_SNOWY, CHECKBOX);
  90.             if (ct != NULL)
  91.                 for (i = 0; i < 4; i++)
  92.                     *(ct+i) = *(ct+2+i);
  93.         }
  94.         DisplayModified = TRUE;
  95.     }
  96. #ifdef INCLUDE_WINDOWOPTIONS
  97.     if (cfg.Border)
  98.         SetCheckBox(&Display, ID_BORDER);
  99.     if (cfg.Title)
  100.         SetCheckBox(&Display, ID_TITLE);
  101.     if (cfg.StatusBar)
  102.         SetCheckBox(&Display, ID_STATUSBAR);
  103.     if (cfg.Texture)
  104.         SetCheckBox(&Display, ID_TEXTURE);
  105. #endif
  106.     if (cfg.mono == 1)
  107.         PushRadioButton(&Display, ID_MONO);
  108.     else if (cfg.mono == 2)
  109.         PushRadioButton(&Display, ID_REVERSE);
  110.     else
  111.         PushRadioButton(&Display, ID_COLOR);
  112.     if (cfg.ScreenLines == 25)
  113.         PushRadioButton(&Display, ID_25LINES);
  114.     else if (cfg.ScreenLines == 43)
  115.         PushRadioButton(&Display, ID_43LINES);
  116.     else if (cfg.ScreenLines == 50)
  117.         PushRadioButton(&Display, ID_50LINES);
  118.     if (cfg.snowy)
  119.         SetCheckBox(&Display, ID_SNOWY);
  120.     if (SCREENHEIGHT != cfg.ScreenLines)    {
  121.         SetScreenHeight(cfg.ScreenLines);
  122.         if (WindowHeight(wnd) == ScreenHeight ||
  123.                 SCREENHEIGHT-1 < GetBottom(wnd))    {
  124.             WindowHeight(wnd) = SCREENHEIGHT;
  125.             GetBottom(wnd) = GetTop(wnd)+WindowHeight(wnd)-1;
  126.             wnd->RestoredRC = WindowRect(wnd);
  127.         }
  128.     }
  129.     SelectColors(wnd);
  130. #ifdef INCLUDE_WINDOWOPTIONS
  131.     SelectBorder(wnd);
  132.     SelectTitle(wnd);
  133.     SelectStatusBar(wnd);
  134. #endif
  135.     rtn = BaseWndProc(APPLICATION, wnd, CREATE_WINDOW, 0, 0);
  136.     if (wnd->extension != NULL)
  137.         CreateMenu(wnd);
  138.     CreateStatusBar(wnd);
  139.     SendMessage(NULL, SHOW_MOUSE, 0, 0);
  140.     return rtn;
  141. }
  142.  
  143. /* --------- ADDSTATUS Message ---------- */
  144. static void AddStatusMsg(WINDOW wnd, PARAM p1)
  145. {
  146.     if (wnd->StatusBar != NULL)    {
  147.         if (p1 && *(char *)p1)
  148.             SendMessage(wnd->StatusBar, SETTEXT, p1, 0);
  149.         else 
  150.             SendMessage(wnd->StatusBar, CLEARTEXT, 0, 0);
  151.         SendMessage(wnd->StatusBar, PAINT, 0, 0);
  152.     }
  153. }
  154.  
  155. /* -------- SETFOCUS Message -------- */
  156. static void SetFocusMsg(WINDOW wnd, BOOL p1)
  157. {
  158.     if (p1)
  159.         SendMessage(inFocus, SETFOCUS, FALSE, 0);
  160.     inFocus = p1 ? wnd : NULL;
  161.     SendMessage(NULL, HIDE_CURSOR, 0, 0);
  162.     if (isVisible(wnd))
  163.         SendMessage(wnd, BORDER, 0, 0);
  164.     else 
  165.         SendMessage(wnd, SHOW_WINDOW, 0, 0);
  166. }
  167.  
  168. /* ------- SIZE Message -------- */
  169. static void SizeMsg(WINDOW wnd, PARAM p1, PARAM p2)
  170. {
  171.     BOOL WasVisible;
  172.     WasVisible = isVisible(wnd);
  173.     if (WasVisible)
  174.         SendMessage(wnd, HIDE_WINDOW, 0, 0);
  175.     if (p1-GetLeft(wnd) < 30)
  176.         p1 = GetLeft(wnd) + 30;
  177.     BaseWndProc(APPLICATION, wnd, SIZE, p1, p2);
  178.     CreateMenu(wnd);
  179.     CreateStatusBar(wnd);
  180.     if (WasVisible)
  181.         SendMessage(wnd, SHOW_WINDOW, 0, 0);
  182. }
  183.  
  184. /* ----------- KEYBOARD Message ------------ */
  185. static int KeyboardMsg(WINDOW wnd, PARAM p1, PARAM p2)
  186. {
  187.     if (WindowMoving || WindowSizing || (int) p1 == F1)
  188.         return BaseWndProc(APPLICATION, wnd, KEYBOARD, p1, p2);
  189.     switch ((int) p1)    {
  190.         case ALT_F4:
  191.             if (TestAttribute(wnd, CONTROLBOX))
  192.                 PostMessage(wnd, CLOSE_WINDOW, 0, 0);
  193.             return TRUE;
  194. #ifdef INCLUDE_MULTI_WINDOWS
  195.         case ALT_F6:
  196.             SetNextFocus();
  197.             return TRUE;
  198. #endif
  199.         case ALT_HYPHEN:
  200.             if (TestAttribute(wnd, CONTROLBOX))
  201.                 BuildSystemMenu(wnd);
  202.             return TRUE;
  203.         default:
  204.             break;
  205.     }
  206.     PostMessage(wnd->MenuBarWnd, KEYBOARD, p1, p2);
  207.     return TRUE;
  208. }
  209.  
  210. /* --------- SHIFT_CHANGED Message -------- */
  211. static void ShiftChangedMsg(WINDOW wnd, PARAM p1)
  212. {
  213.     extern BOOL AltDown;
  214.     if ((int)p1 & ALTKEY)
  215.         AltDown = TRUE;
  216.     else if (AltDown)    {
  217.         AltDown = FALSE;
  218.         if (wnd->MenuBarWnd != inFocus)
  219.             SendMessage(NULL, HIDE_CURSOR, 0, 0);
  220.         SendMessage(wnd->MenuBarWnd, KEYBOARD, F10, 0);
  221.     }
  222. }
  223.  
  224. /* -------- COMMAND Message ------- */
  225. static void CommandMsg(WINDOW wnd, PARAM p1, PARAM p2)
  226. {
  227.     switch ((int)p1)    {
  228.         case ID_HELP:
  229.             DisplayHelp(wnd, DFlatApplication);
  230.             break;
  231.         case ID_HELPHELP:
  232.             DisplayHelp(wnd, "HelpHelp");
  233.             break;
  234.         case ID_EXTHELP:
  235.             DisplayHelp(wnd, "ExtHelp");
  236.             break;
  237.         case ID_KEYSHELP:
  238.             DisplayHelp(wnd, "KeysHelp");
  239.             break;
  240.         case ID_HELPINDEX:
  241.             DisplayHelp(wnd, "HelpIndex");
  242.             break;
  243. #ifdef INCLUDE_LOGGING
  244.         case ID_LOG:
  245.             MessageLog(wnd);
  246.             break;
  247. #endif
  248. #ifdef INCLUDE_SHELLDOS
  249.         case ID_DOS:
  250.             ShellDOS(wnd);
  251.             break;
  252. #endif
  253.         case ID_EXIT:
  254.         case ID_SYSCLOSE:
  255.             PostMessage(wnd, CLOSE_WINDOW, 0, 0);
  256.             break;
  257.         case ID_DISPLAY:
  258.             if (DialogBox(wnd, &Display, TRUE, NULL))    {
  259.                 if (inFocus == wnd->MenuBarWnd || inFocus == wnd->StatusBar)
  260.                     oldFocus = ApplicationWindow;
  261.                 else 
  262.                     oldFocus = inFocus;
  263.                 SendMessage(wnd, HIDE_WINDOW, 0, 0);
  264.                 SelectColors(wnd);
  265.                 SelectLines(wnd);
  266. #ifdef INCLUDE_WINDOWOPTIONS
  267.                 SelectBorder(wnd);
  268.                 SelectTitle(wnd);
  269.                 SelectStatusBar(wnd);
  270.                 SelectTexture();
  271. #endif
  272.                 CreateMenu(wnd);
  273.                 CreateStatusBar(wnd);
  274.                 SendMessage(wnd, SHOW_WINDOW, 0, 0);
  275.                 SendMessage(oldFocus, SETFOCUS, TRUE, 0);
  276.             }
  277.             break;
  278.         case ID_SAVEOPTIONS:
  279.             SaveConfig();
  280.             break;
  281. #ifdef INCLUDE_MULTI_WINDOWS
  282.         case ID_WINDOW:
  283.             ChooseWindow(wnd, CurrentMenuSelection-2);
  284.             break;
  285.         case ID_CLOSEALL:
  286.             CloseAll(wnd, FALSE);
  287.             break;
  288.         case ID_MOREWINDOWS:
  289.             MoreWindows(wnd);
  290.             break;
  291. #endif
  292. #ifdef INCLUDE_RESTORE
  293.         case ID_SYSRESTORE:
  294. #endif
  295.         case ID_SYSMOVE:
  296.         case ID_SYSSIZE:
  297. #ifdef INCLUDE_MINIMIZE
  298.         case ID_SYSMINIMIZE:
  299. #endif
  300. #ifdef INCLUDE_MAXIMIZE
  301.         case ID_SYSMAXIMIZE:
  302. #endif
  303.             BaseWndProc(APPLICATION, wnd, COMMAND, p1, p2);
  304.             break;
  305.         default:
  306.             if (inFocus != wnd->MenuBarWnd && inFocus != wnd)
  307.                 PostMessage(inFocus, COMMAND, p1, p2);
  308.             break;
  309.     }
  310. }
  311.  
  312. /* --------- CLOSE_WINDOW Message -------- */
  313. static int CloseWindowMsg(WINDOW wnd)
  314. {
  315.     int rtn;
  316. #ifdef INCLUDE_MULTI_WINDOWS
  317.     CloseAll(wnd, TRUE);
  318.     WindowSel = 0;
  319. #endif
  320.     PostMessage(NULL, STOP, 0, 0);
  321.     rtn = BaseWndProc(APPLICATION, wnd, CLOSE_WINDOW, 0, 0);
  322.     if (ScreenHeight != SCREENHEIGHT)
  323.         SetScreenHeight(ScreenHeight);
  324.     UnLoadHelpFile();
  325.     DisplayModified = FALSE;
  326.     ApplicationWindow = NULL;
  327.     setdisk(toupper(*Cwd) - 'A');
  328.     chdir(Cwd+2);
  329.     return rtn;
  330. }
  331.  
  332. /* --- APPLICATION Window Class window processing module --- */
  333. int ApplicationProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  334. {
  335.     switch (msg)    {
  336.         case CREATE_WINDOW:
  337.             return CreateWindowMsg(wnd);
  338.         case HIDE_WINDOW:
  339.             if (wnd == inFocus)
  340.                 inFocus = NULL;
  341.             break;
  342.         case ADDSTATUS:
  343.             AddStatusMsg(wnd, p1);
  344.             return TRUE;
  345.         case SETFOCUS:
  346.             if ((int)p1 == (inFocus != wnd))    {
  347.                 SetFocusMsg(wnd, (BOOL) p1);
  348.                 return TRUE;
  349.             }
  350.             break;
  351.         case SIZE:
  352.             SizeMsg(wnd, p1, p2);
  353.             return TRUE;
  354. #ifdef INCLUDE_MINIMIZE
  355.         case MINIMIZE:
  356.             return TRUE;
  357. #endif
  358.         case KEYBOARD:
  359.             return KeyboardMsg(wnd, p1, p2);
  360.         case SHIFT_CHANGED:
  361.             ShiftChangedMsg(wnd, p1);
  362.             return TRUE;
  363.         case PAINT:
  364.             if (isVisible(wnd))    {
  365.                 int cl = cfg.Texture ? APPLCHAR : ' ';
  366.                 ClearWindow(wnd, (RECT *)p1, cl);
  367.             }
  368.             return TRUE;
  369.         case COMMAND:
  370.             CommandMsg(wnd, p1, p2);
  371.             return TRUE;
  372.         case CLOSE_WINDOW:
  373.             return CloseWindowMsg(wnd);
  374.         default:
  375.             break;
  376.     }
  377.     return BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  378. }
  379.  
  380. #ifdef INCLUDE_SHELLDOS
  381. static void SwitchCursor(void)
  382. {
  383.     SendMessage(NULL, SAVE_CURSOR, 0, 0);
  384.     SwapCursorStack();
  385.     SendMessage(NULL, RESTORE_CURSOR, 0, 0);
  386. }
  387.  
  388. /* ------- Shell out to DOS ---------- */
  389. static void ShellDOS(WINDOW wnd)
  390. {
  391.     oldFocus = inFocus;
  392.     SendMessage(wnd, HIDE_WINDOW, 0, 0);
  393.     SwitchCursor();
  394.     if (ScreenHeight != SCREENHEIGHT)
  395.         SetScreenHeight(ScreenHeight);
  396.     SendMessage(NULL, HIDE_MOUSE, 0, 0);
  397.     printf("To return to %s, execute the DOS exit command.",
  398.                     DFlatApplication);
  399.     fflush(stdout);
  400.     spawnl(P_WAIT, getenv("COMSPEC"), NULL);
  401.     if (SCREENHEIGHT != cfg.ScreenLines)
  402.         SetScreenHeight(cfg.ScreenLines);
  403.     SwitchCursor();
  404.     SendMessage(wnd, SHOW_WINDOW, 0, 0);
  405.     SendMessage(oldFocus, SETFOCUS, TRUE, 0);
  406.     SendMessage(NULL, SHOW_MOUSE, 0, 0);
  407. }
  408. #endif
  409.  
  410. /* -------- Create the menu bar -------- */
  411. static void CreateMenu(WINDOW wnd)
  412. {
  413.     AddAttribute(wnd, HASMENUBAR);
  414.     if (wnd->MenuBarWnd != NULL)
  415.         SendMessage(wnd->MenuBarWnd, CLOSE_WINDOW, 0, 0);
  416.     wnd->MenuBarWnd = CreateWindow(MENUBAR,
  417.                         NULL,
  418.                         GetClientLeft(wnd),
  419.                         GetClientTop(wnd)-1,
  420.                         1,
  421.                         ClientWidth(wnd),
  422.                         NULL,
  423.                         wnd,
  424.                         NULL,
  425.                         0);
  426.     SendMessage(wnd->MenuBarWnd,BUILDMENU,
  427.         (PARAM)wnd->extension,0);
  428.     AddAttribute(wnd->MenuBarWnd, VISIBLE);
  429. }
  430.  
  431. /* ----------- Create the status bar ------------- */
  432. static void CreateStatusBar(WINDOW wnd)
  433. {
  434.     if (wnd->StatusBar != NULL)    {
  435.         SendMessage(wnd->StatusBar, CLOSE_WINDOW, 0, 0);
  436.         wnd->StatusBar = NULL;
  437.     }
  438.     if (TestAttribute(wnd, HASSTATUSBAR))    {
  439.         wnd->StatusBar = CreateWindow(STATUSBAR,
  440.                             NULL,
  441.                             GetClientLeft(wnd),
  442.                             GetBottom(wnd),
  443.                             1,
  444.                             ClientWidth(wnd),
  445.                             NULL,
  446.                             wnd,
  447.                             NULL,
  448.                             0);
  449.         AddAttribute(wnd->StatusBar, VISIBLE);
  450.     }
  451. }
  452.  
  453. #ifdef INCLUDE_MULTI_WINDOWS
  454. /* -------- return the name of a document window ------- */
  455. static char *WindowName(WINDOW wnd)
  456. {
  457.     if (GetTitle(wnd) == NULL)    {
  458.         if (GetClass(wnd) == DIALOG)
  459.             return ((DBOX *)(wnd->extension))->HelpName;
  460.         else 
  461.             return "Untitled";
  462.     }
  463.     else
  464.         return GetTitle(wnd);
  465. }
  466.  
  467. /* ----------- Prepare the Window menu ------------ */
  468. void PrepWindowMenu(void *w, struct Menu *mnu)
  469. {
  470.     WINDOW wnd = w;
  471.     struct PopDown *p0 = mnu->Selections;
  472.     struct PopDown *pd = mnu->Selections + 2;
  473.     struct PopDown *ca = mnu->Selections + 13;
  474.     int MenuNo = 0;
  475.     WINDOW cwnd;
  476.     mnu->Selection = 0;
  477.     oldFocus = NULL;
  478.     if (GetClass(wnd) != APPLICATION)    {
  479.         oldFocus = wnd;
  480.         /* ----- point to the APPLICATION window ----- */
  481.         if (ApplicationWindow == NULL)
  482.             return;
  483.         cwnd = FirstWindow(ApplicationWindow);
  484.         /* ----- get the first 9 document windows ----- */
  485.         while (cwnd != NULL && MenuNo < 9)    {
  486.             if (isVisible(cwnd) && GetClass(cwnd) != MENUBAR &&
  487.                     GetClass(cwnd) != STATUSBAR) {
  488.                 /* --- add the document window to the menu --- */
  489.                 strncpy(Menus[MenuNo]+4, WindowName(cwnd), 20);
  490.                 pd->SelectionTitle = Menus[MenuNo];
  491.                 if (cwnd == oldFocus)    {
  492.                     /* -- mark the current document -- */
  493.                     pd->Attrib |= CHECKED;
  494.                     mnu->Selection = MenuNo+2;
  495.                 }
  496.                 else
  497.                     pd->Attrib &= ~CHECKED;
  498.                 pd++;
  499.                 MenuNo++;
  500.             }
  501.             cwnd = NextWindow(cwnd);
  502.         }
  503.     }
  504.     if (MenuNo)
  505.         p0->SelectionTitle = "~Close all";
  506.     else
  507.         p0->SelectionTitle = NULL;
  508.     if (MenuNo >= 9)    {
  509.         *pd++ = *ca;
  510.         if (mnu->Selection == 0)
  511.             mnu->Selection = 11;
  512.     }
  513.     pd->SelectionTitle = NULL;
  514. }
  515.  
  516. /* window processing module for the More Windows dialog box */
  517. static int WindowPrep(WINDOW wnd,MESSAGE msg,PARAM p1,PARAM p2)
  518. {
  519.     switch (msg)    {
  520.         case INITIATE_DIALOG:    {
  521.             WINDOW wnd1;
  522.             WINDOW cwnd = ControlWindow(&Windows,ID_WINDOWLIST);
  523.             int sel = 0;
  524.             if (cwnd == NULL)
  525.                 return FALSE;
  526.             wnd1 = FirstWindow(ApplicationWindow);
  527.             while (wnd1 != NULL)    {
  528.                 if (isVisible(wnd1) && wnd1 != wnd &&
  529.                         GetClass(wnd1) != MENUBAR &&
  530.                             GetClass(wnd1) != STATUSBAR)    {
  531.                     if (wnd1 == oldFocus)
  532.                         WindowSel = sel;
  533.                     SendMessage(cwnd, ADDTEXT,
  534.                         (PARAM) WindowName(wnd1), 0);
  535.                     sel++;
  536.                 }
  537.                 wnd1 = NextWindow(wnd1);
  538.             }
  539.             SendMessage(cwnd, LB_SETSELECTION, WindowSel, 0);
  540.             AddAttribute(cwnd, VSCROLLBAR);
  541.             PostMessage(cwnd, SHOW_WINDOW, 0, 0);
  542.             break;
  543.         }
  544.         case COMMAND:
  545.             switch ((int) p1)    {
  546.                 case ID_OK:
  547.                     if ((int)p2 == 0)
  548.                         WindowSel = SendMessage(
  549.                                     ControlWindow(&Windows,
  550.                                     ID_WINDOWLIST),
  551.                                     LB_CURRENTSELECTION, 0, 0);
  552.                     break;
  553.                 case ID_WINDOWLIST:
  554.                     if ((int) p2 == LB_CHOOSE)
  555.                         SendMessage(wnd, COMMAND, ID_OK, 0);
  556.                     break;
  557.                 default:
  558.                     break;
  559.             }
  560.             break;
  561.         default:
  562.             break;
  563.     }
  564.     return DefaultWndProc(wnd, msg, p1, p2);
  565. }
  566.  
  567. /* ---- the More Windows command on the Window menu ---- */
  568. static void MoreWindows(WINDOW wnd)
  569. {
  570.     if (DialogBox(wnd, &Windows, TRUE, WindowPrep))
  571.         ChooseWindow(wnd, WindowSel);
  572. }
  573.  
  574. /* ----- user chose a window from the Window menu
  575.         or the More Window dialog box ----- */
  576. static void ChooseWindow(WINDOW wnd, int WindowNo)
  577. {
  578.     WINDOW cwnd = FirstWindow(wnd);
  579.     while (cwnd != NULL)    {
  580.         if (isVisible(cwnd) &&
  581.                 GetClass(cwnd) != MENUBAR &&
  582.                     GetClass(cwnd) != STATUSBAR)
  583.             if (WindowNo-- == 0)
  584.                 break;
  585.         cwnd = NextWindow(cwnd);
  586.     }
  587.     if (cwnd != NULL)    {
  588.         SendMessage(cwnd, SETFOCUS, TRUE, 0);
  589.         if (cwnd->condition == ISMINIMIZED)
  590.             SendMessage(cwnd, RESTORE, 0, 0);
  591.     }
  592. }
  593.  
  594. /* ----- Close all document windows ----- */
  595. static void CloseAll(WINDOW wnd, int closing)
  596. {
  597.     WINDOW wnd1, wnd2;
  598.     SendMessage(wnd, SETFOCUS, TRUE, 0);
  599.     wnd1 = LastWindow(wnd);
  600.     while (wnd1 != NULL)    {
  601.         wnd2 = PrevWindow(wnd1);
  602.         if (isVisible(wnd1) &&
  603.                 GetClass(wnd1) != MENUBAR &&
  604.                     GetClass(wnd1) != STATUSBAR)    {
  605.             ClearVisible(wnd1);
  606.             SendMessage(wnd1, CLOSE_WINDOW, 0, 0);
  607.         }
  608.         wnd1 = wnd2;
  609.     }
  610.     if (!closing)
  611.         SendMessage(wnd, PAINT, 0, 0);
  612. }
  613.  
  614. #endif    /* #ifdef INCLUDE_MULTI_WINDOWS */
  615.  
  616. static void DoWindowColors(WINDOW wnd)
  617. {
  618.     WINDOW cwnd;
  619.     InitWindowColors(wnd);
  620.     cwnd = FirstWindow(wnd);
  621.     while (cwnd != NULL)    {
  622.         DoWindowColors(cwnd);
  623.         if (GetClass(cwnd) == TEXT && GetText(cwnd) != NULL)
  624.             SendMessage(cwnd, CLEARTEXT, 0, 0);
  625.         cwnd = NextWindow(cwnd);
  626.     }
  627. }
  628.  
  629. /* ----- set up colors for the application window ------ */
  630. static void SelectColors(WINDOW wnd)
  631. {
  632.     if (RadioButtonSetting(&Display, ID_MONO))
  633.         cfg.mono = 1;
  634.     else if (RadioButtonSetting(&Display, ID_REVERSE))
  635.         cfg.mono = 2;
  636.     else
  637.         cfg.mono = 0;
  638.     cfg.snowy = CheckBoxSetting(&Display, ID_SNOWY);
  639.     get_videomode();
  640.     if ((ismono() || video_mode == 2) && cfg.mono == 0)
  641.         cfg.mono = 1;
  642.  
  643.     if (cfg.mono == 1)
  644.         memcpy(cfg.clr, bw, sizeof bw);
  645.     else if (cfg.mono == 2)
  646.         memcpy(cfg.clr, reverse, sizeof reverse);
  647.     else
  648.         memcpy(cfg.clr, color, sizeof color);
  649.     DoWindowColors(wnd);
  650. }
  651.  
  652. /* ---- select screen lines ---- */
  653. static void SelectLines(WINDOW wnd)
  654. {
  655.     cfg.ScreenLines = 25;
  656.     if (isEGA() || isVGA())    {
  657.         if (RadioButtonSetting(&Display, ID_43LINES))
  658.             cfg.ScreenLines = 43;
  659.         else if (RadioButtonSetting(&Display, ID_50LINES))
  660.             cfg.ScreenLines = 50;
  661.     }
  662.     if (SCREENHEIGHT != cfg.ScreenLines)    {
  663.         SetScreenHeight(cfg.ScreenLines);
  664.         /* ---- re-maximize ---- */
  665.         if (wnd->condition == ISMAXIMIZED)    {
  666.             SendMessage(wnd, SIZE, (PARAM) GetRight(wnd),
  667.                 SCREENHEIGHT-1);
  668.             return;
  669.         }
  670.         /* --- adjust if current size does not fit --- */
  671.         if (WindowHeight(wnd) > SCREENHEIGHT)
  672.             SendMessage(wnd, SIZE, (PARAM) GetRight(wnd),
  673.                 (PARAM) GetTop(wnd)+SCREENHEIGHT-1);
  674.         /* --- if window is off-screen, move it on-screen --- */
  675.         if (GetTop(wnd) >= SCREENHEIGHT-1)
  676.             SendMessage(wnd, MOVE, (PARAM) GetLeft(wnd),
  677.                 (PARAM) SCREENHEIGHT-WindowHeight(wnd));
  678.     }
  679. }
  680.  
  681. /* ---- set the screen height in the video hardware ---- */
  682. static void SetScreenHeight(int height)
  683. {
  684.     if (isEGA() || isVGA())    {
  685.         SendMessage(NULL, SAVE_CURSOR, 0, 0);
  686.         switch (height)    {
  687.             case 25:
  688.                 Set25();
  689.                 break;
  690.             case 43:
  691.                 Set43();
  692.                 break;
  693.             case 50:
  694.                 Set50();
  695.                 break;
  696.             default:
  697.                 break;
  698.         }
  699.         SendMessage(NULL, RESTORE_CURSOR, 0, 0);
  700.         SendMessage(NULL, RESET_MOUSE, 0, 0);
  701.         SendMessage(NULL, SHOW_MOUSE, 0, 0);
  702.     }
  703. }
  704.  
  705. #ifdef INCLUDE_WINDOWOPTIONS
  706.  
  707. /* ----- select the screen texture ----- */
  708. static void SelectTexture(void)
  709. {
  710.     cfg.Texture = CheckBoxSetting(&Display, ID_TEXTURE);
  711. }
  712.  
  713. /* -- select whether the application screen has a border -- */
  714. static void SelectBorder(WINDOW wnd)
  715. {
  716.     cfg.Border = CheckBoxSetting(&Display, ID_BORDER);
  717.     if (cfg.Border)
  718.         AddAttribute(wnd, HASBORDER);
  719.     else
  720.         ClearAttribute(wnd, HASBORDER);
  721. }
  722.  
  723. /* select whether the application screen has a status bar */
  724. static void SelectStatusBar(WINDOW wnd)
  725. {
  726.     cfg.StatusBar = CheckBoxSetting(&Display, ID_STATUSBAR);
  727.     if (cfg.StatusBar)
  728.         AddAttribute(wnd, HASSTATUSBAR);
  729.     else
  730.         ClearAttribute(wnd, HASSTATUSBAR);
  731. }
  732.  
  733. /* select whether the application screen has a title bar */
  734. static void SelectTitle(WINDOW wnd)
  735. {
  736.     cfg.Title = CheckBoxSetting(&Display, ID_TITLE);
  737.     if (cfg.Title)
  738.         AddAttribute(wnd, HASTITLEBAR);
  739.     else
  740.         ClearAttribute(wnd, HASTITLEBAR);
  741. }
  742.  
  743. #endif
  744.  
  745. 
  746.