mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 06:09:14 +02:00
added property sorting, hiding, showing only, aliasing for TTIGrid
git-svn-id: trunk@6542 -
This commit is contained in:
parent
4da758ff04
commit
c126bfd858
@ -16,6 +16,14 @@
|
|||||||
Provides LCL controls that access lists of properties of TPersistent objects
|
Provides LCL controls that access lists of properties of TPersistent objects
|
||||||
via RTTI
|
via RTTI
|
||||||
- the FreePascal Run Time Type Information.
|
- the FreePascal Run Time Type Information.
|
||||||
|
|
||||||
|
ToDo:
|
||||||
|
- better keyboard navigation
|
||||||
|
- add option: showing buttons for paDialog properties
|
||||||
|
- property editor for 'ListObject'
|
||||||
|
- persistent selected cell after rebuild
|
||||||
|
- moving objects
|
||||||
|
- adding, deleting objects
|
||||||
}
|
}
|
||||||
unit RTTIGrids;
|
unit RTTIGrids;
|
||||||
|
|
||||||
@ -72,25 +80,6 @@ type
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
TTIListDirection = (tldObjectsAsRows, tldObjectsAsColumns);
|
|
||||||
TTIGridState = (
|
|
||||||
tgsRebuildTIListNeeded,
|
|
||||||
tgsDefaultDrawing // set during default drawing
|
|
||||||
);
|
|
||||||
TTIGridStates = set of TTIGridState;
|
|
||||||
TTIGridCellType = (
|
|
||||||
tgctNone, // out or undefined
|
|
||||||
tgctValue, // a normal property cell
|
|
||||||
tgctPropName, // header cell for property name
|
|
||||||
tgctPropNameAlt,// header cell for alternative prop name (e.g. FixedRows>1)
|
|
||||||
tgctObjectName, // header cell for object name
|
|
||||||
tgctObjectNameAlt,// header cell for alternative obj name (e.g. FixedCols>1)
|
|
||||||
tgctCorner // corner cell left, top of grid
|
|
||||||
);
|
|
||||||
TTIGridOption = (
|
|
||||||
tgoStartIndexAtOne // start shown object index at 1
|
|
||||||
);
|
|
||||||
TTIGridOptions = set of TTIGridOption;
|
|
||||||
TTICustomGrid = class;
|
TTICustomGrid = class;
|
||||||
|
|
||||||
{ TTIGridProperty }
|
{ TTIGridProperty }
|
||||||
@ -108,8 +97,10 @@ type
|
|||||||
public
|
public
|
||||||
constructor Create(TheGrid: TTICustomGrid; TheEditor: TPropertyEditor;
|
constructor Create(TheGrid: TTICustomGrid; TheEditor: TPropertyEditor;
|
||||||
TheIndex: integer);
|
TheIndex: integer);
|
||||||
|
destructor Destroy; override;
|
||||||
function PropInfo: PPropInfo;
|
function PropInfo: PPropInfo;
|
||||||
function GetEditorControl: TWinControl;
|
function GetEditorControl: TWinControl;
|
||||||
|
function PropName: string;
|
||||||
public
|
public
|
||||||
property Editor: TPropertyEditor read FEditor;
|
property Editor: TPropertyEditor read FEditor;
|
||||||
property Grid: TTICustomGrid read FGrid;
|
property Grid: TTICustomGrid read FGrid;
|
||||||
@ -117,29 +108,79 @@ type
|
|||||||
property Title: string read FTitle write SetTitle;
|
property Title: string read FTitle write SetTitle;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
TTIListDirection = (tldObjectsAsRows, tldObjectsAsColumns);
|
||||||
|
TTIGridState = (
|
||||||
|
tgsRebuildTIListNeeded,
|
||||||
|
tgsRebuildingTIList,
|
||||||
|
tgsDefaultDrawing // set during default drawing
|
||||||
|
);
|
||||||
|
TTIGridStates = set of TTIGridState;
|
||||||
|
|
||||||
|
TTIGridCellType = (
|
||||||
|
tgctNone, // out or undefined
|
||||||
|
tgctValue, // a normal property cell
|
||||||
|
tgctPropName, // header cell for property name
|
||||||
|
tgctPropNameAlt,// header cell for alternative prop name (e.g. FixedRows>1)
|
||||||
|
tgctObjectName, // header cell for object name
|
||||||
|
tgctObjectNameAlt,// header cell for alternative obj name (e.g. FixedCols>1)
|
||||||
|
tgctCorner // corner cell left, top of grid
|
||||||
|
);
|
||||||
|
TTIGridCellTypes = set of TTIGridCellType;
|
||||||
|
|
||||||
|
TTIGridOption = (
|
||||||
|
tgoStartIndexAtOne, // start shown object index at 1
|
||||||
|
tgoShowOnlyProperties // show only properties in ShowOnlyProperties
|
||||||
|
);
|
||||||
|
TTIGridOptions = set of TTIGridOption;
|
||||||
|
|
||||||
|
TTIGridGetObject = procedure(Sender: TTICustomGrid; Index: integer;
|
||||||
|
var TIObject: TPersistent) of object;
|
||||||
|
TTIGridGetObjectCount = procedure(Sender: TTICustomGrid;
|
||||||
|
ListObject: TObject;
|
||||||
|
var ObjCount: integer) of object;
|
||||||
|
TTIGridGetObjectName = procedure(TIObject: TPersistent;
|
||||||
|
var ObjName: string) of object;
|
||||||
|
TTIGridCreateCellEditor = procedure(GridProp: TTIGridProperty;
|
||||||
|
var NewEditorControl: TControl) of object;
|
||||||
|
TTIGridInitCellEditor = procedure(GridProp: TTIGridProperty;
|
||||||
|
TheEditorControl: TControl) of object;
|
||||||
|
|
||||||
{ TTICustomGrid }
|
{ TTICustomGrid }
|
||||||
|
|
||||||
TTICustomGrid = class(TCustomGrid)
|
TTICustomGrid = class(TCustomGrid)
|
||||||
private
|
private
|
||||||
|
FAliasPropertyNames: TAliasStrings;
|
||||||
FFilter: TTypeKinds;
|
FFilter: TTypeKinds;
|
||||||
|
FHideProperties: TStrings;
|
||||||
FListDirection: TTIListDirection;
|
FListDirection: TTIListDirection;
|
||||||
FListObject: TObject;
|
FListObject: TObject;
|
||||||
|
FOnCreateCellEditor: TTIGridCreateCellEditor;
|
||||||
|
FOnGetObject: TTIGridGetObject;
|
||||||
|
FOnGetObjectCount: TTIGridGetObjectCount;
|
||||||
|
FOnGetObjectName: TTIGridGetObjectName;
|
||||||
FOnHeaderClick: THdrEvent;
|
FOnHeaderClick: THdrEvent;
|
||||||
FOnHeaderSized: THdrEvent;
|
FOnHeaderSized: THdrEvent;
|
||||||
FHeaderPropHook: TPropertyEditorHook;
|
FHeaderPropHook: TPropertyEditorHook;
|
||||||
|
FOnInitCellEditor: TTIGridInitCellEditor;
|
||||||
|
FOnPropertiesCreated: TNotifyEvent;
|
||||||
|
FPropertyOrder: TStrings;
|
||||||
|
FShowOnlyProperties: TStrings;
|
||||||
FTIOptions: TTIGridOptions;
|
FTIOptions: TTIGridOptions;
|
||||||
FTIStates: TTIGridStates;
|
FTIStates: TTIGridStates;
|
||||||
FTIObjectCount: integer;
|
FTIObjectCount: integer;
|
||||||
FProperties: TList;
|
FProperties: TList;
|
||||||
function GetProperties(Index: integer): TTIGridProperty;
|
function GetProperties(Index: integer): TTIGridProperty;
|
||||||
function GetPropertyCount: integer;
|
function GetPropertyCount: integer;
|
||||||
|
procedure SetAliasPropertyNames(const AValue: TAliasStrings);
|
||||||
procedure SetFilter(const AValue: TTypeKinds);
|
procedure SetFilter(const AValue: TTypeKinds);
|
||||||
|
procedure SetHideProperties(const AValue: TStrings);
|
||||||
procedure SetListDirection(const AValue: TTIListDirection);
|
procedure SetListDirection(const AValue: TTIListDirection);
|
||||||
procedure SetListObject(const AValue: TObject);
|
procedure SetListObject(const AValue: TObject);
|
||||||
|
procedure SetPropertyOrder(const AValue: TStrings);
|
||||||
|
procedure SetShowOnlyProperties(const AValue: TStrings);
|
||||||
procedure SetTIOptions(const NewOptions: TTIGridOptions);
|
procedure SetTIOptions(const NewOptions: TTIGridOptions);
|
||||||
protected
|
protected
|
||||||
procedure LoadCollection;
|
|
||||||
procedure LoadTList;
|
|
||||||
procedure RebuildGridLayout; virtual;
|
procedure RebuildGridLayout; virtual;
|
||||||
procedure AddHeaderPropertyEditor(Prop: TPropertyEditor);
|
procedure AddHeaderPropertyEditor(Prop: TPropertyEditor);
|
||||||
procedure DrawCell(aCol, aRow: Integer; aRect: TRect;
|
procedure DrawCell(aCol, aRow: Integer; aRect: TRect;
|
||||||
@ -151,8 +192,9 @@ type
|
|||||||
var aMin,aMax,aPriority: Integer); override;
|
var aMin,aMax,aPriority: Integer); override;
|
||||||
procedure SelectEditor; override;
|
procedure SelectEditor; override;
|
||||||
procedure DoEditorControlKeyUp(Sender: TObject; var Key: Word;
|
procedure DoEditorControlKeyUp(Sender: TObject; var Key: Word;
|
||||||
Shift: TShiftState); virtual;
|
Shift: TShiftState); virtual;
|
||||||
procedure EditorHide; override;
|
procedure EditorHide; override;
|
||||||
|
procedure WriteCellText(aRect: TRect; const aText: string);
|
||||||
public
|
public
|
||||||
constructor Create(TheOwner: TComponent); override;
|
constructor Create(TheOwner: TComponent); override;
|
||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
@ -161,7 +203,7 @@ type
|
|||||||
procedure ClearProperties;
|
procedure ClearProperties;
|
||||||
procedure DefaultDrawCell(aCol, aRow: Integer; var aRect: TRect;
|
procedure DefaultDrawCell(aCol, aRow: Integer; var aRect: TRect;
|
||||||
aState: TGridDrawState); virtual;
|
aState: TGridDrawState); virtual;
|
||||||
procedure DrawObjectName(Index: integer; aRect: TRect;
|
procedure DrawObjectName(Index: integer; const aRect: TRect;
|
||||||
aState: TGridDrawState);
|
aState: TGridDrawState);
|
||||||
procedure GetCellEditor(aCol, aRow: integer;
|
procedure GetCellEditor(aCol, aRow: integer;
|
||||||
var PropEditor: TPropertyEditor;
|
var PropEditor: TPropertyEditor;
|
||||||
@ -174,16 +216,37 @@ type
|
|||||||
var ObjectIndex, PropertyIndex: integer;
|
var ObjectIndex, PropertyIndex: integer;
|
||||||
var CellType: TTIGridCellType);
|
var CellType: TTIGridCellType);
|
||||||
function GetCurrentGridProperty: TTIGridProperty;
|
function GetCurrentGridProperty: TTIGridProperty;
|
||||||
|
function IndexOfGridProperty(const PropName: string): integer;
|
||||||
|
function FindGridProperty(const PropName: string): TTIGridProperty;
|
||||||
|
procedure MoveProperty(FromID, ToID: integer);
|
||||||
public
|
public
|
||||||
|
property AliasPropertyNames: TAliasStrings read FAliasPropertyNames
|
||||||
|
write SetAliasPropertyNames;
|
||||||
property DefaultRowHeight default 20;
|
property DefaultRowHeight default 20;
|
||||||
property Filter: TTypeKinds read FFilter write SetFilter default AllTypeKinds;
|
property Filter: TTypeKinds read FFilter write SetFilter default AllTypeKinds;
|
||||||
|
property HideProperties: TStrings read FHideProperties
|
||||||
|
write SetHideProperties;
|
||||||
property ListDirection: TTIListDirection read FListDirection
|
property ListDirection: TTIListDirection read FListDirection
|
||||||
write SetListDirection default tldObjectsAsRows;
|
write SetListDirection default tldObjectsAsRows;
|
||||||
property ListObject: TObject read FListObject write SetListObject;
|
property ListObject: TObject read FListObject write SetListObject;
|
||||||
|
property OnCreateCellEditor: TTIGridCreateCellEditor
|
||||||
|
read FOnCreateCellEditor write FOnCreateCellEditor;
|
||||||
|
property OnGetObject: TTIGridGetObject read FOnGetObject write FOnGetObject;
|
||||||
|
property OnGetObjectCount: TTIGridGetObjectCount read FOnGetObjectCount
|
||||||
|
write FOnGetObjectCount;
|
||||||
|
property OnGetObjectName: TTIGridGetObjectName read FOnGetObjectName
|
||||||
|
write FOnGetObjectName;
|
||||||
property OnHeaderClick: THdrEvent read FOnHeaderClick write FOnHeaderClick;
|
property OnHeaderClick: THdrEvent read FOnHeaderClick write FOnHeaderClick;
|
||||||
property OnHeaderSized: THdrEvent read FOnHeaderSized write FOnHeaderSized;
|
property OnHeaderSized: THdrEvent read FOnHeaderSized write FOnHeaderSized;
|
||||||
|
property OnInitCellEditor: TTIGridInitCellEditor read FOnInitCellEditor
|
||||||
|
write FOnInitCellEditor;
|
||||||
|
property OnPropertiesCreated: TNotifyEvent read FOnPropertiesCreated
|
||||||
|
write FOnPropertiesCreated;
|
||||||
property Properties[Index: integer]: TTIGridProperty read GetProperties;
|
property Properties[Index: integer]: TTIGridProperty read GetProperties;
|
||||||
property PropertyCount: integer read GetPropertyCount;
|
property PropertyCount: integer read GetPropertyCount;
|
||||||
|
property PropertyOrder: TStrings read FPropertyOrder write SetPropertyOrder;
|
||||||
|
property ShowOnlyProperties: TStrings read FShowOnlyProperties
|
||||||
|
write SetShowOnlyProperties;
|
||||||
property TIObjectCount: integer read FTIObjectCount;
|
property TIObjectCount: integer read FTIObjectCount;
|
||||||
property TIOptions: TTIGridOptions read FTIOptions write SetTIOptions;
|
property TIOptions: TTIGridOptions read FTIOptions write SetTIOptions;
|
||||||
end;
|
end;
|
||||||
@ -193,6 +256,7 @@ type
|
|||||||
|
|
||||||
TTIGrid = class(TTICustomGrid)
|
TTIGrid = class(TTICustomGrid)
|
||||||
published
|
published
|
||||||
|
property AliasPropertyNames;
|
||||||
property Align;
|
property Align;
|
||||||
property Anchors;
|
property Anchors;
|
||||||
property AutoAdvance;
|
property AutoAdvance;
|
||||||
@ -210,13 +274,19 @@ type
|
|||||||
property FixedRows;
|
property FixedRows;
|
||||||
property Flat;
|
property Flat;
|
||||||
property Font;
|
property Font;
|
||||||
|
property HideProperties;
|
||||||
property ListDirection;
|
property ListDirection;
|
||||||
|
property OnCreateCellEditor;
|
||||||
property OnDblClick;
|
property OnDblClick;
|
||||||
property OnEditButtonClick;
|
property OnEditButtonClick;
|
||||||
property OnEnter;
|
property OnEnter;
|
||||||
property OnExit;
|
property OnExit;
|
||||||
|
property OnGetObject;
|
||||||
|
property OnGetObjectCount;
|
||||||
|
property OnGetObjectName;
|
||||||
property OnHeaderClick;
|
property OnHeaderClick;
|
||||||
property OnHeaderSized;
|
property OnHeaderSized;
|
||||||
|
property OnInitCellEditor;
|
||||||
property OnKeyDown;
|
property OnKeyDown;
|
||||||
property OnKeyPress;
|
property OnKeyPress;
|
||||||
property OnKeyUp;
|
property OnKeyUp;
|
||||||
@ -224,11 +294,14 @@ type
|
|||||||
property OnMouseMove;
|
property OnMouseMove;
|
||||||
property OnMouseUp;
|
property OnMouseUp;
|
||||||
property OnPrepareCanvas;
|
property OnPrepareCanvas;
|
||||||
|
property OnPropertiesCreated;
|
||||||
property Options;
|
property Options;
|
||||||
property ParentColor;
|
property ParentColor;
|
||||||
property ParentFont;
|
property ParentFont;
|
||||||
property PopupMenu;
|
property PopupMenu;
|
||||||
|
property PropertyOrder;
|
||||||
property ShowHint;
|
property ShowHint;
|
||||||
|
property ShowOnlyProperties;
|
||||||
property TabOrder;
|
property TabOrder;
|
||||||
property TabStop;
|
property TabStop;
|
||||||
property TIOptions;
|
property TIOptions;
|
||||||
@ -247,7 +320,7 @@ type
|
|||||||
property PropEditorClass: TPropertyEditorClass read FPropEditorClass
|
property PropEditorClass: TPropertyEditorClass read FPropEditorClass
|
||||||
write FPropEditorClass;
|
write FPropEditorClass;
|
||||||
property WinControlClass: TWinControlClass read FWinControlClass
|
property WinControlClass: TWinControlClass read FWinControlClass
|
||||||
write FWinControlClass;
|
write FWinControlClass;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
@ -335,6 +408,14 @@ begin
|
|||||||
Result:=FProperties.Count;
|
Result:=FProperties.Count;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTICustomGrid.SetAliasPropertyNames(const AValue: TAliasStrings);
|
||||||
|
begin
|
||||||
|
if FAliasPropertyNames=AValue then exit;
|
||||||
|
if FAliasPropertyNames.Equals(AValue) then exit;
|
||||||
|
FAliasPropertyNames.Assign(AValue);
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
function TTICustomGrid.GetProperties(Index: integer): TTIGridProperty;
|
function TTICustomGrid.GetProperties(Index: integer): TTIGridProperty;
|
||||||
begin
|
begin
|
||||||
Result:=TTIGridProperty(FProperties[Index]);
|
Result:=TTIGridProperty(FProperties[Index]);
|
||||||
@ -347,6 +428,14 @@ begin
|
|||||||
ReloadTIList;
|
ReloadTIList;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTICustomGrid.SetHideProperties(const AValue: TStrings);
|
||||||
|
begin
|
||||||
|
if FHideProperties=AValue then exit;
|
||||||
|
if FHideProperties.Equals(AValue) then exit;
|
||||||
|
FHideProperties.Assign(AValue);
|
||||||
|
ReloadTIList;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTICustomGrid.SetListObject(const AValue: TObject);
|
procedure TTICustomGrid.SetListObject(const AValue: TObject);
|
||||||
begin
|
begin
|
||||||
if FListObject=AValue then exit;
|
if FListObject=AValue then exit;
|
||||||
@ -354,6 +443,23 @@ begin
|
|||||||
ReloadTIList;
|
ReloadTIList;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTICustomGrid.SetPropertyOrder(const AValue: TStrings);
|
||||||
|
begin
|
||||||
|
if FPropertyOrder=AValue then exit;
|
||||||
|
if FPropertyOrder.Equals(AValue) then exit;
|
||||||
|
FPropertyOrder.Assign(AValue);
|
||||||
|
ReloadTIList;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTICustomGrid.SetShowOnlyProperties(const AValue: TStrings);
|
||||||
|
begin
|
||||||
|
if FShowOnlyProperties=AValue then exit;
|
||||||
|
if FShowOnlyProperties.Equals(AValue) then exit;
|
||||||
|
FShowOnlyProperties.Assign(AValue);
|
||||||
|
if tgoShowOnlyProperties in FTIOptions then
|
||||||
|
ReloadTIList;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure TTICustomGrid.SetTIOptions(const NewOptions: TTIGridOptions);
|
procedure TTICustomGrid.SetTIOptions(const NewOptions: TTIGridOptions);
|
||||||
var
|
var
|
||||||
ChangedOptions: TTIGridOptions;
|
ChangedOptions: TTIGridOptions;
|
||||||
@ -362,48 +468,48 @@ begin
|
|||||||
ChangedOptions:=(FTIOptions-NewOptions)+(NewOptions-FTIOptions);
|
ChangedOptions:=(FTIOptions-NewOptions)+(NewOptions-FTIOptions);
|
||||||
FTIOptions:=NewOptions;
|
FTIOptions:=NewOptions;
|
||||||
if tgoStartIndexAtOne in ChangedOptions then Invalidate;
|
if tgoStartIndexAtOne in ChangedOptions then Invalidate;
|
||||||
|
if tgoShowOnlyProperties in ChangedOptions then ReloadTIList;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTICustomGrid.ReloadTIList;
|
procedure TTICustomGrid.ReloadTIList;
|
||||||
begin
|
begin
|
||||||
|
if tgsRebuildingTIList in FTIStates then exit;
|
||||||
if ([csLoading,csDestroying]*ComponentState)<>[] then begin
|
if ([csLoading,csDestroying]*ComponentState)<>[] then begin
|
||||||
Include(FTIStates,tgsRebuildTIListNeeded);
|
Include(FTIStates,tgsRebuildTIListNeeded);
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
Exclude(FTIStates,tgsRebuildTIListNeeded);
|
Exclude(FTIStates,tgsRebuildTIListNeeded);
|
||||||
if FListObject is TCollection then begin
|
Include(FTIStates,tgsRebuildingTIList);
|
||||||
LoadCollection;
|
try
|
||||||
end else if FListObject is TList then begin
|
EditorHide;
|
||||||
LoadTList;
|
ClearProperties;
|
||||||
end else begin
|
FTIObjectCount:=0;
|
||||||
// ListObject is not valid
|
if Assigned(OnGetObjectCount) then
|
||||||
|
OnGetObjectCount(Self,ListObject,FTIObjectCount)
|
||||||
|
else if FListObject is TCollection then
|
||||||
|
FTIObjectCount:=TCollection(FListObject).Count
|
||||||
|
else if FListObject is TList then
|
||||||
|
FTIObjectCount:=TList(FListObject).Count
|
||||||
|
else begin
|
||||||
|
// ListObject is not valid
|
||||||
|
end;
|
||||||
|
RebuildGridLayout;
|
||||||
|
finally
|
||||||
|
Exclude(FTIStates,tgsRebuildingTIList);
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTICustomGrid.LoadCollection;
|
|
||||||
var
|
|
||||||
TheCollection: TCollection;
|
|
||||||
begin
|
|
||||||
TheCollection:=FListObject as TCollection;
|
|
||||||
FTIObjectCount:=TheCollection.Count;
|
|
||||||
RebuildGridLayout;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TTICustomGrid.LoadTList;
|
|
||||||
var
|
|
||||||
TheList: TList;
|
|
||||||
begin
|
|
||||||
TheList:=FListObject as TList;
|
|
||||||
FTIObjectCount:=TheList.Count;
|
|
||||||
RebuildGridLayout;
|
|
||||||
end;
|
|
||||||
|
|
||||||
procedure TTICustomGrid.RebuildGridLayout;
|
procedure TTICustomGrid.RebuildGridLayout;
|
||||||
var
|
var
|
||||||
CurItem: TPersistent;
|
CurItem: TPersistent;
|
||||||
HeaderLines: LongInt;
|
HeaderLines: LongInt;
|
||||||
PropCount: LongInt;
|
PropCount: LongInt;
|
||||||
|
i: Integer;
|
||||||
|
ToID: Integer;
|
||||||
|
FromID: integer;
|
||||||
begin
|
begin
|
||||||
|
ClearProperties;
|
||||||
|
// set column/row count for objects
|
||||||
if ListDirection=tldObjectsAsRows then begin
|
if ListDirection=tldObjectsAsRows then begin
|
||||||
HeaderLines:=FixedRows;
|
HeaderLines:=FixedRows;
|
||||||
RowCount:=HeaderLines+FTIObjectCount
|
RowCount:=HeaderLines+FTIObjectCount
|
||||||
@ -423,18 +529,38 @@ begin
|
|||||||
ClearProperties;
|
ClearProperties;
|
||||||
GetPersistentProperties(CurItem, FFilter, FHeaderPropHook,
|
GetPersistentProperties(CurItem, FFilter, FHeaderPropHook,
|
||||||
@AddHeaderPropertyEditor,nil);
|
@AddHeaderPropertyEditor,nil);
|
||||||
|
// reorder
|
||||||
|
ToID:=0;
|
||||||
|
for i:=0 to FPropertyOrder.Count-1 do begin
|
||||||
|
FromID:=IndexOfGridProperty(FPropertyOrder[i]);
|
||||||
|
if FromID>=0 then begin
|
||||||
|
MoveProperty(FromID,ToID);
|
||||||
|
inc(ToID);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// set column/row count for properties
|
||||||
PropCount:=PropertyCount;
|
PropCount:=PropertyCount;
|
||||||
if ListDirection=tldObjectsAsRows then begin
|
if ListDirection=tldObjectsAsRows then begin
|
||||||
ColCount:=FixedCols+PropCount;
|
ColCount:=FixedCols+PropCount;
|
||||||
end else begin
|
end else begin
|
||||||
RowCount:=FixedRows+PropCount;
|
RowCount:=FixedRows+PropCount;
|
||||||
end;
|
end;
|
||||||
|
if Assigned(OnPropertiesCreated) then OnPropertiesCreated(Self);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTICustomGrid.AddHeaderPropertyEditor(Prop: TPropertyEditor);
|
procedure TTICustomGrid.AddHeaderPropertyEditor(Prop: TPropertyEditor);
|
||||||
var
|
var
|
||||||
NewProperty: TTIGridProperty;
|
NewProperty: TTIGridProperty;
|
||||||
begin
|
begin
|
||||||
|
if (FHideProperties.IndexOf(Prop.GetPropInfo^.Name)>=0)
|
||||||
|
or ((tgoShowOnlyProperties in FTIOptions)
|
||||||
|
and (FShowOnlyProperties.IndexOf(Prop.GetPropInfo^.Name)<0))
|
||||||
|
then begin
|
||||||
|
// skip property
|
||||||
|
Prop.Free;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
NewProperty:=TTIGridProperty.Create(Self,Prop,FProperties.Count);
|
NewProperty:=TTIGridProperty.Create(Self,Prop,FProperties.Count);
|
||||||
FProperties.Add(NewProperty);
|
FProperties.Add(NewProperty);
|
||||||
end;
|
end;
|
||||||
@ -504,10 +630,10 @@ begin
|
|||||||
PropLink:=GetPropertyLinkOfComponent(NewEditor);
|
PropLink:=GetPropertyLinkOfComponent(NewEditor);
|
||||||
if PropLink<>nil then begin
|
if PropLink<>nil then begin
|
||||||
CurObject:=GetTIObject(ObjectIndex);
|
CurObject:=GetTIObject(ObjectIndex);
|
||||||
PropName:=CurProp.Editor.GetPropInfo^.Name;
|
PropName:=CurProp.PropName;
|
||||||
PropLink.SetObjectAndProperty(CurObject,PropName);
|
PropLink.SetObjectAndProperty(CurObject,PropName);
|
||||||
end;
|
end;
|
||||||
if (goEditing in Options) and Assigned(OnSelectEditor) then
|
if Assigned(OnSelectEditor) then
|
||||||
OnSelectEditor(Self,Col,Row,NewEditor);
|
OnSelectEditor(Self,Col,Row,NewEditor);
|
||||||
end;
|
end;
|
||||||
Editor:=NewEditor;
|
Editor:=NewEditor;
|
||||||
@ -581,6 +707,17 @@ begin
|
|||||||
inherited EditorHide;
|
inherited EditorHide;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TTICustomGrid.WriteCellText(aRect: TRect; const aText: string);
|
||||||
|
begin
|
||||||
|
if aText='' then exit;
|
||||||
|
case Canvas.TextStyle.Alignment of
|
||||||
|
Classes.taLeftJustify: Inc(aRect.Left, 3);
|
||||||
|
Classes.taRightJustify: Dec(aRect.Right, 3);
|
||||||
|
end;
|
||||||
|
Inc(aRect.Top, 2);
|
||||||
|
Canvas.TextRect(aRect,ARect.Left,ARect.Top,aText);
|
||||||
|
end;
|
||||||
|
|
||||||
constructor TTICustomGrid.Create(TheOwner: TComponent);
|
constructor TTICustomGrid.Create(TheOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(TheOwner);
|
inherited Create(TheOwner);
|
||||||
@ -592,6 +729,10 @@ begin
|
|||||||
tkQWord{,tkDynArray,tkInterfaceRaw}];
|
tkQWord{,tkDynArray,tkInterfaceRaw}];
|
||||||
FProperties:=TList.Create;
|
FProperties:=TList.Create;
|
||||||
FListDirection:=tldObjectsAsRows;
|
FListDirection:=tldObjectsAsRows;
|
||||||
|
FHideProperties:=TStringList.Create;
|
||||||
|
FPropertyOrder:=TStringList.Create;
|
||||||
|
FShowOnlyProperties:=TStringList.Create;
|
||||||
|
FAliasPropertyNames:=TAliasStrings.Create;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
destructor TTICustomGrid.Destroy;
|
destructor TTICustomGrid.Destroy;
|
||||||
@ -599,13 +740,18 @@ begin
|
|||||||
ClearProperties;
|
ClearProperties;
|
||||||
FreeThenNil(FProperties);
|
FreeThenNil(FProperties);
|
||||||
FreeThenNil(FHeaderPropHook);
|
FreeThenNil(FHeaderPropHook);
|
||||||
|
FreeThenNil(FHideProperties);
|
||||||
|
FreeThenNil(FPropertyOrder);
|
||||||
|
FreeThenNil(FShowOnlyProperties);
|
||||||
|
FreeThenNil(FAliasPropertyNames);
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTICustomGrid.Loaded;
|
procedure TTICustomGrid.Loaded;
|
||||||
begin
|
begin
|
||||||
inherited Loaded;
|
inherited Loaded;
|
||||||
ReloadTIList;
|
if tgsRebuildTIListNeeded in FTIStates then
|
||||||
|
ReloadTIList;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTICustomGrid.ClearProperties;
|
procedure TTICustomGrid.ClearProperties;
|
||||||
@ -613,7 +759,11 @@ var
|
|||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
if FProperties=nil then exit;
|
if FProperties=nil then exit;
|
||||||
for i:=0 to FProperties.Count-1 do TObject(FProperties[i]).Free;
|
for i:=0 to FProperties.Count-1 do begin
|
||||||
|
TObject(FProperties[i]).Free;
|
||||||
|
FProperties[i]:=nil;
|
||||||
|
end;
|
||||||
|
FProperties.Clear;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTICustomGrid.DefaultDrawCell(aCol, aRow: Integer; var aRect: TRect;
|
procedure TTICustomGrid.DefaultDrawCell(aCol, aRow: Integer; var aRect: TRect;
|
||||||
@ -625,6 +775,8 @@ var
|
|||||||
ObjectIndex: integer;
|
ObjectIndex: integer;
|
||||||
PropertyIndex: integer;
|
PropertyIndex: integer;
|
||||||
CellType: TTIGridCellType;
|
CellType: TTIGridCellType;
|
||||||
|
AliasPropName: String;
|
||||||
|
PropName: String;
|
||||||
begin
|
begin
|
||||||
OldDefaultDrawing:=tgsDefaultDrawing in FTIStates;
|
OldDefaultDrawing:=tgsDefaultDrawing in FTIStates;
|
||||||
Include(FTIStates,tgsDefaultDrawing);
|
Include(FTIStates,tgsDefaultDrawing);
|
||||||
@ -647,9 +799,16 @@ begin
|
|||||||
if PropEditor<>nil then begin
|
if PropEditor<>nil then begin
|
||||||
//debugln('TTICustomGrid.DefaultDrawCell B ',dbgsName(PropEditor),' ',PropEditor.GetName,' ',PropEditor.GetValue);
|
//debugln('TTICustomGrid.DefaultDrawCell B ',dbgsName(PropEditor),' ',PropEditor.GetName,' ',PropEditor.GetValue);
|
||||||
try
|
try
|
||||||
if gdFixed in aState then
|
if gdFixed in aState then begin
|
||||||
PropEditor.PropDrawName(Canvas,aRect,GridStateToPropEditState(aState))
|
PropName:=PropEditor.GetName;
|
||||||
else
|
AliasPropName:=AliasPropertyNames.ValueToAlias(PropName);
|
||||||
|
if AliasPropName=PropName then begin
|
||||||
|
PropEditor.PropDrawName(Canvas,aRect,
|
||||||
|
GridStateToPropEditState(aState));
|
||||||
|
end else begin
|
||||||
|
WriteCellText(aRect,AliasPropName);
|
||||||
|
end;
|
||||||
|
end else
|
||||||
PropEditor.PropDrawValue(Canvas,aRect,GridStateToPropEditState(aState));
|
PropEditor.PropDrawValue(Canvas,aRect,GridStateToPropEditState(aState));
|
||||||
finally
|
finally
|
||||||
if IndependentEditor then PropEditor.Free;
|
if IndependentEditor then PropEditor.Free;
|
||||||
@ -660,7 +819,7 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTICustomGrid.DrawObjectName(Index: integer; aRect: TRect;
|
procedure TTICustomGrid.DrawObjectName(Index: integer; const aRect: TRect;
|
||||||
aState: TGridDrawState);
|
aState: TGridDrawState);
|
||||||
|
|
||||||
function GetTIObjectName(ObjIndex: integer): string;
|
function GetTIObjectName(ObjIndex: integer): string;
|
||||||
@ -670,6 +829,10 @@ procedure TTICustomGrid.DrawObjectName(Index: integer; aRect: TRect;
|
|||||||
begin
|
begin
|
||||||
Result:='';
|
Result:='';
|
||||||
AnObject:=GetTIObject(ObjIndex);
|
AnObject:=GetTIObject(ObjIndex);
|
||||||
|
if Assigned(OnGetObjectName) then begin
|
||||||
|
OnGetObjectName(AnObject,Result);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
if AnObject is TComponent then
|
if AnObject is TComponent then
|
||||||
Result:=TComponent(AnObject).Name
|
Result:=TComponent(AnObject).Name
|
||||||
else if AnObject is TCollectionItem then begin
|
else if AnObject is TCollectionItem then begin
|
||||||
@ -686,25 +849,13 @@ procedure TTICustomGrid.DrawObjectName(Index: integer; aRect: TRect;
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure FixRectangle;
|
|
||||||
begin
|
|
||||||
case Canvas.TextStyle.Alignment of
|
|
||||||
Classes.taLeftJustify: Inc(aRect.Left, 3);
|
|
||||||
Classes.taRightJustify: Dec(aRect.Right, 3);
|
|
||||||
end;
|
|
||||||
Inc(aRect.Top, 2);
|
|
||||||
end;
|
|
||||||
|
|
||||||
var
|
var
|
||||||
ObjectName: String;
|
ObjectName: String;
|
||||||
begin
|
begin
|
||||||
if aState=[] then ;
|
if aState=[] then ;
|
||||||
if (Index<0) or (Index>=TIObjectCount) then exit;
|
if (Index<0) or (Index>=TIObjectCount) then exit;
|
||||||
ObjectName:=GetTIObjectName(Index);
|
ObjectName:=GetTIObjectName(Index);
|
||||||
if ObjectName<>'' then begin
|
WriteCellText(aRect,ObjectName);
|
||||||
FixRectangle;
|
|
||||||
Canvas.TextRect(aRect,ARect.Left,ARect.Top,ObjectName);
|
|
||||||
end;
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TTICustomGrid.GetCellEditor(aCol, aRow: integer;
|
procedure TTICustomGrid.GetCellEditor(aCol, aRow: integer;
|
||||||
@ -790,6 +941,15 @@ var
|
|||||||
begin
|
begin
|
||||||
Result:=nil;
|
Result:=nil;
|
||||||
if (Index<0) or (Index>=TIObjectCount) then exit;
|
if (Index<0) or (Index>=TIObjectCount) then exit;
|
||||||
|
|
||||||
|
// use event
|
||||||
|
if Assigned(OnGetObject) then begin
|
||||||
|
Result:=nil;
|
||||||
|
OnGetObject(Self,Index,Result);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// try standard lists: TCollection and TList
|
||||||
if ListObject is TCollection then begin
|
if ListObject is TCollection then begin
|
||||||
ACollection:=TCollection(ListObject);
|
ACollection:=TCollection(ListObject);
|
||||||
if csDesigning in ComponentState then begin
|
if csDesigning in ComponentState then begin
|
||||||
@ -881,6 +1041,36 @@ begin
|
|||||||
Result:=Properties[PropertyIndex];
|
Result:=Properties[PropertyIndex];
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TTICustomGrid.IndexOfGridProperty(const PropName: string
|
||||||
|
): integer;
|
||||||
|
begin
|
||||||
|
Result:=FProperties.Count-1;
|
||||||
|
while (Result>=0) and (CompareText(Properties[Result].PropName,PropName)<>0)
|
||||||
|
do dec(Result);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TTICustomGrid.FindGridProperty(const PropName: string
|
||||||
|
): TTIGridProperty;
|
||||||
|
var
|
||||||
|
i: integer;
|
||||||
|
begin
|
||||||
|
i:=IndexOfGridProperty(PropName);
|
||||||
|
if i>=0 then
|
||||||
|
Result:=Properties[i]
|
||||||
|
else
|
||||||
|
Result:=nil;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TTICustomGrid.MoveProperty(FromID, ToID: integer);
|
||||||
|
begin
|
||||||
|
if FromID=ToID then exit;
|
||||||
|
EditorHide;
|
||||||
|
FProperties.Move(FromID,ToID);
|
||||||
|
Properties[FromID].FIndex:=FromID;
|
||||||
|
Properties[ToID].FIndex:=ToID;
|
||||||
|
Invalidate;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TTIGridProperty }
|
{ TTIGridProperty }
|
||||||
|
|
||||||
procedure TTIGridProperty.EditorControlKeyUp(Sender: TObject; var Key: Word;
|
procedure TTIGridProperty.EditorControlKeyUp(Sender: TObject; var Key: Word;
|
||||||
@ -904,6 +1094,13 @@ begin
|
|||||||
FTitle:=TheEditor.GetName;
|
FTitle:=TheEditor.GetName;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
destructor TTIGridProperty.Destroy;
|
||||||
|
begin
|
||||||
|
FreeThenNil(FEditorControl);
|
||||||
|
FreeThenNil(FEditor);
|
||||||
|
inherited Destroy;
|
||||||
|
end;
|
||||||
|
|
||||||
function TTIGridProperty.PropInfo: PPropInfo;
|
function TTIGridProperty.PropInfo: PPropInfo;
|
||||||
begin
|
begin
|
||||||
Result:=Editor.GetPropInfo;
|
Result:=Editor.GetPropInfo;
|
||||||
@ -915,23 +1112,34 @@ var
|
|||||||
Attr: TPropertyAttributes;
|
Attr: TPropertyAttributes;
|
||||||
begin
|
begin
|
||||||
if FEditorControl=nil then begin
|
if FEditorControl=nil then begin
|
||||||
EditorClass:=FindTIGridControl(TPropertyEditorClass(Editor.ClassType));
|
if Assigned(Grid.OnCreateCellEditor) then
|
||||||
if EditorClass=nil then begin
|
Grid.OnCreateCellEditor(Self,FEditorControl);
|
||||||
Attr:=Editor.GetAttributes;
|
if FEditorControl=nil then begin
|
||||||
if paValueList in Attr then
|
EditorClass:=FindTIGridControl(TPropertyEditorClass(Editor.ClassType));
|
||||||
EditorClass:=TTIComboBox
|
if EditorClass=nil then begin
|
||||||
else if (paDialog in Attr) and (paReadOnly in Attr) then
|
Attr:=Editor.GetAttributes;
|
||||||
EditorClass:=TTIButton
|
if (paDialog in Attr) and (paReadOnly in Attr) then
|
||||||
else
|
EditorClass:=TTIButton
|
||||||
EditorClass:=TTIEdit;
|
else if (paValueList in Attr) then
|
||||||
|
EditorClass:=TTIComboBox
|
||||||
|
else
|
||||||
|
EditorClass:=TTIEdit;
|
||||||
|
end;
|
||||||
|
FEditorControl:=EditorClass.Create(FGrid);
|
||||||
end;
|
end;
|
||||||
FEditorControl:=EditorClass.Create(FGrid);
|
|
||||||
FEditorControl.OnKeyUp:=@EditorControlKeyUp;
|
FEditorControl.OnKeyUp:=@EditorControlKeyUp;
|
||||||
FEditorControl.AutoSize:=false;
|
FEditorControl.AutoSize:=false;
|
||||||
|
if Assigned(Grid.OnInitCellEditor) then
|
||||||
|
Grid.OnInitCellEditor(Self,FEditorControl);
|
||||||
end;
|
end;
|
||||||
Result:=FEditorControl;
|
Result:=FEditorControl;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TTIGridProperty.PropName: string;
|
||||||
|
begin
|
||||||
|
Result:=PropInfo^.Name;
|
||||||
|
end;
|
||||||
|
|
||||||
initialization
|
initialization
|
||||||
RegisteredTIGridControls:=nil;
|
RegisteredTIGridControls:=nil;
|
||||||
// property editor for TTICustomPropertyGrid.TIObject
|
// property editor for TTICustomPropertyGrid.TIObject
|
||||||
|
@ -4242,7 +4242,8 @@ end;
|
|||||||
|
|
||||||
procedure TCustomGrid.EditorHide;
|
procedure TCustomGrid.EditorHide;
|
||||||
begin
|
begin
|
||||||
if not FEditorHiding and (Editor<>nil) and Editor.HandleAllocated and Editor.Visible then
|
if not FEditorHiding and (Editor<>nil) and Editor.HandleAllocated
|
||||||
|
and Editor.Visible then
|
||||||
begin
|
begin
|
||||||
FEditorMode:=False;
|
FEditorMode:=False;
|
||||||
{$IfDef dbgFocus} DebugLn('EditorHide INIT FCol=',FCol,' FRow=',FRow);{$Endif}
|
{$IfDef dbgFocus} DebugLn('EditorHide INIT FCol=',FCol,' FRow=',FRow);{$Endif}
|
||||||
|
Loading…
Reference in New Issue
Block a user