LCL, components: TCustomEditButton: enable image list support, use LCLBtnGlyphs.

git-svn-id: trunk@57722 -
This commit is contained in:
ondrej 2018-04-26 09:59:30 +00:00
parent aab1ffcedf
commit 801f6efb1b
5 changed files with 133 additions and 144 deletions

View File

@ -18,7 +18,7 @@ interface
uses
Classes, TypInfo, SysUtils, LCLProc, Forms, Controls, LCLType, GraphType,
LazFileUtils, Graphics, Buttons, Menus, ExtCtrls, Dialogs,
LCLIntf, PropEdits, PropEditUtils, ImgList, Math,
LCLIntf, PropEdits, PropEditUtils, ImgList, EditBtn, Math,
GraphicPropEdit; // defines TGraphicPropertyEditorForm
type
@ -674,7 +674,8 @@ begin
begin
if not (
(Component is TCustomSpeedButton)
or (Component is TCustomBitBtn))
or (Component is TCustomBitBtn)
or (Component is TCustomEditButton))
then
Component := Component.GetParentComponent;
if Component = nil then

View File

@ -53,7 +53,7 @@ type
function ReturnKeyHandled: Boolean; override;
procedure SortAndFilter; override;
procedure ApplyFilterCore; override;
function GetDefaultGlyph: TBitmap; override;
function GetDefaultGlyphName: string; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@ -68,9 +68,6 @@ type
property FilteredListbox: TCustomListBox read fFilteredListbox write SetFilteredListbox;
end;
var
ListFilterGlyph: TBitmap;
implementation
{ TListBoxFilterEdit }
@ -133,9 +130,9 @@ begin
MoveTo(0, ASelect);
end;
function TListFilterEdit.GetDefaultGlyph: TBitmap;
function TListFilterEdit.GetDefaultGlyphName: string;
begin
Result := ListFilterGlyph;
Result := 'btnfiltercancel';
end;
procedure TListFilterEdit.SetFilteredListbox(const AValue: TCustomListBox);

View File

@ -68,7 +68,7 @@ type
function ReturnKeyHandled: Boolean; override;
procedure SortAndFilter; override;
procedure ApplyFilterCore; override;
function GetDefaultGlyph: TBitmap; override;
function GetDefaultGlyphName: string; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@ -82,9 +82,6 @@ type
property ByAllFields: Boolean read fByAllFields write fByAllFields default False;
end;
var
ListFilterGlyph: TBitmap;
implementation
{ TListViewDataItem }
@ -118,9 +115,9 @@ begin
inherited Destroy;
end;
function TListViewFilterEdit.GetDefaultGlyph: TBitmap;
function TListViewFilterEdit.GetDefaultGlyphName: string;
begin
Result := ListFilterGlyph;
Result := 'btnfiltercancel';
end;
function TListViewFilterEdit.GetLastSelectedIndex: Integer;

View File

@ -96,7 +96,7 @@ type
function ReturnKeyHandled: Boolean; override;
procedure SortAndFilter; override;
procedure ApplyFilterCore; override;
function GetDefaultGlyph: TBitmap; override;
function GetDefaultGlyphName: string; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@ -133,9 +133,6 @@ type
constructor Create(AFilename: string; aData: Pointer);
end;
var
TreeFilterGlyph: TBitmap;
implementation
{ TTreeFilterBranch }
@ -430,9 +427,9 @@ begin
inherited Destroy;
end;
function TTreeFilterEdit.GetDefaultGlyph: TBitmap;
function TTreeFilterEdit.GetDefaultGlyphName: string;
begin
Result := TreeFilterGlyph;
Result := 'btnfiltercancel';
end;
procedure TTreeFilterEdit.OnBeforeTreeDestroy(Sender: TObject);

View File

