home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp21beta.zip / ATVSRC.RAR / VIEWS.PAS < prev   
Pascal/Delphi Source File  |  2000-08-15  |  105KB  |  3,931 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Turbo Pascal Version 7.0                        }
  5. {       Turbo Vision Unit                               }
  6. {                                                       }
  7. {       Copyright (c) 1992 Borland International        }
  8. {                                                       }
  9. {       Virtual Pascal v2.1                             }
  10. {       Copyright (C) 1996-2000 vpascal.com             }
  11. {                                                       }
  12. {*******************************************************}
  13.  
  14. unit Views;
  15.  
  16. {$X+,I-,S-,Cdecl-,Delphi-,Use32+}
  17.  
  18. interface
  19.  
  20. uses Objects, Drivers, Memory;
  21.  
  22. const
  23.  
  24. { TView State masks }
  25.  
  26.   sfVisible     = $0001;
  27.   sfCursorVis   = $0002;
  28.   sfCursorIns   = $0004;
  29.   sfShadow      = $0008;
  30.   sfActive      = $0010;
  31.   sfSelected    = $0020;
  32.   sfFocused     = $0040;
  33.   sfDragging    = $0080;
  34.   sfDisabled    = $0100;
  35.   sfModal       = $0200;
  36.   sfDefault     = $0400;
  37.   sfExposed     = $0800;
  38.  
  39. { TView Option masks }
  40.  
  41.   ofSelectable  = $0001;
  42.   ofTopSelect   = $0002;
  43.   ofFirstClick  = $0004;
  44.   ofFramed      = $0008;
  45.   ofPreProcess  = $0010;
  46.   ofPostProcess = $0020;
  47.   ofBuffered    = $0040;
  48.   ofTileable    = $0080;
  49.   ofCenterX     = $0100;
  50.   ofCenterY     = $0200;
  51.   ofCentered    = $0300;
  52.   ofValidate    = $0400;
  53.   ofVersion     = $3000;
  54.   ofVersion10   = $0000;
  55.   ofVersion20   = $1000;
  56.  
  57. { TView GrowMode masks }
  58.  
  59.   gfGrowLoX = $01;
  60.   gfGrowLoY = $02;
  61.   gfGrowHiX = $04;
  62.   gfGrowHiY = $08;
  63.   gfGrowAll = $0F;
  64.   gfGrowRel = $10;
  65.  
  66. { TView DragMode masks }
  67.  
  68.   dmDragMove = $01;
  69.   dmDragGrow = $02;
  70.   dmLimitLoX = $10;
  71.   dmLimitLoY = $20;
  72.   dmLimitHiX = $40;
  73.   dmLimitHiY = $80;
  74.   dmLimitAll = $F0;
  75.  
  76. { TView Help context codes }
  77.  
  78.   hcNoContext = 0;
  79.   hcDragging  = 1;
  80.  
  81. { TScrollBar part codes }
  82.  
  83.   sbLeftArrow  = 0;
  84.   sbRightArrow = 1;
  85.   sbPageLeft   = 2;
  86.   sbPageRight  = 3;
  87.   sbUpArrow    = 4;
  88.   sbDownArrow  = 5;
  89.   sbPageUp     = 6;
  90.   sbPageDown   = 7;
  91.   sbIndicator  = 8;
  92.  
  93. { TScrollBar options for TWindow.StandardScrollBar }
  94.  
  95.   sbHorizontal     = $0000;
  96.   sbVertical       = $0001;
  97.   sbHandleKeyboard = $0002;
  98.  
  99. { TWindow Flags masks }
  100.  
  101.   wfMove  = $01;
  102.   wfGrow  = $02;
  103.   wfClose = $04;
  104.   wfZoom  = $08;
  105.  
  106. { TWindow number constants }
  107.  
  108.   wnNoNumber = 0;
  109.  
  110. { TWindow palette entries }
  111.  
  112.   wpBlueWindow = 0;
  113.   wpCyanWindow = 1;
  114.   wpGrayWindow = 2;
  115.  
  116. { Standard command codes }
  117.  
  118.   cmValid   = 0;
  119.   cmQuit    = 1;
  120.   cmError   = 2;
  121.   cmMenu    = 3;
  122.   cmClose   = 4;
  123.   cmZoom    = 5;
  124.   cmResize  = 6;
  125.   cmNext    = 7;
  126.   cmPrev    = 8;
  127.   cmHelp    = 9;
  128.  
  129. { Application command codes }
  130.  
  131.   cmCut     = 20;
  132.   cmCopy    = 21;
  133.   cmPaste   = 22;
  134.   cmUndo    = 23;
  135.   cmClear   = 24;
  136.   cmTile    = 25;
  137.   cmCascade = 26;
  138.  
  139. { TDialog standard commands }
  140.  
  141.   cmOK      = 10;
  142.   cmCancel  = 11;
  143.   cmYes     = 12;
  144.   cmNo      = 13;
  145.   cmDefault = 14;
  146.  
  147. { Standard messages }
  148.  
  149.   cmReceivedFocus     = 50;
  150.   cmReleasedFocus     = 51;
  151.   cmCommandSetChanged = 52;
  152.  
  153. { TScrollBar messages }
  154.  
  155.   cmScrollBarChanged  = 53;
  156.   cmScrollBarClicked  = 54;
  157.  
  158. { TWindow select messages }
  159.  
  160.   cmSelectWindowNum   = 55;
  161.  
  162. { TListViewer messages }
  163.  
  164.   cmListItemSelected  = 56;
  165.  
  166. { Color palettes }
  167.  
  168.   CFrame      = #1#1#2#2#3;
  169.   CScrollBar  = #4#5#5;
  170.   CScroller   = #6#7;
  171.   CListViewer = #26#26#27#28#29;
  172.  
  173.   CBlueWindow = #8#9#10#11#12#13#14#15;
  174.   CCyanWindow = #16#17#18#19#20#21#22#23;
  175.   CGrayWindow = #24#25#26#27#28#29#30#31;
  176.  
  177. { TDrawBuffer maximum view width }
  178.  
  179.   MaxViewWidth = 255;
  180.  
  181. type
  182.  
  183. { Command sets }
  184.  
  185.   PCommandSet = ^TCommandSet;
  186.   TCommandSet = set of Byte;
  187.  
  188. { Color palette type }
  189.  
  190.   PPalette = ^TPalette;
  191.   TPalette = String;
  192.  
  193. { TDrawBuffer, buffer used by draw methods }
  194.  
  195.   TDrawBuffer = array[0..MaxViewWidth - 1] of SmallWord;
  196.  
  197. { TView object Pointer }
  198.  
  199.   PView = ^TView;
  200.  
  201. { TGroup object Pointer }
  202.  
  203.   PGroup = ^TGroup;
  204.  
  205. { TView object }
  206.  
  207.   TView = object(TObject)
  208.     Owner: PGroup;
  209.     Next: PView;
  210.     Origin: TPoint;
  211.     Size: TPoint;
  212.     Cursor: TPoint;
  213.     GrowMode: Byte;
  214.     DragMode: Byte;
  215.     HelpCtx: Word;
  216.     State: Word;
  217.     Options: Word;
  218.     EventMask: Word;
  219.     constructor Init(var Bounds: TRect);
  220.     constructor Load(var S: TStream);
  221.     destructor Done; virtual;
  222.     procedure Awaken; virtual;
  223.     procedure BlockCursor;
  224.     procedure CalcBounds(var Bounds: TRect; Delta: TPoint); virtual;
  225.     procedure ChangeBounds(var Bounds: TRect); virtual;
  226.     procedure ClearEvent(var Event: TEvent);
  227.     function CommandEnabled(Command: Word): Boolean;
  228.     function DataSize: Word; virtual;
  229.     procedure DisableCommands(Commands: TCommandSet);
  230.     procedure DragView(Event: TEvent; Mode: Byte;
  231.       var Limits: TRect; MinSize, MaxSize: TPoint);
  232.     procedure Draw; virtual;
  233.     procedure DrawView;
  234.     procedure EnableCommands(Commands: TCommandSet);
  235.     procedure EndModal(Command: Word); virtual;
  236.     function EventAvail: Boolean;
  237.     function Execute: Word; virtual;
  238.     function Exposed: Boolean;
  239.     function Focus: Boolean;
  240.     procedure GetBounds(var Bounds: TRect);
  241.     procedure GetClipRect(var Clip: TRect);
  242.     function GetColor(Color: Word): Word;
  243.     procedure GetCommands(var Commands: TCommandSet);
  244.     procedure GetData(var Rec); virtual;
  245.     procedure GetEvent(var Event: TEvent); virtual;
  246.     procedure GetExtent(var Extent: TRect);
  247.     function GetHelpCtx: Word; virtual;
  248.     function GetPalette: PPalette; virtual;
  249.     procedure GetPeerViewPtr(var S: TStream; var P);
  250.     function GetState(AState: Word): Boolean;
  251.     procedure GrowTo(X, Y: Integer);
  252.     procedure HandleEvent(var Event: TEvent); virtual;
  253.     procedure Hide;
  254.     procedure HideCursor;
  255.     procedure KeyEvent(var Event: TEvent);
  256.     procedure Locate(var Bounds: TRect);
  257.     procedure MakeFirst;
  258.     procedure MakeGlobal(Source: TPoint; var Dest: TPoint);
  259.     procedure MakeLocal(Source: TPoint; var Dest: TPoint);
  260.     function MouseEvent(var Event: TEvent; Mask: Word): Boolean;
  261.     function MouseInView(Mouse: TPoint): Boolean;
  262.     procedure MoveTo(X, Y: Integer);
  263.     function NextView: PView;
  264.     procedure NormalCursor;
  265.     function Prev: PView;
  266.     function PrevView: PView;
  267.     procedure PutEvent(var Event: TEvent); virtual;
  268.     procedure PutInFrontOf(Target: PView);
  269.     procedure PutPeerViewPtr(var S: TStream; P: PView);
  270.     procedure Select;
  271.     procedure SetBounds(var Bounds: TRect);
  272.     procedure SetCommands(Commands: TCommandSet);
  273.     procedure SetCmdState(Commands: TCommandSet; Enable: Boolean);
  274.     procedure SetCursor(X, Y: Integer);
  275.     procedure SetData(var Rec); virtual;
  276.     procedure SetState(AState: Word; Enable: Boolean); virtual;
  277.     procedure Show;
  278.     procedure ShowCursor;
  279.     procedure SizeLimits(var Min, Max: TPoint); virtual;
  280.     procedure Store(var S: TStream);
  281.     function TopView: PView;
  282.     function Valid(Command: Word): Boolean; virtual;
  283.     procedure WriteBuf(X, Y, W, H: Integer; var Buf);
  284.     procedure WriteChar(X, Y: Integer; C: Char; Color: Byte;
  285.       Count: Integer);
  286.     procedure WriteLine(X, Y, W, H: Integer; var Buf);
  287.     procedure WriteStr(X, Y: Integer; Str: String; Color: Byte);
  288.   private
  289.     procedure DrawCursor;
  290.     procedure DrawHide(LastView: PView);
  291.     procedure DrawShow(LastView: PView);
  292.     procedure DrawUnderRect(var R: TRect; LastView: PView);
  293.     procedure DrawUnderView(DoShadow: Boolean; LastView: PView);
  294.     procedure ResetCursor; virtual;
  295.   end;
  296.  
  297. { TFrame types }
  298.  
  299.   TTitleStr = string[80];
  300.  
  301. { TFrame object }
  302.  
  303.   { Palette layout }
  304.   { 1 = Passive frame }
  305.   { 2 = Passive title }
  306.   { 3 = Active frame }
  307.   { 4 = Active title }
  308.   { 5 = Icons }
  309.  
  310.   PFrame = ^TFrame;
  311.   TFrame = object(TView)
  312.     constructor Init(var Bounds: TRect);
  313.     procedure Draw; virtual;
  314.     function GetPalette: PPalette; virtual;
  315.     procedure HandleEvent(var Event: TEvent); virtual;
  316.     procedure SetState(AState: Word; Enable: Boolean); virtual;
  317.   private
  318.     FrameMode: Word;
  319.     procedure FrameLine(var FrameBuf; Y, N: Integer; Color: Byte);
  320.   end;
  321.  
  322. { ScrollBar characters }
  323.  
  324.   TScrollChars = array[0..4] of Char;
  325.  
  326. { TScrollBar object }
  327.  
  328.   { Palette layout }
  329.   { 1 = Page areas }
  330.   { 2 = Arrows }
  331.   { 3 = Indicator }
  332.  
  333.   PScrollBar = ^TScrollBar;
  334.   TScrollBar = object(TView)
  335.     Value: Integer;
  336.     Min: Integer;
  337.     Max: Integer;
  338.     PgStep: Integer;
  339.     ArStep: Integer;
  340.     constructor Init(var Bounds: TRect);
  341.     constructor Load(var S: TStream);
  342.     procedure Draw; virtual;
  343.     function GetPalette: PPalette; virtual;
  344.     procedure HandleEvent(var Event: TEvent); virtual;
  345.     procedure ScrollDraw; virtual;
  346.     function ScrollStep(Part: Integer): Integer; virtual;
  347.     procedure SetParams(AValue, AMin, AMax, APgStep, AArStep: Integer);
  348.     procedure SetRange(AMin, AMax: Integer);
  349.     procedure SetStep(APgStep, AArStep: Integer);
  350.     procedure SetValue(AValue: Integer);
  351.     procedure Store(var S: TStream);
  352.   private
  353.     Chars: TScrollChars;
  354.     procedure DrawPos(Pos: Integer);
  355.     function GetPos: Integer;
  356.     function GetSize: Integer;
  357.   end;
  358.  
  359. { TScroller object }
  360.  
  361.   { Palette layout }
  362.   { 1 = Normal text }
  363.   { 2 = Selected text }
  364.  
  365.   PScroller = ^TScroller;
  366.   TScroller = object(TView)
  367.     HScrollBar: PScrollBar;
  368.     VScrollBar: PScrollBar;
  369.     Delta: TPoint;
  370.     Limit: TPoint;
  371.     constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
  372.     constructor Load(var S: TStream);
  373.     procedure ChangeBounds(var Bounds: TRect); virtual;
  374.     function GetPalette: PPalette; virtual;
  375.     procedure HandleEvent(var Event: TEvent); virtual;
  376.     procedure ScrollDraw; virtual;
  377.     procedure ScrollTo(X, Y: Integer);
  378.     procedure SetLimit(X, Y: Integer);
  379.     procedure SetState(AState: Word; Enable: Boolean); virtual;
  380.     procedure Store(var S: TStream);
  381.   private
  382.     DrawLock: Byte;
  383.     DrawFlag: Boolean;
  384.     procedure CheckDraw;
  385.   end;
  386.  
  387. { TListViewer }
  388.  
  389.   { Palette layout }
  390.   { 1 = Active }
  391.   { 2 = Inactive }
  392.   { 3 = Focused }
  393.   { 4 = Selected }
  394.   { 5 = Divider }
  395.  
  396.   PListViewer = ^TListViewer;
  397.  
  398.   TListViewer = object(TView)
  399.     HScrollBar: PScrollBar;
  400.     VScrollBar: PScrollBar;
  401.     NumCols: Integer;
  402.     TopItem: Integer;
  403.     Focused: Integer;
  404.     Range: Integer;
  405.     constructor Init(var Bounds: TRect; ANumCols: Word;
  406.       AHScrollBar, AVScrollBar: PScrollBar);
  407.     constructor Load(var S: TStream);
  408.     procedure ChangeBounds(var Bounds: TRect); virtual;
  409.     procedure Draw; virtual;
  410.     procedure FocusItem(Item: Integer); virtual;
  411.     function GetPalette: PPalette; virtual;
  412.     function GetText(Item: Integer; MaxLen: Integer): String; virtual;
  413.     function IsSelected(Item: Integer): Boolean; virtual;
  414.     procedure HandleEvent(var Event: TEvent); virtual;
  415.     procedure SelectItem(Item: Integer); virtual;
  416.     procedure SetRange(ARange: Integer);
  417.     procedure SetState(AState: Word; Enable: Boolean); virtual;
  418.     procedure Store(var S: TStream);
  419.   private
  420.     procedure FocusItemNum(Item: Integer); virtual;
  421.   end;
  422.  
  423. { Video buffer }
  424.  
  425.   PVideoBuf = ^TVideoBuf;
  426.   TVideoBuf = array[0..3999] of SmallWord;
  427.  
  428. { Selection modes }
  429.  
  430.   SelectMode = (NormalSelect, EnterSelect, LeaveSelect);
  431.  
  432. { TGroup object }
  433.  
  434.   TGroup = object(TView)
  435.     Last: PView;
  436.     Current: PView;
  437.     Phase: (phFocused, phPreProcess, phPostProcess);
  438.     Buffer: PVideoBuf;
  439.     EndState: Word;
  440.     constructor Init(var Bounds: TRect);
  441.     constructor Load(var S: TStream);
  442.     destructor Done; virtual;
  443.     procedure Awaken; virtual;
  444.     procedure ChangeBounds(var Bounds: TRect); virtual;
  445.     function DataSize: Word; virtual;
  446.     procedure Delete(P: PView);
  447.     procedure Draw; virtual;
  448.     procedure EndModal(Command: Word); virtual;
  449.     procedure EventError(var Event: TEvent); virtual;
  450.     function ExecView(P: PView): Word;
  451.     function Execute: Word; virtual;
  452.     function First: PView;
  453.     function FirstThat(P: Pointer): PView;
  454.     function FocusNext(Forwards: Boolean): Boolean;
  455.     procedure ForEach(P: Pointer);
  456.     procedure GetData(var Rec); virtual;
  457.     function GetHelpCtx: Word; virtual;
  458.     procedure GetSubViewPtr(var S: TStream; var P);
  459.     procedure HandleEvent(var Event: TEvent); virtual;
  460.     procedure Insert(P: PView);
  461.     procedure InsertBefore(P, Target: PView);
  462.     procedure Lock;
  463.     procedure PutSubViewPtr(var S: TStream; P: PView);
  464.     procedure Redraw;
  465.     procedure SelectNext(Forwards: Boolean);
  466.     procedure SetData(var Rec); virtual;
  467.     procedure SetState(AState: Word; Enable: Boolean); virtual;
  468.     procedure Store(var S: TStream);
  469.     procedure Unlock;
  470.     function Valid(Command: Word): Boolean; virtual;
  471.   private
  472.     Clip: TRect;
  473.     LockFlag: Byte;
  474.     function At(Index: Integer): PView;
  475.     procedure DrawSubViews(P, Bottom: PView);
  476.     function FirstMatch(AState: Word; AOptions: Word): PView;
  477.     function FindNext(Forwards: Boolean): PView;
  478.     procedure FreeBuffer;
  479.     procedure GetBuffer;
  480.     function IndexOf(P: PView): Integer;
  481.     procedure InsertView(P, Target: PView);
  482.     procedure RemoveView(P: PView);
  483.     procedure ResetCurrent;
  484.     procedure ResetCursor; virtual;
  485.     procedure SetCurrent(P: PView; Mode: SelectMode);
  486.   end;
  487.  
  488. { TWindow object }
  489.  
  490.   { Palette layout }
  491.   { 1 = Frame passive }
  492.   { 2 = Frame active }
  493.   { 3 = Frame icon }
  494.   { 4 = ScrollBar page area }
  495.   { 5 = ScrollBar controls }
  496.   { 6 = Scroller normal text }
  497.   { 7 = Scroller selected text }
  498.   { 8 = Reserved }
  499.  
  500.   PWindow = ^TWindow;
  501.   TWindow = object(TGroup)
  502.     Flags: Byte;
  503.     ZoomRect: TRect;
  504.     Number: Integer;
  505.     Palette: Integer;
  506.     Frame: PFrame;
  507.     Title: PString;
  508.     constructor Init(var Bounds: TRect; ATitle: TTitleStr; ANumber: Integer);
  509.     constructor Load(var S: TStream);
  510.     destructor Done; virtual;
  511.     procedure Close; virtual;
  512.     function GetPalette: PPalette; virtual;
  513.     function GetTitle(MaxSize: Integer): TTitleStr; virtual;
  514.     procedure HandleEvent(var Event: TEvent); virtual;
  515.     procedure InitFrame; virtual;
  516.     procedure SetState(AState: Word; Enable: Boolean); virtual;
  517.     procedure SizeLimits(var Min, Max: TPoint); virtual;
  518.     function StandardScrollBar(AOptions: Word): PScrollBar;
  519.     procedure Store(var S: TStream);
  520.     procedure Zoom; virtual;
  521.   end;
  522.  
  523. { Message dispatch function }
  524.  
  525. function Message(Receiver: PView; What, Command: Word;
  526.   InfoPtr: Pointer): Pointer;
  527.  
  528. { Views registration procedure }
  529.  
  530. procedure RegisterViews;
  531.  
  532. const
  533.  
  534. { Event masks }
  535.  
  536.   PositionalEvents: Word = evMouse;
  537.   FocusedEvents: Word = evKeyboard + evCommand;
  538.  
  539. { Minimum window size }
  540.  
  541.   MinWinSize: TPoint = (X: 16; Y: 6);
  542.  
  543. { Shadow definitions }
  544.  
  545.   ShadowSize: TPoint = (X: 2; Y: 1);
  546.   ShadowAttr: Byte = $08;
  547.  
  548. { Markers control }
  549.  
  550.   ShowMarkers: Boolean = False;
  551.  
  552. { MapColor error return value }
  553.  
  554.   ErrorAttr: Byte = $CF;
  555.  
  556. { Stream Registration Records }
  557.  
  558. const
  559.   RView: TStreamRec = (
  560.      ObjType: 1;
  561.      VmtLink: Ofs(TypeOf(TView)^);
  562.      Load:    @TView.Load;
  563.      Store:   @TView.Store
  564.   );
  565.  
  566. const
  567.   RFrame: TStreamRec = (
  568.      ObjType: 2;
  569.      VmtLink: Ofs(TypeOf(TFrame)^);
  570.      Load:    @TFrame.Load;
  571.      Store:   @TFrame.Store
  572.   );
  573.  
  574. const
  575.   RScrollBar: TStreamRec = (
  576.      ObjType: 3;
  577.      VmtLink: Ofs(TypeOf(TScrollBar)^);
  578.      Load:    @TScrollBar.Load;
  579.      Store:   @TScrollBar.Store
  580.   );
  581.  
  582. const
  583.   RScroller: TStreamRec = (
  584.      ObjType: 4;
  585.      VmtLink: Ofs(TypeOf(TScroller)^);
  586.      Load:    @TScroller.Load;
  587.      Store:   @TScroller.Store
  588.   );
  589.  
  590. const
  591.   RListViewer: TStreamRec = (
  592.      ObjType: 5;
  593.      VmtLink: Ofs(TypeOf(TListViewer)^);
  594.      Load:    @TListViewer.Load;
  595.      Store:   @TLIstViewer.Store
  596.   );
  597.  
  598. const
  599.   RGroup: TStreamRec = (
  600.      ObjType: 6;
  601.      VmtLink: Ofs(TypeOf(TGroup)^);
  602.      Load:    @TGroup.Load;
  603.      Store:   @TGroup.Store
  604.   );
  605.  
  606. const
  607.   RWindow: TStreamRec = (
  608.      ObjType: 7;
  609.      VmtLink: Ofs(TypeOf(TWindow)^);
  610.      Load:    @TWindow.Load;
  611.      Store:   @TWindow.Store
  612.   );
  613.  
  614. { Characters used for drawing selected and default items in  }
  615. { monochrome color sets                                      }
  616.  
  617.   SpecialChars: array[0..5] of Char = (#175, #174, #26, #27, ' ', ' ');
  618.  
  619. { True if the command set has changed since being set to false }
  620.  
  621.   CommandSetChanged: Boolean = False;
  622.  
  623. { True if the cursor is currently hidden }
  624.  
  625.   CursorHidden: Boolean = True;
  626.  
  627. { Line drawing characters }
  628.  
  629.   ldFrameChars        : array[0..31] of Char = '   └ │┌├ ┘─┴┐┤┬┼   ╚ ║╔║ ╝══╗║═ ';
  630. { Codepage = 437 :                             '   └ │┌├ ┘─┴┐┤┬┼   ╚ ║╔╟ ╝═╧╗╢╤ '; }
  631.  
  632.   ldMenuFrameChars    : array[0..19] of Char = ' ┌─┐  └─┘  │ │  ├─┤ ';
  633.  
  634.   ldCloseWindow       : array[0..4] of char = '[~■~]';
  635.   ldCloseClicked      : array[0..4] of char = '[~'#15'~]';
  636.   ldMaximize          : array[0..4] of char = '[~'#24'~]';
  637.   ldBottomRight       : array[0..3] of char = '~─┘~';
  638.  
  639.   ldVerticalScroll    : TScrollChars = #30#31#177#254#178;
  640.   ldHorizontalScroll  : TScrollChars = #17#16#177#254#178;
  641.  
  642.   ldHistoryDropDown   : array[0..4] of char = #222'~'#25'~'#221;
  643.  
  644.   ldPathDir           : array[0..2] of char = '└─┬';
  645.   ldFirstDir          : array[0..2] of char =   '└┬─';
  646.   ldMiddleDir         : array[0..2] of char =   ' ├─';
  647.   ldLastDir           : array[0..2] of char =   ' └─';
  648.   ldIndentSize        : String[10] = '  ';
  649.  
  650.   ldDesktopBackground : char = #176; // ░
  651.   ldSubMenuArrow      : char = #16;  //
  652.  
  653.   ldVerticalBar       : char = #179; // │
  654.   ldHorizontalBar     : char = #196; // ─
  655.   ldDblHorizontalBar  : char = #205; // ═
  656.   ldBlockFull         : char = #219; // █
  657.   ldBlockBottom       : char = #220; // ▄
  658.   ldBlockTop          : char = #223; // ▀
  659.   ldRadioSelect       : char = #7;   //
  660.  
  661. implementation
  662.  
  663. uses VpSysLow;
  664.  
  665. type
  666.   PFixupList = ^TFixupList;
  667.   TFixupList = array[1..4096] of Pointer;
  668.  
  669. const
  670.   OwnerGroup: PGroup = nil;
  671.   FixupList: PFixupList = nil;
  672.   TheTopView: PView = nil;
  673.  
  674. const
  675.  
  676. { Bit flags to determine how to draw the frame icons }
  677.  
  678.   fmCloseClicked = $0001;
  679.   fmZoomClicked  = $0002;
  680.  
  681. { Current command set. All but window commands are active by default }
  682.  
  683.   CurCommandSet: TCommandSet =
  684.     [0..255] - [cmZoom, cmClose, cmResize, cmNext, cmPrev];
  685.  
  686. procedure ShowBuffer(BufOfs,Len: Word);
  687. begin
  688.   asm
  689.                 push    esi
  690.                 push    edi
  691.                 mov     esi,ScreenBuffer
  692.                 add     esi,BufOfs                // Pointer to screen
  693.                 mov     edx,esi
  694.                 mov     edi,OFFSET ScreenMirror
  695.                 add     edi,BufOfs                // Pointer to mirror
  696.                 mov     ecx,Len                   // Length of required update
  697.                 mov     eax,ecx
  698.                 shr     ecx,2
  699.                 and     eax,3
  700.                 test    eax,eax                   // divisible by 4?
  701.                 je      @@Byte4
  702.                 inc     ecx
  703.               @@Byte4:
  704.                 cld
  705.                 repe    cmpsd                     // Compare mirror and buffer
  706.                 jne     @@Update                  // Buffers ne; search from other end
  707.                 xor     eax,eax                   // Do not update screen
  708.                 jmp     @@Equal
  709.               @@Update:
  710.                 inc     ecx
  711.                 sub     edi,4                     // Adjust pointers
  712.                 sub     esi,4
  713.                 sub     edx,esi                   // Subtract new from old
  714.                 sub     BufOfs,edx                // Set new offset to start from
  715.  
  716.                 push    esi                       // Store place to update from
  717.                 push    edi
  718.                 lea     esi,[esi+ecx*4-4]
  719.                 lea     edi,[edi+ecx*4-4]
  720.                 std
  721.                 repe    cmpsd
  722.                 pop     edi
  723.                 pop     esi
  724.                 inc     ecx                       // Increase counter
  725.                 mov     eax,ecx                   // Store new length
  726.                 shl     eax,2                     // New length times dword size
  727.                 cld
  728.                 rep     movsd                     // Update
  729.               @@Equal:
  730.                 mov     Len,eax
  731.                 pop     edi
  732.                 pop     esi
  733.   end;
  734.   If Len <> 0 then
  735.     SysTVShowBuf(BufOfs, Len);
  736. end;
  737.  
  738. { Convert color into attribute                          }
  739. { In    AL = Color                                      }
  740. { Out   AL = Attribute                                  }
  741.  
  742. procedure MapColor; assembler; {&USES ebx} {&FRAME-}
  743. const
  744.   Self = 8;
  745.   TView_GetPalette = vmtHeaderSize + $2C;
  746. asm
  747.                 test    al,al
  748.                 jz      @@3
  749.                 mov     ecx,[ebp].Self
  750.               @@1:
  751.                 push    ecx
  752.                 push    eax
  753.                 push    ecx                     { [1]:Pointer = Self    }
  754.                 mov     ecx,[ecx]
  755.                 Call    DWord Ptr [ecx].TView_GetPalette
  756.                 mov     ebx,eax
  757.                 pop     eax
  758.                 pop     ecx
  759.                 test    ebx,ebx
  760.                 jz      @@2
  761.                 cmp     al,[ebx]
  762.                 ja      @@3
  763.                 xlat
  764.                 test    al,al
  765.                 jz      @@3
  766.               @@2:
  767.                 mov     ecx,[ecx].TView.Owner
  768.                 jecxz   @@4
  769.                 jmp     @@1
  770.               @@3:
  771.                 mov     al,ErrorAttr
  772.               @@4:
  773. end;
  774.  
  775. { Convert color pair into attribute pair                }
  776. { In    AX = Color pair                                 }
  777. { Out   AX = Attribute pair                             }
  778.  
  779. procedure MapCPair; {&USES None} {&FRAME-}
  780. asm
  781.                 test    ah,ah
  782.                 jz      @@1
  783.                 xchg    al,ah
  784.                 Call    MapColor
  785.                 xchg    al,ah
  786.               @@1:
  787.                 Call    MapColor
  788. end;
  789.  
  790. { Write to view                                         }
  791. { In    eax   = Y coordinate                            }
  792. {       ebx   = X coordinate                            }
  793. {       ecx   = Count                                   }
  794. {       edi   = Buffer Pointer                          }
  795.  
  796. procedure WriteView; assembler; {&USES None} {&FRAME-}
  797. const
  798.   Self   =   8;
  799.   Target =  -4;
  800.   Buffer =  -8;
  801.   BufOfs = -12;
  802. asm
  803.                 mov     [ebp].BufOfs,ebx
  804.                 mov     [ebp].Buffer[0],edi
  805.                 add     ecx,ebx
  806.                 xor     edx,edx         { edx = Flag (0:Char&Attr,1:Char only) }
  807.                 mov     edi,[ebp].Self
  808.                 test    eax,eax
  809.                 jl      @@3
  810.                 cmp     eax,[edi].TView.Size.Y
  811.                 jge     @@3
  812.                 test    ebx,ebx
  813.                 jge     @@1
  814.                 xor     ebx,ebx
  815.               @@1:
  816.                 cmp     ecx,[edi].TView.Size.X
  817.                 jle     @@2
  818.                 mov     ecx,[edi].TView.Size.X
  819.               @@2:
  820.                 cmp     ebx,ecx
  821.                 jl      @@10
  822.               @@3:
  823.                 ret
  824.  
  825.               @@10:
  826.                 test    [edi].TView.State,sfVisible
  827.                 jz      @@3
  828.                 cmp     [edi].TView.Owner,0
  829.                 jz      @@3
  830.                 mov     [ebp].Target,edi
  831.                 add     eax,[edi].TView.Origin.Y
  832.                 mov     esi,[edi].TView.Origin.X
  833.                 add     ebx,esi
  834.                 add     ecx,esi
  835.                 add     [ebp].BufOfs,esi
  836.                 mov     edi,[edi].TView.Owner
  837.                 cmp     eax,[edi].TGroup.Clip.A.Y
  838.                 jl      @@3
  839.                 cmp     eax,[edi].TGroup.Clip.B.Y
  840.                 jge     @@3
  841.                 cmp     ebx,[edi].TGroup.Clip.A.X
  842.                 jge     @@11
  843.                 mov     ebx,[edi].TGroup.Clip.A.X
  844.               @@11:
  845.                 cmp     ecx,[edi].TGroup.Clip.B.X
  846.                 jle     @@12
  847.                 mov     ecx,[edi].TGroup.Clip.B.X
  848.               @@12:
  849.                 cmp     ebx,ecx
  850.                 jge     @@3
  851.                 mov     edi,[edi].TGroup.Last
  852.               @@20:
  853.                 mov     edi,[edi].TView.Next
  854.                 cmp     edi,[ebp].Target
  855.                 je      @@40
  856.                 test    [edi].TView.State,sfVisible
  857.                 jz      @@20
  858.                 mov     esi,[edi].TView.Origin.Y
  859.                 cmp     eax,esi
  860.                 jl      @@20
  861.                 add     esi,[edi].TView.Size.Y
  862.                 cmp     eax,esi
  863.                 jl      @@23
  864.                 test    [edi].TView.State,sfShadow
  865.                 jz      @@20
  866.                 add     esi,ShadowSize.Y
  867.                 cmp     eax,esi
  868.                 jge     @@20
  869.                 mov     esi,[edi].TView.Origin.X
  870.                 add     esi,ShadowSize.X
  871.                 cmp     ebx,esi
  872.                 jge     @@22
  873.                 cmp     ecx,esi
  874.                 jle     @@20
  875.                 Call    @@30
  876.               @@22:
  877.                 add     esi,[edi].TView.Size.X
  878.                 jmp     @@26
  879.               @@23:
  880.                 mov     esi,[edi].TView.Origin.X
  881.                 cmp     ebx,esi
  882.                 jge     @@24
  883.                 cmp     ecx,esi
  884.                 jle     @@20
  885.                 Call    @@30
  886.               @@24:
  887.                 add     esi,[edi].TView.Size.X
  888.                 cmp     ebx,esi
  889.                 jge     @@25
  890.                 cmp     ecx,esi
  891.                 jle     @@31
  892.                 mov     ebx,esi
  893.               @@25:
  894.                 test    [edi].TView.State,sfShadow
  895.                 je      @@20
  896.                 push    esi
  897.                 mov     esi,[edi].TView.Origin.Y
  898.                 add     esi,ShadowSize.Y
  899.                 cmp     eax,esi
  900.                 pop     esi
  901.                 jl      @@27
  902.                 add     esi,ShadowSize.X
  903.               @@26:
  904.                 cmp     ebx,esi
  905.                 jge     @@27
  906.                 inc     edx
  907.                 cmp     ecx,esi
  908.                 jle     @@27
  909.                 Call    @@30
  910.                 dec     edx
  911.               @@27:
  912.                 jmp     @@20
  913.  
  914.               @@30:
  915.                 push    DWord Ptr [ebp].Target
  916.                 push    DWord Ptr [ebp].BufOfs
  917.                 push    edi
  918.                 push    esi
  919.                 push    edx
  920.                 push    ecx
  921.                 push    eax
  922.                 mov     ecx,esi
  923.                 Call    @@20
  924.                 pop     eax
  925.                 pop     ecx
  926.                 pop     edx
  927.                 pop     esi
  928.                 pop     edi
  929.                 pop     DWord Ptr [ebp].BufOfs
  930.                 pop     DWord Ptr [ebp].Target
  931.                 mov     ebx,esi
  932.               @@31:
  933.                 ret
  934.  
  935.               @@40:
  936.                 mov     edi,[edi].TView.Owner
  937.                 mov     esi,[edi].TGroup.Buffer
  938.                 test    esi,esi
  939.                 jz      @@44
  940.                 cmp     esi,ScreenBuffer
  941.                 jne     @@43
  942.                 push    eax
  943.                 push    ecx
  944.                 push    edx
  945.                 Call    UpdateMouseWhere
  946.                 pop     edx
  947.                 pop     ecx
  948.                 pop     eax
  949.                 cmp     eax,MouseWhere.Y
  950.                 jne     @@43
  951.                 cmp     ebx,MouseWhere.X
  952.                 ja      @@43
  953.                 cmp     ecx,MouseWhere.X
  954.                 jbe     @@43
  955.                 push    eax
  956.                 push    ecx
  957.                 push    edx
  958.                 Call    HideMouse
  959.                 pop     edx
  960.                 pop     ecx
  961.                 pop     eax
  962.                 Call    @@50
  963.                 push    eax
  964.                 push    ecx
  965.                 push    edx
  966.                 Call    ShowMouse
  967.                 pop     edx
  968.                 pop     ecx
  969.                 pop     eax
  970.                 jmp     @@44
  971.               @@43:
  972.                 Call    @@50
  973.               @@44:
  974.                 cmp     [edi].TGroup.LockFlag,0
  975.                 jne     @@31
  976.                 jmp     @@10
  977.  
  978. { Copy to Buffer }
  979.  
  980.               @@50:
  981.                 push    edi
  982.                 push    ecx
  983.                 push    ebx
  984.                 push    eax
  985.                 mul     [edi].TView.Size.X.Byte[0]
  986.                 add     eax,ebx
  987.                 lea     edi,[esi+eax*2]
  988.                 xor     al,al
  989.                 mov     ah,ShadowAttr
  990.                 sub     ecx,ebx
  991.                 xchg    esi,ebx
  992.                 sub     esi,[ebp].BufOfs
  993.                 shl     esi,1
  994.                 add     esi,[ebp].Buffer
  995.                 push    edi
  996.                 push    ecx
  997.                 cld
  998.                 test    edx,edx
  999.                 jnz     @@52
  1000.                 shr     ecx,1
  1001.                 rep     movsd
  1002.                 adc     ecx,ecx
  1003.                 rep     movsw
  1004.                 jmp     @@53
  1005.               @@52:
  1006.                 lodsb
  1007.                 inc     esi
  1008.                 stosw
  1009.                 loop    @@52
  1010.               @@53:
  1011.                 pop     ecx
  1012.                 pop     edi
  1013.                 mov     eax,ScreenBuffer
  1014.                 cmp     ebx,eax
  1015.                 jne     @@54
  1016.                 shl     ecx,1
  1017.                 sub     edi,eax
  1018.                 push    edi                     { [1]:DWord = Offset }
  1019.                 push    ecx                     { [2]:DWord = Length }
  1020.                 Call    ShowBuffer
  1021.               @@54:
  1022.                 pop     eax
  1023.                 pop     ebx
  1024.                 pop     ecx
  1025.                 pop     edi
  1026.                 ret
  1027. end;
  1028.  
  1029. { TView }
  1030.  
  1031. constructor TView.Init(var Bounds: TRect);
  1032. begin
  1033.   TObject.Init;
  1034.   Owner := nil;
  1035.   State := sfVisible;
  1036.   SetBounds(Bounds);
  1037.   DragMode := dmLimitLoY;
  1038.   HelpCtx := hcNoContext;
  1039.   EventMask := evMouseDown + evKeyDown + evCommand;
  1040. end;
  1041.  
  1042. constructor TView.Load(var S: TStream);
  1043. begin
  1044.   TObject.Init;
  1045.   S.Read(Origin,
  1046.     SizeOf(TPoint) * 3 +
  1047.     SizeOf(Byte) * 2 +
  1048.     SizeOf(Word) * 4);
  1049. end;
  1050.  
  1051. destructor TView.Done;
  1052. begin
  1053.   Hide;
  1054.   if Owner <> nil then Owner^.Delete(@Self);
  1055. end;
  1056.  
  1057. procedure TView.Awaken;
  1058. begin
  1059. end;
  1060.  
  1061. procedure TView.BlockCursor;
  1062. begin
  1063.   SetState(sfCursorIns, True);
  1064. end;
  1065.  
  1066. procedure TView.CalcBounds(var Bounds: TRect; Delta: TPoint);
  1067. var
  1068.   S, D: Integer;
  1069.   Min, Max: TPoint;
  1070.  
  1071. procedure Grow(var I: Integer);
  1072. begin
  1073.   if GrowMode and gfGrowRel = 0 then Inc(I, D) else
  1074.     I := (I * S + (S - D) shr 1) div (S - D);
  1075. end;
  1076.  
  1077. function Range(Val, Min, Max: Integer): Integer;
  1078. begin
  1079.   if Val < Min then Range := Min else
  1080.     if Val > Max then Range := Max else
  1081.       Range := Val;
  1082. end;
  1083.  
  1084. begin
  1085.   GetBounds(Bounds);
  1086.   S := Owner^.Size.X;
  1087.   D := Delta.X;
  1088.   if GrowMode and gfGrowLoX <> 0 then Grow(Bounds.A.X);
  1089.   if GrowMode and gfGrowHiX <> 0 then Grow(Bounds.B.X);
  1090.   if Bounds.B.X - Bounds.A.X > MaxViewWidth then
  1091.     Bounds.B.X := Bounds.A.X + MaxViewWidth;
  1092.   S := Owner^.Size.Y;
  1093.   D := Delta.Y;
  1094.   if GrowMode and gfGrowLoY <> 0 then Grow(Bounds.A.Y);
  1095.   if GrowMode and gfGrowHiY <> 0 then Grow(Bounds.B.Y);
  1096.   SizeLimits(Min, Max);
  1097.   Bounds.B.X := Bounds.A.X + Range(Bounds.B.X - Bounds.A.X, Min.X, Max.X);
  1098.   Bounds.B.Y := Bounds.A.Y + Range(Bounds.B.Y - Bounds.A.Y, Min.Y, Max.Y);
  1099. end;
  1100.  
  1101. procedure TView.ChangeBounds(var Bounds: TRect);
  1102. begin
  1103.   SetBounds(Bounds);
  1104.   DrawView;
  1105. end;
  1106.  
  1107. procedure TView.ClearEvent(var Event: TEvent);
  1108. begin
  1109.   Event.What := evNothing;
  1110.   Event.InfoPtr := @Self;
  1111. end;
  1112.  
  1113. function TView.CommandEnabled(Command: Word): Boolean;
  1114. begin
  1115.   CommandEnabled := (Command > 255) or (Command in CurCommandSet);
  1116. end;
  1117.  
  1118. function TView.DataSize: Word;
  1119. begin
  1120.   DataSize := 0;
  1121. end;
  1122.  
  1123. procedure TView.DisableCommands(Commands: TCommandSet);
  1124. begin
  1125.   CommandSetChanged := CommandSetChanged or (CurCommandSet * Commands <> []);
  1126.   CurCommandSet := CurCommandSet - Commands;
  1127. end;
  1128.  
  1129. procedure TView.DragView(Event: TEvent; Mode: Byte;
  1130.   var Limits: TRect; MinSize, MaxSize: TPoint);
  1131. var
  1132.   P, S: TPoint;
  1133.   SaveBounds: TRect;
  1134.  
  1135. function Min(I, J: Integer): Integer;
  1136. begin
  1137.   if I < J then Min := I else Min := J;
  1138. end;
  1139.  
  1140. function Max(I, J: Integer): Integer;
  1141. begin
  1142.   if I > J then Max := I else Max := J;
  1143. end;
  1144.  
  1145. procedure MoveGrow(P, S: TPoint);
  1146. var
  1147.   R: TRect;
  1148. begin
  1149.   S.X := Min(Max(S.X, MinSize.X), MaxSize.X);
  1150.   S.Y := Min(Max(S.Y, MinSize.Y), MaxSize.Y);
  1151.   P.X := Min(Max(P.X, Limits.A.X - S.X + 1), Limits.B.X - 1);
  1152.   P.Y := Min(Max(P.Y, Limits.A.Y - S.Y + 1), Limits.B.Y - 1);
  1153.   if Mode and dmLimitLoX <> 0 then P.X := Max(P.X, Limits.A.X);
  1154.   if Mode and dmLimitLoY <> 0 then P.Y := Max(P.Y, Limits.A.Y);
  1155.   if Mode and dmLimitHiX <> 0 then P.X := Min(P.X, Limits.B.X - S.X);
  1156.   if Mode and dmLimitHiY <> 0 then P.Y := Min(P.Y, Limits.B.Y - S.Y);
  1157.   R.Assign(P.X, P.Y, P.X + S.X, P.Y + S.Y);
  1158.   Locate(R);
  1159. end;
  1160.  
  1161. procedure Change(DX, DY: Integer);
  1162. begin
  1163.   if (Mode and dmDragMove <> 0) and (GetShiftState and $03 = 0) then
  1164.   begin
  1165.     Inc(P.X, DX);
  1166.     Inc(P.Y, DY);
  1167.   end else
  1168.   if (Mode and dmDragGrow <> 0) and (GetShiftState and $03 <> 0) then
  1169.   begin
  1170.     Inc(S.X, DX);
  1171.     Inc(S.Y, DY);
  1172.   end;
  1173. end;
  1174.  
  1175. procedure Update(X, Y: Integer);
  1176. begin
  1177.   if Mode and dmDragMove <> 0 then
  1178.   begin
  1179.     P.X := X;
  1180.     P.Y := Y;
  1181.   end;
  1182. end;
  1183.  
  1184. begin
  1185.   SetState(sfDragging, True);
  1186.   if Event.What = evMouseDown then
  1187.   begin
  1188.     if Mode and dmDragMove <> 0 then
  1189.     begin
  1190.       P.X := Origin.X - Event.Where.X;
  1191.       P.Y := Origin.Y - Event.Where.Y;
  1192.       repeat
  1193.         Inc(Event.Where.X, P.X);
  1194.         Inc(Event.Where.Y, P.Y);
  1195.         MoveGrow(Event.Where, Size);
  1196.       until not MouseEvent(Event, evMouseMove);
  1197.     end else
  1198.     begin
  1199.       P.X := Size.X - Event.Where.X;
  1200.       P.Y := Size.Y - Event.Where.Y;
  1201.       repeat
  1202.         Inc(Event.Where.X, P.X);
  1203.         Inc(Event.Where.Y, P.Y);
  1204.         MoveGrow(Origin, Event.Where);
  1205.       until not MouseEvent(Event, evMouseMove);
  1206.     end;
  1207.   end else
  1208.   begin
  1209.     GetBounds(SaveBounds);
  1210.     repeat
  1211.       P := Origin;
  1212.       S := Size;
  1213.       KeyEvent(Event);
  1214.       case Event.KeyCode and $FF00 of
  1215.         kbLeft: Change(-1, 0);
  1216.         kbRight: Change(1, 0);
  1217.         kbUp: Change(0, -1);
  1218.         kbDown: Change(0, 1);
  1219.         kbCtrlLeft: Change(-8, 0);
  1220.         kbCtrlRight: Change(8, 0);
  1221.         kbHome: Update(Limits.A.X, P.Y);
  1222.         kbEnd: Update(Limits.B.X - S.X, P.Y);
  1223.         kbPgUp: Update(P.X, Limits.A.Y);
  1224.         kbPgDn: Update(P.X, Limits.B.Y - S.Y);
  1225.       end;
  1226.       MoveGrow(P, S);
  1227.     until (Event.KeyCode = kbEnter) or (Event.KeyCode = kbEsc);
  1228.     if Event.KeyCode = kbEsc then Locate(SaveBounds);
  1229.   end;
  1230.   SetState(sfDragging, False);
  1231. end;
  1232.  
  1233. procedure TView.Draw;
  1234. var
  1235.   B: TDrawBuffer;
  1236. begin
  1237.   MoveChar(B, ' ', GetColor(1), Size.X);
  1238.   WriteLine(0, 0, Size.X, Size.Y, B);
  1239. end;
  1240.  
  1241. procedure TView.DrawCursor;
  1242. begin
  1243.   if State and sfFocused <> 0 then ResetCursor;
  1244. end;
  1245.  
  1246. procedure TView.DrawHide(LastView: PView);
  1247. begin
  1248.   DrawCursor;
  1249.   DrawUnderView(State and sfShadow <> 0, LastView);
  1250. end;
  1251.  
  1252. procedure TView.DrawShow(LastView: PView);
  1253. begin
  1254.   DrawView;
  1255.   if State and sfShadow <> 0 then DrawUnderView(True, LastView);
  1256. end;
  1257.  
  1258. procedure TView.DrawUnderRect(var R: TRect; LastView: PView);
  1259. begin
  1260.   Owner^.Clip.Intersect(R);
  1261.   Owner^.DrawSubViews(NextView, LastView);
  1262.   Owner^.GetExtent(Owner^.Clip);
  1263. end;
  1264.  
  1265. procedure TView.DrawUnderView(DoShadow: Boolean; LastView: PView);
  1266. var
  1267.   R: TRect;
  1268. begin
  1269.   GetBounds(R);
  1270. // AM: Always increase to include shadow rect, to make sure it is
  1271. // removed if this option is changed.
  1272. // if DoShadow then
  1273.   begin
  1274.     Inc(R.B.X, ShadowSize.X);
  1275.     Inc(R.B.Y, ShadowSize.Y);
  1276.   end;
  1277.   DrawUnderRect(R, LastView);
  1278. end;
  1279.  
  1280. procedure TView.DrawView;
  1281. begin
  1282.   if Exposed then
  1283.   begin
  1284.     Draw;
  1285.     DrawCursor;
  1286.   end;
  1287. end;
  1288.  
  1289. procedure TView.EnableCommands(Commands: TCommandSet);
  1290. begin
  1291.   CommandSetChanged := CommandSetChanged or
  1292.     (CurCommandSet * Commands <> Commands);
  1293.   CurCommandSet := CurCommandSet + Commands;
  1294. end;
  1295.  
  1296. procedure TView.EndModal(Command: Word);
  1297. var
  1298.   P: PView;
  1299. begin
  1300.   P := TopView;
  1301.   if TopView <> nil then TopView^.EndModal(Command);
  1302. end;
  1303.  
  1304. function TView.EventAvail: Boolean;
  1305. var
  1306.   Event: TEvent;
  1307. begin
  1308.   GetEvent(Event);
  1309.   if Event.What <> evNothing then PutEvent(Event);
  1310.   EventAvail := Event.What <> evNothing;
  1311. end;
  1312.  
  1313. procedure TView.GetBounds(var Bounds: TRect); {&USES esi,edi} {&FRAME-}
  1314. asm
  1315.                 mov     esi,Self
  1316.                 add     esi,OFFSET TView.Origin
  1317.                 mov     edi,Bounds
  1318.                 cld
  1319.                 lodsd                           {Origin.X}
  1320.                 mov     ecx,eax
  1321.                 stosd
  1322.                 lodsd                           {Origin.Y}
  1323.                 mov     edx,eax
  1324.                 stosd
  1325.                 lodsd                           {Size.X}
  1326.                 add     eax,ecx
  1327.                 stosd
  1328.                 lodsd                           {Size.Y}
  1329.                 add     eax,edx
  1330.                 stosd
  1331. end;
  1332.  
  1333. function TView.Execute: Word;
  1334. begin
  1335.   Execute := cmCancel;
  1336. end;
  1337.  
  1338. function TView.Exposed: Boolean; assembler; {&USES ebx,esi,edi} {&FRAME+}
  1339. var
  1340.   Target: Pointer;
  1341. asm
  1342.                 mov     edi,Self
  1343.                 test    [edi].TView.State,sfExposed
  1344.                 je      @@2
  1345.                 xor     eax,eax
  1346.                 cmp     eax,[edi].TView.Size.X
  1347.                 jge     @@2
  1348.                 cmp     eax,[edi].TView.Size.Y
  1349.                 jge     @@2
  1350.               @@1:
  1351.                 xor     ebx,ebx
  1352.                 mov     ecx,[edi].TView.Size.X
  1353.                 push    eax
  1354.                 Call    @@11
  1355.                 pop     eax
  1356.                 jnc     @@3
  1357.                 mov     edi,Self
  1358.                 inc     eax
  1359.                 cmp     eax,[edi].TView.Size.Y
  1360.                 jl      @@1
  1361.               @@2:
  1362.                 mov     al,0
  1363.                 jmp     @@30
  1364.               @@3:
  1365.                 mov     al,1
  1366.                 jmp     @@30
  1367.  
  1368.               @@8:
  1369.                 stc
  1370.               @@9:
  1371.                 ret
  1372.  
  1373.               @@10:
  1374.                 mov     edi,[edi].TView.Owner
  1375.                 cmp     [edi].TGroup.Buffer,0
  1376.                 jne     @@9
  1377.               @@11:
  1378.                 mov     Target,edi
  1379.                 add     eax,[edi].TView.Origin.Y
  1380.                 mov     esi,[edi].TView.Origin.X
  1381.                 add     ebx,esi
  1382.                 add     ecx,esi
  1383.                 mov     edi,[edi].TView.Owner
  1384.                 test    edi,edi
  1385.                 jz      @@9
  1386.                 cmp     eax,[edi].TGroup.Clip.A.Y
  1387.                 jl      @@8
  1388.                 cmp     eax,[edi].TGroup.Clip.B.Y
  1389.                 jge     @@8
  1390.                 cmp     ebx,[edi].TGroup.Clip.A.X
  1391.                 jge     @@12
  1392.                 mov     ebx,[edi].TGroup.Clip.A.X
  1393.               @@12:
  1394.                 cmp     ecx,[edi].TGroup.Clip.B.X
  1395.                 jle     @@13
  1396.                 mov     ecx,[edi].TGroup.Clip.B.X
  1397.               @@13:
  1398.                 cmp     ebx,ecx
  1399.                 jge     @@8
  1400.                 mov     edi,[edi].TGroup.Last
  1401.               @@20:
  1402.                 mov     edi,[edi].TView.Next
  1403.                 cmp     edi,Target
  1404.                 je      @@10
  1405.                 test    [edi].TView.State,sfVisible
  1406.                 jz      @@20
  1407.                 mov     esi,[edi].TView.Origin.Y
  1408.                 cmp     eax,esi
  1409.                 jl      @@20
  1410.                 add     esi,[edi].TView.Size.Y
  1411.                 cmp     eax,esi
  1412.                 jge     @@20
  1413.                 mov     esi,[edi].TView.Origin.X
  1414.                 cmp     ebx,esi
  1415.                 jl      @@22
  1416.                 add     esi,[edi].TView.Size.X
  1417.                 cmp     ebx,esi
  1418.                 jge     @@20
  1419.                 mov     ebx,esi
  1420.                 cmp     ebx,ecx
  1421.                 jl      @@20
  1422.                 stc
  1423.                 ret
  1424.               @@22:
  1425.                 cmp     ecx,esi
  1426.                 jle     @@20
  1427.                 add     esi,[edi].TView.Size.X
  1428.                 cmp     ecx,esi
  1429.                 jg      @@23
  1430.                 mov     ecx,[edi].TView.Origin.X
  1431.                 jmp     @@20
  1432.               @@23:
  1433.                 push    Target
  1434.                 push    edi
  1435.                 push    esi
  1436.                 push    ecx
  1437.                 push    eax
  1438.                 mov     ecx,[edi].TView.Origin.X
  1439.                 Call    @@20
  1440.                 pop     eax
  1441.                 pop     ecx
  1442.                 pop     ebx
  1443.                 pop     edi
  1444.                 pop     Target
  1445.                 jc      @@20
  1446.                 retn
  1447.               @@30:
  1448. end;
  1449.  
  1450. function TView.Focus: Boolean;
  1451. var
  1452.   Result: Boolean;
  1453. begin
  1454.   Result := True;
  1455.   if State and (sfSelected + sfModal) = 0 then
  1456.   begin
  1457.     if Owner <> nil then
  1458.     begin
  1459.       Result := Owner^.Focus;
  1460.       if Result then
  1461.         if ((Owner^.Current = nil) or
  1462.           (Owner^.Current^.Options and ofValidate = 0) or
  1463.           (Owner^.Current^.Valid(cmReleasedFocus))) then
  1464.           Select
  1465.         else
  1466.           Result := False;
  1467.     end;
  1468.   end;
  1469.   Focus := Result;
  1470. end;
  1471.  
  1472. procedure TView.GetClipRect(var Clip: TRect);
  1473. begin
  1474.   GetBounds(Clip);
  1475.   if Owner <> nil then Clip.Intersect(Owner^.Clip);
  1476.   Clip.Move(-Origin.X, -Origin.Y);
  1477. end;
  1478.  
  1479. function TView.GetColor(Color: Word): Word; {&USES None} {&FRAME+}
  1480. asm
  1481.                 mov     eax,Color
  1482.                 Call    MapCPair
  1483. end;
  1484.  
  1485. procedure TView.GetCommands(var Commands: TCommandSet);
  1486. begin
  1487.   Commands := CurCommandSet;
  1488. end;
  1489.  
  1490. procedure TView.GetData(var Rec);
  1491. begin
  1492. end;
  1493.  
  1494. procedure TView.GetEvent(var Event: TEvent);
  1495. begin
  1496.   if Owner <> nil then Owner^.GetEvent(Event);
  1497. end;
  1498.  
  1499. procedure TView.GetExtent(var Extent: TRect); {&USES esi,edi} {&FRAME-}
  1500. asm
  1501.                 mov     esi,Self
  1502.                 add     esi,OFFSET TView.Size
  1503.                 mov     edi,Extent
  1504.                 cld
  1505.                 xor     eax,eax
  1506.                 stosd
  1507.                 stosd
  1508.                 movsd
  1509.                 movsd
  1510. end;
  1511.  
  1512. function TView.GetHelpCtx: Word;
  1513. begin
  1514.   if State and sfDragging <> 0 then
  1515.     GetHelpCtx := hcDragging else
  1516.     GetHelpCtx := HelpCtx;
  1517. end;
  1518.  
  1519. function TView.GetPalette: PPalette;
  1520. begin
  1521.   GetPalette := nil;
  1522. end;
  1523.  
  1524. procedure TView.GetPeerViewPtr(var S: TStream; var P);
  1525. var
  1526.   Index: Integer;
  1527. begin
  1528.   S.Read(Index, SizeOf(Word));
  1529.   if (Index = 0) or (OwnerGroup = nil) then Pointer(P) := nil
  1530.   else
  1531.   begin
  1532.     Pointer(P) := FixupList^[Index];
  1533.     FixupList^[Index] := @P;
  1534.   end;
  1535. end;
  1536.  
  1537. function TView.GetState(AState: Word): Boolean;
  1538. begin
  1539.   GetState := State and AState = AState;
  1540. end;
  1541.  
  1542. procedure TView.GrowTo(X, Y: Integer);
  1543. var
  1544.   R: TRect;
  1545. begin
  1546.   R.Assign(Origin.X, Origin.Y, Origin.X + X, Origin.Y + Y);
  1547.   Locate(R);
  1548. end;
  1549.  
  1550. procedure TView.HandleEvent(var Event: TEvent);
  1551. begin
  1552.   if Event.What = evMouseDown then
  1553.     if (State and (sfSelected + sfDisabled) = 0) and
  1554.        (Options and ofSelectable <> 0) then
  1555.       if not Focus or (Options and ofFirstClick = 0) then
  1556.         ClearEvent(Event);
  1557. end;
  1558.  
  1559. procedure TView.Hide;
  1560. begin
  1561.   if State and sfVisible <> 0 then SetState(sfVisible, False);
  1562. end;
  1563.  
  1564. procedure TView.HideCursor;
  1565. begin
  1566.   SetState(sfCursorVis, False);
  1567. end;
  1568.  
  1569. procedure TView.KeyEvent(var Event: TEvent);
  1570. begin
  1571.   repeat GetEvent(Event) until Event.What = evKeyDown;
  1572. end;
  1573.  
  1574. procedure TView.Locate(var Bounds: TRect);
  1575. var
  1576.   R: TRect;
  1577.   Min, Max: TPoint;
  1578.  
  1579. function Range(Val, Min, Max: Integer): Integer;
  1580. begin
  1581.   if Val < Min then Range := Min else
  1582.     if Val > Max then Range := Max else
  1583.       Range := Val;
  1584. end;
  1585.  
  1586. begin
  1587.   SizeLimits(Min, Max);
  1588.   Bounds.B.X := Bounds.A.X + Range(Bounds.B.X - Bounds.A.X, Min.X, Max.X);
  1589.   Bounds.B.Y := Bounds.A.Y + Range(Bounds.B.Y - Bounds.A.Y, Min.Y, Max.Y);
  1590.   GetBounds(R);
  1591.   if not Bounds.Equals(R) then
  1592.   begin
  1593.     ChangeBounds(Bounds);
  1594.     if (Owner <> nil) and (State and sfVisible <> 0) then
  1595.     begin
  1596.       if State and sfShadow <> 0 then
  1597.       begin
  1598.         R.Union(Bounds);
  1599.         Inc(R.B.X, ShadowSize.X);
  1600.         Inc(R.B.Y, ShadowSize.Y);
  1601.       end;
  1602.       DrawUnderRect(R, nil);
  1603.     end;
  1604.   end;
  1605. end;
  1606.  
  1607. procedure TView.MakeFirst;
  1608. begin
  1609.   PutInFrontOf(Owner^.First);
  1610. end;
  1611.  
  1612. procedure TView.MakeGlobal(Source: TPoint; var Dest: TPoint); {&USES None} {&FRAME-}
  1613. asm
  1614.                 mov     ecx,Self
  1615.                 xor     eax,eax
  1616.                 mov     edx,eax
  1617.               @@1:
  1618.                 add     eax,[ecx].TView.Origin.X
  1619.                 add     edx,[ecx].TView.Origin.Y
  1620.                 mov     ecx,[ecx].TView.Owner
  1621.                 test    ecx,ecx
  1622.                 jnz     @@1
  1623.                 add     eax,Source.X
  1624.                 add     edx,Source.Y
  1625.                 mov     ecx,Dest
  1626.                 mov     [ecx].TPoint.X,eax
  1627.                 mov     [ecx].TPoint.Y,edx
  1628. end;
  1629.  
  1630. procedure TView.MakeLocal(Source: TPoint; var Dest: TPoint); {&USES None} {&FRAME-}
  1631. asm
  1632.                 mov     ecx,Self
  1633.                 xor     eax,eax
  1634.                 mov     edx,eax
  1635.               @@1:
  1636.                 add     eax,[ecx].TView.Origin.X
  1637.                 add     edx,[ecx].TView.Origin.Y
  1638.                 mov     ecx,[ecx].TView.Owner
  1639.                 test    ecx,ecx
  1640.                 jnz     @@1
  1641.                 neg     eax
  1642.                 neg     edx
  1643.                 add     eax,Source.X
  1644.                 add     edx,Source.Y
  1645.                 mov     ecx,Dest
  1646.                 mov     [ecx].TPoint.X,eax
  1647.                 mov     [ecx].TPoint.Y,edx
  1648. end;
  1649.  
  1650. function TView.MouseEvent(var Event: TEvent; Mask: Word): Boolean;
  1651. begin
  1652.   repeat GetEvent(Event) until Event.What and (Mask or evMouseUp) <> 0;
  1653.   MouseEvent := Event.What <> evMouseUp;
  1654. end;
  1655.  
  1656. function TView.MouseInView(Mouse: TPoint): Boolean;
  1657. var
  1658.   Extent: TRect;
  1659. begin
  1660.   MakeLocal(Mouse, Mouse);
  1661.   GetExtent(Extent);
  1662.   MouseInView := Extent.Contains(Mouse);
  1663. end;
  1664.  
  1665. procedure TView.MoveTo(X, Y: Integer);
  1666. var
  1667.   R: TRect;
  1668. begin
  1669.   R.Assign(X, Y, X + Size.X, Y + Size.Y);
  1670.   Locate(R);
  1671. end;
  1672.  
  1673. function TView.NextView: PView;
  1674. begin
  1675.   if @Self = Owner^.Last then NextView := nil else NextView := Next;
  1676. end;
  1677.  
  1678. procedure TView.NormalCursor;
  1679. begin
  1680.   SetState(sfCursorIns, False);
  1681. end;
  1682.  
  1683. function TView.Prev: PView; {&USES None} {&FRAME-}
  1684. asm
  1685.                 mov     edx,Self
  1686.                 mov     ecx,edx
  1687.               @@1:
  1688.                 mov     eax,edx
  1689.                 mov     edx,[edx].TView.Next
  1690.                 cmp     edx,ecx
  1691.                 jne     @@1
  1692. end;
  1693.  
  1694. function TView.PrevView: PView;
  1695. begin
  1696.   if @Self = Owner^.First then PrevView := nil else PrevView := Prev;
  1697. end;
  1698.  
  1699. procedure TView.PutEvent(var Event: TEvent);
  1700. begin
  1701.   if Owner <> nil then Owner^.PutEvent(Event);
  1702. end;
  1703.  
  1704. procedure TView.PutInFrontOf(Target: PView);
  1705. var
  1706.   P, LastView: PView;
  1707.  
  1708. procedure MoveView;
  1709. begin
  1710.   Owner^.RemoveView(@Self);
  1711.   Owner^.InsertView(@Self, Target);
  1712. end;
  1713.  
  1714. begin
  1715.   if (Owner <> nil) and (Target <> @Self) and (Target <> NextView) and
  1716.     ((Target = nil) or (Target^.Owner = Owner)) then
  1717.     if State and sfVisible = 0 then MoveView else
  1718.     begin
  1719.  
  1720.       LastView := NextView;
  1721.       if LastView <> nil then
  1722.       begin
  1723.         P := Target;
  1724.         while (P <> nil) and (P <> LastView) do P := P^.NextView;
  1725.         if P = nil then LastView := Target;
  1726.       end;
  1727.       State := State and not sfVisible;
  1728.       if LastView = Target then DrawHide(LastView);
  1729.       MoveView;
  1730.       State := State or sfVisible;
  1731.       if LastView <> Target then DrawShow(LastView);
  1732.       if Options and ofSelectable <> 0 then
  1733.       begin
  1734.         Owner^.ResetCurrent;
  1735.         Owner^.ResetCursor;
  1736.       end;
  1737.     end;
  1738. end;
  1739.  
  1740. procedure TView.PutPeerViewPtr(var S: TStream; P: PView);
  1741. var
  1742.   Index: Integer;
  1743. begin
  1744.   if (P = nil) or (OwnerGroup = nil) then Index := 0
  1745.   else Index := OwnerGroup^.IndexOf(P);
  1746.   S.Write(Index, SizeOf(Word));
  1747. end;
  1748.  
  1749. procedure TView.ResetCursor; {&USES esi,edi} {&FRAME-}
  1750. asm
  1751.                 mov     edi,Self
  1752.                 mov     eax,[edi].TView.State
  1753.                 not     eax
  1754.                 test    eax,sfVisible+sfCursorVis+sfFocused
  1755.                 jne     @@Hide
  1756.                 mov     eax,[edi].TView.Cursor.Y
  1757.                 mov     edx,[edi].TView.Cursor.X
  1758.               @@1:
  1759.                 test    eax,eax
  1760.                 jl      @@Hide
  1761.                 cmp     eax,[edi].TView.Size.Y
  1762.                 jge     @@Hide
  1763.                 test    edx,edx
  1764.                 jl      @@Hide
  1765.                 cmp     edx,[edi].TView.Size.X
  1766.                 jge     @@Hide
  1767.                 add     eax,[edi].TView.Origin.Y
  1768.                 add     edx,[edi].TView.Origin.X
  1769.                 mov     ecx,edi
  1770.                 mov     edi,[edi].TView.Owner
  1771.                 test    edi,edi
  1772.                 jz      @@Show
  1773.                 test    [edi].TView.State,sfVisible
  1774.                 je      @@Hide
  1775.                 mov     edi,[edi].TGroup.Last
  1776.               @@2:
  1777.                 mov     edi,[edi].TView.Next
  1778.                 cmp     ecx,edi
  1779.                 jne     @@3
  1780.                 mov     edi,[edi].TView.Owner
  1781.                 jmp     @@1
  1782.               @@3:
  1783.                 test    [edi].TView.State,sfVisible
  1784.                 je      @@2
  1785.                 mov     esi,[edi].TView.Origin.Y
  1786.                 cmp     eax,esi
  1787.                 jl      @@2
  1788.                 add     esi,[edi].TView.Size.Y
  1789.                 cmp     eax,esi
  1790.                 jge     @@2
  1791.                 mov     esi,[edi].TView.Origin.X
  1792.                 cmp     edx,esi
  1793.                 jl      @@2
  1794.                 add     esi,[edi].TView.Size.X
  1795.                 cmp     edx,esi
  1796.                 jge     @@2
  1797.               @@Hide:
  1798.                 mov     al,0                    // Show := False
  1799.                 xor     ecx,ecx
  1800.                 jmp     @@4
  1801. { Set Cursor Position }
  1802.               @@Show:
  1803.                 push    edx                     // [1]:DWord = Column
  1804.                 push    eax                     // [2]:DWord = Row
  1805.                 Call    SysTVSetCurPos
  1806. { Set Cursor Shape }
  1807.                 mov     al,1                    // Show := True
  1808.                 mov     cx,CursorLines
  1809.                 mov     edi,Self
  1810.                 test    [edi].TView.State,sfCursorIns
  1811.                 jz      @@4
  1812.                 mov     ch,1
  1813.                 test    cl,cl
  1814.                 jne     @@4
  1815.                 mov     cl,7
  1816.               @@4:
  1817.                 xor     al,1
  1818.                 mov     CursorHidden,al
  1819.                 xor     al,1
  1820.                 movzx   edx,ch
  1821.                 movzx   ecx,cl
  1822.                 push    edx                     // [1]:Integer = Y1
  1823.                 push    ecx                     // [2]:Integer = Y2
  1824.                 push    eax                     // [3]:Boolean = Show
  1825.                 Call    SysTVSetCurType
  1826. end;
  1827.  
  1828. procedure TView.Select;
  1829. begin
  1830.   if Options and ofSelectable <> 0 then
  1831.     if Options and ofTopSelect <> 0 then MakeFirst else
  1832.       if Owner <> nil then Owner^.SetCurrent(@Self, NormalSelect);
  1833. end;
  1834.  
  1835. procedure TView.SetBounds(var Bounds: TRect); {&USES None} {&FRAME-}
  1836. asm
  1837.                 mov     edx,Self
  1838.                 mov     ecx,Bounds
  1839.                 mov     eax,[ecx].TRect.A.X
  1840.                 mov     [edx].Origin.X,eax
  1841.                 mov     eax,[ecx].TRect.A.Y
  1842.                 mov     [edx].Origin.Y,eax
  1843.                 mov     eax,[ecx].TRect.B.X
  1844.                 sub     eax,[ecx].TRect.A.X
  1845.                 mov     [edx].Size.X,eax
  1846.                 mov     eax,[ecx].TRect.B.Y
  1847.                 sub     eax,[ecx].TRect.A.Y
  1848.                 mov     [edx].Size.Y,eax
  1849. end;
  1850.  
  1851. procedure TView.SetCmdState(Commands: TCommandSet; Enable: Boolean);
  1852. begin
  1853.   if Enable then EnableCommands(Commands)
  1854.   else DisableCommands(Commands);
  1855. end;
  1856.  
  1857. procedure TView.SetCommands(Commands: TCommandSet);
  1858. begin
  1859.   CommandSetChanged := CommandSetChanged or (CurCommandSet <> Commands);
  1860.   CurCommandSet := Commands;
  1861. end;
  1862.  
  1863. procedure TView.SetCursor(X, Y: Integer);
  1864. begin
  1865.   Cursor.X := X;
  1866.   Cursor.Y := Y;
  1867.   DrawCursor;
  1868. end;
  1869.  
  1870. procedure TView.SetData(var Rec);
  1871. begin
  1872. end;
  1873.  
  1874. procedure TView.SetState(AState: Word; Enable: Boolean);
  1875. var
  1876.   Command: Word;
  1877. begin
  1878.   if Enable then
  1879.     State := State or AState else
  1880.     State := State and not AState;
  1881.   if Owner <> nil then
  1882.     case AState of
  1883.       sfVisible:
  1884.         begin
  1885.           if Owner^.State and sfExposed <> 0 then
  1886.             SetState(sfExposed, Enable);
  1887.           if Enable then DrawShow(nil) else DrawHide(nil);
  1888.           if Options and ofSelectable <> 0 then Owner^.ResetCurrent;
  1889.         end;
  1890.       sfCursorVis, sfCursorIns:
  1891.         DrawCursor;
  1892.       sfShadow:
  1893.         DrawUnderView(State and sfShadow <> 0, nil);
  1894.       sfFocused:
  1895.         begin
  1896.           ResetCursor;
  1897.           if Enable then
  1898.             Command := cmReceivedFocus else
  1899.             Command := cmReleasedFocus;
  1900.           Message(Owner, evBroadcast, Command, @Self);
  1901.         end;
  1902.     end;
  1903. end;
  1904.  
  1905. procedure TView.Show;
  1906. begin
  1907.   if State and sfVisible = 0 then SetState(sfVisible, True);
  1908. end;
  1909.  
  1910. procedure TView.ShowCursor;
  1911. begin
  1912.   SetState(sfCursorVis, True);
  1913. end;
  1914.  
  1915. procedure TView.SizeLimits(var Min, Max: TPoint);
  1916. begin
  1917.   Min.X := 0;
  1918.   Min.Y := 0;
  1919.   if Owner <> nil then Max := Owner^.Size
  1920.  else
  1921.   begin
  1922.     Max.X := MaxLongint;
  1923.     Max.Y := MaxLongint;
  1924.   end;
  1925. end;
  1926.  
  1927. procedure TView.Store(var S: TStream);
  1928. var
  1929.   SaveState: Word;
  1930. begin
  1931.   SaveState := State;
  1932.   State := State and not (sfActive + sfSelected + sfFocused + sfExposed);
  1933.   S.Write(Origin,
  1934.     SizeOf(TPoint) * 3 +
  1935.     SizeOf(Byte) * 2 +
  1936.     SizeOf(Word) * 4);
  1937.   State := SaveState;
  1938. end;
  1939.  
  1940. function TView.TopView: PView;
  1941. var
  1942.   P: PView;
  1943. begin
  1944.   if TheTopView = nil then
  1945.   begin
  1946.     P := @Self;
  1947.     while (P <> nil) and (P^.State and sfModal = 0) do P := P^.Owner;
  1948.     TopView := P;
  1949.   end
  1950.   else TopView := TheTopView;
  1951. end;
  1952.  
  1953. function TView.Valid(Command: Word): Boolean;
  1954. begin
  1955.   Valid := True;
  1956. end;
  1957.  
  1958. procedure TView.WriteBuf(X, Y, W, H: Integer; var Buf); assembler; {&USES ebx,esi,edi} {&FRAME+}
  1959. var
  1960.   Target: Pointer; {Variables used by WriteView}
  1961.   Buffer: Pointer;
  1962.   Offset: Word;
  1963. asm
  1964.                 cmp     H,0
  1965.                 jle     @@2
  1966.               @@1:
  1967.                 mov     eax,Y
  1968.                 mov     ebx,X
  1969.                 mov     ecx,W
  1970.                 mov     edi,Buf
  1971.                 Call    WriteView
  1972.                 mov     eax,W
  1973.                 shl     eax,1
  1974.                 add     Buf,eax
  1975.                 inc     Y
  1976.                 dec     H
  1977.                 jnz     @@1
  1978.               @@2:
  1979. end;
  1980.  
  1981. procedure TView.WriteChar(X, Y: Integer; C: Char; Color: Byte;
  1982.   Count: Integer); assembler; {&USES ebx,esi,edi} {&FRAME+}
  1983. var
  1984.   Target: Pointer; {Variables used by WriteView}
  1985.   Buffer: Pointer;
  1986.   Offset: Word;
  1987. asm
  1988.                 mov     al,Color
  1989.                 Call    MapColor
  1990.                 mov     ah,al
  1991.                 mov     al,C
  1992.                 mov     ecx,Count
  1993.                 test    ecx,ecx
  1994.                 jle     @@2
  1995.                 cmp     ecx,256
  1996.                 jle     @@1
  1997.                 mov     ecx,256
  1998.               @@1:
  1999.                 lea     ebx,[ecx*2+2]
  2000.                 and     ebx,NOT 11b
  2001.                 sub     esp,ebx
  2002.                 mov     edi,esp
  2003.                 mov     edx,eax
  2004.                 shl     eax,16
  2005.                 mov     ax,dx
  2006.                 mov     edx,ecx
  2007.                 cld
  2008.                 shr     ecx,1
  2009.                 rep     stosd
  2010.                 adc     ecx,ecx
  2011.                 rep     stosw
  2012.                 mov     ecx,edx
  2013.                 mov     edi,esp
  2014.                 mov     eax,Y
  2015.                 push    ebx
  2016.                 mov     ebx,X
  2017.                 Call    WriteView
  2018.                 pop     eax
  2019.                 add     esp,eax
  2020.               @@2:
  2021. end;
  2022.  
  2023. procedure TView.WriteLine(X, Y, W, H: Integer; var Buf); assembler; {&USES ebx,esi,edi} {&FRAME+}
  2024. var
  2025.   Target: Pointer; {Variables used by WriteView}
  2026.   Buffer: Pointer;
  2027.   Offset: Word;
  2028. asm
  2029.                 cmp     H,0
  2030.                 jle     @@2
  2031.               @@1:
  2032.                 mov     eax,Y
  2033.                 mov     ebx,X
  2034.                 mov     ecx,W
  2035.                 mov     edi,Buf
  2036.                 Call    WriteView
  2037.                 inc     Y
  2038.                 dec     H
  2039.                 jne     @@1
  2040.               @@2:
  2041. end;
  2042.  
  2043.  
  2044.  
  2045. procedure TView.WriteStr(X, Y: Integer; Str: String; Color: Byte); assembler; {&USES ebx,esi,edi} {&FRAME+}
  2046. var
  2047.   Target: Pointer; {Variables used by WriteView}
  2048.   Buffer: Pointer;
  2049.   Offset: Word;
  2050. asm
  2051.                 mov     al,Color
  2052.                 Call    MapColor
  2053.                 mov     ah,al
  2054.                 mov     esi,Str
  2055.                 xor     ecx,ecx
  2056.                 cld
  2057.                 lodsb
  2058.                 mov     cl,al
  2059.                 jecxz   @@2
  2060.                 lea     ebx,[ecx*2+2]
  2061.                 and     ebx,NOT 11b
  2062.                 sub     esp,ebx
  2063.                 mov     edi,esp
  2064.                 mov     edx,ecx
  2065.               @@1:
  2066.                 lodsb
  2067.                 stosw
  2068.                 loop    @@1
  2069.                 mov     ecx,edx
  2070.                 mov     edi,esp
  2071.                 mov     eax,Y
  2072.                 push    ebx
  2073.                 mov     ebx,X
  2074.                 Call    WriteView
  2075.                 pop     eax
  2076.                 add     esp,eax
  2077.               @@2:
  2078. end;
  2079.  
  2080. { TFrame }
  2081.  
  2082. constructor TFrame.Init(var Bounds: TRect);
  2083. begin
  2084.   TView.Init(Bounds);
  2085.   GrowMode := gfGrowHiX + gfGrowHiY;
  2086.   EventMask := EventMask or evBroadcast;
  2087. end;
  2088.  
  2089. procedure TFrame.FrameLine(var FrameBuf; Y, N: Integer;
  2090.   Color: Byte); assembler; {&USES ebx,esi,edi} {&FRAME-}
  2091. const
  2092.   InitFrame: array[0..17] of Byte =
  2093.     ($06, $0A, $0C, $05, $00, $05, $03, $0A, $09,
  2094.      $16, $1A, $1C, $15, $00, $15, $13, $1A, $19);
  2095. var
  2096.   FrameMask: array[0..MaxViewWidth-1] of Byte;
  2097. asm
  2098. {                cmp     CodePage,437
  2099.                 je      @@0
  2100.                 lea     ebx,ldFrameChars
  2101.                 mov     [ebx+23].Byte,'║'
  2102.                 mov     [ebx+27].Byte,'═'
  2103.                 mov     [ebx+29].Byte,'║'
  2104.                 mov     [ebx+30].Byte,'═'
  2105.               @@0:
  2106. }
  2107.                 mov     ebx,Self
  2108.                 mov     edx,[ebx].TFrame.Size.X
  2109.                 lea     ecx,[edx-2]
  2110.                 mov     esi,OFFSET InitFrame
  2111.                 add     esi,N
  2112.                 lea     edi,FrameMask
  2113.                 cld
  2114.                 movsb
  2115.                 lodsb
  2116.                 rep     stosb
  2117.                 movsb
  2118.                 mov     ebx,[ebx].TFrame.Owner
  2119.                 mov     ebx,[ebx].TGroup.Last
  2120.                 dec     edx
  2121.               @@1:
  2122.                 mov     ebx,[ebx].TView.Next
  2123.                 cmp     ebx,Self
  2124.                 je      @@10
  2125.               @@2:
  2126.                 test    [ebx].TView.Options,ofFramed
  2127.                 je      @@1
  2128.                 test    [ebx].TView.State,sfVisible
  2129.                 je      @@1
  2130.                 mov     eax,Y
  2131.                 sub     eax,[ebx].TView.Origin.Y
  2132.                 jl      @@3
  2133.                 cmp     eax,[ebx].TView.Size.Y
  2134.                 jg      @@1
  2135.                 mov     ax,0005h
  2136.                 jl      @@4
  2137.                 mov     ax,0A03h
  2138.                 jmp     @@4
  2139.               @@3:
  2140.                 inc     eax
  2141.                 jne     @@1
  2142.                 mov     ax,0A06h
  2143.               @@4:
  2144.                 mov     esi,[ebx].TView.Origin.X
  2145.                 mov     edi,[ebx].TView.Size.X
  2146.                 add     edi,esi
  2147.                 cmp     esi,1
  2148.                 jg      @@5
  2149.                 xor     esi,esi
  2150.                 inc     esi
  2151.               @@5:
  2152.                 cmp     edi,edx
  2153.                 jl      @@6
  2154.                 mov     edi,edx
  2155.               @@6:
  2156.                 cmp     esi,edi
  2157.                 jge     @@1
  2158.                 or      Byte Ptr FrameMask[esi-1],AL
  2159.                 xor     al,ah
  2160.                 or      Byte Ptr FrameMask[edi],AL
  2161.                 test    ah,ah
  2162.                 jz      @@1
  2163.                 mov     ecx,edi
  2164.                 sub     ecx,esi
  2165.               @@8:
  2166.                 or      Byte Ptr FrameMask[esi],ah
  2167.                 inc     esi
  2168.                 loop    @@8
  2169.                 jmp     @@1
  2170.               @@10:
  2171.                 inc     edx
  2172.                 mov     ah,Color
  2173.                 mov     ebx,OFFSET ldFrameChars
  2174.                 mov     ecx,edx
  2175.                 lea     esi,FrameMask
  2176.                 mov     edi,FrameBuf
  2177.               @@11:
  2178.                 lodsb
  2179.                 xlat
  2180.                 stosw
  2181.                 loop    @@11
  2182. end;
  2183.  
  2184. procedure TFrame.Draw;
  2185. var
  2186.   CFrame, CTitle: Word;
  2187.   F, I, L, Width: Integer;
  2188.   B: TDrawBuffer;
  2189.   Title: TTitleStr;
  2190.   Min, Max: TPoint;
  2191. begin
  2192.   if State and sfDragging <> 0 then
  2193.   begin
  2194.     CFrame := $0505;
  2195.     CTitle := $0005;
  2196.     F := 0;
  2197.   end else if State and sfActive = 0 then
  2198.   begin
  2199.     CFrame := $0101;
  2200.     CTitle := $0002;
  2201.     F := 0;
  2202.   end else
  2203.   begin
  2204.     CFrame := $0503;
  2205.     CTitle := $0004;
  2206.     F := 9;
  2207.   end;
  2208.   CFrame := GetColor(CFrame);
  2209.   CTitle := GetColor(CTitle);
  2210.   Width := Size.X;
  2211.   L := Width - 10;
  2212.   if PWindow(Owner)^.Flags and (wfClose+wfZoom) <> 0 then Dec(L,6);
  2213.   FrameLine(B, 0, F, Byte(CFrame));
  2214.   if (PWindow(Owner)^.Number <> wnNoNumber) and
  2215.      (PWindow(Owner)^.Number < 10) then
  2216.   begin
  2217.     Dec(L,4);
  2218.     if PWindow(Owner)^.Flags and wfZoom <> 0 then I := 7
  2219.     else I := 3;
  2220.     WordRec(B[Width - I]).Lo := PWindow(Owner)^.Number + $30;
  2221.   end;
  2222.   if Owner <> nil then Title := PWindow(Owner)^.GetTitle(L)
  2223.   else Title := '';
  2224.   if Title <> '' then
  2225.   begin
  2226.     L := Length(Title);
  2227.     if L > Width - 10 then L := Width - 10;
  2228.     if L < 0 then L := 0;
  2229.     I := (Width - L) shr 1;
  2230.     MoveChar(B[I - 1], ' ', CTitle, 1);
  2231.     MoveBuf(B[I], Title[1], CTitle, L);
  2232.     MoveChar(B[I + L], ' ', CTitle, 1);
  2233.   end;
  2234.   if State and sfActive <> 0 then
  2235.   begin
  2236.     if PWindow(Owner)^.Flags and wfClose <> 0 then
  2237.       if FrameMode and fmCloseClicked = 0 then
  2238.         MoveCStr(B[2], ldCloseWindow, CFrame)
  2239.       else MoveCStr(B[2], ldCloseClicked, CFrame);
  2240.     if PWindow(Owner)^.Flags and wfZoom <> 0 then
  2241.     begin
  2242.       MoveCStr(B[Width - 5], ldMaximize, CFrame);
  2243.       Owner^.SizeLimits(Min, Max);
  2244.       if FrameMode and fmZoomClicked <> 0 then
  2245.         WordRec(B[Width - 4]).Lo := 15
  2246.       else if (Owner^.Size.X = Max.X) and (Owner^.Size.Y = Max.Y) then
  2247.         WordRec(B[Width - 4]).Lo := 18;
  2248.     end;
  2249.   end;
  2250.   WriteLine(0, 0, Size.X, 1, B);
  2251.   for I := 1 to Size.Y - 2 do
  2252.   begin
  2253.     FrameLine(B, I, F + 3, Byte(CFrame));
  2254.     WriteLine(0, I, Size.X, 1, B);
  2255.   end;
  2256.   FrameLine(B, Size.Y - 1, F + 6, Byte(CFrame));
  2257.   if State and sfActive <> 0 then
  2258.     if PWindow(Owner)^.Flags and wfGrow <> 0 then
  2259.       MoveCStr(B[Width - 2], ldBottomRight, CFrame);
  2260.   WriteLine(0, Size.Y - 1, Size.X, 1, B);
  2261. end;
  2262.  
  2263. function TFrame.GetPalette: PPalette;
  2264. const
  2265.   P: String[Length(CFrame)] = CFrame;
  2266. begin
  2267.   GetPalette := @P;
  2268. end;
  2269.  
  2270. procedure TFrame.HandleEvent(var Event: TEvent);
  2271. var
  2272.   Mouse: TPoint;
  2273.  
  2274. procedure DragWindow(Mode: Byte);
  2275. var
  2276.   Limits: TRect;
  2277.   Min, Max: TPoint;
  2278. begin
  2279.   Owner^.Owner^.GetExtent(Limits);
  2280.   Owner^.SizeLimits(Min, Max);
  2281.   Owner^.DragView(Event, Owner^.DragMode or Mode, Limits, Min, Max);
  2282.   ClearEvent(Event);
  2283. end;
  2284.  
  2285. begin
  2286.   TView.HandleEvent(Event);
  2287.   if Event.What = evMouseDown then
  2288.   begin
  2289.     MakeLocal(Event.Where, Mouse);
  2290.     if Mouse.Y = 0 then
  2291.     begin
  2292.       if (PWindow(Owner)^.Flags and wfClose <> 0) and
  2293.         (State and sfActive <> 0) and (Mouse.X >= 2) and (Mouse.X <= 4) then
  2294.       begin
  2295.         repeat
  2296.           MakeLocal(Event.Where, Mouse);
  2297.           if (Mouse.X >= 2) and (Mouse.X <= 4) and (Mouse.Y = 0) then
  2298.             FrameMode := fmCloseClicked
  2299.           else FrameMode := 0;
  2300.           DrawView;
  2301.         until not MouseEvent(Event, evMouseMove + evMouseAuto);
  2302.         FrameMode := 0;
  2303.         if (Mouse.X >= 2) and (Mouse.X <= 4) and (Mouse.Y = 0) then
  2304.         begin
  2305.           Event.What := evCommand;
  2306.           Event.Command := cmClose;
  2307.           Event.InfoPtr := Owner;
  2308.           PutEvent(Event);
  2309.         end;
  2310.         ClearEvent(Event);
  2311.         DrawView;
  2312.       end else
  2313.         if (PWindow(Owner)^.Flags and wfZoom <> 0) and
  2314.           (State and sfActive <> 0) and (Event.Double or
  2315.           (Mouse.X >= Size.X - 5) and
  2316.           (Mouse.X <= Size.X - 3)) then
  2317.         begin
  2318.           if not Event.Double then
  2319.             repeat
  2320.               MakeLocal(Event.Where, Mouse);
  2321.               if (Mouse.X >= Size.X - 5) and (Mouse.X <= Size.X - 3) and
  2322.                 (Mouse.Y = 0) then
  2323.                 FrameMode := fmZoomClicked
  2324.               else FrameMode := 0;
  2325.               DrawView;
  2326.             until not MouseEvent(Event, evMouseMove + evMouseAuto);
  2327.           FrameMode := 0;
  2328.           if ((Mouse.X >= Size.X - 5) and (Mouse.X <= Size.X - 3) and
  2329.               (Mouse.Y = 0)) or Event.Double then
  2330.           begin
  2331.             Event.What := evCommand;
  2332.             Event.Command := cmZoom;
  2333.             Event.InfoPtr := Owner;
  2334.             PutEvent(Event);
  2335.           end;
  2336.           ClearEvent(Event);
  2337.           DrawView;
  2338.         end else
  2339.           if PWindow(Owner)^.Flags and wfMove <> 0 then
  2340.             DragWindow(dmDragMove);
  2341.     end else
  2342.       if (State and sfActive <> 0) and (Mouse.X >= Size.X - 2) and
  2343.           (Mouse.Y >= Size.Y - 1) then
  2344.         if PWindow(Owner)^.Flags and wfGrow <> 0 then
  2345.           DragWindow(dmDragGrow);
  2346.   end;
  2347. end;
  2348.  
  2349. procedure TFrame.SetState(AState: Word; Enable: Boolean);
  2350. begin
  2351.   TView.SetState(AState, Enable);
  2352.   if AState and (sfActive + sfDragging) <> 0 then DrawView;
  2353. end;
  2354.  
  2355. { TScrollBar }
  2356.  
  2357. constructor TScrollBar.Init(var Bounds: TRect);
  2358. begin
  2359.   TView.Init(Bounds);
  2360.   Value := 0;
  2361.   Min := 0;
  2362.   Max := 0;
  2363.   PgStep := 1;
  2364.   ArStep := 1;
  2365.   if Size.X = 1 then
  2366.   begin
  2367.     GrowMode := gfGrowLoX + gfGrowHiX + gfGrowHiY;
  2368.     Chars := ldVerticalScroll;
  2369.   end else
  2370.   begin
  2371.     GrowMode := gfGrowLoY + gfGrowHiX + gfGrowHiY;
  2372.     Chars := ldHorizontalScroll;
  2373.   end;
  2374. end;
  2375.  
  2376. constructor TScrollBar.Load(var S: TStream);
  2377. begin
  2378.   TView.Load(S);
  2379.   S.Read(Value, SizeOf(Integer) * 5 + SizeOf(TScrollChars));
  2380. end;
  2381.  
  2382. procedure TScrollBar.Draw;
  2383. begin
  2384.   DrawPos(GetPos);
  2385. end;
  2386.  
  2387. procedure TScrollBar.DrawPos(Pos: Integer);
  2388. var
  2389.   S: Integer;
  2390.   B: TDrawBuffer;
  2391. begin
  2392.   S := GetSize - 1;
  2393.   MoveChar(B[0], Chars[0], GetColor(2), 1);
  2394.   if Max = Min then
  2395.     MoveChar(B[1], Chars[4], GetColor(1), S - 1)
  2396.   else
  2397.   begin
  2398.     MoveChar(B[1], Chars[2], GetColor(1), S - 1);
  2399.     MoveChar(B[Pos], Chars[3], GetColor(3), 1);
  2400.   end;
  2401.   MoveChar(B[S], Chars[1], GetColor(2), 1);
  2402.   WriteBuf(0, 0, Size.X, Size.Y, B);
  2403. end;
  2404.  
  2405. function TScrollBar.GetPalette: PPalette;
  2406. const
  2407.   P: String[Length(CScrollBar)] = CScrollBar;
  2408. begin
  2409.   GetPalette := @P;
  2410. end;
  2411.  
  2412. function TScrollBar.GetPos: Integer;
  2413. var
  2414.   R: Integer;
  2415. begin
  2416.   R := Max - Min;
  2417.   if R = 0 then
  2418.     GetPos := 1 else
  2419.     GetPos := ((Value - Min) * (GetSize - 3) + R shr 1) div R + 1;
  2420. end;
  2421.  
  2422. function TScrollBar.GetSize: Integer;
  2423. var
  2424.   S: Integer;
  2425. begin
  2426.   if Size.X = 1 then S := Size.Y else S := Size.X;
  2427.   if S < 3 then GetSize := 3 else GetSize := S;
  2428. end;
  2429.  
  2430. procedure TScrollBar.HandleEvent(var Event: TEvent);
  2431. var
  2432.   Tracking: Boolean;
  2433.   I, P, S, ClickPart: Integer;
  2434.   Mouse: TPoint;
  2435.   Extent: TRect;
  2436.  
  2437. function GetPartCode: Integer;
  2438. var
  2439.   Mark, Part: Integer;
  2440. begin
  2441.   Part := -1;
  2442.   if Extent.Contains(Mouse) then
  2443.   begin
  2444.     if Size.X = 1 then Mark := Mouse.Y else Mark := Mouse.X;
  2445.     if Mark = P then Part := sbIndicator else
  2446.     begin
  2447.       if Mark < 1 then Part := sbLeftArrow else
  2448.         if Mark < P then Part := sbPageLeft else
  2449.           if Mark < S then Part := sbPageRight else
  2450.             Part := sbRightArrow;
  2451.       if Size.X = 1 then Inc(Part, 4);
  2452.     end;
  2453.   end;
  2454.   GetPartCode := Part;
  2455. end;
  2456.  
  2457. procedure Clicked;
  2458. begin
  2459.   Message(Owner, evBroadcast, cmScrollBarClicked, @Self);
  2460. end;
  2461.  
  2462. begin
  2463.   TView.HandleEvent(Event);
  2464.   case Event.What of
  2465.     evMouseDown:
  2466.       begin
  2467.         Clicked;
  2468.         MakeLocal(Event.Where, Mouse);
  2469.         GetExtent(Extent);
  2470.         Extent.Grow(1, 1);
  2471.         P := GetPos;
  2472.         S := GetSize - 1;
  2473.         ClickPart := GetPartCode;
  2474.         if ClickPart <> sbIndicator then
  2475.         begin
  2476.           repeat
  2477.             MakeLocal(Event.Where, Mouse);
  2478.             if GetPartCode = ClickPart then
  2479.               SetValue(Value + ScrollStep(ClickPart));
  2480.           until not MouseEvent(Event, evMouseAuto);
  2481.         end else
  2482.         begin
  2483.           repeat
  2484.             MakeLocal(Event.Where, Mouse);
  2485.             Tracking := Extent.Contains(Mouse);
  2486.             if Tracking then
  2487.             begin
  2488.               if Size.X = 1 then I := Mouse.Y else I := Mouse.X;
  2489.               if I <= 0 then I := 1;
  2490.               if I >= S then I := S - 1;
  2491.             end else I := GetPos;
  2492.             if I <> P then
  2493.             begin
  2494.               DrawPos(I);
  2495.               P := I;
  2496.             end;
  2497.           until not MouseEvent(Event, evMouseMove);
  2498.           if Tracking and (S > 2) then
  2499.           begin
  2500.             Dec(S, 2);
  2501.             SetValue(((P - 1) * (Max - Min) + S shr 1) div S + Min);
  2502.           end;
  2503.         end;
  2504.         ClearEvent(Event);
  2505.       end;
  2506.     evKeyDown:
  2507.       if State and sfVisible <> 0 then
  2508.       begin
  2509.         ClickPart := sbIndicator;
  2510.         if Size.Y = 1 then
  2511.           case CtrlToArrow(Event.KeyCode) of
  2512.             kbLeft: ClickPart := sbLeftArrow;
  2513.             kbRight: ClickPart := sbRightArrow;
  2514.             kbCtrlLeft: ClickPart := sbPageLeft;
  2515.             kbCtrlRight: ClickPart := sbPageRight;
  2516.             kbHome: I := Min;
  2517.             kbEnd: I := Max;
  2518.           else
  2519.             Exit;
  2520.           end
  2521.         else
  2522.           case CtrlToArrow(Event.KeyCode) of
  2523.             kbUp: ClickPart := sbUpArrow;
  2524.             kbDown: ClickPart := sbDownArrow;
  2525.             kbPgUp: ClickPart := sbPageUp;
  2526.             kbPgDn: ClickPart := sbPageDown;
  2527.             kbCtrlPgUp: I := Min;
  2528.             kbCtrlPgDn: I := Max;
  2529.           else
  2530.             Exit;
  2531.           end;
  2532.         Clicked;
  2533.         if ClickPart <> sbIndicator then I := Value + ScrollStep(ClickPart);
  2534.         SetValue(I);
  2535.         ClearEvent(Event);
  2536.       end;
  2537.   end;
  2538. end;
  2539.  
  2540. procedure TScrollBar.ScrollDraw;
  2541. begin
  2542.   Message(Owner, evBroadcast, cmScrollBarChanged, @Self);
  2543. end;
  2544.  
  2545. function TScrollBar.ScrollStep(Part: Integer): Integer;
  2546. var
  2547.   Step: Integer;
  2548. begin
  2549.   if Part and 2 = 0 then Step := ArStep else Step := PgStep;
  2550.   if Part and 1 = 0 then ScrollStep := -Step else ScrollStep := Step;
  2551. end;
  2552.  
  2553. procedure TScrollBar.SetParams(AValue, AMin, AMax, APgStep,
  2554.   AArStep: Integer);
  2555. var
  2556.   SValue: Integer;
  2557. begin
  2558.   if AMax < AMin then AMax := AMin;
  2559.   if AValue < AMin then AValue := AMin;
  2560.   if AValue > AMax then AValue := AMax;
  2561.   SValue := Value;
  2562.   if (SValue <> AValue) or (Min <> AMin) or (Max <> AMax) then
  2563.   begin
  2564.     Value := AValue;
  2565.     Min := AMin;
  2566.     Max := AMax;
  2567.     DrawView;
  2568.     if SValue <> AValue then ScrollDraw;
  2569.   end;
  2570.   PgStep := APgStep;
  2571.   ArStep := AArStep;
  2572. end;
  2573.  
  2574. procedure TScrollBar.SetRange(AMin, AMax: Integer);
  2575. begin
  2576.   SetParams(Value, AMin, AMax, PgStep, ArStep);
  2577. end;
  2578.  
  2579. procedure TScrollBar.SetStep(APgStep, AArStep: Integer);
  2580. begin
  2581.   SetParams(Value, Min, Max, APgStep, AArStep);
  2582. end;
  2583.  
  2584. procedure TScrollBar.SetValue(AValue: Integer);
  2585. begin
  2586.   SetParams(AValue, Min, Max, PgStep, ArStep);
  2587. end;
  2588.  
  2589. procedure TScrollBar.Store(var S: TStream);
  2590. begin
  2591.   TView.Store(S);
  2592.   S.Write(Value, SizeOf(Integer) * 5 + SizeOf(TScrollChars));
  2593. end;
  2594.  
  2595. { TScroller }
  2596.  
  2597. constructor TScroller.Init(var Bounds: TRect; AHScrollBar,
  2598.   AVScrollBar: PScrollBar);
  2599. begin
  2600.   TView.Init(Bounds);
  2601.   Options := Options or ofSelectable;
  2602.   EventMask := EventMask or evBroadcast;
  2603.   HScrollBar := AHScrollBar;
  2604.   VScrollBar := AVScrollBar;
  2605. end;
  2606.  
  2607. constructor TScroller.Load(var S: TStream);
  2608. begin
  2609.   TView.Load(S);
  2610.   GetPeerViewPtr(S, HScrollBar);
  2611.   GetPeerViewPtr(S, VScrollBar);
  2612.   S.Read(Delta, SizeOf(TPoint)*2);
  2613. end;
  2614.  
  2615. procedure TScroller.ChangeBounds(var Bounds: TRect);
  2616. begin
  2617.   SetBounds(Bounds);
  2618.   Inc(DrawLock);
  2619.   SetLimit(Limit.X, Limit.Y);
  2620.   Dec(DrawLock);
  2621.   DrawFlag := False;
  2622.   DrawView;
  2623. end;
  2624.  
  2625. procedure TScroller.CheckDraw;
  2626. begin
  2627.   if (DrawLock = 0) and DrawFlag then
  2628.   begin
  2629.     DrawFlag := False;
  2630.     DrawView;
  2631.   end;
  2632. end;
  2633.  
  2634. function TScroller.GetPalette: PPalette;
  2635. const
  2636.   P: String[Length(CScroller)] = CScroller;
  2637. begin
  2638.   GetPalette := @P;
  2639. end;
  2640.  
  2641. procedure TScroller.HandleEvent(var Event: TEvent);
  2642. begin
  2643.   TView.HandleEvent(Event);
  2644.   if (Event.What = evBroadcast) and (Event.Command = cmScrollBarChanged) and
  2645.      ((Event.InfoPtr = HScrollBar) or (Event.InfoPtr = VScrollBar)) then
  2646.       ScrollDraw;
  2647. end;
  2648.  
  2649. procedure TScroller.ScrollDraw;
  2650. var
  2651.   D: TPoint;
  2652. begin
  2653.   if HScrollBar <> nil then D.X := HScrollBar^.Value
  2654.   else D.X := 0;
  2655.   if VScrollBar <> nil then D.Y := VScrollBar^.Value
  2656.   else D.Y := 0;
  2657.   if (D.X <> Delta.X) or (D.Y <> Delta.Y) then
  2658.   begin
  2659.     SetCursor(Cursor.X + Delta.X - D.X, Cursor.Y + Delta.Y - D.Y);
  2660.     Delta := D;
  2661.     if DrawLock <> 0 then DrawFlag := True else DrawView;
  2662.   end;
  2663. end;
  2664.  
  2665. procedure TScroller.ScrollTo(X, Y: Integer);
  2666. begin
  2667.   Inc(DrawLock);
  2668.   if HScrollBar <> nil then HScrollBar^.SetValue(X);
  2669.   if VScrollBar <> nil then VScrollBar^.SetValue(Y);
  2670.   Dec(DrawLock);
  2671.   CheckDraw;
  2672. end;
  2673.  
  2674. procedure TScroller.SetLimit(X, Y: Integer);
  2675. begin
  2676.   Limit.X := X;
  2677.   Limit.Y := Y;
  2678.   Inc(DrawLock);
  2679.   if HScrollBar <> nil then
  2680.     HScrollBar^.SetParams(HScrollBar^.Value, 0, X - Size.X, Size.X - 1,
  2681.       HScrollBar^.ArStep);
  2682.   if VScrollBar <> nil then
  2683.     VScrollBar^.SetParams(VScrollBar^.Value, 0, Y - Size.Y, Size.Y - 1,
  2684.       VScrollBar^.ArStep);
  2685.   Dec(DrawLock);
  2686.   CheckDraw;
  2687. end;
  2688.  
  2689. procedure TScroller.SetState(AState: Word; Enable: Boolean);
  2690.  
  2691. procedure ShowSBar(SBar: PScrollBar);
  2692. begin
  2693.   if (SBar <> nil) then
  2694.     if GetState(sfActive + sfSelected) then SBar^.Show
  2695.     else SBar^.Hide;
  2696. end;
  2697.  
  2698. begin
  2699.   TView.SetState(AState, Enable);
  2700.   if AState and (sfActive + sfSelected) <> 0 then
  2701.   begin
  2702.     ShowSBar(HScrollBar);
  2703.     ShowSBar(VScrollBar);
  2704.   end;
  2705. end;
  2706.  
  2707. procedure TScroller.Store(var S: TStream);
  2708. begin
  2709.   TView.Store(S);
  2710.   PutPeerViewPtr(S, HScrollBar);
  2711.   PutPeerViewPtr(S, VScrollBar);
  2712.   S.Write(Delta, SizeOf(TPoint)*2);
  2713. end;
  2714.  
  2715. { TListViewer }
  2716.  
  2717. constructor TListViewer.Init(var Bounds: TRect; ANumCols: Word;
  2718.   AHScrollBar, AVScrollBar: PScrollBar);
  2719. var
  2720.   ArStep, PgStep: Integer;
  2721. begin
  2722.   TView.Init(Bounds);
  2723.   Options := Options or (ofFirstClick + ofSelectable);
  2724.   EventMask := EventMask or evBroadcast;
  2725.   Range := 0;
  2726.   NumCols := ANumCols;
  2727.   Focused := 0;
  2728.   if AVScrollBar <> nil then
  2729.   begin
  2730.     if NumCols = 1 then
  2731.     begin
  2732.       PgStep := Size.Y -1;
  2733.       ArStep := 1;
  2734.     end else
  2735.     begin
  2736.       PgStep := Size.Y * NumCols;
  2737.       ArStep := Size.Y;
  2738.     end;
  2739.     AVScrollBar^.SetStep(PgStep, ArStep);
  2740.   end;
  2741.   if AHScrollBar <> nil then AHScrollBar^.SetStep(Size.X div NumCols, 1);
  2742.   HScrollBar := AHScrollBar;
  2743.   VScrollBar := AVScrollBar;
  2744. end;
  2745.  
  2746. constructor TListViewer.Load(var S: TStream);
  2747. begin
  2748.   TView.Load(S);
  2749.   GetPeerViewPtr(S, HScrollBar);
  2750.   GetPeerViewPtr(S, VScrollBar);
  2751.   S.Read(NumCols, SizeOf(Word) * 4);
  2752. end;
  2753.  
  2754. procedure TListViewer.ChangeBounds(var Bounds: TRect);
  2755. begin
  2756.   TView.ChangeBounds(Bounds);
  2757.   if HScrollBar <> nil then
  2758.     HScrollBar^.SetStep(Size.X div NumCols, 1);
  2759.   if VScrollBar <> nil then
  2760.     if NumCols > 1 then
  2761.       VScrollBar^.SetStep(Size.Y * NumCols, Size.Y)
  2762.     else
  2763.       VScrollBar^.SetStep(Size.Y - 1, 1);
  2764. end;
  2765.  
  2766. procedure TListViewer.Draw;
  2767. var
  2768.   I, J, Item: Integer;
  2769.   NormalColor, SelectedColor, FocusedColor, Color: Word;
  2770.   ColWidth, CurCol, Indent: Integer;
  2771.   B: TDrawBuffer;
  2772.   Text: String;
  2773.   SCOff: Byte;
  2774. begin
  2775.   if State and (sfSelected + sfActive) = (sfSelected + sfActive) then
  2776.   begin
  2777.     NormalColor := GetColor(1);
  2778.     FocusedColor := GetColor(3);
  2779.     SelectedColor := GetColor(4);
  2780.   end else
  2781.   begin
  2782.     NormalColor := GetColor(2);
  2783.     SelectedColor := GetColor(4);
  2784.   end;
  2785.   if HScrollBar <> nil then Indent := HScrollBar^.Value
  2786.   else Indent := 0;
  2787.   ColWidth := Size.X div NumCols + 1;
  2788.   for I := 0 to Size.Y - 1 do
  2789.   begin
  2790.     for J := 0 to NumCols-1 do
  2791.     begin
  2792.       Item := J*Size.Y + I + TopItem;
  2793.       CurCol := J*ColWidth;
  2794.       if (State and (sfSelected + sfActive) = (sfSelected + sfActive)) and
  2795.         (Focused = Item) and (Range > 0) then
  2796.       begin
  2797.         Color := FocusedColor;
  2798.         SetCursor(CurCol+1,I);
  2799.         SCOff := 0;
  2800.       end
  2801.       else if (Item < Range) and IsSelected(Item) then
  2802.       begin
  2803.         Color := SelectedColor;
  2804.         SCOff := 2;
  2805.       end
  2806.       else
  2807.       begin
  2808.         Color := NormalColor;
  2809.         SCOff := 4;
  2810.       end;
  2811.       MoveChar(B[CurCol], ' ', Color, ColWidth);
  2812.       if Item < Range then
  2813.       begin
  2814.         Text := GetText(Item, ColWidth + Indent);
  2815.         Text := Copy(Text,Indent,ColWidth);
  2816.         MoveStr(B[CurCol+1], Text, Color);
  2817.         if ShowMarkers then
  2818.         begin
  2819.           WordRec(B[CurCol]).Lo := Byte(SpecialChars[SCOff]);
  2820.           WordRec(B[CurCol+ColWidth-2]).Lo := Byte(SpecialChars[SCOff+1]);
  2821.         end;
  2822.       end;
  2823.       MoveChar(B[CurCol+ColWidth-1], ldVerticalBar, GetColor(5), 1);
  2824.     end;
  2825.     WriteLine(0, I, Size.X, 1, B);
  2826.   end;
  2827. end;
  2828.  
  2829. procedure TListViewer.FocusItem(Item: Integer);
  2830. begin
  2831.   Focused := Item;
  2832.   if VScrollBar <> nil then VScrollBar^.SetValue(Item);
  2833.   if Item < TopItem then
  2834.     if NumCols = 1 then TopItem := Item
  2835.     else TopItem := Item - Item mod Size.Y
  2836.   else if Item >= TopItem + (Size.Y*NumCols) then
  2837.     if NumCols = 1 then TopItem := Item - Size.Y + 1
  2838.     else TopItem := Item - Item mod Size.Y - (Size.Y*(NumCols - 1));
  2839. end;
  2840.  
  2841. procedure TListViewer.FocusItemNum(Item: Integer);
  2842. begin
  2843.   if Item < 0 then Item := 0
  2844.   else if (Item >= Range) and (Range > 0) then Item := Range-1;
  2845.   if Range <> 0 then FocusItem(Item);
  2846. end;
  2847.  
  2848. function TListViewer.GetPalette: PPalette;
  2849. const
  2850.   P: String[Length(CListViewer)] = CListViewer;
  2851. begin
  2852.   GetPalette := @P;
  2853. end;
  2854.  
  2855. function TListViewer.GetText(Item: Integer; MaxLen: Integer): String;
  2856. begin
  2857.   Abstract;
  2858. end;
  2859.  
  2860. function TListViewer.IsSelected(Item: Integer): Boolean;
  2861. begin
  2862.   IsSelected := Item = Focused;
  2863. end;
  2864.  
  2865. procedure TListViewer.HandleEvent(var Event: TEvent);
  2866. const
  2867.   MouseAutosToSkip = 4;
  2868. var
  2869.   Mouse: TPoint;
  2870.   ColWidth: Word;
  2871.   OldItem, NewItem: Integer;
  2872.   Count: Word;
  2873. begin
  2874.   TView.HandleEvent(Event);
  2875.   if Event.What = evMouseDown then
  2876.   begin
  2877.     ColWidth := Size.X div NumCols + 1;
  2878.     OldItem := Focused;
  2879.     MakeLocal(Event.Where, Mouse);
  2880.     if MouseInView(Event.Where) then
  2881.       NewItem := Mouse.Y + (Size.Y * (Mouse.X div ColWidth)) + TopItem
  2882.     else NewItem := OldItem;
  2883.     Count := 0;
  2884.     repeat
  2885.       if NewItem <> OldItem then
  2886.       begin
  2887.         FocusItemNum(NewItem);
  2888.         DrawView;
  2889.       end;
  2890.       OldItem := NewItem;
  2891.       MakeLocal(Event.Where, Mouse);
  2892.       if MouseInView(Event.Where) then
  2893.         NewItem := Mouse.Y + (Size.Y * (Mouse.X div ColWidth)) + TopItem
  2894.       else
  2895.       begin
  2896.         if NumCols = 1 then
  2897.         begin
  2898.           if Event.What = evMouseAuto then Inc(Count);
  2899.           if Count = MouseAutosToSkip then
  2900.           begin
  2901.             Count := 0;
  2902.             if Mouse.Y < 0 then NewItem := Focused-1
  2903.             else if Mouse.Y >= Size.Y then NewItem := Focused+1;
  2904.           end;
  2905.         end
  2906.         else
  2907.         begin
  2908.           if Event.What = evMouseAuto then Inc(Count);
  2909.           if Count = MouseAutosToSkip then
  2910.           begin
  2911.             Count := 0;
  2912.             if Mouse.X < 0 then NewItem := Focused-Size.Y
  2913.             else if Mouse.X >= Size.X then NewItem := Focused+Size.Y
  2914.             else if Mouse.Y < 0 then
  2915.               NewItem := Focused - Focused mod Size.Y
  2916.             else if Mouse.Y > Size.Y then
  2917.               NewItem := Focused - Focused mod Size.Y + Size.Y - 1;
  2918.           end
  2919.         end;
  2920.       end;
  2921.     until not MouseEvent(Event, evMouseMove + evMouseAuto);
  2922.     FocusItemNum(NewItem);
  2923.     DrawView;
  2924.     if Event.Double and (Range > Focused) then SelectItem(Focused);
  2925.     ClearEvent(Event);
  2926.   end
  2927.   else if Event.What = evKeyDown then
  2928.   begin
  2929.     if (Event.CharCode = ' ') and (Focused < Range) then
  2930.     begin
  2931.       SelectItem(Focused);
  2932.       NewItem := Focused;
  2933.     end
  2934.     else case CtrlToArrow(Event.KeyCode) of
  2935.       kbUp: NewItem := Focused - 1;
  2936.       kbDown: NewItem := Focused + 1;
  2937.       kbRight: if NumCols > 1 then NewItem := Focused + Size.Y else Exit;
  2938.       kbLeft: if NumCols > 1 then NewItem := Focused - Size.Y else Exit;
  2939.       kbPgDn: NewItem := Focused + Size.Y * NumCols;
  2940.       kbPgUp: NewItem := Focused - Size.Y * NumCols;
  2941.       kbHome: NewItem := TopItem;
  2942.       kbEnd: NewItem := TopItem + (Size.Y * NumCols) - 1;
  2943.       kbCtrlPgDn: NewItem := Range - 1;
  2944.                         kbCtrlPgUp: NewItem := 0;
  2945.                 else
  2946.       Exit;
  2947.     end;
  2948.     FocusItemNum(NewItem);
  2949.     DrawView;
  2950.     ClearEvent(Event);
  2951.   end else if Event.What = evBroadcast then
  2952.     if Options and ofSelectable <> 0 then
  2953.       if (Event.Command = cmScrollBarClicked) and
  2954.          ((Event.InfoPtr = HScrollBar) or (Event.InfoPtr = VScrollBar)) then
  2955.         Select
  2956.       else if (Event.Command = cmScrollBarChanged) then
  2957.       begin
  2958.         if (VScrollBar = Event.InfoPtr) then
  2959.         begin
  2960.           FocusItemNum(VScrollBar^.Value);
  2961.           DrawView;
  2962.         end else if (HScrollBar = Event.InfoPtr) then DrawView;
  2963.       end;
  2964. end;
  2965.  
  2966. procedure TListViewer.SelectItem(Item: Integer);
  2967. begin
  2968.   Message(Owner, evBroadcast, cmListItemSelected, @Self);
  2969. end;
  2970.  
  2971. procedure TListViewer.SetRange(ARange: Integer);
  2972. begin
  2973.   Range := ARange;
  2974.   if VScrollBar <> nil then
  2975.   begin
  2976.     if Focused > ARange then Focused := 0;
  2977.     VScrollbar^.SetParams(Focused, 0, ARange-1, VScrollBar^.PgStep,
  2978.       VScrollBar^.ArStep);
  2979.   end;
  2980. end;
  2981.  
  2982. procedure TListViewer.SetState(AState: Word; Enable: Boolean);
  2983.  
  2984. procedure ShowSBar(SBar: PScrollBar);
  2985. begin
  2986.   if (SBar <> nil) then
  2987.     if GetState(sfActive) and GetState(sfVisible) then SBar^.Show
  2988.     else SBar^.Hide;
  2989. end;
  2990.  
  2991. begin
  2992.   TView.SetState(AState, Enable);
  2993.   if AState and (sfSelected + sfActive + sfVisible) <> 0 then
  2994.   begin
  2995.     ShowSBar(HScrollBar);
  2996.     ShowSBar(VScrollBar);
  2997.     DrawView;
  2998.   end;
  2999. end;
  3000.  
  3001. procedure TListViewer.Store(var S: TStream);
  3002. begin
  3003.   TView.Store(S);
  3004.   PutPeerViewPtr(S, HScrollBar);
  3005.   PutPeerViewPtr(S, VScrollBar);
  3006.   S.Write(NumCols, SizeOf(Word) * 4);
  3007. end;
  3008.  
  3009. { TGroup }
  3010.  
  3011. constructor TGroup.Init(var Bounds: TRect);
  3012. begin
  3013.   TView.Init(Bounds);
  3014.   Options := Options or (ofSelectable + ofBuffered);
  3015.   GetExtent(Clip);
  3016.   EventMask := $FFFFFFFF;
  3017. end;
  3018.  
  3019. constructor TGroup.Load(var S: TStream);
  3020. var
  3021.   FixupSave: PFixupList;
  3022.   Count, I: Integer;
  3023.   P, Q: ^Pointer;
  3024.   V: PView;
  3025.   OwnerSave: PGroup;
  3026.   SaveESP: Word;
  3027. begin
  3028.   TView.Load(S);
  3029.   GetExtent(Clip);
  3030.   OwnerSave := OwnerGroup;
  3031.   OwnerGroup := @Self;
  3032.   FixupSave := FixupList;
  3033.   S.Read(Count, SizeOf(Word));
  3034.   asm         {&SAVES ebx,edx,esi}
  3035.                 mov     SaveESP,esp
  3036.                 mov     ecx,Count
  3037.                 shl     ecx,2
  3038.                 sub     esp,ecx
  3039.                 mov     FixupList,esp
  3040.                 mov     edi,esp
  3041.                 xor     eax,eax
  3042.                 shr     ecx,2
  3043.                 cld
  3044.                 rep     stosd
  3045.   end;
  3046.   for I := 1 to Count do
  3047.   begin
  3048.     V := PView(S.Get);
  3049.     if V <> nil then InsertView(V, nil);
  3050.   end;
  3051.   V := Last;
  3052.   for I := 1 to Count do
  3053.   begin
  3054.     V := V^.Next;
  3055.     P := FixupList^[I];
  3056.     while P <> nil do
  3057.     begin
  3058.       Q := P;
  3059.       P := P^;
  3060.       Q^ := V;
  3061.     end;
  3062.   end;
  3063.   OwnerGroup := OwnerSave;
  3064.   FixupList := FixupSave;
  3065.   GetSubViewPtr(S, V);
  3066.   SetCurrent(V, NormalSelect);
  3067.   if OwnerGroup = nil then Awaken;
  3068.   asm   mov esp,SaveESP   end;
  3069. end;
  3070.  
  3071. destructor TGroup.Done;
  3072. var
  3073.   P, T: PView;
  3074. begin
  3075.   Hide;
  3076.   P := Last;
  3077.   if P <> nil then
  3078.   begin
  3079.     repeat
  3080.       P^.Hide;
  3081.       P := P^.Prev;
  3082.     until P = Last;
  3083.     repeat
  3084.       T := P^.Prev;
  3085.       Dispose(P, Done);
  3086.       P := T;
  3087.     until Last = nil;
  3088.   end;
  3089.   FreeBuffer;
  3090.   TView.Done;
  3091. end;
  3092.  
  3093. function TGroup.At(Index: Integer): PView; {&USES None} {&FRAME-}
  3094. asm
  3095.                 mov     eax,Self
  3096.                 mov     eax,[eax].TGroup.Last
  3097.                 mov     ecx,Index
  3098.               @@1:
  3099.                 mov     eax,[eax].TView.Next
  3100.                 loop    @@1
  3101. end;
  3102.  
  3103. procedure TGroup.Awaken;
  3104.  
  3105.   procedure DoAwaken(P: PView);
  3106.   begin
  3107.     P^.Awaken;
  3108.   end;
  3109.  
  3110. begin
  3111.   ForEach(@DoAwaken);
  3112. end;
  3113.  
  3114. procedure TGroup.ChangeBounds(var Bounds: TRect);
  3115. var
  3116.   D: TPoint;
  3117.  
  3118. procedure DoCalcChange(P: PView);
  3119. var
  3120.   R: TRect;
  3121. begin
  3122.   P^.CalcBounds(R, D);
  3123.   P^.ChangeBounds(R);
  3124. end;
  3125.  
  3126. begin
  3127.   D.X := Bounds.B.X - Bounds.A.X - Size.X;
  3128.   D.Y := Bounds.B.Y - Bounds.A.Y - Size.Y;
  3129.   if (D.X or D.Y) = 0 then
  3130.   begin
  3131.     SetBounds(Bounds);
  3132.     DrawView;
  3133.   end else
  3134.   begin
  3135.     FreeBuffer;
  3136.     SetBounds(Bounds);
  3137.     GetExtent(Clip);
  3138.     GetBuffer;
  3139.     Lock;
  3140.     ForEach(@DoCalcChange);
  3141.     Unlock;
  3142.   end;
  3143. end;
  3144.  
  3145. function TGroup.DataSize: Word;
  3146. var
  3147.   T: Word;
  3148.  
  3149. procedure AddSubviewDataSize(P: PView);
  3150. begin
  3151.   Inc(T, P^.DataSize);
  3152. end;
  3153.  
  3154. begin
  3155.   T := 0;
  3156.   ForEach(@AddSubviewDataSize);
  3157.   DataSize := T;
  3158. end;
  3159.  
  3160. procedure TGroup.Delete(P: PView);
  3161. var
  3162.   SaveState: Word;
  3163. begin
  3164.   SaveState := P^.State;
  3165.   P^.Hide;
  3166.   RemoveView(P);
  3167.   P^.Owner := nil;
  3168.   P^.Next := nil;
  3169.   if SaveState and sfVisible <> 0 then P^.Show;
  3170. end;
  3171.  
  3172. procedure TGroup.Draw;
  3173. var
  3174.   R: TRect;
  3175. begin
  3176.   if Buffer = nil then
  3177.   begin
  3178.     GetBuffer;
  3179.     if Buffer <> nil then
  3180.     begin
  3181.       Inc(LockFlag);
  3182.       Redraw;
  3183.       Dec(LockFlag);
  3184.     end;
  3185.   end;
  3186.   if Buffer <> nil then WriteBuf(0, 0, Size.X, Size.Y, Buffer^) else
  3187.   begin
  3188.     GetClipRect(Clip);
  3189.     Redraw;
  3190.     GetExtent(Clip);
  3191.   end;
  3192. end;
  3193.  
  3194. procedure TGroup.DrawSubViews(P, Bottom: PView);
  3195. begin
  3196.   if P <> nil then
  3197.     while P <> Bottom do
  3198.     begin
  3199.       P^.DrawView;
  3200.       P := P^.NextView;
  3201.     end;
  3202. end;
  3203.  
  3204. procedure TGroup.EndModal(Command: Word);
  3205. begin
  3206.   if State and sfModal <> 0 then EndState := Command
  3207.   else TView.EndModal(Command);
  3208. end;
  3209.  
  3210. procedure TGroup.EventError(var Event: TEvent);
  3211. begin
  3212.   if Owner <> nil then Owner^.EventError(Event);
  3213. end;
  3214.  
  3215. function TGroup.Execute: Word;
  3216. var
  3217.   E: TEvent;
  3218. begin
  3219.   repeat
  3220.     EndState := 0;
  3221.     repeat
  3222.       GetEvent(E);
  3223.       HandleEvent(E);
  3224.       if E.What <> evNothing then EventError(E);
  3225.     until EndState <> 0;
  3226.   until Valid(EndState);
  3227.   Execute := EndState;
  3228. end;
  3229.  
  3230. function TGroup.ExecView(P: PView): Word;
  3231. var
  3232.   SaveOptions: Word;
  3233.   SaveOwner: PGroup;
  3234.   SaveTopView: PView;
  3235.   SaveCurrent: PView;
  3236.   SaveCommands: TCommandSet;
  3237. begin
  3238.   if P <> nil then
  3239.   begin
  3240.     SaveOptions := P^.Options;
  3241.     SaveOwner := P^.Owner;
  3242.     SaveTopView := TheTopView;
  3243.     SaveCurrent := Current;
  3244.     GetCommands(SaveCommands);
  3245.     TheTopView := P;
  3246.     P^.Options := P^.Options and not ofSelectable;
  3247.     P^.SetState(sfModal, True);
  3248.     SetCurrent(P, EnterSelect);
  3249.     if SaveOwner = nil then Insert(P);
  3250.     ExecView := P^.Execute;
  3251.     if SaveOwner = nil then Delete(P);
  3252.     SetCurrent(SaveCurrent, LeaveSelect);
  3253.     P^.SetState(sfModal, False);
  3254.     P^.Options := SaveOptions;
  3255.     TheTopView := SaveTopView;
  3256.     SetCommands(SaveCommands);
  3257.   end else ExecView := cmCancel;
  3258. end;
  3259.  
  3260. function TGroup.First: PView;
  3261. begin
  3262.   if Last = nil then First := nil else First := Last^.Next;
  3263. end;
  3264.  
  3265. function TGroup.FirstMatch(AState: Word; AOptions: Word): PView;
  3266.  
  3267. function Matches(P: PView): Boolean;
  3268. begin
  3269.   Matches := (P^.State and AState = AState) and
  3270.     (P^.Options and AOptions = AOptions);
  3271. end;
  3272.  
  3273. begin
  3274.   FirstMatch := FirstThat(@Matches);
  3275. end;
  3276.  
  3277. function TGroup.FirstThat(P: Pointer): PView; assembler; {&USES None} {&FRAME-}
  3278. var
  3279.   ALast: Pointer;
  3280. asm
  3281.                 mov     eax,Self
  3282.                 mov     eax,[eax].TGroup.Last
  3283.                 test    eax,eax
  3284.                 jz      @@2
  3285.                 mov     ALast,eax
  3286.               @@1:
  3287.                 mov     ecx,P
  3288.                 mov     eax,[eax].TView.Next
  3289.                 push    eax
  3290.                 push    eax                     {[1]:Pointer = PView }
  3291.                 Call    ecx
  3292.                 test    al,al
  3293.                 pop     eax
  3294.                 jnz     @@2
  3295.                 cmp     eax,ALast
  3296.                 jne     @@1
  3297.                 xor     eax,eax
  3298.               @@2:
  3299. end;
  3300.  
  3301. function TGroup.FindNext(Forwards: Boolean): PView;
  3302. var
  3303.   P: PView;
  3304. begin
  3305.   FindNext := nil;
  3306.   if Current <> nil then
  3307.   begin
  3308.     P := Current;
  3309.     repeat
  3310.       if Forwards then P := P^.Next else P := P^.Prev;
  3311.     until ((P^.State and (sfVisible + sfDisabled) = sfVisible) and
  3312.       (P^.Options and ofSelectable <> 0)) or (P = Current);
  3313.     if P <> Current then FindNext := P;
  3314.   end;
  3315. end;
  3316.  
  3317. function TGroup.FocusNext(Forwards: Boolean): Boolean;
  3318. var
  3319.   P: PView;
  3320. begin
  3321.   P := FindNext(Forwards);
  3322.   FocusNext := True;
  3323.   if P <> nil then FocusNext := P^.Focus;
  3324. end;
  3325.  
  3326. procedure TGroup.ForEach(P: Pointer); assembler; {&USES ebx} {&FRAME-}
  3327. var
  3328.   ALast: Pointer;
  3329. asm
  3330.                 mov     ecx,Self
  3331.                 mov     ecx,[ecx].TGroup.Last
  3332.                 jecxz   @@RET
  3333.                 mov     ebx,P
  3334.                 mov     ALast,ecx
  3335.                 mov     ecx,[ecx].TView.Next
  3336.               @@1:
  3337.                 cmp     ecx,ALast
  3338.                 je      @@2
  3339.                 push    [ecx].TView.Next
  3340.                 push    ecx
  3341.                 Call    ebx
  3342.                 pop     ecx
  3343.                 jmp     @@1
  3344.               @@2:
  3345.                 push    ecx
  3346.                 Call    ebx
  3347.               @@RET:
  3348. end;
  3349.  
  3350. procedure TGroup.FreeBuffer;
  3351. begin
  3352.   if (Options and ofBuffered <> 0) and (Buffer <> nil) then
  3353.     DisposeCache(Pointer(Buffer));
  3354. end;
  3355.  
  3356. { Allocate a group buffer if the group is exposed and buffered }
  3357.  
  3358. procedure TGroup.GetBuffer; {&USES None} {&FRAME-}
  3359. asm
  3360.                 mov     ecx,Self
  3361.                 test    [ecx].State,sfExposed
  3362.                 jz      @@1
  3363.                 test    [ecx].Options,ofBuffered
  3364.                 jz      @@1
  3365.                 cmp     [ecx].Buffer,0
  3366.                 jnz     @@1
  3367.                 mov     eax,[ecx].TView.Size.X
  3368.                 mul     [ecx].TView.Size.Y
  3369.                 jo      @@1
  3370.                 shl     eax,1
  3371.                 jc      @@1
  3372.                 js      @@1
  3373.                 lea     ecx,[ecx].TView.Buffer
  3374.                 push    ecx             { [1]:Pointer = @ of the buffer@ }
  3375.                 push    eax             { [2]:Pointer = Buffer Size      }
  3376.                 Call    NewCache
  3377.               @@1:
  3378. end;
  3379.  
  3380. procedure TGroup.GetData(var Rec);
  3381. type
  3382.   Bytes = array[0..65534] of Byte;
  3383. var
  3384.   I: Word;
  3385.   V: PView;
  3386. begin
  3387.   I := 0;
  3388.   if Last <> nil then
  3389.   begin
  3390.     V := Last;
  3391.     repeat
  3392.       V^.GetData(Bytes(Rec)[I]);
  3393.       Inc(I, V^.DataSize);
  3394.       V := V^.Prev;
  3395.     until V = Last;
  3396.   end;
  3397. end;
  3398.  
  3399. function TGroup.GetHelpCtx: Word;
  3400. var
  3401.   H: Word;
  3402. begin
  3403.   H:= hcNoContext;
  3404.   if Current <> nil then H := Current^.GetHelpCtx;
  3405.   if H = hcNoContext then H := TView.GetHelpCtx;
  3406.   GetHelpCtx := H;
  3407. end;
  3408.  
  3409. procedure TGroup.GetSubViewPtr(var S: TStream; var P);
  3410. var
  3411.   Index: Word;
  3412. begin
  3413.   S.Read(Index, SizeOf(Word));
  3414.   if Index > 0 then
  3415.     Pointer(P) := At(Index)
  3416.   else
  3417.     Pointer(P) := nil;
  3418. end;
  3419.  
  3420. procedure TGroup.HandleEvent(var Event: TEvent);
  3421.  
  3422. procedure DoHandleEvent(P: PView);
  3423. begin
  3424.   if (P = nil) or ((P^.State and sfDisabled <> 0)
  3425.     and (Event.What and (PositionalEvents or FocusedEvents) <> 0)) then Exit;
  3426.   case Phase of
  3427.     phPreProcess: if P^.Options and ofPreProcess = 0 then Exit;
  3428.     phPostProcess: if P^.Options and ofPostProcess = 0 then Exit;
  3429.   end;
  3430.   if Event.What and P^.EventMask <> 0 then P^.HandleEvent(Event);
  3431. end;
  3432.  
  3433. function ContainsMouse(P: PView): Boolean;
  3434. begin
  3435.   ContainsMouse := (P^.State and sfVisible <> 0) and
  3436.     P^.MouseInView(Event.Where);
  3437. end;
  3438.  
  3439. begin
  3440.   TView.HandleEvent(Event);
  3441.   if Event.What and FocusedEvents <> 0 then
  3442.   begin
  3443.     Phase := phPreProcess;
  3444.     ForEach(@DoHandleEvent);
  3445.     Phase := phFocused;
  3446.     DoHandleEvent(Current);
  3447.     Phase := phPostProcess;
  3448.     ForEach(@DoHandleEvent);
  3449.   end else
  3450.   begin
  3451.     Phase := phFocused;
  3452.     if (Event.What and PositionalEvents <> 0) then
  3453.       DoHandleEvent(FirstThat(@ContainsMouse)) else
  3454.       ForEach(@DoHandleEvent);
  3455.   end;
  3456. end;
  3457.  
  3458. function TGroup.IndexOf(P: PView): Integer; {&USES None} {&FRAME-}
  3459. asm
  3460.                 mov     ecx,Self
  3461.                 mov     ecx,[ecx].TGroup.Last
  3462.                 jecxz   @@2
  3463.                 mov     edx,ecx
  3464.                 xor     eax,eax
  3465.               @@1:
  3466.                 inc     eax
  3467.                 mov     ecx,[ecx].TView.Next
  3468.                 cmp     ecx,P
  3469.                 je      @@3
  3470.                 cmp     ecx,edx
  3471.                 jne     @@1
  3472.               @@2:
  3473.                 xor     eax,eax
  3474.               @@3:
  3475. end;
  3476.  
  3477. procedure TGroup.Insert(P: PView);
  3478. begin
  3479.   InsertBefore(P, First);
  3480. end;
  3481.  
  3482. procedure TGroup.InsertBefore(P, Target: PView);
  3483. var
  3484.   SaveState: Word;
  3485. begin
  3486.   if (P <> nil) and (P^.Owner = nil) and
  3487.     ((Target = nil) or (Target^.Owner = @Self)) then
  3488.   begin
  3489.     if P^.Options and ofCenterX <> 0 then
  3490.       P^.Origin.X := (Size.X - P^.Size.X) div 2;
  3491.     if P^.Options and ofCenterY <> 0 then
  3492.       P^.Origin.Y := (Size.Y - P^.Size.Y) div 2;
  3493.     SaveState := P^.State;
  3494.     P^.Hide;
  3495.     InsertView(P, Target);
  3496.     if SaveState and sfVisible <> 0 then P^.Show;
  3497.     if State and sfActive <> 0 then
  3498.       P^.SetState(sfActive, True);
  3499.   end;
  3500. end;
  3501.  
  3502. procedure TGroup.InsertView(P, Target: PView);
  3503. begin
  3504.   P^.Owner := @Self;
  3505.   if Target <> nil then
  3506.   begin
  3507.     Target := Target^.Prev;
  3508.     P^.Next := Target^.Next;
  3509.     Target^.Next := P;
  3510.   end else
  3511.   begin
  3512.     if Last = nil then P^.Next := P else
  3513.     begin
  3514.       P^.Next := Last^.Next;
  3515.       Last^.Next := P;
  3516.     end;
  3517.     Last := P;
  3518.   end;
  3519. end;
  3520.  
  3521. procedure TGroup.Lock;
  3522. begin
  3523.   if (Buffer <> nil) or (LockFlag <> 0) then Inc(LockFlag);
  3524. end;
  3525.  
  3526. procedure TGroup.PutSubViewPtr(var S: TStream; P: PView);
  3527. var
  3528.   Index: Word;
  3529. begin
  3530.   if P = nil then Index := 0
  3531.   else Index := IndexOf(P);
  3532.   S.Write(Index, SizeOf(Word));
  3533. end;
  3534.  
  3535. procedure TGroup.Redraw;
  3536. begin
  3537.   DrawSubViews(First, nil);
  3538. end;
  3539.  
  3540. procedure TGroup.RemoveView(P: PView); {&USES edi} {&FRAME+}
  3541. asm
  3542.                 mov     edx,Self
  3543.                 mov     edi,P
  3544.                 mov     edx,[edx].TGroup.Last
  3545.                 test    edx,edx
  3546.                 jz      @@4
  3547.                 mov     eax,edx
  3548.               @@1:
  3549.                 mov     ecx,[edx].TView.Next
  3550.                 cmp     ecx,edi
  3551.                 je      @@2
  3552.                 cmp     ecx,eax
  3553.                 je      @@4
  3554.                 mov     edx,ecx
  3555.                 jmp     @@1
  3556.               @@2:
  3557.                 mov     ecx,[edi].TView.Next
  3558.                 mov     [edx].TView.Next,ecx
  3559.                 cmp     eax,edi
  3560.                 jne     @@4
  3561.                 cmp     ecx,edi
  3562.                 jne     @@3
  3563.                 xor     edx,edx
  3564.               @@3:
  3565.                 mov     edi,Self
  3566.                 mov     [edi].TView.Last,edx
  3567.               @@4:
  3568. end;
  3569.  
  3570. procedure TGroup.ResetCurrent;
  3571. begin
  3572.   SetCurrent(FirstMatch(sfVisible, ofSelectable), NormalSelect);
  3573. end;
  3574.  
  3575. procedure TGroup.ResetCursor;
  3576. begin
  3577.   if Current <> nil then Current^.ResetCursor;
  3578. end;
  3579.  
  3580. procedure TGroup.SelectNext(Forwards: Boolean);
  3581. var
  3582.   P: PView;
  3583. begin
  3584.   P := FindNext(Forwards);
  3585.   if P <> nil then P^.Select;
  3586. end;
  3587.  
  3588. procedure TGroup.SetCurrent(P: PView; Mode: SelectMode);
  3589.  
  3590. procedure SelectView(P: PView; Enable: Boolean);
  3591. begin
  3592.   if P <> nil then P^.SetState(sfSelected, Enable);
  3593. end;
  3594.  
  3595. procedure FocusView(P: PView; Enable: Boolean);
  3596. begin
  3597.   if (State and sfFocused <> 0) and (P <> nil) then
  3598.     P^.SetState(sfFocused, Enable);
  3599. end;
  3600.  
  3601. begin
  3602.   if Current <> P then
  3603.   begin
  3604.     Lock;
  3605.     FocusView(Current, False);
  3606.     if Mode <> EnterSelect then SelectView(Current, False);
  3607.     if Mode <> LeaveSelect then SelectView(P, True);
  3608.     FocusView(P, True);
  3609.     Current := P;
  3610.     Unlock;
  3611.   end;
  3612. end;
  3613.  
  3614. procedure TGroup.SetData(var Rec);
  3615. type
  3616.   Bytes = array[0..65534] of Byte;
  3617. var
  3618.   I: Word;
  3619.   V: PView;
  3620. begin
  3621.   I := 0;
  3622.   if Last <> nil then
  3623.   begin
  3624.     V := Last;
  3625.     repeat
  3626.       V^.SetData(Bytes(Rec)[I]);
  3627.       Inc(I, V^.DataSize);
  3628.       V := V^.Prev;
  3629.     until V = Last;
  3630.   end;
  3631. end;
  3632.  
  3633. procedure TGroup.SetState(AState: Word; Enable: Boolean);
  3634.  
  3635. procedure DoSetState(P: PView);
  3636. begin
  3637.   P^.SetState(AState, Enable);
  3638. end;
  3639.  
  3640. procedure DoExpose(P: PView);
  3641. begin
  3642.   if P^.State and sfVisible <> 0 then P^.SetState(sfExposed, Enable);
  3643. end;
  3644.  
  3645. begin
  3646.   TView.SetState(AState, Enable);
  3647.   case AState of
  3648.     sfActive, sfDragging:
  3649.       begin
  3650.         Lock;
  3651.         ForEach(@DoSetState);
  3652.         Unlock;
  3653.       end;
  3654.     sfFocused:
  3655.       if Current <> nil then Current^.SetState(sfFocused, Enable);
  3656.     sfExposed:
  3657.       begin
  3658.         ForEach(@DoExpose);
  3659.         if not Enable then FreeBuffer;
  3660.       end;
  3661.   end;
  3662. end;
  3663.  
  3664. procedure TGroup.Store(var S: TStream);
  3665. var
  3666.   Count: Integer;
  3667.   OwnerSave: PGroup;
  3668.  
  3669. procedure DoPut(P: PView);
  3670. begin
  3671.   S.Put(P);
  3672. end;
  3673.  
  3674. begin
  3675.   TView.Store(S);
  3676.   OwnerSave := OwnerGroup;
  3677.   OwnerGroup := @Self;
  3678.   Count := IndexOf(Last);
  3679.   S.Write(Count, SizeOf(Word));
  3680.   ForEach(@DoPut);
  3681.   PutSubViewPtr(S, Current);
  3682.   OwnerGroup := OwnerSave;
  3683. end;
  3684.  
  3685. procedure TGroup.Unlock;
  3686. begin
  3687.   if LockFlag <> 0 then
  3688.   begin
  3689.     Dec(LockFlag);
  3690.     if LockFlag = 0 then DrawView;
  3691.   end;
  3692. end;
  3693.  
  3694. function TGroup.Valid(Command: Word): Boolean;
  3695.  
  3696. function IsInvalid(P: PView): Boolean;
  3697. begin
  3698.   IsInvalid := not P^.Valid(Command);
  3699. end;
  3700.  
  3701. begin
  3702.   Valid := True;
  3703.   if Command = cmReleasedFocus then
  3704.   begin
  3705.     if (Current <> nil) and (Current^.Options and ofValidate <> 0) then
  3706.       Valid := Current^.Valid(Command);
  3707.   end
  3708.   else
  3709.     Valid := FirstThat(@IsInvalid) = nil;
  3710. end;
  3711.  
  3712. { TWindow }
  3713.  
  3714. constructor TWindow.Init(var Bounds: TRect; ATitle: TTitleStr;
  3715.   ANumber: Integer);
  3716. begin
  3717.   TGroup.Init(Bounds);
  3718.   State := State or sfShadow;
  3719.   Options := Options or (ofSelectable + ofTopSelect);
  3720.   GrowMode := gfGrowAll + gfGrowRel;
  3721.   Flags := wfMove + wfGrow + wfClose + wfZoom;
  3722.   Title := NewStr(ATitle);
  3723.   Number := ANumber;
  3724.   Palette := wpBlueWindow;
  3725.   InitFrame;
  3726.   if Frame <> nil then Insert(Frame);
  3727.   GetBounds(ZoomRect);
  3728. end;
  3729.  
  3730. constructor TWindow.Load(var S: TStream);
  3731. begin
  3732.   TGroup.Load(S);
  3733.   S.Read(Flags, SizeOf(Byte) + SizeOf(TRect) + 2 * SizeOf(Integer));
  3734.   GetSubViewPtr(S, Frame);
  3735.   Title := S.ReadStr;
  3736. end;
  3737.  
  3738. destructor TWindow.Done;
  3739. begin
  3740.   TGroup.Done;
  3741.   DisposeStr(Title);
  3742. end;
  3743.  
  3744. procedure TWindow.Close;
  3745. begin
  3746.   if Valid(cmClose) then Free;
  3747. end;
  3748.  
  3749. function TWindow.GetPalette: PPalette;
  3750. const
  3751.   P: array[wpBlueWindow..wpGrayWindow] of string[Length(CBlueWindow)] =
  3752.     (CBlueWindow, CCyanWindow, CGrayWindow);
  3753. begin
  3754.   GetPalette := @P[Palette];
  3755. end;
  3756.  
  3757. function TWindow.GetTitle(MaxSize: Integer): TTitleStr;
  3758. begin
  3759.   if Title <> nil then GetTitle := Title^
  3760.   else GetTitle := '';
  3761. end;
  3762.  
  3763. procedure TWindow.HandleEvent(var Event: TEvent);
  3764. var
  3765.   Limits: TRect;
  3766.   Min, Max: TPoint;
  3767. begin
  3768.   TGroup.HandleEvent(Event);
  3769.   if (Event.What = evCommand) then
  3770.     case Event.Command of
  3771.       cmResize:
  3772.         if Flags and (wfMove + wfGrow) <> 0 then
  3773.         begin
  3774.           Owner^.GetExtent(Limits);
  3775.           SizeLimits(Min, Max);
  3776.           DragView(Event, DragMode or (Flags and (wfMove + wfGrow)),
  3777.             Limits, Min, Max);
  3778.           ClearEvent(Event);
  3779.         end;
  3780.       cmClose:
  3781.         if (Flags and wfClose <> 0) and
  3782.           ((Event.InfoPtr = nil) or (Event.InfoPtr = @Self)) then
  3783.         begin
  3784.           ClearEvent(Event);
  3785.           if State and sfModal = 0 then Close else
  3786.           begin
  3787.             Event.What := evCommand;
  3788.             Event.Command := cmCancel;
  3789.             PutEvent(Event);
  3790.             ClearEvent(Event);
  3791.           end;
  3792.         end;
  3793.       cmZoom:
  3794.         if (Flags and wfZoom <> 0) and
  3795.           ((Event.InfoPtr = nil) or (Event.InfoPtr = @Self)) then
  3796.         begin
  3797.           Zoom;
  3798.           ClearEvent(Event);
  3799.         end;
  3800.     end
  3801.   else if Event.What = evKeyDown then
  3802.     case Event.KeyCode of
  3803.       kbTab:
  3804.         begin
  3805.           FocusNext(False);
  3806.           ClearEvent(Event);
  3807.         end;
  3808.       kbShiftTab:
  3809.         begin
  3810.           FocusNext(True);
  3811.           ClearEvent(Event);
  3812.         end;
  3813.     end
  3814.   else if (Event.What = evBroadcast) and (Event.Command = cmSelectWindowNum)
  3815.          and (Event.InfoInt = Number) and (Options and ofSelectable <> 0) then
  3816.   begin
  3817.     Select;
  3818.     ClearEvent(Event);
  3819.   end;
  3820. end;
  3821.  
  3822. procedure TWindow.InitFrame;
  3823. var
  3824.   R: TRect;
  3825. begin
  3826.   GetExtent(R);
  3827.   Frame := New(PFrame, Init(R));
  3828. end;
  3829.  
  3830. procedure TWindow.SetState(AState: Word; Enable: Boolean);
  3831. var
  3832.   WindowCommands: TCommandSet;
  3833. begin
  3834.   TGroup.SetState(AState, Enable);
  3835.   if AState = sfSelected then
  3836.     SetState(sfActive, Enable);
  3837.   if (AState = sfSelected) or ((AState = sfExposed) and
  3838.     (State and sfSelected <> 0)) then
  3839.   begin
  3840.     WindowCommands := [cmNext, cmPrev];
  3841.     if Flags and (wfGrow + wfMove) <> 0 then
  3842.       WindowCommands := WindowCommands + [cmResize];
  3843.     if Flags and wfClose <> 0 then
  3844.       WindowCommands := WindowCommands + [cmClose];
  3845.     if Flags and wfZoom <> 0 then
  3846.       WindowCommands := WindowCommands + [cmZoom];
  3847.     if Enable then EnableCommands(WindowCommands)
  3848.     else DisableCommands(WindowCommands);
  3849.   end;
  3850. end;
  3851.  
  3852. function TWindow.StandardScrollBar(AOptions: Word): PScrollBar;
  3853. var
  3854.   R: TRect;
  3855.   S: PScrollBar;
  3856. begin
  3857.   GetExtent(R);
  3858.   if AOptions and sbVertical = 0 then
  3859.     R.Assign(R.A.X + 2, R.B.Y-1, R.B.X-2, R.B.Y) else
  3860.     R.Assign(R.B.X-1,R.A.Y+1,R.B.X,R.B.Y-1);
  3861.   S := New(PScrollBar, Init(R));
  3862.   Insert(S);
  3863.   if AOptions and sbHandleKeyboard <> 0 then
  3864.     S^.Options := S^.Options or ofPostProcess;
  3865.   StandardScrollBar := S;
  3866. end;
  3867.  
  3868. procedure TWindow.SizeLimits(var Min, Max: TPoint);
  3869. begin
  3870.   TView.SizeLimits(Min, Max);
  3871.   Min.X := MinWinSize.X;
  3872.   Min.Y := MinWinSize.Y;
  3873. end;
  3874.  
  3875. procedure TWindow.Store(var S: TStream);
  3876. begin
  3877.   TGroup.Store(S);
  3878.   S.Write(Flags, SizeOf(Byte) + SizeOf(TRect) + 2 * SizeOf(Integer));
  3879.   PutSubViewPtr(S, Frame);
  3880.   S.WriteStr(Title);
  3881. end;
  3882.  
  3883. procedure TWindow.Zoom;
  3884. var
  3885.   R: TRect;
  3886.   Max, Min: TPoint;
  3887. begin
  3888.   SizeLimits(Min, Max);
  3889.   if (Size.X <> Max.X) or (Size.Y <> Max.Y) then
  3890.   begin
  3891.     GetBounds(ZoomRect);
  3892.     R.A.X := 0;
  3893.     R.A.Y := 0;
  3894.     R.B := Max;
  3895.     Locate(R);
  3896.   end else Locate(ZoomRect);
  3897. end;
  3898.  
  3899. { Message dispatch function }
  3900.  
  3901. function Message(Receiver: PView; What, Command: Word;
  3902.   InfoPtr: Pointer): Pointer;
  3903. var
  3904.   Event: TEvent;
  3905. begin
  3906.   Message := nil;
  3907.   if Receiver <> nil then
  3908.   begin
  3909.     Event.What := What;
  3910.     Event.Command := Command;
  3911.     Event.InfoPtr := InfoPtr;
  3912.     Receiver^.HandleEvent(Event);
  3913.     if Event.What = evNothing then Message := Event.InfoPtr;
  3914.   end;
  3915. end;
  3916.  
  3917. { Views registration procedure }
  3918.  
  3919. procedure RegisterViews;
  3920. begin
  3921.   RegisterType(RView);
  3922.   RegisterType(RFrame);
  3923.   RegisterType(RScrollBar);
  3924.   RegisterType(RScroller);
  3925.   RegisterType(RListViewer);
  3926.   RegisterType(RGroup);
  3927.   RegisterType(RWindow);
  3928. end;
  3929.  
  3930. end.
  3931.