1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_accessibility.hxx"
30 #include "accessibility/extended/accessibletabbarbase.hxx"
31 #ifndef ACCESSIBILITY_EXT_ACCESSIBLETABBARPAGELIST
32 #include "accessibility/extended/accessibletabbarpagelist.hxx"
33 #endif
34 #include <toolkit/helper/externallock.hxx>
35 #include <svtools/tabbar.hxx>
36 
37 //.........................................................................
38 namespace accessibility
39 {
40 //.........................................................................
41 
42 AccessibleTabBarBase::AccessibleTabBarBase( TabBar* pTabBar ) :
43     AccessibleExtendedComponentHelper_BASE( new VCLExternalSolarLock() ),
44     m_pTabBar( 0 )
45 {
46     m_pExternalLock = static_cast< VCLExternalSolarLock* >( getExternalLock() );
47     SetTabBarPointer( pTabBar );
48 }
49 
50 AccessibleTabBarBase::~AccessibleTabBarBase()
51 {
52     ClearTabBarPointer();
53     DELETEZ( m_pExternalLock );
54 }
55 
56 IMPL_LINK( AccessibleTabBarBase, WindowEventListener, VclSimpleEvent*, pEvent )
57 {
58     VclWindowEvent* pWinEvent = dynamic_cast< VclWindowEvent* >( pEvent );
59     DBG_ASSERT( pWinEvent, "AccessibleTabBarBase::WindowEventListener - unknown window event" );
60     if( pWinEvent )
61     {
62         Window* pEventWindow = pWinEvent->GetWindow();
63         DBG_ASSERT( pEventWindow, "AccessibleTabBarBase::WindowEventListener: no window!" );
64 
65         if( ( pWinEvent->GetId() == VCLEVENT_TABBAR_PAGEREMOVED ) &&
66             ( (sal_uInt16)(sal_IntPtr) pWinEvent->GetData() == TabBar::PAGE_NOT_FOUND ) &&
67             ( dynamic_cast< AccessibleTabBarPageList *> (this) != NULL ) )
68         {
69             return 0;
70         }
71 
72         if ( !pEventWindow->IsAccessibilityEventsSuppressed() || (pWinEvent->GetId() == VCLEVENT_OBJECT_DYING) )
73             ProcessWindowEvent( *pWinEvent );
74     }
75     return 0;
76 }
77 
78 void AccessibleTabBarBase::ProcessWindowEvent( const VclWindowEvent& rVclWindowEvent )
79 {
80     if( rVclWindowEvent.GetId() == VCLEVENT_OBJECT_DYING )
81         ClearTabBarPointer();
82 }
83 
84 // XComponent
85 
86 void AccessibleTabBarBase::disposing()
87 {
88     AccessibleExtendedComponentHelper_BASE::disposing();
89     ClearTabBarPointer();
90 }
91 
92 // private
93 
94 void AccessibleTabBarBase::SetTabBarPointer( TabBar* pTabBar )
95 {
96     DBG_ASSERT( !m_pTabBar, "AccessibleTabBarBase::SetTabBarPointer - multiple call" );
97     m_pTabBar = pTabBar;
98     if( m_pTabBar )
99         m_pTabBar->AddEventListener( LINK( this, AccessibleTabBarBase, WindowEventListener ) );
100 }
101 
102 void AccessibleTabBarBase::ClearTabBarPointer()
103 {
104     if( m_pTabBar )
105     {
106         m_pTabBar->RemoveEventListener( LINK( this, AccessibleTabBarBase, WindowEventListener ) );
107         m_pTabBar = 0;
108     }
109 }
110 
111 //.........................................................................
112 }   // namespace accessibility
113 //.........................................................................
114 
115