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 "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()
55 * Returns the number of action.
57 * @param nActions the number of action.
59 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccActionBase::nActions(/*[out,retval]*/long* nActions
)
66 if( pRXAct
.is() && nActions
!= nullptr )
68 *nActions
= GetXInterface()->getAccessibleActionCount();
79 * Performs specified action on the object.
81 * @param actionIndex the index of action.
83 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccActionBase::doAction(/* [in] */ long actionIndex
)
91 return GetXInterface()->doAccessibleAction( actionIndex
)?S_OK
:E_FAIL
;
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
)
108 ENTER_PROTECTED_BLOCK
111 if(description
== nullptr)
114 // #CHECK XInterface#
118 OUString ouStr
= GetXInterface()->getAccessibleActionDescription(actionIndex
);
121 SAFE_SYSFREESTRING(*description
);
122 *description
= SysAllocString(o3tl::toW(ouStr
.getStr()));
126 LEAVE_PROTECTED_BLOCK
129 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccActionBase::get_name( long, BSTR __RPC_FAR
*)
134 COM_DECLSPEC_NOTHROW STDMETHODIMP
CAccActionBase::get_localizedName( long, BSTR __RPC_FAR
*)
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
,
152 /* [length_is][length_is][size_is][size_is][out] */ BSTR __RPC_FAR
*__RPC_FAR
*keyBinding
,
153 /* [retval][out] */ long __RPC_FAR
*nBinding
)
157 ENTER_PROTECTED_BLOCK
159 if( !keyBinding
|| !nBinding
)
165 Reference
< XAccessibleKeyBinding
> binding
= GetXInterface()->getAccessibleActionKeyBinding(actionIndex
);
169 long nCount
= binding
.get()->getAccessibleKeyBindingCount();
171 *keyBinding
= static_cast<BSTR
*>(::CoTaskMemAlloc(nCount
*sizeof(BSTR
)));
173 // #CHECK Memory Allocation#
174 if(*keyBinding
== nullptr)
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()));
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
);
205 if(pUNOInterface
== nullptr)
207 Reference
<XAccessibleContext
> pRContext
= pUNOInterface
->getAccessibleContext();
208 if( !pRContext
.is() )
211 Reference
<XAccessibleAction
> pRXI(pRContext
,UNO_QUERY
);
218 LEAVE_PROTECTED_BLOCK
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */