Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / winaccessibility / source / UAccCOM / AccActionBase.cxx
blobbe8a5bfbfe4d09aa984a3af59d481ab0007f6598
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 "AccessibleKeyStroke.h"
37 #include "acccommon.h"
39 using namespace com::sun::star::accessibility::AccessibleRole;
40 using namespace com::sun::star::accessibility;
41 using namespace com::sun::star::uno;
42 using namespace com::sun::star::awt;
45 // Construction/Destruction
48 CAccActionBase::CAccActionBase()
51 CAccActionBase::~CAccActionBase()
54 /**
55 * Returns the number of action.
57 * @param nActions the number of action.
59 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::nActions(/*[out,retval]*/long* nActions)
61 SolarMutexGuard g;
63 ENTER_PROTECTED_BLOCK
65 // #CHECK#
66 if( pRXAct.is() && nActions != nullptr )
68 *nActions = GetXInterface()->getAccessibleActionCount();
69 return S_OK;
71 *nActions = 0;
73 return S_OK;
75 LEAVE_PROTECTED_BLOCK
78 /**
79 * Performs specified action on the object.
81 * @param actionIndex the index of action.
83 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::doAction(/* [in] */ long actionIndex)
85 SolarMutexGuard g;
87 ENTER_PROTECTED_BLOCK
89 if( pRXAct.is() )
91 return GetXInterface()->doAccessibleAction( actionIndex )?S_OK:E_FAIL;
93 return E_FAIL;
95 LEAVE_PROTECTED_BLOCK
98 /**
99 * Gets description of specified action.
101 * @param actionIndex the index of action.
102 * @param description the description string of the specified action.
104 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::get_description(long actionIndex,BSTR __RPC_FAR *description)
106 SolarMutexGuard g;
108 ENTER_PROTECTED_BLOCK
110 // #CHECK#
111 if(description == nullptr)
112 return E_INVALIDARG;
114 // #CHECK XInterface#
115 if(!pRXAct.is())
116 return E_FAIL;
118 OUString ouStr = GetXInterface()->getAccessibleActionDescription(actionIndex);
119 // #CHECK#
121 SAFE_SYSFREESTRING(*description);
122 *description = SysAllocString(o3tl::toW(ouStr.getStr()));
124 return S_OK;
126 LEAVE_PROTECTED_BLOCK
129 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::get_name( long, BSTR __RPC_FAR *)
131 return E_NOTIMPL;
134 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::get_localizedName( long, BSTR __RPC_FAR *)
136 return E_NOTIMPL;
140 * Returns key binding object (if any) associated with specified action
141 * key binding is string.
142 * e.g. "alt+d" (like IAccessible::get_accKeyboardShortcut).
144 * @param actionIndex the index of action.
145 * @param nMaxBinding the max number of key binding.
146 * @param keyBinding the key binding array.
147 * @param nBinding the actual number of key binding returned.
149 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::get_keyBinding(
150 /* [in] */ long actionIndex,
151 /* [in] */ long,
152 /* [length_is][length_is][size_is][size_is][out] */ BSTR __RPC_FAR *__RPC_FAR *keyBinding,
153 /* [retval][out] */ long __RPC_FAR *nBinding)
155 SolarMutexGuard g;
157 ENTER_PROTECTED_BLOCK
159 if( !keyBinding || !nBinding)
160 return E_INVALIDARG;
162 if( !pRXAct.is() )
163 return E_FAIL;
165 Reference< XAccessibleKeyBinding > binding = GetXInterface()->getAccessibleActionKeyBinding(actionIndex);
166 if( !binding.is() )
167 return E_FAIL;
169 long nCount = binding.get()->getAccessibleKeyBindingCount();
171 *keyBinding = static_cast<BSTR*>(::CoTaskMemAlloc(nCount*sizeof(BSTR)));
173 // #CHECK Memory Allocation#
174 if(*keyBinding == nullptr)
175 return E_FAIL;
177 for( int index = 0;index < nCount;index++ )
179 auto const wString = comphelper::GetkeyBindingStrByXkeyBinding(
180 binding.get()->getAccessibleKeyBinding(index));
182 (*keyBinding)[index] = SysAllocString(o3tl::toW(wString.getStr()));
185 *nBinding = nCount;
186 return S_OK;
188 LEAVE_PROTECTED_BLOCK
192 * Override of IUNOXWrapper.
194 * @param pXInterface the pointer of UNO interface.
196 COM_DECLSPEC_NOTHROW STDMETHODIMP CAccActionBase::put_XInterface(hyper pXInterface)
198 // internal IUNOXWrapper - no mutex meeded
200 ENTER_PROTECTED_BLOCK
202 CUNOXWrapper::put_XInterface(pXInterface);
204 //special query.
205 if(pUNOInterface == nullptr)
206 return E_FAIL;
207 Reference<XAccessibleContext> pRContext = pUNOInterface->getAccessibleContext();
208 if( !pRContext.is() )
209 return E_FAIL;
211 Reference<XAccessibleAction> pRXI(pRContext,UNO_QUERY);
212 if( !pRXI.is() )
213 pRXAct = nullptr;
214 else
215 pRXAct = pRXI.get();
216 return S_OK;
218 LEAVE_PROTECTED_BLOCK
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */