home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / sibdemo3.zip / SOURCE.DAT / SOURCE / SPCC / TOOLSAPI.PAS < prev   
Pascal/Delphi Source File  |  1997-12-03  |  20KB  |  407 lines

  1.  
  2. {╔══════════════════════════════════════════════════════════════════════════╗
  3.  ║                                                                          ║
  4.  ║     Sibyl Portable Component Classes                                     ║
  5.  ║                                                                          ║
  6.  ║     Copyright (C) 1995,97 SpeedSoft Germany,   All rights reserved.      ║
  7.  ║                                                                          ║
  8.  ╚══════════════════════════════════════════════════════════════════════════╝}
  9.  
  10. Unit ToolsAPI;
  11.  
  12. Interface
  13.  
  14. Uses Classes,Forms,Graphics,editors;
  15.  
  16. Type
  17.   //Tools Service API. the Reference For This Class Is ToolServices And Is created by the SP/2
  18.   //IDE ON Library Initialization
  19.   TCreateModuleFlag = (cmfAddToProject,cmfShowSource,cmfShowForm,
  20.                        cmfUnNamed,cmfNewUnit,cmfNewForm,cmfMainForm,cmfMarkModified,
  21.                        cmfNewFile,cmfExisting);
  22.  
  23.   TCreateModuleFlags = Set Of TCreateModuleFlag;
  24.  
  25.   TProjectEnumProc = Function(Param: Pointer;Const FileName, UnitName,
  26.                               FormName:String):Boolean;
  27.  
  28.   TFileNotification = (fnFileOpening, fnFileOpened, fnFileClosing,
  29.                        fnProjectOpening, fnProjectOpened, fnProjectClosing, fnAddedToProject,
  30.                        fnRemovedFromProject, fnDefaultDesktopLoad, fnDefaultDesktopSave,
  31.                        fnProjectDesktopLoad, fnProjectDesktopSave, fnProjectSaved, fnFileSaved);
  32.  
  33.   TIMainMenuIntf = Class;
  34.  
  35.   TIAddInNotifier = Class
  36.         Procedure FileNotification(NotifyCode: TFileNotification;
  37.                                    Const FileName:String;Var Cancel:Boolean); Virtual;Abstract;
  38.   End;
  39.  
  40.   TIModuleInterface=Class;
  41.  
  42.   TIToolServices = Class
  43.     //Opens A New project. If PrjName Is Empty, Create A New, Empty project.
  44.     Function OpenProject(Const PrjName:String):Boolean; Virtual;Abstract;
  45.     //Extended Version Of OpenProject
  46.     Function OpenProjectEx(Const PrjName:String;VisualProject,CreateNew:Boolean):Boolean;Virtual;Abstract;
  47.     //Close project And return True ON Success
  48.     Function CloseProject:Boolean; Virtual;Abstract;
  49.     //determines If A named project can be opened, no Load
  50.     Function OpenProjectInfo(Const PrjName:String):Boolean; Virtual;Abstract;
  51.     //save Current project And return True ON Success
  52.     Function SaveProject:Boolean; Virtual;Abstract;
  53.     //returns True If specified File Is Open Or can be Loaded
  54.     Function OpenFile(Const FileName:String):Boolean; Virtual;Abstract;
  55.     //Closes Open Editor File, If it Is Not Open return also True
  56.     Function CloseFile(Const FileName:String):Boolean; Virtual;Abstract;
  57.     //Saves the specified files, If it Is Not Open return also True
  58.     Function SaveFile(Const FileName:String):Boolean; Virtual;Abstract;
  59.     //creates A New Module
  60.     Function CreateModule(Const ModuleName:String;
  61.                           Source, Form: TMemoryStream;
  62.                           CreateFlags: TCreateModuleFlags):Boolean; Virtual;Abstract;
  63.     //Extended Version Of CreateModule
  64.     Function CreateModuleEx(Const ModuleName, FormName, AncestorClass:String;
  65.                             Source, Form: TMemoryStream;
  66.                             CreateFlags: TCreateModuleFlags):TIModuleInterface; Virtual;Abstract;
  67.     //returns IDE Application Form
  68.     Function GetParentForm:TForm; Virtual;Abstract;
  69.     //returns Current project Name
  70.     Function GetProjectName:String; Virtual;Abstract;
  71.     //returns primary File Of project
  72.     Function GetPrimaryFile:String;Virtual;Abstract;
  73.     //returns Count Of units belonging To the Current project
  74.     Function GetUnitCount:LongInt; Virtual;Abstract;
  75.     //returns full Name Of project Unit With specified Index
  76.     Function GetUnitName(Index:LongInt):String; Virtual;Abstract;
  77.     //calls EnumProc For each Unit In the project
  78.     Function EnumProjectUnits(EnumProc: TProjectEnumProc;Param: Pointer):Boolean; Virtual;Abstract;
  79.     //return All files that belong To the Current project
  80.     Procedure GetProjectFiles(AStrings:TStrings);Virtual;Abstract;
  81.     //return Number Of available Forms In Current project
  82.     Function GetFormCount:LongInt; Virtual;Abstract;
  83.     //Get Name Of Form With specified Index
  84.     Function GetFormName(Index:LongInt):String; Virtual;Abstract;
  85.     //Get full Name Of Current File Or Form-Unit-File, Empty String If no File Is Active
  86.     Function GetCurrentFile:String; Virtual;Abstract;
  87.     //returns True If specified File Is Open
  88.     Function IsFileOpen(Const FileName:String):Boolean; Virtual;Abstract;
  89.     //Generate New Unit Name And File Name
  90.     Function GetNewModuleName(Var UnitIdent,FileName:String):Boolean; Virtual;Abstract;
  91.     //Get Count Of Currently installed Component modules (units)
  92.     Function GetModuleCount:LongInt; Virtual;Abstract;
  93.     //Get Component Unit Name With specified Index
  94.     Function GetModuleName(Index:LongInt):String; Virtual;Abstract;
  95.     //Get Component Count Of Component Unit With specified Index
  96.     Function GetComponentCount(Index:LongInt):LongInt; Virtual;Abstract;
  97.     //Get Component Name from Component Unit With specified Index
  98.     Function GetComponentName(ModIndex,CompIndex:LongInt):String; Virtual;Abstract;
  99.     //Get Interface For A File Loaded into the Editor
  100.     Function GetModuleInterface(Const FileName:String):TIModuleInterface; Virtual;Abstract;
  101.     //Get Interface For A Form And its associated Editor File
  102.     Function GetFormModuleInterface(Const FormName:String):TIModuleInterface; Virtual;Abstract;
  103.     //gets IDE main Menu
  104.     Function GetMainMenu:TIMainMenuIntf; Virtual;Abstract;
  105.     //Adds A Notification Proc
  106.     //gets main Menu Handle - Use With care
  107.     Function GetMainMenuHandle:TMenu;Virtual;Abstract;
  108.     Function AddNotifier(AddInNotifier:TIAddInNotifier):Boolean; Virtual;Abstract;
  109.     //Remove Notification Proc
  110.     Function RemoveNotifier(AddInNotifier:TIAddInNotifier):Boolean; Virtual;Abstract;
  111.     //Get Version Of the IDE
  112.     Function GetVersion:LongInt; Virtual;Abstract;
  113.   End;
  114.  
  115.   TIMenuItemIntf=Class;
  116.  
  117.   TIMenuFlag = (mfInvalid, mfEnabled, mfVisible, mfChecked, mfBreak, mfBarBreak,mfRadioItem);
  118.   TIMenuFlags = Set Of TIMenuFlag;
  119.  
  120.   TIMenuClickEvent = Procedure(Sender:TIMenuItemIntf) Of Object;
  121.  
  122.   //note: All TIMainMenuIntf queried MUST be freed by the client !!
  123.   TIMainMenuIntf = Class
  124.     //returns Interface For IDE main Menu (Top Level)
  125.     Function GetMenuItems: TIMenuItemIntf; Virtual;Abstract;
  126.     //returns Interface For Menu Item Or Submenu With specified Name
  127.     Function FindMenuItem(Const MenuName:String):TIMenuItemIntf; Virtual;Abstract;
  128.   End;
  129.  
  130.   //note: All TIMenuItemIntf queried MUST be freed by the client !!
  131.   TIMenuItemIntf = Class
  132.     //Destroys Menu Item associated With the Interface, returns False If the Item was created by IDE
  133.     Function DestroyMenuItem:Boolean; Virtual;Abstract;
  134.     //Get Index Of This Item within the Menu Tree
  135.     Function GetIndex:LongInt; Virtual;Abstract;
  136.     //Get Count Of submenus For This Interface
  137.     Function GetItemCount:LongInt; Virtual;Abstract;
  138.     //Get Submenu Item With specified Index
  139.     Function GetItem(Index:LongInt):TIMenuItemIntf; Virtual;Abstract;
  140.     //Get (internal !) Name Of Menu associated With Interface, See also GetCaption
  141.     Function GetName:String; Virtual;Abstract;
  142.     //Get parent Interface Of Item Or Nil
  143.     Function GetParent: TIMenuItemIntf; Virtual;Abstract;
  144.     //Get Caption Of Menu associated With the Interface
  145.     Function GetCaption:String; Virtual;Abstract;
  146.     //Set Caption Of Menu associated With the Interface
  147.     Function SetCaption(Const Caption:String):Boolean; Virtual;Abstract;
  148.     //Get ShortCut Of Menu
  149.     Function GetShortCut:TKeyCode; Virtual;Abstract;
  150.     //Set ShortCut Of Menu
  151.     Function SetShortCut(ShortCut:TKeyCode):Boolean; Virtual;Abstract;
  152.     //Get Flags Of Menu
  153.     Function GetFlags:TIMenuFlags; Virtual;Abstract;
  154.     //Set Flags Of Menu
  155.     Function SetFlags(Mask,Flags: TIMenuFlags):Boolean; Virtual;Abstract;
  156.     //Get Hint Of Menu
  157.     Function GetHint:String; Virtual;Abstract;
  158.     //Set Hint Of Menu
  159.     Function SetHint(Hint:String):Boolean; Virtual;Abstract;
  160.     //Get help context Of Menu
  161.     Function GetContext:THelpContext; Virtual;Abstract;
  162.     //Set help context For Menu
  163.     Function SetContext(context:THelpContext):Boolean; Virtual;Abstract;
  164.     //Get OnClick event For the Menu
  165.     Function GetOnClick:TIMenuClickEvent; Virtual;Abstract;
  166.     //Set OnClick event For the Menu
  167.     Function SetOnClick(Click:TIMenuClickEvent):Boolean; Virtual;Abstract;
  168.     //inserts an Item
  169.     Function InsertItem(Index:LongInt;Caption,Name,Hint:String;
  170.                         ShortCut:TKeyCode;context:THelpContext;Flags:TIMenuFlags;
  171.                         EventHandler:TIMenuClickEvent):TIMenuItemIntf; Virtual;Abstract;
  172.     //Get Menu Item associates With the Interface - Use With care !
  173.     Function GetMenuEntry:TMenuItem; Virtual;Abstract;
  174.   End;
  175.  
  176.   TNotifyCode = (ncModuleDeleted, ncModuleRenamed, ncEditorModified,
  177.                  ncFormModified, ncEditorSelected, ncFormSelected, ncBeforeSave,
  178.                  ncAfterSave, ncFormSaving, ncProjResModified);
  179.  
  180.   TIModuleNotifier=Class
  181.     Procedure notify(NotifyCode:TNotifyCode); Virtual;Abstract;
  182.     Procedure ComponentRenamed(ComponentHandle:Pointer;
  183.                                Const OldName,NewName:String); Virtual;Abstract;
  184.   End;
  185.  
  186.   TIEditorInterface=Class;
  187.   TIFormInterface=Class;
  188.  
  189.   //represents File And Forms Open In A project
  190.   //note: All TIModuleInterface queried MUST be freed by the client !!
  191.   TIModuleInterface=Class
  192.     //Get Editor Interface For the Module Or Nil
  193.     Function GetEditorInterface:TIEditorInterface; Virtual;Abstract;
  194.     //Get Form Interface For the Module Or Nil
  195.     Function GetFormInterface:TIFormInterface; Virtual;Abstract;
  196.     //Close the Module without Saving (See save)
  197.     Function Close:Boolean; Virtual;Abstract;
  198.     //Saves the Module, If forcesave Is True, the user will Not be asked
  199.     Function save(forcesave: Boolean):Boolean; Virtual;Abstract;
  200.     //Rename Module
  201.     Function Rename(Const NewName:String):Boolean; Virtual;Abstract;
  202.     //Show Source File Of Editor In topmost Editor Window
  203.     Function ShowSource:Boolean; Virtual;Abstract;
  204.     //Show Form Of Module If present
  205.     Function ShowForm:Boolean; Virtual;Abstract;
  206.     //Add Notification Proc
  207.     Function AddNotifier(AModuleNotifier:TIModuleNotifier):Boolean; Virtual;Abstract;
  208.     //Remove Notification Proc
  209.     Function RemoveNotifier(AModuleNotifier:TIModuleNotifier):Boolean; Virtual;Abstract;
  210.   End;
  211.  
  212.   TEditPos = Record
  213.     Col: SMALLINT;
  214.     Line: LongInt;
  215.   End;
  216.  
  217.   TSyntaxHighlighter = (shNone, shPascal, shSQL, shQuery);
  218.  
  219.   //represents Editor File opened
  220.   //note: All TIEditorInterface queried MUST be freed by the client !!
  221.   TIEditorInterface=Class
  222.     //gets Text At specified Position
  223.     Function GetText(Position:LongInt;Var Buffer;BufSize:LongInt):LongInt;Virtual;Abstract;
  224.     //copies Text from actual Position To Pos into the Clipboard
  225.     Function CopyTo(Pos:LongInt):Boolean; Virtual;Abstract;
  226.     //deletes Text from actual positon To Pos into the Clipboard
  227.     Function DeleteTo(Pos:LongInt):Boolean; Virtual;Abstract;
  228.     //Insert specified Text At Current Position
  229.     Function Insert(Var Buffer;BufSize:LongInt):Boolean; Virtual;Abstract;
  230.     //Get Editor Position
  231.     Function Position: LongInt; Virtual;Abstract;
  232.     //Get File Name Of Editor
  233.     Function FileName:String; Virtual;Abstract;
  234.     //Get total Lines Of edit Buffer
  235.     Function LinesInBuffer:LongInt; Virtual;Abstract;
  236.     //returns True If edit Buffer was Modified
  237.     Function BufferModified:Boolean; Virtual;Abstract;
  238.     //Forces the Editor To be Modified
  239.     Function MarkModified:Boolean; Virtual;Abstract;
  240.     //sets color Table
  241.     Function SetSyntaxHighlighter(SyntaxHighlighter:TSyntaxHighlighter):TSyntaxHighlighter;Virtual;Abstract;
  242.     //Get Editor Position
  243.     Function GetPos:TEditPos; Virtual;Abstract;
  244.     //Set Editor positon
  245.     Procedure SetPos(Value: TEditPos); Virtual;Abstract;
  246.     //Get Editor Form Instance - Use With care !
  247.     Function GetEditorForm:TEditor; Virtual;Abstract;
  248.  
  249.     Property CursorPos: TEditPos Read GetPos Write SetPos;
  250.   End;
  251.  
  252.   TIComponentInterface=Class;
  253.  
  254.   //represents Form inside designer
  255.   //note: All TIFormInterface queried MUST be freed by the client !!
  256.   TIFormInterface=Class
  257.     //returns Unit File Name For the Form
  258.     Function FileName:String; Virtual;Abstract;
  259.     //returns True If the Form Is Modified
  260.     Function FormModified:Boolean; Virtual;Abstract;
  261.     //Forces the Form To be marked As Modified
  262.     Function MarkModified:Boolean; Virtual;Abstract;
  263.     //Get Component Interface For the Form
  264.     Function GetFormComponent:TIComponentInterface; Virtual;Abstract;
  265.     //Get Form Instance For the Form - Use With care !
  266.     Function GetFormInstance:TForm; Virtual;Abstract;
  267.     //Find Component by Name And return Interface
  268.     Function FindComponent(Const Name:String):TIComponentInterface; Virtual;Abstract;
  269.     //Get Component Interface from Instance
  270.     Function GetComponentFromHandle(ComponentHandle:TObject):TIComponentInterface; Virtual;Abstract;
  271.     //Get Selection Count In Form Editor
  272.     Function GetSelCount:LongInt; Virtual;Abstract;
  273.     //Get Selected Component Interface from Index
  274.     Function GetSelComponent(Index:LongInt):TIComponentInterface; Virtual;Abstract;
  275.     //gets parent Interface that created the Form
  276.     Function GetCreateParent: TIComponentInterface; Virtual;Abstract;
  277.     //Create New Component, If containter Is Not Nil, it Is the parent, If Name Is Empty, it Is auto-created
  278.     Function CreateComponent(Container: TIComponentInterface;Const TypeName,Name:String;
  279.                              X,Y,W,H:LongInt):TIComponentInterface; Virtual;Abstract;
  280.   End;
  281.  
  282.   TPropertyType = (ptUnknown, ptInteger, ptChar, ptEnumeration, ptFloat,
  283.                    ptString, ptSet, ptClass, ptMethod, ptWChar, ptLString, ptLWString,
  284.                    ptVariant,ptBoolean,ptCString,ptClassRef,ptRecord);
  285.  
  286.   TGetChildCallback = Function(Param:Pointer;ComponentInterface:TIComponentInterface):Boolean;
  287.  
  288.   //represents Components inside A Form
  289.   //note: All TIComponentInterface queried MUST be freed by the client !!
  290.   TIComponentInterface=Class
  291.     //returns Component Type As String
  292.     Function GetComponentType:String; Virtual;Abstract;
  293.     //returns Component Instance - Use With care !
  294.     Function GetComponentHandle:TComponent; Virtual;Abstract;
  295.     //returns parent Interface
  296.     Function GetParent:TIComponentInterface; Virtual;Abstract;
  297.     //returns True If Interface Is A descendant Of TControl
  298.     Function IsTControl:Boolean; Virtual;Abstract;
  299.     //returns Property Count For the Interface Instance
  300.     Function GetPropCount:LongInt; Virtual;Abstract;
  301.     //Get Property Name from Index
  302.     Function GetPropName(Index:LongInt):String; Virtual;Abstract;
  303.     //Get Property Type from Index
  304.     Function GetPropType(Index:LongInt;Var TypeLen:LongInt):TPropertyType; Virtual;Abstract;
  305.     //Get Property Type from Name
  306.     Function GetPropTypeByName(Const Name:String;Var TypeLen:LongInt):TPropertyType; Virtual;Abstract;
  307.     //gets Property Value from Index
  308.     Function GetPropValue(Index:LongInt;Var Value):Boolean; Virtual;Abstract;
  309.     //gets Property Value from Name
  310.     Function GetPropValueByName(Const Name:String;Var Value):Boolean; Virtual;Abstract;
  311.     //sets Property from Index
  312.     Function SetProp(Index:LongInt;Const Value):Boolean; Virtual;Abstract;
  313.     //sets Property from Name
  314.     Function SetPropByName(Const Name:String;Const Value):Boolean; Virtual;Abstract;
  315.     //Enums component's Children
  316.     Function GetChildren(Param:Pointer;Proc:TGetChildCallback): Boolean; Virtual;Abstract;
  317.     //Get Count Of Child Controls
  318.     Function GetControlCount:LongInt; Virtual;Abstract;
  319.     //Get Control from Index
  320.     Function GetControl(Index:LongInt):TIComponentInterface; Virtual;Abstract;
  321.     //Get Count Of Child Components
  322.     Function GetComponentCount:LongInt; Virtual;Abstract;
  323.     //Get Child Component from Index
  324.     Function GetComponent(Index:LongInt):TIComponentInterface; Virtual;Abstract;
  325.     //Select Component
  326.     Function Select: Boolean; Virtual;Abstract;
  327.     //Focus Component
  328.     Function Focus: Boolean; Virtual;Abstract;
  329.     //Delete Component
  330.     Function Delete: Boolean; Virtual;Abstract;
  331.     //Set event Property And Add Some Code To it (optional)
  332.     Function SetEventProperty(Const PropertyName,MethodName:String;Code:TStream):Boolean;Virtual;Abstract;
  333.     //Get method Name Of A event Property
  334.     Function GetEventProperty(Const PropertyName:String):String;Virtual;Abstract;
  335.   End;
  336.  
  337.   //Expert interfaces - provided by client, created And destroyed by IDE
  338.   TExpertStyle = (esStandard, esForm, esProject, esAddIn);
  339.   TExpertState = Set Of (esEnabled, esChecked);
  340.  
  341.   TIExpert=Class(TComponent)
  342.     //Required: returns Name Of Expert
  343.     Function GetName:String; Virtual;Abstract;
  344.     //Required For styles esForm And esProject: returns author Of Expert
  345.     Function GetAuthor:String; Virtual;Abstract;
  346.     //Required For styles esForm And esProject: returns comment Of Expert
  347.     Function GetComment:String; Virtual;Abstract;
  348.     //Required For styles esForm And esProject: returns page For repository, Empty String For Default
  349.     Function GetPage:String; Virtual;Abstract;
  350.     //Required For styles esForm And esProject: returns Bitmap For Expert, Nil For Default
  351.     Function GetGlyph: TBitmap; Virtual;Abstract;
  352.     //Required: returns Style Of Expert
  353.     Function GetStyle: TExpertStyle; Virtual;Abstract;
  354.     //Required If Style Is esStandard: returns Menu State Of Expert
  355.     Function GetState: TExpertState; Virtual;Abstract;
  356.     //Required: returns UNIQUE IDString Of Expert. Supposed format Is: CompanyName.ExpertFunction, ex. SpeedSoft.AppExpert
  357.     Function GetIDString:String; Virtual;Abstract;
  358.     //Required If Style Is esStandard:returns Menu Text For Expert
  359.     Function GetMenuText:String; Virtual;Abstract;
  360.     //Required If Style Is esForm,esStandard Or esProject: called whenever project Is invoked
  361.     Procedure Execute; Virtual;Abstract;
  362.     //Required: Is called whenever the IDE registeres This Expert
  363.     Procedure Register; Virtual;Abstract;
  364.     //Required: Is called whenever the IDE unloads This Expert. the Expert Is destroyed after This call
  365.     Procedure Unload; Virtual;Abstract;
  366.   End;
  367.  
  368.   TIExpertClass=Class Of TIExpert;
  369.  
  370. Const
  371.    ToolServices:TIToolServices=Nil;
  372.  
  373. Procedure RegisterLibraryExperts(Experts:Array Of TIExpertClass);
  374. Procedure FreeAllLibraryExperts;
  375.  
  376. Implementation
  377.  
  378. Procedure RegisterLibraryExperts(Experts:Array Of TIExpertClass);
  379. Var T:LongInt;
  380. Begin
  381.      For T:=0 To High(Experts) Do LibExperts.Add(Experts[T]);
  382. End;
  383.  
  384. Procedure FreeAllLibraryExperts;
  385. Var T:LongInt;
  386.     Expert:TIExpert;
  387. Begin
  388.      LibExperts.Clear;
  389.      For T:=0 To LibExpertInstances.Count-1 Do
  390.      Begin
  391.           Expert:=TIExpert(LibExpertInstances.Items[T]);
  392.           Expert.Unload;
  393.           Expert.Destroy;
  394.      End;
  395.      LibExpertInstances.Clear;
  396. End;
  397.  
  398. Procedure RegisterToolsAPI(ToolServ:TIToolServices);
  399. Begin
  400.      ToolServices:=ToolServ;
  401. End;
  402.  
  403. Begin
  404.      RegisterToolsAPIProc:=Pointer(@RegisterToolsAPI);
  405. End.
  406.  
  407.