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