1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_accessibility.hxx"
26 #include <accessibility/standard/vclxaccessibletabpagewindow.hxx>
27 #include <toolkit/helper/convert.hxx>
28 #include <vcl/tabctrl.hxx>
29 #include <vcl/tabpage.hxx>
30 
31 
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::accessibility;
35 using namespace ::comphelper;
36 
37 
38 //	----------------------------------------------------
39 //	class VCLXAccessibleTabPageWindow
40 //	----------------------------------------------------
41 
42 VCLXAccessibleTabPageWindow::VCLXAccessibleTabPageWindow( VCLXWindow* pVCLXWindow )
43 	:VCLXAccessibleComponent( pVCLXWindow )
44 {
45     m_pTabPage = static_cast< TabPage* >( GetWindow() );
46     if ( m_pTabPage )
47     {
48         Window* pParent = m_pTabPage->GetAccessibleParentWindow();
49         if ( pParent && pParent->GetType() == WINDOW_TABCONTROL )
50         {
51 		    m_pTabControl = static_cast< TabControl* >( pParent );
52 		    if ( m_pTabControl )
53 		    {
54 			    for ( sal_uInt16 i = 0, nCount = m_pTabControl->GetPageCount(); i < nCount; ++i )
55 			    {
56 				    sal_uInt16 nPageId = m_pTabControl->GetPageId( i );
57 				    if ( m_pTabControl->GetTabPage( nPageId ) == m_pTabPage )
58                         m_nPageId = nPageId;
59                 }
60             }
61         }
62     }
63 }
64 
65 // -----------------------------------------------------------------------------
66 
67 VCLXAccessibleTabPageWindow::~VCLXAccessibleTabPageWindow()
68 {
69 }
70 
71 // -----------------------------------------------------------------------------
72 // OCommonAccessibleComponent
73 // -----------------------------------------------------------------------------
74 
75 awt::Rectangle VCLXAccessibleTabPageWindow::implGetBounds() throw (RuntimeException)
76 {
77     awt::Rectangle aBounds( 0, 0, 0, 0 );
78 
79     if ( m_pTabControl )
80     {
81         Rectangle aPageRect = m_pTabControl->GetTabBounds( m_nPageId );
82         if ( m_pTabPage )
83         {
84             Rectangle aRect = Rectangle( m_pTabPage->GetPosPixel(), m_pTabPage->GetSizePixel() );
85             aRect.Move( -aPageRect.Left(), -aPageRect.Top() );
86             aBounds = AWTRectangle( aRect );
87         }
88     }
89 
90 	return aBounds;
91 }
92 
93 // -----------------------------------------------------------------------------
94 // XComponent
95 // -----------------------------------------------------------------------------
96 
97 void VCLXAccessibleTabPageWindow::disposing()
98 {
99 	VCLXAccessibleComponent::disposing();
100 
101     m_pTabControl = NULL;
102     m_pTabPage = NULL;
103 }
104 
105 // -----------------------------------------------------------------------------
106 // XAccessibleContext
107 // -----------------------------------------------------------------------------
108 
109 Reference< XAccessible > VCLXAccessibleTabPageWindow::getAccessibleParent(  ) throw (RuntimeException)
110 {
111     OExternalLockGuard aGuard( this );
112 
113 	Reference< XAccessible > xParent;
114     if ( m_pTabControl )
115     {
116         Reference< XAccessible > xAcc( m_pTabControl->GetAccessible() );
117         if ( xAcc.is() )
118         {
119             Reference< XAccessibleContext > xCont( xAcc->getAccessibleContext() );
120             if ( xCont.is() )
121                 xParent = xCont->getAccessibleChild( m_pTabControl->GetPagePos( m_nPageId ) );
122         }
123     }
124 
125 	return xParent;
126 }
127 
128 // -----------------------------------------------------------------------------
129 
130 sal_Int32 VCLXAccessibleTabPageWindow::getAccessibleIndexInParent(  ) throw (RuntimeException)
131 {
132 	OExternalLockGuard aGuard( this );
133 
134     return 0;
135 }
136 
137 // -----------------------------------------------------------------------------
138