1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_accessibility.hxx"
30 #include <accessibility/standard/vclxaccessiblestatusbar.hxx>
31 #include <accessibility/standard/vclxaccessiblestatusbaritem.hxx>
32 #include <toolkit/helper/convert.hxx>
33 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
34 #include <vcl/status.hxx>
37 using namespace ::com::sun::star
;
38 using namespace ::com::sun::star::uno
;
39 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::accessibility
;
41 using namespace ::comphelper
;
44 // ----------------------------------------------------
45 // class VCLXAccessibleStatusBar
46 // ----------------------------------------------------
48 VCLXAccessibleStatusBar::VCLXAccessibleStatusBar( VCLXWindow
* pVCLXWindow
)
49 :VCLXAccessibleComponent( pVCLXWindow
)
51 m_pStatusBar
= static_cast< StatusBar
* >( GetWindow() );
54 m_aAccessibleChildren
.assign( m_pStatusBar
->GetItemCount(), Reference
< XAccessible
>() );
57 // -----------------------------------------------------------------------------
59 VCLXAccessibleStatusBar::~VCLXAccessibleStatusBar()
63 // -----------------------------------------------------------------------------
65 void VCLXAccessibleStatusBar::UpdateShowing( sal_Int32 i
, sal_Bool bShowing
)
67 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
69 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
72 VCLXAccessibleStatusBarItem
* pVCLXAccessibleStatusBarItem
= static_cast< VCLXAccessibleStatusBarItem
* >( xChild
.get() );
73 if ( pVCLXAccessibleStatusBarItem
)
74 pVCLXAccessibleStatusBarItem
->SetShowing( bShowing
);
79 // -----------------------------------------------------------------------------
81 void VCLXAccessibleStatusBar::UpdateItemName( sal_Int32 i
)
83 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
85 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
88 VCLXAccessibleStatusBarItem
* pVCLXAccessibleStatusBarItem
= static_cast< VCLXAccessibleStatusBarItem
* >( xChild
.get() );
89 if ( pVCLXAccessibleStatusBarItem
)
91 ::rtl::OUString sItemName
= pVCLXAccessibleStatusBarItem
->GetItemName();
92 pVCLXAccessibleStatusBarItem
->SetItemName( sItemName
);
98 // -----------------------------------------------------------------------------
100 void VCLXAccessibleStatusBar::UpdateItemText( sal_Int32 i
)
102 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
104 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
107 VCLXAccessibleStatusBarItem
* pVCLXAccessibleStatusBarItem
= static_cast< VCLXAccessibleStatusBarItem
* >( xChild
.get() );
108 if ( pVCLXAccessibleStatusBarItem
)
110 ::rtl::OUString sItemText
= pVCLXAccessibleStatusBarItem
->GetItemText();
111 pVCLXAccessibleStatusBarItem
->SetItemText( sItemText
);
117 // -----------------------------------------------------------------------------
119 void VCLXAccessibleStatusBar::InsertChild( sal_Int32 i
)
121 if ( i
>= 0 && i
<= (sal_Int32
)m_aAccessibleChildren
.size() )
123 // insert entry in child list
124 m_aAccessibleChildren
.insert( m_aAccessibleChildren
.begin() + i
, Reference
< XAccessible
>() );
126 // send accessible child event
127 Reference
< XAccessible
> xChild( getAccessibleChild( i
) );
130 Any aOldValue
, aNewValue
;
131 aNewValue
<<= xChild
;
132 NotifyAccessibleEvent( AccessibleEventId::CHILD
, aOldValue
, aNewValue
);
137 // -----------------------------------------------------------------------------
139 void VCLXAccessibleStatusBar::RemoveChild( sal_Int32 i
)
141 if ( i
>= 0 && i
< (sal_Int32
)m_aAccessibleChildren
.size() )
143 // get the accessible of the removed page
144 Reference
< XAccessible
> xChild( m_aAccessibleChildren
[i
] );
146 // remove entry in child list
147 m_aAccessibleChildren
.erase( m_aAccessibleChildren
.begin() + i
);
149 // send accessible child event
152 Any aOldValue
, aNewValue
;
153 aOldValue
<<= xChild
;
154 NotifyAccessibleEvent( AccessibleEventId::CHILD
, aOldValue
, aNewValue
);
156 Reference
< XComponent
> xComponent( xChild
, UNO_QUERY
);
157 if ( xComponent
.is() )
158 xComponent
->dispose();
163 // -----------------------------------------------------------------------------
165 void VCLXAccessibleStatusBar::ProcessWindowEvent( const VclWindowEvent
& rVclWindowEvent
)
167 switch ( rVclWindowEvent
.GetId() )
169 case VCLEVENT_STATUSBAR_ITEMADDED
:
173 sal_uInt16 nItemId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
174 sal_uInt16 nItemPos
= m_pStatusBar
->GetItemPos( nItemId
);
175 InsertChild( nItemPos
);
179 case VCLEVENT_STATUSBAR_ITEMREMOVED
:
183 sal_uInt16 nItemId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
184 for ( sal_Int32 i
= 0, nCount
= getAccessibleChildCount(); i
< nCount
; ++i
)
186 Reference
< XAccessible
> xChild( getAccessibleChild( i
) );
189 VCLXAccessibleStatusBarItem
* pVCLXAccessibleStatusBarItem
= static_cast< VCLXAccessibleStatusBarItem
* >( xChild
.get() );
190 if ( pVCLXAccessibleStatusBarItem
&& pVCLXAccessibleStatusBarItem
->GetItemId() == nItemId
)
200 case VCLEVENT_STATUSBAR_ALLITEMSREMOVED
:
202 for ( sal_Int32 i
= m_aAccessibleChildren
.size() - 1; i
>= 0; --i
)
206 case VCLEVENT_STATUSBAR_SHOWITEM
:
207 case VCLEVENT_STATUSBAR_HIDEITEM
:
211 sal_uInt16 nItemId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
212 sal_uInt16 nItemPos
= m_pStatusBar
->GetItemPos( nItemId
);
213 UpdateShowing( nItemPos
, rVclWindowEvent
.GetId() == VCLEVENT_STATUSBAR_SHOWITEM
);
217 case VCLEVENT_STATUSBAR_SHOWALLITEMS
:
218 case VCLEVENT_STATUSBAR_HIDEALLITEMS
:
220 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
221 UpdateShowing( i
, rVclWindowEvent
.GetId() == VCLEVENT_STATUSBAR_SHOWALLITEMS
);
224 case VCLEVENT_STATUSBAR_NAMECHANGED
:
228 sal_uInt16 nItemId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
229 sal_uInt16 nItemPos
= m_pStatusBar
->GetItemPos( nItemId
);
230 UpdateItemName( nItemPos
);
234 case VCLEVENT_STATUSBAR_DRAWITEM
:
238 sal_uInt16 nItemId
= (sal_uInt16
)(sal_IntPtr
) rVclWindowEvent
.GetData();
239 sal_uInt16 nItemPos
= m_pStatusBar
->GetItemPos( nItemId
);
240 UpdateItemText( nItemPos
);
244 case VCLEVENT_OBJECT_DYING
:
250 // dispose all children
251 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
253 Reference
< XComponent
> xComponent( m_aAccessibleChildren
[i
], UNO_QUERY
);
254 if ( xComponent
.is() )
255 xComponent
->dispose();
257 m_aAccessibleChildren
.clear();
260 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent
);
264 VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent
);
268 // -----------------------------------------------------------------------------
270 // -----------------------------------------------------------------------------
272 void VCLXAccessibleStatusBar::disposing()
274 VCLXAccessibleComponent::disposing();
280 // dispose all children
281 for ( sal_uInt32 i
= 0; i
< m_aAccessibleChildren
.size(); ++i
)
283 Reference
< XComponent
> xComponent( m_aAccessibleChildren
[i
], UNO_QUERY
);
284 if ( xComponent
.is() )
285 xComponent
->dispose();
287 m_aAccessibleChildren
.clear();
291 // -----------------------------------------------------------------------------
293 // -----------------------------------------------------------------------------
295 ::rtl::OUString
VCLXAccessibleStatusBar::getImplementationName() throw (RuntimeException
)
297 return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleStatusBar" );
300 // -----------------------------------------------------------------------------
302 Sequence
< ::rtl::OUString
> VCLXAccessibleStatusBar::getSupportedServiceNames() throw (RuntimeException
)
304 Sequence
< ::rtl::OUString
> aNames(1);
305 aNames
[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleStatusBar" );
309 // -----------------------------------------------------------------------------
310 // XAccessibleContext
311 // -----------------------------------------------------------------------------
313 sal_Int32
VCLXAccessibleStatusBar::getAccessibleChildCount() throw (RuntimeException
)
315 OExternalLockGuard
aGuard( this );
317 return m_aAccessibleChildren
.size();
320 // -----------------------------------------------------------------------------
322 Reference
< XAccessible
> VCLXAccessibleStatusBar::getAccessibleChild( sal_Int32 i
) throw (IndexOutOfBoundsException
, RuntimeException
)
324 OExternalLockGuard
aGuard( this );
326 if ( i
< 0 || i
>= getAccessibleChildCount() )
327 throw IndexOutOfBoundsException();
329 Reference
< XAccessible
> xChild
= m_aAccessibleChildren
[i
];
334 sal_uInt16 nItemId
= m_pStatusBar
->GetItemId( (sal_uInt16
)i
);
336 xChild
= new VCLXAccessibleStatusBarItem( m_pStatusBar
, nItemId
);
338 // insert into status bar item list
339 m_aAccessibleChildren
[i
] = xChild
;
346 // -----------------------------------------------------------------------------
347 // XAccessibleComponent
348 // -----------------------------------------------------------------------------
350 Reference
< XAccessible
> VCLXAccessibleStatusBar::getAccessibleAtPoint( const awt::Point
& rPoint
) throw (RuntimeException
)
352 OExternalLockGuard
aGuard( this );
354 Reference
< XAccessible
> xChild
;
357 sal_uInt16 nItemId
= m_pStatusBar
->GetItemId( VCLPoint( rPoint
) );
358 sal_Int32 nItemPos
= m_pStatusBar
->GetItemPos( nItemId
);
359 if ( nItemPos
>= 0 && nItemPos
< (sal_Int32
)m_aAccessibleChildren
.size() )
360 xChild
= getAccessibleChild( nItemPos
);
366 // -----------------------------------------------------------------------------