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 <com/sun/star/lang/IndexOutOfBoundsException.hpp>
21 #include <extended/AccessibleGridControlTable.hxx>
22 #include <extended/AccessibleGridControlTableCell.hxx>
23 #include <toolkit/helper/convert.hxx>
24 #include <vcl/accessibletable.hxx>
25 #include <vcl/svapp.hxx>
26 #include <tools/debug.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 ::vcl
;
35 using namespace ::vcl::table
;
38 namespace accessibility
{
41 AccessibleGridControlTable::AccessibleGridControlTable(
42 const Reference
< XAccessible
>& rxParent
,
43 IAccessibleTable
& rTable
) :
44 AccessibleGridControlTableBase( rxParent
, rTable
, TCTYPE_TABLE
)
48 // XAccessibleContext ---------------------------------------------------------
50 Reference
< XAccessible
> SAL_CALL
51 AccessibleGridControlTable::getAccessibleChild( sal_Int32 nChildIndex
)
53 SolarMutexGuard aSolarGuard
;
56 ensureIsValidIndex( nChildIndex
);
57 sal_Int32 nCount
= getAccessibleChildCount();
58 if(m_pAccessCellVector
.empty() || m_pAccessCellVector
.size() != static_cast<unsigned>(nCount
))
60 m_pAccessCellVector
.resize(nCount
);
61 m_pCellVector
.resize(nCount
);
63 if(!m_pAccessCellVector
[nChildIndex
].is())
65 AccessibleGridControlTableCell
* pCell
= new AccessibleGridControlTableCell(this, m_aTable
, nChildIndex
/m_aTable
.GetColumnCount(), nChildIndex
%m_aTable
.GetColumnCount());
66 m_pCellVector
[nChildIndex
] = pCell
;
67 m_pAccessCellVector
[nChildIndex
] = pCell
;
69 return m_pAccessCellVector
[nChildIndex
];
72 sal_Int32 SAL_CALL
AccessibleGridControlTable::getAccessibleIndexInParent()
75 if(m_aTable
.HasRowHeader() && m_aTable
.HasColHeader())
77 else if((!m_aTable
.HasRowHeader() && m_aTable
.HasColHeader()) || (m_aTable
.HasRowHeader() && !m_aTable
.HasColHeader()) )
83 // XAccessibleComponent -------------------------------------------------------
85 Reference
< XAccessible
> SAL_CALL
86 AccessibleGridControlTable::getAccessibleAtPoint( const awt::Point
& rPoint
)
88 SolarMutexGuard aSolarGuard
;
92 Reference
< XAccessible
> xChild
;
94 sal_Int32 nColumnPos
= 0;
95 if( m_aTable
.ConvertPointToCellAddress( nRow
, nColumnPos
, VCLPoint( rPoint
) ) )
96 xChild
= new AccessibleGridControlTableCell(this, m_aTable
, nRow
, nColumnPos
);
100 void SAL_CALL
AccessibleGridControlTable::grabFocus()
102 SolarMutexGuard aSolarGuard
;
105 m_aTable
.GrabFocus();
108 // XAccessibleTable -----------------------------------------------------------
110 OUString SAL_CALL
AccessibleGridControlTable::getAccessibleRowDescription( sal_Int32 nRow
)
112 SolarMutexGuard aSolarGuard
;
115 ensureIsValidRow( nRow
);
116 return "row description";
119 OUString SAL_CALL
AccessibleGridControlTable::getAccessibleColumnDescription( sal_Int32 nColumn
)
121 SolarMutexGuard aSolarGuard
;
124 ensureIsValidColumn( nColumn
);
125 return "col description";
128 Reference
< XAccessibleTable
> SAL_CALL
AccessibleGridControlTable::getAccessibleRowHeaders()
133 if(m_aTable
.HasColHeader())
134 return implGetHeaderBar( 1 );
136 return implGetHeaderBar( 0 );
139 Reference
< XAccessibleTable
> SAL_CALL
AccessibleGridControlTable::getAccessibleColumnHeaders()
144 return implGetHeaderBar( 0 );
147 Sequence
< sal_Int32
> SAL_CALL
AccessibleGridControlTable::getSelectedAccessibleRows()
149 SolarMutexGuard aSolarGuard
;
152 Sequence
< sal_Int32
> aSelSeq
;
153 implGetSelectedRows( aSelSeq
);
157 //columns aren't selectable
158 Sequence
< sal_Int32
> SAL_CALL
AccessibleGridControlTable::getSelectedAccessibleColumns()
160 Sequence
< sal_Int32
> aSelSeq(0);
164 sal_Bool SAL_CALL
AccessibleGridControlTable::isAccessibleRowSelected( sal_Int32 nRow
)
166 SolarMutexGuard aSolarGuard
;
169 ensureIsValidRow( nRow
);
170 Sequence
< sal_Int32
> selectedRows
= getSelectedAccessibleRows();
171 return comphelper::findValue(selectedRows
, nRow
) != -1;
174 //columns aren't selectable
175 sal_Bool SAL_CALL
AccessibleGridControlTable::isAccessibleColumnSelected( sal_Int32
)
180 Reference
< XAccessible
> SAL_CALL
AccessibleGridControlTable::getAccessibleCellAt(
181 sal_Int32 nRow
, sal_Int32 nColumn
)
183 SolarMutexGuard aSolarGuard
;
186 ensureIsValidAddress( nRow
, nColumn
);
187 sal_Int32 nCount
= getAccessibleChildCount();
188 sal_Int32 nChildIndex
= nRow
*m_aTable
.GetColumnCount() + nColumn
;
189 if(m_pAccessCellVector
.empty() || m_pAccessCellVector
.size() != static_cast<unsigned>(nCount
))
191 m_pAccessCellVector
.resize(nCount
);
192 m_pCellVector
.resize(nCount
);
194 if(!m_pAccessCellVector
[nChildIndex
].is())
196 AccessibleGridControlTableCell
* pCell
= new AccessibleGridControlTableCell(this, m_aTable
, nRow
, nColumn
);
197 m_pCellVector
[nChildIndex
] = pCell
;
198 m_pAccessCellVector
[nChildIndex
] = pCell
;
200 return m_pAccessCellVector
[nChildIndex
];
203 sal_Bool SAL_CALL
AccessibleGridControlTable::isAccessibleSelected(
204 sal_Int32 nRow
, sal_Int32 nColumn
)
206 SolarMutexGuard aSolarGuard
;
209 ensureIsValidAddress( nRow
, nColumn
);
210 //selection of single cells not possible, so if row is selected, the cell will be selected too
211 return isAccessibleRowSelected(nRow
);
213 void SAL_CALL
AccessibleGridControlTable::selectAccessibleChild( sal_Int32 nChildIndex
)
215 SolarMutexGuard aSolarGuard
;
218 ensureIsValidIndex( nChildIndex
);
219 sal_Int32 nColumns
= m_aTable
.GetColumnCount();
220 sal_Int32 nRow
= nChildIndex
/ nColumns
;
221 m_aTable
.SelectRow( nRow
, true );
223 sal_Bool SAL_CALL
AccessibleGridControlTable::isAccessibleChildSelected( sal_Int32 nChildIndex
)
225 SolarMutexGuard aSolarGuard
;
228 ensureIsValidIndex( nChildIndex
);
229 sal_Int32 nColumns
= m_aTable
.GetColumnCount();
230 sal_Int32 nRow
= nChildIndex
/ nColumns
;
231 return isAccessibleRowSelected(nRow
);
233 void SAL_CALL
AccessibleGridControlTable::clearAccessibleSelection()
235 SolarMutexGuard aSolarGuard
;
238 m_aTable
.SelectAllRows( false );
240 void SAL_CALL
AccessibleGridControlTable::selectAllAccessibleChildren()
242 SolarMutexGuard aSolarGuard
;
245 Sequence
< sal_Int32
> selectedRows
= getSelectedAccessibleRows();
246 for(long i
=0; i
<m_aTable
.GetRowCount(); i
++)
249 sal_Int32 SAL_CALL
AccessibleGridControlTable::getSelectedAccessibleChildCount()
251 SolarMutexGuard aSolarGuard
;
254 Sequence
< sal_Int32
> selectedRows
= getSelectedAccessibleRows();
255 sal_Int32 nColumns
= m_aTable
.GetColumnCount();
256 return selectedRows
.getLength()*nColumns
;
258 Reference
< XAccessible
> SAL_CALL
259 AccessibleGridControlTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
)
261 SolarMutexGuard aSolarGuard
;
264 if(isAccessibleChildSelected(nSelectedChildIndex
))
265 return getAccessibleChild(nSelectedChildIndex
);
269 //not implemented yet, because only row selection possible
270 void SAL_CALL
AccessibleGridControlTable::deselectAccessibleChild(
273 SolarMutexGuard aSolarGuard
;
277 // XInterface -----------------------------------------------------------------
279 Any SAL_CALL
AccessibleGridControlTable::queryInterface( const uno::Type
& rType
)
281 Any
aAny( AccessibleGridControlTableBase::queryInterface( rType
) );
282 return aAny
.hasValue() ?
283 aAny
: AccessibleGridControlTableSelectionImplHelper::queryInterface( rType
);
286 void SAL_CALL
AccessibleGridControlTable::acquire() throw ()
288 AccessibleGridControlTableBase::acquire();
291 void SAL_CALL
AccessibleGridControlTable::release() throw ()
293 AccessibleGridControlTableBase::release();
295 // XServiceInfo ---------------------------------------------------------------
297 OUString SAL_CALL
AccessibleGridControlTable::getImplementationName()
299 return "com.sun.star.accessibility.AccessibleGridControlTable";
302 // internal virtual methods ---------------------------------------------------
304 tools::Rectangle
AccessibleGridControlTable::implGetBoundingBox()
306 vcl::Window
* pParent
= m_aTable
.GetAccessibleParentWindow();
307 DBG_ASSERT( pParent
, "implGetBoundingBox - missing parent window" );
308 tools::Rectangle
aGridRect( m_aTable
.GetWindowExtentsRelative( pParent
));
309 tools::Rectangle
aTableRect( m_aTable
.calcTableRect() );
310 long nX
= aGridRect
.Left() + aTableRect
.Left();
311 long nY
= aGridRect
.Top() + aTableRect
.Top();
312 long nWidth
= aGridRect
.GetSize().Width()-aTableRect
.Left();
313 long nHeight
= aGridRect
.GetSize().Height()-aTableRect
.Top();
314 tools::Rectangle
aTable( Point( nX
, nY
), Size( nWidth
, nHeight
));
318 tools::Rectangle
AccessibleGridControlTable::implGetBoundingBoxOnScreen()
320 tools::Rectangle
aGridRect( m_aTable
.GetWindowExtentsRelative( nullptr ));
321 tools::Rectangle
aTableRect( m_aTable
.calcTableRect() );
322 long nX
= aGridRect
.Left() + aTableRect
.Left();
323 long nY
= aGridRect
.Top() + aTableRect
.Top();
324 long nWidth
= aGridRect
.GetSize().Width()-aTableRect
.Left();
325 long nHeight
= aGridRect
.GetSize().Height()-aTableRect
.Top();
326 tools::Rectangle
aTable( Point( nX
, nY
), Size( nWidth
, nHeight
));
329 // internal helper methods ----------------------------------------------------
330 Reference
< XAccessibleTable
> AccessibleGridControlTable::implGetHeaderBar(
331 sal_Int32 nChildIndex
)
333 Reference
< XAccessible
> xRet
;
334 Reference
< XAccessibleContext
> xContext( m_xParent
, uno::UNO_QUERY
);
339 xRet
= xContext
->getAccessibleChild( nChildIndex
);
341 catch (const lang::IndexOutOfBoundsException
&)
343 OSL_FAIL( "implGetHeaderBar - wrong child index" );
345 // RuntimeException goes to caller
347 return Reference
< XAccessibleTable
>( xRet
, uno::UNO_QUERY
);
351 } // namespace accessibility
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */