LCL: Add properties Hot/Disabled/Pressed/SelectedImageIndex to TBitBtn and TSpeedButton. Issue #33299.

This commit is contained in:
wp_xyz 2021-12-26 18:06:53 +01:00
parent 3e7c23c53c
commit 6e2454530b
4 changed files with 64 additions and 27 deletions

View File

@ -77,7 +77,7 @@ type
FImageIndexes: array[TButtonState] of Integer; FImageIndexes: array[TButtonState] of Integer;
FImages: TCustomImageList; FImages: TCustomImageList;
FExternalImages: TCustomImageList; FExternalImages: TCustomImageList;
FExternalImageIndex: Integer; FExternalImageIndexes: array[TButtonState] of Integer;
FExternalImageWidth: Integer; FExternalImageWidth: Integer;
FLCLGlyphResourceName: string; FLCLGlyphResourceName: string;
FOriginal: TBitmap; FOriginal: TBitmap;
@ -86,10 +86,12 @@ type
FImagesCache: TImageListCache; FImagesCache: TImageListCache;
FTransparentMode: TGlyphTransparencyMode; // set by our owner to indicate that the glyphbitmap should be transparent FTransparentMode: TGlyphTransparencyMode; // set by our owner to indicate that the glyphbitmap should be transparent
FLCLGlyphName: string; FLCLGlyphName: string;
function GetExternalImageIndex(AState: TButtonState): Integer;
function GetHeight: Integer; function GetHeight: Integer;
function GetNumGlyphs: TNumGlyphs; function GetNumGlyphs: TNumGlyphs;
function GetWidth: Integer; function GetWidth: Integer;
procedure SetExternalImageIndex(const AExternalImageIndex: Integer); procedure ResetExternalImageIndexes;
procedure SetExternalImageIndex(AState: TButtonState; const AExternalImageIndex: Integer);
procedure SetExternalImages(const AExternalImages: TCustomImageList); procedure SetExternalImages(const AExternalImages: TCustomImageList);
procedure SetExternalImageWidth(const AExternalImageWidth: Integer); procedure SetExternalImageWidth(const AExternalImageWidth: Integer);
procedure SetGlyph(Value: TBitmap); procedure SetGlyph(Value: TBitmap);
@ -134,8 +136,12 @@ type
property Images: TCustomImageList read FImages; property Images: TCustomImageList read FImages;
property LCLGlyphName: string read FLCLGlyphName write SetLCLGlyphName; property LCLGlyphName: string read FLCLGlyphName write SetLCLGlyphName;
property ExternalImages: TCustomImageList read FExternalImages write SetExternalImages; property ExternalImages: TCustomImageList read FExternalImages write SetExternalImages;
property ExternalImageIndex: Integer read FExternalImageIndex write SetExternalImageIndex;
property ExternalImageWidth: Integer read FExternalImageWidth write SetExternalImageWidth; property ExternalImageWidth: Integer read FExternalImageWidth write SetExternalImageWidth;
property ExternalImageIndex: Integer index bsUp read GetExternalImageIndex write SetExternalImageIndex;
property ExternalHotImageIndex: Integer index bsHot read GetExternalImageIndex write SetExternalImageIndex;
property ExternalDisabledImageIndex: Integer index bsDisabled read GetExternalImageIndex write SetExternalImageIndex;
property ExternalPressedImageIndex: Integer index bsDown read GetExternalImageIndex write SetExternalImageIndex;
property ExternalSelectedImageIndex: Integer index bsExclusive read GetExternalImageIndex write SetExternalImageIndex;
property Width: Integer read GetWidth; property Width: Integer read GetWidth;
property Height: Integer read GetHeight; property Height: Integer read GetHeight;
property ShowMode: TGlyphShowMode read FShowMode write SetShowMode; property ShowMode: TGlyphShowMode read FShowMode write SetShowMode;
@ -178,8 +184,8 @@ type
function GetCaptionOfKind(AKind: TBitBtnKind): String; function GetCaptionOfKind(AKind: TBitBtnKind): String;
function GetImages: TCustomImageList; function GetImages: TCustomImageList;
procedure SetImages(const aImages: TCustomImageList); procedure SetImages(const aImages: TCustomImageList);
function GetImageIndex: TImageIndex; function GetImageIndex(AState: TButtonState): TImageIndex;
procedure SetImageIndex(const aImageIndex: TImageIndex); procedure SetImageIndex(AState: TButtonState; const AImageIndex: TImageIndex);
function GetImageWidth: Integer; function GetImageWidth: Integer;
procedure SetImageWidth(const aImageWidth: Integer); procedure SetImageWidth(const aImageWidth: Integer);
protected protected
@ -206,14 +212,18 @@ type
public public
property Caption stored IsCaptionStored; property Caption stored IsCaptionStored;
property DefaultCaption: Boolean read FDefaultCaption write SetDefaultCaption default False; property DefaultCaption: Boolean read FDefaultCaption write SetDefaultCaption default False;
property DisabledImageIndex: TImageIndex index bsDisabled read GetImageIndex write SetImageIndex default -1;
property Glyph: TBitmap read GetGlyph write SetGlyph stored IsGlyphStored; property Glyph: TBitmap read GetGlyph write SetGlyph stored IsGlyphStored;
property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1; property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1;
property HotImageIndex: TImageIndex index bsHot read GetImageIndex write SetImageIndex default -1;
property Images: TCustomImageList read GetImages write SetImages; property Images: TCustomImageList read GetImages write SetImages;
property ImageIndex: TImageIndex read GetImageIndex write SetImageIndex default -1; property ImageIndex: TImageIndex index bsUp read GetImageIndex write SetImageIndex default -1;
property ImageWidth: Integer read GetImageWidth write SetImageWidth default 0; property ImageWidth: Integer read GetImageWidth write SetImageWidth default 0;
property Kind: TBitBtnKind read FKind write SetKind default bkCustom; property Kind: TBitBtnKind read FKind write SetKind default bkCustom;
property Layout: TButtonLayout read FLayout write SetLayout default blGlyphLeft; property Layout: TButtonLayout read FLayout write SetLayout default blGlyphLeft;
property Margin: integer read FMargin write SetMargin default -1; property Margin: integer read FMargin write SetMargin default -1;
property PressedImageIndex: TImageIndex index bsDown read GetImageIndex write SetImageIndex default -1;
// property SelectedImageIndex: TImageIndex index bsExclusive read GetImageIndex write SetImageIndex default -1;
property Spacing: Integer read FSpacing write SetSpacing default 4; property Spacing: Integer read FSpacing write SetSpacing default 4;
property GlyphShowMode: TGlyphShowMode read GetGlyphShowMode write SetGlyphShowMode default gsmApplication; property GlyphShowMode: TGlyphShowMode read GetGlyphShowMode write SetGlyphShowMode default gsmApplication;
end; end;
@ -236,6 +246,7 @@ type
property Constraints; property Constraints;
property Default; property Default;
property DefaultCaption; property DefaultCaption;
property DisabledImageIndex;
property DragCursor; property DragCursor;
property DragKind; property DragKind;
property DragMode; property DragMode;
@ -243,6 +254,7 @@ type
property Font; property Font;
property Glyph; property Glyph;
property GlyphShowMode; property GlyphShowMode;
property HotImageIndex;
property Kind; property Kind;
property Layout; property Layout;
property Margin; property Margin;
@ -277,6 +289,8 @@ type
property ParentFont; property ParentFont;
property ParentShowHint; property ParentShowHint;
property PopupMenu; property PopupMenu;
property PressedImageIndex;
// property SelectedImageIndex;
property ShowHint; property ShowHint;
property Spacing; property Spacing;
property TabOrder; property TabOrder;
@ -339,8 +353,8 @@ type
procedure WMLButtonDBLCLK(Var Message: TLMLButtonDblClk); message LM_LBUTTONDBLCLK; procedure WMLButtonDBLCLK(Var Message: TLMLButtonDblClk); message LM_LBUTTONDBLCLK;
function GetImages: TCustomImageList; function GetImages: TCustomImageList;
procedure SetImages(const aImages: TCustomImageList); procedure SetImages(const aImages: TCustomImageList);
function GetImageIndex: TImageIndex; function GetImageIndex(AState: TButtonState): TImageIndex;
procedure SetImageIndex(const aImageIndex: TImageIndex); procedure SetImageIndex(AState: TButtonState; const AImageIndex: TImageIndex);
function GetImageWidth: Integer; function GetImageWidth: Integer;
procedure SetImageWidth(const aImageWidth: Integer); procedure SetImageWidth(const aImageWidth: Integer);
protected protected
@ -394,16 +408,20 @@ type
public public
property AllowAllUp: Boolean read FAllowAllUp write SetAllowAllUp default false; property AllowAllUp: Boolean read FAllowAllUp write SetAllowAllUp default false;
property Color default clBtnFace; property Color default clBtnFace;
property DisabledImageIndex: TImageIndex index bsDisabled read GetImageIndex write SetImageIndex default -1;
property Down: Boolean read FDown write SetDown default false; property Down: Boolean read FDown write SetDown default false;
property Flat: Boolean read FFlat write SetFlat default false; property Flat: Boolean read FFlat write SetFlat default false;
property Glyph: TBitmap read GetGlyph write SetGlyph stored IsGlyphStored; property Glyph: TBitmap read GetGlyph write SetGlyph stored IsGlyphStored;
property GroupIndex: Integer read FGroupIndex write SetGroupIndex default 0; property GroupIndex: Integer read FGroupIndex write SetGroupIndex default 0;
property HotImageIndex: TImageIndex index bsHot read GetImageIndex write SetImageIndex default -1;
property Images: TCustomImageList read GetImages write SetImages; property Images: TCustomImageList read GetImages write SetImages;
property ImageIndex: TImageIndex read GetImageIndex write SetImageIndex default -1; property ImageIndex: TImageIndex index bsUp read GetImageIndex write SetImageIndex default -1;
property ImageWidth: Integer read GetImageWidth write SetImageWidth default 0; property ImageWidth: Integer read GetImageWidth write SetImageWidth default 0;
property Layout: TButtonLayout read FLayout write SetLayout default blGlyphLeft; property Layout: TButtonLayout read FLayout write SetLayout default blGlyphLeft;
property Margin: integer read FMargin write SetMargin default -1; property Margin: integer read FMargin write SetMargin default -1;
property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1; property NumGlyphs: Integer read GetNumGlyphs write SetNumGlyphs default 1;
property PressedImageIndex: TImageIndex index bsDown read GetImageIndex write SetImageIndex default -1;
property SelectedImageIndex: TImageIndex index bsExclusive read GetImageIndex write SetImageIndex default -1;
property ShowAccelChar: boolean read FShowAccelChar write SetShowAccelChar default true; property ShowAccelChar: boolean read FShowAccelChar write SetShowAccelChar default true;
property ShowCaption: boolean read FShowCaption write SetShowCaption default true; property ShowCaption: boolean read FShowCaption write SetShowCaption default true;
property Spacing: integer read FSpacing write SetSpacing default 4; property Spacing: integer read FSpacing write SetSpacing default 4;
@ -425,6 +443,7 @@ type
property Constraints; property Constraints;
property Caption; property Caption;
property Color; property Color;
property DisabledImageIndex;
property Down; property Down;
property DragCursor; property DragCursor;
property DragKind; property DragKind;
@ -434,12 +453,15 @@ type
property Font; property Font;
property Glyph; property Glyph;
property GroupIndex; property GroupIndex;
property HotImageIndex;
property Images; property Images;
property ImageIndex; property ImageIndex;
property ImageWidth; property ImageWidth;
property Layout; property Layout;
property Margin; property Margin;
property NumGlyphs; property NumGlyphs;
property PressedImageIndex;
property SelectedImageIndex;
property Spacing; property Spacing;
property Transparent; property Transparent;
property Visible; property Visible;

