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_aCellVector
.empty() || m_aCellVector
.size() != static_cast<unsigned>(nCount
))
60 m_aCellVector
.resize(nCount
);
62 if(!m_aCellVector
[nChildIndex
].is())
64 rtl::Reference
<AccessibleGridControlTableCell
> pCell
= new AccessibleGridControlTableCell(this, m_aTable
, nChildIndex
/m_aTable
.GetColumnCount(), nChildIndex
%m_aTable
.GetColumnCount());
65 m_aCellVector
[nChildIndex
] = pCell
;
67 return m_aCellVector
[nChildIndex
];
70 sal_Int32 SAL_CALL
AccessibleGridControlTable::getAccessibleIndexInParent()
73 if(m_aTable
.HasRowHeader() && m_aTable
.HasColHeader())
75 else if((!m_aTable
.HasRowHeader() && m_aTable
.HasColHeader()) || (m_aTable
.HasRowHeader() && !m_aTable
.HasColHeader()) )
81 // XAccessibleComponent -------------------------------------------------------
83 Reference
< XAccessible
> SAL_CALL
84 AccessibleGridControlTable::getAccessibleAtPoint( const awt::Point
& rPoint
)
86 SolarMutexGuard aSolarGuard
;
90 Reference
< XAccessible
> xChild
;
92 sal_Int32 nColumnPos
= 0;
93 if( m_aTable
.ConvertPointToCellAddress( nRow
, nColumnPos
, VCLPoint( rPoint
) ) )
94 xChild
= new AccessibleGridControlTableCell(this, m_aTable
, nRow
, nColumnPos
);
98 void SAL_CALL
AccessibleGridControlTable::grabFocus()
100 SolarMutexGuard aSolarGuard
;
103 m_aTable
.GrabFocus();
106 // XAccessibleTable -----------------------------------------------------------
108 OUString SAL_CALL
AccessibleGridControlTable::getAccessibleRowDescription( sal_Int32 nRow
)
110 SolarMutexGuard aSolarGuard
;
113 ensureIsValidRow( nRow
);
114 return "row description";
117 OUString SAL_CALL
AccessibleGridControlTable::getAccessibleColumnDescription( sal_Int32 nColumn
)
119 SolarMutexGuard aSolarGuard
;
122 ensureIsValidColumn( nColumn
);
123 return "col description";
126 Reference
< XAccessibleTable
> SAL_CALL
AccessibleGridControlTable::getAccessibleRowHeaders()
131 if(m_aTable
.HasColHeader())
132 return implGetHeaderBar( 1 );
134 return implGetHeaderBar( 0 );
137 Reference
< XAccessibleTable
> SAL_CALL
AccessibleGridControlTable::getAccessibleColumnHeaders()
142 return implGetHeaderBar( 0 );
145 Sequence
< sal_Int32
> SAL_CALL
AccessibleGridControlTable::getSelectedAccessibleRows()
147 SolarMutexGuard aSolarGuard
;
150 Sequence
< sal_Int32
> aSelSeq
;
151 implGetSelectedRows( aSelSeq
);
155 //columns aren't selectable
156 Sequence
< sal_Int32
> SAL_CALL
AccessibleGridControlTable::getSelectedAccessibleColumns()
161 sal_Bool SAL_CALL
AccessibleGridControlTable::isAccessibleRowSelected( sal_Int32 nRow
)
163 SolarMutexGuard aSolarGuard
;
166 ensureIsValidRow( nRow
);
167 Sequence
< sal_Int32
> selectedRows
= getSelectedAccessibleRows();
168 return comphelper::findValue(selectedRows
, nRow
) != -1;
171 //columns aren't selectable
172 sal_Bool SAL_CALL
AccessibleGridControlTable::isAccessibleColumnSelected( sal_Int32
)
177 Reference
< XAccessible
> SAL_CALL
AccessibleGridControlTable::getAccessibleCellAt(
178 sal_Int32 nRow
, sal_Int32 nColumn
)
180 SolarMutexGuard aSolarGuard
;
183 ensureIsValidAddress( nRow
, nColumn
);
184 sal_Int32 nCount
= getAccessibleChildCount();
185 sal_Int32 nChildIndex
= nRow
*m_aTable
.GetColumnCount() + nColumn
;
186 if(m_aCellVector
.empty() || m_aCellVector
.size() != static_cast<unsigned>(nCount
))
188 m_aCellVector
.resize(nCount
);
190 if(!m_aCellVector
[nChildIndex
].is())
192 rtl::Reference
<AccessibleGridControlTableCell
> pCell
= new AccessibleGridControlTableCell(this, m_aTable
, nRow
, nColumn
);
193 m_aCellVector
[nChildIndex
] = pCell
;
195 return m_aCellVector
[nChildIndex
];
198 sal_Bool SAL_CALL
AccessibleGridControlTable::isAccessibleSelected(
199 sal_Int32 nRow
, sal_Int32 nColumn
)
201 SolarMutexGuard aSolarGuard
;
204 ensureIsValidAddress( nRow
, nColumn
);
205 //selection of single cells not possible, so if row is selected, the cell will be selected too
206 return isAccessibleRowSelected(nRow
);
208 void SAL_CALL
AccessibleGridControlTable::selectAccessibleChild( sal_Int32 nChildIndex
)
210 SolarMutexGuard aSolarGuard
;
213 ensureIsValidIndex( nChildIndex
);
214 sal_Int32 nColumns
= m_aTable
.GetColumnCount();
215 sal_Int32 nRow
= nChildIndex
/ nColumns
;
216 m_aTable
.SelectRow( nRow
, true );
218 sal_Bool SAL_CALL
AccessibleGridControlTable::isAccessibleChildSelected( sal_Int32 nChildIndex
)
220 SolarMutexGuard aSolarGuard
;
223 ensureIsValidIndex( nChildIndex
);
224 sal_Int32 nColumns
= m_aTable
.GetColumnCount();
225 sal_Int32 nRow
= nChildIndex
/ nColumns
;
226 return isAccessibleRowSelected(nRow
);
228 void SAL_CALL
AccessibleGridControlTable::clearAccessibleSelection()
230 SolarMutexGuard aSolarGuard
;
233 m_aTable
.SelectAllRows( false );
235 void SAL_CALL
AccessibleGridControlTable::selectAllAccessibleChildren()
237 SolarMutexGuard aSolarGuard
;
240 Sequence
< sal_Int32
> selectedRows
= getSelectedAccessibleRows();
241 auto selectedRowsRange
= asNonConstRange(selectedRows
);
242 for(tools::Long i
=0; i
<m_aTable
.GetRowCount(); i
++)
243 selectedRowsRange
[i
]=i
;
245 sal_Int32 SAL_CALL
AccessibleGridControlTable::getSelectedAccessibleChildCount()
247 SolarMutexGuard aSolarGuard
;
250 Sequence
< sal_Int32
> selectedRows
= getSelectedAccessibleRows();
251 sal_Int32 nColumns
= m_aTable
.GetColumnCount();
252 return selectedRows
.getLength()*nColumns
;
254 Reference
< XAccessible
> SAL_CALL
255 AccessibleGridControlTable::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex
)
257 SolarMutexGuard aSolarGuard
;
260 if(isAccessibleChildSelected(nSelectedChildIndex
))
261 return getAccessibleChild(nSelectedChildIndex
);
265 //not implemented yet, because only row selection possible
266 void SAL_CALL
AccessibleGridControlTable::deselectAccessibleChild(
269 SolarMutexGuard aSolarGuard
;
273 // XInterface -----------------------------------------------------------------
275 Any SAL_CALL
AccessibleGridControlTable::queryInterface( const uno::Type
& rType
)
277 Any
aAny( AccessibleGridControlTableBase::queryInterface( rType
) );
278 return aAny
.hasValue() ?
279 aAny
: AccessibleGridControlTableSelectionImplHelper::queryInterface( rType
);
282 void SAL_CALL
AccessibleGridControlTable::acquire() noexcept
284 AccessibleGridControlTableBase::acquire();
287 void SAL_CALL
AccessibleGridControlTable::release() noexcept
289 AccessibleGridControlTableBase::release();
291 // XServiceInfo ---------------------------------------------------------------
293 OUString SAL_CALL
AccessibleGridControlTable::getImplementationName()
295 return "com.sun.star.accessibility.AccessibleGridControlTable";
298 // internal virtual methods ---------------------------------------------------
300 tools::Rectangle
AccessibleGridControlTable::implGetBoundingBox()
302 vcl::Window
* pParent
= m_aTable
.GetAccessibleParentWindow();
303 DBG_ASSERT( pParent
, "implGetBoundingBox - missing parent window" );
304 tools::Rectangle
aGridRect( m_aTable
.GetWindowExtentsRelative( pParent
));
305 tools::Rectangle
aTableRect( m_aTable
.calcTableRect() );
306 tools::Long nX
= aGridRect
.Left() + aTableRect
.Left();
307 tools::Long nY
= aGridRect
.Top() + aTableRect
.Top();
308 tools::Long nWidth
= aGridRect
.GetSize().Width()-aTableRect
.Left();
309 tools::Long nHeight
= aGridRect
.GetSize().Height()-aTableRect
.Top();
310 tools::Rectangle
aTable( Point( nX
, nY
), Size( nWidth
, nHeight
));
314 tools::Rectangle
AccessibleGridControlTable::implGetBoundingBoxOnScreen()
316 tools::Rectangle
aGridRect( m_aTable
.GetWindowExtentsRelative( nullptr ));
317 tools::Rectangle
aTableRect( m_aTable
.calcTableRect() );
318 tools::Long nX
= aGridRect
.Left() + aTableRect
.Left();
319 tools::Long nY
= aGridRect
.Top() + aTableRect
.Top();
320 tools::Long nWidth
= aGridRect
.GetSize().Width()-aTableRect
.Left();
321 tools::Long nHeight
= aGridRect
.GetSize().Height()-aTableRect
.Top();
322 tools::Rectangle
aTable( Point( nX
, nY
), Size( nWidth
, nHeight
));
325 // internal helper methods ----------------------------------------------------
326 Reference
< XAccessibleTable
> AccessibleGridControlTable::implGetHeaderBar(
327 sal_Int32 nChildIndex
)
329 Reference
< XAccessible
> xRet
;
330 Reference
< XAccessibleContext
> xContext( m_xParent
, uno::UNO_QUERY
);
335 xRet
= xContext
->getAccessibleChild( nChildIndex
);
337 catch (const lang::IndexOutOfBoundsException
&)
339 OSL_FAIL( "implGetHeaderBar - wrong child index" );
341 // RuntimeException goes to caller
343 return Reference
< XAccessibleTable
>( xRet
, uno::UNO_QUERY
);
347 } // namespace accessibility
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */