lok: vcl: fix multiple floatwin removal case more robustly.
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTableBase.cxx
blobb34a207d1bdfbbc6e639b76ae2940d75165dfc97
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 <extended/AccessibleGridControlTableBase.hxx>
21 #include <vcl/accessibletable.hxx>
22 #include <tools/multisel.hxx>
23 #include <comphelper/sequence.hxx>
25 using css::uno::Reference;
26 using css::uno::Sequence;
27 using css::uno::Any;
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::accessibility;
31 using namespace ::vcl;
32 using namespace ::vcl::table;
35 namespace accessibility {
38 AccessibleGridControlTableBase::AccessibleGridControlTableBase(
39 const Reference< XAccessible >& rxParent,
40 IAccessibleTable& rTable,
41 AccessibleTableControlObjType eObjType ) :
42 GridControlAccessibleElement( rxParent, rTable, eObjType )
46 // XAccessibleContext ---------------------------------------------------------
48 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleChildCount()
50 SolarMutexGuard aSolarGuard;
52 ensureIsAlive();
53 sal_Int32 nChildren = 0;
54 if(m_eObjType == TCTYPE_ROWHEADERBAR)
55 nChildren = m_aTable.GetRowCount();
56 else if(m_eObjType == TCTYPE_TABLE)
57 nChildren = m_aTable.GetRowCount()*m_aTable.GetColumnCount();
58 else if(m_eObjType == TCTYPE_COLUMNHEADERBAR)
59 nChildren = m_aTable.GetColumnCount();
60 return nChildren;
63 sal_Int16 SAL_CALL AccessibleGridControlTableBase::getAccessibleRole()
65 SolarMutexGuard g;
67 ensureIsAlive();
68 return AccessibleRole::TABLE;
71 // XAccessibleTable -----------------------------------------------------------
73 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowCount()
75 SolarMutexGuard aSolarGuard;
77 ensureIsAlive();
78 return m_aTable.GetRowCount();
81 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnCount()
83 SolarMutexGuard aSolarGuard;
85 ensureIsAlive();
86 return m_aTable.GetColumnCount();
89 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowExtentAt(
90 sal_Int32 nRow, sal_Int32 nColumn )
92 SolarMutexGuard aSolarGuard;
94 ensureIsAlive();
95 ensureIsValidAddress( nRow, nColumn );
96 return 1; // merged cells not supported
99 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnExtentAt(
100 sal_Int32 nRow, sal_Int32 nColumn )
102 SolarMutexGuard aSolarGuard;
104 ensureIsAlive();
105 ensureIsValidAddress( nRow, nColumn );
106 return 1; // merged cells not supported
109 Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleCaption()
111 SolarMutexGuard g;
113 ensureIsAlive();
114 return nullptr; // not supported
117 Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleSummary()
119 SolarMutexGuard g;
121 ensureIsAlive();
122 return nullptr; // not supported
125 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleIndex(
126 sal_Int32 nRow, sal_Int32 nColumn )
128 SolarMutexGuard aSolarGuard;
130 ensureIsAlive();
131 ensureIsValidAddress( nRow, nColumn );
132 return nRow * m_aTable.GetColumnCount() + nColumn;
135 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRow( sal_Int32 nChildIndex )
137 SolarMutexGuard aSolarGuard;
139 ensureIsAlive();
140 ensureIsValidIndex( nChildIndex );
141 return implGetRow( nChildIndex );
144 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumn( sal_Int32 nChildIndex )
146 SolarMutexGuard aSolarGuard;
148 ensureIsAlive();
149 ensureIsValidIndex( nChildIndex );
150 return implGetColumn( nChildIndex );
153 // XInterface -----------------------------------------------------------------
155 Any SAL_CALL AccessibleGridControlTableBase::queryInterface( const uno::Type& rType )
157 Any aAny( GridControlAccessibleElement::queryInterface( rType ) );
158 return aAny.hasValue() ?
159 aAny : AccessibleGridControlTableImplHelper::queryInterface( rType );
162 void SAL_CALL AccessibleGridControlTableBase::acquire() throw ()
164 GridControlAccessibleElement::acquire();
167 void SAL_CALL AccessibleGridControlTableBase::release() throw ()
169 GridControlAccessibleElement::release();
172 // XTypeProvider --------------------------------------------------------------
174 Sequence< uno::Type > SAL_CALL AccessibleGridControlTableBase::getTypes()
176 return ::comphelper::concatSequences(
177 GridControlAccessibleElement::getTypes(),
178 AccessibleGridControlTableImplHelper::getTypes() );
181 Sequence< sal_Int8 > SAL_CALL AccessibleGridControlTableBase::getImplementationId()
183 return css::uno::Sequence<sal_Int8>();
186 // internal helper methods ----------------------------------------------------
188 sal_Int32 AccessibleGridControlTableBase::implGetRow( sal_Int32 nChildIndex ) const
190 sal_Int32 nColumns = m_aTable.GetColumnCount();
191 return nColumns ? (nChildIndex / nColumns) : 0;
194 sal_Int32 AccessibleGridControlTableBase::implGetColumn( sal_Int32 nChildIndex ) const
196 sal_Int32 nColumns = m_aTable.GetColumnCount();
197 return nColumns ? (nChildIndex % nColumns) : 0;
200 void AccessibleGridControlTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq )
202 sal_Int32 const selectionCount( m_aTable.GetSelectedRowCount() );
203 rSeq.realloc( selectionCount );
204 for ( sal_Int32 i=0; i<selectionCount; ++i )
205 rSeq[i] = m_aTable.GetSelectedRowIndex(i);
208 void AccessibleGridControlTableBase::ensureIsValidRow( sal_Int32 nRow )
210 if( nRow >= m_aTable.GetRowCount() )
211 throw lang::IndexOutOfBoundsException( "row index is invalid", *this );
214 void AccessibleGridControlTableBase::ensureIsValidColumn( sal_Int32 nColumn )
216 if( nColumn >= m_aTable.GetColumnCount() )
217 throw lang::IndexOutOfBoundsException( "column index is invalid", *this );
220 void AccessibleGridControlTableBase::ensureIsValidAddress(
221 sal_Int32 nRow, sal_Int32 nColumn )
223 ensureIsValidRow( nRow );
224 ensureIsValidColumn( nColumn );
227 void AccessibleGridControlTableBase::ensureIsValidIndex( sal_Int32 nChildIndex )
229 if( nChildIndex >= m_aTable.GetRowCount()*m_aTable.GetColumnCount() )
230 throw lang::IndexOutOfBoundsException( "child index is invalid", *this );
234 } // namespace accessibility
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */