VrBlotter.pas
上传用户:hbszzs
上传日期:2008-08-20
资源大小:628k
文件大小:12k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. {*****************************************************}
  2. {                                                     }
  3. {     Varian Component Workshop                       }
  4. {                                                     }
  5. {     Varian Software NL (c) 1996-2000                }
  6. {     All Rights Reserved                             }
  7. {                                                     }
  8. {*****************************************************}
  9. unit VrBlotter;
  10. {$I VRLIB.INC}
  11. interface
  12. uses
  13.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Dialogs,
  14.   VrClasses, VrControls, VrSysUtils;
  15. type
  16. {$IFDEF VER110}
  17.   TCustomVrBlotter = class(TVrCustomControl)
  18.   private
  19.     FAutoSizeDocking: Boolean;
  20.     FBevel: TVrBevel;
  21.     FFullRepaint: Boolean;
  22.     FLocked: Boolean;
  23.     FGlyph: TBitmap;
  24.     procedure SetGlyph(Value: TBitmap);
  25.     procedure BevelChanged(Sender: TObject);
  26.     procedure GlyphChanged(Sender: TObject);
  27.     procedure CMIsToolControl(var Message: TMessage); message CM_ISTOOLCONTROL;
  28.     procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED;
  29.     procedure CMDockClient(var Message: TCMDockClient); message CM_DOCKCLIENT;
  30.   protected
  31.     procedure CreateParams(var Params: TCreateParams); override;
  32.     function CanAutoSize(var NewWidth, NewHeight: Integer): Boolean; override;
  33.     procedure AdjustClientRect(var Rect: TRect); override;
  34.     procedure Paint; override;
  35.     property Bevel: TVrBevel read FBevel write FBevel;
  36.     property Color default clBlack;
  37.     property FullRepaint: Boolean read FFullRepaint write FFullRepaint default True;
  38.     property Locked: Boolean read FLocked write FLocked default False;
  39.     property ParentColor default False;
  40.     property Glyph: TBitmap read FGlyph write SetGlyph;
  41.   public
  42.     constructor Create(AOwner: TComponent); override;
  43.     destructor Destroy; override;
  44.   end;
  45.   TVrBlotter = class(TCustomVrBlotter)
  46.   public
  47.     property DockManager;
  48.   published
  49.     property Align;
  50.     property Anchors;
  51.     property AutoSize;
  52.     property Bevel;
  53.     property Glyph;
  54.     property Color;
  55.     property Constraints;
  56.     property Ctl3D;
  57.     property UseDockManager default True;
  58.     property DockSite;
  59.     property DragCursor;
  60.     property DragKind;
  61.     property DragMode;
  62.     property Enabled;
  63.     property FullRepaint;
  64.     property Locked;
  65.     property ParentColor;
  66.     property ParentCtl3D;
  67.     property ParentShowHint;
  68.     property PopupMenu;
  69.     property ShowHint;
  70.     property TabOrder;
  71.     property TabStop;
  72.     property Visible;
  73.     property OnCanResize;
  74.     property OnClick;
  75.     property OnConstrainedResize;
  76. {$IFDEF VER130}
  77.     property OnContextPopup;
  78. {$ENDIF}
  79.     property OnDockDrop;
  80.     property OnDockOver;
  81.     property OnDblClick;
  82.     property OnDragDrop;
  83.     property OnDragOver;
  84.     property OnEndDock;
  85.     property OnEndDrag;
  86.     property OnEnter;
  87.     property OnExit;
  88.     property OnGetSiteInfo;
  89.     property OnMouseDown;
  90.     property OnMouseMove;
  91.     property OnMouseUp;
  92.     property OnResize;
  93.     property OnStartDock;
  94.     property OnStartDrag;
  95.     property OnUnDock;
  96.   end;
  97. {$ELSE}
  98.   TCustomVrBlotter = class(TVrCustomControl)
  99.   private
  100.     FBevel: TVrBevel;
  101.     FFullRepaint: Boolean;
  102.     FLocked: Boolean;
  103.     FGlyph: TBitmap;
  104.     FOnResize: TNotifyEvent;
  105.     procedure SetGlyph(Value: TBitmap);
  106.     procedure GlyphChanged(Sender: TObject);
  107.     procedure BevelChanged(Sender: TObject);
  108.     procedure CMIsToolControl(var Message: TMessage); message CM_ISTOOLCONTROL;
  109.     procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED;
  110.   protected
  111.     procedure CreateParams(var Params: TCreateParams); override;
  112.     procedure AlignControls(AControl: TControl; var Rect: TRect); override;
  113.     procedure Paint; override;
  114.     procedure Resize; dynamic;
  115.     property Color default clBlack;
  116.     property FullRepaint: Boolean read FFullRepaint write FFullRepaint default True;
  117.     property Locked: Boolean read FLocked write FLocked default False;
  118.     property Bevel: TVrBevel read FBevel write FBevel;
  119.     property ParentColor default False;
  120.     property Glyph: TBitmap read FGlyph write SetGlyph;
  121.     property OnResize: TNotifyEvent read FOnResize write FOnResize;
  122.   public
  123.     constructor Create(AOwner: TComponent); override;
  124.     destructor Destroy; override;
  125.   end;
  126.   TVrBlotter = class(TCustomVrBlotter)
  127.   published
  128.     property Align;
  129.     property Bevel;
  130.     property Glyph;
  131.     property DragCursor;
  132.     property DragMode;
  133.     property Enabled;
  134.     property FullRepaint;
  135.     property Color;
  136.     property Font;
  137.     property Locked;
  138.     property ParentColor;
  139.     property ParentFont;
  140.     property ParentShowHint;
  141.     property PopupMenu;
  142.     property ShowHint;
  143.     property TabOrder;
  144.     property TabStop;
  145.     property Visible;
  146.     property OnClick;
  147.     property OnDblClick;
  148.     property OnDragDrop;
  149.     property OnDragOver;
  150.     property OnEndDrag;
  151.     property OnEnter;
  152.     property OnExit;
  153.     property OnMouseDown;
  154.     property OnMouseMove;
  155.     property OnMouseUp;
  156.     property OnResize;
  157.     property OnStartDrag;
  158.   end;
  159. {$ENDIF}
  160. implementation
  161. { TCustomVrBlotter }
  162. {$IFDEF VER110}
  163. constructor TCustomVrBlotter.Create(AOwner: TComponent);
  164. begin
  165.   inherited Create(AOwner);
  166.   ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
  167.     csOpaque, csDoubleClicks, csReplicatable] - [csSetCaption];
  168.   Width := 185;
  169.   Height := 75;
  170.   Color := clBlack;
  171.   UseDockManager := True;
  172.   FBevel := TVrBevel.Create;
  173.   with FBevel do
  174.   begin
  175.     InnerShadow := clGreen;
  176.     InnerHighlight := clLime;
  177.     InnerColor := clBlack;
  178.     OuterShadow := clGreen;
  179.     OuterHighlight := clLime;
  180.     OnChange := BevelChanged;
  181.   end;
  182.   FGlyph := TBitmap.Create;
  183.   FGlyph.OnChange := GlyphChanged;
  184.   FFullRepaint := True;
  185. end;
  186. destructor TCustomVrBlotter.Destroy;
  187. begin
  188.   FBevel.Free;
  189.   FGlyph.Free;
  190.   inherited Destroy;
  191. end;
  192. procedure TCustomVrBlotter.CreateParams(var Params: TCreateParams);
  193. begin
  194.   inherited CreateParams(Params);
  195.   with Params do
  196.     WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
  197. end;
  198. procedure TCustomVrBlotter.CMIsToolControl(var Message: TMessage);
  199. begin
  200.   if not FLocked then Message.Result := 1;
  201. end;
  202. procedure TCustomVrBlotter.SetGlyph(Value: TBitmap);
  203. begin
  204.   FGlyph.Assign(Value);
  205. end;
  206. procedure TCustomVrBlotter.GlyphChanged(Sender: TObject);
  207. begin
  208.   Invalidate;
  209. end;
  210. procedure TCustomVrBlotter.BevelChanged(Sender: TObject);
  211. begin
  212.   Realign;
  213.   Invalidate;
  214. end;
  215. procedure TCustomVrBlotter.WMWindowPosChanged(var Message: TWMWindowPosChanged);
  216. var
  217.   BevelPixels: Integer;
  218.   Rect: TRect;
  219. begin
  220.   if FullRepaint then
  221.     Invalidate
  222.   else
  223.   begin
  224.     BevelPixels := 0;
  225.     if Bevel.InnerOutline <> osNone then Inc(BevelPixels);
  226.     if Bevel.OuterOutline <> osNone then Inc(BevelPixels);
  227.     Inc(BevelPixels, Bevel.InnerSpace);
  228.     Inc(BevelPixels, Bevel.OuterSpace);
  229.     if Bevel.InnerStyle <> bsNone then Inc(BevelPixels, Bevel.InnerWidth);
  230.     if Bevel.OuterStyle <> bsNone then Inc(BevelPixels, Bevel.OuterWidth);
  231.     if BevelPixels > 0 then
  232.     begin
  233.       Rect.Right := Width;
  234.       Rect.Bottom := Height;
  235.       if Message.WindowPos^.cx <> Rect.Right then
  236.       begin
  237.         Rect.Top := 0;
  238.         Rect.Left := Rect.Right - BevelPixels - 1;
  239.         InvalidateRect(Handle, @Rect, True);
  240.       end;
  241.       if Message.WindowPos^.cy <> Rect.Bottom then
  242.       begin
  243.         Rect.Left := 0;
  244.         Rect.Top := Rect.Bottom - BevelPixels - 1;
  245.         InvalidateRect(Handle, @Rect, True);
  246.       end;
  247.     end;
  248.   end;
  249.   inherited;
  250.   if not Loading then Resize;
  251. end;
  252. procedure TCustomVrBlotter.AdjustClientRect(var Rect: TRect);
  253. begin
  254.   inherited AdjustClientRect(Rect);
  255.   Bevel.GetVisibleArea(Rect);
  256. end;
  257. procedure TCustomVrBlotter.Paint;
  258. var
  259.   Rect: TRect;
  260. begin
  261.   Rect := GetClientRect;
  262.   if FGlyph.Empty then
  263.   begin
  264.     with Canvas do
  265.     begin
  266.       Brush.Color := Color;
  267.       FillRect(Rect);
  268.     end;
  269.   end else DrawTiledBitmap(Canvas, Rect, FGlyph);
  270.   FBevel.Paint(Canvas, Rect);
  271. end;
  272. procedure TCustomVrBlotter.CMDockClient(var Message: TCMDockClient);
  273. var
  274.   R: TRect;
  275.   Dim: Integer;
  276. begin
  277.   if AutoSize then
  278.   begin
  279.     FAutoSizeDocking := True;
  280.     try
  281.       R := Message.DockSource.DockRect;
  282.       case Align of
  283.         alLeft: if Width = 0 then Width := R.Right - R.Left;
  284.         alRight: if Width = 0 then
  285.           begin
  286.             Dim := R.Right - R.Left;
  287.             SetBounds(Left - Dim, Top, Dim, Height);
  288.           end;
  289.         alTop: if Height = 0 then Height := R.Bottom - R.Top;
  290.         alBottom: if Height = 0 then
  291.           begin
  292.             Dim := R.Bottom - R.Top;
  293.             SetBounds(Left, Top - Dim, Width, Dim);
  294.           end;
  295.       end;
  296.       inherited;
  297.       Exit;
  298.     finally
  299.       FAutoSizeDocking := False;
  300.     end;
  301.   end;
  302.   inherited;
  303. end;
  304. function TCustomVrBlotter.CanAutoSize(var NewWidth, NewHeight: Integer): Boolean;
  305. begin
  306.   Result := (not FAutoSizeDocking) and inherited CanAutoSize(NewWidth, NewHeight);
  307. end;
  308. {$ELSE}
  309. constructor TCustomVrBlotter.Create(AOwner: TComponent);
  310. begin
  311.   inherited Create(AOwner);
  312.   ControlStyle := [csAcceptsControls, csCaptureMouse, csClickEvents,
  313.     csOpaque, csDoubleClicks, csReplicatable] - [csSetCaption];
  314.   Width := 185;
  315.   Height := 75;
  316.   Color := clBlack;
  317.   FBevel := TVrBevel.Create;
  318.   with FBevel do
  319.   begin
  320.     InnerShadow := clGreen;
  321.     InnerHighlight := clLime;
  322.     InnerColor := clBlack;
  323.     OuterShadow := clGreen;
  324.     OuterHighlight := clLime;
  325.     OnChange := BevelChanged;
  326.   end;
  327.   FGlyph := TBitmap.Create;
  328.   FGlyph.OnChange := GlyphChanged;
  329.   FFullRepaint := True;
  330. end;
  331. destructor TCustomVrBlotter.Destroy;
  332. begin
  333.   FBevel.Free;
  334.   FGlyph.Free;
  335.   inherited Destroy;
  336. end;
  337. procedure TCustomVrBlotter.CreateParams(var Params: TCreateParams);
  338. begin
  339.   inherited CreateParams(Params);
  340.   with Params do
  341.     WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
  342. end;
  343. procedure TCustomVrBlotter.CMIsToolControl(var Message: TMessage);
  344. begin
  345.   if not FLocked then Message.Result := 1;
  346. end;
  347. procedure TCustomVrBlotter.SetGlyph(Value: TBitmap);
  348. begin
  349.   FGlyph.Assign(Value);
  350. end;
  351. procedure TCustomVrBlotter.GlyphChanged(Sender: TObject);
  352. begin
  353.   Invalidate;
  354. end;
  355. procedure TCustomVrBlotter.BevelChanged(Sender: TObject);
  356. begin
  357.   Realign;
  358.   Invalidate;
  359. end;
  360. procedure TCustomVrBlotter.Resize;
  361. begin
  362.   if Assigned(FOnResize) then FOnResize(Self);
  363. end;
  364. procedure TCustomVrBlotter.WMWindowPosChanged(var Message: TWMWindowPosChanged);
  365. var
  366.   BevelPixels: Integer;
  367.   Rect: TRect;
  368. begin
  369.   if FullRepaint then
  370.     Invalidate
  371.   else
  372.   begin
  373.     BevelPixels := 0;
  374.     if Bevel.InnerOutline <> osNone then Inc(BevelPixels);
  375.     if Bevel.OuterOutline <> osNone then Inc(BevelPixels);
  376.     Inc(BevelPixels, Bevel.InnerSpace);
  377.     Inc(BevelPixels, Bevel.OuterSpace);
  378.     if Bevel.InnerStyle <> bsNone then Inc(BevelPixels, Bevel.InnerWidth);
  379.     if Bevel.OuterStyle <> bsNone then Inc(BevelPixels, Bevel.OuterWidth);
  380.     if BevelPixels > 0 then
  381.     begin
  382.       Rect.Right := Width;
  383.       Rect.Bottom := Height;
  384.       if Message.WindowPos^.cx <> Rect.Right then
  385.       begin
  386.         Rect.Top := 0;
  387.         Rect.Left := Rect.Right - BevelPixels - 1;
  388.         InvalidateRect(Handle, @Rect, True);
  389.       end;
  390.       if Message.WindowPos^.cy <> Rect.Bottom then
  391.       begin
  392.         Rect.Left := 0;
  393.         Rect.Top := Rect.Bottom - BevelPixels - 1;
  394.         InvalidateRect(Handle, @Rect, True);
  395.       end;
  396.     end;
  397.   end;
  398.   inherited;
  399.   if not Loading then Resize;
  400. end;
  401. procedure TCustomVrBlotter.AlignControls(AControl: TControl; var Rect: TRect);
  402. begin
  403.   FBevel.GetVisibleArea(Rect);
  404.   inherited AlignControls(AControl, Rect);
  405. end;
  406. procedure TCustomVrBlotter.Paint;
  407. var
  408.   Rect: TRect;
  409. begin
  410.   Rect := GetClientRect;
  411.   if FGlyph.Empty then
  412.   begin
  413.     with Canvas do
  414.     begin
  415.       Brush.Color := Color;
  416.       FillRect(Rect);
  417.     end;
  418.   end else DrawTiledBitmap(Canvas, Rect, FGlyph);
  419.   FBevel.Paint(Canvas, Rect);
  420. end;
  421. {$ENDIF}
  422. end.