Branch libreoffice-5-0-4
[LibreOffice.git] / accessibility / source / extended / AccessibleBrowseBoxTableBase.cxx
blobcd03927c19621aa803a058694005e46e2e48538a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "accessibility/extended/AccessibleBrowseBoxTableBase.hxx"
21 #include <svtools/accessibletableprovider.hxx>
22 #include <tools/multisel.hxx>
23 #include <comphelper/sequence.hxx>
24 #include <comphelper/servicehelper.hxx>
28 using ::com::sun::star::uno::Reference;
29 using ::com::sun::star::uno::Sequence;
30 using ::com::sun::star::uno::Any;
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::accessibility;
34 using namespace ::svt;
38 namespace accessibility {
42 // Ctor/Dtor/disposing --------------------------------------------------------
44 AccessibleBrowseBoxTableBase::AccessibleBrowseBoxTableBase(
45 const Reference< XAccessible >& rxParent,
46 IAccessibleTableProvider& rBrowseBox,
47 AccessibleBrowseBoxObjType eObjType ) :
48 BrowseBoxAccessibleElement( rxParent, rBrowseBox,NULL, eObjType )
52 AccessibleBrowseBoxTableBase::~AccessibleBrowseBoxTableBase()
56 // XAccessibleContext ---------------------------------------------------------
58 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleChildCount()
59 throw ( uno::RuntimeException, std::exception )
61 SolarMutexGuard aSolarGuard;
62 ::osl::MutexGuard aGuard( getOslMutex() );
63 ensureIsAlive();
64 return implGetChildCount();
67 sal_Int16 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRole()
68 throw ( uno::RuntimeException, std::exception )
70 ensureIsAlive();
71 return AccessibleRole::TABLE;
74 // XAccessibleTable -----------------------------------------------------------
76 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRowCount()
77 throw ( uno::RuntimeException, std::exception )
79 SolarMutexGuard aSolarGuard;
80 ::osl::MutexGuard aGuard( getOslMutex() );
81 ensureIsAlive();
82 return implGetRowCount();
85 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumnCount()
86 throw ( uno::RuntimeException, std::exception )
88 SolarMutexGuard aSolarGuard;
89 ::osl::MutexGuard aGuard( getOslMutex() );
90 ensureIsAlive();
91 return implGetColumnCount();
94 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRowExtentAt(
95 sal_Int32 nRow, sal_Int32 nColumn )
96 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
98 SolarMutexGuard aSolarGuard;
99 ::osl::MutexGuard aGuard( getOslMutex() );
100 ensureIsAlive();
101 ensureIsValidAddress( nRow, nColumn );
102 return 1; // merged cells not supported
105 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumnExtentAt(
106 sal_Int32 nRow, sal_Int32 nColumn )
107 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
109 SolarMutexGuard aSolarGuard;
110 ::osl::MutexGuard aGuard( getOslMutex() );
111 ensureIsAlive();
112 ensureIsValidAddress( nRow, nColumn );
113 return 1; // merged cells not supported
116 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleCaption()
117 throw ( uno::RuntimeException, std::exception )
119 ensureIsAlive();
120 return NULL; // not supported
123 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleSummary()
124 throw ( uno::RuntimeException, std::exception )
126 ensureIsAlive();
127 return NULL; // not supported
130 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleIndex(
131 sal_Int32 nRow, sal_Int32 nColumn )
132 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
134 SolarMutexGuard aSolarGuard;
135 ::osl::MutexGuard aGuard( getOslMutex() );
136 ensureIsAlive();
137 ensureIsValidAddress( nRow, nColumn );
138 return implGetChildIndex( nRow, nColumn );
141 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRow( sal_Int32 nChildIndex )
142 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
144 SolarMutexGuard aSolarGuard;
145 ::osl::MutexGuard aGuard( getOslMutex() );
146 ensureIsAlive();
147 ensureIsValidIndex( nChildIndex );
148 return implGetRow( nChildIndex );
151 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumn( sal_Int32 nChildIndex )
152 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException, std::exception )
154 SolarMutexGuard aSolarGuard;
155 ::osl::MutexGuard aGuard( getOslMutex() );
156 ensureIsAlive();
157 ensureIsValidIndex( nChildIndex );
158 return implGetColumn( nChildIndex );
161 // XInterface -----------------------------------------------------------------
163 Any SAL_CALL AccessibleBrowseBoxTableBase::queryInterface( const uno::Type& rType )
164 throw ( uno::RuntimeException, std::exception )
166 Any aAny( BrowseBoxAccessibleElement::queryInterface( rType ) );
167 return aAny.hasValue() ?
168 aAny : AccessibleBrowseBoxTableImplHelper::queryInterface( rType );
171 void SAL_CALL AccessibleBrowseBoxTableBase::acquire() throw ()
173 BrowseBoxAccessibleElement::acquire();
176 void SAL_CALL AccessibleBrowseBoxTableBase::release() throw ()
178 BrowseBoxAccessibleElement::release();
181 // XTypeProvider --------------------------------------------------------------
183 Sequence< uno::Type > SAL_CALL AccessibleBrowseBoxTableBase::getTypes()
184 throw ( uno::RuntimeException, std::exception )
186 return ::comphelper::concatSequences(
187 BrowseBoxAccessibleElement::getTypes(),
188 AccessibleBrowseBoxTableImplHelper::getTypes() );
191 Sequence< sal_Int8 > SAL_CALL AccessibleBrowseBoxTableBase::getImplementationId()
192 throw ( uno::RuntimeException, std::exception )
194 return css::uno::Sequence<sal_Int8>();
197 // internal virtual methods ---------------------------------------------------
199 sal_Int32 AccessibleBrowseBoxTableBase::implGetRowCount() const
201 return mpBrowseBox->GetRowCount();
204 sal_Int32 AccessibleBrowseBoxTableBase::implGetColumnCount() const
206 sal_uInt16 nColumns = mpBrowseBox->GetColumnCount();
207 // do not count the "handle column"
208 if( nColumns && implHasHandleColumn() )
209 --nColumns;
210 return nColumns;
213 // internal helper methods ----------------------------------------------------
215 bool AccessibleBrowseBoxTableBase::implHasHandleColumn() const
217 return mpBrowseBox->HasRowHeader();
220 sal_uInt16 AccessibleBrowseBoxTableBase::implToVCLColumnPos( sal_Int32 nColumn ) const
222 sal_uInt16 nVCLPos = 0;
223 if( (0 <= nColumn) && (nColumn < implGetColumnCount()) )
225 // regard "handle column"
226 if( implHasHandleColumn() )
227 ++nColumn;
228 nVCLPos = static_cast< sal_uInt16 >( nColumn );
230 return nVCLPos;
233 sal_Int32 AccessibleBrowseBoxTableBase::implGetChildCount() const
235 return implGetRowCount() * implGetColumnCount();
238 sal_Int32 AccessibleBrowseBoxTableBase::implGetRow( sal_Int32 nChildIndex ) const
240 sal_Int32 nColumns = implGetColumnCount();
241 return nColumns ? (nChildIndex / nColumns) : 0;
244 sal_Int32 AccessibleBrowseBoxTableBase::implGetColumn( sal_Int32 nChildIndex ) const
246 sal_Int32 nColumns = implGetColumnCount();
247 return nColumns ? (nChildIndex % nColumns) : 0;
250 sal_Int32 AccessibleBrowseBoxTableBase::implGetChildIndex(
251 sal_Int32 nRow, sal_Int32 nColumn ) const
253 return nRow * implGetColumnCount() + nColumn;
256 bool AccessibleBrowseBoxTableBase::implIsRowSelected( sal_Int32 nRow ) const
258 return mpBrowseBox->IsRowSelected( nRow );
261 bool AccessibleBrowseBoxTableBase::implIsColumnSelected( sal_Int32 nColumn ) const
263 if( implHasHandleColumn() )
264 --nColumn;
265 return mpBrowseBox->IsColumnSelected( nColumn );
268 void AccessibleBrowseBoxTableBase::implSelectRow( sal_Int32 nRow, bool bSelect )
270 mpBrowseBox->SelectRow( nRow, bSelect, true );
273 void AccessibleBrowseBoxTableBase::implSelectColumn( sal_Int32 nColumnPos, bool bSelect )
275 mpBrowseBox->SelectColumn( (sal_uInt16)nColumnPos, bSelect );
278 sal_Int32 AccessibleBrowseBoxTableBase::implGetSelectedRowCount() const
280 return mpBrowseBox->GetSelectedRowCount();
283 sal_Int32 AccessibleBrowseBoxTableBase::implGetSelectedColumnCount() const
285 return mpBrowseBox->GetSelectedColumnCount();
288 void AccessibleBrowseBoxTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq )
290 mpBrowseBox->GetAllSelectedRows( rSeq );
293 void AccessibleBrowseBoxTableBase::implGetSelectedColumns( Sequence< sal_Int32 >& rSeq )
295 mpBrowseBox->GetAllSelectedColumns( rSeq );
298 void AccessibleBrowseBoxTableBase::ensureIsValidRow( sal_Int32 nRow )
299 throw ( lang::IndexOutOfBoundsException )
301 if( nRow >= implGetRowCount() )
302 throw lang::IndexOutOfBoundsException(
303 OUString( "row index is invalid" ), *this );
306 void AccessibleBrowseBoxTableBase::ensureIsValidColumn( sal_Int32 nColumn )
307 throw ( lang::IndexOutOfBoundsException )
309 if( nColumn >= implGetColumnCount() )
310 throw lang::IndexOutOfBoundsException(
311 OUString( "column index is invalid" ), *this );
314 void AccessibleBrowseBoxTableBase::ensureIsValidAddress(
315 sal_Int32 nRow, sal_Int32 nColumn )
316 throw ( lang::IndexOutOfBoundsException )
318 ensureIsValidRow( nRow );
319 ensureIsValidColumn( nColumn );
322 void AccessibleBrowseBoxTableBase::ensureIsValidIndex( sal_Int32 nChildIndex )
323 throw ( lang::IndexOutOfBoundsException )
325 if( nChildIndex >= implGetChildCount() )
326 throw lang::IndexOutOfBoundsException(
327 OUString( "child index is invalid" ), *this );
332 } // namespace accessibility
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */