Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControlTableBase.cxx
blobf6d75707dade57f9da44bb90ca3af8434c5d90ce
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/AccessibleGridControlTableBase.hxx"
21 #include <svtools/accessibletable.hxx>
22 #include <tools/multisel.hxx>
23 #include <comphelper/sequence.hxx>
24 #include <comphelper/servicehelper.hxx>
26 // ============================================================================
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;
35 using namespace ::svt::table;
37 // ============================================================================
39 namespace accessibility {
41 // ============================================================================
43 AccessibleGridControlTableBase::AccessibleGridControlTableBase(
44 const Reference< XAccessible >& rxParent,
45 IAccessibleTable& rTable,
46 AccessibleTableControlObjType eObjType ) :
47 GridControlAccessibleElement( rxParent, rTable, eObjType )
51 AccessibleGridControlTableBase::~AccessibleGridControlTableBase()
55 // XAccessibleContext ---------------------------------------------------------
57 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleChildCount()
58 throw ( uno::RuntimeException )
60 SolarMutexGuard aSolarGuard;
61 ::osl::MutexGuard aGuard( getOslMutex() );
62 ensureIsAlive();
63 sal_Int32 nChildren = 0;
64 if(m_eObjType == TCTYPE_ROWHEADERBAR)
65 nChildren = m_aTable.GetRowCount();
66 else if(m_eObjType == TCTYPE_TABLE)
67 nChildren = m_aTable.GetRowCount()*m_aTable.GetColumnCount();
68 else if(m_eObjType == TCTYPE_COLUMNHEADERBAR)
69 nChildren = m_aTable.GetColumnCount();
70 return nChildren;
73 sal_Int16 SAL_CALL AccessibleGridControlTableBase::getAccessibleRole()
74 throw ( uno::RuntimeException )
76 ensureIsAlive();
77 return AccessibleRole::TABLE;
80 // XAccessibleTable -----------------------------------------------------------
82 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowCount()
83 throw ( uno::RuntimeException )
85 SolarMutexGuard aSolarGuard;
86 ::osl::MutexGuard aGuard( getOslMutex() );
87 ensureIsAlive();
88 return m_aTable.GetRowCount();
91 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnCount()
92 throw ( uno::RuntimeException )
94 SolarMutexGuard aSolarGuard;
95 ::osl::MutexGuard aGuard( getOslMutex() );
96 ensureIsAlive();
97 return m_aTable.GetColumnCount();
100 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRowExtentAt(
101 sal_Int32 nRow, sal_Int32 nColumn )
102 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
104 SolarMutexGuard aSolarGuard;
105 ::osl::MutexGuard aGuard( getOslMutex() );
106 ensureIsAlive();
107 ensureIsValidAddress( nRow, nColumn );
108 return 1; // merged cells not supported
111 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumnExtentAt(
112 sal_Int32 nRow, sal_Int32 nColumn )
113 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
115 SolarMutexGuard aSolarGuard;
116 ::osl::MutexGuard aGuard( getOslMutex() );
117 ensureIsAlive();
118 ensureIsValidAddress( nRow, nColumn );
119 return 1; // merged cells not supported
122 Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleCaption()
123 throw ( uno::RuntimeException )
125 ensureIsAlive();
126 return NULL; // not supported
129 Reference< XAccessible > SAL_CALL AccessibleGridControlTableBase::getAccessibleSummary()
130 throw ( uno::RuntimeException )
132 ensureIsAlive();
133 return NULL; // not supported
136 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleIndex(
137 sal_Int32 nRow, sal_Int32 nColumn )
138 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
140 SolarMutexGuard aSolarGuard;
141 ::osl::MutexGuard aGuard( getOslMutex() );
142 ensureIsAlive();
143 ensureIsValidAddress( nRow, nColumn );
144 return implGetChildIndex( nRow, nColumn );
147 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleRow( sal_Int32 nChildIndex )
148 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
150 SolarMutexGuard aSolarGuard;
151 ::osl::MutexGuard aGuard( getOslMutex() );
152 ensureIsAlive();
153 ensureIsValidIndex( nChildIndex );
154 return implGetRow( nChildIndex );
157 sal_Int32 SAL_CALL AccessibleGridControlTableBase::getAccessibleColumn( sal_Int32 nChildIndex )
158 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
160 SolarMutexGuard aSolarGuard;
161 ::osl::MutexGuard aGuard( getOslMutex() );
162 ensureIsAlive();
163 ensureIsValidIndex( nChildIndex );
164 return implGetColumn( nChildIndex );
167 // XInterface -----------------------------------------------------------------
169 Any SAL_CALL AccessibleGridControlTableBase::queryInterface( const uno::Type& rType )
170 throw ( uno::RuntimeException )
172 Any aAny( GridControlAccessibleElement::queryInterface( rType ) );
173 return aAny.hasValue() ?
174 aAny : AccessibleGridControlTableImplHelper::queryInterface( rType );
177 void SAL_CALL AccessibleGridControlTableBase::acquire() throw ()
179 GridControlAccessibleElement::acquire();
182 void SAL_CALL AccessibleGridControlTableBase::release() throw ()
184 GridControlAccessibleElement::release();
187 // XTypeProvider --------------------------------------------------------------
189 Sequence< uno::Type > SAL_CALL AccessibleGridControlTableBase::getTypes()
190 throw ( uno::RuntimeException )
192 return ::comphelper::concatSequences(
193 GridControlAccessibleElement::getTypes(),
194 AccessibleGridControlTableImplHelper::getTypes() );
197 namespace
199 class theAccessibleGridControlTableBaseImplementationId : public rtl::Static< UnoTunnelIdInit, theAccessibleGridControlTableBaseImplementationId > {};
202 Sequence< sal_Int8 > SAL_CALL AccessibleGridControlTableBase::getImplementationId()
203 throw ( uno::RuntimeException )
205 return theAccessibleGridControlTableBaseImplementationId::get().getSeq();
208 // internal helper methods ----------------------------------------------------
210 sal_Int32 AccessibleGridControlTableBase::implGetChildCount() const
212 return m_aTable.GetRowCount()*m_aTable.GetColumnCount();
215 sal_Int32 AccessibleGridControlTableBase::implGetRow( sal_Int32 nChildIndex ) const
217 sal_Int32 nColumns = m_aTable.GetColumnCount();
218 return nColumns ? (nChildIndex / nColumns) : 0;
221 sal_Int32 AccessibleGridControlTableBase::implGetColumn( sal_Int32 nChildIndex ) const
223 sal_Int32 nColumns = m_aTable.GetColumnCount();
224 return nColumns ? (nChildIndex % nColumns) : 0;
227 sal_Int32 AccessibleGridControlTableBase::implGetChildIndex(
228 sal_Int32 nRow, sal_Int32 nColumn ) const
230 return nRow * m_aTable.GetColumnCount() + nColumn;
233 void AccessibleGridControlTableBase::implGetSelectedRows( Sequence< sal_Int32 >& rSeq )
235 sal_Int32 const selectionCount( m_aTable.GetSelectedRowCount() );
236 rSeq.realloc( selectionCount );
237 for ( sal_Int32 i=0; i<selectionCount; ++i )
238 rSeq[i] = m_aTable.GetSelectedRowIndex(i);
241 void AccessibleGridControlTableBase::ensureIsValidRow( sal_Int32 nRow )
242 throw ( lang::IndexOutOfBoundsException )
244 if( nRow >= m_aTable.GetRowCount() )
245 throw lang::IndexOutOfBoundsException(
246 OUString( "row index is invalid" ), *this );
249 void AccessibleGridControlTableBase::ensureIsValidColumn( sal_Int32 nColumn )
250 throw ( lang::IndexOutOfBoundsException )
252 if( nColumn >= m_aTable.GetColumnCount() )
253 throw lang::IndexOutOfBoundsException(
254 OUString( "column index is invalid" ), *this );
257 void AccessibleGridControlTableBase::ensureIsValidAddress(
258 sal_Int32 nRow, sal_Int32 nColumn )
259 throw ( lang::IndexOutOfBoundsException )
261 ensureIsValidRow( nRow );
262 ensureIsValidColumn( nColumn );
265 void AccessibleGridControlTableBase::ensureIsValidIndex( sal_Int32 nChildIndex )
266 throw ( lang::IndexOutOfBoundsException )
268 if( nChildIndex >= implGetChildCount() )
269 throw lang::IndexOutOfBoundsException(
270 OUString( "child index is invalid" ), *this );
273 // ============================================================================
275 } // namespace accessibility
277 // ============================================================================
279 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */