home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / ArrangeScript / Sources / PlugIn.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-21  |  7.9 KB  |  186 lines  |  [TEXT/CWIE]

  1. /*
  2.     This file defines a "generic" plugin class for Arrange 2.0.
  3.     To use it, you should modify the file 'SubClass.h', which subclasses
  4.     the Plugin class definition by adding new fields and private functions,
  5.     and implementing the appropriate methods in another C++ source file.
  6.  
  7.     I'd strongly suggest that you base your plugin on one of the examples,
  8.     or at least be familiar with one or more of them. You should not have to
  9.     examine or make changes to this file or Plugin.cp. Most of what is
  10.     contained here hides the details of interfacing Arrange and the module
  11.     'hook' mechanism to C++
  12.  
  13.     This version of Plugin.h was written by Paul Chambers on 11/27/94 and
  14.     last updated on 12/6/84.
  15.     It is derived from the original GenericPlugin.h, written by
  16.     Steve Newman on 12/24/93 and last updated on 7/15/94.
  17. */
  18.  
  19. #ifndef __Plugin_h__
  20. #define __Plugin_h__
  21.  
  22. #ifndef rez
  23.  
  24. #include "ArrangeCallbacks.h"
  25.  
  26. #if    defined(__MWERKS__) && !defined(__powerc)
  27. #include <A4Stuff.h>    //    also included in <MacHeaders>
  28. #define SetupGlobals()    long oldA4 = SetCurrentA4()    //    setup A4 to point to global data segment
  29. #define RestoreGlobals()    SetA4(oldA4)            //    restore A4 to saved value before returning
  30. #else
  31. #define SetupGlobals()
  32. #define RestoreGlobals()
  33. #endif
  34.  
  35. #pragma parameter Set1Reg(__D0)
  36. pascal void Set1Reg(int D0) = 0x4E71;
  37. #pragma parameter Set2Reg(__A0,__D0)
  38. pascal void Set2Reg(void *A0,int D0) = 0x4E71;
  39. #pragma parameter Set3Reg(__A0,__A1,__D0)
  40. pascal void Set3Reg(void *A0,void *A1,int D0) = 0x4E71;
  41.  
  42. class Plugin
  43. {
  44.     /* These hook functions simply pass control into the appropriate method */
  45.     friend arHookResult OurClickHook( ModuleParamBlock* pb, arClickLocation loc,
  46.                                     Point where, pShort modifiers, pShort clickCount,
  47.                                     arNoteID note, arFieldID field, arPathID path ENDP );
  48.     friend arHookResult OurKeyHook  ( ModuleParamBlock* pb,
  49.                                     pShort theChar, pShort key, pShort modifiers ENDP );
  50.     friend arHookResult OurMenuHook ( ModuleParamBlock* pb, Integer commandCode,
  51.                                     Integer commandParam, pShort modifiers ENDP );
  52.     friend arHookResult OurFieldHook( ModuleParamBlock* pb, arNoteID note,
  53.                                         arFieldID field, arFieldAction action,
  54.                                         const char* choiceText ENDP );
  55.     friend void            OurTopicHook( ModuleParamBlock* pb, arTopicID newTopic,
  56.                                          arWindowID newWindow, arTopicAction action ENDP);
  57.     friend void            OurTickHook ( ModuleParamBlock* pb ENDP);
  58.     friend arHookResult OurFileHook ( ModuleParamBlock* pb, arFileAction action ENDP);
  59.     friend arHookResult OurQuitHook ( ModuleParamBlock* pb ENDP);
  60.     friend void            OurATMHook  ( ModuleParamBlock* pb ENDP);
  61.     friend Integer        OurImportHook( ModuleParamBlock* pb, const FSSpec *file,
  62.                                         pShort fRefnum, Integer formatID,
  63.                                         pBoolean sniff, arTopicID destTopic ENDP);
  64.     friend Integer        OurExportHook( ModuleParamBlock* pb, const FSSpec *file,
  65.                                         pShort fRefnum, Integer formatID,
  66.                                         arEFType type, arTopicID srcTopic ENDP );
  67.  
  68. public:
  69.     Plugin(const ArrangeCallbackTbl* theCalls);
  70.     ~Plugin();
  71.  
  72.     void* operator new( size_t);
  73.     void* operator new( size_t, void *p) { return p; };
  74.     void  operator delete( void * ) { /* do nothing */ };
  75.     
  76.  
  77. protected:
  78.         /* This function is called whenever the user clicks in an "interesting place"
  79.         in a document window.  It should return true if we handle the click, false
  80.         (the normal case) when the click should be passed along to other plug-ins
  81.         or to Arrange's normal event processing.  See the documentation for
  82.         SetClickHook for more details. */
  83.  
  84.     void InstallClickHook ( uInteger refcon, pBoolean addHook );
  85.     arHookResult ClickEvent( arClickLocation loc, Point where, Short modifiers,
  86.                                       Short clickCount, arNoteID note, arFieldID field,
  87.                                       arPathID path );
  88.  
  89.         /* This function is called whenever the user types a key which matches the
  90.         filters we pass to SetKeyHook in Plugin's constructor.  It should return
  91.         true if we handle the event, false (the normal case) when the event
  92.         should be passed along to other plug-ins or to Arrange's normal event
  93.         processing.  See the documentation for SetKeyHook for more details. */
  94.  
  95.     void InstallKeyHook ( uInteger refcon, pBoolean addHook,
  96.                             pShort charFilter, pShort keyFilter, pShort modFilter );
  97.     arHookResult KeyEvent ( Short theChar, Short key, Short modifiers );
  98.  
  99.         /* This function is called whenever the user chooses a menu item for which
  100.         we have registered (via the SetMenuHook function).  It should return true
  101.         if we handle the command, false (the normal case) when the command should
  102.         be passed along to other plug-ins or to Arrange's normal event processing.
  103.         See the documentation for SetMenuHook for more details. */
  104.  
  105.     void InstallMenuHook ( uInteger refcon, pBoolean addHook, Integer commandCode );
  106.     arHookResult MenuEvent ( Integer commandCode, Integer commandParam,
  107.                                       Short modifiers );
  108.  
  109.         /* If we register to recieve events for a field by calling SetFieldHook, this
  110.         function will be called for any events in that field.  It should return false
  111.         in almost all cases.
  112.         See the documentation for SetFieldHook and RegisterFieldProc for more details. */
  113.  
  114.     void InstallFieldHook ( uInteger refcon, pBoolean addHook, arFieldID field );
  115.     void RegisterFieldProc ( const char* name, Integer id, arFPType type,
  116.                                 Integer fieldTypes, uInteger refcon ENDP );
  117.     arHookResult FieldEvent ( arNoteID note, arFieldID field, arFieldAction action,
  118.                                       const char* choiceText );
  119.  
  120.         /* This function is called whenever the user switches windows or changes
  121.         the current folder/topic/view in the front window.  See the documentation
  122.         for SetTopicHook for more details. */
  123.  
  124.     void InstallTopicHook ( uInteger refcon, pBoolean addHook );
  125.     void TopicEvent ( arTopicID newTopic, arWindowID newWindow,
  126.                                       arTopicAction action );
  127.         /* This function is called periodically, whenever Arrange recieves a null
  128.         event from the Event Manager. */
  129.  
  130.     void InstallTickHook ( uInteger refcon, pBoolean addHook );
  131.     void TickEvent ( );
  132.  
  133.         /* This function is called whenever various file-level events occur.
  134.         It should return true in almost all cases.
  135.         See the documentation for SetFileHook for more details. */
  136.  
  137.     void InstallFileHook ( uInteger refcon, pBoolean addHook );
  138.     arHookResult FileEvent ( arFileAction action );
  139.  
  140.         /* This function is called if the user voluntarily quits Arrange.  It should
  141.         return true to allow the user to quit, false to prevent it.
  142.         See the documentation for SetQuitHook for more details. */
  143.  
  144.     void InstallQuitHook ( uInteger refcon, pBoolean addHook );
  145.     arHookResult QuitEvent ( );
  146.  
  147.         /* This function is called whenever the user clicks in the menu bar or types
  148.         a command key, just before processing the event.  It should do any fixing
  149.         up of menus which might be necessary based on the current state of affairs.
  150.         See the documentation for SetATMHook for more details. */
  151.  
  152.     void InstallATMHook ( uInteger refcon, pBoolean addHook );
  153.     void ATMEvent ( );
  154.  
  155.         /* This function is called whenever the user imports a file of a type
  156.         for which this plugin registered a format. It is called first to
  157.         assess how likely it is that the provided format is the import
  158.         format supported, and then again to import the format. */
  159.  
  160.     void RegisterImportFormat ( const char* name, Integer formatID,
  161.                                 OSType* fileTypes, Integer fileTypeCount,
  162.                                 uInteger refcon ENDP );
  163.     Integer ImportFile ( const FSSpec* file, pShort fRefnum,
  164.                                 Integer formatID, pBoolean sniff, arTopicID destTopic );
  165.  
  166.         /* Export the provided topic to the given file. Assume that the file is already
  167.         open, and leave the file open and unflushed. */
  168.  
  169.     void RegisterExportFormat ( const char* name, Integer formatID,
  170.                                 arEFType type, uInteger refcon,
  171.                                 OSType fileType, OSType fileCreator ENDP );
  172.     Integer ExportTopic ( const FSSpec* file, pShort fRefnum,
  173.                                 Integer formatID, arEFType type, arTopicID srcTopic);
  174.  
  175.     /****** inline functions, to make the code more readable ******/
  176.  
  177. #include "inlineCallbacks.h"
  178.  
  179.     /****** Instance Data ******/
  180.  
  181.     const ArrangeCallbackTbl* calls; // callback table
  182.  
  183. }; // Plugin
  184.  
  185. #endif // rez
  186. #endif // __Plugin_h__