Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / winaccessibility / source / UAccCOM / MAccessible.h
blobcdbe0e85905d01af62b656c0a26f82f67b56c171
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_WINACCESSIBILITY_SOURCE_UACCCOM_MACCESSIBLE_H
21 #define INCLUDED_WINACCESSIBILITY_SOURCE_UACCCOM_MACCESSIBLE_H
23 #include "Resource.h" // main symbols
24 #include <map>
25 #include <com/sun/star/accessibility/XAccessible.hpp>
26 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
27 #include <com/sun/star/accessibility/XAccessibleAction.hpp>
28 #include <AccObjectManagerAgent.hxx>
29 #include "EnumVariant.h"
30 #include "acccommon.h"
31 #include <rtl/ustring.hxx>
33 #define OBJID_WINDOW ((LONG)0x00000000)
34 #define OBJID_SYSMENU ((LONG)0xFFFFFFFF)
35 #define OBJID_TITLEBAR ((LONG)0xFFFFFFFE)
36 #define OBJID_MENU ((LONG)0xFFFFFFFD)
37 #define OBJID_CLIENT ((LONG)0xFFFFFFFC)
38 #define OBJID_VSCROLL ((LONG)0xFFFFFFFB)
39 #define OBJID_HSCROLL ((LONG)0xFFFFFFFA)
40 #define OBJID_SIZEGRIP ((LONG)0xFFFFFFF9)
41 #define OBJID_CARET ((LONG)0xFFFFFFF8)
42 #define OBJID_CURSOR ((LONG)0xFFFFFFF7)
43 #define OBJID_ALERT ((LONG)0xFFFFFFF6)
44 #define OBJID_SOUND ((LONG)0xFFFFFFF5)
45 #define OBJID_QUERYCLASSNAMEIDX ((LONG)0xFFFFFFF4)
46 #define OBJID_NATIVEOM ((LONG)0xFFFFFFF0)
48 /**
49 *This class implements IMAccessible interface, which inherits from IAccessible2, and
50 *in turn inherits from IAccessible. So its methods include the methods defined only in
51 *IAccessible, plus the methods defined only in IAccessible2, plus the methods defined
52 *only in IMAccessible.
54 class ATL_NO_VTABLE CMAccessible :
55 public CComObjectRoot,
56 public CComCoClass<CMAccessible, &CLSID_MAccessible>,
57 public IDispatchImpl<IMAccessible, &IID_IMAccessible, &LIBID_UACCCOMLib>,
58 public IServiceProvider,
59 public IAccessibleApplication
61 typedef ::std::map<const GUID, CComPtr<IUnknown>, ltComp> XGUIDToComObjHash;
63 public:
64 CMAccessible();
65 virtual ~CMAccessible();
67 DECLARE_NO_REGISTRY()
69 DECLARE_GET_CONTROLLING_UNKNOWN()
71 DECLARE_PROTECT_FINAL_CONSTRUCT()
73 BEGIN_COM_MAP(CMAccessible)
74 COM_INTERFACE_ENTRY(IMAccessible)
75 COM_INTERFACE_ENTRY(IAccessible)
76 COM_INTERFACE_ENTRY(IAccessible2)
77 COM_INTERFACE_ENTRY(IDispatch)
78 COM_INTERFACE_ENTRY(IAccessibleApplication)
79 COM_INTERFACE_ENTRY(IServiceProvider)
80 COM_INTERFACE_ENTRY_FUNC_BLIND(NULL,SmartQI_)
81 #if defined __clang__
82 #pragma clang diagnostic push
83 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
84 #endif
85 END_COM_MAP()
86 #if defined __clang__
87 #pragma clang diagnostic pop
88 #endif
90 // IMAccessible
91 STDMETHOD(put_accValue)(VARIANT varChild,BSTR szValue) override;
92 STDMETHOD(put_accName)(VARIANT varChild,BSTR szName) override;
93 STDMETHOD(accDoDefaultAction)(VARIANT varChild) override;
94 STDMETHOD(accHitTest)(long xLeft,long yTop,VARIANT *pvarChild) override;
95 STDMETHOD(accNavigate)(long navDir,VARIANT varStart,VARIANT *pvarEndUpAt) override;
96 STDMETHOD(accLocation)(long *pxLeft,long *pyTop,long *pcxWidth,long *pcyHeight,VARIANT varChild) override;
97 STDMETHOD(accSelect)(long flagsSelect,VARIANT varChild) override;
98 STDMETHOD(get_accDefaultAction)( VARIANT varChild,BSTR *pszDefaultAction) override;
99 STDMETHOD(get_accSelection)(VARIANT *pvarChildren) override;
100 STDMETHOD(get_accFocus)(VARIANT *pvarChild) override;
101 STDMETHOD(get_accKeyboardShortcut)( VARIANT varChild,BSTR *pszKeyboardShortcut) override;
102 STDMETHOD(get_accHelpTopic)(BSTR *pszHelpFile,VARIANT varChild,long *pidTopic) override;
103 STDMETHOD(get_accHelp)(VARIANT varChild,BSTR *pszHelp) override;
104 STDMETHOD(get_accState)(VARIANT varChild,VARIANT *pvarState) override;
105 STDMETHOD(get_accRole)(VARIANT varChild,VARIANT *pvarRole) override;
106 STDMETHOD(get_accDescription)(VARIANT varChild,BSTR *pszDescription) override;
107 STDMETHOD(get_accValue)( VARIANT varChild,BSTR *pszValue) override;
108 STDMETHOD(get_accName)(VARIANT varChild,BSTR *pszName) override;
109 STDMETHOD(get_accChild)(VARIANT varChild,IDispatch **ppdispChild) override;
110 STDMETHOD(get_accChildCount)(long *pcountChildren) override;
111 STDMETHOD(get_accParent)( IDispatch **ppdispParent) override;
113 // methods which are defined only in the IAccessible2
114 // These methods only declare here, and their implementation bodies are empty now.
115 STDMETHOD(get_nRelations)( long __RPC_FAR *nRelations) override;
116 STDMETHOD(get_relation)( long relationIndex, IAccessibleRelation __RPC_FAR *__RPC_FAR *relation) override;
117 STDMETHOD(get_relations)( long maxRelations, IAccessibleRelation __RPC_FAR *__RPC_FAR *relation, long __RPC_FAR *nRelations) override;
118 STDMETHOD(role)(long __RPC_FAR *role) override;
119 STDMETHOD(get_nActions)(long __RPC_FAR *nActions);
120 STDMETHOD(scrollTo)(enum IA2ScrollType scrollType) override;
121 STDMETHOD(scrollToPoint)(enum IA2CoordinateType coordinateType, long x, long y) override;
122 STDMETHOD(get_groupPosition)(long __RPC_FAR *groupLevel,long __RPC_FAR *similarItemsInGroup,long __RPC_FAR *positionInGroup) override;
123 STDMETHOD(get_states)( AccessibleStates __RPC_FAR *states ) override;
124 STDMETHOD(get_extendedRole)( BSTR __RPC_FAR *extendedRole ) override;
125 STDMETHOD(get_localizedExtendedRole)( BSTR __RPC_FAR *localizedExtendedRole ) override;
126 STDMETHOD(get_nExtendedStates)( long __RPC_FAR *nExtendedStates) override;
127 STDMETHOD(get_extendedStates)( long maxExtendedStates, BSTR __RPC_FAR *__RPC_FAR *extendedStates, long __RPC_FAR *nExtendedStates) override;
128 STDMETHOD(get_localizedExtendedStates)(long maxLocalizedExtendedStates,BSTR __RPC_FAR *__RPC_FAR *localizedExtendedStates,long __RPC_FAR *nLocalizedExtendedStates) override;
129 STDMETHOD(get_uniqueID)(long __RPC_FAR *uniqueID) override;
130 STDMETHOD(get_windowHandle)(HWND __RPC_FAR *windowHandle) override;
131 STDMETHOD(get_indexInParent)( long __RPC_FAR *accParentIndex ) override;
132 STDMETHOD(get_locale)( IA2Locale __RPC_FAR *locale ) override;
133 STDMETHOD(get_attributes)(/*[out]*/ BSTR *pAttr) override;
135 //IServiceProvider.
136 STDMETHOD(QueryService)(REFGUID guidService, REFIID riid, void** ppvObject) override;
138 //IAccessibleApplication
139 STDMETHOD(get_appName)(BSTR __RPC_FAR *name) override;
140 STDMETHOD(get_appVersion)(BSTR __RPC_FAR *version) override;
141 STDMETHOD(get_toolkitName)(BSTR __RPC_FAR *name) override;
142 STDMETHOD(get_toolkitVersion)(BSTR __RPC_FAR *version) override;
144 // methods which are defined only in IMAccessible
145 // These methods are provided for UNO management system.
146 // The UNO management system use these methods to put Accessibility
147 // information to COM.
148 STDMETHOD(Put_XAccName)(const OLECHAR __RPC_FAR *pszName) override;
149 STDMETHOD(Put_XAccRole)(unsigned short pRole) override;
150 STDMETHOD(DecreaseState)(DWORD pXSate) override;
151 STDMETHOD(IncreaseState)(DWORD pXSate) override;
152 STDMETHOD(SetState)(DWORD pXSate) override;
153 STDMETHOD(Put_XAccDescription)(const OLECHAR __RPC_FAR *pszDescription) override;
154 STDMETHOD(Put_XAccValue)(const OLECHAR __RPC_FAR *pszAccValue) override;
155 STDMETHOD(Put_XAccLocation)(const Location sLocation) override;
156 STDMETHOD(Put_XAccFocus)(long dChildID) override;
157 STDMETHOD(Put_XAccParent)(IMAccessible __RPC_FAR *pIParent) override;
158 STDMETHOD(Put_XAccWindowHandle)(HWND hwnd) override;
159 STDMETHOD(Put_XAccChildID)(long dChildID) override;
160 STDMETHOD(Put_XAccAgent)(hyper pAgent) override;
161 STDMETHOD(NotifyDestroy)(BOOL isDestroy) override;
162 STDMETHOD(Put_ActionDescription)( const OLECHAR* szAction) override;
163 STDMETHOD(SetDefaultAction)(hyper pAction) override;
164 STDMETHOD(GetUNOInterface)(hyper*) override;
165 STDMETHOD(SetXAccessible)(hyper) override;
167 private:
168 BSTR m_pszName;
169 BSTR m_pszValue;
170 BSTR m_pszActionDescription;
171 unsigned short m_iRole;
172 DWORD m_dState;
173 BSTR m_pszDescription;
174 IMAccessible* m_pIParent;
175 Location m_sLocation;
177 // identify a COM object/Acc object uniquely
178 long m_dChildID;
179 // specify the focus child ID in object self and its direct children
181 long m_dFocusChildID;
182 // parent window handle,will be used in the future application, its value comes from UNO
184 HWND m_hwnd;
186 // the COM class which implements IEnumVARIANT interface,currently only used in
187 // the implementation of get_accSelection
188 CEnumVariant* m_pEnumVar;
190 // specify if the XAccessible is invalid
191 BOOL m_isDestroy;
193 css::uno::Reference<css::accessibility::XAccessible> m_xAccessible;
194 // initially m_xAction and m_xContext are the same object
195 // but they may be different once AccObject::UpdateAction() is called?
196 css::uno::Reference<css::accessibility::XAccessibleAction> m_xAction;
197 css::uno::Reference<css::accessibility::XAccessibleContext> m_xContext;
199 private:
201 // the helper methods in order to implement the above public methods
202 IMAccessible* GetChildInterface(long dChildIndex);//notice here the parameter is child index,not child id
203 IMAccessible* GetNavigateChildForDM(VARIANT varCur,short flags);//for descendant manage
204 HRESULT GetFirstChild(VARIANT varStart,VARIANT* pvarEndUpAt);//for accNavigate implementation
205 HRESULT GetLastChild(VARIANT varStart,VARIANT* pvarEndUpAt);//for accNavigate implementation
206 HRESULT GetNextSibling(VARIANT varStart,VARIANT* pvarEndUpAt);//for accNavigate implementation
207 HRESULT GetPreSibling(VARIANT varStart,VARIANT* pvarEndUpAt);//for accNavigate implementation
208 BOOL IsDescendantManage();//identify whether the current COM belongs to manage_descendant roles
210 // the following private methods are used to implement accSelect method
211 HRESULT SelectChild(css::accessibility::XAccessible* pItem);
212 HRESULT DeSelectChild(css::accessibility::XAccessible* pItem);
213 HRESULT SelectMultipleChidren(css::accessibility::XAccessible** pItem,
214 int size);
215 HRESULT DeSelectMultipleChildren(css::accessibility::XAccessible** pItem,
216 int size);
217 static css::accessibility::XAccessibleContext* GetContextByXAcc(
218 css::accessibility::XAccessible* pXAcc);
219 css::uno::Reference<css::accessibility::XAccessibleSelection> GetSelection();
220 // end accSelect implementation methods
221 static BOOL GetXInterfaceFromXAccessible(css::accessibility::XAccessible*,
222 css::uno::XInterface**, int);
223 HRESULT WINAPI SmartQI(void* pv, REFIID iid, void** ppvObject);
225 public:
226 STDMETHOD(Get_XAccChildID)(/*[out,retval]*/ long* childID) override;
227 // AccObjectManagerAgent is a management object in UNO, here keep its pointer for
228 // the implementation of accNavigate when descendant manage happens for List,Tree, or Table
229 // AccObjectManagerAgent and the following UNO objects XAccessible,XAccessibleSelection,
230 // XAccessibleAction are all used to operate UNO accessibility information directly when
231 // implement some specific MSAA methods,such as accSelection,accNavigate
232 static AccObjectManagerAgent* g_pAgent;
234 static BOOL get_IAccessibleFromXAccessible(
235 css::accessibility::XAccessible * pXAcc, IAccessible** ppIA);
236 BOOL m_bRequiresSave;
237 XGUIDToComObjHash m_containedObjects;
239 static HRESULT WINAPI SmartQI_(void* pv,
240 REFIID iid, void** ppvObject, DWORD_PTR)
242 return static_cast<CMAccessible*>(pv)->SmartQI(pv,iid,ppvObject);
245 static OUString get_StringFromAny(css::uno::Any const & pAny);
247 static OUString get_String4Numbering(const css::uno::Any& pAny,
248 sal_Int16 numberingLevel, const OUString& numberingPrefix);
250 // Helper function for data conversion.
251 static void ConvertAnyToVariant(const css::uno::Any &rAnyVal,
252 VARIANT *pvData);
257 #endif // INCLUDED_WINACCESSIBILITY_SOURCE_UACCCOM_MACCESSIBLE_H
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */