Buttons: LoadGlyphFromResource, GetButtonImageIndex

This commit is contained in:
Ondrej Pokorny 2022-09-29 00:24:20 +02:00
parent 016d9d0534
commit dc374c1447

View File

@ -511,6 +511,7 @@ type
}
type
TGetDefaultBitBtnGlyph = function(Kind: TBitBtnKind; var Handled: Boolean): TBitmap;
TButtonImage = idButtonOk..idButtonNoToAll;
var
GetDefaultBitBtnGlyph: TGetDefaultBitBtnGlyph = nil;
@ -518,11 +519,13 @@ function GetLCLDefaultBtnGlyph(Kind: TBitBtnKind): TGraphic;
procedure LoadGlyphFromResourceName(AGlyph: TButtonGlyph; Instance: THandle; const AName: String);
procedure LoadGlyphFromLazarusResource(AGlyph: TButtonGlyph; const AName: String);
procedure LoadGlyphFromStock(AGlyph: TButtonGlyph; idButton: Integer);
procedure LoadGlyphFromResource(AGlyph: TButtonGlyph; idButton: Integer); // DPI-aware
// helper functions (search LCLType for idButton)
function GetButtonCaption(idButton: Integer): String;
function GetDefaultButtonIcon(idButton: Integer; ScalePercent: Integer = 100): TCustomBitmap;
function GetButtonIcon(idButton: Integer): TCustomBitmap;
function GetButtonImageIndex(idButton: TButtonImage): Integer; // DPI-aware: image index for the LCLGlyphs image list
function BidiAdjustButtonLayout(IsRightToLeft: Boolean; Layout: TButtonLayout): TButtonLayout;
function dbgs(Kind: TBitBtnKind): string; overload;
@ -540,7 +543,7 @@ const
idButtonNo, idButtonClose, idButtonAbort, idButtonRetry, idButtonIgnore,
idButtonAll, idButtonNoToAll, idButtonYesToAll);
BitBtnResNames: array[idButtonOk..idButtonNoToAll] of String =
BitBtnResNames: array[TButtonImage] of String =
(
{idButtonOk } 'btn_ok',
{idButtonCancel } 'btn_cancel',
@ -625,6 +628,15 @@ begin
end;
end;
procedure LoadGlyphFromResource(AGlyph: TButtonGlyph; idButton: Integer);
var
I: Integer;
begin
if not((Low(TButtonImage)<=idButton) and (idButton<=High(TButtonImage))) then
Exit;
AGlyph.LCLGlyphName := BitBtnResNames[idButton];
end;
function GetButtonCaption(idButton: Integer): String;
begin
case idButton of
@ -663,6 +675,11 @@ begin
Result := GetDefaultButtonIcon(idButton);
end;
function GetButtonImageIndex(idButton: TButtonImage): Integer;
begin
Result := LCLGlyphs.GetImageIndex(BitBtnResNames[idButton]);
end;
const
BtnBidiLayout: array[Boolean, TButtonLayout] of TButtonLayout =
(