• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

AbiGeneric.h

Go to the documentation of this file.
00001 /*
00002  * Generic Plugin
00003  * This is intended only as a base class for other plugins
00004  *
00005  * It is derived from AbiPaint, which is in turn derived
00006  *   from AbiGimp copyright 2002 Martin Sevior which in turn
00007  *   is based on AiksaurusABI - Abiword plugin for Aiksaurus
00008  *   Copyright (C) 2001 by Jared Davis
00009  * Also tidbits taken from ImageMagick plugin & ScriptHappy
00010  *   plugin, copyright 2002 by Dom Lachowicz [and others]
00011  * And chunks taken from AbiCommand plugin, copyright 2002
00012  *   by Martin Sevior
00013  * This generic plugin initially assembled from above pieces
00014  *   by Kenneth J. Davis, though I [KJD] claim no copyright
00015  *   on any portion of AbiWord (TM) nor related plugins.
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License
00019  * as published by the Free Software Foundation; either version 2
00020  * of the License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful,
00023  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00025  * GNU General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301 USA.
00031  */
00032 
00033 #ifndef XAP_GENERIC_PLUGIN_H
00034 #define XAP_GENERIC_PLUGIN_H
00035 
00036 
00037 #ifndef ABI_PLUGIN_NAME // allow easy redefinition
00038 #define ABI_PLUGIN_NAME AbiPlugin
00039 #endif
00040 
00041 
00042 /* should be defined, as some headers differ when included by a plugin */
00043 #ifndef ABI_PLUGIN_SOURCE
00044 #define ABI_PLUGIN_SOURCE __FILE__
00045 #endif
00046 
00047 
00048 /* Some useful XP includes */
00049 #include "ut_assert.h"
00050 #include "ut_debugmsg.h"
00051 #include "ut_path.h"
00052 #include "ut_sleep.h"
00053 
00054 #include "ut_process.h"
00055 
00056 #include "xap_App.h"
00057 #include "xap_DialogFactory.h"
00058 #include "xap_Dlg_FileOpenSaveAs.h"
00059 #include "xap_Frame.h"
00060 #include "xap_Menu_Layouts.h"
00061 #include "xap_Module.h"
00062 #include "xap_Prefs.h"
00063 #include "ap_Dialog_Id.h"
00064 #include "ap_Menu_Id.h"
00065 #include "ev_EditMethod.h"
00066 #include "ev_Menu.h"
00067 #include "ev_Menu_Actions.h"
00068 #include "ev_Menu_Labels.h"
00069 #include "ev_Menu_Layouts.h"
00070 #include "fg_Graphic.h"
00071 #include "fl_BlockLayout.h"
00072 #include "fp_Run.h"
00073 #include "fv_View.h"
00074 #include "ie_imp.h"
00075 #include "ie_impGraphic.h"
00076 #include "ie_exp.h"
00077 #include "ie_types.h"
00078 
00079 #include <sys/types.h>
00080 #include <sys/stat.h>
00081 
00082 /*
00083  * funky defines required for what I want to do
00084  * see ANSI C spec for reasons for some of the funkiness
00085  */
00086 #define ABI_PLUGIN_mk2str(x) # x
00087 #define ABI_PLUGIN_mkstr(x) ABI_PLUGIN_mk2str(x)
00088 #define ABI_PLUGIN_glue(a,b) a ## b
00089 #define ABI_PLUGIN_xglue(a,b) ABI_PLUGIN_glue(a,b)
00090 #define ABI_PLUGIN_METHODNAME(a) ABI_PLUGIN_xglue(ABI_PLUGIN_NAME,a)
00091 
00092 #define ABI_PLUGIN_SCHEME ABI_PLUGIN_xglue(_,ABI_PLUGIN_xglue(ABI_PLUGIN_NAME,_))
00093 #define ABI_PLUGIN_SCHEME_NAME ABI_PLUGIN_mkstr(ABI_PLUGIN_SCHEME)
00094 
00095 /*
00096  * Macro to help declare the editor methods
00097  */
00098 #define ABI_PLUGIN_METHOD(m) ABI_PLUGIN_METHODNAME(_PluginCallback_##m)
00099 #define ABI_PLUGIN_METHOD_STR(m) ABI_PLUGIN_mkstr(ABI_PLUGIN_METHOD(m))
00100 #define DECLARE_ABI_PLUGIN_METHOD(m) \
00101 bool ABI_PLUGIN_METHOD(m)(AV_View* v, EV_EditMethodCallData *d)
00102 
00103 
00104 /* To declare a method use something along the lines of:
00105 DECLARE_ABIPAINT_EDITOR_METHOD(invoke);
00106 */
00107 
00108 
00109 #define ABI_GRAYABLE_MENUITEM(m) ABI_PLUGIN_METHODNAME(_MenuGrayState_##m)
00110 #define ABI_GRAYABLE_MENUITEM_PROTOTYPE(m) \
00111 EV_Menu_ItemState ABI_GRAYABLE_MENUITEM(m)(AV_View * pAV_View, XAP_Menu_Id id)
00112 #define DECLARE_ABI_GRAYABLE_MENUITEM(m,boolFunc) \
00113 ABI_GRAYABLE_MENUITEM_PROTOTYPE(m) \
00114 { \
00115     UT_UNUSED(pAV_View); \
00116     UT_UNUSED(id); \
00117     if (boolFunc()) \
00118         return EV_MIS_ZERO; \
00119     else \
00120         return EV_MIS_Gray; \
00121 }
00122 
00123 
00124 /* To declare a menu helper function that indicates if the menu
00125  * is active or grayed out, 1st define a function that returns a
00126  * bool (true if menu should be active else false) and takes no
00127  * arguments.  Use the DECLARE macro to actually include the
00128  * function, and just ABI_GRAYABLE_MENUITEM to make use of it.
00129 bool isImageSelected (void);
00130 ABI_GRAYABLE_MENUITEM_PROTOTYPE(image);
00131 ... ABI_GRAYABLE_MENUITEM(image), ...
00132 DECLARE_ABI_GRAYABLE_MENUITEM(image, isImageSelected())
00133 */
00134 
00135 
00136 #define ABI_TOGGLEABLE_MENUITEM(m) ABI_PLUGIN_METHODNAME(_MenuToggleState_##m)
00137 #define ABI_TOGGLEABLE_MENUITEM_PROTOTYPE(m) \
00138 EV_Menu_ItemState ABI_TOGGLEABLE_MENUITEM(m)(AV_View * pAV_View, XAP_Menu_Id id)
00139 #define DECLARE_ABI_TOGGLEABLE_MENUITEM(m,boolFunc) \
00140 ABI_TOGGLEABLE_MENUITEM_PROTOTYPE(m) \
00141 { \
00142     if (boolFunc()) \
00143         return EV_MIS_ZERO; \
00144     else \
00145         return EV_MIS_Toggled; \
00146 }
00147 
00148 
00149 /*
00150  * Abiword Plugin Interface
00151  * These are implemented by this generic class,
00152  * any work should be done by extending appropriate methods, not implementing these.
00153  */
00154 
00155 ABI_FAR_CALL
00156 int abi_plugin_register (XAP_ModuleInfo * mi);
00157 
00158 ABI_FAR_CALL
00159 int abi_plugin_unregister (XAP_ModuleInfo * mi);
00160 
00161 ABI_FAR_CALL
00162 int abi_plugin_supports_version (UT_uint32 major, UT_uint32 minor, UT_uint32 release);
00163 
00164 
00165 /*
00166  * Preference / User modifiable settings
00167  * All settings are stored in a '_plugin_' scheme with corresponding plugin name
00168  */
00169 /* use preference file (instead of registry) to store/retrieve settings */
00170 extern XAP_Prefs * prefs;  /* = XAP_App::getApp()->getPrefs(); */
00171 extern XAP_PrefsScheme * prefsScheme;
00172 /* our Plugin Scheme name in preference file,  e.g. "_AbiGeneric_" */
00173 extern const gchar * szAbiPluginSchemeName;
00174 
00175 
00176 /* Note:  Make sure the methodName field is Not NULL, otherwise
00177  *        AbiWord.exe will probably segfault -- actual results
00178  *        depend on where other plugins add menu items.
00179  * Note2: Make sure the label is unique across ALL plugins (and
00180  *        internal menu labels), any duplicates [including NULL]
00181  *        may cause the menu to display incorrectly.  This is
00182  *        most notable on the end of a submenu; its probably ok
00183  *        for separators to share a NULL label.
00184  */
00185 typedef struct AbiMenuOptions
00186 {
00187   const char    * methodName;
00188   EV_EditMethod_pFn method;
00189   const char    * label;        /* use & in label to set key binding, should be unique within a submenu */
00190   const char    * description;
00191   EV_Menu_LayoutFlags flags;        /* usually EV_MLF_Normal                                 */
00192   bool hasSubMenu;
00193   bool hasDialog;
00194   bool checkBox;
00195   EV_GetMenuItemState_pFn pfnGetState;
00196   EV_GetMenuItemComputedLabel_pFn pfnGetDynLabel;
00197   /* if both of the following are false, then why do you even have the entry?                */
00198   bool inMainMenu;          /* true if should show in main menu     (generally true) */
00199   bool inContextMenu;           /* true if should show in context menu  (depends)        */
00200   XAP_Menu_Id id;
00201 } AbiMenuOptions ;
00202 
00203 
00204 /*
00205  *   Adds [or removes] all of this plugins menu items to AbiWord
00206  *   amo is an array of the above structure, each element of the array defines an
00207  *     entry to add to the Main and/or Context menu.
00208  *   num_menuitems is how many entries are in the array (usually sizeof(amo)/sizeof(amo[0]))
00209  *   prevMM is the [English] Main menu item we place our 1st menu item after
00210  *   prevCM is the [English] Context menu item we place our 1st context menu item after
00211  *     prevMM and prevCM should not be NULL unless there is no entry added to the respective menu
00212  */
00213 UT_Error addToMenus(AbiMenuOptions amo[], UT_uint32 num_menuitems, XAP_Menu_Id prevMM, XAP_Menu_Id prevCM);
00214 UT_Error removeFromMenus(const AbiMenuOptions amo[], UT_uint32 num_menuitems);
00215 
00216 /* returns true only if user requested to cancel save, pass suggested path in */
00217 bool getFileName(std::string &szFile, XAP_Frame * pFrame, XAP_Dialog_Id id,
00218                  const char **szDescList, const char **szSuffixList, int *ft);
00219 
00220 /* returns true only if currently an image is selected */
00221 bool isImageSelected (void);
00222 
00223 /* locks or unlocks GUI, automatically aquires/releases lock/unlock EV_EditMethods */
00224 void plugin_imp_lockGUI(EV_EditMethodCallData *d);
00225 void plugin_imp_unlockGUI(EV_EditMethodCallData *d);
00226 #ifdef ABI_PLUGIN_DONT_LOCKGUI
00227 #define lockGUI(d)
00228 #define unlockGUI(d)
00229 #else
00230 #define lockGUI(d) plugin_imp_lockGUI(d)
00231 #define unlockGUI(d) plugin_imp_unlockGUI(d)
00232 #endif
00233 
00234 
00235 /*
00236  * Abstract Plugin Functions that a plugin using AbiGeneric should implement
00237  *
00238  */
00239 /* abi_plugin_register calls getModuleInfo to obtain module data */
00240 XAP_ModuleInfo *      getModuleInfo(void);
00241 bool                  doRegistration(void);
00242 void                  doUnregistration(void);
00243 
00244 
00245 #endif /* XAP_GENERIC_PLUGIN_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1