1*c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*c82f2877SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*c82f2877SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*c82f2877SAndrew Rist * distributed with this work for additional information
6*c82f2877SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*c82f2877SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*c82f2877SAndrew Rist * "License"); you may not use this file except in compliance
9*c82f2877SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*c82f2877SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*c82f2877SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*c82f2877SAndrew Rist * software distributed under the License is distributed on an
15*c82f2877SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c82f2877SAndrew Rist * KIND, either express or implied. See the License for the
17*c82f2877SAndrew Rist * specific language governing permissions and limitations
18*c82f2877SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*c82f2877SAndrew Rist *************************************************************/
21*c82f2877SAndrew Rist
22*c82f2877SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_accessibility.hxx"
26cdf0e10cSrcweir #include <accessibility/standard/vclxaccessiblestatusbar.hxx>
27cdf0e10cSrcweir #include <accessibility/standard/vclxaccessiblestatusbaritem.hxx>
28cdf0e10cSrcweir #include <toolkit/helper/convert.hxx>
29cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
30cdf0e10cSrcweir #include <vcl/status.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir
33cdf0e10cSrcweir using namespace ::com::sun::star;
34cdf0e10cSrcweir using namespace ::com::sun::star::uno;
35cdf0e10cSrcweir using namespace ::com::sun::star::lang;
36cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
37cdf0e10cSrcweir using namespace ::comphelper;
38cdf0e10cSrcweir
39cdf0e10cSrcweir
40cdf0e10cSrcweir // ----------------------------------------------------
41cdf0e10cSrcweir // class VCLXAccessibleStatusBar
42cdf0e10cSrcweir // ----------------------------------------------------
43cdf0e10cSrcweir
VCLXAccessibleStatusBar(VCLXWindow * pVCLXWindow)44cdf0e10cSrcweir VCLXAccessibleStatusBar::VCLXAccessibleStatusBar( VCLXWindow* pVCLXWindow )
45cdf0e10cSrcweir :VCLXAccessibleComponent( pVCLXWindow )
46cdf0e10cSrcweir {
47cdf0e10cSrcweir m_pStatusBar = static_cast< StatusBar* >( GetWindow() );
48cdf0e10cSrcweir
49cdf0e10cSrcweir if ( m_pStatusBar )
50cdf0e10cSrcweir m_aAccessibleChildren.assign( m_pStatusBar->GetItemCount(), Reference< XAccessible >() );
51cdf0e10cSrcweir }
52cdf0e10cSrcweir
53cdf0e10cSrcweir // -----------------------------------------------------------------------------
54cdf0e10cSrcweir
~VCLXAccessibleStatusBar()55cdf0e10cSrcweir VCLXAccessibleStatusBar::~VCLXAccessibleStatusBar()
56cdf0e10cSrcweir {
57cdf0e10cSrcweir }
58cdf0e10cSrcweir
59cdf0e10cSrcweir // -----------------------------------------------------------------------------
60cdf0e10cSrcweir
UpdateShowing(sal_Int32 i,sal_Bool bShowing)61cdf0e10cSrcweir void VCLXAccessibleStatusBar::UpdateShowing( sal_Int32 i, sal_Bool bShowing )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
64cdf0e10cSrcweir {
65cdf0e10cSrcweir Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
66cdf0e10cSrcweir if ( xChild.is() )
67cdf0e10cSrcweir {
68cdf0e10cSrcweir VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
69cdf0e10cSrcweir if ( pVCLXAccessibleStatusBarItem )
70cdf0e10cSrcweir pVCLXAccessibleStatusBarItem->SetShowing( bShowing );
71cdf0e10cSrcweir }
72cdf0e10cSrcweir }
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
75cdf0e10cSrcweir // -----------------------------------------------------------------------------
76cdf0e10cSrcweir
UpdateItemName(sal_Int32 i)77cdf0e10cSrcweir void VCLXAccessibleStatusBar::UpdateItemName( sal_Int32 i )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
80cdf0e10cSrcweir {
81cdf0e10cSrcweir Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
82cdf0e10cSrcweir if ( xChild.is() )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
85cdf0e10cSrcweir if ( pVCLXAccessibleStatusBarItem )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir ::rtl::OUString sItemName = pVCLXAccessibleStatusBarItem->GetItemName();
88cdf0e10cSrcweir pVCLXAccessibleStatusBarItem->SetItemName( sItemName );
89cdf0e10cSrcweir }
90cdf0e10cSrcweir }
91cdf0e10cSrcweir }
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir // -----------------------------------------------------------------------------
95cdf0e10cSrcweir
UpdateItemText(sal_Int32 i)96cdf0e10cSrcweir void VCLXAccessibleStatusBar::UpdateItemText( sal_Int32 i )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
99cdf0e10cSrcweir {
100cdf0e10cSrcweir Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
101cdf0e10cSrcweir if ( xChild.is() )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
104cdf0e10cSrcweir if ( pVCLXAccessibleStatusBarItem )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir ::rtl::OUString sItemText = pVCLXAccessibleStatusBarItem->GetItemText();
107cdf0e10cSrcweir pVCLXAccessibleStatusBarItem->SetItemText( sItemText );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir }
110cdf0e10cSrcweir }
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir // -----------------------------------------------------------------------------
114cdf0e10cSrcweir
InsertChild(sal_Int32 i)115cdf0e10cSrcweir void VCLXAccessibleStatusBar::InsertChild( sal_Int32 i )
116cdf0e10cSrcweir {
117cdf0e10cSrcweir if ( i >= 0 && i <= (sal_Int32)m_aAccessibleChildren.size() )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir // insert entry in child list
120cdf0e10cSrcweir m_aAccessibleChildren.insert( m_aAccessibleChildren.begin() + i, Reference< XAccessible >() );
121cdf0e10cSrcweir
122cdf0e10cSrcweir // send accessible child event
123cdf0e10cSrcweir Reference< XAccessible > xChild( getAccessibleChild( i ) );
124cdf0e10cSrcweir if ( xChild.is() )
125cdf0e10cSrcweir {
126cdf0e10cSrcweir Any aOldValue, aNewValue;
127cdf0e10cSrcweir aNewValue <<= xChild;
128cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
129cdf0e10cSrcweir }
130cdf0e10cSrcweir }
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
133cdf0e10cSrcweir // -----------------------------------------------------------------------------
134cdf0e10cSrcweir
RemoveChild(sal_Int32 i)135cdf0e10cSrcweir void VCLXAccessibleStatusBar::RemoveChild( sal_Int32 i )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir if ( i >= 0 && i < (sal_Int32)m_aAccessibleChildren.size() )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir // get the accessible of the removed page
140cdf0e10cSrcweir Reference< XAccessible > xChild( m_aAccessibleChildren[i] );
141cdf0e10cSrcweir
142cdf0e10cSrcweir // remove entry in child list
143cdf0e10cSrcweir m_aAccessibleChildren.erase( m_aAccessibleChildren.begin() + i );
144cdf0e10cSrcweir
145cdf0e10cSrcweir // send accessible child event
146cdf0e10cSrcweir if ( xChild.is() )
147cdf0e10cSrcweir {
148cdf0e10cSrcweir Any aOldValue, aNewValue;
149cdf0e10cSrcweir aOldValue <<= xChild;
150cdf0e10cSrcweir NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldValue, aNewValue );
151cdf0e10cSrcweir
152cdf0e10cSrcweir Reference< XComponent > xComponent( xChild, UNO_QUERY );
153cdf0e10cSrcweir if ( xComponent.is() )
154cdf0e10cSrcweir xComponent->dispose();
155cdf0e10cSrcweir }
156cdf0e10cSrcweir }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir
159cdf0e10cSrcweir // -----------------------------------------------------------------------------
160cdf0e10cSrcweir
ProcessWindowEvent(const VclWindowEvent & rVclWindowEvent)161cdf0e10cSrcweir void VCLXAccessibleStatusBar::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
162cdf0e10cSrcweir {
163cdf0e10cSrcweir switch ( rVclWindowEvent.GetId() )
164cdf0e10cSrcweir {
165cdf0e10cSrcweir case VCLEVENT_STATUSBAR_ITEMADDED:
166cdf0e10cSrcweir {
167cdf0e10cSrcweir if ( m_pStatusBar )
168cdf0e10cSrcweir {
169cdf0e10cSrcweir sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
170cdf0e10cSrcweir sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
171cdf0e10cSrcweir InsertChild( nItemPos );
172cdf0e10cSrcweir }
173cdf0e10cSrcweir }
174cdf0e10cSrcweir break;
175cdf0e10cSrcweir case VCLEVENT_STATUSBAR_ITEMREMOVED:
176cdf0e10cSrcweir {
177cdf0e10cSrcweir if ( m_pStatusBar )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
180cdf0e10cSrcweir for ( sal_Int32 i = 0, nCount = getAccessibleChildCount(); i < nCount; ++i )
181cdf0e10cSrcweir {
182cdf0e10cSrcweir Reference< XAccessible > xChild( getAccessibleChild( i ) );
183cdf0e10cSrcweir if ( xChild.is() )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir VCLXAccessibleStatusBarItem* pVCLXAccessibleStatusBarItem = static_cast< VCLXAccessibleStatusBarItem* >( xChild.get() );
186cdf0e10cSrcweir if ( pVCLXAccessibleStatusBarItem && pVCLXAccessibleStatusBarItem->GetItemId() == nItemId )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir RemoveChild( i );
189cdf0e10cSrcweir break;
190cdf0e10cSrcweir }
191cdf0e10cSrcweir }
192cdf0e10cSrcweir }
193cdf0e10cSrcweir }
194cdf0e10cSrcweir }
195cdf0e10cSrcweir break;
196cdf0e10cSrcweir case VCLEVENT_STATUSBAR_ALLITEMSREMOVED:
197cdf0e10cSrcweir {
198cdf0e10cSrcweir for ( sal_Int32 i = m_aAccessibleChildren.size() - 1; i >= 0; --i )
199cdf0e10cSrcweir RemoveChild( i );
200cdf0e10cSrcweir }
201cdf0e10cSrcweir break;
202cdf0e10cSrcweir case VCLEVENT_STATUSBAR_SHOWITEM:
203cdf0e10cSrcweir case VCLEVENT_STATUSBAR_HIDEITEM:
204cdf0e10cSrcweir {
205cdf0e10cSrcweir if ( m_pStatusBar )
206cdf0e10cSrcweir {
207cdf0e10cSrcweir sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
208cdf0e10cSrcweir sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
209cdf0e10cSrcweir UpdateShowing( nItemPos, rVclWindowEvent.GetId() == VCLEVENT_STATUSBAR_SHOWITEM );
210cdf0e10cSrcweir }
211cdf0e10cSrcweir }
212cdf0e10cSrcweir break;
213cdf0e10cSrcweir case VCLEVENT_STATUSBAR_SHOWALLITEMS:
214cdf0e10cSrcweir case VCLEVENT_STATUSBAR_HIDEALLITEMS:
215cdf0e10cSrcweir {
216cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
217cdf0e10cSrcweir UpdateShowing( i, rVclWindowEvent.GetId() == VCLEVENT_STATUSBAR_SHOWALLITEMS );
218cdf0e10cSrcweir }
219cdf0e10cSrcweir break;
220cdf0e10cSrcweir case VCLEVENT_STATUSBAR_NAMECHANGED:
221cdf0e10cSrcweir {
222cdf0e10cSrcweir if ( m_pStatusBar )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
225cdf0e10cSrcweir sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
226cdf0e10cSrcweir UpdateItemName( nItemPos );
227cdf0e10cSrcweir }
228cdf0e10cSrcweir }
229cdf0e10cSrcweir break;
230cdf0e10cSrcweir case VCLEVENT_STATUSBAR_DRAWITEM:
231cdf0e10cSrcweir {
232cdf0e10cSrcweir if ( m_pStatusBar )
233cdf0e10cSrcweir {
234cdf0e10cSrcweir sal_uInt16 nItemId = (sal_uInt16)(sal_IntPtr) rVclWindowEvent.GetData();
235cdf0e10cSrcweir sal_uInt16 nItemPos = m_pStatusBar->GetItemPos( nItemId );
236cdf0e10cSrcweir UpdateItemText( nItemPos );
237cdf0e10cSrcweir }
238cdf0e10cSrcweir }
239cdf0e10cSrcweir break;
240cdf0e10cSrcweir case VCLEVENT_OBJECT_DYING:
241cdf0e10cSrcweir {
242cdf0e10cSrcweir if ( m_pStatusBar )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir m_pStatusBar = NULL;
245cdf0e10cSrcweir
246cdf0e10cSrcweir // dispose all children
247cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY );
250cdf0e10cSrcweir if ( xComponent.is() )
251cdf0e10cSrcweir xComponent->dispose();
252cdf0e10cSrcweir }
253cdf0e10cSrcweir m_aAccessibleChildren.clear();
254cdf0e10cSrcweir }
255cdf0e10cSrcweir
256cdf0e10cSrcweir VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
257cdf0e10cSrcweir }
258cdf0e10cSrcweir break;
259cdf0e10cSrcweir default:
260cdf0e10cSrcweir VCLXAccessibleComponent::ProcessWindowEvent( rVclWindowEvent );
261cdf0e10cSrcweir }
262cdf0e10cSrcweir }
263cdf0e10cSrcweir
264cdf0e10cSrcweir // -----------------------------------------------------------------------------
265cdf0e10cSrcweir // XComponent
266cdf0e10cSrcweir // -----------------------------------------------------------------------------
267cdf0e10cSrcweir
disposing()268cdf0e10cSrcweir void VCLXAccessibleStatusBar::disposing()
269cdf0e10cSrcweir {
270cdf0e10cSrcweir VCLXAccessibleComponent::disposing();
271cdf0e10cSrcweir
272cdf0e10cSrcweir if ( m_pStatusBar )
273cdf0e10cSrcweir {
274cdf0e10cSrcweir m_pStatusBar = NULL;
275cdf0e10cSrcweir
276cdf0e10cSrcweir // dispose all children
277cdf0e10cSrcweir for ( sal_uInt32 i = 0; i < m_aAccessibleChildren.size(); ++i )
278cdf0e10cSrcweir {
279cdf0e10cSrcweir Reference< XComponent > xComponent( m_aAccessibleChildren[i], UNO_QUERY );
280cdf0e10cSrcweir if ( xComponent.is() )
281cdf0e10cSrcweir xComponent->dispose();
282cdf0e10cSrcweir }
283cdf0e10cSrcweir m_aAccessibleChildren.clear();
284cdf0e10cSrcweir }
285cdf0e10cSrcweir }
286cdf0e10cSrcweir
287cdf0e10cSrcweir // -----------------------------------------------------------------------------
288cdf0e10cSrcweir // XServiceInfo
289cdf0e10cSrcweir // -----------------------------------------------------------------------------
290cdf0e10cSrcweir
getImplementationName()291cdf0e10cSrcweir ::rtl::OUString VCLXAccessibleStatusBar::getImplementationName() throw (RuntimeException)
292cdf0e10cSrcweir {
293cdf0e10cSrcweir return ::rtl::OUString::createFromAscii( "com.sun.star.comp.toolkit.AccessibleStatusBar" );
294cdf0e10cSrcweir }
295cdf0e10cSrcweir
296cdf0e10cSrcweir // -----------------------------------------------------------------------------
297cdf0e10cSrcweir
getSupportedServiceNames()298cdf0e10cSrcweir Sequence< ::rtl::OUString > VCLXAccessibleStatusBar::getSupportedServiceNames() throw (RuntimeException)
299cdf0e10cSrcweir {
300cdf0e10cSrcweir Sequence< ::rtl::OUString > aNames(1);
301cdf0e10cSrcweir aNames[0] = ::rtl::OUString::createFromAscii( "com.sun.star.awt.AccessibleStatusBar" );
302cdf0e10cSrcweir return aNames;
303cdf0e10cSrcweir }
304cdf0e10cSrcweir
305cdf0e10cSrcweir // -----------------------------------------------------------------------------
306cdf0e10cSrcweir // XAccessibleContext
307cdf0e10cSrcweir // -----------------------------------------------------------------------------
308cdf0e10cSrcweir
getAccessibleChildCount()309cdf0e10cSrcweir sal_Int32 VCLXAccessibleStatusBar::getAccessibleChildCount() throw (RuntimeException)
310cdf0e10cSrcweir {
311cdf0e10cSrcweir OExternalLockGuard aGuard( this );
312cdf0e10cSrcweir
313cdf0e10cSrcweir return m_aAccessibleChildren.size();
314cdf0e10cSrcweir }
315cdf0e10cSrcweir
316cdf0e10cSrcweir // -----------------------------------------------------------------------------
317cdf0e10cSrcweir
getAccessibleChild(sal_Int32 i)318cdf0e10cSrcweir Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleChild( sal_Int32 i ) throw (IndexOutOfBoundsException, RuntimeException)
319cdf0e10cSrcweir {
320cdf0e10cSrcweir OExternalLockGuard aGuard( this );
321cdf0e10cSrcweir
322cdf0e10cSrcweir if ( i < 0 || i >= getAccessibleChildCount() )
323cdf0e10cSrcweir throw IndexOutOfBoundsException();
324cdf0e10cSrcweir
325cdf0e10cSrcweir Reference< XAccessible > xChild = m_aAccessibleChildren[i];
326cdf0e10cSrcweir if ( !xChild.is() )
327cdf0e10cSrcweir {
328cdf0e10cSrcweir if ( m_pStatusBar )
329cdf0e10cSrcweir {
330cdf0e10cSrcweir sal_uInt16 nItemId = m_pStatusBar->GetItemId( (sal_uInt16)i );
331cdf0e10cSrcweir
332cdf0e10cSrcweir xChild = new VCLXAccessibleStatusBarItem( m_pStatusBar, nItemId );
333cdf0e10cSrcweir
334cdf0e10cSrcweir // insert into status bar item list
335cdf0e10cSrcweir m_aAccessibleChildren[i] = xChild;
336cdf0e10cSrcweir }
337cdf0e10cSrcweir }
338cdf0e10cSrcweir
339cdf0e10cSrcweir return xChild;
340cdf0e10cSrcweir }
341cdf0e10cSrcweir
342cdf0e10cSrcweir // -----------------------------------------------------------------------------
343cdf0e10cSrcweir // XAccessibleComponent
344cdf0e10cSrcweir // -----------------------------------------------------------------------------
345cdf0e10cSrcweir
getAccessibleAtPoint(const awt::Point & rPoint)346cdf0e10cSrcweir Reference< XAccessible > VCLXAccessibleStatusBar::getAccessibleAtPoint( const awt::Point& rPoint ) throw (RuntimeException)
347cdf0e10cSrcweir {
348cdf0e10cSrcweir OExternalLockGuard aGuard( this );
349cdf0e10cSrcweir
350cdf0e10cSrcweir Reference< XAccessible > xChild;
351cdf0e10cSrcweir if ( m_pStatusBar )
352cdf0e10cSrcweir {
353cdf0e10cSrcweir sal_uInt16 nItemId = m_pStatusBar->GetItemId( VCLPoint( rPoint ) );
354cdf0e10cSrcweir sal_Int32 nItemPos = m_pStatusBar->GetItemPos( nItemId );
355cdf0e10cSrcweir if ( nItemPos >= 0 && nItemPos < (sal_Int32)m_aAccessibleChildren.size() )
356cdf0e10cSrcweir xChild = getAccessibleChild( nItemPos );
357cdf0e10cSrcweir }
358cdf0e10cSrcweir
359cdf0e10cSrcweir return xChild;
360cdf0e10cSrcweir }
361cdf0e10cSrcweir
362cdf0e10cSrcweir // -----------------------------------------------------------------------------
363