/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; c-indent-level: 8 -*- */ /* this file is part of evince, a gnome document viewer * * Copyright (C) 2009 litl, LLC * * Evince is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Evince is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __SCRIPTABLE_PLUGIN_H__ #define __SCRIPTABLE_PLUGIN_H__ #include #include NPObject *AllocateScriptablePluginObject (NPP npp, NPClass *aClass); NPObject *AllocateConstructablePluginObject (NPP npp, NPClass *aClass); class ScriptablePluginObjectBase : public NPObject { public: ScriptablePluginObjectBase (NPP npp) : mNpp(npp) { } virtual ~ScriptablePluginObjectBase () { } virtual void Invalidate (); virtual bool HasMethod (NPIdentifier name); virtual bool Invoke (NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result); virtual bool InvokeDefault (const NPVariant *args, uint32_t argCount, NPVariant *result); virtual bool HasProperty (NPIdentifier name); virtual bool GetProperty (NPIdentifier name, NPVariant *result); virtual bool SetProperty (NPIdentifier name, const NPVariant *value); virtual bool RemoveProperty (NPIdentifier name); virtual bool Enumerate (NPIdentifier **identifier, uint32_t *count); virtual bool Construct (const NPVariant *args, uint32_t argCount, NPVariant *result); static void _Deallocate (NPObject *npobj); static void _Invalidate (NPObject *npobj); static bool _HasMethod (NPObject *npobj, NPIdentifier name); static bool _Invoke (NPObject *npobj, NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result); static bool _InvokeDefault (NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result); static bool _HasProperty (NPObject * npobj, NPIdentifier name); static bool _GetProperty (NPObject *npobj, NPIdentifier name, NPVariant *result); static bool _SetProperty (NPObject *npobj, NPIdentifier name, const NPVariant *value); static bool _RemoveProperty (NPObject *npobj, NPIdentifier name); static bool _Enumerate (NPObject *npobj, NPIdentifier **identifier, uint32_t *count); static bool _Construct (NPObject *npobj, const NPVariant *args, uint32_t argCount, NPVariant *result); protected: NPP mNpp; }; class ScriptablePluginObject : public ScriptablePluginObjectBase { public: ScriptablePluginObject (NPP npp); virtual bool HasMethod (NPIdentifier name); virtual bool HasProperty (NPIdentifier name); virtual bool GetProperty (NPIdentifier name, NPVariant *result); virtual bool SetProperty (NPIdentifier name, const NPVariant *value); virtual bool Invoke (NPIdentifier name, const NPVariant *args, uint32_t argCount, NPVariant *result); virtual bool InvokeDefault (const NPVariant *args, uint32_t argCount, NPVariant *result); virtual void CallBrowser (const char *function_name); private: NPIdentifier mTitleID; NPIdentifier mZoomID; NPIdentifier mCanCopyID; NPIdentifier mCanFindOnPageID; NPIdentifier mMagicWrapperID; NPIdentifier mZoomInID; NPIdentifier mZoomOutID; NPIdentifier mFindTermsID; NPIdentifier mFindPreviousID; NPIdentifier mFindNextID; NPObject *mMagicWrapper; }; class ConstructablePluginObject : public ScriptablePluginObjectBase { public: ConstructablePluginObject (NPP npp) : ScriptablePluginObjectBase (npp) { } virtual bool Construct (const NPVariant *args, uint32_t argCount, NPVariant *result); }; #define DECLARE_NPOBJECT_CLASS_WITH_BASE(_class, ctor) \ static NPClass s##_class##_NPClass = { \ NP_CLASS_STRUCT_VERSION_CTOR, \ ctor, \ ScriptablePluginObjectBase::_Deallocate, \ ScriptablePluginObjectBase::_Invalidate, \ ScriptablePluginObjectBase::_HasMethod, \ ScriptablePluginObjectBase::_Invoke, \ ScriptablePluginObjectBase::_InvokeDefault, \ ScriptablePluginObjectBase::_HasProperty, \ ScriptablePluginObjectBase::_GetProperty, \ ScriptablePluginObjectBase::_SetProperty, \ ScriptablePluginObjectBase::_RemoveProperty, \ ScriptablePluginObjectBase::_Enumerate, \ ScriptablePluginObjectBase::_Construct \ } #define GET_NPOBJECT_CLASS(_class) &s##_class##_NPClass DECLARE_NPOBJECT_CLASS_WITH_BASE (ScriptablePluginObject, AllocateScriptablePluginObject); DECLARE_NPOBJECT_CLASS_WITH_BASE (ConstructablePluginObject, AllocateConstructablePluginObject); #endif // __SCRIPTABLE_PLUGIN_H__