Changes from Mattias and I.

Shane

git-svn-id: trunk@65 -
This commit is contained in:
lazarus 2000-12-15 18:25:17 +00:00
parent 5546bff903
commit bfde22b079
4 changed files with 1276 additions and 527 deletions

View File

@ -70,14 +70,6 @@ uses
var
GridPoints : TGridPoint;
Function TDesigner.GetFormAncestor : String;
var
PI : PTypeInfo;
begin
PI := FCustomForm.ClassInfo;
Result := PI^.Name;
Delete(Result,1,1);
end;
constructor TDesigner.Create(CustomForm : TCustomForm);
var
@ -120,6 +112,16 @@ Begin
Inherited;
end;
Function TDesigner.GetFormAncestor : String;
var
PI : PTypeInfo;
begin
PI := FCustomForm.ClassInfo;
Result := PI^.Name;
Delete(Result,1,1);
end;
procedure TDesigner.CreateNew(FileName : string);
begin
@ -215,13 +217,11 @@ For I := 0 to FSource.Count-1 do
end;
procedure TDesigner.Notification(AComponent: TComponent; Operation: TOperation);
Begin
if Operation = opInsert then
Begin
// AddControlCode(AComponent);
end
if Operation = opInsert then
begin
end
else
if Operation = opRemove then
begin

File diff suppressed because it is too large Load Diff

View File

