IDE: designer forms are now created with delayed autosize

git-svn-id: trunk@24423 -
This commit is contained in:
mattias 2010-04-05 00:29:46 +00:00
parent ad982bfee9
commit e77e383461
7 changed files with 66 additions and 27 deletions

View File

@ -1871,6 +1871,7 @@ var
NewComponent: TComponent;
NewComponentClass: TComponentClass;
NewName: String;
DisableAutoSize: Boolean;
begin
if MouseDownComponent=nil then exit;
@ -1958,11 +1959,14 @@ var
// create component and component interface
DebugLn(['AddComponent ',DbgSName(NewComponentClass),' Parent=',DbgSName(NewParent),' ',NewLeft,',',NewTop,',',NewWidth,',',NewHeight]);
DisableAutoSize:={$IFDEF OldAutoSize}false{$ELSE}true{$ENDIF};
NewCI := TComponentInterface(TheFormEditor.CreateComponent(
ParentCI,NewComponentClass,'',
NewLeft,NewTop,NewWidth,NewHeight));
NewLeft,NewTop,NewWidth,NewHeight,DisableAutoSize));
if NewCI=nil then exit;
NewComponent:=NewCI.Component;
if DisableAutoSize and (NewComponent is TControl) then
TControl(NewComponent).EnableAutoSizing;
TheFormEditor.FixupReferences(NewComponent); // e.g. frame references a datamodule
// modified

View File

@ -148,7 +148,7 @@ type
DestroyDriver: Boolean); virtual;
function DoCreateJITComponent(const NewComponentName, NewClassName,
NewUnitName: shortstring; AncestorClass: TClass;
Visible: boolean):integer;
Visible, DisableAutoSize: boolean):integer;
procedure ReadInlineComponent(var Component: TComponent;
ComponentClass: TComponentClass; NewOwner: TComponent);
procedure DoFinishReading; virtual;
@ -160,11 +160,12 @@ type
property Items[Index: integer]: TComponent read GetItem; default;
function Count: integer;
function AddNewJITComponent(const NewUnitName: shortstring;
AncestorClass: TClass): integer;
AncestorClass: TClass;
DisableAutoSize: boolean): integer;
function AddJITComponentFromStream(BinStream: TStream;
AncestorClass: TClass;
const NewUnitName: ShortString;
Interactive, Visible: Boolean;
Interactive, Visible, DisableAutoSize: Boolean;
ContextObj: TObject): integer;
procedure DestroyJITComponent(JITComponent: TComponent);
procedure DestroyJITComponent(Index: integer);
@ -796,7 +797,7 @@ begin
end;
function TJITComponentList.AddNewJITComponent(const NewUnitName: shortstring;
AncestorClass: TClass): integer;
AncestorClass: TClass; DisableAutoSize: boolean): integer;
var
NewComponentName, NewClassName: shortstring;
begin
@ -810,13 +811,13 @@ begin
' NewUnitName=',NewUnitName,' AncestorClass=',AncestorClass.ClassName);
{$ENDIF}
Result:=DoCreateJITComponent(NewComponentName,NewClassName,NewUnitName,
AncestorClass,true);
AncestorClass,true,DisableAutoSize);
end;
function TJITComponentList.AddJITComponentFromStream(BinStream: TStream;
AncestorClass: TClass;
const NewUnitName: ShortString;
Interactive, Visible: Boolean;
Interactive, Visible, DisableAutoSize: Boolean;
ContextObj: TObject): integer;
// returns new index
// -1 = invalid stream
@ -904,7 +905,7 @@ begin
debugln('[TJITComponentList.AddJITComponentFromStream] Create ...');
{$ENDIF}
try
Result:=DoCreateJITComponent('',NewClassName,NewUnitName,AncestorClass,Visible);
Result:=DoCreateJITComponent('',NewClassName,NewUnitName,AncestorClass,Visible,DisableAutoSize);
if Result<0 then exit;
ReadAncestorStreams;
ReadStream(BinStream, FCurReadJITComponent.ClassType);
@ -994,7 +995,7 @@ end;
function TJITComponentList.DoCreateJITComponent(
const NewComponentName, NewClassName, NewUnitName: shortstring;
AncestorClass: TClass; Visible: boolean):integer;
AncestorClass: TClass; Visible, DisableAutoSize: boolean):integer;
var
Instance:TComponent;
ok: boolean;
@ -1015,6 +1016,8 @@ begin
NewUnitName);
//debugln('[TJITForms.DoCreateJITComponent] Creating an instance of JIT class "'+NewClassName+'" = class('+AncestorClass.ClassName+') ...');
Instance:=TComponent(FCurReadClass.NewInstance);
if DisableAutoSize and (Instance is TControl) then
TControl(Instance).DisableAutoSizing;
//debugln('[TJITForms.DoCreateJITComponent] Initializing new instance ... ',DbgS(Instance));
TComponent(FCurReadJITComponent):=Instance;
try

