home *** CD-ROM | disk | FTP | other *** search
-
- {*******************************************************}
- { }
- { Delphi Visual Component Library }
- { }
- { Copyright (c) 1995,97 Borland International }
- { }
- {*******************************************************}
-
- unit ToolWin;
-
- {$R-}
-
- interface
-
- uses Windows, Messages, Classes, Controls, Forms;
-
- type
-
- { TToolWindow }
-
- TEdgeBorder = (ebLeft, ebTop, ebRight, ebBottom);
- TEdgeBorders = set of TEdgeBorder;
-
- TEdgeStyle = (esNone, esRaised, esLowered);
-
- TToolWindow = class(TWinControl)
- private
- FBorderWidth: Integer;
- FEdgeBorders: TEdgeBorders;
- FEdgeInner: TEdgeStyle;
- FEdgeOuter: TEdgeStyle;
- procedure SetBorderWidth(Value: Integer);
- procedure SetEdgeBorders(Value: TEdgeBorders);
- procedure SetEdgeInner(Value: TEdgeStyle);
- procedure SetEdgeOuter(Value: TEdgeStyle);
- procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
- procedure WMNCPaint(var Message: TMessage); message WM_NCPAINT;
- procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
- public
- constructor Create(AOwner: TComponent); override;
- property BorderWidth: Integer read FBorderWidth write SetBorderWidth default 0;
- property EdgeBorders: TEdgeBorders read FEdgeBorders write SetEdgeBorders default [ebLeft, ebTop, ebRight, ebBottom];
- property EdgeInner: TEdgeStyle read FEdgeInner write SetEdgeInner default esRaised;
- property EdgeOuter: TEdgeStyle read FEdgeOuter write SetEdgeOuter default esLowered;
- end;
-
- implementation
-
- { TToolWindow }
-
- constructor TToolWindow.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FEdgeBorders := [ebLeft, ebTop, ebRight, ebBottom];
- FEdgeInner := esRaised;
- FEdgeOuter := esLowered;
- end;
-
- procedure TToolWindow.SetBorderWidth(Value: Integer);
- begin
- if FBorderWidth <> Value then
- begin
- FBorderWidth := Value;
- RecreateWnd;
- end;
- end;
-
- procedure TToolWindow.SetEdgeBorders(Value: TEdgeBorders);
- begin
- if FEdgeBorders <> Value then
- begin
- FEdgeBorders := Value;
- RecreateWnd;
- end;
- end;
-
- procedure TToolWindow.SetEdgeInner(Value: TEdgeStyle);
- begin
- if FEdgeInner <> Value then
- begin
- FEdgeInner := Value;
- RecreateWnd;
- end;
- end;
-
- procedure TToolWindow.SetEdgeOuter(Value: TEdgeStyle);
- begin
- if FEdgeOuter <> Value then
- begin
- FEdgeOuter := Value;
- RecreateWnd;
- end;
- end;
-
- procedure TToolWindow.WMNCCalcSize(var Message: TWMNCCalcSize);
- var
- EdgeSize: Integer;
- begin
- with Message.CalcSize_Params^ do
- begin
- InflateRect(rgrc[0], -BorderWidth, -BorderWidth);
- EdgeSize := 0;
- if EdgeInner <> esNone then Inc(EdgeSize, 1);
- if EdgeOuter <> esNone then Inc(EdgeSize, 1);
- with rgrc[0] do
- begin
- if ebLeft in FEdgeBorders then Inc(Left, EdgeSize);
- if ebTop in FEdgeBorders then Inc(Top, EdgeSize);
- if ebRight in FEdgeBorders then Dec(Right, EdgeSize);
- if ebBottom in FEdgeBorders then Dec(Bottom, EdgeSize);
- end;
- end;
- inherited;
- end;
-
- procedure TToolWindow.WMNCPaint(var Message: TMessage);
- const
- InnerStyles: array[TEdgeStyle] of Integer = (0, BDR_RAISEDINNER, BDR_SUNKENINNER);
- OuterStyles: array[TEdgeStyle] of Integer = (0, BDR_RAISEDOUTER, BDR_SUNKENOUTER);
- Ctl3DStyles: array[Boolean] of Integer = (BF_MONO, 0);
- var
- DC: HDC;
- RC, RW: TRect;
- begin
- { Get window DC that is clipped to the non-client area }
- DC := GetWindowDC(Handle);
- try
- Windows.GetClientRect(Handle, RC);
- GetWindowRect(Handle, RW);
- MapWindowPoints(0, Handle, RW, 2);
- OffsetRect(RC, -RW.Left, -RW.Top);
- ExcludeClipRect(DC, RC.Left, RC.Top, RC.Right, RC.Bottom);
- { Draw borders in non-client area }
- OffsetRect(RW, -RW.Left, -RW.Top);
- DrawEdge(DC, RW, InnerStyles[FEdgeInner] or OuterStyles[FEdgeOuter],
- Byte(FEdgeBorders) or Ctl3DStyles[Ctl3D] or BF_ADJUST);
- { Erase parts not drawn }
- IntersectClipRect(DC, RW.Left, RW.Top, RW.Right, RW.Bottom);
- Windows.FillRect(DC, RW, Brush.Handle);
- finally
- ReleaseDC(Handle, DC);
- end;
- end;
-
- procedure TToolWindow.CMCtl3DChanged(var Message: TMessage);
- begin
- inherited;
- if FEdgeBorders <> [] then RecreateWnd;
- end;
-
- end.
-