mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-28 19:20:33 +02:00
LCL: buttons: make TLCLBtnGlyphs.GetImageIndex simpler. Use ResourceName/GlyphName as key.
git-svn-id: trunk@57721 -
This commit is contained in:
parent
685e707752
commit
aab1ffcedf
@ -334,7 +334,7 @@ type
|
||||
FState: TButtonState;
|
||||
class procedure WSRegisterClass; override;
|
||||
function GetNumGlyphs: Integer;
|
||||
procedure GlyphChanged(Sender: TObject);
|
||||
procedure GlyphChanged(Sender: TObject); virtual;
|
||||
function DialogChar(var Message: TLMKey): boolean; override;
|
||||
procedure CalculatePreferredSize(var PreferredWidth,
|
||||
PreferredHeight: integer; WithThemeSpace: Boolean); override;
|
||||
@ -450,16 +450,14 @@ type
|
||||
TLCLBtnGlyphs = class(TImageList)
|
||||
private type
|
||||
TEntryKey = record
|
||||
ParentClass: TClass;
|
||||
GlyphIndex: Integer;
|
||||
GlyphName: string;
|
||||
end;
|
||||
PEntryKey = ^TEntryKey;
|
||||
|
||||
TEntry = class
|
||||
public
|
||||
// key
|
||||
ParentClass: TClass; // the component class that registers a glyph
|
||||
GlyphIndex: Integer; // the unique glyph index within the component class
|
||||
GlyphName: string;
|
||||
|
||||
// value
|
||||
ImageIndex: Integer; // the image index in TLCLBtnGlyphs
|
||||
@ -473,8 +471,7 @@ type
|
||||
private
|
||||
FImageIndexes: TAvgLvlTree;
|
||||
public
|
||||
function GetImageIndex(AParentClass: TClass;
|
||||
AGlyphIndex: Integer; const AResourceName: string): Integer;
|
||||
function GetImageIndex(const AResourceName: string): Integer;
|
||||
|
||||
constructor Create(AOwner: TComponent); override;
|
||||
destructor Destroy; override;
|
||||
@ -545,9 +542,6 @@ const
|
||||
{idButtonNoToAll } 'btn_no'
|
||||
);
|
||||
|
||||
var
|
||||
GLCLBtnGlyphs: TLCLBtnGlyphs = nil;
|
||||
|
||||
implementation
|
||||
|
||||
{$R btn_icons.res}
|
||||
@ -555,6 +549,9 @@ implementation
|
||||
uses
|
||||
WSButtons;
|
||||
|
||||
var
|
||||
GLCLBtnGlyphs: TLCLBtnGlyphs = nil;
|
||||
|
||||
function GetLCLDefaultBtnGlyph(Kind: TBitBtnKind): TGraphic;
|
||||
begin
|
||||
Result := GetDefaultButtonIcon(BitBtnImages[Kind]);
|
||||
@ -710,9 +707,7 @@ var
|
||||
AItem1: TEntry absolute Item1;
|
||||
AItem2: TEntry absolute Item2;
|
||||
begin
|
||||
Result := CompareValue(PtrInt(AItem1.ParentClass), PtrInt(AItem2.ParentClass));
|
||||
if Result<>0 then Exit;
|
||||
Result := CompareValue(AItem1.GlyphIndex, AItem2.GlyphIndex);
|
||||
Result := CompareStr(AItem1.GlyphName, AItem2.GlyphName);
|
||||
end;
|
||||
|
||||
class function TLCLBtnGlyphs.TEntry.CompareKey(Key, Item: Pointer): Integer;
|
||||
@ -720,9 +715,7 @@ var
|
||||
AKey: PEntryKey absolute Key;
|
||||
AItem: TEntry absolute Item;
|
||||
begin
|
||||
Result := CompareValue(PtrInt(AKey^.ParentClass), PtrInt(AItem.ParentClass));
|
||||
if Result<>0 then Exit;
|
||||
Result := CompareValue(AKey^.GlyphIndex, AItem.GlyphIndex);
|
||||
Result := CompareStr(AKey^.GlyphName, AItem.GlyphName);
|
||||
end;
|
||||
|
||||
{ TLCLBtnGlyphs }
|
||||
@ -744,8 +737,7 @@ begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TLCLBtnGlyphs.GetImageIndex(AParentClass: TClass;
|
||||
AGlyphIndex: Integer; const AResourceName: string): Integer;
|
||||
function TLCLBtnGlyphs.GetImageIndex(const AResourceName: string): Integer;
|
||||
|
||||
function AddBtnImage(ResolutionWidth: Integer): Integer;
|
||||
var
|
||||
@ -771,8 +763,7 @@ var
|
||||
E: TEntry;
|
||||
I: Integer;
|
||||
begin
|
||||
K.ParentClass := AParentClass;
|
||||
K.GlyphIndex := AGlyphIndex;
|
||||
K.GlyphName := AResourceName;
|
||||
|
||||
ANode := FImageIndexes.FindKey(@K, @TEntry.CompareKey);
|
||||
if ANode<>nil then
|
||||
@ -780,8 +771,7 @@ begin
|
||||
else
|
||||
begin
|
||||
E := TEntry.Create;
|
||||
E.ParentClass := AParentClass;
|
||||
E.GlyphIndex := AGlyphIndex;
|
||||
E.GlyphName := AResourceName;
|
||||
E.ImageIndex := AddBtnImage(CResolutions[Low(CResolutions)]);
|
||||
for I := Low(CResolutions)+1 to High(CResolutions) do
|
||||
AddBtnImage(CResolutions[I]);
|
||||
|
@ -318,7 +318,7 @@ begin
|
||||
idButton := BitBtnImages[Kind];
|
||||
if (idButton >= Low(BitBtnResNames)) and (idButton <= High(BitBtnResNames))
|
||||
and (BitBtnResNames[idButton] <> '') then
|
||||
ImageIndex := LCLBtnGlyphs.GetImageIndex(TCustomBitBtn, idButton, BitBtnResNames[idButton])
|
||||
ImageIndex := LCLBtnGlyphs.GetImageIndex(BitBtnResNames[idButton])
|
||||
else
|
||||
ImageIndex := -1;
|
||||
GlyphValid := True;
|
||||
|
@ -287,8 +287,7 @@ begin
|
||||
end else
|
||||
begin //Load default images
|
||||
CurButton.Images := LCLBtnGlyphs;
|
||||
CurButton.ImageIndex := LCLBtnGlyphs.GetImageIndex(TDBCustomNavigator,
|
||||
Ord(CurButtonType), DBNavButtonResourceName[CurButtonType]);
|
||||
CurButton.ImageIndex := LCLBtnGlyphs.GetImageIndex(DBNavButtonResourceName[CurButtonType]);
|
||||
end;
|
||||
CurButton.Parent:=Self;
|
||||
CurButton.OnClick:=@ButtonClickHandler;
|
||||
@ -324,8 +323,7 @@ begin
|
||||
end else
|
||||
begin //Load default images
|
||||
CurFocusableButton.Images := LCLBtnGlyphs;
|
||||
CurFocusableButton.ImageIndex := LCLBtnGlyphs.GetImageIndex(TDBCustomNavigator,
|
||||
Ord(CurButtonType), DBNavButtonResourceName[CurButtonType]);
|
||||
CurFocusableButton.ImageIndex := LCLBtnGlyphs.GetImageIndex(DBNavButtonResourceName[CurButtonType]);
|
||||
end;
|
||||
CurFocusableButton.TabStop := True;
|
||||
CurFocusableButton.Parent:=Self;
|
||||
|
Loading…
Reference in New Issue
Block a user