@ -33,7 +33,7 @@ uses
Classes, SysUtils, LCLProc, LResources, LCLStrConsts, Types, LCLType,
LMessages, Graphics, Controls, Forms, LazFileUtils, LazUTF8, Dialogs,
StdCtrls, Buttons, Calendar, ExtDlgs, GroupedEdit, CalendarPopup, MaskEdit,
Menus, StrUtils, DateUtils, TimePopup, CalcForm;
Menus, StrUtils, DateUtils, TimePopup, CalcForm, ImgList;
const
NullDate: TDateTime = 0;
@ -48,6 +48,11 @@ type
procedure DoExit; override;
end;
TEditSpeedButton = class(TSpeedButton)
protected
procedure GlyphChanged(Sender: TObject); override;
end;
{ TCustomEditButton }
TCustomEditButton = class(TCustomAbstractGroupedEdit)
@ -63,7 +68,6 @@ type
function GetGlyph: TBitmap;
function GetNumGlyps: Integer;
function GetEdit: TEbEdit;
function IsCustomGlyph : Boolean;
procedure SetFocusOnButtonClick(AValue: Boolean);
procedure SetOnButtonClick(AValue: TNotifyEvent);
@ -71,6 +75,12 @@ type
procedure SetFlat(AValue: Boolean);
procedure SetGlyph(AValue: TBitmap);
procedure SetNumGlyphs(AValue: Integer);
function GetImages: TCustomImageList;
procedure SetImages(const aImages: TCustomImageList);
function GetImageIndex: TImageIndex;
procedure SetImageIndex(const aImageIndex: TImageIndex);
function GetImageWidth: Integer;
procedure SetImageWidth(const aImageWidth: Integer);
protected
procedure ButtonClick; virtual;
procedure BuddyClick; override;
@ -78,13 +88,14 @@ type
function GetBuddyClassType: TControlClass; override;
class function GetControlClassDefaultSize: TSize; override;
function CalcButtonVisible: Boolean; virtual;
function GetDefaultGlyph: TBitmap; virtual;
function GetDefaultGlyphName: String; virtual;
function GetDefaultGlyphName: string; virtual;
procedure CalculatePreferredSize(var PreferredWidth,
PreferredHeight: integer;
WithThemeSpace: Boolean); override;
procedure CheckButtonVisible;
procedure LoadDefaultGlyph;
procedure GlyphChanged(Sender: TObject); virtual;
property Button: TSpeedButton read GetButton;
property ButtonCaption: TCaption read GetBuddyCaption write SetBuddyCaption;
@ -95,8 +106,11 @@ type
property Edit: TEbEdit read GetEdit;
property Flat: Boolean read FFlat write SetFlat default False;
property FocusOnButtonClick: Boolean read GetFocusOnButtonClick write SetFocusOnButtonClick default False;
property Glyph: TBitmap read GetGlyph write SetGlyph stored IsCustomGlyph;
property Glyph: TBitmap read GetGlyph write SetGlyph;
property NumGlyphs: Integer read GetNumGlyps write SetNumGlyphs;
property Images: TCustomImageList read GetImages write SetImages;
property ImageIndex: TImageIndex read GetImageIndex write SetImageIndex default -1;
property ImageWidth: Integer read GetImageWidth write SetImageWidth default 0;
property Spacing default 4;
property OnButtonClick: TNotifyEvent read GetOnButtonClick write SetOnButtonClick;
@ -140,6 +154,9 @@ type
property Glyph;
// property HideSelection;
property Hint;
property Images;
property ImageIndex;
property ImageWidth;
property Layout;
property MaxLength;
property NumGlyphs;
@ -233,7 +250,7 @@ type
procedure MoveHome(ASelect: Boolean = False); virtual; abstract;
procedure MoveEnd(ASelect: Boolean = False); virtual; abstract;
function ReturnKeyHandled: Boolean; virtual; abstract;
function GetDefaultGlyphName: String; override;
function GetDefaultGlyphName: string; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
@ -261,7 +278,6 @@ type
property ButtonWidth;
property Constraints;
property DirectInput;
property NumGlyphs;
property Flat;
property FocusOnButtonClick;
// Other properties
@ -278,6 +294,10 @@ type
property Enabled;
property Font;
property Glyph;
property NumGlyphs;
property Images;
property ImageIndex;
property ImageWidth;
property Layout;
property MaxLength;
property ParentBidiMode;
@ -340,8 +360,7 @@ type
FFileNameChangeLock: Integer;
procedure SetFileName(const AValue: String);
protected
function GetDefaultGlyph: TBitmap; override;
function GetDefaultGlyphName: String; override;
function GetDefaultGlyphName: string; override;
function CreateDialog(AKind: TDialogKind): TCommonDialog; virtual;
procedure SaveDialogResult(AKind: TDialogKind; D: TCommonDialog); virtual;
procedure ButtonClick; override;
@ -376,6 +395,9 @@ type
property DirectInput;
property Glyph;
property NumGlyphs;
property Images;
property ImageIndex;
property ImageWidth;
property Flat;
property FocusOnButtonClick;
// Other properties
@ -445,8 +467,7 @@ type
function GetDirectory: String;
procedure SetDirectory(const AValue: String);
protected
function GetDefaultGlyph: TBitmap; override;
function GetDefaultGlyphName: String; override;
function GetDefaultGlyphName: string; override;
function CreateDialog: TCommonDialog; virtual;
function GetDialogResult(D : TCommonDialog) : String; virtual;
procedure ButtonClick; override;
@ -472,6 +493,9 @@ type
property DirectInput;
property Glyph;
property NumGlyphs;
property Images;
property ImageIndex;
property ImageWidth;
property Flat;
property FocusOnButtonClick;
// Other properties
@ -556,8 +580,7 @@ type
procedure SetDateOrder(const AValue: TDateOrder);
function DateToText(Value: TDateTime): String;
protected
function GetDefaultGlyph: TBitmap; override;
function GetDefaultGlyphName: String; override;
function GetDefaultGlyphName: string; override;
procedure ButtonClick; override;
procedure EditDblClick; override;
procedure EditEditingDone; override;
@ -599,6 +622,9 @@ type
property DirectInput;
property Glyph;
property NumGlyphs;
property Images;
property ImageIndex;
property ImageWidth;
property DragMode;
property EchoMode;
property Enabled;
@ -667,8 +693,7 @@ type
procedure ParseInput;
function TryParseInput(AInput: String; out ParseResult: TDateTime): Boolean;
protected
function GetDefaultGlyph: TBitmap; override;
function GetDefaultGlyphName: String; override;
function GetDefaultGlyphName: string; override;
procedure ButtonClick; override;
procedure EditDblClick; override;
procedure EditEditingDone; override;
@ -701,6 +726,9 @@ type
property DirectInput;
property Glyph;
property NumGlyphs;
property Images;
property ImageIndex;
property ImageWidth;
property DragMode;
property EchoMode;
property Enabled;
@ -764,8 +792,7 @@ type
function TitleStored: boolean;
protected
FCalcDialog : TForm;
function GetDefaultGlyph: TBitmap; override;
function GetDefaultGlyphName: String; override;
function GetDefaultGlyphName: string; override;
procedure ButtonClick; override;
public
constructor Create(AOwner: TComponent); override;
@ -791,6 +818,9 @@ type
property DirectInput;
property Glyph;
property NumGlyphs;
property Images;
property ImageIndex;
property ImageWidth;
property Flat;
property FocusOnButtonClick;
// Other properties
@ -846,13 +876,6 @@ type
property TextHint;
end;
var
FileOpenGlyph: TBitmap;
DateGlyph: TBitmap;
CalcGlyph: TBitmap;
TimeGlyph: TBitmap;
const
ResBtnListFilter = 'btnfiltercancel';
ResBtnFileOpen = 'btnselfile';
@ -867,6 +890,14 @@ implementation
{$R lcl_edbtnimg.res}
{ TEditSpeedButton }
procedure TEditSpeedButton.GlyphChanged(Sender: TObject);
begin
inherited GlyphChanged(Sender);
if (Owner is TCustomEditButton) then TCustomEditButton(Owner).GlyphChanged(Sender);
end;
{ TEbEdit }
procedure TEbEdit.DoEnter;
@ -891,60 +922,6 @@ begin
PreferredWidth := 0;
end;
function TCustomEditButton.IsCustomGlyph: Boolean;
function _LoadRes: TBitmap;
var
ResName: String;
C : TCustomBitmap;
begin
ResName := GetDefaultGlyphName;
if ResName = '' then
Exit(nil);
Result := TBitmap.Create;
try
try
C := TPortableNetworkGraphic.Create;
C.LoadFromResourceName(hInstance, ResName);
Result.Assign(C); // the "Equals" did not work with ClassType different
// maybe it should compare the "RawImage" because it is independent of ClassType
finally
C.Free;
end;
except
Result.Free;
raise;
end;
end;
var
B, GlypRes, GlypActual: TBitmap;
begin
GlypActual := nil;
GlypRes := nil;
try
B := GetDefaultGlyph;
if B = nil then // if Default Glyph is nil, use the resource
begin
GlypRes := _LoadRes;
B := GlypRes;
end;
if B = nil then
Result := Glyph <> nil
else if Glyph = nil then
Result := True
else
begin
GlypActual := TBitmap.Create; // the "Equals" did not work with ClassType different.
GlypActual.Assign(Glyph);
Result := not GlypActual.Equals(B);
end;
finally
GlypRes.Free;
GlypActual.Free;
end;
end;
procedure TCustomEditButton.SetFocusOnButtonClick(AValue: Boolean);
begin
FocusOnBuddyClick := AValue;
@ -969,6 +946,27 @@ begin
Result := Button.Glyph;
end;
function TCustomEditButton.GetImageIndex: TImageIndex;
begin
if Button.Images=LCLBtnGlyphs then
Result := -1
else
Result := Button.ImageIndex;
end;
function TCustomEditButton.GetImages: TCustomImageList;
begin
if Button.Images=LCLBtnGlyphs then
Result := nil
else
Result := Button.Images;
end;
function TCustomEditButton.GetImageWidth: Integer;
begin
Result := Button.ImageWidth;
end;
function TCustomEditButton.GetButton: TSpeedButton;
begin
Result := TSpeedButton(Buddy);
@ -979,6 +977,25 @@ begin
Result := OnBuddyClick;
end;
procedure TCustomEditButton.GlyphChanged(Sender: TObject);
begin
if ((Button.Glyph=nil) or (Button.Glyph.Empty))
and (Button.Images=nil) then
LoadDefaultGlyph;
end;
procedure TCustomEditButton.LoadDefaultGlyph;
var
N: string;
begin
N := GetDefaultGlyphName;
if N <> '' then
begin
Images := LCLBtnGlyphs;
ImageIndex := LCLBtnGlyphs.GetImageIndex(N);
end;
end;
function TCustomEditButton.GetFocusOnButtonClick: Boolean;
begin
Result := FocusOnBuddyClick;
@ -1001,12 +1018,7 @@ begin
Result.CY := 23; //as TCustomEdit
end;
function TCustomEditButton.GetDefaultGlyph: TBitmap;
begin
Result := nil;
end;
function TCustomEditButton.GetDefaultGlyphName: String;
function TCustomEditButton.GetDefaultGlyphName: string;
begin
Result := '';
end;
@ -1054,9 +1066,26 @@ end;
procedure TCustomEditButton.SetGlyph(AValue: TBitmap);
begin
Button.Glyph := AValue;
if AValue=nil then
LoadDefaultGlyph;
Invalidate;
end;
procedure TCustomEditButton.SetImageIndex(const aImageIndex: TImageIndex);
begin
Button.ImageIndex := aImageIndex;
end;
procedure TCustomEditButton.SetImages(const aImages: TCustomImageList);
begin
Button.Images := aImages;
end;
procedure TCustomEditButton.SetImageWidth(const aImageWidth: Integer);
begin
Button.ImageWidth := aImageWidth;
end;
function TCustomEditButton.GetEditorClassType: TGEEditClass;
begin
Result := TEbEdit;
@ -1064,12 +1093,10 @@ end;
function TCustomEditButton.GetBuddyClassType: TControlClass;
begin
Result := TSpeedButton;
Result := TEditSpeedButton;
end;
constructor TCustomEditButton.Create(AOwner: TComponent);
var
B: TBitmap;
begin
inherited Create(AOwner);
FButtonOnlyWhenFocused := False;
@ -1077,12 +1104,7 @@ begin
SetInitialBounds(0, 0, GetControlClassDefaultSize.CX, GetControlClassDefaultSize.CY);
B := GetDefaultGlyph;
if B = nil
then
Button.LoadGlyphFromResourceName(hInstance, GetDefaultGlyphName)
else
Button.Glyph := B;
LoadDefaultGlyph;
Spacing := 4;
end;
@ -1261,7 +1283,7 @@ begin
end;
end;
function TCustomControlFilterEdit.GetDefaultGlyphName: String;
function TCustomControlFilterEdit.GetDefaultGlyphName: string;
begin
Result := ResBtnListFilter;
end;
@ -1378,12 +1400,7 @@ begin
if FocusOnButtonClick then FocusAndMaybeSelectAll;
end;
function TFileNameEdit.GetDefaultGlyph: TBitmap;
begin
Result := FileOpenGlyph;
end;
function TFileNameEdit.GetDefaultGlyphName: String;
function TFileNameEdit.GetDefaultGlyphName: string;
begin
Result := ResBtnFileOpen;
end;
@ -1469,12 +1486,7 @@ begin
if FocusOnButtonClick then FocusAndMaybeSelectAll;
end;
function TDirectoryEdit.GetDefaultGlyph: TBitmap;
begin
Result := FileOpenGlyph;
end;
function TDirectoryEdit.GetDefaultGlyphName: String;
function TDirectoryEdit.GetDefaultGlyphName: string;
begin
Result := ResBtnSelDir;
end;
@ -1537,12 +1549,7 @@ begin
Result := FFixedDateFormat;
end;
function TDateEdit.GetDefaultGlyph: TBitmap;
begin
Result := DateGlyph;
end;
function TDateEdit.GetDefaultGlyphName: String;
function TDateEdit.GetDefaultGlyphName: string;
begin
Result := ResBtnCalendar;
end;
@ -2121,12 +2128,7 @@ begin
SetTime(FTime);
end;
function TTimeEdit.GetDefaultGlyph: TBitmap;
begin
Result := TimeGlyph;
end;
function TTimeEdit.GetDefaultGlyphName: String;
function TTimeEdit.GetDefaultGlyphName: string;
begin
Result := ResBtnTime;
end;
@ -2168,12 +2170,7 @@ begin
Result:=StrToIntDef(Text,0);
end;
function TCalcEdit.GetDefaultGlyph: TBitmap;
begin
Result := CalcGlyph;
end;
function TCalcEdit.GetDefaultGlyphName: String;
function TCalcEdit.GetDefaultGlyphName: string;
begin
Result := ResBtnCalculator;
end;