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/AccessibleGridControlTable.hxx"
21 #include "accessibility/extended/AccessibleGridControlTableCell.hxx"
22 #include <svtools/accessibletable.hxx>
26 using ::com::sun::star::uno::Reference
;
27 using ::com::sun::star::uno::Sequence
;
28 using ::com::sun::star::uno::Any
;
30 using namespace ::com::sun::star
;
31 using namespace ::com::sun::star::accessibility
;
32 using namespace ::svt
;
33 using namespace ::svt::table
;
36 namespace accessibility
{
40 AccessibleGridControlTable::AccessibleGridControlTable(
41 const Reference
< XAccessible
>& rxParent
,
42 IAccessibleTable
& rTable
,
43 AccessibleTableControlObjType _eType
) :
44 AccessibleGridControlTableBase( rxParent
, rTable
, _eType
)
46 ,m_pAccessCellVector( )
50 AccessibleGridControlTable::~AccessibleGridControlTable()
54 // XAccessibleContext ---------------------------------------------------------
56 Reference
< XAccessible
> SAL_CALL
57 AccessibleGridControlTable::getAccessibleChild( sal_Int32 nChildIndex
)
58 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
60 SolarMutexGuard aSolarGuard
;
63 ensureIsValidIndex( nChildIndex
);
64 sal_Int32 nCount
= getAccessibleChildCount();
65 if(m_pAccessCellVector
.size() == 0 || m_pAccessCellVector
.size() != (unsigned)nCount
)
67 m_pAccessCellVector
.resize(nCount
);
68 m_pCellVector
.resize(nCount
);
70 if(!m_pAccessCellVector
[nChildIndex
].is())
72 AccessibleGridControlTableCell
* pCell
= new AccessibleGridControlTableCell(this, m_aTable
, nChildIndex
/m_aTable
.GetColumnCount(), nChildIndex
%m_aTable
.GetColumnCount(), TCTYPE_TABLECELL
);
73 m_pCellVector
[nChildIndex
] = pCell
;
74 m_pAccessCellVector
[nChildIndex
] = pCell
;
76 return m_pAccessCellVector
[nChildIndex
];
79 sal_Int32 SAL_CALL
AccessibleGridControlTable::getAccessibleIndexInParent()
80 throw ( uno::RuntimeException
, std::exception
)
83 if(m_aTable
.HasRowHeader() && m_aTable
.HasColHeader())
85 else if((!m_aTable
.HasRowHeader() && m_aTable
.HasColHeader()) || (m_aTable
.HasRowHeader() && !m_aTable
.HasColHeader()) )
91 // XAccessibleComponent -------------------------------------------------------
93 Reference
< XAccessible
> SAL_CALL
94 AccessibleGridControlTable::getAccessibleAtPoint( const awt::Point
& rPoint
)
95 throw ( uno::RuntimeException
, std::exception
)
97 SolarMutexGuard aSolarGuard
;
101 Reference
< XAccessible
> xChild
;
103 sal_Int32 nColumnPos
= 0;
104 if( m_aTable
.ConvertPointToCellAddress( nRow
, nColumnPos
, VCLPoint( rPoint
) ) )
105 xChild
= new AccessibleGridControlTableCell(this, m_aTable
, nRow
, nColumnPos
, TCTYPE_TABLECELL
);
109 void SAL_CALL
AccessibleGridControlTable::grabFocus()
110 throw ( uno::RuntimeException
, std::exception
)
112 SolarMutexGuard aSolarGuard
;
115 m_aTable
.GrabFocus();
118 // XAccessibleTable -----------------------------------------------------------
120 OUString SAL_CALL
AccessibleGridControlTable::getAccessibleRowDescription( sal_Int32 nRow
)
121 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
123 SolarMutexGuard aSolarGuard
;
126 ensureIsValidRow( nRow
);
127 return m_aTable
.GetRowDescription( nRow
);
130 OUString SAL_CALL
AccessibleGridControlTable::getAccessibleColumnDescription( sal_Int32 nColumn
)
131 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
133 SolarMutexGuard aSolarGuard
;
136 ensureIsValidColumn( nColumn
);
137 return m_aTable
.GetColumnDescription( (sal_uInt16
)nColumn
);
140 Reference
< XAccessibleTable
> SAL_CALL
AccessibleGridControlTable::getAccessibleRowHeaders()
141 throw ( uno::RuntimeException
, std::exception
)
146 if(m_aTable
.HasColHeader())
147 return implGetHeaderBar( 1 );
149 return implGetHeaderBar( 0 );
152 Reference
< XAccessibleTable
> SAL_CALL
AccessibleGridControlTable::getAccessibleColumnHeaders()
153 throw ( uno::RuntimeException
, std::exception
)
158 return implGetHeaderBar( 0 );
161 Sequence
< sal_Int32
> SAL_CALL
AccessibleGridControlTable::getSelectedAccessibleRows()
162 throw ( uno::RuntimeException
, std::exception
)
164 SolarMutexGuard aSolarGuard
;
167 Sequence
< sal_Int32
> aSelSeq
;
168 implGetSelectedRows( aSelSeq
);
172 //columns aren't selectable
173 Sequence
< sal_Int32
> SAL_CALL
AccessibleGridControlTable::getSelectedAccessibleColumns()
174 throw ( uno::RuntimeException
, std::exception
)
176 Sequence
< sal_Int32
> aSelSeq(0);
180 sal_Bool SAL_CALL
AccessibleGridControlTable::isAccessibleRowSelected( sal_Int32 nRow
)
181 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
183 SolarMutexGuard aSolarGuard
;
186 ensureIsValidRow( nRow
);
187 bool bSelected
= false;
188 Sequence
< sal_Int32
> selectedRows
= getSelectedAccessibleRows();
189 for(int i
=0; i
<selectedRows
.getLength(); i
++)
191 if(nRow
== selectedRows
[i
])
200 //columns aren't selectable
201 sal_Bool SAL_CALL
AccessibleGridControlTable::isAccessibleColumnSelected( sal_Int32 nColumn
)
202 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
208 Reference
< XAccessible
> SAL_CALL
AccessibleGridControlTable::getAccessibleCellAt(
209 sal_Int32 nRow
, sal_Int32 nColumn
)
210 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
212 SolarMutexGuard aSolarGuard
;
215 ensureIsValidAddress( nRow
, nColumn
);
216 sal_Int32 nCount
= getAccessibleChildCount();
217 sal_Int32 nChildIndex
= nRow
*m_aTable
.GetColumnCount() + nColumn
;
218 if(m_pAccessCellVector
.size() == 0 || m_pAccessCellVector
.size() != (unsigned)nCount
)
220 m_pAccessCellVector
.resize(nCount
);
221 m_pCellVector
.resize(nCount
);
223 if(!m_pAccessCellVector
[nChildIndex
].is())
225 AccessibleGridControlTableCell
* pCell
= new AccessibleGridControlTableCell(this, m_aTable
, nRow
, nColumn
, TCTYPE_TABLECELL
);
226 m_pCellVector
[nChildIndex
] = pCell
;
227 m_pAccessCellVector
[nChildIndex
] = pCell
;
229 return m_pAccessCellVector
[nChildIndex
];
232 sal_Bool SAL_CALL
AccessibleGridControlTable::isAccessibleSelected(
233 sal_Int32 nRow
, sal_Int32 nColumn
)
234 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
236 SolarMutexGuard aSolarGuard
;
239 ensureIsValidAddress( nRow
, nColumn
);
241 //selection of single cells not possible, so if row is selected, the cell will be selected too
242 return isAccessibleRowSelected(nRow
);
244 void SAL_CALL
AccessibleGridControlTable::selectAccessibleChild( sal_Int32 nChildIndex
)
245 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
247 SolarMutexGuard aSolarGuard
;
250 ensureIsValidIndex( nChildIndex
);
251 sal_Int32 nColumns
= m_aTable
.GetColumnCount();
252 sal_Int32 nRow
= (nChildIndex
/ nColumns
);
253 m_aTable
.SelectRow( nRow
, true );
255 sal_Bool SAL_CALL
AccessibleGridControlTable::isAccessibleChildSelected( sal_Int32 nChildIndex
)
256 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
258 SolarMutexGuard aSolarGuard
;
261 ensureIsValidIndex( nChildIndex
);
262 sal_Int32 nColumns
= m_aTable
.GetColumnCount();
263 sal_Int32 nRow
= (nChildIndex
/ nColumns
);
264 return isAccessibleRowSelected(nRow
);
266 void SAL_CALL
AccessibleGridControlTable::clearAccessibleSelection()
267 throw ( uno::RuntimeException
, std::exception
)
269 SolarMutexGuard aSolarGuard
;
272 m_aTable
.SelectAllRows( false );
274 void SAL_CALL
AccessibleGridControlTable::selectAllAccessibleChildren()
275 throw ( uno::RuntimeException
, std::exception
)
277 SolarMutexGuard aSolarGuard
;
280 Sequence
< sal_Int32
> selectedRows
= getSelectedAccessibleRows();
281 for(int i
=0;i
<m_aTable
.GetRowCount();i
++)
284 sal_Int32 SAL_CALL
AccessibleGridControlTable::getSelectedAccessibleChildCount()
285 throw ( uno::RuntimeException
, std::exception
)
287 SolarMutexGuard aSolarGuard
;
290 Sequence
< sal_Int32
> selectedRows
= getSelectedAccessibleRows();
291 sal_Int32 nColumns
= m_aTable
.GetColumnCount();
292 return selectedRows
.getLength()*nColumns
;
294 Reference
< XAccessible
> SAL_CALL
295 AccessibleGridControlTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
)
296 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
298 SolarMutexGuard aSolarGuard
;
301 if(isAccessibleChildSelected(nSelectedChildIndex
))
302 return getAccessibleChild(nSelectedChildIndex
);
306 //not implemented yet, because only row selection possible
307 void SAL_CALL
AccessibleGridControlTable::deselectAccessibleChild(
308 sal_Int32 nSelectedChildIndex
)
309 throw ( lang::IndexOutOfBoundsException
, uno::RuntimeException
, std::exception
)
311 SolarMutexGuard aSolarGuard
;
314 (void)nSelectedChildIndex
;
316 // XInterface -----------------------------------------------------------------
318 Any SAL_CALL
AccessibleGridControlTable::queryInterface( const uno::Type
& rType
)
319 throw ( uno::RuntimeException
, std::exception
)
321 Any
aAny( AccessibleGridControlTableBase::queryInterface( rType
) );
322 return aAny
.hasValue() ?
323 aAny
: AccessibleGridControlTableImplHelper1::queryInterface( rType
);
326 void SAL_CALL
AccessibleGridControlTable::acquire() throw ()
328 AccessibleGridControlTableBase::acquire();
331 void SAL_CALL
AccessibleGridControlTable::release() throw ()
333 AccessibleGridControlTableBase::release();
335 // XServiceInfo ---------------------------------------------------------------
337 OUString SAL_CALL
AccessibleGridControlTable::getImplementationName()
338 throw ( uno::RuntimeException
, std::exception
)
340 return OUString( "com.sun.star.accessibility.AccessibleGridControlTable" );
343 // internal virtual methods ---------------------------------------------------
345 Rectangle
AccessibleGridControlTable::implGetBoundingBox()
347 vcl::Window
* pParent
= m_aTable
.GetAccessibleParentWindow();
348 DBG_ASSERT( pParent
, "implGetBoundingBox - missing parent window" );
349 Rectangle
aGridRect( m_aTable
.GetWindowExtentsRelative( pParent
));
350 Rectangle
aTableRect( m_aTable
.calcTableRect() );
351 long nX
= aGridRect
.Left() + aTableRect
.Left();
352 long nY
= aGridRect
.Top() + aTableRect
.Top();
353 long nWidth
= aGridRect
.GetSize().Width()-aTableRect
.Left();
354 long nHeight
= aGridRect
.GetSize().Height()-aTableRect
.Top();
355 Rectangle
aTable( Point( nX
, nY
), Size( nWidth
, nHeight
));
359 Rectangle
AccessibleGridControlTable::implGetBoundingBoxOnScreen()
361 Rectangle
aGridRect( m_aTable
.GetWindowExtentsRelative( NULL
));
362 Rectangle
aTableRect( m_aTable
.calcTableRect() );
363 long nX
= aGridRect
.Left() + aTableRect
.Left();
364 long nY
= aGridRect
.Top() + aTableRect
.Top();
365 long nWidth
= aGridRect
.GetSize().Width()-aTableRect
.Left();
366 long nHeight
= aGridRect
.GetSize().Height()-aTableRect
.Top();
367 Rectangle
aTable( Point( nX
, nY
), Size( nWidth
, nHeight
));
370 // internal helper methods ----------------------------------------------------
371 Reference
< XAccessibleTable
> AccessibleGridControlTable::implGetHeaderBar(
372 sal_Int32 nChildIndex
)
373 throw ( uno::RuntimeException
)
375 Reference
< XAccessible
> xRet
;
376 Reference
< XAccessibleContext
> xContext( m_xParent
, uno::UNO_QUERY
);
381 xRet
= xContext
->getAccessibleChild( nChildIndex
);
383 catch (const lang::IndexOutOfBoundsException
&)
385 OSL_FAIL( "implGetHeaderBar - wrong child index" );
387 // RuntimeException goes to caller
389 return Reference
< XAccessibleTable
>( xRet
, uno::UNO_QUERY
);
395 } // namespace accessibility
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */