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