View File

@ -107,9 +107,9 @@ begin
Result := FButtonGlyph.ShowMode; Result := FButtonGlyph.ShowMode;
end; end;
function TCustomBitBtn.GetImageIndex: TImageIndex; function TCustomBitBtn.GetImageIndex(AState: TButtonState): TImageIndex;
begin begin
Result := FButtonGlyph.ExternalImageIndex; Result := FButtonGlyph.FExternalImageIndexes[AState];
end; end;
function TCustomBitBtn.GetImages: TCustomImageList; function TCustomBitBtn.GetImages: TCustomImageList;
@ -156,9 +156,10 @@ begin
FButtonGlyph.ShowMode := AValue; FButtonGlyph.ShowMode := AValue;
end; end;
procedure TCustomBitBtn.SetImageIndex(const aImageIndex: TImageIndex); procedure TCustomBitBtn.SetImageIndex(AState: TButtonState;
const AImageIndex: TImageIndex);
begin begin
FButtonGlyph.ExternalImageIndex := aImageIndex; FButtonGlyph.SetExternalImageIndex(AState, AImageIndex);
end; end;
procedure TCustomBitBtn.SetImages(const aImages: TCustomImageList); procedure TCustomBitBtn.SetImages(const aImages: TCustomImageList);

View File

@ -67,7 +67,7 @@ begin
FOriginal := TGlyphBitmap.Create(Self); FOriginal := TGlyphBitmap.Create(Self);
FOriginal.OnChange := @GlyphChanged; FOriginal.OnChange := @GlyphChanged;
FNumGlyphs := Low(TNumGlyphs); FNumGlyphs := Low(TNumGlyphs);
FExternalImageIndex := -1; ResetExternalImageIndexes;
end; end;
{------------------------------------------------------------------------------ {------------------------------------------------------------------------------
@ -108,7 +108,9 @@ begin
if Assigned(FExternalImages) and CanShow then if Assigned(FExternalImages) and CanShow then
begin begin
AImages := FExternalImages; AImages := FExternalImages;
AIndex := FExternalImageIndex; AIndex := FExternalImageIndexes[State];
if (State <> bsUp) and (AIndex = -1) then
AIndex := FExternalImageIndexes[bsUp];
AEffect := CEffects[AUseAutoEffects > 0, State]; AEffect := CEffects[AUseAutoEffects > 0, State];
AImageResolution := AImages.ResolutionForPPI[FExternalImageWidth, APPI, ACanvasScaleFactor]; AImageResolution := AImages.ResolutionForPPI[FExternalImageWidth, APPI, ACanvasScaleFactor];
end else end else
@ -173,7 +175,7 @@ begin
else else
begin begin
FExternalImages := nil; FExternalImages := nil;
FExternalImageIndex := -1; ResetExternalImageIndexes;
end; end;
FOriginal.OnChange := nil; FOriginal.OnChange := nil;
FOriginal.Assign(Value); FOriginal.Assign(Value);
@ -203,7 +205,7 @@ begin
begin begin
ClearImages; ClearImages;
FExternalImages := nil; FExternalImages := nil;
FExternalImageIndex := -1; ResetExternalImageIndexes;
FExternalImageWidth := 0; FExternalImageWidth := 0;
end; end;
DoChange; DoChange;
@ -256,7 +258,7 @@ begin
FImagesCache := GetImageListCache; FImagesCache := GetImageListCache;
FImagesCache.RegisterListener(Self); FImagesCache.RegisterListener(Self);
FImagesCache.RegisterBitmap(Self, FOriginal, NumGlyphs); FImagesCache.RegisterBitmap(Self, FOriginal, NumGlyphs);
FExternalImageIndex := -1; //ResetExternalImageIndexes;
FExternalImages := nil; FExternalImages := nil;
ClearLCLGlyph; ClearLCLGlyph;
end; end;
@ -300,16 +302,27 @@ begin
Result := Draw(Canvas, Client, Offset, State, Transparent, BiDiFlags, 96, 1); Result := Draw(Canvas, Client, Offset, State, Transparent, BiDiFlags, 96, 1);
end; end;
function TButtonGlyph.GetExternalImageIndex(AState: TButtonState): Integer;
begin
Result := FExternalImageIndexes[AState];
end;
procedure TButtonGlyph.Refresh; procedure TButtonGlyph.Refresh;
begin begin
GlyphChanged(FOriginal); GlyphChanged(FOriginal);
end; end;
procedure TButtonGlyph.SetExternalImageIndex(const AExternalImageIndex: Integer); procedure TButtonGlyph.ResetExternalImageIndexes;
begin begin
if FExternalImageIndex = AExternalImageIndex then Exit; FillChar(FExternalImageIndexes, SizeOf(FExternalImageIndexes), $FF);
FExternalImageIndex := AExternalImageIndex; end;
if FExternalImageIndex>=0 then
procedure TButtonGlyph.SetExternalImageIndex(AState: TButtonState;
const AExternalImageIndex: Integer);
begin
if FExternalImageIndexes[AState] = AExternalImageIndex then Exit;
FExternalImageIndexes[AState] := AExternalImageIndex;
if FExternalImageIndexes[AState] >= 0 then
ClearLCLGlyph; ClearLCLGlyph;
DoChange; DoChange;
end; end;
@ -418,7 +431,7 @@ begin
Result := Result :=
((FImages <> nil) and (FImageIndexes[Low(TButtonState)]>=0)) ((FImages <> nil) and (FImageIndexes[Low(TButtonState)]>=0))
or (FLCLGlyphResourceName <> '') or (FLCLGlyphResourceName <> '')
or ((FExternalImages <> nil) and (FExternalImageIndex > -1)); or ((FExternalImages <> nil) and (ExternalImageIndex > -1));
end; end;
procedure TButtonGlyph.CacheSetImageIndex(AIndex, AImageIndex: Integer); procedure TButtonGlyph.CacheSetImageIndex(AIndex, AImageIndex: Integer);

View File

@ -211,9 +211,10 @@ begin
end; end;
end; end;
procedure TCustomSpeedButton.SetImageIndex(const aImageIndex: TImageIndex); procedure TCustomSpeedButton.SetImageIndex(AState: TButtonState;
const AImageIndex: TImageIndex);
begin begin
FGlyph.ExternalImageIndex := aImageIndex; FGlyph.SetExternalImageIndex(AState, AImageIndex);
end; end;
procedure TCustomSpeedButton.SetImages(const aImages: TCustomImageList); procedure TCustomSpeedButton.SetImages(const aImages: TCustomImageList);
@ -1077,9 +1078,9 @@ begin
Result.CY := AImageRes.Height; Result.CY := AImageRes.Height;
end; end;
function TCustomSpeedButton.GetImageIndex: TImageIndex; function TCustomSpeedButton.GetImageIndex(AState: TButtonState): TImageIndex;
begin begin
Result := FGlyph.ExternalImageIndex; Result := FGlyph.FExternalImageIndexes[AState];
end; end;
function TCustomSpeedButton.GetImages: TCustomImageList; function TCustomSpeedButton.GetImages: TCustomImageList;