Title: EasyToolBar
Question: This article contains the unit EasyToolBar. This toolbar simulates the Office 2003 toolbars.
NOTE!
You need the other posts to be able to compile this components.
You must disable the Compiled Resources (*.dcr) to compile this components. I'll send the dcr's to the admins and tell them to attach them.
Answer:
Unit EasyToolBar;
Interface
Uses Classes, Controls, Graphics, Windows, Messages, Forms, EasyToolBarButtons, Menus;
Type
TEasyToolBar = Class(TCustomControl)
Private
{ Private declarations }
fOwner : TComponent;
fParent : TWinControl;
fImages : TImageList;
fDirection : TTileMode;
fPopupMenu : TPopupMenu;
Procedure SetImages(NewImages: TImageList);
Procedure SetDirection(NewDirection: TTileMode);
Procedure SetPopupMenu(NewPopupMenu: TPopupMenu);
Procedure DrawBackground;
Procedure DrawMoveGrip;
Procedure DrawDropDownMenu;
Protected
{ Protected declarations }
Procedure WMEraseBkGnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
Public
{ Public declarations }
Constructor Create(AOwner: TComponent); override;
Destructor Destroy; override;
Procedure AdjustClientRect(var Rect: TRect); override;
Procedure Resize; override;
Procedure Paint; override;
Published
{ Published declarations }
Property Align;
Property Color;
Property ParentColor;
// Property DockSite;
Property DragCursor;
Property DragKind;
Property DragMode;
Property Enabled;
Property TabStop;
Property TabOrder;
Property Direction: TTileMode read fDirection write SetDirection;
Property Images: TImageList read fImages write SetImages;
Property PopupMenu: TPopupMenu read fPopupMenu write SetPopupMenu;
End;
Procedure Register;
Implementation
Uses EasyGraphicsFunctions;
{$R *.dcr}
Procedure Register;
Begin
RegisterComponents('EasyWare - Visual', [TEasyToolBar]);
End;
Constructor TEasyToolBar.Create(AOwner: TComponent);
Begin
Inherited Create(AOwner);
ControlStyle := [csOpaque, csAcceptsControls, csCaptureMouse, csClickEvents, csDoubleClicks];
fOwner := AOwner;
fParent := NIL;
fImages := NIL;
fDirection := tbHorizontal;
fPopupMenu := NIL;
Width := 150;
Height := 25;
Align := alTop;
ParentColor := True;
DoubleBuffered := True;
End;
Destructor TEasyToolBar.Destroy;
Begin
Inherited Destroy;
End;
Procedure TEasyToolBar.DrawBackground;
Begin
IF (fDirection = tbVertical) Then
Begin
DrawFadedBar(
Canvas,
Rect(0, 0, ClientWidth, ClientHeight),
(fDirection = tbVertical),
RGB(221, 236, 254),
RGB(129, 169, 226)
);
End
Else
Begin
DrawFadedBarEx(
Canvas,
Rect(0, 0, ClientWidth, ClientHeight),
(fDirection = tbVertical),
RGB(221, 236, 254),
RGB(129, 169, 226)
);
{
// Bottom
DrawFadedBar(
Canvas,
Rect(0, ClientHeight-5, ClientWidth, ClientHeight-2),
(fDirection = tbVertical),
RGB(149, 184, 233),
RGB(129, 169, 226)
);
// Middle
DrawFadedBar(
Canvas,
Rect(0, 5, ClientWidth, ClientHeight-6),
(fDirection = tbVertical),
RGB(213, 231, 253),
RGB(156, 189, 235)
);
// Top
DrawFadedBar(
Canvas,
Rect(0, 0, ClientWidth, 4),
(fDirection = tbVertical),
RGB(221, 236, 254),
RGB(215, 232, 253)
);
}
End;
Canvas.Pen.Color := RGB(59, 97, 156);
IF (fDirection = tbVertical) Then
Begin
Canvas.MoveTo(ClientWidth-1, 0);
Canvas.LineTo(ClientWidth-1, ClientHeight);
End
Else
Begin
Canvas.MoveTo(0, ClientHeight-1);
Canvas.LineTo(ClientWidth, ClientHeight-1);
End;
End;
Procedure TEasyToolBar.DrawMoveGrip;
Procedure DrawDot(X, Y: Integer);
Begin
Canvas.Brush.Color := clWhite;
Canvas.FillRect( Rect(X+1, Y+1, X+3, Y+3) );
Canvas.Brush.Color := RGB(39, 65, 118);
Canvas.FillRect( Rect(X, Y, X+2, Y+2) );
End;
Var
X, Y : Integer;
Begin
IF (fDirection = tbVertical) Then
Begin
X := 3;
While (X Begin
DrawDot(X, 3);
Inc(X, 4);
End;
Canvas.Pixels[ClientWidth-1, 0] := Color;
Canvas.Pixels[ClientWidth-2, 0] := RGB(189, 213, 250);
Canvas.Pixels[ClientWidth-1, 1] := RGB(189, 213, 250);
Canvas.Pixels[0, 0] := Color;
Canvas.Pixels[0, 1] := Color;
Canvas.Pixels[1, 1] := Color;
End
Else
Begin
Y := 3;
While (Y Begin
DrawDot(3, Y);
Inc(Y, 4);
End;
Canvas.Pixels[0, 0] := Color;
Canvas.Pixels[1, 0] := RGB(189, 213, 250);
Canvas.Pixels[0, 1] := RGB(189, 213, 250);
Canvas.Pixels[0, ClientHeight-1] := Color;
Canvas.Pixels[0, ClientHeight-2] := Color;
Canvas.Pixels[1, ClientHeight-1] := Color;
End;
End;
Procedure TEasyToolBar.DrawDropDownMenu;
Var
StartColor : TColor;
EndColor : TColor;
R, G, B : Real;
Step_R : Real;
Step_G : Real;
Step_B : Real;
Len : Integer;
X, Y : Integer;
PolyArray : Array[1..10] of TPoint;
Begin
IF (Assigned(fPopupMenu)) Then
Begin
Canvas.Brush.Color := Color;
IF (fDirection = tbVertical) Then
Begin
Canvas.FillRect( Rect(0, ClientHeight-5, ClientWidth, ClientHeight) );
End
Else
Begin
Canvas.FillRect( Rect(ClientWidth-5, 0, ClientWidth, ClientHeight) );
End;
IF (fDirection = tbVertical) Then Len := ClientWidth-1
Else Len := ClientHeight-1;
IF (Len
StartColor := RGB(117, 166, 241);
EndColor := RGB(0, 53, 145);
Step_R := (GetRValue(EndColor) - GetRValue(StartColor)) / Len;
Step_G := (GetGValue(EndColor) - GetGValue(StartColor)) / Len;
Step_B := (GetBValue(EndColor) - GetBValue(StartColor)) / Len;
R := GetRValue(StartColor);
G := GetGValue(StartColor);
B := GetBValue(StartColor);
X := 0;
Y := 0;
While (Len = 0) do
Begin
Canvas.Pen.Color := RGB(Round(R), Round(G), Round(B));
IF (fDirection = tbVertical) Then
Begin
Y := ClientHeight-14;
IF (X Else IF (X
Canvas.MoveTo(X, Y);
Canvas.LineTo(X, Y+11);
End
Else
Begin
X := ClientWidth-14;
IF (Y Else IF (Y
Canvas.MoveTo(X, Y);
Canvas.LineTo(X+11, Y);
End;
Inc(X);
Inc(Y);
R := R + Step_R;
G := G + Step_G;
B := B + Step_B;
Dec(Len);
End;
End
Else
IF (Align alClient) Then
Begin
Canvas.Pen.Style := psClear;
Canvas.Brush.Color := Color;
IF (fDirection = tbHorizontal) Then
Begin
PolyArray[1].x := ClientWidth-2;
PolyArray[1].y := 0;
PolyArray[2].x := ClientWidth-1;
PolyArray[2].y := 1;
PolyArray[3].x := ClientWidth;
PolyArray[3].y := 2;
PolyArray[4].x := ClientWidth;
PolyArray[4].y := ClientHeight-3;
PolyArray[5].x := ClientWidth-1;
PolyArray[5].y := ClientHeight-2;
PolyArray[6].x := ClientWidth-2;
PolyArray[6].y := ClientHeight-1;
PolyArray[7].x := ClientWidth-2;
PolyArray[7].y := ClientHeight;
PolyArray[8].x := ClientWidth;
PolyArray[8].y := ClientHeight;
PolyArray[9].x := ClientWidth;
PolyArray[9].y := 0;
PolyArray[10].x := ClientWidth-2;
PolyArray[10].y := 0;
Canvas.Polygon( PolyArray );
End
Else
Begin
End;
Canvas.Pen.Style := psSolid;
End;
End;
Procedure TEasyToolBar.Paint;
Begin
Inherited Paint;
DrawBackground;
DrawMoveGrip;
DrawDropDownMenu;
End;
Procedure TEasyToolBar.SetImages(NewImages: TImageList);
Begin
fImages := NewImages;
Invalidate;
End;
Procedure TEasyToolBar.SetDirection(NewDirection: TTileMode);
Begin
IF (fDirection NewDirection) Then
Begin
fDirection := NewDirection;
Invalidate;
End;
End;
Procedure TEasyToolBar.SetPopupMenu(NewPopupMenu: TPopupMenu);
Begin
IF (fPopupMenu NewPopupMenu) Then
Begin
fPopupMenu := NewPopupMenu;
Invalidate;
End;
End;
Procedure TEasyToolBar.AdjustClientRect(var Rect: TRect);
Begin
Inherited AdjustClientRect(Rect);
IF (fDirection = tbVertical) Then
Begin
Rect.Left := 1;
Rect.Top := 8;
Rect.Right := ClientWidth-2;
Rect.Bottom := ClientHeight-14;//-2;
End
Else
Begin
Rect.Left := 8;
Rect.Top := 1;
Rect.Right := ClientWidth-14;//-2;
Rect.Bottom := ClientHeight-2;
End;
End;
Procedure TEasyToolBar.WMEraseBkGnd(var Message: TWMEraseBkgnd);
Begin
// Prevent erasing of the background...
Message.Result := 1;
End;
Procedure TEasyToolBar.Resize;
Begin
End;
End.