C
HAPTER
2: Tutorial
Callers and selectors
24
The options specify plug-in behavior to be provided by Illustrator. Filters do not have any special behavior
but could use some default behavior options, like the
kPluginWantsResultsAutoSelectedOption
constant, which is used to control how artwork is selected when the plug-in returns control to Illustrator.
The final argument is returned to the plug-in by Illustrator. It is a reference to the added plug-in type. For
simple plug-ins, where only one instance of a given plug-in type is added, this value can be ignored. If a
plug-in adds more than one instance of a type, this reference should be saved in the
globals
block whose
reference is returned to Illustrator. When a plug-in is called, Illustrator passes the active instance of the
plug-in inside the message data. The saved references and current plug-in are compared later, to
determine which plug-in instance was selected by the user:
if ( (AIFilterMessage)message->filter == g->filterVariation1) {
// Do something for this variation
}
else {
// Do the other variation
}
Of course, if you have no special requirements, you do not need to do any checking. That is it for
initialization. The
kSPInterfaceStartupSelector
selector is called only once.
Caller: kSPInterfaceCaller, selector: kSPInterfaceShutdownSelector
When Illustrator is in the process of quitting, each plug-in receives a
kSPInterfaceShutdownSelector
message. Only one such message is received per Illustrator session. Actions that should happen when the
user is completely finished using the plug-in, like saving preference information, are done at this time.
Also, any needed follow-up action for something done during the
kSelectorAIStartupPlugin
message
should be done now. Some actions, like adding a plug-in type, do not need any clean up. A common
example is freeing allocated memory that the system does not automatically free when the application is
quit. A shut-down routine corresponding to the
StartupPlugin()
function above would look like this:
static AIErr ShutdownPlugin( SPInterfaceMessage* message )
{
AIErr error = kNoErr;
if ( g != nil ) {
message->d.basic->FreeBlock(g);
g = nil;
message->d.globals = nil;
}
return error;
}
Caller: kSPAccessCaller, selector: kSPAccessReloadSelector
Plug-in code is loaded and unloaded dynamically, depending on whether Illustrator is using it. If the code
is unused by the main application or another plug-in for a pre-defined period of time, it is unloaded. This is
true of all plug-in types, including plug-in suites. Illustrator notifies the plug-in of the loading and
unloading events.
After the start-up selector is received, each time your plug-in is brought into memory, it receives the
kSPAccessCaller
/
kSPAccessReloadSelector
message pair. Reload is your plug-in’s opportunity to
restore state information it needs to run, like global variables. Plug-in suites use the reload message to set
up their function tables. A reload routine looks something like this:
Globals* g;