Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / standard / vclxaccessiblestatusbar.cxx
blob42d1db5eb38eace7267ab8f0654cd903b9c1637a
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 <accessibility/standard/vclxaccessiblestatusbar.hxx>
21 #include <accessibility/standard/vclxaccessiblestatusbaritem.hxx>
22 #include <toolkit/helper/convert.hxx>
23 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
24 #include <vcl/status.hxx>
27 using namespace ::com::sun::star;
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::lang;
30 using namespace ::com::sun::star::accessibility;
31 using namespace ::comphelper;
35 // class VCLXAccessibleStatusBar
38 VCLXAccessibleStatusBar::VCLXAccessibleStatusBar( VCLXWindow* pVCLXWindow )
39 :VCLXAccessibleComponent( pVCLXWindow )
41 m_pStatusBar = static_cast< StatusBar *>( GetWindow().get() );
43 if ( m_pStatusBar )
44 m_aAccessibleChildren.assign( m_pStatusBar->GetItemCount(), Reference< XAccessible >() );
49 VCLXAccessibleStatusBar::~VCLXAccessibleStatusBar()
55 void VCLXAccessibleStatusBar::UpdateShowing( sal_Int32 i, bool bShowing )
57 if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
59 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
60 if ( xChild.is() )
62 VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
63 if ( pVCLXAccessibleStatusBarItem )
64 pVCLXAccessibleStatusBarItem->SetShowing( bShowing );
71 void VCLXAccessibleStatusBar::UpdateItemName( sal_Int32 i )
73 if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
75 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
76 if ( xChild.is() )
78 VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
79 if ( pVCLXAccessibleStatusBarItem )
81 OUString sItemName = pVCLXAccessibleStatusBarItem->GetItemName();
82 pVCLXAccessibleStatusBarItem->SetItemName( sItemName );
90 void VCLXAccessibleStatusBar::UpdateItemText( sal_Int32 i )
92 if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
94 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
95 if ( xChild.is() )
97 VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
98 if ( pVCLXAccessibleStatusBarItem )
100 OUString sItemText = pVCLXAccessibleStatusBarItem->GetItemText();
101 pVCLXAccessibleStatusBarItem->SetItemText( sItemText );
109 void VCLXAccessibleStatusBar::InsertChild( sal_Int32 i )
111 if ( i >= 0 && i <= (sal_Int32)m_aAccessibleChildren.size() )
113 // insert entry in child list
114 m_aAccessibleChildren.insert( m_aAccessibleChildren.begin() + i, Reference< XAccessible >() );
116 // send accessible child event
117 Reference< XAccessible > xChild( getAccessibleChild( i ) );
118 if ( xChild.is() )
120 Any aOldValue, aNewValue;
121 aNewValue <<= xChild;
122 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
129 void VCLXAccessibleStatusBar::RemoveChild( sal_Int32 i )
131 if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
133 // get the accessible of the removed page
134 Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
136 // remove entry in child list
137 m_aAccessibleChildren.erase( m_aAccessibleChildren.begin() + i );
139 // send accessible child event
140 if ( xChild.is() )
142 Any aOldValue, aNewValue;
143 aOldValue <<= xChild;
144 NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
146 Reference< XComponent > xComponent( xChild, UNO_QUERY );
147 if ( xComponent.is() )
148 xComponent->dispose();
155 void VCLXAccessibleStatusBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
157 switch ( rVclWindowEvent.GetId() )
159 case VCLEVENT_STATUSBAR_ITEMADDED:
161 if ( m_pStatusBar )
163 sal_uInt16 nItemId = (sal_uInt16)reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData());
164 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
165 InsertChild( nItemPos );
168 break;
169 case VCLEVENT_STATUSBAR_ITEMREMOVED:
171 if ( m_pStatusBar )
173 sal_uInt16 nItemId = (sal_uInt16)reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData());
174 for ( sal_Int32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
176 Reference< XAccessible > xChild( getAccessibleChild( i ) );
177 if ( xChild.is() )
179 VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
180 if ( pVCLXAccessibleStatusBarItem && pVCLXAccessibleStatusBarItem->GetItemId() == nItemId )
182 RemoveChild( i );
183 break;
189 break;
190 case VCLEVENT_STATUSBAR_ALLITEMSREMOVED:
192 for ( sal_Int32 i = m_aAccessibleChildren.size() - 1; i >= 0; --i )
193 RemoveChild( i );
195 break;
196 case VCLEVENT_STATUSBAR_SHOWITEM:
197 case VCLEVENT_STATUSBAR_HIDEITEM:
199 if ( m_pStatusBar )
201 sal_uInt16 nItemId = (sal_uInt16)reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData());
202 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
203 UpdateShowing( nItemPos, rVclWindowEvent.GetId() == VCLEVENT_STATUSBAR_SHOWITEM );
206 break;
207 case VCLEVENT_STATUSBAR_SHOWALLITEMS:
208 case VCLEVENT_STATUSBAR_HIDEALLITEMS:
210 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
211 UpdateShowing( i, rVclWindowEvent.GetId() == VCLEVENT_STATUSBAR_SHOWALLITEMS );
213 break;
214 case VCLEVENT_STATUSBAR_NAMECHANGED:
216 if ( m_pStatusBar )
218 sal_uInt16 nItemId = (sal_uInt16)reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData());
219 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
220 UpdateItemName( nItemPos );
223 break;
224 case VCLEVENT_STATUSBAR_DRAWITEM:
226 if ( m_pStatusBar )
228 sal_uInt16 nItemId = (sal_uInt16)reinterpret_cast<sal_IntPtr>(rVclWindowEvent.GetData());
229 sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
230 UpdateItemText( nItemPos );
233 break;
234 case VCLEVENT_OBJECT_DYING:
236 if ( m_pStatusBar )
238 m_pStatusBar = NULL;
240 // dispose all children
241 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
243 Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY );
244 if ( xComponent.is() )
245 xComponent->dispose();
247 m_aAccessibleChildren.clear();
250 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
252 break;
253 default:
254 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
259 // XComponent
262 void VCLXAccessibleStatusBar::disposing()
264 VCLXAccessibleComponent::disposing();
266 if ( m_pStatusBar )
268 m_pStatusBar = NULL;
270 // dispose all children
271 for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
273 Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY );
274 if ( xComponent.is() )
275 xComponent->dispose();
277 m_aAccessibleChildren.clear();
282 // XServiceInfo
285 OUString VCLXAccessibleStatusBar::getImplementationName() throw (RuntimeException, std::exception)
287 return OUString( "com.sun.star.comp.toolkit.AccessibleStatusBar" );
292 Sequence< OUString > VCLXAccessibleStatusBar::getSupportedServiceNames() throw (RuntimeException, std::exception)
294 Sequence< OUString > aNames(1);
295 aNames[0] = "com.sun.star.awt.AccessibleStatusBar";
296 return aNames;
300 // XAccessibleContext
303 sal_Int32 VCLXAccessibleStatusBar::getAccessibleChildCount() throw (RuntimeException, std::exception)
305 OExternalLockGuard aGuard( this );
307 return m_aAccessibleChildren.size();
312 Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException, std::exception)
314 OExternalLockGuard aGuard( this );
316 if ( i < 0 || i >= getAccessibleChildCount() )
317 throw IndexOutOfBoundsException();
319 Reference< XAccessible > xChild = m_aAccessibleChildren[i];
320 if ( !xChild.is() )
322 if ( m_pStatusBar )
324 sal_uInt16 nItemId = m_pStatusBar->GetItemId( (sal_uInt16)i );
326 xChild = new VCLXAccessibleStatusBarItem( m_pStatusBar, nItemId );
328 // insert into status bar item list
329 m_aAccessibleChildren[i] = xChild;
333 return xChild;
337 // XAccessibleComponent
340 Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException, std::exception)
342 OExternalLockGuard aGuard( this );
344 Reference< XAccessible > xChild;
345 if ( m_pStatusBar )
347 sal_uInt16 nItemId = m_pStatusBar->GetItemId( VCLPoint( rPoint ) );
348 sal_Int32 nItemPos = m_pStatusBar->GetItemPos( nItemId );
349 if ( nItemPos >= 0 && nItemPos < (sal_Int32)m_aAccessibleChildren.size() )
350 xChild = getAccessibleChild( nItemPos );
353 return xChild;
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */