Title: EasySymantecMenu
Question: This article contains the unit EasySymantecMenu. This is a look-alike to the PcAnywhere 11 leftside menu.
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 EasySymantecMenu;
Interface
Uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCtrls, EasyToolBarButtons;
Type
TIntButtonType = Array[0..17, 0..17] of Byte;
TEasySymantecMenu = Class;
TEasySymantecMenuNavigationBar = Class;
TEasySymantecMenuNavigationOption = Class(TCustomControl)
Private
{ Private declarations }
fImages : TImageList;
fImageIndex : Integer;
GotMouse : Boolean;
Selected : Boolean;
Function GetParentBar: TEasySymantecMenuNavigationBar;
Procedure SetImages(NewImages: TImageList);
Procedure SetImageIndex(NewIndex: Integer);
Protected
{ Protected declarations }
// Procedure Notification(AComponent: TComponent; Operation: TOperation); override;
// Procedure Resize; override;
Procedure CMEnabledChanged(var msg: TMessage); message CM_ENABLEDCHANGED;
Procedure CMShowHintChanged(var msg: TMessage); message CM_SHOWHINTCHANGED;
Procedure CMTextChanged(var msg: TMessage); message CM_TEXTCHANGED;
Procedure CMMouseEnter(var msg: TMessage); message CM_MOUSEENTER;
Procedure CMMouseLeave(var msg: TMessage); message CM_MOUSELEAVE;
Public
{ Public declarations }
Constructor Create(AOwner: TComponent); override;
Destructor Destroy; override;
Procedure Click; override;
Procedure Paint; override;
Property ParentBar: TEasySymantecMenuNavigationBar read GetParentBar;
Published
{ Published declarations }
Property ImageIndex: Integer read fImageIndex write SetImageIndex;
Property Enabled;
Property ShowHint;
Property OnClick;
Property Align;
Property Caption;
Property Images: TImageList read fImages write SetImages;
End;
TEasySymantecMenuNavigationBar = Class(TCustomControl)
Private
{ Private declarations }
fImages : TImageList;
OldHeight : Integer;
GotMouse : Boolean;
fMaximized : Boolean;
fAutoSize : Boolean;
Procedure UpdateOptions;
Procedure DrawFadedHeader(DstCanvas: TCanvas);
Procedure AutoSizeClients;
Procedure SetImages(NewImages: TImageList);
Procedure SetMaximized(NewValue: Boolean);
Protected
{ Protected declarations }
Procedure Notification(AComponent: TComponent; Operation: TOperation); override;
Procedure Resize; override;
Procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
Procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
Procedure CMTextChanged(var msg: TMessage); message CM_TEXTCHANGED;
Procedure CMMouseEnter(var msg: TMessage); message CM_MOUSEENTER;
Procedure CMMouseLeave(var msg: TMessage); message CM_MOUSELEAVE;
Procedure WMEraseBkGnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
Procedure SetAutoSize(NewAutoSize: Boolean); {$IFDEF VER140} override; {$ENDIF}
Public
{ Public declarations }
Constructor Create(AOwner: TComponent); override;
Destructor Destroy; override;
Procedure AdjustClientRect(var Rect: TRect); override;
Procedure Paint; override;
Published
{ Published declarations }
// Property Images: TImageList read fImages write SetImages;
Property Enabled;
Property Maximized: Boolean read fMaximized write SetMaximized;
Property Align;
Property AutoSize: Boolean read fAutoSize write SetAutoSize;
Property Caption;
Property Color;
Property Images: TImageList read fImages write SetImages;
End;
TEasySymantecMenu = Class(TCustomControl)
Private
{ Private declarations }
OldWidth : Integer;
ButtonsRect : TRect;
fImages : TImageList;
fMaximized : Boolean;
fOnMenuResize : TNotifyEvent;
fVerticalMenuColor : TColor;
Function GetVerticalMenuWidth: Integer;
Procedure SetImages(NewImages: TImageList);
Procedure SetVerticalMenuColor(NewColor: TColor);
Procedure SetMaximized(NewValue: Boolean);
Protected
{ Protected declarations }
Procedure Notification(AComponent: TComponent; Operation: TOperation); override;
Procedure Resize; override;
Function GetVerticalBarRect: TRect;
Function GetVerticalMenuRect: TRect;
Procedure DrawVerticalMenu(DstCanvas: TCanvas);
Procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
Procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
Procedure WMEraseBkGnd(var Message: TWMEraseBkgnd);
Function AddButton: TEasyToolBarButton;
Public
{ Public declarations }
Constructor Create(AOwner: TComponent); override;
Destructor Destroy; override;
Procedure AdjustClientRect(var Rect: TRect); override;
Procedure RepositionButtons;
Procedure Paint; override;
Published
{ Published declarations }
Property Images: TImageList read fImages write SetImages;
Property VerticalMenuColor: TColor read fVerticalMenuColor write SetVerticalMenuColor;
Property Maximized: Boolean read fMaximized write SetMaximized;
Property Align;
Property OnMenuResize: TNotifyEvent read fOnMenuResize write fOnMenuResize;
End;
Procedure Register;
Implementation
Uses EasyGraphicsFunctions;
{$R *.dcr}
Const
mncDarkBlue = TColor($6A240A);
mncBorder = TColor($F0E9E6);
mncButtonBar = TColor($E8DEDA);
mncSelectedOption = TColor($A57B6B);
Const
MinButtonSize = 24;
VerticalMinimizeButton : TIntButtonType = (
(0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0),
(0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0),
(1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
(1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
(1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
(1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
(1,1,0,0,0,1,1,1,0,0,1,1,1,0,1,1,0,0),
(1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,0,0),
(1,1,0,1,1,1,0,0,1,1,1,0,0,0,1,1,0,0),
(1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1,0,0),
(1,1,0,0,0,1,1,1,0,0,1,1,1,0,1,1,0,0),
(1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
(1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
(1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
(1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0),
(0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,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5),
(0,0,5,2,2,2,2,2,2,2,2,2,2,2,5,5,5,0),
(0,0,0,5,2,2,2,2,2,2,2,2,2,5,5,5,0,0),
(0,0,0,0,5,5,5,5,5,5,5,5,5,5,5,0,0,0),
(0,0,0,0,0,5,5,5,5,5,5,5,5,5,0,0,0,0)
);
Procedure Register;
Begin
RegisterComponents('EasyWare - Visual', [TEasySymantecMenu, TEasySymantecMenuNavigationBar, TEasySymantecMenuNavigationOption]);
End;
Procedure DrawIntButton(Canvas: TCanvas; ix, iy: Integer; Button: TIntButtonType);
Var
X, Y : Integer;
Begin
For Y := 0 to 17 do
Begin
For X := 0 to 17 do
Begin
Case Button[Y, X] of
1 : Canvas.Pixels[ix+X, iy+Y] := RGB(193, 200, 217); // Light blue
2 : Canvas.Pixels[ix+X, iy+Y] := RGB(107, 123, 165); // Medium blue
3 : Canvas.Pixels[ix+X, iy+Y] := mncBorder; // Super-Light blue
4 : Canvas.Pixels[ix+X, iy+Y] := RGB(7, 25, 74); // Super-Dark blue
5 : Canvas.Pixels[ix+X, iy+Y] := RGB(112, 119, 137); // Dark gray
End;
End;
End;
End;
(******************************************************************************)
(******************************************************************************)
(******************************************************************************)
Constructor TEasySymantecMenuNavigationOption.Create(AOwner: TComponent);
Begin
Inherited;
ControlStyle := ControlStyle + [csOpaque, csSetCaption];
DoubleBuffered := True;
fImages := NIL;
fImageIndex := 0;
GotMouse := False;
Selected := False;
Height := 18;
Align := alTop;
End;
Destructor TEasySymantecMenuNavigationOption.Destroy;
Begin
Inherited;
End;
Function TEasySymantecMenuNavigationOption.GetParentBar: TEasySymantecMenuNavigationBar;
Begin
Result := NIL;
IF (Parent is TEasySymantecMenuNavigationBar) Then Result := (Parent as TEasySymantecMenuNavigationBar);
End;
Procedure TEasySymantecMenuNavigationOption.SetImageIndex(NewIndex: Integer);
Begin
IF (NewIndex fImageIndex) Then
Begin
fImageIndex := NewIndex;
Invalidate;
End;
End;
Procedure TEasySymantecMenuNavigationOption.CMMouseEnter(var msg: TMessage);
Begin
Inherited;
GotMouse := True;
IF (Enabled) Then Repaint;
End;
Procedure TEasySymantecMenuNavigationOption.CMMouseLeave(var msg: TMessage);
Begin
Inherited;
GotMouse := False;
IF (Enabled) Then Repaint;
End;
Procedure TEasySymantecMenuNavigationOption.Click;
Begin
Selected := True;
Paint;
Inherited;
Selected := False;
Paint;
End;
Procedure TEasySymantecMenuNavigationOption.SetImages(NewImages: TImageList);
Begin
fImages := NewImages;
Invalidate;
End;
Procedure TEasySymantecMenuNavigationOption.CMEnabledChanged(var msg: TMessage);
Begin
Inherited;
Invalidate;
End;
Procedure TEasySymantecMenuNavigationOption.CMShowHintChanged(var msg: TMessage);
Begin
Inherited;
Invalidate;
End;
Procedure TEasySymantecMenuNavigationOption.CMTextChanged(var msg: TMessage);
Begin
Inherited;
Invalidate;
End;
Procedure TEasySymantecMenuNavigationOption.Paint;
Var
X, Y : Integer;
Bmp : TBitmap;
ImgList : TImageList;
Begin
Canvas.Brush.Style := bsSolid;
IF (Selected) Then Canvas.Brush.Color := mncSelectedOption
Else Canvas.Brush.Color := mncButtonBar;
Canvas.FillRect(ClientRect);
Canvas.Brush.Style := bsClear;
Canvas.Font.Name := 'MS Sans Serif';
Canvas.Font.Size := 8;
Canvas.Font.Color := clBlack;
IF (GotMouse) and (Enabled) Then Canvas.Font.Color := RGB(132, 117, 127);
IF (Selected) Then Canvas.Font.Color := clWhite;
X := 4;
ImgList := NIL;
IF (Assigned(ParentBar)) Then ImgList := ParentBar.Images;
IF (not Assigned(ImgList)) Then ImgList := Images;
IF (Assigned(ImgList)) Then
Begin
Bmp := GetBitmap(ImgList, fImageIndex, Enabled, False{GotMouse});
Y := (Height div 2) - (ImgList.Height div 2);
Canvas.Draw(X, Y, Bmp);
Inc(X, ImgList.Width+5);
Bmp.Free;
End;
Y := (Height div 2) - (Canvas.TextHeight(Caption) div 2);
Canvas.TextOut(X, Y, Caption);
End;
(******************************************************************************)
(******************************************************************************)
(******************************************************************************)
Constructor TEasySymantecMenuNavigationBar.Create(AOwner: TComponent);
Begin
Inherited;
ControlStyle := ControlStyle + [csOpaque, csAcceptsControls, csSetCaption];
DoubleBuffered := True;
GotMouse := False;
fMaximized := True;
OldHeight := 0;
Height := 100;
Align := alTop;
fAutoSize := False;
Color := mncButtonBar;
End;
Destructor TEasySymantecMenuNavigationBar.Destroy;
Begin
Inherited;
End;
Procedure TEasySymantecMenuNavigationBar.AdjustClientRect(var Rect: TRect);
Begin
Inherited AdjustClientRect(Rect);
IF (fMaximized) Then
Begin
Rect.Left := 1;
Rect.Top := 23;
Rect.Right := ClientWidth-1;
Rect.Bottom := ClientHeight-1;
End
Else Rect := Classes.Rect(0,0,0,0);
End;
Procedure TEasySymantecMenuNavigationBar.SetMaximized(NewValue: Boolean);
Var
Y : Integer;
Begin
IF (NewValue fMaximized) Then
Begin
fMaximized := NewValue;
AutoSize := False;
IF (fMaximized) Then
Begin
Y := Height;
While (Y Begin
Inc(Y, 2);
IF (Y OldHeight) Then Y := OldHeight;
Height := Y;
End;
// Height := OldHeight;
End
Else
Begin
OldHeight := Height;
Height := 24;
End;
Invalidate;
End;
End;
Procedure TEasySymantecMenuNavigationBar.SetImages(NewImages: TImageList);
Begin
fImages := NewImages;
UpdateOptions;
Invalidate;
End;
Procedure TEasySymantecMenuNavigationBar.UpdateOptions;
Var
I : Integer;
Option : TEasySymantecMenuNavigationOption;
Begin
For I := 0 to ControlCount-1 do
Begin
IF (Controls[I] is TEasySymantecMenuNavigationOption) Then
Begin
Option := (Controls[I] as TEasySymantecMenuNavigationOption);
Option.Invalidate;
End;
End;
End;
Procedure TEasySymantecMenuNavigationBar.Notification(AComponent: TComponent; Operation: TOperation);
Begin
Inherited;
IF (not (csDestroying in ComponentState)) Then AutoSizeClients;
End;
Procedure TEasySymantecMenuNavigationBar.AutoSizeClients;
Var
I : Integer;
Option : TEasySymantecMenuNavigationOption;
R : TRect;
H : Integer;
Begin
IF (fAutoSize) Then
Begin
R := ClientRect;
AdjustClientRect(R);
H := 0;
For I := 0 to ControlCount-1 do
Begin
IF (Controls[I] is TEasySymantecMenuNavigationOption) Then
Begin
Option := (Controls[I] as TEasySymantecMenuNavigationOption);
IF (Option.Visible) Then H := H + Option.Height;
End;
End;
Height := H + R.Top + (ClientHeight-R.Bottom);
End;
End;
Procedure TEasySymantecMenuNavigationBar.SetAutoSize(NewAutoSize: Boolean);
Begin
IF (NewAutoSize fAutoSize) Then
Begin
fAutoSize := NewAutoSize;
AutoSizeClients;
End;
End;
Procedure TEasySymantecMenuNavigationBar.Resize;
Begin
AutoSizeClients;
End;
Procedure TEasySymantecMenuNavigationBar.CMMouseEnter(var msg: TMessage);
Var
P : TPoint;
Begin
P := ScreenToClient(Mouse.CursorPos);
GotMouse := (P.x = 0) and (P.y = 0) and (P.y IF (Assigned(ControlAtPos(Point(P.x, P.y), True, True))) Then GotMouse := False;
IF (Enabled) and (GotMouse) Then
Begin
Cursor := crHandPoint;
Repaint;
End
Else Cursor := crDefault;
End;
Procedure TEasySymantecMenuNavigationBar.CMMouseLeave(var msg: TMessage);
Begin
GotMouse := False;
IF (Enabled) Then Repaint;
Cursor := crDefault;
End;
Procedure TEasySymantecMenuNavigationBar.CMTextChanged(var msg: TMessage);
Begin
Inherited;
Invalidate;
End;
Procedure TEasySymantecMenuNavigationBar.WMEraseBkGnd(var Message: TWMEraseBkgnd);
Begin
// Prevent erasing of the background...
Message.Result := 1;
End;
Procedure TEasySymantecMenuNavigationBar.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Begin
Inherited;
IF (Y Begin
Maximized := (not Maximized);
End;
End;
Procedure TEasySymantecMenuNavigationBar.MouseMove(Shift: TShiftState; X, Y: Integer);
Var
NewGot : Boolean;
Begin
Inherited;
NewGot := (X = 0) and (X = 0) and (Y IF (Assigned(ControlAtPos(Point(X, Y), True, True))) Then NewGot := False;
IF (NewGot GotMouse) Then
Begin
GotMouse := NewGot;
IF (GotMouse) Then Cursor := crHandPoint
Else Cursor := crDefault;
Repaint;
End;
End;
Procedure TEasySymantecMenuNavigationBar.DrawFadedHeader(DstCanvas: TCanvas);
Var
R : TRect;
X : Real;
XStep : Real;
Steps : Integer;
Red : Real;
Green : Real;
Blue : Real;
RStep : Real;
GStep : Real;
BStep : Real;
StartColor : TColor;
EndColor : TColor;
Begin
R.Left := 1;
R.Right := ClientWidth-1;
R.Top := 1;
R.Bottom := R.Top + 22;
Steps := 128;
IF (Steps (R.Right-R.Left)) Then Steps := (R.Right-R.Left);
IF (Steps
StartColor := RGB(255, 255, 255);
EndColor := RGB(157, 168, 195);
XStep := (R.Right-R.Left) / Steps;
RStep := (GetRValue(EndColor)-GetRValue(StartColor)) / Steps;
GStep := (GetGValue(EndColor)-GetGValue(StartColor)) / Steps;
BStep := (GetBValue(EndColor)-GetBValue(StartColor)) / Steps;
Red := GetRValue(StartColor);
Green := GetGValue(StartColor);
Blue := GetBValue(StartColor);
DstCanvas.Brush.Style := bsSolid;
X := R.Left;
While (X Begin
DstCanvas.Brush.Color := Rgb(Round(Red), Round(Green), Round(Blue));
DstCanvas.FillRect(Rect(Round(X), R.Top, Round(X+XStep), R.Bottom));
Red := Red + RStep;
Green := Green + GStep;
Blue := Blue + BStep;
X := X + XStep;
End;
End;
Procedure TEasySymantecMenuNavigationBar.Paint;
Var
Bmp : TBitmap;
Begin
Bmp := TBitmap.Create;
Bmp.PixelFormat := pf24bit;
Bmp.Width := Width;
Bmp.Height := Height;
// Just make sure we draw the upper corners...
Bmp.Canvas.Brush.Color := mncDarkBlue;
Bmp.Canvas.FillRect(Rect(0, 0, Width, 10));
DrawFadedHeader(Bmp.Canvas);
Bmp.Canvas.Pixels[1, 1] := mncDarkBlue;
Bmp.Canvas.Pixels[Width-2, 1] := mncDarkBlue;
Bmp.Canvas.Pen.Color := clBlack;
Bmp.Canvas.Brush.Style := bsClear;
Bmp.Canvas.RoundRect(0, 0, Width, Height+10, 9, 9);
Bmp.Canvas.MoveTo(0, Height-1);
Bmp.Canvas.LineTo(Width, Height-1);
IF (GotMouse) and (Enabled) Then Bmp.Canvas.Font.Color := RGB(132, 117, 127)
Else Bmp.Canvas.Font.Color := clBlack;
Bmp.Canvas.Font.Name := 'MS Sans Serif';
Bmp.Canvas.Font.Size := 8;
Bmp.Canvas.TextOut(5, 5, Caption);
Bmp.Canvas.Brush.Style := bsSolid;
Bmp.Canvas.Brush.Color := Color;
Bmp.Canvas.FillRect(Rect(1, 23, Width-1, Height-1));
IF (not fMaximized) Then
Begin
DrawIntButton(Bmp.Canvas, ClientWidth-22, 3, NavigationMaximizeButton);
End
Else
Begin
DrawIntButton(Bmp.Canvas, ClientWidth-22, 3, NavigationMinimizeButton);
End;
Canvas.Draw(0, 0, Bmp);
Bmp.Free;
End;
(******************************************************************************)
(******************************************************************************)
(******************************************************************************)
Constructor TEasySymantecMenu.Create(AOwner: TComponent);
Begin
Inherited Create(AOwner);
ControlStyle := ControlStyle + [csOpaque, csAcceptsControls];
DoubleBuffered := True;
Width := 250;
Height := 300;
Color := mncDarkBlue;
fVerticalMenuColor := RGB(179, 187, 209);
fMaximized := True;
OldWidth := Width;
fOnMenuResize := NIL;
ButtonsRect := Rect(0, 0, 0, 0);
End;
Destructor TEasySymantecMenu.Destroy;
Begin
Inherited Destroy;
End;
Procedure TEasySymantecMenu.Notification(AComponent: TComponent; Operation: TOperation);
Begin
Inherited Notification(AComponent, Operation);
IF (AComponent = Images) and (Operation = opRemove) Then Images := NIL;
End;
Procedure TEasySymantecMenu.AdjustClientRect(var Rect: TRect);
Var
MenuRect : TRect;
Begin
Inherited AdjustClientRect(Rect);
IF (fMaximized) Then
Begin
MenuRect := GetVerticalMenuRect;
Rect.Left := 5;
Rect.Top := 5;
Rect.Right := MenuRect.Left-5;
Rect.Bottom := ClientHeight-5;
End
Else Rect := Classes.Rect(0,0,0,0);
End;
Procedure TEasySymantecMenu.WMEraseBkGnd(var Message: TWMEraseBkgnd);
Begin
// Prevent erasing of the background...
Message.Result := 1;
End;
Procedure TEasySymantecMenu.SetImages(NewImages: TImageList);
Begin
fImages := NewImages;
RepositionButtons;
Invalidate;
End;
Procedure TEasySymantecMenu.SetVerticalMenuColor(NewColor: TColor);
Begin
IF (NewColor fVerticalMenuColor) Then
Begin
fVerticalMenuColor := NewColor;
Invalidate;
End;
End;
Procedure TEasySymantecMenu.SetMaximized(NewValue: Boolean);
Begin
IF (NewValue fMaximized) Then
Begin
fMaximized := NewValue;
IF (fMaximized) Then
Begin
Width := OldWidth;
End
Else
Begin
OldWidth := Width;
Width := GetVerticalMenuWidth+1;
End;
IF (Assigned(fOnMenuResize)) Then fOnMenuResize(self);
RepositionButtons;
End;
End;
Function TEasySymantecMenu.AddButton: TEasyToolBarButton;
Begin
Result := TEasyToolBarButton.Create(self);
Result.Parent := self;
End;
Procedure TEasySymantecMenu.Resize;
Begin
Inherited;
IF (not Maximized) Then Width := GetVerticalMenuWidth+1;
RepositionButtons;
End;
Function TEasySymantecMenu.GetVerticalMenuWidth: Integer;
Var
W : Integer;
Begin
W := 0;
IF (Assigned(Images)) Then
Begin
W := Images.Width - 28;
IF (W End;
Result := 34 + W;
End;
Function TEasySymantecMenu.GetVerticalBarRect: TRect;
Begin
Result := Rect(ClientWidth-GetVerticalMenuWidth, 0, ClientWidth, ClientHeight);
End;
Function TEasySymantecMenu.GetVerticalMenuRect: TRect;
Var
Client : TRect;
Begin
Client := GetVerticalBarRect;
// IF QuestionMark is present...: Result := Rect(Client.Left, Client.Top, Client.Left+28, Client.Top+91);
Result := Rect(Client.Left, Client.Top, Client.Left+28, Client.Top+33);
End;
Procedure TEasySymantecMenu.DrawVerticalMenu(DstCanvas: TCanvas);
Var
Client : TRect;
MenuClient : TRect;
Begin
Client := GetVerticalBarRect;
DstCanvas.Brush.Color := fVerticalMenuColor;
DstCanvas.FillRect(Client);
MenuClient := GetVerticalMenuRect;
DstCanvas.Pen.Color := mncBorder;
DstCanvas.Brush.Color := mncDarkBlue;
DstCanvas.RoundRect(MenuClient.Left, MenuClient.Top, MenuClient.Right, MenuClient.Bottom, 9, 9);
// Remove the last part from the round rectangle.
DstCanvas.FillRect(Rect(MenuClient.Left, MenuClient.Top+1, MenuClient.Left+10, MenuClient.Bottom-1));
// Draw the connection parts between the main menu and the vertical menu...
DstCanvas.MoveTo(MenuClient.Left, MenuClient.Top);
DstCanvas.LineTo(MenuClient.Left+10, MenuClient.Top);
DstCanvas.MoveTo(MenuClient.Left, MenuClient.Bottom-1);
DstCanvas.LineTo(MenuClient.Left+10, MenuClient.Bottom-1);
IF (not fMaximized) Then
Begin
DrawIntButton(DstCanvas, MenuClient.Left+5, MenuClient.Top+8, VerticalMaximizeButton);
End
Else
Begin
// Remove the last line from the rectangle created by the main menu...
DstCanvas.FillRect(Rect(MenuClient.Left-1, MenuClient.Top+1, MenuClient.Left, MenuClient.Bottom-1));
DrawIntButton(DstCanvas, MenuClient.Left+5, MenuClient.Top+8, VerticalMinimizeButton);
End;
IF (not fMaximized) or (csDesigning in ComponentState) Then
Begin
IF (ButtonsRect.Bottom-ButtonsRect.Top 0) Then
Begin
DstCanvas.Pen.Color := mncDarkBlue;
DstCanvas.Brush.Color := mncButtonBar;
DstCanvas.Rectangle(ButtonsRect);
End;
End;
End;
Procedure TEasySymantecMenu.Paint;
Var
Bmp : TBitmap;
Client : TRect;
Begin
Bmp := TBitmap.Create;
Bmp.PixelFormat := pf24bit;
Bmp.Width := Width;
Bmp.Height := Height;
Client := Rect(0, 0, ClientWidth-GetVerticalMenuWidth, ClientHeight);
Bmp.Canvas.Brush.Color := mncDarkBlue;
Bmp.Canvas.FillRect(Client);
Bmp.Canvas.Pen.Color := mncBorder;
Bmp.Canvas.Rectangle(Client);
DrawVerticalMenu(Bmp.Canvas);
Canvas.Draw(0, 0, Bmp);
Bmp.Free;
End;
Procedure TEasySymantecMenu.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Var
MenuRect : TRect;
ButtonRect : TRect;
Begin
Inherited;
MenuRect := GetVerticalMenuRect;
ButtonRect := Rect(MenuRect.Left+5, MenuRect.Top+8, MenuRect.Left+5+16, MenuRect.Top+8+17);
IF (PtInRect(ButtonRect, Point(X, Y))) Then
Begin
Maximized := (not Maximized);
End;
End;
Procedure TEasySymantecMenu.MouseMove(Shift: TShiftState; X, Y: Integer);
Var
MenuRect : TRect;
ButtonRect : TRect;
Begin
Inherited;
MenuRect := GetVerticalMenuRect;
ButtonRect := Rect(MenuRect.Left+5, MenuRect.Top+8, MenuRect.Left+5+16, MenuRect.Top+8+17);
IF (PtInRect(ButtonRect, Point(X, Y))) Then Cursor := crHandPoint
Else Cursor := crDefault;
//
End;
Procedure TEasySymantecMenu.RepositionButtons;
Var
I : Integer;
Button : TEasyToolBarButton;
MenuRect : TRect;
Y : Integer;
W : Integer;
Begin
MenuRect := GetVerticalMenuRect;
ButtonsRect := MenuRect;
ButtonsRect.Top := MenuRect.Bottom;
ButtonsRect.Bottom := ButtonsRect.Top;
IF (Assigned(fImages)) Then
Begin
W := fImages.Width;
IF (W
ButtonsRect.Right := ButtonsRect.Left + W + 6;
End;
Y := MenuRect.Bottom+1;
For I := 0 to ControlCount-1 do
Begin
IF (Controls[I] is TEasyToolBarButton) Then
Begin
Button := (Controls[I] as TEasyToolBarButton);
Button.Left := MenuRect.Left+1;
Button.Top := Y;
Button.UpdateSize;
Button.Visible := (not Maximized);
Inc(Y, Button.Height);
End;
End;
ButtonsRect.Bottom := Y+1;
End;
End.