home *** CD-ROM | disk | FTP | other *** search
/ Chip 2001 December / Chip_2001-12_cd1.bin / zkuste / delphi / kolekce / d345 / JWTOOL.ZIP / jwtool / JwRotPan.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2001-09-29  |  6.9 KB  |  244 lines

  1. unit JwRotPan;
  2.  
  3. //  Version History
  4. //     Num     Date        Notes
  5. //     1.00  ???????   Initial Release
  6.  
  7. //  Created By:
  8. //    Joseph Wilcock
  9. //    Coockoo@hotmail.com
  10. //    http://msnhomepages.talkcity.com/RedmondAve/coockoo/
  11.  
  12. interface
  13.  
  14. uses WinTypes, WinProcs, Messages, SysUtils, Classes, Controls,
  15.      Forms, Graphics, Stdctrls, Extctrls, JwRtFsh;
  16.  
  17. type
  18.   TJwRotatePanel = class(TPanel)
  19.     private
  20.       { Private fields of TJwRotatePanel }
  21.       FApiFont: TApiFontRec;
  22.       FOffsetLeft: LongInt;
  23.       FOffsetTop: LongInt;
  24.       FOffsetRight: LongInt;
  25.       FOffsetBottom: LongInt;
  26.  
  27.       { Private methods of TJwRotatePanel }
  28.     protected
  29.       { Protected fields of TJwRotatePanel }
  30.  
  31.       { Protected methods of TJwRotatePanel }
  32.       procedure Loaded; override;
  33.       procedure Paint; override;
  34.  
  35.     public
  36.       { Public fields and properties of TJwRotatePanel }
  37.  
  38.       { Public methods of TJwRotatePanel }
  39.       constructor Create(AOwner: TComponent); override;
  40.       destructor Destroy; override;
  41.  
  42.       Procedure OnChangeFont( Sender: TObject );
  43.       Procedure SetApiFont( Value: TApiFontRec );
  44.       Procedure SetLeftOffset( Value: LongInt );
  45.       Procedure SetTopOffset( Value: LongInt );
  46.       Procedure SetRightOffset( Value: LongInt );
  47.       Procedure SetBottomOffset( Value: LongInt );
  48.       procedure DoDrawText(var Rect: TRect; Flags: Word);
  49.     published
  50.       { Published properties of TJwRotatePanel }
  51.       property ApiFont: TApiFontRec Read FApiFont Write SetApiFont;
  52.       Property OffsetLeft: LongInt Read FOffsetLeft Write SetLeftOffset
  53.         Default 0;
  54.       Property OffsetTop: LongInt Read FOffsetTop Write SetTopOffset
  55.         Default 0;
  56.       Property OffsetRight: LongInt Read FOffsetRight Write SetRightOffset
  57.         Default 0;
  58.       Property OffsetBottom: LongInt Read FOffsetBottom Write SetBottomOffset
  59.         Default 0;
  60.       Property Anchors;
  61.       property OnClick;
  62.       property OnDblClick;
  63.       property OnDragDrop;
  64.       property OnEnter;
  65.       property OnExit;
  66.       property OnKeyDown;
  67.       property OnKeyPress;
  68.       property OnKeyUp;
  69.       property OnMouseDown;
  70.       property OnMouseMove;
  71.       property OnMouseUp;
  72.     end;
  73.  
  74. procedure Register;
  75.  
  76. implementation
  77.  
  78. procedure Register;
  79. begin
  80.   RegisterComponents('JwTools', [TJwRotatePanel]);
  81. end;
  82.  
  83. constructor TJwRotatePanel.Create(AOwner: TComponent);
  84. begin
  85.   inherited Create(AOwner);
  86.   FApiFont := TApiFontRec.Create;
  87.   FApiFont.OnChange := OnChangeFont;
  88.   FOffsetLeft := 0;
  89.   FOffsetTop := 0;
  90.   FOffsetRight := 0;
  91.   FOffsetBottom := 0;
  92. end;
  93.  
  94. destructor TJwRotatePanel.Destroy;
  95. begin
  96.   inherited Destroy;
  97. end;
  98.  
  99. Procedure TJwRotatePanel.SetApiFont( Value: TApiFontRec );
  100. begin
  101.   FApiFont.Assign( Value );
  102.   FApiFont.OnChange := OnChangeFont;
  103.   Invalidate;
  104. end;
  105.  
  106. procedure TJwRotatePanel.Loaded;
  107. begin
  108.   inherited Loaded;
  109. end;
  110.  
  111. procedure TJwRotatePanel.Paint;
  112. var
  113.   Rect: TRect;
  114.   TopColor, BottomColor: TColor;
  115.   Text: array[0..255] of Char;
  116.   FontHeight: Integer;
  117. const
  118.   Alignments: array[TAlignment] of Word = (DT_LEFT, DT_RIGHT, DT_CENTER);
  119.  
  120.   procedure AdjustColors(Bevel: TPanelBevel);
  121.   begin
  122.     TopColor := clBtnHighlight;
  123.     if Bevel = bvLowered then TopColor := clBtnShadow;
  124.     BottomColor := clBtnShadow;
  125.     if Bevel = bvLowered then BottomColor := clBtnHighlight;
  126.   end;
  127.  
  128. begin
  129.   Rect := GetClientRect;
  130.   if BevelOuter <> bvNone then
  131.   begin
  132.     AdjustColors(BevelOuter);
  133.     Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);
  134.   end;
  135.   Frame3D(Canvas, Rect, Color, Color, BorderWidth);
  136.   if BevelInner <> bvNone then
  137.   begin
  138.     AdjustColors(BevelInner);
  139.     Frame3D(Canvas, Rect, TopColor, BottomColor, BevelWidth);
  140.   end;
  141.   with Canvas do
  142.   begin
  143.     Brush.Color := Color;
  144.     FillRect(Rect);
  145.     Brush.Style := bsClear;
  146.     Font := Self.Font;
  147.     FontHeight := TextHeight('W');
  148.  
  149.     Rect := ClientRect;
  150.     Rect.Left := Rect.Left + FOffsetLeft;
  151.     Rect.Top := Rect.Top + FOffsetTop;
  152.     Rect.Right := Rect.Right - FOffsetRight;
  153.     Rect.Bottom := Rect.Bottom - FOffsetBottom;
  154.     {StrPCopy(Text, Caption);
  155.     DoDrawText(Handle, Text, StrLen(Text), Rect, (DT_EXPANDTABS or
  156.       DT_VCENTER) or Alignments[Alignment]);}
  157.     DoDrawText( Rect, (DT_EXPANDTABS or DT_VCENTER) or Alignments[Alignment] );
  158.   end;
  159. end;
  160.  
  161. procedure TJwRotatePanel.DoDrawText(var Rect: TRect; Flags: Word);
  162. var
  163.   Text: array[0..255] of Char;
  164.   TmpStr: array[0..255] of Char;
  165. begin
  166.   GetTextBuf(Text, SizeOf(Text));
  167.   if (Flags and DT_CALCRECT <> 0) and ((Text[0] = #0) and
  168.     (Text[0] = '&') and (Text[1] = #0)) then StrCopy(Text, ' ');
  169.   Flags := Flags or DT_NOPREFIX;
  170.  
  171.   {Right here is where we break ranks with the old code.  We want to change the font
  172.   to have the properties that WE set.  We'll do this in a case statement so that
  173.   changes to the API Wont ruin our code.}
  174.  
  175.   with FApiFont do begin
  176.       if Escapement > 0 then
  177.         Flags := DT_NOCLIP;
  178.       StrPCopy( TmpStr, FaceName );
  179.       Canvas.Font.Color := OverFontColor;
  180.       Canvas.Font.Handle := CreateFont(   FontHeight,  {Height}
  181.                                            FontWidth,  {Width}
  182.                                           Escapement,  {Escapement}
  183.                                          Orientation,  {Orientation}
  184.                                 ApiFontWeight,          {Weight}
  185.                                               Italic,  {Italic}
  186.                                            Underline,  {Underline}
  187.                                            StrikeOut,  {StrikeOut}
  188.                                 ApiFontCharSet,         {CharSet}
  189.                                 ApiFontOutPrecision,    {OutputPrecision}
  190.                                 ApiFontClipPrecision,   {ClipPrecision}
  191.                                 ApiFontQuality,         {Quality}
  192.                                 ApiFontPitchAndFamily,  {PitchAndFamily}
  193.                                                TmpStr );{FaceName}
  194.   end; {end of with TmpFont}
  195.  
  196.  
  197.   {Canvas.Font := Font;}
  198.   if not Enabled then Canvas.Font.Color := clGrayText;
  199.   DrawText(Canvas.Handle, Text, StrLen(Text), Rect, Flags);
  200. end;
  201.  
  202. Procedure TJwRotatePanel.OnChangeFont( Sender: TObject );
  203. begin
  204.   InValidate;
  205. end;
  206.  
  207. Procedure TJwRotatePanel.SetLeftOffset( Value: LongInt );
  208. begin
  209.   if FOffsetLeft <> Value then
  210.     begin
  211.       FOffsetLeft := Value;
  212.       InValidate;
  213.     end;
  214. end;
  215.  
  216. Procedure TJwRotatePanel.SetTopOffset( Value: LongInt );
  217. begin
  218.   if FOffsetTop <> Value then
  219.     begin
  220.       FOffsetTop := Value;
  221.       InValidate;
  222.     end;
  223. end;
  224.  
  225. Procedure TJwRotatePanel.SetRightOffset( Value: LongInt );
  226. begin
  227.   if FOffsetRight <> Value then
  228.     begin
  229.       FOffsetRight := Value;
  230.       InValidate;
  231.     end;
  232. end;
  233.  
  234. Procedure TJwRotatePanel.SetBottomOffset( Value: LongInt );
  235. begin
  236.   if FOffsetBottom <> Value then
  237.     begin
  238.       FOffsetBottom := Value;
  239.       InValidate;
  240.     end;
  241. end;
  242.  
  243. end.
  244.