home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / drdobbs / 1991 / 08 / dflat5 / applicat.c next >
Text File  |  1991-06-23  |  18KB  |  708 lines

  1. /* ------------- applicat.c ------------- */
  2.  
  3. #include <stdio.h>
  4. #include <string.h>
  5. #include <stdlib.h>
  6. #include <dos.h>
  7. #include <process.h>
  8. #include "dflat.h"
  9.  
  10. static int ScreenHeight;
  11.  
  12. #ifdef INCLUDE_DIALOG_BOXES
  13. extern DBOX TabStops;
  14. extern DBOX DisplayCGA;
  15. extern DBOX DisplayEGA;
  16. extern DBOX DisplayVGA;
  17. extern DBOX Windows;
  18. extern DBOX Log;
  19. static DBOX *Display;
  20. #endif
  21.  
  22. static void ShellDOS(WINDOW);
  23. static void CreateMenu(WINDOW);
  24. static void CreateStatusBar(WINDOW);
  25. static void CloseAll(WINDOW);
  26. static void SelectColors(void);
  27. static void SetScreenHeight(int);
  28. #ifdef INCLUDE_MULTIDOCS
  29. static void ChooseWindow(WINDOW, int);
  30. static void SelectTexture(void);
  31. static void SelectBorder(WINDOW);
  32. static void SelectTitle(WINDOW);
  33. static void SelectStatusBar(WINDOW);
  34. #endif
  35. #ifdef INCLUDE_DIALOG_BOXES
  36. static void SelectLines(WINDOW);
  37. #endif
  38.  
  39. int ApplicationProc(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  40. {
  41.     int rtn, WasVisible;
  42.  
  43.     switch (msg)    {
  44.         case CREATE_WINDOW:
  45.             ScreenHeight = SCREENHEIGHT;
  46.             if (!LoadConfig())
  47.                 cfg.ScreenLines = ScreenHeight;
  48.             if (cfg.InsertMode)
  49.                 SetCommandToggle(MainMenu, ID_INSERT);
  50.             if (cfg.WordWrap)
  51.                 SetCommandToggle(MainMenu, ID_WRAP);
  52. #ifdef INCLUDE_DIALOG_BOXES
  53.             if (isVGA())
  54.                 Display = &DisplayVGA;
  55.             else if (isEGA())
  56.                 Display = &DisplayEGA;
  57.             else 
  58.                 Display = &DisplayCGA;
  59.             if (cfg.Border)
  60.                 SetCheckBox(Display, ID_BORDER);
  61.             if (cfg.Title)
  62.                 SetCheckBox(Display, ID_TITLE);
  63.             if (cfg.StatusBar)
  64.                 SetCheckBox(Display, ID_STATUSBAR);
  65.             if (cfg.Texture)
  66.                 SetCheckBox(Display, ID_TEXTURE);
  67.             if (cfg.mono == 1)
  68.                 PushRadioButton(Display, ID_MONO);
  69.             else if (cfg.mono == 2)
  70.                 PushRadioButton(Display, ID_REVERSE);
  71.             else
  72.                 PushRadioButton(Display, ID_COLOR);
  73.             if (cfg.ScreenLines == 25)
  74.                 PushRadioButton(Display, ID_25LINES);
  75.             else if (cfg.ScreenLines == 43)
  76.                 PushRadioButton(Display, ID_43LINES);
  77.             else if (cfg.ScreenLines == 50)
  78.                 PushRadioButton(Display, ID_50LINES);
  79. #endif
  80.             if (SCREENHEIGHT != cfg.ScreenLines)    {
  81.                 SetScreenHeight(cfg.ScreenLines);
  82.                 if (WindowHeight(wnd) == ScreenHeight ||
  83.                         SCREENHEIGHT-1 < GetBottom(wnd))    {
  84.                     WindowHeight(wnd) = SCREENHEIGHT-1;
  85.                     GetBottom(wnd) = GetTop(wnd)+WindowHeight(wnd)-1;
  86.                     wnd->RestoredRC = WindowRect(wnd);
  87.                 }
  88.             }
  89.             SelectColors();
  90. #ifdef INCLUDE_MULTIDOCS
  91.             SelectBorder(wnd);
  92.             SelectTitle(wnd);
  93.             SelectStatusBar(wnd);
  94. #endif
  95.             rtn = BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  96.             if (wnd->extension != NULL)
  97.                 CreateMenu(wnd);
  98. #ifdef INCLUDE_STATUSBAR
  99.             CreateStatusBar(wnd);
  100. #endif
  101. #ifdef INCLUDE_HELP
  102.             LoadHelpFile();
  103. #endif
  104.             SendMessage(NULLWND, SHOW_MOUSE, 0, 0);
  105.             return rtn;
  106. #ifdef INCLUDE_STATUSBAR
  107.         case ADDSTATUS:
  108.             if (wnd->StatusBar != NULLWND)    {
  109.                 if (p1 && *(char *)p1)
  110.                     SendMessage(wnd->StatusBar, SETTEXT, p1, p2);
  111.                 else 
  112.                     SendMessage(wnd->StatusBar, CLEARTEXT, 0, 0);
  113.                 SendMessage(wnd->StatusBar, PAINT, 0, 0);
  114.             }
  115.             return TRUE;
  116. #endif
  117.         case SETFOCUS:
  118.             if (p1 && inFocus != wnd)    {
  119.                 /* ---- setting focus ------ */
  120.                 SendMessage(inFocus, SETFOCUS, FALSE, 0);
  121.                 /* remove window from list */
  122.                 RemoveFocusWindow(wnd);
  123.                 /* move window to end of list */
  124.                 AppendFocusWindow(wnd);
  125.                 inFocus = wnd;
  126.                 SendMessage(wnd, BORDER, 0, 0);
  127.                 return TRUE;
  128.             }
  129.             break;
  130.         case SIZE:
  131.             WasVisible = isVisible(wnd);
  132.             if (WasVisible)
  133.                 SendMessage(wnd, HIDE_WINDOW, 0, 0);
  134.             if (p1-GetLeft(wnd) < 30)
  135.                 p1 = GetLeft(wnd) + 30;
  136.             BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  137.             CreateMenu(wnd);
  138. #ifdef INCLUDE_STATUSBAR
  139.             CreateStatusBar(wnd);
  140. #endif
  141.             if (WasVisible)
  142.                 SendMessage(wnd, SHOW_WINDOW, 0, 0);
  143.             return TRUE;
  144.         case KEYBOARD:
  145. #ifdef INCLUDE_HELP
  146.             if ((int)p1 == F1)
  147.                 break;
  148. #endif
  149. #ifdef INCLUDE_SYSTEM_MENUS
  150.             if ((int)p1 == ALT_HYPHEN)    {
  151.                 BuildSystemMenu(wnd);
  152.                 return TRUE;
  153.             }
  154.             if (WindowSizing || WindowMoving)
  155.                 break;
  156. #endif
  157.         /* ----- fall through here ----- */
  158.         case SHIFT_CHANGED:
  159.             PostMessage(wnd->MenuBar, msg, p1, p2);
  160.             return TRUE;
  161.         case PAINT:
  162.             if (isVisible(wnd))
  163.                 ClearWindow(wnd, (RECT *)p1, cfg.Texture ?
  164.                     APPLCHAR : ' ');
  165.             return TRUE;
  166.         case COMMAND:
  167.             switch ((int)p1)    {
  168. #ifdef INCLUDE_HELP
  169.                 case ID_HELP:
  170.                     DisplayHelp(wnd, DFLAT_APPLICATION);
  171.                     break;
  172.                 case ID_HELPHELP:
  173.                     DisplayHelp(wnd, "HelpHelp");
  174.                     break;
  175.                 case ID_EXTHELP:
  176.                     DisplayHelp(wnd, "ExtHelp");
  177.                     break;
  178.                 case ID_KEYSHELP:
  179.                     DisplayHelp(wnd, "KeysHelp");
  180.                     break;
  181.                 case ID_HELPINDEX:
  182.                     DisplayHelp(wnd, "HelpIndex");
  183.                     break;
  184. #ifdef INCLUDE_RELOADHELP
  185.                 case ID_LOADHELP:
  186.                     LoadHelpFile();
  187.                     break;
  188. #endif
  189. #endif
  190. #ifdef INCLUDE_LOGGING
  191.                 case ID_LOG:
  192.                     MessageLog(wnd);
  193.                     if (CheckBoxSetting(&Log, ID_LOGGING))
  194.                         SetCommandToggle(MainMenu, ID_LOG);
  195.                     else
  196.                         ClearCommandToggle(MainMenu, ID_LOG);
  197.                     break;
  198. #endif
  199.                 case ID_DOS:
  200.                     ShellDOS(wnd);
  201.                     return TRUE;
  202.                 case ID_EXIT:
  203.                 case ID_SYSCLOSE:
  204.                     PostMessage(wnd, CLOSE_WINDOW, 0, 0);
  205.                     break;
  206. #ifdef INCLUDE_DIALOG_BOXES
  207.                 case ID_DISPLAY:
  208.                     if (DialogBox(wnd, Display, TRUE, NULL))    {
  209.                         SendMessage(wnd, HIDE_WINDOW, 0, 0);
  210.                         SelectColors();
  211.                         SelectLines(wnd);
  212. #ifdef INCLUDE_MULTIDOCS
  213.                         SelectBorder(wnd);
  214.                         SelectTitle(wnd);
  215.                         SelectStatusBar(wnd);
  216.                         SelectTexture();
  217. #endif
  218.                         CreateMenu(wnd);
  219. #ifdef INCLUDE_STATUSBAR
  220.                         CreateStatusBar(wnd);
  221. #endif
  222.                         SendMessage(wnd, SHOW_WINDOW, 0, 0);
  223.                     }
  224.                     break;
  225.                 case ID_TABS:
  226.                     switch (cfg.Tabs)    {
  227.                         case 2:
  228.                             PushRadioButton(&TabStops, ID_TAB2);
  229.                             break;
  230.                         case 4:
  231.                             PushRadioButton(&TabStops, ID_TAB4);
  232.                             break;
  233.                         case 6:
  234.                             PushRadioButton(&TabStops, ID_TAB6);
  235.                             break;
  236.                         case 8:
  237.                             PushRadioButton(&TabStops, ID_TAB8);
  238.                             break;
  239.                         default:
  240.                             break;
  241.                     }
  242.                     if (DialogBox(wnd, &TabStops, TRUE, NULL))    {
  243.                         if (RadioButtonSetting(&TabStops, ID_TAB2))
  244.                             cfg.Tabs = 2;
  245.                         if (RadioButtonSetting(&TabStops, ID_TAB4))
  246.                             cfg.Tabs = 4;
  247.                         if (RadioButtonSetting(&TabStops, ID_TAB6))
  248.                             cfg.Tabs = 6;                    
  249.                         if (RadioButtonSetting(&TabStops, ID_TAB8))
  250.                             cfg.Tabs = 8;
  251.                     }
  252.                     break;
  253. #endif
  254.                 case ID_SAVEOPTIONS:
  255.                     SaveConfig();
  256.                     break;
  257. #ifdef INCLUDE_MULTIDOCS
  258.                 case ID_WINDOW:
  259.                     ChooseWindow(wnd, (int)p2-2);
  260.                     break;
  261.                 case ID_CLOSEALL:
  262.                     CloseAll(wnd);
  263.                     break;
  264. #endif
  265.                 case ID_SYSRESTORE:
  266.                 case ID_SYSMOVE:
  267.                 case ID_SYSSIZE:
  268.                 case ID_SYSMINIMIZE:
  269.                 case ID_SYSMAXIMIZE:
  270.                     return BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  271.                 default:
  272.                     if (inFocus != wnd->MenuBar)
  273.                         PostMessage(inFocus, msg, p1, p2);
  274.                     break;
  275.             }
  276.             return TRUE;
  277. #ifdef INCLUDE_SYSTEM_MENUS
  278.         case LEFT_BUTTON:    {
  279.             WINDOW wnd1 = wnd;
  280.             int mx, my;
  281.             if (WindowSizing || WindowMoving)
  282.                 return FALSE;
  283.             if (SendMessage(wnd, INSIDE_WINDOW, p1, p2))    {
  284.                 if (inFocus && inFocus != wnd->MenuBar)
  285.                     if (SendMessage(inFocus, INSIDE_WINDOW, p1, p2))
  286.                         wnd1 = inFocus;
  287.                 mx = (int) p1 - GetLeft(wnd1);
  288.                 my = (int) p2 - GetTop(wnd1);
  289.                 if (HitControlBox(wnd1, mx, my))    {
  290.                     BuildSystemMenu(wnd1);
  291.                     return TRUE;
  292.                 }
  293.             }
  294.             break;
  295.         }
  296. #endif
  297.         case CLOSE_WINDOW:
  298.             if (!YesNoBox("Exit " DFLAT_APPLICATION "?"))
  299.                 return FALSE;
  300.             CloseAll(wnd);
  301.             PostMessage(NULLWND, STOP, 0, 0);
  302.             rtn = BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  303.             if (ScreenHeight != SCREENHEIGHT)
  304.                 SetScreenHeight(ScreenHeight);
  305. #ifdef INCLUDE_HELP
  306.             UnLoadHelpFile();
  307. #endif
  308.             SendMessage(NULLWND, HIDE_MOUSE, 0, 0);
  309.             return rtn;
  310.         default:
  311.             break;
  312.     }
  313.     return BaseWndProc(APPLICATION, wnd, msg, p1, p2);
  314. }
  315.  
  316. static void SwitchCursor(void)
  317. {
  318.     SendMessage(NULLWND, SAVE_CURSOR, 0, 0);
  319.     SwapCursorStack();
  320.     SendMessage(NULLWND, RESTORE_CURSOR, 0, 0);
  321. }
  322.  
  323. /* ------- Shell out to DOS ---------- */
  324. static void ShellDOS(WINDOW wnd)
  325. {
  326.     SendMessage(wnd, HIDE_WINDOW, 0, 0);
  327.     SwitchCursor();
  328.     if (ScreenHeight != SCREENHEIGHT)
  329.         SetScreenHeight(ScreenHeight);
  330.     SendMessage(NULLWND, HIDE_MOUSE, 0, 0);
  331.     printf("To return to " DFLAT_APPLICATION
  332.         ", execute the DOS exit command.");
  333.     spawnl(P_WAIT, getenv("COMSPEC"), NULL);
  334.     if (SCREENHEIGHT != cfg.ScreenLines)
  335.         SetScreenHeight(cfg.ScreenLines);
  336.     SwitchCursor();
  337.     SendMessage(wnd, SHOW_WINDOW, 0, 0);
  338.     SendMessage(NULLWND, SHOW_MOUSE, 0, 0);
  339. }
  340.  
  341. static void CreateMenu(WINDOW wnd)
  342. {
  343.     AddAttribute(wnd, HASMENUBAR);
  344.     if (wnd->MenuBar != NULLWND)
  345.         SendMessage(wnd->MenuBar, CLOSE_WINDOW, 0, 0);
  346.     wnd->MenuBar = CreateWindow(MENUBAR,
  347.                         NULL,
  348.                         GetClientLeft(wnd),
  349.                         GetClientTop(wnd)-1,
  350.                         1,
  351.                         ClientWidth(wnd),
  352.                         NULL,
  353.                         wnd,
  354.                         NULL,
  355.                         0);
  356.     SendMessage(wnd->MenuBar, BUILDMENU, (PARAM) wnd->extension, 0);
  357. }
  358.  
  359. #ifdef INCLUDE_STATUSBAR
  360. static void CreateStatusBar(WINDOW wnd)
  361. {
  362.     if (wnd->StatusBar != NULLWND)    {
  363.         SendMessage(wnd->StatusBar, CLOSE_WINDOW, 0, 0);
  364.         wnd->StatusBar = NULLWND;
  365.     }
  366.     if (TestAttribute(wnd, HASBORDER) &&
  367.             TestAttribute(wnd, HASSTATUSBAR))    {
  368.         wnd->StatusBar = CreateWindow(STATUSBAR,
  369.                             NULL,
  370.                             GetClientLeft(wnd),
  371.                             GetBottom(wnd),
  372.                             1,
  373.                             ClientWidth(wnd),
  374.                             NULL,
  375.                             wnd,
  376.                             NULL,
  377.                             SAVESELF);
  378.     }
  379. }
  380. #endif
  381.  
  382. static WINDOW oldFocus;
  383.  
  384. static void SetOldFocus(void)
  385. {
  386.     if (GetClass(inFocus) == MENUBAR)
  387.         oldFocus = PrevWindow(inFocus);
  388.     else
  389.         oldFocus = inFocus;
  390. }
  391.  
  392. void PrepFileMenu(void *wnd, struct Menu *mnu)
  393. {
  394.     DeactivateCommand(MainMenu, ID_SAVE);
  395.     DeactivateCommand(MainMenu, ID_SAVEAS);
  396.     DeactivateCommand(MainMenu, ID_PRINT);
  397.     SetOldFocus();
  398.     if (oldFocus != NULLWND && GetClass(oldFocus) == EDITBOX) {
  399.         if (isMultiLine(oldFocus))    {
  400.             ActivateCommand(MainMenu, ID_SAVE);
  401.             ActivateCommand(MainMenu, ID_SAVEAS);
  402.             ActivateCommand(MainMenu, ID_PRINT);
  403.         }
  404.     }
  405. }
  406.  
  407. void PrepSearchMenu(void *wnd, struct Menu *mnu)
  408. {
  409.     DeactivateCommand(MainMenu, ID_SEARCH);
  410.     DeactivateCommand(MainMenu, ID_REPLACE);
  411.     DeactivateCommand(MainMenu, ID_SEARCHNEXT);
  412.     SetOldFocus();
  413.     if (oldFocus != NULLWND && GetClass(oldFocus) == EDITBOX) {
  414.         if (isMultiLine(oldFocus))    {
  415.             ActivateCommand(MainMenu, ID_SEARCH);
  416.             ActivateCommand(MainMenu, ID_REPLACE);
  417.             ActivateCommand(MainMenu, ID_SEARCHNEXT);
  418.         }
  419.     }
  420. }
  421.  
  422. void PrepEditMenu(void *wnd, struct Menu *mnu)
  423. {
  424.     DeactivateCommand(MainMenu, ID_CUT);
  425.     DeactivateCommand(MainMenu, ID_COPY);
  426.     DeactivateCommand(MainMenu, ID_CLEAR);
  427.     DeactivateCommand(MainMenu, ID_DELETETEXT);
  428.     DeactivateCommand(MainMenu, ID_PARAGRAPH);
  429.     DeactivateCommand(MainMenu, ID_PASTE);
  430.     DeactivateCommand(MainMenu, ID_UNDO);
  431.     DeactivateCommand(MainMenu, ID_SEARCH);
  432.     DeactivateCommand(MainMenu, ID_SEARCHNEXT);
  433.     SetOldFocus();
  434.     if (oldFocus != NULLWND && GetClass(oldFocus) == EDITBOX) {
  435.         if (isMultiLine(oldFocus))    {
  436.             if (BlockMarked(oldFocus))    {
  437.                 ActivateCommand(MainMenu, ID_CUT);
  438.                 ActivateCommand(MainMenu, ID_COPY);
  439.                 ActivateCommand(MainMenu, ID_CLEAR);
  440.                 ActivateCommand(MainMenu, ID_DELETETEXT);
  441.             }
  442.             ActivateCommand(MainMenu, ID_PARAGRAPH);
  443.             if (!TestAttribute(oldFocus, READONLY) &&
  444.                         Clipboard != NULL)
  445.                 ActivateCommand(MainMenu, ID_PASTE);
  446.             if (oldFocus->DeletedText != NULL)
  447.                 ActivateCommand(MainMenu, ID_UNDO);
  448.         }
  449.     }
  450. }
  451.  
  452. static char *Menus[9] = {
  453.     "~1.                      ",
  454.     "~2.                      ",
  455.     "~3.                      ",
  456.     "~4.                      ",
  457.     "~5.                      ",
  458.     "~6.                      ",
  459.     "~7.                      ",
  460.     "~8.                      ",
  461.     "~9.                      "
  462. };
  463.  
  464. #ifdef INCLUDE_MULTIDOCS
  465.  
  466. static int WindowSel;
  467.  
  468. void PrepWindowMenu(void *wnd, struct Menu *mnu)
  469. {
  470.     struct PopDown *p0 = mnu->Selections;
  471.     struct PopDown *pd = mnu->Selections + 2;
  472.     struct PopDown *ca = mnu->Selections + 13;
  473.     int MenuNo = 0;
  474.     WINDOW wnd1 = Built.FirstWindow;
  475.     mnu->Selection = 0;
  476.     oldFocus = PrevWindow(inFocus);
  477.     while (wnd1 != NULLWND && MenuNo < 9)    {
  478.         if (GetClass(wnd1) != MENUBAR &&
  479.                 GetClass(wnd1) != STATUSBAR &&
  480.                     GetParent(wnd1) == wnd)    {
  481.             strncpy(Menus[MenuNo]+4, GetTitle(wnd1), 20);
  482.             pd->SelectionTitle = Menus[MenuNo];
  483.             if (wnd1 == oldFocus)    {
  484.                 pd->Attrib |= CHECKED;
  485.                 mnu->Selection = MenuNo+2;
  486.             }
  487.             else
  488.                 pd->Attrib &= ~CHECKED;
  489.             pd++;
  490.             MenuNo++;
  491.         }
  492.         wnd1 = NextWindowBuilt(wnd1);
  493.     }
  494.     if (MenuNo)
  495.         p0->SelectionTitle = "~Close all";
  496.     else
  497.         p0->SelectionTitle = NULL;
  498.     if (wnd1 != NULLWND)    {
  499.         *pd++ = *ca;
  500.         if (mnu->Selection == 0)
  501.             mnu->Selection = 11;
  502.     }
  503.     pd->SelectionTitle = NULL;
  504. }
  505.  
  506. #ifdef INCLUDE_DIALOG_BOXES
  507. static int WindowPrep(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  508. {
  509.     switch (msg)    {
  510.         case INITIATE_DIALOG:    {
  511.             WINDOW wnd1 = Built.FirstWindow;
  512.             WINDOW cwnd = ControlWindow(&Windows, ID_WINDOWLIST);
  513.             int sel = 0;
  514.             if (cwnd == NULLWND)
  515.                 return FALSE;
  516.             while (wnd1 != NULLWND)    {
  517.                 if (GetClass(wnd1) != MENUBAR &&
  518.                         GetClass(wnd1) != STATUSBAR &&
  519.                             GetParent(wnd1) == GetParent(wnd) &&
  520.                                 wnd1 != wnd)    {
  521.                     if (wnd1 == oldFocus)
  522.                         WindowSel = sel;
  523.                     SendMessage(cwnd, ADDTEXT, (PARAM) GetTitle(wnd1), 0);
  524.                     sel++;
  525.                 }
  526.                 wnd1 = NextWindowBuilt(wnd1);
  527.             }
  528.             SendMessage(cwnd, LB_SETSELECTION, WindowSel, 0);
  529. #ifdef INCLUDE_SCROLLBARS
  530.             AddAttribute(cwnd, VSCROLLBAR);
  531. #endif
  532.             PostMessage(cwnd, SHOW_WINDOW, 0, 0);
  533.             break;
  534.         }
  535.         case COMMAND:
  536.             switch ((int) p1)    {
  537.                 case ID_OK:
  538.                     WindowSel = SendMessage(ControlWindow(&Windows,
  539.                                         ID_WINDOWLIST),
  540.                                             LB_CURRENTSELECTION, 0, 0);
  541.                     break;
  542.                 case ID_WINDOWLIST:
  543.                     if ((int) p2 == LB_CHOOSE)
  544.                         SendMessage(wnd, COMMAND, ID_OK, 0);
  545.                     break;
  546.                 default:
  547.                     break;
  548.             }
  549.             break;
  550.         default:
  551.             break;
  552.     }
  553.     return DefaultWndProc(wnd, msg, p1, p2);
  554. }
  555. #endif
  556.  
  557. static void ChooseWindow(WINDOW wnd, int WindowNo)
  558. {
  559.     WINDOW wnd1 = GetFirstChild(wnd);
  560.     if (WindowNo == 9)    {
  561. #ifdef INCLUDE_DIALOG_BOXES
  562.         if (DialogBox(wnd, &Windows, TRUE, WindowPrep))
  563.             WindowNo = WindowSel;
  564.         else
  565. #endif
  566.             return;
  567.     }
  568.     while (wnd1 != NULLWND)    {
  569.         if (GetClass(wnd1) != MENUBAR && GetClass(wnd1) != STATUSBAR)
  570.             if (WindowNo-- == 0)
  571.                 break;
  572.         wnd1 = GetNextChild(wnd, wnd1);
  573.     }
  574.     SendMessage(wnd1, SETFOCUS, TRUE, 0);
  575.     if (wnd1->condition == ISMINIMIZED)
  576.         SendMessage(wnd1, RESTORE, 0, 0);
  577. }
  578.  
  579. #endif
  580.  
  581. static void SelectColors(void)
  582. {
  583. #ifdef INCLUDE_DIALOG_BOXES
  584.     if (RadioButtonSetting(Display, ID_MONO))
  585.         cfg.mono = 1;
  586.     else if (RadioButtonSetting(Display, ID_REVERSE))
  587.         cfg.mono = 2;
  588.     else
  589.         cfg.mono = 0;
  590. #endif
  591.     if ((ismono() || video_mode == 2) && cfg.mono == 0)
  592.         cfg.mono = 1;
  593.  
  594.     if (cfg.mono == 1)
  595.         memcpy(cfg.clr, bw, sizeof bw);
  596.     else if (cfg.mono == 2)
  597.         memcpy(cfg.clr, reverse, sizeof reverse);
  598.     else
  599.         memcpy(cfg.clr, color, sizeof color);
  600. }
  601.  
  602. #ifdef INCLUDE_DIALOG_BOXES
  603. static void SelectLines(WINDOW wnd)
  604. {
  605.     cfg.ScreenLines = 25;
  606.     if (isEGA() || isVGA())    {
  607.         if (RadioButtonSetting(Display, ID_43LINES))
  608.             cfg.ScreenLines = 43;
  609.         else if (RadioButtonSetting(Display, ID_50LINES))
  610.             cfg.ScreenLines = 50;
  611.     }
  612.     if (SCREENHEIGHT != cfg.ScreenLines)    {
  613.         int FullScreen = WindowHeight(wnd) == SCREENHEIGHT;
  614.         SetScreenHeight(cfg.ScreenLines);
  615.         if (FullScreen || SCREENHEIGHT-1 < GetBottom(wnd))
  616.             SendMessage(wnd, SIZE, (PARAM) GetRight(wnd),
  617.                 SCREENHEIGHT-1);
  618.     }
  619. }
  620. #endif
  621.  
  622. static void SetScreenHeight(int height)
  623. {
  624.     if (isEGA() || isVGA())    {
  625.         SendMessage(NULLWND, SAVE_CURSOR, 0, 0);
  626.         switch (height)    {
  627.             case 25:
  628.                 Set25();
  629.                 break;
  630.             case 43:
  631.                 Set43();
  632.                 break;
  633.             case 50:
  634.                 Set50();
  635.                 break;
  636.             default:
  637.                 break;
  638.         }
  639.         SendMessage(NULLWND, RESTORE_CURSOR, 0, 0);
  640.         resetmouse();
  641.         SendMessage(NULLWND, SHOW_MOUSE, 0, 0);
  642.     }
  643. }
  644.  
  645. #ifdef INCLUDE_MULTIDOCS
  646. static void SelectTexture(void)
  647. {
  648. #ifdef INCLUDE_DIALOG_BOXES
  649.     cfg.Texture = CheckBoxSetting(Display, ID_TEXTURE);
  650. #endif
  651. }
  652.  
  653. static void SelectBorder(WINDOW wnd)
  654. {
  655. #ifdef INCLUDE_DIALOG_BOXES
  656.     cfg.Border = CheckBoxSetting(Display, ID_BORDER);
  657. #endif
  658.     if (cfg.Border)
  659.         AddAttribute(wnd, HASBORDER);
  660.     else
  661.         ClearAttribute(wnd, HASBORDER);
  662. }
  663.  
  664. static void SelectStatusBar(WINDOW wnd)
  665. {
  666. #ifdef INCLUDE_DIALOG_BOXES
  667.     cfg.StatusBar = CheckBoxSetting(Display, ID_STATUSBAR);
  668. #endif
  669.     if (cfg.StatusBar)
  670.         AddAttribute(wnd, HASSTATUSBAR);
  671.     else
  672.         ClearAttribute(wnd, HASSTATUSBAR);
  673. }
  674.  
  675. static void SelectTitle(WINDOW wnd)
  676. {
  677. #ifdef INCLUDE_DIALOG_BOXES
  678.     cfg.Title = CheckBoxSetting(Display, ID_TITLE);
  679. #endif
  680.     if (cfg.Title)
  681.         AddAttribute(wnd, HASTITLEBAR);
  682.     else
  683.         ClearAttribute(wnd, HASTITLEBAR);
  684. }
  685. #endif
  686.  
  687. static void CloseAll(WINDOW wnd)
  688. {
  689.     WINDOW wnd1 = GetLastChild(wnd);
  690.     ClearAttribute(wnd, VISIBLE);
  691.     while (wnd1 != NULLWND)    {
  692.         if (GetClass(wnd1) == MENUBAR
  693. #ifdef INCLUDE_STATUSBAR
  694.                 || GetClass(wnd1) == STATUSBAR
  695. #endif
  696.                         )
  697.             wnd1 = GetPrevChild(wnd, wnd1);
  698.         else    {
  699.             SendMessage(wnd1, CLOSE_WINDOW, 0, 0);
  700.             wnd1 = GetLastChild(wnd);
  701.         }
  702.     }
  703.     AddAttribute(wnd, VISIBLE);
  704.     SendMessage(wnd, SETFOCUS, TRUE, 0);
  705.     SendMessage(wnd, PAINT, 0, 0);
  706. }
  707.  
  708.