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>
33 #include "AccessibleKeyStroke.h"
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 * Helper function used for getting default action by UNO role.
55 * @param pRContext UNO context interface pointer.
56 * @param pRet the corresponding string to be returned.
58 void GetDfActionByUNORole(XAccessibleContext
* pRContext
, BSTR
* pRet
)
61 if(pRContext
== NULL
|| pRet
== NULL
)
66 long Role
= pRContext
->getAccessibleRole();
71 *pRet
= ::SysAllocString(PRESS_STR
);
76 *pRet
= ::SysAllocString(SELECT_STR
);
80 Reference
< XAccessibleStateSet
> pRState
= pRContext
->getAccessibleStateSet();
86 Sequence
<short> pStates
= pRState
->getStates();
87 int count
= pStates
.getLength();
88 *pRet
= ::SysAllocString(CHECK_STR
);
89 for( int iIndex
= 0;iIndex
< count
;iIndex
++ )
91 if( pStates
[iIndex
] == AccessibleStateType::CHECKED
)
93 SAFE_SYSFREESTRING(*pRet
);
94 *pRet
= ::SysAllocString(UNCHECK_STR
);
104 * Returns the number of action.
106 * @param nActions the number of action.
108 STDMETHODIMP
CAccActionBase::nActions(/*[out,retval]*/long* nActions
)
112 ENTER_PROTECTED_BLOCK
115 if( pRXAct
.is() && nActions
!= NULL
)
117 *nActions
= GetXInterface()->getAccessibleActionCount();
124 LEAVE_PROTECTED_BLOCK
128 * Performs specified action on the object.
130 * @param actionIndex the index of action.
132 STDMETHODIMP
CAccActionBase::doAction(/* [in] */ long actionIndex
)
136 ENTER_PROTECTED_BLOCK
140 return GetXInterface()->doAccessibleAction( actionIndex
)?S_OK
:E_FAIL
;
144 LEAVE_PROTECTED_BLOCK
148 * Gets description of specified action.
150 * @param actionIndex the index of action.
151 * @param description the description string of the specified action.
153 STDMETHODIMP
CAccActionBase::get_description(long actionIndex
,BSTR __RPC_FAR
*description
)
157 ENTER_PROTECTED_BLOCK
160 if(description
== NULL
)
163 // #CHECK XInterface#
167 ::rtl::OUString ouStr
= GetXInterface()->getAccessibleActionDescription(actionIndex
);
170 SAFE_SYSFREESTRING(*description
);
171 *description
= SysAllocString((OLECHAR
*)ouStr
.getStr());
175 LEAVE_PROTECTED_BLOCK
178 STDMETHODIMP
CAccActionBase::get_name( long, BSTR __RPC_FAR
*)
183 STDMETHODIMP
CAccActionBase::get_localizedName( long, BSTR __RPC_FAR
*)
189 * Returns key binding object (if any) associated with specified action
190 * key binding is string.
191 * e.g. "alt+d" (like IAccessible::get_accKeyboardShortcut).
193 * @param actionIndex the index of action.
194 * @param nMaxBinding the max number of key binding.
195 * @param keyBinding the key binding array.
196 * @param nBinding the actual number of key binding returned.
198 STDMETHODIMP
CAccActionBase::get_keyBinding(
199 /* [in] */ long actionIndex
,
201 /* [length_is][length_is][size_is][size_is][out] */ BSTR __RPC_FAR
*__RPC_FAR
*keyBinding
,
202 /* [retval][out] */ long __RPC_FAR
*nBinding
)
206 ENTER_PROTECTED_BLOCK
208 if( !keyBinding
|| !nBinding
)
214 Reference
< XAccessibleKeyBinding
> binding
= GetXInterface()->getAccessibleActionKeyBinding(actionIndex
);
218 long nCount
= (binding
.get())->getAccessibleKeyBindingCount();
222 *keyBinding
= (BSTR
*)::CoTaskMemAlloc(nCount
*sizeof(BSTR
));
224 // #CHECK Memory Allocation#
225 if(*keyBinding
== NULL
)
228 for( int index
= 0;index
< nCount
;index
++ )
230 memset(wString
,0,sizeof(wString
));
231 GetkeyBindingStrByXkeyBinding( (binding
.get())->getAccessibleKeyBinding(index
), wString
);
233 (*keyBinding
)[index
] = SysAllocString(wString
);
239 LEAVE_PROTECTED_BLOCK
243 * Override of IUNOXWrapper.
245 * @param pXInterface the pointer of UNO interface.
247 STDMETHODIMP
CAccActionBase::put_XInterface(hyper pXInterface
)
249 // internal IUNOXWrapper - no mutex meeded
251 ENTER_PROTECTED_BLOCK
253 CUNOXWrapper::put_XInterface(pXInterface
);
256 if(pUNOInterface
== NULL
)
258 Reference
<XAccessibleContext
> pRContext
= pUNOInterface
->getAccessibleContext();
259 if( !pRContext
.is() )
262 Reference
<XAccessibleAction
> pRXI(pRContext
,UNO_QUERY
);
269 LEAVE_PROTECTED_BLOCK
273 * Helper function used for converting keybinding to string.
275 * @param keySet the key stroke sequence.
276 * @param pString the output keybinding string.
278 void CAccActionBase::GetkeyBindingStrByXkeyBinding( const Sequence
< KeyStroke
> &keySet
, OLECHAR
* pString
)
284 for( int iIndex
= 0;iIndex
< keySet
.getLength();iIndex
++ )
286 KeyStroke stroke
= keySet
[iIndex
];
287 OLECHAR wString
[64] = {NULL
};
288 wcscat(wString
, OLESTR("\n"));
289 wcscat(wString
, &stroke
.KeyChar
);
291 wcscat( pString
, wString
);
296 * Helper function used for converting key code to ole string.
298 * @param key the key code.
300 OLECHAR
const * CAccActionBase::getOLECHARFromKeyCode(long key
)
309 #define CODEENTRY(key) {KEYCODE_##key, L#key}
310 {MODIFIER_SHIFT
, L
"SHIFT" },
311 {MODIFIER_CTRL
, L
"CTRL" },
312 {MODIFIER_ALT
, L
"ALT" },
313 CODEENTRY(NUM0
),CODEENTRY(NUM1
),CODEENTRY(NUM2
),CODEENTRY(NUM3
),CODEENTRY(NUM4
),CODEENTRY(NUM5
),
314 CODEENTRY(NUM6
),CODEENTRY(NUM7
),CODEENTRY(NUM8
),CODEENTRY(NUM9
),
315 CODEENTRY(A
),CODEENTRY(B
),CODEENTRY(C
),CODEENTRY(D
),CODEENTRY(E
),CODEENTRY(F
),
316 CODEENTRY(G
),CODEENTRY(H
),CODEENTRY(I
),CODEENTRY(J
),CODEENTRY(K
),CODEENTRY(L
),
317 CODEENTRY(M
),CODEENTRY(N
),CODEENTRY(O
),CODEENTRY(P
),CODEENTRY(Q
),CODEENTRY(R
),
318 CODEENTRY(S
),CODEENTRY(T
),CODEENTRY(U
),CODEENTRY(V
),CODEENTRY(W
),CODEENTRY(X
),
319 CODEENTRY(Y
),CODEENTRY(Z
),
320 CODEENTRY(F1
),CODEENTRY(F2
),CODEENTRY(F3
),CODEENTRY(F4
),CODEENTRY(F5
),CODEENTRY(F6
),
321 CODEENTRY(F7
),CODEENTRY(F8
),CODEENTRY(F9
),CODEENTRY(F10
),CODEENTRY(F11
),CODEENTRY(F12
),
322 CODEENTRY(F13
),CODEENTRY(F14
),CODEENTRY(F15
),CODEENTRY(F16
),CODEENTRY(F17
),CODEENTRY(F18
),
323 CODEENTRY(F19
),CODEENTRY(F20
),CODEENTRY(F21
),CODEENTRY(F22
),CODEENTRY(F23
),CODEENTRY(F24
),
324 CODEENTRY(F25
),CODEENTRY(F26
),
326 { KEYCODE_DOWN
, L
"DOWN" },
327 { KEYCODE_UP
, L
"UP" },
328 { KEYCODE_LEFT
, L
"LEFT" },
329 { KEYCODE_RIGHT
, L
"RIGHT" },
330 { KEYCODE_HOME
, L
"HOME" },
331 { KEYCODE_END
, L
"END" },
332 { KEYCODE_PAGEUP
, L
"PAGEUP" },
333 { KEYCODE_PAGEDOWN
, L
"PAGEDOWN" },
334 { KEYCODE_RETURN
, L
"RETURN" },
335 { KEYCODE_ESCAPE
, L
"ESCAPE" },
336 { KEYCODE_TAB
, L
"TAB" },
337 { KEYCODE_BACKSPACE
, L
"BACKSPACE" },
338 { KEYCODE_SPACE
, L
"SPACE" },
339 { KEYCODE_INSERT
, L
"INSERT" },
340 { KEYCODE_DELETE
, L
"DELETE" },
341 { KEYCODE_ADD
, L
"ADD" },
342 { KEYCODE_SUBTRACT
, L
"SUBTRACT" },
343 { KEYCODE_MULTIPLY
, L
"MULTIPLY" },
344 { KEYCODE_DIVIDE
, L
"DIVIDE" },
345 { KEYCODE_POINT
, L
"POINT" },
346 { KEYCODE_COMMA
, L
"COMMA" },
347 { KEYCODE_LESS
, L
"LESS" },
348 { KEYCODE_GREATER
, L
"GREATER" },
349 { KEYCODE_EQUAL
, L
"EQUAL" },
350 { KEYCODE_OPEN
, L
"OPEN" },
351 { KEYCODE_CUT
, L
"CUT" },
352 { KEYCODE_COPY
, L
"COPY" },
353 { KEYCODE_PASTE
, L
"PASTE" },
354 { KEYCODE_UNDO
, L
"UNDO" },
355 { KEYCODE_REPEAT
, L
"REPEAT" },
356 { KEYCODE_FIND
, L
"FIND" },
357 { KEYCODE_PROPERTIES
, L
"PROPERTIES" },
358 { KEYCODE_FRONT
, L
"FRONT" },
359 { KEYCODE_CONTEXTMENU
, L
"CONTEXTMENU" },
360 { KEYCODE_HELP
, L
"HELP" },
362 static long nCount
= SAL_N_ELEMENTS(map
);
369 if(key
<map
[mid
].keyCode
)
371 else if(key
>map
[mid
].keyCode
)
378 if(key
== map
[mid
].keyCode
)
388 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */