2007-04-02 14:49:00 +00:00
|
|
|
unit X2CLMenuBarActions;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Contnrs,
|
|
|
|
Graphics,
|
|
|
|
Windows,
|
|
|
|
|
|
|
|
X2CLMenuBar;
|
|
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
{
|
|
|
|
:$ Animate group expand/collapse.
|
|
|
|
|
|
|
|
:: Handles the animating of a single group.
|
|
|
|
}
|
|
|
|
TX2MenuBarAnimateAction = class(TX2CustomMenuBarAction)
|
|
|
|
private
|
|
|
|
FAnimator: TX2CustomMenuBarAnimator;
|
|
|
|
FGroup: TX2MenuBarGroup;
|
|
|
|
protected
|
|
|
|
property Animator: TX2CustomMenuBarAnimator read FAnimator;
|
|
|
|
property Group: TX2MenuBarGroup read FGroup;
|
|
|
|
public
|
|
|
|
constructor Create(AMenuBar: TX2CustomMenuBar; AGroup: TX2MenuBarGroup;
|
|
|
|
AAnimator: TX2CustomMenuBarAnimator);
|
2009-04-22 14:22:01 +00:00
|
|
|
destructor Destroy; override;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure Start; override;
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure BeforePaint; override;
|
2007-04-02 14:49:00 +00:00
|
|
|
procedure GetItemHeight(AItem: TX2CustomMenuBarItem; var AHeight: Integer;
|
|
|
|
var AHandled: Boolean); override;
|
|
|
|
procedure DrawMenuItem(ACanvas: TCanvas; APainter: TX2CustomMenuBarPainter;
|
|
|
|
AItem: TX2CustomMenuBarItem; const AMenuBounds: TRect;
|
|
|
|
const AItemBounds: TRect; AState: TX2MenuBarDrawStates;
|
|
|
|
var AHandled: Boolean); override;
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure AfterPaint; override;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Animate multiple groups expanding/collapsing.
|
|
|
|
|
|
|
|
:: Manages multiple TX2MenuBarAnimateAction instances in one action.
|
|
|
|
}
|
|
|
|
TX2MenuBarAnimateMultipleAction = class(TX2CustomMenuBarAction)
|
|
|
|
private
|
|
|
|
FAnimateActions: TObjectList;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function GetCount: Integer;
|
2007-04-02 14:49:00 +00:00
|
|
|
protected
|
|
|
|
function GetAnimateAction(AIndex: Integer): TX2MenuBarAnimateAction;
|
2009-04-22 14:22:01 +00:00
|
|
|
function GetTerminated: Boolean; override;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
property AnimateActions: TObjectList read FAnimateActions;
|
|
|
|
public
|
|
|
|
constructor Create(AMenuBar: TX2CustomMenuBar);
|
2009-04-22 14:22:01 +00:00
|
|
|
destructor Destroy; override;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
procedure Add(AAction: TX2MenuBarAnimateAction);
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure BeforePaint; override;
|
2007-04-02 14:49:00 +00:00
|
|
|
procedure GetItemHeight(AItem: TX2CustomMenuBarItem; var AHeight: Integer;
|
|
|
|
var AHandled: Boolean); override;
|
|
|
|
procedure DrawMenuItem(ACanvas: TCanvas; APainter: TX2CustomMenuBarPainter;
|
|
|
|
AItem: TX2CustomMenuBarItem; const AMenuBounds: TRect;
|
|
|
|
const AItemBounds: TRect; AState: TX2MenuBarDrawStates;
|
|
|
|
var AHandled: Boolean); override;
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure AfterPaint; override;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
property Count: Integer read GetCount;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Sets the Expanded property of a group.
|
|
|
|
|
|
|
|
:: Provides a way to set the Expanded property of a group after it has
|
|
|
|
:: been animated.
|
|
|
|
}
|
|
|
|
TX2MenuBarExpandAction = class(TX2CustomMenuBarAction)
|
|
|
|
private
|
|
|
|
FExpanding: Boolean;
|
|
|
|
FGroup: TX2MenuBarGroup;
|
|
|
|
public
|
|
|
|
constructor Create(AMenuBar: TX2CustomMenuBar; AGroup: TX2MenuBarGroup;
|
|
|
|
AExpanding: Boolean);
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure Start; override;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Sets the Selected property.
|
|
|
|
|
|
|
|
:: Provides a way to set the Selected property of an item after
|
|
|
|
:: animating.
|
|
|
|
}
|
|
|
|
TX2MenuBarSelectAction = class(TX2CustomMenuBarAction)
|
|
|
|
private
|
|
|
|
FItem: TX2CustomMenuBarItem;
|
|
|
|
public
|
2007-04-20 13:37:56 +00:00
|
|
|
constructor Create(AMenuBar: TX2CustomMenuBar; AItem: TX2CustomMenuBarItem);
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure Start; override;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
|
|
|
SysUtils;
|
|
|
|
|
2007-06-01 06:41:52 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
type
|
|
|
|
TProtectedX2CustomMenuBarPainter = class(TX2CustomMenuBarPainter);
|
|
|
|
TProtectedX2CustomMenuBar = class(TX2CustomMenuBar);
|
|
|
|
TProtectedX2MenuBarGroup = class(TX2MenuBarGroup);
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
{ TX2MenuBarAnimateAction }
|
|
|
|
constructor TX2MenuBarAnimateAction.Create(AMenuBar: TX2CustomMenuBar; AGroup: TX2MenuBarGroup;
|
|
|
|
AAnimator: TX2CustomMenuBarAnimator);
|
|
|
|
begin
|
|
|
|
inherited Create(AMenuBar);
|
|
|
|
|
|
|
|
FAnimator := AAnimator;
|
|
|
|
FGroup := AGroup;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
destructor TX2MenuBarAnimateAction.Destroy;
|
2007-06-01 06:41:52 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FAnimator);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2MenuBarAnimateAction.Start;
|
2007-04-20 13:37:56 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
Animator.ResetStartTime;
|
2007-04-20 13:37:56 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2MenuBarAnimateAction.BeforePaint;
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
Animator.Update;
|
2007-04-02 14:49:00 +00:00
|
|
|
if Animator.Terminated then
|
2009-04-22 14:22:01 +00:00
|
|
|
Terminate;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2MenuBarAnimateAction.GetItemHeight(AItem: TX2CustomMenuBarItem;
|
|
|
|
var AHeight: Integer;
|
|
|
|
var AHandled: Boolean);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
if AItem = Group then
|
|
|
|
begin
|
|
|
|
AHeight := Animator.Height;
|
|
|
|
AHandled := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2MenuBarAnimateAction.DrawMenuItem(ACanvas: TCanvas; APainter: TX2CustomMenuBarPainter;
|
|
|
|
AItem: TX2CustomMenuBarItem; const AMenuBounds,
|
|
|
|
AItemBounds: TRect; AState: TX2MenuBarDrawStates;
|
|
|
|
var AHandled: Boolean);
|
|
|
|
var
|
|
|
|
groupBounds: TRect;
|
|
|
|
painter: TProtectedX2CustomMenuBarPainter;
|
|
|
|
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
if Group = AItem then
|
|
|
|
begin
|
|
|
|
painter := TProtectedX2CustomMenuBarPainter(APainter);
|
|
|
|
groupBounds := AMenuBounds;
|
|
|
|
groupBounds.Top := AItemBounds.Bottom +
|
|
|
|
painter.GetSpacing(seAfterGroupHeader) +
|
|
|
|
painter.GetSpacing(seBeforeFirstItem);
|
|
|
|
groupBounds.Bottom := groupBounds.Top + Animator.Height;
|
|
|
|
Animator.Draw(ACanvas, groupBounds);
|
|
|
|
// AHandled := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2MenuBarAnimateAction.AfterPaint;
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
if not Terminated then
|
|
|
|
begin
|
|
|
|
{ Prevent 100% CPU usage }
|
|
|
|
Sleep(5);
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
TProtectedX2CustomMenuBar(MenuBar).TestMousePos;
|
|
|
|
MenuBar.Invalidate;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2MenuBarAnimateMultipleAction }
|
|
|
|
constructor TX2MenuBarAnimateMultipleAction.Create(AMenuBar: TX2CustomMenuBar);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
FAnimateActions := TObjectList.Create(True);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
destructor TX2MenuBarAnimateMultipleAction.Destroy;
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FAnimateActions);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2MenuBarAnimateMultipleAction.Add(AAction: TX2MenuBarAnimateAction);
|
|
|
|
begin
|
|
|
|
AnimateActions.Add(AAction);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2MenuBarAnimateMultipleAction.BeforePaint;
|
2007-04-02 14:49:00 +00:00
|
|
|
var
|
|
|
|
actionIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
for actionIndex := 0 to Pred(AnimateActions.Count) do
|
2009-04-22 14:22:01 +00:00
|
|
|
GetAnimateAction(actionIndex).BeforePaint;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2MenuBarAnimateMultipleAction.GetItemHeight(AItem: TX2CustomMenuBarItem;
|
|
|
|
var AHeight: Integer;
|
|
|
|
var AHandled: Boolean);
|
|
|
|
var
|
|
|
|
actionIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
for actionIndex := 0 to Pred(AnimateActions.Count) do
|
|
|
|
begin
|
|
|
|
GetAnimateAction(actionIndex).GetItemHeight(AItem, AHeight, AHandled);
|
|
|
|
|
|
|
|
if AHandled then
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2MenuBarAnimateMultipleAction.DrawMenuItem(ACanvas: TCanvas;
|
|
|
|
APainter: TX2CustomMenuBarPainter;
|
|
|
|
AItem: TX2CustomMenuBarItem;
|
|
|
|
const AMenuBounds, AItemBounds: TRect;
|
|
|
|
AState: TX2MenuBarDrawStates;
|
|
|
|
var AHandled: Boolean);
|
|
|
|
var
|
|
|
|
actionIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
for actionIndex := 0 to Pred(AnimateActions.Count) do
|
|
|
|
begin
|
|
|
|
GetAnimateAction(actionIndex).DrawMenuItem(ACanvas, APainter, AItem,
|
|
|
|
AMenuBounds, AItemBounds, AState,
|
|
|
|
AHandled);
|
|
|
|
|
|
|
|
if AHandled then
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2MenuBarAnimateMultipleAction.AfterPaint;
|
2007-04-02 14:49:00 +00:00
|
|
|
var
|
|
|
|
actionIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
for actionIndex := 0 to Pred(AnimateActions.Count) do
|
2009-04-22 14:22:01 +00:00
|
|
|
GetAnimateAction(actionIndex).AfterPaint;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2MenuBarAnimateMultipleAction.GetAnimateAction(AIndex: Integer): TX2MenuBarAnimateAction;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarAnimateAction(AnimateActions[AIndex]);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2MenuBarAnimateMultipleAction.GetCount: Integer;
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
Result := FAnimateActions.Count;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2MenuBarAnimateMultipleAction.GetTerminated: Boolean;
|
2007-04-02 14:49:00 +00:00
|
|
|
var
|
|
|
|
actionIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
Result := inherited GetTerminated;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
if not Result then
|
|
|
|
begin
|
|
|
|
for actionIndex := 0 to Pred(AnimateActions.Count) do
|
|
|
|
if GetAnimateAction(actionIndex).Terminated then
|
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2MenuBarExpandAction }
|
|
|
|
constructor TX2MenuBarExpandAction.Create(AMenuBar: TX2CustomMenuBar;
|
|
|
|
AGroup: TX2MenuBarGroup;
|
|
|
|
AExpanding: Boolean);
|
|
|
|
begin
|
|
|
|
inherited Create(AMenuBar);
|
|
|
|
|
|
|
|
FExpanding := AExpanding;
|
|
|
|
FGroup := AGroup;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2MenuBarExpandAction.Start;
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
TProtectedX2CustomMenuBar(MenuBar).InternalSetExpanded(FGroup, FExpanding);
|
2009-04-22 14:22:01 +00:00
|
|
|
Terminate;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
|
|
|
{ TX2MenuBarSelectAction }
|
|
|
|
constructor TX2MenuBarSelectAction.Create(AMenuBar: TX2CustomMenuBar;
|
|
|
|
AItem: TX2CustomMenuBarItem);
|
|
|
|
begin
|
|
|
|
inherited Create(AMenuBar);
|
|
|
|
|
|
|
|
FItem := AItem;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2MenuBarSelectAction.Start;
|
2007-04-20 13:37:56 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
TProtectedX2CustomMenuBar(MenuBar).InternalSetSelected(FItem);
|
2009-04-22 14:22:01 +00:00
|
|
|
Terminate;
|
2007-04-20 13:37:56 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
end.
|