1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 #ifndef __MACCESSIBLE_H_ 23 #define __MACCESSIBLE_H_ 24 25 #include <Windows.h> 26 #include "resource.h" // main symbols 27 #include <vector> 28 #include <map> 29 #include <com/sun/star/accessibility/XAccessible.hpp> 30 #include <com/sun/star/accessibility/XAccessibleSelection.hpp> 31 #include <com/sun/star/accessibility/XAccessibleAction.hpp> 32 #include <AccObjectManagerAgent.hxx> 33 #include "EnumVariant.h" 34 #ifndef __ACCCOMMON_H_ 35 #include "acccommon.h" 36 #endif 37 #ifndef __AccessibleApplication_h__ 38 #include "AccessibleApplication.h" 39 #endif 40 #ifndef _RTL_USTRING_HXX_ 41 #include <rtl/ustring.hxx> 42 #endif 43 44 #define CHILDID_SELF 0 45 #define OBJID_WINDOW ((LONG)0x00000000) 46 #define OBJID_SYSMENU ((LONG)0xFFFFFFFF) 47 #define OBJID_TITLEBAR ((LONG)0xFFFFFFFE) 48 #define OBJID_MENU ((LONG)0xFFFFFFFD) 49 #define OBJID_CLIENT ((LONG)0xFFFFFFFC) 50 #define OBJID_VSCROLL ((LONG)0xFFFFFFFB) 51 #define OBJID_HSCROLL ((LONG)0xFFFFFFFA) 52 #define OBJID_SIZEGRIP ((LONG)0xFFFFFFF9) 53 #define OBJID_CARET ((LONG)0xFFFFFFF8) 54 #define OBJID_CURSOR ((LONG)0xFFFFFFF7) 55 #define OBJID_ALERT ((LONG)0xFFFFFFF6) 56 #define OBJID_SOUND ((LONG)0xFFFFFFF5) 57 #define OBJID_QUERYCLASSNAMEIDX ((LONG)0xFFFFFFF4) 58 #define OBJID_NATIVEOM ((LONG)0xFFFFFFF0) 59 60 using namespace rtl; 61 /** 62 *This class implements IMAccessible interface, which inherits from IAccessible2, and 63 *in turn inherits from IAccessible. So its methods include the methods defined only in 64 *IAccessible, plus the methods defined only in IAccessible2, plus the methods defined 65 *only in IMAccessible. 66 */ 67 class ATL_NO_VTABLE CMAccessible : 68 public CComObjectRoot, 69 public CComCoClass<CMAccessible, &CLSID_MAccessible>, 70 public IDispatchImpl<IMAccessible, &IID_IMAccessible, &LIBID_UACCCOMLib>, 71 public IServiceProvider, 72 public IAccessibleApplication 73 { 74 typedef map< const GUID, CComPtr<IUnknown> ,ltComp > XGUIDToComObjHash; 75 76 typedef HRESULT (WINAPI _UNO_AGGCREATORFUNC)(void*, REFIID, LPVOID*); 77 78 struct _UNO_AGGMAP_ENTRY 79 { 80 const IID* piid; 81 _UNO_AGGCREATORFUNC* pfnCreateInstance; 82 int XIFIndex; 83 }; 84 85 enum XInterfaceIndex { 86 XI_COMPONENT = 0x01, 87 XI_TEXT = 0x02, 88 XI_TABLE = 0x03, 89 XI_EDITABLETEXT = 0x04, 90 XI_IMAGE = 0x05, 91 XI_SELECTION = 0x06, 92 XI_EXTENDEDCOMP = 0x07, 93 XI_VALUE = 0x08, 94 XI_KEYBINDING = 0x09, 95 XI_ACTION = 0x0A, 96 XI_HYPERTEXT = 0x0B, 97 XI_HYPERLINK = 0x0C, 98 XI_ATTRIBUTE = 0x0D, 99 XI_NULL = -1 100 }; 101 102 public: 103 CMAccessible(); 104 virtual ~CMAccessible(); 105 DECLARE_REGISTRY_RESOURCEID(IDR_MACCESSIBLE) 106 107 DECLARE_GET_CONTROLLING_UNKNOWN() 108 109 DECLARE_PROTECT_FINAL_CONSTRUCT() 110 111 BEGIN_COM_MAP(CMAccessible) 112 COM_INTERFACE_ENTRY(IMAccessible) 113 COM_INTERFACE_ENTRY(IAccessible) 114 COM_INTERFACE_ENTRY(IAccessible2) 115 COM_INTERFACE_ENTRY(IDispatch) 116 COM_INTERFACE_ENTRY(IAccessibleApplication) 117 COM_INTERFACE_ENTRY(IServiceProvider) 118 COM_INTERFACE_ENTRY_FUNC_BLIND(NULL,_SmartQI) 119 END_COM_MAP() 120 121 // AGGREGATE OBJECT MAP 122 BEGIN_AGGOBJECT_MAP(CMAccessible) 123 AGGOBJECT_ENTRY(IID_IAccessibleComponent, CLSID_AccComponent, COMPONENT) 124 AGGOBJECT_ENTRY(IID_IAccessibleText, CLSID_AccText, TEXT) 125 AGGOBJECT_ENTRY(IID_IAccessibleEditableText, CLSID_AccEditableText, EDITABLETEXT) 126 AGGOBJECT_ENTRY(IID_IAccessibleImage, CLSID_AccImage, IMAGE) 127 AGGOBJECT_ENTRY(IID_IAccessibleTable, CLSID_AccTable, TABLE) 128 AGGOBJECT_ENTRY(IID_IAccessibleAction, CLSID_AccAction, ACTION) 129 AGGOBJECT_ENTRY(IID_IAccessibleValue, CLSID_AccValue, VALUE) 130 AGGOBJECT_ENTRY(IID_IAccessibleHypertext, CLSID_AccHypertext, HYPERTEXT) 131 AGGOBJECT_ENTRY(IID_IAccessibleHyperlink, CLSID_AccHyperLink, HYPERLINK) 132 133 134 END_AGGOBJECT_MAP() 135 136 // IMAccessible 137 STDMETHOD(put_accValue)(VARIANT varChild,BSTR szValue); 138 STDMETHOD(put_accName)(VARIANT varChild,BSTR szName); 139 STDMETHOD(accDoDefaultAction)(VARIANT varChild); 140 STDMETHOD(accHitTest)(long xLeft,long yTop,VARIANT *pvarChild); 141 STDMETHOD(accNavigate)(long navDir,VARIANT varStart,VARIANT *pvarEndUpAt); 142 STDMETHOD(accLocation)(long *pxLeft,long *pyTop,long *pcxWidth,long *pcyHeight,VARIANT varChild); 143 STDMETHOD(accSelect)(long flagsSelect,VARIANT varChild); 144 STDMETHOD(get_accDefaultAction)( VARIANT varChild,BSTR *pszDefaultAction); 145 STDMETHOD(get_accSelection)(VARIANT *pvarChildren); 146 STDMETHOD(get_accFocus)(VARIANT *pvarChild); 147 STDMETHOD(get_accKeyboardShortcut)( VARIANT varChild,BSTR *pszKeyboardShortcut); 148 STDMETHOD(get_accHelpTopic)(BSTR *pszHelpFile,VARIANT varChild,long *pidTopic); 149 STDMETHOD(get_accHelp)(VARIANT varChild,BSTR *pszHelp); 150 STDMETHOD(get_accState)(VARIANT varChild,VARIANT *pvarState); 151 STDMETHOD(get_accRole)(VARIANT varChild,VARIANT *pvarRole); 152 STDMETHOD(get_accDescription)(VARIANT varChild,BSTR *pszDescription); 153 STDMETHOD(get_accValue)( VARIANT varChild,BSTR *pszValue); 154 STDMETHOD(get_accName)(VARIANT varChild,BSTR *pszName); 155 STDMETHOD(get_accChild)(VARIANT varChild,IDispatch **ppdispChild); 156 STDMETHOD(get_accChildCount)(long *pcountChildren); 157 STDMETHOD(get_accParent)( IDispatch **ppdispParent); 158 159 // methods which are defined only in the IAccessible2 160 // These methods only declare here, and their implementation bodies are empty now. 161 STDMETHOD(get_nRelations)( long __RPC_FAR *nRelations) ; 162 STDMETHOD(get_relation)( long relationIndex, IAccessibleRelation __RPC_FAR *__RPC_FAR *relation) ; 163 STDMETHOD(get_relations)( long maxRelations, IAccessibleRelation __RPC_FAR *__RPC_FAR *relation, long __RPC_FAR *nRelations) ; 164 STDMETHOD(role)(long __RPC_FAR *role); 165 STDMETHOD(get_nActions)(long __RPC_FAR *nActions); 166 STDMETHOD(scrollTo)(enum IA2ScrollType scrollType); 167 STDMETHOD(scrollToPoint)(enum IA2CoordinateType coordinateType, long x, long y); 168 STDMETHOD(get_groupPosition)(long __RPC_FAR *groupLevel,long __RPC_FAR *similarItemsInGroup,long __RPC_FAR *positionInGroup); 169 STDMETHOD(get_states)( AccessibleStates __RPC_FAR *states ); 170 STDMETHOD(get_extendedRole)( BSTR __RPC_FAR *extendedRole ); 171 STDMETHOD(get_localizedExtendedRole)( BSTR __RPC_FAR *localizedExtendedRole ); 172 STDMETHOD(get_nExtendedStates)( long __RPC_FAR *nExtendedStates); 173 STDMETHOD(get_extendedStates)( long maxExtendedStates, BSTR __RPC_FAR *__RPC_FAR *extendedStates, long __RPC_FAR *nExtendedStates); 174 STDMETHOD(get_localizedExtendedStates)(long maxLocalizedExtendedStates,BSTR __RPC_FAR *__RPC_FAR *localizedExtendedStates,long __RPC_FAR *nLocalizedExtendedStates); 175 STDMETHOD(get_uniqueID)(long __RPC_FAR *uniqueID); 176 STDMETHOD(get_windowHandle)(HWND __RPC_FAR *windowHandle); 177 STDMETHOD(get_indexInParent)( long __RPC_FAR *accParentIndex ); 178 STDMETHOD(get_locale)( IA2Locale __RPC_FAR *locale ); 179 STDMETHOD(get_attributes)(/*[out]*/ BSTR *pAttr); 180 181 //IServiceProvider. 182 STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void** ppvObject); 183 184 //IAccessibleApplication 185 STDMETHOD(get_appName)(BSTR __RPC_FAR *name); 186 STDMETHOD(get_appVersion)(BSTR __RPC_FAR *version); 187 STDMETHOD(get_toolkitName)(BSTR __RPC_FAR *name); 188 STDMETHOD(get_toolkitVersion)(BSTR __RPC_FAR *version); 189 190 // methods which are defined only in IMAccessible 191 // These methods are provided for UNO management system. 192 // The UNO management system use these methods to put Accessibility 193 // information to COM. 194 STDMETHOD(Put_XAccName)(const OLECHAR __RPC_FAR *pszName); 195 STDMETHOD(Put_XAccRole)(unsigned short pRole); 196 STDMETHOD(DecreaseState)(DWORD pXSate); 197 STDMETHOD(IncreaseState)(DWORD pXSate); 198 STDMETHOD(SetState)(DWORD pXSate); 199 STDMETHOD(Put_XAccDescription)(const OLECHAR __RPC_FAR *pszDescription); 200 STDMETHOD(Put_XAccValue)(const OLECHAR __RPC_FAR *pszAccValue); 201 STDMETHOD(Put_XAccLocation)(const Location sLocation); 202 STDMETHOD(Put_XAccFocus)(long dChildID); 203 STDMETHOD(Put_XAccParent)(IMAccessible __RPC_FAR *pIParent); 204 STDMETHOD(Put_XAccWindowHandle)(HWND hwnd); 205 STDMETHOD(Put_XAccChildID)(long dChildID); 206 STDMETHOD(Put_XAccAgent)(long pAgent); 207 STDMETHOD(NotifyDestroy)(BOOL isDestroy); 208 STDMETHOD(Put_ActionDescription)( const OLECHAR* szAction); 209 STDMETHOD(SetDefaultAction)(long pAction); 210 STDMETHOD(GetUNOInterface)(long*); 211 STDMETHOD(SetXAccessible)(long); 212 213 private: 214 OLECHAR* m_pszName; 215 OLECHAR* m_pszValue; 216 OLECHAR* m_pszActionDescription; 217 unsigned short m_iRole; 218 DWORD m_dState; 219 OLECHAR* m_pszDescription; 220 IMAccessible* m_pIParent; 221 Location m_sLocation; 222 223 // identify a COM object/Acc object uniquely 224 long m_dChildID; 225 // specify the focus child ID in object self and its direct children 226 227 long m_dFocusChildID; 228 // parent window handle,will be used in the future application, its value comes from UNO 229 230 HWND m_hwnd; 231 232 // the COM class which implements IEnumVARIANT interface,currently only used in 233 // the implementation of get_accSelection 234 CEnumVariant* m_pEnumVar; 235 236 // specify if the XAccessible is invalid 237 BOOL m_isDestroy; 238 239 XAccessible* pUNOInterface; 240 Reference< XAccessible > pRef; 241 XAccessible* pAchorUNOInterface; 242 XAccessibleAction* m_pXAction; 243 XAccessibleContext* pRContextInterface; 244 Reference<XAccessibleContext> pRContext; 245 246 private: 247 248 // the helper methods in order to implement the above public methods 249 IMAccessible* GetChildInterface(long dChildIndex);//notice here the parameter is child index,not child id 250 IMAccessible* GetNavigateChildForDM(VARIANT varCur,short flags);//for decendant manage 251 HRESULT GetFirstChild(VARIANT varStart,VARIANT* pvarEndUpAt);//for accNavigate implementation 252 HRESULT GetLastChild(VARIANT varStart,VARIANT* pvarEndUpAt);//for accNavigate implementation 253 HRESULT GetNextSibling(VARIANT varStart,VARIANT* pvarEndUpAt);//for accNavigate implementation 254 HRESULT GetPreSibling(VARIANT varStart,VARIANT* pvarEndUpAt);//for accNavigate implementation 255 BOOL IsDecendantManage();//identify whether the current COM belongs to manage_decendant roles 256 257 // the following private methods are used to implement accSelect method 258 HRESULT SelectChild(XAccessible* pItem); 259 HRESULT DeSelectChild(XAccessible* pItem); 260 HRESULT SelectMutipleChidren( XAccessible** pItem,int size ); 261 HRESULT DeSelectMutipleChildren( XAccessible** pItem,int size ); 262 XAccessibleContext* GetContextByXAcc( XAccessible* pXAcc ); 263 Reference< XAccessibleSelection > GetSelection(); 264 // end accSelect implementation methods 265 BOOL GetXInterfaceFromXAccessible(XAccessible*, XInterface**, int); 266 HRESULT WINAPI SmartQI(void* pv, REFIID iid, void** ppvObject); 267 268 public: 269 STDMETHOD(Get_XAccChildID)(/*[out,retval]*/ long* childID); 270 // AccObjectManagerAgent is a management object in UNO, here keep its pointer for 271 // the implementation of accNavigate when decendant manage happens for List,Tree, or Table 272 // AccObjectManagerAgent and the following UNO objects XAccessble,XAccessibleSelection, 273 // XAccessibleAction are all used to operate UNO accessiblility information directly when 274 // implement some specific MSAA methods,such as accSelection,accNavigate 275 static AccObjectManagerAgent* g_pAgent; 276 277 static BOOL get_IAccessibleFromXAccessible(long pXAcc,IAccessible** ppIA); 278 BOOL m_bRequiresSave; 279 XGUIDToComObjHash m_containedObjects; 280 281 static HRESULT WINAPI _SmartQI(void* pv, 282 REFIID iid, void** ppvObject, DWORD) 283 { 284 return ((CMAccessible*)pv)->SmartQI(pv,iid,ppvObject); 285 } 286 287 static void get_OLECHARFromAny(Any& pAny, OLECHAR* pChar); 288 289 static void get_OLECHAR4Numbering(const Any& pAny, short numberingLevel, const OUString& numberingPrefix,OLECHAR* pChar); 290 291 // Helper function for data conversion. 292 static void ConvertAnyToVariant(const ::com::sun::star::uno::Any &rAnyVal, VARIANT *pvData); 293 }; 294 295 296 297 #endif //__MACCESSIBLE_H_ 298