1 /* AbiSource Program Utilities 2 * Copyright (C) 1998 AbiSource, Inc. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 * 02110-1301 USA. 18 */ 19 20 #ifndef EV_MENU_ACTIONS_H 21 #define EV_MENU_ACTIONS_H 22 23 /**************************************************************** 24 ***************************************************************** 25 ** This file defines a framework for the set of actions which 26 ** may be bound to a menu Id. This binding is independent of 27 ** the actual menu containing the item and actual menu layout. 28 ** 29 ** For example, we may have "File|Open" on the unique menus 30 ** for three different types of top-level windows and on a 31 ** context menu, but they all do the same fire the same event 32 ** (have the same binding). 33 ** 34 ** We create one EV_Menu_Action per menu-item per application. 35 ** 36 ** We create one EV_Menu_ActionSet per application. 37 ** 38 ***************************************************************** 39 ****************************************************************/ 40 41 #include "ut_types.h" 42 #include "xap_Types.h" 43 #include "ut_vector.h" 44 #include "ut_string_class.h" 45 46 class XAP_App; 47 class XAP_Frame; 48 class AV_View; 49 class EV_Menu_Label; 50 51 // TODO consider removing bHoldsSubMenu bit from this file. 52 53 /*****************************************************************/ 54 55 typedef enum _ev_Menu_ItemState /* values may be ORed */ 56 { 57 EV_MIS_ZERO = 0x00, /* nothing is turned on */ 58 EV_MIS_Gray = 0x01, /* item is or should be gray */ 59 EV_MIS_Toggled = 0x02, /* checkable item should be checked */ 60 EV_MIS_Bold = 0x04 /* item is or should be bold */ 61 62 } EV_Menu_ItemState; 63 64 typedef EV_Menu_ItemState ( EV_GetMenuItemState_Fn )(AV_View * pView, XAP_Menu_Id id); 65 typedef EV_Menu_ItemState (*EV_GetMenuItemState_pFn)(AV_View * pView, XAP_Menu_Id id); 66 #ifdef ABI_DLL 67 #define Defun_EV_GetMenuItemState_Fn(fn) EV_Menu_ItemState fn(AV_View * pAV_View, XAP_Menu_Id id) 68 #else 69 #define Defun_EV_GetMenuItemState_Fn(fn) ABI_EXPORT EV_Menu_ItemState fn(AV_View * pAV_View, XAP_Menu_Id id) 70 #endif 71 72 // TODO decide if ...GetMenuItemComputedLabel... should take an XAP_App or an AV_View. 73 // TODO for most-recently-used-file-list and window-history, we probably just need 74 // TODO the ap. but for view-specific things (like toggles where we change the menu 75 // TODO item name rather than doing a checkmark), we need the view. 76 77 // for now, current (quick) compromise is to pass the XAP_Frame, 78 // because you can get to either of them easily from there -- pcr 79 80 typedef const char * ( EV_GetMenuItemComputedLabel_Fn )(const EV_Menu_Label * pLabel, XAP_Menu_Id id); 81 typedef const char * (*EV_GetMenuItemComputedLabel_pFn)(const EV_Menu_Label * pLabel, XAP_Menu_Id id); 82 #ifdef ABI_DLL 83 #define Defun_EV_GetMenuItemComputedLabel_Fn(fn) const char * fn(const EV_Menu_Label * pLabel, XAP_Menu_Id id) 84 #else 85 #define Defun_EV_GetMenuItemComputedLabel_Fn(fn) ABI_EXPORT const char * fn(const EV_Menu_Label * pLabel, XAP_Menu_Id id) 86 #endif 87 88 /*****************************************************************/ 89 90 class ABI_EXPORT EV_Menu_Action 91 { 92 public: 93 EV_Menu_Action(XAP_Menu_Id id, 94 bool bHoldsSubMenu, 95 bool bRaisesDialog, 96 bool bCheckable, 97 bool bRadio, 98 const char* szMethodName, 99 EV_GetMenuItemState_pFn pfnGetState, 100 EV_GetMenuItemComputedLabel_pFn pfnGetLabel, 101 const UT_String& stScriptName = ""); 102 ~EV_Menu_Action(); 103 104 XAP_Menu_Id getMenuId() const; 105 void incrementId(void); 106 bool hasDynamicLabel() const; 107 const char* getDynamicLabel(const EV_Menu_Label * pLabel) const; 108 const char* getMethodName() const; getScriptName()109 const UT_String& getScriptName() const { return m_stScriptName; } 110 bool hasGetStateFunction() const; 111 EV_Menu_ItemState getMenuItemState(AV_View * pView) const; 112 bool raisesDialog() const; 113 bool isCheckable() const; 114 bool isRadio () const; 115 116 private: 117 XAP_Menu_Id m_id; 118 bool m_bHoldsSubMenu; /* is a PullRight */ 119 bool m_bRaisesDialog; /* does it raise a dialog */ 120 bool m_bCheckable; /* is it checkable */ 121 bool m_bRadio; /* is it radio */ 122 char * m_szMethodName; /* name of method to invoke */ 123 EV_GetMenuItemState_pFn m_pfnGetState; /* to get state on an activate */ 124 EV_GetMenuItemComputedLabel_pFn m_pfnGetLabel; /* to get computed label (for things like window-list) */ 125 UT_String m_stScriptName; /* extra data that the method may need */ 126 }; 127 128 /*****************************************************************/ 129 130 class ABI_EXPORT EV_Menu_ActionSet /* a glorified array with bounds checking */ 131 { 132 public: 133 EV_Menu_ActionSet(XAP_Menu_Id first, XAP_Menu_Id last); 134 ~EV_Menu_ActionSet(); 135 136 bool setAction(XAP_Menu_Id id, 137 bool bHoldsSubMenu, 138 bool bRaisesDialog, 139 bool bCheckable, 140 bool bRadio, 141 const char * szMethodName, 142 EV_GetMenuItemState_pFn pfnGetState, 143 EV_GetMenuItemComputedLabel_pFn pfnGetLabel, 144 const UT_String& stScriptName = ""); 145 bool addAction(EV_Menu_Action *pAction); 146 147 const EV_Menu_Action * getAction(XAP_Menu_Id id) const; 148 149 private: 150 UT_GenericVector<EV_Menu_Action *> m_actionTable; 151 XAP_Menu_Id m_first; 152 }; 153 154 #endif /* EV_MENU_ACTIONS_H */ 155