@ -30,58 +30,55 @@ uses
Const OrdinalTypes = [tkInteger,tkChar,tkENumeration,tkbool];
type
{
TComponentInterface is derived from TIComponentInterface. It gives access to
each control that's dropped onto the form
}
TCustomFormEditor = class; //forward declaration
TSetProc = Procedure (const Value) of Object;
TGetProc = Function : Variant of Object;
TCustomFormEditor = class; //forward declaration
TSetProc = Procedure (const Value) of Object;
TGetProc = Function : Variant of Object;
TComponentInterface = class(TIComponentInterface)
private
FControl : TComponent;
FFormEditor : TCustomFormEditor; //used to call it's functions
Function FSetProp(PRI : PPropInfo; const Value) : Boolean;
Function FGetProp(PRI : PPropInfo; var Value) : Boolean;
protected
Function GetPPropInfobyIndex(Index : Integer) : PPropInfo;
Function GetPPropInfobyName(Name : String) : PPropInfo;
MySetProc : TSetPRoc;
MyGetProc : TGetProc;
public
constructor Create;
destructor Destroy; override;
private
FControl : TComponent;
FFormEditor : TCustomFormEditor; //used to call it's functions
Function FSetProp(PRI : PPropInfo; const Value) : Boolean;
Function FGetProp(PRI : PPropInfo; var Value) : Boolean;
Function GetComponentType : String; override;
Function GetComponentHandle : LongInt; override;
Function GetParent : TIComponentInterface; override;
Function IsTControl : Boolean; override;
Function GetPropCount : Integer; override;
Function GetPropType(Index : Integer) : TTypeKind; override;
Function GetPropName(Index : Integer) : String; override;
Function GetPropTypebyName(Name : String) : TTypeKind; override;
protected
Function GetPPropInfobyIndex(Index : Integer) : PPropInfo;
Function GetPPropInfobyName(Name : String) : PPropInfo;
MySetProc : TSetPRoc;
MyGetProc : TGetProc;
public
constructor Create;
destructor Destroy; override;
Function GetPropValue(Index : Integer; var Value) : Boolean; override;
Function GetPropValuebyName(Name: String; var Value) : Boolean; override;
Function SetProp(Index : Integer; const Value) : Boolean; override;
Function SetPropbyName(Name : String; const Value) : Boolean; override;
Function GetComponentType : String; override;
Function GetComponentHandle : LongInt; override;
Function GetParent : TIComponentInterface; override;
Function IsTControl : Boolean; override;
Function GetPropCount : Integer; override;
Function GetPropType(Index : Integer) : TTypeKind; override;
Function GetPropName(Index : Integer) : String; override;
Function GetPropTypebyName(Name : String) : TTypeKind; override;
Function GetControlCount: Integer; override;
Function GetControl(Index : Integer): TIComponentInterface; override;
Function GetPropValue(Index : Integer; var Value) : Boolean; override;
Function GetPropValuebyName(Name: String; var Value) : Boolean; override;
Function SetProp(Index : Integer; const Value) : Boolean; override;
Function SetPropbyName(Name : String; const Value) : Boolean; override;
Function GetComponentCount: Integer; override;
Function GetComponent(Index : Integer): TIComponentInterface; override;
Function GetControlCount: Integer; override;
Function GetControl(Index : Integer): TIComponentInterface; override;
Function Select : Boolean; override;
Function Focus : Boolean; override;
Function Delete : Boolean; override;
property Control : TComponent read FCOntrol;
Function GetComponentCount: Integer; override;
Function GetComponent(Index : Integer): TIComponentInterface; override;
Function Select : Boolean; override;
Function Focus : Boolean; override;
Function Delete : Boolean; override;
property Control : TComponent read FCOntrol;
end;
{
@ -98,9 +95,7 @@ TCustomFormEditor
FSelectedComponents : TComponentSelectionList;
FObj_Inspector : TObjectInspector;
protected
public
constructor Create;
destructor Destroy; override;
@ -111,8 +106,8 @@ TCustomFormEditor
Function FindComponent(AComponent: TComponent): TIComponentInterface; override;
Function GetFormComponent : TIComponentInterface; override;
// Function CreateComponent(CI : TIComponentInterface; TypeName : String;
Function CreateComponent(CI : TIComponentInterface; TypeClass : TComponentClass;
X,Y,W,H : Integer): TIComponentInterface; override;
Function CreateComponent(ParentCI : TIComponentInterface;
TypeClass : TComponentClass; X,Y,W,H : Integer): TIComponentInterface; override;
Procedure ClearSelected;
property SelectedComponents : TComponentSelectionList read FSelectedComponents write FSelectedComponents;
property Obj_Inspector : TObjectInspector read FObj_Inspector write FObj_Inspector;
@ -121,54 +116,59 @@ TCustomFormEditor
implementation
uses
SysUtils;
{TComponentInterface}
constructor TComponentInterface.Create;
begin
inherited;
inherited Create;
end;
destructor TComponentInterface.Destroy;
begin
inherited;
inherited Destroy;
end;
Function TComponentInterface.FSetProp(PRI : PPropInfo; const Value) : Boolean;
Function TComponentInterface.FSetProp(PRI : PPropInfo;
const Value) : Boolean;
Begin
case PRI^.PropType^.Kind of
tkBool: SetOrdProp(FControl,PRI,longint(Value));
tkSString,
tkLString,
tkAString,
tkWString : Begin
Writeln('String...');
SetStrProp(FControl,PRI,String(Value));
end;
tkInteger,
tkInt64 : Begin
Writeln('Int64...');
SetInt64Prop(FControl,PRI,Int64(Value));
end;
tkFloat : Begin
Writeln('Float...');
SetFloatProp(FControl,PRI,Extended(Value));
end;
tkVariant : Begin
Writeln('Variant...');
SetVariantProp(FControl,PRI,Variant(Value));
end;
tkMethod : Begin
Writeln('Method...');
SetMethodProp(FControl,PRI,TMethod(value));
end;
else
Result := False;
end;//case
case PRI^.PropType^.Kind of
tkBool: SetOrdProp(FControl,PRI,longint(Value));
tkSString,
tkLString,
tkAString,
tkWString : Begin
Writeln('String...');
SetStrProp(FControl,PRI,String(Value));
Result := True;
end;
tkInteger,
tkInt64 : Begin
Writeln('Int64...');
SetInt64Prop(FControl,PRI,Int64(Value));
Result := True;
end;
tkFloat : Begin
Writeln('Float...');
SetFloatProp(FControl,PRI,Extended(Value));
Result := True;
end;
tkVariant : Begin
Writeln('Variant...');
SetVariantProp(FControl,PRI,Variant(Value));
Result := True;
end;
tkMethod : Begin
Writeln('Method...');
SetMethodProp(FControl,PRI,TMethod(value));
Result := True;
end;
else
Result := False;
end;//case
end;
Function TComponentInterface.FGetProp(PRI : PPropInfo; var Value) : Boolean;
@ -208,20 +208,23 @@ Result := True;
end;
Function TComponentInterface.GetPPropInfoByIndex(Index:Integer): PPropInfo;
var
PT : PTypeData;
PP : PPropList;
PI : PTypeInfo;
PT : PTypeData;
PP : PPropList;
PI : PTypeInfo;
Begin
PI := FControl.ClassInfo;
PT:=GetTypeData(PI);
GetMem (PP,PT^.PropCount*SizeOf(Pointer));
GetPropInfos(PI,PP);
if Index < PT^.PropCount then
Result:=PP^[index]
else
Result := nil;
Result:=PP^[index]
else
Result := nil;
//does freeing this kill my result? Check this...
// Freemem(PP);
@ -229,10 +232,10 @@ end;
Function TComponentInterface.GetPPropInfoByName(Name:String): PPropInfo;
var
PT : PTypeData;
PP : PPropList;
PI : PTypeInfo;
I : Longint;
PT : PTypeData;
PP : PPropList;
PI : PTypeInfo;
I : Longint;
Begin
Name := Uppercase(name);
PI := FControl.ClassInfo;
@ -241,39 +244,39 @@ Begin
GetPropInfos(PI,PP);
I := -1;
repeat
inc(i);
inc(i);
until (PP^[i]^.Name = Name) or (i = PT^.PropCount-1);
if PP^[i]^.Name = Name then
Result:=PP^[i]
else
Result := nil;
Result:=PP^[i]
else
Result := nil;
//does freeing this kill my result? Check this...
// Freemem(PP);
end;
Function TComponentInterface.GetComponentType : String;
Begin
//???What do I return? TObject's Classtype?
Result:=FControl.ClassName;
end;
Function TComponentInterface.GetComponentHandle : LongInt;
Begin
//return the TWinControl handle?
if (FControl is TWinControl) then
Result := TWinControl(FControl).Handle;
if (FControl is TWinControl) then
Result := TWinControl(FControl).Handle;
end;
Function TComponentInterface.GetParent : TIComponentInterface;
Begin
result := nil;
if (FCOntrol is TControl) then
if TControl(FControl).Parent <> nil then
begin
Result := FFormEditor.FindComponentByName(TControl(FControl).Parent.Name);
end;
result := nil;
if (FCOntrol is TControl) then
if TControl(FControl).Parent <> nil then
begin
Result := FFormEditor.FindComponent(TControl(FControl).Parent);
end;
end;
Function TComponentInterface.IsTControl : Boolean;
@ -283,11 +286,10 @@ end;
Function TComponentInterface.GetPropCount : Integer;
var
PT : PTypeData;
PT : PTypeData;
Begin
PT:=GetTypeData(FControl.ClassInfo);
Result := PT^.PropCount;
PT:=GetTypeData(FControl.ClassInfo);
Result := PT^.PropCount;
end;
Function TComponentInterface.GetPropType(Index : Integer) : TTypeKind;
@ -297,7 +299,8 @@ PP : PPropList;
PI : PTypeInfo;
Num : Integer;
Begin
PT:=GetTypeData(FControl.ClassInfo);
PI:=FControl.ClassInfo;
PT:=GetTypeData(PI);
GetMem (PP,PT^.PropCount*SizeOf(Pointer));
GetPropInfos(PI,PP);
if Index < PT^.PropCount then
@ -315,7 +318,8 @@ PP : PPropList;
PI : PTypeInfo;
Num : Integer;
Begin
PT:=GetTypeData(FControl.ClassInfo);
PI:=FControl.ClassInfo;
PT:=GetTypeData(PI);
GetMem (PP,PT^.PropCount*SizeOf(Pointer));
GetPropInfos(PI,PP);
if Index < PT^.PropCount then
@ -323,37 +327,34 @@ Begin
else
Result := '';
freemem(PP);
end;
Function TComponentInterface.GetPropTypebyName(Name : String) : TTypeKind;
var
PT : PTypeData;
PP : PPropList;
PI : PTypeInfo;
Num : Integer;
I : Longint;
PT : PTypeData;
PP : PPropList;
PI : PTypeInfo;
I : Longint;
Begin
PT:=GetTypeData(FControl.ClassInfo);
PI:=FControl.ClassInfo;
PT:=GetTypeData(PI);
GetMem (PP,PT^.PropCount*SizeOf(Pointer));
GetPropInfos(PI,PP);
Result := tkUnknown;
For I:=0 to PT^.PropCount-1 do
If PP^[i]<>Nil then
begin
if PP^[i]^.Name = Name then
begin
Result := PP^[i]^.PropType^.Kind;
Break;
end;
end;
begin
if PP^[i]^.Name = Name then
begin
Result := PP^[i]^.PropType^.Kind;
Break;
end;
end;
freemem(PP);
end;
Function TComponentInterface.GetPropValue(Index : Integer; var Value) : Boolean;
var
PP : PPropInfo;
@ -385,94 +386,98 @@ Begin
end;
end;
Function TComponentInterface.SetPropbyName(Name : String; const Value) : Boolean;
var
PRI : PPropInfo;
PRI : PPropInfo;
Begin
Result := False;
Writeln('SetPropByName Name='''+Name+'''');
Result := False;
PRI := GetPropInfo(FControl.ClassInfo,Name);
if PRI <> nil then
Begin
Result :=FSetProp(PRI,Value);
end;
PRI := GetPropInfo(FControl.ClassInfo,Name);
if PRI <> nil then
Begin
Result :=FSetProp(PRI,Value);
end;
end;
Function TComponentInterface.GetControlCount: Integer;
Begin
// XXX Todo:
end;
Function TComponentInterface.GetControl(Index : Integer): TIComponentInterface;
Begin
// XXX Todo:
end;
Function TComponentInterface.GetComponentCount: Integer;
Begin
// XXX Todo:
end;
Function TComponentInterface.GetComponent(Index : Integer): TIComponentInterface;
Begin
// XXX Todo:
end;
Function TComponentInterface.Select : Boolean;
Begin
// XXX Todo:
end;
Function TComponentInterface.Focus : Boolean;
Begin
// XXX Todo:
end;
Function TComponentInterface.Delete : Boolean;
Begin
// XXX Todo:
end;
{TCustomFormEditor}
constructor TCustomFormEditor.Create;
begin
inherited Create;
FComponentInterfaceList := TList.Create;
FSelectedComponents := TComponentSelectionList.Create;
inherited Create;
FComponentInterfaceList := TList.Create;
FSelectedComponents := TComponentSelectionList.Create;
end;
destructor TCustomFormEditor.Destroy;
begin
inherited;
FComponentInterfaceList.Destroy;
FSelectedComponents.Destroy;
inherited;
FComponentInterfaceList.Free;
FSelectedComponents.Free;
end;
Function TCustomFormEditor.AddSelected(Value : TComponent) : Integer;
Begin
Result := -1;
FSelectedComponents.Add(Value);
Result := FSelectedComponents.Count;
//call the OI to update it's selected.
Obj_Inspector.Selections := FSelectedComponents;
FSelectedComponents.Add(Value);
Result := FSelectedComponents.Count;
// call the OI to update it's selected.
writeln('[TCustomFormEditor.AddSelected] '+Value.Name);
Obj_Inspector.Selections := FSelectedComponents;
end;
Function TCustomFormEditor.Filename : String;
begin
Result := 'testing.pp';
Result := 'testing.pp';
end;
Function TCustomFormEditor.FormModified : Boolean;
Begin
Result := FModified;
Result := FModified;
end;
Function TCustomFormEditor.FindComponentByName(const Name : String) : TIComponentInterface;
@ -481,156 +486,170 @@ Var
Begin
Num := 0;
While Num < FComponentInterfaceList.Count do
Begin
Result := TIComponentInterface(FComponentInterfaceList.Items[Num]);
if TComponentInterface(Result).FControl.Name = Name then break;
inc(num);
end;
Begin
Result := TIComponentInterface(FComponentInterfaceList.Items[Num]);
if Upcase(TComponentInterface(Result).FControl.Name) = UpCase(Name) then
exit;
inc(num);
end;
Result:=nil;
end;
Function TCustomFormEditor.FindComponent(AComponent: TComponent) : TIComponentInterface;
Function TCustomFormEditor.FindComponent(AComponent:TComponent): TIComponentInterface;
Var
Num : Integer;
Begin
Num := 0;
While Num < FComponentInterfaceList.Count do
Begin
Result := TIComponentInterface(FComponentInterfaceList.Items[Num]);
if TComponentInterface(Result).FControl = AComponent then break;
inc(num);
end;
Begin
Result := TIComponentInterface(FComponentInterfaceList.Items[Num]);
if TComponentInterface(Result).FControl = AComponent then exit;
inc(num);
end;
Result:=nil;
end;
//Function TCustomFormEditor.CreateComponent(CI : TIComponentInterface; TypeName : String;
Function TCustomFormEditor.CreateComponent(CI : TIComponentInterface; TypeClass : TComponentClass;
X,Y,W,H : Integer): TIComponentInterface;
Function TCustomFormEditor.CreateComponent(
ParentCI : TIComponentInterface;
TypeClass : TComponentClass; X,Y,W,H : Integer): TIComponentInterface;
Var
Temp : TComponentInterface;
TempInterface : TComponentInterface;
TempClass : TPersistentClass;
TempName : String;
Found : Boolean;
I, Num : Integer;
Temp : TComponentInterface;
TempInterface : TComponentInterface;
TempClass : TPersistentClass;
TempName : String;
Found : Boolean;
I, Num : Integer;
CompLeft, CompTop, CompWidth, CompHeight: integer;
DummyComponent:TComponent;
Begin
Temp := TComponentInterface.Create;
Writeln('TComponentInterface created......');
if SelectedComponents.Count = 0 then
Temp.FControl := TypeClass.Create(nil)
else
Begin
Writeln('Selected Components > 0');
if (SelectedComponents.Items[0] is TWinControl) and (csAcceptsControls in TWinControl(SelectedComponents.Items[0]).ControlStyle) then
writeln('[TCustomFormEditor.CreateComponent] Class='''+TypeClass.ClassName+'''');
Temp := TComponentInterface.Create;
Writeln('TComponentInterface created......');
if Assigned(ParentCI) then begin
if Assigned(TComponentInterface(ParentCI).FControl.Owner) then
Temp.FControl :=
TypeClass.Create(TComponentInterface(ParentCI).FControl.Owner)
else
Temp.FControl :=
TypeClass.Create(TComponentInterface(ParentCI).FControl)
end else
Temp.FControl := TypeClass.Create(nil);
{ if SelectedComponents.Count = 0 then
else
Begin
Writeln('Selected Components > 0');
if (SelectedComponents.Items[0] is TWinControl)
and (csAcceptsControls in
TWinControl(SelectedComponents.Items[0]).ControlStyle) then
Begin
Writeln('The Control is a TWinControl and it accepts controls');
Writeln('The owners name is '+TWinControl(SelectedComponents.Items[0]).Name);
Temp.FControl := TypeClass.Create(SelectedComponents.Items[0]);
Writeln('The Control is a TWinControl and it accepts controls');
Writeln('The owners name is '+TWinControl(SelectedComponents.Items[0]).Name);
Temp.FControl := TypeClass.Create(SelectedComponents.Items[0]);
end
else
Begin
Writeln('The Control is not a TWinControl or it does not accept controls');
Temp.FControl := TypeClass.Create(SelectedComponents.Items[0].Owner);
Writeln('The Control is not a TWinControl or it does not accept controls');
Temp.FControl := TypeClass.Create(SelectedComponents.Items[0].Owner);
end;
end;
end;}
//create a name for the control
Writeln('4');
TempName := Temp.FControl.ClassName;
delete(TempName,1,1);
writeln('TempName is ....'+TempName);
Found := True;
Num := 0;
While Found do
Begin
Found := False;
inc(num);
Writeln('NUm = '+inttostr(num));
for I := 0 to FComponentInterfaceList.Count-1 do
begin
if TComponent(TComponentInterface(FComponentInterfaceList.Items[i]).FControl).Name = TempName+inttostr(Num) then
begin
Found := True;
break;
end;
end;
end;
Temp.FControl.Name := TempName+Inttostr(num);
Writeln('TempName + num = '+TempName+Inttostr(num));
Writeln('4');
if Assigned(CI) then
Begin
if (TComponentInterface(CI).FControl is TWinControl) and
(csAcceptsControls in TWinControl(TComponentInterface(CI).FControl).COntrolStyle)then
begin
TWinControl(Temp.FControl).Parent := TWinControl(TComponentInterface(CI).FControl);
end
else
TWinControl(Temp.FControl).Parent := TWinControl(TComponentInterface(CI).FControl).Parent;
End
else
Begin //CI is not assigned so check the selected control
Writeln('CI is not assigned....');
if SelectedComponents.Count > 0 then
if Assigned(ParentCI) then
Begin
if (TComponentInterface(ParentCI).FControl is TWinControl)
and (csAcceptsControls in
TWinControl(TComponentInterface(ParentCI).FControl).ControlStyle) then
begin
TWinControl(Temp.FControl).Parent :=
TWinControl(TComponentInterface(ParentCI).FControl);
writeln('Parent is '''+TWinControl(Temp.FControl).Parent.Name+'''');
end
else
begin
TWinControl(Temp.FControl).Parent :=
TWinControl(TComponentInterface(ParentCI).FControl).Parent;
writeln('Parent is '''+TWinControl(Temp.FControl).Parent.Name+'''');
end;
{ End
else
Begin //ParentCI is not assigned so check the selected control
Writeln('ParentCI is not assigned....');
if SelectedComponents.Count > 0 then
Begin
Writeln('CI is not assigned but something is selected....');
TempInterface := TComponentInterface(FindComponentByName(SelectedComponents.Items[0].Name));
Writeln('The selected control is....'+TempInterface.FControl.Name);
Writeln('ParentCI is not assigned but something is selected....');
TempInterface := TComponentInterface(
FindComponent(SelectedComponents.Items[0]));
Writeln('The selected control is '''+TempInterface.FControl.Name+'''');
if (TempInterface.FControl is TWinControl) and
(csAcceptsControls in
TWinControl(TempInterface.FControl).ControlStyle) then
Begin
Writeln('The selected control IS a TWincontrol and accepts controls');
TWinControl(Temp.FControl).Parent :=
TWinControl(TempInterface.FControl);
end
else
TWinControl(Temp.FControl).Parent :=
TWinControl(TempInterface.FControl).Parent;
end}
end;
if (TempInterface.FControl is TWinControl) and
(csAcceptsControls in TWinControl(TempInterface.FControl).ControlStyle)then
Begin
Writeln('The selected control IS a TWincontrol and accepts controls');
TWinControl(Temp.FControl).Parent := TWinControl(TempInterface.FControl);
end
else
TWinControl(Temp.FControl).Parent := TWinControl(TempInterface.FControl).Parent;
end
end;
Writeln('5');
TempName := Temp.FControl.ClassName;
delete(TempName,1,1);
writeln('TempName is '''+TempName+'''');
Num := 0;
Found := True;
While Found do
Begin
Found := False;
inc(num);
for I := 0 to FComponentInterfaceList.Count-1 do
begin
DummyComponent:=TComponent(TComponentInterface(
FComponentInterfaceList.Items[i]).FControl);
if UpCase(DummyComponent.Name)=UpCase(TempName+IntToStr(Num)) then
begin
Found := True;
break;
end;
end;
end;
Temp.FControl.Name := TempName+IntToStr(Num);
Writeln('TempName + num = '+TempName+Inttostr(num));
if (Temp.FControl is TControl) then
Begin
CompLeft:=X;
CompTop:=Y;
CompWidth:=W;
CompHeight:=H;
if CompWidth<=0 then CompWidth:=TControl(Temp.FControl).Width;
if CompHeight<=0 then CompHeight:=TControl(Temp.FControl).Height;
if CompLeft<0 then
CompLeft:=(TControl(Temp.FControl).Parent.Width + CompWidth) div 2;
if CompTop<0 then
CompTop:=(TControl(Temp.FControl).Parent.Height+ CompHeight) div 2;
TControl(Temp.FControl).SetBounds(CompLeft,CompTop,CompWidth,CompHeight);
end;
if (Temp.FControl is TControl) then
Begin
if (X <> -1) and (Y <> -1) and (W <> -1) and (H <> -1) then
TControl(Temp.FControl).SetBounds(X,Y,W,H)
else
Begin
if (W <> -1) then TControl(Temp.FControl).Width := W; //if W=-1 then use default size otherwise use W
FComponentInterfaceList.Add(Temp);
if (H <> -1) then TControl(Temp.FControl).Height := H; //if H=-1 then use default size otherwise use H
if (X <> -1) then TControl(Temp.FControl).Left := X //if X=-1 then center in parent otherwise use X
else
TControl(Temp.FControl).Left := (TControl(Temp.FControl).Parent.Width div 2) - (TControl(Temp.FControl).Width div 2);
if (Y <> -1) then TControl(Temp.FControl).Top := Y //if Y=-1 then center in parent otherwise use Y
else
TControl(Temp.FControl).Top := (TControl(Temp.FControl).Parent.Height div 2) - (TControl(Temp.FControl).Height div 2);
end;
end;
FComponentInterfaceList.Add(Temp);
Result := Temp;
Result := Temp;
end;
Function TCustomFormEditor.GetFormComponent : TIComponentInterface;
Begin
//this can only be used IF you have one FormEditor per form. I currently don't
//this can only be used IF you have one FormEditor per form. I currently don't
end;
Procedure TCustomFormEditor.ClearSelected;
Begin
FSelectedComponents.Clear;
FSelectedComponents.Clear;
end;

View File

@ -1634,6 +1634,7 @@ Begin
ObjectInspector1.FillComponentComboBox;
TDesigner(TForm(NewCI.Control.Owner).Designer).AddControlCode(NewCI.Control);
if NewCI.Control is TControl then begin
// set the OnMouseDown and OnMouseUp event so we know when the control
// is selected or a new control is dropped
@ -1648,68 +1649,8 @@ writeln('NewComponent is TControl');
MouseDownControl:=nil;
ControlClick(Notebook1); //this resets it to the mouse.
exit;
//see if the mouse moved or there was simply a click on the form
{ if (X >= 0) and (X <= TControl(sender).Width) and
(Y >= 0) and (Y <= TControl(sender).Height) then
begin
// mouse was down and up on the form.
// We clicked on the form. Let's see what the active selection is in the
// IDE control bar. If it's the pointer, then we set the
// FormEditor1.SelectedComponents to Sender,
// otherwise we drop a control and call the CreateComponent function.
if BPressed = 1 then
Begin // mouse pointer button pressed.
FormEditor1.ClearSelected;
Writeln('Clicked on the form!!!!! Forms name is '+TForm(Sender).Name);
FormEditor1.AddSelected(TComponent(Sender));
end
else
Begin
// add a new control
// check to see if the mouse moved between clicks.
// If so then they sized the control
if (MouseUpPos.X <> MouseDownPos.X) or (MouseUpPos.Y <> MouseDownPos.Y) then begin
// CInterface := TComponentInterface(FormEditor1.CreateComponent(nil,
// TComponentClass(TIdeComponent(
// ideComplist.items[bpressed-1]).ClassType)
// ,NewLeft1,NewTop1,NewLeft2,NewTop2));
end
else begin
end;
CInterface := TComponentInterface(FormEditor1.CreateComponent(nil,
TComponentClass(TIdeComponent(
ideComplist.items[bpressed-1]).ClassType),
MouseDownPos.X,MouseDownPos.Y,-1,-1));
//Set up some default values for the control here
// CInterface is a TComponentInterface defined in CustomFormEditor.pp
CInterface.SetPropByName('VISIBLE',True);
// CInterface.SetPropByName('NAME','PLEASEWORK1');
// CInterface.SetPropbyName('CAPTION','Click me!');
CInterface.SetPropByName('HINT','Click');
CInterface.SetPropByName('TOP',10);
CInterface.SetPropByName('ONCLICK',@ClickOnControl);
//set the ONCLICK event so we know when the control is selected;
// TControl(CInterface.Control).OnClick := @ClickOnControl;
FormEditor1.ClearSelected;
FormEditor1.AddSelected(TComponent(Cinterface.Control));
end;
//TIdeComponent(ideComplist.items[bpressed-1]).
end;
ControlClick(Notebook1); //this resets it to the mouse.
}
Writeln('MouseuponControl');
end;
{------------------------------------------------------------------------------}
procedure TForm1.mnuNewFormClicked(Sender : TObject);
var
@ -2319,9 +2260,9 @@ end.
{ =============================================================================
$Log$
Revision 1.17 2000/12/15 15:29:09 lazarus
Changes my Mattias for dropping controls.
Changes by Shane for adding code to the form source.
Revision 1.18 2000/12/15 18:25:16 lazarus
Changes from Mattias and I.
Shane
Revision 1.16 2000/12/01 20:23:34 lazarus
renamed Object_Inspector and Prop_edits by removing the underline.