View File

@ -284,6 +284,7 @@ var
CompIntf, ParentCI: TIComponentInterface;
TypeClass: TComponentClass;
X, Y: integer;
DisableAutoSize: Boolean;
begin
if not Assigned(AComponent)
then Exit;
@ -301,9 +302,14 @@ begin
if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentCI,X,Y)
then exit;
CompIntf:=FormEditingHook.CreateComponent(ParentCI,TypeClass,'',X,Y,0,0);
if Assigned(CompIntf)
then GlobalDesignHook.PersistentAdded(CompIntf.Component,true);
DisableAutoSize:={$IFDEF OldAutoSize}false{$ELSE}true{$ENDIF};
CompIntf:=FormEditingHook.CreateComponent(ParentCI,TypeClass,'',X,Y,0,0,
DisableAutoSize);
if Assigned(CompIntf) then begin
if DisableAutoSize and (CompIntf.Component is TControl) then
TControl(CompIntf.Component).EnableAutoSizing;
GlobalDesignHook.PersistentAdded(CompIntf.Component,true);
end;
end;
procedure TComponentListForm.ListboxComponentsDblClick(Sender: TObject);

View File

@ -250,6 +250,7 @@ var
ParentCI: TIComponentInterface;
X, Y: integer;
CompIntf: TIComponentInterface;
DisableAutoSize: Boolean;
begin
//debugln('TComponentPalette.ComponentBtnDblClick ',TComponent(Sender).Name);
if SelectButton(TComponent(Sender)) and (FSelected<>nil) then begin
@ -265,8 +266,12 @@ begin
if not FormEditingHook.GetDefaultComponentPosition(TypeClass,ParentCI,X,Y)
then exit;
//debugln('TComponentPalette.ComponentBtnDblClick ',dbgsName(Sender),' ',dbgs(X),',',dbgs(Y));
CompIntf:=FormEditingHook.CreateComponent(ParentCI,TypeClass,'',X,Y,0,0);
DisableAutoSize:={$IFDEF OldAutoSize}false{$ELSE}true{$ENDIF};
CompIntf:=FormEditingHook.CreateComponent(ParentCI,TypeClass,'',X,Y,0,0,
DisableAutoSize);
if CompIntf<>nil then begin
if DisableAutoSize and (CompIntf.Component is TControl) then
TControl(CompIntf.Component).EnableAutoSizing;
GlobalDesignHook.PersistentAdded(CompIntf.Component,true);
end;
end;

View File

@ -254,18 +254,21 @@ each control that's dropped onto the form
function CreateComponent(ParentCI: TIComponentInterface;
TypeClass: TComponentClass;
const AUnitName: shortstring;
NewLeft,NewTop,NewWidth,NewHeight: Integer): TIComponentInterface; override;
NewLeft,NewTop,NewWidth,NewHeight: Integer;
DisableAutoSize: boolean): TIComponentInterface; override;
function CreateComponentFromStream(BinStream: TStream;
AncestorType: TComponentClass;
const NewUnitName: ShortString;
Interactive: boolean;
Visible: boolean = true;
DisableAutoSize: boolean = false;
ContextObj: TObject = nil): TIComponentInterface; override;
function CreateRawComponentFromStream(BinStream: TStream;
AncestorType: TComponentClass;
const NewUnitName: ShortString;
Interactive: boolean;
Visible: boolean = true;
DisableAutoSize: boolean = false;
ContextObj: TObject = nil): TComponent;
function CreateChildComponentFromStream(BinStream: TStream;
ComponentClass: TComponentClass; Root: TComponent;
@ -1578,8 +1581,9 @@ begin
end;
function TCustomFormEditor.CreateComponent(ParentCI: TIComponentInterface;
TypeClass: TComponentClass; const AUnitName: shortstring; NewLeft, NewTop, NewWidth, NewHeight: Integer
): TIComponentInterface;
TypeClass: TComponentClass; const AUnitName: shortstring;
NewLeft, NewTop, NewWidth, NewHeight: Integer;
DisableAutoSize: boolean): TIComponentInterface;
const
PreferredDistanceMin = 30;
PreferredDistanceMax = 250;
@ -1636,6 +1640,8 @@ begin
OwnerComponent := OwnerComponent.Owner;
try
NewComponent := TComponent(TypeClass.newinstance);
if DisableAutoSize and (NewComponent is TControl) then
TControl(NewComponent).DisableAutoSizing;
SetComponentDesignMode(NewComponent,true);
if DescendFromDesignerBaseClass(TypeClass)>=0 then begin
// this class can have its own lfm streams (e.g. a TFrame)
@ -1699,7 +1705,7 @@ begin
JITList:=GetJITListOfType(TypeClass);
if JITList=nil then
RaiseException('TCustomFormEditor.CreateComponent '+TypeClass.ClassName);
NewJITIndex := JITList.AddNewJITComponent(NewUnitName,TypeClass);
NewJITIndex := JITList.AddNewJITComponent(NewUnitName,TypeClass,DisableAutoSize);
if NewJITIndex < 0 then
exit;
// create component interface
@ -1881,20 +1887,20 @@ function TCustomFormEditor.CreateComponentFromStream(
BinStream: TStream;
AncestorType: TComponentClass;
const NewUnitName: ShortString;
Interactive: boolean; Visible: boolean;
Interactive: boolean; Visible: boolean; DisableAutoSize: boolean;
ContextObj: TObject): TIComponentInterface;
var
NewComponent: TComponent;
begin
NewComponent:=CreateRawComponentFromStream(BinStream,
AncestorType,NewUnitName,Interactive,Visible,ContextObj);
AncestorType,NewUnitName,Interactive,Visible,DisableAutoSize,ContextObj);
Result:=CreateComponentInterface(NewComponent,true);
end;
function TCustomFormEditor.CreateRawComponentFromStream(BinStream: TStream;
AncestorType: TComponentClass;
const NewUnitName: ShortString;
Interactive: boolean; Visible: boolean;
Interactive: boolean; Visible: boolean; DisableAutoSize: boolean;
ContextObj: TObject): TComponent;
var
NewJITIndex: integer;
@ -1906,7 +1912,8 @@ begin
RaiseException('TCustomFormEditor.CreateComponentFromStream ClassName='+
AncestorType.ClassName);
NewJITIndex := JITList.AddJITComponentFromStream(BinStream,
AncestorType,NewUnitName,Interactive,Visible,ContextObj);
AncestorType,NewUnitName,Interactive,Visible,DisableAutoSize,
ContextObj);
if NewJITIndex < 0 then begin
Result:=nil;
exit;

View File

@ -648,7 +648,8 @@ type
NewOwner: TObject; NewFilename: string; var NewCodeBuffer: TCodeBuffer;
var NewUnitName: string; AskForFilename: boolean): TModalResult;
function CreateNewForm(NewUnitInfo: TUnitInfo;
AncestorType: TPersistentClass; ResourceCode: TCodeBuffer; UseCreateFormStatements: Boolean): TModalResult;
AncestorType: TPersistentClass; ResourceCode: TCodeBuffer;
UseCreateFormStatements, DisableAutoSize: Boolean): TModalResult;
// methods for 'save unit'
function DoShowSaveFileAsDialog(var AFilename: string; AnUnitInfo: TUnitInfo;
@ -4662,7 +4663,7 @@ end;
function TMainIDE.CreateNewForm(NewUnitInfo: TUnitInfo;
AncestorType: TPersistentClass; ResourceCode: TCodeBuffer;
UseCreateFormStatements: Boolean): TModalResult;
UseCreateFormStatements, DisableAutoSize: Boolean): TModalResult;
var
CInterface: TComponentInterface;
NewComponent: TComponent;
@ -4695,7 +4696,7 @@ begin
// create jit component
CInterface := TComponentInterface(
FormEditor1.CreateComponent(nil,TComponentClass(AncestorType),
NewUnitInfo.CreateUnitName, new_x, new_y, 0,0));
NewUnitInfo.CreateUnitName, new_x, new_y, 0,0,DisableAutoSize));
if CInterface=nil then begin
DebugLn(['TMainIDE.CreateNewForm FormEditor1.CreateComponent failed ',dbgsName(TComponentClass(AncestorType))]);
exit(mrCancel);
@ -5938,6 +5939,7 @@ var
NestedClassName: string;
NestedClass: TComponentClass;
NestedUnitInfo: TUnitInfo;
DisableAutoSize: Boolean;
begin
{$IFDEF IDE_DEBUG}
debugln('TMainIDE.DoLoadLFM A ',AnUnitInfo.Filename,' IsPartOfProject=',dbgs(AnUnitInfo.IsPartOfProject),' ');
@ -5945,6 +5947,7 @@ begin
ReferencesLocked:=false;
MissingClasses:=nil;
NewComponent:=nil;
try
if (ofRevert in OpenFlags) and (AnUnitInfo.Component<>nil) then begin
// the component must be destroyed and recreated
@ -6083,8 +6086,11 @@ begin
if NewUnitName='' then
NewUnitName:=ExtractFileNameOnly(AnUnitInfo.Filename);
// ToDo: create AncestorBinStream(s) via hook, not via parameters
DisableAutoSize:={$IFDEF OldAutoSize}false{$ELSE}true{$ENDIF};
NewComponent:=FormEditor1.CreateRawComponentFromStream(BinStream,
AncestorType,copy(NewUnitName,1,255),true,true,AnUnitInfo);
AncestorType,copy(NewUnitName,1,255),true,true,DisableAutoSize,AnUnitInfo);
if DisableAutoSize and (NewComponent is TControl) then
TControl(NewComponent).EnableAutoSizing;
Project1.InvalidateUnitComponentDesignerDependencies;
AnUnitInfo.Component:=NewComponent;
if (AncestorUnitInfo<>nil) then
@ -7739,6 +7745,7 @@ var
ResType: TResourceType;
SrcNoteBook: TSourceNotebook;
AShareEditor: TSourceEditor;
DisableAutoSize: Boolean;
begin
//debugln('TMainIDE.DoNewEditorFile A NewFilename=',NewFilename);
// empty NewFilename is ok, it will be auto generated
@ -7859,8 +7866,13 @@ begin
end else begin
// create a designer form for a form/datamodule/frame
//DebugLn(['TMainIDE.DoNewFile Name=',NewFileDescriptor.Name,' Class=',NewFileDescriptor.ClassName]);
DisableAutoSize:={$IFDEF OldAutoSize}false{$ELSE}true{$ENDIF};
Result := CreateNewForm(NewUnitInfo, AncestorType, nil,
NewFileDescriptor.UseCreateFormStatements);
NewFileDescriptor.UseCreateFormStatements,
DisableAutoSize);
if DisableAutoSize and (NewUnitInfo.Component<>nil)
and (NewUnitInfo.Component is TControl) then
TControl(NewUnitInfo.Component).EnableAutoSizing;
end;
if Result<>mrOk then exit;
end;

View File

@ -169,12 +169,14 @@ type
function CreateComponent(ParentCI: TIComponentInterface;
TypeClass: TComponentClass;
const AUnitName: shortstring;
X,Y,W,H: Integer): TIComponentInterface; virtual; abstract;
X,Y,W,H: Integer;
DisableAutoSize: boolean): TIComponentInterface; virtual; abstract;
function CreateComponentFromStream(BinStream: TStream;
AncestorType: TComponentClass;
const NewUnitName: ShortString;
Interactive: boolean;
Visible: boolean = true;
DisableAutoSize: boolean = false;
ContextObj: TObject = nil): TIComponentInterface; virtual; abstract;
function CreateChildComponentFromStream(BinStream: TStream;
ComponentClass: TComponentClass;