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;
|
|
|
|
|
2009-08-06 08:44:12 +00:00
|
|
|
|
|
|
|
{$IFDEF VER180}
|
|
|
|
{$DEFINE D2006}
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
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,
|
2007-06-01 06:41:52 +00:00
|
|
|
SysUtils,
|
2006-03-30 04:54:11 +00:00
|
|
|
Types,
|
2006-03-24 05:56:59 +00:00
|
|
|
Windows;
|
2009-04-22 14:22:01 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
type
|
2007-06-01 06:41:52 +00:00
|
|
|
EInvalidItem = class(Exception);
|
2009-04-22 14:22:01 +00:00
|
|
|
EMenuBarInternalError = class(Exception);
|
2007-06-01 06:41:52 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
TX2MenuBarAnimationStyle = (asNone, asSlide, asDissolve, asFade,
|
2007-04-02 14:49:00 +00:00
|
|
|
asSlideFade, asCustom);
|
2006-04-02 20:00:02 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
TX2MenuBarDirection = (mbdUp, mbdDown);
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
const
|
|
|
|
DefaultAnimationStyle = asSlide;
|
|
|
|
DefaultAnimationTime = 250;
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
type
|
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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2009-08-06 08:44:12 +00:00
|
|
|
TX2MenuBarItemsEnumerator = class;
|
|
|
|
TX2MenuBarGroupsEnumerator = 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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
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-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;
|
2007-04-02 14:49:00 +00:00
|
|
|
TX2MenuBarGetAnimatorClassEvent = procedure(Sender: TObject; var AnimatorClass: TX2CustomMenuBarAnimatorClass) 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
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
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
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
{
|
|
|
|
:$ Abstract animation buffer provider
|
|
|
|
|
|
|
|
:: Provides on-demand retrieval of the buffer required for animation.
|
|
|
|
}
|
|
|
|
TX2CustomMenuBarAnimatorBuffer = class(TObject)
|
|
|
|
private
|
|
|
|
FBitmap: Graphics.TBitmap;
|
|
|
|
protected
|
|
|
|
procedure PrepareBitmap(ABitmap: Graphics.TBitmap); virtual; abstract;
|
|
|
|
|
|
|
|
function GetBitmap: Graphics.TBitmap; virtual;
|
|
|
|
function GetHeight: Integer; virtual;
|
|
|
|
function GetWidth: Integer; virtual;
|
|
|
|
public
|
|
|
|
destructor Destroy; override;
|
|
|
|
|
|
|
|
property Bitmap: Graphics.TBitmap read GetBitmap;
|
|
|
|
property Height: Integer read GetHeight;
|
|
|
|
property Width: Integer read GetWidth;
|
|
|
|
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;
|
|
|
|
FStartTime: Cardinal;
|
2009-04-22 14:22:01 +00:00
|
|
|
FItemsBuffer: TX2CustomMenuBarAnimatorBuffer;
|
2006-03-24 05:56:59 +00:00
|
|
|
FTerminated: Boolean;
|
|
|
|
protected
|
2009-04-22 14:22:01 +00:00
|
|
|
function GetTimeElapsed: Cardinal; virtual;
|
|
|
|
function GetHeight: Integer; virtual;
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure SetExpanding(const Value: Boolean); virtual;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure Terminate; virtual;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
property ItemsBuffer: TX2CustomMenuBarAnimatorBuffer read FItemsBuffer;
|
|
|
|
property TimeElapsed: Cardinal read GetTimeElapsed;
|
2006-03-24 05:56:59 +00:00
|
|
|
public
|
2009-04-22 14:22:01 +00:00
|
|
|
constructor Create(AItemsBuffer: TX2CustomMenuBarAnimatorBuffer); virtual;
|
|
|
|
destructor Destroy; override;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure ResetStartTime;
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure Update; virtual;
|
2006-03-30 04:54:11 +00:00
|
|
|
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;
|
|
|
|
property Height: Integer read GetHeight;
|
2007-04-02 14:49:00 +00:00
|
|
|
property StartTime: Cardinal read FStartTime write FStartTime;
|
|
|
|
property Terminated: Boolean read FTerminated;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{
|
|
|
|
:$ 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;
|
2009-04-22 14:22:01 +00:00
|
|
|
FPaintCount: Integer;
|
2006-03-24 05:56:59 +00:00
|
|
|
FObservers: TInterfaceList;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function GetMenuBar: TX2CustomMenuBar;
|
2006-03-24 05:56:59 +00:00
|
|
|
protected
|
|
|
|
procedure BeginPaint(const AMenuBar: TX2CustomMenuBar);
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure EndPaint;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function ApplyMargins(const ABounds: TRect): TRect; virtual;
|
2009-04-22 14:22:01 +00:00
|
|
|
function UndoMargins(const ABounds: TRect): TRect; virtual;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
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;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure DrawBackground(ACanvas: TCanvas; const ABounds: TRect; const AOffset: TPoint); virtual; abstract;
|
2006-03-24 05:56:59 +00:00
|
|
|
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
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure NotifyObservers;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
property MenuBar: TX2CustomMenuBar read GetMenuBar;
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
2009-04-22 14:22:01 +00:00
|
|
|
destructor Destroy; override;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
:$ Abstract action class.
|
|
|
|
|
|
|
|
:: Provides a base for menu bar actions which need to be performed
|
2007-06-01 06:41:52 +00:00
|
|
|
:: asynchronous and/or in sequence.
|
2007-04-02 14:49:00 +00:00
|
|
|
}
|
|
|
|
TX2CustomMenuBarAction = class(TObject)
|
|
|
|
private
|
|
|
|
FMenuBar: TX2CustomMenuBar;
|
2007-04-20 13:37:56 +00:00
|
|
|
FStarted: Boolean;
|
2007-04-02 14:49:00 +00:00
|
|
|
FTerminated: Boolean;
|
|
|
|
protected
|
2009-04-22 14:22:01 +00:00
|
|
|
function GetTerminated: Boolean; virtual;
|
|
|
|
procedure Terminate; virtual;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
property MenuBar: TX2CustomMenuBar read FMenuBar;
|
|
|
|
public
|
|
|
|
constructor Create(AMenuBar: TX2CustomMenuBar);
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function AllowUpdateScrollbar: Boolean; virtual;
|
|
|
|
function AllowInteraction: Boolean; virtual;
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure Start; virtual;
|
|
|
|
procedure Stop; virtual;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure BeforePaint; virtual;
|
2007-04-02 14:49:00 +00:00
|
|
|
procedure GetItemHeight(AItem: TX2CustomMenuBarItem; var AHeight: Integer; var AHandled: Boolean); virtual;
|
|
|
|
procedure DrawMenuItem(ACanvas: TCanvas; APainter: TX2CustomMenuBarPainter;
|
|
|
|
AItem: TX2CustomMenuBarItem; const AMenuBounds,
|
|
|
|
AItemBounds: TRect; AState: TX2MenuBarDrawStates;
|
|
|
|
var AHandled: Boolean); virtual;
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure AfterPaint; virtual;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
property Started: Boolean read FStarted;
|
2007-04-02 14:49:00 +00:00
|
|
|
property Terminated: Boolean read GetTerminated;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
{
|
|
|
|
:$ Animation buffer menu bar link.
|
|
|
|
}
|
|
|
|
TX2MenuBarAnimatorBuffer = class(TX2CustomMenuBarAnimatorBuffer)
|
|
|
|
private
|
|
|
|
FGroup: TX2MenuBarGroup;
|
|
|
|
FMenuBar: TX2CustomMenuBar;
|
|
|
|
protected
|
|
|
|
procedure PrepareBitmap(ABitmap: Graphics.TBitmap); override;
|
|
|
|
public
|
|
|
|
constructor Create(AMenuBar: TX2CustomMenuBar; AGroup: TX2MenuBarGroup);
|
|
|
|
|
|
|
|
property Group: TX2MenuBarGroup read FGroup write FGroup;
|
|
|
|
property MenuBar: TX2CustomMenuBar read FMenuBar write FMenuBar;
|
|
|
|
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;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function IsCaptionLinked: Boolean; override;
|
|
|
|
function IsEnabledLinked: Boolean; override;
|
|
|
|
function IsImageIndexLinked: Boolean; override;
|
|
|
|
function IsVisibleLinked: Boolean; override;
|
2006-05-22 05:13:12 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
{
|
|
|
|
:$ Provides component notifications for collection items.
|
|
|
|
}
|
|
|
|
TX2ComponentNotification = class(TComponent)
|
|
|
|
private
|
|
|
|
FOnNotification: TX2ComponentNotificationEvent;
|
|
|
|
protected
|
|
|
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
|
|
|
published
|
|
|
|
property OnNotification: TX2ComponentNotificationEvent read FOnNotification write FOnNotification;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
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;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function IsCaptionStored: Boolean; virtual;
|
|
|
|
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;
|
2009-04-22 14:22:01 +00:00
|
|
|
destructor Destroy; override;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
{
|
|
|
|
:$ 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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
{
|
|
|
|
:$ Contains a single menu item.
|
|
|
|
}
|
|
|
|
TX2MenuBarItem = class(TX2CustomMenuBarItem)
|
|
|
|
private
|
2009-04-22 14:22:01 +00:00
|
|
|
function GetGroup: TX2MenuBarGroup;
|
2006-05-22 05:13:12 +00:00
|
|
|
protected
|
2009-04-22 14:22:01 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
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);
|
|
|
|
|
2009-08-06 08:44:12 +00:00
|
|
|
function GetEnumerator: TX2MenuBarItemsEnumerator;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
function Add(const ACaption: TCaption = ''): TX2MenuBarItem;
|
|
|
|
|
|
|
|
property Items[Index: Integer]: TX2MenuBarItem read GetItem write SetItem; default;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{
|
|
|
|
:$ 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
|
|
|
|
2009-04-22 14:22:01 +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
|
2009-04-22 14:22:01 +00:00
|
|
|
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;
|
2009-04-22 14:22:01 +00:00
|
|
|
destructor Destroy; override;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2009-08-06 08:44:12 +00:00
|
|
|
function GetEnumerator: TX2MenuBarItemsEnumerator;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure Assign(Source: TPersistent); override;
|
2009-03-13 15:27:22 +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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{
|
|
|
|
:$ 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);
|
|
|
|
|
2009-08-06 08:44:12 +00:00
|
|
|
function GetEnumerator: TX2MenuBarGroupsEnumerator;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
function Add(const ACaption: TCaption = ''): TX2MenuBarGroup;
|
|
|
|
|
|
|
|
property Items[Index: Integer]: TX2MenuBarGroup read GetItem write SetItem; default;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{
|
|
|
|
:$ 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;
|
|
|
|
FAutoCollapse: Boolean;
|
|
|
|
FAutoSelectItem: Boolean;
|
|
|
|
FBorderStyle: TBorderStyle;
|
|
|
|
FCursorGroup: TCursor;
|
|
|
|
FCursorItem: TCursor;
|
|
|
|
FHideScrollbar: Boolean;
|
2007-04-02 14:49:00 +00:00
|
|
|
FGroups: TX2MenuBarGroups;
|
2006-04-17 18:41:43 +00:00
|
|
|
FImages: TCustomImageList;
|
2008-05-26 10:22:50 +00:00
|
|
|
FImagesChangeLink: TChangeLink;
|
2006-04-17 18:41:43 +00:00
|
|
|
FOnCollapsed: TX2MenuBarExpandedEvent;
|
|
|
|
FOnCollapsing: TX2MenuBarExpandingEvent;
|
|
|
|
FOnExpanded: TX2MenuBarExpandedEvent;
|
|
|
|
FOnExpanding: TX2MenuBarExpandingEvent;
|
2007-04-02 14:49:00 +00:00
|
|
|
FOnGetAnimatorClass: TX2MenuBarGetAnimatorClassEvent;
|
2006-04-17 18:41:43 +00:00
|
|
|
FOnSelectedChanged: TX2MenuBarSelectedChangedEvent;
|
|
|
|
FOnSelectedChanging: TX2MenuBarSelectedChangingEvent;
|
|
|
|
FPainter: TX2CustomMenuBarPainter;
|
|
|
|
FScrollbar: Boolean;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
FHotItem: TX2CustomMenuBarItem;
|
2006-04-17 18:41:43 +00:00
|
|
|
FSelectedItem: TX2CustomMenuBarItem;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
FActionQueue: TObjectList;
|
|
|
|
FBuffer: Graphics.TBitmap;
|
|
|
|
FDesigner: IX2MenuBarDesigner;
|
|
|
|
FLastMousePos: TPoint;
|
|
|
|
FScrollOffset: Integer;
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure SetAllowCollapseAll(const Value: Boolean);
|
|
|
|
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-04-22 14:22:01 +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);
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure UpdateScrollbar;
|
2008-05-26 10:22:50 +00:00
|
|
|
procedure ImagesChange(Sender: TObject);
|
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;
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure CMMouseLeave(var Msg: TMessage); message CM_MOUSELEAVE;
|
|
|
|
|
|
|
|
procedure WMVScroll(var Msg: TWMVScroll); message WM_VSCROLL;
|
2007-06-01 06:41:52 +00:00
|
|
|
// procedure WMMouseWheel(var Message: TWMMouseWheel); message WM_MOUSEWHEEL;
|
|
|
|
// procedure CMMouseWheel(var Message: TCMMouseWheel); message CM_MOUSEWHEEL;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TestMousePos; virtual;
|
|
|
|
function GetMenuHeight: Integer; virtual;
|
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
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
{ Painting }
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure Paint; override;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure FindGroupBounds(Sender: TObject; Item: TX2CustomMenuBarItem; const MenuBounds: TRect; const ItemBounds: TRect; Data: Pointer; var Abort: Boolean);
|
|
|
|
function GetGroupBounds(AGroup: TX2MenuBarGroup): TRect;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
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;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function GetAnimatorClass: TX2CustomMenuBarAnimatorClass; virtual;
|
2007-04-02 14:49:00 +00:00
|
|
|
function GetAnimateAction(AGroup: TX2MenuBarGroup; AExpanding: Boolean): TX2CustomMenuBarAction; virtual;
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure GetAnimateGroup(AGroup: TX2MenuBarGroup; ABitmap: Graphics.TBitmap); virtual;
|
2006-04-02 20:00:02 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function IterateItemBounds(ACallback: TX2MenuBarItemBoundsProc; AData: Pointer = nil): TX2CustomMenuBarItem;
|
2009-04-22 14:22:01 +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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
{ Action queue }
|
2009-04-22 14:22:01 +00:00
|
|
|
function GetCurrentAction: TX2CustomMenuBarAction;
|
2007-04-02 14:49:00 +00:00
|
|
|
procedure PushAction(AAction: TX2CustomMenuBarAction);
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure PopCurrentAction;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
property ActionQueue: TObjectList read FActionQueue;
|
|
|
|
property HotItem: TX2CustomMenuBarItem read FHotItem write FHotItem;
|
|
|
|
|
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 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;
|
2007-04-02 14:49:00 +00:00
|
|
|
property Scrollbar: Boolean read FScrollbar write SetScrollbar default True;
|
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
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;
|
2007-04-02 14:49:00 +00:00
|
|
|
property OnGetAnimatorClass: TX2MenuBarGetAnimatorClassEvent read FOnGetAnimatorClass write FOnGetAnimatorClass;
|
2006-04-17 18:41:43 +00:00
|
|
|
property OnSelectedChanged: TX2MenuBarSelectedChangedEvent read FOnSelectedChanged write FOnSelectedChanged;
|
|
|
|
property OnSelectedChanging: TX2MenuBarSelectedChangingEvent read FOnSelectedChanging write FOnSelectedChanging;
|
2006-03-24 05:56:59 +00:00
|
|
|
protected
|
2007-04-20 13:37:56 +00:00
|
|
|
procedure InternalSetExpanded(AGroup: TX2MenuBarGroup; AExpanded: Boolean); virtual;
|
|
|
|
procedure InternalSetSelected(AItem: TX2CustomMenuBarItem); virtual;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
function DoAutoCollapse(AGroup: TX2MenuBarGroup): Boolean; virtual;
|
|
|
|
function DoAutoSelectItem(AGroup: TX2MenuBarGroup): Boolean; virtual;
|
|
|
|
function DoExpand(AGroup: TX2MenuBarGroup; AExpanding: Boolean): Boolean; virtual;
|
|
|
|
function DoSelectItem(AItem: TX2CustomMenuBarItem): Boolean; virtual;
|
|
|
|
|
|
|
|
function PerformAutoCollapse(AGroup: TX2MenuBarGroup): Boolean; virtual;
|
|
|
|
function PerformAutoSelectItem(AGroup: TX2MenuBarGroup): Boolean; virtual;
|
|
|
|
function PerformExpand(AGroup: TX2MenuBarGroup; AExpanding: Boolean): Boolean; virtual;
|
|
|
|
function PerformSelectItem(AItem: TX2CustomMenuBarItem): Boolean; virtual;
|
|
|
|
|
|
|
|
procedure DoCollapsed(AGroup: TX2MenuBarGroup); virtual;
|
|
|
|
procedure DoCollapsing(AGroup: TX2MenuBarGroup; var AAllowed: Boolean); virtual;
|
|
|
|
procedure DoExpanded(AGroup: TX2MenuBarGroup); virtual;
|
|
|
|
procedure DoExpanding(AGroup: TX2MenuBarGroup; var AAllowed: 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;
|
2009-04-22 14:22:01 +00:00
|
|
|
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;
|
2009-04-22 14:22:01 +00:00
|
|
|
destructor Destroy; override;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2009-08-06 08:44:12 +00:00
|
|
|
function GetEnumerator: TX2MenuBarGroupsEnumerator;
|
|
|
|
|
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;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function SelectFirst: TX2CustomMenuBarItem;
|
|
|
|
function SelectLast: TX2CustomMenuBarItem;
|
|
|
|
function SelectNext: TX2CustomMenuBarItem;
|
|
|
|
function SelectPrior: TX2CustomMenuBarItem;
|
2006-05-22 05:13:12 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
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;
|
2009-03-30 11:20:23 +00:00
|
|
|
|
|
|
|
property Designer: IX2MenuBarDesigner read FDesigner write FDesigner;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{
|
|
|
|
:$ 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;
|
2007-06-01 06:41:52 +00:00
|
|
|
property TabOrder;
|
|
|
|
property TabStop default True;
|
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;
|
2009-08-06 08:44:12 +00:00
|
|
|
{$IFDEF D2006}
|
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;
|
|
|
|
|
|
|
|
|
2009-08-06 08:44:12 +00:00
|
|
|
{
|
|
|
|
:$ For iterators support for D2006+
|
|
|
|
}
|
|
|
|
TX2MenuBarItemsEnumerator = class(TCollectionEnumerator)
|
|
|
|
private
|
|
|
|
function GetCurrent: TX2MenuBarItem;
|
|
|
|
public
|
|
|
|
property Current: TX2MenuBarItem read GetCurrent;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
TX2MenuBarGroupsEnumerator = class(TCollectionEnumerator)
|
|
|
|
private
|
|
|
|
function GetCurrent: TX2MenuBarGroup;
|
|
|
|
public
|
|
|
|
property Current: TX2MenuBarGroup read GetCurrent;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
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-04-01 19:51:46 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
implementation
|
|
|
|
uses
|
2007-04-02 14:49:00 +00:00
|
|
|
X2CLGraphics,
|
|
|
|
X2CLMenuBarActions,
|
2006-04-02 20:00:02 +00:00
|
|
|
X2CLMenuBarAnimators;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2007-06-01 06:41:52 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
const
|
|
|
|
SDefaultItemCaption = 'Menu Item';
|
|
|
|
SDefaultGroupCaption = 'Group';
|
|
|
|
SNoPainter = 'Painter property not set';
|
2007-06-01 06:41:52 +00:00
|
|
|
SInvalidItem = 'Item does not belong to this MenuBar';
|
2009-04-22 14:22:01 +00:00
|
|
|
SBeginPaintConflict = 'BeginPaint already called for a different MenuBar';
|
|
|
|
SEndPaintWithoutBegin = 'EndPaint called without BeginPaint';
|
2007-06-01 06:41:52 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
type
|
|
|
|
TProtectedCollection = class(TCollection);
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
PFindGroupBoundsInfo = ^TFindGroupBoundsInfo;
|
|
|
|
TFindGroupBoundsInfo = record
|
|
|
|
Group: TX2MenuBarGroup;
|
|
|
|
Bounds: TRect;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2007-04-02 14:49:00 +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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +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
|
2009-04-22 14:22:01 +00:00
|
|
|
FObservers := TInterfaceList.Create;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
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
|
2009-04-22 14:22:01 +00:00
|
|
|
if (FPaintCount > 0) and (AMenuBar <> FMenuBar) then
|
|
|
|
raise EMenuBarInternalError.Create(SBeginPaintConflict);
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
FMenuBar := AMenuBar;
|
2009-04-22 14:22:01 +00:00
|
|
|
Inc(FPaintCount);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.EndPaint;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
if FPaintCount = 0 then
|
|
|
|
raise EMenuBarInternalError.Create(SEndPaintWithoutBegin);
|
|
|
|
|
|
|
|
Dec(FPaintCount);
|
|
|
|
if FPaintCount = 0 then
|
|
|
|
FMenuBar := nil;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBarPainter.UndoMargins(const ABounds: TRect): TRect;
|
|
|
|
begin
|
|
|
|
Result := ABounds;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
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
|
|
|
|
2007-04-20 13:37:56 +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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBarPainter.GetMenuBar: TX2CustomMenuBar;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Assert(Assigned(FMenuBar), 'BeginPaint not called');
|
|
|
|
Result := FMenuBar;
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
{ TX2CustomMenuBarAnimatorBuffer }
|
|
|
|
destructor TX2CustomMenuBarAnimatorBuffer.Destroy;
|
|
|
|
begin
|
|
|
|
FreeAndNil(FBitmap);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomMenuBarAnimatorBuffer.GetBitmap: Graphics.TBitmap;
|
|
|
|
begin
|
|
|
|
if not Assigned(FBitmap) then
|
|
|
|
begin
|
|
|
|
FBitmap := Graphics.TBitmap.Create;
|
|
|
|
FBitmap.PixelFormat := pf32bit;
|
|
|
|
PrepareBitmap(FBitmap);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Result := FBitmap;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBarAnimatorBuffer.GetHeight: Integer;
|
|
|
|
begin
|
|
|
|
Result := Bitmap.Height;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomMenuBarAnimatorBuffer.GetWidth: Integer;
|
|
|
|
begin
|
|
|
|
Result := Bitmap.Width;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
{ TX2CustomMenuBarAnimator }
|
2009-04-22 14:22:01 +00:00
|
|
|
constructor TX2CustomMenuBarAnimator.Create(AItemsBuffer: TX2CustomMenuBarAnimatorBuffer);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
inherited Create;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
ResetStartTime;
|
|
|
|
FItemsBuffer := AItemsBuffer;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
destructor TX2CustomMenuBarAnimator.Destroy;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FItemsBuffer);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBarAnimator.ResetStartTime;
|
2007-04-20 13:37:56 +00:00
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
FStartTime := GetTickCount;
|
2007-04-20 13:37:56 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBarAnimator.GetHeight: Integer;
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
Result := ItemsBuffer.Height;
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBarAnimator.GetTimeElapsed: Cardinal;
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
|
|
|
currentTime: Cardinal;
|
|
|
|
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
currentTime := GetTickCount;
|
2006-03-24 05:56:59 +00:00
|
|
|
Result := currentTime - FStartTime;
|
|
|
|
|
|
|
|
if currentTime < FStartTime then
|
|
|
|
Inc(Result, High(Cardinal));
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBarAnimator.Terminate;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
FTerminated := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBarAnimator.Update;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
{ TX2CustomMenuBarAction }
|
|
|
|
constructor TX2CustomMenuBarAction.Create(AMenuBar: TX2CustomMenuBar);
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
FMenuBar := AMenuBar;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBarAction.Terminate;
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
FTerminated := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBarAction.AllowInteraction: Boolean;
|
2007-04-20 13:37:56 +00:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBarAction.AllowUpdateScrollbar: Boolean;
|
2007-04-20 13:37:56 +00:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBarAction.Start;
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
2007-04-20 13:37:56 +00:00
|
|
|
FStarted := True;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBarAction.Stop;
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
2007-04-20 13:37:56 +00:00
|
|
|
FStarted := False;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBarAction.BeforePaint;
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBarAction.GetItemHeight(AItem: TX2CustomMenuBarItem; var AHeight: Integer; var AHandled: Boolean);
|
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBarAction.DrawMenuItem(ACanvas: TCanvas; APainter: TX2CustomMenuBarPainter;
|
|
|
|
AItem: TX2CustomMenuBarItem; const AMenuBounds,
|
|
|
|
AItemBounds: TRect; AState: TX2MenuBarDrawStates;
|
|
|
|
var AHandled: Boolean);
|
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBarAction.AfterPaint;
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBarAction.GetTerminated: Boolean;
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
Result := FTerminated;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
{ TX2MenuBarAnimatorBuffer }
|
|
|
|
constructor TX2MenuBarAnimatorBuffer.Create(AMenuBar: TX2CustomMenuBar; AGroup: TX2MenuBarGroup);
|
|
|
|
begin
|
|
|
|
inherited Create;
|
|
|
|
|
|
|
|
FGroup := AGroup;
|
|
|
|
FMenuBar := AMenuBar;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2MenuBarAnimatorBuffer.PrepareBitmap(ABitmap: Graphics.TBitmap);
|
|
|
|
begin
|
|
|
|
MenuBar.GetAnimateGroup(Group, ABitmap);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
{ TX2MenuBarActionLink }
|
|
|
|
procedure TX2MenuBarActionLink.AssignClient(AClient: TObject);
|
|
|
|
begin
|
|
|
|
FClient := (AClient as TX2CustomMenuBarItem);
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2MenuBarActionLink.IsCaptionLinked: Boolean;
|
2006-05-22 05:13:12 +00:00
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
Result := inherited IsCaptionLinked and
|
2006-05-22 05:13:12 +00:00
|
|
|
(Client.Caption = (Action as TCustomAction).Caption);
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2MenuBarActionLink.IsEnabledLinked: Boolean;
|
2006-05-22 05:13:12 +00:00
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
Result := inherited IsCaptionLinked and
|
2006-05-22 05:13:12 +00:00
|
|
|
(Client.Enabled = (Action as TCustomAction).Enabled);
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2MenuBarActionLink.IsImageIndexLinked: Boolean;
|
2006-05-22 05:13:12 +00:00
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
Result := inherited IsCaptionLinked and
|
2006-05-22 05:13:12 +00:00
|
|
|
(Client.ImageIndex = (Action as TCustomAction).ImageIndex);
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2MenuBarActionLink.IsVisibleLinked: Boolean;
|
2006-05-22 05:13:12 +00:00
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
Result := inherited IsCaptionLinked and
|
2006-05-22 05:13:12 +00:00
|
|
|
(Client.Visible = (Action as TCustomAction).Visible);
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
procedure TX2MenuBarActionLink.SetCaption(const Value: string);
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
if IsCaptionLinked then
|
2006-05-22 05:13:12 +00:00
|
|
|
Client.Caption := Value;
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
procedure TX2MenuBarActionLink.SetEnabled(Value: Boolean);
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
if IsEnabledLinked then
|
2006-05-22 05:13:12 +00:00
|
|
|
Client.Enabled := Value;
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
procedure TX2MenuBarActionLink.SetImageIndex(Value: Integer);
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
if IsImageIndexLinked then
|
2006-05-22 05:13:12 +00:00
|
|
|
Client.ImageIndex := Value;
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
procedure TX2MenuBarActionLink.SetVisible(Value: Boolean);
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
if IsVisibleLinked then
|
2006-05-22 05:13:12 +00:00
|
|
|
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;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
destructor TX2CustomMenuBarItem.Destroy;
|
2006-03-30 04:54:11 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
procedure TX2CustomMenuBarItem.ActionChange(Sender: TObject;
|
|
|
|
CheckDefaults: Boolean);
|
|
|
|
begin
|
|
|
|
if Sender is TCustomAction then
|
|
|
|
with TCustomAction(Sender) do
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
if (not CheckDefaults) or (not Self.IsCaptionStored) then
|
2006-05-22 05:13:12 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBarItem.IsCaptionStored: Boolean;
|
2006-05-22 05:13:12 +00:00
|
|
|
begin
|
|
|
|
Result := (Length(Caption) > 0);
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBarItem.GetMenuBar: TX2CustomMenuBar;
|
2006-03-30 04:54:11 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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
|
|
|
|
2007-04-20 13:37:56 +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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2MenuBarItem.IsCaptionStored: Boolean;
|
2006-05-22 05:13:12 +00:00
|
|
|
begin
|
|
|
|
Result := (Caption <> SDefaultItemCaption);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2MenuBarItem.GetGroup: TX2MenuBarGroup;
|
2006-03-30 04:54:11 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2009-08-06 08:44:12 +00:00
|
|
|
function TX2MenuBarItems.GetEnumerator: TX2MenuBarItemsEnumerator;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarItemsEnumerator.Create(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
function TX2MenuBarItems.Add(const ACaption: TCaption): TX2MenuBarItem;
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
destructor TX2MenuBarGroup.Destroy;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FItems);
|
|
|
|
|
|
|
|
if OwnsData then
|
|
|
|
FreeAndNil(FData);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-08-06 08:44:12 +00:00
|
|
|
function TX2MenuBarGroup.GetEnumerator: TX2MenuBarItemsEnumerator;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarItemsEnumerator.Create(Items);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
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
|
|
|
|
2009-04-22 14:22:01 +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
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
procedure TX2MenuBarGroup.InternalSetExpanded(const Value: Boolean);
|
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);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2MenuBarGroup.IsCaptionStored: Boolean;
|
2006-05-22 05:13:12 +00:00
|
|
|
begin
|
|
|
|
Result := (Caption <> SDefaultGroupCaption);
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2009-08-06 08:44:12 +00:00
|
|
|
function TX2MenuBarGroups.GetEnumerator: TX2MenuBarGroupsEnumerator;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarGroupsEnumerator.Create(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
function TX2MenuBarGroups.Add(const ACaption: TCaption): TX2MenuBarGroup;
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
FActionQueue := TObjectList.Create(True);
|
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-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;
|
2009-04-22 14:22:01 +00:00
|
|
|
FImagesChangeLink := TChangeLink.Create;
|
2006-04-02 20:00:02 +00:00
|
|
|
FScrollbar := True;
|
2007-06-01 06:41:52 +00:00
|
|
|
TabStop := True;
|
2008-05-26 10:22:50 +00:00
|
|
|
|
|
|
|
FImagesChangeLink.OnChange := ImagesChange;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBar.Loaded;
|
2007-01-31 09:41:11 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
UpdateScrollbar;
|
2007-01-31 09:41:11 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
destructor TX2CustomMenuBar.Destroy;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2008-05-26 10:22:50 +00:00
|
|
|
Images := nil;
|
2007-01-31 09:41:11 +00:00
|
|
|
Painter := nil;
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
FreeAndNil(FGroups);
|
2007-01-31 09:41:11 +00:00
|
|
|
FreeAndNil(FBuffer);
|
2007-04-02 14:49:00 +00:00
|
|
|
FreeAndNil(FActionQueue);
|
2008-05-26 10:22:50 +00:00
|
|
|
FreeAndNil(FImagesChangeLink);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-08-06 08:44:12 +00:00
|
|
|
function TX2CustomMenuBar.GetEnumerator: TX2MenuBarGroupsEnumerator;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarGroupsEnumerator.Create(Groups);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure TX2CustomMenuBar.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
|
|
|
|
begin
|
|
|
|
Msg.Result := 0;
|
|
|
|
end;
|
|
|
|
|
2008-05-26 10:22:50 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBar.Paint;
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
2006-03-30 04:54:11 +00:00
|
|
|
bufferRect: TRect;
|
2007-04-02 14:49:00 +00:00
|
|
|
currentAction: TX2CustomMenuBarAction;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Assigned(Painter) then
|
|
|
|
begin
|
2007-04-02 14:49:00 +00:00
|
|
|
{ Prepare buffer }
|
2007-01-31 09:41:11 +00:00
|
|
|
if not Assigned(FBuffer) then
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
FBuffer := Graphics.TBitmap.Create;
|
2007-01-31 09:41:11 +00:00
|
|
|
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-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
{ Update action }
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction := GetCurrentAction;
|
2007-04-02 14:49:00 +00:00
|
|
|
if Assigned(currentAction) then
|
2007-04-20 13:37:56 +00:00
|
|
|
begin
|
|
|
|
if not currentAction.Started then
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction.Start;
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction.BeforePaint;
|
2007-04-20 13:37:56 +00:00
|
|
|
end;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
UpdateScrollbar;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
{ Draw menu }
|
2007-01-31 09:41:11 +00:00
|
|
|
Painter.BeginPaint(Self);
|
|
|
|
try
|
2009-04-22 14:22:01 +00:00
|
|
|
Painter.DrawBackground(FBuffer.Canvas, bufferRect, Point(0, 0));
|
2007-01-31 09:41:11 +00:00
|
|
|
DrawMenu(FBuffer.Canvas);
|
2006-03-24 05:56:59 +00:00
|
|
|
finally
|
2009-04-22 14:22:01 +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);
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
{ Action queue }
|
|
|
|
if Assigned(currentAction) then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2007-04-20 13:37:56 +00:00
|
|
|
{ Make sure Paint is called again while there's an action queue }
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction.AfterPaint;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
if currentAction.Terminated then
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction.Stop;
|
|
|
|
PopCurrentAction;
|
2007-06-01 06:41:52 +00:00
|
|
|
|
|
|
|
{ Start the next action in the queue, continue until we find an
|
|
|
|
action which doesn't terminate immediately. See PushAction. }
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction := GetCurrentAction;
|
2007-06-01 06:41:52 +00:00
|
|
|
while Assigned(currentAction) do
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction.Start;
|
2007-06-01 06:41:52 +00:00
|
|
|
|
|
|
|
if currentAction.Terminated then
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction.Stop;
|
|
|
|
PopCurrentAction;
|
2007-06-01 06:41:52 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction := GetCurrentAction;
|
2007-06-01 06:41:52 +00:00
|
|
|
end else
|
|
|
|
Break;
|
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
end;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
DrawNoPainter(Self.Canvas, Self.ClientRect);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBar.FindGroupBounds(Sender: TObject; Item: TX2CustomMenuBarItem;
|
|
|
|
const MenuBounds, ItemBounds: TRect;
|
|
|
|
Data: Pointer; var Abort: Boolean);
|
|
|
|
var
|
|
|
|
findInfo: PFindGroupBoundsInfo;
|
|
|
|
|
|
|
|
begin
|
|
|
|
findInfo := Data;
|
|
|
|
|
|
|
|
if Item = findInfo^.Group then
|
|
|
|
begin
|
|
|
|
findInfo^.Bounds := ItemBounds;
|
|
|
|
Abort := True;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.GetGroupBounds(AGroup: TX2MenuBarGroup): TRect;
|
|
|
|
var
|
|
|
|
findInfo: TFindGroupBoundsInfo;
|
|
|
|
|
|
|
|
begin
|
|
|
|
findInfo.Group := AGroup;
|
|
|
|
if Assigned(IterateItemBounds(FindGroupBounds, @findInfo)) then
|
|
|
|
begin
|
|
|
|
Result := findInfo.Bounds;
|
|
|
|
|
|
|
|
{ We receive the bounds of the group item, start with the first
|
|
|
|
menu item. }
|
|
|
|
Result.Top := Result.Bottom;
|
|
|
|
Result.Bottom := Result.Top + Painter.GetGroupHeight(AGroup);
|
|
|
|
end;
|
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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
|
2007-04-02 14:49:00 +00:00
|
|
|
canvas: TCanvas;
|
|
|
|
currentAction: TX2CustomMenuBarAction;
|
|
|
|
drawState: TX2MenuBarDrawStates;
|
|
|
|
handled: Boolean;
|
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
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
canvas := TCanvas(Data);
|
|
|
|
drawState := GetDrawState(Item);
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction := GetCurrentAction;
|
2007-04-02 14:49:00 +00:00
|
|
|
handled := False;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
if Assigned(currentAction) then
|
|
|
|
currentAction.DrawMenuItem(canvas, Painter, Item, MenuBounds, ItemBounds,
|
|
|
|
drawState, handled);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
if not handled then
|
|
|
|
begin
|
|
|
|
if Item is TX2MenuBarGroup then
|
|
|
|
Painter.DrawGroupHeader(canvas, TX2MenuBarGroup(Item), ItemBounds, drawState)
|
|
|
|
else if Item is TX2MenuBarItem then
|
|
|
|
Painter.DrawItem(canvas, TX2MenuBarItem(Item), ItemBounds, drawState);
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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
|
|
|
|
2007-04-20 13:37:56 +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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
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);
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
X2CLGraphics.DrawText(ACanvas, SNoPainter, ABounds, taCenter);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBar.GetAnimatorClass: TX2CustomMenuBarAnimatorClass;
|
2006-04-02 20:00:02 +00:00
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
case AnimationStyle of
|
|
|
|
asSlide: Result := TX2MenuBarSlideAnimator;
|
|
|
|
asDissolve: Result := TX2MenuBarDissolveAnimator;
|
|
|
|
asFade: Result := TX2MenuBarFadeAnimator;
|
|
|
|
asSlideFade: Result := TX2MenuBarSlideFadeAnimator;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
function TX2CustomMenuBar.GetAnimateAction(AGroup: TX2MenuBarGroup; AExpanding: Boolean): TX2CustomMenuBarAction;
|
|
|
|
var
|
|
|
|
animatorClass: TX2CustomMenuBarAnimatorClass;
|
|
|
|
animator: TX2CustomMenuBarAnimator;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
if not Assigned(Painter) then
|
|
|
|
Exit;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
animatorClass := GetAnimatorClass;
|
2007-04-02 14:49:00 +00:00
|
|
|
if Assigned(animatorClass) and not (csDesigning in ComponentState) then
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
animator := animatorClass.Create(TX2MenuBarAnimatorBuffer.Create(Self, AGroup));
|
|
|
|
animator.AnimationTime := AnimationTime;
|
|
|
|
animator.Expanding := AExpanding;
|
|
|
|
|
|
|
|
Result := TX2MenuBarAnimateAction.Create(Self, AGroup, animator);
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.GetAnimateGroup(AGroup: TX2MenuBarGroup; ABitmap: Graphics.TBitmap);
|
|
|
|
var
|
|
|
|
itemsBounds: TRect;
|
|
|
|
groupOffset: TPoint;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Painter.BeginPaint(Self);
|
|
|
|
try
|
|
|
|
itemsBounds := GetGroupBounds(AGroup);
|
|
|
|
ABitmap.PixelFormat := pf32bit;
|
|
|
|
ABitmap.Width := itemsBounds.Right - itemsBounds.Left;
|
|
|
|
ABitmap.Height := itemsBounds.Bottom - itemsBounds.Top;
|
|
|
|
|
|
|
|
{ Pass the original position of the group to the painter, so it
|
|
|
|
can do proper custom backgrounds. }
|
|
|
|
Painter.UndoMargins(itemsBounds);
|
|
|
|
groupOffset := itemsBounds.TopLeft;
|
|
|
|
|
|
|
|
// #ToDo1 (MvR) 17-04-2009: even tijdelijk; een van de metrics moet meegenomen worden in de berekening
|
|
|
|
Inc(groupOffset.Y, 8);
|
|
|
|
|
|
|
|
itemsBounds := Rect(0, 0, ABitmap.Width, ABitmap.Height);
|
|
|
|
|
|
|
|
ABitmap.Canvas.Font.Assign(Self.Font);
|
|
|
|
|
|
|
|
Painter.DrawBackground(ABitmap.Canvas, itemsBounds, groupOffset);
|
|
|
|
DrawMenuItems(ABitmap.Canvas, AGroup, itemsBounds);
|
|
|
|
finally
|
|
|
|
Painter.EndPaint;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBar.IterateItemBounds(ACallback: TX2MenuBarItemBoundsProc;
|
|
|
|
AData: Pointer): TX2CustomMenuBarItem;
|
|
|
|
var
|
2007-04-02 14:49:00 +00:00
|
|
|
abort: Boolean;
|
|
|
|
currentAction: TX2CustomMenuBarAction;
|
2006-03-30 04:54:11 +00:00
|
|
|
group: TX2MenuBarGroup;
|
2007-04-02 14:49:00 +00:00
|
|
|
groupIndex: Integer;
|
|
|
|
handled: Boolean;
|
|
|
|
item: TX2MenuBarItem;
|
2006-03-30 04:54:11 +00:00
|
|
|
itemBounds: TRect;
|
2007-04-02 14:49:00 +00:00
|
|
|
itemHeight: Integer;
|
2006-03-30 04:54:11 +00:00
|
|
|
itemIndex: Integer;
|
2007-04-02 14:49:00 +00:00
|
|
|
menuBounds: TRect;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
Assert(Assigned(Painter), 'No Painter assigned');
|
2007-04-02 14:49:00 +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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
itemBounds.Top := itemBounds.Bottom +
|
|
|
|
Painter.GetSpacing(seAfterGroupHeader);
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction := GetCurrentAction;
|
2007-04-02 14:49:00 +00:00
|
|
|
handled := False;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
if Assigned(currentAction) then
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
2007-04-02 14:49:00 +00:00
|
|
|
itemHeight := 0;
|
|
|
|
|
|
|
|
currentAction.GetItemHeight(group, itemHeight, handled);
|
|
|
|
if handled then
|
|
|
|
Inc(itemBounds.Top, itemHeight);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if (not handled) and 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);
|
2009-04-22 14:22:01 +00:00
|
|
|
function ExpandedGroupsCount: Integer;
|
2006-03-30 04:54:11 +00:00
|
|
|
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 }
|
2007-04-20 13:37:56 +00:00
|
|
|
// #ToDo1 (MvR) 20-4-2007: check OnSelectedChanging behaviour
|
2007-04-02 14:49:00 +00:00
|
|
|
// if AutoSelectItem then
|
|
|
|
// if not DoAutoSelectItem(AGroup, saBefore) then
|
|
|
|
// exit;
|
2007-01-31 09:41:11 +00:00
|
|
|
|
|
|
|
{ Allow collapse all }
|
|
|
|
if not (AExpanding or AllowCollapseAll) then
|
2009-04-22 14:22:01 +00:00
|
|
|
if ExpandedGroupsCount = 1 then
|
2007-01-31 09:41:11 +00:00
|
|
|
begin
|
|
|
|
if AExpanding and (not Assigned(SelectedItem)) then
|
|
|
|
SelectedItem := AGroup;
|
|
|
|
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
if AGroup.Items.Count > 0 then
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
{ Auto collapse first }
|
|
|
|
if AutoCollapse and AExpanding then
|
|
|
|
DoAutoCollapse(AGroup);
|
|
|
|
|
|
|
|
PerformExpand(AGroup, AExpanding);
|
|
|
|
end else
|
2007-01-31 09:41:11 +00:00
|
|
|
begin
|
|
|
|
AGroup.InternalSetExpanded(AExpanding);
|
2007-04-02 14:49:00 +00:00
|
|
|
SelectedItem := AGroup;
|
|
|
|
|
|
|
|
{ Auto collapse after - if selecting the group takes some time this ensures
|
|
|
|
that the animation starts afterwards. }
|
|
|
|
if AutoCollapse and AExpanding then
|
|
|
|
DoAutoCollapse(AGroup);
|
2007-01-31 09:41:11 +00:00
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBar.DoSelectedChanged;
|
2006-04-17 18:41:43 +00:00
|
|
|
begin
|
|
|
|
if Assigned(FOnSelectedChanged) then
|
|
|
|
FOnSelectedChanged(Self, SelectedItem);
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
procedure TX2CustomMenuBar.DoCollapsed(AGroup: TX2MenuBarGroup);
|
|
|
|
begin
|
|
|
|
if Assigned(FOnCollapsed) then
|
|
|
|
FOnCollapsed(Self, AGroup);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.DoCollapsing(AGroup: TX2MenuBarGroup; var AAllowed: Boolean);
|
|
|
|
begin
|
|
|
|
if Assigned(FOnCollapsing) then
|
|
|
|
FOnCollapsing(Self, AGroup, AAllowed);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.DoExpanded(AGroup: TX2MenuBarGroup);
|
|
|
|
begin
|
|
|
|
if Assigned(FOnExpanded) then
|
|
|
|
FOnExpanded(Self, AGroup);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.DoExpanding(AGroup: TX2MenuBarGroup; var AAllowed: Boolean);
|
|
|
|
begin
|
|
|
|
if Assigned(FOnExpanding) then
|
|
|
|
FOnExpanding(Self, AGroup, AAllowed);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBar.AllowInteraction: Boolean;
|
2007-04-20 13:37:56 +00:00
|
|
|
var
|
|
|
|
currentAction: TX2CustomMenuBarAction;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2007-04-20 13:37:56 +00:00
|
|
|
Result := True;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction := GetCurrentAction;
|
2007-04-20 13:37:56 +00:00
|
|
|
if Assigned(currentAction) then
|
2009-04-22 14:22:01 +00:00
|
|
|
Result := currentAction.AllowInteraction;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
function TX2CustomMenuBar.ItemEnabled(AItem: TX2CustomMenuBarItem): Boolean;
|
|
|
|
begin
|
|
|
|
Result := AItem.Enabled and AItem.Visible;
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBar.GetCurrentAction: TX2CustomMenuBarAction;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2007-04-02 14:49:00 +00:00
|
|
|
Result := nil;
|
|
|
|
if ActionQueue.Count > 0 then
|
|
|
|
Result := TX2CustomMenuBarAction(ActionQueue[0]);
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
procedure TX2CustomMenuBar.PushAction(AAction: TX2CustomMenuBarAction);
|
2007-06-01 06:41:52 +00:00
|
|
|
var
|
|
|
|
action: TX2CustomMenuBarAction;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
2007-06-01 06:41:52 +00:00
|
|
|
action := AAction;
|
|
|
|
|
|
|
|
if ActionQueue.Count = 0 then
|
|
|
|
begin
|
|
|
|
{ Start the action; if it's terminated immediately don't add it to the
|
|
|
|
queue. This enables actions like selecting an item without requiring
|
|
|
|
animation to fire straight away. }
|
2009-04-22 14:22:01 +00:00
|
|
|
action.Start;
|
2007-06-01 06:41:52 +00:00
|
|
|
|
|
|
|
if action.Terminated then
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
action.Stop;
|
2007-06-01 06:41:52 +00:00
|
|
|
FreeAndNil(action);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Assigned(action) then
|
|
|
|
ActionQueue.Add(action);
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBar.PopCurrentAction;
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
if ActionQueue.Count > 0 then
|
|
|
|
ActionQueue.Delete(0);
|
2006-03-30 04:54:11 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
procedure TX2CustomMenuBar.InternalSetExpanded(AGroup: TX2MenuBarGroup;
|
|
|
|
AExpanded: Boolean);
|
|
|
|
begin
|
|
|
|
AGroup.InternalSetExpanded(AExpanded);
|
|
|
|
DoExpandedChanged(AGroup);
|
2007-06-01 06:41:52 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2007-04-20 13:37:56 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.InternalSetSelected(AItem: TX2CustomMenuBarItem);
|
2007-06-01 06:41:52 +00:00
|
|
|
var
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
begin
|
|
|
|
FSelectedItem := AItem;
|
2009-04-22 14:22:01 +00:00
|
|
|
DoSelectedChanged;
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2007-06-01 06:41:52 +00:00
|
|
|
if Assigned(AItem) then
|
|
|
|
begin
|
|
|
|
if (AItem is TX2MenuBarItem) then
|
|
|
|
begin
|
|
|
|
group := TX2MenuBarItem(AItem).Group;
|
|
|
|
if Assigned(group) then
|
|
|
|
group.SelectedItem := AItem.Index;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Assigned(AItem) and Assigned(AItem.Action) then
|
|
|
|
AItem.ActionLink.Execute(Self);
|
|
|
|
end;
|
2007-04-20 13:37:56 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
function TX2CustomMenuBar.DoAutoCollapse(AGroup: TX2MenuBarGroup): Boolean;
|
2006-03-30 04:54:11 +00:00
|
|
|
var
|
2007-04-02 14:49:00 +00:00
|
|
|
possibleGroup: TX2MenuBarGroup;
|
2006-03-30 04:54:11 +00:00
|
|
|
expandedGroup: TX2MenuBarGroup;
|
|
|
|
groupIndex: Integer;
|
|
|
|
group: TX2MenuBarGroup;
|
2007-04-02 14:49:00 +00:00
|
|
|
collapseGroups: TList;
|
|
|
|
collapseActions: TX2MenuBarAnimateMultipleAction;
|
|
|
|
collapseAction: TX2MenuBarAnimateAction;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
begin
|
2007-04-02 14:49:00 +00:00
|
|
|
Result := True;
|
2006-03-30 04:54:11 +00:00
|
|
|
expandedGroup := AGroup;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
{ If no group is specified, use the first appropriate group }
|
2006-03-30 04:54:11 +00:00
|
|
|
if not Assigned(expandedGroup) then
|
|
|
|
begin
|
2007-04-02 14:49:00 +00:00
|
|
|
possibleGroup := nil;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
if ItemVisible(Groups[groupIndex]) then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2007-04-02 14:49:00 +00:00
|
|
|
if Groups[groupIndex].Expanded then
|
|
|
|
begin
|
|
|
|
expandedGroup := Groups[groupIndex];
|
|
|
|
break;
|
|
|
|
end else
|
|
|
|
if not Assigned(possibleGroup) then
|
|
|
|
possibleGroup := nil;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
if not Assigned(expandedGroup) then
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
|
|
|
expandedGroup := possibleGroup;
|
|
|
|
|
|
|
|
if Assigned(expandedGroup) then
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
2007-04-02 14:49:00 +00:00
|
|
|
{ Expand the first visible group. This will trigger DoAutoCollapse
|
|
|
|
again. }
|
|
|
|
Result := PerformExpand(expandedGroup, True);
|
|
|
|
Exit;
|
|
|
|
end;
|
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
end;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
collapseGroups := TList.Create;
|
2007-04-02 14:49:00 +00:00
|
|
|
try
|
|
|
|
{ Determine which groups to collapse }
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
begin
|
|
|
|
group := Groups[groupIndex];
|
|
|
|
|
|
|
|
if (group <> expandedGroup) and (group.Expanded) then
|
|
|
|
collapseGroups.Add(group);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if collapseGroups.Count > 0 then
|
|
|
|
begin
|
|
|
|
{ If more than one, collapse simultaniously }
|
|
|
|
if collapseGroups.Count > 1 then
|
|
|
|
begin
|
|
|
|
{ Check if all the groups are allowed to collapse first }
|
|
|
|
for groupIndex := 0 to Pred(collapseGroups.Count) do
|
|
|
|
begin
|
|
|
|
group := TX2MenuBarGroup(collapseGroups[groupIndex]);
|
|
|
|
DoCollapsing(group, Result);
|
|
|
|
|
|
|
|
if not Result then
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
if Result then
|
|
|
|
begin
|
|
|
|
{ Animate visible groups }
|
|
|
|
collapseActions := TX2MenuBarAnimateMultipleAction.Create(Self);
|
|
|
|
|
|
|
|
for groupIndex := 0 to Pred(collapseGroups.Count) do
|
|
|
|
begin
|
|
|
|
group := TX2MenuBarGroup(collapseGroups[groupIndex]);
|
|
|
|
|
|
|
|
if ItemVisible(group) then
|
|
|
|
begin
|
|
|
|
collapseAction := TX2MenuBarAnimateAction(GetAnimateAction(group, False));
|
|
|
|
|
|
|
|
if Assigned(collapseAction) then
|
|
|
|
collapseActions.Add(collapseAction);
|
|
|
|
end;
|
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
if collapseActions.Count > 0 then
|
|
|
|
PushAction(collapseActions)
|
|
|
|
else
|
|
|
|
FreeAndNil(collapseActions);
|
|
|
|
|
|
|
|
|
|
|
|
{ Add the collapse actions after the animation so OnCollapsed events
|
|
|
|
raise afterwards. }
|
|
|
|
for groupIndex := 0 to Pred(collapseGroups.Count) do
|
|
|
|
PushAction(TX2MenuBarExpandAction.Create(Self, TX2MenuBarGroup(collapseGroups[groupIndex]),
|
|
|
|
False));
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
Result := PerformExpand(TX2MenuBarGroup(collapseGroups[0]), False);
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeAndNil(collapseGroups);
|
2006-03-30 04:54:11 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
function TX2CustomMenuBar.DoAutoSelectItem(AGroup: TX2MenuBarGroup): 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
|
2007-04-20 13:37:56 +00:00
|
|
|
Result := True;
|
2006-04-17 18:41:43 +00:00
|
|
|
group := AGroup;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
if Assigned(newItem) and (newItem <> SelectedItem) then
|
|
|
|
PerformSelectItem(newItem);
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
|
|
|
end;
|
2006-04-17 18:41:43 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
function TX2CustomMenuBar.DoExpand(AGroup: TX2MenuBarGroup; AExpanding: Boolean): Boolean;
|
|
|
|
var
|
|
|
|
allowed: Boolean;
|
|
|
|
expandAction: TX2MenuBarAnimateAction;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
allowed := True;
|
|
|
|
|
|
|
|
if AExpanding then
|
|
|
|
DoExpanding(AGroup, allowed)
|
|
|
|
else
|
|
|
|
DoCollapsing(AGroup, allowed);
|
|
|
|
|
|
|
|
if not allowed then
|
|
|
|
Exit;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
if AExpanding then
|
|
|
|
if not PerformAutoCollapse(AGroup) then
|
|
|
|
Exit;
|
|
|
|
|
|
|
|
// if not AExpanding then
|
|
|
|
// begin
|
|
|
|
// // #ToDo1 (MvR) 22-3-2007: ? anything ?
|
|
|
|
// end else
|
|
|
|
// begin
|
|
|
|
// if not (PerformAutoCollapse(AGroup) and
|
|
|
|
// PerformAutoSelectItem(AGroup)) then
|
|
|
|
// Result := False;
|
|
|
|
// end;
|
2007-04-02 14:49:00 +00:00
|
|
|
|
|
|
|
Result := True;
|
|
|
|
expandAction := TX2MenuBarAnimateAction(GetAnimateAction(AGroup, AExpanding));
|
|
|
|
if Assigned(expandAction) then
|
|
|
|
PushAction(expandAction);
|
|
|
|
|
|
|
|
PushAction(TX2MenuBarExpandAction.Create(Self, AGroup, AExpanding));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.DoSelectItem(AItem: TX2CustomMenuBarItem): Boolean;
|
|
|
|
begin
|
2007-04-20 13:37:56 +00:00
|
|
|
PushAction(TX2MenuBarSelectAction.Create(Self, AItem));
|
2007-04-02 14:49:00 +00:00
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.PerformAutoCollapse(AGroup: TX2MenuBarGroup): Boolean;
|
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
|
|
|
|
if AutoCollapse then
|
|
|
|
Result := DoAutoCollapse(AGroup);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.PerformAutoSelectItem(AGroup: TX2MenuBarGroup): Boolean;
|
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
|
|
|
|
if AutoSelectItem then
|
|
|
|
Result := DoAutoSelectItem(AGroup);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.PerformExpand(AGroup: TX2MenuBarGroup;
|
|
|
|
AExpanding: Boolean): Boolean;
|
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
|
|
|
|
if AExpanding <> AGroup.Expanded then
|
|
|
|
Result := DoExpand(AGroup, AExpanding);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.PerformSelectItem(AItem: TX2CustomMenuBarItem): Boolean;
|
|
|
|
begin
|
|
|
|
Result := DoSelectItem(AItem);
|
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
|
2009-04-22 14:22:01 +00:00
|
|
|
Painter.EndPaint;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
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;
|
2010-03-30 13:36:13 +00:00
|
|
|
|
|
|
|
case ADirection of
|
|
|
|
mbdUp: groupIndex := Pred(Groups.Count);
|
|
|
|
mbdDown: groupIndex := 0;
|
|
|
|
end;
|
|
|
|
|
2007-01-31 09:41:11 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBar.SelectFirst: TX2CustomMenuBarItem;
|
2006-05-22 05:13:12 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBar.SelectLast: TX2CustomMenuBarItem;
|
2006-05-22 05:13:12 +00:00
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
if AllowInteraction then
|
|
|
|
begin
|
2010-03-30 13:36:13 +00:00
|
|
|
Result := Iterate(FindEnabledItem, mbdUp);
|
2007-01-31 09:41:11 +00:00
|
|
|
if Assigned(Result) then
|
|
|
|
SelectedItem := Result;
|
|
|
|
end;
|
2006-05-22 05:13:12 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBar.SelectNext: TX2CustomMenuBarItem;
|
2006-05-22 05:13:12 +00:00
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
if AllowInteraction then
|
|
|
|
begin
|
2007-04-20 13:37:56 +00:00
|
|
|
Result := Iterate(FindEnabledItem, mbdDown, nil, SelectedItem);
|
2007-01-31 09:41:11 +00:00
|
|
|
if Assigned(Result) then
|
|
|
|
SelectedItem := Result;
|
|
|
|
end;
|
2006-05-22 05:13:12 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBar.SelectPrior: TX2CustomMenuBarItem;
|
2006-05-22 05:13:12 +00:00
|
|
|
begin
|
2007-01-31 09:41:11 +00:00
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
if AllowInteraction then
|
|
|
|
begin
|
2007-04-20 13:37:56 +00:00
|
|
|
Result := Iterate(FindEnabledItem, mbdUp, nil, SelectedItem);
|
2007-01-31 09:41:11 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-05-22 05:13:12 +00:00
|
|
|
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;
|
2009-04-22 14:22:01 +00:00
|
|
|
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;
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.PainterUpdate(Sender: TX2CustomMenuBarPainter);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2006-04-17 18:41:43 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2006-04-02 20:00:02 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
|
|
|
X, Y: Integer);
|
|
|
|
var
|
|
|
|
hitTest: TX2MenuBarHitTest;
|
|
|
|
|
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
if Button = mbLeft then
|
2007-04-02 14:49:00 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
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);
|
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;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
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);
|
2009-04-22 14:22:01 +00:00
|
|
|
TestMousePos;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
cursor := crDefault;
|
2007-04-02 14:49:00 +00:00
|
|
|
if Assigned(HotItem) then
|
|
|
|
begin
|
|
|
|
if HotItem is TX2MenuBarGroup then
|
2006-04-17 18:41:43 +00:00
|
|
|
cursor := CursorGroup
|
2007-04-02 14:49:00 +00:00
|
|
|
else if HotItem is TX2MenuBarItem then
|
2006-04-17 18:41:43 +00:00
|
|
|
cursor := CursorItem;
|
2007-04-02 14:49:00 +00:00
|
|
|
end;
|
2006-04-17 18:41:43 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
if (cursor <> crDefault) and ItemEnabled(HotItem) 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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
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;
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2006-03-24 05:56:59 +00:00
|
|
|
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);
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2006-04-02 20:00:02 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBar.TestMousePos;
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
|
|
|
hitTest: TX2MenuBarHitTest;
|
|
|
|
|
|
|
|
begin
|
|
|
|
hitTest := Self.HitTest(FLastMousePos.X, FLastMousePos.Y);
|
|
|
|
if hitTest.Item <> FHotItem then
|
|
|
|
begin
|
2007-04-02 14:49:00 +00:00
|
|
|
HotItem := hitTest.Item;
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
function TX2CustomMenuBar.GetMenuHeight: Integer;
|
2006-04-01 19:51:46 +00:00
|
|
|
var
|
2007-04-02 14:49:00 +00:00
|
|
|
currentAction: TX2CustomMenuBarAction;
|
2006-04-01 19:51:46 +00:00
|
|
|
group: TX2MenuBarGroup;
|
2007-04-02 14:49:00 +00:00
|
|
|
groupIndex: Integer;
|
|
|
|
handled: Boolean;
|
2006-04-01 19:51:46 +00:00
|
|
|
item: TX2MenuBarItem;
|
2007-04-02 14:49:00 +00:00
|
|
|
itemHeight: Integer;
|
|
|
|
itemIndex: Integer;
|
|
|
|
menuBounds: TRect;
|
2006-04-01 19:51:46 +00:00
|
|
|
|
|
|
|
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));
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
handled := False;
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction := GetCurrentAction;
|
2007-04-02 14:49:00 +00:00
|
|
|
if Assigned(currentAction) then
|
2006-04-01 19:51:46 +00:00
|
|
|
begin
|
2007-04-02 14:49:00 +00:00
|
|
|
currentAction.GetItemHeight(group, itemHeight, handled);
|
|
|
|
|
|
|
|
if handled then
|
|
|
|
Inc(Result, itemHeight);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if (not handled) and group.Expanded then
|
2006-04-01 19:51:46 +00:00
|
|
|
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;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
procedure TX2CustomMenuBar.UpdateScrollbar;
|
2006-04-02 20:00:02 +00:00
|
|
|
var
|
2007-04-20 13:37:56 +00:00
|
|
|
currentAction: TX2CustomMenuBarAction;
|
2006-04-02 20:00:02 +00:00
|
|
|
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. }
|
2009-04-22 14:22:01 +00:00
|
|
|
currentAction := GetCurrentAction;
|
|
|
|
if Assigned(currentAction) and (not currentAction.AllowUpdateScrollbar) then
|
2006-04-02 20:00:02 +00:00
|
|
|
exit;
|
|
|
|
|
|
|
|
FillChar(scrollInfo, SizeOf(TScrollInfo), #0);
|
|
|
|
scrollInfo.cbSize := SizeOf(TScrollInfo);
|
|
|
|
scrollInfo.fMask := SIF_PAGE or SIF_RANGE;
|
|
|
|
|
|
|
|
if Scrollbar then
|
|
|
|
begin
|
|
|
|
scrollInfo.nMin := 0;
|
2009-04-22 14:22:01 +00:00
|
|
|
scrollInfo.nMax := GetMenuHeight;
|
2006-04-02 20:00:02 +00:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
2008-05-26 10:22:50 +00:00
|
|
|
procedure TX2CustomMenuBar.ImagesChange(Sender: TObject);
|
|
|
|
begin
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2008-05-26 10:22:50 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBar.SetAllowCollapseAll(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FAllowCollapseAll then
|
|
|
|
begin
|
|
|
|
FAllowCollapseAll := Value;
|
|
|
|
|
|
|
|
end;
|
|
|
|
end;
|
2006-04-01 19:51:46 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBar.SetAutoSelectItem(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FAutoSelectItem then
|
|
|
|
begin
|
|
|
|
FAutoSelectItem := Value;
|
|
|
|
|
2007-04-20 13:37:56 +00:00
|
|
|
if Value and (not Assigned(SelectedItem)) then
|
|
|
|
DoAutoSelectItem(nil);
|
2006-04-02 20:00:02 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure TX2CustomMenuBar.SetBorderStyle(const Value: TBorderStyle);
|
|
|
|
begin
|
|
|
|
if Value <> FBorderStyle then
|
|
|
|
begin
|
|
|
|
FBorderStyle := Value;
|
2009-04-22 14:22:01 +00:00
|
|
|
RecreateWnd;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure TX2CustomMenuBar.SetGroups(const Value: TX2MenuBarGroups);
|
|
|
|
begin
|
|
|
|
if Value <> FGroups then
|
|
|
|
FGroups.Assign(Value);
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBar.SetHideScrollbar(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FHideScrollbar then
|
|
|
|
begin
|
|
|
|
FHideScrollbar := Value;
|
2009-04-22 14:22:01 +00:00
|
|
|
RecreateWnd;
|
2006-04-02 20:00:02 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
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
|
2008-05-26 10:22:50 +00:00
|
|
|
begin
|
|
|
|
FImages.UnRegisterChanges(FImagesChangeLink);
|
2006-04-17 18:41:43 +00:00
|
|
|
FImages.RemoveFreeNotification(Self);
|
2008-05-26 10:22:50 +00:00
|
|
|
end;
|
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
|
2008-05-26 10:22:50 +00:00
|
|
|
begin
|
2006-04-17 18:41:43 +00:00
|
|
|
FImages.FreeNotification(Self);
|
2008-05-26 10:22:50 +00:00
|
|
|
FImages.RegisterChanges(FImagesChangeLink);
|
|
|
|
end;
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
// #ToDo1 (MvR) 13-3-2007: check queue ?
|
2006-03-24 05:56:59 +00:00
|
|
|
FPainter := Value;
|
|
|
|
|
|
|
|
if Assigned(FPainter) then
|
|
|
|
begin
|
|
|
|
FPainter.FreeNotification(Self);
|
|
|
|
FPainter.AttachObserver(Self);
|
|
|
|
end;
|
|
|
|
|
2009-04-22 14:22:01 +00:00
|
|
|
Invalidate;
|
2006-04-02 20:00:02 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-04-02 20:00:02 +00:00
|
|
|
procedure TX2CustomMenuBar.SetScrollbar(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FScrollbar then
|
|
|
|
begin
|
|
|
|
FScrollbar := Value;
|
2009-04-22 14:22:01 +00:00
|
|
|
RecreateWnd;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
|
2006-04-17 18:41:43 +00:00
|
|
|
procedure TX2CustomMenuBar.SetSelectedItem(const Value: TX2CustomMenuBarItem);
|
|
|
|
var
|
|
|
|
allowed: Boolean;
|
|
|
|
group: TX2MenuBarGroup;
|
2007-04-02 14:49:00 +00:00
|
|
|
selectItem: TX2CustomMenuBarItem;
|
2006-04-17 18:41:43 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Value <> FSelectedItem then
|
|
|
|
begin
|
2007-06-01 06:41:52 +00:00
|
|
|
if Assigned(Value) and (Value.MenuBar <> Self) then
|
|
|
|
raise EInvalidItem.Create(SInvalidItem);
|
|
|
|
|
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
allowed := (not Assigned(Value)) or ItemEnabled(Value);
|
|
|
|
if allowed then
|
|
|
|
DoSelectedChanging(Value, allowed);
|
|
|
|
|
2007-06-01 06:41:52 +00:00
|
|
|
|
2007-04-02 14:49:00 +00:00
|
|
|
if allowed then
|
2006-04-17 18:41:43 +00:00
|
|
|
begin
|
2007-04-02 14:49:00 +00:00
|
|
|
selectItem := Value;
|
|
|
|
|
2007-06-01 06:41:52 +00:00
|
|
|
if Assigned(selectItem) then
|
2006-04-17 18:41:43 +00:00
|
|
|
begin
|
2007-06-01 06:41:52 +00:00
|
|
|
if selectItem is TX2MenuBarGroup then
|
2006-04-17 18:41:43 +00:00
|
|
|
begin
|
2007-06-01 06:41:52 +00:00
|
|
|
group := TX2MenuBarGroup(selectItem);
|
|
|
|
|
|
|
|
{ Check if the group should be collapsed }
|
|
|
|
if group.Expanded and (not AutoCollapse) then
|
2007-04-20 13:37:56 +00:00
|
|
|
begin
|
2007-06-01 06:41:52 +00:00
|
|
|
PerformExpand(group, False);
|
2007-04-20 13:37:56 +00:00
|
|
|
end else
|
|
|
|
begin
|
2007-06-01 06:41:52 +00:00
|
|
|
if group.Items.Count > 0 then
|
|
|
|
begin
|
|
|
|
PerformExpand(group, True);
|
|
|
|
PerformAutoSelectItem(group);
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
if PerformAutoCollapse(group) then
|
|
|
|
PerformSelectItem(group);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
if (selectItem is TX2MenuBarItem) then
|
|
|
|
begin
|
|
|
|
group := TX2MenuBarItem(selectItem).Group;
|
|
|
|
if Assigned(group) and (not group.Expanded) then
|
|
|
|
PerformExpand(group, True);
|
2007-04-20 13:37:56 +00:00
|
|
|
end;
|
2007-06-01 06:41:52 +00:00
|
|
|
|
|
|
|
PerformSelectItem(selectItem);
|
2006-04-17 18:41:43 +00:00
|
|
|
end;
|
2007-04-02 14:49:00 +00:00
|
|
|
end else
|
|
|
|
PerformSelectItem(selectItem);
|
|
|
|
end;
|
2006-04-17 18:41:43 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-06-01 06:41:52 +00:00
|
|
|
//procedure TX2CustomMenuBar.WMMouseWheel(var Message: TWMMouseWheel);
|
|
|
|
//begin
|
|
|
|
//// MessageBox(0, 'I gots a mousewheel', '', 0);
|
|
|
|
//end;
|
|
|
|
//
|
|
|
|
//procedure TX2CustomMenuBar.CMMouseWheel(var Message: TCMMouseWheel);
|
|
|
|
//begin
|
|
|
|
//// MessageBox(0, 'I gots a mousewheel', '', 0);
|
|
|
|
//end;
|
|
|
|
|
2009-08-06 08:44:12 +00:00
|
|
|
|
|
|
|
{ TX2MenuBarItemsEnumerator }
|
|
|
|
function TX2MenuBarItemsEnumerator.GetCurrent: TX2MenuBarItem;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarItem(inherited GetCurrent);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2MenuBarGroupsEnumerator }
|
|
|
|
function TX2MenuBarGroupsEnumerator.GetCurrent: TX2MenuBarGroup;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarGroup(inherited GetCurrent);
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
end.
|