bump product version to 7.6.3.2-android
[LibreOffice.git] / accessibility / source / standard / vclxaccessiblestatusbar.cxx
blob52d32eb7cc55ad8f09f3a46b32e7fc4edc78aa45
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <standard/vclxaccessiblestatusbar.hxx>
21 #include <standard/vclxaccessiblestatusbaritem.hxx>
22 #include <toolkit/helper/convert.hxx>
23 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
24 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
25 #include <comphelper/accessiblecontexthelper.hxx>
26 #include <o3tl/safeint.hxx>
27 #include <vcl/status.hxx>
28 #include <vcl/vclevent.hxx>
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;
40 VCLXAccessibleStatusBar::VCLXAccessibleStatusBar( VCLXWindow* pVCLXWindow )
41 :VCLXAccessibleComponent( pVCLXWindow )
43 m_pStatusBar = GetAs<StatusBar>();
45 if ( m_pStatusBar )
46 m_aAccessibleChildren.assign( m_pStatusBar->GetItemCount(), Reference< XAccessible >() );
50 void VCLXAccessibleStatusBar::UpdateShowing( sal_Int32 i, bool bShowing )
52 if ( i >= 0 && o3tl::make_unsigned(i) < m_aAccessibleChildren.size() )
54 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
55 if ( xChild.is() )
57 VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
58 if ( pVCLXAccessibleStatusBarItem )
59 pVCLXAccessibleStatusBarItem->SetShowing( bShowing );
65 void VCLXAccessibleStatusBar::UpdateItemName( sal_Int32 i )
67 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
68 return;
70 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
71 if ( xChild.is() )
73 VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
74 if ( pVCLXAccessibleStatusBarItem )
76 OUString sItemName = pVCLXAccessibleStatusBarItem->GetItemName();
77 pVCLXAccessibleStatusBarItem->SetItemName( sItemName );
83 void VCLXAccessibleStatusBar::UpdateItemText( sal_Int32 i )
85 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
86 return;
88 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
89 if ( xChild.is() )
91 VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
92 if ( pVCLXAccessibleStatusBarItem )
94 OUString sItemText = pVCLXAccessibleStatusBarItem->GetItemText();
95 pVCLXAccessibleStatusBarItem->SetItemText( sItemText );
101 void VCLXAccessibleStatusBar::InsertChild( sal_Int32 i )
103 if ( i < 0 || o3tl::make_unsigned(i) > m_aAccessibleChildren.size() )
104 return;
106 // insert entry in child list
107 m_aAccessibleChildren.insert( m_aAccessibleChildren.begin() + i, Reference< XAccessible >() );
109 // send accessible child event
110 Reference< XAccessible > xChild( getAccessibleChild( i ) );
111 if ( xChild.is() )
113 Any aOldValue, aNewValue;
114 aNewValue <<= xChild;
115 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
120 void VCLXAccessibleStatusBar::RemoveChild( sal_Int32 i )
122 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
123 return;
125 // get the accessible of the removed page
126 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
128 // remove entry in child list
129 m_aAccessibleChildren.erase( m_aAccessibleChildren.begin() + i );
131 // send accessible child event
132 if ( xChild.is() )
134 Any aOldValue, aNewValue;
135 aOldValue <<= xChild;
136 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
138 Reference< XComponent > xComponent( xChild, UNO_QUERY );
139 if ( xComponent.is() )
140 xComponent->dispose();
145 void VCLXAccessibleStatusBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
147 switch ( rVclWindowEvent.GetId() )
149 case VclEventId::StatusbarItemAdded:
151 if ( m_pStatusBar )
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 );
158 break;
159 case VclEventId::StatusbarItemRemoved:
161 if ( m_pStatusBar )
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 )
166 Reference< XAccessible > xChild( getAccessibleChild( i ) );
167 if ( xChild.is() )
169 VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
170 if ( pVCLXAccessibleStatusBarItem && pVCLXAccessibleStatusBarItem->GetItemId() == nItemId )
172 RemoveChild( i );
173 break;
179 break;
180 case VclEventId::StatusbarAllItemsRemoved:
182 for ( sal_Int32 i = m_aAccessibleChildren.size() - 1; i >= 0; --i )
183 RemoveChild( i );
185 break;
186 case VclEventId::StatusbarShowItem:
187 case VclEventId::StatusbarHideItem:
189 if ( m_pStatusBar )
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 );
196 break;
197 case VclEventId::StatusbarNameChanged:
199 if ( m_pStatusBar )
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 );
206 break;
207 case VclEventId::StatusbarDrawItem:
209 if ( m_pStatusBar )
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 );
216 break;
217 case VclEventId::ObjectDying:
219 if ( m_pStatusBar )
221 m_pStatusBar = nullptr;
223 // dispose all children
224 for (const Reference<XAccessible>& i : m_aAccessibleChildren)
226 Reference< XComponent > xComponent( i, UNO_QUERY );
227 if ( xComponent.is() )
228 xComponent->dispose();
230 m_aAccessibleChildren.clear();
233 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
235 break;
236 default:
237 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
242 // XComponent
245 void VCLXAccessibleStatusBar::disposing()
247 VCLXAccessibleComponent::disposing();
249 if ( !m_pStatusBar )
250 return;
252 m_pStatusBar = nullptr;
254 // dispose all children
255 for (const Reference<XAccessible>& i : m_aAccessibleChildren)
257 Reference< XComponent > xComponent( i, UNO_QUERY );
258 if ( xComponent.is() )
259 xComponent->dispose();
261 m_aAccessibleChildren.clear();
265 // XServiceInfo
268 OUString VCLXAccessibleStatusBar::getImplementationName()
270 return "com.sun.star.comp.toolkit.AccessibleStatusBar";
274 Sequence< OUString > VCLXAccessibleStatusBar::getSupportedServiceNames()
276 return { "com.sun.star.awt.AccessibleStatusBar" };
280 // XAccessibleContext
283 sal_Int64 VCLXAccessibleStatusBar::getAccessibleChildCount()
285 OExternalLockGuard aGuard( this );
287 return m_aAccessibleChildren.size();
291 Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleChild( sal_Int64 i )
293 OExternalLockGuard aGuard( this );
295 if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
296 throw IndexOutOfBoundsException();
298 Reference< XAccessible > xChild = m_aAccessibleChildren[i];
299 if ( !xChild.is() )
301 if ( m_pStatusBar )
303 sal_uInt16 nItemId = m_pStatusBar->GetItemId( static_cast<sal_uInt16>(i) );
305 xChild = new VCLXAccessibleStatusBarItem( m_pStatusBar, nItemId );
307 // insert into status bar item list
308 m_aAccessibleChildren[i] = xChild;
312 return xChild;
316 // XAccessibleComponent
319 Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleAtPoint( const awt::Point& rPoint )
321 OExternalLockGuard aGuard( this );
323 Reference< XAccessible > xChild;
324 if ( m_pStatusBar )
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 );
332 return xChild;
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */