1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include "accessibility/extended/AccessibleToolPanelDeck.hxx"
23 #include <com/sun/star/accessibility/AccessibleRole.hpp>
24 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
25 #include <com/sun/star/accessibility/AccessibleStateType.hpp>
26 #include <com/sun/star/lang/DisposedException.hpp>
28 #include <svtools/toolpanel/toolpaneldeck.hxx>
29 #include <toolkit/awt/vclxwindow.hxx>
30 #include <toolkit/helper/vclunohelper.hxx>
31 #include <vcl/svapp.hxx>
32 #include <osl/mutex.hxx>
33 #include <unotools/accessiblestatesethelper.hxx>
34 #include <tools/diagnose_ex.h>
36 #include <boost/noncopyable.hpp>
38 //......................................................................................................................
39 namespace accessibility
41 //......................................................................................................................
43 /** === begin UNO using === **/
44 using ::com::sun::star::uno::Reference
;
45 using ::com::sun::star::uno::XInterface
;
46 using ::com::sun::star::uno::UNO_QUERY
;
47 using ::com::sun::star::uno::UNO_QUERY_THROW
;
48 using ::com::sun::star::uno::UNO_SET_THROW
;
49 using ::com::sun::star::uno::Exception
;
50 using ::com::sun::star::uno::RuntimeException
;
51 using ::com::sun::star::uno::Any
;
52 using ::com::sun::star::uno::makeAny
;
53 using ::com::sun::star::uno::Sequence
;
54 using ::com::sun::star::uno::Type
;
55 using ::com::sun::star::accessibility::XAccessible
;
56 using ::com::sun::star::accessibility::XAccessibleContext
;
57 using ::com::sun::star::lang::DisposedException
;
58 using ::com::sun::star::lang::IndexOutOfBoundsException
;
59 using ::com::sun::star::lang::Locale
;
60 using ::com::sun::star::accessibility::XAccessibleRelationSet
;
61 using ::com::sun::star::accessibility::XAccessibleStateSet
;
62 using ::com::sun::star::accessibility::IllegalAccessibleComponentStateException
;
63 using ::com::sun::star::awt::XFont
;
64 /** === end UNO using === **/
65 namespace AccessibleRole
= ::com::sun::star::accessibility::AccessibleRole
;
66 namespace AccessibleEventId
= ::com::sun::star::accessibility::AccessibleEventId
;
67 namespace AccessibleStateType
= ::com::sun::star::accessibility::AccessibleStateType
;
69 typedef ::com::sun::star::awt::Point UnoPoint
;
71 //==================================================================================================================
72 //= AccessibleToolPanelDeck_Impl - declaration
73 //==================================================================================================================
74 class AccessibleToolPanelDeck_Impl
:public ::boost::noncopyable
75 ,public ::svt::IToolPanelDeckListener
78 AccessibleToolPanelDeck_Impl(
79 AccessibleToolPanelDeck
& i_rAntiImpl
,
80 const Reference
< XAccessible
>& i_rAccessibleParent
,
81 ::svt::ToolPanelDeck
& i_rPanelDeck
85 bool isDisposed() const { return m_pPanelDeck
== NULL
; }
88 virtual ~AccessibleToolPanelDeck_Impl();
90 Reference
< XAccessible
> getOwnAccessible() const;
91 Reference
< XAccessible
> getActivePanelAccessible();
94 // IToolPanelDeckListener
95 virtual void PanelInserted( const ::svt::PToolPanel
& i_pPanel
, const size_t i_nPosition
);
96 virtual void PanelRemoved( const size_t i_nPosition
);
97 virtual void ActivePanelChanged( const ::boost::optional
< size_t >& i_rOldActive
, const ::boost::optional
< size_t >& i_rNewActive
);
98 virtual void LayouterChanged( const ::svt::PDeckLayouter
& i_rNewLayouter
);
102 AccessibleToolPanelDeck
& m_rAntiImpl
;
103 Reference
< XAccessible
> m_xAccessibleParent
;
104 ::svt::ToolPanelDeck
* m_pPanelDeck
;
106 Reference
< XAccessible
> m_xActivePanelAccessible
;
109 //==================================================================================================================
111 //==================================================================================================================
117 MethodGuard( AccessibleToolPanelDeck_Impl
& i_rImpl
)
120 i_rImpl
.checkDisposed();
127 SolarMutexGuard m_aGuard
;
131 //==================================================================================================================
132 //= AccessibleToolPanelDeck_Impl - implementation
133 //==================================================================================================================
134 //------------------------------------------------------------------------------------------------------------------
135 AccessibleToolPanelDeck_Impl::AccessibleToolPanelDeck_Impl( AccessibleToolPanelDeck
& i_rAntiImpl
, const Reference
< XAccessible
>& i_rAccessibleParent
,
136 ::svt::ToolPanelDeck
& i_rPanelDeck
)
137 :m_rAntiImpl( i_rAntiImpl
)
138 ,m_xAccessibleParent( i_rAccessibleParent
)
139 ,m_pPanelDeck( &i_rPanelDeck
)
140 ,m_xActivePanelAccessible()
142 m_pPanelDeck
->AddListener( *this );
145 //------------------------------------------------------------------------------------------------------------------
146 AccessibleToolPanelDeck_Impl::~AccessibleToolPanelDeck_Impl()
152 //------------------------------------------------------------------------------------------------------------------
153 void AccessibleToolPanelDeck_Impl::dispose()
155 ENSURE_OR_RETURN_VOID( !isDisposed(), "disposed twice" );
156 m_pPanelDeck
->RemoveListener( *this );
158 m_xAccessibleParent
.clear();
161 //------------------------------------------------------------------------------------------------------------------
162 void AccessibleToolPanelDeck_Impl::checkDisposed()
165 throw DisposedException( OUString(), *&m_rAntiImpl
);
168 //------------------------------------------------------------------------------------------------------------------
169 Reference
< XAccessible
> AccessibleToolPanelDeck_Impl::getOwnAccessible() const
171 Reference
< XAccessible
> xOwnAccessible( static_cast< XAccessible
* >( m_rAntiImpl
.GetVCLXWindow() ) );
172 OSL_ENSURE( xOwnAccessible
->getAccessibleContext() == Reference
< XAccessibleContext
>( &m_rAntiImpl
),
173 "AccessibleToolPanelDeck_Impl::getOwnAccessible: could not retrieve proper XAccessible for /myself!" );
174 return xOwnAccessible
;
177 //------------------------------------------------------------------------------------------------------------------
178 Reference
< XAccessible
> AccessibleToolPanelDeck_Impl::getActivePanelAccessible()
180 ENSURE_OR_RETURN( !isDisposed(), "AccessibleToolPanelDeck_Impl::getActivePanelAccessible: already disposed!", NULL
);
182 if ( !m_xActivePanelAccessible
.is() )
184 ::boost::optional
< size_t > aActivePanel( m_pPanelDeck
->GetActivePanel() );
185 ENSURE_OR_RETURN( !!aActivePanel
, "AccessibleToolPanelDeck_Impl::getActivePanelAccessible: this should not be called without an active panel!", NULL
);
186 ::svt::PToolPanel
pActivePanel( m_pPanelDeck
->GetPanel( *aActivePanel
) );
187 ENSURE_OR_RETURN( pActivePanel
.get() != NULL
, "AccessibleToolPanelDeck_Impl::getActivePanelAccessible: no active panel!", NULL
);
188 m_xActivePanelAccessible
= pActivePanel
->CreatePanelAccessible( getOwnAccessible() );
189 OSL_ENSURE( m_xActivePanelAccessible
.is(), "AccessibleToolPanelDeck_Impl::getActivePanelAccessible: illegal accessible returned by the panel!" );
192 return m_xActivePanelAccessible
;
195 //------------------------------------------------------------------------------------------------------------------
196 void AccessibleToolPanelDeck_Impl::PanelInserted( const ::svt::PToolPanel
& i_pPanel
, const size_t i_nPosition
)
202 //------------------------------------------------------------------------------------------------------------------
203 void AccessibleToolPanelDeck_Impl::PanelRemoved( const size_t i_nPosition
)
208 //------------------------------------------------------------------------------------------------------------------
209 void AccessibleToolPanelDeck_Impl::ActivePanelChanged( const ::boost::optional
< size_t >& i_rOldActive
, const ::boost::optional
< size_t >& i_rNewActive
)
211 if ( !!i_rOldActive
)
213 if ( !m_xActivePanelAccessible
.is() )
215 // again, this might in theory happen if the XAccessible for the active panel has never before been requested.
216 // In this case, just say that all our children are invalid, so they all must be re-requested.
217 m_rAntiImpl
.NotifyAccessibleEvent( AccessibleEventId::INVALIDATE_ALL_CHILDREN
, Any(), Any() );
221 m_rAntiImpl
.NotifyAccessibleEvent( AccessibleEventId::CHILD
, makeAny( m_xActivePanelAccessible
), Any() );
225 m_xActivePanelAccessible
.clear();
227 if ( !!i_rNewActive
)
229 m_rAntiImpl
.NotifyAccessibleEvent( AccessibleEventId::CHILD
, Any(), makeAny( getActivePanelAccessible() ) );
233 //------------------------------------------------------------------------------------------------------------------
234 void AccessibleToolPanelDeck_Impl::LayouterChanged( const ::svt::PDeckLayouter
& i_rNewLayouter
)
236 MethodGuard
aGuard( *this );
238 (void)i_rNewLayouter
;
239 m_rAntiImpl
.NotifyAccessibleEvent( AccessibleEventId::INVALIDATE_ALL_CHILDREN
, Any(), Any() );
242 //------------------------------------------------------------------------------------------------------------------
243 void AccessibleToolPanelDeck_Impl::Dying()
245 // the tool panel deck is dying, so dispose ourself
246 m_rAntiImpl
.dispose();
249 //==================================================================================================================
250 //= AccessibleToolPanelDeck
251 //==================================================================================================================
252 //------------------------------------------------------------------------------------------------------------------
253 AccessibleToolPanelDeck::AccessibleToolPanelDeck( const Reference
< XAccessible
>& i_rAccessibleParent
,
254 ::svt::ToolPanelDeck
& i_rPanelDeck
)
255 :AccessibleToolPanelDeck_Base( i_rPanelDeck
.GetWindowPeer() )
256 ,m_pImpl( new AccessibleToolPanelDeck_Impl( *this, i_rAccessibleParent
, i_rPanelDeck
) )
260 //------------------------------------------------------------------------------------------------------------------
261 AccessibleToolPanelDeck::~AccessibleToolPanelDeck()
265 //------------------------------------------------------------------------------------------------------------------
266 sal_Int32 SAL_CALL
AccessibleToolPanelDeck::getAccessibleChildCount( ) throw (RuntimeException
)
268 MethodGuard
aGuard( *m_pImpl
);
270 sal_Int32
nChildCount( m_pImpl
->m_pPanelDeck
->GetLayouter()->GetAccessibleChildCount() );
272 ::boost::optional
< size_t > aActivePanel( m_pImpl
->m_pPanelDeck
->GetActivePanel() );
273 if ( !!aActivePanel
)
274 return ++nChildCount
;
279 //------------------------------------------------------------------------------------------------------------------
280 Reference
< XAccessible
> SAL_CALL
AccessibleToolPanelDeck::getAccessibleChild( sal_Int32 i_nIndex
) throw (IndexOutOfBoundsException
, RuntimeException
)
282 MethodGuard
aGuard( *m_pImpl
);
284 const sal_Int32
nChildCount( getAccessibleChildCount() );
285 if ( ( i_nIndex
< 0 ) || ( i_nIndex
>= nChildCount
) )
286 throw IndexOutOfBoundsException( OUString(), *this );
288 // first "n" children are provided by the layouter
289 const size_t nLayouterCount( m_pImpl
->m_pPanelDeck
->GetLayouter()->GetAccessibleChildCount() );
290 if ( size_t( i_nIndex
) < nLayouterCount
)
291 return m_pImpl
->m_pPanelDeck
->GetLayouter()->GetAccessibleChild(
293 m_pImpl
->getOwnAccessible()
296 // the last child is the XAccessible of the active panel
297 return m_pImpl
->getActivePanelAccessible();
300 //------------------------------------------------------------------------------------------------------------------
301 Reference
< XAccessible
> SAL_CALL
AccessibleToolPanelDeck::getAccessibleParent( ) throw (RuntimeException
)
303 MethodGuard
aGuard( *m_pImpl
);
304 const Reference
< XAccessible
> xParent
= implGetForeignControlledParent();
307 return m_pImpl
->m_xAccessibleParent
;
310 //------------------------------------------------------------------------------------------------------------------
311 sal_Int16 SAL_CALL
AccessibleToolPanelDeck::getAccessibleRole( ) throw (RuntimeException
)
313 MethodGuard
aGuard( *m_pImpl
);
314 return AccessibleRole::PANEL
;
317 //------------------------------------------------------------------------------------------------------------------
318 Reference
< XAccessible
> SAL_CALL
AccessibleToolPanelDeck::getAccessibleAtPoint( const UnoPoint
& i_rPoint
) throw (RuntimeException
)
320 MethodGuard
aGuard( *m_pImpl
);
322 const ::Point
aRequestedPoint( VCLUnoHelper::ConvertToVCLPoint( i_rPoint
) );
323 // check the panel window itself
324 const ::Window
& rActivePanelAnchor( m_pImpl
->m_pPanelDeck
->GetPanelWindowAnchor() );
325 const Rectangle
aPanelAnchorArea( rActivePanelAnchor
.GetPosPixel(), rActivePanelAnchor
.GetOutputSizePixel() );
326 if ( aPanelAnchorArea
.IsInside( aRequestedPoint
) )
327 // note that this assumes that the Window which actually implements the concrete panel covers
328 // the complete area of its "anchor" Window. But this is ensured by the ToolPanelDeck implementation.
329 return m_pImpl
->getActivePanelAccessible();
331 // check the XAccessible instances provided by the layouter
334 const ::svt::PDeckLayouter
pLayouter( m_pImpl
->m_pPanelDeck
->GetLayouter() );
335 ENSURE_OR_THROW( pLayouter
.get() != NULL
, "invalid layouter" );
337 const size_t nLayouterChildren
= pLayouter
->GetAccessibleChildCount();
338 for ( size_t i
=0; i
<nLayouterChildren
; ++i
)
340 const Reference
< XAccessible
> xLayoutItemAccessible( pLayouter
->GetAccessibleChild( i
, m_pImpl
->getOwnAccessible() ), UNO_SET_THROW
);
341 const Reference
< XAccessibleComponent
> xLayoutItemComponent( xLayoutItemAccessible
->getAccessibleContext(), UNO_QUERY_THROW
);
342 const ::Rectangle
aLayoutItemBounds( VCLUnoHelper::ConvertToVCLRect( xLayoutItemComponent
->getBounds() ) );
343 if ( aLayoutItemBounds
.IsInside( aRequestedPoint
) )
344 return xLayoutItemAccessible
;
347 catch( const Exception
& )
349 DBG_UNHANDLED_EXCEPTION();
355 //------------------------------------------------------------------------------------------------------------------
356 void SAL_CALL
AccessibleToolPanelDeck::grabFocus( ) throw (RuntimeException
)
358 MethodGuard
aGuard( *m_pImpl
);
359 m_pImpl
->m_pPanelDeck
->GrabFocus();
362 //------------------------------------------------------------------------------------------------------------------
363 void SAL_CALL
AccessibleToolPanelDeck::disposing()
365 AccessibleToolPanelDeck_Base::disposing();
369 //------------------------------------------------------------------------------------------------------------------
370 Reference
< XAccessible
> AccessibleToolPanelDeck::GetChildAccessible( const VclWindowEvent
& i_rVclWindowEvent
)
372 // don't let the base class generate any A11Y events from VclWindowEvent, we completely manage those
373 // A11Y events ourself
374 (void)i_rVclWindowEvent
;
378 //------------------------------------------------------------------------------------------------------------------
379 void AccessibleToolPanelDeck::FillAccessibleStateSet( ::utl::AccessibleStateSetHelper
& i_rStateSet
)
381 AccessibleToolPanelDeck_Base::FillAccessibleStateSet( i_rStateSet
);
382 if ( m_pImpl
->isDisposed() )
384 i_rStateSet
.AddState( AccessibleStateType::DEFUNC
);
388 i_rStateSet
.AddState( AccessibleStateType::FOCUSABLE
);
392 //......................................................................................................................
393 } // namespace accessibility
394 //......................................................................................................................
396 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */