home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 August / VPR9708A.ISO / D3TRIAL / INSTALL / DATA.Z / DSGNINTF.INT < prev    next >
Text File  |  1997-03-20  |  35KB  |  802 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Visual Component Library                 }
  5. {                                                       }
  6. {       Copyright (c) 1995,97 Borland International     }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit DsgnIntf;
  11.  
  12. interface
  13.  
  14. {$N+,S-,R-}
  15.  
  16. uses SysUtils, Classes, Graphics, Controls, Forms, TypInfo;
  17.  
  18. type
  19.  
  20. { TComponentList }
  21.  
  22.   TComponentList = class(TObject)
  23.   public
  24.     constructor Create;
  25.     destructor Destroy; override;
  26.     function Add(Item: TPersistent): Integer;
  27.     function Equals(List: TComponentList): Boolean;
  28.     property Count: Integer;
  29.     property Items[Index: Integer]: TPersistent; default;
  30.   end;
  31.  
  32. { Forward declaration }
  33.  
  34.   TComponentEditor = class;
  35.  
  36. { TFormDesigner }
  37.  
  38.   TFormDesigner = class(TDesigner)
  39.   public
  40.     function CreateMethod(const Name: string; TypeData: PTypeData): TMethod; virtual; abstract;
  41.     function GetMethodName(const Method: TMethod): string; virtual; abstract;
  42.     procedure GetMethods(TypeData: PTypeData; Proc: TGetStrProc); virtual; abstract;
  43.     function GetPrivateDirectory: string; virtual; abstract;
  44.     procedure GetSelections(List: TComponentList); virtual; abstract;
  45.     function MethodExists(const Name: string): Boolean; virtual; abstract;
  46.     procedure RenameMethod(const CurName, NewName: string); virtual; abstract;
  47.     procedure SelectComponent(Instance: TPersistent); virtual; abstract;
  48.     procedure SetSelections(List: TComponentList); virtual; abstract;
  49.     procedure ShowMethod(const Name: string); virtual; abstract;
  50.     function UniqueName(const BaseName: string): string; virtual; abstract;
  51.     procedure GetComponentNames(TypeData: PTypeData; Proc: TGetStrProc); virtual; abstract;
  52.     function GetComponent(const Name: string): TComponent; virtual; abstract;
  53.     function GetComponentName(Component: TComponent): string; virtual; abstract;
  54.     function GetObject(const Name: string): TPersistent; virtual; abstract;
  55.     function GetObjectName(Instance: TPersistent): string; virtual; abstract;
  56.     procedure GetObjectNames(TypeData: PTypeData; Proc: TGetStrProc); virtual; abstract;
  57.     function MethodFromAncestor(const Method: TMethod): Boolean; virtual; abstract;
  58.     function CreateComponent(ComponentClass: TComponentClass; Parent: TComponent;
  59.       Left, Top, Width, Height: Integer): TComponent; virtual; abstract;
  60.     function IsComponentLinkable(Component: TComponent): Boolean; virtual; abstract;
  61.     procedure MakeComponentLinkable(Component: TComponent); virtual; abstract;
  62.     function GetRoot: TComponent; virtual; abstract;
  63.     procedure Revert(Instance: TPersistent; PropInfo: PPropInfo); virtual; abstract;
  64.     function GetIsDormant: Boolean; virtual; abstract;
  65.     function HasInterface: Boolean; virtual; abstract;
  66.     function HasInterfaceMember(const Name: string): Boolean; virtual; abstract;
  67.     procedure AddInterfaceMember(const MemberText: string); virtual; abstract;
  68.     property IsDormant: Boolean;
  69.   end;
  70.  
  71. { TPropertyEditor
  72.   Edits a property of a component, or list of components, selected into the
  73.   Object Inspector.  The property editor is created based on the type of the
  74.   property being edited as determined by the types registered by
  75.   RegisterPropertyEditor.  The Object Inspector uses the a TPropertyEditor
  76.   for all modification to a property. GetName and GetValue are called to display
  77.   the name and value of the property.  SetValue is called whenever the user
  78.   requests to change the value.  Edit is called when the user double-clicks the
  79.   property in the Object Inspector. GetValues is called when the drop-down
  80.   list of a property is displayed.  GetProperties is called when the property
  81.   is expanded to show sub-properties.  AllEqual is called to decide whether or
  82.   not to display the value of the property when more than one component is
  83.   selected.
  84.  
  85.   The following are methods that can be overriden to change the behavior of
  86.   the property editor:
  87.  
  88.     Activate
  89.       Called whenever the property becomes selected in the object inspector.
  90.       This is potientially useful to allow certian property attributes to
  91.       to only be determined whenever the property is selected in the object
  92.       inspector. Only paSubProperties and paMultiSelect, returned from
  93.       GetAttributes, need to be accurate before this method is called.
  94.     AllEqual
  95.       Called whenever there are more than one components selected.  If this
  96.       method returns true, GetValue is called, otherwise blank is displayed
  97.       in the Object Inspector.  This is called only when GetAttributes
  98.       returns paMultiSelect.
  99.     Edit
  100.       Called when the '...' button is pressed or the property is double-clicked.
  101.       This can, for example, bring up a dialog to allow the editing the
  102.       component in some more meaningful fashion than by text (e.g. the Font
  103.       property).
  104.     GetAttributes
  105.       Returns the information for use in the Object Inspector to be able to
  106.       show the approprate tools.  GetAttributes return a set of type
  107.       TPropertyAttributes:
  108.         paValueList:     The property editor can return an enumerated list of
  109.                          values for the property.  If GetValues calls Proc
  110.                          with values then this attribute should be set.  This
  111.                          will cause the drop-down button to appear to the right
  112.                          of the property in the Object Inspector.
  113.         paSortList:      Object Inspector to sort the list returned by
  114.                          GetValues.
  115.         paSubProperties: The property editor has sub-properties that will be
  116.                          displayed indented and below the current property in
  117.                          standard outline format. If GetProperties will
  118.                          generate property objects then this attribute should
  119.                          be set.
  120.         paDialog:        Indicates that the Edit method will bring up a
  121.                          dialog.  This will cause the '...' button to be
  122.                          displayed to the right of the property in the Object
  123.                          Inspector.
  124.         paMultiSelect:   Allows the property to be displayed when more than
  125.                          one component is selected.  Some properties are not
  126.                          approprate for multi-selection (e.g. the Name
  127.                          property).
  128.         paAutoUpdate:    Causes the SetValue method to be called on each
  129.                          change made to the editor instead of after the change
  130.                          has been approved (e.g. the Caption property).
  131.         paReadOnly:      Value is not allowed to change.
  132.         paRevertable:    Allows the property to be reverted to the original
  133.                          value.  Things that shouldn't be reverted are nested
  134.                          properties (e.g. Fonts) and elements of a composite
  135.                          property such as set element values.
  136.     GetComponent
  137.       Returns the Index'th component being edited by this property editor.  This
  138.       is used to retieve the components.  A property editor can only refer to
  139.       multiple components when paMultiSelect is returned from GetAttributes.
  140.     GetEditLimit
  141.       Returns the number of character the user is allowed to enter for the
  142.       value.  The inplace editor of the object inspector will be have its
  143.       text limited set to the return value.  By default this limit is 255.
  144.     GetName
  145.       Returns a the name of the property.  By default the value is retrieved
  146.       from the type information with all underbars replaced by spaces.  This
  147.       should only be overriden if the name of the property is not the name
  148.       that should appear in the Object Inspector.
  149.     GetProperties
  150.       Should be overriden to call PropertyProc for every sub-property (or nested
  151.       property) of the property begin edited and passing a new TPropertyEdtior
  152.       for each sub-property.  By default, PropertyProc is not called and no
  153.       sub-properties are assumed.  TClassProperty will pass a new property
  154.       editor for each published property in a class.  TSetProperty passes a
  155.       new editor for each element in the set.
  156.     GetPropType
  157.       Returns the type information pointer for the propertie(s) being edited.
  158.     GetValue
  159.       Returns the string value of the property. By default this returns
  160.       '(unknown)'.  This should be overriden to return the appropriate value.
  161.     GetValues
  162.       Called when paValueList is returned in GetAttributes.  Should call Proc
  163.       for every value that is acceptable for this property.  TEnumProperty
  164.       will pass every element in the enumeration.
  165.     Initialize
  166.       Called after the property editor has been created but before it is used.
  167.       Many times property editors are created and because they are not a common
  168.       property across the entire selection they are thrown away.  Initialize is
  169.       called after it is determined the property editor is going to be used by
  170.       the object inspector and not just thrown away.
  171.     SetValue(Value)
  172.       Called to set the value of the property.  The property editor should be
  173.       able to translate the string and call one of the SetXxxValue methods. If
  174.       the string is not in the correct format or not an allowed value, the
  175.       property editor should generate an exception describing the problem. Set
  176.       value can ignore all changes and allow all editing of the property be
  177.       accomplished through the Edit method (e.g. the Picture property).
  178.  
  179.   Properties and methods useful in creating a new TPropertyEditor classes:
  180.  
  181.     Name property
  182.       Returns the name of the property returned by GetName
  183.     PrivateDirectory property
  184.       It is either the .EXE or the "working directory" as specified in
  185.       the registry under the key:
  186.         "HKEY_CURRENT_USER\Software\Borland\Delphi\3.0\Globals\PrivateDir"
  187.       If the property editor needs auxilury or state files (templates, examples,
  188.       etc) they should be stored in this directory.
  189.     Properties indexed property
  190.       The TProperty objects representing all the components being edited
  191.       by the property editor.  If more than one component is selected, one
  192.       TProperty object is created for each component.  Typically, it is not
  193.       necessary to use this array since the Get/SetXxxValue methods will
  194.       propagate the values appropriatly.
  195.     Value property
  196.       The current value, as a string, of the property as returned by GetValue.
  197.     Modified
  198.       Called to indicate the value of the property has been modified.  Called
  199.       automatically by the SetXxxValue methods.  If you call a TProperty
  200.       SetXxxValue method directly, you *must* call Modified as well.
  201.     GetXxxValue
  202.       Gets the value of the first property in the Properties property.  Calls
  203.       the appropriate TProperty GetXxxValue method to retrieve the value.
  204.     SetXxxValue
  205.       Sets the value of all the properties in the Properties property.  Calls
  206.       the approprate TProperty SetXxxxValue methods to set the value. }
  207.  
  208.   TPropertyAttribute = (paValueList, paSubProperties, paDialog,
  209.     paMultiSelect, paAutoUpdate, paSortList, paReadOnly, paRevertable);
  210.   TPropertyAttributes = set of TPropertyAttribute;
  211.  
  212.   TPropertyEditor = class;
  213.  
  214.   TInstProp = record
  215.     Instance: TPersistent;
  216.     PropInfo: PPropInfo;
  217.   end;
  218.  
  219.   PInstPropList = ^TInstPropList;
  220.   TInstPropList = array[0..1023] of TInstProp;
  221.  
  222.   TGetPropEditProc = procedure(Prop: TPropertyEditor) of object;
  223.  
  224.   TPropertyEditor = class
  225.   protected
  226.     function GetPropInfo: PPropInfo;
  227.     function GetFloatValue: Extended;
  228.     function GetFloatValueAt(Index: Integer): Extended;
  229.     function GetMethodValue: TMethod;
  230.     function GetMethodValueAt(Index: Integer): TMethod;
  231.     function GetOrdValue: Longint;
  232.     function GetOrdValueAt(Index: Integer): Longint;
  233.     function GetStrValue: string;
  234.     function GetStrValueAt(Index: Integer): string;
  235.     function GetVarValue: Variant;
  236.     function GetVarValueAt(Index: Integer): Variant;
  237.     procedure Modified;
  238.     procedure SetFloatValue(Value: Extended);
  239.     procedure SetMethodValue(const Value: TMethod);
  240.     procedure SetOrdValue(Value: Longint);
  241.     procedure SetStrValue(const Value: string);
  242.     procedure SetVarValue(const Value: Variant);
  243.   public
  244.     destructor Destroy; override;
  245.     procedure Activate; virtual;
  246.     function AllEqual: Boolean; virtual;
  247.     procedure Edit; virtual;
  248.     function GetAttributes: TPropertyAttributes; virtual;
  249.     function GetComponent(Index: Integer): TPersistent;
  250.     function GetEditLimit: Integer; virtual;
  251.     function GetName: string; virtual;
  252.     procedure GetProperties(Proc: TGetPropEditProc); virtual;
  253.     function GetPropType: PTypeInfo;
  254.     function GetValue: string; virtual;
  255.     procedure GetValues(Proc: TGetStrProc); virtual;
  256.     procedure Initialize; virtual;
  257.     procedure Revert;
  258.     procedure SetValue(const Value: string); virtual;
  259.     function ValueAvailable: Boolean;
  260.     property Designer: TFormDesigner;
  261.     property PrivateDirectory: string;
  262.     property PropCount: Integer;
  263.     property Value: string;
  264.   end;
  265.  
  266.   TPropertyEditorClass = class of TPropertyEditor;
  267.  
  268. { TOrdinalProperty
  269.   The base class of all ordinal property editors.  It established that ordinal
  270.   properties are all equal if the GetOrdValue all return the same value. }
  271.  
  272.   TOrdinalProperty = class(TPropertyEditor)
  273.     function AllEqual: Boolean; override;
  274.     function GetEditLimit: Integer; override;
  275.   end;
  276.  
  277. { TIntegerProperty
  278.   Default editor for all Longint properties and all subtypes of the Longint
  279.   type (i.e. Integer, Word, 1..10, etc.).  Retricts the value entrered into
  280.   the property to the range of the sub-type. }
  281.  
  282.   TIntegerProperty = class(TOrdinalProperty)
  283.   public
  284.     function GetValue: string; override;
  285.     procedure SetValue(const Value: string); override;
  286.   end;
  287.  
  288. { TCharProperty
  289.   Default editor for all Char properties and sub-types of Char (i.e. Char,
  290.   'A'..'Z', etc.). }
  291.  
  292.   TCharProperty = class(TOrdinalProperty)
  293.   public
  294.     function GetValue: string; override;
  295.     procedure SetValue(const Value: string); override;
  296.   end;
  297.  
  298. { TEnumProperty
  299.   The default property editor for all enumerated properties (e.g. TShape =
  300.   (sCircle, sTriangle, sSquare), etc.). }
  301.  
  302.   TEnumProperty = class(TOrdinalProperty)
  303.   public
  304.     function GetAttributes: TPropertyAttributes; override;
  305.     function GetValue: string; override;
  306.     procedure GetValues(Proc: TGetStrProc); override;
  307.     procedure SetValue(const Value: string); override;
  308.   end;
  309.  
  310.   TBoolProperty = class(TEnumProperty)
  311.     function GetValue: string; override;
  312.     procedure GetValues(Proc: TGetStrProc); override;
  313.     procedure SetValue(const Value: string); override;
  314.   end;
  315.  
  316. { TFloatProperty
  317.   The default property editor for all floating point types (e.g. Float,
  318.   Single, Double, etc.) }
  319.  
  320.   TFloatProperty = class(TPropertyEditor)
  321.   public
  322.     function AllEqual: Boolean; override;
  323.     function GetValue: string; override;
  324.     procedure SetValue(const Value: string); override;
  325.   end;
  326.  
  327. { TStringProperty
  328.   The default property editor for all strings and sub types (e.g. string,
  329.   string[20], etc.). }
  330.  
  331.   TStringProperty = class(TPropertyEditor)
  332.   public
  333.     function AllEqual: Boolean; override;
  334.     function GetEditLimit: Integer; override;
  335.     function GetValue: string; override;
  336.     procedure SetValue(const Value: string); override;
  337.   end;
  338.  
  339. { TSetElementProperty
  340.   A property editor that edits an individual set element.  GetName is
  341.   changed to display the set element name instead of the property name and
  342.   Get/SetValue is changed to reflect the individual element state.  This
  343.   editor is created by the TSetProperty editor. }
  344.  
  345.   TSetElementProperty = class(TPropertyEditor)
  346.   public
  347.     destructor Destroy; override;
  348.     function AllEqual: Boolean; override;
  349.     function GetAttributes: TPropertyAttributes; override;
  350.     function GetName: string; override;
  351.     function GetValue: string; override;
  352.     procedure GetValues(Proc: TGetStrProc); override;
  353.     procedure SetValue(const Value: string); override;
  354.    end;
  355.  
  356. { TSetProperty
  357.   Default property editor for all set properties. This editor does not edit
  358.   the set directly but will display sub-properties for each element of the
  359.   set. GetValue displays the value of the set in standard set syntax. }
  360.  
  361.   TSetProperty = class(TOrdinalProperty)
  362.   public
  363.     function GetAttributes: TPropertyAttributes; override;
  364.     procedure GetProperties(Proc: TGetPropEditProc); override;
  365.     function GetValue: string; override;
  366.   end;
  367.  
  368. { TClassProperty
  369.   Default property editor for all objects.  Does not allow modifing the
  370.   property but does display the class name of the object and will allow the
  371.   editing of the object's properties as sub-properties of the property. }
  372.  
  373.   TClassProperty = class(TPropertyEditor)
  374.   public
  375.     function GetAttributes: TPropertyAttributes; override;
  376.     procedure GetProperties(Proc: TGetPropEditProc); override;
  377.     function GetValue: string; override;
  378.   end;
  379.  
  380. { TMethodProperty
  381.   Property editor for all method properties. }
  382.  
  383.   TMethodProperty = class(TPropertyEditor)
  384.   public
  385.     function AllEqual: Boolean; override;
  386.     procedure Edit; override;
  387.     function GetAttributes: TPropertyAttributes; override;
  388.     function GetEditLimit: Integer; override;
  389.     function GetValue: string; override;
  390.     procedure GetValues(Proc: TGetStrProc); override;
  391.     procedure SetValue(const AValue: string); override;
  392.     function GetFormMethodName: string; virtual;
  393.     function GetTrimmedEventName: string;
  394.   end;
  395.  
  396. { TComponentProperty
  397.   The default editor for TComponents.  It does not allow editing of the
  398.   properties of the component.  It allow the user to set the value of this
  399.   property to point to a component in the same form that is type compatible
  400.   with the property being edited (e.g. the ActiveControl property). }
  401.  
  402.   TComponentProperty = class(TPropertyEditor)
  403.   public
  404.     function GetAttributes: TPropertyAttributes; override;
  405.     function GetEditLimit: Integer; override;
  406.     function GetValue: string; override;
  407.     procedure GetValues(Proc: TGetStrProc); override;
  408.     procedure SetValue(const Value: string); override;
  409.   end;
  410.  
  411. { TComponentNameProperty
  412.   Property editor for the Name property.  It restricts the name property
  413.   from being displayed when more than one component is selected. }
  414.  
  415.   TComponentNameProperty = class(TStringProperty)
  416.   public
  417.     function GetAttributes: TPropertyAttributes; override;
  418.     function GetEditLimit: Integer; override;
  419.   end;
  420.  
  421. { TFontNameProperty
  422.   Editor for the TFont.FontName property.  Displays a drop-down list of all
  423.   the fonts known by Windows.}
  424.  
  425.   TFontNameProperty = class(TStringProperty)
  426.   public
  427.     function GetAttributes: TPropertyAttributes; override;
  428.     procedure GetValues(Proc: TGetStrProc); override;
  429.   end;
  430.  
  431. { TFontCharsetProperty
  432.   Editor for the TFont.Charset property.  Displays a drop-down list of the
  433.   character-set by Windows.}
  434.  
  435.   TFontCharsetProperty = class(TIntegerProperty)
  436.   public
  437.     function GetAttributes: TPropertyAttributes; override;
  438.     function GetValue: string; override;
  439.     procedure GetValues(Proc: TGetStrProc); override;
  440.     procedure SetValue(const Value: string); override;
  441.   end;
  442.  
  443. { TImeNameProperty
  444.   Editor for the TImeName property.  Displays a drop-down list of all
  445.   the IME names known by Windows.}
  446.  
  447.   TImeNameProperty = class(TStringProperty)
  448.   public
  449.     function GetAttributes: TPropertyAttributes; override;
  450.     procedure GetValues(Proc: TGetStrProc); override;
  451.   end;
  452.  
  453. { TColorProperty
  454.   Property editor for the TColor type.  Displays the color as a clXXX value
  455.   if one exists, otherwise displays the value as hex.  Also allows the
  456.   clXXX value to be picked from a list. }
  457.  
  458.   TColorProperty = class(TIntegerProperty)
  459.   public
  460.     procedure Edit; override;
  461.     function GetAttributes: TPropertyAttributes; override;
  462.     function GetValue: string; override;
  463.     procedure GetValues(Proc: TGetStrProc); override;
  464.     procedure SetValue(const Value: string); override;
  465.   end;
  466.  
  467. { TCursorProperty
  468.   Property editor for the TCursor type.  Displays the color as a crXXX value
  469.   if one exists, otherwise displays the value as hex.  Also allows the
  470.   clXXX value to be picked from a list. }
  471.  
  472.   TCursorProperty = class(TIntegerProperty)
  473.   public
  474.     function GetAttributes: TPropertyAttributes; override;
  475.     function GetValue: string; override;
  476.     procedure GetValues(Proc: TGetStrProc); override;
  477.     procedure SetValue(const Value: string); override;
  478.   end;
  479.  
  480. { TFontProperty
  481.   Property editor the Font property.  Brings up the font dialog as well as
  482.   allowing the properties of the object to be edited. }
  483.  
  484.   TFontProperty = class(TClassProperty)
  485.   public
  486.     procedure Edit; override;
  487.     function GetAttributes: TPropertyAttributes; override;
  488.   end;
  489.  
  490. { TModalResultProperty }
  491.  
  492.   TModalResultProperty = class(TIntegerProperty)
  493.   public
  494.     function GetAttributes: TPropertyAttributes; override;
  495.     function GetValue: string; override;
  496.     procedure GetValues(Proc: TGetStrProc); override;
  497.     procedure SetValue(const Value: string); override;
  498.   end;
  499.  
  500. { TShortCutProperty
  501.   Property editor the the ShortCut property.  Allows both typing in a short
  502.   cut value or picking a short-cut value from a list. }
  503.  
  504.   TShortCutProperty = class(TOrdinalProperty)
  505.   public
  506.     function GetAttributes: TPropertyAttributes; override;
  507.     function GetValue: string; override;
  508.     procedure GetValues(Proc: TGetStrProc); override;
  509.     procedure SetValue(const Value: string); override;
  510.   end;
  511.  
  512. { TMPFilenameProperty
  513.   Property editor for the TMediaPlayer.  Displays an File Open Dialog
  514.   for the name of the media file.}
  515.  
  516.   TMPFilenameProperty = class(TStringProperty)
  517.   public
  518.     procedure Edit; override;
  519.     function GetAttributes: TPropertyAttributes; override;
  520.   end;
  521.  
  522. { TTabOrderProperty
  523.   Property editor for the TabOrder property.  Prevents the property from being
  524.   displayed when more than one component is selected. }
  525.  
  526.   TTabOrderProperty = class(TIntegerProperty)
  527.   public
  528.     function GetAttributes: TPropertyAttributes; override;
  529.   end;
  530.  
  531. { TCaptionProperty
  532.   Property editor for the Caption and Text properties.  Updates the value of
  533.   the property for each change instead on when the property is approved. }
  534.  
  535.   TCaptionProperty = class(TStringProperty)
  536.   public
  537.     function GetAttributes: TPropertyAttributes; override;
  538.   end;
  539.  
  540. { TDateProperty
  541.   Property editor for date portion of TDateTime type. }
  542.  
  543.   TDateProperty = class(TPropertyEditor)
  544.     function GetAttributes: TPropertyAttributes; override;
  545.     function GetValue: string; override;
  546.     procedure SetValue(const Value: string); override;
  547.   end;
  548.  
  549. { TTimeProperty
  550.   Property editor for time portion of TDateTime type. }
  551.  
  552.   TTimeProperty = class(TPropertyEditor)
  553.     function GetAttributes: TPropertyAttributes; override;
  554.     function GetValue: string; override;
  555.     procedure SetValue(const Value: string); override;
  556.   end;
  557.  
  558. { TDateTimeProperty
  559.   Edits both date and time data... simultaneously!  }
  560.  
  561.   TDateTimeProperty = class(TPropertyEditor)
  562.     function GetAttributes: TPropertyAttributes; override;
  563.     function GetValue: string; override;
  564.     procedure SetValue(const Value: string); override;
  565.   end;
  566.  
  567.   EPropertyError = class(Exception);
  568.  
  569. { TComponentEditor
  570.   A component editor is created for each component that is selected in the
  571.   form designer based on the component's type (see GetComponentEditor and
  572.   RegisterComponentEditor).  When the component is double-clicked the Edit
  573.   method is called.  When the context menu for the component is invoked the
  574.   GetVerbCount and GetVerb methods are called to build the menu.  If one
  575.   of the verbs are selected ExecuteVerb is called.  Paste is called whenever
  576.   the component is pasted to the clipboard.  You only need to create a
  577.   component editor if you wish to add verbs to the context menu, change
  578.   the default double-click behavior, or paste an additional clipboard format.
  579.   The default component editor (TDefaultEditor) implements Edit to searchs the
  580.   properties of the component and generates (or navigates to) the OnCreate,
  581.   OnChanged, or OnClick event (whichever it finds first).  Whenever the
  582.   component modifies the component is *must* call Designer.Modified to inform
  583.   the designer that the form has been modified.
  584.  
  585.     Create(AComponent, ADesigner)
  586.       Called to create the component editor.  AComponent is the component to
  587.       be edited by the editor.  ADesigner is an interface to the designer to
  588.       find controls and create methods (this is not use often).
  589.     Edit
  590.       Called when the user double-clicks the component. The component editor can
  591.       bring up a dialog in responce to this method, for example, or some kind
  592.       of design expert.  If GetVerbCount is greater than zero, edit will execute
  593.       the first verb in the list (ExecuteVerb(0)).
  594.     ExecuteVerb(Index)
  595.       The Index'ed verb was selected by the use off the context menu.  The
  596.       meaning of this is determined by component editor.
  597.     GetVerb
  598.       The component editor should return a string that will be displayed in the
  599.       context menu.  It is the responsibility of the component editor to place
  600.       the & character and the '...' characters as appropriate.
  601.     GetVerbCount
  602.       The number of valid indexs to GetVerb and Execute verb.  The index assumed
  603.       to be zero based (i.e. 0..GetVerbCount - 1).
  604.     Copy
  605.       Called when the component is being copyied to the clipboard.  The
  606.       component's filed image is already on the clipboard.  This gives the
  607.       component editor a chance to paste a different type of format which is
  608.       ignored by the designer but might be recoginized by another application. }
  609.  
  610.   TComponentEditor = class
  611.   public
  612.     constructor Create(AComponent: TComponent; ADesigner: TFormDesigner); virtual;
  613.     procedure Edit; virtual;
  614.     procedure ExecuteVerb(Index: Integer); virtual;
  615.     function GetVerb(Index: Integer): string; virtual;
  616.     function GetVerbCount: Integer; virtual;
  617.     procedure Copy; virtual;
  618.     property Component: TComponent;
  619.     property Designer: TFormDesigner;
  620.   end;
  621.  
  622.   TComponentEditorClass = class of TComponentEditor;
  623.  
  624.   TDefaultEditor = class(TComponentEditor)
  625.   protected
  626.     procedure EditProperty(PropertyEditor: TPropertyEditor;
  627.       var Continue, FreeEditor: Boolean); virtual;
  628.   public
  629.     procedure Edit; override;
  630.   end;
  631.  
  632. { Global variables initialized internally by the form designer }
  633.  
  634. type
  635.   TFreeCustomModulesProc = procedure (Group: Integer);
  636.  
  637. var
  638.   FreeCustomModulesProc: TFreeCustomModulesProc;
  639.  
  640. { RegisterPropertyEditor
  641.   Registers a new property editor for the given type.  When a component is
  642.   selected the Object Inspector will create a property editor for each
  643.   of the component's properties.  The property editor is created based on
  644.   the type of the property.  If, for example, the property type is an
  645.   Integer, the property editor for Integer will be created (by default
  646.   that would be TIntegerProperty). Most properties do not need specialized
  647.   property editors.  For example, if the property is an ordinal type the
  648.   default property editor will restrict the range to the ordinal subtype
  649.   range (e.g. a property of type TMyRange = 1..10 will only allow values
  650.   between 1 and 10 to be entered into the property).  Enumerated types will
  651.   display a drop-down list of all the enumerated values (e.g. TShapes =
  652.   (sCircle, sSquare, sTriangle) will be edited by a drop-down list containing
  653.   only sCircle, sSquare and sTriangle).  A property editor need only be
  654.   created if default property editor or none of the existing property editors
  655.   are sufficient to edit the property.  This is typically because the
  656.   property is an object.  The properties are looked up newest to oldest.
  657.   This allows and existing property editor replaced by a custom property
  658.   editor.
  659.  
  660.     PropertyType
  661.       The type information pointer returned by the TypeInfo built-in function
  662.       (e.g. TypeInfo(TMyRange) or TypeInfo(TShapes)).
  663.  
  664.     ComponentClass
  665.       Type type of the component to which to restrict this type editor.  This
  666.       parameter can be left nil which will mean this type editor applies to all
  667.       properties of PropertyType.
  668.  
  669.     PropertyName
  670.       The name of the property to which to restrict this type editor.  This
  671.       parameter is ignored if ComponentClass is nil.  This paramter can be
  672.       an empty string ('') which will mean that this editor applies to all
  673.       properties of PropertyType in ComponentClass.
  674.  
  675.     EditorClass
  676.       The class of the editor to be created whenever a property of the type
  677.       passed in PropertyTypeInfo is displayed in the Object Inspector.  The
  678.       class will be created by calling EditorClass.Create. }
  679.  
  680. procedure RegisterPropertyEditor(PropertyType: PTypeInfo; ComponentClass: TClass;
  681.   const PropertyName: string; EditorClass: TPropertyEditorClass);
  682.  
  683. type
  684.   TPropertyMapperFunc = function(Obj: TPersistent;
  685.     PropInfo: PPropInfo): TPropertyEditorClass;
  686.     
  687. procedure RegisterPropertyMapper(Mapper: TPropertyMapperFunc);
  688.  
  689. procedure GetComponentProperties(Components: TComponentList;
  690.   Filter: TTypeKinds; Designer: TFormDesigner; Proc: TGetPropEditProc);
  691.  
  692. procedure RegisterComponentEditor(ComponentClass: TComponentClass;
  693.   ComponentEditor: TComponentEditorClass);
  694.  
  695. function GetComponentEditor(Component: TComponent;
  696.   Designer: TFormDesigner): TComponentEditor;
  697.  
  698. { Custom modules }
  699. { A custom module allows containers that descend from classes other than TForm
  700.   to be created and edited by the form designer. This is useful for other form
  701.   like containers (e.g. a report designer) or for specialized forms (e.g. an
  702.   ActiveForm) or for generic component containers (e.g. a TDataModule). It is
  703.   assumed that the base class registered will call InitInheritedComponent in its
  704.   constructor which will initialize the component from the associated DFM file
  705.   stored in the programs resources. See the constructors of TDataModule and
  706.   TForm for examples of how to write such a constructor.
  707.  
  708.   The following designer assumptions are made, depending on the base components
  709.   ancestor,
  710.  
  711.     If ComponentBaseClass descends from TForm,
  712.  
  713.        it is designed by creating an instance of the component as the form.
  714.        Allows designing TForm descendents and modifying their properties as
  715.        well as the form properties
  716.  
  717.     If ComponentBaseClass descends from TWinControl (but not TForm),
  718.  
  719.        it is designed by creating an instance of the control, placing it into a
  720.        design-time form.  The form's client size is in the default size of the
  721.        control.
  722.  
  723.     If ComponentBaseClass descends from TDataModule,
  724.  
  725.        it is designed by creating and instance of the class and creating a
  726.        special non-visual container designer to edit the components and display
  727.        the icons of the contained components.
  728.  
  729.   The module will appear in the project file with a colon and the base class
  730.   name appended after the component name (e.g. MyDataModle: TDataModule).
  731.  
  732.   Note it is not legal to register anything that does not desend from one of
  733.   the above.
  734.  
  735.   TCustomModule class
  736.     This an instance of this class is created for each custom module that is
  737.     loaded. This class is also destroyed whenever the module is unloaded.
  738.     The Saving method is called prior to the file being saved. When the context
  739.     menu for the module is invoked the GetVerbCount and GetVerb methods are
  740.     called to build the menu.  If one of the verbs are selected ExecuteVerb is
  741.     called.
  742.  
  743.     ExecuteVerb(Index)
  744.       The Index'ed verb was selected by the use off the context menu.  The
  745.       meaning of this is determined by custom module.
  746.     GetAttributes
  747.       Only used for TWinControl object to determine if the control is "client
  748.       aligned" in the designer or if the object should sized independently
  749.       from the designer.  This is a set for future expansion.
  750.     GetVerb(Index)
  751.       The custom module should return a string that will be displayed in the
  752.       context menu.  It is the responsibility of the custom module to place
  753.       the & character and the '...' characters as appropriate.
  754.     GetVerbCount
  755.       The number of valid indexs to GetVerb and Execute verb.  The index assumed
  756.       to be zero based (i.e. 0..GetVerbCount - 1).
  757.     Saving
  758.       Called prior to the module being saved.
  759.     ValidateComponent(Component)
  760.       ValidateCompoennt is called whenever a component is created by the
  761.       user for the designer to contain.  The intent is for this procedure to
  762.       raise an exception with a descriptive message if the component is not
  763.       applicable for the container. For example, a TComponent module should
  764.       throw an exception if the component descends from TControl.
  765.     Root
  766.       This is the instance being designed.}
  767.  
  768. type
  769.   TCustomModuleAttribute = (cmaVirtualSize);
  770.   TCustomModuleAttributes = set of TCustomModuleAttribute;
  771.  
  772.   TCustomModule = class
  773.   public
  774.     constructor Create(ARoot: TComponent); virtual;
  775.     procedure ExecuteVerb(Index: Integer); virtual;
  776.     function GetAttributes: TCustomModuleAttributes; virtual;
  777.     function GetVerb(Index: Integer): string; virtual;
  778.     function GetVerbCount: Integer; virtual;
  779.     procedure Saving; virtual;
  780.     procedure ValidateComponent(Component: TComponent); virtual;
  781.     property Root: TComponent;
  782.   end;
  783.  
  784.   TCustomModuleClass = class of TCustomModule;
  785.  
  786.   TRegisterCustomModuleProc = procedure (Group: Integer;
  787.     ComponentBaseClass: TComponentClass;
  788.     CustomModuleClass: TCustomModuleClass);
  789.  
  790. procedure RegisterCustomModule(ComponentBaseClass: TComponentClass;
  791.   CustomModuleClass: TCustomModuleClass);
  792.  
  793. var
  794.   RegisterCustomModuleProc: TRegisterCustomModuleProc;
  795.  
  796. { Routines used by the form designer for package management }
  797.  
  798. function NewEditorGroup: Integer;
  799. procedure FreeEditorGroup(Group: Integer);
  800.  
  801. implementation
  802.