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 .
21 // AccActionBase.cpp: implementation of the CAccActionBase class.
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()
53 * Returns the number of action.
55 * @param nActions the number of action.
57 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccActionBase::nActions(/*[out,retval]*/long* nActions
)
64 if( pRXAct
.is() && nActions
!= nullptr )
66 *nActions
= GetXInterface()->getAccessibleActionCount();
73 } catch(...) { return E_FAIL
; }
77 * Performs specified action on the object.
79 * @param actionIndex the index of action.
81 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccActionBase::doAction(/* [in] */ long actionIndex
)
89 return GetXInterface()->doAccessibleAction( actionIndex
)?S_OK
:E_FAIL
;
93 } catch(...) { return E_FAIL
; }
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
)
109 if(description
== nullptr)
112 // #CHECK XInterface#
116 OUString ouStr
= GetXInterface()->getAccessibleActionDescription(actionIndex
);
119 SysFreeString(*description
);
120 *description
= SysAllocString(o3tl::toW(ouStr
.getStr()));
124 } catch(...) { return E_FAIL
; }
127 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccActionBase::get_name( long, BSTR __RPC_FAR
*)
132 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccActionBase::get_localizedName( long, BSTR __RPC_FAR
*)
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
,
150 /* [length_is][length_is][size_is][size_is][out] */ BSTR __RPC_FAR
*__RPC_FAR
*keyBinding
,
151 /* [retval][out] */ long __RPC_FAR
*nBinding
)
157 if( !keyBinding
|| !nBinding
)
163 Reference
< XAccessibleKeyBinding
> binding
= GetXInterface()->getAccessibleActionKeyBinding(actionIndex
);
167 sal_Int32 nCount
= binding
->getAccessibleKeyBindingCount();
169 *keyBinding
= static_cast<BSTR
*>(::CoTaskMemAlloc(nCount
*sizeof(BSTR
)));
171 // #CHECK Memory Allocation#
172 if(*keyBinding
== nullptr)
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()));
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
200 CUNOXWrapper::put_XInterface(pXInterface
);
203 if(pUNOInterface
== nullptr)
205 Reference
<XAccessibleContext
> pRContext
= pUNOInterface
->getAccessibleContext();
206 if( !pRContext
.is() )
209 Reference
<XAccessibleAction
> pRXI(pRContext
,UNO_QUERY
);
216 } catch(...) { return E_FAIL
; }
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */