/src/libreoffice/vcl/source/accessibility/accessibleiconchoicectrl.cxx
Line | Count | Source |
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 | | |
20 | | #include <accessibility/accessibleiconchoicectrl.hxx> |
21 | | #include <accessibility/accessibleiconchoicectrlentry.hxx> |
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> |
26 | | #include <comphelper/accessiblecontexthelper.hxx> |
27 | | #include <vcl/vclevent.hxx> |
28 | | #include <vcl/toolkit/ivctrl.hxx> |
29 | | |
30 | | // class AccessibleIconChoiceCtrl ---------------------------------------------- |
31 | | |
32 | | using namespace ::com::sun::star::accessibility; |
33 | | using namespace ::com::sun::star::uno; |
34 | | using namespace ::com::sun::star::lang; |
35 | | using namespace ::com::sun::star; |
36 | | |
37 | | |
38 | | // Ctor() and Dtor() |
39 | | |
40 | | AccessibleIconChoiceCtrl::AccessibleIconChoiceCtrl(SvtIconChoiceCtrl& _rIconCtrl) |
41 | 0 | : ImplInheritanceHelper(&_rIconCtrl) |
42 | 0 | { |
43 | 0 | } |
44 | | |
45 | | void AccessibleIconChoiceCtrl::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent ) |
46 | 0 | { |
47 | 0 | if ( !isAlive() ) |
48 | 0 | return; |
49 | | |
50 | 0 | switch ( rVclWindowEvent.GetId() ) |
51 | 0 | { |
52 | 0 | case VclEventId::ListboxSelect : |
53 | 0 | { |
54 | 0 | if (getCtrl()) |
55 | 0 | { |
56 | 0 | SvxIconChoiceCtrlEntry* pEntry = static_cast< SvxIconChoiceCtrlEntry* >( rVclWindowEvent.GetData() ); |
57 | 0 | if ( pEntry ) |
58 | 0 | { |
59 | 0 | sal_Int32 nPos = getCtrl()->GetEntryListPos( pEntry ); |
60 | 0 | Reference< XAccessible > xChild = new AccessibleIconChoiceCtrlEntry( *getCtrl(), nPos, this ); |
61 | 0 | uno::Any aOldValue, aNewValue; |
62 | 0 | aNewValue <<= xChild; |
63 | 0 | if (getCtrl()->HasFocus()) |
64 | 0 | NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue ); |
65 | |
|
66 | 0 | NotifyAccessibleEvent( AccessibleEventId::SELECTION_CHANGED, aOldValue, aNewValue ); |
67 | 0 | } |
68 | 0 | } |
69 | 0 | break; |
70 | 0 | } |
71 | 0 | case VclEventId::WindowGetFocus : |
72 | 0 | { |
73 | 0 | VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl(); |
74 | 0 | if ( pCtrl && pCtrl->HasFocus() ) |
75 | 0 | { |
76 | 0 | SvxIconChoiceCtrlEntry* pEntry = getCtrl()->GetSelectedEntry(); |
77 | 0 | if ( pEntry ) |
78 | 0 | { |
79 | 0 | sal_Int32 nPos = pCtrl->GetEntryListPos( pEntry ); |
80 | 0 | Reference< XAccessible > xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, nPos, this ); |
81 | 0 | uno::Any aOldValue, aNewValue; |
82 | 0 | aNewValue <<= xChild; |
83 | 0 | NotifyAccessibleEvent( AccessibleEventId::ACTIVE_DESCENDANT_CHANGED, aOldValue, aNewValue ); |
84 | 0 | } |
85 | 0 | } |
86 | 0 | break; |
87 | 0 | } |
88 | 0 | default: |
89 | 0 | VCLXAccessibleComponent::ProcessWindowChildEvent (rVclWindowEvent); |
90 | 0 | } |
91 | 0 | } |
92 | | |
93 | | // XServiceInfo |
94 | | |
95 | | OUString SAL_CALL AccessibleIconChoiceCtrl::getImplementationName() |
96 | 0 | { |
97 | 0 | return u"com.sun.star.comp.svtools.AccessibleIconChoiceControl"_ustr; |
98 | 0 | } |
99 | | |
100 | | Sequence< OUString > SAL_CALL AccessibleIconChoiceCtrl::getSupportedServiceNames() |
101 | 0 | { |
102 | 0 | return {u"com.sun.star.accessibility.AccessibleContext"_ustr, |
103 | 0 | u"com.sun.star.awt.AccessibleIconChoiceControl"_ustr}; |
104 | 0 | } |
105 | | |
106 | | // XAccessibleContext |
107 | | |
108 | | sal_Int64 SAL_CALL AccessibleIconChoiceCtrl::getAccessibleChildCount( ) |
109 | 0 | { |
110 | 0 | ::comphelper::OExternalLockGuard aGuard( this ); |
111 | |
|
112 | 0 | return getCtrl()->GetEntryCount(); |
113 | 0 | } |
114 | | |
115 | | Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getAccessibleChild( sal_Int64 i ) |
116 | 0 | { |
117 | 0 | ::comphelper::OExternalLockGuard aGuard( this ); |
118 | |
|
119 | 0 | if (i < 0 || i >= getAccessibleChildCount()) |
120 | 0 | throw IndexOutOfBoundsException(); |
121 | | |
122 | 0 | VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl(); |
123 | 0 | return new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this ); |
124 | 0 | } |
125 | | |
126 | | sal_Int16 SAL_CALL AccessibleIconChoiceCtrl::getAccessibleRole( ) |
127 | 0 | { |
128 | | //return AccessibleRole::TREE; |
129 | 0 | return AccessibleRole::LIST; |
130 | 0 | } |
131 | | |
132 | | OUString SAL_CALL AccessibleIconChoiceCtrl::getAccessibleDescription( ) |
133 | 0 | { |
134 | 0 | ::comphelper::OExternalLockGuard aGuard( this ); |
135 | |
|
136 | 0 | return getCtrl()->GetAccessibleDescription(); |
137 | 0 | } |
138 | | |
139 | | OUString SAL_CALL AccessibleIconChoiceCtrl::getAccessibleName( ) |
140 | 0 | { |
141 | 0 | ::comphelper::OExternalLockGuard aGuard( this ); |
142 | |
|
143 | 0 | return getCtrl()->GetAccessibleName(); |
144 | 0 | } |
145 | | |
146 | | // XAccessibleSelection |
147 | | |
148 | | void SAL_CALL AccessibleIconChoiceCtrl::selectAccessibleChild( sal_Int64 nChildIndex ) |
149 | 0 | { |
150 | 0 | ::comphelper::OExternalLockGuard aGuard( this ); |
151 | |
|
152 | 0 | if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount()) |
153 | 0 | throw IndexOutOfBoundsException(); |
154 | | |
155 | 0 | VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl(); |
156 | 0 | SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex ); |
157 | 0 | if ( !pEntry ) |
158 | 0 | throw IndexOutOfBoundsException(); |
159 | | |
160 | 0 | pCtrl->SetCursor( pEntry ); |
161 | 0 | } |
162 | | |
163 | | sal_Bool SAL_CALL AccessibleIconChoiceCtrl::isAccessibleChildSelected( sal_Int64 nChildIndex ) |
164 | 0 | { |
165 | 0 | ::comphelper::OExternalLockGuard aGuard( this ); |
166 | |
|
167 | 0 | if (nChildIndex < 0 || nChildIndex >= getAccessibleChildCount()) |
168 | 0 | throw IndexOutOfBoundsException(); |
169 | | |
170 | 0 | VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl(); |
171 | 0 | SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( nChildIndex ); |
172 | 0 | if ( !pEntry ) |
173 | 0 | throw IndexOutOfBoundsException(); |
174 | | |
175 | 0 | return ( pCtrl->GetCursor() == pEntry ); |
176 | 0 | } |
177 | | |
178 | | void SAL_CALL AccessibleIconChoiceCtrl::clearAccessibleSelection( ) |
179 | 0 | { |
180 | | // one entry should always be selected, so don't unselect |
181 | 0 | } |
182 | | |
183 | | void SAL_CALL AccessibleIconChoiceCtrl::selectAllAccessibleChildren( ) |
184 | 0 | { |
185 | 0 | ::comphelper::OExternalLockGuard aGuard( this ); |
186 | | |
187 | | // don't do anything if there are no or multiple entries, as only |
188 | | // a single one can be selected |
189 | 0 | VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl(); |
190 | 0 | sal_Int32 nCount = pCtrl->GetEntryCount(); |
191 | 0 | if (nCount != 1) |
192 | 0 | return; |
193 | | |
194 | 0 | pCtrl->SetCursor(pCtrl->GetEntry(0)); |
195 | 0 | } |
196 | | |
197 | | sal_Int64 SAL_CALL AccessibleIconChoiceCtrl::getSelectedAccessibleChildCount( ) |
198 | 0 | { |
199 | 0 | ::comphelper::OExternalLockGuard aGuard( this ); |
200 | |
|
201 | 0 | VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl(); |
202 | 0 | if (pCtrl->GetCursor()) |
203 | 0 | return 1; |
204 | | |
205 | 0 | return 0; |
206 | 0 | } |
207 | | |
208 | | Reference< XAccessible > SAL_CALL AccessibleIconChoiceCtrl::getSelectedAccessibleChild( sal_Int64 nSelectedChildIndex ) |
209 | 0 | { |
210 | 0 | ::comphelper::OExternalLockGuard aGuard( this ); |
211 | |
|
212 | 0 | if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getSelectedAccessibleChildCount() ) |
213 | 0 | throw IndexOutOfBoundsException(); |
214 | | |
215 | 0 | rtl::Reference< AccessibleIconChoiceCtrlEntry > xChild; |
216 | 0 | sal_Int32 nSelCount = 0; |
217 | 0 | VclPtr<SvtIconChoiceCtrl> pCtrl = getCtrl(); |
218 | 0 | sal_Int32 nCount = pCtrl->GetEntryCount(); |
219 | 0 | for ( sal_Int32 i = 0; i < nCount; ++i ) |
220 | 0 | { |
221 | 0 | SvxIconChoiceCtrlEntry* pEntry = pCtrl->GetEntry( i ); |
222 | 0 | if ( pCtrl->GetCursor() == pEntry ) |
223 | 0 | ++nSelCount; |
224 | |
|
225 | 0 | if ( nSelCount == ( nSelectedChildIndex + 1 ) ) |
226 | 0 | { |
227 | 0 | xChild = new AccessibleIconChoiceCtrlEntry( *pCtrl, i, this ); |
228 | 0 | break; |
229 | 0 | } |
230 | 0 | } |
231 | |
|
232 | 0 | return xChild; |
233 | 0 | } |
234 | | |
235 | | void SAL_CALL AccessibleIconChoiceCtrl::deselectAccessibleChild( sal_Int64 nSelectedChildIndex ) |
236 | 0 | { |
237 | 0 | ::comphelper::OExternalLockGuard aGuard( this ); |
238 | |
|
239 | 0 | if ( nSelectedChildIndex < 0 || nSelectedChildIndex >= getAccessibleChildCount() ) |
240 | 0 | throw IndexOutOfBoundsException(); |
241 | | |
242 | | // one entry should always be selected, so don't unselect |
243 | 0 | } |
244 | | |
245 | | void AccessibleIconChoiceCtrl::FillAccessibleStateSet( sal_Int64& rStateSet ) |
246 | 0 | { |
247 | 0 | VCLXAccessibleComponent::FillAccessibleStateSet( rStateSet ); |
248 | 0 | if ( isAlive() ) |
249 | 0 | { |
250 | 0 | rStateSet |= AccessibleStateType::FOCUSABLE; |
251 | 0 | rStateSet |= AccessibleStateType::MANAGES_DESCENDANTS; |
252 | 0 | } |
253 | 0 | } |
254 | | |
255 | | VclPtr< SvtIconChoiceCtrl > AccessibleIconChoiceCtrl::getCtrl() const |
256 | 0 | { |
257 | 0 | return GetAs<SvtIconChoiceCtrl >(); |
258 | 0 | } |
259 | | |
260 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |