1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleBrowseBoxTableBase.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_accessibility.hxx"
35 #include "accessibility/extended/AccessibleBrowseBoxTableBase.hxx"
36 #include <svtools/accessibletableprovider.hxx>
37 #include <tools/multisel.hxx>
38 #include <comphelper/sequence.hxx>
40 // ============================================================================
42 using ::rtl::OUString
;
44 using ::com::sun::star::uno::Reference
;
45 using ::com::sun::star::uno::Sequence
;
46 using ::com::sun::star::uno::Any
;
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::accessibility
;
50 using namespace ::svt
;
52 // ============================================================================
54 namespace accessibility
{
56 // ============================================================================
58 // Ctor/Dtor/disposing --------------------------------------------------------
60 DBG_NAME( AccessibleBrowseBoxTableBase
)
62 AccessibleBrowseBoxTableBase::AccessibleBrowseBoxTableBase(
63 const Reference
< XAccessible
>& rxParent
,
64 IAccessibleTableProvider
& rBrowseBox
,
65 AccessibleBrowseBoxObjType eObjType
) :
66 BrowseBoxAccessibleElement( rxParent
, rBrowseBox
,NULL
, eObjType
)
68 DBG_CTOR( AccessibleBrowseBoxTableBase
, NULL
);
71 AccessibleBrowseBoxTableBase::~AccessibleBrowseBoxTableBase()
73 DBG_DTOR( AccessibleBrowseBoxTableBase
, NULL
);
76 // XAccessibleContext ---------------------------------------------------------
78 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleChildCount()
79 throw ( uno::RuntimeException
)
81 BBSolarGuard aSolarGuard
;
82 ::osl::MutexGuard
aGuard( getOslMutex() );
84 return implGetChildCount();
87 sal_Int16 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleRole()
88 throw ( uno::RuntimeException
)
91 return AccessibleRole::TABLE
;
94 // XAccessibleTable -----------------------------------------------------------
96 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleRowCount()
97 throw ( uno::RuntimeException
)
99 BBSolarGuard aSolarGuard
;
100 ::osl::MutexGuard
aGuard( getOslMutex() );
102 return implGetRowCount();
105 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleColumnCount()
106 throw ( uno::RuntimeException
)
108 BBSolarGuard aSolarGuard
;
109 ::osl::MutexGuard
aGuard( getOslMutex() );
111 return implGetColumnCount();
114 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleRowExtentAt(
115 sal_Int32 nRow
, sal_Int32 nColumn
)
116 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
)
118 BBSolarGuard aSolarGuard
;
119 ::osl::MutexGuard
aGuard( getOslMutex() );
121 ensureIsValidAddress( nRow
, nColumn
);
122 return 1; // merged cells not supported
125 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleColumnExtentAt(
126 sal_Int32 nRow
, sal_Int32 nColumn
)
127 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
)
129 BBSolarGuard aSolarGuard
;
130 ::osl::MutexGuard
aGuard( getOslMutex() );
132 ensureIsValidAddress( nRow
, nColumn
);
133 return 1; // merged cells not supported
136 Reference
< XAccessible
> SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleCaption()
137 throw ( uno::RuntimeException
)
140 return NULL
; // not supported
143 Reference
< XAccessible
> SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleSummary()
144 throw ( uno::RuntimeException
)
147 return NULL
; // not supported
150 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleIndex(
151 sal_Int32 nRow
, sal_Int32 nColumn
)
152 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
)
154 BBSolarGuard aSolarGuard
;
155 ::osl::MutexGuard
aGuard( getOslMutex() );
157 ensureIsValidAddress( nRow
, nColumn
);
158 return implGetChildIndex( nRow
, nColumn
);
161 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleRow( sal_Int32 nChildIndex
)
162 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
)
164 BBSolarGuard aSolarGuard
;
165 ::osl::MutexGuard
aGuard( getOslMutex() );
167 ensureIsValidIndex( nChildIndex
);
168 return implGetRow( nChildIndex
);
171 sal_Int32 SAL_CALL
AccessibleBrowseBoxTableBase::getAccessibleColumn( sal_Int32 nChildIndex
)
172 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
)
174 BBSolarGuard aSolarGuard
;
175 ::osl::MutexGuard
aGuard( getOslMutex() );
177 ensureIsValidIndex( nChildIndex
);
178 return implGetColumn( nChildIndex
);
181 // XInterface -----------------------------------------------------------------
183 Any SAL_CALL
AccessibleBrowseBoxTableBase::queryInterface( const uno::Type
& rType
)
184 throw ( uno::RuntimeException
)
186 Any
aAny( BrowseBoxAccessibleElement::queryInterface( rType
) );
187 return aAny
.hasValue() ?
188 aAny
: AccessibleBrowseBoxTableImplHelper::queryInterface( rType
);
191 void SAL_CALL
AccessibleBrowseBoxTableBase::acquire() throw ()
193 BrowseBoxAccessibleElement::acquire();
196 void SAL_CALL
AccessibleBrowseBoxTableBase::release() throw ()
198 BrowseBoxAccessibleElement::release();
201 // XTypeProvider --------------------------------------------------------------
203 Sequence
< uno::Type
> SAL_CALL
AccessibleBrowseBoxTableBase::getTypes()
204 throw ( uno::RuntimeException
)
206 return ::comphelper::concatSequences(
207 BrowseBoxAccessibleElement::getTypes(),
208 AccessibleBrowseBoxTableImplHelper::getTypes() );
211 Sequence
< sal_Int8
> SAL_CALL
AccessibleBrowseBoxTableBase::getImplementationId()
212 throw ( uno::RuntimeException
)
214 ::osl::MutexGuard
aGuard( getOslGlobalMutex() );
215 static Sequence
< sal_Int8
> aId
;
216 implCreateUuid( aId
);
220 // internal virtual methods ---------------------------------------------------
222 sal_Int32
AccessibleBrowseBoxTableBase::implGetRowCount() const
224 return mpBrowseBox
->GetRowCount();
227 sal_Int32
AccessibleBrowseBoxTableBase::implGetColumnCount() const
229 sal_uInt16 nColumns
= mpBrowseBox
->GetColumnCount();
230 // do not count the "handle column"
231 if( nColumns
&& implHasHandleColumn() )
236 // internal helper methods ----------------------------------------------------
238 sal_Bool
AccessibleBrowseBoxTableBase::implHasHandleColumn() const
240 return mpBrowseBox
->HasRowHeader();
243 sal_uInt16
AccessibleBrowseBoxTableBase::implToVCLColumnPos( sal_Int32 nColumn
) const
245 sal_uInt16 nVCLPos
= 0;
246 if( (0 <= nColumn
) && (nColumn
< implGetColumnCount()) )
248 // regard "handle column"
249 if( implHasHandleColumn() )
251 nVCLPos
= static_cast< sal_uInt16
>( nColumn
);
256 sal_Int32
AccessibleBrowseBoxTableBase::implGetChildCount() const
258 return implGetRowCount() * implGetColumnCount();
261 sal_Int32
AccessibleBrowseBoxTableBase::implGetRow( sal_Int32 nChildIndex
) const
263 sal_Int32 nColumns
= implGetColumnCount();
264 return nColumns
? (nChildIndex
/ nColumns
) : 0;
267 sal_Int32
AccessibleBrowseBoxTableBase::implGetColumn( sal_Int32 nChildIndex
) const
269 sal_Int32 nColumns
= implGetColumnCount();
270 return nColumns
? (nChildIndex
% nColumns
) : 0;
273 sal_Int32
AccessibleBrowseBoxTableBase::implGetChildIndex(
274 sal_Int32 nRow
, sal_Int32 nColumn
) const
276 return nRow
* implGetColumnCount() + nColumn
;
279 sal_Bool
AccessibleBrowseBoxTableBase::implIsRowSelected( sal_Int32 nRow
) const
281 return mpBrowseBox
->IsRowSelected( nRow
);
284 sal_Bool
AccessibleBrowseBoxTableBase::implIsColumnSelected( sal_Int32 nColumn
) const
286 if( implHasHandleColumn() )
288 return mpBrowseBox
->IsColumnSelected( nColumn
);
291 void AccessibleBrowseBoxTableBase::implSelectRow( sal_Int32 nRow
, sal_Bool bSelect
)
293 mpBrowseBox
->SelectRow( nRow
, bSelect
, sal_True
);
296 void AccessibleBrowseBoxTableBase::implSelectColumn( sal_Int32 nColumnPos
, sal_Bool bSelect
)
298 mpBrowseBox
->SelectColumn( (sal_uInt16
)nColumnPos
, bSelect
);
301 sal_Int32
AccessibleBrowseBoxTableBase::implGetSelectedRowCount() const
303 return mpBrowseBox
->GetSelectedRowCount();
306 sal_Int32
AccessibleBrowseBoxTableBase::implGetSelectedColumnCount() const
308 return mpBrowseBox
->GetSelectedColumnCount();
311 void AccessibleBrowseBoxTableBase::implGetSelectedRows( Sequence
< sal_Int32
>& rSeq
)
313 mpBrowseBox
->GetAllSelectedRows( rSeq
);
316 void AccessibleBrowseBoxTableBase::implGetSelectedColumns( Sequence
< sal_Int32
>& rSeq
)
318 mpBrowseBox
->GetAllSelectedColumns( rSeq
);
321 void AccessibleBrowseBoxTableBase::ensureIsValidRow( sal_Int32 nRow
)
322 throw ( lang::IndexOutOfBoundsException
)
324 if( nRow
>= implGetRowCount() )
325 throw lang::IndexOutOfBoundsException(
326 OUString( RTL_CONSTASCII_USTRINGPARAM( "row index is invalid" ) ), *this );
329 void AccessibleBrowseBoxTableBase::ensureIsValidColumn( sal_Int32 nColumn
)
330 throw ( lang::IndexOutOfBoundsException
)
332 if( nColumn
>= implGetColumnCount() )
333 throw lang::IndexOutOfBoundsException(
334 OUString( RTL_CONSTASCII_USTRINGPARAM("column index is invalid") ), *this );
337 void AccessibleBrowseBoxTableBase::ensureIsValidAddress(
338 sal_Int32 nRow
, sal_Int32 nColumn
)
339 throw ( lang::IndexOutOfBoundsException
)
341 ensureIsValidRow( nRow
);
342 ensureIsValidColumn( nColumn
);
345 void AccessibleBrowseBoxTableBase::ensureIsValidIndex( sal_Int32 nChildIndex
)
346 throw ( lang::IndexOutOfBoundsException
)
348 if( nChildIndex
>= implGetChildCount() )
349 throw lang::IndexOutOfBoundsException(
350 OUString( RTL_CONSTASCII_USTRINGPARAM("child index is invalid") ), *this );
353 // ============================================================================
355 } // namespace accessibility
357 // ============================================================================