1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3*cdf0e10cSrcweir  *
4*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
5*cdf0e10cSrcweir  *
6*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
7*cdf0e10cSrcweir  *
8*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
9*cdf0e10cSrcweir  *
10*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
11*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
12*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
13*cdf0e10cSrcweir  *
14*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
15*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
18*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
19*cdf0e10cSrcweir  *
20*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
21*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
22*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
23*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
24*cdf0e10cSrcweir  *
25*cdf0e10cSrcweir  ************************************************************************/
26*cdf0e10cSrcweir 
27*cdf0e10cSrcweir #include "precompiled_accessibility.hxx"
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir #include "accessibility/extended/AccessibleToolPanelDeckTabBar.hxx"
30*cdf0e10cSrcweir #include "accessibility/extended/AccessibleToolPanelDeckTabBarItem.hxx"
31*cdf0e10cSrcweir #include "accessibility/helper/accresmgr.hxx"
32*cdf0e10cSrcweir #include "accessibility/helper/accessiblestrings.hrc"
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir /** === begin UNO includes === **/
35*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleRole.hpp>
36*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
37*cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleStateType.hpp>
38*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp>
39*cdf0e10cSrcweir /** === end UNO includes === **/
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir #include <svtools/toolpanel/toolpaneldeck.hxx>
42*cdf0e10cSrcweir #include <svtools/toolpanel/paneltabbar.hxx>
43*cdf0e10cSrcweir #include <unotools/accessiblestatesethelper.hxx>
44*cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
45*cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
46*cdf0e10cSrcweir #include <vcl/svapp.hxx>
47*cdf0e10cSrcweir #include <vcl/button.hxx>
48*cdf0e10cSrcweir #include <vos/mutex.hxx>
49*cdf0e10cSrcweir #include <tools/diagnose_ex.h>
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir #include <vector>
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir //......................................................................................................................
54*cdf0e10cSrcweir namespace accessibility
55*cdf0e10cSrcweir {
56*cdf0e10cSrcweir //......................................................................................................................
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir 	/** === begin UNO using === **/
59*cdf0e10cSrcweir 	using ::com::sun::star::uno::Reference;
60*cdf0e10cSrcweir 	using ::com::sun::star::uno::XInterface;
61*cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY;
62*cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_QUERY_THROW;
63*cdf0e10cSrcweir 	using ::com::sun::star::uno::UNO_SET_THROW;
64*cdf0e10cSrcweir 	using ::com::sun::star::uno::Exception;
65*cdf0e10cSrcweir 	using ::com::sun::star::uno::RuntimeException;
66*cdf0e10cSrcweir 	using ::com::sun::star::uno::Any;
67*cdf0e10cSrcweir 	using ::com::sun::star::uno::makeAny;
68*cdf0e10cSrcweir 	using ::com::sun::star::uno::Sequence;
69*cdf0e10cSrcweir 	using ::com::sun::star::uno::Type;
70*cdf0e10cSrcweir     using ::com::sun::star::accessibility::XAccessible;
71*cdf0e10cSrcweir     using ::com::sun::star::lang::DisposedException;
72*cdf0e10cSrcweir     using ::com::sun::star::lang::IndexOutOfBoundsException;
73*cdf0e10cSrcweir     using ::com::sun::star::accessibility::XAccessibleContext;
74*cdf0e10cSrcweir     /** === end UNO using === **/
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir     namespace AccessibleRole = ::com::sun::star::accessibility::AccessibleRole;
77*cdf0e10cSrcweir     namespace AccessibleEventId = ::com::sun::star::accessibility::AccessibleEventId;
78*cdf0e10cSrcweir     namespace AccessibleStateType = ::com::sun::star::accessibility::AccessibleStateType;
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     typedef ::com::sun::star::awt::Point        UnoPoint;
81*cdf0e10cSrcweir     typedef ::com::sun::star::awt::Size         UnoSize;
82*cdf0e10cSrcweir     typedef ::com::sun::star::awt::Rectangle    UnoRectangle;
83*cdf0e10cSrcweir 
84*cdf0e10cSrcweir 	//==================================================================================================================
85*cdf0e10cSrcweir 	//= AccessibleWrapper
86*cdf0e10cSrcweir 	//==================================================================================================================
87*cdf0e10cSrcweir     typedef ::cppu::WeakImplHelper1< XAccessible > AccessibleWrapper_Base;
88*cdf0e10cSrcweir     class AccessibleWrapper : public AccessibleWrapper_Base
89*cdf0e10cSrcweir     {
90*cdf0e10cSrcweir     public:
91*cdf0e10cSrcweir         AccessibleWrapper( const Reference< XAccessibleContext >& i_rContext )
92*cdf0e10cSrcweir             :m_xContext( i_rContext )
93*cdf0e10cSrcweir         {
94*cdf0e10cSrcweir         }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir         // XAccessible
97*cdf0e10cSrcweir         virtual Reference< XAccessibleContext > SAL_CALL getAccessibleContext(  ) throw (RuntimeException)
98*cdf0e10cSrcweir         {
99*cdf0e10cSrcweir             return m_xContext;
100*cdf0e10cSrcweir         }
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir     private:
103*cdf0e10cSrcweir         const Reference< XAccessibleContext >   m_xContext;
104*cdf0e10cSrcweir     };
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 	//==================================================================================================================
107*cdf0e10cSrcweir 	//= AccessibleToolPanelTabBar_Impl
108*cdf0e10cSrcweir 	//==================================================================================================================
109*cdf0e10cSrcweir     class AccessibleToolPanelTabBar_Impl    :public ::boost::noncopyable
110*cdf0e10cSrcweir                                             ,public ::svt::IToolPanelDeckListener
111*cdf0e10cSrcweir     {
112*cdf0e10cSrcweir     public:
113*cdf0e10cSrcweir         AccessibleToolPanelTabBar_Impl(
114*cdf0e10cSrcweir             AccessibleToolPanelTabBar& i_rAntiImpl,
115*cdf0e10cSrcweir             const Reference< XAccessible >& i_rAccessibleParent,
116*cdf0e10cSrcweir             ::svt::IToolPanelDeck& i_rPanelDeck,
117*cdf0e10cSrcweir             ::svt::PanelTabBar& i_rTabBar
118*cdf0e10cSrcweir         );
119*cdf0e10cSrcweir         ~AccessibleToolPanelTabBar_Impl();
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir         void    checkDisposed();
122*cdf0e10cSrcweir         bool    isDisposed() const { return m_pPanelDeck == NULL; }
123*cdf0e10cSrcweir         void    dispose();
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir         ::svt::IToolPanelDeck*          getPanelDeck() const { return m_pPanelDeck; }
126*cdf0e10cSrcweir         ::svt::PanelTabBar*             getTabBar() const { return m_pTabBar; }
127*cdf0e10cSrcweir         const Reference< XAccessible >& getAccessibleParent() const { return m_xAccessibleParent; }
128*cdf0e10cSrcweir         Reference< XAccessible >        getAccessiblePanelItem( size_t i_nPosition );
129*cdf0e10cSrcweir         Reference< XAccessible >        getOwnAccessible() const;
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir     protected:
132*cdf0e10cSrcweir         // IToolPanelDeckListener
133*cdf0e10cSrcweir         virtual void PanelInserted( const ::svt::PToolPanel& i_pPanel, const size_t i_nPosition );
134*cdf0e10cSrcweir         virtual void PanelRemoved( const size_t i_nPosition );
135*cdf0e10cSrcweir         virtual void ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive );
136*cdf0e10cSrcweir         virtual void LayouterChanged( const ::svt::PDeckLayouter& i_rNewLayouter );
137*cdf0e10cSrcweir         virtual void Dying();
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir         DECL_LINK( OnWindowEvent, const VclSimpleEvent* );
140*cdf0e10cSrcweir 
141*cdf0e10cSrcweir     private:
142*cdf0e10cSrcweir         AccessibleToolPanelTabBar&                  m_rAntiImpl;
143*cdf0e10cSrcweir         Reference< XAccessible >                    m_xAccessibleParent;
144*cdf0e10cSrcweir         ::svt::IToolPanelDeck*                      m_pPanelDeck;
145*cdf0e10cSrcweir         ::svt::PanelTabBar*                         m_pTabBar;
146*cdf0e10cSrcweir         ::std::vector< Reference< XAccessible > >   m_aChildren;
147*cdf0e10cSrcweir     };
148*cdf0e10cSrcweir 
149*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
150*cdf0e10cSrcweir     AccessibleToolPanelTabBar_Impl::AccessibleToolPanelTabBar_Impl( AccessibleToolPanelTabBar& i_rAntiImpl,
151*cdf0e10cSrcweir             const Reference< XAccessible >& i_rAccessibleParent, ::svt::IToolPanelDeck& i_rPanelDeck, ::svt::PanelTabBar& i_rTabBar )
152*cdf0e10cSrcweir         :m_rAntiImpl( i_rAntiImpl )
153*cdf0e10cSrcweir         ,m_xAccessibleParent( i_rAccessibleParent )
154*cdf0e10cSrcweir         ,m_pPanelDeck( &i_rPanelDeck )
155*cdf0e10cSrcweir         ,m_pTabBar( &i_rTabBar )
156*cdf0e10cSrcweir         ,m_aChildren()
157*cdf0e10cSrcweir     {
158*cdf0e10cSrcweir         m_pPanelDeck->AddListener( *this );
159*cdf0e10cSrcweir         m_aChildren.resize( m_pPanelDeck->GetPanelCount() );
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir         const String sAccessibleDescription( TK_RES_STRING( RID_STR_ACC_DESC_PANELDECL_TABBAR ) );
162*cdf0e10cSrcweir         i_rTabBar.SetAccessibleName( sAccessibleDescription );
163*cdf0e10cSrcweir         i_rTabBar.SetAccessibleDescription( sAccessibleDescription );
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir         i_rTabBar.GetScrollButton( true ).AddEventListener( LINK( this, AccessibleToolPanelTabBar_Impl, OnWindowEvent ) );
166*cdf0e10cSrcweir         i_rTabBar.GetScrollButton( false ).AddEventListener( LINK( this, AccessibleToolPanelTabBar_Impl, OnWindowEvent ) );
167*cdf0e10cSrcweir     }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
170*cdf0e10cSrcweir     void AccessibleToolPanelTabBar_Impl::checkDisposed()
171*cdf0e10cSrcweir     {
172*cdf0e10cSrcweir         if ( isDisposed() )
173*cdf0e10cSrcweir             throw DisposedException( ::rtl::OUString(), *&m_rAntiImpl );
174*cdf0e10cSrcweir     }
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
177*cdf0e10cSrcweir     AccessibleToolPanelTabBar_Impl::~AccessibleToolPanelTabBar_Impl()
178*cdf0e10cSrcweir     {
179*cdf0e10cSrcweir         if ( !isDisposed() )
180*cdf0e10cSrcweir             dispose();
181*cdf0e10cSrcweir     }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
184*cdf0e10cSrcweir     void AccessibleToolPanelTabBar_Impl::dispose()
185*cdf0e10cSrcweir     {
186*cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( !isDisposed(), "disposed twice" );
187*cdf0e10cSrcweir         m_pPanelDeck->RemoveListener( *this );
188*cdf0e10cSrcweir         m_pPanelDeck = NULL;
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir         m_pTabBar->GetScrollButton( true ).RemoveEventListener( LINK( this, AccessibleToolPanelTabBar_Impl, OnWindowEvent ) );
191*cdf0e10cSrcweir         m_pTabBar->GetScrollButton( false ).RemoveEventListener( LINK( this, AccessibleToolPanelTabBar_Impl, OnWindowEvent ) );
192*cdf0e10cSrcweir         m_pTabBar = NULL;
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir         m_xAccessibleParent.clear();
195*cdf0e10cSrcweir     }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
198*cdf0e10cSrcweir     Reference< XAccessible > AccessibleToolPanelTabBar_Impl::getAccessiblePanelItem( size_t i_nPosition )
199*cdf0e10cSrcweir     {
200*cdf0e10cSrcweir         ENSURE_OR_RETURN( !isDisposed(), "AccessibleToolPanelTabBar_Impl::getAccessiblePanelItem: already disposed!", NULL );
201*cdf0e10cSrcweir         ENSURE_OR_RETURN( i_nPosition < m_aChildren.size(), "AccessibleToolPanelTabBar_Impl::getAccessiblePanelItem: invalid index!", NULL );
202*cdf0e10cSrcweir 
203*cdf0e10cSrcweir         Reference< XAccessible >& rAccessibleChild( m_aChildren[ i_nPosition ] );
204*cdf0e10cSrcweir         if ( !rAccessibleChild.is() )
205*cdf0e10cSrcweir         {
206*cdf0e10cSrcweir             ::rtl::Reference< AccessibleToolPanelDeckTabBarItem > pAccesibleItemContext( new AccessibleToolPanelDeckTabBarItem(
207*cdf0e10cSrcweir                 getOwnAccessible(), *m_pPanelDeck, *m_pTabBar, i_nPosition ) );
208*cdf0e10cSrcweir             rAccessibleChild.set( new AccessibleWrapper( pAccesibleItemContext.get() ) );
209*cdf0e10cSrcweir             pAccesibleItemContext->lateInit( rAccessibleChild );
210*cdf0e10cSrcweir         }
211*cdf0e10cSrcweir         return rAccessibleChild;
212*cdf0e10cSrcweir     }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
215*cdf0e10cSrcweir     Reference< XAccessible > AccessibleToolPanelTabBar_Impl::getOwnAccessible() const
216*cdf0e10cSrcweir     {
217*cdf0e10cSrcweir         Reference< XAccessible > xOwnAccessible( static_cast< XAccessible* >( m_rAntiImpl.GetVCLXWindow() ) );
218*cdf0e10cSrcweir         OSL_ENSURE( xOwnAccessible->getAccessibleContext() == Reference< XAccessibleContext >( &m_rAntiImpl ),
219*cdf0e10cSrcweir             "AccessibleToolPanelTabBar_Impl::getOwnAccessible: could not retrieve proper XAccessible for /myself!" );
220*cdf0e10cSrcweir         return xOwnAccessible;
221*cdf0e10cSrcweir     }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
224*cdf0e10cSrcweir     void AccessibleToolPanelTabBar_Impl::PanelInserted( const ::svt::PToolPanel& i_pPanel, const size_t i_nPosition )
225*cdf0e10cSrcweir     {
226*cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( i_nPosition <= m_aChildren.size(), "AccessibleToolPanelTabBar_Impl::PanelInserted: illegal position (or invalid cache!)" );
227*cdf0e10cSrcweir         (void)i_pPanel;
228*cdf0e10cSrcweir         m_aChildren.insert( m_aChildren.begin() + i_nPosition, NULL );
229*cdf0e10cSrcweir         m_rAntiImpl.NotifyAccessibleEvent( AccessibleEventId::CHILD, Any(), makeAny( getAccessiblePanelItem( i_nPosition ) ) );
230*cdf0e10cSrcweir     }
231*cdf0e10cSrcweir 
232*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
233*cdf0e10cSrcweir     void AccessibleToolPanelTabBar_Impl::PanelRemoved( const size_t i_nPosition )
234*cdf0e10cSrcweir     {
235*cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( i_nPosition < m_aChildren.size(), "AccessibleToolPanelTabBar_Impl::PanelInserted: illegal position (or invalid cache!)" );
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir         const Reference< XAccessible > xOldChild( getAccessiblePanelItem( i_nPosition ) );
238*cdf0e10cSrcweir         m_aChildren.erase( m_aChildren.begin() + i_nPosition );
239*cdf0e10cSrcweir         m_rAntiImpl.NotifyAccessibleEvent( AccessibleEventId::CHILD, makeAny( xOldChild ), Any() );
240*cdf0e10cSrcweir     }
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
243*cdf0e10cSrcweir     void AccessibleToolPanelTabBar_Impl::ActivePanelChanged( const ::boost::optional< size_t >& i_rOldActive, const ::boost::optional< size_t >& i_rNewActive )
244*cdf0e10cSrcweir     {
245*cdf0e10cSrcweir         (void)i_rOldActive;
246*cdf0e10cSrcweir         (void)i_rNewActive;
247*cdf0e10cSrcweir     }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
250*cdf0e10cSrcweir     void AccessibleToolPanelTabBar_Impl::LayouterChanged( const ::svt::PDeckLayouter& i_rNewLayouter )
251*cdf0e10cSrcweir     {
252*cdf0e10cSrcweir         (void)i_rNewLayouter;
253*cdf0e10cSrcweir         m_rAntiImpl.dispose();
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
257*cdf0e10cSrcweir     void AccessibleToolPanelTabBar_Impl::Dying()
258*cdf0e10cSrcweir     {
259*cdf0e10cSrcweir         m_rAntiImpl.dispose();
260*cdf0e10cSrcweir     }
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
263*cdf0e10cSrcweir     IMPL_LINK( AccessibleToolPanelTabBar_Impl, OnWindowEvent, const VclSimpleEvent*, i_pEvent )
264*cdf0e10cSrcweir     {
265*cdf0e10cSrcweir         ENSURE_OR_RETURN( !isDisposed(), "AccessibleToolPanelTabBar_Impl::OnWindowEvent: already disposed!", 0L );
266*cdf0e10cSrcweir 
267*cdf0e10cSrcweir         const VclWindowEvent* pWindowEvent( dynamic_cast< const VclWindowEvent* >( i_pEvent ) );
268*cdf0e10cSrcweir         if ( !pWindowEvent )
269*cdf0e10cSrcweir             return 0L;
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir         const bool bForwardButton = ( pWindowEvent->GetWindow() == &m_pTabBar->GetScrollButton( true ) );
272*cdf0e10cSrcweir         const bool bBackwardButton = ( pWindowEvent->GetWindow() == &m_pTabBar->GetScrollButton( false ) );
273*cdf0e10cSrcweir         ENSURE_OR_RETURN( bForwardButton || bBackwardButton, "AccessibleToolPanelTabBar_Impl::OnWindowEvent: where does this come from?", 0L );
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir         const bool bShow = ( i_pEvent->GetId() == VCLEVENT_WINDOW_SHOW );
276*cdf0e10cSrcweir         const bool bHide = ( i_pEvent->GetId() == VCLEVENT_WINDOW_HIDE );
277*cdf0e10cSrcweir         if ( !bShow && !bHide )
278*cdf0e10cSrcweir             // not interested in events other than visibility changes
279*cdf0e10cSrcweir             return 0L;
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir         const Reference< XAccessible > xButtonAccessible( m_pTabBar->GetScrollButton( bForwardButton ).GetAccessible() );
282*cdf0e10cSrcweir         const Any aOldChild( bHide ? xButtonAccessible : Reference< XAccessible >() );
283*cdf0e10cSrcweir         const Any aNewChild( bShow ? xButtonAccessible : Reference< XAccessible >() );
284*cdf0e10cSrcweir         m_rAntiImpl.NotifyAccessibleEvent( AccessibleEventId::CHILD, aOldChild, aNewChild );
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir         return 1L;
287*cdf0e10cSrcweir     }
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir 	//==================================================================================================================
290*cdf0e10cSrcweir 	//= MethodGuard
291*cdf0e10cSrcweir 	//==================================================================================================================
292*cdf0e10cSrcweir     namespace
293*cdf0e10cSrcweir     {
294*cdf0e10cSrcweir         class MethodGuard
295*cdf0e10cSrcweir         {
296*cdf0e10cSrcweir         public:
297*cdf0e10cSrcweir             MethodGuard( AccessibleToolPanelTabBar_Impl& i_rImpl )
298*cdf0e10cSrcweir                 :m_aGuard( Application::GetSolarMutex() )
299*cdf0e10cSrcweir             {
300*cdf0e10cSrcweir                 i_rImpl.checkDisposed();
301*cdf0e10cSrcweir             }
302*cdf0e10cSrcweir             ~MethodGuard()
303*cdf0e10cSrcweir             {
304*cdf0e10cSrcweir             }
305*cdf0e10cSrcweir 
306*cdf0e10cSrcweir             void clear()
307*cdf0e10cSrcweir             {
308*cdf0e10cSrcweir                 m_aGuard.clear();
309*cdf0e10cSrcweir             }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir         private:
312*cdf0e10cSrcweir             ::vos::OClearableGuard  m_aGuard;
313*cdf0e10cSrcweir         };
314*cdf0e10cSrcweir     }
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir 	//==================================================================================================================
317*cdf0e10cSrcweir 	//= AccessibleToolPanelTabBar
318*cdf0e10cSrcweir 	//==================================================================================================================
319*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
320*cdf0e10cSrcweir     AccessibleToolPanelTabBar::AccessibleToolPanelTabBar( const Reference< XAccessible >& i_rAccessibleParent,
321*cdf0e10cSrcweir             ::svt::IToolPanelDeck& i_rPanelDeck, ::svt::PanelTabBar& i_rTabBar )
322*cdf0e10cSrcweir         :AccessibleToolPanelTabBar_Base( i_rTabBar.GetWindowPeer() )
323*cdf0e10cSrcweir         ,m_pImpl( new AccessibleToolPanelTabBar_Impl( *this, i_rAccessibleParent, i_rPanelDeck, i_rTabBar ) )
324*cdf0e10cSrcweir     {
325*cdf0e10cSrcweir     }
326*cdf0e10cSrcweir 
327*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
328*cdf0e10cSrcweir     AccessibleToolPanelTabBar::~AccessibleToolPanelTabBar()
329*cdf0e10cSrcweir     {
330*cdf0e10cSrcweir     }
331*cdf0e10cSrcweir 
332*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
333*cdf0e10cSrcweir 	sal_Int32 SAL_CALL AccessibleToolPanelTabBar::getAccessibleChildCount(  ) throw (RuntimeException)
334*cdf0e10cSrcweir     {
335*cdf0e10cSrcweir         MethodGuard aGuard( *m_pImpl );
336*cdf0e10cSrcweir 
337*cdf0e10cSrcweir         const bool bHasScrollBack = m_pImpl->getTabBar()->GetScrollButton( false ).IsVisible();
338*cdf0e10cSrcweir         const bool bHasScrollForward = m_pImpl->getTabBar()->GetScrollButton( true ).IsVisible();
339*cdf0e10cSrcweir 
340*cdf0e10cSrcweir         return  m_pImpl->getPanelDeck()->GetPanelCount()
341*cdf0e10cSrcweir             +   ( bHasScrollBack ? 1 : 0 )
342*cdf0e10cSrcweir             +   ( bHasScrollForward ? 1 : 0 );
343*cdf0e10cSrcweir     }
344*cdf0e10cSrcweir 
345*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
346*cdf0e10cSrcweir 	Reference< XAccessible > SAL_CALL AccessibleToolPanelTabBar::getAccessibleChild( sal_Int32 i_nIndex ) throw (IndexOutOfBoundsException, RuntimeException)
347*cdf0e10cSrcweir     {
348*cdf0e10cSrcweir         MethodGuard aGuard( *m_pImpl );
349*cdf0e10cSrcweir 
350*cdf0e10cSrcweir         const bool bHasScrollBack = m_pImpl->getTabBar()->GetScrollButton( false ).IsVisible();
351*cdf0e10cSrcweir         const bool bHasScrollForward = m_pImpl->getTabBar()->GetScrollButton( true ).IsVisible();
352*cdf0e10cSrcweir 
353*cdf0e10cSrcweir         const bool bScrollBackRequested = ( bHasScrollBack && ( i_nIndex == 0 ) );
354*cdf0e10cSrcweir         const bool bScrollForwardRequested = ( bHasScrollForward && ( i_nIndex == getAccessibleChildCount() - 1 ) );
355*cdf0e10cSrcweir         OSL_ENSURE( !( bScrollBackRequested && bScrollForwardRequested ), "AccessibleToolPanelTabBar::getAccessibleChild: ouch!" );
356*cdf0e10cSrcweir 
357*cdf0e10cSrcweir         if ( bScrollBackRequested || bScrollForwardRequested )
358*cdf0e10cSrcweir         {
359*cdf0e10cSrcweir             Reference< XAccessible > xScrollButtonAccessible( m_pImpl->getTabBar()->GetScrollButton( bScrollForwardRequested ).GetAccessible() );
360*cdf0e10cSrcweir             ENSURE_OR_RETURN( xScrollButtonAccessible.is(), "AccessibleToolPanelTabBar::getAccessibleChild: invalid button accessible!", NULL );
361*cdf0e10cSrcweir         #if OSL_DEBUG_LEVEL > 0
362*cdf0e10cSrcweir             Reference< XAccessibleContext > xScrollButtonContext( xScrollButtonAccessible->getAccessibleContext() );
363*cdf0e10cSrcweir             ENSURE_OR_RETURN( xScrollButtonContext.is(), "AccessibleToolPanelTabBar::getAccessibleChild: invalid button accessible context!", xScrollButtonAccessible );
364*cdf0e10cSrcweir             OSL_ENSURE( xScrollButtonContext->getAccessibleParent() == m_pImpl->getOwnAccessible(),
365*cdf0e10cSrcweir                 "AccessibleToolPanelTabBar::getAccessibleChild: wrong parent at the button's accesible!" );
366*cdf0e10cSrcweir         #endif
367*cdf0e10cSrcweir             return xScrollButtonAccessible;
368*cdf0e10cSrcweir         }
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir         return m_pImpl->getAccessiblePanelItem( i_nIndex - ( bHasScrollBack ? 1 : 0 ) );
371*cdf0e10cSrcweir     }
372*cdf0e10cSrcweir 
373*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
374*cdf0e10cSrcweir 	Reference< XAccessible > SAL_CALL AccessibleToolPanelTabBar::getAccessibleParent(  ) throw (RuntimeException)
375*cdf0e10cSrcweir     {
376*cdf0e10cSrcweir         MethodGuard aGuard( *m_pImpl );
377*cdf0e10cSrcweir         return m_pImpl->getAccessibleParent();
378*cdf0e10cSrcweir     }
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
381*cdf0e10cSrcweir 	sal_Int16 SAL_CALL AccessibleToolPanelTabBar::getAccessibleRole(  ) throw (RuntimeException)
382*cdf0e10cSrcweir     {
383*cdf0e10cSrcweir         MethodGuard aGuard( *m_pImpl );
384*cdf0e10cSrcweir         return AccessibleRole::PAGE_TAB_LIST;
385*cdf0e10cSrcweir     }
386*cdf0e10cSrcweir 
387*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
388*cdf0e10cSrcweir     namespace
389*cdf0e10cSrcweir     {
390*cdf0e10cSrcweir         bool lcl_covers( const ::Window& i_rWindow, const ::Point& i_rPoint )
391*cdf0e10cSrcweir         {
392*cdf0e10cSrcweir             const Rectangle aWindowBounds( i_rWindow.GetWindowExtentsRelative( i_rWindow.GetParent() ) );
393*cdf0e10cSrcweir             return aWindowBounds.IsInside( i_rPoint );
394*cdf0e10cSrcweir         }
395*cdf0e10cSrcweir     }
396*cdf0e10cSrcweir 
397*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
398*cdf0e10cSrcweir 	Reference< XAccessible > SAL_CALL AccessibleToolPanelTabBar::getAccessibleAtPoint( const UnoPoint& i_rPoint ) throw (RuntimeException)
399*cdf0e10cSrcweir     {
400*cdf0e10cSrcweir         MethodGuard aGuard( *m_pImpl );
401*cdf0e10cSrcweir 
402*cdf0e10cSrcweir         // check the tab items
403*cdf0e10cSrcweir         const UnoPoint aOwnScreenPos( getLocationOnScreen() );
404*cdf0e10cSrcweir         const ::Point aRequestedScreenPoint( i_rPoint.X + aOwnScreenPos.X, i_rPoint.Y + aOwnScreenPos.Y );
405*cdf0e10cSrcweir 
406*cdf0e10cSrcweir         for ( size_t i=0; i<m_pImpl->getPanelDeck()->GetPanelCount(); ++i )
407*cdf0e10cSrcweir         {
408*cdf0e10cSrcweir             const ::Rectangle aItemScreenRect( m_pImpl->getTabBar()->GetItemScreenRect(i) );
409*cdf0e10cSrcweir             if ( aItemScreenRect.IsInside( aRequestedScreenPoint ) )
410*cdf0e10cSrcweir                 return m_pImpl->getAccessiblePanelItem(i);
411*cdf0e10cSrcweir         }
412*cdf0e10cSrcweir 
413*cdf0e10cSrcweir         // check the scroll buttons
414*cdf0e10cSrcweir         const ::Point aRequestedClientPoint( VCLUnoHelper::ConvertToVCLPoint( i_rPoint ) );
415*cdf0e10cSrcweir 
416*cdf0e10cSrcweir         const bool bHasScrollBack = m_pImpl->getTabBar()->GetScrollButton( false ).IsVisible();
417*cdf0e10cSrcweir         if ( bHasScrollBack && lcl_covers( m_pImpl->getTabBar()->GetScrollButton( false ), aRequestedClientPoint ) )
418*cdf0e10cSrcweir             return m_pImpl->getTabBar()->GetScrollButton( false ).GetAccessible();
419*cdf0e10cSrcweir 
420*cdf0e10cSrcweir         const bool bHasScrollForward = m_pImpl->getTabBar()->GetScrollButton( true ).IsVisible();
421*cdf0e10cSrcweir         if ( bHasScrollForward && lcl_covers( m_pImpl->getTabBar()->GetScrollButton( true ), aRequestedClientPoint ) )
422*cdf0e10cSrcweir             return m_pImpl->getTabBar()->GetScrollButton( true ).GetAccessible();
423*cdf0e10cSrcweir 
424*cdf0e10cSrcweir         // no hit
425*cdf0e10cSrcweir         return NULL;
426*cdf0e10cSrcweir     }
427*cdf0e10cSrcweir 
428*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
429*cdf0e10cSrcweir     void SAL_CALL AccessibleToolPanelTabBar::disposing()
430*cdf0e10cSrcweir     {
431*cdf0e10cSrcweir         AccessibleToolPanelTabBar_Base::disposing();
432*cdf0e10cSrcweir         m_pImpl->dispose();
433*cdf0e10cSrcweir     }
434*cdf0e10cSrcweir 
435*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
436*cdf0e10cSrcweir     Reference< XAccessible > AccessibleToolPanelTabBar::GetChildAccessible( const VclWindowEvent& i_rVclWindowEvent )
437*cdf0e10cSrcweir     {
438*cdf0e10cSrcweir         // don't let the base class generate any A11Y events from VclWindowEvent, we completely manage those
439*cdf0e10cSrcweir         // A11Y events ourself
440*cdf0e10cSrcweir         (void)i_rVclWindowEvent;
441*cdf0e10cSrcweir         return NULL;
442*cdf0e10cSrcweir     }
443*cdf0e10cSrcweir 
444*cdf0e10cSrcweir 	//------------------------------------------------------------------------------------------------------------------
445*cdf0e10cSrcweir     void AccessibleToolPanelTabBar::FillAccessibleStateSet( ::utl::AccessibleStateSetHelper& i_rStateSet )
446*cdf0e10cSrcweir     {
447*cdf0e10cSrcweir         AccessibleToolPanelTabBar_Base::FillAccessibleStateSet( i_rStateSet );
448*cdf0e10cSrcweir         i_rStateSet.AddState( AccessibleStateType::FOCUSABLE );
449*cdf0e10cSrcweir 
450*cdf0e10cSrcweir         ENSURE_OR_RETURN_VOID( !m_pImpl->isDisposed(), "AccessibleToolPanelTabBar::FillAccessibleStateSet: already disposed!" );
451*cdf0e10cSrcweir         if ( m_pImpl->getTabBar()->IsVertical() )
452*cdf0e10cSrcweir             i_rStateSet.AddState( AccessibleStateType::VERTICAL );
453*cdf0e10cSrcweir         else
454*cdf0e10cSrcweir             i_rStateSet.AddState( AccessibleStateType::HORIZONTAL );
455*cdf0e10cSrcweir     }
456*cdf0e10cSrcweir 
457*cdf0e10cSrcweir //......................................................................................................................
458*cdf0e10cSrcweir } // namespace accessibility
459*cdf0e10cSrcweir //......................................................................................................................
460