implemented handler lists for property hooks

git-svn-id: trunk@4162 -
This commit is contained in:
mattias 2003-05-19 15:16:49 +00:00
parent 121a4e35e7
commit d9d414c8f3
2 changed files with 605 additions and 143 deletions

View File

@ -29,6 +29,8 @@ unit ObjectInspector;
{$MODE OBJFPC}{$H+} {$MODE OBJFPC}{$H+}
{$DEFINE DoNotCatchOIExceptions}
interface interface
uses uses
@ -688,15 +690,19 @@ begin
if NewValue<>CurRow.Editor.GetVisualValue then begin if NewValue<>CurRow.Editor.GetVisualValue then begin
Include(FStates,pgsApplyingValue); Include(FStates,pgsApplyingValue);
try try
{$IFNDEF DoNotCatchOIExceptions}
try try
{$ENDIF}
//writeln('TOIPropertyGrid.SetRowValue B ClassName=',CurRow.Editor.ClassName,' Visual=',CurRow.Editor.GetVisualValue,' NewValue=',NewValue,' AllEqual=',CurRow.Editor.AllEqual); //writeln('TOIPropertyGrid.SetRowValue B ClassName=',CurRow.Editor.ClassName,' Visual=',CurRow.Editor.GetVisualValue,' NewValue=',NewValue,' AllEqual=',CurRow.Editor.AllEqual);
CurRow.Editor.SetValue(NewValue); CurRow.Editor.SetValue(NewValue);
//writeln('TOIPropertyGrid.SetRowValue C ClassName=',CurRow.Editor.ClassName,' Visual=',CurRow.Editor.GetVisualValue,' NewValue=',NewValue,' AllEqual=',CurRow.Editor.AllEqual); //writeln('TOIPropertyGrid.SetRowValue C ClassName=',CurRow.Editor.ClassName,' Visual=',CurRow.Editor.GetVisualValue,' NewValue=',NewValue,' AllEqual=',CurRow.Editor.AllEqual);
{$IFNDEF DoNotCatchOIExceptions}
except except
on E: Exception do begin on E: Exception do begin
MessageDlg('Error',E.Message,mtError,[mbOk],0); MessageDlg('Error',E.Message,mtError,[mbOk],0);
end; end;
end; end;
{$ENDIF}
if (OldChangeStep<>FChangeStep) then begin if (OldChangeStep<>FChangeStep) then begin
// the selection has changed // the selection has changed
// => CurRow does not exist any more // => CurRow does not exist any more
@ -746,14 +752,18 @@ begin
OldChangeStep:=fChangeStep; OldChangeStep:=fChangeStep;
CurRow:=Rows[FItemIndex]; CurRow:=Rows[FItemIndex];
if paDialog in CurRow.Editor.GetAttributes then begin if paDialog in CurRow.Editor.GetAttributes then begin
{$IFNDEF DoNotCatchOIExceptions}
try try
{$ENDIF}
writeln('#################### TOIPropertyGrid.DoCallEdit for ',CurRow.Editor.ClassName); writeln('#################### TOIPropertyGrid.DoCallEdit for ',CurRow.Editor.ClassName);
CurRow.Editor.Edit; CurRow.Editor.Edit;
{$IFNDEF DoNotCatchOIExceptions}
except except
on E: Exception do begin on E: Exception do begin
MessageDlg('Error',E.Message,mtError,[mbOk],0); MessageDlg('Error',E.Message,mtError,[mbOk],0);
end; end;
end; end;
{$ENDIF}
if (OldChangeStep<>FChangeStep) then begin if (OldChangeStep<>FChangeStep) then begin
// the selection has changed // the selection has changed
// => CurRow does not exist any more // => CurRow does not exist any more
@ -2179,8 +2189,9 @@ procedure TObjectInspector.SetPropertyEditorHook(NewValue:TPropertyEditorHook);
begin begin
if FPropertyEditorHook<>NewValue then begin if FPropertyEditorHook<>NewValue then begin
FPropertyEditorHook:=NewValue; FPropertyEditorHook:=NewValue;
FPropertyEditorHook.OnChangeLookupRoot:=@PropEditLookupRootChange; FPropertyEditorHook.AddHandlerChangeLookupRoot(@PropEditLookupRootChange);
FPropertyEditorHook.OnRefreshPropertyValues:=@PropEditRefreshPropertyValues; FPropertyEditorHook.AddHandlerRefreshPropertyValues(
@PropEditRefreshPropertyValues);
// select root component // select root component
FComponentList.Clear; FComponentList.Clear;
if (FPropertyEditorHook<>nil) and (FPropertyEditorHook.LookupRoot<>nil) then if (FPropertyEditorHook<>nil) and (FPropertyEditorHook.LookupRoot<>nil) then

View File

