Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Interapplication Communication /
Chapter 2 - Edition Manager / Subscribing to Non-Edition Files


Calling an Edition Opener

You use the CallEditionOpenerProc function to call an edition opener. Since the Edition Manager is a package that may move, a real pointer cannot be safely returned for the standard opener and I/O routines. The system opener and the
I/O routines are returned as a value that is not a valid address to a procedure. The CallEditionOpenerProc and CallFormatIOProc functions check for these values and call the system openers.

You should never assume that a value for a system opener is a fixed constant.

err := CallEditionOpenerProc (selector, PB, routine);
Set the selector parameter to one of the edition opener verbs. The edition opener verbs include

The PB parameter of the CallEditionOpenerProc function is an edition opener parameter block.

TYPE EditionOpenerParamBlock = 
   RECORD
      info:          EditionInfoRecord;   {edition container to }
                                          { be subscribed to}
      sectionH:      SectionHandle;       {publisher or }
                                          { subscriber }
                                          { requesting open}
      document:      FSSpecPtr;           {document passed}
      fdCreator:     OSType;              {Finder creator type}
      ioRefNum:      LongInt;             {reference number}
      ioProc:        FormatIOProcPtr;     {routine to read }
                                          { formats}
      success:       Boolean;             {reading or writing }
                                          { was successful}
      formatsMask:   SignedByte;          {formats required to }
                                          { subscribe}
   END;
The routine parameter of the CallEditionOpenerProc function is a pointer to an edition opener function.

The following list shows which fields of the edition opener parameter block are used by the edition opener verbs:
Opener verb FieldDescriptionCalled by
eoCanSubscribe-->infoEdition container to subscribe to.NewSubscriberDialogfunction for a subscriber
 -->formatsMaskFormats required to subscribe.
 <--Return valueA noErr code indicates that an edition container can be subscribed to. A noTypeErr code indicates that an edition container cannot be subscribed to.
eoOpen-->infoEdition container to open for reading.OpenEdition and GetStandardFormats functions for a subscriber
 -->sectionHSubscriber section requesting open or NIL.
 <--ioRefNumReference number for use by I/O routine. Not the same as EditionRefNum.
 <--ioProcI/O routine to call to read formats.
 <--Return valueA noErr code or appropriate error code.
eoClose-->infoEdition container to be closed for reading.CloseEdition and GetStandardFormats functions for a subscriber
 -->sectionHSubscriber section requesting close or NIL.
 -->ioRefNumValue returned by eoOpen.
 -->ioProcValue returned by eoOpen.
 -->successSuccess value passed to the CloseEdition function.
 <--Return valueA noErr code or appropriate error code.
     
eoOpenNew-->infoEdition container to open for writing.OpenNewEdition function for a publisher
 -->sectionHPublisher section requesting open or NIL.
 -->documentDocument pointer passed into the OpenNewEdition function.
 -->fdCreatorThe fdCreator passed into the OpenNewEdition function.
 <--ioRefNumReference number for use by I/O routine. Not the same as EditionRefNum.
 <--ioProcI/O routine to call to write formats.
 <--Return valueA noErr code or appropriate error code.
eoCloseNew-->infoEdition container to be closed after writing.CloseEdition function for a publisher
 -->sectionHPublisher section requesting close or NIL.
 -->ioRefNumValue returned by eoOpenNew.
 -->ioProcValue returned by eoOpenNew.
 -->successSuccess value passed to the CloseEdition function.
 <--Return valueA noErr code or appropriate error code.

As Listing 2-9 demonstrates, you install your own edition opener function by first saving the current opener and then installing your own opener. The listing also shows an edition opener, the MyEditionOpener function. When it receives the eoCanSubscribe opener verb, the MyEditionOpener function calls another application-defined routine, MyCanSubscribe. The Edition Manager sends your edition opener this verb to help it build the list of files displayed by the NewSubscriber function. The MyCanSubscribe function returns noErr if it can subscribe to the file; otherwise, it calls the original edition opener to handle the request.

Listing 2-9 Using your own edition opener function

VAR
   gOriginalOpener: EditionOpenerProcPtr;{global variable}

PROCEDURE MyInstallMyOpener;
BEGIN
   FailOSErr(GetEditionOpenerProc(gOriginalOpener));
   FailOSErr(SetEditionOpenerProc(@MyEditionOpener));
END; {MyInstallMyOpener}

FUNCTION MyEditionOpener (selector: EditionOpenerVerb; 
                          VAR PB: EditionOpenerParamBlock) 
                           : OSErr; 
BEGIN
   WITH PB DO
   BEGIN
      CASE selector OF
         eoCanSubscribe:
            MyEditionOpener := MyCanSubscribe(PB);
         eoOpen:
            MyEditionOpener := MyEditionOpen(PB);
         eoClose:
            MyEditionOpener := MyEditionClose(PB);
         OTHERWISE
            {call the original edition opener}
            MyEditionOpener 
               := CallEditionOpenerProc(selector, PB,
                                       gOriginalOpener);
      END; {of CASE}
   END; {of WITH}
END; {MyEditionOpener}

FUNCTION MyCanSubscribe (VAR PB: EditionOpenerParamBlock): OSErr;
BEGIN
   {check file type to see if it is a file you can emulate as an }
   { edition}
   IF PB.info.fdType = {for example}'PICT' THEN
      MyCanSubscribe := noErr
   ELSE {otherwise, let the saved edition opener decide}
         MyCanSubscribe := CallEditionOpenerProc(eoCanSubscribe,
                                             PB, gOriginalOpener);
END; {MyCanSubscribe}

Previous Book Contents Book Index Next

© Apple Computer, Inc.
7 JUL 1996