LCL/ComboBoxEx: Use type TImageIndex for image index properties of TComboboxEx. Issue #33026, patch by Michal Gawrycki.

git-svn-id: trunk@62379 -
This commit is contained in:
wp 2019-12-11 21:43:21 +00:00
parent d25e7447c1
commit 9449a23949
3 changed files with 50 additions and 27 deletions

View File

@ -654,6 +654,10 @@ end;
{ TImageIndexPropertyEditor }
type
TOwnedCollectionHelper = class(TOwnedCollection)
end;
function TImageIndexPropertyEditor.GetImageList: TCustomImageList;
var
Persistent: TPersistent;
@ -663,8 +667,25 @@ var
begin
Result := nil;
Persistent := GetComponent(0);
if not (Persistent is TComponent) then
if (Persistent is TCollectionItem) and
(TCollectionItem(Persistent).Collection <> nil) and
(TCollectionItem(Persistent).Collection is TOwnedCollection) and
(TOwnedCollectionHelper(TCollectionItem(Persistent).Collection).Owner <> nil) and
(TOwnedCollectionHelper(TCollectionItem(Persistent).Collection).Owner is TComponent) then
begin
Component := TComponent(TOwnedCollectionHelper(TCollectionItem(Persistent).Collection).Owner);
PropInfo := TypInfo.GetPropInfo(Component, 'Images');
if PropInfo = nil then
Exit;
Obj := GetObjectProp(Component, PropInfo);
if Obj is TCustomImageList then
Exit(TCustomImageList(Obj));
Exit;
end
else
if not (Persistent is TComponent) then
Exit;
if Component is TMenuItem then
begin
@ -788,6 +809,8 @@ initialization
RegisterPropertyEditor(TypeInfo(AnsiString), TFont, 'Name', TFontNamePropertyEditor);
RegisterPropertyEditor(TypeInfo(TFontCharset), nil, 'CharSet', TFontCharsetPropertyEditor);
RegisterPropertyEditor(TypeInfo(TImageIndex), TPersistent, 'ImageIndex', TImageIndexPropertyEditor);
RegisterPropertyEditor(TypeInfo(TImageIndex), TPersistent, 'OverlayImageIndex', TImageIndexPropertyEditor);
RegisterPropertyEditor(TypeInfo(TImageIndex), TPersistent, 'SelectedImageIndex', TImageIndexPropertyEditor);
RegisterPropertyEditor(TypeInfo(TImageIndex), TGridColumnTitle, 'ImageIndex', TGridImageIndexPropertyEditor);
RegisterPropertyEditor(TypeInfo(TImageIndex), TCustomGrid, 'ImageIndexSortAsc', TGridImageIndexPropertyEditor);
RegisterPropertyEditor(TypeInfo(TImageIndex), TCustomGrid, 'ImageIndexSortDesc', TGridImageIndexPropertyEditor);

View File

