IDEIntf+LCL: TGetDesignerFormEvent using TPersistent instead of TComponent

git-svn-id: trunk@22907 -
This commit is contained in:
mattias 2009-12-01 20:33:50 +00:00
parent 53ede9fe10
commit f358340f56
4 changed files with 48 additions and 29 deletions

View File

@ -186,7 +186,7 @@ each control that's dropped onto the form
): TJITComponentList; ): TJITComponentList;
function FindJITListByClass(AComponentClass: TComponentClass function FindJITListByClass(AComponentClass: TComponentClass
): TJITComponentList; ): TJITComponentList;
function GetDesignerForm(AComponent: TComponent): TCustomForm; override; function GetDesignerForm(APersistent: TPersistent): TCustomForm; override;
function FindNonFormForm(LookupRoot: TComponent): TCustomNonFormDesignerForm; function FindNonFormForm(LookupRoot: TComponent): TCustomNonFormDesignerForm;
@ -1207,19 +1207,20 @@ begin
Result := nil; Result := nil;
end; end;
function TCustomFormEditor.GetDesignerForm(AComponent: TComponent): TCustomForm; function TCustomFormEditor.GetDesignerForm(APersistent: TPersistent): TCustomForm;
var var
OwnerComponent: TComponent; TheOwner: TPersistent;
begin begin
Result := nil; Result:=nil;
if AComponent = nil then exit; TheOwner := GetLookupRootForComponent(APersistent);
OwnerComponent := AComponent; if TheOwner = nil then
while OwnerComponent.Owner <> nil do exit;
OwnerComponent := OwnerComponent.Owner; if TheOwner is TCustomForm then
if OwnerComponent is TCustomForm then Result := TCustomForm(TheOwner)
Result := TCustomForm(OwnerComponent) else if TheOwner is TComponent then
Result := FindNonFormForm(TComponent(TheOwner))
else else
Result := FindNonFormForm(OwnerComponent); exit;
end; end;
function TCustomFormEditor.FindNonFormForm(LookupRoot: TComponent): TCustomNonFormDesignerForm; function TCustomFormEditor.FindNonFormForm(LookupRoot: TComponent): TCustomNonFormDesignerForm;

View File

@ -197,7 +197,7 @@ type
function DesignerCount: integer; virtual; abstract; function DesignerCount: integer; virtual; abstract;
property Designer[Index: integer]: TIDesigner read GetDesigner; property Designer[Index: integer]: TIDesigner read GetDesigner;
function GetCurrentDesigner: TIDesigner; virtual; abstract; function GetCurrentDesigner: TIDesigner; virtual; abstract;
function GetDesignerForm(AComponent: TComponent): TCustomForm; virtual; abstract; function GetDesignerForm(APersistent: TPersistent): TCustomForm; virtual; abstract;
function GetDesignerByComponent(AComponent: TComponent function GetDesignerByComponent(AComponent: TComponent
): TIDesigner; virtual; abstract; ): TIDesigner; virtual; abstract;

View File

@ -4232,9 +4232,10 @@ end;
procedure TObjectInspectorDlg.ComponentTreeDblClick(Sender: TObject); procedure TObjectInspectorDlg.ComponentTreeDblClick(Sender: TObject);
var var
AComponent: TComponent; APersistent: TPersistent;
CompEditor: TBaseComponentEditor; CompEditor: TBaseComponentEditor;
ADesigner: TIDesigner; ADesigner: TIDesigner;
AComponent: TComponent;
begin begin
if (PropertyEditorHook=nil) or (PropertyEditorHook.LookupRoot=nil) then if (PropertyEditorHook=nil) or (PropertyEditorHook.LookupRoot=nil) then
Exit; Exit;
@ -4242,7 +4243,10 @@ begin
ComponentTreeSelectionChanged(Sender); ComponentTreeSelectionChanged(Sender);
if not Assigned(ComponentTree.Selected) then if not Assigned(ComponentTree.Selected) then
Exit; Exit;
AComponent := TComponent(ComponentTree.Selected.Data); APersistent := TPersistent(ComponentTree.Selected.Data);
if not (APersistent is TComponent) then
exit;
AComponent:=TComponent(APersistent);
ADesigner := FindRootDesigner(AComponent); ADesigner := FindRootDesigner(AComponent);
if not (ADesigner is TComponentEditorDesigner) then if not (ADesigner is TComponentEditorDesigner) then
Exit; Exit;

View File

@ -1500,15 +1500,15 @@ procedure RestoreFocusState(FocusState: TFocusState);
type type
TGetDesignerFormEvent = TGetDesignerFormEvent =
function(AComponent: TComponent): TCustomForm of object; function(APersistent: TPersistent): TCustomForm of object;
var var
OnGetDesignerForm: TGetDesignerFormEvent = nil; OnGetDesignerForm: TGetDesignerFormEvent = nil;
function GetParentForm(Control:TControl): TCustomForm; function GetParentForm(Control:TControl): TCustomForm;
function GetFirstParentForm(Control:TControl): TCustomForm; function GetFirstParentForm(Control:TControl): TCustomForm;
function GetDesignerForm(AComponent: TComponent): TCustomForm; function GetDesignerForm(APersistent: TPersistent): TCustomForm;
function FindRootDesigner(AComponent: TComponent): TIDesigner; function FindRootDesigner(APersistent: TPersistent): TIDesigner;
function IsAccel(VK: word; const Str: string): Boolean; function IsAccel(VK: word; const Str: string): Boolean;
procedure NotifyApplicationUserInput(Msg: Cardinal); procedure NotifyApplicationUserInput(Msg: Cardinal);
@ -1705,12 +1705,12 @@ end;
//============================================================================== //==============================================================================
function FindRootDesigner(AComponent: TComponent): TIDesigner; function FindRootDesigner(APersistent: TPersistent): TIDesigner;
var var
Form: TCustomForm; Form: TCustomForm;
begin begin
Result:=nil; Result:=nil;
Form:=GetDesignerForm(AComponent); Form:=GetDesignerForm(APersistent);
if Form<>nil then if Form<>nil then
Result:=Form.Designer; Result:=Form.Designer;
end; end;
@ -1722,21 +1722,35 @@ begin
Result:=TCustomForm(Control); Result:=TCustomForm(Control);
end; end;
function GetDesignerForm(AComponent: TComponent): TCustomForm; function GetDesignerForm(APersistent: TPersistent): TCustomForm;
var
OwnerComponent: TComponent;
begin begin
if AComponent = nil then Exit(nil); if APersistent = nil then Exit(nil);
if Assigned(OnGetDesignerForm) then if Assigned(OnGetDesignerForm) then
Result := OnGetDesignerForm(AComponent) Result := OnGetDesignerForm(APersistent)
else else
begin begin
Result := nil; Result := nil;
OwnerComponent := AComponent; repeat
while OwnerComponent.Owner <> nil do if (APersistent is TComponent) then begin
OwnerComponent := OwnerComponent.Owner; if TComponent(APersistent).Owner<>nil then
if OwnerComponent is TCustomForm then APersistent:=TComponent(APersistent).Owner
Result := TCustomForm(OwnerComponent); else
exit;
end else if APersistent is TCollection then begin
if TCollection(APersistent).Owner<>nil then
APersistent:=TCollection(APersistent).Owner
else
exit;
end else if APersistent is TCollectionItem then begin
if TCollectionItem(APersistent).Collection<>nil then
APersistent:=TCollectionItem(APersistent).Collection
else
exit;
end else
exit;
until false;
if APersistent is TCustomForm then
Result := TCustomForm(APersistent);
end; end;
end; end;