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 
31 
32 #include "accessibility/extended/AccessibleBrowseBoxTableBase.hxx"
33 #include <svtools/accessibletableprovider.hxx>
34 #include <tools/multisel.hxx>
35 #include <comphelper/sequence.hxx>
36 
37 // ============================================================================
38 
39 using ::rtl::OUString;
40 
41 using ::com::sun::star::uno::Reference;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Any;
44 
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::accessibility;
47 using namespace ::svt;
48 
49 // ============================================================================
50 
51 namespace accessibility {
52 
53 // ============================================================================
54 
55 // Ctor/Dtor/disposing --------------------------------------------------------
56 
57 DBG_NAME( AccessibleBrowseBoxTableBase )
58 
59 AccessibleBrowseBoxTableBase::AccessibleBrowseBoxTableBase(
60         const Reference< XAccessible >& rxParent,
61         IAccessibleTableProvider&                      rBrowseBox,
62         AccessibleBrowseBoxObjType      eObjType ) :
63     BrowseBoxAccessibleElement( rxParent, rBrowseBox,NULL, eObjType )
64 {
65     DBG_CTOR( AccessibleBrowseBoxTableBase, NULL );
66 }
67 
68 AccessibleBrowseBoxTableBase::~AccessibleBrowseBoxTableBase()
69 {
70     DBG_DTOR( AccessibleBrowseBoxTableBase, NULL );
71 }
72 
73 // XAccessibleContext ---------------------------------------------------------
74 
75 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleChildCount()
76     throw ( uno::RuntimeException )
77 {
78     BBSolarGuard aSolarGuard;
79     ::osl::MutexGuard aGuard( getOslMutex() );
80     ensureIsAlive();
81     return implGetChildCount();
82 }
83 
84 sal_Int16 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRole()
85     throw ( uno::RuntimeException )
86 {
87     ensureIsAlive();
88     return AccessibleRole::TABLE;
89 }
90 
91 // XAccessibleTable -----------------------------------------------------------
92 
93 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRowCount()
94     throw ( uno::RuntimeException )
95 {
96     BBSolarGuard aSolarGuard;
97     ::osl::MutexGuard aGuard( getOslMutex() );
98     ensureIsAlive();
99     return implGetRowCount();
100 }
101 
102 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumnCount()
103     throw ( uno::RuntimeException )
104 {
105     BBSolarGuard aSolarGuard;
106     ::osl::MutexGuard aGuard( getOslMutex() );
107     ensureIsAlive();
108     return implGetColumnCount();
109 }
110 
111 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRowExtentAt(
112         sal_Int32 nRow, sal_Int32 nColumn )
113     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
114 {
115     BBSolarGuard aSolarGuard;
116     ::osl::MutexGuard aGuard( getOslMutex() );
117     ensureIsAlive();
118     ensureIsValidAddress( nRow, nColumn );
119     return 1;   // merged cells not supported
120 }
121 
122 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumnExtentAt(
123         sal_Int32 nRow, sal_Int32 nColumn )
124     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
125 {
126     BBSolarGuard aSolarGuard;
127     ::osl::MutexGuard aGuard( getOslMutex() );
128     ensureIsAlive();
129     ensureIsValidAddress( nRow, nColumn );
130     return 1;   // merged cells not supported
131 }
132 
133 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleCaption()
134     throw ( uno::RuntimeException )
135 {
136     ensureIsAlive();
137     return NULL;    // not supported
138 }
139 
140 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleSummary()
141     throw ( uno::RuntimeException )
142 {
143     ensureIsAlive();
144     return NULL;    // not supported
145 }
146 
147 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleIndex(
148         sal_Int32 nRow, sal_Int32 nColumn )
149     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
150 {
151     BBSolarGuard aSolarGuard;
152     ::osl::MutexGuard aGuard( getOslMutex() );
153     ensureIsAlive();
154     ensureIsValidAddress( nRow, nColumn );
155     return implGetChildIndex( nRow, nColumn );
156 }
157 
158 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRow( sal_Int32 nChildIndex )
159     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
160 {
161     BBSolarGuard aSolarGuard;
162     ::osl::MutexGuard aGuard( getOslMutex() );
163     ensureIsAlive();
164     ensureIsValidIndex( nChildIndex );
165     return implGetRow( nChildIndex );
166 }
167 
168 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumn( sal_Int32 nChildIndex )
169     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
170 {
171     BBSolarGuard aSolarGuard;
172     ::osl::MutexGuard aGuard( getOslMutex() );
173     ensureIsAlive();
174     ensureIsValidIndex( nChildIndex );
175     return implGetColumn( nChildIndex );
176 }
177 
178 // XInterface -----------------------------------------------------------------
179 
180 Any SAL_CALL AccessibleBrowseBoxTableBase::queryInterface( const uno::Type& rType )
181     throw ( uno::RuntimeException )
182 {
183     Any aAny( BrowseBoxAccessibleElement::queryInterface( rType ) );
184     return aAny.hasValue() ?
185         aAny : AccessibleBrowseBoxTableImplHelper::queryInterface( rType );
186 }
187 
188 void SAL_CALL AccessibleBrowseBoxTableBase::acquire() throw ()
189 {
190     BrowseBoxAccessibleElement::acquire();
191 }
192 
193 void SAL_CALL AccessibleBrowseBoxTableBase::release() throw ()
194 {
195     BrowseBoxAccessibleElement::release();
196 }
197 
198 // XTypeProvider --------------------------------------------------------------
199 
200 Sequence< uno::Type > SAL_CALL AccessibleBrowseBoxTableBase::getTypes()
201     throw ( uno::RuntimeException )
202 {
203     return ::comphelper::concatSequences(
204         BrowseBoxAccessibleElement::getTypes(),
205         AccessibleBrowseBoxTableImplHelper::getTypes() );
206 }
207 
208 Sequence< sal_Int8 > SAL_CALL AccessibleBrowseBoxTableBase::getImplementationId()
209     throw ( uno::RuntimeException )
210 {
211     ::osl::MutexGuard aGuard( getOslGlobalMutex() );
212     static Sequence< sal_Int8 > aId;
213     implCreateUuid( aId );
214 	return aId;
215 }
216 
217 // internal virtual methods ---------------------------------------------------
218 
219 sal_Int32 AccessibleBrowseBoxTableBase::implGetRowCount() const
220 {
221     return mpBrowseBox->GetRowCount();
222 }
223 
224 sal_Int32 AccessibleBrowseBoxTableBase::implGetColumnCount() const
225 {
226     sal_uInt16 nColumns = mpBrowseBox->GetColumnCount();
227     // do not count the "handle column"
228     if( nColumns && implHasHandleColumn() )
229         --nColumns;
230     return nColumns;
231 }
232 
233 // internal helper methods ----------------------------------------------------
234 
235 sal_Bool AccessibleBrowseBoxTableBase::implHasHandleColumn() const
236 {
237     return mpBrowseBox->HasRowHeader();
238 }
239 
240 sal_uInt16 AccessibleBrowseBoxTableBase::implToVCLColumnPos( sal_Int32 nColumn ) const
241 {
242     sal_uInt16 nVCLPos = 0;
243     if( (0 <= nColumn) && (nColumn < implGetColumnCount()) )
244     {
245         // regard "handle column"
246         if( implHasHandleColumn() )
247             ++nColumn;
248         nVCLPos = static_cast< sal_uInt16 >( nColumn );
249     }
250     return nVCLPos;
251 }
252 
253 sal_Int32 AccessibleBrowseBoxTableBase::implGetChildCount() const
254 {
255     return implGetRowCount() * implGetColumnCount();
256 }
257 
258 sal_Int32 AccessibleBrowseBoxTableBase::implGetRow( sal_Int32 nChildIndex ) const
259 {
260     sal_Int32 nColumns = implGetColumnCount();
261     return nColumns ? (nChildIndex / nColumns) : 0;
262 }
263 
264 sal_Int32 AccessibleBrowseBoxTableBase::implGetColumn( sal_Int32 nChildIndex ) const
265 {
266     sal_Int32 nColumns = implGetColumnCount();
267     return nColumns ? (nChildIndex % nColumns) : 0;
268 }
269 
270 sal_Int32 AccessibleBrowseBoxTableBase::implGetChildIndex(
271         sal_Int32 nRow, sal_Int32 nColumn ) const
272 {
273     return nRow * implGetColumnCount() + nColumn;
274 }
275 
276 sal_Bool AccessibleBrowseBoxTableBase::implIsRowSelected( sal_Int32 nRow ) const
277 {
278     return mpBrowseBox->IsRowSelected( nRow );
279 }
280 
281 sal_Bool AccessibleBrowseBoxTableBase::implIsColumnSelected( sal_Int32 nColumn ) const
282 {
283     if( implHasHandleColumn() )
284         --nColumn;
285     return mpBrowseBox->IsColumnSelected( nColumn );
286 }
287 
288 void AccessibleBrowseBoxTableBase::implSelectRow( sal_Int32 nRow, sal_Bool bSelect )
289 {
290     mpBrowseBox->SelectRow( nRow, bSelect, sal_True );
291 }
292 
293 void AccessibleBrowseBoxTableBase::implSelectColumn( sal_Int32 nColumnPos, sal_Bool bSelect )
294 {
295     mpBrowseBox->SelectColumn( (sal_uInt16)nColumnPos, bSelect );
296 }
297 
298 sal_Int32 AccessibleBrowseBoxTableBase::implGetSelectedRowCount() const
299 {
300     return mpBrowseBox->GetSelectedRowCount();
301 }
302 
303 sal_Int32 AccessibleBrowseBoxTableBase::implGetSelectedColumnCount() const
304 {
305     return mpBrowseBox->GetSelectedColumnCount();
306 }
307 
308 void AccessibleBrowseBoxTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq )
309 {
310     mpBrowseBox->GetAllSelectedRows( rSeq );
311 }
312 
313 void AccessibleBrowseBoxTableBase::implGetSelectedColumns( Sequence< sal_Int32 >& rSeq )
314 {
315 	mpBrowseBox->GetAllSelectedColumns( rSeq );
316 }
317 
318 void AccessibleBrowseBoxTableBase::ensureIsValidRow( sal_Int32 nRow )
319     throw ( lang::IndexOutOfBoundsException )
320 {
321     if( nRow >= implGetRowCount() )
322         throw lang::IndexOutOfBoundsException(
323             OUString( RTL_CONSTASCII_USTRINGPARAM( "row index is invalid" ) ), *this );
324 }
325 
326 void AccessibleBrowseBoxTableBase::ensureIsValidColumn( sal_Int32 nColumn )
327     throw ( lang::IndexOutOfBoundsException )
328 {
329     if( nColumn >= implGetColumnCount() )
330         throw lang::IndexOutOfBoundsException(
331             OUString( RTL_CONSTASCII_USTRINGPARAM("column index is invalid") ), *this );
332 }
333 
334 void AccessibleBrowseBoxTableBase::ensureIsValidAddress(
335         sal_Int32 nRow, sal_Int32 nColumn )
336     throw ( lang::IndexOutOfBoundsException )
337 {
338     ensureIsValidRow( nRow );
339     ensureIsValidColumn( nColumn );
340 }
341 
342 void AccessibleBrowseBoxTableBase::ensureIsValidIndex( sal_Int32 nChildIndex )
343     throw ( lang::IndexOutOfBoundsException )
344 {
345     if( nChildIndex >= implGetChildCount() )
346         throw lang::IndexOutOfBoundsException(
347             OUString( RTL_CONSTASCII_USTRINGPARAM("child index is invalid") ), *this );
348 }
349 
350 // ============================================================================
351 
352 } // namespace accessibility
353 
354 // ============================================================================
355 
356