2006-03-24 05:56:59 +00:00
|
|
|
{
|
|
|
|
:: X2CLMenuBar is a generic group/items menu. Through the various painters,
|
|
|
|
:: it can resemble styles such as the musikCube or BBox/Uname-IT menu bars.
|
|
|
|
::
|
2006-05-22 05:13:12 +00:00
|
|
|
:: Part of the X2Software Component Library
|
|
|
|
:: http://www.x2software.net/
|
|
|
|
::
|
2006-03-24 05:56:59 +00:00
|
|
|
:: Last changed: $Date$
|
|
|
|
:: Revision: $Rev$
|
|
|
|
:: Author: $Author$
|
|
|
|
}
|
|
|
|
unit X2CLMenuBar;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
2006-05-22 05:13:12 +00:00
|
|
|
ActnList,
|
2006-03-24 05:56:59 +00:00
|
|
|
Classes,
|
|
|
|
Contnrs,
|
|
|
|
Controls,
|
|
|
|
Forms,
|
|
|
|
Graphics,
|
|
|
|
ImgList,
|
|
|
|
Messages,
|
2006-03-30 04:54:11 +00:00
|
|
|
Types,
|
2006-03-24 05:56:59 +00:00
|
|
|
Windows;
|
|
|
|
|
|
|
|
type
|
2006-04-02 20:00:02 +00:00
|
|
|
TX2MenuBarAnimationStyle = (asNone, asSlide, asDissolve, asFade,
|
|
|
|
asSlideFade);
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
TX2MenuBarDirection = (mbdUp, mbdDown);
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
const
|
|
|
|
DefaultAnimationStyle = asSlide;
|
|
|
|
DefaultAnimationTime = 250;
|
|
|
|
|
|
|
|
type
|
2007-01-31 09:41:11 +00:00
|
|
|
{$IFNDEF VER180}
|
|
|
|
// #ToDo1 (MvR) 24-5-2006: check how D2006 defines these
|
|
|
|
TVerticalAlignment = (taTop, taBottom, taVerticalCenter);
|
|
|
|
{$ENDIF}
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
// #ToDo1 (MvR) 25-3-2006: various Select methods for key support
|
2006-04-02 20:00:02 +00:00
|
|
|
// #ToDo1 (MvR) 1-4-2006: scroll wheel support
|
2006-04-01 19:51:46 +00:00
|
|
|
TX2CustomMenuBarAnimatorClass = class of TX2CustomMenuBarAnimator;
|
|
|
|
TX2CustomMenuBarAnimator = class;
|
2006-03-30 04:54:11 +00:00
|
|
|
TX2CustomMenuBarPainterClass = class of TX2CustomMenuBarPainter;
|
|
|
|
TX2CustomMenuBarPainter = class;
|
|
|
|
TX2CustomMenuBarItem = class;
|
2006-03-24 05:56:59 +00:00
|
|
|
TX2MenuBarItem = class;
|
|
|
|
TX2MenuBarGroup = class;
|
|
|
|
TX2CustomMenuBar = class;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
IX2MenuBarDesigner = interface
|
|
|
|
['{F648CFD2-771D-4531-84D0-621FD7597E48}']
|
|
|
|
procedure ItemAdded(AItem: TX2CustomMenuBarItem);
|
|
|
|
procedure ItemModified(AItem: TX2CustomMenuBarItem);
|
|
|
|
procedure ItemDeleting(AItem: TX2CustomMenuBarItem);
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
TX2MenuBarHitTest = record
|
|
|
|
HitTestCode: Integer;
|
2006-03-30 04:54:11 +00:00
|
|
|
Item: TX2CustomMenuBarItem;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
TX2MenuBarDrawState = (mdsHot, mdsSelected, mdsGroupHot, mdsGroupSelected);
|
|
|
|
TX2MenuBarDrawStates = set of TX2MenuBarDrawState;
|
|
|
|
|
|
|
|
TX2MenuBarSpacingElement = (seBeforeGroupHeader, seAfterGroupHeader,
|
|
|
|
seBeforeFirstItem, seAfterLastItem,
|
|
|
|
seBeforeItem, seAfterItem);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
TX2MenuBarSelectAction = (saBefore, saAfter, saBoth);
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
TX2ComponentNotificationEvent = procedure(Sender: TObject; AComponent: TComponent; Operation: TOperation) of object;
|
2006-04-17 18:41:43 +00:00
|
|
|
TX2MenuBarExpandingEvent = procedure(Sender: TObject; Group: TX2MenuBarGroup; var Allowed: Boolean) of object;
|
|
|
|
TX2MenuBarExpandedEvent = procedure(Sender: TObject; Group: TX2MenuBarGroup) of object;
|
|
|
|
TX2MenuBarSelectedChangingEvent = procedure(Sender: TObject; Item, NewItem: TX2CustomMenUBarItem; var Allowed: Boolean) of object;
|
|
|
|
TX2MenuBarSelectedChangedEvent = procedure(Sender: TObject; Item: TX2CustomMenUBarItem) of object;
|
2006-04-02 20:00:02 +00:00
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
TX2MenuBarItemBoundsProc = procedure(Sender: TObject;
|
|
|
|
Item: TX2CustomMenuBarItem;
|
|
|
|
const MenuBounds: TRect;
|
|
|
|
const ItemBounds: TRect;
|
|
|
|
Data: Pointer;
|
|
|
|
var Abort: Boolean) of object;
|
2006-04-02 20:00:02 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
TX2MenuBarIterateProc = procedure(Sender: TObject;
|
|
|
|
Item: TX2CustomMenuBarItem;
|
|
|
|
Data: Pointer;
|
|
|
|
var Abort: Boolean) of object;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
TCollectionNotifyEvent = procedure(Sender: TObject; Item: TCollectionItem; Action: TCollectionNotification) of object;
|
|
|
|
TCollectionUpdateEvent = procedure(Sender: TObject; Item: TCollectionItem) of object;
|
2006-04-02 20:00:02 +00:00
|
|
|
|
|
|
|
IX2MenuBarPainterObserver = interface
|
|
|
|
['{22DE60C9-49A1-4E7D-B547-901BEDCC0FB7}']
|
|
|
|
procedure PainterUpdate(Sender: TX2CustomMenuBarPainter);
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
:$ Abstract animation class
|
|
|
|
|
|
|
|
:: Descendants implement the animation-specific drawing code.
|
|
|
|
}
|
2006-04-01 19:51:46 +00:00
|
|
|
TX2CustomMenuBarAnimator = class(TObject)
|
2006-03-24 05:56:59 +00:00
|
|
|
private
|
|
|
|
FAnimationTime: Cardinal;
|
|
|
|
FExpanding: Boolean;
|
|
|
|
FGroup: TX2MenuBarGroup;
|
|
|
|
FStartTime: Cardinal;
|
|
|
|
FItemsBuffer: Graphics.TBitmap;
|
|
|
|
FTerminated: Boolean;
|
|
|
|
protected
|
2006-03-30 04:54:11 +00:00
|
|
|
function GetTimeElapsed(): Cardinal; virtual;
|
|
|
|
function GetHeight(): Integer; virtual;
|
|
|
|
procedure SetExpanding(const Value: Boolean); virtual;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure Terminate(); virtual;
|
|
|
|
|
|
|
|
property ItemsBuffer: Graphics.TBitmap read FItemsBuffer;
|
|
|
|
property TimeElapsed: Cardinal read GetTimeElapsed;
|
|
|
|
public
|
|
|
|
constructor Create(AItemsBuffer: Graphics.TBitmap); virtual;
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure Update(); virtual;
|
|
|
|
procedure Draw(ACanvas: TCanvas; const ABounds: TRect); virtual; abstract;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
property AnimationTime: Cardinal read FAnimationTime write FAnimationTime;
|
2006-03-30 04:54:11 +00:00
|
|
|
property Expanding: Boolean read FExpanding write SetExpanding;
|
2006-03-24 05:56:59 +00:00
|
|
|
property Group: TX2MenuBarGroup read FGroup write FGroup;
|
|
|
|
property Terminated: Boolean read FTerminated;
|
2006-03-30 04:54:11 +00:00
|
|
|
property Height: Integer read GetHeight;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Abstract painter class.
|
|
|
|
|
|
|
|
:: Descendants must implement the actual drawing code.
|
|
|
|
}
|
2006-03-30 04:54:11 +00:00
|
|
|
TX2CustomMenuBarPainter = class(TComponent)
|
2006-03-24 05:56:59 +00:00
|
|
|
private
|
|
|
|
FMenuBar: TX2CustomMenuBar;
|
|
|
|
FObservers: TInterfaceList;
|
|
|
|
|
|
|
|
function GetMenuBar(): TX2CustomMenuBar;
|
|
|
|
protected
|
|
|
|
procedure BeginPaint(const AMenuBar: TX2CustomMenuBar);
|
|
|
|
procedure EndPaint();
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function ApplyMargins(const ABounds: TRect): TRect; virtual;
|
|
|
|
function GetSpacing(AElement: TX2MenuBarSpacingElement): Integer; virtual;
|
2006-03-24 05:56:59 +00:00
|
|
|
function GetGroupHeaderHeight(AGroup: TX2MenuBarGroup): Integer; virtual; abstract;
|
|
|
|
function GetGroupHeight(AGroup: TX2MenuBarGroup): Integer; virtual;
|
|
|
|
function GetItemHeight(AItem: TX2MenuBarItem): Integer; virtual; abstract;
|
|
|
|
|
|
|
|
procedure DrawBackground(ACanvas: TCanvas; const ABounds: TRect); virtual; abstract;
|
|
|
|
procedure DrawGroupHeader(ACanvas: TCanvas; AGroup: TX2MenuBarGroup; const ABounds: TRect; AState: TX2MenuBarDrawStates); virtual; abstract;
|
|
|
|
procedure DrawItem(ACanvas: TCanvas; AItem: TX2MenuBarItem; const ABounds: TRect; AState: TX2MenuBarDrawStates); virtual; abstract;
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure FindHit(Sender: TObject; Item: TX2CustomMenuBarItem; const MenuBounds: TRect; const ItemBounds: TRect; Data: Pointer; var Abort: Boolean);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
procedure NotifyObservers();
|
|
|
|
|
|
|
|
property MenuBar: TX2CustomMenuBar read GetMenuBar;
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function HitTest(const APoint: TPoint): TX2MenuBarHitTest; overload; virtual;
|
2006-03-24 05:56:59 +00:00
|
|
|
function HitTest(AX, AY: Integer): TX2MenuBarHitTest; overload;
|
|
|
|
|
|
|
|
procedure AttachObserver(AObserver: IX2MenuBarPainterObserver);
|
|
|
|
procedure DetachObserver(AObserver: IX2MenuBarPainterObserver);
|
|
|
|
end;
|
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
{
|
|
|
|
:$ Action link for menu items and groups.
|
|
|
|
}
|
|
|
|
TX2MenuBarActionLink = class(TActionLink)
|
|
|
|
private
|
|
|
|
FClient: TX2CustomMenuBarItem;
|
|
|
|
protected
|
|
|
|
procedure AssignClient(AClient: TObject); override;
|
|
|
|
|
|
|
|
function IsCaptionLinked(): Boolean; override;
|
|
|
|
function IsEnabledLinked(): Boolean; override;
|
|
|
|
function IsImageIndexLinked(): Boolean; override;
|
|
|
|
function IsVisibleLinked(): Boolean; override;
|
|
|
|
procedure SetCaption(const Value: string); override;
|
|
|
|
procedure SetEnabled(Value: Boolean); override;
|
|
|
|
procedure SetImageIndex(Value: Integer); override;
|
|
|
|
procedure SetVisible(Value: Boolean); override;
|
|
|
|
|
|
|
|
property Client: TX2CustomMenuBarItem read FClient;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Provides component notifications for collection items.
|
|
|
|
}
|
|
|
|
TX2ComponentNotification = class(TComponent)
|
|
|
|
private
|
|
|
|
FOnNotification: TX2ComponentNotificationEvent;
|
|
|
|
published
|
|
|
|
protected
|
|
|
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
|
|
|
published
|
|
|
|
property OnNotification: TX2ComponentNotificationEvent read FOnNotification write FOnNotification;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{
|
2006-03-30 04:54:11 +00:00
|
|
|
:$ Base class for menu items and groups.
|
2006-03-24 05:56:59 +00:00
|
|
|
}
|
2006-03-30 04:54:11 +00:00
|
|
|
TX2CustomMenuBarItem = class(TCollectionItem)
|
2006-03-24 05:56:59 +00:00
|
|
|
private
|
2006-05-22 05:13:12 +00:00
|
|
|
FAction: TBasicAction;
|
|
|
|
FActionLink: TX2MenuBarActionLink;
|
2006-03-24 05:56:59 +00:00
|
|
|
FCaption: String;
|
|
|
|
FData: TObject;
|
2006-04-02 20:00:02 +00:00
|
|
|
FEnabled: Boolean;
|
2006-03-24 05:56:59 +00:00
|
|
|
FImageIndex: TImageIndex;
|
2006-03-30 04:54:11 +00:00
|
|
|
FOwnsData: Boolean;
|
2007-01-31 09:41:11 +00:00
|
|
|
FTag: Integer;
|
2006-04-02 20:00:02 +00:00
|
|
|
FVisible: Boolean;
|
2006-05-22 05:13:12 +00:00
|
|
|
|
|
|
|
FNotification: TX2ComponentNotification;
|
|
|
|
private
|
|
|
|
procedure DoActionChange(Sender: TObject);
|
2006-03-30 04:54:11 +00:00
|
|
|
protected
|
2006-05-22 05:13:12 +00:00
|
|
|
procedure ActionChange(Sender: TObject; CheckDefaults: Boolean); virtual;
|
|
|
|
|
|
|
|
function IsCaptionStored(): Boolean; virtual;
|
2006-03-30 04:54:11 +00:00
|
|
|
function GetMenuBar(): TX2CustomMenuBar; virtual;
|
2006-05-22 05:13:12 +00:00
|
|
|
procedure SetAction(const Value: TBasicAction);
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure SetCaption(const Value: String); virtual;
|
|
|
|
procedure SetData(const Value: TObject); virtual;
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure SetEnabled(const Value: Boolean); virtual;
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure SetImageIndex(const Value: TImageIndex); virtual;
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure SetVisible(const Value: Boolean); virtual;
|
2006-03-24 05:56:59 +00:00
|
|
|
public
|
|
|
|
constructor Create(Collection: TCollection); override;
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
|
|
|
procedure Assign(Source: TPersistent); override;
|
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
property ActionLink: TX2MenuBarActionLink read FActionLink;
|
|
|
|
property Data: TObject read FData write SetData;
|
|
|
|
property OwnsData: Boolean read FOwnsData write FOwnsData;
|
|
|
|
property MenuBar: TX2CustomMenuBar read GetMenuBar;
|
2006-03-24 05:56:59 +00:00
|
|
|
published
|
2006-05-22 05:13:12 +00:00
|
|
|
property Action: TBasicAction read FAction write SetAction;
|
|
|
|
property Caption: String read FCaption write SetCaption stored IsCaptionStored;
|
|
|
|
property Enabled: Boolean read FEnabled write SetEnabled default True;
|
|
|
|
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
|
2007-01-31 09:41:11 +00:00
|
|
|
property Tag: Integer read FTag write FTag default 0;
|
2006-05-22 05:13:12 +00:00
|
|
|
property Visible: Boolean read FVisible write SetVisible default True;
|
2006-04-02 20:00:02 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Base class for menu collections.
|
|
|
|
}
|
|
|
|
TX2CustomMenuBarItems = class(TOwnedCollection)
|
|
|
|
private
|
2006-04-17 18:41:43 +00:00
|
|
|
FOnNotify: TCollectionNotifyEvent;
|
|
|
|
FOnUpdate: TCollectionUpdateEvent;
|
2006-04-02 20:00:02 +00:00
|
|
|
protected
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure Notify(Item: TCollectionItem; Action: TCollectionNotification); override;
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure Update(Item: TCollectionItem); override;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
property OnNotify: TCollectionNotifyEvent read FOnNotify write FOnNotify;
|
|
|
|
property OnUpdate: TCollectionUpdateEvent read FOnUpdate write FOnUpdate;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
{
|
|
|
|
:$ Contains a single menu item.
|
|
|
|
}
|
|
|
|
TX2MenuBarItem = class(TX2CustomMenuBarItem)
|
|
|
|
private
|
|
|
|
function GetGroup(): TX2MenuBarGroup;
|
2006-05-22 05:13:12 +00:00
|
|
|
protected
|
|
|
|
function IsCaptionStored(): Boolean; override;
|
2006-03-30 04:54:11 +00:00
|
|
|
public
|
2006-04-17 18:41:43 +00:00
|
|
|
constructor Create(Collection: TCollection); override;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
property Group: TX2MenuBarGroup read GetGroup;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{
|
|
|
|
:$ Manages a collection of menu items.
|
|
|
|
}
|
2006-04-02 20:00:02 +00:00
|
|
|
TX2MenuBarItems = class(TX2CustomMenuBarItems)
|
2006-03-24 05:56:59 +00:00
|
|
|
private
|
|
|
|
function GetItem(Index: Integer): TX2MenuBarItem;
|
|
|
|
procedure SetItem(Index: Integer; const Value: TX2MenuBarItem);
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TPersistent);
|
|
|
|
|
|
|
|
function Add(const ACaption: TCaption = ''): TX2MenuBarItem;
|
|
|
|
|
|
|
|
property Items[Index: Integer]: TX2MenuBarItem read GetItem write SetItem; default;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Contains a single menu group.
|
|
|
|
}
|
2006-03-30 04:54:11 +00:00
|
|
|
TX2MenuBarGroup = class(TX2CustomMenuBarItem)
|
2006-03-24 05:56:59 +00:00
|
|
|
private
|
2006-03-30 04:54:11 +00:00
|
|
|
FExpanded: Boolean;
|
|
|
|
FItems: TX2MenuBarItems;
|
|
|
|
FSelectedItem: Integer;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function GetSelectedItem(): Integer;
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure SetExpanded(const Value: Boolean);
|
|
|
|
procedure SetItems(const Value: TX2MenuBarItems);
|
2006-05-22 05:13:12 +00:00
|
|
|
protected
|
|
|
|
function IsCaptionStored(): Boolean; override;
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure SetEnabled(const Value: Boolean); override;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure InternalSetExpanded(const Value: Boolean);
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure ItemsNotify(Sender: TObject; Item: TCollectionItem; Action: TCollectionNotification);
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure ItemsUpdate(Sender: TObject; Item: TCollectionItem);
|
2006-03-24 05:56:59 +00:00
|
|
|
public
|
|
|
|
constructor Create(Collection: TCollection); override;
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
|
|
|
procedure Assign(Source: TPersistent); override;
|
2009-03-13 14:16:14 +00:00
|
|
|
|
|
|
|
property SelectedItem: Integer read GetSelectedItem write FSelectedItem;
|
2006-03-24 05:56:59 +00:00
|
|
|
published
|
|
|
|
property Expanded: Boolean read FExpanded write SetExpanded;
|
|
|
|
property Items: TX2MenuBarItems read FItems write SetItems;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Manages a collection of menu groups.
|
|
|
|
}
|
2006-04-02 20:00:02 +00:00
|
|
|
TX2MenuBarGroups = class(TX2CustomMenuBarItems)
|
2006-03-24 05:56:59 +00:00
|
|
|
private
|
|
|
|
function GetItem(Index: Integer): TX2MenuBarGroup;
|
|
|
|
procedure SetItem(Index: Integer; const Value: TX2MenuBarGroup);
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TPersistent);
|
|
|
|
|
|
|
|
function Add(const ACaption: TCaption = ''): TX2MenuBarGroup;
|
|
|
|
|
|
|
|
property Items[Index: Integer]: TX2MenuBarGroup read GetItem write SetItem; default;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Implements the menu bar.
|
|
|
|
|
|
|
|
:: The menu bar is the visual container for the menu. It manages the groups
|
|
|
|
:: and items, and implements the switching between menu items. It does not
|
|
|
|
:: paint itself, instead it delegates this to it's linked Painter.
|
|
|
|
}
|
|
|
|
TX2CustomMenuBar = class(TCustomControl, IX2MenuBarPainterObserver)
|
|
|
|
private
|
2006-04-17 18:41:43 +00:00
|
|
|
FAllowCollapseAll: Boolean;
|
|
|
|
FAnimationStyle: TX2MenuBarAnimationStyle;
|
|
|
|
FAnimationTime: Cardinal;
|
|
|
|
FAnimator: TX2CustomMenuBarAnimator;
|
|
|
|
FAutoCollapse: Boolean;
|
|
|
|
FAutoSelectItem: Boolean;
|
|
|
|
FBorderStyle: TBorderStyle;
|
2007-01-31 09:41:11 +00:00
|
|
|
FBuffer: Graphics.TBitmap;
|
2006-04-17 18:41:43 +00:00
|
|
|
FCursorGroup: TCursor;
|
|
|
|
FCursorItem: TCursor;
|
|
|
|
FDesigner: IX2MenuBarDesigner;
|
|
|
|
FExpandingGroups: TStringList;
|
|
|
|
FGroups: TX2MenuBarGroups;
|
|
|
|
FHideScrollbar: Boolean;
|
|
|
|
FHotItem: TX2CustomMenuBarItem;
|
|
|
|
FImages: TCustomImageList;
|
|
|
|
FLastMousePos: TPoint;
|
|
|
|
FOnCollapsed: TX2MenuBarExpandedEvent;
|
|
|
|
FOnCollapsing: TX2MenuBarExpandingEvent;
|
|
|
|
FOnExpanded: TX2MenuBarExpandedEvent;
|
|
|
|
FOnExpanding: TX2MenuBarExpandingEvent;
|
|
|
|
FOnSelectedChanged: TX2MenuBarSelectedChangedEvent;
|
|
|
|
FOnSelectedChanging: TX2MenuBarSelectedChangingEvent;
|
|
|
|
FPainter: TX2CustomMenuBarPainter;
|
|
|
|
FScrollbar: Boolean;
|
|
|
|
FScrollOffset: Integer;
|
|
|
|
FSelectedItem: TX2CustomMenuBarItem;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure SetAllowCollapseAll(const Value: Boolean);
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure SetAnimator(const Value: TX2CustomMenuBarAnimator);
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure SetAutoCollapse(const Value: Boolean);
|
|
|
|
procedure SetAutoSelectItem(const Value: Boolean);
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure SetBorderStyle(const Value: TBorderStyle);
|
|
|
|
procedure SetGroups(const Value: TX2MenuBarGroups);
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure SetHideScrollbar(const Value: Boolean);
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure SetImages(const Value: TCustomImageList);
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure SetScrollbar(const Value: Boolean);
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure SetSelectedItem(const Value: TX2CustomMenuBarItem);
|
2006-03-24 05:56:59 +00:00
|
|
|
protected
|
|
|
|
procedure CreateParams(var Params: TCreateParams); override;
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure Loaded(); override;
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure PainterUpdate(Sender: TX2CustomMenuBarPainter);
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure GroupsNotify(Sender: TObject; Item: TCollectionItem; Action: TCollectionNotification);
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure GroupsUpdate(Sender: TObject; Item: TCollectionItem);
|
|
|
|
procedure UpdateScrollbar();
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
|
|
|
|
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
|
|
|
// procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
|
|
|
|
|
|
|
|
procedure WMVScroll(var Msg: TWMVScroll); message WM_VSCROLL;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
procedure TestMousePos(); virtual;
|
2006-04-01 19:51:46 +00:00
|
|
|
function GetMenuHeight(): Integer; virtual;
|
2006-04-17 18:41:43 +00:00
|
|
|
|
|
|
|
property Designer: IX2MenuBarDesigner read FDesigner write FDesigner;
|
2006-03-24 05:56:59 +00:00
|
|
|
protected
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure SetPainter(const Value: TX2CustomMenuBarPainter); virtual;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
|
|
|
|
procedure Paint(); override;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function GetDrawState(AItem: TX2CustomMenuBarItem): TX2MenuBarDrawStates;
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure DrawMenu(ACanvas: TCanvas); virtual;
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure DrawMenuItem(Sender: TObject; Item: TX2CustomMenuBarItem; const MenuBounds, ItemBounds: TRect; Data: Pointer; var Abort: Boolean); virtual;
|
|
|
|
procedure DrawMenuItems(ACanvas: TCanvas; AGroup: TX2MenuBarGroup; const ABounds: TRect); virtual;
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure DrawNoPainter(ACanvas: TCanvas; const ABounds: TRect); virtual;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
function GetAnimatorClass(): TX2CustomMenuBarAnimatorClass; virtual;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function IterateItemBounds(ACallback: TX2MenuBarItemBoundsProc; AData: Pointer = nil): TX2CustomMenuBarItem;
|
2006-03-24 05:56:59 +00:00
|
|
|
function AllowInteraction(): Boolean; virtual;
|
2007-01-31 09:41:11 +00:00
|
|
|
function ItemEnabled(AItem: TX2CustomMenuBarItem): Boolean; virtual;
|
2006-04-02 20:00:02 +00:00
|
|
|
function ItemVisible(AItem: TX2CustomMenuBarItem): Boolean; virtual;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
property AllowCollapseAll: Boolean read FAllowCollapseAll write SetAllowCollapseAll default True;
|
|
|
|
property AnimationStyle: TX2MenuBarAnimationStyle read FAnimationStyle write FAnimationStyle default DefaultAnimationStyle;
|
|
|
|
property AnimationTime: Cardinal read FAnimationTime write FAnimationTime default DefaultAnimationTime;
|
|
|
|
property Animator: TX2CustomMenuBarAnimator read FAnimator write SetAnimator;
|
|
|
|
property AutoCollapse: Boolean read FAutoCollapse write SetAutoCollapse default False;
|
|
|
|
property AutoSelectItem: Boolean read FAutoSelectItem write SetAutoSelectItem default False;
|
|
|
|
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsNone;
|
|
|
|
property CursorGroup: TCursor read FCursorGroup write FCursorGroup default crDefault;
|
|
|
|
property CursorItem: TCursor read FCursorItem write FCursorItem default crDefault;
|
|
|
|
property HideScrollbar: Boolean read FHideScrollbar write SetHideScrollbar default True;
|
|
|
|
property OnCollapsed: TX2MenuBarExpandedEvent read FOnCollapsed write FOnCollapsed;
|
|
|
|
property OnCollapsing: TX2MenuBarExpandingEvent read FOnCollapsing write FOnCollapsing;
|
|
|
|
property OnExpanded: TX2MenuBarExpandedEvent read FOnExpanded write FOnExpanded;
|
|
|
|
property OnExpanding: TX2MenuBarExpandingEvent read FOnExpanding write FOnExpanding;
|
|
|
|
property OnSelectedChanged: TX2MenuBarSelectedChangedEvent read FOnSelectedChanged write FOnSelectedChanged;
|
|
|
|
property OnSelectedChanging: TX2MenuBarSelectedChangingEvent read FOnSelectedChanging write FOnSelectedChanging;
|
|
|
|
property Scrollbar: Boolean read FScrollbar write SetScrollbar default True;
|
2006-03-24 05:56:59 +00:00
|
|
|
protected
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure DoAutoCollapse(AGroup: TX2MenuBarGroup); virtual;
|
|
|
|
function DoAutoSelectItem(AGroup: TX2MenuBarGroup; AAction: TX2MenuBarSelectAction): Boolean; virtual;
|
|
|
|
procedure DoExpand(AGroup: TX2MenuBarGroup; AExpanding: Boolean); virtual;
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure DoExpandedChanging(AGroup: TX2MenuBarGroup; AExpanding: Boolean); virtual;
|
|
|
|
procedure DoExpandedChanged(AGroup: TX2MenuBarGroup); virtual;
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure DoSelectedChanging(ANewItem: TX2CustomMenuBarItem; var AAllowed: Boolean); virtual;
|
|
|
|
procedure DoSelectedChanged(); virtual;
|
2007-01-31 09:41:11 +00:00
|
|
|
|
|
|
|
procedure FindEnabledItem(Sender: TObject; Item: TX2CustomMenuBarItem; Data: Pointer; var Abort: Boolean);
|
2006-03-24 05:56:59 +00:00
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function HitTest(const APoint: TPoint): TX2MenuBarHitTest; overload;
|
2006-03-24 05:56:59 +00:00
|
|
|
function HitTest(AX, AY: Integer): TX2MenuBarHitTest; overload;
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
function Iterate(ACallback: TX2MenuBarIterateProc;
|
|
|
|
ADirection: TX2MenuBarDirection = mbdDown;
|
|
|
|
AData: Pointer = nil;
|
|
|
|
AStart: TX2CustomMenuBarItem = nil): TX2CustomMenuBarItem;
|
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
function SelectFirst(): TX2CustomMenuBarItem;
|
|
|
|
function SelectLast(): TX2CustomMenuBarItem;
|
|
|
|
function SelectNext(): TX2CustomMenuBarItem;
|
|
|
|
function SelectPrior(): TX2CustomMenuBarItem;
|
|
|
|
|
|
|
|
function SelectGroup(AIndex: Integer): TX2MenuBarGroup;
|
2007-01-31 09:41:11 +00:00
|
|
|
function SelectItem(AIndex: Integer; AGroup: TX2MenuBarGroup): TX2CustomMenuBarItem; overload;
|
|
|
|
function SelectItem(AIndex: Integer; AGroup: Integer): TX2CustomMenuBarItem; overload;
|
|
|
|
function SelectItem(AIndex: Integer): TX2CustomMenuBarItem; overload;
|
|
|
|
|
|
|
|
procedure ResetGroupsSelectedItem();
|
2006-05-22 05:13:12 +00:00
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
property Groups: TX2MenuBarGroups read FGroups write SetGroups;
|
|
|
|
property Images: TCustomImageList read FImages write SetImages;
|
|
|
|
property Painter: TX2CustomMenuBarPainter read FPainter write SetPainter;
|
|
|
|
property SelectedItem: TX2CustomMenuBarItem read FSelectedItem write SetSelectedItem;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Exposes the menu bar's published properties.
|
|
|
|
}
|
|
|
|
TX2MenuBar = class(TX2CustomMenuBar)
|
|
|
|
published
|
|
|
|
property Align;
|
2006-04-02 20:00:02 +00:00
|
|
|
property AllowCollapseAll;
|
|
|
|
property AnimationStyle;
|
|
|
|
property AnimationTime;
|
|
|
|
property AutoCollapse;
|
|
|
|
property AutoSelectItem;
|
2006-03-24 05:56:59 +00:00
|
|
|
property BevelEdges;
|
|
|
|
property BevelInner;
|
|
|
|
property BevelKind;
|
|
|
|
property BevelOuter;
|
|
|
|
property BorderStyle;
|
|
|
|
property BorderWidth;
|
2006-04-17 18:41:43 +00:00
|
|
|
property CursorGroup;
|
|
|
|
property CursorItem;
|
2007-01-31 09:41:11 +00:00
|
|
|
property Font;
|
2006-03-24 05:56:59 +00:00
|
|
|
property Groups;
|
2006-04-02 20:00:02 +00:00
|
|
|
property HideScrollbar;
|
2006-04-17 18:41:43 +00:00
|
|
|
property Images;
|
2007-01-31 09:41:11 +00:00
|
|
|
property ParentFont;
|
2006-03-24 05:56:59 +00:00
|
|
|
property OnClick;
|
2006-04-02 20:00:02 +00:00
|
|
|
property OnCollapsed;
|
|
|
|
property OnCollapsing;
|
2006-03-24 05:56:59 +00:00
|
|
|
property OnDblClick;
|
|
|
|
property OnEnter;
|
|
|
|
property OnExit;
|
2006-04-02 20:00:02 +00:00
|
|
|
property OnExpanded;
|
|
|
|
property OnExpanding;
|
2007-01-31 09:41:11 +00:00
|
|
|
property OnSelectedChanged;
|
2006-04-17 18:41:43 +00:00
|
|
|
property OnSelectedChanging;
|
2007-01-31 09:41:11 +00:00
|
|
|
{$IFDEF VER180}
|
2006-03-24 05:56:59 +00:00
|
|
|
property OnMouseActivate;
|
|
|
|
property OnMouseEnter;
|
|
|
|
property OnMouseLeave;
|
2007-01-31 09:41:11 +00:00
|
|
|
{$ENDIF}
|
|
|
|
property OnMouseDown;
|
2006-03-24 05:56:59 +00:00
|
|
|
property OnMouseMove;
|
|
|
|
property OnMouseUp;
|
|
|
|
property OnResize;
|
|
|
|
property Painter;
|
2006-04-02 20:00:02 +00:00
|
|
|
property Scrollbar;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Provides a wrapper for the DrawText API.
|
|
|
|
}
|
|
|
|
TDrawTextClipStyle = (csNone, csEllipsis, csPathEllipsis);
|
|
|
|
|
|
|
|
procedure DrawText(ACanvas: TCanvas; const AText: String;
|
|
|
|
const ABounds: TRect;
|
|
|
|
AHorzAlignment: TAlignment = taLeftJustify;
|
|
|
|
AVertAlignment: TVerticalAlignment = taVerticalCenter;
|
|
|
|
AMultiLine: Boolean = False;
|
|
|
|
AClipStyle: TDrawTextClipStyle = csNone);
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
{
|
|
|
|
:$ Returns a pointer to the first physical scanline.
|
|
|
|
|
|
|
|
:: In bottom-up bitmaps, the most common kind, the Scanline property
|
|
|
|
:: compensates for this by returning the last physical row for Scanline[0];
|
|
|
|
:: the first visual row. For most effects, the order in which the rows are
|
|
|
|
:: processed is not important; speed is. This function returns the first
|
|
|
|
:: physical scanline, which can be used as a single big array for the whole
|
|
|
|
:: bitmap.
|
|
|
|
|
|
|
|
:! Note that every scanline is padded until it is a multiple of 4 bytes
|
|
|
|
:! (32 bits). For true lineair access, ensure the bitmap has a PixelFormat
|
|
|
|
:! of pf32bit.
|
|
|
|
}
|
|
|
|
function GetScanlinePointer(ABitmap: Graphics.TBitmap): Pointer;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Wrapper for DrawFocusRect.
|
|
|
|
|
|
|
|
:: Ensures the canvas is set up correctly for a standard focus rectangle.
|
|
|
|
}
|
|
|
|
procedure DrawFocusRect(ACanvas: TCanvas; const ABounds: TRect);
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Draws one bitmap over another with the specified Alpha transparency.
|
|
|
|
|
|
|
|
:: Both bitmaps must be the same size.
|
|
|
|
}
|
|
|
|
procedure DrawBlended(ABackground, AForeground: Graphics.TBitmap; AAlpha: Byte);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
{ HitTest Codes }
|
|
|
|
htUnknown = 0;
|
|
|
|
htBackground = 1;
|
|
|
|
htGroup = 2;
|
|
|
|
htItem = 3;
|
2006-04-01 19:51:46 +00:00
|
|
|
htScroller = 4;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
type
|
|
|
|
PRGBAArray = ^TRGBAArray;
|
|
|
|
TRGBAArray = array[Word] of TRGBQuad;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
implementation
|
|
|
|
uses
|
2006-04-02 20:00:02 +00:00
|
|
|
SysUtils,
|
|
|
|
|
|
|
|
X2CLMenuBarAnimators;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
const
|
|
|
|
SDefaultItemCaption = 'Menu Item';
|
|
|
|
SDefaultGroupCaption = 'Group';
|
|
|
|
SNoPainter = 'Painter property not set';
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
type
|
|
|
|
TProtectedCollection = class(TCollection);
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
{ Convenience functions }
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure DrawText(ACanvas: TCanvas; const AText: String;
|
|
|
|
const ABounds: TRect; AHorzAlignment: TAlignment;
|
|
|
|
AVertAlignment: TVerticalAlignment;
|
|
|
|
AMultiLine: Boolean; AClipStyle: TDrawTextClipStyle);
|
|
|
|
const
|
|
|
|
HorzAlignmentFlags: array[TAlignment] of Cardinal =
|
|
|
|
(DT_LEFT, DT_RIGHT, DT_CENTER);
|
|
|
|
VertAlignmentFlags: array[TVerticalAlignment] of Cardinal =
|
|
|
|
(DT_TOP, DT_BOTTOM, DT_VCENTER);
|
|
|
|
MultiLineFlags: array[Boolean] of Cardinal =
|
|
|
|
(DT_SINGLELINE, 0);
|
|
|
|
ClipStyleFlags: array[TDrawTextClipStyle] of Cardinal =
|
|
|
|
(0, DT_END_ELLIPSIS, DT_PATH_ELLIPSIS);
|
|
|
|
|
|
|
|
var
|
|
|
|
flags: Cardinal;
|
|
|
|
bounds: TRect;
|
|
|
|
|
|
|
|
begin
|
2006-04-02 20:00:02 +00:00
|
|
|
flags := HorzAlignmentFlags[AHorzAlignment] or
|
2006-03-24 05:56:59 +00:00
|
|
|
VertAlignmentFlags[AVertAlignment] or
|
|
|
|
MultiLineFlags[AMultiLine] or
|
|
|
|
ClipStyleFlags[AClipStyle];
|
|
|
|
|
|
|
|
if AMultiLine and (AClipStyle <> csNone) then
|
|
|
|
flags := flags or DT_EDITCONTROL;
|
|
|
|
|
|
|
|
bounds := ABounds;
|
|
|
|
Windows.DrawText(ACanvas.Handle, PChar(AText), Length(AText), bounds, flags);
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
function GetScanlinePointer(ABitmap: Graphics.TBitmap): Pointer;
|
|
|
|
var
|
|
|
|
firstScanline: Pointer;
|
|
|
|
lastScanline: Pointer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
firstScanline := ABitmap.ScanLine[0];
|
|
|
|
lastScanline := ABitmap.ScanLine[Pred(ABitmap.Height)];
|
|
|
|
|
|
|
|
if Cardinal(firstScanline) > Cardinal(lastScanline) then
|
|
|
|
Result := lastScanline
|
|
|
|
else
|
|
|
|
Result := firstScanline;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure DrawFocusRect(ACanvas: TCanvas; const ABounds: TRect);
|
|
|
|
begin
|
|
|
|
SetTextColor(ACanvas.Handle, ColorToRGB(clBlack));
|
|
|
|
Windows.DrawFocusRect(ACanvas.Handle, ABounds);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure DrawBlended(ABackground, AForeground: Graphics.TBitmap; AAlpha: Byte);
|
|
|
|
var
|
|
|
|
sourcePixels: PRGBAArray;
|
|
|
|
destPixels: PRGBAArray;
|
|
|
|
sourcePixel: PRGBQuad;
|
|
|
|
pixelCount: Integer;
|
|
|
|
pixelIndex: Integer;
|
|
|
|
backAlpha: Integer;
|
|
|
|
foreAlpha: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
backAlpha := AAlpha;
|
|
|
|
foreAlpha := 256 - AAlpha;
|
|
|
|
pixelCount := AForeground.Width * AForeground.Height;
|
|
|
|
sourcePixels := GetScanlinePointer(AForeground);
|
|
|
|
destPixels := GetScanlinePointer(ABackground);
|
|
|
|
|
|
|
|
for pixelIndex := Pred(pixelCount) downto 0 do
|
|
|
|
with destPixels^[pixelIndex] do
|
|
|
|
begin
|
|
|
|
sourcePixel := @sourcePixels^[pixelIndex];
|
|
|
|
rgbRed := ((rgbRed * backAlpha) +
|
|
|
|
(sourcePixel^.rgbRed * foreAlpha)) shr 8;
|
|
|
|
rgbGreen := ((rgbGreen * backAlpha) +
|
|
|
|
(sourcePixel^.rgbGreen * foreAlpha)) shr 8;
|
|
|
|
rgbBlue := ((rgbBlue * backAlpha) +
|
|
|
|
(sourcePixel^.rgbBlue * foreAlpha)) shr 8;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
{ TX2CustomMenuBarPainter }
|
|
|
|
constructor TX2CustomMenuBarPainter.Create(AOwner: TComponent);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
if AOwner is TX2CustomMenuBar then
|
|
|
|
FMenuBar := TX2CustomMenuBar(AOwner);
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
destructor TX2CustomMenuBarPainter.Destroy();
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FObservers);
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.AttachObserver(AObserver: IX2MenuBarPainterObserver);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
if not Assigned(FObservers) then
|
|
|
|
FObservers := TInterfaceList.Create();
|
|
|
|
|
|
|
|
if FObservers.IndexOf(AObserver) = -1 then
|
|
|
|
FObservers.Add(AObserver);
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.DetachObserver(AObserver: IX2MenuBarPainterObserver);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
if Assigned(FObservers) then
|
|
|
|
FObservers.Remove(AObserver);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.BeginPaint(const AMenuBar: TX2CustomMenuBar);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Assert(not Assigned(FMenuBar), 'BeginPaint already called');
|
|
|
|
FMenuBar := AMenuBar;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.EndPaint();
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Assert(Assigned(FMenuBar), 'EndPaint without BeginPaint');
|
|
|
|
FMenuBar := nil;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.NotifyObservers();
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
|
|
|
observerIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if Assigned(FObservers) then
|
|
|
|
for observerIndex := 0 to Pred(FObservers.Count) do
|
|
|
|
(FObservers[observerIndex] as IX2MenuBarPainterObserver).PainterUpdate(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBarPainter.ApplyMargins(const ABounds: TRect): TRect;
|
|
|
|
begin
|
|
|
|
Result := ABounds;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBarPainter.GetGroupHeight(AGroup: TX2MenuBarGroup): Integer;
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
|
|
|
itemIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
2006-04-02 20:00:02 +00:00
|
|
|
Result := GetSpacing(seBeforeFirstItem) +
|
|
|
|
GetSpacing(seAfterLastItem);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
for itemIndex := 0 to Pred(AGroup.Items.Count) do
|
|
|
|
if MenuBar.ItemVisible(AGroup.Items[itemIndex]) then
|
|
|
|
Inc(Result, GetSpacing(seBeforeItem) +
|
|
|
|
GetItemHeight(AGroup.Items[itemIndex]) +
|
|
|
|
GetSpacing(seAfterItem));
|
2006-04-01 19:51:46 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.FindHit(Sender: TObject; Item: TX2CustomMenuBarItem; const MenuBounds, ItemBounds: TRect; Data: Pointer; var Abort: Boolean);
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
2006-03-30 04:54:11 +00:00
|
|
|
hitPoint: PPoint;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
hitPoint := Data;
|
|
|
|
Abort := PtInRect(ItemBounds, hitPoint^);
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBarPainter.HitTest(const APoint: TPoint): TX2MenuBarHitTest;
|
|
|
|
var
|
|
|
|
hitPoint: TPoint;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
hitPoint := APoint;
|
|
|
|
Result.HitTestCode := htUnknown;
|
|
|
|
Result.Item := MenuBar.IterateItemBounds(FindHit, @hitPoint);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
if Assigned(Result.Item) then
|
|
|
|
if Result.Item is TX2MenuBarGroup then
|
|
|
|
Result.HitTestCode := htGroup
|
|
|
|
else if Result.Item is TX2MenuBarItem then
|
|
|
|
Result.HitTestCode := htItem;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBarPainter.HitTest(AX, AY: Integer): TX2MenuBarHitTest;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Result := HitTest(Point(AX, AY));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBarPainter.GetMenuBar(): TX2CustomMenuBar;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Assert(Assigned(FMenuBar), 'BeginPaint not called');
|
|
|
|
Result := FMenuBar;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBarPainter.GetSpacing(AElement: TX2MenuBarSpacingElement): Integer;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
|
|
|
|
{ TX2CustomMenuBarAnimator }
|
|
|
|
constructor TX2CustomMenuBarAnimator.Create(AItemsBuffer: Graphics.TBitmap);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
inherited Create();
|
|
|
|
|
|
|
|
FStartTime := GetTickCount();
|
|
|
|
FItemsBuffer := Graphics.TBitmap.Create();
|
|
|
|
FItemsBuffer.Assign(AItemsBuffer);
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
destructor TX2CustomMenuBarAnimator.Destroy();
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FItemsBuffer);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
function TX2CustomMenuBarAnimator.GetHeight(): Integer;
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
Result := ItemsBuffer.Height;
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
function TX2CustomMenuBarAnimator.GetTimeElapsed(): Cardinal;
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
|
|
|
currentTime: Cardinal;
|
|
|
|
|
|
|
|
begin
|
|
|
|
currentTime := GetTickCount();
|
|
|
|
Result := currentTime - FStartTime;
|
|
|
|
|
|
|
|
if currentTime < FStartTime then
|
|
|
|
Inc(Result, High(Cardinal));
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure TX2CustomMenuBarAnimator.SetExpanding(const Value: Boolean);
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
FExpanding := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure TX2CustomMenuBarAnimator.Terminate();
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
FTerminated := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure TX2CustomMenuBarAnimator.Update();
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
{ TX2MenuBarActionLink }
|
|
|
|
procedure TX2MenuBarActionLink.AssignClient(AClient: TObject);
|
|
|
|
begin
|
|
|
|
FClient := (AClient as TX2CustomMenuBarItem);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2MenuBarActionLink.IsCaptionLinked(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := inherited IsCaptionLinked() and
|
|
|
|
(Client.Caption = (Action as TCustomAction).Caption);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2MenuBarActionLink.IsEnabledLinked(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := inherited IsCaptionLinked() and
|
|
|
|
(Client.Enabled = (Action as TCustomAction).Enabled);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2MenuBarActionLink.IsImageIndexLinked(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := inherited IsCaptionLinked() and
|
|
|
|
(Client.ImageIndex = (Action as TCustomAction).ImageIndex);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2MenuBarActionLink.IsVisibleLinked(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := inherited IsCaptionLinked() and
|
|
|
|
(Client.Visible = (Action as TCustomAction).Visible);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarActionLink.SetCaption(const Value: string);
|
|
|
|
begin
|
|
|
|
if IsCaptionLinked() then
|
|
|
|
Client.Caption := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarActionLink.SetEnabled(Value: Boolean);
|
|
|
|
begin
|
|
|
|
if IsEnabledLinked() then
|
|
|
|
Client.Enabled := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarActionLink.SetImageIndex(Value: Integer);
|
|
|
|
begin
|
|
|
|
if IsImageIndexLinked() then
|
|
|
|
Client.ImageIndex := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarActionLink.SetVisible(Value: Boolean);
|
|
|
|
begin
|
|
|
|
if IsVisibleLinked() then
|
|
|
|
Client.Visible := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2ComponentNotification }
|
|
|
|
procedure TX2ComponentNotification.Notification(AComponent: TComponent;
|
|
|
|
Operation: TOperation);
|
|
|
|
begin
|
|
|
|
if Assigned(FOnNotification) then
|
|
|
|
FOnNotification(Self, AComponent, Operation);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
{ TX2CustomMenuBarItem }
|
|
|
|
constructor TX2CustomMenuBarItem.Create(Collection: TCollection);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-04-02 20:00:02 +00:00
|
|
|
FEnabled := True;
|
2006-03-30 04:54:11 +00:00
|
|
|
FImageIndex := -1;
|
|
|
|
FOwnsData := True;
|
2006-04-02 20:00:02 +00:00
|
|
|
FVisible := True;
|
2006-04-17 18:41:43 +00:00
|
|
|
|
|
|
|
inherited;
|
2006-03-30 04:54:11 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TX2CustomMenuBarItem.Destroy();
|
|
|
|
begin
|
|
|
|
Data := nil;
|
2006-05-22 05:13:12 +00:00
|
|
|
FreeAndNil(FActionLink);
|
|
|
|
FreeAndNil(FNotification);
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
inherited;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
procedure TX2CustomMenuBarItem.Assign(Source: TPersistent);
|
|
|
|
begin
|
|
|
|
if Source is TX2CustomMenuBarItem then
|
|
|
|
with TX2CustomMenuBarItem(Source) do
|
|
|
|
begin
|
|
|
|
Self.Caption := Caption;
|
|
|
|
Self.Data := Data;
|
|
|
|
Self.OwnsData := OwnsData;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBarItem.DoActionChange(Sender: TObject);
|
|
|
|
begin
|
|
|
|
if Sender = Action then
|
|
|
|
ActionChange(Sender, False);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBarItem.ActionChange(Sender: TObject;
|
|
|
|
CheckDefaults: Boolean);
|
|
|
|
begin
|
|
|
|
if Sender is TCustomAction then
|
|
|
|
with TCustomAction(Sender) do
|
|
|
|
begin
|
|
|
|
if (not CheckDefaults) or (not Self.IsCaptionStored()) then
|
|
|
|
Self.Caption := Caption;
|
|
|
|
|
|
|
|
if (not CheckDefaults) or Self.Enabled then
|
|
|
|
Self.Enabled := Enabled;
|
|
|
|
|
|
|
|
if (not CheckDefaults) or (Self.ImageIndex = -1) then
|
|
|
|
Self.ImageIndex := ImageIndex;
|
|
|
|
|
|
|
|
if (not CheckDefaults) or Self.Visible then
|
|
|
|
Self.Visible := Visible;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomMenuBarItem.IsCaptionStored(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := (Length(Caption) > 0);
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBarItem.GetMenuBar(): TX2CustomMenuBar;
|
|
|
|
var
|
|
|
|
parentCollection: TCollection;
|
|
|
|
parentOwner: TPersistent;
|
2006-05-22 05:13:12 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
Result := nil;
|
|
|
|
parentCollection := Collection;
|
|
|
|
|
|
|
|
{ Traverse up the tree of CollectionItems and OwnedCollections until
|
|
|
|
we find a MenuBar... or not. }
|
|
|
|
while Assigned(parentCollection) do
|
|
|
|
begin
|
|
|
|
parentOwner := parentCollection.Owner;
|
|
|
|
if Assigned(parentOwner) then
|
|
|
|
begin
|
|
|
|
if parentOwner is TX2CustomMenuBar then
|
|
|
|
begin
|
|
|
|
Result := TX2CustomMenuBar(parentCollection.Owner);
|
|
|
|
break;
|
|
|
|
end else if parentOwner is TCollectionItem then
|
|
|
|
parentCollection := TCollectionItem(parentOwner).Collection;
|
|
|
|
end else
|
|
|
|
break;
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
procedure TX2CustomMenuBarItem.SetAction(const Value: TBasicAction);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-05-22 05:13:12 +00:00
|
|
|
if Value <> FAction then
|
|
|
|
begin
|
|
|
|
if Assigned(FAction) then
|
|
|
|
FAction.RemoveFreeNotification(FNotification);
|
|
|
|
|
|
|
|
FAction := Value;
|
|
|
|
|
|
|
|
if Assigned(FAction) then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-05-22 05:13:12 +00:00
|
|
|
if not Assigned(FActionLink) then
|
|
|
|
begin
|
|
|
|
FActionLink := TX2MenuBarActionLink.Create(Self);
|
|
|
|
FActionLink.OnChange := DoActionChange;
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
FActionLink.Action := Value;
|
|
|
|
|
|
|
|
if not Assigned(FNotification) then
|
|
|
|
FNotification := TX2ComponentNotification.Create(nil);
|
|
|
|
|
|
|
|
ActionChange(Value, csLoading in Value.ComponentState);
|
|
|
|
FAction.FreeNotification(FNotification);
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
FreeAndNil(FActionLink);
|
|
|
|
FreeAndNil(FNotification);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarItem.SetCaption(const Value: String);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
if Value <> FCaption then
|
|
|
|
begin
|
|
|
|
FCaption := Value;
|
|
|
|
Changed(False);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarItem.SetData(const Value: TObject);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
if Value <> FData then
|
|
|
|
begin
|
|
|
|
if FOwnsData then
|
|
|
|
FreeAndNil(FData);
|
|
|
|
|
|
|
|
FData := Value;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBarItem.SetEnabled(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FEnabled then
|
|
|
|
begin
|
|
|
|
FEnabled := Value;
|
|
|
|
Changed(False);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarItem.SetImageIndex(const Value: TImageIndex);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
if Value <> FImageIndex then
|
|
|
|
begin
|
|
|
|
FImageIndex := Value;
|
|
|
|
Changed(False);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBarItem.SetVisible(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FVisible then
|
|
|
|
begin
|
|
|
|
FVisible := Value;
|
|
|
|
Changed(False);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2CustomMenuBarItems }
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure TX2CustomMenuBarItems.Notify(Item: TCollectionItem; Action: TCollectionNotification);
|
|
|
|
begin
|
|
|
|
if Assigned(FOnNotify) then
|
|
|
|
FOnNotify(Self, Item, Action);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBarItems.Update(Item: TCollectionItem);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
if Assigned(FOnUpdate) then
|
|
|
|
FOnUpdate(Self, Item);
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
{ TX2MenuBarItem }
|
2006-04-17 18:41:43 +00:00
|
|
|
constructor TX2MenuBarItem.Create(Collection: TCollection);
|
|
|
|
begin
|
|
|
|
Caption := SDefaultItemCaption;
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
|
|
|
|
function TX2MenuBarItem.IsCaptionStored(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := (Caption <> SDefaultItemCaption);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2MenuBarItem.GetGroup(): TX2MenuBarGroup;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
if Assigned(Collection) and (Collection.Owner <> nil) and
|
|
|
|
(Collection.Owner is TX2MenuBarGroup) then
|
|
|
|
Result := TX2MenuBarGroup(Collection.Owner);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{ TX2MenuBarItems }
|
|
|
|
constructor TX2MenuBarItems.Create(AOwner: TPersistent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner, TX2MenuBarItem);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2MenuBarItems.Add(const ACaption: TCaption): TX2MenuBarItem;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarItem(inherited Add());
|
2006-04-17 18:41:43 +00:00
|
|
|
|
|
|
|
if Length(ACaption) > 0 then
|
|
|
|
Result.Caption := ACaption;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2MenuBarItems.GetItem(Index: Integer): TX2MenuBarItem;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarItem(inherited GetItem(Index));
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarItems.SetItem(Index: Integer; const Value: TX2MenuBarItem);
|
|
|
|
begin
|
|
|
|
inherited SetItem(Index, Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2MenuBarGroup }
|
|
|
|
constructor TX2MenuBarGroup.Create(Collection: TCollection);
|
|
|
|
begin
|
2006-04-17 18:41:43 +00:00
|
|
|
Caption := SDefaultGroupCaption;
|
2006-04-02 20:00:02 +00:00
|
|
|
FItems := TX2MenuBarItems.Create(Self);
|
2006-04-17 18:41:43 +00:00
|
|
|
FItems.OnNotify := ItemsNotify;
|
2006-04-02 20:00:02 +00:00
|
|
|
FItems.OnUpdate := ItemsUpdate;
|
2006-04-17 18:41:43 +00:00
|
|
|
|
|
|
|
{ This results in the Collection's Notification being called, which needs to
|
|
|
|
be after we create our Items property. }
|
|
|
|
inherited;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TX2MenuBarGroup.Destroy();
|
|
|
|
begin
|
|
|
|
FreeAndNil(FItems);
|
|
|
|
|
|
|
|
if OwnsData then
|
|
|
|
FreeAndNil(FData);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2MenuBarGroup.Assign(Source: TPersistent);
|
|
|
|
begin
|
|
|
|
if Source is TX2MenuBarGroup then
|
|
|
|
with TX2MenuBarGroup(Source) do
|
|
|
|
Self.Items.Assign(Items);
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
inherited;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
function TX2MenuBarGroup.GetSelectedItem(): Integer;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
Result := -1;
|
2007-01-31 09:41:11 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
if Items.Count > 0 then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
if (FSelectedItem >= 0) and (FSelectedItem < Items.Count) then
|
|
|
|
Result := FSelectedItem
|
|
|
|
else
|
|
|
|
Result := 0;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2MenuBarGroup.InternalSetExpanded(const Value: Boolean);
|
|
|
|
var
|
|
|
|
menu: TX2CustomMenuBar;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-04-02 20:00:02 +00:00
|
|
|
if Value <> FExpanded then
|
|
|
|
begin
|
|
|
|
FExpanded := Value;
|
|
|
|
Changed(False);
|
|
|
|
|
|
|
|
menu := MenuBar;
|
|
|
|
if Assigned(menu) then
|
|
|
|
menu.DoExpandedChanged(Self);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure TX2MenuBarGroup.ItemsNotify(Sender: TObject; Item: TCollectionItem; Action: TCollectionNotification);
|
|
|
|
begin
|
|
|
|
if Assigned(Self.Collection) then
|
|
|
|
TProtectedCollection(Self.Collection).Notify(Item, Action);
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2MenuBarGroup.ItemsUpdate(Sender: TObject; Item: TCollectionItem);
|
|
|
|
var
|
|
|
|
groupCollection: TProtectedCollection;
|
|
|
|
|
|
|
|
begin
|
|
|
|
groupCollection := TProtectedCollection(Self.Collection);
|
|
|
|
|
|
|
|
if Assigned(groupCollection) and (groupCollection.UpdateCount = 0) then
|
|
|
|
groupCollection.Update(Item);
|
|
|
|
end;
|
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
function TX2MenuBarGroup.IsCaptionStored(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := (Caption <> SDefaultGroupCaption);
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2MenuBarGroup.SetEnabled(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
inherited;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
if not Value then
|
|
|
|
Expanded := False;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarGroup.SetExpanded(const Value: Boolean);
|
|
|
|
var
|
|
|
|
menu: TX2CustomMenuBar;
|
|
|
|
|
|
|
|
begin
|
2006-04-02 20:00:02 +00:00
|
|
|
if (Value <> FExpanded) and
|
|
|
|
((not Value) or Enabled) then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
menu := MenuBar;
|
|
|
|
if Assigned(menu) then
|
2006-03-30 04:54:11 +00:00
|
|
|
menu.DoExpandedChanging(Self, Value)
|
|
|
|
else
|
|
|
|
InternalSetExpanded(Value);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarGroup.SetItems(const Value: TX2MenuBarItems);
|
|
|
|
begin
|
|
|
|
if Value <> FItems then
|
|
|
|
begin
|
|
|
|
FItems.Assign(Value);
|
|
|
|
Changed(False);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2MenuBarGroups }
|
|
|
|
constructor TX2MenuBarGroups.Create(AOwner: TPersistent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner, TX2MenuBarGroup);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2MenuBarGroups.Add(const ACaption: TCaption): TX2MenuBarGroup;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarGroup(inherited Add());
|
2006-04-17 18:41:43 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
if Length(ACaption) > 0 then
|
|
|
|
Result.Caption := ACaption;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2MenuBarGroups.GetItem(Index: Integer): TX2MenuBarGroup;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarGroup(inherited GetItem(Index));
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarGroups.SetItem(Index: Integer; const Value: TX2MenuBarGroup);
|
|
|
|
begin
|
|
|
|
inherited SetItem(Index, Value);
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{ TX2CustomMenuBar }
|
|
|
|
constructor TX2CustomMenuBar.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
FAllowCollapseAll := True;
|
|
|
|
FAnimationStyle := DefaultAnimationStyle;
|
|
|
|
FAnimationTime := DefaultAnimationTime;
|
2006-03-30 04:54:11 +00:00
|
|
|
FBorderStyle := bsNone;
|
2006-04-17 18:41:43 +00:00
|
|
|
FCursorGroup := crDefault;
|
|
|
|
FCursorItem := crDefault;
|
2006-03-30 04:54:11 +00:00
|
|
|
FExpandingGroups := TStringList.Create();
|
2006-04-02 20:00:02 +00:00
|
|
|
FGroups := TX2MenuBarGroups.Create(Self);
|
2006-04-17 18:41:43 +00:00
|
|
|
FGroups.OnNotify := GroupsNotify;
|
2006-04-02 20:00:02 +00:00
|
|
|
FGroups.OnUpdate := GroupsUpdate;
|
|
|
|
FHideScrollbar := True;
|
|
|
|
FScrollbar := True;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.CreateParams(var Params: TCreateParams);
|
|
|
|
const
|
|
|
|
BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
|
|
|
|
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
{ Source: TScrollBox.CreateParams
|
|
|
|
Applies the BorderStyle property. }
|
2006-03-24 05:56:59 +00:00
|
|
|
with Params do
|
|
|
|
begin
|
2006-04-02 20:00:02 +00:00
|
|
|
Style := Style or WS_VSCROLL or BorderStyles[FBorderStyle];
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
if NewStyleControls and Ctl3D and (FBorderStyle = bsSingle) then
|
|
|
|
begin
|
|
|
|
Style := Style and not WS_BORDER;
|
|
|
|
ExStyle := ExStyle or WS_EX_CLIENTEDGE;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure TX2CustomMenuBar.Loaded();
|
2007-01-31 09:41:11 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
UpdateScrollbar();
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
destructor TX2CustomMenuBar.Destroy();
|
|
|
|
begin
|
2006-04-01 19:51:46 +00:00
|
|
|
Animator := nil;
|
2007-01-31 09:41:11 +00:00
|
|
|
Painter := nil;
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
FreeAndNil(FExpandingGroups);
|
2006-03-24 05:56:59 +00:00
|
|
|
FreeAndNil(FGroups);
|
2007-01-31 09:41:11 +00:00
|
|
|
FreeAndNil(FBuffer);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
|
|
|
|
begin
|
|
|
|
Msg.Result := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.Paint();
|
|
|
|
var
|
2006-03-30 04:54:11 +00:00
|
|
|
bufferRect: TRect;
|
|
|
|
expand: Boolean;
|
|
|
|
group: TX2MenuBarGroup;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Assigned(Painter) then
|
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
if not Assigned(FBuffer) then
|
|
|
|
begin
|
|
|
|
FBuffer := Graphics.TBitmap.Create();
|
|
|
|
FBuffer.PixelFormat := pf32bit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if (FBuffer.Width <> Self.ClientWidth) or
|
|
|
|
(FBuffer.Height <> Self.ClientHeight) then
|
|
|
|
begin
|
|
|
|
FBuffer.Width := Self.ClientWidth;
|
|
|
|
FBuffer.Height := Self.ClientHeight;
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
bufferRect := Rect(0, 0, FBuffer.Width, FBuffer.Height);
|
|
|
|
FBuffer.Canvas.Font.Assign(Self.Font);
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
if Assigned(Animator) then
|
|
|
|
Animator.Update();
|
|
|
|
|
|
|
|
UpdateScrollbar();
|
|
|
|
Painter.BeginPaint(Self);
|
|
|
|
try
|
|
|
|
Painter.DrawBackground(FBuffer.Canvas, bufferRect);
|
|
|
|
DrawMenu(FBuffer.Canvas);
|
2006-03-24 05:56:59 +00:00
|
|
|
finally
|
2007-01-31 09:41:11 +00:00
|
|
|
Painter.EndPaint();
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
Self.Canvas.Draw(0, 0, FBuffer);
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
if Assigned(Animator) then
|
|
|
|
begin
|
|
|
|
if Animator.Terminated then
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
Animator.Group.InternalSetExpanded(Animator.Expanding);
|
2006-04-01 19:51:46 +00:00
|
|
|
Animator := nil;
|
2006-03-30 04:54:11 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
{ Prevent 100% CPU usage }
|
|
|
|
Sleep(5);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
TestMousePos();
|
|
|
|
Invalidate();
|
2006-03-30 04:54:11 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
{ Process animation queue }
|
|
|
|
if FExpandingGroups.Count > 0 then
|
|
|
|
begin
|
|
|
|
expand := (FExpandingGroups[0] = #1);
|
|
|
|
group := TX2MenuBarGroup(FExpandingGroups.Objects[0]);
|
|
|
|
FExpandingGroups.Delete(0);
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
DoExpand(group, expand);
|
2006-03-30 04:54:11 +00:00
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
DrawNoPainter(Self.Canvas, Self.ClientRect);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBar.GetDrawState(AItem: TX2CustomMenuBarItem): TX2MenuBarDrawStates;
|
|
|
|
function ItemGroup(AGroupItem: TX2CustomMenuBarItem): TX2MenuBarGroup;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
if AGroupItem is TX2MenuBarItem then
|
|
|
|
Result := TX2MenuBarItem(AGroupItem).Group;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Result := [];
|
|
|
|
|
|
|
|
if AItem = FHotItem then
|
|
|
|
Include(Result, mdsHot);
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
if AItem = SelectedItem then
|
2006-03-24 05:56:59 +00:00
|
|
|
Include(Result, mdsSelected);
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
if Assigned(FHotItem) and (AItem = ItemGroup(FHotItem)) then
|
|
|
|
Include(Result, mdsGroupHot);
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
if Assigned(SelectedItem) and (AItem = ItemGroup(SelectedItem)) then
|
2006-03-30 04:54:11 +00:00
|
|
|
Include(Result, mdsGroupSelected);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.DrawMenuItem(Sender: TObject;
|
|
|
|
Item: TX2CustomMenuBarItem;
|
|
|
|
const MenuBounds, ItemBounds: TRect;
|
|
|
|
Data: Pointer; var Abort: Boolean);
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
2006-03-30 04:54:11 +00:00
|
|
|
canvas: TCanvas;
|
|
|
|
drawState: TX2MenuBarDrawStates;
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
groupBounds: TRect;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
if ItemBounds.Top > MenuBounds.Bottom then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
Abort := True;
|
|
|
|
exit;
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
canvas := TCanvas(Data);
|
|
|
|
drawState := GetDrawState(Item);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
if Item is TX2MenuBarGroup then
|
|
|
|
begin
|
|
|
|
group := TX2MenuBarGroup(Item);
|
|
|
|
Painter.DrawGroupHeader(canvas, group, ItemBounds,
|
|
|
|
drawState);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
if Assigned(Animator) and (Animator.Group = group) then
|
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
groupBounds := MenuBounds;
|
|
|
|
groupBounds.Top := ItemBounds.Bottom +
|
|
|
|
Painter.GetSpacing(seAfterGroupHeader) +
|
|
|
|
Painter.GetSpacing(seBeforeFirstItem);
|
|
|
|
groupBounds.Bottom := groupBounds.Top + Animator.Height;
|
|
|
|
Animator.Draw(canvas, groupBounds);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
end else if Item is TX2MenuBarItem then
|
|
|
|
Painter.DrawItem(canvas, TX2MenuBarItem(Item), ItemBounds, drawState);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.DrawMenuItems(ACanvas: TCanvas; AGroup: TX2MenuBarGroup; const ABounds: TRect);
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
2006-03-30 04:54:11 +00:00
|
|
|
itemBounds: TRect;
|
2006-03-24 05:56:59 +00:00
|
|
|
itemIndex: Integer;
|
|
|
|
item: TX2MenuBarItem;
|
|
|
|
drawState: TX2MenuBarDrawStates;
|
|
|
|
|
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
Assert(Assigned(Painter), 'No Painter assigned');
|
2006-03-24 05:56:59 +00:00
|
|
|
itemBounds := ABounds;
|
2006-03-30 04:54:11 +00:00
|
|
|
Inc(itemBounds.Top, Painter.GetSpacing(seBeforeFirstItem));
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
for itemIndex := 0 to Pred(AGroup.Items.Count) do
|
|
|
|
begin
|
|
|
|
item := AGroup.Items[itemIndex];
|
2006-04-02 20:00:02 +00:00
|
|
|
if not ItemVisible(item) then
|
|
|
|
continue;
|
|
|
|
|
|
|
|
Inc(itemBounds.Top, Painter.GetSpacing(seBeforeItem));
|
2006-03-24 05:56:59 +00:00
|
|
|
itemBounds.Bottom := itemBounds.Top + Painter.GetItemHeight(item);
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
drawState := GetDrawState(item);
|
|
|
|
Painter.DrawItem(ACanvas, item, itemBounds, drawState);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
itemBounds.Top := itemBounds.Bottom + Painter.GetSpacing(seAfterItem);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure TX2CustomMenuBar.DrawMenu(ACanvas: TCanvas);
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
IterateItemBounds(DrawMenuItem, Pointer(ACanvas));
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.DrawNoPainter(ACanvas: TCanvas; const ABounds: TRect);
|
|
|
|
const
|
|
|
|
XorColor = $00FFD8CE; // RGB(206, 216, 255)
|
|
|
|
|
|
|
|
begin
|
|
|
|
with ACanvas do
|
|
|
|
begin
|
|
|
|
Brush.Color := clBtnFace;
|
|
|
|
FillRect(ABounds);
|
|
|
|
|
|
|
|
Pen.Style := psDot;
|
|
|
|
Pen.Mode := pmXor;
|
|
|
|
Pen.Color := XorColor;
|
|
|
|
Brush.Style := bsClear;
|
|
|
|
Rectangle(ABounds);
|
|
|
|
|
|
|
|
DrawText(ACanvas, SNoPainter, ABounds, taCenter);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
function TX2CustomMenuBar.GetAnimatorClass(): TX2CustomMenuBarAnimatorClass;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
case AnimationStyle of
|
|
|
|
asSlide: Result := TX2MenuBarSlideAnimator;
|
|
|
|
asDissolve: Result := TX2MenuBarDissolveAnimator;
|
|
|
|
asFade: Result := TX2MenuBarFadeAnimator;
|
|
|
|
asSlideFade: Result := TX2MenuBarSlideFadeAnimator;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBar.IterateItemBounds(ACallback: TX2MenuBarItemBoundsProc;
|
|
|
|
AData: Pointer): TX2CustomMenuBarItem;
|
|
|
|
var
|
|
|
|
groupIndex: Integer;
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
menuBounds: TRect;
|
|
|
|
itemBounds: TRect;
|
|
|
|
itemIndex: Integer;
|
|
|
|
item: TX2MenuBarItem;
|
|
|
|
abort: Boolean;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
Assert(Assigned(Painter), 'No Painter assigned');
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
Result := nil;
|
|
|
|
menuBounds := Painter.ApplyMargins(Self.ClientRect);
|
|
|
|
itemBounds := menuBounds;
|
2006-04-02 20:00:02 +00:00
|
|
|
OffsetRect(itemBounds, 0, -FScrollOffset);
|
2006-03-30 04:54:11 +00:00
|
|
|
abort := False;
|
|
|
|
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
begin
|
|
|
|
{ Group }
|
|
|
|
group := Groups[groupIndex];
|
2006-04-02 20:00:02 +00:00
|
|
|
if not ItemVisible(group) then
|
|
|
|
continue;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
Inc(itemBounds.Top, Painter.GetSpacing(seBeforeGroupHeader));
|
|
|
|
itemBounds.Bottom := itemBounds.Top +
|
|
|
|
Painter.GetGroupHeaderHeight(group);
|
|
|
|
|
|
|
|
ACallback(Self, group, menuBounds, itemBounds, AData, abort);
|
|
|
|
if abort then
|
|
|
|
begin
|
|
|
|
Result := group;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
|
|
|
|
itemBounds.Top := itemBounds.Bottom +
|
|
|
|
Painter.GetSpacing(seAfterGroupHeader);
|
|
|
|
|
|
|
|
if Assigned(Animator) and (Animator.Group = group) then
|
|
|
|
begin
|
|
|
|
{ Animated group }
|
|
|
|
Inc(itemBounds.Top, Animator.Height);
|
2007-01-31 09:41:11 +00:00
|
|
|
end else if group.Expanded and (group.Items.Count > 0) then
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
Inc(itemBounds.Top, Painter.GetSpacing(seBeforeFirstItem));
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
for itemIndex := 0 to Pred(group.Items.Count) do
|
|
|
|
begin
|
|
|
|
{ Item }
|
|
|
|
item := group.Items[itemIndex];
|
2006-04-02 20:00:02 +00:00
|
|
|
if not ItemVisible(item) then
|
|
|
|
continue;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
Inc(itemBounds.Top, Painter.GetSpacing(seBeforeItem));
|
|
|
|
itemBounds.Bottom := itemBounds.Top + Painter.GetItemHeight(item);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
ACallback(Self, item, menuBounds, itemBounds, AData, abort);
|
|
|
|
if abort then
|
|
|
|
begin
|
|
|
|
Result := item;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
|
|
|
|
itemBounds.Top := itemBounds.Bottom +
|
|
|
|
Painter.GetSpacing(seAfterItem);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Inc(itemBounds.Top, Painter.GetSpacing(seAfterLastItem));
|
|
|
|
end;
|
|
|
|
|
|
|
|
if abort then
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.DoExpandedChanging(AGroup: TX2MenuBarGroup;
|
|
|
|
AExpanding: Boolean);
|
|
|
|
function ExpandedGroupsCount(): Integer;
|
|
|
|
var
|
|
|
|
groupIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
if Groups[groupIndex].Expanded then
|
|
|
|
Inc(Result);
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
var
|
|
|
|
allowed: Boolean;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
if csLoading in ComponentState then
|
|
|
|
begin
|
|
|
|
AGroup.InternalSetExpanded(AExpanding);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
if AGroup.Items.Count > 0 then
|
2006-04-02 20:00:02 +00:00
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
allowed := True;
|
|
|
|
if AExpanding then
|
|
|
|
begin
|
|
|
|
if Assigned(FOnExpanding) then
|
|
|
|
FOnExpanding(Self, AGroup, allowed);
|
|
|
|
end else
|
|
|
|
if Assigned(FOnCollapsing) then
|
|
|
|
FOnCollapsing(Self, AGroup, allowed);
|
2006-04-02 20:00:02 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
if not allowed then
|
2006-04-17 18:41:43 +00:00
|
|
|
exit;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
{ Pretend to auto select item - required for proper functioning of
|
|
|
|
the OnSelectedChanging event }
|
|
|
|
if AutoSelectItem then
|
|
|
|
if not DoAutoSelectItem(AGroup, saBefore) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
{ Allow collapse all }
|
|
|
|
if not (AExpanding or AllowCollapseAll) then
|
|
|
|
if ExpandedGroupsCount() = 1 then
|
|
|
|
begin
|
|
|
|
if AExpanding and (not Assigned(SelectedItem)) then
|
|
|
|
SelectedItem := AGroup;
|
|
|
|
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
{ Auto collapse }
|
2006-04-02 20:00:02 +00:00
|
|
|
if AutoCollapse then
|
2006-03-30 04:54:11 +00:00
|
|
|
if AExpanding then
|
2006-04-02 20:00:02 +00:00
|
|
|
DoAutoCollapse(AGroup);
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
if AGroup.Items.Count > 0 then
|
|
|
|
DoExpand(AGroup, AExpanding)
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
AGroup.InternalSetExpanded(AExpanding);
|
|
|
|
SelectedItem := AGroup
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.DoExpandedChanged(AGroup: TX2MenuBarGroup);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-04-02 20:00:02 +00:00
|
|
|
if AGroup.Expanded then
|
|
|
|
begin
|
2006-04-17 18:41:43 +00:00
|
|
|
{ Auto select item }
|
|
|
|
if AutoSelectItem then
|
|
|
|
DoAutoSelectItem(AGroup, saAfter);
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
if Assigned(FOnExpanded) then
|
|
|
|
FOnExpanded(Self, AGroup);
|
|
|
|
end else
|
|
|
|
if Assigned(FOnCollapsed) then
|
|
|
|
FOnCollapsed(Self, AGroup);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure TX2CustomMenuBar.DoSelectedChanging(ANewItem: TX2CustomMenuBarItem;
|
|
|
|
var AAllowed: Boolean);
|
|
|
|
begin
|
|
|
|
if Assigned(FOnSelectedChanging) then
|
|
|
|
FOnSelectedChanging(Self, SelectedItem, ANewItem, AAllowed);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.DoSelectedChanged();
|
|
|
|
begin
|
|
|
|
if Assigned(FOnSelectedChanged) then
|
|
|
|
FOnSelectedChanged(Self, SelectedItem);
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
function TX2CustomMenuBar.AllowInteraction(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := not Assigned(Animator);
|
|
|
|
end;
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
function TX2CustomMenuBar.ItemEnabled(AItem: TX2CustomMenuBarItem): Boolean;
|
|
|
|
begin
|
|
|
|
Result := AItem.Enabled and AItem.Visible;
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
function TX2CustomMenuBar.ItemVisible(AItem: TX2CustomMenuBarItem): Boolean;
|
|
|
|
begin
|
|
|
|
Result := AItem.Visible or (csDesigning in ComponentState);
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure TX2CustomMenuBar.DoExpand(AGroup: TX2MenuBarGroup;
|
|
|
|
AExpanding: Boolean);
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
2006-04-01 19:51:46 +00:00
|
|
|
animatorClass: TX2CustomMenuBarAnimatorClass;
|
2006-03-24 05:56:59 +00:00
|
|
|
itemsBuffer: Graphics.TBitmap;
|
|
|
|
itemsBounds: TRect;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if not Assigned(Painter) then
|
|
|
|
exit;
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
if AGroup.Items.Count = 0 then
|
|
|
|
begin
|
|
|
|
AGroup.InternalSetExpanded(AExpanding);
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
if Assigned(Animator) then
|
|
|
|
begin
|
|
|
|
FExpandingGroups.AddObject(Chr(Ord(AExpanding)), AGroup);
|
|
|
|
end else
|
|
|
|
begin
|
2006-04-02 20:00:02 +00:00
|
|
|
animatorClass := GetAnimatorClass();
|
|
|
|
if Assigned(animatorClass) and not (csDesigning in ComponentState) then
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
Painter.BeginPaint(Self);
|
|
|
|
try
|
|
|
|
itemsBuffer := Graphics.TBitmap.Create();
|
|
|
|
try
|
|
|
|
itemsBounds := Painter.ApplyMargins(Self.ClientRect);
|
2006-04-01 19:51:46 +00:00
|
|
|
itemsBuffer.PixelFormat := pf32bit;
|
2006-03-30 04:54:11 +00:00
|
|
|
itemsBuffer.Width := itemsBounds.Right - itemsBounds.Left;
|
|
|
|
itemsBuffer.Height := Painter.GetGroupHeight(AGroup);
|
|
|
|
itemsBounds := Rect(0, 0, itemsBuffer.Width, itemsBuffer.Height);
|
2006-04-01 19:51:46 +00:00
|
|
|
itemsBuffer.Canvas.Font.Assign(Self.Font);
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
// #ToDo3 (MvR) 23-3-2006: this will probably cause problems if we ever
|
|
|
|
// want a bitmapped/customdrawn background.
|
|
|
|
// Maybe we can trick around a bit with the
|
|
|
|
// canvas offset? think about it later.
|
|
|
|
Painter.DrawBackground(itemsBuffer.Canvas, itemsBounds);
|
|
|
|
DrawMenuItems(itemsBuffer.Canvas, AGroup, itemsBounds);
|
|
|
|
|
|
|
|
Animator := animatorClass.Create(itemsBuffer);
|
2006-04-02 20:00:02 +00:00
|
|
|
Animator.AnimationTime := AnimationTime;
|
2006-03-30 04:54:11 +00:00
|
|
|
Animator.Expanding := AExpanding;
|
|
|
|
Animator.Group := AGroup;
|
|
|
|
finally
|
|
|
|
FreeAndNil(itemsBuffer);
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
Painter.EndPaint();
|
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
AGroup.InternalSetExpanded(AExpanding);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBar.DoAutoCollapse(AGroup: TX2MenuBarGroup);
|
2006-03-30 04:54:11 +00:00
|
|
|
var
|
|
|
|
expandedGroup: TX2MenuBarGroup;
|
|
|
|
groupIndex: Integer;
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
|
|
|
|
begin
|
|
|
|
expandedGroup := AGroup;
|
|
|
|
if not Assigned(expandedGroup) then
|
|
|
|
begin
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
if Groups[groupIndex].Expanded then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
expandedGroup := Groups[groupIndex];
|
|
|
|
break;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
if not Assigned(expandedGroup) then
|
|
|
|
if Groups.Count > 0 then
|
|
|
|
begin
|
|
|
|
expandedGroup := Groups[0];
|
|
|
|
expandedGroup.Expanded := True;
|
|
|
|
end else
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
begin
|
|
|
|
group := Groups[groupIndex];
|
|
|
|
|
|
|
|
if (group <> expandedGroup) and (group.Expanded) then
|
|
|
|
DoExpand(group, False);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
function TX2CustomMenuBar.DoAutoSelectItem(AGroup: TX2MenuBarGroup;
|
|
|
|
AAction: TX2MenuBarSelectAction): Boolean;
|
2006-03-30 04:54:11 +00:00
|
|
|
var
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
groupIndex: Integer;
|
2006-04-17 18:41:43 +00:00
|
|
|
newItem: TX2CustomMenuBarItem;
|
2007-01-31 09:41:11 +00:00
|
|
|
itemIndex: Integer;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
begin
|
2006-04-17 18:41:43 +00:00
|
|
|
Result := True;
|
|
|
|
group := AGroup;
|
2006-03-30 04:54:11 +00:00
|
|
|
if not Assigned(group) then
|
|
|
|
begin
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
if Groups[groupIndex].Expanded then
|
|
|
|
begin
|
|
|
|
group := Groups[groupIndex];
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if (not Assigned(group)) and (Groups.Count > 0) then
|
|
|
|
begin
|
|
|
|
group := Groups[0];
|
|
|
|
group.Expanded := True;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
if not Assigned(group) then
|
|
|
|
exit;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
if group.Items.Count > 0 then
|
|
|
|
begin
|
2006-04-17 18:41:43 +00:00
|
|
|
newItem := group.Items[group.SelectedItem];
|
2007-01-31 09:41:11 +00:00
|
|
|
if not ItemEnabled(newItem) then
|
|
|
|
begin
|
|
|
|
newItem := nil;
|
2006-04-17 18:41:43 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
for itemIndex := 0 to Pred(group.Items.Count) do
|
|
|
|
if ItemEnabled(group.Items[itemIndex]) then
|
|
|
|
begin
|
|
|
|
newItem := group.Items[itemIndex];
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Assigned(newItem) and (newItem <> SelectedItem) then
|
2006-04-17 18:41:43 +00:00
|
|
|
begin
|
|
|
|
if AAction in [saBefore, saBoth] then
|
|
|
|
DoSelectedChanging(newItem, Result);
|
|
|
|
|
|
|
|
if Result and (AAction in [saAfter, saBoth]) then
|
2007-01-31 09:41:11 +00:00
|
|
|
SelectedItem := newItem;
|
2006-04-17 18:41:43 +00:00
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
procedure TX2CustomMenuBar.ResetGroupsSelectedItem;
|
|
|
|
var
|
|
|
|
groupIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
Groups[groupIndex].SelectedItem := -1;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBar.HitTest(const APoint: TPoint): TX2MenuBarHitTest;
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
|
|
|
hitPoint: TPoint;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result.HitTestCode := htUnknown;
|
|
|
|
Result.Item := nil;
|
|
|
|
hitPoint := APoint;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
if PtInRect(Self.ClientRect, APoint) then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Painter.BeginPaint(Self);
|
|
|
|
try
|
|
|
|
Result := Painter.HitTest(hitPoint);
|
|
|
|
finally
|
|
|
|
Painter.EndPaint();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.HitTest(AX, AY: Integer): TX2MenuBarHitTest;
|
|
|
|
begin
|
|
|
|
Result := HitTest(Point(AX, AY));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
function TX2CustomMenuBar.Iterate(ACallback: TX2MenuBarIterateProc;
|
|
|
|
ADirection: TX2MenuBarDirection;
|
|
|
|
AData: Pointer;
|
|
|
|
AStart: TX2CustomMenuBarItem): TX2CustomMenuBarItem;
|
|
|
|
procedure MoveIndex(var AIndex: Integer);
|
|
|
|
begin
|
|
|
|
case ADirection of
|
|
|
|
mbdUp: Dec(AIndex);
|
|
|
|
mbdDown: Inc(AIndex);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
abort: Boolean;
|
|
|
|
groupIndex: Integer;
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
itemIndex: Integer;
|
|
|
|
item: TX2MenuBarItem;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
groupIndex := 0;
|
|
|
|
itemIndex := -2;
|
|
|
|
abort := False;
|
|
|
|
|
|
|
|
if Assigned(AStart) then
|
|
|
|
begin
|
|
|
|
if AStart is TX2MenuBarItem then
|
|
|
|
begin
|
|
|
|
groupIndex := TX2MenuBarItem(AStart).Group.Index;
|
|
|
|
itemIndex := AStart.Index;
|
|
|
|
MoveIndex(itemIndex);
|
|
|
|
end else
|
|
|
|
groupIndex := AStart.Index;
|
|
|
|
end;
|
|
|
|
|
|
|
|
while (groupIndex >= 0) and (groupIndex < Groups.Count) do
|
|
|
|
begin
|
|
|
|
group := Groups[groupIndex];
|
|
|
|
|
|
|
|
if group.Items.Count = 0 then
|
|
|
|
begin
|
|
|
|
if group <> AStart then
|
|
|
|
begin
|
|
|
|
ACallback(Self, group, AData, abort);
|
|
|
|
if abort then
|
|
|
|
begin
|
|
|
|
Result := group;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
if itemIndex = -2 then
|
|
|
|
case ADirection of
|
|
|
|
mbdUp: itemIndex := Pred(group.Items.Count);
|
|
|
|
mbdDown: itemIndex := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
while (itemIndex >= 0) and (itemIndex < group.Items.Count) do
|
|
|
|
begin
|
|
|
|
item := group.Items[itemIndex];
|
|
|
|
|
|
|
|
ACallback(Self, item, AData, abort);
|
|
|
|
if abort then
|
|
|
|
begin
|
|
|
|
Result := item;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
|
|
|
|
MoveIndex(itemIndex);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Assigned(Result) then
|
|
|
|
Break;
|
|
|
|
|
|
|
|
itemIndex := -2;
|
|
|
|
MoveIndex(groupIndex);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.FindEnabledItem(Sender: TObject;
|
|
|
|
Item: TX2CustomMenuBarItem;
|
|
|
|
Data: Pointer;
|
|
|
|
var Abort: Boolean);
|
|
|
|
begin
|
|
|
|
Abort := ItemEnabled(Item);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
function TX2CustomMenuBar.SelectFirst(): TX2CustomMenuBarItem;
|
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
if AllowInteraction then
|
|
|
|
begin
|
|
|
|
Result := Iterate(FindEnabledItem);
|
|
|
|
if Assigned(Result) then
|
|
|
|
SelectedItem := Result;
|
|
|
|
end;
|
2006-05-22 05:13:12 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.SelectLast(): TX2CustomMenuBarItem;
|
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
if AllowInteraction then
|
|
|
|
begin
|
|
|
|
Result := Iterate(FindEnabledItem, mbdDown);
|
|
|
|
if Assigned(Result) then
|
|
|
|
SelectedItem := Result;
|
|
|
|
end;
|
2006-05-22 05:13:12 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.SelectNext(): TX2CustomMenuBarItem;
|
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
if AllowInteraction then
|
|
|
|
begin
|
|
|
|
Result := Iterate(FindEnabledItem, mbdDown, nil, FSelectedItem);
|
|
|
|
if Assigned(Result) then
|
|
|
|
SelectedItem := Result;
|
|
|
|
end;
|
2006-05-22 05:13:12 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.SelectPrior(): TX2CustomMenuBarItem;
|
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
if AllowInteraction then
|
|
|
|
begin
|
|
|
|
Result := Iterate(FindEnabledItem, mbdUp, nil, FSelectedItem);
|
|
|
|
if Assigned(Result) then
|
|
|
|
SelectedItem := Result;
|
|
|
|
end;
|
2006-05-22 05:13:12 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.SelectGroup(AIndex: Integer): TX2MenuBarGroup;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
2007-01-31 09:41:11 +00:00
|
|
|
|
|
|
|
if AllowInteraction then
|
|
|
|
begin
|
|
|
|
if (AIndex >= 0) and (AIndex < Groups.Count) then
|
|
|
|
begin
|
|
|
|
Result := Groups[AIndex];
|
|
|
|
SelectedItem := Result;
|
|
|
|
end;
|
|
|
|
end;
|
2006-05-22 05:13:12 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.SelectItem(AIndex: Integer;
|
|
|
|
AGroup: TX2MenuBarGroup): TX2CustomMenuBarItem;
|
2007-01-31 09:41:11 +00:00
|
|
|
var
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
groupIndex: Integer;
|
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
begin
|
|
|
|
Result := nil;
|
2007-01-31 09:41:11 +00:00
|
|
|
|
|
|
|
if AllowInteraction then
|
|
|
|
begin
|
|
|
|
group := AGroup;
|
|
|
|
if not Assigned(group) then
|
|
|
|
begin
|
|
|
|
if Assigned(SelectedItem) then
|
|
|
|
begin
|
|
|
|
if SelectedItem is TX2MenuBarItem then
|
|
|
|
group := TX2MenuBarItem(SelectedItem).Group
|
|
|
|
else
|
|
|
|
group := (SelectedItem as TX2MenuBarGroup);
|
|
|
|
end else
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
if Groups[groupIndex].Expanded then
|
|
|
|
begin
|
|
|
|
group := Groups[groupIndex];
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Assigned(group) and (AIndex >= 0) and (AIndex < group.Items.Count) then
|
|
|
|
begin
|
|
|
|
Result := group.Items[AIndex];
|
|
|
|
SelectedItem := Result;
|
|
|
|
end;
|
|
|
|
end;
|
2006-05-22 05:13:12 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.SelectItem(AIndex, AGroup: Integer): TX2CustomMenuBarItem;
|
|
|
|
var
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
|
|
|
|
begin
|
|
|
|
group := nil;
|
|
|
|
if (AGroup > 0) and (AGroup < Groups.Count) then
|
|
|
|
group := Groups[AGroup];
|
|
|
|
|
|
|
|
Result := SelectItem(AIndex, group);
|
|
|
|
end;
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
function TX2CustomMenuBar.SelectItem(AIndex: Integer): TX2CustomMenuBarItem;
|
|
|
|
begin
|
|
|
|
Result := SelectItem(AIndex, nil);
|
|
|
|
end;
|
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure TX2CustomMenuBar.Notification(AComponent: TComponent; Operation: TOperation);
|
|
|
|
begin
|
|
|
|
if Operation = opRemove then
|
|
|
|
if AComponent = FPainter then
|
|
|
|
begin
|
|
|
|
FPainter := nil;
|
|
|
|
Invalidate();
|
2006-04-17 18:41:43 +00:00
|
|
|
end else if AComponent = FImages then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-04-17 18:41:43 +00:00
|
|
|
FImages := nil;
|
2006-03-24 05:56:59 +00:00
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.PainterUpdate(Sender: TX2CustomMenuBarPainter);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure TX2CustomMenuBar.GroupsNotify(Sender: TObject; Item: TCollectionItem; Action: TCollectionNotification);
|
|
|
|
begin
|
|
|
|
if Action = cnDeleting then
|
|
|
|
if Item = SelectedItem then
|
|
|
|
SelectedItem := nil
|
|
|
|
else if Item = FHotItem then
|
|
|
|
FHotItem := nil;
|
|
|
|
|
|
|
|
if Assigned(Designer) then
|
|
|
|
case Action of
|
|
|
|
cnAdded: Designer.ItemAdded(Item as TX2CustomMenuBarItem);
|
|
|
|
cnDeleting: Designer.ItemDeleting(Item as TX2CustomMenuBarItem);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if TProtectedCollection(Item.Collection).UpdateCount = 0 then
|
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBar.GroupsUpdate(Sender: TObject; Item: TCollectionItem);
|
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
if Assigned(SelectedItem) and (not ItemEnabled(SelectedItem)) then
|
2006-04-17 18:41:43 +00:00
|
|
|
SelectedItem := nil;
|
|
|
|
|
|
|
|
if Assigned(Designer) then
|
|
|
|
Designer.ItemModified(Item as TX2CustomMenuBarItem);
|
2006-04-02 20:00:02 +00:00
|
|
|
|
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
|
|
|
X, Y: Integer);
|
|
|
|
var
|
|
|
|
hitTest: TX2MenuBarHitTest;
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
|
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
if Button = mbLeft then
|
|
|
|
if AllowInteraction then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
hitTest := Self.HitTest(X, Y);
|
|
|
|
|
|
|
|
if hitTest.HitTestCode = htGroup then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
group := TX2MenuBarGroup(hitTest.Item);
|
2007-01-31 09:41:11 +00:00
|
|
|
if ItemEnabled(group) then
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
group.Expanded := not group.Expanded;
|
2006-04-17 18:41:43 +00:00
|
|
|
hitTest.Item := SelectedItem;
|
2006-03-30 04:54:11 +00:00
|
|
|
Invalidate();
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
if Assigned(hitTest.Item) then
|
2006-04-17 18:41:43 +00:00
|
|
|
SelectedItem := hitTest.Item;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.MouseMove(Shift: TShiftState; X, Y: Integer);
|
2006-04-17 18:41:43 +00:00
|
|
|
var
|
|
|
|
cursor: TCursor;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
FLastMousePos := Point(X, Y);
|
|
|
|
TestMousePos();
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
cursor := crDefault;
|
|
|
|
if Assigned(FHotItem) then
|
|
|
|
if FHotItem is TX2MenuBarGroup then
|
|
|
|
cursor := CursorGroup
|
|
|
|
else if FHotItem is TX2MenuBarItem then
|
|
|
|
cursor := CursorItem;
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
if (cursor <> crDefault) and ItemEnabled(FHotItem) then
|
2006-04-17 18:41:43 +00:00
|
|
|
begin
|
|
|
|
Windows.SetCursor(Screen.Cursors[cursor]);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
//procedure TX2CustomMenuBar.MouseUp(Button: TMouseButton; Shift: TShiftState;
|
|
|
|
// X, Y: Integer);
|
|
|
|
//begin
|
|
|
|
// inherited;
|
|
|
|
//end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBar.CMMouseLeave(var Msg: TMessage);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
FLastMousePos := Point(-1, -1);
|
|
|
|
FHotItem := nil;
|
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.WMVScroll(var Msg: TWMVScroll);
|
|
|
|
var
|
|
|
|
scrollInfo: TScrollInfo;
|
|
|
|
scrollPos: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Msg.Result := 0;
|
|
|
|
if Msg.ScrollCode = SB_ENDSCROLL then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
scrollPos := -1;
|
|
|
|
|
|
|
|
FillChar(scrollInfo, SizeOf(TScrollInfo), #0);
|
|
|
|
scrollInfo.cbSize := SizeOf(TScrollInfo);
|
|
|
|
|
|
|
|
if Msg.ScrollCode = SB_THUMBTRACK then
|
|
|
|
begin
|
|
|
|
scrollInfo.fMask := SIF_TRACKPOS;
|
|
|
|
if GetScrollInfo(Self.Handle, SB_VERT, scrollInfo) then
|
|
|
|
scrollPos := scrollInfo.nTrackPos;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
scrollInfo.fMask := SIF_RANGE or SIF_POS or SIF_PAGE;
|
|
|
|
if GetScrollInfo(Self.Handle, SB_VERT, scrollInfo) then
|
|
|
|
case Msg.ScrollCode of
|
|
|
|
SB_BOTTOM:
|
|
|
|
scrollPos := scrollInfo.nMax;
|
|
|
|
|
|
|
|
// #ToDo2 (MvR) 2-4-2006: scroll to the next item
|
|
|
|
// (needs GetTopItem implementation)
|
|
|
|
SB_LINEDOWN:
|
|
|
|
begin
|
|
|
|
scrollPos := scrollInfo.nPos + 40;
|
|
|
|
if scrollPos > scrollInfo.nMax then
|
|
|
|
scrollPos := scrollInfo.nMax;
|
|
|
|
end;
|
|
|
|
SB_LINEUP:
|
|
|
|
begin
|
|
|
|
scrollPos := scrollInfo.nPos - 40;
|
|
|
|
if scrollPos < scrollInfo.nMin then
|
|
|
|
scrollPos := scrollInfo.nMin;
|
|
|
|
end;
|
|
|
|
|
|
|
|
SB_PAGEDOWN:
|
|
|
|
begin
|
|
|
|
scrollPos := scrollInfo.nPos + Integer(scrollInfo.nPage);
|
|
|
|
if scrollPos > scrollInfo.nMax then
|
|
|
|
scrollPos := scrollInfo.nMax;
|
|
|
|
end;
|
|
|
|
SB_PAGEUP:
|
|
|
|
begin
|
|
|
|
scrollPos := scrollInfo.nPos - Integer(scrollInfo.nPage);
|
|
|
|
if scrollPos < scrollInfo.nMin then
|
|
|
|
scrollPos := scrollInfo.nMin;
|
|
|
|
end;
|
|
|
|
SB_TOP:
|
|
|
|
scrollPos := 0;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if scrollPos <> -1 then
|
|
|
|
begin
|
|
|
|
FillChar(scrollInfo, SizeOf(TScrollInfo), #0);
|
|
|
|
scrollInfo.cbSize := SizeOf(TScrollInfo);
|
|
|
|
scrollInfo.fMask := SIF_POS;
|
|
|
|
scrollInfo.nPos := scrollPos;
|
|
|
|
|
|
|
|
SetScrollInfo(Self.Handle, SB_VERT, scrollInfo, False);
|
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure TX2CustomMenuBar.TestMousePos();
|
|
|
|
var
|
|
|
|
hitTest: TX2MenuBarHitTest;
|
|
|
|
|
|
|
|
begin
|
|
|
|
hitTest := Self.HitTest(FLastMousePos.X, FLastMousePos.Y);
|
|
|
|
if hitTest.Item <> FHotItem then
|
|
|
|
begin
|
|
|
|
FHotItem := hitTest.Item;
|
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
function TX2CustomMenuBar.GetMenuHeight(): Integer;
|
|
|
|
var
|
|
|
|
groupIndex: Integer;
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
menuBounds: TRect;
|
|
|
|
itemIndex: Integer;
|
|
|
|
item: TX2MenuBarItem;
|
|
|
|
|
|
|
|
begin
|
2006-04-02 20:00:02 +00:00
|
|
|
if not Assigned(Painter) then
|
|
|
|
begin
|
|
|
|
Result := -1;
|
|
|
|
exit;
|
|
|
|
end;
|
2006-04-01 19:51:46 +00:00
|
|
|
|
|
|
|
menuBounds := Painter.ApplyMargins(Self.ClientRect);
|
|
|
|
Result := Self.ClientHeight - (menuBounds.Bottom - menuBounds.Top);
|
|
|
|
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
begin
|
|
|
|
{ Group }
|
|
|
|
group := Groups[groupIndex];
|
2006-04-02 20:00:02 +00:00
|
|
|
if not ItemVisible(group) then
|
|
|
|
continue;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
Inc(Result, Painter.GetSpacing(seBeforeGroupHeader) +
|
|
|
|
Painter.GetGroupHeaderHeight(group) +
|
|
|
|
Painter.GetSpacing(seAfterGroupHeader));
|
|
|
|
|
|
|
|
if Assigned(Animator) and (Animator.Group = group) then
|
|
|
|
begin
|
|
|
|
{ Animated group }
|
|
|
|
Inc(Result, Animator.Height);
|
|
|
|
end else if group.Expanded then
|
|
|
|
begin
|
|
|
|
Inc(Result, Painter.GetSpacing(seBeforeFirstItem));
|
|
|
|
|
|
|
|
for itemIndex := 0 to Pred(group.Items.Count) do
|
|
|
|
begin
|
|
|
|
{ Item }
|
|
|
|
item := group.Items[itemIndex];
|
2006-04-02 20:00:02 +00:00
|
|
|
if not ItemVisible(item) then
|
|
|
|
continue;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
Inc(Result, Painter.GetSpacing(seBeforeItem) +
|
|
|
|
Painter.GetItemHeight(item) +
|
|
|
|
Painter.GetSpacing(seAfterItem));
|
|
|
|
end;
|
|
|
|
|
|
|
|
Inc(Result, Painter.GetSpacing(seAfterLastItem));
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBar.UpdateScrollbar();
|
|
|
|
var
|
|
|
|
scrollInfo: TScrollInfo;
|
|
|
|
|
|
|
|
begin
|
|
|
|
{ Don't update the scrollbar while animating, prevents issues with the
|
|
|
|
items buffer width if the scrollbar happens to show/hide during animation. }
|
|
|
|
if Assigned(Animator) then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
FillChar(scrollInfo, SizeOf(TScrollInfo), #0);
|
|
|
|
scrollInfo.cbSize := SizeOf(TScrollInfo);
|
|
|
|
scrollInfo.fMask := SIF_PAGE or SIF_RANGE;
|
|
|
|
|
|
|
|
if Scrollbar then
|
|
|
|
begin
|
|
|
|
scrollInfo.nMin := 0;
|
|
|
|
scrollInfo.nMax := GetMenuHeight();
|
|
|
|
scrollInfo.nPage := Self.ClientHeight;
|
|
|
|
|
|
|
|
if not HideScrollbar then
|
|
|
|
scrollInfo.fMask := scrollInfo.fMask or SIF_DISABLENOSCROLL;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
scrollInfo.nMin := 0;
|
|
|
|
scrollInfo.nMax := 0;
|
|
|
|
scrollInfo.nPage := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
SetScrollInfo(Self.Handle, SB_VERT, scrollInfo, True);
|
|
|
|
|
|
|
|
FillChar(scrollInfo, SizeOf(TScrollInfo), #0);
|
|
|
|
scrollInfo.cbSize := SizeOf(TScrollInfo);
|
|
|
|
scrollInfo.fMask := SIF_POS;
|
|
|
|
FScrollOffset := 0;
|
|
|
|
|
|
|
|
if GetScrollInfo(Self.Handle, SB_VERT, scrollInfo) then
|
|
|
|
FScrollOffset := scrollInfo.nPos;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.SetAllowCollapseAll(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FAllowCollapseAll then
|
|
|
|
begin
|
|
|
|
FAllowCollapseAll := Value;
|
|
|
|
|
|
|
|
end;
|
|
|
|
end;
|
2006-04-01 19:51:46 +00:00
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.SetAnimator(const Value: TX2CustomMenuBarAnimator);
|
|
|
|
begin
|
|
|
|
if Value <> FAnimator then
|
|
|
|
begin
|
|
|
|
FreeAndNil(FAnimator);
|
|
|
|
FAnimator := Value;
|
|
|
|
end;
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBar.SetAutoCollapse(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FAutoCollapse then
|
|
|
|
begin
|
|
|
|
FAutoCollapse := Value;
|
|
|
|
|
|
|
|
if Value then
|
|
|
|
DoAutoCollapse(nil);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.SetAutoSelectItem(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FAutoSelectItem then
|
|
|
|
begin
|
|
|
|
FAutoSelectItem := Value;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
if Value and (not Assigned(SelectedItem)) then
|
|
|
|
DoAutoSelectItem(nil, saBoth);
|
2006-04-02 20:00:02 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure TX2CustomMenuBar.SetBorderStyle(const Value: TBorderStyle);
|
|
|
|
begin
|
|
|
|
if Value <> FBorderStyle then
|
|
|
|
begin
|
|
|
|
FBorderStyle := Value;
|
|
|
|
RecreateWnd();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.SetGroups(const Value: TX2MenuBarGroups);
|
|
|
|
begin
|
|
|
|
if Value <> FGroups then
|
|
|
|
FGroups.Assign(Value);
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBar.SetHideScrollbar(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FHideScrollbar then
|
|
|
|
begin
|
|
|
|
FHideScrollbar := Value;
|
|
|
|
RecreateWnd();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure TX2CustomMenuBar.SetImages(const Value: TCustomImageList);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-04-17 18:41:43 +00:00
|
|
|
if Value <> FImages then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-04-17 18:41:43 +00:00
|
|
|
if Assigned(FImages) then
|
|
|
|
FImages.RemoveFreeNotification(Self);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
FImages := Value;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
if Assigned(FImages) then
|
|
|
|
FImages.FreeNotification(Self);
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.SetPainter(const Value: TX2CustomMenuBarPainter);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
if FPainter <> Value then
|
|
|
|
begin
|
|
|
|
if Assigned(FPainter) then
|
|
|
|
begin
|
|
|
|
FPainter.DetachObserver(Self);
|
|
|
|
FPainter.RemoveFreeNotification(Self);
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
Animator := nil;
|
2006-03-24 05:56:59 +00:00
|
|
|
FPainter := Value;
|
|
|
|
|
|
|
|
if Assigned(FPainter) then
|
|
|
|
begin
|
|
|
|
FPainter.FreeNotification(Self);
|
|
|
|
FPainter.AttachObserver(Self);
|
|
|
|
end;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.SetScrollbar(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FScrollbar then
|
|
|
|
begin
|
|
|
|
FScrollbar := Value;
|
|
|
|
RecreateWnd();
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure TX2CustomMenuBar.SetSelectedItem(const Value: TX2CustomMenuBarItem);
|
|
|
|
var
|
|
|
|
allowed: Boolean;
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if Value <> FSelectedItem then
|
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
if Assigned(Value) then
|
2006-04-17 18:41:43 +00:00
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
allowed := ItemEnabled(Value);
|
|
|
|
if allowed then
|
2006-04-17 18:41:43 +00:00
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
DoSelectedChanging(Value, allowed);
|
|
|
|
|
|
|
|
if allowed then
|
2006-04-17 18:41:43 +00:00
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
if Value is TX2MenuBarGroup then
|
|
|
|
begin
|
|
|
|
group := TX2MenuBarGroup(Value);
|
|
|
|
|
|
|
|
if group.Items.Count > 0 then
|
|
|
|
begin
|
|
|
|
// Item is a group, expand it (triggers autoselect too if appropriate)
|
|
|
|
group.Expanded := True;
|
|
|
|
Exit;
|
|
|
|
end else
|
|
|
|
DoAutoCollapse(group);
|
|
|
|
end;
|
|
|
|
|
|
|
|
FSelectedItem := Value;
|
|
|
|
|
|
|
|
if Value is TX2MenuBarItem then
|
|
|
|
begin
|
|
|
|
group := TX2MenuBarItem(Value).Group;
|
|
|
|
if Assigned(group) then
|
|
|
|
begin
|
|
|
|
group.SelectedItem := Value.Index;
|
|
|
|
|
|
|
|
if not group.Expanded then
|
|
|
|
group.Expanded := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Assigned(FSelectedItem) and Assigned(FSelectedItem.Action) then
|
|
|
|
FSelectedItem.ActionLink.Execute(Self);
|
2006-04-17 18:41:43 +00:00
|
|
|
end;
|
|
|
|
end;
|
2007-01-31 09:41:11 +00:00
|
|
|
end else
|
|
|
|
FSelectedItem := Value;
|
2006-04-17 18:41:43 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
DoSelectedChanged();
|
|
|
|
Invalidate();
|
2006-04-17 18:41:43 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
end.
|
2006-04-01 19:51:46 +00:00
|
|
|
|