@ -58,35 +58,35 @@ type
private
FCaption: TTranslateString;
FData: TCustomData;
FImageIndex: SmallInt;
FImageIndex: TImageIndex;
procedure SetCaption(const AValue: TTranslateString);
procedure SetImageIndex(AValue: SmallInt);
procedure SetImageIndex(AValue: TImageIndex);
public
property Data: TCustomData read FData write FData;
constructor Create(ACollection: TCollection); override;
published
property Caption: TTranslateString read FCaption write SetCaption;
property ImageIndex: SmallInt read FImageIndex write SetImageIndex default -1;
property ImageIndex: TImageIndex read FImageIndex write SetImageIndex default -1;
end;
{ TComboExItem }
TComboExItem = class(TListControlItem)
private
FIndent: SmallInt;
FOverlayImageIndex: SmallInt;
FSelectedImageIndex: SmallInt;
procedure SetIndent(AValue: SmallInt);
procedure SetOverlayImageIndex(AValue: SmallInt);
procedure SetSelectedImageIndex(AValue: SmallInt);
FIndent: Integer;
FOverlayImageIndex: TImageIndex;
FSelectedImageIndex: TImageIndex;
procedure SetIndent(AValue: Integer);
procedure SetOverlayImageIndex(AValue: TImageIndex);
procedure SetSelectedImageIndex(AValue: TImageIndex);
protected const
cDefCaption = 'ItemEx';
public
constructor Create(ACollection: TCollection); override;
destructor Destroy; override;
published
property Indent: SmallInt read FIndent write SetIndent default -1;
property OverlayImageIndex: SmallInt read FOverlayImageIndex write SetOverlayImageIndex default -1;
property SelectedImageIndex: SmallInt read FSelectedImageIndex write SetSelectedImageIndex default -1;
property Indent: Integer read FIndent write SetIndent default -1;
property OverlayImageIndex: TImageIndex read FOverlayImageIndex write SetOverlayImageIndex default -1;
property SelectedImageIndex: TImageIndex read FSelectedImageIndex write SetSelectedImageIndex default -1;
end;
{ TListControlItems }
@ -161,18 +161,18 @@ type
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function Add: Integer; overload;
procedure Add(const ACaption: string; AIndent: SmallInt = -1;
AImgIdx: SmallInt = -1; AOverlayImgIdx: SmallInt = -1;
ASelectedImgIdx: SmallInt = -1); overload;
procedure Add(const ACaption: string; AIndent: Integer = -1;
AImgIdx: TImageIndex = -1; AOverlayImgIdx: TImageIndex = -1;
ASelectedImgIdx: TImageIndex = -1); overload;
procedure AddItem(const Item: String; AnObject: TObject); override;
procedure AssignItemsEx(AItems: TStrings); overload;
procedure AssignItemsEx(AItemsEx: TComboExItems); overload;
procedure Clear; override;
procedure Delete(AIndex: Integer);
procedure DeleteSelected;
procedure Insert(AIndex: Integer; const ACaption: string; AIndent: SmallInt = -1;
AImgIdx: SmallInt = -1; AOverlayImgIdx: SmallInt = -1;
ASelectedImgIdx: SmallInt = -1);
procedure Insert(AIndex: Integer; const ACaption: string; AIndent: Integer = -1;
AImgIdx: TImageIndex = -1; AOverlayImgIdx: TImageIndex = -1;
ASelectedImgIdx: TImageIndex = -1);
property AutoCompleteOptions: TAutoCompleteOptions read FAutoCompleteOptions
write FAutoCompleteOptions default cDefAutoCompOpts;
property Images: TCustomImageList read FImages write SetImages;

View File

@ -27,7 +27,7 @@ begin
Changed(False);
end;
procedure TListControlItem.SetImageIndex(AValue: SmallInt);
procedure TListControlItem.SetImageIndex(AValue: TImageIndex);
begin
if FImageIndex=AValue then exit;
FImageIndex:=AValue;
@ -59,21 +59,21 @@ end;
{ TComboExItem.Setters }
procedure TComboExItem.SetIndent(AValue: SmallInt);
procedure TComboExItem.SetIndent(AValue: Integer);
begin
if FIndent=AValue then exit;
FIndent:=AValue;
Changed(False);
end;
procedure TComboExItem.SetOverlayImageIndex(AValue: SmallInt);
procedure TComboExItem.SetOverlayImageIndex(AValue: TImageIndex);
begin
if FOverlayImageIndex=AValue then exit;
FOverlayImageIndex:=AValue;
{ Changed(False); }
end;
procedure TComboExItem.SetSelectedImageIndex(AValue: SmallInt);
procedure TComboExItem.SetSelectedImageIndex(AValue: TImageIndex);
begin
if FSelectedImageIndex=AValue then exit;
FSelectedImageIndex:=AValue;
@ -287,8 +287,8 @@ begin
inherited Destroy;
end;
procedure TCustomComboBoxEx.Add(const ACaption: string; AIndent: SmallInt; AImgIdx: SmallInt;
AOverlayImgIdx: SmallInt; ASelectedImgIdx: SmallInt);
procedure TCustomComboBoxEx.Add(const ACaption: string; AIndent: Integer;
AImgIdx: TImageIndex; AOverlayImgIdx: TImageIndex; ASelectedImgIdx: TImageIndex);
begin
Insert(ItemsEx.Count, ACaption, AIndent, AImgIdx, AOverlayImgIdx, ASelectedImgIdx);
end;
@ -437,8 +437,8 @@ begin
FRightToLeft:=IsRightToLeft;
end;
procedure TCustomComboBoxEx.Insert(AIndex: Integer; const ACaption: string; AIndent: SmallInt = -1;
AImgIdx: SmallInt = -1; AOverlayImgIdx: SmallInt = -1; ASelectedImgIdx: SmallInt = -1);
procedure TCustomComboBoxEx.Insert(AIndex: Integer; const ACaption: string; AIndent: Integer = -1;
AImgIdx: TImageIndex = -1; AOverlayImgIdx: TImageIndex = -1; ASelectedImgIdx: TImageIndex = -1);
var aItem: TCollectionItem;
begin
aItem:=ItemsEx.Insert(AIndex);