LibreOffice Module accessibility (master) 1
accessibleiconchoicectrl.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
22#include <com/sun/star/accessibility/AccessibleEventId.hpp>
23#include <com/sun/star/accessibility/AccessibleRole.hpp>
24#include <com/sun/star/accessibility/AccessibleStateType.hpp>
25#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
29
30
31namespace accessibility
32{
33
34
35 // class AccessibleIconChoiceCtrl ----------------------------------------------
36
37 using namespace ::com::sun::star::accessibility;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::lang;
40 using namespace ::com::sun::star;
41
42
43 // Ctor() and Dtor()
44
46 ImplInheritanceHelper( _rIconCtrl.GetWindowPeer() ),
47 m_xParent ( _xParent )
48 {
49 }
50
52 {
53 if ( !isAlive() )
54 return;
55
56 switch ( rVclWindowEvent.GetId() )
57 {
58 case VclEventId::ListboxSelect :
59 {
60 // First send an event that tells the listeners of a
61 // modified selection. The active descendant event is
62 // send after that so that the receiving AT has time to
63 // read the text or name of the active child.
64// NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, Any(), Any() );
65
66 if ( getCtrl() && getCtrl()->HasFocus() )
67 {
68 SvxIconChoiceCtrlEntry* pEntry = static_cast< SvxIconChoiceCtrlEntry* >( rVclWindowEvent.GetData() );
69 if ( pEntry )
70 {
71 sal_Int32 nPos = getCtrl()->GetEntryListPos( pEntry );
73 uno::Any aOldValue, aNewValue;
74 aNewValue <<= xChild;
75 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue );
76
77 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, aOldValue, aNewValue );
78
79 }
80 }
81 break;
82 }
83 case VclEventId::WindowGetFocus :
84 {
86 if ( pCtrl && pCtrl->HasFocus() )
87 {
88 SvxIconChoiceCtrlEntry* pEntry = static_cast< SvxIconChoiceCtrlEntry* >( rVclWindowEvent.GetData() );
89 if ( pEntry == nullptr )
90 {
91 pEntry = getCtrl()->GetSelectedEntry();
92 }
93 if ( pEntry )
94 {
95 sal_Int32 nPos = pCtrl->GetEntryListPos( pEntry );
97 uno::Any aOldValue, aNewValue;
98 aNewValue <<= xChild;
99 NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue );
100 NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, aOldValue, aNewValue );
101 }
102 }
103 break;
104 }
105 default:
106 VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent);
107 }
108 }
109
110 // XComponent
111
113 {
114 ::osl::MutexGuard aGuard( m_aMutex );
115
116 m_xParent = nullptr;
117 }
118
119 // XServiceInfo
120
122 {
123 return "com.sun.star.comp.svtools.AccessibleIconChoiceControl";
124 }
125
127 {
128 return {"com.sun.star.accessibility.AccessibleContext",
129 "com.sun.star.accessibility.AccessibleComponent",
130 "com.sun.star.awt.AccessibleIconChoiceControl"};
131 }
132
133 sal_Bool SAL_CALL AccessibleIconChoiceCtrl::supportsService( const OUString& _rServiceName )
134 {
135 return cppu::supportsService(this, _rServiceName);
136 }
137
138 // XAccessible
139
141 {
142 ensureAlive();
143 return this;
144 }
145
146 // XAccessibleContext
147
149 {
151
152 return getCtrl()->GetEntryCount();
153 }
154
156 {
158
159 if (i < 0 || i >= getAccessibleChildCount())
160 throw IndexOutOfBoundsException();
161
163 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry(i);
164 if ( !pEntry )
165 throw RuntimeException("getAccessibleChild: Entry "
166 + OUString::number(i) + " not found",
167 getXWeak());
168
169 return new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this );
170 }
171
173 {
174 ::osl::MutexGuard aGuard( m_aMutex );
175
176 ensureAlive();
177 return m_xParent;
178 }
179
181 {
182 //return AccessibleRole::TREE;
183 return AccessibleRole::LIST;
184 }
185
187 {
189
190 return getCtrl()->GetAccessibleDescription();
191 }
192
194 {
196
197 OUString sName = getCtrl()->GetAccessibleName();
198 if ( sName.isEmpty() )
199 sName = "IconChoiceControl";
200 return sName;
201 }
202
203 // XAccessibleSelection
204
205 void SAL_CALL AccessibleIconChoiceCtrl::selectAccessibleChild( sal_Int64 nChildIndex )
206 {
208
209 if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
210 throw IndexOutOfBoundsException();
211
213 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex );
214 if ( !pEntry )
215 throw IndexOutOfBoundsException();
216
217 pCtrl->SetCursor( pEntry );
218 }
219
221 {
223
224 if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount())
225 throw IndexOutOfBoundsException();
226
228 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex );
229 if ( !pEntry )
230 throw IndexOutOfBoundsException();
231
232 return ( pCtrl->GetCursor() == pEntry );
233 }
234
236 {
238 getCtrl()->SetNoSelection();
239 }
240
242 {
244
246 sal_Int32 nCount = pCtrl->GetEntryCount();
247 for ( sal_Int32 i = 0; i < nCount; ++i )
248 {
249 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
250 if ( pCtrl->GetCursor() != pEntry )
251 pCtrl->SetCursor( pEntry );
252 }
253 }
254
256 {
258
259 sal_Int64 nSelCount = 0;
261 sal_Int32 nCount = pCtrl->GetEntryCount();
262 for ( sal_Int32 i = 0; i < nCount; ++i )
263 {
264 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
265 if ( pCtrl->GetCursor() == pEntry )
266 ++nSelCount;
267 }
268
269 return nSelCount;
270 }
271
273 {
275
276 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() )
277 throw IndexOutOfBoundsException();
278
280 sal_Int32 nSelCount = 0;
282 sal_Int32 nCount = pCtrl->GetEntryCount();
283 for ( sal_Int32 i = 0; i < nCount; ++i )
284 {
285 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
286 if ( pCtrl->GetCursor() == pEntry )
287 ++nSelCount;
288
289 if ( nSelCount == ( nSelectedChildIndex + 1 ) )
290 {
291 xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this );
292 break;
293 }
294 }
295
296 return xChild;
297 }
298
299 void SAL_CALL AccessibleIconChoiceCtrl::deselectAccessibleChild( sal_Int64 nSelectedChildIndex )
300 {
302
303 if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getAccessibleChildCount() )
304 throw IndexOutOfBoundsException();
305
306 sal_Int32 nSelCount = 0;
308 sal_Int32 nCount = pCtrl->GetEntryCount();
309 bool bFound = false;
310 for ( sal_Int32 i = 0; i < nCount; ++i )
311 {
312 SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i );
313 if ( pEntry->IsSelected() )
314 {
315 ++nSelCount;
316 if ( i == nSelectedChildIndex )
317 bFound = true;
318 }
319 }
320
321 // if only one entry is selected and its index is chosen to deselect -> no selection anymore
322 if ( nSelCount == 1 && bFound )
323 pCtrl->SetNoSelection();
324 }
325
327 {
328 VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet );
329 if ( isAlive() )
330 {
331 rStateSet |= AccessibleStateType::FOCUSABLE;
332 rStateSet |= AccessibleStateType::MANAGES_DESCENDANTS;
333 rStateSet |= AccessibleStateType::SELECTABLE;
334 }
335 }
336
338 {
339 return GetAs<SvtIconChoiceCtrl >();
340 }
341
342}// namespace accessibility
343
344
345/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool IsSelected() const
VclEventId GetId() const
void * GetData() const
the class AccessibleListBoxEntry represents the class for an accessible object of a listbox entry
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void FillAccessibleStateSet(sal_Int64 &rStateSet) override
virtual sal_Int64 SAL_CALL getAccessibleChildCount() override
virtual void ProcessWindowEvent(const VclWindowEvent &rVclWindowEvent) override
sal_Bool SAL_CALL isAccessibleChildSelected(sal_Int64 nChildIndex) override
virtual void SAL_CALL disposing() override
this function is called upon disposing the component
virtual OUString SAL_CALL getAccessibleName() override
virtual OUString SAL_CALL getAccessibleDescription() override
virtual css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL getAccessibleContext() override
AccessibleIconChoiceCtrl(SvtIconChoiceCtrl const &_rIconCtrl, const css::uno::Reference< css::accessibility::XAccessible > &_xParent)
OAccessibleBase needs a valid view.
css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getSelectedAccessibleChild(sal_Int64 nSelectedChildIndex) override
VclPtr< SvtIconChoiceCtrl > getCtrl() const
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleChild(sal_Int64 i) override
void SAL_CALL selectAccessibleChild(sal_Int64 nChildIndex) override
css::uno::Reference< css::accessibility::XAccessible > m_xParent
virtual css::uno::Reference< css::accessibility::XAccessible > SAL_CALL getAccessibleParent() override
void SAL_CALL deselectAccessibleChild(sal_Int64 nSelectedChildIndex) override
sal_Int64 SAL_CALL getSelectedAccessibleChildCount() override
virtual sal_Int16 SAL_CALL getAccessibleRole() override
virtual OUString SAL_CALL getImplementationName() override
int nCount
OUString sName
std::mutex m_aMutex
sal_uInt16 nPos
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
bool isAlive()
unsigned char sal_Bool