Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccActionBase.cxx
blob3062e96a855cfac6a9484c1ed86dc74df9dc61cc
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 .
21 // AccActionBase.cpp: implementation of the CAccActionBase class.
23 #include "stdafx.h"
25 #include "AccActionBase.h"
26 #include <com/sun/star/accessibility/XAccessible.hpp>
27 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
28 #include <com/sun/star/accessibility/AccessibleRole.hpp>
29 #include <com/sun/star/accessibility/XAccessibleContext.hpp>
31 #include <vcl/svapp.hxx>
32 #include <o3tl/char16_t2wchar_t.hxx>
33 #include <comphelper/AccessibleImplementationHelper.hxx>
35 #include "acccommon.h"
37 using namespace com::sun::star::accessibility::AccessibleRole;
38 using namespace com::sun::star::accessibility;
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::awt;
43 // Construction/Destruction
46 CAccActionBase::CAccActionBase()
49 CAccActionBase::~CAccActionBase()
52 /**
53 * Returns the number of action.
55 * @param nActions the number of action.
57 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::nActions(/*[out,retval]*/long* nActions)
59 SolarMutexGuard g;
61 try {
63 // #CHECK#
64 if( pRXAct.is() && nActions != nullptr )
66 *nActions = GetXInterface()->getAccessibleActionCount();
67 return S_OK;
69 *nActions = 0;
71 return S_OK;
73 } catch(...) { return E_FAIL; }
76 /**
77 * Performs specified action on the object.
79 * @param actionIndex the index of action.
81 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::doAction(/* [in] */ long actionIndex)
83 SolarMutexGuard g;
85 try {
87 if( pRXAct.is() )
89 return GetXInterface()->doAccessibleAction( actionIndex )?S_OK:E_FAIL;
91 return E_FAIL;
93 } catch(...) { return E_FAIL; }
96 /**
97 * Gets description of specified action.
99 * @param actionIndex the index of action.
100 * @param description the description string of the specified action.
102 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::get_description(long actionIndex,BSTR __RPC_FAR *description)
104 SolarMutexGuard g;
106 try {
108 // #CHECK#
109 if(description == nullptr)
110 return E_INVALIDARG;
112 // #CHECK XInterface#
113 if(!pRXAct.is())
114 return E_FAIL;
116 OUString ouStr = GetXInterface()->getAccessibleActionDescription(actionIndex);
117 // #CHECK#
119 SysFreeString(*description);
120 *description = SysAllocString(o3tl::toW(ouStr.getStr()));
122 return S_OK;
124 } catch(...) { return E_FAIL; }
127 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::get_name( long, BSTR __RPC_FAR *)
129 return E_NOTIMPL;
132 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::get_localizedName( long, BSTR __RPC_FAR *)
134 return E_NOTIMPL;
138 * Returns key binding object (if any) associated with specified action
139 * key binding is string.
140 * e.g. "alt+d" (like IAccessible::get_accKeyboardShortcut).
142 * @param actionIndex the index of action.
143 * @param nMaxBinding the max number of key binding.
144 * @param keyBinding the key binding array.
145 * @param nBinding the actual number of key binding returned.
147 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::get_keyBinding(
148 /* [in] */ long actionIndex,
149 /* [in] */ long,
150 /* [length_is][length_is][size_is][size_is][out] */ BSTR __RPC_FAR *__RPC_FAR *keyBinding,
151 /* [retval][out] */ long __RPC_FAR *nBinding)
153 SolarMutexGuard g;
155 try {
157 if( !keyBinding || !nBinding)
158 return E_INVALIDARG;
160 if( !pRXAct.is() )
161 return E_FAIL;
163 Reference< XAccessibleKeyBinding > binding = GetXInterface()->getAccessibleActionKeyBinding(actionIndex);
164 if( !binding.is() )
165 return E_FAIL;
167 sal_Int32 nCount = binding->getAccessibleKeyBindingCount();
169 *keyBinding = static_cast<BSTR*>(::CoTaskMemAlloc(nCount*sizeof(BSTR)));
171 // #CHECK Memory Allocation#
172 if(*keyBinding == nullptr)
173 return E_FAIL;
175 for( sal_Int32 index = 0;index < nCount;index++ )
177 auto const wString = comphelper::GetkeyBindingStrByXkeyBinding(
178 binding->getAccessibleKeyBinding(index));
180 (*keyBinding)[index] = SysAllocString(o3tl::toW(wString.getStr()));
183 *nBinding = nCount;
184 return S_OK;
186 } catch(...) { return E_FAIL; }
190 * Override of IUNOXWrapper.
192 * @param pXInterface the pointer of UNO interface.
194 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::put_XInterface(hyper pXInterface)
196 // internal IUNOXWrapper - no mutex meeded
198 try {
200 CUNOXWrapper::put_XInterface(pXInterface);
202 //special query.
203 if(pUNOInterface == nullptr)
204 return E_FAIL;
205 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
206 if( !pRContext.is() )
207 return E_FAIL;
209 Reference<XAccessibleAction> pRXI(pRContext,UNO_QUERY);
210 if( !pRXI.is() )
211 pRXAct = nullptr;
212 else
213 pRXAct = pRXI.get();
214 return S_OK;
216 } catch(...) { return E_FAIL; }
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */