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