Debian Codegraph @

vcl/source/accessibility/vclxaccessiblestatusbar.cxx

raw symbols SCIP
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/vclxaccessiblestatusbar.hxx>
21 #include <accessibility/vclxaccessiblestatusbaritem.hxx>
22 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
23 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
24 #include <comphelper/accessiblecontexthelper.hxx>
25 #include <o3tl/safeint.hxx>
26 #include <vcl/status.hxx>
27 #include <vcl/unohelp.hxx>
28 #include <vcl/vclevent.hxx>
29
30
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::accessibility;
35 using namespace ::comphelper;
36
37
38
39
40 VCLXAccessibleStatusBar::VCLXAccessibleStatusBar(vcl::Window* pWindow)
41 : VCLXAccessibleComponent(pWindow)
42 {
43 m_pStatusBar = GetAs<StatusBar>();
44
45 if ( m_pStatusBar )
46 m_aAccessibleChildren.assign( m_pStatusBar->GetItemCount(), rtl::Reference< VCLXAccessibleStatusBarItem >() );
47 }
48
49
50 void VCLXAccessibleStatusBar::UpdateShowing( sal_Int32 i, bool bShowing )
51 {
52 if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() )
53 {
54 rtl::Reference< VCLXAccessibleStatusBarItem > pVCLXAccessibleStatusBarItem( m_aAccessibleChildren[i] );
55 if ( pVCLXAccessibleStatusBarItem )
56 pVCLXAccessibleStatusBarItem->SetShowing( bShowing );
57 }
58 }
59
60
61 void VCLXAccessibleStatusBar::UpdateItemName( sal_Int32 i )
62 {
63 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
64 return;
65
66 rtl::Reference< VCLXAccessibleStatusBarItem > pVCLXAccessibleStatusBarItem( m_aAccessibleChildren[i] );
67 if ( pVCLXAccessibleStatusBarItem.is() )
68 {
69 OUString sItemName = pVCLXAccessibleStatusBarItem->GetItemName();
70 pVCLXAccessibleStatusBarItem->SetItemName( sItemName );
71 }
72 }
73
74
75 void VCLXAccessibleStatusBar::UpdateItemText( sal_Int32 i )
76 {
77 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
78 return;
79
80 rtl::Reference< VCLXAccessibleStatusBarItem > pVCLXAccessibleStatusBarItem( m_aAccessibleChildren[i] );
81 if ( pVCLXAccessibleStatusBarItem.is() )
82 {
83 OUString sItemText = pVCLXAccessibleStatusBarItem->GetItemText();
84 pVCLXAccessibleStatusBarItem->SetItemText( sItemText );
85 }
86 }
87
88
89 void VCLXAccessibleStatusBar::InsertChild( sal_Int32 i )
90 {
91 if ( i < 0 || o3tl::make_unsigned(i) > m_aAccessibleChildren.size() )
92 return;
93
94 // insert entry in child list
95 m_aAccessibleChildren.insert( m_aAccessibleChildren.begin() + i, rtl::Reference< VCLXAccessibleStatusBarItem >() );
96
97 // send accessible child event
98 Reference< XAccessible > xChild( getAccessibleChild( i ) );
99 if ( xChild.is() )
100 {
101 Any aOldValue, aNewValue;
102 aNewValue <<= xChild;
103 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
104 }
105 }
106
107
108 void VCLXAccessibleStatusBar::RemoveChild( sal_Int32 i )
109 {
110 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
111 return;
112
113 // get the accessible of the removed page
114 rtl::Reference< VCLXAccessibleStatusBarItem > xChild( m_aAccessibleChildren[i] );
115
116 // remove entry in child list
117 m_aAccessibleChildren.erase( m_aAccessibleChildren.begin() + i );
118
119 // send accessible child event
120 if ( xChild.is() )
121 {
122 Any aOldValue, aNewValue;
123 aOldValue <<= Reference< XAccessible >(xChild);
124 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
125
126 xChild->dispose();
127 }
128 }
129
130
131 void VCLXAccessibleStatusBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
132 {
133 switch ( rVclWindowEvent.GetId() )
134 {
135 case VclEventId::StatusbarItemAdded:
136 {
137 if ( m_pStatusBar )
138 {
139 sal_uInt16 nItemId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
140 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
141 InsertChild( nItemPos );
142 }
143 }
144 break;
145 case VclEventId::StatusbarItemRemoved:
146 {
147 if ( m_pStatusBar )
148 {
149 OExternalLockGuard aGuard( this );
150
151 sal_uInt16 nItemId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
152 for ( sal_Int64 i = 0, nCount = m_aAccessibleChildren.size(); i < nCount; ++i )
153 {
154 sal_uInt16 nChildItemId = m_pStatusBar->GetItemId( static_cast<sal_uInt16>(i) );
155 if ( nChildItemId == nItemId )
156 {
157 RemoveChild( i );
158 break;
159 }
160 }
161 }
162 }
163 break;
164 case VclEventId::StatusbarAllItemsRemoved:
165 {
166 for ( sal_Int32 i = m_aAccessibleChildren.size() - 1; i >= 0; --i )
167 RemoveChild( i );
168 }
169 break;
170 case VclEventId::StatusbarShowItem:
171 case VclEventId::StatusbarHideItem:
172 {
173 if ( m_pStatusBar )
174 {
175 sal_uInt16 nItemId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
176 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
177 UpdateShowing( nItemPos, rVclWindowEvent.GetId() == VclEventId::StatusbarShowItem );
178 }
179 }
180 break;
181 case VclEventId::StatusbarNameChanged:
182 {
183 if ( m_pStatusBar )
184 {
185 sal_uInt16 nItemId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
186 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
187 UpdateItemName( nItemPos );
188 }
189 }
190 break;
191 case VclEventId::StatusbarDrawItem:
192 {
193 if ( m_pStatusBar )
194 {
195 sal_uInt16 nItemId = static_cast<sal_uInt16>(reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData()));
196 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
197 UpdateItemText( nItemPos );
198 }
199 }
200 break;
201 case VclEventId::ObjectDying:
202 {
203 if ( m_pStatusBar )
204 {
205 m_pStatusBar = nullptr;
206
207 // dispose all children
208 for (const rtl::Reference<VCLXAccessibleStatusBarItem>& xComponent : m_aAccessibleChildren)
209 {
210 if ( xComponent.is() )
211 xComponent->dispose();
212 }
213 m_aAccessibleChildren.clear();
214 }
215
216 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
217 }
218 break;
219 default:
220 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
221 }
222 }
223
224
225 // XComponent
226
227
228 void VCLXAccessibleStatusBar::disposing()
229 {
230 VCLXAccessibleComponent::disposing();
231
232 if ( !m_pStatusBar )
233 return;
234
235 m_pStatusBar = nullptr;
236
237 // dispose all children
238 for (const rtl::Reference<VCLXAccessibleStatusBarItem>& xComponent : m_aAccessibleChildren)
239 {
240 if ( xComponent.is() )
241 xComponent->dispose();
242 }
243 m_aAccessibleChildren.clear();
244 }
245
246
247 // XServiceInfo
248
249
250 OUString VCLXAccessibleStatusBar::getImplementationName()
251 {
252 return u"com.sun.star.comp.toolkit.AccessibleStatusBar"_ustr;
253 }
254
255
256 Sequence< OUString > VCLXAccessibleStatusBar::getSupportedServiceNames()
257 {
258 return { u"com.sun.star.awt.AccessibleStatusBar"_ustr };
259 }
260
261
262 // XAccessibleContext
263
264
265 sal_Int64 VCLXAccessibleStatusBar::getAccessibleChildCount()
266 {
267 OExternalLockGuard aGuard( this );
268
269 return m_aAccessibleChildren.size();
270 }
271
272
273 Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleChild( sal_Int64 i )
274 {
275 OExternalLockGuard aGuard( this );
276
277 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
278 throw IndexOutOfBoundsException();
279
280 rtl::Reference< VCLXAccessibleStatusBarItem > xChild = m_aAccessibleChildren[i];
281 if ( !xChild.is() )
282 {
283 if ( m_pStatusBar )
284 {
285 sal_uInt16 nItemId = m_pStatusBar->GetItemId( static_cast<sal_uInt16>(i) );
286
287 xChild = new VCLXAccessibleStatusBarItem( m_pStatusBar, nItemId );
288
289 // insert into status bar item list
290 m_aAccessibleChildren[i] = xChild;
291 }
292 }
293
294 return xChild;
295 }
296
297
298 // XAccessibleComponent
299
300
301 Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleAtPoint( const awt::Point& rPoint )
302 {
303 OExternalLockGuard aGuard( this );
304
305 Reference< XAccessible > xChild;
306 if ( m_pStatusBar )
307 {
308 sal_uInt16 nItemId = m_pStatusBar->GetItemId(vcl::unohelper::ConvertToVCLPoint(rPoint));
309 sal_Int32 nItemPos = m_pStatusBar->GetItemPos( nItemId );
310 if ( nItemPos >= 0 && o3tl::make_unsigned(nItemPos) < m_aAccessibleChildren.size() )
311 xChild = getAccessibleChild( nItemPos );
312 }
313
314 return xChild;
315 }
316
317
318 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */