1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vclxaccessiblestatusbar.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
33 #include <accessibility/standard/vclxaccessiblestatusbar.hxx>
34 #include <accessibility/standard/vclxaccessiblestatusbaritem.hxx>
35 #include <toolkit/helper/convert.hxx>
36 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
37 #include <vcl/status.hxx>
40 using namespace ::com::sun::star
;
41 using namespace ::com::sun::star::uno
;
42 using namespace ::com::sun::star::lang
;
43 using namespace ::com::sun::star::accessibility
;
44 using namespace ::comphelper
;
47 // ----------------------------------------------------
48 // class VCLXAccessibleStatusBar
49 // ----------------------------------------------------
51 VCLXAccessibleStatusBar::VCLXAccessibleStatusBar( VCLXWindow
* pVCLXWindow
)
52 :VCLXAccessibleComponent( pVCLXWindow
)
54 m_pStatusBar
= static_cast< StatusBar
* >( GetWindow() );
57 m_aAccessibleChildren
.assign( m_pStatusBar
->GetItemCount(), Reference
< XAccessible
>() );
60 // -----------------------------------------------------------------------------
62 VCLXAccessibleStatusBar::~VCLXAccessibleStatusBar()
66 // -----------------------------------------------------------------------------
68 void VCLXAccessibleStatusBar::UpdateShowing( sal_Int32 i
, sal_Bool bShowing
)
70 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
72 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
75 VCLXAccessibleStatusBarItem
* pVCLXAccessibleStatusBarItem
= static_cast< VCLXAccessibleStatusBarItem
* >( xChild
.get() );
76 if ( pVCLXAccessibleStatusBarItem
)
77 pVCLXAccessibleStatusBarItem
->SetShowing( bShowing
);
82 // -----------------------------------------------------------------------------
84 void VCLXAccessibleStatusBar::UpdateItemName( sal_Int32 i
)
86 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
88 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
91 VCLXAccessibleStatusBarItem
* pVCLXAccessibleStatusBarItem
= static_cast< VCLXAccessibleStatusBarItem
* >( xChild
.get() );
92 if ( pVCLXAccessibleStatusBarItem
)
94 ::rtl::OUString sItemName
= pVCLXAccessibleStatusBarItem
->GetItemName();
95 pVCLXAccessibleStatusBarItem
->SetItemName( sItemName
);
101 // -----------------------------------------------------------------------------
103 void VCLXAccessibleStatusBar::UpdateItemText( sal_Int32 i
)
105 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
107 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
110 VCLXAccessibleStatusBarItem
* pVCLXAccessibleStatusBarItem
= static_cast< VCLXAccessibleStatusBarItem
* >( xChild
.get() );
111 if ( pVCLXAccessibleStatusBarItem
)
113 ::rtl::OUString sItemText
= pVCLXAccessibleStatusBarItem
->GetItemText();
114 pVCLXAccessibleStatusBarItem
->SetItemText( sItemText
);
120 // -----------------------------------------------------------------------------
122 void VCLXAccessibleStatusBar::InsertChild( sal_Int32 i
)
124 if ( i
>= 0 && i
<= (sal_Int32
)m_aAccessibleChildren
.size() )
126 // insert entry in child list
127 m_aAccessibleChildren
.insert( m_aAccessibleChildren
.begin() + i
, Reference
< XAccessible
>() );
129 // send accessible child event
130 Reference
< XAccessible
> xChild( getAccessibleChild( i
) );
133 Any aOldValue
, aNewValue
;
134 aNewValue
<<= xChild
;
135 NotifyAccessibleEvent( AccessibleEventId::CHILD
, aOldValue
, aNewValue
);
140 // -----------------------------------------------------------------------------
142 void VCLXAccessibleStatusBar::RemoveChild( sal_Int32 i
)
144 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
146 // get the accessible of the removed page
147 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
149 // remove entry in child list
150 m_aAccessibleChildren
.erase( m_aAccessibleChildren
.begin() + i
);
152 // send accessible child event
155 Any aOldValue
, aNewValue
;
156 aOldValue
<<= xChild
;
157 NotifyAccessibleEvent( AccessibleEventId::CHILD
, aOldValue
, aNewValue
);
159 Reference
< XComponent
> xComponent( xChild
, UNO_QUERY
);
160 if ( xComponent
.is() )
161 xComponent
->dispose();
166 // -----------------------------------------------------------------------------
168 void VCLXAccessibleStatusBar::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
170 switch ( rVclWindowEvent
.GetId() )
172 case VCLEVENT_STATUSBAR_ITEMADDED
:
176 sal_uInt16 nItemId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
177 sal_uInt16 nItemPos
= m_pStatusBar
->GetItemPos( nItemId
);
178 InsertChild( nItemPos
);
182 case VCLEVENT_STATUSBAR_ITEMREMOVED
:
186 sal_uInt16 nItemId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
187 for ( sal_Int32 i
= 0, nCount
= getAccessibleChildCount(); i
< nCount
; ++i
)
189 Reference
< XAccessible
> xChild( getAccessibleChild( i
) );
192 VCLXAccessibleStatusBarItem
* pVCLXAccessibleStatusBarItem
= static_cast< VCLXAccessibleStatusBarItem
* >( xChild
.get() );
193 if ( pVCLXAccessibleStatusBarItem
&& pVCLXAccessibleStatusBarItem
->GetItemId() == nItemId
)
203 case VCLEVENT_STATUSBAR_ALLITEMSREMOVED
:
205 for ( sal_Int32 i
= m_aAccessibleChildren
.size() - 1; i
>= 0; --i
)
209 case VCLEVENT_STATUSBAR_SHOWITEM
:
210 case VCLEVENT_STATUSBAR_HIDEITEM
:
214 sal_uInt16 nItemId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
215 sal_uInt16 nItemPos
= m_pStatusBar
->GetItemPos( nItemId
);
216 UpdateShowing( nItemPos
, rVclWindowEvent
.GetId() == VCLEVENT_STATUSBAR_SHOWITEM
);
220 case VCLEVENT_STATUSBAR_SHOWALLITEMS
:
221 case VCLEVENT_STATUSBAR_HIDEALLITEMS
:
223 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
224 UpdateShowing( i
, rVclWindowEvent
.GetId() == VCLEVENT_STATUSBAR_SHOWALLITEMS
);
227 case VCLEVENT_STATUSBAR_NAMECHANGED
:
231 sal_uInt16 nItemId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
232 sal_uInt16 nItemPos
= m_pStatusBar
->GetItemPos( nItemId
);
233 UpdateItemName( nItemPos
);
237 case VCLEVENT_STATUSBAR_DRAWITEM
:
241 sal_uInt16 nItemId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
242 sal_uInt16 nItemPos
= m_pStatusBar
->GetItemPos( nItemId
);
243 UpdateItemText( nItemPos
);
247 case VCLEVENT_OBJECT_DYING
:
253 // dispose all children
254 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
256 Reference
< XComponent
> xComponent( m_aAccessibleChildren
[i
], UNO_QUERY
);
257 if ( xComponent
.is() )
258 xComponent
->dispose();
260 m_aAccessibleChildren
.clear();
263 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent
);
267 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent
);
271 // -----------------------------------------------------------------------------
273 // -----------------------------------------------------------------------------
275 void VCLXAccessibleStatusBar::disposing()
277 VCLXAccessibleComponent::disposing();
283 // dispose all children
284 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
286 Reference
< XComponent
> xComponent( m_aAccessibleChildren
[i
], UNO_QUERY
);
287 if ( xComponent
.is() )
288 xComponent
->dispose();
290 m_aAccessibleChildren
.clear();
294 // -----------------------------------------------------------------------------
296 // -----------------------------------------------------------------------------
298 ::rtl::OUString
VCLXAccessibleStatusBar::getImplementationName() throw (RuntimeException
)
300 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleStatusBar" );
303 // -----------------------------------------------------------------------------
305 Sequence
< ::rtl::OUString
> VCLXAccessibleStatusBar::getSupportedServiceNames() throw (RuntimeException
)
307 Sequence
< ::rtl::OUString
> aNames(1);
308 aNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleStatusBar" );
312 // -----------------------------------------------------------------------------
313 // XAccessibleContext
314 // -----------------------------------------------------------------------------
316 sal_Int32
VCLXAccessibleStatusBar::getAccessibleChildCount() throw (RuntimeException
)
318 OExternalLockGuard
aGuard( this );
320 return m_aAccessibleChildren
.size();
323 // -----------------------------------------------------------------------------
325 Reference
< XAccessible
> VCLXAccessibleStatusBar::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
327 OExternalLockGuard
aGuard( this );
329 if ( i
< 0 || i
>= getAccessibleChildCount() )
330 throw IndexOutOfBoundsException();
332 Reference
< XAccessible
> xChild
= m_aAccessibleChildren
[i
];
337 sal_uInt16 nItemId
= m_pStatusBar
->GetItemId( (USHORT
)i
);
339 xChild
= new VCLXAccessibleStatusBarItem( m_pStatusBar
, nItemId
);
341 // insert into status bar item list
342 m_aAccessibleChildren
[i
] = xChild
;
349 // -----------------------------------------------------------------------------
350 // XAccessibleComponent
351 // -----------------------------------------------------------------------------
353 Reference
< XAccessible
> VCLXAccessibleStatusBar::getAccessibleAtPoint( const awt::Point
& rPoint
) throw (RuntimeException
)
355 OExternalLockGuard
aGuard( this );
357 Reference
< XAccessible
> xChild
;
360 sal_uInt16 nItemId
= m_pStatusBar
->GetItemId( VCLPoint( rPoint
) );
361 sal_Int32 nItemPos
= m_pStatusBar
->GetItemPos( nItemId
);
362 if ( nItemPos
>= 0 && nItemPos
< (sal_Int32
)m_aAccessibleChildren
.size() )
363 xChild
= getAccessibleChild( nItemPos
);
369 // -----------------------------------------------------------------------------