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