C
HAPTER
2: Tutorial
Plug-in type-specific messages
25
static AIErr ReloadPlugin( SPAccessMessage *message )
{
AIErr error = kNoErr;
g = ( Globals* )message->d.globals;
return error;
}
Caller: kSPAccessCaller, selector: kSPAccessUnloadSelector
The opposite of the reload selector is
kSelectorAIUnloadPlugin
. This is an opportunity for the plug-in to
save any state information before being removed from memory. Here is a sample routine for the unload
selector:
static AIErr UnloadPlugin( SPAccessMessage* message )
{
AIErr error = kNoErr;
message->d.globals = g;
return error;
}
Plug-in type-specific messages
The selectors discussed so far are received by all plug-ins. Other caller/selector pairs a plug-in receives
depend on the
plug-in types
added at start-up. This section describes the caller/selector pairs associated
with the plug-in types used in the Tutorial. For a description of the major plug-in types Illustrator supports,
see
Chapter 1, “Overview.”
Filter plug-ins
Illustrator allows plug-ins to add new filters to the Object menu. To add a filter, your plug-in must do the
following:
X
Call
AIFilterSuite::AddFilter
on start-up, to add the filter to Illustrator.
X
Handle messages relating to filter events.
There are two caller/selector pair messages associated with Filter plug-in types:
X
Get-filter parameters (
kCallerAIFilter
/
kSelectorAIGetFilterParameters
).
X
Go filter (
kCallerAIFilter
/
kSelectorAIGoFilter
).
The get-filter-parameters selector pair is an opportunity for your plug-in to present a dialog to the user,
requesting information about how the plug-in should work. It is followed by the go-selector pair, which is
when the plug-in actually does its work. The parameters are acquired in a separate call to support the Last
Filter feature in the Filter menu, which applies the last-used filter without asking the user for a new set of
parameters. In this case, you receive a
kCallerAIFilter
/
kSelectorAIGoFilter
pair without a preceding
kCallerAIFilter
/
kSelectorAIGetFilterParameters
pair.
The Tutorial plug-in’s
PluginMain
function handles these selector pairs as follows:
} else if ( strcmp( caller, kCallerAIFilter ) == 0 ) {
if ( strcmp( selector, kSelectorAIGetFilterParameters ) == 0 )
error = GetFilterParameters( ( AIFilterMessage* )message );