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 
27 
28 #include "accessibility/extended/AccessibleBrowseBoxTable.hxx"
29 #include <svtools/accessibletableprovider.hxx>
30 
31 // ============================================================================
32 
33 using ::rtl::OUString;
34 
35 using ::com::sun::star::uno::Reference;
36 using ::com::sun::star::uno::Sequence;
37 using ::com::sun::star::uno::Any;
38 
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::accessibility;
41 using namespace ::svt;
42 
43 // ============================================================================
44 
45 namespace accessibility {
46 
47 // ============================================================================
48 
49 // Ctor/Dtor/disposing --------------------------------------------------------
50 
DBG_NAME(AccessibleBrowseBoxTable)51 DBG_NAME( AccessibleBrowseBoxTable )
52 
53 AccessibleBrowseBoxTable::AccessibleBrowseBoxTable(
54         const Reference< XAccessible >& rxParent,
55         IAccessibleTableProvider&                      rBrowseBox ) :
56     AccessibleBrowseBoxTableBase( rxParent, rBrowseBox, BBTYPE_TABLE )
57 {
58     DBG_CTOR( AccessibleBrowseBoxTable, NULL );
59 }
60 
~AccessibleBrowseBoxTable()61 AccessibleBrowseBoxTable::~AccessibleBrowseBoxTable()
62 {
63     DBG_DTOR( AccessibleBrowseBoxTable, NULL );
64 }
65 
66 // XAccessibleContext ---------------------------------------------------------
67 
68 Reference< XAccessible > SAL_CALL
getAccessibleChild(sal_Int32 nChildIndex)69 AccessibleBrowseBoxTable::getAccessibleChild( sal_Int32 nChildIndex )
70     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
71 {
72     BBSolarGuard aSolarGuard;
73     ::osl::MutexGuard aGuard( getOslMutex() );
74     ensureIsAlive();
75     ensureIsValidIndex( nChildIndex );
76     return mpBrowseBox->CreateAccessibleCell(
77         implGetRow( nChildIndex ), (sal_Int16)implGetColumn( nChildIndex ) );
78 }
79 
getAccessibleIndexInParent()80 sal_Int32 SAL_CALL AccessibleBrowseBoxTable::getAccessibleIndexInParent()
81     throw ( uno::RuntimeException )
82 {
83     ensureIsAlive();
84     return BBINDEX_TABLE;
85 }
86 
87 // XAccessibleComponent -------------------------------------------------------
88 
89 Reference< XAccessible > SAL_CALL
getAccessibleAtPoint(const awt::Point & rPoint)90 AccessibleBrowseBoxTable::getAccessibleAtPoint( const awt::Point& rPoint )
91     throw ( uno::RuntimeException )
92 {
93     BBSolarGuard aSolarGuard;
94     ::osl::MutexGuard aGuard( getOslMutex() );
95     ensureIsAlive();
96 
97     Reference< XAccessible > xChild;
98     sal_Int32 nRow = 0;
99     sal_uInt16 nColumnPos = 0;
100     if( mpBrowseBox->ConvertPointToCellAddress( nRow, nColumnPos, VCLPoint( rPoint ) ) )
101         xChild = mpBrowseBox->CreateAccessibleCell( nRow, nColumnPos );
102 
103     return xChild;
104 }
105 
grabFocus()106 void SAL_CALL AccessibleBrowseBoxTable::grabFocus()
107     throw ( uno::RuntimeException )
108 {
109     BBSolarGuard aSolarGuard;
110     ::osl::MutexGuard aGuard( getOslMutex() );
111     ensureIsAlive();
112     mpBrowseBox->GrabTableFocus();
113 }
114 
getAccessibleKeyBinding()115 Any SAL_CALL AccessibleBrowseBoxTable::getAccessibleKeyBinding()
116     throw ( uno::RuntimeException )
117 {
118     ensureIsAlive();
119     return Any();   // no special key bindings for data table
120 }
121 
122 // XAccessibleTable -----------------------------------------------------------
123 
getAccessibleRowDescription(sal_Int32 nRow)124 OUString SAL_CALL AccessibleBrowseBoxTable::getAccessibleRowDescription( sal_Int32 nRow )
125     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
126 {
127     BBSolarGuard aSolarGuard;
128     ::osl::MutexGuard aGuard( getOslMutex() );
129     ensureIsAlive();
130     ensureIsValidRow( nRow );
131     return mpBrowseBox->GetRowDescription( nRow );
132 }
133 
getAccessibleColumnDescription(sal_Int32 nColumn)134 OUString SAL_CALL AccessibleBrowseBoxTable::getAccessibleColumnDescription( sal_Int32 nColumn )
135     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
136 {
137     BBSolarGuard aSolarGuard;
138     ::osl::MutexGuard aGuard( getOslMutex() );
139     ensureIsAlive();
140     ensureIsValidColumn( nColumn );
141     return mpBrowseBox->GetColumnDescription( (sal_uInt16)nColumn );
142 }
143 
getAccessibleRowHeaders()144 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxTable::getAccessibleRowHeaders()
145     throw ( uno::RuntimeException )
146 {
147     ::osl::MutexGuard aGuard( getOslMutex() );
148     ensureIsAlive();
149     return implGetHeaderBar( BBINDEX_ROWHEADERBAR );
150 }
151 
getAccessibleColumnHeaders()152 Reference< XAccessibleTable > SAL_CALL AccessibleBrowseBoxTable::getAccessibleColumnHeaders()
153     throw ( uno::RuntimeException )
154 {
155     ::osl::MutexGuard aGuard( getOslMutex() );
156     ensureIsAlive();
157     return implGetHeaderBar( BBINDEX_COLUMNHEADERBAR );
158 }
159 
getSelectedAccessibleRows()160 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxTable::getSelectedAccessibleRows()
161     throw ( uno::RuntimeException )
162 {
163     BBSolarGuard aSolarGuard;
164     ::osl::MutexGuard aGuard( getOslMutex() );
165     ensureIsAlive();
166 
167     Sequence< sal_Int32 > aSelSeq;
168     implGetSelectedRows( aSelSeq );
169     return aSelSeq;
170 }
171 
getSelectedAccessibleColumns()172 Sequence< sal_Int32 > SAL_CALL AccessibleBrowseBoxTable::getSelectedAccessibleColumns()
173     throw ( uno::RuntimeException )
174 {
175     BBSolarGuard aSolarGuard;
176     ::osl::MutexGuard aGuard( getOslMutex() );
177     ensureIsAlive();
178 
179     Sequence< sal_Int32 > aSelSeq;
180     implGetSelectedColumns( aSelSeq );
181     return aSelSeq;
182 }
183 
isAccessibleRowSelected(sal_Int32 nRow)184 sal_Bool SAL_CALL AccessibleBrowseBoxTable::isAccessibleRowSelected( sal_Int32 nRow )
185     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
186 {
187     BBSolarGuard aSolarGuard;
188     ::osl::MutexGuard aGuard( getOslMutex() );
189     ensureIsAlive();
190     ensureIsValidRow( nRow );
191     return implIsRowSelected( nRow );
192 }
193 
isAccessibleColumnSelected(sal_Int32 nColumn)194 sal_Bool SAL_CALL AccessibleBrowseBoxTable::isAccessibleColumnSelected( sal_Int32 nColumn )
195     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
196 {
197     BBSolarGuard aSolarGuard;
198     ::osl::MutexGuard aGuard( getOslMutex() );
199     ensureIsAlive();
200     ensureIsValidColumn( nColumn );
201     return implIsColumnSelected( nColumn );
202 }
203 
getAccessibleCellAt(sal_Int32 nRow,sal_Int32 nColumn)204 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxTable::getAccessibleCellAt(
205         sal_Int32 nRow, sal_Int32 nColumn )
206     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
207 {
208     BBSolarGuard aSolarGuard;
209     ::osl::MutexGuard aGuard( getOslMutex() );
210     ensureIsAlive();
211     ensureIsValidAddress( nRow, nColumn );
212     return mpBrowseBox->CreateAccessibleCell( nRow, (sal_Int16)nColumn );
213 }
214 
isAccessibleSelected(sal_Int32 nRow,sal_Int32 nColumn)215 sal_Bool SAL_CALL AccessibleBrowseBoxTable::isAccessibleSelected(
216         sal_Int32 nRow, sal_Int32 nColumn )
217     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
218 {
219     BBSolarGuard aSolarGuard;
220     ::osl::MutexGuard aGuard( getOslMutex() );
221     ensureIsAlive();
222     ensureIsValidAddress( nRow, nColumn );
223     return implIsRowSelected( nRow ) || implIsColumnSelected( nColumn );
224 }
225 
226 // XServiceInfo ---------------------------------------------------------------
227 
getImplementationName()228 OUString SAL_CALL AccessibleBrowseBoxTable::getImplementationName()
229     throw ( uno::RuntimeException )
230 {
231     return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.AccessibleBrowseBoxTable" ) );
232 }
233 
234 // internal virtual methods ---------------------------------------------------
235 
implGetBoundingBox()236 Rectangle AccessibleBrowseBoxTable::implGetBoundingBox()
237 {
238 	return mpBrowseBox->calcTableRect(sal_False);
239 }
240 
implGetBoundingBoxOnScreen()241 Rectangle AccessibleBrowseBoxTable::implGetBoundingBoxOnScreen()
242 {
243     return mpBrowseBox->calcTableRect();
244 }
245 
246 // internal helper methods ----------------------------------------------------
247 
implGetHeaderBar(sal_Int32 nChildIndex)248 Reference< XAccessibleTable > AccessibleBrowseBoxTable::implGetHeaderBar(
249         sal_Int32 nChildIndex )
250     throw ( uno::RuntimeException )
251 {
252     Reference< XAccessible > xRet;
253     Reference< XAccessibleContext > xContext( mxParent, uno::UNO_QUERY );
254     if( xContext.is() )
255     {
256         try
257         {
258             xRet = xContext->getAccessibleChild( nChildIndex );
259         }
260         catch( lang::IndexOutOfBoundsException& )
261         {
262             DBG_ERROR( "implGetHeaderBar - wrong child index" );
263         }
264         // RuntimeException goes to caller
265     }
266     return Reference< XAccessibleTable >( xRet, uno::UNO_QUERY );
267 }
268 
269 // ============================================================================
270 
271 } // namespace accessibility
272 
273 // ============================================================================
274 
275