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/standard/vclxaccessibletabpagewindow.hxx>
31 #include <toolkit/helper/convert.hxx>
32 #include <vcl/tabctrl.hxx>
33 #include <vcl/tabpage.hxx>
34 
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::accessibility;
39 using namespace ::comphelper;
40 
41 
42 //	----------------------------------------------------
43 //	class VCLXAccessibleTabPageWindow
44 //	----------------------------------------------------
45 
46 VCLXAccessibleTabPageWindow::VCLXAccessibleTabPageWindow( VCLXWindow* pVCLXWindow )
47 	:VCLXAccessibleComponent( pVCLXWindow )
48 {
49     m_pTabPage = static_cast< TabPage* >( GetWindow() );
50     if ( m_pTabPage )
51     {
52         Window* pParent = m_pTabPage->GetAccessibleParentWindow();
53         if ( pParent && pParent->GetType() == WINDOW_TABCONTROL )
54         {
55 		    m_pTabControl = static_cast< TabControl* >( pParent );
56 		    if ( m_pTabControl )
57 		    {
58 			    for ( sal_uInt16 i = 0, nCount = m_pTabControl->GetPageCount(); i < nCount; ++i )
59 			    {
60 				    sal_uInt16 nPageId = m_pTabControl->GetPageId( i );
61 				    if ( m_pTabControl->GetTabPage( nPageId ) == m_pTabPage )
62                         m_nPageId = nPageId;
63                 }
64             }
65         }
66     }
67 }
68 
69 // -----------------------------------------------------------------------------
70 
71 VCLXAccessibleTabPageWindow::~VCLXAccessibleTabPageWindow()
72 {
73 }
74 
75 // -----------------------------------------------------------------------------
76 // OCommonAccessibleComponent
77 // -----------------------------------------------------------------------------
78 
79 awt::Rectangle VCLXAccessibleTabPageWindow::implGetBounds() throw (RuntimeException)
80 {
81     awt::Rectangle aBounds( 0, 0, 0, 0 );
82 
83     if ( m_pTabControl )
84     {
85         Rectangle aPageRect = m_pTabControl->GetTabBounds( m_nPageId );
86         if ( m_pTabPage )
87         {
88             Rectangle aRect = Rectangle( m_pTabPage->GetPosPixel(), m_pTabPage->GetSizePixel() );
89             aRect.Move( -aPageRect.Left(), -aPageRect.Top() );
90             aBounds = AWTRectangle( aRect );
91         }
92     }
93 
94 	return aBounds;
95 }
96 
97 // -----------------------------------------------------------------------------
98 // XComponent
99 // -----------------------------------------------------------------------------
100 
101 void VCLXAccessibleTabPageWindow::disposing()
102 {
103 	VCLXAccessibleComponent::disposing();
104 
105     m_pTabControl = NULL;
106     m_pTabPage = NULL;
107 }
108 
109 // -----------------------------------------------------------------------------
110 // XAccessibleContext
111 // -----------------------------------------------------------------------------
112 
113 Reference< XAccessible > VCLXAccessibleTabPageWindow::getAccessibleParent(  ) throw (RuntimeException)
114 {
115     OExternalLockGuard aGuard( this );
116 
117 	Reference< XAccessible > xParent;
118     if ( m_pTabControl )
119     {
120         Reference< XAccessible > xAcc( m_pTabControl->GetAccessible() );
121         if ( xAcc.is() )
122         {
123             Reference< XAccessibleContext > xCont( xAcc->getAccessibleContext() );
124             if ( xCont.is() )
125                 xParent = xCont->getAccessibleChild( m_pTabControl->GetPagePos( m_nPageId ) );
126         }
127     }
128 
129 	return xParent;
130 }
131 
132 // -----------------------------------------------------------------------------
133 
134 sal_Int32 VCLXAccessibleTabPageWindow::getAccessibleIndexInParent(  ) throw (RuntimeException)
135 {
136 	OExternalLockGuard aGuard( this );
137 
138     return 0;
139 }
140 
141 // -----------------------------------------------------------------------------
142