📄 dsgnintf.pas
字号:
TDefaultEditor = class(TComponentEditor, IDefaultEditor)
private
FFirst: TPropertyEditor;
FBest: TPropertyEditor;
FContinue: Boolean;
procedure CheckEdit(PropertyEditor: TPropertyEditor);
protected
procedure EditProperty(PropertyEditor: TPropertyEditor;
var Continue, FreeEditor: Boolean); virtual;
public
procedure Edit; override;
end;
{ Global variables initialized internally by the form designer }
type
TFreeCustomModulesProc = procedure (Group: Integer);
var
FreeCustomModulesProc: TFreeCustomModulesProc;
{ RegisterPropertyEditor
Registers a new property editor for the given type. When a component is
selected the Object Inspector will create a property editor for each
of the component's properties. The property editor is created based on
the type of the property. If, for example, the property type is an
Integer, the property editor for Integer will be created (by default
that would be TIntegerProperty). Most properties do not need specialized
property editors. For example, if the property is an ordinal type the
default property editor will restrict the range to the ordinal subtype
range (e.g. a property of type TMyRange = 1..10 will only allow values
between 1 and 10 to be entered into the property). Enumerated types will
display a drop-down list of all the enumerated values (e.g. TShapes =
(sCircle, sSquare, sTriangle) will be edited by a drop-down list containing
only sCircle, sSquare and sTriangle). A property editor need only be
created if default property editor or none of the existing property editors
are sufficient to edit the property. This is typically because the
property is an object. The properties are looked up newest to oldest.
This allows and existing property editor replaced by a custom property
editor.
PropertyType
The type information pointer returned by the TypeInfo built-in function
(e.g. TypeInfo(TMyRange) or TypeInfo(TShapes)).
ComponentClass
Type of the component to which to restrict this type editor. This
parameter can be left nil which will mean this type editor applies to all
properties of PropertyType.
PropertyName
The name of the property to which to restrict this type editor. This
parameter is ignored if ComponentClass is nil. This parameter can be
an empty string ('') which will mean that this editor applies to all
properties of PropertyType in ComponentClass.
EditorClass
The class of the editor to be created whenever a property of the type
passed in PropertyTypeInfo is displayed in the Object Inspector. The
class will be created by calling EditorClass.Create. }
procedure RegisterPropertyEditor(PropertyType: PTypeInfo; ComponentClass: TClass;
const PropertyName: string; EditorClass: TPropertyEditorClass);
type
TPropertyMapperFunc = function(Obj: TPersistent;
PropInfo: PPropInfo): TPropertyEditorClass;
procedure RegisterPropertyMapper(Mapper: TPropertyMapperFunc);
procedure GetComponentProperties(Components: TDesignerSelectionList;
Filter: TTypeKinds; Designer: IFormDesigner; Proc: TGetPropEditProc);
procedure RegisterComponentEditor(ComponentClass: TComponentClass;
ComponentEditor: TComponentEditorClass);
function GetComponentEditor(Component: TComponent;
Designer: IFormDesigner): TComponentEditor;
{ Custom modules }
{ A custom module allows containers that descend from classes other than TForm
to be created and edited by the form designer. This is useful for other form
like containers (e.g. a report designer) or for specialized forms (e.g. an
ActiveForm) or for generic component containers (e.g. a TDataModule). It is
assumed that the base class registered will call InitInheritedComponent in its
constructor which will initialize the component from the associated DFM file
stored in the programs resources. See the constructors of TDataModule and
TForm for examples of how to write such a constructor.
The following designer assumptions are made, depending on the base components
ancestor,
If ComponentBaseClass descends from TForm,
it is designed by creating an instance of the component as the form.
Allows designing TForm descendants and modifying their properties as
well as the form properties
If ComponentBaseClass descends from TWinControl (but not TForm),
it is designed by creating an instance of the control, placing it into a
design-time form. The form's client size is the default size of the
control.
If ComponentBaseClass descends from TDataModule,
it is designed by creating an instance of the class and creating a
special non-visual container designer to edit the components and display
the icons of the contained components.
The module will appear in the project file with a colon and the base class
name appended after the component name (e.g. MyDataModule: TDataModule).
Note it is not legal to register anything that does not descend from one of
the above.
TCustomModule class
An instance of this class is created for each custom module that is
loaded. This class is also destroyed whenever the module is unloaded.
The Saving method is called prior to the file being saved. When the context
menu for the module is invoked the GetVerbCount and GetVerb methods are
called to build the menu. If one of the verbs is selected ExecuteVerb is
called.
ExecuteVerb(Index)
The Index'ed verb was selected by the use off the context menu. The
meaning of this is determined by custom module.
GetAttributes
cmaVirtualSize: For TWinControl objects only: including this attribute makes
the control "client aligned" in the design window. Without this
attribute, the object is sized independently from the design window.
Attributes are a set to allow for future expansion of features.
GetVerb(Index)
The custom module should return a string that will be displayed in the
context menu. It is the responsibility of the custom module to place
the & character and the '...' characters as appropriate.
GetVerbCount
The number of valid indexs to GetVerb and Execute verb. The index assumed
to be zero based (i.e. 0..GetVerbCount - 1).
PrepareItem
While constructing the context menu PrepareItem will be called for
each verb. It will be passed the menu item that will be used to represent
the verb. The module editor can customize the menu item as it sees fit,
including adding subitems. If you don't want that particular menu item
to be shown don't free it, simply set it's Visible property to False.
Saving
Called prior to the module being saved.
ValidateComponent(Component)
ValidateComponent is called whenever a component is created by the
user for the designer to contain. The intent is for this procedure to
raise an exception with a descriptive message if the component is not
applicable for the container. For example, a TComponent module should
throw an exception if the component descends from TControl.
Root
This is the instance being designed.}
type
TCustomModuleAttribute = (cmaVirtualSize);
TCustomModuleAttributes = set of TCustomModuleAttribute;
TCustomModule = class
private
FRoot: IComponent;
public
constructor Create(ARoot: IComponent); virtual;
procedure ExecuteVerb(Index: Integer); virtual;
function CreateDesignerForm(Designer: IDesigner): TCustomForm; virtual;
function GetAttributes: TCustomModuleAttributes; virtual;
function GetVerb(Index: Integer): string; virtual;
function GetVerbCount: Integer; virtual;
procedure PrepareItem(Index: Integer; const AItem: TMenuItem); virtual;
procedure Saving; virtual;
procedure ValidateComponent(Component: IComponent); virtual;
class function Nestable: Boolean; virtual;
property Root: IComponent read FRoot;
end;
TCustomModuleClass = class of TCustomModule;
TRegisterCustomModuleProc = procedure (Group: Integer;
ComponentBaseClass: TComponentClass;
CustomModuleClass: TCustomModuleClass);
ICustomModuleSettings = interface
['{50947DAD-E627-11D2-B728-00C04FA35D12}']
function IniSection: string;
end;
ICustomModuleProjectSettings = interface(ICustomModuleSettings)
['{78E12CC2-DBCC-11D2-B727-00C04FA35D12}']
procedure SaveProjectState(AFile: TMemIniFile);
procedure LoadProjectState(AFile: TMemIniFile);
end;
ICustomModuleUnitSettings = interface(ICustomModuleSettings)
['{78E12CC1-DBCC-11D2-B727-00C04FA35D12}']
procedure SaveUnitState(AFile: TMemIniFile);
procedure LoadUnitState(AFile: TMemIniFile);
end;
IDesignerPersistence = interface
['{D32194C2-EECF-11D2-AAD2-00C04FB16FBC}']
procedure Save(const Stream: IStream);
procedure Load(const Stream: IStream);
end;
procedure RegisterCustomModule(ComponentBaseClass: TComponentClass;
CustomModuleClass: TCustomModuleClass);
var
RegisterCustomModuleProc: TRegisterCustomModuleProc;
{ Routines used by the form designer for package management }
type
TGroupChangeProc = procedure(AGroup: Integer);
function NewEditorGroup: Integer;
procedure FreeEditorGroup(Group: Integer);
procedure NotifyGroupChange(AProc: TGroupChangeProc);
procedure UnNotifyGroupChange(AProc: TGroupChangeProc);
var // number of significant characters in identifiers
MaxIdentLength: Byte = 63;
{ Property Categories Classes
The following three components make up the category management system.
Access to them is usually managed by the following support functions.
TPropertyCategoryList
Contains and maintains the list of TPropertyCategories. There are numerous
'As a whole' access and manipulation methods for categories as well as
simplified access functions.
TPropertyCategory
Contains and maintains the list of TPropertyFilters. There are numerous
'As a whole' access and manipulation methods for filters as well as data
about the category itself.
TPropertyFilter
Maintains the information about a single filter associated with a particular
category. Along with its filter specific data it also encapsulates the
matching algorithm. }
type
TPropertyFilter = class(TObject)
private
FMask: TMask;
FComponentClass: TClass;
FPropertyType: PTypeInfo;
FGroup: Integer;
public
constructor Create(const APropertyName: String; AComponentClass: TClass;
APropertyType: PTypeInfo);
destructor Destroy; override;
function Match(const APropertyName: String; AComponentClass: TClass;
APropertyType: PTypeInfo): Boolean;
property ComponentClass: TClass read FComponentClass;
property PropertyType: PTypeInfo read FPropertyType;
end;
TPropertyCategoryClass = class of TPropertyCategory;
TPropertyCategory = class(TObject)
private
FList: TObjectList;
FMatchCount: Integer;
FEditor: TPropertyEditor;
FEnabled, FVisible: Boolean;
FGroup: Integer;
protected
function GetFilter(Index: Integer): TPropertyFilter;
public
constructor Create;
destructor Destroy; override;
function Add(AFilter: TPropertyFilter): TPropertyFilter;
function Count: integer;
function Match(const APropertyName: String; AComponentClass: TClass;
APropertyType: PTypeInfo): Boolean;
procedure ClearMatches;
procedure FreeEditorGroup(AGroup: Integer);
class function Name: string; virtual;
class function Description: string; virtual;
procedure PropDraw(ACanvas: TCanvas; const ARect: TRect;
ASelected: Boolean); dynamic;
property Filters[Index: Integer]: TPropertyFilter read GetFilter;
property MatchCount: Integer read FMatchCount;
property Visible: Boolean read FVisible write FVisible;
property Editor: TPropertyEditor read FEditor write FEditor;
end;
TPropertyCategoryVisibleMode = (pcvAll, pcvToggle, pcvNone, pcvNotListed, pcvOnlyListed);
TPropertyCategoryList = class(TObject)
private
FList: TObjectList;
FMiscCategory: TPropertyCategory;
protected
function GetCategory(Index: Integer): TPropertyCategory;
function GetHiddenCategories: string;
procedure SetHiddenCategories(const Value: string);
public
constructor Create;
destructor Destroy; override;
function FindCategory(ACategoryClass: TPropertyCategoryClass): TPropertyCategory;
function IndexOf(ACategoryClass: TPropertyCategoryClass): Integer; overload;
function IndexOf(const ACategoryName: string): Integer; overload;
procedure ClearMatches;
procedure FreeEditorGroup(AGroup: Integer);
function MiscCategory: TPropertyCategory;
function Count: integer;
function Match(const APropertyName: String; AComponentClass: TClass;
APropertyType: PTypeInfo = nil): Boolean;
function ChangeVisibility(AMode: TPropertyCategoryVisibleMode): Boolean; overload;
function ChangeVisibility(AMode: TPropertyCategoryVisibleMode;
const AClasses: array of TClass): Boolean; overload;
property HiddenCategories: string read GetHiddenCategories write SetHiddenCategories;
property Categories[Index: Integer]: TPropertyCategory read GetCategory; default;
end;
{ Property Categories Helpers
RegisterPropertyInCategory
This function comes in four flavors, each taking slightly different set of
arguments. You can specify a category filter by property name; by class
type and property name; by property type and property name; and finally
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -