2010-03-05 21:57:25 +00:00
|
|
|
{ rxtoolbar unit
|
|
|
|
|
2018-11-05 20:49:44 +00:00
|
|
|
Copyright (C) 2005-2018 Lagunov Aleksey alexs75@yandex.ru and Lazarus team
|
2017-01-25 09:56:51 +00:00
|
|
|
original conception from rx library for Delphi (c)
|
2010-03-05 21:57:25 +00:00
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms of the GNU Library General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
option) any later version with the following modification:
|
|
|
|
|
|
|
|
As a special exception, the copyright holders of this library give you
|
|
|
|
permission to link this library with independent modules to produce an
|
|
|
|
executable, regardless of the license terms of these independent modules,and
|
|
|
|
to copy and distribute the resulting executable under terms of your choice,
|
|
|
|
provided that you also meet, for each linked independent module, the terms
|
|
|
|
and conditions of the license of that module. An independent module is a
|
|
|
|
module which is not derived from or based on this library. If you modify
|
|
|
|
this library, you may extend this exception to your version of the library,
|
|
|
|
but you are not obligated to do so. If you do not wish to do so, delete this
|
|
|
|
exception statement from your version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
|
|
|
|
for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public License
|
|
|
|
along with this library; if not, write to the Free Software Foundation,
|
|
|
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
}
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
unit rxtoolbar;
|
|
|
|
|
|
|
|
{$I rx.inc}
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
2007-08-10 22:15:51 +00:00
|
|
|
Classes, SysUtils, LCLType, LCLIntf, Buttons, Controls, ExtCtrls, ActnList,
|
2018-12-13 11:42:18 +00:00
|
|
|
PropertyStorage, Menus, Forms, types, Graphics, ImgList;
|
2007-08-09 21:36:59 +00:00
|
|
|
|
|
|
|
const
|
2018-12-13 11:42:18 +00:00
|
|
|
DefButtonWidth = 24;
|
|
|
|
DefButtonHeight = 23;
|
|
|
|
DefSeparatorWidth = 7;
|
2007-09-01 11:39:17 +00:00
|
|
|
DropDownExtraBtnWidth = 15;
|
2018-12-13 11:42:18 +00:00
|
|
|
DefSpacing = 4;
|
2007-09-01 11:39:17 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
type
|
|
|
|
TToolPanel = class;
|
|
|
|
TToolbarItem = class;
|
2018-12-13 11:42:18 +00:00
|
|
|
TToolbarItemsEnumerator = class;
|
|
|
|
|
2007-09-01 11:39:17 +00:00
|
|
|
TToolbarButtonStyle = (tbrButton, tbrCheck, tbrDropDown, tbrSeparator,
|
|
|
|
tbrDivider, tbrDropDownExtra);
|
2008-09-29 12:11:20 +00:00
|
|
|
TToolBarStyle = (tbsStandart, tbsWindowsXP, tbsNative);
|
2007-08-10 22:15:51 +00:00
|
|
|
TToolButtonAllign = (tbaNone, tbaLeft, tbaRignt);
|
2007-08-09 21:36:59 +00:00
|
|
|
|
|
|
|
TToolPanelOption = (tpFlatBtns, tpTransparentBtns, tpStretchBitmap,
|
|
|
|
tpCustomizable, tpGlyphPopup, tpCaptionPopup);
|
|
|
|
TToolPanelOptions = set of TToolPanelOption;
|
|
|
|
|
|
|
|
{ TToolbarButtonActionLink }
|
|
|
|
|
|
|
|
TToolbarButtonActionLink = class(TSpeedButtonActionLink)
|
|
|
|
protected
|
2009-11-23 18:07:35 +00:00
|
|
|
procedure SetImageIndex(Value: Integer); override;
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure SetEnabled(Value: Boolean); override;
|
|
|
|
procedure SetCaption(const Value: string); override;
|
2018-12-13 11:42:18 +00:00
|
|
|
public
|
|
|
|
function IsImageIndexLinked: Boolean; override;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
TToolbarButtonActionLinkClass = class of TToolbarButtonActionLink;
|
|
|
|
|
|
|
|
{ TToolbarButton }
|
|
|
|
TToolbarButton = class(TCustomSpeedButton)
|
|
|
|
private
|
|
|
|
FDesign:boolean;
|
|
|
|
FDesignX,
|
|
|
|
FDesignY:integer;
|
|
|
|
FDrag:boolean;
|
|
|
|
FDropDownMenu:TPopupMenu;
|
|
|
|
FToolbarButtonStyle:TToolbarButtonStyle;
|
|
|
|
FLastDrawFlagsA:integer;
|
|
|
|
FOwnerItem:TToolbarItem;
|
2007-09-01 11:39:17 +00:00
|
|
|
FFullPush:boolean;
|
2007-08-09 21:36:59 +00:00
|
|
|
function IsDesignMode:boolean;
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure PaintSeparator;
|
2018-12-13 11:42:18 +00:00
|
|
|
function ToolPanel:TToolPanel; inline;
|
2007-08-09 21:36:59 +00:00
|
|
|
protected
|
|
|
|
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;
|
2007-09-01 11:39:17 +00:00
|
|
|
procedure MouseLeave; override;
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure Paint; override;
|
|
|
|
procedure UpdateState(InvalidateOnChange: boolean); override;
|
|
|
|
procedure SetDesign(AValue:boolean; AToolbarItem:TToolbarItem);
|
|
|
|
procedure SetEnabled(NewEnabled: boolean); override;
|
|
|
|
function GetActionLinkClass: TControlActionLinkClass; override;
|
2007-08-10 22:15:51 +00:00
|
|
|
function GetDrawFlagsA: integer;
|
2018-12-13 11:42:18 +00:00
|
|
|
procedure CalculatePreferredSize( var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override;
|
2007-08-09 21:36:59 +00:00
|
|
|
public
|
|
|
|
destructor Destroy; override;
|
2018-12-14 11:41:03 +00:00
|
|
|
procedure Click; override;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{ TToolbarItem }
|
|
|
|
|
|
|
|
TToolbarItem = class(TCollectionItem)
|
|
|
|
private
|
2018-12-13 11:42:18 +00:00
|
|
|
FTextWidth:integer;
|
|
|
|
FTextHeight:integer;
|
|
|
|
|
|
|
|
FIntWidth:integer;
|
|
|
|
FIntHeight:integer;
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
FButton: TToolbarButton;
|
|
|
|
function GetAction: TBasicAction;
|
|
|
|
function GetButtonStyle: TToolbarButtonStyle;
|
|
|
|
function GetDropDownMenu: TPopupMenu;
|
|
|
|
function GetGroupIndex: Integer;
|
|
|
|
function GetLayout: TButtonLayout;
|
|
|
|
function GetShowCaption: boolean;
|
|
|
|
function GetTag: Longint;
|
|
|
|
function GetVisible: boolean;
|
|
|
|
procedure SetAction(const AValue: TBasicAction);
|
|
|
|
procedure SetButtonStyle(const AValue: TToolbarButtonStyle);
|
|
|
|
procedure SetDropDownMenu(const AValue: TPopupMenu);
|
|
|
|
procedure SetGroupIndex(const AValue: Integer);
|
|
|
|
procedure SetLayout(const AValue: TButtonLayout);
|
|
|
|
procedure SetShowCaption(const AValue: boolean);
|
|
|
|
procedure SetTag(const AValue: Longint);
|
|
|
|
procedure SetVisible(const AValue: boolean);
|
2007-08-10 22:15:51 +00:00
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
procedure InternalCalcSize;
|
2007-08-09 21:36:59 +00:00
|
|
|
protected
|
|
|
|
function GetDisplayName: string; override;
|
|
|
|
public
|
|
|
|
constructor Create(ACollection: TCollection); override;
|
|
|
|
destructor Destroy; override;
|
|
|
|
published
|
|
|
|
property Action:TBasicAction read GetAction write SetAction;
|
|
|
|
property Visible:boolean read GetVisible write SetVisible;
|
|
|
|
property DropDownMenu: TPopupMenu read GetDropDownMenu write SetDropDownMenu;
|
|
|
|
property ShowCaption:boolean read GetShowCaption write SetShowCaption;
|
|
|
|
property GroupIndex: Integer read GetGroupIndex write SetGroupIndex default 0;
|
|
|
|
property Layout: TButtonLayout read GetLayout write SetLayout default blGlyphLeft;
|
|
|
|
property ButtonStyle:TToolbarButtonStyle read GetButtonStyle write SetButtonStyle default tbrButton;
|
|
|
|
property Tag: Longint read GetTag write SetTag default 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TToolbarItems }
|
|
|
|
|
2013-06-02 19:38:20 +00:00
|
|
|
TToolbarItems = class(TOwnedCollection)
|
2007-08-09 21:36:59 +00:00
|
|
|
private
|
|
|
|
FToolPanel:TToolPanel;
|
|
|
|
function GetByActionName(ActionName: string): TToolbarItem;
|
|
|
|
function GetToolbarItem(Index: Integer): TToolbarItem;
|
|
|
|
procedure SetToolbarItem(Index: Integer; const AValue: TToolbarItem);
|
2018-12-13 11:42:18 +00:00
|
|
|
protected
|
|
|
|
procedure Notify(Item: TCollectionItem;Action: TCollectionNotification); override;
|
2007-08-09 21:36:59 +00:00
|
|
|
public
|
|
|
|
constructor Create(ToolPanel: TToolPanel);
|
2018-12-13 11:42:18 +00:00
|
|
|
function GetEnumerator: TToolbarItemsEnumerator;
|
|
|
|
function Add(AAction:TBasicAction): TToolbarItem;
|
|
|
|
function IndexOf(AItem:TToolbarItem):Integer;
|
2007-08-09 21:36:59 +00:00
|
|
|
property Items[Index: Integer]: TToolbarItem read GetToolbarItem write SetToolbarItem; default;
|
|
|
|
property ByActionName[ActionName:string]:TToolbarItem read GetByActionName;
|
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
{ TToolbarItemsEnumerator }
|
|
|
|
|
|
|
|
TToolbarItemsEnumerator = class
|
|
|
|
private
|
|
|
|
FList: TToolbarItems;
|
|
|
|
FPosition: Integer;
|
|
|
|
public
|
|
|
|
constructor Create(AList: TToolbarItems);
|
|
|
|
function GetCurrent: TToolbarItem;
|
|
|
|
function MoveNext: Boolean;
|
|
|
|
property Current: TToolbarItem read GetCurrent;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
{ TToolPanel }
|
|
|
|
|
|
|
|
TToolPanel = class(TCustomPanel)
|
|
|
|
private
|
2018-12-13 11:42:18 +00:00
|
|
|
//
|
|
|
|
FInternalDefButtonWidth:integer;
|
|
|
|
FInternalDefButtonHeight:integer;
|
|
|
|
FInternalDefSeparatorWidth:integer;
|
|
|
|
FInternalDropDownExtraBtnWidth:integer;
|
|
|
|
FInternalSpacing:integer;
|
2019-01-05 10:47:14 +00:00
|
|
|
FVisibleItems:TFPList;
|
2018-12-13 11:42:18 +00:00
|
|
|
|
|
|
|
//
|
2007-08-10 22:15:51 +00:00
|
|
|
FButtonAllign: TToolButtonAllign;
|
2016-01-14 10:13:52 +00:00
|
|
|
FCustomizeShortCut: boolean;
|
2007-08-09 21:36:59 +00:00
|
|
|
FImageList: TImageList;
|
2007-08-10 22:15:51 +00:00
|
|
|
FImageListSelected: TImageList;
|
2007-08-09 21:36:59 +00:00
|
|
|
FOptions: TToolPanelOptions;
|
|
|
|
FPropertyStorageLink:TPropertyStorageLink;
|
2018-12-13 11:42:18 +00:00
|
|
|
FSpacing: Integer;
|
2007-08-09 21:36:59 +00:00
|
|
|
FToolbarItems:TToolbarItems;
|
2018-12-13 11:42:18 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
FToolBarStyle: TToolBarStyle;
|
|
|
|
FVersion: Integer;
|
2007-09-01 11:39:17 +00:00
|
|
|
FArrowBmp:TBitmap;
|
2007-08-09 21:36:59 +00:00
|
|
|
function GetBtnHeight: Integer;
|
|
|
|
function GetBtnWidth: Integer;
|
|
|
|
function GetPropertyStorage: TCustomPropertyStorage;
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure SetButtonAllign(const AValue: TToolButtonAllign);
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure SetImageList(const AValue: TImageList);
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure SetImageListSelected(const AValue: TImageList);
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure SetItems(const AValue: TToolbarItems);
|
|
|
|
procedure SetOptions(const AValue: TToolPanelOptions);
|
|
|
|
procedure SetPropertyStorage(const AValue: TCustomPropertyStorage);
|
|
|
|
procedure OnIniSave(Sender: TObject);
|
|
|
|
procedure OnIniLoad(Sender: TObject);
|
|
|
|
procedure SetToolBarStyle(const AValue: TToolBarStyle);
|
2008-09-01 13:30:17 +00:00
|
|
|
procedure ReAlignToolBtn;
|
2018-12-13 11:42:18 +00:00
|
|
|
|
|
|
|
procedure InternalCalcImgSize;
|
|
|
|
procedure InternalCalcButtonsSize(out MaxHeight:Integer);
|
2019-01-05 10:47:14 +00:00
|
|
|
procedure UpdateVisibleItems;
|
2007-08-09 21:36:59 +00:00
|
|
|
protected
|
2018-12-13 11:42:18 +00:00
|
|
|
FDefImgWidth:integer;
|
|
|
|
FDefImgHeight:integer;
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure Notification(AComponent: TComponent;
|
|
|
|
Operation: TOperation); override;
|
|
|
|
procedure SetCustomizing(AValue:boolean);
|
2018-12-13 11:42:18 +00:00
|
|
|
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
|
2008-11-06 08:36:09 +00:00
|
|
|
procedure Loaded; override;
|
2018-12-13 11:42:18 +00:00
|
|
|
procedure CalculatePreferredSize( var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean); override;
|
|
|
|
function DoAlignChildControls(TheAlign: TAlign; AControl: TControl; AControlList: TFPList; var ARect: TRect): Boolean; override;
|
2007-08-09 21:36:59 +00:00
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy; override;
|
|
|
|
procedure Customize(HelpCtx: Longint);
|
2018-12-14 11:41:03 +00:00
|
|
|
procedure GetPreferredSize(var PreferredWidth, PreferredHeight: integer; Raw: boolean = false; WithThemeSpace: boolean = true); override;
|
2010-03-15 17:56:12 +00:00
|
|
|
procedure SetBounds(aLeft, aTop, aWidth, aHeight: integer); override;
|
2019-01-05 10:47:14 +00:00
|
|
|
|
|
|
|
property VisibleItems:TFPList read FVisibleItems;
|
2018-12-13 11:42:18 +00:00
|
|
|
property DefImgWidth:integer read FDefImgWidth;
|
|
|
|
property DefImgHeight:integer read FDefImgHeight;
|
2007-08-09 21:36:59 +00:00
|
|
|
published
|
2018-12-13 11:42:18 +00:00
|
|
|
property Items:TToolbarItems read FToolbarItems write SetItems;
|
2007-08-09 21:36:59 +00:00
|
|
|
property ImageList:TImageList read FImageList write SetImageList;
|
2007-08-10 22:15:51 +00:00
|
|
|
property ImageListSelected:TImageList read FImageListSelected write SetImageListSelected;
|
2007-08-09 21:36:59 +00:00
|
|
|
property PropertyStorage:TCustomPropertyStorage read GetPropertyStorage write SetPropertyStorage;
|
|
|
|
property ToolBarStyle:TToolBarStyle read FToolBarStyle write SetToolBarStyle default tbsStandart;
|
|
|
|
property Options:TToolPanelOptions read FOptions write SetOptions;
|
|
|
|
property Version: Integer read FVersion write FVersion default 0;
|
2010-04-23 16:32:38 +00:00
|
|
|
property ButtonAllign:TToolButtonAllign read FButtonAllign write SetButtonAllign default tbaLeft;
|
2016-01-14 10:13:52 +00:00
|
|
|
property CustomizeShortCut:boolean read FCustomizeShortCut write FCustomizeShortCut;
|
2007-08-09 21:36:59 +00:00
|
|
|
|
|
|
|
property Align;
|
|
|
|
property Alignment;
|
|
|
|
property Anchors;
|
|
|
|
property BorderSpacing;
|
|
|
|
property BevelInner;
|
|
|
|
property BevelOuter;
|
|
|
|
property BevelWidth;
|
|
|
|
property BorderWidth;
|
|
|
|
property BorderStyle;
|
|
|
|
property ChildSizing;
|
|
|
|
property ClientHeight;
|
|
|
|
property ClientWidth;
|
|
|
|
property Color;
|
|
|
|
property Constraints;
|
|
|
|
property DragMode;
|
|
|
|
property Enabled;
|
|
|
|
property Font;
|
|
|
|
property FullRepaint;
|
|
|
|
property ParentColor;
|
|
|
|
property ParentFont;
|
|
|
|
property ParentShowHint;
|
|
|
|
property PopupMenu;
|
|
|
|
property ShowHint;
|
|
|
|
property TabOrder;
|
|
|
|
property TabStop;
|
|
|
|
property Visible;
|
2018-12-13 11:42:18 +00:00
|
|
|
property Spacing:Integer read FSpacing write FSpacing default DefSpacing;
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
property OnClick;
|
|
|
|
property OnDblClick;
|
|
|
|
property OnDragDrop;
|
|
|
|
property OnDragOver;
|
|
|
|
property OnEndDrag;
|
|
|
|
property OnEnter;
|
|
|
|
property OnExit;
|
|
|
|
property OnMouseDown;
|
|
|
|
property OnMouseMove;
|
|
|
|
property OnMouseUp;
|
2014-09-29 07:02:18 +00:00
|
|
|
property OnMouseWheel;
|
|
|
|
property OnMouseWheelDown;
|
|
|
|
property OnMouseWheelUp;
|
2007-08-09 21:36:59 +00:00
|
|
|
property OnResize;
|
|
|
|
property OnStartDrag;
|
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
2017-08-22 12:28:33 +00:00
|
|
|
uses Math, RxTBRSetup, LCLProc, rxlclutils, Dialogs, typinfo, rxdconst, GraphType,
|
2018-12-14 11:41:03 +00:00
|
|
|
LResources, LCLVersion;
|
2007-08-09 21:36:59 +00:00
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
{ TToolbarItemsEnumerator }
|
|
|
|
|
|
|
|
constructor TToolbarItemsEnumerator.Create(AList: TToolbarItems);
|
|
|
|
begin
|
|
|
|
FList := AList;
|
|
|
|
FPosition := -1;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TToolbarItemsEnumerator.GetCurrent: TToolbarItem;
|
|
|
|
begin
|
|
|
|
Result := FList[FPosition];
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TToolbarItemsEnumerator.MoveNext: Boolean;
|
|
|
|
begin
|
|
|
|
Inc(FPosition);
|
|
|
|
Result := FPosition < FList.Count;
|
|
|
|
end;
|
2007-08-10 22:15:51 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
{ TToolbarButton }
|
|
|
|
|
|
|
|
function TToolbarButton.IsDesignMode: boolean;
|
|
|
|
begin
|
|
|
|
Result:=(Assigned(Parent) and (csDesigning in Parent.ComponentState)) or (FDesign);
|
|
|
|
end;
|
|
|
|
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure TToolbarButton.PaintSeparator;
|
|
|
|
var
|
|
|
|
PaintRect: TRect;
|
|
|
|
X, H:integer;
|
|
|
|
begin
|
|
|
|
PaintRect:=ClientRect;
|
|
|
|
Canvas.Brush.Color := Color;
|
|
|
|
Canvas.FillRect(PaintRect);
|
2007-09-01 11:39:17 +00:00
|
|
|
if FToolbarButtonStyle = tbrSeparator then
|
2007-08-10 22:15:51 +00:00
|
|
|
begin
|
2007-09-01 11:39:17 +00:00
|
|
|
X:=Width div 2 - 1;
|
|
|
|
H:=TToolPanel(Parent).Height;
|
|
|
|
if X>0 then
|
|
|
|
begin
|
|
|
|
Canvas.Pen.Color:=clBtnShadow;
|
|
|
|
Canvas.Line(X, 1, X, H);
|
|
|
|
Canvas.Pen.Color:=clWindow;
|
|
|
|
Canvas.Line(X+1, 1, X+1, H);
|
|
|
|
end;
|
2007-08-10 22:15:51 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
function TToolbarButton.ToolPanel: TToolPanel;
|
|
|
|
begin
|
|
|
|
Result:=TToolbarItems(FOwnerItem.Collection).FToolPanel;
|
|
|
|
end;
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure TToolbarButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X,
|
|
|
|
Y: Integer);
|
|
|
|
begin
|
|
|
|
if IsDesignMode then
|
|
|
|
begin
|
|
|
|
FDrag:=true;
|
|
|
|
FDesignX:=Max(X-1, 1);
|
|
|
|
FDesignY:=Max(Y-1, 1);
|
|
|
|
end
|
|
|
|
else
|
2007-09-01 11:39:17 +00:00
|
|
|
begin
|
|
|
|
FFullPush:=X < (Width - DropDownExtraBtnWidth - 5);
|
|
|
|
inherited MouseDown(Button, Shift, X, Y);
|
|
|
|
end;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolbarButton.MouseMove(Shift: TShiftState; X, Y: Integer);
|
|
|
|
begin
|
|
|
|
if IsDesignMode and FDrag then
|
|
|
|
begin
|
|
|
|
Top:=Max(0, Min(Y+Top-FDesignY, Parent.Height - Height));
|
|
|
|
Left:=Max(0, Min(X+Left-FDesignX, Parent.Width - Width));
|
|
|
|
end
|
|
|
|
else
|
2007-09-01 11:39:17 +00:00
|
|
|
begin
|
|
|
|
inherited MouseMove(Shift, X, Y);
|
|
|
|
end
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolbarButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
|
|
|
|
Y: Integer);
|
|
|
|
begin
|
|
|
|
if IsDesignMode then
|
|
|
|
begin
|
|
|
|
FDrag:=false;
|
|
|
|
Top:=4;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
inherited MouseUp(Button, Shift, X, Y);
|
|
|
|
end;
|
|
|
|
|
2007-09-01 11:39:17 +00:00
|
|
|
procedure TToolbarButton.MouseLeave;
|
|
|
|
begin
|
|
|
|
inherited MouseLeave;
|
|
|
|
FFullPush:=true;
|
|
|
|
end;
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure TToolbarButton.Paint;
|
|
|
|
var
|
2007-09-01 11:39:17 +00:00
|
|
|
PaintRect, PaintRect1: TRect;
|
2007-08-09 21:36:59 +00:00
|
|
|
GlyphWidth, GlyphHeight: Integer;
|
|
|
|
Offset, OffsetCap: TPoint;
|
|
|
|
ClientSize, TotalSize, TextSize: TSize;
|
2018-12-14 11:41:03 +00:00
|
|
|
M, S : integer;
|
2007-08-09 21:36:59 +00:00
|
|
|
TXTStyle : TTextStyle;
|
2018-12-13 11:42:18 +00:00
|
|
|
FImgN, FImgS: TImageList;
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
2007-09-01 11:39:17 +00:00
|
|
|
if FToolbarButtonStyle in [tbrSeparator, tbrDivider] then
|
2007-08-10 22:15:51 +00:00
|
|
|
begin
|
|
|
|
PaintSeparator;
|
|
|
|
exit;
|
|
|
|
end;
|
2018-11-19 07:46:27 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
UpdateState(false);
|
2018-12-13 11:42:18 +00:00
|
|
|
if (not Assigned(Action)) or (ToolPanel.FToolBarStyle = tbsNative) then
|
2018-11-19 07:46:27 +00:00
|
|
|
begin
|
|
|
|
inherited Paint;
|
2008-09-29 12:11:20 +00:00
|
|
|
exit;
|
2018-11-19 07:46:27 +00:00
|
|
|
end;
|
2008-09-29 12:11:20 +00:00
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
FImgN:=ToolPanel.FImageList;
|
|
|
|
FImgS:=ToolPanel.FImageListSelected;
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
PaintRect:=ClientRect;
|
2018-12-13 11:42:18 +00:00
|
|
|
|
2019-01-05 10:47:14 +00:00
|
|
|
//11
|
|
|
|
FLastDrawFlagsA:=GetDrawFlagsA;
|
2007-08-09 21:36:59 +00:00
|
|
|
|
2019-01-05 10:47:14 +00:00
|
|
|
if not Transparent then
|
|
|
|
begin
|
|
|
|
Canvas.Brush.Color := Color;
|
|
|
|
Canvas.FillRect(PaintRect);
|
|
|
|
end;
|
2007-08-09 21:36:59 +00:00
|
|
|
|
2019-01-05 10:47:14 +00:00
|
|
|
if FLastDrawFlagsA <> 0 then
|
|
|
|
begin
|
|
|
|
if ToolPanel.FToolBarStyle = tbsWindowsXP then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
|
2019-01-05 10:47:14 +00:00
|
|
|
if FToolbarButtonStyle = tbrDropDownExtra then
|
2007-09-01 11:39:17 +00:00
|
|
|
begin
|
2019-01-05 10:47:14 +00:00
|
|
|
PaintRect1:=PaintRect;
|
|
|
|
Dec(PaintRect1.Right, DropDownExtraBtnWidth);
|
|
|
|
if FFullPush then
|
|
|
|
DrawButtonFrameXP(Canvas, PaintRect1, (FLastDrawFlagsA and DFCS_PUSHED) <> 0, (FLastDrawFlagsA and DFCS_FLAT) <> 0)
|
2007-09-01 11:39:17 +00:00
|
|
|
else
|
2019-01-05 10:47:14 +00:00
|
|
|
DrawButtonFrameXP(Canvas, PaintRect1, false, (FLastDrawFlagsA and DFCS_FLAT) <> 0);
|
|
|
|
|
|
|
|
PaintRect1:=PaintRect;
|
|
|
|
PaintRect1.Left:=PaintRect1.Right - DropDownExtraBtnWidth;
|
|
|
|
DrawButtonFrameXP(Canvas, PaintRect1, (FLastDrawFlagsA and DFCS_PUSHED) <> 0, (FLastDrawFlagsA and DFCS_FLAT) <> 0);
|
2007-09-01 11:39:17 +00:00
|
|
|
end
|
2007-08-09 21:36:59 +00:00
|
|
|
else
|
2019-01-05 10:47:14 +00:00
|
|
|
DrawButtonFrameXP(Canvas, PaintRect, (FLastDrawFlagsA and DFCS_PUSHED) <> 0, (FLastDrawFlagsA and DFCS_FLAT) <> 0);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
if FToolbarButtonStyle = tbrDropDownExtra then
|
2007-09-01 11:39:17 +00:00
|
|
|
begin
|
2019-01-05 10:47:14 +00:00
|
|
|
PaintRect1:=PaintRect;
|
|
|
|
Dec(PaintRect1.Right, DropDownExtraBtnWidth);
|
2007-09-01 11:39:17 +00:00
|
|
|
|
2019-01-05 10:47:14 +00:00
|
|
|
if FFullPush then
|
|
|
|
begin
|
2007-09-01 11:39:17 +00:00
|
|
|
DrawButtonFrame(Canvas, PaintRect1, (FLastDrawFlagsA and DFCS_PUSHED) <> 0,
|
2019-01-05 10:47:14 +00:00
|
|
|
(FLastDrawFlagsA and DFCS_FLAT) <> 0);
|
2007-09-01 11:39:17 +00:00
|
|
|
end
|
|
|
|
else
|
2019-01-05 10:47:14 +00:00
|
|
|
begin
|
|
|
|
DrawButtonFrame(Canvas, PaintRect1, false,
|
|
|
|
(FLastDrawFlagsA and DFCS_FLAT) <> 0);
|
|
|
|
end;
|
|
|
|
|
|
|
|
PaintRect1:=PaintRect;
|
|
|
|
PaintRect1.Left:=PaintRect1.Right - DropDownExtraBtnWidth;
|
|
|
|
DrawButtonFrame(Canvas, PaintRect1, (FLastDrawFlagsA and DFCS_PUSHED) <> 0,
|
2007-08-09 21:36:59 +00:00
|
|
|
(FLastDrawFlagsA and DFCS_FLAT) <> 0);
|
2019-01-05 10:47:14 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
DrawButtonFrame(Canvas, PaintRect, (FLastDrawFlagsA and DFCS_PUSHED) <> 0,
|
|
|
|
(FLastDrawFlagsA and DFCS_FLAT) <> 0);
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
2019-01-05 10:47:14 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
if FToolbarButtonStyle = tbrDropDownExtra then
|
|
|
|
begin
|
|
|
|
Canvas.Draw(PaintRect.Right - 10, Height div 2, ToolPanel.FArrowBmp);
|
|
|
|
Dec(PaintRect.Right, DropDownExtraBtnWidth);
|
|
|
|
end;
|
|
|
|
//11
|
|
|
|
if (Action is TCustomAction) and Assigned(FImgN) and (TCustomAction(Action).ImageIndex>-1) and (TCustomAction(Action).ImageIndex < FImgN.Count) then
|
|
|
|
begin
|
|
|
|
|
2007-09-01 11:39:17 +00:00
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
GlyphWidth:=ToolPanel.FDefImgWidth;
|
|
|
|
GlyphHeight:=ToolPanel.FDefImgHeight;
|
2007-08-09 21:36:59 +00:00
|
|
|
|
|
|
|
ClientSize.cx:= PaintRect.Right - PaintRect.Left;
|
|
|
|
ClientSize.cy:= PaintRect.Bottom - PaintRect.Top;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
if ShowCaption then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
TextSize.cx:= FOwnerItem.FTextWidth;
|
|
|
|
TextSize.cy:= FOwnerItem.FTextHeight;
|
2007-08-09 21:36:59 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
TextSize.cx:= 0;
|
|
|
|
TextSize.cy:= 0;
|
|
|
|
end;
|
|
|
|
|
|
|
|
if (GlyphWidth = 0) or (GlyphHeight = 0) or (TextSize.cx = 0) or (TextSize.cy = 0) then
|
|
|
|
S:= 0
|
|
|
|
else
|
2018-12-13 11:42:18 +00:00
|
|
|
S:= ToolPanel.FInternalSpacing;
|
2007-08-09 21:36:59 +00:00
|
|
|
|
|
|
|
// Calculate caption and glyph layout
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
if S = -1 then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
TotalSize.cx:= TextSize.cx + GlyphWidth;
|
|
|
|
TotalSize.cy:= TextSize.cy + GlyphHeight;
|
|
|
|
if Layout in [blGlyphLeft, blGlyphRight] then
|
|
|
|
M:= (ClientSize.cx - TotalSize.cx) div 3
|
|
|
|
else
|
|
|
|
M:= (ClientSize.cy - TotalSize.cy) div 3;
|
|
|
|
S:= M;
|
2018-12-13 11:42:18 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
2007-08-09 21:36:59 +00:00
|
|
|
TotalSize.cx:= GlyphWidth + S + TextSize.cx;
|
|
|
|
TotalSize.cy:= GlyphHeight + S + TextSize.cy;
|
|
|
|
if Layout in [blGlyphLeft, blGlyphRight] then
|
|
|
|
M:= (ClientSize.cx - TotalSize.cx + 1) div 2
|
|
|
|
else
|
|
|
|
M:= (ClientSize.cy - TotalSize.cy + 1) div 2
|
|
|
|
end;
|
|
|
|
|
|
|
|
case Layout of
|
|
|
|
blGlyphLeft :
|
|
|
|
begin
|
|
|
|
Offset.X:= M;
|
|
|
|
Offset.Y:= (ClientSize.cy - GlyphHeight + 1) div 2;
|
|
|
|
OffsetCap.X:= Offset.X + GlyphWidth + S;
|
|
|
|
OffsetCap.Y:= (ClientSize.cy - TextSize.cy) div 2;
|
|
|
|
end;
|
|
|
|
blGlyphRight : begin
|
|
|
|
Offset.X:= ClientSize.cx - M - GlyphWidth;
|
|
|
|
Offset.Y:= (ClientSize.cy - GlyphHeight + 1) div 2;
|
|
|
|
OffsetCap.X:= Offset.X - S - TextSize.cx;
|
|
|
|
OffsetCap.Y:= (ClientSize.cy - TextSize.cy) div 2;
|
|
|
|
end;
|
|
|
|
blGlyphTop : begin
|
|
|
|
Offset.X:= (ClientSize.cx - GlyphWidth + 1) div 2;
|
|
|
|
Offset.Y:= M;
|
|
|
|
OffsetCap.X:= (ClientSize.cx - TextSize.cx + 1) div 2;
|
|
|
|
OffsetCap.Y:= Offset.Y + GlyphHeight + S;
|
|
|
|
end;
|
|
|
|
blGlyphBottom : begin
|
|
|
|
Offset.X:= (ClientSize.cx - GlyphWidth + 1) div 2;
|
|
|
|
Offset.Y:= ClientSize.cy - M - GlyphHeight;
|
|
|
|
OffsetCap.X:= (ClientSize.cx - TextSize.cx + 1) div 2;
|
|
|
|
OffsetCap.Y:= Offset.Y - S - TextSize.cy;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
if ((FLastDrawFlagsA and DFCS_FLAT) <> 0) and ((FLastDrawFlagsA and DFCS_PUSHED) = 0) and (not Assigned(FImgS)) and (tpGlyphPopup in ToolPanel.Options) and FFullPush then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
{$IF LCL_FullVersion >= 1080000}
|
|
|
|
//FImageList.DrawForPPI(Canvas, Offset.X, Offset.Y,
|
|
|
|
FImgN.DrawForPPI(Canvas, Offset.X, Offset.Y,
|
|
|
|
TCustomAction(Action).ImageIndex,
|
|
|
|
FImgN.Width,
|
|
|
|
Font.PixelsPerInch,
|
|
|
|
GetCanvasScaleFactor,
|
|
|
|
gdeShadowed);
|
|
|
|
{$ELSE}
|
2018-11-19 07:46:27 +00:00
|
|
|
FImageList.Draw(Canvas, Offset.X, Offset.Y, TCustomAction(Action).ImageIndex, gde1Bit);
|
2018-12-13 11:42:18 +00:00
|
|
|
{$ENDIF}
|
2007-08-09 21:36:59 +00:00
|
|
|
Dec(Offset.X, 2);
|
|
|
|
Dec(Offset.Y, 2);
|
|
|
|
end;
|
2007-08-10 22:15:51 +00:00
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
if Assigned(FImgS) and (FImgS.Count>TCustomAction(Action).ImageIndex) and ((FLastDrawFlagsA and DFCS_FLAT) <> 0) and ((FLastDrawFlagsA and DFCS_PUSHED) = 0) then
|
|
|
|
begin
|
|
|
|
{$IF LCL_FullVersion >= 1080000}
|
|
|
|
FImgS.DrawForPPI(Canvas, Offset.X, Offset.Y,
|
|
|
|
TCustomAction(Action).ImageIndex,
|
|
|
|
FImgS.Width,
|
|
|
|
Font.PixelsPerInch,
|
|
|
|
GetCanvasScaleFactor,
|
|
|
|
TCustomAction(Action).Enabled);
|
|
|
|
{$ELSE}
|
|
|
|
FImgS.Draw(Canvas, Offset.X, Offset.Y, TCustomAction(Action).ImageIndex, TCustomAction(Action).Enabled)
|
|
|
|
{$ENDIF}
|
|
|
|
end
|
2007-08-10 22:15:51 +00:00
|
|
|
else
|
2018-12-13 11:42:18 +00:00
|
|
|
{$IF LCL_FullVersion >= 1080000}
|
|
|
|
//FImageList.DrawForPPI(Canvas, Offset.X, Offset.Y,
|
|
|
|
FImgN.DrawForPPI(Canvas, Offset.X, Offset.Y,
|
|
|
|
TCustomAction(Action).ImageIndex,
|
|
|
|
FImgN.Width,
|
|
|
|
Font.PixelsPerInch,
|
|
|
|
GetCanvasScaleFactor,
|
|
|
|
TCustomAction(Action).Enabled);
|
|
|
|
{$ELSE}
|
2007-08-10 22:15:51 +00:00
|
|
|
FImageList.Draw(Canvas, Offset.X, Offset.Y, TCustomAction(Action).ImageIndex, TCustomAction(Action).Enabled);
|
2018-12-13 11:42:18 +00:00
|
|
|
{$ENDIF}
|
2019-01-05 10:47:14 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
OffsetCap.X:=0;
|
|
|
|
OffsetCap.Y:=0;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
2018-12-13 11:42:18 +00:00
|
|
|
|
2009-06-22 17:58:57 +00:00
|
|
|
if (Caption <> '') and ShowCaption then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
TXTStyle := Canvas.TextStyle;
|
|
|
|
TXTStyle.Opaque := False;
|
|
|
|
TXTStyle.Clipping := True;
|
|
|
|
TXTStyle.ShowPrefix := True;
|
|
|
|
TXTStyle.Alignment := taLeftJustify;
|
|
|
|
TXTStyle.Layout := tlTop;
|
|
|
|
TXTStyle.SystemFont := Canvas.Font.IsDefault;//Match System Default Style
|
|
|
|
With PaintRect, OffsetCap do
|
|
|
|
begin
|
|
|
|
Left := Left + X;
|
|
|
|
Top := Top + Y;
|
|
|
|
end;
|
|
|
|
If not Enabled then
|
|
|
|
begin
|
|
|
|
Canvas.Font.Color := clBtnHighlight;
|
|
|
|
OffsetRect(PaintRect, 1, 1);
|
|
|
|
Canvas.TextRect(PaintRect, PaintRect.Left, PaintRect.Top, Caption, TXTStyle);
|
|
|
|
Canvas.Font.Color := clBtnShadow;
|
|
|
|
OffsetRect(PaintRect, -1, -1);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
2009-08-06 16:59:07 +00:00
|
|
|
Canvas.Font.Color := clWindowText;
|
2018-12-13 11:42:18 +00:00
|
|
|
if ((FLastDrawFlagsA and DFCS_FLAT) <> 0) and ((FLastDrawFlagsA and DFCS_PUSHED) = 0) and (ToolPanel.FToolBarStyle <> tbsWindowsXP) and (tpCaptionPopup in ToolPanel.Options) then
|
2007-08-09 21:36:59 +00:00
|
|
|
OffsetRect(PaintRect, -2, -2);
|
|
|
|
end;
|
|
|
|
Canvas.TextRect(PaintRect, PaintRect.Left, PaintRect.Top, Caption, TXTStyle);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolbarButton.Click;
|
|
|
|
var
|
|
|
|
P:TPoint;
|
|
|
|
begin
|
|
|
|
if (csDesigning in ComponentState) or FDesign then exit;
|
|
|
|
if FToolbarButtonStyle = tbrDropDown then
|
|
|
|
begin
|
|
|
|
if Assigned(FDropDownMenu) then
|
|
|
|
begin
|
|
|
|
P.X:=0;
|
|
|
|
P.Y:=Height;
|
|
|
|
P:=ClientToScreen(P);
|
|
|
|
FDropDownMenu.PopUp(P.X, P.Y);
|
|
|
|
end;
|
|
|
|
end
|
2007-09-01 11:39:17 +00:00
|
|
|
else
|
|
|
|
if (FToolbarButtonStyle = tbrDropDownExtra) and (not FFullPush) then
|
|
|
|
begin
|
|
|
|
if Assigned(FDropDownMenu) then
|
|
|
|
begin
|
|
|
|
P.X:=Width - DropDownExtraBtnWidth;
|
|
|
|
P.Y:=Height;
|
|
|
|
P:=ClientToScreen(P);
|
|
|
|
FDropDownMenu.PopUp(P.X, P.Y);
|
|
|
|
end;
|
|
|
|
end
|
2007-08-09 21:36:59 +00:00
|
|
|
else
|
|
|
|
inherited Click;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolbarButton.UpdateState(InvalidateOnChange: boolean);
|
|
|
|
var
|
|
|
|
OldState: TButtonState;
|
|
|
|
begin
|
|
|
|
OldState:=FState;
|
|
|
|
inherited UpdateState(InvalidateOnChange);
|
2007-08-10 22:15:51 +00:00
|
|
|
if InvalidateOnChange and ((FState<>OldState) or (FLastDrawFlagsA<>GetDrawFlagsA)) then
|
2007-08-09 21:36:59 +00:00
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolbarButton.SetDesign(AValue:boolean; AToolbarItem:TToolbarItem);
|
|
|
|
begin
|
|
|
|
FDesign:=AValue;
|
|
|
|
if FDesign then
|
|
|
|
begin
|
|
|
|
Enabled:=true;
|
|
|
|
Flat:=false;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
Flat:=tpFlatBtns in ToolPanel.Options;
|
2007-08-09 21:36:59 +00:00
|
|
|
ActionChange(Action, true);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolbarButton.SetEnabled(NewEnabled: boolean);
|
|
|
|
begin
|
|
|
|
if FToolbarButtonStyle = tbrDropDown then
|
|
|
|
NewEnabled :=true;
|
2007-08-10 22:15:51 +00:00
|
|
|
if (not NewEnabled) and Enabled then
|
|
|
|
begin
|
|
|
|
FState := bsDisabled;
|
|
|
|
MouseLeave;
|
|
|
|
end;
|
2007-08-09 21:36:59 +00:00
|
|
|
inherited SetEnabled(NewEnabled);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TToolbarButton.GetActionLinkClass: TControlActionLinkClass;
|
|
|
|
begin
|
|
|
|
Result:=TToolbarButtonActionLink;
|
|
|
|
end;
|
|
|
|
|
2007-08-10 22:15:51 +00:00
|
|
|
function TToolbarButton.GetDrawFlagsA: integer;
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
2007-08-10 22:15:51 +00:00
|
|
|
if (Flat and not MouseInControl and not (FState in [bsDown, bsExclusive])) or (not Enabled) then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
Result := 0;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
Result:=DFCS_BUTTONPUSH;
|
|
|
|
if FState in [bsDown, bsExclusive] then
|
|
|
|
inc(Result,DFCS_PUSHED);
|
|
|
|
if not Enabled then
|
|
|
|
inc(Result,DFCS_INACTIVE);
|
|
|
|
if Flat then
|
|
|
|
inc(Result,DFCS_FLAT);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
procedure TToolbarButton.CalculatePreferredSize(var PreferredWidth,
|
|
|
|
PreferredHeight: integer; WithThemeSpace: Boolean);
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
inherited CalculatePreferredSize(PreferredWidth, PreferredHeight, WithThemeSpace);
|
|
|
|
if PreferredWidth < FOwnerItem.FIntWidth then
|
|
|
|
PreferredWidth:=FOwnerItem.FIntWidth;
|
|
|
|
if PreferredHeight < FOwnerItem.FIntHeight then
|
|
|
|
PreferredHeight:=FOwnerItem.FIntHeight;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TToolbarButton.Destroy;
|
|
|
|
begin
|
|
|
|
if Assigned(FOwnerItem) then
|
|
|
|
begin
|
|
|
|
FOwnerItem.FButton:=nil;
|
|
|
|
FOwnerItem.Free;
|
|
|
|
end;
|
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
{ TToolbarItems }
|
|
|
|
|
|
|
|
function TToolbarItems.GetToolbarItem(Index: Integer): TToolbarItem;
|
|
|
|
begin
|
|
|
|
result := TToolbarItem( inherited Items[Index] );
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TToolbarItems.GetByActionName(ActionName: string): TToolbarItem;
|
|
|
|
var
|
|
|
|
i:integer;
|
|
|
|
begin
|
|
|
|
Result:=nil;
|
|
|
|
for i:=0 to Count-1 do
|
2007-08-10 22:15:51 +00:00
|
|
|
if Assigned(Items[i].Action) and (Items[i].Action.Name = ActionName) then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
Result:=Items[i];
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolbarItems.SetToolbarItem(Index: Integer;
|
|
|
|
const AValue: TToolbarItem);
|
|
|
|
begin
|
|
|
|
Items[Index].Assign( AValue );
|
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
procedure TToolbarItems.Notify(Item: TCollectionItem;
|
|
|
|
Action: TCollectionNotification);
|
|
|
|
begin
|
|
|
|
if Action = cnDeleting then
|
|
|
|
FToolPanel.DisableAlign;
|
|
|
|
inherited Notify(Item, Action);
|
|
|
|
if Action = cnDeleting then
|
2018-12-14 11:41:03 +00:00
|
|
|
FToolPanel.EnableAlign
|
|
|
|
else
|
|
|
|
FToolPanel.ReAlignToolBtn;
|
2018-12-13 11:42:18 +00:00
|
|
|
end;
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
constructor TToolbarItems.Create(ToolPanel: TToolPanel);
|
|
|
|
begin
|
2013-06-02 19:38:20 +00:00
|
|
|
inherited Create(ToolPanel, TToolbarItem);
|
2007-08-09 21:36:59 +00:00
|
|
|
FToolPanel:=ToolPanel;
|
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
function TToolbarItems.GetEnumerator: TToolbarItemsEnumerator;
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
Result:=TToolbarItemsEnumerator.Create(Self);
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
function TToolbarItems.Add(AAction: TBasicAction): TToolbarItem;
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
Result:=inherited Add as TToolbarItem;
|
|
|
|
Result.Action:=AAction;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
function TToolbarItems.IndexOf(AItem: TToolbarItem): Integer;
|
|
|
|
var
|
|
|
|
i: Integer;
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
Result:=-1;
|
|
|
|
if AItem.Collection <> Self then Exit;
|
|
|
|
for i:=0 to Count-1 do
|
|
|
|
if Items[i] = AItem then
|
|
|
|
Exit(i);
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
{ TToolPanel }
|
2007-08-09 21:36:59 +00:00
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
function TToolPanel.GetBtnHeight: Integer;
|
2007-08-09 21:36:59 +00:00
|
|
|
var
|
2018-12-13 11:42:18 +00:00
|
|
|
AImageResolution: TScaledImageListResolution;
|
|
|
|
FExternalImageWidth: Integer;
|
|
|
|
begin
|
|
|
|
{$IF LCL_FullVersion >= 1080000}
|
|
|
|
FExternalImageWidth:=0;
|
|
|
|
AImageResolution := FImageList.ResolutionForPPI[FExternalImageWidth, Font.PixelsPerInch, GetCanvasScaleFactor];
|
|
|
|
Result:=AImageResolution.Height;
|
|
|
|
{$ELSE}
|
|
|
|
Result:=FDefButtonHeight;
|
|
|
|
{$ENDIF}
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
function TToolPanel.GetBtnWidth: Integer;
|
2007-08-09 21:36:59 +00:00
|
|
|
var
|
2018-12-13 11:42:18 +00:00
|
|
|
AImageResolution: TScaledImageListResolution;
|
|
|
|
FExternalImageWidth: Integer;
|
|
|
|
begin
|
|
|
|
{$IF LCL_FullVersion >= 1080000}
|
|
|
|
FExternalImageWidth:=0;
|
|
|
|
AImageResolution := FImageList.ResolutionForPPI[FExternalImageWidth, Font.PixelsPerInch, GetCanvasScaleFactor];
|
|
|
|
Result:=AImageResolution.Width;
|
|
|
|
{$ELSE}
|
|
|
|
Result:=FDefButtonWidth;
|
|
|
|
{$ENDIF}
|
|
|
|
end;
|
2010-03-22 19:48:23 +00:00
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
function TToolPanel.GetPropertyStorage: TCustomPropertyStorage;
|
|
|
|
begin
|
|
|
|
Result:=FPropertyStorageLink.Storage;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure TToolPanel.SetButtonAllign(const AValue: TToolButtonAllign);
|
|
|
|
begin
|
|
|
|
if FButtonAllign=AValue then exit;
|
|
|
|
FButtonAllign:=AValue;
|
|
|
|
if not (csLoading in ComponentState) then
|
2018-12-13 11:42:18 +00:00
|
|
|
ReAlign;
|
2007-08-10 22:15:51 +00:00
|
|
|
end;
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure TToolPanel.SetImageList(const AValue: TImageList);
|
|
|
|
begin
|
|
|
|
if FImageList=AValue then exit;
|
|
|
|
FImageList:=AValue;
|
2019-01-05 10:47:14 +00:00
|
|
|
|
|
|
|
InternalCalcImgSize;
|
|
|
|
|
|
|
|
InvalidatePreferredSize;
|
|
|
|
AdjustSize;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure TToolPanel.SetImageListSelected(const AValue: TImageList);
|
|
|
|
begin
|
|
|
|
if FImageListSelected=AValue then exit;
|
|
|
|
FImageListSelected:=AValue;
|
|
|
|
end;
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure TToolPanel.SetItems(const AValue: TToolbarItems);
|
|
|
|
begin
|
|
|
|
FToolbarItems.Assign(AValue);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolPanel.SetOptions(const AValue: TToolPanelOptions);
|
|
|
|
var
|
|
|
|
i:integer;
|
|
|
|
begin
|
|
|
|
if FOptions=AValue then exit;
|
|
|
|
FOptions:=AValue;
|
|
|
|
|
|
|
|
for i:=0 to FToolbarItems.Count - 1 do
|
|
|
|
begin
|
|
|
|
FToolbarItems[i].FButton.Transparent:=tpTransparentBtns in FOptions;
|
|
|
|
FToolbarItems[i].FButton.Flat:=tpFlatBtns in FOptions;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolPanel.SetPropertyStorage(const AValue: TCustomPropertyStorage);
|
|
|
|
begin
|
|
|
|
FPropertyStorageLink.Storage:=AValue;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TToolPanel.OnIniSave(Sender: TObject);
|
|
|
|
var
|
|
|
|
S, S1:string;
|
|
|
|
tpo:TToolPanelOptions;
|
|
|
|
tpo1:integer absolute tpo;
|
2018-12-13 11:42:18 +00:00
|
|
|
IT: TToolbarItem;
|
|
|
|
I:integer;
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
S:=Owner.Name+'.'+Name;
|
2018-12-13 11:42:18 +00:00
|
|
|
FPropertyStorageLink.Storage.WriteInteger(S+sVersion2, FVersion);
|
2007-08-09 21:36:59 +00:00
|
|
|
FPropertyStorageLink.Storage.WriteInteger(S+sShowHint, ord(ShowHint));
|
|
|
|
tpo:=FOptions;
|
|
|
|
FPropertyStorageLink.Storage.WriteString(S+sOptions, SetToString(GetPropInfo(Self, 'Options'), tpo1));
|
|
|
|
FPropertyStorageLink.Storage.WriteString(S+sToolBarStyle, GetEnumProp(Self, 'ToolBarStyle'));
|
2007-08-10 22:15:51 +00:00
|
|
|
FPropertyStorageLink.Storage.WriteString(S+sButtonAllign, GetEnumProp(Self, 'ButtonAllign'));
|
2018-12-13 11:42:18 +00:00
|
|
|
|
|
|
|
I:=0;
|
2019-01-08 19:15:14 +00:00
|
|
|
for i:=0 to FVisibleItems.Count-1 do
|
|
|
|
begin
|
|
|
|
IT:=TToolbarItem(FVisibleItems[i]);
|
|
|
|
S1:=S + sItem + IntToStr(i);
|
|
|
|
FPropertyStorageLink.Storage.WriteString(S1+sOptions, GetEnumProp(IT, 'ButtonStyle'));
|
|
|
|
FPropertyStorageLink.Storage.WriteInteger(S1+sIndex, IT.Index);
|
|
|
|
if Assigned(IT.Action) then
|
|
|
|
begin
|
|
|
|
FPropertyStorageLink.Storage.WriteString(S1+sAction, IT.Action.Name);
|
|
|
|
FPropertyStorageLink.Storage.WriteInteger(S1+sShowCaption, ord(IT.ShowCaption));
|
|
|
|
if FCustomizeShortCut then
|
|
|
|
FPropertyStorageLink.Storage.WriteString(S1+sShortCut, ShortCutToText(TCustomAction(IT.Action).ShortCut));
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
FPropertyStorageLink.Storage.WriteInteger(S+sCount, FVisibleItems.Count);
|
|
|
|
(*
|
2018-12-13 11:42:18 +00:00
|
|
|
for IT in Items do
|
|
|
|
if IT.Visible then
|
|
|
|
begin
|
|
|
|
S1:=S + sItem + IntToStr(i);
|
|
|
|
FPropertyStorageLink.Storage.WriteString(S1+sOptions, GetEnumProp(IT, 'ButtonStyle'));
|
2018-12-14 12:17:30 +00:00
|
|
|
FPropertyStorageLink.Storage.WriteInteger(S1+sIndex, IT.Index);
|
2018-12-13 11:42:18 +00:00
|
|
|
if Assigned(IT.Action) then
|
|
|
|
begin
|
|
|
|
FPropertyStorageLink.Storage.WriteString(S1+sAction, IT.Action.Name);
|
|
|
|
FPropertyStorageLink.Storage.WriteInteger(S1+sShowCaption, ord(IT.ShowCaption));
|
|
|
|
if FCustomizeShortCut then
|
|
|
|
FPropertyStorageLink.Storage.WriteString(S1+sShortCut, ShortCutToText(TCustomAction(IT.Action).ShortCut));
|
|
|
|
end;
|
|
|
|
Inc(i);
|
|
|
|
end;
|
|
|
|
FPropertyStorageLink.Storage.WriteInteger(S+sCount, i);
|
2019-01-08 19:15:14 +00:00
|
|
|
|
|
|
|
*)
|
2018-12-13 11:42:18 +00:00
|
|
|
(* for i:=0 to FToolbarItems.Count-1 do
|
|
|
|
begin
|
|
|
|
IT:=FToolbarItems[i];
|
|
|
|
if IT.Visible then ;
|
|
|
|
if Assigned(IT.Action) then
|
|
|
|
begin
|
|
|
|
FPropertyStorageLink.Storage.WriteString(S1+sAction, IT.Action.Name);
|
|
|
|
FPropertyStorageLink.Storage.WriteInteger(S1+sVisible, ord(IT.Visible));
|
|
|
|
FPropertyStorageLink.Storage.WriteInteger(S1+sShowCaption, ord(IT.ShowCaption));
|
|
|
|
if FCustomizeShortCut and Assigned(IT.Action) then
|
|
|
|
FPropertyStorageLink.Storage.WriteString(S1+sShortCut, ShortCutToText(TCustomAction(IT.Action).ShortCut));
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if IT
|
|
|
|
begin
|
|
|
|
FPropertyStorageLink.Storage.WriteString(S1+sAction, '');
|
|
|
|
FPropertyStorageLink.Storage.WriteString(S1+sAction, '');
|
|
|
|
end;
|
|
|
|
end; *)
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolPanel.OnIniLoad(Sender: TObject);
|
|
|
|
function OldReadBtnPosition(ASection:string):boolean;
|
|
|
|
var
|
|
|
|
ACount: LongInt;
|
|
|
|
i: Integer;
|
|
|
|
S, S1, AActionName, S2: String;
|
|
|
|
St: TStringList;
|
|
|
|
P, P1: TToolbarItem;
|
|
|
|
begin
|
|
|
|
ACount:=FPropertyStorageLink.Storage.ReadInteger(ASection+sCount, -1);
|
|
|
|
if ACount < 0 then Exit(false);
|
2019-01-05 21:22:47 +00:00
|
|
|
FVisibleItems.Clear;
|
2018-12-13 11:42:18 +00:00
|
|
|
Result:=true;
|
|
|
|
S:=ASection+sItem;
|
|
|
|
St:=TStringList.Create;
|
|
|
|
St.Sorted:=true;
|
|
|
|
for P in Items do P.Visible:=false;
|
|
|
|
for i:=0 to ACount-1 do
|
|
|
|
begin
|
|
|
|
S1:=S+IntToStr(i);
|
|
|
|
AActionName:=FPropertyStorageLink.Storage.ReadString(S1+sAction, '');
|
|
|
|
P:=FToolbarItems.ByActionName[AActionName];
|
|
|
|
if Assigned(P) then
|
|
|
|
begin
|
|
|
|
St.AddObject('%0.5d-%s', [FPropertyStorageLink.Storage.ReadInteger(S1+sLeft, -1), AActionName], P);
|
|
|
|
P.Visible:=true;
|
2019-01-08 19:15:14 +00:00
|
|
|
FVisibleItems.Add(P);
|
2018-12-13 11:42:18 +00:00
|
|
|
|
|
|
|
if FCustomizeShortCut and Assigned(P.Action) then
|
|
|
|
begin
|
|
|
|
S2:=FPropertyStorageLink.Storage.ReadString(S1+sShortCut, ShortCutToText(TCustomAction(P.Action).ShortCut));
|
|
|
|
TCustomAction(P.Action).ShortCut:=TextToShortCut(S2);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
for i:=0 to St.Count-1 do
|
|
|
|
begin
|
|
|
|
P:=TToolbarItem(St.Objects[i]);
|
|
|
|
P1:=Items[i];
|
|
|
|
Items.Exchange(P.ID, P1.ID);
|
|
|
|
end;
|
|
|
|
St.Free;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function GetFreeSeparator:TToolbarItem;
|
|
|
|
var
|
|
|
|
TI: TToolbarItem;
|
|
|
|
begin
|
|
|
|
Result:=nil;
|
|
|
|
for TI in Items do
|
|
|
|
if (TI.ButtonStyle in [tbrSeparator, tbrDivider]) and (not TI.Visible) then
|
|
|
|
Exit(TI);
|
|
|
|
|
|
|
|
Result:=Items.Add(nil);
|
|
|
|
Result.ButtonStyle:=tbrSeparator;
|
|
|
|
Result.Visible:=true;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function ReadBtnPosition(ASection:string):boolean;
|
|
|
|
var
|
|
|
|
St: TStringList;
|
|
|
|
P, P1: TToolbarItem;
|
|
|
|
FCnt: LongInt;
|
|
|
|
S, S1, SType, FActionName, S2: string;
|
|
|
|
i: Integer;
|
|
|
|
begin
|
|
|
|
Result:=false;
|
|
|
|
S:=ASection;
|
|
|
|
FCnt:=FPropertyStorageLink.Storage.ReadInteger(S+sVersion2, FVersion);
|
|
|
|
if FCnt < FVersion then Exit;
|
2019-01-05 21:22:47 +00:00
|
|
|
FVisibleItems.Clear;
|
2018-12-13 11:42:18 +00:00
|
|
|
for P in Items do P.Visible:=false;
|
|
|
|
St:=TStringList.Create;
|
|
|
|
FCnt:=FPropertyStorageLink.Storage.ReadInteger(S+sCount, 0);
|
2007-08-09 21:36:59 +00:00
|
|
|
S:=S+sItem;
|
2018-12-13 11:42:18 +00:00
|
|
|
for i:=0 to FCnt-1 do
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
S1:=S+IntToStr(i);
|
2018-12-13 11:42:18 +00:00
|
|
|
SType:=FPropertyStorageLink.Storage.ReadString(S1+sOptions, '');
|
|
|
|
if (SType = 'tbrSeparator') or (SType = 'tbrDivider') then
|
2007-08-10 22:15:51 +00:00
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
P:=GetFreeSeparator;
|
|
|
|
if Assigned(P) then
|
|
|
|
begin
|
|
|
|
P.Visible:=true;
|
2019-01-05 10:47:14 +00:00
|
|
|
FVisibleItems.Add(P);
|
2018-12-13 11:42:18 +00:00
|
|
|
St.AddObject('S', P);
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if (SType <>'') then
|
|
|
|
begin
|
|
|
|
FActionName:=FPropertyStorageLink.Storage.ReadString(S1+sAction, '');
|
|
|
|
P:=FToolbarItems.ByActionName[FActionName];
|
|
|
|
if Assigned(P) then
|
|
|
|
begin
|
|
|
|
P.Visible:=true;
|
2019-01-05 10:47:14 +00:00
|
|
|
FVisibleItems.Add(P);
|
2018-12-13 11:42:18 +00:00
|
|
|
P.ShowCaption:=FPropertyStorageLink.Storage.ReadInteger(S1+sShowCaption, ord(P.ShowCaption))<>0;
|
|
|
|
if FCustomizeShortCut and Assigned(P.Action) then
|
|
|
|
begin
|
|
|
|
S2:=FPropertyStorageLink.Storage.ReadString(S1+sShortCut, ShortCutToText(TCustomAction(P.Action).ShortCut));
|
|
|
|
TCustomAction(P.Action).ShortCut:=TextToShortCut(S2);
|
|
|
|
end;
|
|
|
|
|
|
|
|
St.AddObject('S', P);
|
|
|
|
end;
|
2007-08-10 22:15:51 +00:00
|
|
|
end;
|
2018-12-14 12:17:30 +00:00
|
|
|
|
|
|
|
if Assigned(P) then
|
|
|
|
P.Index:= FPropertyStorageLink.Storage.ReadInteger(S1+sIndex, I);
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
2018-12-13 11:42:18 +00:00
|
|
|
for i:=0 to St.Count-1 do
|
|
|
|
begin
|
|
|
|
P:=TToolbarItem(St.Objects[i]);
|
|
|
|
P1:=Items[i];
|
|
|
|
Items.Exchange(P.ID, P1.ID);
|
|
|
|
end;
|
|
|
|
|
|
|
|
St.Free;
|
|
|
|
|
|
|
|
Result:=true;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
2018-12-14 11:41:03 +00:00
|
|
|
ACount:integer;
|
2007-08-09 21:36:59 +00:00
|
|
|
tpo:TToolPanelOptions;
|
|
|
|
tpo1:integer absolute tpo;
|
2018-12-13 11:42:18 +00:00
|
|
|
S: TComponentName;
|
|
|
|
FEnableRead: Boolean;
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
S:=Owner.Name+'.'+Name;
|
2018-12-13 11:42:18 +00:00
|
|
|
ACount:=FPropertyStorageLink.Storage.ReadInteger(S+sVersion2, -9999); //Check cfg version
|
|
|
|
|
|
|
|
Items.BeginUpdate;
|
|
|
|
if ACount = -9999 then
|
|
|
|
FEnableRead:=OldReadBtnPosition(S)
|
|
|
|
else
|
|
|
|
FEnableRead:=ReadBtnPosition(S);
|
|
|
|
|
|
|
|
if FEnableRead then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
ShowHint:=FPropertyStorageLink.Storage.ReadInteger(S+sShowHint, ord(ShowHint))<>0;
|
|
|
|
|
|
|
|
tpo:=FOptions;
|
|
|
|
tpo1:=StringToSet(GetPropInfo(Self, 'Options'), FPropertyStorageLink.Storage.ReadString(S+sOptions, SetToString(GetPropInfo(Self, 'Options'), tpo1)));
|
|
|
|
SetOptions(tpo);
|
|
|
|
|
|
|
|
SetEnumProp(Self, 'ToolBarStyle', FPropertyStorageLink.Storage.ReadString(S+sToolBarStyle, GetEnumProp(Self, 'ToolBarStyle')));
|
2007-08-10 22:15:51 +00:00
|
|
|
SetEnumProp(Self, 'ButtonAllign', FPropertyStorageLink.Storage.ReadString(S+sButtonAllign, GetEnumProp(Self, 'ButtonAllign')));
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
2018-12-13 11:42:18 +00:00
|
|
|
Items.EndUpdate;
|
|
|
|
ReAlignToolBtn;
|
2007-08-09 21:36:59 +00:00
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolPanel.SetToolBarStyle(const AValue: TToolBarStyle);
|
|
|
|
begin
|
|
|
|
if FToolBarStyle=AValue then exit;
|
|
|
|
FToolBarStyle:=AValue;
|
2018-12-13 11:42:18 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
if FToolBarStyle = tbsWindowsXP then
|
2014-07-18 05:03:51 +00:00
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
// BorderWidth:=4;
|
2007-08-09 21:36:59 +00:00
|
|
|
SetOptions(FOptions + [tpFlatBtns]);
|
2014-07-18 05:03:51 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
// BorderWidth:=1
|
2014-07-18 05:03:51 +00:00
|
|
|
end;
|
2007-08-09 21:36:59 +00:00
|
|
|
Invalidate;
|
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
|
2008-09-01 13:30:17 +00:00
|
|
|
procedure TToolPanel.ReAlignToolBtn;
|
|
|
|
var
|
2018-12-13 11:42:18 +00:00
|
|
|
H: Integer;
|
2008-09-01 13:30:17 +00:00
|
|
|
begin
|
2019-01-05 10:47:14 +00:00
|
|
|
if Assigned(Parent) and not (csLoading in ComponentState) and (not (csDestroying in ComponentState)) then
|
2008-09-01 13:30:17 +00:00
|
|
|
begin
|
2019-01-05 10:47:14 +00:00
|
|
|
if csDesigning in ComponentState then
|
|
|
|
UpdateVisibleItems;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
InternalCalcButtonsSize(H);
|
|
|
|
ReAlign;
|
2008-09-01 13:30:17 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
procedure TToolPanel.InternalCalcImgSize;
|
|
|
|
var
|
|
|
|
AImageResolution: TScaledImageListResolution;
|
|
|
|
begin
|
|
|
|
FInternalDefButtonWidth:=ScaleDesignToForm(DefButtonWidth);
|
|
|
|
FInternalDefButtonHeight:=ScaleDesignToForm(DefButtonHeight);
|
|
|
|
FInternalDefSeparatorWidth:=ScaleDesignToForm(DefSeparatorWidth);
|
|
|
|
FInternalDropDownExtraBtnWidth:=ScaleDesignToForm(DropDownExtraBtnWidth);
|
|
|
|
FInternalSpacing:=ScaleDesignToForm(Spacing);
|
|
|
|
|
|
|
|
if Assigned(FImageList) then
|
|
|
|
begin
|
|
|
|
{$IF LCL_FullVersion >= 1080000}
|
|
|
|
AImageResolution := FImageList.ResolutionForPPI[0, Font.PixelsPerInch, GetCanvasScaleFactor];
|
|
|
|
FDefImgWidth:=AImageResolution.Width;
|
|
|
|
FDefImgHeight:=AImageResolution.Height;
|
|
|
|
{$ELSE}
|
|
|
|
FDefImgWidth:=FImageList.Width;
|
|
|
|
FDefImgHeight:=FImageList.Height;
|
|
|
|
{$ENDIF}
|
2018-12-14 10:54:15 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
FDefImgWidth:=FInternalDefButtonWidth;
|
|
|
|
FDefImgHeight:=FInternalDefButtonHeight;
|
2018-12-13 11:42:18 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolPanel.InternalCalcButtonsSize(out MaxHeight: Integer);
|
|
|
|
var
|
|
|
|
DC: HDC;
|
|
|
|
Flags: Cardinal;
|
|
|
|
TI: TToolbarItem;
|
|
|
|
R: TRect;
|
|
|
|
OldFont: HGDIOBJ;
|
2019-01-05 10:47:14 +00:00
|
|
|
S: String;
|
|
|
|
FTH: LongInt;
|
|
|
|
I: Integer;
|
2018-12-13 11:42:18 +00:00
|
|
|
begin
|
|
|
|
InternalCalcImgSize;
|
2018-12-14 10:54:15 +00:00
|
|
|
MaxHeight:=FDefImgHeight;
|
2019-01-05 10:47:14 +00:00
|
|
|
if HandleAllocated then
|
|
|
|
begin
|
|
|
|
DC := GetDC(Handle);
|
|
|
|
try
|
|
|
|
OldFont := SelectObject(DC, HGDIOBJ(Font.Reference.Handle));
|
|
|
|
Flags := DT_CALCRECT or DT_SINGLELINE or DT_NOPREFIX;
|
2018-12-13 11:42:18 +00:00
|
|
|
|
|
|
|
R := Rect(0, 0, 10000, 10000);
|
2019-01-05 10:47:14 +00:00
|
|
|
S:='Wg';
|
|
|
|
DrawText(DC, PChar(S), Length(S), R, Flags);
|
|
|
|
FTH:=R.Bottom - R.Top;
|
2018-12-13 11:42:18 +00:00
|
|
|
|
2019-01-05 10:47:14 +00:00
|
|
|
|
|
|
|
for I:=0 to FVisibleItems.Count-1 do
|
2018-12-13 11:42:18 +00:00
|
|
|
begin
|
2019-01-05 10:47:14 +00:00
|
|
|
TI:=TToolbarItem(FVisibleItems[i]);
|
|
|
|
TI.FTextWidth := 0;
|
|
|
|
R := Rect(0, 0, 10000, 10000);
|
|
|
|
if Assigned(TI.FButton) then
|
|
|
|
begin
|
|
|
|
S:=TI.FButton.Caption;
|
|
|
|
if S<>'' then
|
|
|
|
begin
|
|
|
|
DrawText(DC, PChar(S), Length(S), R, Flags);
|
|
|
|
TI.FTextWidth := R.Right - R.Left;
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
|
|
|
TI.FTextHeight := FTH;
|
2018-12-13 11:42:18 +00:00
|
|
|
TI.InternalCalcSize;
|
|
|
|
end;
|
2019-01-05 10:47:14 +00:00
|
|
|
|
|
|
|
SelectObject(DC, OldFont);
|
|
|
|
finally
|
|
|
|
ReleaseDC(Parent.Handle, DC);
|
2018-12-13 11:42:18 +00:00
|
|
|
end;
|
|
|
|
|
2019-01-05 10:47:14 +00:00
|
|
|
for I:=0 to FVisibleItems.Count-1 do
|
2018-12-13 11:42:18 +00:00
|
|
|
begin
|
2019-01-05 10:47:14 +00:00
|
|
|
TI:=TToolbarItem(FVisibleItems[i]);
|
|
|
|
if Assigned(TI.FButton) then
|
|
|
|
begin
|
|
|
|
//TI.InternalCalcSize;
|
|
|
|
MaxHeight:=Max(MaxHeight, TI.FIntHeight);
|
|
|
|
end;
|
2018-12-13 11:42:18 +00:00
|
|
|
end;
|
2019-01-05 10:47:14 +00:00
|
|
|
end;
|
2018-12-13 11:42:18 +00:00
|
|
|
|
|
|
|
for TI in FToolbarItems do
|
|
|
|
if Assigned(TI.FButton) then
|
|
|
|
TI.FIntHeight:=MaxHeight;
|
|
|
|
end;
|
|
|
|
|
2019-01-05 10:47:14 +00:00
|
|
|
procedure TToolPanel.UpdateVisibleItems;
|
|
|
|
var
|
|
|
|
P: TToolbarItem;
|
|
|
|
begin
|
|
|
|
FVisibleItems.Clear;
|
|
|
|
for P in Items do
|
|
|
|
if P.Visible then
|
|
|
|
FVisibleItems.Add(P);
|
|
|
|
end;
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure TToolPanel.Notification(AComponent: TComponent; Operation: TOperation);
|
|
|
|
var
|
2019-01-05 10:47:14 +00:00
|
|
|
P: TToolbarItem;
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
inherited Notification(AComponent, Operation);
|
|
|
|
if Operation = opRemove then
|
|
|
|
begin
|
|
|
|
if AComponent = FImageList then
|
|
|
|
SetImageList(nil)
|
|
|
|
else
|
2018-04-10 20:37:18 +00:00
|
|
|
if AComponent = FImageListSelected then
|
|
|
|
SetImageListSelected(nil)
|
|
|
|
else
|
2007-08-09 21:36:59 +00:00
|
|
|
if AComponent is TPopupMenu then
|
|
|
|
begin
|
2019-01-05 10:47:14 +00:00
|
|
|
for P in FToolbarItems do
|
|
|
|
if P.DropDownMenu = AComponent then
|
|
|
|
P.DropDownMenu:=nil;
|
2007-08-09 21:36:59 +00:00
|
|
|
end
|
|
|
|
else
|
|
|
|
if AComponent is TBasicAction then
|
|
|
|
begin
|
2019-01-05 10:47:14 +00:00
|
|
|
for P in FToolbarItems do
|
|
|
|
if P.Action = AComponent then
|
|
|
|
P.Action:=nil;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolPanel.SetCustomizing(AValue: boolean);
|
|
|
|
var
|
|
|
|
i:integer;
|
|
|
|
begin
|
|
|
|
for i:=0 to FToolbarItems.Count - 1 do
|
|
|
|
FToolbarItems[i].FButton.SetDesign(AValue, FToolbarItems[i]);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolPanel.MouseUp(Button: TMouseButton; Shift: TShiftState; X,
|
|
|
|
Y: Integer);
|
|
|
|
begin
|
|
|
|
inherited MouseUp(Button, Shift, X, Y);
|
|
|
|
if (Button = mbRight) and (ssCtrl in Shift) and (tpCustomizable in FOptions) then
|
|
|
|
Customize(HelpContext);
|
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
procedure TToolPanel.Loaded;
|
2007-08-10 22:15:51 +00:00
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
inherited Loaded;
|
|
|
|
SetCustomizing(false);
|
2019-01-05 10:47:14 +00:00
|
|
|
UpdateVisibleItems;
|
2007-08-10 22:15:51 +00:00
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
procedure TToolPanel.CalculatePreferredSize(var PreferredWidth,
|
|
|
|
PreferredHeight: integer; WithThemeSpace: Boolean);
|
|
|
|
begin
|
|
|
|
PreferredWidth:=Parent.ClientWidth;
|
|
|
|
InternalCalcButtonsSize(PreferredHeight);
|
|
|
|
inherited CalculatePreferredSize( PreferredWidth, PreferredHeight, WithThemeSpace);
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TToolPanel.DoAlignChildControls(TheAlign: TAlign; AControl: TControl;
|
|
|
|
AControlList: TFPList; var ARect: TRect): Boolean;
|
2008-11-06 08:36:09 +00:00
|
|
|
var
|
2018-12-13 11:42:18 +00:00
|
|
|
TI: TToolbarItem;
|
|
|
|
I, L: Integer;
|
2018-12-14 12:17:30 +00:00
|
|
|
S: String;
|
2008-11-06 08:36:09 +00:00
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
if TheAlign = alCustom then
|
2010-03-15 17:56:12 +00:00
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
Result:=true;
|
|
|
|
|
|
|
|
if FButtonAllign = tbaLeft then
|
|
|
|
begin
|
|
|
|
L:=BorderWidth;
|
2019-01-05 10:47:14 +00:00
|
|
|
|
|
|
|
for i:=0 to FVisibleItems.Count-1 do
|
2018-12-13 11:42:18 +00:00
|
|
|
begin
|
2019-01-05 10:47:14 +00:00
|
|
|
TI:=TToolbarItem(FVisibleItems[i]);
|
|
|
|
if Assigned(TI.FButton) then
|
2018-12-13 11:42:18 +00:00
|
|
|
begin
|
|
|
|
TI.FButton.SetBounds(L, FInternalSpacing, TI.FIntWidth, TI.FIntHeight);
|
|
|
|
L:=L + TI.FIntWidth;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
L:=ClientWidth - BorderWidth;
|
2019-01-05 10:47:14 +00:00
|
|
|
for i:=FVisibleItems.Count-1 downto 0 do
|
2018-12-13 11:42:18 +00:00
|
|
|
begin
|
2019-01-05 10:47:14 +00:00
|
|
|
TI:=TToolbarItem(FVisibleItems[i]);
|
|
|
|
if Assigned(TI.FButton) then
|
2018-12-13 11:42:18 +00:00
|
|
|
begin
|
|
|
|
L:=L - TI.FIntWidth;
|
|
|
|
TI.FButton.SetBounds(L, FInternalSpacing, TI.FIntWidth, TI.FIntHeight);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result:=inherited DoAlignChildControls(TheAlign, AControl, AControlList, ARect);
|
2008-11-06 08:36:09 +00:00
|
|
|
end;
|
|
|
|
|
2018-12-14 10:54:15 +00:00
|
|
|
procedure TToolPanel.GetPreferredSize(var PreferredWidth,
|
|
|
|
PreferredHeight: integer; Raw: boolean; WithThemeSpace: boolean);
|
|
|
|
begin
|
|
|
|
inherited GetPreferredSize(PreferredWidth, PreferredHeight, Raw, WithThemeSpace);
|
|
|
|
if PreferredHeight < FInternalDefButtonHeight then
|
|
|
|
PreferredHeight:=FInternalDefButtonHeight;
|
|
|
|
end;
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
constructor TToolPanel.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited Create(AOwner);
|
2019-01-05 10:47:14 +00:00
|
|
|
FVisibleItems:=TFPList.Create;
|
2007-09-01 11:39:17 +00:00
|
|
|
FArrowBmp:=CreateArrowBitmap;
|
2016-01-14 10:13:52 +00:00
|
|
|
FCustomizeShortCut:=false;
|
2018-12-13 11:42:18 +00:00
|
|
|
AutoSize:=true;
|
2010-04-23 16:32:38 +00:00
|
|
|
FButtonAllign:=tbaLeft;
|
2007-08-09 21:36:59 +00:00
|
|
|
FToolbarItems:=TToolbarItems.Create(Self);
|
2010-03-31 16:14:25 +00:00
|
|
|
if Assigned(AOwner) and not (csLoading in AOwner.ComponentState) then
|
|
|
|
Align:=alTop;
|
2007-08-09 21:36:59 +00:00
|
|
|
Height:=DefButtonHeight;
|
|
|
|
FPropertyStorageLink:=TPropertyStorageLink.Create;
|
|
|
|
FPropertyStorageLink.OnSave:=@OnIniSave;
|
|
|
|
FPropertyStorageLink.OnLoad:=@OnIniLoad;
|
|
|
|
FToolBarStyle:=tbsStandart;
|
|
|
|
BorderWidth:=4;
|
2010-03-15 17:56:12 +00:00
|
|
|
ControlStyle:=ControlStyle - [csSetCaption] + [csAcceptsControls];
|
2018-12-13 11:42:18 +00:00
|
|
|
FSpacing:=DefSpacing;
|
2007-08-09 21:36:59 +00:00
|
|
|
Caption:='';
|
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TToolPanel.Destroy;
|
|
|
|
begin
|
|
|
|
FreeAndNil(FToolbarItems);
|
|
|
|
FreeAndNil(FPropertyStorageLink);
|
2007-09-01 11:39:17 +00:00
|
|
|
FreeAndNil(FArrowBmp);
|
2019-01-05 10:47:14 +00:00
|
|
|
FreeAndNil(FVisibleItems);
|
2007-08-09 21:36:59 +00:00
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolPanel.Customize(HelpCtx: Longint);
|
2018-12-13 11:42:18 +00:00
|
|
|
var
|
|
|
|
FCustomizer: TToolPanelSetupForm;
|
|
|
|
begin
|
|
|
|
FCustomizer:=TToolPanelSetupForm.CreateSetupForm(Self);
|
|
|
|
try
|
|
|
|
FCustomizer.HelpContext:=HelpCtx;
|
|
|
|
SetCustomizing(true);
|
|
|
|
FCustomizer.ShowModal;
|
|
|
|
finally
|
|
|
|
SetCustomizing(false);
|
|
|
|
FCustomizer.Free;
|
|
|
|
end;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-15 17:56:12 +00:00
|
|
|
procedure TToolPanel.SetBounds(aLeft, aTop, aWidth, aHeight: integer);
|
2018-12-13 11:42:18 +00:00
|
|
|
var
|
|
|
|
FExternalImageWidth: Integer;
|
|
|
|
AImageResolution: TScaledImageListResolution;
|
2010-03-15 17:56:12 +00:00
|
|
|
begin
|
2010-03-22 19:48:23 +00:00
|
|
|
if not (csLoading in ComponentState) then
|
|
|
|
begin
|
|
|
|
if Assigned(FImageList) then
|
2018-12-13 11:42:18 +00:00
|
|
|
begin
|
|
|
|
{$IF LCL_FullVersion >= 1080000}
|
|
|
|
FExternalImageWidth:=0;
|
|
|
|
AImageResolution := FImageList.ResolutionForPPI[FExternalImageWidth, Font.PixelsPerInch, GetCanvasScaleFactor];
|
|
|
|
aHeight:=AImageResolution.Height+8 + Max(BorderWidth, 4) * 2
|
|
|
|
{$ELSE}
|
2014-07-18 05:03:51 +00:00
|
|
|
aHeight:=FImageList.Height+8 + Max(BorderWidth, 4) * 2
|
2018-12-13 11:42:18 +00:00
|
|
|
{$ENDIF}
|
|
|
|
end
|
2010-03-22 19:48:23 +00:00
|
|
|
else
|
2018-12-13 11:42:18 +00:00
|
|
|
aHeight:=FInternalDefButtonHeight + BorderWidth * 2;
|
2010-03-22 19:48:23 +00:00
|
|
|
end;
|
2018-12-14 10:54:15 +00:00
|
|
|
|
2010-03-15 17:56:12 +00:00
|
|
|
inherited SetBounds(aLeft, aTop, aWidth, aHeight);
|
|
|
|
end;
|
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
{ TToolbarItem }
|
|
|
|
|
|
|
|
procedure TToolbarItem.SetAction(const AValue: TBasicAction);
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) and (FButton.Action<>AValue) then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
FButton.Action:=AValue;
|
2018-12-13 11:42:18 +00:00
|
|
|
if not (csLoading in TToolbarItems(Collection).FToolPanel.ComponentState) then
|
|
|
|
TToolbarItems(Collection).FToolPanel.ReAlignToolBtn;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure TToolbarItem.SetButtonStyle(const AValue: TToolbarButtonStyle);
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) and (FButton.FToolbarButtonStyle<>AValue) then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
FButton.FToolbarButtonStyle:=AValue;
|
2018-12-13 11:42:18 +00:00
|
|
|
TToolbarItems(Collection).FToolPanel.ReAlignToolBtn;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolbarItem.SetDropDownMenu(const AValue: TPopupMenu);
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) and (FButton.FDropDownMenu<>AValue) then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
FButton.FDropDownMenu:=AValue;
|
|
|
|
FButton.Invalidate;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolbarItem.SetGroupIndex(const AValue: Integer);
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) and (FButton.GroupIndex <> AValue) then
|
|
|
|
begin
|
|
|
|
FButton.GroupIndex:=AValue;
|
|
|
|
FButton.Invalidate;
|
|
|
|
end;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
2018-12-14 12:17:30 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure TToolbarItem.SetLayout(const AValue: TButtonLayout);
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) and (FButton.Layout<>AValue) then
|
|
|
|
begin
|
|
|
|
FButton.Layout:=AValue;
|
|
|
|
TToolbarItems(Collection).FToolPanel.ReAlignToolBtn;
|
|
|
|
end;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
2018-12-14 12:17:30 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure TToolbarItem.SetShowCaption(const AValue: boolean);
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) and (FButton.ShowCaption<>AValue) then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
2009-06-22 17:58:57 +00:00
|
|
|
FButton.ShowCaption:=AValue;
|
2010-03-22 19:48:23 +00:00
|
|
|
if not (csLoading in TToolbarItems(Collection).FToolPanel.ComponentState) then
|
2018-12-13 11:42:18 +00:00
|
|
|
TToolbarItems(Collection).FToolPanel.ReAlignToolBtn;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolbarItem.SetTag(const AValue: Longint);
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) and (FButton.Tag<>AValue) then
|
|
|
|
FButton.Tag:=AValue;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
2018-12-14 12:17:30 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
function TToolbarItem.GetAction: TBasicAction;
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) then
|
|
|
|
Result:=FButton.Action
|
|
|
|
else
|
|
|
|
Result:=nil;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
2018-12-14 12:17:30 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
function TToolbarItem.GetButtonStyle: TToolbarButtonStyle;
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) then
|
|
|
|
Result:=FButton.FToolbarButtonStyle
|
|
|
|
else
|
|
|
|
Result:=tbrButton;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TToolbarItem.GetDropDownMenu: TPopupMenu;
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) then
|
|
|
|
Result:=FButton.FDropDownMenu
|
|
|
|
else
|
|
|
|
Result:=nil;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TToolbarItem.GetGroupIndex: Integer;
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) then
|
|
|
|
Result:=FButton.GroupIndex
|
|
|
|
else
|
|
|
|
Result:=0;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TToolbarItem.GetLayout: TButtonLayout;
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) then
|
|
|
|
Result:=FButton.Layout
|
|
|
|
else
|
|
|
|
Result:=blGlyphLeft;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TToolbarItem.GetShowCaption: boolean;
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) then
|
|
|
|
Result:=FButton.ShowCaption
|
|
|
|
else
|
|
|
|
Result:=false;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TToolbarItem.GetTag: Longint;
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) then
|
|
|
|
Result:=FButton.Tag
|
|
|
|
else
|
|
|
|
Result:=0;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
2018-12-14 12:17:30 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
function TToolbarItem.GetVisible: boolean;
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) then
|
|
|
|
Result:=FButton.Visible
|
|
|
|
else
|
|
|
|
Result:=false;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
2018-12-14 12:17:30 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
procedure TToolbarItem.SetVisible(const AValue: boolean);
|
|
|
|
begin
|
2018-12-14 12:17:30 +00:00
|
|
|
if Assigned(FButton) and (FButton.Visible<>AValue) then
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
FButton.Visible:=AValue;
|
|
|
|
FButton.Invalidate;
|
2019-01-05 10:47:14 +00:00
|
|
|
|
|
|
|
if csDesigning in TToolbarItems(Collection).FToolPanel.ComponentState then
|
|
|
|
begin
|
|
|
|
TToolbarItems(Collection).FToolPanel.UpdateVisibleItems;
|
|
|
|
TToolbarItems(Collection).FToolPanel.ReAlign;
|
|
|
|
end;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
end;
|
2018-12-13 11:42:18 +00:00
|
|
|
|
|
|
|
procedure TToolbarItem.InternalCalcSize;
|
|
|
|
begin
|
|
|
|
FIntHeight:=0;
|
|
|
|
if ButtonStyle in [tbrSeparator, tbrDivider] then
|
|
|
|
FIntWidth:=DefSeparatorWidth
|
|
|
|
else
|
|
|
|
begin
|
2019-01-05 10:47:14 +00:00
|
|
|
FIntWidth:=TToolbarItems(Collection).FToolPanel.FDefImgWidth + 2;
|
2018-12-13 11:42:18 +00:00
|
|
|
|
|
|
|
if ButtonStyle = tbrDropDownExtra then
|
|
|
|
FIntWidth:=FIntWidth + TToolbarItems(Collection).FToolPanel.FInternalDropDownExtraBtnWidth + TToolbarItems(Collection).FToolPanel.FInternalSpacing * 2;
|
|
|
|
|
|
|
|
if ShowCaption then
|
|
|
|
begin
|
|
|
|
if (Layout in [blGlyphLeft, blGlyphRight]) then
|
|
|
|
begin
|
|
|
|
FIntWidth:=FIntWidth + TToolbarItems(Collection).FToolPanel.FInternalSpacing * 2 + FTextWidth;
|
|
|
|
FIntHeight:=Max(FTextHeight + TToolbarItems(Collection).FToolPanel.FInternalSpacing * 2, TToolbarItems(Collection).FToolPanel.FDefImgHeight);
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
FIntWidth:=Max(FTextWidth + TToolbarItems(Collection).FToolPanel.FInternalSpacing * 2, TToolbarItems(Collection).FToolPanel.FDefImgWidth);
|
|
|
|
FIntHeight:=FIntHeight + TToolbarItems(Collection).FToolPanel.FInternalSpacing * 2 + FTextHeight;
|
|
|
|
end;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
FIntWidth:=FIntWidth + (*TToolbarItems(Collection).FToolPanel.FDefImgWidth + *) TToolbarItems(Collection).FToolPanel.FInternalSpacing * 2;
|
|
|
|
FIntHeight:=FIntHeight + (*TToolbarItems(Collection).FToolPanel.FDefImgHeight + *) TToolbarItems(Collection).FToolPanel.FInternalSpacing * 2;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2007-08-10 22:15:51 +00:00
|
|
|
|
2007-08-09 21:36:59 +00:00
|
|
|
function TToolbarItem.GetDisplayName: string;
|
|
|
|
begin
|
2007-09-01 11:39:17 +00:00
|
|
|
if ButtonStyle in [tbrSeparator, tbrDivider] then
|
2007-08-10 22:15:51 +00:00
|
|
|
begin
|
2007-09-01 11:39:17 +00:00
|
|
|
Result:='Separator'
|
2007-08-10 22:15:51 +00:00
|
|
|
end
|
|
|
|
else
|
2007-08-09 21:36:59 +00:00
|
|
|
if Assigned(Action) then
|
|
|
|
begin
|
|
|
|
if (Action is TCustomAction) then
|
|
|
|
Result:=TCustomAction(Action).Name + ' - ' +TCustomAction(Action).Caption
|
|
|
|
else
|
|
|
|
Result:=TCustomAction(Action).Name;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
Result:=inherited GetDisplayName;
|
|
|
|
end;
|
|
|
|
|
|
|
|
constructor TToolbarItem.Create(ACollection: TCollection);
|
2007-08-10 22:15:51 +00:00
|
|
|
var
|
2010-03-15 17:56:12 +00:00
|
|
|
TB:TToolPanel;
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
|
|
|
inherited Create(ACollection);
|
2018-12-14 12:17:30 +00:00
|
|
|
|
2010-03-15 17:56:12 +00:00
|
|
|
TB:=TToolbarItems(ACollection).FToolPanel;
|
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
TB.DisableAlign;
|
|
|
|
FButton:=TToolbarButton.Create(TB);
|
|
|
|
FButton.Parent:=TB;
|
2007-08-09 21:36:59 +00:00
|
|
|
FButton.Flat:=tpFlatBtns in TToolbarItems(ACollection).FToolPanel.Options;
|
|
|
|
FButton.Transparent:=tpTransparentBtns in TToolbarItems(ACollection).FToolPanel.Options;
|
2009-06-22 17:58:57 +00:00
|
|
|
FButton.ShowCaption:=false;
|
2018-12-13 11:42:18 +00:00
|
|
|
FButton.AutoSize:=true;
|
|
|
|
FButton.Align:=alCustom;
|
2007-08-09 21:36:59 +00:00
|
|
|
FButton.FOwnerItem:=Self;
|
2007-09-01 11:39:17 +00:00
|
|
|
FButton.FFullPush:=true;
|
2010-08-26 17:38:32 +00:00
|
|
|
FButton.ParentColor:=true;
|
2018-12-14 12:17:30 +00:00
|
|
|
|
2018-12-13 11:42:18 +00:00
|
|
|
TB.EnableAlign;
|
2007-08-09 21:36:59 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TToolbarItem.Destroy;
|
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
if Assigned(FButton) then
|
|
|
|
begin
|
|
|
|
FButton.FOwnerItem:=nil;
|
|
|
|
FreeAndNil(FButton);
|
|
|
|
end;
|
2007-08-09 21:36:59 +00:00
|
|
|
inherited Destroy;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ TToolbarButtonActionLink }
|
|
|
|
|
2009-11-23 18:07:35 +00:00
|
|
|
procedure TToolbarButtonActionLink.SetImageIndex(Value: Integer);
|
2007-08-09 21:36:59 +00:00
|
|
|
begin
|
2018-12-13 11:42:18 +00:00
|
|
|
inherited;
|
2007-08-09 21:36:59 +00:00
|
|
|
FClient.Invalidate;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TToolbarButtonActionLink.IsImageIndexLinked: Boolean;
|
|
|
|
begin
|
|
|
|
Result:=true;
|
|
|
|
end;
|
|
|
|
|
2007-08-10 22:15:51 +00:00
|
|
|
procedure TToolbarButtonActionLink.SetEnabled(Value: Boolean);
|
|
|
|
begin
|
|
|
|
if (FClient as TToolbarButton).FToolbarButtonStyle = tbrDropDown then
|
|
|
|
FClient.Enabled:=true
|
|
|
|
else
|
|
|
|
inherited SetEnabled(Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TToolbarButtonActionLink.SetCaption(const Value: string);
|
|
|
|
begin
|
|
|
|
inherited SetCaption(Value);
|
2018-12-13 11:42:18 +00:00
|
|
|
TToolbarButton(FClient).ToolPanel.ReAlignToolBtn
|
2007-08-10 22:15:51 +00:00
|
|
|
end;
|
|
|
|
|
2010-03-26 18:27:12 +00:00
|
|
|
initialization
|
|
|
|
RegisterPropertyToSkip(TToolbarButton, 'AutoSize', 'Old stile AutoSize in button', '');
|
|
|
|
RegisterPropertyToSkip(TToolbarItem, 'AutoSize', 'Old stile AutoSize in button', '');
|
|
|
|
RegisterPropertyToSkip(TToolPanel, 'AutoSize', 'Old stile AutoSize in button', '');
|
2018-12-13 11:42:18 +00:00
|
|
|
RegisterPropertyToSkip(TToolPanel, 'BtnWidth', 'Use scaling', '');
|
|
|
|
RegisterPropertyToSkip(TToolPanel, 'BtnHeight', 'Use scaling', '');
|
|
|
|
RegisterPropertyToSkip(TToolbarItem, 'Left', 'Use scaling', '');
|
|
|
|
RegisterPropertyToSkip(TToolbarItem, 'Height', 'Use scaling', '');
|
|
|
|
RegisterPropertyToSkip(TToolbarItem, 'Top', 'Use scaling', '');
|
|
|
|
RegisterPropertyToSkip(TToolbarItem, 'Width', 'Use scaling', '');
|
2007-08-09 21:36:59 +00:00
|
|
|
end.
|
|
|
|
|