IDE: implemented creating designer for hidden component

git-svn-id: trunk@10045 -
This commit is contained in:
mattias 2006-10-06 17:28:20 +00:00
parent d7d43ee618
commit b6f164d0aa
4 changed files with 61 additions and 25 deletions

View File

@ -485,6 +485,8 @@ begin
GlobalDesignHook.PersistentDeleting(FLookupRoot); GlobalDesignHook.PersistentDeleting(FLookupRoot);
end; end;
// delete // delete
if Form<>nil then
Form.Designer:=nil;
TheFormEditor.DeleteComponent(FLookupRoot,FreeComponent); TheFormEditor.DeleteComponent(FLookupRoot,FreeComponent);
end; end;
Free; Free;

View File

@ -39,7 +39,7 @@ uses
MemCheck, MemCheck,
{$ENDIF} {$ENDIF}
// LCL+FCL // LCL+FCL
Classes, SysUtils, TypInfo, Math, Classes, SysUtils, TypInfo, Math, LCLIntf, LCLType,
AVL_Tree, AVL_Tree,
LCLProc, Graphics, Controls, Forms, Menus, Dialogs, LCLProc, Graphics, Controls, Forms, Menus, Dialogs,
// components // components
@ -832,12 +832,13 @@ var
CompIntf : TComponentInterface; CompIntf : TComponentInterface;
i: integer; i: integer;
AForm: TCustomForm; AForm: TCustomForm;
AWinControl: TWinControl;
Begin Begin
CompIntf := TComponentInterface(FindComponent(AComponent)); CompIntf := TComponentInterface(FindComponent(AComponent));
if CompIntf <> nil then if CompIntf <> nil then
FComponentInterfaces.Remove(CompIntf); FComponentInterfaces.Remove(CompIntf);
DebugLn(['TCustomFormEditor.DeleteControl ',DbgSName(AComponent),' IsJITComponent=',IsJITComponent(AComponent)]); DebugLn(['TCustomFormEditor.DeleteComponent ',DbgSName(AComponent),' IsJITComponent=',IsJITComponent(AComponent),' FreeComponent=',FreeComponent]);
if IsJITComponent(AComponent) then begin if IsJITComponent(AComponent) then begin
// value is a top level component // value is a top level component
i:=AComponent.ComponentCount-1; i:=AComponent.ComponentCount-1;
@ -857,7 +858,7 @@ Begin
// free/unbind a non form component and its designer form // free/unbind a non form component and its designer form
AForm:=GetDesignerForm(AComponent); AForm:=GetDesignerForm(AComponent);
if (AForm<>nil) and (not (AForm is TNonControlDesignerForm)) then if (AForm<>nil) and (not (AForm is TNonControlDesignerForm)) then
RaiseException('TCustomFormEditor.DeleteControl Where is the TNonControlDesignerForm? '+AComponent.ClassName); RaiseException('TCustomFormEditor.DeleteComponent Where is the TNonControlDesignerForm? '+AComponent.ClassName);
if AForm<>nil then begin if AForm<>nil then begin
FNonControlForms.Remove(AForm); FNonControlForms.Remove(AForm);
TNonControlDesignerForm(AForm).LookupRoot:=nil; TNonControlDesignerForm(AForm).LookupRoot:=nil;
@ -866,7 +867,7 @@ Begin
if FreeComponent then if FreeComponent then
JITNonFormList.DestroyJITComponent(AComponent); JITNonFormList.DestroyJITComponent(AComponent);
end else end else
RaiseException('TCustomFormEditor.DeleteControl '+AComponent.ClassName); RaiseException('TCustomFormEditor.DeleteComponent '+AComponent.ClassName);
CompIntf.Free; CompIntf.Free;
end end
else if CompIntf<>nil then begin else if CompIntf<>nil then begin
@ -876,9 +877,19 @@ Begin
else else
CompIntf.Free; CompIntf.Free;
end else if FreeComponent then begin end else if FreeComponent then begin
DebugLn(['WARNING: TCustomFormEditor.DeleteComponent freeing orphaned component ',DbgSName(AComponent)]); if (AComponent.Owner=nil) then
DebugLn(['WARNING: TCustomFormEditor.DeleteComponent freeing orphaned component ',DbgSName(AComponent)]);
TryFreeComponent(AComponent); TryFreeComponent(AComponent);
end; end;
// if not free, then free the handle to hide it
if (not FreeComponent) and (AComponent is TWinControl) then begin
AWinControl:=TWinControl(AComponent);
if AWinControl.HandleAllocated and (AWinControl.Parent=nil) then begin
AWinControl.ControlStyle:=AWinControl.ControlStyle+[csNoDesignVisible];
LCLIntf.ShowWindow(AWinControl.Handle,SW_HIDE);
DebugLn(['TCustomFormEditor.DeleteComponent Hiding: ',dbgsName(AWinControl)]);
end;
end;
end; end;
Function TCustomFormEditor.FindComponentByName( Function TCustomFormEditor.FindComponentByName(
@ -1074,6 +1085,7 @@ var
OwnerComponent: TComponent; OwnerComponent: TComponent;
begin begin
Result:=nil; Result:=nil;
if AComponent=nil then exit;
OwnerComponent:=AComponent; OwnerComponent:=AComponent;
while OwnerComponent.Owner<>nil do while OwnerComponent.Owner<>nil do
OwnerComponent:=OwnerComponent.Owner; OwnerComponent:=OwnerComponent.Owner;

View File

@ -729,8 +729,8 @@ type
var ActiveSourceEditor: TSourceEditor; var ActiveUnitInfo: TUnitInfo); override; var ActiveSourceEditor: TSourceEditor; var ActiveUnitInfo: TUnitInfo); override;
function GetDesignerWithProjectFile(AFile: TLazProjectFile; function GetDesignerWithProjectFile(AFile: TLazProjectFile;
LoadForm: boolean): TIDesigner; override; LoadForm: boolean): TIDesigner; override;
function GetFormOfSource(AnUnitInfo: TUnitInfo; function GetDesignerFormOfSource(AnUnitInfo: TUnitInfo;
LoadForm: boolean): TCustomForm; LoadForm: boolean): TCustomForm;
function GetProjectFileWithRootComponent(AComponent: TComponent): TLazProjectFile; override; function GetProjectFileWithRootComponent(AComponent: TComponent): TLazProjectFile; override;
function GetProjectFileWithDesigner(ADesigner: TIDesigner): TLazProjectFile; override; function GetProjectFileWithDesigner(ADesigner: TIDesigner): TLazProjectFile; override;
procedure GetObjectInspectorUnit( procedure GetObjectInspectorUnit(
@ -4805,8 +4805,9 @@ begin
if Result<>mrOk then exit; if Result<>mrOk then exit;
// check installed packages // check installed packages
if (AnUnitInfo.Component=nil) and AnUnitInfo.IsPartOfProject then begin if (AnUnitInfo.Component=nil) and AnUnitInfo.IsPartOfProject
// opening a single form of the project -> check installed packages and (not (ofProjectLoading in OpenFlags)) then begin
// opening a form of the project -> check installed packages
Result:=PkgBoss.CheckProjectHasInstalledPackages(Project1); Result:=PkgBoss.CheckProjectHasInstalledPackages(Project1);
if not (Result in [mrOk,mrIgnore]) then exit; if not (Result in [mrOk,mrIgnore]) then exit;
end; end;
@ -4863,11 +4864,12 @@ begin
// try loading the ancestor first (unit, lfm and component instance) // try loading the ancestor first (unit, lfm and component instance)
if (AncestorType=nil) then begin if (AncestorType=nil) then begin
Result:=DoLoadComponentDependencyHidden(AnUnitInfo,AncestorClassName,OpenFlags, Result:=DoLoadComponentDependencyHidden(AnUnitInfo,AncestorClassName,
AncestorType,AncestorUnitInfo); OpenFlags,AncestorType,AncestorUnitInfo);
if Result=mrAbort then exit; if Result=mrAbort then exit;
if Result=mrOk then begin if Result=mrOk then begin
Result:=DoSaveFileResourceToBinStream(AncestorUnitInfo,AncestorBinStream); Result:=DoSaveFileResourceToBinStream(AncestorUnitInfo,
AncestorBinStream);
if Result<>mrOk then exit; if Result<>mrOk then exit;
AncestorBinStream.Position:=0; AncestorBinStream.Position:=0;
end else begin end else begin
@ -4938,9 +4940,10 @@ begin
end; end;
end else begin end else begin
// keep old instance, just add a designer // keep old instance, just add a designer
NewComponent:=AnUnitInfo.Component; DebugLn(['TMainIDE.DoLoadLFM Creating designer for hidden component of ',AnUnitInfo.Filename]);
end; end;
NewComponent:=AnUnitInfo.Component;
// create the designer // create the designer
if ([ofProjectLoading,ofLoadHiddenResource]*OpenFlags=[]) then if ([ofProjectLoading,ofLoadHiddenResource]*OpenFlags=[]) then
FormEditor1.ClearSelection; FormEditor1.ClearSelection;
@ -4951,7 +4954,7 @@ begin
DesignerForm:=nil; DesignerForm:=nil;
if not (ofLoadHiddenResource in OpenFlags) then begin if not (ofLoadHiddenResource in OpenFlags) then begin
CreateDesignerForComponent(NewComponent); CreateDesignerForComponent(NewComponent);
DesignerForm:=FormEditor1.GetDesignerForm(AnUnitInfo.Component); DesignerForm:=FormEditor1.GetDesignerForm(NewComponent);
end; end;
// select the new form (object inspector, formeditor, control selection) // select the new form (object inspector, formeditor, control selection)
@ -4963,6 +4966,10 @@ begin
// show new form // show new form
if DesignerForm<>nil then begin if DesignerForm<>nil then begin
DesignerForm.ControlStyle:=DesignerForm.ControlStyle-[csNoDesignVisible];
if NewComponent is TControl then
TControl(NewComponent).ControlStyle:=
TControl(NewComponent).ControlStyle-[csNoDesignVisible];
LCLIntf.ShowWindow(DesignerForm.Handle,SW_SHOWNORMAL); LCLIntf.ShowWindow(DesignerForm.Handle,SW_SHOWNORMAL);
FLastFormActivated:=DesignerForm; FLastFormActivated:=DesignerForm;
end; end;
@ -5147,6 +5154,7 @@ function TMainIDE.CloseUnitComponent(AnUnitInfo: TUnitInfo; Flags: TCloseFlags
begin begin
CompUnitInfo:=Project1.FirstUnitWithComponent; CompUnitInfo:=Project1.FirstUnitWithComponent;
while CompUnitInfo<>nil do begin while CompUnitInfo<>nil do begin
DebugLn(['FreeUnusedComponents ',CompUnitInfo.Filename,' ',dbgsName(CompUnitInfo.Component),' UnitComponentIsUsed=',UnitComponentIsUsed(CompUnitInfo,true)]);
if not UnitComponentIsUsed(CompUnitInfo,true) then begin if not UnitComponentIsUsed(CompUnitInfo,true) then begin
CloseUnitComponent(CompUnitInfo,Flags); CloseUnitComponent(CompUnitInfo,Flags);
exit; exit;
@ -5162,6 +5170,7 @@ var
begin begin
LookupRoot:=AnUnitInfo.Component; LookupRoot:=AnUnitInfo.Component;
if LookupRoot=nil then exit(mrOk); if LookupRoot=nil then exit(mrOk);
DebugLn(['TMainIDE.CloseUnitComponent ',AnUnitInfo.Filename,' ',dbgsName(LookupRoot)]);
// save // save
if (cfSaveFirst in Flags) and (AnUnitInfo.EditorIndex>=0) then begin if (cfSaveFirst in Flags) and (AnUnitInfo.EditorIndex>=0) then begin
@ -5197,7 +5206,6 @@ begin
if UnitComponentIsUsed(AnUnitInfo,false) then begin if UnitComponentIsUsed(AnUnitInfo,false) then begin
// free designer, keep component hidden // free designer, keep component hidden
DebugLn(['TMainIDE.CloseUnitComponent hiding component and freeing designer: ',AnUnitInfo.Filename,' ',DbgSName(AnUnitInfo.Component)]); DebugLn(['TMainIDE.CloseUnitComponent hiding component and freeing designer: ',AnUnitInfo.Filename,' ',DbgSName(AnUnitInfo.Component)]);
LCLIntf.ShowWindow(AForm.Handle,SW_HIDE);
OldDesigner.FreeDesigner(false); OldDesigner.FreeDesigner(false);
end else begin end else begin
// free designer and design form // free designer and design form
@ -5251,7 +5259,7 @@ begin
// check if a designer is open // check if a designer is open
if CheckHasDesigner then begin if CheckHasDesigner then begin
AForm:=FormEditor1.GetDesignerForm(LookupRoot); AForm:=FormEditor1.GetDesignerForm(LookupRoot);
if AForm<>nil then exit(true); if (AForm<>nil) and (AForm.Designer<>nil) then exit(true);
end; end;
// check if another component uses this component // check if another component uses this component
if Project1.UnitUsingComponentUnit(AnUnitInfo)<>nil then if Project1.UnitUsingComponentUnit(AnUnitInfo)<>nil then
@ -6473,7 +6481,7 @@ Begin
if Result=mrAbort then exit; if Result=mrAbort then exit;
end; end;
if OnlyForms and (AnUnitInfo.ComponentName<>'') then begin if OnlyForms and (AnUnitInfo.ComponentName<>'') then begin
AForm:=GetFormOfSource(AnUnitInfo,true); AForm:=GetDesignerFormOfSource(AnUnitInfo,true);
if AForm<>nil then if AForm<>nil then
ShowDesignerForm(AForm); ShowDesignerForm(AForm);
end; end;
@ -8754,7 +8762,7 @@ var
AForm: TCustomForm; AForm: TCustomForm;
begin begin
AnUnitInfo:=AFile as TUnitInfo; AnUnitInfo:=AFile as TUnitInfo;
AForm:=GetFormOfSource(AnUnitInfo,LoadForm); AForm:=GetDesignerFormOfSource(AnUnitInfo,LoadForm);
if AForm<>nil then if AForm<>nil then
Result:=AForm.Designer; Result:=AForm.Designer;
end; end;
@ -9189,7 +9197,7 @@ begin
GetCurrentUnit(ActiveSourceEditor,ActiveUnitInfo); GetCurrentUnit(ActiveSourceEditor,ActiveUnitInfo);
if (ActiveUnitInfo = nil) then exit; if (ActiveUnitInfo = nil) then exit;
// load the form, if not already done // load the form, if not already done
AForm:=GetFormOfSource(ActiveUnitInfo,true); AForm:=GetDesignerFormOfSource(ActiveUnitInfo,true);
if AForm=nil then exit; if AForm=nil then exit;
FDisplayState:= dsForm; FDisplayState:= dsForm;
FLastFormActivated:=AForm; FLastFormActivated:=AForm;
@ -11943,16 +11951,21 @@ begin
end; end;
end; end;
function TMainIDE.GetFormOfSource(AnUnitInfo: TUnitInfo; LoadForm: boolean function TMainIDE.GetDesignerFormOfSource(AnUnitInfo: TUnitInfo; LoadForm: boolean
): TCustomForm; ): TCustomForm;
begin begin
Result:=nil; Result:=nil;
if (AnUnitInfo.Component=nil) and LoadForm
and FilenameIsPascalSource(AnUnitInfo.Filename) then begin
DoLoadLFM(AnUnitInfo,[],[]);
end;
if AnUnitInfo.Component<>nil then if AnUnitInfo.Component<>nil then
Result:=FormEditor1.GetDesignerForm(AnUnitInfo.Component); Result:=FormEditor1.GetDesignerForm(AnUnitInfo.Component);
if ((Result=nil) or (Result.Designer=nil)) and LoadForm
and FilenameIsPascalSource(AnUnitInfo.Filename) then begin
DebugLn(['TMainIDE.GetFormOfSource ',AnUnitInfo.Filename,' ',dbgsName(AnUnitInfo.Component)]);
DoLoadLFM(AnUnitInfo,[],[]);
end;
if (Result=nil) and (AnUnitInfo.Component<>nil) then
Result:=FormEditor1.GetDesignerForm(AnUnitInfo.Component);
if (Result<>nil) and (Result.Designer=nil) then
Result:=nil;
end; end;
function TMainIDE.GetProjectFileWithRootComponent(AComponent: TComponent function TMainIDE.GetProjectFileWithRootComponent(AComponent: TComponent

View File

@ -9346,6 +9346,8 @@ begin
GtkWindow:=PGtkWindow(hWnd); GtkWindow:=PGtkWindow(hWnd);
if GtkWindow=nil then if GtkWindow=nil then
RaiseGDBException('TGtkWidgetSet.ShowWindow hWnd is nil'); RaiseGDBException('TGtkWidgetSet.ShowWindow hWnd is nil');
if not GtkWidgetIsA(PGtkWidget(GtkWindow),GTK_TYPE_WINDOW) then
RaiseGDBException('TGtkWidgetSet.ShowWindow hWnd is not a gtkwindow');
{$IFDEF Gtk2} {$IFDEF Gtk2}
//debugln('TGtkWidgetSet.ShowWindow A ',GetWidgetDebugReport(PGtkWidget(GtkWindow)),' nCmdShow=',dbgs(nCmdShow),' SW_MINIMIZE=',dbgs(SW_MINIMIZE=nCmdShow)); //debugln('TGtkWidgetSet.ShowWindow A ',GetWidgetDebugReport(PGtkWidget(GtkWindow)),' nCmdShow=',dbgs(nCmdShow),' SW_MINIMIZE=',dbgs(SW_MINIMIZE=nCmdShow));
@ -9358,6 +9360,9 @@ begin
gtk_window_unmaximize(GtkWindow); gtk_window_unmaximize(GtkWindow);
end; end;
SW_HIDE:
gdk_window_hide(PgtkWidget(GtkWindow)^.Window);
SW_MINIMIZE: SW_MINIMIZE:
gtk_window_iconify(GtkWindow); gtk_window_iconify(GtkWindow);
@ -9377,6 +9382,11 @@ begin
{$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF} {$IFDEF DebugGDKTraps}EndGDKErrorTrap;{$ENDIF}
end; end;
SW_HIDE:
begin
gdk_window_hide(PgtkWidget(GtkWindow)^.Window);
end;
SW_MINIMIZE: SW_MINIMIZE:
begin begin
GDK_WINDOW_MINIMIZE(PGdkWindowPrivate(PgtkWidget(GtkWindow)^.Window)); GDK_WINDOW_MINIMIZE(PGdkWindowPrivate(PgtkWidget(GtkWindow)^.Window));
@ -9386,7 +9396,6 @@ begin
GDK_WINDOW_MAXIMIZE(PGdkWindowPrivate(PgtkWidget(GtkWindow)^.Window)); GDK_WINDOW_MAXIMIZE(PGdkWindowPrivate(PgtkWidget(GtkWindow)^.Window));
end; end;
end; end;
Result:=true; Result:=true;