@ -912,41 +912,53 @@ type
TPropHookModified = procedure of object; TPropHookModified = procedure of object;
TPropHookRevert = procedure(Instance:TPersistent; PropInfo:PPropInfo) of object; TPropHookRevert = procedure(Instance:TPersistent; PropInfo:PPropInfo) of object;
TPropHookRefreshPropertyValues = procedure of object; TPropHookRefreshPropertyValues = procedure of object;
TPropHookType = (
// lookup root
htChangeLookupRoot,
// methods
htCreateMethod,
htGetMethodName,
htGetMethods,
htMethodExists,
htRenameMethod,
htShowMethod,
htMethodFromAncestor,
htChainCall,
// components
htGetComponent,
htGetComponentName,
htGetComponentNames,
htGetRootClassName,
htComponentRenamed,
htComponentAdded,
htDeleteComponent,
// persistent objects
htGetObject,
htGetObjectName,
htGetObjectNames,
// modifing
htModified,
htRevert,
htRefreshPropertyValues
);
TPropertyEditorHook = class TPropertyEditorHook = class
private private
FHandlers: array[TPropHookType] of TMethodList;
// lookup root // lookup root
FLookupRoot: TComponent; FLookupRoot: TComponent;
FOnChangeLookupRoot: TPropHookChangeLookupRoot;
// methods
FOnCreateMethod: TPropHookCreateMethod;
FOnGetMethodName: TPropHookGetMethodName;
FOnGetMethods: TPropHookGetMethods;
FOnMethodExists: TPropHookMethodExists;
FOnRenameMethod: TPropHookRenameMethod;
FOnShowMethod: TPropHookShowMethod;
FOnMethodFromAncestor: TPropHookMethodFromAncestor;
FOnChainCall: TPropHookChainCall;
// components
FOnGetComponent: TPropHookGetComponent;
FOnGetComponentName: TPropHookGetComponentName;
FOnGetComponentNames: TPropHookGetComponentNames;
FOnGetRootClassName: TPropHookGetRootClassName;
FOnComponentRenamed: TPropHookComponentRenamed;
FOnComponentAdded: TPropHookComponentAdded;
FOnDeleteComponent: TPropHookDeleteComponent;
// persistent objects
FOnGetObject: TPropHookGetObject;
FOnGetObjectName: TPropHookGetObjectName;
FOnGetObjectNames: TPropHookGetObjectNames;
// modifing
FOnModified: TPropHookModified;
FOnRevert: TPropHookRevert;
FOnRefreshPropertyValues: TPropHookRefreshPropertyValues;
procedure SetLookupRoot(AComponent:TComponent); procedure SetLookupRoot(AComponent:TComponent);
procedure AddHandler(HookType: TPropHookType; const Handler: TMethod);
procedure RemoveHandler(HookType: TPropHookType; const Handler: TMethod);
function GetHandlerCount(HookType: TPropHookType): integer;
function GetNextHandlerIndex(HookType: TPropHookType; var i: integer): boolean;
public public
GetPrivateDirectory:AnsiString; GetPrivateDirectory:AnsiString;
constructor Create;
destructor Destroy; override;
// lookup root // lookup root
property LookupRoot:TComponent read FLookupRoot write SetLookupRoot; property LookupRoot:TComponent read FLookupRoot write SetLookupRoot;
// methods // methods
@ -961,50 +973,94 @@ type
procedure ChainCall(const AMethodName, InstanceName, procedure ChainCall(const AMethodName, InstanceName,
InstanceMethod:ShortString; TypeData:PTypeData); InstanceMethod:ShortString; TypeData:PTypeData);
// components // components
function GetComponent(const Name:ShortString):TComponent; function GetComponent(const Name: ShortString):TComponent;
function GetComponentName(AComponent:TComponent):ShortString; function GetComponentName(AComponent: TComponent):ShortString;
procedure GetComponentNames(TypeData:PTypeData; Proc:TGetStringProc); procedure GetComponentNames(TypeData:PTypeData; const Proc:TGetStringProc);
function GetRootClassName:ShortString; function GetRootClassName:ShortString;
procedure ComponentRenamed(AComponent: TComponent); procedure ComponentRenamed(AComponent: TComponent);
procedure ComponentAdded(AComponent: TComponent; Select: boolean); procedure ComponentAdded(AComponent: TComponent; Select: boolean);
procedure DeleteComponent(AComponent: TComponent); procedure DeleteComponent(AComponent: TComponent);
// persistent objects // persistent objects
function GetObject(const Name:ShortString):TPersistent; function GetObject(const Name: ShortString):TPersistent;
function GetObjectName(Instance:TPersistent):ShortString; function GetObjectName(Instance: TPersistent):ShortString;
procedure GetObjectNames(TypeData:PTypeData; Proc:TGetStringProc); procedure GetObjectNames(TypeData: PTypeData; const Proc:TGetStringProc);
// modifing // modifing
procedure Modified; procedure Modified;
procedure Revert(Instance:TPersistent; PropInfo:PPropInfo); procedure Revert(Instance:TPersistent; PropInfo:PPropInfo);
procedure RefreshPropertyValues; procedure RefreshPropertyValues;
public
// Handlers
// lookup root // lookup root
property OnChangeLookupRoot:TPropHookChangeLookupRoot procedure AddHandlerChangeLookupRoot(
read FOnChangeLookupRoot write FOnChangeLookupRoot; OnChangeLookupRoot: TPropHookChangeLookupRoot);
procedure RemoveHandlerChangeLookupRoot(
OnChangeLookupRoot: TPropHookChangeLookupRoot);
// method events // method events
property OnCreateMethod:TPropHookCreateMethod read FOnCreateMethod write FOnCreateMethod; procedure AddHandlerCreateMethod(OnCreateMethod: TPropHookCreateMethod);
property OnGetMethodName:TPropHookGetMethodName read FOnGetMethodName write FOnGetMethodName; procedure RemoveHandlerCreateMethod(OnCreateMethod: TPropHookCreateMethod);
property OnGetMethods:TPropHookGetMethods read FOnGetMethods write FOnGetMethods; procedure AddHandlerGetMethodName(OnGetMethodName: TPropHookGetMethodName);
property OnMethodExists:TPropHookMethodExists read FOnMethodExists write FOnMethodExists; procedure RemoveHandlerGetMethodName(OnGetMethodName: TPropHookGetMethodName);
property OnRenameMethod:TPropHookRenameMethod read FOnRenameMethod write FOnRenameMethod; procedure AddHandlerGetMethods(OnGetMethods: TPropHookGetMethods);
property OnShowMethod:TPropHookShowMethod read FOnShowMethod write FOnShowMethod; procedure RemoveHandlerGetMethods(OnGetMethods: TPropHookGetMethods);
property OnMethodFromAncestor:TPropHookMethodFromAncestor read FOnMethodFromAncestor write FOnMethodFromAncestor; procedure AddHandlerMethodExists(OnMethodExists: TPropHookMethodExists);
property OnChainCall:TPropHookChainCall read FOnChainCall write FOnChainCall; procedure RemoveHandlerMethodExists(OnMethodExists: TPropHookMethodExists);
procedure AddHandlerRenameMethod(OnRenameMethod: TPropHookRenameMethod);
procedure RemoveHandlerRenameMethod(OnRenameMethod: TPropHookRenameMethod);
procedure AddHandlerShowMethod(OnShowMethod: TPropHookShowMethod);
procedure RemoveHandlerShowMethod(OnShowMethod: TPropHookShowMethod);
procedure AddHandlerMethodFromAncestor(
OnMethodFromAncestor: TPropHookMethodFromAncestor);
procedure RemoveHandlerMethodFromAncestor(
OnMethodFromAncestor: TPropHookMethodFromAncestor);
procedure AddHandlerChainCall(OnChainCall: TPropHookChainCall);
procedure RemoveHandlerChainCall(OnChainCall: TPropHookChainCall);
// component event // component event
property OnGetComponent:TPropHookGetComponent read FOnGetComponent write FOnGetComponent; procedure AddHandlerGetComponent(OnGetComponent: TPropHookGetComponent);
property OnGetComponentName:TPropHookGetComponentName read FOnGetComponentName write FOnGetComponentName; procedure RemoveHandlerGetComponent(OnGetComponent: TPropHookGetComponent);
property OnGetComponentNames:TPropHookGetComponentNames read FOnGetComponentNames write FOnGetComponentNames; procedure AddHandlerGetComponentName(
property OnGetRootClassName:TPropHookGetRootClassName read FOnGetRootClassName write FOnGetRootClassName; OnGetComponentName: TPropHookGetComponentName);
property OnComponentRenamed:TPropHookComponentRenamed read FOnComponentRenamed write FOnComponentRenamed; procedure RemoveHandlerGetComponentName(
property OnComponentAdded:TPropHookComponentAdded read FOnComponentAdded write FOnComponentAdded; OnGetComponentName: TPropHookGetComponentName);
property OnDeleteComponent:TPropHookDeleteComponent read FOnDeleteComponent write FOnDeleteComponent; procedure AddHandlerGetComponentNames(
OnGetComponentNames: TPropHookGetComponentNames);
procedure RemoveHandlerGetComponentNames(
OnGetComponentNames: TPropHookGetComponentNames);
procedure AddHandlerGetRootClassName(
OnGetRootClassName: TPropHookGetRootClassName);
procedure RemoveHandlerGetRootClassName(
OnGetRootClassName: TPropHookGetRootClassName);
procedure AddHandlerComponentRenamed(
OnComponentRenamed: TPropHookComponentRenamed);
procedure RemoveHandlerComponentRenamed(
OnComponentRenamed: TPropHookComponentRenamed);
procedure AddHandlerComponentAdded(
OnComponentAdded: TPropHookComponentAdded);
procedure RemoveHandlerComponentAdded(
OnComponentAdded: TPropHookComponentAdded);
procedure AddHandlerDeleteComponent(
OnDeleteComponent: TPropHookDeleteComponent);
procedure RemoveHandlerDeleteComponent(
OnDeleteComponent: TPropHookDeleteComponent);
// persistent object events // persistent object events
property OnGetObject:TPropHookGetObject read FOnGetObject write FOnGetObject; procedure AddHandlerGetObject(OnGetObject: TPropHookGetObject);
property OnGetObjectName:TPropHookGetObjectName read FOnGetObjectName write FOnGetObjectName; procedure RemoveHandlerGetObject(OnGetObject: TPropHookGetObject);
property OnGetObjectNames:TPropHookGetObjectNames read FOnGetObjectNames write FOnGetObjectNames; procedure AddHandlerGetObjectName(OnGetObjectName: TPropHookGetObjectName);
procedure RemoveHandlerGetObjectName(
OnGetObjectName: TPropHookGetObjectName);
procedure AddHandlerGetObjectNames(
OnGetObjectNames: TPropHookGetObjectNames);
procedure RemoveHandlerGetObjectNames(
OnGetObjectNames: TPropHookGetObjectNames);
// modifing events // modifing events
property OnModified:TPropHookModified read FOnModified write FOnModified; procedure AddHandlerModified(OnModified: TPropHookModified);
property OnRevert:TPropHookRevert read FOnRevert write FOnRevert; procedure RemoveHandlerModified(OnModified: TPropHookModified);
property OnRefreshPropertyValues:TPropHookRefreshPropertyValues read FOnRefreshPropertyValues write FOnRefreshPropertyValues; procedure AddHandlerRevert(OnRevert: TPropHookRevert);
procedure RemoveHandlerRevert(OnRevert: TPropHookRevert);
procedure AddHandlerRefreshPropertyValues(
OnRefreshPropertyValues: TPropHookRefreshPropertyValues);
procedure RemoveHandlerRefreshPropertyValues(
OnRefreshPropertyValues: TPropHookRefreshPropertyValues);
end; end;
//============================================================================== //==============================================================================
@ -4094,20 +4150,30 @@ end;
function TPropertyEditorHook.CreateMethod(const Name:Shortstring; function TPropertyEditorHook.CreateMethod(const Name:Shortstring;
ATypeInfo:PTypeInfo): TMethod; ATypeInfo:PTypeInfo): TMethod;
var
i: Integer;
Handler: TPropHookCreateMethod;
begin begin
if IsValidIdent(Name) and (ATypeInfo<>nil) and Assigned(FOnCreateMethod) then Result.Code:=nil;
Result:=FOnCreateMethod(Name,ATypeInfo) Result.Data:=nil;
else begin if IsValidIdent(Name) and (ATypeInfo<>nil) then begin
Result.Code:=nil; i:=GetHandlerCount(htCreateMethod);
Result.Data:=nil; while GetNextHandlerIndex(htCreateMethod,i) do begin
Handler:=TPropHookCreateMethod(FHandlers[htCreateMethod][i]);
Result:=Handler(Name,ATypeInfo);
if Result.Code<>nil then exit;
end;
end; end;
end; end;
function TPropertyEditorHook.GetMethodName(const Method:TMethod): ShortString; function TPropertyEditorHook.GetMethodName(const Method:TMethod): ShortString;
var
i: Integer;
begin begin
if Assigned(FOnGetMethodName) then i:=GetHandlerCount(htGetMethodName);
Result:=FOnGetMethodName(Method) if GetNextHandlerIndex(htGetMethodName,i) then begin
else begin Result:=TPropHookGetMethodName(FHandlers[htGetMethodName][i])(Method);
end else begin
// search the method name with the given code pointer // search the method name with the given code pointer
if Assigned(Method.Code) then begin if Assigned(Method.Code) then begin
if Assigned(LookupRoot) then begin if Assigned(LookupRoot) then begin
@ -4123,22 +4189,33 @@ end;
procedure TPropertyEditorHook.GetMethods(TypeData:PTypeData; procedure TPropertyEditorHook.GetMethods(TypeData:PTypeData;
Proc:TGetStringProc); Proc:TGetStringProc);
var
i: Integer;
begin begin
if Assigned(FOnGetMethods) then i:=GetHandlerCount(htGetMethods);
FOnGetMethods(TypeData,Proc); while GetNextHandlerIndex(htGetMethods,i) do
TPropHookGetMethods(FHandlers[htGetMethods][i])(TypeData,Proc);
end; end;
function TPropertyEditorHook.MethodExists(const Name:Shortstring; function TPropertyEditorHook.MethodExists(const Name:Shortstring;
TypeData: PTypeData; TypeData: PTypeData;
var MethodIsCompatible, MethodIsPublished, IdentIsMethod: boolean):boolean; var MethodIsCompatible, MethodIsPublished, IdentIsMethod: boolean):boolean;
var
i: Integer;
Handler: TPropHookMethodExists;
begin begin
// check if a published method with given name exists in LookupRoot // check if a published method with given name exists in LookupRoot
if IsValidIdent(Name) and Assigned(FOnMethodExists) then Result:=IsValidIdent(Name) and Assigned(FLookupRoot);
Result:=FOnMethodExists(Name,TypeData, if not Result then exit;
MethodIsCompatible,MethodIsPublished,IdentIsMethod) i:=GetHandlerCount(htMethodExists);
else begin if i>=0 then begin
Result:=IsValidIdent(Name) and Assigned(LookupRoot) while GetNextHandlerIndex(htMethodExists,i) do begin
and (LookupRoot.MethodAddress(Name)<>nil); Handler:=TPropHookMethodExists(FHandlers[htMethodExists][i]);
Result:=Handler(Name,TypeData,
MethodIsCompatible,MethodIsPublished,IdentIsMethod);
end;
end else begin
Result:=(LookupRoot.MethodAddress(Name)<>nil);
MethodIsCompatible:=Result; MethodIsCompatible:=Result;
MethodIsPublished:=Result; MethodIsPublished:=Result;
IdentIsMethod:=Result; IdentIsMethod:=Result;
@ -4146,27 +4223,37 @@ begin
end; end;
procedure TPropertyEditorHook.RenameMethod(const CurName, NewName:ShortString); procedure TPropertyEditorHook.RenameMethod(const CurName, NewName:ShortString);
// rename published method in LookupRoot object and source
var
i: Integer;
begin begin
// rename published method in LookupRoot object and source i:=GetHandlerCount(htRenameMethod);
if Assigned(FOnRenameMethod) then while GetNextHandlerIndex(htRenameMethod,i) do
FOnRenameMethod(CurName,NewName); TPropHookRenameMethod(FHandlers[htRenameMethod][i])(CurName,NewName);
end; end;
procedure TPropertyEditorHook.ShowMethod(const Name:Shortstring); procedure TPropertyEditorHook.ShowMethod(const Name:Shortstring);
// jump cursor to published method body
var
i: Integer;
begin begin
// jump cursor to published method body i:=GetHandlerCount(htShowMethod);
if Assigned(FOnShowMethod) then while GetNextHandlerIndex(htShowMethod,i) do
FOnShowMethod(Name); TPropHookShowMethod(FHandlers[htShowMethod][i])(Name);
end; end;
function TPropertyEditorHook.MethodFromAncestor(const Method:TMethod):boolean; function TPropertyEditorHook.MethodFromAncestor(const Method:TMethod):boolean;
var AncestorClass: TClass; var AncestorClass: TClass;
i: Integer;
Handler: TPropHookMethodFromAncestor;
begin begin
// check if given Method is not in LookupRoot source, // check if given Method is not in LookupRoot source,
// but in one of its ancestors // but in one of its ancestors
if Assigned(FOnMethodFromAncestor) then i:=GetHandlerCount(htMethodFromAncestor);
Result:=FOnMethodFromAncestor(Method) if GetNextHandlerIndex(htMethodFromAncestor,i) then begin
else begin Handler:=TPropHookMethodFromAncestor(FHandlers[htMethodFromAncestor][i]);
Result:=Handler(Method);
end else begin
if (Method.Data<>nil) then begin if (Method.Data<>nil) then begin
AncestorClass:=TObject(Method.Data).ClassParent; AncestorClass:=TObject(Method.Data).ClassParent;
Result:=(AncestorClass<>nil) Result:=(AncestorClass<>nil)
@ -4177,114 +4264,156 @@ begin
end; end;
procedure TPropertyEditorHook.ChainCall(const AMethodName, InstanceName, procedure TPropertyEditorHook.ChainCall(const AMethodName, InstanceName,
InstanceMethod:Shortstring; TypeData:PTypeData); InstanceMethod:Shortstring; TypeData:PTypeData);
var
i: Integer;
Handler: TPropHookChainCall;
begin begin
if Assigned(FOnChainCall) then i:=GetHandlerCount(htChainCall);
FOnChainCall(AMethodName,InstanceName,InstanceMethod,TypeData); while GetNextHandlerIndex(htChainCall,i) do begin
Handler:=TPropHookChainCall(FHandlers[htChainCall][i]);
Handler(AMethodName,InstanceName,InstanceMethod,TypeData);
end;
end; end;
function TPropertyEditorHook.GetComponent(const Name:Shortstring):TComponent; function TPropertyEditorHook.GetComponent(const Name:Shortstring):TComponent;
var
i: Integer;
begin begin
if Assigned(FOnGetComponent) then Result:=nil;
Result:=FOnGetComponent(Name) if not Assigned(LookupRoot) then exit;
else begin i:=GetHandlerCount(htGetComponent);
if Assigned(LookupRoot) then begin while GetNextHandlerIndex(htGetComponent,i) and (Result=nil) do
Result:=LookupRoot.FindComponent(Name); Result:=TPropHookGetComponent(FHandlers[htGetComponent][i])(Name);
end else begin if Result=nil then
Result:=nil; Result:=LookupRoot.FindComponent(Name);
end;
end;
end; end;
function TPropertyEditorHook.GetComponentName( function TPropertyEditorHook.GetComponentName(
AComponent:TComponent):Shortstring; AComponent:TComponent):Shortstring;
var
i: Integer;
Handler: TPropHookGetComponentName;
begin begin
if Assigned(FOnGetComponentName) then Result:='';
Result:=FOnGetComponentName(AComponent) if AComponent=nil then exit;
else begin i:=GetHandlerCount(htGetComponentName);
if Assigned(AComponent) then while GetNextHandlerIndex(htGetComponentName,i) and (Result='') do begin
Result:=AComponent.Name Handler:=TPropHookGetComponentName(FHandlers[htGetComponentName][i]);
else Result:=Handler(AComponent);
Result:='';
end; end;
if Result='' then
Result:=AComponent.Name;
end; end;
procedure TPropertyEditorHook.GetComponentNames(TypeData:PTypeData; procedure TPropertyEditorHook.GetComponentNames(TypeData:PTypeData;
Proc:TGetStringProc); const Proc:TGetStringProc);
var i: integer; var i: integer;
Handler: TPropHookGetComponentNames;
begin begin
if Assigned(FOnGetComponentNames) then if not Assigned(LookupRoot) then exit;
FOnGetComponentNames(TypeData,Proc) i:=GetHandlerCount(htGetComponentNames);
else begin if i>0 then begin
if Assigned(LookupRoot) then while GetNextHandlerIndex(htGetComponentNames,i) do begin
for i:=0 to LookupRoot.ComponentCount-1 do Handler:=TPropHookGetComponentNames(FHandlers[htGetComponentNames][i]);
if (LookupRoot.Components[i] is TypeData^.ClassType) then Handler(TypeData,Proc);
Proc(LookupRoot.Components[i].Name); end;
end else begin
for i:=0 to LookupRoot.ComponentCount-1 do
if (LookupRoot.Components[i] is TypeData^.ClassType) then
Proc(LookupRoot.Components[i].Name);
end; end;
end; end;
function TPropertyEditorHook.GetRootClassName:Shortstring; function TPropertyEditorHook.GetRootClassName:Shortstring;
var
i: Integer;
Handler: TPropHookGetRootClassName;
begin begin
if Assigned(FOnGetRootClassName) then begin Result:='';
Result:=FOnGetRootClassName(); i:=GetHandlerCount(htGetRootClassName);
end else begin while GetNextHandlerIndex(htGetRootClassName,i) and (Result='') do begin
if Assigned(LookupRoot) then Handler:=TPropHookGetRootClassName(FHandlers[htGetRootClassName][i]);
Result:=LookupRoot.ClassName Result:=Handler();
else
Result:='';
end; end;
if (Result='') and Assigned(LookupRoot) then
Result:=LookupRoot.ClassName;
end; end;
procedure TPropertyEditorHook.ComponentRenamed(AComponent: TComponent); procedure TPropertyEditorHook.ComponentRenamed(AComponent: TComponent);
var
i: Integer;
begin begin
if Assigned(OnComponentRenamed) then i:=GetHandlerCount(htComponentRenamed);
OnComponentRenamed(AComponent); while GetNextHandlerIndex(htComponentRenamed,i) do
TPropHookComponentRenamed(FHandlers[htComponentRenamed][i])(AComponent);
end; end;
procedure TPropertyEditorHook.ComponentAdded(AComponent: TComponent; procedure TPropertyEditorHook.ComponentAdded(AComponent: TComponent;
Select: boolean); Select: boolean);
var
i: Integer;
begin begin
if Assigned(OnComponentAdded) then i:=GetHandlerCount(htComponentAdded);
OnComponentAdded(AComponent,Select); while GetNextHandlerIndex(htComponentAdded,i) do
TPropHookComponentAdded(FHandlers[htComponentAdded][i])(AComponent,Select);
end; end;
procedure TPropertyEditorHook.DeleteComponent(AComponent: TComponent); procedure TPropertyEditorHook.DeleteComponent(AComponent: TComponent);
var
i: Integer;
begin begin
if Assigned(OnDeleteComponent) then if AComponent=nil then exit;
OnDeleteComponent(AComponent) i:=GetHandlerCount(htDeleteComponent);
else if i>0 then begin
while GetNextHandlerIndex(htDeleteComponent,i) do
TPropHookDeleteComponent(FHandlers[htDeleteComponent][i])(AComponent);
end else
AComponent.Free; AComponent.Free;
end; end;
function TPropertyEditorHook.GetObject(const Name:Shortstring):TPersistent; function TPropertyEditorHook.GetObject(const Name:Shortstring):TPersistent;
var
i: Integer;
begin begin
if Assigned(FOnGetObject) then Result:=nil;
Result:=FOnGetObject(Name) i:=GetHandlerCount(htGetObject);
else while GetNextHandlerIndex(htGetObject,i) and (Result=nil) do
Result:=nil; Result:=TPropHookGetObject(FHandlers[htGetObject][i])(Name);
end; end;
function TPropertyEditorHook.GetObjectName(Instance:TPersistent):Shortstring; function TPropertyEditorHook.GetObjectName(Instance:TPersistent):Shortstring;
var
i: Integer;
begin begin
if Assigned(FOnGetObjectName) then Result:='';
Result:=FOnGetObjectName(Instance) i:=GetHandlerCount(htGetObjectName);
else begin if i>0 then begin
while GetNextHandlerIndex(htGetObjectName,i) and (Result='') do
Result:=TPropHookGetObjectName(FHandlers[htGetObject][i])(Instance);
end else
if Instance is TComponent then if Instance is TComponent then
Result:=TComponent(Instance).Name; Result:=TComponent(Instance).Name;
end;
end; end;
procedure TPropertyEditorHook.GetObjectNames(TypeData:PTypeData; procedure TPropertyEditorHook.GetObjectNames(TypeData:PTypeData;
Proc:TGetStringProc); const Proc:TGetStringProc);
var
i: Integer;
begin begin
if Assigned(FOnGetObjectNames) then i:=GetHandlerCount(htGetObjectNames);
FOnGetObjectNames(TypeData,Proc); while GetNextHandlerIndex(htGetObjectNames,i) do
TPropHookGetObjectNames(FHandlers[htGetObjectNames][i])(TypeData,Proc);
end; end;
procedure TPropertyEditorHook.Modified; procedure TPropertyEditorHook.Modified;
var
i: Integer;
begin begin
if Assigned(FOnModified) then begin i:=GetHandlerCount(htModified);
FOnModified(); if i>0 then begin
while GetNextHandlerIndex(htModified,i) do
TPropHookModified(FHandlers[htModified][i])();
end else if FLookupRoot<>nil then begin end else if FLookupRoot<>nil then begin
if (FLookupRoot is TCustomForm) if (FLookupRoot is TCustomForm)
and (TCustomForm(FLookupRoot).Designer<>nil) then and (TCustomForm(FLookupRoot).Designer<>nil) then
@ -4293,24 +4422,346 @@ begin
end; end;
procedure TPropertyEditorHook.Revert(Instance:TPersistent; procedure TPropertyEditorHook.Revert(Instance:TPersistent;
PropInfo:PPropInfo); PropInfo:PPropInfo);
var
i: Integer;
begin begin
if Assigned(FOnRevert) then i:=GetHandlerCount(htRevert);
FOnRevert(Instance,PropInfo); while GetNextHandlerIndex(htRevert,i) do
TPropHookRevert(FHandlers[htRevert][i])(Instance,PropInfo);
end; end;
procedure TPropertyEditorHook.RefreshPropertyValues; procedure TPropertyEditorHook.RefreshPropertyValues;
var
i: Integer;
begin begin
if Assigned(FOnRefreshPropertyValues) then i:=GetHandlerCount(htRefreshPropertyValues);
FOnRefreshPropertyValues(); while GetNextHandlerIndex(htRefreshPropertyValues,i) do
TPropHookRefreshPropertyValues(FHandlers[htRefreshPropertyValues][i])();
end;
procedure TPropertyEditorHook.AddHandlerChangeLookupRoot(
OnChangeLookupRoot: TPropHookChangeLookupRoot);
begin
AddHandler(htChangeLookupRoot,TMethod(OnChangeLookupRoot));
end;
procedure TPropertyEditorHook.RemoveHandlerChangeLookupRoot(
OnChangeLookupRoot: TPropHookChangeLookupRoot);
begin
RemoveHandler(htChangeLookupRoot,TMethod(OnChangeLookupRoot));
end;
procedure TPropertyEditorHook.AddHandlerCreateMethod(
OnCreateMethod: TPropHookCreateMethod);
begin
AddHandler(htCreateMethod,TMethod(OnCreateMethod));
end;
procedure TPropertyEditorHook.RemoveHandlerCreateMethod(
OnCreateMethod: TPropHookCreateMethod);
begin
RemoveHandler(htCreateMethod,TMethod(OnCreateMethod));
end;
procedure TPropertyEditorHook.AddHandlerGetMethodName(
OnGetMethodName: TPropHookGetMethodName);
begin
AddHandler(htGetMethodName,TMethod(OnGetMethodName));
end;
procedure TPropertyEditorHook.RemoveHandlerGetMethodName(
OnGetMethodName: TPropHookGetMethodName);
begin
RemoveHandler(htGetMethodName,TMethod(OnGetMethodName));
end;
procedure TPropertyEditorHook.AddHandlerGetMethods(
OnGetMethods: TPropHookGetMethods);
begin
AddHandler(htGetMethods,TMethod(OnGetMethods));
end;
procedure TPropertyEditorHook.RemoveHandlerGetMethods(
OnGetMethods: TPropHookGetMethods);
begin
RemoveHandler(htGetMethods,TMethod(OnGetMethods));
end;
procedure TPropertyEditorHook.AddHandlerMethodExists(
OnMethodExists: TPropHookMethodExists);
begin
AddHandler(htMethodExists,TMethod(OnMethodExists));
end;
procedure TPropertyEditorHook.RemoveHandlerMethodExists(
OnMethodExists: TPropHookMethodExists);
begin
RemoveHandler(htMethodExists,TMethod(OnMethodExists));
end;
procedure TPropertyEditorHook.AddHandlerRenameMethod(
OnRenameMethod: TPropHookRenameMethod);
begin
AddHandler(htRenameMethod,TMethod(OnRenameMethod));
end;
procedure TPropertyEditorHook.RemoveHandlerRenameMethod(
OnRenameMethod: TPropHookRenameMethod);
begin
RemoveHandler(htRenameMethod,TMethod(OnRenameMethod));
end;
procedure TPropertyEditorHook.AddHandlerShowMethod(
OnShowMethod: TPropHookShowMethod);
begin
AddHandler(htShowMethod,TMethod(OnShowMethod));
end;
procedure TPropertyEditorHook.RemoveHandlerShowMethod(
OnShowMethod: TPropHookShowMethod);
begin
RemoveHandler(htShowMethod,TMethod(OnShowMethod));
end;
procedure TPropertyEditorHook.AddHandlerMethodFromAncestor(
OnMethodFromAncestor: TPropHookMethodFromAncestor);
begin
AddHandler(htMethodFromAncestor,TMethod(OnMethodFromAncestor));
end;
procedure TPropertyEditorHook.RemoveHandlerMethodFromAncestor(
OnMethodFromAncestor: TPropHookMethodFromAncestor);
begin
RemoveHandler(htMethodFromAncestor,TMethod(OnMethodFromAncestor));
end;
procedure TPropertyEditorHook.AddHandlerChainCall(
OnChainCall: TPropHookChainCall);
begin
AddHandler(htChainCall,TMethod(OnChainCall));
end;
procedure TPropertyEditorHook.RemoveHandlerChainCall(
OnChainCall: TPropHookChainCall);
begin
RemoveHandler(htChainCall,TMethod(OnChainCall));
end;
procedure TPropertyEditorHook.AddHandlerGetComponent(
OnGetComponent: TPropHookGetComponent);
begin
AddHandler(htGetComponent,TMethod(OnGetComponent));
end;
procedure TPropertyEditorHook.RemoveHandlerGetComponent(
OnGetComponent: TPropHookGetComponent);
begin
RemoveHandler(htGetComponent,TMethod(OnGetComponent));
end;
procedure TPropertyEditorHook.AddHandlerGetComponentName(
OnGetComponentName: TPropHookGetComponentName);
begin
AddHandler(htGetComponentName,TMethod(OnGetComponentName));
end;
procedure TPropertyEditorHook.RemoveHandlerGetComponentName(
OnGetComponentName: TPropHookGetComponentName);
begin
RemoveHandler(htGetComponentName,TMethod(OnGetComponentName));
end;
procedure TPropertyEditorHook.AddHandlerGetComponentNames(
OnGetComponentNames: TPropHookGetComponentNames);
begin
AddHandler(htGetComponentNames,TMethod(OnGetComponentNames));
end;
procedure TPropertyEditorHook.RemoveHandlerGetComponentNames(
OnGetComponentNames: TPropHookGetComponentNames);
begin
RemoveHandler(htGetComponentNames,TMethod(OnGetComponentNames));
end;
procedure TPropertyEditorHook.AddHandlerGetRootClassName(
OnGetRootClassName: TPropHookGetRootClassName);
begin
AddHandler(htGetRootClassName,TMethod(OnGetRootClassName));
end;
procedure TPropertyEditorHook.RemoveHandlerGetRootClassName(
OnGetRootClassName: TPropHookGetRootClassName);
begin
RemoveHandler(htGetRootClassName,TMethod(OnGetRootClassName));
end;
procedure TPropertyEditorHook.AddHandlerComponentRenamed(
OnComponentRenamed: TPropHookComponentRenamed);
begin
AddHandler(htComponentRenamed,TMethod(OnComponentRenamed));
end;
procedure TPropertyEditorHook.RemoveHandlerComponentRenamed(
OnComponentRenamed: TPropHookComponentRenamed);
begin
RemoveHandler(htComponentRenamed,TMethod(OnComponentRenamed));
end;
procedure TPropertyEditorHook.AddHandlerComponentAdded(
OnComponentAdded: TPropHookComponentAdded);
begin
AddHandler(htComponentAdded,TMethod(OnComponentAdded));
end;
procedure TPropertyEditorHook.RemoveHandlerComponentAdded(
OnComponentAdded: TPropHookComponentAdded);
begin
RemoveHandler(htComponentAdded,TMethod(OnComponentAdded));
end;
procedure TPropertyEditorHook.AddHandlerDeleteComponent(
OnDeleteComponent: TPropHookDeleteComponent);
begin
AddHandler(htDeleteComponent,TMethod(OnDeleteComponent));
end;
procedure TPropertyEditorHook.RemoveHandlerDeleteComponent(
OnDeleteComponent: TPropHookDeleteComponent);
begin
RemoveHandler(htDeleteComponent,TMethod(OnDeleteComponent));
end;
procedure TPropertyEditorHook.AddHandlerGetObject(
OnGetObject: TPropHookGetObject);
begin
AddHandler(htGetObject,TMethod(OnGetObject));
end;
procedure TPropertyEditorHook.RemoveHandlerGetObject(
OnGetObject: TPropHookGetObject);
begin
RemoveHandler(htGetObject,TMethod(OnGetObject));
end;
procedure TPropertyEditorHook.AddHandlerGetObjectName(
OnGetObjectName: TPropHookGetObjectName);
begin
AddHandler(htGetObjectName,TMethod(OnGetObjectName));
end;
procedure TPropertyEditorHook.RemoveHandlerGetObjectName(
OnGetObjectName: TPropHookGetObjectName);
begin
RemoveHandler(htGetObjectName,TMethod(OnGetObjectName));
end;
procedure TPropertyEditorHook.AddHandlerGetObjectNames(
OnGetObjectNames: TPropHookGetObjectNames);
begin
AddHandler(htGetObjectNames,TMethod(OnGetObjectNames));
end;
procedure TPropertyEditorHook.RemoveHandlerGetObjectNames(
OnGetObjectNames: TPropHookGetObjectNames);
begin
RemoveHandler(htGetObjectNames,TMethod(OnGetObjectNames));
end;
procedure TPropertyEditorHook.AddHandlerModified(OnModified: TPropHookModified
);
begin
AddHandler(htModified,TMethod(OnModified));
end;
procedure TPropertyEditorHook.RemoveHandlerModified(
OnModified: TPropHookModified);
begin
RemoveHandler(htModified,TMethod(OnModified));
end;
procedure TPropertyEditorHook.AddHandlerRevert(OnRevert: TPropHookRevert);
begin
AddHandler(htRevert,TMethod(OnRevert));
end;
procedure TPropertyEditorHook.RemoveHandlerRevert(OnRevert: TPropHookRevert);
begin
RemoveHandler(htRevert,TMethod(OnRevert));
end;
procedure TPropertyEditorHook.AddHandlerRefreshPropertyValues(
OnRefreshPropertyValues: TPropHookRefreshPropertyValues);
begin
AddHandler(htRefreshPropertyValues,TMethod(OnRefreshPropertyValues));
end;
procedure TPropertyEditorHook.RemoveHandlerRefreshPropertyValues(
OnRefreshPropertyValues: TPropHookRefreshPropertyValues);
begin
RemoveHandler(htRefreshPropertyValues,TMethod(OnRefreshPropertyValues));
end; end;
procedure TPropertyEditorHook.SetLookupRoot(AComponent:TComponent); procedure TPropertyEditorHook.SetLookupRoot(AComponent:TComponent);
var
i: Integer;
begin begin
if FLookupRoot=AComponent then exit; if FLookupRoot=AComponent then exit;
FLookupRoot:=AComponent; FLookupRoot:=AComponent;
if Assigned(FOnChangeLookupRoot) then i:=GetHandlerCount(htChangeLookupRoot);
FOnChangeLookupRoot(); while GetNextHandlerIndex(htChangeLookupRoot,i) do
TPropHookChangeLookupRoot(FHandlers[htChangeLookupRoot][i])();
end;
procedure TPropertyEditorHook.AddHandler(HookType: TPropHookType;
const Handler: TMethod);
begin
if Handler.Code=nil then RaiseGDBException('TPropertyEditorHook.AddHandler');
if FHandlers[HookType]=nil then
FHandlers[HookType]:=TMethodList.Create;
FHandlers[HookType].Add(Handler);
end;
procedure TPropertyEditorHook.RemoveHandler(HookType: TPropHookType;
const Handler: TMethod);
begin
if FHandlers[HookType]=nil then exit;
FHandlers[HookType].Remove(Handler);
end;
function TPropertyEditorHook.GetHandlerCount(HookType: TPropHookType): integer;
begin
if FHandlers[HookType]<>nil then
Result:=FHandlers[HookType].Count
else
Result:=0;
end;
function TPropertyEditorHook.GetNextHandlerIndex(HookType: TPropHookType;
var i: integer): boolean;
begin
if FHandlers[HookType]<>nil then begin
dec(i);
if (i>=FHandlers[HookType].Count) then
i:=FHandlers[HookType].Count-1;
end else begin
i:=-1;
end;
Result:=(i>=0);
end;
constructor TPropertyEditorHook.Create;
begin
inherited Create;
end;
destructor TPropertyEditorHook.Destroy;
var
HookType: TPropHookType;
begin
for HookType:=Low(TPropHookType) to high(TPropHookType) do
FreeThenNil(FHandlers[HookType]);
inherited Destroy;
end; end;
//****************************************************************************** //******************************************************************************