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.
|
|
|
|
::
|
|
|
|
:: Last changed: $Date$
|
|
|
|
:: Revision: $Rev$
|
|
|
|
:: Author: $Author$
|
|
|
|
}
|
|
|
|
unit X2CLMenuBar;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Classes,
|
|
|
|
Contnrs,
|
|
|
|
Controls,
|
|
|
|
Forms,
|
|
|
|
Graphics,
|
|
|
|
ImgList,
|
|
|
|
Messages,
|
2006-03-30 04:54:11 +00:00
|
|
|
Types,
|
2006-03-24 05:56:59 +00:00
|
|
|
Windows;
|
|
|
|
|
|
|
|
type
|
|
|
|
// #ToDo1 (MvR) 19-3-2006: implement collection Update mechanisms
|
|
|
|
// #ToDo1 (MvR) 19-3-2006: OnCollapsing/OnCollapse/expand events
|
|
|
|
// #ToDo1 (MvR) 19-3-2006: AutoCollapse property
|
|
|
|
// #ToDo1 (MvR) 19-3-2006: AutoSelectItem property or something
|
|
|
|
// #ToDo1 (MvR) 19-3-2006: find a way to remember the selected item per
|
|
|
|
// group, required for when AutoCollapse = True and
|
|
|
|
// AutoSelectItem = True
|
2006-03-30 04:54:11 +00:00
|
|
|
// #ToDo1 (MvR) 25-3-2006: various Select methods for key support
|
2006-04-01 19:51:46 +00:00
|
|
|
// #ToDo1 (MvR) 1-4-2006: scrollbar support
|
|
|
|
// #ToDo1 (MvR) 1-4-2006: Enabled/Visible properties
|
|
|
|
TX2CustomMenuBarAnimatorClass = class of TX2CustomMenuBarAnimator;
|
|
|
|
TX2CustomMenuBarAnimator = class;
|
|
|
|
TX2CustomMenuBarScrollerClass = class of TX2CustomMenuBarScroller;
|
|
|
|
TX2CustomMenuBarScroller = 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;
|
|
|
|
|
|
|
|
IX2MenuBarPainterObserver = interface
|
|
|
|
['{22DE60C9-49A1-4E7D-B547-901BEDCC0FB7}']
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure PainterUpdate(Sender: TX2CustomMenuBarPainter);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
TX2MenuBarHitTest = record
|
|
|
|
HitTestCode: Integer;
|
2006-03-30 04:54:11 +00:00
|
|
|
Item: TX2CustomMenuBarItem;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
TX2MenuBarDrawState = (mdsHot, mdsSelected, mdsGroupHot, mdsGroupSelected);
|
2006-03-24 05:56:59 +00:00
|
|
|
TX2MenuBarDrawStates = set of TX2MenuBarDrawState;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
TX2MenuBarAnimationStyle = (asNone, asSlide, asDissolve);
|
2006-03-30 04:54:11 +00:00
|
|
|
TX2MenuBarSpacingElement = (seBeforeGroupHeader, seAfterGroupHeader,
|
|
|
|
seBeforeFirstItem, seAfterLastItem,
|
|
|
|
seBeforeItem, seAfterItem);
|
|
|
|
|
|
|
|
TX2MenuBarItemBoundsProc = procedure(Sender: TObject;
|
|
|
|
Item: TX2CustomMenuBarItem;
|
|
|
|
const MenuBounds: TRect;
|
|
|
|
const ItemBounds: TRect;
|
|
|
|
Data: Pointer;
|
|
|
|
var Abort: Boolean) of object;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
:$ Abstract animation class
|
|
|
|
|
|
|
|
:: Descendants implement the animation-specific drawing code.
|
|
|
|
}
|
2006-04-01 19:51:46 +00:00
|
|
|
TX2CustomMenuBarAnimator = class(TObject)
|
2006-03-24 05:56:59 +00:00
|
|
|
private
|
|
|
|
FAnimationTime: Cardinal;
|
|
|
|
FExpanding: Boolean;
|
|
|
|
FGroup: TX2MenuBarGroup;
|
|
|
|
FStartTime: Cardinal;
|
|
|
|
FItemsBuffer: Graphics.TBitmap;
|
|
|
|
FTerminated: Boolean;
|
|
|
|
protected
|
2006-03-30 04:54:11 +00:00
|
|
|
function GetTimeElapsed(): Cardinal; virtual;
|
|
|
|
function GetHeight(): Integer; virtual;
|
|
|
|
procedure SetExpanding(const Value: Boolean); virtual;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure Terminate(); virtual;
|
|
|
|
|
|
|
|
property ItemsBuffer: Graphics.TBitmap read FItemsBuffer;
|
|
|
|
property TimeElapsed: Cardinal read GetTimeElapsed;
|
|
|
|
public
|
|
|
|
constructor Create(AItemsBuffer: Graphics.TBitmap); virtual;
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure Update(); virtual;
|
|
|
|
procedure Draw(ACanvas: TCanvas; const ABounds: TRect); virtual; abstract;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
property AnimationTime: Cardinal read FAnimationTime write FAnimationTime;
|
2006-03-30 04:54:11 +00:00
|
|
|
property Expanding: Boolean read FExpanding write SetExpanding;
|
2006-03-24 05:56:59 +00:00
|
|
|
property Group: TX2MenuBarGroup read FGroup write FGroup;
|
|
|
|
property Terminated: Boolean read FTerminated;
|
2006-03-30 04:54:11 +00:00
|
|
|
property Height: Integer read GetHeight;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Implements a sliding animation
|
|
|
|
}
|
2006-04-01 19:51:46 +00:00
|
|
|
TX2MenuBarSlideAnimator = class(TX2CustomMenuBarAnimator)
|
2006-03-24 05:56:59 +00:00
|
|
|
private
|
|
|
|
FSlideHeight: Integer;
|
2006-03-30 04:54:11 +00:00
|
|
|
protected
|
|
|
|
function GetHeight(): Integer; override;
|
2006-03-24 05:56:59 +00:00
|
|
|
public
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure Update(); override;
|
|
|
|
procedure Draw(ACanvas: TCanvas; const ABounds: TRect); override;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
2006-04-01 19:51:46 +00:00
|
|
|
:$ Implements a dissolve animation
|
2006-03-30 04:54:11 +00:00
|
|
|
}
|
2006-04-01 19:51:46 +00:00
|
|
|
TX2MenuBarDissolveAnimator = class(TX2CustomMenuBarAnimator)
|
2006-03-30 04:54:11 +00:00
|
|
|
private
|
|
|
|
FItemsState: Graphics.TBitmap;
|
|
|
|
FMask: Graphics.TBitmap;
|
|
|
|
FPixels: TList;
|
|
|
|
protected
|
|
|
|
procedure SetExpanding(const Value: Boolean); override;
|
|
|
|
|
|
|
|
property ItemsState: Graphics.TBitmap read FItemsState;
|
|
|
|
property Mask: Graphics.TBitmap read FMask;
|
|
|
|
public
|
|
|
|
constructor Create(AItemsBuffer: Graphics.TBitmap); override;
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
|
|
|
procedure Update(); override;
|
|
|
|
procedure Draw(ACanvas: TCanvas; const ABounds: TRect); override;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
{
|
|
|
|
:$ Abstract scroller class.
|
|
|
|
}
|
|
|
|
TX2CustomMenuBarScroller = class(TPersistent)
|
|
|
|
private
|
|
|
|
FMenuBar: TX2CustomMenuBar;
|
|
|
|
FClientHeight: Integer;
|
|
|
|
FMenuHeight: Integer;
|
|
|
|
FOffset: Integer;
|
|
|
|
protected
|
|
|
|
function ApplyMargins(const ABounds: TRect): TRect; virtual;
|
|
|
|
|
|
|
|
property MenuBar: TX2CustomMenuBar read FMenuBar;
|
|
|
|
public
|
|
|
|
constructor Create(AMenuBar: TX2CustomMenuBar); virtual;
|
|
|
|
|
|
|
|
procedure Draw(ACanvas: TCanvas; const ABounds: TRect); virtual; abstract;
|
|
|
|
|
|
|
|
function HitTest(const APoint: TPoint): TX2MenuBarHitTest; overload; virtual;
|
|
|
|
function HitTest(AX, AY: Integer): TX2MenuBarHitTest; overload;
|
|
|
|
|
|
|
|
property ClientHeight: Integer read FClientHeight write FClientHeight;
|
|
|
|
property MenuHeight: Integer read FMenuHeight write FMenuHeight;
|
|
|
|
property Offset: Integer read FOffset write FOffset;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Scrollbar class.
|
|
|
|
}
|
|
|
|
TScrollbarArrowDirection = (adUp, adDown);
|
|
|
|
|
|
|
|
TX2MenuBarScrollbarScroller = class(TX2CustomMenuBarScroller)
|
|
|
|
private
|
|
|
|
FScrollbarWidth: Integer;
|
|
|
|
FArrowHeight: Integer;
|
|
|
|
protected
|
|
|
|
function ApplyMargins(const ABounds: TRect): TRect; override;
|
|
|
|
|
|
|
|
procedure DrawArrowButton(ACanvas: TCanvas; const ABounds: TRect; ADirection: TScrollbarArrowDirection); virtual;
|
|
|
|
procedure DrawBackground(ACanvas: TCanvas; const ABounds: TRect); virtual;
|
|
|
|
procedure DrawThumb(ACanvas: TCanvas; const ABounds: TRect); virtual;
|
|
|
|
|
|
|
|
property ScrollbarWidth: Integer read FScrollbarWidth write FScrollbarWidth;
|
|
|
|
property ArrowHeight: Integer read FArrowHeight write FArrowHeight;
|
|
|
|
public
|
|
|
|
constructor Create(AMenuBar: TX2CustomMenuBar); override;
|
|
|
|
|
|
|
|
function HitTest(const APoint: TPoint): TX2MenuBarHitTest; override;
|
|
|
|
|
|
|
|
procedure Draw(ACanvas: TCanvas; const ABounds: TRect); override;
|
|
|
|
end;
|
|
|
|
|
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
|
|
|
|
FAnimationStyle: TX2MenuBarAnimationStyle;
|
|
|
|
FAnimationTime: Cardinal;
|
|
|
|
FMenuBar: TX2CustomMenuBar;
|
|
|
|
FObservers: TInterfaceList;
|
|
|
|
|
|
|
|
function GetMenuBar(): TX2CustomMenuBar;
|
|
|
|
protected
|
|
|
|
procedure BeginPaint(const AMenuBar: TX2CustomMenuBar);
|
|
|
|
procedure EndPaint();
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function ApplyMargins(const ABounds: TRect): TRect; virtual;
|
|
|
|
function GetSpacing(AElement: TX2MenuBarSpacingElement): Integer; virtual;
|
2006-03-24 05:56:59 +00:00
|
|
|
function GetGroupHeaderHeight(AGroup: TX2MenuBarGroup): Integer; virtual; abstract;
|
|
|
|
function GetGroupHeight(AGroup: TX2MenuBarGroup): Integer; virtual;
|
|
|
|
function GetItemHeight(AItem: TX2MenuBarItem): Integer; virtual; abstract;
|
|
|
|
|
|
|
|
procedure DrawBackground(ACanvas: TCanvas; const ABounds: TRect); virtual; abstract;
|
|
|
|
procedure DrawGroupHeader(ACanvas: TCanvas; AGroup: TX2MenuBarGroup; const ABounds: TRect; AState: TX2MenuBarDrawStates); virtual; abstract;
|
|
|
|
procedure DrawItem(ACanvas: TCanvas; AItem: TX2MenuBarItem; const ABounds: TRect; AState: TX2MenuBarDrawStates); virtual; abstract;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
function GetAnimatorClass(): TX2CustomMenuBarAnimatorClass; virtual;
|
|
|
|
function GetScrollerClass(): TX2CustomMenuBarScrollerClass; virtual;
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure FindHit(Sender: TObject; Item: TX2CustomMenuBarItem; const MenuBounds: TRect; const ItemBounds: TRect; Data: Pointer; var Abort: Boolean);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
procedure NotifyObservers();
|
|
|
|
|
|
|
|
property MenuBar: TX2CustomMenuBar read GetMenuBar;
|
|
|
|
protected
|
|
|
|
property AnimationStyle: TX2MenuBarAnimationStyle read FAnimationStyle write FAnimationStyle;
|
|
|
|
property AnimationTime: Cardinal read FAnimationTime write FAnimationTime;
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function HitTest(const APoint: TPoint): TX2MenuBarHitTest; overload; virtual;
|
2006-03-24 05:56:59 +00:00
|
|
|
function HitTest(AX, AY: Integer): TX2MenuBarHitTest; overload;
|
|
|
|
|
|
|
|
procedure AttachObserver(AObserver: IX2MenuBarPainterObserver);
|
|
|
|
procedure DetachObserver(AObserver: IX2MenuBarPainterObserver);
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
2006-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
|
|
|
|
FCaption: String;
|
|
|
|
FData: TObject;
|
|
|
|
FImageIndex: TImageIndex;
|
2006-03-30 04:54:11 +00:00
|
|
|
FOwnsData: Boolean;
|
|
|
|
protected
|
|
|
|
function GetMenuBar(): TX2CustomMenuBar; virtual;
|
|
|
|
procedure SetCaption(const Value: String); virtual;
|
|
|
|
procedure SetData(const Value: TObject); virtual;
|
|
|
|
procedure SetImageIndex(const Value: TImageIndex); virtual;
|
2006-03-24 05:56:59 +00:00
|
|
|
public
|
|
|
|
constructor Create(Collection: TCollection); override;
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
|
|
|
procedure Assign(Source: TPersistent); override;
|
|
|
|
|
|
|
|
property Data: TObject read FData write SetData;
|
|
|
|
property OwnsData: Boolean read FOwnsData write FOwnsData;
|
2006-03-30 04:54:11 +00:00
|
|
|
property MenuBar: TX2CustomMenuBar read GetMenuBar;
|
2006-03-24 05:56:59 +00:00
|
|
|
published
|
|
|
|
property Caption: String read FCaption write SetCaption;
|
|
|
|
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
{
|
|
|
|
:$ Contains a single menu item.
|
|
|
|
}
|
|
|
|
TX2MenuBarItem = class(TX2CustomMenuBarItem)
|
|
|
|
private
|
|
|
|
function GetGroup(): TX2MenuBarGroup;
|
|
|
|
public
|
|
|
|
property Group: TX2MenuBarGroup read GetGroup;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{
|
|
|
|
:$ Manages a collection of menu items.
|
|
|
|
}
|
|
|
|
TX2MenuBarItems = class(TOwnedCollection)
|
|
|
|
private
|
|
|
|
function GetItem(Index: Integer): TX2MenuBarItem;
|
|
|
|
procedure SetItem(Index: Integer; const Value: TX2MenuBarItem);
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TPersistent);
|
|
|
|
|
|
|
|
function Add(const ACaption: TCaption = ''): TX2MenuBarItem;
|
|
|
|
|
|
|
|
property Items[Index: Integer]: TX2MenuBarItem read GetItem write SetItem; default;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Contains a single menu group.
|
|
|
|
}
|
2006-03-30 04:54:11 +00:00
|
|
|
TX2MenuBarGroup = class(TX2CustomMenuBarItem)
|
2006-03-24 05:56:59 +00:00
|
|
|
private
|
2006-03-30 04:54:11 +00:00
|
|
|
FExpanded: Boolean;
|
|
|
|
FItems: TX2MenuBarItems;
|
|
|
|
FSelectedItem: Integer;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function GetSelectedItem(): Integer;
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure SetExpanded(const Value: Boolean);
|
|
|
|
procedure SetItems(const Value: TX2MenuBarItems);
|
2006-03-30 04:54:11 +00:00
|
|
|
protected
|
|
|
|
procedure InternalSetExpanded(const Value: Boolean);
|
|
|
|
|
|
|
|
property SelectedItem: Integer read GetSelectedItem write FSelectedItem;
|
2006-03-24 05:56:59 +00:00
|
|
|
public
|
|
|
|
constructor Create(Collection: TCollection); override;
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
|
|
|
procedure Assign(Source: TPersistent); override;
|
|
|
|
published
|
|
|
|
property Expanded: Boolean read FExpanded write SetExpanded;
|
|
|
|
property Items: TX2MenuBarItems read FItems write SetItems;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Manages a collection of menu groups.
|
|
|
|
}
|
|
|
|
TX2MenuBarGroups = class(TOwnedCollection)
|
|
|
|
private
|
|
|
|
function GetItem(Index: Integer): TX2MenuBarGroup;
|
|
|
|
procedure SetItem(Index: Integer; const Value: TX2MenuBarGroup);
|
|
|
|
public
|
|
|
|
constructor Create(AOwner: TPersistent);
|
|
|
|
|
|
|
|
function Add(const ACaption: TCaption = ''): TX2MenuBarGroup;
|
|
|
|
|
|
|
|
property Items[Index: Integer]: TX2MenuBarGroup read GetItem write SetItem; default;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
TX2MenuBarOption = (mboAutoCollapse, { Allow only a single group to be expanded }
|
|
|
|
mboAutoSelectItem, { Always select an item when expanding a group }
|
|
|
|
mboAllowCollapseAll); { Allow all groups to be collapsed }
|
|
|
|
TX2MenuBarOptions = set of TX2MenuBarOption;
|
|
|
|
|
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-01 19:51:46 +00:00
|
|
|
FAnimator: TX2CustomMenuBarAnimator;
|
2006-03-30 04:54:11 +00:00
|
|
|
FBorderStyle: TBorderStyle;
|
|
|
|
FExpandingGroups: TStringList;
|
|
|
|
FGroups: TX2MenuBarGroups;
|
|
|
|
FHotItem: TX2CustomMenuBarItem;
|
|
|
|
FImageList: TCustomImageList;
|
|
|
|
FLastMousePos: TPoint;
|
|
|
|
FOptions: TX2MenuBarOptions;
|
|
|
|
FPainter: TX2CustomMenuBarPainter;
|
|
|
|
FSelectedItem: TX2CustomMenuBarItem;
|
2006-04-01 19:51:46 +00:00
|
|
|
FScroller: TX2CustomMenuBarScroller;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure SetAnimator(const Value: TX2CustomMenuBarAnimator);
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure SetBorderStyle(const Value: TBorderStyle);
|
|
|
|
procedure SetGroups(const Value: TX2MenuBarGroups);
|
|
|
|
procedure SetImageList(const Value: TCustomImageList);
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure SetOptions(const Value: TX2MenuBarOptions);
|
|
|
|
procedure SetScroller(const Value: TX2CustomMenuBarScroller);
|
2006-03-24 05:56:59 +00:00
|
|
|
protected
|
|
|
|
procedure CreateParams(var Params: TCreateParams); override;
|
|
|
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure PainterUpdate(Sender: TX2CustomMenuBarPainter);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
|
|
|
|
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
|
|
|
|
// procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
|
|
|
|
procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
|
|
|
|
|
|
|
|
procedure TestMousePos(); virtual;
|
2006-04-01 19:51:46 +00:00
|
|
|
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
|
|
|
|
|
|
|
procedure WMEraseBkgnd(var Msg: TWMEraseBkgnd); message WM_ERASEBKGND;
|
|
|
|
procedure Paint(); override;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function GetDrawState(AItem: TX2CustomMenuBarItem): TX2MenuBarDrawStates;
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure DrawMenu(ACanvas: TCanvas); virtual;
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure DrawMenuItem(Sender: TObject; Item: TX2CustomMenuBarItem; const MenuBounds, ItemBounds: TRect; Data: Pointer; var Abort: Boolean); virtual;
|
|
|
|
procedure DrawMenuItems(ACanvas: TCanvas; AGroup: TX2MenuBarGroup; const ABounds: TRect); virtual;
|
2006-03-24 05:56:59 +00:00
|
|
|
procedure DrawNoPainter(ACanvas: TCanvas; const ABounds: TRect); virtual;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function IterateItemBounds(ACallback: TX2MenuBarItemBoundsProc; AData: Pointer = nil): TX2CustomMenuBarItem;
|
2006-03-24 05:56:59 +00:00
|
|
|
function AllowInteraction(): Boolean; virtual;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
procedure AutoCollapse(AGroup: TX2MenuBarGroup);
|
|
|
|
procedure AutoSelectItem(AGroup: TX2MenuBarGroup);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
property Animator: TX2CustomMenuBarAnimator read FAnimator write SetAnimator;
|
|
|
|
property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsNone;
|
|
|
|
property Options: TX2MenuBarOptions read FOptions write SetOptions;
|
|
|
|
property Scroller: TX2CustomMenuBarScroller read FScroller write SetScroller;
|
2006-03-24 05:56:59 +00:00
|
|
|
protected
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure DoExpand(AGroup: TX2MenuBarGroup; AExpanding: Boolean);
|
|
|
|
procedure DoExpandedChanging(AGroup: TX2MenuBarGroup; AExpanding: Boolean); virtual;
|
|
|
|
procedure DoExpandedChanged(AGroup: TX2MenuBarGroup); virtual;
|
2006-03-24 05:56:59 +00:00
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy(); override;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function HitTest(const APoint: TPoint): TX2MenuBarHitTest; overload;
|
2006-03-24 05:56:59 +00:00
|
|
|
function HitTest(AX, AY: Integer): TX2MenuBarHitTest; overload;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
property Groups: TX2MenuBarGroups read FGroups write SetGroups;
|
|
|
|
property ImageList: TCustomImageList read FImageList write SetImageList;
|
|
|
|
property Painter: TX2CustomMenuBarPainter read FPainter write SetPainter;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Exposes the menu bar's published properties.
|
|
|
|
}
|
|
|
|
TX2MenuBar = class(TX2CustomMenuBar)
|
|
|
|
published
|
|
|
|
property Align;
|
|
|
|
property BevelEdges;
|
|
|
|
property BevelInner;
|
|
|
|
property BevelKind;
|
|
|
|
property BevelOuter;
|
|
|
|
property BorderStyle;
|
|
|
|
property BorderWidth;
|
|
|
|
property Groups;
|
|
|
|
property ImageList;
|
|
|
|
property OnClick;
|
|
|
|
property OnDblClick;
|
|
|
|
property OnEnter;
|
|
|
|
property OnExit;
|
|
|
|
property OnMouseActivate;
|
|
|
|
property OnMouseDown;
|
|
|
|
property OnMouseEnter;
|
|
|
|
property OnMouseLeave;
|
|
|
|
property OnMouseMove;
|
|
|
|
property OnMouseUp;
|
|
|
|
property OnResize;
|
2006-03-30 04:54:11 +00:00
|
|
|
property Options;
|
2006-03-24 05:56:59 +00:00
|
|
|
property Painter;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Provides a wrapper for the DrawText API.
|
|
|
|
}
|
|
|
|
TDrawTextClipStyle = (csNone, csEllipsis, csPathEllipsis);
|
|
|
|
|
|
|
|
procedure DrawText(ACanvas: TCanvas; const AText: String;
|
|
|
|
const ABounds: TRect;
|
|
|
|
AHorzAlignment: TAlignment = taLeftJustify;
|
|
|
|
AVertAlignment: TVerticalAlignment = taVerticalCenter;
|
|
|
|
AMultiLine: Boolean = False;
|
|
|
|
AClipStyle: TDrawTextClipStyle = csNone);
|
|
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
{ HitTest Codes }
|
|
|
|
htUnknown = 0;
|
|
|
|
htBackground = 1;
|
|
|
|
htGroup = 2;
|
|
|
|
htItem = 3;
|
2006-04-01 19:51:46 +00:00
|
|
|
htScroller = 4;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
type
|
|
|
|
PRGBAArray = ^TRGBAArray;
|
|
|
|
TRGBAArray = array[Word] of TRGBQuad;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
implementation
|
|
|
|
uses
|
|
|
|
SysUtils;
|
|
|
|
|
|
|
|
const
|
|
|
|
DefaultAnimationStyle = asSlide;
|
|
|
|
DefaultAnimationTime = 250;
|
|
|
|
SDefaultItemCaption = 'Menu Item';
|
|
|
|
SDefaultGroupCaption = 'Group';
|
|
|
|
SNoPainter = 'Painter property not set';
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
{ DrawText wrapper }
|
|
|
|
procedure DrawText(ACanvas: TCanvas; const AText: String;
|
|
|
|
const ABounds: TRect; AHorzAlignment: TAlignment;
|
|
|
|
AVertAlignment: TVerticalAlignment;
|
|
|
|
AMultiLine: Boolean; AClipStyle: TDrawTextClipStyle);
|
|
|
|
const
|
|
|
|
HorzAlignmentFlags: array[TAlignment] of Cardinal =
|
|
|
|
(DT_LEFT, DT_RIGHT, DT_CENTER);
|
|
|
|
VertAlignmentFlags: array[TVerticalAlignment] of Cardinal =
|
|
|
|
(DT_TOP, DT_BOTTOM, DT_VCENTER);
|
|
|
|
MultiLineFlags: array[Boolean] of Cardinal =
|
|
|
|
(DT_SINGLELINE, 0);
|
|
|
|
ClipStyleFlags: array[TDrawTextClipStyle] of Cardinal =
|
|
|
|
(0, DT_END_ELLIPSIS, DT_PATH_ELLIPSIS);
|
|
|
|
|
|
|
|
var
|
|
|
|
flags: Cardinal;
|
|
|
|
bounds: TRect;
|
|
|
|
|
|
|
|
begin
|
|
|
|
flags := HorzAlignmentFlags[AHorzAlignment] or
|
|
|
|
VertAlignmentFlags[AVertAlignment] or
|
|
|
|
MultiLineFlags[AMultiLine] or
|
|
|
|
ClipStyleFlags[AClipStyle];
|
|
|
|
|
|
|
|
if AMultiLine and (AClipStyle <> csNone) then
|
|
|
|
flags := flags or DT_EDITCONTROL;
|
|
|
|
|
|
|
|
bounds := ABounds;
|
|
|
|
Windows.DrawText(ACanvas.Handle, PChar(AText), Length(AText), bounds, flags);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
{ TX2CustomMenuBarPainter }
|
|
|
|
constructor TX2CustomMenuBarPainter.Create(AOwner: TComponent);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
FAnimationStyle := DefaultAnimationStyle;
|
|
|
|
FAnimationTime := DefaultAnimationTime;
|
|
|
|
|
|
|
|
if AOwner is TX2CustomMenuBar then
|
|
|
|
FMenuBar := TX2CustomMenuBar(AOwner);
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
destructor TX2CustomMenuBarPainter.Destroy();
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FObservers);
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.AttachObserver(AObserver: IX2MenuBarPainterObserver);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
if not Assigned(FObservers) then
|
|
|
|
FObservers := TInterfaceList.Create();
|
|
|
|
|
|
|
|
if FObservers.IndexOf(AObserver) = -1 then
|
|
|
|
FObservers.Add(AObserver);
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.DetachObserver(AObserver: IX2MenuBarPainterObserver);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
if Assigned(FObservers) then
|
|
|
|
FObservers.Remove(AObserver);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.BeginPaint(const AMenuBar: TX2CustomMenuBar);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Assert(not Assigned(FMenuBar), 'BeginPaint already called');
|
|
|
|
FMenuBar := AMenuBar;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.EndPaint();
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Assert(Assigned(FMenuBar), 'EndPaint without BeginPaint');
|
|
|
|
FMenuBar := nil;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.NotifyObservers();
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
|
|
|
observerIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if Assigned(FObservers) then
|
|
|
|
for observerIndex := 0 to Pred(FObservers.Count) do
|
|
|
|
(FObservers[observerIndex] as IX2MenuBarPainterObserver).PainterUpdate(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBarPainter.ApplyMargins(const ABounds: TRect): TRect;
|
|
|
|
begin
|
|
|
|
Result := ABounds;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBarPainter.GetGroupHeight(AGroup: TX2MenuBarGroup): Integer;
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
|
|
|
itemIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
for itemIndex := 0 to Pred(AGroup.Items.Count) do
|
|
|
|
Inc(Result, GetItemHeight(AGroup.Items[itemIndex]));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
function TX2CustomMenuBarPainter.GetAnimatorClass(): TX2CustomMenuBarAnimatorClass;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Result := nil;
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
case AnimationStyle of
|
2006-03-30 04:54:11 +00:00
|
|
|
asSlide: Result := TX2MenuBarSlideAnimator;
|
2006-04-01 19:51:46 +00:00
|
|
|
asDissolve: Result := TX2MenuBarDissolveAnimator;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
function TX2CustomMenuBarPainter.GetScrollerClass: TX2CustomMenuBarScrollerClass;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarScrollbarScroller;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarPainter.FindHit(Sender: TObject; Item: TX2CustomMenuBarItem; const MenuBounds, ItemBounds: TRect; Data: Pointer; var Abort: Boolean);
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
2006-03-30 04:54:11 +00:00
|
|
|
hitPoint: PPoint;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
hitPoint := Data;
|
|
|
|
Abort := PtInRect(ItemBounds, hitPoint^);
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBarPainter.HitTest(const APoint: TPoint): TX2MenuBarHitTest;
|
|
|
|
var
|
|
|
|
hitPoint: TPoint;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
hitPoint := APoint;
|
|
|
|
Result.HitTestCode := htUnknown;
|
|
|
|
Result.Item := MenuBar.IterateItemBounds(FindHit, @hitPoint);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
if Assigned(Result.Item) then
|
|
|
|
if Result.Item is TX2MenuBarGroup then
|
|
|
|
Result.HitTestCode := htGroup
|
|
|
|
else if Result.Item is TX2MenuBarItem then
|
|
|
|
Result.HitTestCode := htItem;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBarPainter.HitTest(AX, AY: Integer): TX2MenuBarHitTest;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Result := HitTest(Point(AX, AY));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBarPainter.GetMenuBar(): TX2CustomMenuBar;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Assert(Assigned(FMenuBar), 'BeginPaint not called');
|
|
|
|
Result := FMenuBar;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBarPainter.GetSpacing(AElement: TX2MenuBarSpacingElement): Integer;
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
|
|
|
|
{ TX2CustomMenuBarAnimator }
|
|
|
|
constructor TX2CustomMenuBarAnimator.Create(AItemsBuffer: Graphics.TBitmap);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
inherited Create();
|
|
|
|
|
|
|
|
FStartTime := GetTickCount();
|
|
|
|
FItemsBuffer := Graphics.TBitmap.Create();
|
|
|
|
FItemsBuffer.Assign(AItemsBuffer);
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
destructor TX2CustomMenuBarAnimator.Destroy();
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FItemsBuffer);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
function TX2CustomMenuBarAnimator.GetHeight(): Integer;
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
Result := ItemsBuffer.Height;
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
function TX2CustomMenuBarAnimator.GetTimeElapsed(): Cardinal;
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
|
|
|
currentTime: Cardinal;
|
|
|
|
|
|
|
|
begin
|
|
|
|
currentTime := GetTickCount();
|
|
|
|
Result := currentTime - FStartTime;
|
|
|
|
|
|
|
|
if currentTime < FStartTime then
|
|
|
|
Inc(Result, High(Cardinal));
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure TX2CustomMenuBarAnimator.SetExpanding(const Value: Boolean);
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
FExpanding := Value;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure TX2CustomMenuBarAnimator.Terminate();
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
FTerminated := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure TX2CustomMenuBarAnimator.Update();
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{ TX2MenuBarSlideAnimator }
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2MenuBarSlideAnimator.GetHeight(): Integer;
|
|
|
|
begin
|
|
|
|
Result := FSlideHeight;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2MenuBarSlideAnimator.Update();
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
|
|
|
elapsed: Cardinal;
|
|
|
|
|
|
|
|
begin
|
|
|
|
elapsed := TimeElapsed;
|
|
|
|
FSlideHeight := Trunc((elapsed / AnimationTime) * ItemsBuffer.Height);
|
|
|
|
if not Expanding then
|
|
|
|
FSlideHeight := ItemsBuffer.Height - FSlideHeight;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
if FSlideHeight > ItemsBuffer.Height then
|
|
|
|
FSlideHeight := ItemsBuffer.Height
|
|
|
|
else if FSlideHeight < 0 then
|
|
|
|
FSlideHeight := 0;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
if elapsed >= AnimationTime then
|
|
|
|
Terminate();
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarSlideAnimator.Draw(ACanvas: TCanvas; const ABounds: TRect);
|
|
|
|
var
|
|
|
|
sourceRect: TRect;
|
|
|
|
destRect: TRect;
|
|
|
|
|
|
|
|
begin
|
2006-04-01 19:51:46 +00:00
|
|
|
sourceRect := Rect(0, 0, ItemsBuffer.Width, FSlideHeight);
|
|
|
|
destRect := ABounds;
|
|
|
|
destRect.Bottom := destRect.Top + FSlideHeight;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
ACanvas.CopyRect(destRect, ItemsBuffer.Canvas, sourceRect);
|
2006-03-30 04:54:11 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
{ TX2MenuBarDissolveAnimator }
|
|
|
|
constructor TX2MenuBarDissolveAnimator.Create(AItemsBuffer: Graphics.TBitmap);
|
2006-03-30 04:54:11 +00:00
|
|
|
var
|
|
|
|
pixelIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
{ The bitmaps need to be 32-bits since we'll be accessing the scanlines as
|
|
|
|
one big array, not by using Scanline on each row. In 24-bit mode, the
|
|
|
|
scanlines are still aligned on a 32-bits boundary, thus causing problems. }
|
|
|
|
ItemsBuffer.PixelFormat := pf32bit;
|
|
|
|
|
|
|
|
FMask := Graphics.TBitmap.Create();
|
|
|
|
FMask.PixelFormat := pf32bit;
|
|
|
|
FMask.Width := AItemsBuffer.Width;
|
|
|
|
FMask.Height := AItemsBuffer.Height;
|
|
|
|
|
|
|
|
FItemsState := Graphics.TBitmap.Create();
|
|
|
|
FItemsState.PixelFormat := pf32bit;
|
|
|
|
FItemsState.Width := AItemsBuffer.Width;
|
|
|
|
FItemsState.Height := AItemsBuffer.Height;
|
|
|
|
|
|
|
|
{ Prepare an array of pixel indices which will be used to pick random
|
|
|
|
unique pixels in the Update method. }
|
|
|
|
FPixels := TList.Create();
|
|
|
|
FPixels.Count := AItemsBuffer.Width * AItemsBuffer.Height;
|
|
|
|
|
|
|
|
for pixelIndex := 0 to Pred(FPixels.Count) do
|
|
|
|
FPixels[pixelIndex] := Pointer(pixelIndex);
|
|
|
|
|
|
|
|
if RandSeed = 0 then
|
|
|
|
Randomize();
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
destructor TX2MenuBarDissolveAnimator.Destroy();
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FItemsState);
|
|
|
|
FreeAndNil(FMask);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure TX2MenuBarDissolveAnimator.Update();
|
2006-03-30 04:54:11 +00:00
|
|
|
function GetScanlinePointer(ABitmap: Graphics.TBitmap): Pointer;
|
|
|
|
var
|
|
|
|
firstScanline: Pointer;
|
|
|
|
lastScanline: Pointer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
{ Most bitmaps are bottom-up, so Scanline[0] actually returns the
|
|
|
|
last physical row in memory. Check for this condition. Order of
|
|
|
|
scanlines is not important for this effect. }
|
|
|
|
firstScanline := ABitmap.ScanLine[0];
|
|
|
|
lastScanline := ABitmap.ScanLine[Pred(ABitmap.Height)];
|
|
|
|
|
|
|
|
if Cardinal(firstScanline) > Cardinal(lastScanline) then
|
|
|
|
Result := lastScanline
|
|
|
|
else
|
|
|
|
Result := firstScanline;
|
|
|
|
end;
|
|
|
|
|
|
|
|
const
|
|
|
|
RGBBlack: TRGBQuad = (rgbBlue: 0;
|
|
|
|
rgbGreen: 0;
|
|
|
|
rgbRed: 0;
|
|
|
|
rgbReserved: 0);
|
|
|
|
|
|
|
|
RGBWhite: TRGBQuad = (rgbBlue: 255;
|
|
|
|
rgbGreen: 255;
|
|
|
|
rgbRed: 255;
|
|
|
|
rgbReserved: 0);
|
|
|
|
|
|
|
|
var
|
|
|
|
totalPixelCount: Integer;
|
|
|
|
elapsed: Cardinal;
|
|
|
|
pixelsRemaining: Integer;
|
|
|
|
pixel: Integer;
|
|
|
|
pixelIndex: Integer;
|
|
|
|
pixelCount: Integer;
|
|
|
|
pixelPos: Integer;
|
|
|
|
statePixels: PRGBAArray;
|
|
|
|
maskPixels: PRGBAArray;
|
|
|
|
itemsPixels: PRGBAArray;
|
|
|
|
|
|
|
|
begin
|
2006-04-01 19:51:46 +00:00
|
|
|
// #ToDo1 (MvR) 1-4-2006: slow on big menu's, god knows why...
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
totalPixelCount := ItemsBuffer.Width * ItemsBuffer.Height;
|
|
|
|
elapsed := TimeElapsed;
|
|
|
|
pixelsRemaining := totalPixelCount - (Trunc((elapsed / AnimationTime) *
|
|
|
|
totalPixelCount));
|
|
|
|
|
|
|
|
if pixelsRemaining < 0 then
|
|
|
|
pixelsRemaining := 0;
|
|
|
|
|
|
|
|
statePixels := GetScanlinePointer(ItemsState);
|
|
|
|
maskPixels := GetScanlinePointer(Mask);
|
|
|
|
itemsPixels := nil;
|
|
|
|
|
|
|
|
if Expanding then
|
|
|
|
itemsPixels := GetScanlinePointer(ItemsBuffer);
|
|
|
|
|
|
|
|
for pixel := 0 to Pred(FPixels.Count - pixelsRemaining) do
|
|
|
|
begin
|
|
|
|
pixelCount := FPixels.Count;
|
|
|
|
pixelIndex := Random(pixelCount);
|
|
|
|
|
|
|
|
if pixelIndex > Pred(pixelCount) then
|
|
|
|
pixelIndex := Pred(pixelCount);
|
|
|
|
|
|
|
|
pixelPos := Integer(FPixels[pixelIndex]);
|
|
|
|
FPixels.Delete(pixelIndex);
|
|
|
|
|
|
|
|
if Expanding then
|
|
|
|
begin
|
|
|
|
{ Make the pixel visible }
|
|
|
|
statePixels^[pixelPos] := itemsPixels^[pixelPos];
|
|
|
|
maskPixels^[pixelPos] := RGBBlack;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
{ Make the pixel invisible }
|
|
|
|
statePixels^[pixelPos] := RGBBlack;
|
|
|
|
maskPixels^[pixelPos] := RGBWhite;
|
|
|
|
end;
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
if elapsed >= AnimationTime then
|
|
|
|
Terminate();
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure TX2MenuBarDissolveAnimator.Draw(ACanvas: TCanvas; const ABounds: TRect);
|
|
|
|
var
|
|
|
|
boundsRegion: THandle;
|
|
|
|
oldCopyMode: TCopyMode;
|
|
|
|
|
|
|
|
begin
|
|
|
|
boundsRegion := CreateRectRgn(ABounds.Left, ABounds.Top, ABounds.Right,
|
|
|
|
ABounds.Bottom);
|
|
|
|
oldCopyMode := ACanvas.CopyMode;
|
|
|
|
try
|
|
|
|
SelectClipRgn(ACanvas.Handle, boundsRegion);
|
|
|
|
ACanvas.CopyMode := cmSrcAnd;
|
|
|
|
ACanvas.Draw(ABounds.Left, ABounds.Top, Mask);
|
|
|
|
|
|
|
|
ACanvas.CopyMode := cmSrcPaint;
|
|
|
|
ACanvas.Draw(ABounds.Left, ABounds.Top, ItemsState);
|
|
|
|
finally
|
|
|
|
SelectClipRgn(ACanvas.Handle, 0);
|
|
|
|
ACanvas.CopyMode := oldCopyMode;
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure TX2MenuBarDissolveAnimator.SetExpanding(const Value: Boolean);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
if Value then
|
|
|
|
begin
|
|
|
|
{ Start with an invisible group }
|
|
|
|
FMask.Canvas.Brush.Color := clWhite;
|
|
|
|
|
|
|
|
with FItemsState.Canvas do
|
|
|
|
begin
|
|
|
|
Brush.Color := clBlack;
|
|
|
|
FillRect(Rect(0, 0, FItemsState.Width, FItemsState.Height));
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
{ Start with a visible group }
|
|
|
|
FMask.Canvas.Brush.Color := clBlack;
|
|
|
|
FItemsState.Canvas.Draw(0, 0, ItemsBuffer);
|
|
|
|
end;
|
|
|
|
|
|
|
|
FMask.Canvas.FillRect(Rect(0, 0, FMask.Width, FMask.Height));
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
{ TX2CustomMenuBarScroller }
|
|
|
|
constructor TX2CustomMenuBarScroller.Create(AMenuBar: TX2CustomMenuBar);
|
|
|
|
begin
|
|
|
|
inherited Create();
|
|
|
|
|
|
|
|
FMenuBar := AMenuBar;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBarScroller.ApplyMargins(const ABounds: TRect): TRect;
|
|
|
|
begin
|
|
|
|
Result := ABounds;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBarScroller.HitTest(const APoint: TPoint): TX2MenuBarHitTest;
|
|
|
|
begin
|
|
|
|
Result.HitTestCode := htUnknown;
|
|
|
|
Result.Item := nil;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBarScroller.HitTest(AX, AY: Integer): TX2MenuBarHitTest;
|
|
|
|
begin
|
|
|
|
Result := HitTest(Point(AX, AY));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2MenuBarScrollbarScroller }
|
|
|
|
constructor TX2MenuBarScrollbarScroller.Create(AMenuBar: TX2CustomMenuBar);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
FScrollbarWidth := GetSystemMetrics(SM_CXVSCROLL);
|
|
|
|
FArrowHeight := GetSystemMetrics(SM_CYVSCROLL);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2MenuBarScrollbarScroller.ApplyMargins(const ABounds: TRect): TRect;
|
|
|
|
begin
|
|
|
|
Result := inherited ApplyMargins(ABounds);
|
|
|
|
Dec(Result.Right, FScrollbarWidth + 5);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2MenuBarScrollbarScroller.DrawArrowButton(ACanvas: TCanvas;
|
|
|
|
const ABounds: TRect;
|
|
|
|
ADirection: TScrollbarArrowDirection);
|
|
|
|
var
|
|
|
|
flags: Cardinal;
|
|
|
|
|
|
|
|
begin
|
|
|
|
flags := 0{DFCS_INACTIVE};
|
|
|
|
case ADirection of
|
|
|
|
adUp: flags := flags or DFCS_SCROLLUP;
|
|
|
|
adDown: flags := flags or DFCS_SCROLLDOWN;
|
|
|
|
end;
|
|
|
|
|
|
|
|
// #ToDo1 (MvR) 1-4-2006: XP theme support
|
|
|
|
DrawFrameControl(ACanvas.Handle, ABounds, DFC_SCROLL, flags);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarScrollbarScroller.DrawBackground(ACanvas: TCanvas;
|
|
|
|
const ABounds: TRect);
|
|
|
|
function GetForegroundColor(): Cardinal;
|
|
|
|
var
|
|
|
|
color1: Cardinal;
|
|
|
|
color2: Cardinal;
|
|
|
|
|
|
|
|
begin
|
|
|
|
color1 := GetSysColor(COLOR_3DHILIGHT);
|
|
|
|
color2 := GetSysColor(COLOR_WINDOW);
|
|
|
|
|
|
|
|
if (color1 <> $ffffff) and (color1 = color2) then
|
|
|
|
Result := GetSysColor(COLOR_BTNFACE)
|
|
|
|
else
|
|
|
|
Result := GetSysColor(COLOR_3DHILIGHT);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetBackgroundColor(): Cardinal;
|
|
|
|
begin
|
|
|
|
Result := GetSysColor(COLOR_SCROLLBAR);
|
|
|
|
end;
|
|
|
|
|
|
|
|
const
|
|
|
|
CheckPattern: array[0..7] of Word =
|
|
|
|
($aaaa, $5555, $aaaa, $5555, $aaaa, $5555, $aaaa, $5555);
|
|
|
|
|
|
|
|
var
|
|
|
|
patternBitmap: Graphics.TBitmap;
|
|
|
|
|
|
|
|
begin
|
|
|
|
patternBitmap := Graphics.TBitmap.Create();
|
|
|
|
try
|
|
|
|
patternBitmap.Handle := CreateBitmap(8, 8, 1, 1, @CheckPattern);
|
|
|
|
ACanvas.Brush.Bitmap := patternBitmap;
|
|
|
|
|
|
|
|
SetTextColor(ACanvas.Handle, GetForegroundColor());
|
|
|
|
SetBkColor(ACanvas.Handle, GetBackgroundColor());
|
|
|
|
ACanvas.FillRect(ABounds);
|
|
|
|
finally
|
|
|
|
ACanvas.Brush.Bitmap := nil;
|
|
|
|
FreeAndNil(patternBitmap);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarScrollbarScroller.DrawThumb(ACanvas: TCanvas;
|
|
|
|
const ABounds: TRect);
|
|
|
|
var
|
|
|
|
bounds: TRect;
|
|
|
|
|
|
|
|
begin
|
|
|
|
ACanvas.Brush.Color := clBtnFace;
|
|
|
|
ACanvas.FillRect(ABounds);
|
|
|
|
|
|
|
|
bounds := ABounds;
|
|
|
|
DrawEdge(ACanvas.Handle, bounds, EDGE_RAISED, BF_RECT);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2MenuBarScrollbarScroller.HitTest(const APoint: TPoint): TX2MenuBarHitTest;
|
|
|
|
var
|
|
|
|
bounds: TRect;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result.HitTestCode := htUnknown;
|
|
|
|
Result.Item := nil;
|
|
|
|
|
|
|
|
bounds := MenuBar.ClientRect;
|
|
|
|
bounds.Left := bounds.Right - ScrollbarWidth;
|
|
|
|
|
|
|
|
if PtInRect(APoint) then
|
|
|
|
begin
|
|
|
|
Result.HitTestCode := htScroller;
|
|
|
|
Result.Item := Self;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarScrollbarScroller.Draw(ACanvas: TCanvas;
|
|
|
|
const ABounds: TRect);
|
|
|
|
const
|
|
|
|
MinThumbHeight = 8;
|
|
|
|
|
|
|
|
var
|
|
|
|
bounds: TRect;
|
|
|
|
trackBounds: TRect;
|
|
|
|
scrollHeight: Integer;
|
|
|
|
visiblePart: Double;
|
|
|
|
thumbHeight: Integer;
|
|
|
|
scrollArea: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
bounds := ABounds;
|
|
|
|
bounds.Left := bounds.Right - ScrollbarWidth;
|
|
|
|
|
|
|
|
if (bounds.Bottom - bounds.Top) <= (2 * ArrowHeight) then
|
|
|
|
begin
|
|
|
|
{ Top thumb }
|
|
|
|
bounds.Bottom := bounds.Top + ((bounds.Bottom - bounds.Top) div 2);
|
|
|
|
DrawArrowButton(ACanvas, bounds, adUp);
|
|
|
|
|
|
|
|
{ Bottom thumb }
|
|
|
|
bounds.Top := bounds.Bottom;
|
|
|
|
bounds.Bottom := ABounds.Bottom;
|
|
|
|
DrawArrowButton(ACanvas, bounds, adDown);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
{ Top thumb }
|
|
|
|
bounds.Bottom := bounds.Top + ArrowHeight;
|
|
|
|
DrawArrowButton(ACanvas, bounds, adUp);
|
|
|
|
|
|
|
|
{ Bottom thumb }
|
|
|
|
bounds.Bottom := ABounds.Bottom;
|
|
|
|
bounds.Top := bounds.Bottom - ArrowHeight;
|
|
|
|
DrawArrowButton(ACanvas, bounds, adDown);
|
|
|
|
|
|
|
|
{ Track bar }
|
|
|
|
bounds.Bottom := bounds.Top;
|
|
|
|
bounds.Top := ABounds.Top + ArrowHeight;
|
|
|
|
DrawBackground(ACanvas, bounds);
|
|
|
|
trackBounds := bounds;
|
|
|
|
|
|
|
|
{ Thumb }
|
|
|
|
scrollHeight := MenuHeight - ClientHeight;
|
|
|
|
if scrollHeight > 0 then
|
|
|
|
begin
|
|
|
|
visiblePart := ClientHeight / MenuHeight;
|
|
|
|
thumbHeight := Trunc((bounds.Bottom - bounds.Top) * visiblePart);
|
|
|
|
scrollArea := (trackBounds.Bottom - trackBounds.Top) - thumbHeight;
|
|
|
|
|
|
|
|
Inc(bounds.Top, Trunc((Offset / scrollHeight) * scrollArea));
|
|
|
|
bounds.Bottom := bounds.Top + thumbHeight;
|
|
|
|
|
|
|
|
if bounds.Bottom - bounds.Top < MinThumbHeight then
|
|
|
|
bounds.Bottom := bounds.Top + MinThumbHeight;
|
|
|
|
|
|
|
|
if bounds.Bottom > trackBounds.Bottom then
|
|
|
|
bounds.Bottom := trackBounds.Bottom;
|
|
|
|
|
|
|
|
DrawThumb(ACanvas, bounds);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
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-03-30 04:54:11 +00:00
|
|
|
inherited;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
FCaption := SDefaultItemCaption;
|
|
|
|
FImageIndex := -1;
|
|
|
|
FOwnsData := True;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TX2CustomMenuBarItem.Destroy();
|
|
|
|
begin
|
|
|
|
Data := nil;
|
|
|
|
|
|
|
|
inherited;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBarItem.GetMenuBar(): TX2CustomMenuBar;
|
|
|
|
var
|
|
|
|
parentCollection: TCollection;
|
|
|
|
parentOwner: TPersistent;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
Result := nil;
|
|
|
|
parentCollection := Collection;
|
|
|
|
|
|
|
|
{ Traverse up the tree of CollectionItems and OwnedCollections until
|
|
|
|
we find a MenuBar... or not. }
|
|
|
|
while Assigned(parentCollection) do
|
|
|
|
begin
|
|
|
|
parentOwner := parentCollection.Owner;
|
|
|
|
if Assigned(parentOwner) then
|
|
|
|
begin
|
|
|
|
if parentOwner is TX2CustomMenuBar then
|
|
|
|
begin
|
|
|
|
Result := TX2CustomMenuBar(parentCollection.Owner);
|
|
|
|
break;
|
|
|
|
end else if parentOwner is TCollectionItem then
|
|
|
|
parentCollection := TCollectionItem(parentOwner).Collection;
|
|
|
|
end else
|
|
|
|
break;
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarItem.Assign(Source: TPersistent);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
if Source is TX2CustomMenuBarItem then
|
|
|
|
with TX2CustomMenuBarItem(Source) do
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Self.Caption := Caption;
|
|
|
|
Self.Data := Data;
|
|
|
|
Self.OwnsData := OwnsData;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarItem.SetCaption(const Value: String);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
if Value <> FCaption then
|
|
|
|
begin
|
|
|
|
FCaption := Value;
|
|
|
|
Changed(False);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarItem.SetData(const Value: TObject);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
if Value <> FData then
|
|
|
|
begin
|
|
|
|
if FOwnsData then
|
|
|
|
FreeAndNil(FData);
|
|
|
|
|
|
|
|
FData := Value;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBarItem.SetImageIndex(const Value: TImageIndex);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
if Value <> FImageIndex then
|
|
|
|
begin
|
|
|
|
FImageIndex := Value;
|
|
|
|
Changed(False);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
{ TX2MenuBarItem }
|
|
|
|
function TX2MenuBarItem.GetGroup(): TX2MenuBarGroup;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
|
|
|
|
if Assigned(Collection) and (Collection.Owner <> nil) and
|
|
|
|
(Collection.Owner is TX2MenuBarGroup) then
|
|
|
|
Result := TX2MenuBarGroup(Collection.Owner);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{ TX2MenuBarItems }
|
|
|
|
constructor TX2MenuBarItems.Create(AOwner: TPersistent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner, TX2MenuBarItem);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2MenuBarItems.Add(const ACaption: TCaption): TX2MenuBarItem;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarItem(inherited Add());
|
|
|
|
Result.Caption := ACaption;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2MenuBarItems.GetItem(Index: Integer): TX2MenuBarItem;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarItem(inherited GetItem(Index));
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarItems.SetItem(Index: Integer; const Value: TX2MenuBarItem);
|
|
|
|
begin
|
|
|
|
inherited SetItem(Index, Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2MenuBarGroup }
|
|
|
|
constructor TX2MenuBarGroup.Create(Collection: TCollection);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
FCaption := SDefaultGroupCaption;
|
|
|
|
FItems := TX2MenuBarItems.Create(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TX2MenuBarGroup.Destroy();
|
|
|
|
begin
|
|
|
|
FreeAndNil(FItems);
|
|
|
|
|
|
|
|
if OwnsData then
|
|
|
|
FreeAndNil(FData);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2MenuBarGroup.Assign(Source: TPersistent);
|
|
|
|
begin
|
|
|
|
if Source is TX2MenuBarGroup then
|
|
|
|
with TX2MenuBarGroup(Source) do
|
|
|
|
Self.Items.Assign(Items);
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
inherited;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
function TX2MenuBarGroup.GetSelectedItem(): Integer;
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
Result := -1;
|
|
|
|
|
|
|
|
if Items.Count > 0 then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
if (FSelectedItem >= 0) and (FSelectedItem < Items.Count) then
|
|
|
|
Result := FSelectedItem
|
|
|
|
else
|
|
|
|
Result := 0;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2MenuBarGroup.InternalSetExpanded(const Value: Boolean);
|
|
|
|
var
|
|
|
|
menu: TX2CustomMenuBar;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
FExpanded := Value;
|
|
|
|
Changed(False);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
menu := MenuBar;
|
|
|
|
if Assigned(menu) then
|
|
|
|
menu.DoExpandedChanged(Self);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarGroup.SetExpanded(const Value: Boolean);
|
|
|
|
var
|
|
|
|
menu: TX2CustomMenuBar;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if Value <> FExpanded then
|
|
|
|
begin
|
|
|
|
menu := MenuBar;
|
|
|
|
if Assigned(menu) then
|
2006-03-30 04:54:11 +00:00
|
|
|
menu.DoExpandedChanging(Self, Value)
|
|
|
|
else
|
|
|
|
InternalSetExpanded(Value);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarGroup.SetItems(const Value: TX2MenuBarItems);
|
|
|
|
begin
|
|
|
|
if Value <> FItems then
|
|
|
|
begin
|
|
|
|
FItems.Assign(Value);
|
|
|
|
Changed(False);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TX2MenuBarGroups }
|
|
|
|
constructor TX2MenuBarGroups.Create(AOwner: TPersistent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner, TX2MenuBarGroup);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2MenuBarGroups.Add(const ACaption: TCaption): TX2MenuBarGroup;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarGroup(inherited Add());
|
|
|
|
if Length(ACaption) > 0 then
|
|
|
|
Result.Caption := ACaption;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2MenuBarGroups.GetItem(Index: Integer): TX2MenuBarGroup;
|
|
|
|
begin
|
|
|
|
Result := TX2MenuBarGroup(inherited GetItem(Index));
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2MenuBarGroups.SetItem(Index: Integer; const Value: TX2MenuBarGroup);
|
|
|
|
begin
|
|
|
|
inherited SetItem(Index, Value);
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
{ TX2CustomMenuBar }
|
|
|
|
constructor TX2CustomMenuBar.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
FBorderStyle := bsNone;
|
|
|
|
FGroups := TX2MenuBarGroups.Create(Self);
|
|
|
|
FOptions := [mboAllowCollapseAll];
|
|
|
|
FExpandingGroups := TStringList.Create();
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.CreateParams(var Params: TCreateParams);
|
|
|
|
const
|
|
|
|
BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
|
|
|
|
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
{ Source: TScrollBox.CreateParams
|
|
|
|
Applies the BorderStyle property. }
|
2006-03-24 05:56:59 +00:00
|
|
|
with Params do
|
|
|
|
begin
|
|
|
|
Style := Style or BorderStyles[FBorderStyle];
|
|
|
|
|
|
|
|
if NewStyleControls and Ctl3D and (FBorderStyle = bsSingle) then
|
|
|
|
begin
|
|
|
|
Style := Style and not WS_BORDER;
|
|
|
|
ExStyle := ExStyle or WS_EX_CLIENTEDGE;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TX2CustomMenuBar.Destroy();
|
|
|
|
begin
|
2006-04-01 19:51:46 +00:00
|
|
|
Animator := nil;
|
|
|
|
Scroller := nil;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
FreeAndNil(FExpandingGroups);
|
2006-03-24 05:56:59 +00:00
|
|
|
FreeAndNil(FGroups);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.WMEraseBkgnd(var Msg: TWMEraseBkgnd);
|
|
|
|
begin
|
|
|
|
Msg.Result := 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.Paint();
|
|
|
|
var
|
|
|
|
buffer: Graphics.TBitmap;
|
2006-03-30 04:54:11 +00:00
|
|
|
bufferRect: TRect;
|
|
|
|
expand: Boolean;
|
|
|
|
group: TX2MenuBarGroup;
|
2006-04-01 19:51:46 +00:00
|
|
|
scrollerClass: TX2CustomMenuBarScrollerClass;
|
|
|
|
menuHeight: Integer;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Assigned(Painter) then
|
|
|
|
begin
|
|
|
|
buffer := Graphics.TBitmap.Create();
|
|
|
|
try
|
2006-04-01 19:51:46 +00:00
|
|
|
buffer.PixelFormat := pf32bit;
|
2006-03-24 05:56:59 +00:00
|
|
|
buffer.Width := Self.ClientWidth;
|
|
|
|
buffer.Height := Self.ClientHeight;
|
2006-03-30 04:54:11 +00:00
|
|
|
bufferRect := Rect(0, 0, buffer.Width, buffer.Height);
|
|
|
|
buffer.Canvas.Font.Assign(Self.Font);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
if Assigned(Animator) then
|
|
|
|
Animator.Update();
|
|
|
|
|
|
|
|
menuHeight := GetMenuHeight();
|
|
|
|
|
|
|
|
{ Don't change the scroller's visibility while animating }
|
|
|
|
if not Assigned(Animator) then
|
|
|
|
begin
|
|
|
|
if menuHeight > bufferRect.Bottom then
|
|
|
|
begin
|
|
|
|
if not Assigned(Scroller) then
|
|
|
|
begin
|
|
|
|
scrollerClass := Painter.GetScrollerClass();
|
|
|
|
if Assigned(scrollerClass) then
|
|
|
|
Scroller := scrollerClass.Create(Self);
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
if Assigned(Scroller) then
|
|
|
|
Scroller := nil;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
Painter.BeginPaint(Self);
|
|
|
|
try
|
2006-03-30 04:54:11 +00:00
|
|
|
Painter.DrawBackground(buffer.Canvas, bufferRect);
|
2006-04-01 19:51:46 +00:00
|
|
|
DrawMenu(buffer.Canvas);
|
2006-03-30 04:54:11 +00:00
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
if Assigned(Scroller) then
|
|
|
|
begin
|
|
|
|
Scroller.ClientHeight := Self.ClientHeight;
|
|
|
|
Scroller.MenuHeight := menuHeight;
|
|
|
|
Scroller.Draw(buffer.Canvas, bufferRect);
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
finally
|
|
|
|
Painter.EndPaint();
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
Self.Canvas.Draw(0, 0, buffer);
|
|
|
|
FreeAndNil(buffer);
|
|
|
|
end;
|
|
|
|
|
|
|
|
if Assigned(Animator) then
|
|
|
|
begin
|
|
|
|
if Animator.Terminated then
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
Animator.Group.InternalSetExpanded(Animator.Expanding);
|
2006-04-01 19:51:46 +00:00
|
|
|
Animator := nil;
|
2006-03-30 04:54:11 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
{ Prevent 100% CPU usage }
|
|
|
|
Sleep(5);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
TestMousePos();
|
|
|
|
Invalidate();
|
2006-03-30 04:54:11 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
{ Process animation queue }
|
|
|
|
if FExpandingGroups.Count > 0 then
|
|
|
|
begin
|
|
|
|
expand := (FExpandingGroups[0] = #1);
|
|
|
|
group := TX2MenuBarGroup(FExpandingGroups.Objects[0]);
|
|
|
|
FExpandingGroups.Delete(0);
|
|
|
|
|
|
|
|
group.Expanded := expand;
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
DrawNoPainter(Self.Canvas, Self.ClientRect);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBar.GetDrawState(AItem: TX2CustomMenuBarItem): TX2MenuBarDrawStates;
|
|
|
|
function ItemGroup(AGroupItem: TX2CustomMenuBarItem): TX2MenuBarGroup;
|
|
|
|
begin
|
|
|
|
Result := nil;
|
|
|
|
if AGroupItem is TX2MenuBarItem then
|
|
|
|
Result := TX2MenuBarItem(AGroupItem).Group;
|
|
|
|
end;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Result := [];
|
|
|
|
|
|
|
|
if AItem = FHotItem then
|
|
|
|
Include(Result, mdsHot);
|
|
|
|
|
|
|
|
if AItem = FSelectedItem then
|
|
|
|
Include(Result, mdsSelected);
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
if Assigned(FHotItem) and (AItem = ItemGroup(FHotItem)) then
|
|
|
|
Include(Result, mdsGroupHot);
|
|
|
|
|
|
|
|
if Assigned(FSelectedItem) and (AItem = ItemGroup(FSelectedItem)) then
|
|
|
|
Include(Result, mdsGroupSelected);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.DrawMenuItem(Sender: TObject;
|
|
|
|
Item: TX2CustomMenuBarItem;
|
|
|
|
const MenuBounds, ItemBounds: TRect;
|
|
|
|
Data: Pointer; var Abort: Boolean);
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
2006-03-30 04:54:11 +00:00
|
|
|
canvas: TCanvas;
|
|
|
|
drawState: TX2MenuBarDrawStates;
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
groupBounds: TRect;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
if ItemBounds.Top > MenuBounds.Bottom then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
Abort := True;
|
|
|
|
exit;
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
canvas := TCanvas(Data);
|
|
|
|
drawState := GetDrawState(Item);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
if Item is TX2MenuBarGroup then
|
|
|
|
begin
|
|
|
|
group := TX2MenuBarGroup(Item);
|
|
|
|
Painter.DrawGroupHeader(canvas, group, ItemBounds,
|
|
|
|
drawState);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
if Assigned(Animator) and (Animator.Group = group) then
|
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
groupBounds := MenuBounds;
|
|
|
|
groupBounds.Top := ItemBounds.Bottom +
|
|
|
|
Painter.GetSpacing(seAfterGroupHeader) +
|
|
|
|
Painter.GetSpacing(seBeforeFirstItem);
|
|
|
|
groupBounds.Bottom := groupBounds.Top + Animator.Height;
|
|
|
|
Animator.Draw(canvas, groupBounds);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
end else if Item is TX2MenuBarItem then
|
|
|
|
Painter.DrawItem(canvas, TX2MenuBarItem(Item), ItemBounds, drawState);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.DrawMenuItems(ACanvas: TCanvas; AGroup: TX2MenuBarGroup; const ABounds: TRect);
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
2006-03-30 04:54:11 +00:00
|
|
|
itemBounds: TRect;
|
2006-03-24 05:56:59 +00:00
|
|
|
itemIndex: Integer;
|
|
|
|
item: TX2MenuBarItem;
|
|
|
|
drawState: TX2MenuBarDrawStates;
|
|
|
|
|
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
Assert(Assigned(Painter), 'No Painter assigned');
|
2006-03-24 05:56:59 +00:00
|
|
|
itemBounds := ABounds;
|
2006-03-30 04:54:11 +00:00
|
|
|
Inc(itemBounds.Top, Painter.GetSpacing(seBeforeFirstItem));
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
for itemIndex := 0 to Pred(AGroup.Items.Count) do
|
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
Inc(itemBounds.Top, Painter.GetSpacing(seBeforeItem));
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
item := AGroup.Items[itemIndex];
|
|
|
|
itemBounds.Bottom := itemBounds.Top + Painter.GetItemHeight(item);
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
drawState := GetDrawState(item);
|
|
|
|
Painter.DrawItem(ACanvas, item, itemBounds, drawState);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
itemBounds.Top := itemBounds.Bottom + Painter.GetSpacing(seAfterItem);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure TX2CustomMenuBar.DrawMenu(ACanvas: TCanvas);
|
2006-03-30 04:54:11 +00:00
|
|
|
begin
|
|
|
|
IterateItemBounds(DrawMenuItem, Pointer(ACanvas));
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.DrawNoPainter(ACanvas: TCanvas; const ABounds: TRect);
|
|
|
|
const
|
|
|
|
XorColor = $00FFD8CE; // RGB(206, 216, 255)
|
|
|
|
|
|
|
|
begin
|
|
|
|
with ACanvas do
|
|
|
|
begin
|
|
|
|
Brush.Color := clBtnFace;
|
|
|
|
FillRect(ABounds);
|
|
|
|
|
|
|
|
Pen.Style := psDot;
|
|
|
|
Pen.Mode := pmXor;
|
|
|
|
Pen.Color := XorColor;
|
|
|
|
Brush.Style := bsClear;
|
|
|
|
Rectangle(ABounds);
|
|
|
|
|
|
|
|
DrawText(ACanvas, SNoPainter, ABounds, taCenter);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBar.IterateItemBounds(ACallback: TX2MenuBarItemBoundsProc;
|
|
|
|
AData: Pointer): TX2CustomMenuBarItem;
|
|
|
|
var
|
|
|
|
groupIndex: Integer;
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
menuBounds: TRect;
|
|
|
|
itemBounds: TRect;
|
|
|
|
itemIndex: Integer;
|
|
|
|
item: TX2MenuBarItem;
|
|
|
|
abort: Boolean;
|
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
Assert(Assigned(Painter), 'No Painter assigned');
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
Result := nil;
|
|
|
|
menuBounds := Painter.ApplyMargins(Self.ClientRect);
|
2006-04-01 19:51:46 +00:00
|
|
|
if Assigned(Scroller) then
|
|
|
|
menuBounds := Scroller.ApplyMargins(menuBounds);
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
itemBounds := menuBounds;
|
|
|
|
abort := False;
|
|
|
|
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
begin
|
|
|
|
{ Group }
|
|
|
|
group := Groups[groupIndex];
|
|
|
|
Inc(itemBounds.Top, Painter.GetSpacing(seBeforeGroupHeader));
|
|
|
|
itemBounds.Bottom := itemBounds.Top +
|
|
|
|
Painter.GetGroupHeaderHeight(group);
|
|
|
|
|
|
|
|
ACallback(Self, group, menuBounds, itemBounds, AData, abort);
|
|
|
|
if abort then
|
|
|
|
begin
|
|
|
|
Result := group;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
|
|
|
|
itemBounds.Top := itemBounds.Bottom +
|
|
|
|
Painter.GetSpacing(seAfterGroupHeader);
|
|
|
|
|
|
|
|
if Assigned(Animator) and (Animator.Group = group) then
|
|
|
|
begin
|
|
|
|
{ Animated group }
|
|
|
|
Inc(itemBounds.Top, Animator.Height);
|
|
|
|
end else if group.Expanded then
|
|
|
|
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];
|
|
|
|
Inc(itemBounds.Top, Painter.GetSpacing(seBeforeItem));
|
|
|
|
itemBounds.Bottom := itemBounds.Top + Painter.GetItemHeight(item);
|
2006-03-24 05:56:59 +00:00
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
ACallback(Self, item, menuBounds, itemBounds, AData, abort);
|
|
|
|
if abort then
|
|
|
|
begin
|
|
|
|
Result := item;
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
|
|
|
|
itemBounds.Top := itemBounds.Bottom +
|
|
|
|
Painter.GetSpacing(seAfterItem);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Inc(itemBounds.Top, Painter.GetSpacing(seAfterLastItem));
|
|
|
|
end;
|
|
|
|
|
|
|
|
if abort then
|
|
|
|
break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.DoExpandedChanging(AGroup: TX2MenuBarGroup;
|
|
|
|
AExpanding: Boolean);
|
|
|
|
function ExpandedGroupsCount(): Integer;
|
|
|
|
var
|
|
|
|
groupIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
if Groups[groupIndex].Expanded then
|
|
|
|
Inc(Result);
|
|
|
|
end;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if csLoading in ComponentState then
|
|
|
|
begin
|
|
|
|
AGroup.InternalSetExpanded(AExpanding);
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Auto select item }
|
|
|
|
if mboAutoSelectItem in Options then
|
|
|
|
AutoSelectItem(AGroup);
|
|
|
|
|
|
|
|
{ Allow collapse all }
|
|
|
|
if not (AExpanding or (mboAllowCollapseAll in Options)) then
|
|
|
|
if ExpandedGroupsCount() = 1 then
|
|
|
|
exit;
|
|
|
|
|
|
|
|
{ Auto collapse }
|
|
|
|
if mboAutoCollapse in Options then
|
|
|
|
if AExpanding then
|
|
|
|
AutoCollapse(AGroup);
|
|
|
|
|
|
|
|
DoExpand(AGroup, AExpanding);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.DoExpandedChanged(AGroup: TX2MenuBarGroup);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
// #ToDo1 (MvR) 27-3-2006: raise event
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.AllowInteraction(): Boolean;
|
|
|
|
begin
|
|
|
|
Result := not Assigned(Animator);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.DoExpand(AGroup: TX2MenuBarGroup; AExpanding: Boolean);
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
2006-04-01 19:51:46 +00:00
|
|
|
animatorClass: TX2CustomMenuBarAnimatorClass;
|
2006-03-24 05:56:59 +00:00
|
|
|
itemsBuffer: Graphics.TBitmap;
|
|
|
|
itemsBounds: TRect;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if not Assigned(Painter) then
|
|
|
|
exit;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
if Assigned(Animator) then
|
|
|
|
begin
|
|
|
|
FExpandingGroups.AddObject(Chr(Ord(AExpanding)), AGroup);
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
animatorClass := Painter.GetAnimatorClass();
|
|
|
|
if Assigned(animatorClass) then
|
|
|
|
begin
|
|
|
|
Painter.BeginPaint(Self);
|
|
|
|
try
|
|
|
|
itemsBuffer := Graphics.TBitmap.Create();
|
|
|
|
try
|
|
|
|
itemsBounds := Painter.ApplyMargins(Self.ClientRect);
|
2006-04-01 19:51:46 +00:00
|
|
|
if Assigned(Scroller) then
|
|
|
|
itemsBounds := Scroller.ApplyMargins(itemsBounds);
|
|
|
|
|
|
|
|
itemsBuffer.PixelFormat := pf32bit;
|
2006-03-30 04:54:11 +00:00
|
|
|
itemsBuffer.Width := itemsBounds.Right - itemsBounds.Left;
|
|
|
|
itemsBuffer.Height := Painter.GetGroupHeight(AGroup);
|
|
|
|
itemsBounds := Rect(0, 0, itemsBuffer.Width, itemsBuffer.Height);
|
2006-04-01 19:51:46 +00:00
|
|
|
itemsBuffer.Canvas.Font.Assign(Self.Font);
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
// #ToDo3 (MvR) 23-3-2006: this will probably cause problems if we ever
|
|
|
|
// want a bitmapped/customdrawn background.
|
|
|
|
// Maybe we can trick around a bit with the
|
|
|
|
// canvas offset? think about it later.
|
|
|
|
Painter.DrawBackground(itemsBuffer.Canvas, itemsBounds);
|
|
|
|
DrawMenuItems(itemsBuffer.Canvas, AGroup, itemsBounds);
|
|
|
|
|
|
|
|
Animator := animatorClass.Create(itemsBuffer);
|
|
|
|
Animator.AnimationTime := Painter.AnimationTime;
|
|
|
|
Animator.Expanding := AExpanding;
|
|
|
|
Animator.Group := AGroup;
|
|
|
|
finally
|
|
|
|
FreeAndNil(itemsBuffer);
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
Painter.EndPaint();
|
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
AGroup.InternalSetExpanded(AExpanding);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.AutoCollapse(AGroup: TX2MenuBarGroup);
|
|
|
|
var
|
|
|
|
expandedGroup: TX2MenuBarGroup;
|
|
|
|
groupIndex: Integer;
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
|
|
|
|
begin
|
|
|
|
expandedGroup := AGroup;
|
|
|
|
if not Assigned(expandedGroup) then
|
|
|
|
begin
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
if Groups[groupIndex].Expanded then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
expandedGroup := Groups[groupIndex];
|
|
|
|
break;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
2006-03-30 04:54:11 +00:00
|
|
|
|
|
|
|
if not Assigned(expandedGroup) then
|
|
|
|
if Groups.Count > 0 then
|
|
|
|
begin
|
|
|
|
expandedGroup := Groups[0];
|
|
|
|
expandedGroup.Expanded := True;
|
|
|
|
end else
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
for groupIndex := 0 to Pred(Groups.Count) do
|
|
|
|
begin
|
|
|
|
group := Groups[groupIndex];
|
|
|
|
|
|
|
|
if (group <> expandedGroup) and (group.Expanded) then
|
|
|
|
DoExpand(group, False);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.AutoSelectItem(AGroup: TX2MenuBarGroup);
|
|
|
|
var
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
groupIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
group := AGroup;
|
|
|
|
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
|
|
|
|
FSelectedItem := group.Items[group.SelectedItem];
|
|
|
|
Invalidate();
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
function TX2CustomMenuBar.HitTest(const APoint: TPoint): TX2MenuBarHitTest;
|
2006-03-24 05:56:59 +00:00
|
|
|
var
|
|
|
|
hitPoint: TPoint;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result.HitTestCode := htUnknown;
|
|
|
|
Result.Item := nil;
|
|
|
|
hitPoint := APoint;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
if PtInRect(Self.ClientRect, APoint) then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Painter.BeginPaint(Self);
|
|
|
|
try
|
|
|
|
Result := Painter.HitTest(hitPoint);
|
|
|
|
finally
|
|
|
|
Painter.EndPaint();
|
|
|
|
end;
|
2006-04-01 19:51:46 +00:00
|
|
|
|
|
|
|
if (Result.HitTestCode = htUnknown) and Assigned(Scroller) then
|
|
|
|
Result := Scroller.HitTest(APoint);
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TX2CustomMenuBar.HitTest(AX, AY: Integer): TX2MenuBarHitTest;
|
|
|
|
begin
|
|
|
|
Result := HitTest(Point(AX, AY));
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.Notification(AComponent: TComponent; Operation: TOperation);
|
|
|
|
begin
|
|
|
|
if Operation = opRemove then
|
|
|
|
if AComponent = FPainter then
|
|
|
|
begin
|
|
|
|
FPainter := nil;
|
|
|
|
Invalidate();
|
|
|
|
end else if AComponent = FImageList then
|
|
|
|
begin
|
|
|
|
FImageList := nil;
|
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.PainterUpdate(Sender: TX2CustomMenuBarPainter);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.MouseDown(Button: TMouseButton; Shift: TShiftState;
|
|
|
|
X, Y: Integer);
|
|
|
|
var
|
|
|
|
hitTest: TX2MenuBarHitTest;
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
|
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
if Button = mbLeft then
|
|
|
|
if AllowInteraction then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
hitTest := Self.HitTest(X, Y);
|
|
|
|
|
|
|
|
if hitTest.HitTestCode = htGroup then
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
2006-03-30 04:54:11 +00:00
|
|
|
group := TX2MenuBarGroup(hitTest.Item);
|
|
|
|
if group.Items.Count > 0 then
|
|
|
|
begin
|
|
|
|
group.Expanded := not group.Expanded;
|
|
|
|
hitTest.Item := FSelectedItem;
|
|
|
|
Invalidate();
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
if hitTest.HitTestCode = htScroller then
|
|
|
|
Scroller.MouseDown(Button, Shift, X, Y)
|
|
|
|
else
|
|
|
|
Scroller.MouseLeave();
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
if Assigned(hitTest.Item) and (hitTest.Item <> FSelectedItem) then
|
|
|
|
begin
|
|
|
|
if hitTest.HitTestCode = htItem then
|
|
|
|
TX2MenuBarItem(hitTest.Item).Group.SelectedItem := hitTest.Item.Index;
|
|
|
|
|
|
|
|
FSelectedItem := hitTest.Item;
|
|
|
|
Invalidate();
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.MouseMove(Shift: TShiftState; X, Y: Integer);
|
|
|
|
begin
|
|
|
|
FLastMousePos := Point(X, Y);
|
|
|
|
TestMousePos();
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
//procedure TX2CustomMenuBar.MouseUp(Button: TMouseButton; Shift: TShiftState;
|
|
|
|
// X, Y: Integer);
|
|
|
|
//begin
|
|
|
|
// inherited;
|
|
|
|
//end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.CMMouseLeave(var Message: TMessage);
|
|
|
|
begin
|
|
|
|
FLastMousePos := Point(-1, -1);
|
|
|
|
FHotItem := nil;
|
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.TestMousePos();
|
|
|
|
var
|
|
|
|
hitTest: TX2MenuBarHitTest;
|
|
|
|
|
|
|
|
begin
|
|
|
|
hitTest := Self.HitTest(FLastMousePos.X, FLastMousePos.Y);
|
|
|
|
if hitTest.Item <> FHotItem then
|
|
|
|
begin
|
|
|
|
FHotItem := hitTest.Item;
|
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
function TX2CustomMenuBar.GetMenuHeight(): Integer;
|
|
|
|
var
|
|
|
|
groupIndex: Integer;
|
|
|
|
group: TX2MenuBarGroup;
|
|
|
|
menuBounds: TRect;
|
|
|
|
itemIndex: Integer;
|
|
|
|
item: TX2MenuBarItem;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Assert(Assigned(Painter), 'No Painter assigned');
|
|
|
|
|
|
|
|
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];
|
|
|
|
Inc(Result, Painter.GetSpacing(seBeforeGroupHeader) +
|
|
|
|
Painter.GetGroupHeaderHeight(group) +
|
|
|
|
Painter.GetSpacing(seAfterGroupHeader));
|
|
|
|
|
|
|
|
if Assigned(Animator) and (Animator.Group = group) then
|
|
|
|
begin
|
|
|
|
{ Animated group }
|
|
|
|
Inc(Result, Animator.Height);
|
|
|
|
end else if group.Expanded then
|
|
|
|
begin
|
|
|
|
Inc(Result, Painter.GetSpacing(seBeforeFirstItem));
|
|
|
|
|
|
|
|
for itemIndex := 0 to Pred(group.Items.Count) do
|
|
|
|
begin
|
|
|
|
{ Item }
|
|
|
|
item := group.Items[itemIndex];
|
|
|
|
Inc(Result, Painter.GetSpacing(seBeforeItem) +
|
|
|
|
Painter.GetItemHeight(item) +
|
|
|
|
Painter.GetSpacing(seAfterItem));
|
|
|
|
end;
|
|
|
|
|
|
|
|
Inc(Result, Painter.GetSpacing(seAfterLastItem));
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.SetAnimator(const Value: TX2CustomMenuBarAnimator);
|
|
|
|
begin
|
|
|
|
if Value <> FAnimator then
|
|
|
|
begin
|
|
|
|
FreeAndNil(FAnimator);
|
|
|
|
FAnimator := Value;
|
|
|
|
end;
|
|
|
|
end;
|
2006-03-24 05:56:59 +00:00
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.SetBorderStyle(const Value: TBorderStyle);
|
|
|
|
begin
|
|
|
|
if Value <> FBorderStyle then
|
|
|
|
begin
|
|
|
|
FBorderStyle := Value;
|
|
|
|
RecreateWnd();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.SetGroups(const Value: TX2MenuBarGroups);
|
|
|
|
begin
|
|
|
|
if Value <> FGroups then
|
|
|
|
FGroups.Assign(Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2CustomMenuBar.SetImageList(const Value: TCustomImageList);
|
|
|
|
begin
|
|
|
|
if Value <> FImageList then
|
|
|
|
begin
|
|
|
|
if Assigned(FImageList) then
|
|
|
|
FImageList.RemoveFreeNotification(Self);
|
|
|
|
|
|
|
|
FImageList := Value;
|
|
|
|
|
|
|
|
if Assigned(FImageList) then
|
|
|
|
FImageList.FreeNotification(Self);
|
2006-04-01 19:51:46 +00:00
|
|
|
|
2006-03-24 05:56:59 +00:00
|
|
|
Invalidate();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.SetOptions(const Value: TX2MenuBarOptions);
|
|
|
|
begin
|
|
|
|
if Value <> FOptions then
|
|
|
|
begin
|
|
|
|
FOptions := Value;
|
|
|
|
Invalidate();
|
|
|
|
|
|
|
|
if mboAutoCollapse in Options then
|
|
|
|
AutoCollapse(nil);
|
|
|
|
|
|
|
|
if (mboAutoSelectItem in Options) and (not Assigned(FSelectedItem)) then
|
|
|
|
AutoSelectItem(nil);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
procedure TX2CustomMenuBar.SetScroller(const Value: TX2CustomMenuBarScroller);
|
|
|
|
begin
|
|
|
|
if Value <> FScroller then
|
|
|
|
begin
|
|
|
|
FreeAndNil(FScroller);
|
|
|
|
FScroller := Value;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2006-03-30 04:54:11 +00:00
|
|
|
procedure TX2CustomMenuBar.SetPainter(const Value: TX2CustomMenuBarPainter);
|
2006-03-24 05:56:59 +00:00
|
|
|
begin
|
|
|
|
if FPainter <> Value then
|
|
|
|
begin
|
|
|
|
if Assigned(FPainter) then
|
|
|
|
begin
|
|
|
|
FPainter.DetachObserver(Self);
|
|
|
|
FPainter.RemoveFreeNotification(Self);
|
|
|
|
end;
|
|
|
|
|
2006-04-01 19:51:46 +00:00
|
|
|
Animator := nil;
|
|
|
|
Scroller := nil;
|
2006-03-24 05:56:59 +00:00
|
|
|
FPainter := Value;
|
|
|
|
|
|
|
|
if Assigned(FPainter) then
|
|
|
|
begin
|
|
|
|
FPainter.FreeNotification(Self);
|
|
|
|
FPainter.AttachObserver(Self);
|
|
|
|
end;
|
|
|
|
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|
2006-04-01 19:51:46 +00:00
|
|
|
|