mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-10 19:35:58 +02:00
added more code for CustomFormEditor
Shane git-svn-id: trunk@42 -
This commit is contained in:
parent
09c2284956
commit
2ec79ce21b
@ -17,10 +17,10 @@
|
||||
* *
|
||||
***************************************************************************/
|
||||
}
|
||||
{$H+}
|
||||
unit AbstractFormEditor;
|
||||
|
||||
{$mode objfpc}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
@ -28,13 +28,14 @@ uses
|
||||
|
||||
type
|
||||
|
||||
TPropertyType = (ptUnknown, ptINteger, ptChar, ptString, ptFloat, ptSet, ptClass, ptMethod, ptVariant);
|
||||
TPropertyType = (ptUnknown, ptInteger, ptChar, ptEnumeration,ptFloat,ptString,ptSet,
|
||||
ptClass, ptMethod,ptWChar, ptLString, LWString, ptVariant);
|
||||
|
||||
TComponentInterface = class
|
||||
TIComponentInterface = class
|
||||
public
|
||||
Function GetComponentType : String; virtual; abstract;
|
||||
Function GetComponentHandle : LongInt; virtual; abstract;
|
||||
Function GetParent : TComponentInterface; virtual; abstract;
|
||||
Function GetParent : TIComponentInterface; virtual; abstract;
|
||||
Function IsTControl : Boolean; virtual; abstract;
|
||||
Function GetPropCount : Integer; virtual; abstract;
|
||||
Function GetPropType(Index : Integer) : TPropertyType; virtual; abstract;
|
||||
@ -47,10 +48,10 @@ type
|
||||
Function SetPropbyName(Name : String; const Value) : Boolean; virtual; abstract;
|
||||
|
||||
Function GetControlCount: Integer; virtual; abstract;
|
||||
Function GetControl(Index : Integer): TComponentInterface; virtual; abstract;
|
||||
Function GetControl(Index : Integer): TIComponentInterface; virtual; abstract;
|
||||
|
||||
Function GetComponentCount: Integer; virtual; abstract;
|
||||
Function GetComponent(Index : Integer): TComponentInterface; virtual; abstract;
|
||||
Function GetComponent(Index : Integer): TIComponentInterface; virtual; abstract;
|
||||
|
||||
Function Select : Boolean; virtual; abstract;
|
||||
Function Focus : Boolean; virtual; abstract;
|
||||
@ -69,15 +70,15 @@ type
|
||||
public
|
||||
Function Filename : String; virtual; abstract;
|
||||
Function FormModified : Boolean; virtual; abstract;
|
||||
Function FindComponent(const Name : String) : TComponentInterface; virtual; abstract;
|
||||
Function FindComponent(const Name : String) : TIComponentInterface; virtual; abstract;
|
||||
|
||||
Function GetComponentByHandle(const Value : Longint): TComponentInterface; virtual; abstract;
|
||||
Function GetComponentByHandle(const Value : Longint): TIComponentInterface; virtual; abstract;
|
||||
|
||||
Function GetSelCount : Integer; virtual; abstract;
|
||||
Function GetSelComponent(Index : Integer) : TComponentInterface; virtual; abstract;
|
||||
Function GetSelComponent(Index : Integer) : TIComponentInterface; virtual; abstract;
|
||||
|
||||
Function CreateComponent(CI : TComponentInterface; TypeName : String;
|
||||
X,Y,W,H : Integer): TComponentInterface; virtual; abstract;
|
||||
Function CreateComponent(CI : TIComponentInterface; TypeName : String;
|
||||
X,Y,W,H : Integer): TIComponentInterface; virtual; abstract;
|
||||
end;
|
||||
|
||||
|
||||
|
@ -25,10 +25,48 @@ unit CustomFormEditor;
|
||||
interface
|
||||
|
||||
uses
|
||||
classes, abstractformeditor, controls;
|
||||
classes, abstractformeditor, controls,Typinfo;
|
||||
|
||||
type
|
||||
|
||||
{
|
||||
TComponentInterface is derived from TIComponentInterface. It gives access to
|
||||
each control that's dropped onto the form
|
||||
}
|
||||
|
||||
TCustomFormEditor = class; //forward declaration
|
||||
|
||||
TComponentInterface = class(TIComponentInterface)
|
||||
private
|
||||
FControl : TComponent;
|
||||
FFormEditor : TCustomFormEditor; //used to call it's functions
|
||||
|
||||
public
|
||||
Function GetComponentType : String; override;
|
||||
Function GetComponentHandle : LongInt; override;
|
||||
Function GetParent : TIComponentInterface; override;
|
||||
Function IsTControl : Boolean; override;
|
||||
Function GetPropCount : Integer; override;
|
||||
Function GetPropType(Index : Integer) : TPropertyType; override;
|
||||
Function GetPropName(Index : Integer) : String; override;
|
||||
Function GetPropTypebyName(Name : String) : TPropertyType; 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 GetControlCount: Integer; override;
|
||||
Function GetControl(Index : Integer): TIComponentInterface; override;
|
||||
|
||||
Function GetComponentCount: Integer; override;
|
||||
Function GetComponent(Index : Integer): TIComponentInterface; override;
|
||||
|
||||
Function Select : Boolean; override;
|
||||
Function Focus : Boolean; override;
|
||||
Function Delete : Boolean; override;
|
||||
end;
|
||||
|
||||
{
|
||||
TCustomFormEditor
|
||||
One is created whenever a "NEw Form" is created. The Form is contained in the MainControl
|
||||
@ -40,8 +78,10 @@ TCustomFormEditor
|
||||
|
||||
TCustomFormEditor = class(TAbstractFormEditor)
|
||||
private
|
||||
FMainControl : TControl;
|
||||
FControlClass : TControlClass;
|
||||
FMainControl : TControl;
|
||||
FModified : Boolean;
|
||||
FComponentInterfaceList : TList; //used to track and find controls on the form
|
||||
Function GetMainControl : TControl;
|
||||
protected
|
||||
|
||||
@ -51,6 +91,8 @@ TCustomFormEditor
|
||||
destructor Destroy; override;
|
||||
|
||||
Function Filename : String; override;
|
||||
Function FormModified : Boolean; override;
|
||||
Function FindComponent(const Name : String) : TIComponentInterface; override;
|
||||
|
||||
property ControlClass : TControlClass read FControlClass write FControlClass;
|
||||
property MainControl : TControl read GetMainControl;
|
||||
@ -59,13 +101,227 @@ TCustomFormEditor
|
||||
|
||||
implementation
|
||||
|
||||
{TComponentInterface}
|
||||
|
||||
Function TComponentInterface.GetComponentType : String;
|
||||
Begin
|
||||
//???What do I return? TObject's Classtype?
|
||||
end;
|
||||
|
||||
Function TComponentInterface.GetComponentHandle : LongInt;
|
||||
Begin
|
||||
//return the TWinControl 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.FindComponent(TControl(FControl).Parent.Name);
|
||||
end;
|
||||
end;
|
||||
|
||||
Function TComponentInterface.IsTControl : Boolean;
|
||||
Begin
|
||||
Result := (FControl is TControl);
|
||||
end;
|
||||
|
||||
Function TComponentInterface.GetPropCount : Integer;
|
||||
var
|
||||
TypeInfo : PTypeInfo;
|
||||
TypeKinds : TTypeKinds;
|
||||
PropList : TPropList;
|
||||
Begin
|
||||
TypeKinds := [tkInteger,tkChar,tkEnumeration,tkFloat,tkSet,tkMethod,tkSString,tkLString,tkAString,
|
||||
tkWString,tkVariant,tkArray,tkRecord,tkInterface,
|
||||
tkClass,tkObject,tkWChar,tkBool,tkInt64,tkQWord];
|
||||
|
||||
Result := GetPropList(TypeInfo,TypeKinds,@Proplist);
|
||||
end;
|
||||
|
||||
Function TComponentInterface.GetPropType(Index : Integer) : TPropertyType;
|
||||
var
|
||||
TypeInfo : PTypeInfo;
|
||||
TypeKinds : TTypeKinds;
|
||||
PropList : TPropList;
|
||||
PropInfo : TPropInfo;
|
||||
|
||||
Num : Integer;
|
||||
Begin
|
||||
TypeKinds := [tkUnknown,tkInteger,tkChar,tkEnumeration,tkFloat,tkSet,tkMethod,tkSString,tkLString,tkAString,
|
||||
tkWString,tkVariant,tkArray,tkRecord,tkInterface,
|
||||
tkClass,tkObject,tkWChar,tkBool,tkInt64,tkQWord];
|
||||
|
||||
Num := GetPropList(TypeInfo,TypeKinds,@Proplist);
|
||||
|
||||
If NUm > 0 then
|
||||
Begin
|
||||
PropInfo := PropList[Index]^;
|
||||
TypeInfo := PropInfo.PropType;
|
||||
case TypeInfo^.kind of
|
||||
tkUnknown : Result := ptUnknown;
|
||||
tkInteger : Result := ptInteger;
|
||||
tkChar : Result := ptChar;
|
||||
tkEnumeration : Result := ptEnumeration;
|
||||
tkFloat : Result := ptFloat;
|
||||
tkSet : Result := ptSet;
|
||||
tkMethod : Result := ptMethod;
|
||||
tkSString : Result := ptString;
|
||||
tkLString : Result := ptLString;
|
||||
tkAString : Result := ptLString;
|
||||
tkWString : Result := ptLString;
|
||||
tkVariant : Result := ptVariant;
|
||||
tkClass : Result := ptClass;
|
||||
tkWChar : Result := ptWChar;
|
||||
else
|
||||
Result := ptUnknown
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
Function TComponentInterface.GetPropName(Index : Integer) : String;
|
||||
var
|
||||
TypeInfo : PTypeInfo;
|
||||
TypeKinds : TTypeKinds;
|
||||
PropList : TPropList;
|
||||
PropInfo : TPropInfo;
|
||||
|
||||
Num : Integer;
|
||||
Begin
|
||||
TypeKinds := [tkUnknown,tkInteger,tkChar,tkEnumeration,tkFloat,tkSet,tkMethod,tkSString,tkLString,tkAString,
|
||||
tkWString,tkVariant,tkArray,tkRecord,tkInterface,
|
||||
tkClass,tkObject,tkWChar,tkBool,tkInt64,tkQWord];
|
||||
|
||||
Num := GetPropList(TypeInfo,TypeKinds,@Proplist);
|
||||
|
||||
If NUm > 0 then
|
||||
Begin
|
||||
PropInfo := PropList[Index]^;
|
||||
TypeInfo := PropInfo.PropType;
|
||||
Result := TypeInfo^.Name;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
Function TComponentInterface.GetPropTypebyName(Name : String) : TPropertyType;
|
||||
var
|
||||
TypeInfo : PTypeInfo;
|
||||
TypeKinds : TTypeKinds;
|
||||
PropList : TPropList;
|
||||
PropInfo : TPropInfo;
|
||||
|
||||
Num : Integer;
|
||||
Begin
|
||||
TypeKinds := [tkUnknown,tkInteger,tkChar,tkEnumeration,tkFloat,tkSet,tkMethod,tkSString,tkLString,tkAString,
|
||||
tkWString,tkVariant,tkArray,tkRecord,tkInterface,
|
||||
tkClass,tkObject,tkWChar,tkBool,tkInt64,tkQWord];
|
||||
|
||||
Num := GetPropInfo(TypeInfo,Name);
|
||||
|
||||
If NUm > 0 then
|
||||
Begin
|
||||
PropInfo := PropList[Index]^;
|
||||
TypeInfo := PropInfo.PropType;
|
||||
case TypeInfo^.kind of
|
||||
tkUnknown : Result := ptUnknown;
|
||||
tkInteger : Result := ptInteger;
|
||||
tkChar : Result := ptChar;
|
||||
tkEnumeration : Result := ptEnumeration;
|
||||
tkFloat : Result := ptFloat;
|
||||
tkSet : Result := ptSet;
|
||||
tkMethod : Result := ptMethod;
|
||||
tkSString : Result := ptString;
|
||||
tkLString : Result := ptLString;
|
||||
tkAString : Result := ptLString;
|
||||
tkWString : Result := ptLString;
|
||||
tkVariant : Result := ptVariant;
|
||||
tkClass : Result := ptClass;
|
||||
tkWChar : Result := ptWChar;
|
||||
else
|
||||
Result := ptUnknown
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
end;
|
||||
|
||||
|
||||
Function TComponentInterface.GetPropValue(Index : Integer; var Value) : Boolean;
|
||||
Begin
|
||||
|
||||
end;
|
||||
|
||||
Function TComponentInterface.GetPropValuebyName(Name: String; var Value) : Boolean;
|
||||
Begin
|
||||
|
||||
end;
|
||||
|
||||
Function TComponentInterface.SetProp(Index : Integer; const Value) : Boolean;
|
||||
Begin
|
||||
|
||||
end;
|
||||
|
||||
Function TComponentInterface.SetPropbyName(Name : String; const Value) : Boolean;
|
||||
Begin
|
||||
|
||||
end;
|
||||
|
||||
|
||||
Function TComponentInterface.GetControlCount: Integer;
|
||||
Begin
|
||||
|
||||
end;
|
||||
|
||||
Function TComponentInterface.GetControl(Index : Integer): TIComponentInterface;
|
||||
Begin
|
||||
|
||||
end;
|
||||
|
||||
|
||||
Function TComponentInterface.GetComponentCount: Integer;
|
||||
Begin
|
||||
|
||||
end;
|
||||
|
||||
Function TComponentInterface.GetComponent(Index : Integer): TIComponentInterface;
|
||||
Begin
|
||||
|
||||
end;
|
||||
|
||||
|
||||
Function TComponentInterface.Select : Boolean;
|
||||
Begin
|
||||
|
||||
end;
|
||||
|
||||
Function TComponentInterface.Focus : Boolean;
|
||||
Begin
|
||||
|
||||
end;
|
||||
|
||||
Function TComponentInterface.Delete : Boolean;
|
||||
Begin
|
||||
|
||||
end;
|
||||
|
||||
|
||||
|
||||
|
||||
{TCustomFormEditor}
|
||||
|
||||
constructor TCustomFormEditor.Create;
|
||||
begin
|
||||
FComponentInterfaceList := TList.Create;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
destructor TCustomFormEditor.Destroy;
|
||||
begin
|
||||
FComponentInterfaceList.Destroy;
|
||||
inherited;
|
||||
end;
|
||||
|
||||
@ -81,10 +337,28 @@ result := FMainControl;
|
||||
end;
|
||||
|
||||
|
||||
Function TCustomFormEditor.Filename : String; override;
|
||||
Function TCustomFormEditor.Filename : String;
|
||||
begin
|
||||
Result := 'testing.pp';
|
||||
end;
|
||||
|
||||
Function TCustomFormEditor.FormModified : Boolean;
|
||||
Begin
|
||||
Result := FModified;
|
||||
end;
|
||||
|
||||
Function TCustomFormEditor.FindComponent(const Name : String) : TIComponentInterface;
|
||||
Var
|
||||
Num : Integer;
|
||||
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;
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user