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

ev_EditMethod.h

Go to the documentation of this file.
00001 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
00002 /* AbiSource Program Utilities
00003  * Copyright (C) 1998 AbiSource, Inc.
00004  *
00005  * This program is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU General Public License
00007  * as published by the Free Software Foundation; either version 2
00008  * of the License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00018  * 02110-1301 USA.
00019  */
00020 
00021 #ifndef EV_EDITMETHOD_H
00022 #define EV_EDITMETHOD_H
00023 
00024 #include "ut_types.h"
00025 #include "ut_vector.h"
00026 #include "ut_string_class.h"
00027 
00028 class AV_View;
00029 
00030 /*****************************************************************
00031 ******************************************************************
00032 ** The EditMethod mechanism provides essentially a 'call-by-name'
00033 ** capability.  A key, mouse, menu, or toolbar event may be bound
00034 ** to a 'named' function (of type EV_EditMethod_Fn).
00035 **
00036 ** EV_EditMethodType provides some crude type-checking (primarily
00037 ** this is used by the invoker to check if the function requires
00038 ** data ('insertData' can be bound to a key like 'a' but would have
00039 ** problems if bound to 'mouse-1-click').
00040 **
00041 ** All EditMethod functions have a fixed calling sequence.  An
00042 ** instance of EV_EditMethodCallData passed to the function is
00043 ** used to provide all of the actual data that the function needs.
00044 **
00045 ** A EV_EditMethod defines a "named function" and consists of the
00046 ** name, a pointer to the actual code, type-checking information,
00047 ** and a short description of the function.  [I debated whether it
00048 ** would be better to put all of these fields as static members of
00049 ** a class consisting of just the static function -- I'm not sure
00050 ** it matters one way or another.  Perhaps the current way will be
00051 ** a little easier when it comes time to localize the short
00052 ** descriptions....]
00053 **
00054 ** A EV_EditMethodContainer is just that, a container for the
00055 ** EV_EditMethod's.  It provides simple lookup capability.  It
00056 ** currently has 2 tables of EditMethod's -- a static one (the set
00057 ** of our builtin functions) and a dynamic one (intended for use
00058 ** by JavaScript later).  The container provides the entire set
00059 ** of defined functions -- if a function isn't listed in the
00060 ** container, it cannot be found or bound to.
00061 **
00062 ** The actual tables of defined functions are defined by the
00063 ** application and not in this library.
00064 ******************************************************************
00065 *****************************************************************/
00066 
00067 /*****************************************************************/
00068 /*****************************************************************/
00069 
00070 typedef UT_uint32 EV_EditMethodType;
00071 #define EV_EMT_REQUIREDATA      (static_cast<EV_EditMethodType>(0x1))
00072 #define EV_EMT_REQUIRE_SCRIPT_NAME      (static_cast<EV_EditMethodType>(0x2))
00073 /* define a method that can be called without a frame. */
00074 #define EV_EMT_APP_METHOD       (static_cast<EV_EditMethodType>(0x4))
00075 
00076 /*****************************************************************/
00077 /*****************************************************************/
00078 
00079 class ABI_EXPORT EV_EditMethodCallData
00080 {
00081 public:
00082     EV_EditMethodCallData();
00083     EV_EditMethodCallData(const UT_UCSChar * pData, UT_uint32 dataLength);
00084     EV_EditMethodCallData(const char * pChar, UT_uint32 dataLength);
00085     EV_EditMethodCallData(const UT_String& stScriptName);
00086     ~EV_EditMethodCallData();
00087 
00088     UT_sint32           getX() const { return m_xPos; }
00089     UT_sint32           getY() const { return m_yPos; }
00090     const UT_String&    getScriptName() const { return m_stScriptName; }
00091 
00092 // private:
00093     UT_UCSChar *        m_pData;
00094     UT_uint32           m_dataLength;
00095     bool                m_bAllocatedData;
00096     UT_sint32           m_xPos;
00097     UT_sint32           m_yPos;
00098 
00099 private:
00100     UT_String           m_stScriptName;
00101 };
00102 
00103 typedef bool (*EV_EditMethod_pCtxtFn)(AV_View * pView, EV_EditMethodCallData * pCallData,
00104                                       void * context);
00105 typedef bool ( EV_EditMethod_CtxtFn) (AV_View * pView, EV_EditMethodCallData * pCallData,
00106                                       void * context);
00107 
00108 typedef bool (*EV_EditMethod_pFn)(AV_View * pView, EV_EditMethodCallData * pCallData);
00109 typedef bool ( EV_EditMethod_Fn) (AV_View * pView, EV_EditMethodCallData * pCallData);
00110 
00111 /*****************************************************************/
00112 /*****************************************************************/
00113 
00114 class ABI_EXPORT EV_EditMethod
00115 {
00116 public:
00117     EV_EditMethod(const char * szName, EV_EditMethod_pFn fn, EV_EditMethodType emt,
00118                   const char * szDescription);
00119     EV_EditMethod(const char * szName, EV_EditMethod_pCtxtFn fn, EV_EditMethodType emt,
00120                   const char * szDescription, void * context);
00121 
00122     bool                    Fn(AV_View * pView, EV_EditMethodCallData * pCallData) const;
00123 
00124     EV_EditMethodType       getType() const;
00125     const char *            getName() const;
00126     const char *            getDescription() const;
00127 
00128 protected:
00129     const char *            m_szName; // used for lookup; not malloced; should not be localized
00130     EV_EditMethod_pFn       m_fn;
00131     EV_EditMethod_pCtxtFn   m_CtxtFn;
00132     EV_EditMethodType       m_emt;
00133     const char *            m_szDescription; // not malloced; this can be localized
00134     void *                  m_context;
00135 };
00136 
00137 /*****************************************************************/
00138 /*****************************************************************/
00139 
00140 class ABI_EXPORT EV_EditMethodContainer
00141 {
00142 public:
00143     EV_EditMethodContainer(UT_uint32 cStatic, EV_EditMethod arrayStaticEditMethods[]);
00144     ~EV_EditMethodContainer();
00145 
00146     bool                addEditMethod(EV_EditMethod * pem);
00147     bool removeEditMethod(EV_EditMethod * pem);
00148     UT_uint32           countEditMethods();
00149     EV_EditMethod *     getNthEditMethod(UT_uint32 ndx);
00150     EV_EditMethod *     findEditMethodByName(const char * szName) const;
00151 
00152 protected:
00153     UT_uint32           m_countStatic;
00154     EV_EditMethod *     m_arrayStaticEditMethods;       // not malloced
00155     UT_GenericVector<EV_EditMethod *>   m_vecDynamicEditMethods;
00156 };
00157 
00158 /*****************************************************************/
00159 /*****************************************************************/
00160 
00161 ABI_EXPORT bool ev_EditMethod_exists (const char * methodName);
00162 ABI_EXPORT bool ev_EditMethod_exists (const UT_String & methodName);
00163 
00164 /*****************************************************************/
00165 /*****************************************************************/
00166 
00167 ABI_EXPORT bool ev_EditMethod_invoke (const EV_EditMethod * pEM, EV_EditMethodCallData * pData);
00168 ABI_EXPORT bool ev_EditMethod_invoke (const EV_EditMethod * pEM, const UT_String & data);
00169 ABI_EXPORT bool ev_EditMethod_invoke (const EV_EditMethod * pEM, const UT_UCS4String & data);
00170 
00171 ABI_EXPORT bool ev_EditMethod_invoke (const char * methodName, const UT_String & data);
00172 ABI_EXPORT bool ev_EditMethod_invoke (const char * methodName, const UT_UCS4String & data);
00173 ABI_EXPORT bool ev_EditMethod_invoke (const char * methodName, const char * data);
00174 ABI_EXPORT bool ev_EditMethod_invoke (const char * methodName, const UT_UCSChar * data);
00175 ABI_EXPORT bool ev_EditMethod_invoke (const UT_String& methodName, const UT_String & data);
00176 ABI_EXPORT bool ev_EditMethod_invoke (const UT_String& methodName, const UT_UCS4String & data);
00177 
00178 ABI_EXPORT EV_EditMethod* ev_EditMethod_lookup (const char * methodName);
00179 ABI_EXPORT EV_EditMethod* ev_EditMethod_lookup (const UT_String & methodName);
00180 
00181 #endif /* EV_EDITMETHOD_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1