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

ev_Menu_Actions.h

Go to the documentation of this file.
00001 /* AbiSource Program Utilities
00002  * Copyright (C) 1998 AbiSource, Inc.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 #ifndef EV_MENU_ACTIONS_H
00021 #define EV_MENU_ACTIONS_H
00022 
00023 /****************************************************************
00024 *****************************************************************
00025 ** This file defines a framework for the set of actions which
00026 ** may be bound to a menu Id.  This binding is independent of
00027 ** the actual menu containing the item and actual menu layout.
00028 **
00029 ** For example, we may have "File|Open" on the unique menus
00030 ** for three different types of top-level windows and on a
00031 ** context menu, but they all do the same fire the same event
00032 ** (have the same binding).
00033 **
00034 ** We create one EV_Menu_Action per menu-item per application.
00035 **
00036 ** We create one EV_Menu_ActionSet per application.
00037 **
00038 *****************************************************************
00039 ****************************************************************/
00040 
00041 #include "ut_types.h"
00042 #include "xap_Types.h"
00043 #include "ut_vector.h"
00044 #include "ut_string_class.h"
00045 
00046 class XAP_App;
00047 class XAP_Frame;
00048 class AV_View;
00049 class EV_Menu_Label;
00050 
00051 // TODO consider removing bHoldsSubMenu bit from this file.
00052 
00053 /*****************************************************************/
00054 
00055 typedef enum _ev_Menu_ItemState         /* values may be ORed */
00056 {
00057     EV_MIS_ZERO     = 0x00,             /* nothing is turned on */
00058     EV_MIS_Gray     = 0x01,             /* item is or should be gray */
00059     EV_MIS_Toggled  = 0x02,             /* checkable item should be checked */
00060     EV_MIS_Bold     = 0x04              /* item is or should be bold */
00061 
00062 } EV_Menu_ItemState;
00063 
00064 typedef EV_Menu_ItemState ( EV_GetMenuItemState_Fn )(AV_View * pView, XAP_Menu_Id id);
00065 typedef EV_Menu_ItemState (*EV_GetMenuItemState_pFn)(AV_View * pView, XAP_Menu_Id id);
00066 #ifdef ABI_DLL
00067 #define Defun_EV_GetMenuItemState_Fn(fn) EV_Menu_ItemState fn(AV_View * pAV_View, XAP_Menu_Id id)
00068 #else
00069 #define Defun_EV_GetMenuItemState_Fn(fn) ABI_EXPORT EV_Menu_ItemState fn(AV_View * pAV_View, XAP_Menu_Id id)
00070 #endif
00071 
00072 // TODO decide if ...GetMenuItemComputedLabel... should take an XAP_App or an AV_View.
00073 // TODO for most-recently-used-file-list and window-history, we probably just need
00074 // TODO the ap.  but for view-specific things (like toggles where we change the menu
00075 // TODO item name rather than doing a checkmark), we need the view.
00076 
00077 // for now, current (quick) compromise is to pass the XAP_Frame,
00078 // because you can get to either of them easily from there -- pcr
00079 
00080 typedef const char * ( EV_GetMenuItemComputedLabel_Fn )(const EV_Menu_Label * pLabel, XAP_Menu_Id id);
00081 typedef const char * (*EV_GetMenuItemComputedLabel_pFn)(const EV_Menu_Label * pLabel, XAP_Menu_Id id);
00082 #ifdef ABI_DLL
00083 #define Defun_EV_GetMenuItemComputedLabel_Fn(fn) const char * fn(const EV_Menu_Label * pLabel, XAP_Menu_Id id)
00084 #else
00085 #define Defun_EV_GetMenuItemComputedLabel_Fn(fn) ABI_EXPORT const char * fn(const EV_Menu_Label * pLabel, XAP_Menu_Id id)
00086 #endif
00087 
00088 /*****************************************************************/
00089 
00090 class ABI_EXPORT EV_Menu_Action
00091 {
00092 public:
00093     EV_Menu_Action(XAP_Menu_Id id,
00094                    bool bHoldsSubMenu,
00095                    bool bRaisesDialog,
00096                    bool bCheckable,
00097                    bool bRadio,
00098                    const char* szMethodName,
00099                    EV_GetMenuItemState_pFn pfnGetState,
00100                    EV_GetMenuItemComputedLabel_pFn pfnGetLabel,
00101                    const UT_String& stScriptName = "");
00102     ~EV_Menu_Action();
00103 
00104     XAP_Menu_Id                     getMenuId() const;
00105     void                            incrementId(void);
00106     bool                            hasDynamicLabel() const;
00107     const char*                     getDynamicLabel(const EV_Menu_Label * pLabel) const;
00108     const char*                     getMethodName() const;
00109     const UT_String&                getScriptName() const { return m_stScriptName; }
00110     bool                            hasGetStateFunction() const;
00111     EV_Menu_ItemState               getMenuItemState(AV_View * pView) const;
00112     bool                            raisesDialog() const;
00113     bool                            isCheckable() const;
00114     bool                            isRadio () const;
00115 
00116 private:
00117     XAP_Menu_Id                     m_id;
00118     bool                            m_bHoldsSubMenu;    /* is a PullRight */
00119     bool                            m_bRaisesDialog;    /* does it raise a dialog */
00120     bool                            m_bCheckable;       /* is it checkable */
00121     bool                            m_bRadio;           /* is it radio */
00122     char *                          m_szMethodName;     /* name of method to invoke */
00123     EV_GetMenuItemState_pFn         m_pfnGetState;      /* to get state on an activate */
00124     EV_GetMenuItemComputedLabel_pFn m_pfnGetLabel;      /* to get computed label (for things like window-list) */
00125     UT_String                       m_stScriptName;     /* extra data that the method may need */
00126 };
00127 
00128 /*****************************************************************/
00129 
00130 class ABI_EXPORT EV_Menu_ActionSet                  /* a glorified array with bounds checking */
00131 {
00132 public:
00133     EV_Menu_ActionSet(XAP_Menu_Id first, XAP_Menu_Id last);
00134     ~EV_Menu_ActionSet();
00135 
00136     bool                setAction(XAP_Menu_Id id,
00137                                   bool bHoldsSubMenu,
00138                                   bool bRaisesDialog,
00139                                   bool bCheckable,
00140                                   bool bRadio,
00141                                   const char * szMethodName,
00142                                   EV_GetMenuItemState_pFn pfnGetState,
00143                                   EV_GetMenuItemComputedLabel_pFn pfnGetLabel,
00144                                   const UT_String& stScriptName = "");
00145     bool                addAction(EV_Menu_Action *pAction);
00146 
00147     const EV_Menu_Action *  getAction(XAP_Menu_Id id) const;
00148 
00149 private:
00150     UT_GenericVector<EV_Menu_Action *>  m_actionTable;
00151     XAP_Menu_Id         m_first;
00152 };
00153 
00154 #endif /* EV_MENU_ACTIONS_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1