home *** CD-ROM | disk | FTP | other *** search
/ Aztec Shareware Collection / AZ_096.ISO / yahwho / gpframe.pas < prev    next >
Pascal/Delphi Source File  |  1993-06-16  |  3KB  |  96 lines

  1. Unit GpFrame;
  2.  
  3. {
  4. This unit provides a basic frame for TGroups or decendents which have
  5. been inserted into a TWindow. Note that you cannot use a TFrame for this
  6. purpose, because a TFrame demands to be inserted directly into a
  7. TWindow.
  8.  
  9. The frame is drawn in double-line characters in the TWindow palette
  10. Active Frame color whenever the owning group gets the focus, or in
  11. single-line characters using the Passive Frame color when the owning
  12. group loses focus.
  13.  
  14. Note that the owning TGroup is assumed to have a "pass-thru" (nil)
  15. GetPalette function, so that the frame is drawn using the TWindow
  16. indexes. This will be true by default.
  17.  
  18. The frame dynamically resizes itself to the owning group's size.
  19.  
  20. Streaming Note:
  21.  
  22. No stream registration record is provided in this unit.  Most
  23. programmers prefer to assign their own IDs anyway. If you plan to
  24. stream this object, simply provide an appropriate record and call
  25. RegisterType. No override of Store and Load is necessary, since this
  26. object declares no fields.
  27.  
  28. }
  29.  
  30. interface
  31. uses Views,Drivers,Objects;
  32.  
  33. type
  34.   PGroupFrame = ^TGroupFrame;
  35.   TGroupFrame = object(TView)
  36.     constructor Init(var Bounds : TRect);
  37.     procedure Draw; virtual;
  38.     procedure HandleEvent(var Event: TEvent); virtual;
  39.   end;
  40.  
  41. implementation
  42.  
  43. constructor TGroupFrame.Init;
  44. begin
  45.   Inherited Init(Bounds);
  46.   EventMask := EventMask or evBroadcast;
  47. end;
  48.  
  49. procedure TGroupFrame.HandleEvent(var Event: TEvent);
  50. begin
  51.   Inherited HandleEvent(Event);
  52.   with Event do
  53.   if (What = evBroadcast) and (InfoPtr = Owner) then
  54.   case Event.Command of
  55.     cmReleasedFocus, cmReceivedFocus : DrawView;
  56.   end;
  57. end;
  58.  
  59. procedure TGroupFrame.Draw;
  60. const
  61.   T1 = '─';
  62.   S1 = '│';
  63.   T2 = '═';
  64.   S2 = '║';
  65. var
  66.   B : TDrawBuffer;
  67.   N : string;
  68. begin
  69.   Size := Owner^.Size;
  70.   with Size do if (X<2) or (Y<2) then exit;
  71.   FillChar(N[1],Size.X-2,' '); N[0]:=Chr(Size.X-2);
  72.   if Owner^.GetState(sfFocused) then
  73.   begin
  74.     WriteChar(0,0,'╔',2,1);
  75.     WriteChar(1,0,T2,2,Size.X-2);
  76.     WriteChar(Size.X-1,0,'╗',2,1);
  77.     MoveStr(B, S2+N+S2, GetColor(2));
  78.     WriteLine(0, 1, Size.X, Size.Y-2, B);
  79.     WriteChar(0,Size.Y-1,'╚',2,1);
  80.     WriteChar(1,Size.Y-1,T2,2,Size.X-2);
  81.     WriteChar(Size.X-1,Size.Y-1,'╝',2,1);
  82.   end else
  83.   begin
  84.     WriteChar(0,0,'┌',1,1);
  85.     WriteChar(1,0,T1,1,Size.X-2);
  86.     WriteChar(Size.X-1,0,'┐',1,1);
  87.     MoveStr(B, S1+N+S1, GetColor(1));
  88.     WriteLine(0, 1, Size.X, Size.Y-2, B);
  89.     WriteChar(0,Size.Y-1,'└',1,1);
  90.     WriteChar(1,Size.Y-1,T1,1,Size.X-2);
  91.     WriteChar(Size.X-1,Size.Y-1,'┘',1,1);
  92.   end;
  93. end;
  94.  
  95. end.
  96.