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