1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
;
39 namespace accessibility
{
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
, std::exception
)
60 SolarMutexGuard aSolarGuard
;
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();
73 sal_Int16 SAL_CALL
AccessibleGridControlTableBase::getAccessibleRole()
74 throw ( uno::RuntimeException
, std::exception
)
79 return AccessibleRole::TABLE
;
82 // XAccessibleTable -----------------------------------------------------------
84 sal_Int32 SAL_CALL
AccessibleGridControlTableBase::getAccessibleRowCount()
85 throw ( uno::RuntimeException
, std::exception
)
87 SolarMutexGuard aSolarGuard
;
90 return m_aTable
.GetRowCount();
93 sal_Int32 SAL_CALL
AccessibleGridControlTableBase::getAccessibleColumnCount()
94 throw ( uno::RuntimeException
, std::exception
)
96 SolarMutexGuard aSolarGuard
;
99 return m_aTable
.GetColumnCount();
102 sal_Int32 SAL_CALL
AccessibleGridControlTableBase::getAccessibleRowExtentAt(
103 sal_Int32 nRow
, sal_Int32 nColumn
)
104 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
106 SolarMutexGuard aSolarGuard
;
109 ensureIsValidAddress( nRow
, nColumn
);
110 return 1; // merged cells not supported
113 sal_Int32 SAL_CALL
AccessibleGridControlTableBase::getAccessibleColumnExtentAt(
114 sal_Int32 nRow
, sal_Int32 nColumn
)
115 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
117 SolarMutexGuard aSolarGuard
;
120 ensureIsValidAddress( nRow
, nColumn
);
121 return 1; // merged cells not supported
124 Reference
< XAccessible
> SAL_CALL
AccessibleGridControlTableBase::getAccessibleCaption()
125 throw ( uno::RuntimeException
, std::exception
)
130 return NULL
; // not supported
133 Reference
< XAccessible
> SAL_CALL
AccessibleGridControlTableBase::getAccessibleSummary()
134 throw ( uno::RuntimeException
, std::exception
)
139 return NULL
; // not supported
142 sal_Int32 SAL_CALL
AccessibleGridControlTableBase::getAccessibleIndex(
143 sal_Int32 nRow
, sal_Int32 nColumn
)
144 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
146 SolarMutexGuard aSolarGuard
;
149 ensureIsValidAddress( nRow
, nColumn
);
150 return implGetChildIndex( nRow
, nColumn
);
153 sal_Int32 SAL_CALL
AccessibleGridControlTableBase::getAccessibleRow( sal_Int32 nChildIndex
)
154 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
156 SolarMutexGuard aSolarGuard
;
159 ensureIsValidIndex( nChildIndex
);
160 return implGetRow( nChildIndex
);
163 sal_Int32 SAL_CALL
AccessibleGridControlTableBase::getAccessibleColumn( sal_Int32 nChildIndex
)
164 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
166 SolarMutexGuard aSolarGuard
;
169 ensureIsValidIndex( nChildIndex
);
170 return implGetColumn( nChildIndex
);
173 // XInterface -----------------------------------------------------------------
175 Any SAL_CALL
AccessibleGridControlTableBase::queryInterface( const uno::Type
& rType
)
176 throw ( uno::RuntimeException
, std::exception
)
178 Any
aAny( GridControlAccessibleElement::queryInterface( rType
) );
179 return aAny
.hasValue() ?
180 aAny
: AccessibleGridControlTableImplHelper::queryInterface( rType
);
183 void SAL_CALL
AccessibleGridControlTableBase::acquire() throw ()
185 GridControlAccessibleElement::acquire();
188 void SAL_CALL
AccessibleGridControlTableBase::release() throw ()
190 GridControlAccessibleElement::release();
193 // XTypeProvider --------------------------------------------------------------
195 Sequence
< uno::Type
> SAL_CALL
AccessibleGridControlTableBase::getTypes()
196 throw ( uno::RuntimeException
, std::exception
)
198 return ::comphelper::concatSequences(
199 GridControlAccessibleElement::getTypes(),
200 AccessibleGridControlTableImplHelper::getTypes() );
203 Sequence
< sal_Int8
> SAL_CALL
AccessibleGridControlTableBase::getImplementationId()
204 throw ( uno::RuntimeException
, std::exception
)
206 return css::uno::Sequence
<sal_Int8
>();
209 // internal helper methods ----------------------------------------------------
211 sal_Int32
AccessibleGridControlTableBase::implGetChildCount() const
213 return m_aTable
.GetRowCount()*m_aTable
.GetColumnCount();
216 sal_Int32
AccessibleGridControlTableBase::implGetRow( sal_Int32 nChildIndex
) const
218 sal_Int32 nColumns
= m_aTable
.GetColumnCount();
219 return nColumns
? (nChildIndex
/ nColumns
) : 0;
222 sal_Int32
AccessibleGridControlTableBase::implGetColumn( sal_Int32 nChildIndex
) const
224 sal_Int32 nColumns
= m_aTable
.GetColumnCount();
225 return nColumns
? (nChildIndex
% nColumns
) : 0;
228 sal_Int32
AccessibleGridControlTableBase::implGetChildIndex(
229 sal_Int32 nRow
, sal_Int32 nColumn
) const
231 return nRow
* m_aTable
.GetColumnCount() + nColumn
;
234 void AccessibleGridControlTableBase::implGetSelectedRows( Sequence
< sal_Int32
>& rSeq
)
236 sal_Int32
const selectionCount( m_aTable
.GetSelectedRowCount() );
237 rSeq
.realloc( selectionCount
);
238 for ( sal_Int32 i
=0; i
<selectionCount
; ++i
)
239 rSeq
[i
] = m_aTable
.GetSelectedRowIndex(i
);
242 void AccessibleGridControlTableBase::ensureIsValidRow( sal_Int32 nRow
)
243 throw ( lang::IndexOutOfBoundsException
)
245 if( nRow
>= m_aTable
.GetRowCount() )
246 throw lang::IndexOutOfBoundsException(
247 OUString( "row index is invalid" ), *this );
250 void AccessibleGridControlTableBase::ensureIsValidColumn( sal_Int32 nColumn
)
251 throw ( lang::IndexOutOfBoundsException
)
253 if( nColumn
>= m_aTable
.GetColumnCount() )
254 throw lang::IndexOutOfBoundsException(
255 OUString( "column index is invalid" ), *this );
258 void AccessibleGridControlTableBase::ensureIsValidAddress(
259 sal_Int32 nRow
, sal_Int32 nColumn
)
260 throw ( lang::IndexOutOfBoundsException
)
262 ensureIsValidRow( nRow
);
263 ensureIsValidColumn( nColumn
);
266 void AccessibleGridControlTableBase::ensureIsValidIndex( sal_Int32 nChildIndex
)
267 throw ( lang::IndexOutOfBoundsException
)
269 if( nChildIndex
>= implGetChildCount() )
270 throw lang::IndexOutOfBoundsException(
271 OUString( "child index is invalid" ), *this );
276 } // namespace accessibility
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */