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/AccessibleBrowseBoxTableBase.hxx"
21 #include <svtools/accessibletableprovider.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
;
36 // ============================================================================
38 namespace accessibility
{
40 // ============================================================================
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
)
61 SolarMutexGuard aSolarGuard
;
62 ::osl::MutexGuard
aGuard( getOslMutex() );
64 return implGetChildCount();
67 sal_Int16 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleRole()
68 throw ( uno::RuntimeException
)
71 return AccessibleRole::TABLE
;
74 // XAccessibleTable -----------------------------------------------------------
76 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleRowCount()
77 throw ( uno::RuntimeException
)
79 SolarMutexGuard aSolarGuard
;
80 ::osl::MutexGuard
aGuard( getOslMutex() );
82 return implGetRowCount();
85 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleColumnCount()
86 throw ( uno::RuntimeException
)
88 SolarMutexGuard aSolarGuard
;
89 ::osl::MutexGuard
aGuard( getOslMutex() );
91 return implGetColumnCount();
94 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleRowExtentAt(
95 sal_Int32 nRow
, sal_Int32 nColumn
)
96 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
)
98 SolarMutexGuard aSolarGuard
;
99 ::osl::MutexGuard
aGuard( getOslMutex() );
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
)
109 SolarMutexGuard aSolarGuard
;
110 ::osl::MutexGuard
aGuard( getOslMutex() );
112 ensureIsValidAddress( nRow
, nColumn
);
113 return 1; // merged cells not supported
116 Reference
< XAccessible
> SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleCaption()
117 throw ( uno::RuntimeException
)
120 return NULL
; // not supported
123 Reference
< XAccessible
> SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleSummary()
124 throw ( uno::RuntimeException
)
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
)
134 SolarMutexGuard aSolarGuard
;
135 ::osl::MutexGuard
aGuard( getOslMutex() );
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
)
144 SolarMutexGuard aSolarGuard
;
145 ::osl::MutexGuard
aGuard( getOslMutex() );
147 ensureIsValidIndex( nChildIndex
);
148 return implGetRow( nChildIndex
);
151 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleColumn( sal_Int32 nChildIndex
)
152 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
)
154 SolarMutexGuard aSolarGuard
;
155 ::osl::MutexGuard
aGuard( getOslMutex() );
157 ensureIsValidIndex( nChildIndex
);
158 return implGetColumn( nChildIndex
);
161 // XInterface -----------------------------------------------------------------
163 Any SAL_CALL
AccessibleBrowseBoxTableBase::queryInterface( const uno::Type
& rType
)
164 throw ( uno::RuntimeException
)
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
)
186 return ::comphelper::concatSequences(
187 BrowseBoxAccessibleElement::getTypes(),
188 AccessibleBrowseBoxTableImplHelper::getTypes() );
193 class theAccessibleBrowseBoxTableBaseImplementationId
: public rtl::Static
< UnoTunnelIdInit
, theAccessibleBrowseBoxTableBaseImplementationId
> {};
196 Sequence
< sal_Int8
> SAL_CALL
AccessibleBrowseBoxTableBase::getImplementationId()
197 throw ( uno::RuntimeException
)
199 return theAccessibleBrowseBoxTableBaseImplementationId::get().getSeq();
202 // internal virtual methods ---------------------------------------------------
204 sal_Int32
AccessibleBrowseBoxTableBase::implGetRowCount() const
206 return mpBrowseBox
->GetRowCount();
209 sal_Int32
AccessibleBrowseBoxTableBase::implGetColumnCount() const
211 sal_uInt16 nColumns
= mpBrowseBox
->GetColumnCount();
212 // do not count the "handle column"
213 if( nColumns
&& implHasHandleColumn() )
218 // internal helper methods ----------------------------------------------------
220 sal_Bool
AccessibleBrowseBoxTableBase::implHasHandleColumn() const
222 return mpBrowseBox
->HasRowHeader();
225 sal_uInt16
AccessibleBrowseBoxTableBase::implToVCLColumnPos( sal_Int32 nColumn
) const
227 sal_uInt16 nVCLPos
= 0;
228 if( (0 <= nColumn
) && (nColumn
< implGetColumnCount()) )
230 // regard "handle column"
231 if( implHasHandleColumn() )
233 nVCLPos
= static_cast< sal_uInt16
>( nColumn
);
238 sal_Int32
AccessibleBrowseBoxTableBase::implGetChildCount() const
240 return implGetRowCount() * implGetColumnCount();
243 sal_Int32
AccessibleBrowseBoxTableBase::implGetRow( sal_Int32 nChildIndex
) const
245 sal_Int32 nColumns
= implGetColumnCount();
246 return nColumns
? (nChildIndex
/ nColumns
) : 0;
249 sal_Int32
AccessibleBrowseBoxTableBase::implGetColumn( sal_Int32 nChildIndex
) const
251 sal_Int32 nColumns
= implGetColumnCount();
252 return nColumns
? (nChildIndex
% nColumns
) : 0;
255 sal_Int32
AccessibleBrowseBoxTableBase::implGetChildIndex(
256 sal_Int32 nRow
, sal_Int32 nColumn
) const
258 return nRow
* implGetColumnCount() + nColumn
;
261 sal_Bool
AccessibleBrowseBoxTableBase::implIsRowSelected( sal_Int32 nRow
) const
263 return mpBrowseBox
->IsRowSelected( nRow
);
266 sal_Bool
AccessibleBrowseBoxTableBase::implIsColumnSelected( sal_Int32 nColumn
) const
268 if( implHasHandleColumn() )
270 return mpBrowseBox
->IsColumnSelected( nColumn
);
273 void AccessibleBrowseBoxTableBase::implSelectRow( sal_Int32 nRow
, sal_Bool bSelect
)
275 mpBrowseBox
->SelectRow( nRow
, bSelect
, sal_True
);
278 void AccessibleBrowseBoxTableBase::implSelectColumn( sal_Int32 nColumnPos
, sal_Bool bSelect
)
280 mpBrowseBox
->SelectColumn( (sal_uInt16
)nColumnPos
, bSelect
);
283 sal_Int32
AccessibleBrowseBoxTableBase::implGetSelectedRowCount() const
285 return mpBrowseBox
->GetSelectedRowCount();
288 sal_Int32
AccessibleBrowseBoxTableBase::implGetSelectedColumnCount() const
290 return mpBrowseBox
->GetSelectedColumnCount();
293 void AccessibleBrowseBoxTableBase::implGetSelectedRows( Sequence
< sal_Int32
>& rSeq
)
295 mpBrowseBox
->GetAllSelectedRows( rSeq
);
298 void AccessibleBrowseBoxTableBase::implGetSelectedColumns( Sequence
< sal_Int32
>& rSeq
)
300 mpBrowseBox
->GetAllSelectedColumns( rSeq
);
303 void AccessibleBrowseBoxTableBase::ensureIsValidRow( sal_Int32 nRow
)
304 throw ( lang::IndexOutOfBoundsException
)
306 if( nRow
>= implGetRowCount() )
307 throw lang::IndexOutOfBoundsException(
308 OUString( "row index is invalid" ), *this );
311 void AccessibleBrowseBoxTableBase::ensureIsValidColumn( sal_Int32 nColumn
)
312 throw ( lang::IndexOutOfBoundsException
)
314 if( nColumn
>= implGetColumnCount() )
315 throw lang::IndexOutOfBoundsException(
316 OUString( "column index is invalid" ), *this );
319 void AccessibleBrowseBoxTableBase::ensureIsValidAddress(
320 sal_Int32 nRow
, sal_Int32 nColumn
)
321 throw ( lang::IndexOutOfBoundsException
)
323 ensureIsValidRow( nRow
);
324 ensureIsValidColumn( nColumn
);
327 void AccessibleBrowseBoxTableBase::ensureIsValidIndex( sal_Int32 nChildIndex
)
328 throw ( lang::IndexOutOfBoundsException
)
330 if( nChildIndex
>= implGetChildCount() )
331 throw lang::IndexOutOfBoundsException(
332 OUString( "child index is invalid" ), *this );
335 // ============================================================================
337 } // namespace accessibility
339 // ============================================================================
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */