Creating a Subscriber
You need to create a Subscribe To menu command in the Edit menu. When a user chooses Subscribe To from this menu, your application should display
the subscriber dialog box on the user's screen.
box on the user's screen. This function is similar to the CustomGetFile the user, such as the name of the edition being subscribed to. The dialog box
displays a listing of all available editions and allows the user to see a preview
(thumbnail sketch) of the edition selected.
The subscriber dialog box allows the user to choose an edition to subscribe to.
clicks Subscribe or Cancel. When a user selects an edition container, the
available) and displays it.
value of TRUE if the user clicked Cancel. To indicate which edition format types (text, graphics, or sound) your application can read, you set the formatsMask
field to one or more of these constants:
kPICT formatMask Can subscribe to 'PICT',
kTEXT formatMask 'TEXT', and
To support a combination of formats, add the constants together. For example,
a formatsMask of 3 displays both graphics and text edition format types in the
subscriber dialog box.
initialize the container field with the default edition volume reference
number, directory ID, filename, and part. To do so, use the
edition displayed in the dialog box.
This function returns the last edition container for which a new subscriber
was created using the NewSection function. If there is no last edition, or if the volume reference number and directory ID to use, but leaves the filename
blank and returns the fnfErr result code.
the File Manager description for further information on file system specification records.
After filling in the fields of the new subscriber reply record, pass it as a subscriber dialog box.
After displaying the subscriber dialog box, call the NewSection function to create the section record and the alias record.
If the subscriber is set up to receive new editions automatically (not
Section Read event. Whenever your application receives a Section Read event,
it should read the contents of the edition into the subscriber.
The Listing below illustrates how to create a subscriber. As described
earlier, you must set up and display the subscriber dialog box to allow the
user to subscribe to all available editions. After your application creates a
subscriber, your application receives a Section Read event to read in the data
being subscribed to. Be sure to add the newly created section to your list of
sections for this file. There are many different techniques for creating
subscribers and unique IDs; this listing displays one technique.
//Listing. Creating a subscriber
// Assuming inclusion of MacHeaders
#include <Editions.h>
#include <AppleEvents.h>
// This is a sample declaration for the pointer to your document information.
typedef struct {
short resForkRefNum;
short nextSectionID;
} *MyDocumentInfoPtr;
// Prototype your function like this prior to calling it
void DoNewSubscriber(MyDocumentInfoPtr);
void DoNewSubscriber(MyDocumentInfoPtr thisDocument)
{
short resID;
// User defined proto types
void MyErrHandler(OSErr); void AddSectionAliasPair(MyDocumentInfoPtr,SectionHandle, short); // Put default edition name into reply record. // Can subscribe to pictures or text.
reply. formatsMask = kPICT formatMask + kTEXT formatMask; // Display dialog box and let user select}
// There's usually no error returned here, but if there is,
// then it makes no sense to continue with this operation.
// Pass control to MyErrHandler.
if ( dialogErr )
MyErrHandler( dialogErr);
// Do nothing if user canceled.
return;
// Advance counter to make a new unique sectionID for this
// document. It is not necessary to equate section IDs with
// resources.
thisDocument->nextSectionID++;
// Create a subscriber section.
& thisDocument->fileSpec,
stSubscriber,
thisDocument->nextSectionID,
sumAutomatic, &thisSectionH);
if ( sectionErr )
// Same reasoning as above. If a new section could not be
// created, don't continue with this operation. Pass
// control to MyErrHandler.
MyErrHandler( sectionErr);
resID = thisDocument->nextSectionID;
// Add this section/ alias pair to your internal bookkeeping.
// AddSectionAliasPair is a routine to accomplish this.
AddSectionAliasPair( thisDocument, thisSectionH, resID);
// Remember that you will receive a Section Read event to read
// in the edition that you just subscribed to because the initial
// mode is set to sumAutomatic.
// Remember that the section and alias records need to be saved
// as resources when the user saves the document.
}