1.Plugin类
在illustrator SDK中,提供了一个类,可以通过修改这个类来开发新的插件。头文件代码如下:
class Plugin
{
protected:
SPPluginRef fPluginRef;
char fPluginName[kMaxStringLength];//插件名称
Suites *fSuites;//套件指针
int fLockCount;
SPAccessRef fPluginAccess;
ASErr fLastError;
long fErrorTimeout;
ASBoolean fSupressDuplicateErrors;
time_t fLastErrorTime;
public:
Plugin(SPPluginRef pluginRef);
Plugin() {}
virtual ~Plugin();
void *operator new(size_t size);
void operator delete(void *pMem);
ASBoolean SuitesAcquired() { return fSuites != nil; }
virtual void ReportError(ASErr error, char *caller, char *selector, void *message);
static void DefaultError(SPPluginRef ref, ASErr error);
static ASBoolean FilterError(ASErr error);
SPPluginRef GetPluginRef() { return fPluginRef; }
virtual ASErr LockPlugin(ASBoolean lock);
static ASBoolean IsReloadMsg(char *caller, char *selector);
virtual ASErr StartupPlugin(SPInterfaceMessage *message);
virtual ASErr PostStartupPlugin();
virtual ASErr ShutdownPlugin(SPInterfaceMessage *message);
virtual ASErr UnloadPlugin(SPInterfaceMessage *message);
virtual ASErr ReloadPlugin(SPInterfaceMessage *message);
virtual ASErr AcquireProperty(SPPropertiesMessage *message);
virtual ASErr ReleaseProperty(SPPropertiesMessage *message);
virtual void GetPluginName(char *name, unsigned int maxlen);
virtual ASBoolean Purge();
virtual ASErr Message(char *caller, char *selector, void *message);
virtual ASErr SetGlobal(Plugin *plugin);
virtual ASErr AllocateSuiteTables();
virtual ASErr FillSuiteTables();
virtual ASErr EmptySuiteTables();
virtual ASErr AcquireOptionalSuites();
virtual ASErr Notify(AINotifierMessage *message);
virtual ASErr GoAction(DoActionMessage *message);
virtual ASErr GoMenuItem(AIMenuMessage *message);
virtual ASErr UpdateMenuItem(AIMenuMessage *message);
virtual ASErr GetFilterParameters(AIFilterMessage *message);
virtual ASErr GoFilter(AIFilterMessage *message);
virtual ASErr PluginGroupNotify(AIPluginGroupMessage *message);
virtual ASErr PluginGroupUpdate(AIPluginGroupMessage *message);
virtual ASErr GetFileFormatParameters(AIFileFormatMessage *message);
virtual ASErr GoFileFormat(AIFileFormatMessage *message);
virtual ASErr CheckFileFormat(AIFileFormatMessage *message);
virtual ASErr FileFormatUpdate(AIUpdateFileFormatMessage *message);
virtual ASErr SetFileFormatParameters(DoActionMessage *message);
virtual ASErr EditTool(AIToolMessage *message);
virtual ASErr TrackToolCursor(AIToolMessage *message);
virtual ASErr ToolMouseDown(AIToolMessage *message);
virtual ASErr ToolMouseDrag(AIToolMessage *message);
virtual ASErr ToolMouseUp(AIToolMessage *message);
virtual ASErr SelectTool(AIToolMessage *message);
virtual ASErr DeselectTool(AIToolMessage *message);
virtual ASErr ReselectTool(AIToolMessage *message);
virtual ASErr DecreaseDiameter(AIToolMessage *message);
virtual ASErr IncreaseDiameter(AIToolMessage *message);
virtual ASErr EditLiveEffectParameters(AILiveEffectEditParamMessage * message);
virtual ASErr GoLiveEffect(AILiveEffectGoMessage * message);
virtual ASErr LiveEffectInterpolate(AILiveEffectInterpParamMessage * message);
virtual ASErr LiveEffectGetInputType(AILiveEffectInputTypeMessage * message);
virtual ASErr LiveEffectConvertColorSpace(AILiveEffectConvertColorMessage * message);
virtual ASErr LiveEffectScaleParameters(AILiveEffectScaleParamMessage * message);
virtual ASErr LiveEffectAdjustColors(AILiveEffectAdjustColorsMessage * message);
virtual ASErr LiveEffectHandleMerge(AILiveEffectHandleMergeMessage * message);
virtual ASErr GoTimer(AITimerMessage * message);
virtual ASErr GoClipboard( AIClipboardMessage *message );
virtual ASErr CanCopyClipboard( AIClipboardMessage *message );
virtual ASErr CloneClipboard( AIClipboardMessage *message );
virtual ASErr DisposeClipboard( AIClipboardMessage *message );
virtual ASErr WorkspaceWrite( AIWorkspaceMessage *message );
virtual ASErr WorkspaceRestore( AIWorkspaceMessage *message );
virtual ASErr WorkspaceDefault( AIWorkspaceMessage *message );
private:
static char *FindMsg(SPPluginRef ref, ASErr error, char *buf, int len);
};
2.StartupPlugin函数
这个类里大部分是分发部分的消息处理。先查看下,SDK提供的启动函数,代码如下所示:
ASErr Plugin::StartupPlugin(SPInterfaceMessage *message)
{
ASErr error = kNoErr;
if (!error)
error = SetGlobal(this);//全局函数操作(空)
fSuites = new(std::nothrow) Suites;//加载模块
if (!fSuites)
error = kOutOfMemoryErr;
else
{
error = fSuites->Error();//是否发生错误
fSuites->InitializeRefCount();//初始化引用计数
}
if (error)
{
if (fSuites)
delete fSuites;
fSuites = nil;
}
if (!error)
{
if(!error)
error = sSPPlugins->SetPluginName( message->d.self, fPluginName );//设置插件名称
if (!error)
{
char notifierName[kMaxStringLength];
sprintf(notifierName, "%s App Started Notifier", fPluginName);//应用程序启动通知
error = sAINotifier->AddNotifier(message->d.self, notifierName, kAIApplicationStartedNotifier, NULL);
}
}
if (!error)
error = AllocateSuiteTables();
if (!error)
FillSuiteTables();
if(!error)
error = Plugin::LockPlugin(true);//增加引用计数
return error;
}
在插件的启动消息里,最主要是实现了需要使用到的系统其它模块的加载和插件的命名。
3.作者答疑
代码长度过长,如需全部项目或有疑问,请留言。
提示: 作者知了-联系方式1
提示: 作者知了-联系方式2