home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 February / DPPCPRO0299.ISO / February / Delphi / Install / DATA.Z / EDITINTF.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-11  |  24.3 KB  |  475 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Delphi Visual Component Library                 }
  4. {                                                       }
  5. {       Copyright (c) 1996 Borland International        }
  6. {                                                       }
  7. {*******************************************************}
  8.  
  9. unit EditIntf;
  10.  
  11. interface
  12.  
  13. uses SysUtils, Windows, VirtIntf;
  14.  
  15. const
  16.   CursorPos = Integer(0);
  17.   ViewTopPos = Integer(1);
  18.  
  19. type
  20.   { Editor position expressed as column/line after tabs are expanded to spaces }
  21.   TEditPos = record
  22.     Col: SmallInt;
  23.     Line: Longint;
  24.   end;
  25.  
  26.   { Use the TIEditReader class to gain read access to an editor buffer:
  27.  
  28.     NOTES:
  29.       The buffer is accessed as a linear "file" with line breaks included.
  30.       This reader interface could be accessed through a custom read-only
  31.       TStream descendant.
  32.  
  33.     WARNING!!!
  34.      o A TIEditReader should never be active at the same time as a TIEditWriter.
  35.   }
  36.  
  37.   TIEditReader = class(TInterface)
  38.   public
  39.     function GetText(Position: Longint; Buffer: PChar; Count: Longint): Longint;
  40.       virtual; stdcall; abstract;
  41.   end;
  42.  
  43.   { Use the TIEditWriter class to gain write access to an editor buffer:
  44.  
  45.     NOTES:
  46.      o As with the reader, the buffer is accessed as a linear "file" with
  47.        line breaks included.  The writer uses a "copy in place" metaphor for
  48.        modifying the editor buffer.  In other words, the writer can be thought
  49.        of as simply copying from one buffer to another.  All positions (Pos)
  50.        passed to the function are positions relative to the orginal file.  Due
  51.        to the "copy" metaphor of the writer it does not support moving backward
  52.        in the editor buffer. It is recomended that all modifications that must
  53.        be performed should be done from the start to the finish.
  54.      o After the TIEditWriter is freed(released), the undo-buffer of the editor
  55.        is flushed.
  56.  
  57.     WARNING!!!
  58.      o A TIEditWriter should never be active at the same time as a TIEditReader.
  59.   }
  60.  
  61.   TIEditWriter = class(TInterface)
  62.   public
  63.     function CopyTo(Pos: Longint): Boolean; virtual; stdcall; abstract;
  64.     function DeleteTo(Pos: Longint): Boolean; virtual; stdcall; abstract;
  65.     function Insert(Text: PChar): Boolean; virtual; stdcall; abstract;
  66.     function Position: Longint; virtual; stdcall; abstract;
  67.   end;
  68.  
  69.   { The TIEditView represents an individual view on an edit buffer:
  70.  
  71.     This interface allows the cursor and view positions to be accessed and
  72.     updated.  The only restriction on using this interface is that it should
  73.     not be held for any length of time.  Since a view can be deleted at any
  74.     time, the interface could become invalid.
  75.   }
  76.  
  77.   TIEditView = class(TInterface)
  78.   public
  79.     function GetPos(Index: Integer): TEditPos; virtual; stdcall; abstract;
  80.     procedure SetPos(Index: Integer; Value: TEditPos); virtual; stdcall; abstract;
  81.     function GetViewSize: TSize; virtual; stdcall; abstract;
  82.  
  83.     property CursorPos: TEditPos index CursorPos read GetPos write SetPos;
  84.     property TopPos: TEditPos index ViewTopPos read GetPos write SetPos;
  85.     property ViewSize: TSize read GetViewSize;
  86.   end;
  87.  
  88.   { The TIEditorInterface is the base interface to an editor buffer:
  89.  
  90.     Use this interface to obtain TIEditReader, TIEditWriter, and TIEditView
  91.     interfaces.
  92.  
  93.   }
  94.  
  95.   TSyntaxHighlighter = (shNone, shPascal, shSQL, shQuery);
  96.  
  97.   TIEditorInterface = class(TInterface)
  98.   public
  99.     function CreateReader: TIEditReader; virtual; stdcall; abstract;
  100.     function CreateWriter: TIEditWriter; virtual; stdcall; abstract;
  101.     function FileName: string; virtual; stdcall; abstract;
  102.     function LinesInBuffer: Longint; virtual; stdcall; abstract;
  103.     function BufferModified: Boolean; virtual; stdcall; abstract;
  104.     function MarkModified: Boolean; virtual; stdcall; abstract;
  105.     function SetSyntaxHighlighter(SyntaxHighlighter: TSyntaxHighlighter): TSyntaxHighlighter;
  106.       virtual; stdcall; abstract;
  107.     function GetViewCount: Integer; virtual; stdcall; abstract;
  108.     function GetView(Index: Integer): TIEditView; virtual; stdcall; abstract;
  109.   end;
  110.  
  111.   { The TIComponentInterface is the base interface for a component living
  112.     on a form/data module.  Never hold this interface for very long, since
  113.     the component may be deleted at any time.
  114.  
  115.     GetComponentType   - Returns a string representing the type of the
  116.                          component.
  117.     GetParent          - Returns the interface corresponding to the parent
  118.                          control if a TControl, otherwise returns the owner
  119.                          of the control.  If a TPersistent or the root object
  120.                          then it returns nil.
  121.     IsTControl         - Returns True if component is a TControl descendant
  122.     GetPropCount       - Returns the number of published properties on this
  123.                          component.
  124.     GetPropName        - Given the index, returns the property name.
  125.     GetPropType        - Given the index, returns the property type.
  126.     GetPropTypeByName  - Given the name, returns the poperty type
  127.     GetPropValue
  128.     GetPropValueByName - Given the index or name, returns the property value.
  129.                          The untyped var must be large enough to hold the
  130.                          returned value.  If the property is a descendant of
  131.                          TPersistent, the return value is a TIComponent-
  132.                          Interface. For properties of any other object type,
  133.                          the return value is nil.
  134.     SetPropValue
  135.     SetPropValueByName - Given the index or name, sets the property value.
  136.     GetControlCount    - Returns the number of child controls (if a TControl
  137.                          descendant, else returns 0).
  138.     GetControl         - Given the index, returns an interface to the
  139.                          child control.
  140.     GetComponentCount  - Returns the number of child components (if a
  141.                          TComponent descendant, else returns 0).
  142.     GetComponent       - Given the index, returns an interface to the
  143.                          child component.
  144.     Select             - Selects the component and updates the Object Inspector.
  145.     Focus              - Same as Select except it brings the form to front with
  146.                          the component selected.  If this interface is a Form/
  147.                          Data Module, then Focus only brings the form to front.
  148.     Delete             - Deletes the component from the form.  Following this
  149.                          call, this interface will now be invalid and must be
  150.                          freed.
  151.   }
  152.  
  153.   TIComponentInterface = class;
  154.  
  155.   TPropertyType = (ptUnknown, ptInteger, ptChar, ptEnumeration, ptFloat,
  156.     ptString, ptSet, ptClass, ptMethod, ptWChar, ptLString, ptLWString,
  157.     ptVariant);
  158.  
  159.   TGetChildCallback = function (Param: Pointer;
  160.     ComponentInterface: TIComponentInterface): Boolean stdcall;  
  161.  
  162.   TIComponentInterface = class(TInterface)
  163.   public
  164.     function GetComponentType: string; virtual; stdcall; abstract;
  165.     function GetComponentHandle: Pointer; virtual; stdcall; abstract;
  166.     function GetParent: TIComponentInterface; virtual; stdcall; abstract;
  167.     function IsTControl: Boolean; virtual; stdcall; abstract;
  168.     function GetPropCount: Integer; virtual; stdcall; abstract;
  169.     function GetPropName(Index: Integer): string; virtual; stdcall; abstract;
  170.     function GetPropType(Index: Integer): TPropertyType; virtual; stdcall; abstract;
  171.     function GetPropTypeByName(const Name: string): TPropertyType;
  172.       virtual; stdcall; abstract;
  173.     function GetPropValue(Index: Integer; var Value): Boolean;
  174.       virtual; stdcall; abstract;
  175.     function GetPropValueByName(const Name: string; var Value): Boolean;
  176.       virtual; stdcall; abstract;
  177.     function SetProp(Index: Integer; const Value): Boolean;
  178.       virtual; stdcall; abstract;
  179.     function SetPropByName(const Name: string; const Value): Boolean;
  180.       virtual; stdcall; abstract;
  181.     function GetChildren(Param: Pointer; Proc: TGetChildCallback): Boolean;
  182.       virtual; stdcall; abstract;
  183.     function GetControlCount: Integer; virtual; stdcall; abstract;
  184.     function GetControl(Index: Integer): TIComponentInterface;
  185.       virtual; stdcall; abstract;
  186.     function GetComponentCount: Integer; virtual; stdcall; abstract;
  187.     function GetComponent(Index: Integer): TIComponentInterface;
  188.       virtual; stdcall; abstract;
  189.     function Select: Boolean; virtual; stdcall; abstract;
  190.     function Focus: Boolean; virtual; stdcall; abstract;
  191.     function Delete: Boolean; virtual; stdcall; abstract;
  192.   end;
  193.  
  194.   { The TIFormInterface is the base interface to a designed form/data module:
  195.  
  196.      FileName          - Returns the actual filename of the form.
  197.      FormModified      - Returns True if the form has been modified. This is
  198.                          independent of the source code.
  199.      MarkModified      - Forces the form to be marked as modified.  Returns
  200.                          True is successful.
  201.      GetFormComponent  - Returns a TIComponentInterface representing the root
  202.                          component of the Form/Data module.
  203.      FincComponent     - Given the name, returns a component interface of the
  204.                          component on the Form/Data module.  Nil if the
  205.                          component is not found.
  206.      GetComponentFromHandle - Given the component handle (from
  207.                          TIModuleNotifier.ComponentRenamed or
  208.                          TIComponentInterface.GetComponentHandle) returns a
  209.                          TIComponentInterface for that component.
  210.      GetSelCount       - Returns the number of Selected components
  211.      GetSelComponent   - Returns the index'th selected component on the form/
  212.                          Data Module.
  213.      GetCreateParent   - Returns a TIComponentInterface used to parent the
  214.                          component currently being created.
  215.                          NOTE: This is only valid from a TIModuleNotifier.
  216.                          ComponentRenamed callback when OldName = '' and
  217.                          NewName <> ''
  218.      CreateComponent   - Adds a new component of type "TypeName" to the form.
  219.                          if Container is nil, and the component to be added is
  220.                          a TWinControl, then it is parented to the currently
  221.                          selected container.  If Container is non-nil, and it
  222.                          is a TWinControl, then the component is parented to
  223.                          that control.  Set Name to an empty string to allow
  224.                          the component's name to be auto-generated.  Set W and
  225.                          H to -1 to use the default size of the component. Set
  226.                          X and Y to -1 to center the component on the form.
  227.   }
  228.  
  229.   TIFormInterface = class(TInterface)
  230.   public
  231.     function FileName: string; virtual; stdcall; abstract;
  232.     function FormModified: Boolean; virtual; stdcall; abstract;
  233.     function MarkModified: Boolean; virtual; stdcall; abstract;
  234.     function GetFormComponent: TIComponentInterface; virtual; stdcall; abstract;
  235.     function FindComponent(const Name: string): TIComponentInterface;
  236.       virtual; stdcall; abstract;
  237.     function GetComponentFromHandle(ComponentHandle: Pointer): TIComponentInterface;
  238.       virtual; stdcall; abstract;
  239.     function GetSelCount: Integer; virtual; stdcall; abstract;
  240.     function GetSelComponent(Index: Integer): TIComponentInterface;
  241.       virtual; stdcall; abstract;
  242.     function GetCreateParent: TIComponentInterface; virtual; stdcall; abstract;
  243.     function CreateComponent(Container: TIComponentInterface;
  244.       const TypeName: string; X, Y, W, H: Integer): TIComponentInterface;
  245.       virtual; stdcall; abstract;
  246.   end;
  247.  
  248.   TResHeaderValue = (hvFlags, hvLanguage, hvDataVersion, hvVersion,
  249.     hvCharacteristics);
  250.  
  251.   { TIResourceEntry is a raw interface to a resource entry in the project's
  252.     resource file (<projectname>.RES).
  253.  
  254.     This interface is a very raw.  No implication on what is contained within
  255.     a particular entry is made.  It if up to the add-in developer to interpret
  256.     the data accessed through this interface.  NOTE: The 'MAINICON' entry and
  257.     related entries should not be modified as these are maintained by Delphi.  
  258.  
  259.     GetResourceType
  260.     SetResourceType   - Sets and gets the resource type of this entry.  Follows
  261.                         Windows standard of specifying a type by name or value.
  262.                         If the high-word is 0, then the low-word is the
  263.                         resource type value, otherwise it is a pointer to a
  264.                         null terminated ANSI (byte per char) string. Most
  265.                         predefined types are by value.
  266.  
  267.     GetResourceName
  268.     SetResourceName   - Sets and gets the resource name of this entry.  Follows
  269.                         Windows standard of specifying a type by name or value.
  270.                         If the high-word is 0, then the low-word is the
  271.                         resource type value, otherwise it is a pointer to a
  272.                         null terminated ANSI (byte per char) string.
  273.  
  274.     GetHeaderValue
  275.     SetHeaderValue    - Gets and sets various resource header values.  Pass in
  276.                         one of the TResHeaderValues enums to indicate which
  277.                         value to get/set.  Although some values are 16bits
  278.                         (Word) these functions operation only on 32bits
  279.                         (Integer).
  280.  
  281.     GetData           - Returns a raw pointer to the actual resource data buffer.
  282.  
  283.     GetDataSize       - Returns the current size of the data buffer.
  284.  
  285.     SetDataSize       - Resizes the current data buffer.  If the size is
  286.                         smaller than the current size, the data is simply
  287.                         truncated without regard to its current contents.
  288.  
  289.     GetEntryHandle    - Returns a unique handle value identifying the resource
  290.                         entry.
  291.   }
  292.  
  293.   TIResourceEntry = class(TInterface)
  294.   public
  295.     function GetResourceType: PChar; virtual; stdcall; abstract;
  296.     function GetResourceName: PChar; virtual; stdcall; abstract;
  297.     function Change(NewType, NewName: PChar): Boolean; virtual; stdcall; abstract;
  298.     function GetHeaderValue(HeaderValue: TResHeaderValue;
  299.       var Value: Integer): Boolean; virtual; stdcall; abstract;
  300.     function SetHeaderValue(HeaderValue: TResHeaderValue;
  301.       Value: Integer): Boolean; virtual; stdcall; abstract;
  302.     function GetData: Pointer; virtual; stdcall; abstract;
  303.     function GetDataSize: Integer; virtual; stdcall; abstract;
  304.     function SetDataSize(NewSize: Integer): Boolean; virtual; stdcall; abstract;
  305.     function GetEntryHandle: Pointer; virtual; stdcall; abstract;
  306.   end;
  307.  
  308.   { The TIResourceFile is an interface on the project's resource file
  309.     (<projectname>.RES).
  310.  
  311.     GetEntryCount     - Returns the number of Resource entries.
  312.  
  313.     GetEntry          - Given an index, returns a TIResourceEntry of the
  314.                         index'th entry.
  315.  
  316.     FindEntry         - Given a Resource type and name, return a
  317.                         TIResourceEntry or nil if not found.
  318.  
  319.     DeleteEntry       - Given an entry handle, delete the given resource
  320.                         entry.
  321.  
  322.     CreateEntry       - Creates a new resource entry of the given type and name
  323.                         and returns a TIResourceEntry.  Returns nil if the
  324.                         entry already exists or any other error occurs.
  325.   }
  326.  
  327.   TIResourceFile = class(TInterface)
  328.   public
  329.     function FileName: string; virtual; stdcall; abstract;
  330.     function GetEntryCount: Integer; virtual; stdcall; abstract;
  331.     function GetEntry(Index: Integer): TIResourceEntry; virtual; stdcall; abstract;
  332.     function GetEntryFromHandle(EntryHandle: Pointer): TIResourceEntry; virtual; stdcall; abstract;
  333.     function FindEntry(ResType, Name: PChar): TIResourceEntry; virtual; stdcall; abstract;
  334.     function DeleteEntry(EntryHandle: Pointer): Boolean; virtual; stdcall; abstract;
  335.     function CreateEntry(ResType, Name: PChar; Flags, LanguageId: Word;
  336.       DataVersion, Version, Characteristics: Integer): TIResourceEntry; virtual; stdcall; abstract;
  337.   end;
  338.  
  339.   { The TIModuleNotifer interface is a client provided interface:
  340.  
  341.     Use this interface as a base to a client defined implementation.  An
  342.     instance of the TIModuleNotifer decendant is the registered with a
  343.     TIModuleInterface in order to recieve notifications for the events
  344.     defined by the TNotifyCode.
  345.  
  346.       ncModuleDeleted    - the Module associated with the TIModule is being
  347.                            freed.  Perform any clean-up and free all references
  348.                            to a TIModuleInterface, including un-registering
  349.                            the notifier class.
  350.       ncModuleRenamed    - The module was renamed by a "save as" operation.
  351.       ncEditorModified   - The edit buffer was modified by the user or through
  352.                            a TIEditWriter interface (internal of external).
  353.       ncFormModified     - The form was modified by the user or through
  354.                            a TIFormInterface (internal of external).
  355.       ncEditorSelected   - An edit view was selected and focused.
  356.       ncFormSelected     - The associated form was selected and focused.
  357.       ncBeforeSave       - This is sent right before the module (editor and
  358.                            possibly the form) is actually saved to the file
  359.                            system
  360.       ncAfterSave        - Like the ncBeforeSave this is after all saving has
  361.                            occured and was successful.
  362.       ncFormSaving       - This is sent just prior to the associated form is
  363.                            actually streamed out.  This *may* be sent after an
  364.                            ncBeforeSave, but not always.  This may be sent as
  365.                            a result of a project compile operated without an
  366.                            ncBeforSave being sent.
  367.       ncProjResModified  - If this notifier is attached to a project module,
  368.                            this event will be sent when the project resource
  369.                            file changes (mainly when the user changes the
  370.                            Icon, or other changes are made through the
  371.                            TIResourceFile interface).
  372.  
  373.       ComponentRenamed   - Before any component on the associated form/data
  374.                            model is renamed, this event is triggered allowing
  375.                            the interface to track any changes to component on
  376.                            a form.  If NewName is an empty string, component,
  377.                            OldName was deleted.  If OldName is an empty string,
  378.                            component NewName was added and you may call
  379.                            TIFormInterface.GetCreateParent to determine the
  380.                            container in which this component is being created.
  381.                            .GetCreateParent is only valid if component is a
  382.                            TControl.
  383.                            NOTE: This procedure will *NOT* be called when the
  384.                            form is being destroyed due to the form designer
  385.                            being destroyed.
  386.   }
  387.  
  388.   TNotifyCode = (ncModuleDeleted, ncModuleRenamed, ncEditorModified,
  389.     ncFormModified, ncEditorSelected, ncFormSelected, ncBeforeSave,
  390.     ncAfterSave, ncFormSaving, ncProjResModified);
  391.  
  392.   TIModuleNotifier = class(TInterface)
  393.   public
  394.     procedure Notify(NotifyCode: TNotifyCode); virtual; stdcall; abstract;
  395.     procedure ComponentRenamed(ComponentHandle: Pointer;
  396.       const OldName, NewName: string); virtual; stdcall; abstract;
  397.   end;
  398.  
  399.   { The TIModuleInterface represents any file/module open in the IDE:
  400.  
  401.     A module is simply a file, or a file and form.  Use this interface to gain
  402.     access to the edit buffer and form. There is only one instance of a
  403.     TIModuleInterface per module, but is reference counted so it can be treated
  404.     as separate instances.  When finished with the interface, the owner *must*
  405.     "free" it. For instance, if a TIModuleNotifier object is told that the
  406.     module was deleted.
  407.  
  408.     Functions:
  409.  
  410.     GetEditorInterface - This returns an interface to the associated edit
  411.                          buffer.
  412.     GetFormInterface   - This returns an interface to the associated form, if
  413.                          one exists.  Returns nil otherwise.
  414.     GetAncestortModule - Return the ancestor module to this Form/Data module
  415.                          if not a direct descendent of a TForm or TDataModule.
  416.     GetProjectResource - If this module interface is referencing a project
  417.                          module, this will return an interface on the project's
  418.                          resource.  Returns nil if this is not a project module
  419.                          interface. (this resource contains the application's
  420.                          main ICON as entry 'MAINICON').
  421.     IsProjectModule    - Returns True if this is a project module interface,
  422.                          False, otherwise.
  423.     Close              - Returns true if the module was closed.
  424.                          This may cause the ncModuleDeleted notification to
  425.                          be triggered.  If another form references this module
  426.                          through form inheritance, or form linking, the module
  427.                          will remain "open" but is marked for deletion.
  428.                          NOTE: This will close the module without saving or
  429.                                even asking the user to save. See the Save
  430.                                function.
  431.     Save               - Returns true if successfully saved. Pass True in order
  432.                          force the save operation without the user being asked.
  433.                          Otherwise the user will be asked.  If the module is
  434.                          marked UnNamed, the the "Save As" dialog will be
  435.                          presented to the user.
  436.     Rename             - Renames the current module. The form file name will be
  437.                          derived from the new name. An ncModuleRenamed
  438.                          notification will be sent.
  439.     GetFileSystem      - Returns true if able to get the current file system
  440.                          associated with this module. An empty string indicates
  441.                          the default file system.
  442.     SetFileSystem      - Returns true if able to set the file system to the
  443.                          indicated file system. An empty string indicates the
  444.                          default file system.  One use is in response to an
  445.                          ncModuleRenamed notification and tne new name is
  446.                          unavailable in the current file system.
  447.     ShowSource         - Selects and focuses the top-most edit buffer view.
  448.     ShowForm           - Selects and focused the form, if present.
  449.     AddNotifier        - Registers an instance of a descendant to TIModule-
  450.                          Notifier.
  451.     RemoveNotifier     - Removes a registered instance of a TIModuleNotifier.
  452.   }
  453.  
  454.   TIModuleInterface = class(TInterface)
  455.   public
  456.     function GetEditorInterface: TIEditorInterface; virtual; stdcall; abstract;
  457.     function GetFormInterface: TIFormInterface; virtual; stdcall; abstract;
  458.     function GetAncestorModule: TIModuleInterface; virtual; stdcall; abstract;
  459.     function GetProjectResource: TIResourceFile; virtual; stdcall; abstract;
  460.     function IsProjectModule: Boolean; virtual; stdcall; abstract;
  461.     function Close: Boolean; virtual; stdcall; abstract;
  462.     function Save(ForceSave: Boolean): Boolean; virtual; stdcall; abstract;
  463.     function Rename(const NewName: string): Boolean; virtual; stdcall; abstract;
  464.     function GetFileSystem(var FileSystem: string): Boolean; virtual; stdcall; abstract;
  465.     function SetFileSystem(const FileSystem: string): Boolean; virtual; stdcall; abstract;
  466.     function ShowSource: Boolean; virtual; stdcall; abstract;
  467.     function ShowForm: Boolean; virtual; stdcall; abstract;
  468.     function AddNotifier(AModuleNotifier: TIModuleNotifier): Boolean; virtual; stdcall; abstract;
  469.     function RemoveNotifier(AModuleNotifier: TIModuleNotifier): Boolean; virtual; stdcall; abstract;
  470.   end;
  471.  
  472. implementation
  473.  
  474. end.
  475.