home *** CD-ROM | disk | FTP | other *** search
/ Chip 1997 April / Chip_1997-04_cd.bin / prezent / cb / data.z / EDITINTF.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-01-16  |  24.5 KB  |  483 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. {$IFDEF PRONTO_SYNTAX}
  96.   TSyntaxHighlighter = (shNone, shC, shPascal, shSQL, shQuery);
  97. {$ELSE}
  98.   TSyntaxHighlighter = (shNone, shPascal, shSQL, shQuery);
  99. {$ENDIF}
  100.  
  101.   TIEditorInterface = class(TInterface)
  102.   public
  103.     function CreateReader: TIEditReader; virtual; stdcall; abstract;
  104.     function CreateWriter: TIEditWriter; virtual; stdcall; abstract;
  105.     function FileName: string; virtual; stdcall; abstract;
  106.     function LinesInBuffer: Longint; virtual; stdcall; abstract;
  107.     function BufferModified: Boolean; virtual; stdcall; abstract;
  108.     function MarkModified: Boolean; virtual; stdcall; abstract;
  109.     function SetSyntaxHighlighter(SyntaxHighlighter: TSyntaxHighlighter): TSyntaxHighlighter;
  110.       virtual; stdcall; abstract;
  111.     function GetViewCount: Integer; virtual; stdcall; abstract;
  112.     function GetView(Index: Integer): TIEditView; virtual; stdcall; abstract;
  113.   end;
  114.  
  115.   { The TIComponentInterface is the base interface for a component living
  116.     on a form/data module.  Never hold this interface for very long, since
  117.     the component may be deleted at any time.
  118.  
  119.     GetComponentType   - Returns a string representing the type of the
  120.                          component.
  121.     GetParent          - Returns the interface corresponding to the parent
  122.                          control if a TControl, otherwise returns the owner
  123.                          of the control.  If a TPersistent or the root object
  124.                          then it returns nil.
  125.     IsTControl         - Returns True if component is a TControl descendant
  126.     GetPropCount       - Returns the number of published properties on this
  127.                          component.
  128.     GetPropName        - Given the index, returns the property name.
  129.     GetPropType        - Given the index, returns the property type.
  130.     GetPropTypeByName  - Given the name, returns the poperty type
  131.     GetPropValue
  132.     GetPropValueByName - Given the index or name, returns the property value.
  133.                          The untyped var must be large enough to hold the
  134.                          returned value.  If the property is a descendant of
  135.                          TPersistent, the return value is a TIComponent-
  136.                          Interface. For properties of any other object type,
  137.                          the return value is nil.
  138.     SetPropValue
  139.     SetPropValueByName - Given the index or name, sets the property value.
  140.     GetControlCount    - Returns the number of child controls (if a TControl
  141.                          descendant, else returns 0).
  142.     GetControl         - Given the index, returns an interface to the
  143.                          child control.
  144.     GetComponentCount  - Returns the number of child components (if a
  145.                          TComponent descendant, else returns 0).
  146.     GetComponent       - Given the index, returns an interface to the
  147.                          child component.
  148.     Select             - Selects the component and updates the Object Inspector.
  149.     Focus              - Same as Select except it brings the form to front with
  150.                          the component selected.  If this interface is a Form/
  151.                          Data Module, then Focus only brings the form to front.
  152.     Delete             - Deletes the component from the form.  Following this
  153.                          call, this interface will now be invalid and must be
  154.                          freed.
  155.   }
  156.  
  157.   TIComponentInterface = class;
  158.  
  159. {$IFNDEF PRONTO_DUPNAMES}
  160.   TPropertyType = (ptUnknown,
  161. {$ELSE}
  162.   TPropertyType = (ptUNKNOWN,
  163. {$ENDIF}
  164.     ptInteger, ptChar, ptEnumeration, ptFloat, ptString, ptSet, ptClass,
  165.     ptMethod, ptWChar, ptLString, ptLWString, ptVariant);
  166.  
  167.   TGetChildCallback = function (Param: Pointer;
  168.     ComponentInterface: TIComponentInterface): Boolean stdcall;
  169.  
  170.   TIComponentInterface = class(TInterface)
  171.   public
  172.     function GetComponentType: string; virtual; stdcall; abstract;
  173.     function GetComponentHandle: Pointer; virtual; stdcall; abstract;
  174.     function GetParent: TIComponentInterface; virtual; stdcall; abstract;
  175.     function IsTControl: Boolean; virtual; stdcall; abstract;
  176.     function GetPropCount: Integer; virtual; stdcall; abstract;
  177.     function GetPropName(Index: Integer): string; virtual; stdcall; abstract;
  178.     function GetPropType(Index: Integer): TPropertyType; virtual; stdcall; abstract;
  179.     function GetPropTypeByName(const Name: string): TPropertyType;
  180.       virtual; stdcall; abstract;
  181.     function GetPropValue(Index: Integer; var Value): Boolean;
  182.       virtual; stdcall; abstract;
  183.     function GetPropValueByName(const Name: string; var Value): Boolean;
  184.       virtual; stdcall; abstract;
  185.     function SetProp(Index: Integer; const Value): Boolean;
  186.       virtual; stdcall; abstract;
  187.     function SetPropByName(const Name: string; const Value): Boolean;
  188.       virtual; stdcall; abstract;
  189.     function GetChildren(Param: Pointer; Proc: TGetChildCallback): Boolean;
  190.       virtual; stdcall; abstract;
  191.     function GetControlCount: Integer; virtual; stdcall; abstract;
  192.     function GetControl(Index: Integer): TIComponentInterface;
  193.       virtual; stdcall; abstract;
  194.     function GetComponentCount: Integer; virtual; stdcall; abstract;
  195.     function GetComponent(Index: Integer): TIComponentInterface;
  196.       virtual; stdcall; abstract;
  197.     function Select: Boolean; virtual; stdcall; abstract;
  198.     function Focus: Boolean; virtual; stdcall; abstract;
  199.     function Delete: Boolean; virtual; stdcall; abstract;
  200.   end;
  201.  
  202.   { The TIFormInterface is the base interface to a designed form/data module:
  203.  
  204.      FileName          - Returns the actual filename of the form.
  205.      FormModified      - Returns True if the form has been modified. This is
  206.                          independent of the source code.
  207.      MarkModified      - Forces the form to be marked as modified.  Returns
  208.                          True is successful.
  209.      GetFormComponent  - Returns a TIComponentInterface representing the root
  210.                          component of the Form/Data module.
  211.      FincComponent     - Given the name, returns a component interface of the
  212.                          component on the Form/Data module.  Nil if the
  213.                          component is not found.
  214.      GetComponentFromHandle - Given the component handle (from
  215.                          TIModuleNotifier.ComponentRenamed or
  216.                          TIComponentInterface.GetComponentHandle) returns a
  217.                          TIComponentInterface for that component.
  218.      GetSelCount       - Returns the number of Selected components
  219.      GetSelComponent   - Returns the index'th selected component on the form/
  220.                          Data Module.
  221.      GetCreateParent   - Returns a TIComponentInterface used to parent the
  222.                          component currently being created.
  223.                          NOTE: This is only valid from a TIModuleNotifier.
  224.                          ComponentRenamed callback when OldName = '' and
  225.                          NewName <> ''
  226.      CreateComponent   - Adds a new component of type "TypeName" to the form.
  227.                          if Container is nil, and the component to be added is
  228.                          a TWinControl, then it is parented to the currently
  229.                          selected container.  If Container is non-nil, and it
  230.                          is a TWinControl, then the component is parented to
  231.                          that control.  Set Name to an empty string to allow
  232.                          the component's name to be auto-generated.  Set W and
  233.                          H to -1 to use the default size of the component. Set
  234.                          X and Y to -1 to center the component on the form.
  235.   }
  236.  
  237.   TIFormInterface = class(TInterface)
  238.   public
  239.     function FileName: string; virtual; stdcall; abstract;
  240.     function FormModified: Boolean; virtual; stdcall; abstract;
  241.     function MarkModified: Boolean; virtual; stdcall; abstract;
  242.     function GetFormComponent: TIComponentInterface; virtual; stdcall; abstract;
  243.     function FindComponent(const Name: string): TIComponentInterface;
  244.       virtual; stdcall; abstract;
  245.     function GetComponentFromHandle(ComponentHandle: Pointer): TIComponentInterface;
  246.       virtual; stdcall; abstract;
  247.     function GetSelCount: Integer; virtual; stdcall; abstract;
  248.     function GetSelComponent(Index: Integer): TIComponentInterface;
  249.       virtual; stdcall; abstract;
  250.     function GetCreateParent: TIComponentInterface; virtual; stdcall; abstract;
  251.     function CreateComponent(Container: TIComponentInterface;
  252.       const TypeName: string; X, Y, W, H: Integer): TIComponentInterface;
  253.       virtual; stdcall; abstract;
  254.   end;
  255.  
  256.   TResHeaderValue = (hvFlags, hvLanguage, hvDataVersion, hvVersion,
  257.     hvCharacteristics);
  258.  
  259.   { TIResourceEntry is a raw interface to a resource entry in the project's
  260.     resource file (<projectname>.RES).
  261.  
  262.     This interface is a very raw.  No implication on what is contained within
  263.     a particular entry is made.  It if up to the add-in developer to interpret
  264.     the data accessed through this interface.  NOTE: The 'MAINICON' entry and
  265.     related entries should not be modified as these are maintained by Delphi.
  266.  
  267.     GetResourceType
  268.     SetResourceType   - Sets and gets the resource type 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. Most
  273.                         predefined types are by value.
  274.  
  275.     GetResourceName
  276.     SetResourceName   - Sets and gets the resource name of this entry.  Follows
  277.                         Windows standard of specifying a type by name or value.
  278.                         If the high-word is 0, then the low-word is the
  279.                         resource type value, otherwise it is a pointer to a
  280.                         null terminated ANSI (byte per char) string.
  281.  
  282.     GetHeaderValue
  283.     SetHeaderValue    - Gets and sets various resource header values.  Pass in
  284.                         one of the TResHeaderValues enums to indicate which
  285.                         value to get/set.  Although some values are 16bits
  286.                         (Word) these functions operation only on 32bits
  287.                         (Integer).
  288.  
  289.     GetData           - Returns a raw pointer to the actual resource data buffer.
  290.  
  291.     GetDataSize       - Returns the current size of the data buffer.
  292.  
  293.     SetDataSize       - Resizes the current data buffer.  If the size is
  294.                         smaller than the current size, the data is simply
  295.                         truncated without regard to its current contents.
  296.  
  297.     GetEntryHandle    - Returns a unique handle value identifying the resource
  298.                         entry.
  299.   }
  300.  
  301.   TIResourceEntry = class(TInterface)
  302.   public
  303.     function GetResourceType: PChar; virtual; stdcall; abstract;
  304.     function GetResourceName: PChar; virtual; stdcall; abstract;
  305.     function Change(NewType, NewName: PChar): Boolean; virtual; stdcall; abstract;
  306.     function GetHeaderValue(HeaderValue: TResHeaderValue;
  307.       var Value: Integer): Boolean; virtual; stdcall; abstract;
  308.     function SetHeaderValue(HeaderValue: TResHeaderValue;
  309.       Value: Integer): Boolean; virtual; stdcall; abstract;
  310.     function GetData: Pointer; virtual; stdcall; abstract;
  311.     function GetDataSize: Integer; virtual; stdcall; abstract;
  312.     function SetDataSize(NewSize: Integer): Boolean; virtual; stdcall; abstract;
  313.     function GetEntryHandle: Pointer; virtual; stdcall; abstract;
  314.   end;
  315.  
  316.   { The TIResourceFile is an interface on the project's resource file
  317.     (<projectname>.RES).
  318.  
  319.     GetEntryCount     - Returns the number of Resource entries.
  320.  
  321.     GetEntry          - Given an index, returns a TIResourceEntry of the
  322.                         index'th entry.
  323.  
  324.     FindEntry         - Given a Resource type and name, return a
  325.                         TIResourceEntry or nil if not found.
  326.  
  327.     DeleteEntry       - Given an entry handle, delete the given resource
  328.                         entry.
  329.  
  330.     CreateEntry       - Creates a new resource entry of the given type and name
  331.                         and returns a TIResourceEntry.  Returns nil if the
  332.                         entry already exists or any other error occurs.
  333.   }
  334.  
  335.   TIResourceFile = class(TInterface)
  336.   public
  337.     function FileName: string; virtual; stdcall; abstract;
  338.     function GetEntryCount: Integer; virtual; stdcall; abstract;
  339.     function GetEntry(Index: Integer): TIResourceEntry; virtual; stdcall; abstract;
  340.     function GetEntryFromHandle(EntryHandle: Pointer): TIResourceEntry; virtual; stdcall; abstract;
  341.     function FindEntry(ResType, Name: PChar): TIResourceEntry; virtual; stdcall; abstract;
  342.     function DeleteEntry(EntryHandle: Pointer): Boolean; virtual; stdcall; abstract;
  343.     function CreateEntry(ResType, Name: PChar; Flags, LanguageId: Word;
  344.       DataVersion, Version, Characteristics: Integer): TIResourceEntry; virtual; stdcall; abstract;
  345.   end;
  346.  
  347.   { The TIModuleNotifer interface is a client provided interface:
  348.  
  349.     Use this interface as a base to a client defined implementation.  An
  350.     instance of the TIModuleNotifer decendant is the registered with a
  351.     TIModuleInterface in order to recieve notifications for the events
  352.     defined by the TNotifyCode.
  353.  
  354.       ncModuleDeleted    - the Module associated with the TIModule is being
  355.                            freed.  Perform any clean-up and free all references
  356.                            to a TIModuleInterface, including un-registering
  357.                            the notifier class.
  358.       ncModuleRenamed    - The module was renamed by a "save as" operation.
  359.       ncEditorModified   - The edit buffer was modified by the user or through
  360.                            a TIEditWriter interface (internal of external).
  361.       ncFormModified     - The form was modified by the user or through
  362.                            a TIFormInterface (internal of external).
  363.       ncEditorSelected   - An edit view was selected and focused.
  364.       ncFormSelected     - The associated form was selected and focused.
  365.       ncBeforeSave       - This is sent right before the module (editor and
  366.                            possibly the form) is actually saved to the file
  367.                            system
  368.       ncAfterSave        - Like the ncBeforeSave this is after all saving has
  369.                            occured and was successful.
  370.       ncFormSaving       - This is sent just prior to the associated form is
  371.                            actually streamed out.  This *may* be sent after an
  372.                            ncBeforeSave, but not always.  This may be sent as
  373.                            a result of a project compile operated without an
  374.                            ncBeforSave being sent.
  375.       ncProjResModified  - If this notifier is attached to a project module,
  376.                            this event will be sent when the project resource
  377.                            file changes (mainly when the user changes the
  378.                            Icon, or other changes are made through the
  379.                            TIResourceFile interface).
  380.  
  381.       ComponentRenamed   - Before any component on the associated form/data
  382.                            model is renamed, this event is triggered allowing
  383.                            the interface to track any changes to component on
  384.                            a form.  If NewName is an empty string, component,
  385.                            OldName was deleted.  If OldName is an empty string,
  386.                            component NewName was added and you may call
  387.                            TIFormInterface.GetCreateParent to determine the
  388.                            container in which this component is being created.
  389.                            .GetCreateParent is only valid if component is a
  390.                            TControl.
  391.                            NOTE: This procedure will *NOT* be called when the
  392.                            form is being destroyed due to the form designer
  393.                            being destroyed.
  394.   }
  395.  
  396.   TNotifyCode = (ncModuleDeleted, ncModuleRenamed, ncEditorModified,
  397.     ncFormModified, ncEditorSelected, ncFormSelected, ncBeforeSave,
  398.     ncAfterSave, ncFormSaving, ncProjResModified);
  399.  
  400.   TIModuleNotifier = class(TInterface)
  401.   public
  402.     procedure Notify(NotifyCode: TNotifyCode); virtual; stdcall; abstract;
  403.     procedure ComponentRenamed(ComponentHandle: Pointer;
  404.       const OldName, NewName: string); virtual; stdcall; abstract;
  405.   end;
  406.  
  407.   { The TIModuleInterface represents any file/module open in the IDE:
  408.  
  409.     A module is simply a file, or a file and form.  Use this interface to gain
  410.     access to the edit buffer and form. There is only one instance of a
  411.     TIModuleInterface per module, but is reference counted so it can be treated
  412.     as separate instances.  When finished with the interface, the owner *must*
  413.     "free" it. For instance, if a TIModuleNotifier object is told that the
  414.     module was deleted.
  415.  
  416.     Functions:
  417.  
  418.     GetEditorInterface - This returns an interface to the associated edit
  419.                          buffer.
  420.     GetFormInterface   - This returns an interface to the associated form, if
  421.                          one exists.  Returns nil otherwise.
  422.     GetAncestortModule - Return the ancestor module to this Form/Data module
  423.                          if not a direct descendent of a TForm or TDataModule.
  424.     GetProjectResource - If this module interface is referencing a project
  425.                          module, this will return an interface on the project's
  426.                          resource.  Returns nil if this is not a project module
  427.                          interface. (this resource contains the application's
  428.                          main ICON as entry 'MAINICON').
  429.     IsProjectModule    - Returns True if this is a project module interface,
  430.                          False, otherwise.
  431.     Close              - Returns true if the module was closed.
  432.                          This may cause the ncModuleDeleted notification to
  433.                          be triggered.  If another form references this module
  434.                          through form inheritance, or form linking, the module
  435.                          will remain "open" but is marked for deletion.
  436.                          NOTE: This will close the module without saving or
  437.                                even asking the user to save. See the Save
  438.                                function.
  439.     Save               - Returns true if successfully saved. Pass True in order
  440.                          force the save operation without the user being asked.
  441.                          Otherwise the user will be asked.  If the module is
  442.                          marked UnNamed, the the "Save As" dialog will be
  443.                          presented to the user.
  444.     Rename             - Renames the current module. The form file name will be
  445.                          derived from the new name. An ncModuleRenamed
  446.                          notification will be sent.
  447.     GetFileSystem      - Returns true if able to get the current file system
  448.                          associated with this module. An empty string indicates
  449.                          the default file system.
  450.     SetFileSystem      - Returns true if able to set the file system to the
  451.                          indicated file system. An empty string indicates the
  452.                          default file system.  One use is in response to an
  453.                          ncModuleRenamed notification and tne new name is
  454.                          unavailable in the current file system.
  455.     ShowSource         - Selects and focuses the top-most edit buffer view.
  456.     ShowForm           - Selects and focused the form, if present.
  457.     AddNotifier        - Registers an instance of a descendant to TIModule-
  458.                          Notifier.
  459.     RemoveNotifier     - Removes a registered instance of a TIModuleNotifier.
  460.   }
  461.  
  462.   TIModuleInterface = class(TInterface)
  463.   public
  464.     function GetEditorInterface: TIEditorInterface; virtual; stdcall; abstract;
  465.     function GetFormInterface: TIFormInterface; virtual; stdcall; abstract;
  466.     function GetAncestorModule: TIModuleInterface; virtual; stdcall; abstract;
  467.     function GetProjectResource: TIResourceFile; virtual; stdcall; abstract;
  468.     function IsProjectModule: Boolean; virtual; stdcall; abstract;
  469.     function Close: Boolean; virtual; stdcall; abstract;
  470.     function Save(ForceSave: Boolean): Boolean; virtual; stdcall; abstract;
  471.     function Rename(const NewName: string): Boolean; virtual; stdcall; abstract;
  472.     function GetFileSystem(var FileSystem: string): Boolean; virtual; stdcall; abstract;
  473.     function SetFileSystem(const FileSystem: string): Boolean; virtual; stdcall; abstract;
  474.     function ShowSource: Boolean; virtual; stdcall; abstract;
  475.     function ShowForm: Boolean; virtual; stdcall; abstract;
  476.     function AddNotifier(AModuleNotifier: TIModuleNotifier): Boolean; virtual; stdcall; abstract;
  477.     function RemoveNotifier(AModuleNotifier: TIModuleNotifier): Boolean; virtual; stdcall; abstract;
  478.   end;
  479.  
  480. implementation
  481.  
  482. end.
  483.