1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include "Resource.h" // main symbols
25 #include <string_view>
26 #include <com/sun/star/accessibility/XAccessible.hpp>
27 #include <com/sun/star/accessibility/XAccessibleSelection.hpp>
28 #include <com/sun/star/accessibility/XAccessibleAction.hpp>
29 #include <AccObjectWinManager.hxx>
30 #include "EnumVariant.h"
31 #include "acccommon.h"
32 #include <rtl/ustring.hxx>
35 enum class XInterfaceType
;
39 *This class implements IMAccessible interface, which inherits from IAccessible2, and
40 *in turn inherits from IAccessible. So its methods include the methods defined only in
41 *IAccessible, plus the methods defined only in IAccessible2, plus the methods defined
42 *only in IMAccessible.
44 class ATL_NO_VTABLE CMAccessible
:
45 public CComObjectRoot
,
46 public CComCoClass
<CMAccessible
, &CLSID_MAccessible
>,
47 public IDispatchImpl
<IMAccessible
, &IID_IMAccessible
, &LIBID_UACCCOMLib
>,
48 public IServiceProvider
,
49 public IAccessibleApplication
51 typedef ::std::map
<const GUID
, CComPtr
<IUnknown
>, ltComp
> XGUIDToComObjHash
;
55 virtual ~CMAccessible();
59 DECLARE_GET_CONTROLLING_UNKNOWN()
61 DECLARE_PROTECT_FINAL_CONSTRUCT()
63 BEGIN_COM_MAP(CMAccessible
)
64 COM_INTERFACE_ENTRY(IMAccessible
)
65 COM_INTERFACE_ENTRY(IAccessible
)
66 COM_INTERFACE_ENTRY(IAccessible2
)
67 COM_INTERFACE_ENTRY(IDispatch
)
68 COM_INTERFACE_ENTRY(IAccessibleApplication
)
69 COM_INTERFACE_ENTRY(IServiceProvider
)
70 COM_INTERFACE_ENTRY_FUNC_BLIND(0,SmartQI_
)
72 #pragma clang diagnostic push
73 #pragma clang diagnostic ignored "-Winconsistent-missing-override"
77 #pragma clang diagnostic pop
81 STDMETHOD(put_accValue
)(VARIANT varChild
,BSTR szValue
) override
;
82 STDMETHOD(put_accName
)(VARIANT varChild
,BSTR szName
) override
;
83 STDMETHOD(accDoDefaultAction
)(VARIANT varChild
) override
;
84 STDMETHOD(accHitTest
)(long xLeft
,long yTop
,VARIANT
*pvarChild
) override
;
85 STDMETHOD(accNavigate
)(long navDir
,VARIANT varStart
,VARIANT
*pvarEndUpAt
) override
;
86 STDMETHOD(accLocation
)(long *pxLeft
,long *pyTop
,long *pcxWidth
,long *pcyHeight
,VARIANT varChild
) override
;
87 STDMETHOD(accSelect
)(long flagsSelect
,VARIANT varChild
) override
;
88 STDMETHOD(get_accDefaultAction
)( VARIANT varChild
,BSTR
*pszDefaultAction
) override
;
89 STDMETHOD(get_accSelection
)(VARIANT
*pvarChildren
) override
;
90 STDMETHOD(get_accFocus
)(VARIANT
*pvarChild
) override
;
91 STDMETHOD(get_accKeyboardShortcut
)( VARIANT varChild
,BSTR
*pszKeyboardShortcut
) override
;
92 STDMETHOD(get_accHelpTopic
)(BSTR
*pszHelpFile
,VARIANT varChild
,long *pidTopic
) override
;
93 STDMETHOD(get_accHelp
)(VARIANT varChild
,BSTR
*pszHelp
) override
;
94 STDMETHOD(get_accState
)(VARIANT varChild
,VARIANT
*pvarState
) override
;
95 STDMETHOD(get_accRole
)(VARIANT varChild
,VARIANT
*pvarRole
) override
;
96 STDMETHOD(get_accDescription
)(VARIANT varChild
,BSTR
*pszDescription
) override
;
97 STDMETHOD(get_accValue
)( VARIANT varChild
,BSTR
*pszValue
) override
;
98 STDMETHOD(get_accName
)(VARIANT varChild
,BSTR
*pszName
) override
;
99 STDMETHOD(get_accChild
)(VARIANT varChild
,IDispatch
**ppdispChild
) override
;
100 STDMETHOD(get_accChildCount
)(long *pcountChildren
) override
;
101 STDMETHOD(get_accParent
)( IDispatch
**ppdispParent
) override
;
103 // methods which are defined only in the IAccessible2
104 // These methods only declare here, and their implementation bodies are empty now.
105 STDMETHOD(get_nRelations
)( long __RPC_FAR
*nRelations
) override
;
106 STDMETHOD(get_relation
)( long relationIndex
, IAccessibleRelation __RPC_FAR
*__RPC_FAR
*relation
) override
;
107 STDMETHOD(get_relations
)( long maxRelations
, IAccessibleRelation __RPC_FAR
*__RPC_FAR
*relation
, long __RPC_FAR
*nRelations
) override
;
108 STDMETHOD(role
)(long __RPC_FAR
*role
) override
;
109 STDMETHOD(get_nActions
)(long __RPC_FAR
*nActions
);
110 STDMETHOD(scrollTo
)(enum IA2ScrollType scrollType
) override
;
111 STDMETHOD(scrollToPoint
)(enum IA2CoordinateType coordinateType
, long x
, long y
) override
;
112 STDMETHOD(get_groupPosition
)(long __RPC_FAR
*groupLevel
,long __RPC_FAR
*similarItemsInGroup
,long __RPC_FAR
*positionInGroup
) override
;
113 STDMETHOD(get_states
)( AccessibleStates __RPC_FAR
*states
) override
;
114 STDMETHOD(get_extendedRole
)( BSTR __RPC_FAR
*extendedRole
) override
;
115 STDMETHOD(get_localizedExtendedRole
)( BSTR __RPC_FAR
*localizedExtendedRole
) override
;
116 STDMETHOD(get_nExtendedStates
)( long __RPC_FAR
*nExtendedStates
) override
;
117 STDMETHOD(get_extendedStates
)( long maxExtendedStates
, BSTR __RPC_FAR
*__RPC_FAR
*extendedStates
, long __RPC_FAR
*nExtendedStates
) override
;
118 STDMETHOD(get_localizedExtendedStates
)(long maxLocalizedExtendedStates
,BSTR __RPC_FAR
*__RPC_FAR
*localizedExtendedStates
,long __RPC_FAR
*nLocalizedExtendedStates
) override
;
119 STDMETHOD(get_uniqueID
)(long __RPC_FAR
*uniqueID
) override
;
120 STDMETHOD(get_windowHandle
)(HWND __RPC_FAR
*windowHandle
) override
;
121 STDMETHOD(get_indexInParent
)( long __RPC_FAR
*accParentIndex
) override
;
122 STDMETHOD(get_locale
)( IA2Locale __RPC_FAR
*locale
) override
;
123 STDMETHOD(get_attributes
)(/*[out]*/ BSTR
*pAttr
) override
;
126 STDMETHOD(QueryService
)(REFGUID guidService
, REFIID riid
, void** ppvObject
) override
;
128 //IAccessibleApplication
129 STDMETHOD(get_appName
)(BSTR __RPC_FAR
*name
) override
;
130 STDMETHOD(get_appVersion
)(BSTR __RPC_FAR
*version
) override
;
131 STDMETHOD(get_toolkitName
)(BSTR __RPC_FAR
*name
) override
;
132 STDMETHOD(get_toolkitVersion
)(BSTR __RPC_FAR
*version
) override
;
134 // methods which are defined only in IMAccessible
135 // These methods are provided for UNO management system.
136 // The UNO management system use these methods to put Accessibility
137 // information to COM.
138 STDMETHOD(Put_XAccName
)(const OLECHAR __RPC_FAR
*pszName
) override
;
139 STDMETHOD(Put_XAccRole
)(unsigned short pRole
) override
;
140 STDMETHOD(DecreaseState
)(DWORD pXSate
) override
;
141 STDMETHOD(IncreaseState
)(DWORD pXSate
) override
;
142 STDMETHOD(SetState
)(DWORD pXSate
) override
;
143 STDMETHOD(Put_XAccValue
)(const OLECHAR __RPC_FAR
*pszAccValue
) override
;
144 STDMETHOD(Put_XAccFocus
)(long dChildID
) override
;
145 STDMETHOD(Put_XAccParent
)(IMAccessible __RPC_FAR
*pIParent
) override
;
146 STDMETHOD(Put_XAccWindowHandle
)(HWND hwnd
) override
;
147 STDMETHOD(Put_XAccChildID
)(long dChildID
) override
;
148 STDMETHOD(Put_XAccObjectManager
)(hyper pManager
) override
;
149 STDMETHOD(NotifyDestroy
)() override
;
150 STDMETHOD(Put_ActionDescription
)( const OLECHAR
* szAction
) override
;
151 STDMETHOD(SetDefaultAction
)(hyper pAction
) override
;
152 STDMETHOD(GetUNOInterface
)(hyper
*) override
;
153 STDMETHOD(SetXAccessible
)(hyper
) override
;
158 BSTR m_pszActionDescription
;
159 unsigned short m_iRole
;
161 IMAccessible
* m_pIParent
;
163 // identify a COM object/Acc object uniquely
165 // specify the focus child ID in object self and its direct children
167 long m_dFocusChildID
;
168 // parent window handle,will be used in the future application, its value comes from UNO
172 // the COM class which implements IEnumVARIANT interface,currently only used in
173 // the implementation of get_accSelection
174 CEnumVariant
* m_pEnumVar
;
176 // specify if the XAccessible is invalid
179 css::uno::Reference
<css::accessibility::XAccessible
> m_xAccessible
;
180 // initially m_xAction and m_xContext are the same object
181 // but they may be different once AccObject::UpdateAction() is called?
182 css::uno::Reference
<css::accessibility::XAccessibleAction
> m_xAction
;
183 css::uno::Reference
<css::accessibility::XAccessibleContext
> m_xContext
;
187 // the helper methods in order to implement the above public methods
188 IMAccessible
* GetChildInterface(long dChildIndex
);//notice here the parameter is child index,not child id
189 IMAccessible
* GetNavigateChildForDM(VARIANT varCur
,short flags
);//for descendant manage
190 HRESULT
GetFirstChild(VARIANT varStart
,VARIANT
* pvarEndUpAt
);//for accNavigate implementation
191 HRESULT
GetLastChild(VARIANT varStart
,VARIANT
* pvarEndUpAt
);//for accNavigate implementation
192 HRESULT
GetNextSibling(VARIANT varStart
,VARIANT
* pvarEndUpAt
);//for accNavigate implementation
193 HRESULT
GetPreSibling(VARIANT varStart
,VARIANT
* pvarEndUpAt
);//for accNavigate implementation
195 static css::accessibility::XAccessibleContext
* GetContextByXAcc(
196 css::accessibility::XAccessible
* pXAcc
);
197 static bool GetXInterfaceFromXAccessible(css::accessibility::XAccessible
*,
198 css::uno::XInterface
**, XInterfaceType
);
199 HRESULT WINAPI
SmartQI(void* pv
, REFIID iid
, void** ppvObject
);
202 // AccObjectWinManager is a management object in UNO, here keep its pointer for
203 // the implementation of accNavigate when descendant manage happens for List,Tree, or Table
204 // AccObjectWinManager and the following UNO objects XAccessible,XAccessibleSelection,
205 // XAccessibleAction are all used to operate UNO accessibility information directly when
206 // implement some specific MSAA methods,such as accSelection,accNavigate
207 static AccObjectWinManager
* g_pAccObjectManager
;
209 static IAccessible
* get_IAccessibleFromXAccessible(css::accessibility::XAccessible
* pXAcc
);
210 XGUIDToComObjHash m_containedObjects
;
212 static HRESULT WINAPI
SmartQI_(void* pv
,
213 REFIID iid
, void** ppvObject
, DWORD_PTR
)
215 return static_cast<CMAccessible
*>(pv
)->SmartQI(pv
,iid
,ppvObject
);
218 // Helper function for data conversion.
219 static void ConvertAnyToVariant(const css::uno::Any
&rAnyVal
,
225 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */