home *** CD-ROM | disk | FTP | other *** search
/ PC-Online 1998 February / PCOnline_02_1998.iso / filesbbs / dos / listz21s.exe / LZSET10S.RAR / LZS_SCRN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-25  |  5.2 KB  |  203 lines

  1. /*
  2.  * This file is part of LZSETUP (Configuration program for Listerz)
  3.  *
  4.  * Copyright (c) 1997 Branislav L. Slantchev (gargoyle)
  5.  * A fine product of Silicon Creations, Inc.
  6.  *
  7.  * This file is released under the terms and conditions of the GNU
  8.  * General Public License Version 2. The full text of the license is
  9.  * supplied in the Copying.Doc file included with this archive. This
  10.  * free software comes with absolutely no warranty, as outlined in the
  11.  * licensing text. You are not allowed to remove this copyright notice.
  12.  *
  13.  * Contact: Branislav L. Slantchev at 73023.262@compuserve.com
  14. */
  15. #include "geometry.h"
  16. #include "terminal.h"
  17. #include <stdio.h>
  18. #include <opwindow.h>
  19. #include <opcrt.h>
  20. #include <opcolor.h>
  21.  
  22. extern ColorSet   lz_Colors;
  23. extern boolean    lz_Dirty;
  24.  
  25. #define ATTR_HIGH 0x1E
  26. #define ATTR_NORM 0x19
  27. #define BACK_HIGH 0x1F
  28. #define BACK_NORM 0x01
  29. #define CHAR_HIGH '▓'
  30. #define CHAR_NORM '░'
  31.  
  32. static char      *StatusHelp =
  33.     "\x02    F2\x01 Save    \x02 Alt-X \x01Quit    \x02 \032 \x01Move  "
  34.     "\x02   Shift-\032 \x01Resize    \x02 Tab \01Switch    ";
  35. static FlexAttrs  FlexColors = { 0x74, 0x70, 0x74 };
  36.  
  37. /*
  38.  * display the background ansi/avatar/ascii/pcboard/wildcat file
  39. */
  40. static void
  41. DisplayFile(char *fileName)
  42. {
  43.     zTerminal       terminal;
  44.     ansi_interp     ansi;
  45.     avatar_interp   avatar;
  46.     pcboard_interp  pcboard;
  47.     FILE           *fp;
  48.  
  49.     terminal.clrScr();
  50.  
  51.     if( 0 != (fp = fopen(fileName, "rb")) )
  52.     {
  53.         uchar ch;
  54.  
  55.         terminal.RegisterHandler(&avatar);
  56.         terminal.RegisterHandler(&pcboard);
  57.         terminal.RegisterHandler(&ansi);
  58.  
  59.         setvbuf(fp, NULL, 0x4000, _IOFBF);
  60.         ch = fgetc(fp);
  61.         while( !feof(fp) )
  62.         {
  63.             terminal.handle(ch);
  64.             ch = fgetc(fp);
  65.         }
  66.         fclose(fp);
  67.  
  68.         terminal.flush();
  69.     }
  70. }
  71.  
  72. static void
  73. SwitchCurrent(StackWindow &prev, StackWindow &next, char *text)
  74. {
  75.     prev.SetTextAttr(BACK_NORM, 0x07);
  76.     prev.SetBackChar(CHAR_NORM);
  77.     prev.Clear();
  78.     next.Select();
  79.     next.SetTextAttr(BACK_HIGH, 0x07);
  80.     next.SetBackChar(CHAR_HIGH);
  81.     next.Clear();
  82.     next.wFastCenter(text, 1, ATTR_HIGH);
  83. }
  84.  
  85. /*
  86.  * edit several rectangles against a background file 'fileName'
  87. */
  88. void
  89. EditScreen(char *fileName, int nRects, zRect* r[], char *names[])
  90. {
  91.     StackWindow *win;
  92.     byte         x1, x2, y1, y2;
  93.     long         options = wClear|wResizeable|wUserContents;
  94.  
  95.     if( nRects > 1 && 0 != (win = new StackWindow [nRects]) )
  96.     {
  97.         int         i, curWin = 0;
  98.         void far   *buf;
  99.  
  100.         SaveWindow(1, 1, ScreenWidth, ScreenHeight, TRUE, buf);
  101.  
  102.         for( i = 0; i < nRects; ++i )
  103.         {
  104.             x1 = r[i]->a.x; y1 = r[i]->a.y;
  105.             x2 = r[i]->b.x; y2 = r[i]->b.y;
  106.  
  107.             win[i].InitCustom(x1, y1, x2, y2, lz_Colors, options);
  108.             win[i].SetPosLimits(1, 1, ScreenWidth - 1, ScreenHeight - 1);
  109.             win[i].SetSizeLimits(1, 1, ScreenWidth - 1, ScreenHeight - 1);
  110.             win[i].SetCursor(cuHidden);
  111.         }
  112.  
  113.         HiddenCursor();
  114.         DisplayFile(fileName);
  115.         for( i = 0; i < nRects; ++i )
  116.         {
  117.             win[i].Select();
  118.             win[i].Draw();
  119.             win[i].SetTextAttr(BACK_NORM, 0x07);
  120.             win[i].SetBackChar(CHAR_NORM);
  121.             win[i].Clear();
  122.         }
  123.  
  124.         // select the first window
  125.         win[curWin].Select();
  126.         win[curWin].SetTextAttr(BACK_HIGH, 0x07);
  127.         win[curWin].SetBackChar(CHAR_HIGH);
  128.         win[curWin].Clear();
  129.         win[curWin].wFastCenter(names[curWin], 1, ATTR_HIGH);
  130.  
  131.         // draw the help info on line 25
  132.         FlexWrite(StatusHelp, ScreenHeight, 1, FlexColors);
  133.  
  134.         // process user commands and resize/move windows
  135.         for( ;; )
  136.         {
  137.             int prevWin = curWin;
  138.  
  139.             switch( ReadKeyWord() )
  140.             {
  141.                 case 0x2D00:
  142.                     goto DoneSelections;  // Alt+X
  143.  
  144.                 case 0x0F09: // Tab
  145.                     curWin = (curWin + 1) % nRects;
  146.                     SwitchCurrent(win[prevWin], win[curWin], names[curWin]);
  147.                     break;
  148.  
  149.                 case 0x0F00: // Shift+Tab
  150.                     curWin = (0 == curWin) ? nRects - 1 : curWin - 1;
  151.                     SwitchCurrent(win[prevWin], win[curWin], names[curWin]);
  152.                     break;
  153.  
  154.                 case 0x3C00: // F2
  155.                     for( i = 0; i < nRects; ++i )
  156.                     {
  157.                         win[i].Coordinates(x1, y1, x2, y2);
  158.                         r[i]->a.x = x1; r[i]->a.y = y1;
  159.                         r[i]->b.x = x2; r[i]->b.y = y2;
  160.                         lz_Dirty = TRUE;
  161.                     }
  162.                     goto DoneSelections;
  163.  
  164.                 case 0x4B00: // Shift+Left and Left
  165.                     if( KbdFlags() & 3 ) win[curWin].ResizeWindow(-1,0);
  166.                     else win[curWin].MoveWindow(-1, 0);
  167.                     win[curWin].wFastCenter(names[curWin], 1, ATTR_HIGH);
  168.                     break;
  169.  
  170.                 case 0x4D00: // Shift+Right and Right
  171.                     if( KbdFlags() & 3 ) win[curWin].ResizeWindow(+1,0);
  172.                     else win[curWin].MoveWindow(+1, 0);
  173.                     win[curWin].wFastCenter(names[curWin], 1, ATTR_HIGH);
  174.                     break;
  175.  
  176.                 case 0x4800: // Shift+Up and Up
  177.                     if( KbdFlags() & 3 ) win[curWin].ResizeWindow(0,-1);
  178.                     else win[curWin].MoveWindow(0, -1);
  179.                     win[curWin].wFastCenter(names[curWin], 1, ATTR_HIGH);
  180.                     break;
  181.  
  182.                 case 0x5000: // Shift+Down and Down
  183.                     if( KbdFlags() & 3 ) win[curWin].ResizeWindow(0,+1);
  184.                     else win[curWin].MoveWindow(0, +1);
  185.                     win[curWin].wFastCenter(names[curWin], 1, ATTR_HIGH);
  186.                     break;
  187.             }
  188.         }
  189.  
  190.     DoneSelections:
  191.         // screen cleanup
  192.         for( i = 0; i < nRects; ++i )
  193.         {
  194.             win[i].Select();
  195.             win[i].Erase();
  196.             win[i].Done();
  197.         }
  198.         delete[] win;
  199.  
  200.         RestoreWindow(1, 1, ScreenWidth, ScreenHeight, TRUE, buf);
  201.     }
  202. }
  203.