xref: /trunk/main/accessibility/source/extended/AccessibleBrowseBoxTableBase.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 {
73     BBSolarGuard aSolarGuard;
74     ::osl::MutexGuard aGuard( getOslMutex() );
75     ensureIsAlive();
76     return implGetChildCount();
77 }
78 
getAccessibleRole()79 sal_Int16 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRole()
80 {
81     ensureIsAlive();
82     return AccessibleRole::TABLE;
83 }
84 
85 // XAccessibleTable -----------------------------------------------------------
86 
getAccessibleRowCount()87 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRowCount()
88 {
89     BBSolarGuard aSolarGuard;
90     ::osl::MutexGuard aGuard( getOslMutex() );
91     ensureIsAlive();
92     return implGetRowCount();
93 }
94 
getAccessibleColumnCount()95 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumnCount()
96 {
97     BBSolarGuard aSolarGuard;
98     ::osl::MutexGuard aGuard( getOslMutex() );
99     ensureIsAlive();
100     return implGetColumnCount();
101 }
102 
getAccessibleRowExtentAt(sal_Int32 nRow,sal_Int32 nColumn)103 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRowExtentAt(
104         sal_Int32 nRow, sal_Int32 nColumn )
105 {
106     BBSolarGuard aSolarGuard;
107     ::osl::MutexGuard aGuard( getOslMutex() );
108     ensureIsAlive();
109     ensureIsValidAddress( nRow, nColumn );
110     return 1; // merged cells not supported
111 }
112 
getAccessibleColumnExtentAt(sal_Int32 nRow,sal_Int32 nColumn)113 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumnExtentAt(
114         sal_Int32 nRow, sal_Int32 nColumn )
115 {
116     BBSolarGuard aSolarGuard;
117     ::osl::MutexGuard aGuard( getOslMutex() );
118     ensureIsAlive();
119     ensureIsValidAddress( nRow, nColumn );
120     return 1; // merged cells not supported
121 }
122 
getAccessibleCaption()123 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleCaption()
124 {
125     ensureIsAlive();
126     return NULL; // not supported
127 }
128 
getAccessibleSummary()129 Reference< XAccessible > SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleSummary()
130 {
131     ensureIsAlive();
132     return NULL; // not supported
133 }
134 
getAccessibleIndex(sal_Int32 nRow,sal_Int32 nColumn)135 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleIndex(
136         sal_Int32 nRow, sal_Int32 nColumn )
137 {
138     BBSolarGuard aSolarGuard;
139     ::osl::MutexGuard aGuard( getOslMutex() );
140     ensureIsAlive();
141     ensureIsValidAddress( nRow, nColumn );
142     return implGetChildIndex( nRow, nColumn );
143 }
144 
getAccessibleRow(sal_Int32 nChildIndex)145 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleRow( sal_Int32 nChildIndex )
146 {
147     BBSolarGuard aSolarGuard;
148     ::osl::MutexGuard aGuard( getOslMutex() );
149     ensureIsAlive();
150     ensureIsValidIndex( nChildIndex );
151     return implGetRow( nChildIndex );
152 }
153 
getAccessibleColumn(sal_Int32 nChildIndex)154 sal_Int32 SAL_CALL AccessibleBrowseBoxTableBase::getAccessibleColumn( sal_Int32 nChildIndex )
155 {
156     BBSolarGuard aSolarGuard;
157     ::osl::MutexGuard aGuard( getOslMutex() );
158     ensureIsAlive();
159     ensureIsValidIndex( nChildIndex );
160     return implGetColumn( nChildIndex );
161 }
162 
163 // XInterface -----------------------------------------------------------------
164 
queryInterface(const uno::Type & rType)165 Any SAL_CALL AccessibleBrowseBoxTableBase::queryInterface( const uno::Type& rType )
166 {
167     Any aAny( BrowseBoxAccessibleElement::queryInterface( rType ) );
168     return aAny.hasValue() ?
169         aAny : AccessibleBrowseBoxTableImplHelper::queryInterface( rType );
170 }
171 
acquire()172 void SAL_CALL AccessibleBrowseBoxTableBase::acquire() throw ()
173 {
174     BrowseBoxAccessibleElement::acquire();
175 }
176 
release()177 void SAL_CALL AccessibleBrowseBoxTableBase::release() throw ()
178 {
179     BrowseBoxAccessibleElement::release();
180 }
181 
182 // XTypeProvider --------------------------------------------------------------
183 
getTypes()184 Sequence< uno::Type > SAL_CALL AccessibleBrowseBoxTableBase::getTypes()
185 {
186     return ::comphelper::concatSequences(
187         BrowseBoxAccessibleElement::getTypes(),
188         AccessibleBrowseBoxTableImplHelper::getTypes() );
189 }
190 
getImplementationId()191 Sequence< sal_Int8 > SAL_CALL AccessibleBrowseBoxTableBase::getImplementationId()
192 {
193     ::osl::MutexGuard aGuard( getOslGlobalMutex() );
194     static Sequence< sal_Int8 > aId;
195     implCreateUuid( aId );
196     return aId;
197 }
198 
199 // internal virtual methods ---------------------------------------------------
200 
implGetRowCount() const201 sal_Int32 AccessibleBrowseBoxTableBase::implGetRowCount() const
202 {
203     return mpBrowseBox->GetRowCount();
204 }
205 
implGetColumnCount() const206 sal_Int32 AccessibleBrowseBoxTableBase::implGetColumnCount() const
207 {
208     sal_uInt16 nColumns = mpBrowseBox->GetColumnCount();
209     // do not count the "handle column"
210     if( nColumns && implHasHandleColumn() )
211         --nColumns;
212     return nColumns;
213 }
214 
215 // internal helper methods ----------------------------------------------------
216 
implHasHandleColumn() const217 sal_Bool AccessibleBrowseBoxTableBase::implHasHandleColumn() const
218 {
219     return mpBrowseBox->HasRowHeader();
220 }
221 
implToVCLColumnPos(sal_Int32 nColumn) const222 sal_uInt16 AccessibleBrowseBoxTableBase::implToVCLColumnPos( sal_Int32 nColumn ) const
223 {
224     sal_uInt16 nVCLPos = 0;
225     if( (0 <= nColumn) && (nColumn < implGetColumnCount()) )
226     {
227         // regard "handle column"
228         if( implHasHandleColumn() )
229             ++nColumn;
230         nVCLPos = static_cast< sal_uInt16 >( nColumn );
231     }
232     return nVCLPos;
233 }
234 
implGetChildCount() const235 sal_Int32 AccessibleBrowseBoxTableBase::implGetChildCount() const
236 {
237     return implGetRowCount() * implGetColumnCount();
238 }
239 
implGetRow(sal_Int32 nChildIndex) const240 sal_Int32 AccessibleBrowseBoxTableBase::implGetRow( sal_Int32 nChildIndex ) const
241 {
242     sal_Int32 nColumns = implGetColumnCount();
243     return nColumns ? (nChildIndex / nColumns) : 0;
244 }
245 
implGetColumn(sal_Int32 nChildIndex) const246 sal_Int32 AccessibleBrowseBoxTableBase::implGetColumn( sal_Int32 nChildIndex ) const
247 {
248     sal_Int32 nColumns = implGetColumnCount();
249     return nColumns ? (nChildIndex % nColumns) : 0;
250 }
251 
implGetChildIndex(sal_Int32 nRow,sal_Int32 nColumn) const252 sal_Int32 AccessibleBrowseBoxTableBase::implGetChildIndex(
253         sal_Int32 nRow, sal_Int32 nColumn ) const
254 {
255     return nRow * implGetColumnCount() + nColumn;
256 }
257 
implIsRowSelected(sal_Int32 nRow) const258 sal_Bool AccessibleBrowseBoxTableBase::implIsRowSelected( sal_Int32 nRow ) const
259 {
260     return mpBrowseBox->IsRowSelected( nRow );
261 }
262 
implIsColumnSelected(sal_Int32 nColumn) const263 sal_Bool AccessibleBrowseBoxTableBase::implIsColumnSelected( sal_Int32 nColumn ) const
264 {
265     if( implHasHandleColumn() )
266         --nColumn;
267     return mpBrowseBox->IsColumnSelected( nColumn );
268 }
269 
implSelectRow(sal_Int32 nRow,sal_Bool bSelect)270 void AccessibleBrowseBoxTableBase::implSelectRow( sal_Int32 nRow, sal_Bool bSelect )
271 {
272     mpBrowseBox->SelectRow( nRow, bSelect, sal_True );
273 }
274 
implSelectColumn(sal_Int32 nColumnPos,sal_Bool bSelect)275 void AccessibleBrowseBoxTableBase::implSelectColumn( sal_Int32 nColumnPos, sal_Bool bSelect )
276 {
277     mpBrowseBox->SelectColumn( (sal_uInt16)nColumnPos, bSelect );
278 }
279 
implGetSelectedRowCount() const280 sal_Int32 AccessibleBrowseBoxTableBase::implGetSelectedRowCount() const
281 {
282     return mpBrowseBox->GetSelectedRowCount();
283 }
284 
implGetSelectedColumnCount() const285 sal_Int32 AccessibleBrowseBoxTableBase::implGetSelectedColumnCount() const
286 {
287     return mpBrowseBox->GetSelectedColumnCount();
288 }
289 
implGetSelectedRows(Sequence<sal_Int32> & rSeq)290 void AccessibleBrowseBoxTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq )
291 {
292     mpBrowseBox->GetAllSelectedRows( rSeq );
293 }
294 
implGetSelectedColumns(Sequence<sal_Int32> & rSeq)295 void AccessibleBrowseBoxTableBase::implGetSelectedColumns( Sequence< sal_Int32 >& rSeq )
296 {
297     mpBrowseBox->GetAllSelectedColumns( rSeq );
298 }
299 
ensureIsValidRow(sal_Int32 nRow)300 void AccessibleBrowseBoxTableBase::ensureIsValidRow( sal_Int32 nRow )
301 {
302     if( nRow >= implGetRowCount() )
303         throw lang::IndexOutOfBoundsException(
304             OUString( RTL_CONSTASCII_USTRINGPARAM( "row index is invalid" ) ), *this );
305 }
306 
ensureIsValidColumn(sal_Int32 nColumn)307 void AccessibleBrowseBoxTableBase::ensureIsValidColumn( sal_Int32 nColumn )
308 {
309     if( nColumn >= implGetColumnCount() )
310         throw lang::IndexOutOfBoundsException(
311             OUString( RTL_CONSTASCII_USTRINGPARAM("column index is invalid") ), *this );
312 }
313 
ensureIsValidAddress(sal_Int32 nRow,sal_Int32 nColumn)314 void AccessibleBrowseBoxTableBase::ensureIsValidAddress(
315         sal_Int32 nRow, sal_Int32 nColumn )
316 {
317     ensureIsValidRow( nRow );
318     ensureIsValidColumn( nColumn );
319 }
320 
ensureIsValidIndex(sal_Int32 nChildIndex)321 void AccessibleBrowseBoxTableBase::ensureIsValidIndex( sal_Int32 nChildIndex )
322 {
323     if( nChildIndex >= implGetChildCount() )
324         throw lang::IndexOutOfBoundsException(
325             OUString( RTL_CONSTASCII_USTRINGPARAM("child index is invalid") ), *this );
326 }
327 
328 // ============================================================================
329 }   // namespace accessibility
330 // ============================================================================
331