home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w048 / 2.ddi / MSSRC.ARC / MSWINDOW.INC < prev   
Encoding:
Text File  |  1987-12-21  |  4.5 KB  |  141 lines

  1. {                            MSWINDOW.INC
  2.                                MS 4.0
  3.                 Copyright (c) 1985, 87 by Borland International, Inc.         }
  4.  
  5.   procedure EdDrawBox(Border : BorderChars;
  6.                       XPosn, YPosn, XSize, YSize : Byte;
  7.                       BoxAttr : BoxType);
  8.     {-Draw a box frame on the screen}
  9.   var
  10.     L, R, T, B, I, Attr : Byte;
  11.     HorizBar : VarString;
  12.  
  13.   begin                      {EdDrawBox}
  14.  
  15.     L := XPosn;
  16.     R := Pred(XPosn+XSize);
  17.     T := YPosn;
  18.     B := Pred(YPosn+YSize);
  19.     Attr := FrameAttr[BoxAttr];
  20.  
  21.     {Draw horizontal segments}
  22.     HorizBar[0] := Chr(XSize);
  23.     FillChar(HorizBar[1], Length(HorizBar), Border[Horiz]);
  24.     HorizBar[1] := Border[TopLeft];
  25.     HorizBar[Length(HorizBar)] := Border[TopRight];
  26.     {Draw top bar}
  27.     EdFastWrite(HorizBar, T, L, Attr);
  28.     {Fix bottom bar}
  29.     HorizBar[1] := Border[BotLeft];
  30.     HorizBar[Length(HorizBar)] := Border[BotRight];
  31.     EdFastWrite(HorizBar, B, L, Attr);
  32.  
  33.     {Vertical segments}
  34.     for I := Succ(T) to Pred(B) do begin
  35.       EdFastWrite(Border[Vert], I, L, Attr);
  36.       EdFastWrite(Border[Vert], I, R, Attr);
  37.     end;
  38.   end;                       {EdDrawBox}
  39.  
  40.   procedure EdClearWindow(XPosn, YPosn, XSize, YSize, Attr : Byte);
  41.     {-Clear screen region to a specified attribute}
  42.   var
  43.     S : VarString;
  44.     I : Integer;
  45.  
  46.   begin                      {EdClearWindow}
  47.     S[0] := Chr(XSize-2);
  48.     FillChar(S[1], Length(S), Blank);
  49.     for I := 1 to YSize-2 do
  50.       EdFastWrite(S, YPosn+I, Succ(XPosn), Attr);
  51.   end;                       {EdClearWindow}
  52.  
  53.   function EdSetupWindow(Border : BorderChars;
  54.                          XLow, YLow, XHigh, YHigh : Byte;
  55.                          BoxAttr : BoxType) : WindowPtr;
  56.     {-Save current screen and set up a new window}
  57.   var
  58.     W : WindowPtr;
  59.     Xs, Ys, I : Byte;
  60.  
  61.   begin                      {EdSetupWindow}
  62.  
  63.     Xs := Succ(XHigh-XLow);
  64.     Ys := Succ(YHigh-YLow);
  65.  
  66.     {Allocate 2 bytes for each screen position}
  67.     GetMem(W, (Xs*Ys) shl 1);
  68.  
  69.     {Save the existing contents}
  70.     for I := 0 to Pred(Ys) do
  71.       EdMoveFromScreen(Mem[ScreenAdr: (PhyScrCols*Pred(YLow+I)+Pred(XLow)) shl 1], W^[I*Xs], Xs);
  72.  
  73.     {Draw box around window}
  74.     EdDrawBox(Border, XLow, YLow, Xs, Ys, BoxAttr);
  75.  
  76.     {Clear out the window}
  77.     EdClearWindow(XLow, YLow, Xs, Ys, TextAttr[BoxAttr]);
  78.  
  79.     {Return the pointer}
  80.     EdSetupWindow := W;
  81.  
  82.   end;                       {EdSetupWindow}
  83.  
  84.   procedure EdRestoreWindow(var W : WindowPtr;
  85.                             XPosn, YPosn, XSize, YSize : Byte);
  86.     {-Given a pointer to a screen buffer, restore the contents of the window}
  87.   var
  88.     I : Integer;
  89.  
  90.   begin                      {EdRestoreWindow}
  91.     {Restore the contents}
  92.     for I := 0 to Pred(YSize) do
  93.       EdMoveToScreen(W^[I*XSize],
  94.                      Mem[ScreenAdr: (PhyScrCols*Pred(YPosn+I)+Pred(XPosn)) shl 1], XSize);
  95.     {Free the memory}
  96.     FreeMem(W, (XSize*YSize) shl 1);
  97.     EdSetPtrNil(W);
  98.   end;                       {EdRestoreWindow}
  99.  
  100.   procedure EdSaveTextWindow(Border : BorderChars;
  101.                              Title : VarString;
  102.                              XLow, YLow, XHigh, YHigh : Byte;
  103.                              var W : WindowRec);
  104.     {-Save existing screen and set up a new text window}
  105.  
  106.   begin                      {EdSaveTextWindow}
  107.     with W do begin
  108.       XSize := Succ(XHigh-XLow);
  109.       YSize := Succ(YHigh-YLow);
  110.       XPosn := XLow;
  111.       YPosn := YLow;
  112.       Overlap := EdSetupWindow(Border, XLow, YLow, XHigh, YHigh, NormalBox);
  113.  
  114.       {Set up Turbo window}
  115.       EdWindow(Succ(XLow), Succ(YLow), Pred(XHigh), Pred(YHigh));
  116.       GoToXY(1, 1);
  117.  
  118.       {Write a title}
  119.       if Length(Title) <> 0 then
  120.         EdFastWrite(Title, YPosn, XPosn+(XSize-Length(Title)) shr 1, ScreenAttr[MfColor]);
  121.  
  122.       {Turn off cursor}
  123.       EdSetCursor(CursorOff);
  124.     end;
  125.   end;                       {EdSaveTextWindow}
  126.  
  127.   procedure EdRestoreTextWindow(W : WindowRec);
  128.     {Given a pointer to a WindowRec, restore the contents of the window}
  129.  
  130.   begin                      {EdRestoreTextWindow}
  131.     with W do
  132.       {Restore the contents}
  133.       EdRestoreWindow(Overlap, XPosn, YPosn, XSize, YSize);
  134.     {Reset Turbo window to full screen}
  135.     EdWindow(1, 1, PhyScrCols, PhyscrRows);
  136.     {Restore cursor if menus are not on screen}
  137.     if EdPtrIsNil(CurrMenu) then
  138.       EdUpdateCursor;
  139.   end;                       {EdRestoreTextWindow}
  140.  
  141.