bump product version to 7.6.3.2-android
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControl.cxx
blob800ab312d19ec1ba393d29cfe62ea08929423b3e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <extended/AccessibleGridControl.hxx>
21 #include <extended/AccessibleGridControlTable.hxx>
22 #include <extended/AccessibleGridControlHeader.hxx>
23 #include <com/sun/star/accessibility/AccessibleEventId.hpp>
24 #include <com/sun/star/accessibility/AccessibleRole.hpp>
25 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
26 #include <toolkit/helper/convert.hxx>
27 #include <utility>
28 #include <vcl/accessibletable.hxx>
29 #include <vcl/svapp.hxx>
31 namespace accessibility
34 using namespace ::com::sun::star::uno;
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::lang;
37 using namespace ::com::sun::star::accessibility;
38 using namespace ::vcl;
39 using namespace ::vcl::table;
41 AccessibleGridControl::AccessibleGridControl(
42 const css::uno::Reference< css::accessibility::XAccessible >& _rxParent, const css::uno::Reference< css::accessibility::XAccessible >& _rxCreator,
43 ::vcl::table::IAccessibleTable& _rTable )
44 : AccessibleGridControlBase( _rxParent, _rTable, TCTYPE_GRIDCONTROL ),
45 m_aCreator(_rxCreator)
50 void SAL_CALL AccessibleGridControl::disposing()
52 SolarMutexGuard g;
54 m_aCreator.clear();
56 if ( m_xTable.is() )
58 m_xTable->dispose();
59 m_xTable.clear();
61 if ( m_xRowHeaderBar.is() )
63 m_xRowHeaderBar->dispose();
64 m_xRowHeaderBar.clear();
66 if ( m_xColumnHeaderBar.is() )
68 m_xColumnHeaderBar->dispose();
69 m_xColumnHeaderBar.clear();
71 AccessibleGridControlBase::disposing();
74 sal_Int64 AccessibleGridControl::implGetAccessibleChildCount()
76 return m_aTable.GetAccessibleControlCount();
79 // css::accessibility::XAccessibleContext ---------------------------------------------------------
82 sal_Int64 SAL_CALL AccessibleGridControl::getAccessibleChildCount()
84 SolarMutexGuard aSolarGuard;
85 ensureIsAlive();
86 return implGetAccessibleChildCount();
90 css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
91 AccessibleGridControl::getAccessibleChild( sal_Int64 nChildIndex )
93 SolarMutexGuard aSolarGuard;
95 if (nChildIndex<0 || nChildIndex>=implGetAccessibleChildCount())
96 throw IndexOutOfBoundsException();
98 css::uno::Reference< css::accessibility::XAccessible > xChild;
99 if (isAlive())
101 if(nChildIndex == 0 && m_aTable.HasColHeader())
103 if(!m_xColumnHeaderBar.is())
105 m_xColumnHeaderBar = new AccessibleGridControlHeader(m_aCreator, m_aTable, vcl::table::TCTYPE_COLUMNHEADERBAR);
107 xChild = m_xColumnHeaderBar.get();
109 else if(m_aTable.HasRowHeader() && (nChildIndex == 1 || nChildIndex == 0))
111 if(!m_xRowHeaderBar.is())
113 m_xRowHeaderBar = new AccessibleGridControlHeader(m_aCreator, m_aTable, vcl::table::TCTYPE_ROWHEADERBAR);
115 xChild = m_xRowHeaderBar.get();
117 else
119 if(!m_xTable.is())
121 m_xTable = new AccessibleGridControlTable(m_aCreator, m_aTable);
123 xChild = m_xTable.get();
126 return xChild;
130 sal_Int16 SAL_CALL AccessibleGridControl::getAccessibleRole()
132 SolarMutexGuard g;
134 ensureIsAlive();
135 return AccessibleRole::PANEL;
139 // css::accessibility::XAccessibleComponent -------------------------------------------------------
141 css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
142 AccessibleGridControl::getAccessibleAtPoint( const awt::Point& rPoint )
144 SolarMutexGuard aSolarGuard;
145 ensureIsAlive();
147 css::uno::Reference< css::accessibility::XAccessible > xChild;
148 sal_Int32 nIndex = 0;
149 if( m_aTable.ConvertPointToControlIndex( nIndex, VCLPoint( rPoint ) ) )
150 xChild = m_aTable.CreateAccessibleControl( nIndex );
151 else
153 // try whether point is in one of the fixed children
154 // (table, header bars, corner control)
155 Point aPoint( VCLPoint( rPoint ) );
156 for( nIndex = 0; (nIndex < 3) && !xChild.is(); ++nIndex )
158 css::uno::Reference< css::accessibility::XAccessible > xCurrChild( implGetFixedChild( nIndex ) );
159 css::uno::Reference< css::accessibility::XAccessibleComponent >
160 xCurrChildComp( xCurrChild, uno::UNO_QUERY );
162 if( xCurrChildComp.is() &&
163 VCLRectangle( xCurrChildComp->getBounds() ).Contains( aPoint ) )
164 xChild = xCurrChild;
167 return xChild;
171 void SAL_CALL AccessibleGridControl::grabFocus()
173 SolarMutexGuard aSolarGuard;
174 ensureIsAlive();
175 m_aTable.GrabFocus();
178 // XServiceInfo ---------------------------------------------------------------
180 OUString SAL_CALL AccessibleGridControl::getImplementationName()
182 return "com.sun.star.accessibility.AccessibleGridControl";
186 // internal virtual methods ---------------------------------------------------
188 tools::Rectangle AccessibleGridControl::implGetBoundingBox()
190 vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
191 OSL_ENSURE( pParent, "implGetBoundingBox - missing parent window" );
192 return m_aTable.GetWindowExtentsRelative( pParent );
196 tools::Rectangle AccessibleGridControl::implGetBoundingBoxOnScreen()
198 return m_aTable.GetWindowExtentsRelative( nullptr );
200 // internal helper methods ----------------------------------------------------
202 css::uno::Reference< css::accessibility::XAccessible > AccessibleGridControl::implGetTable()
204 if( !m_xTable.is() )
206 m_xTable = createAccessibleTable();
208 return m_xTable;
212 css::uno::Reference< css::accessibility::XAccessible >
213 AccessibleGridControl::implGetHeaderBar( AccessibleTableControlObjType eObjType )
215 css::uno::Reference< css::accessibility::XAccessible > xRet;
216 rtl::Reference< AccessibleGridControlHeader >* pxMember = nullptr;
218 if( eObjType == TCTYPE_ROWHEADERBAR )
219 pxMember = &m_xRowHeaderBar;
220 else if( eObjType == TCTYPE_COLUMNHEADERBAR )
221 pxMember = &m_xColumnHeaderBar;
223 if( pxMember )
225 if( !pxMember->is() )
227 *pxMember = new AccessibleGridControlHeader(
228 m_aCreator, m_aTable, eObjType );
230 xRet = pxMember->get();
232 return xRet;
235 css::uno::Reference< css::accessibility::XAccessible >
236 AccessibleGridControl::implGetFixedChild( sal_Int64 nChildIndex )
238 css::uno::Reference< css::accessibility::XAccessible > xRet;
239 switch( nChildIndex )
241 /** Child index of the column header bar (first row). */
242 case 0:
243 xRet = implGetHeaderBar( TCTYPE_COLUMNHEADERBAR );
244 break;
245 /** Child index of the row header bar ("handle column"). */
246 case 1:
247 xRet = implGetHeaderBar( TCTYPE_ROWHEADERBAR );
248 break;
249 /** Child index of the data table. */
250 case 2:
251 xRet = implGetTable();
252 break;
254 return xRet;
257 rtl::Reference<AccessibleGridControlTable> AccessibleGridControl::createAccessibleTable()
259 css::uno::Reference< css::accessibility::XAccessible > xCreator(m_aCreator);
260 OSL_ENSURE( xCreator.is(), "extended/AccessibleGridControl::createAccessibleTable: my creator died - how this?" );
261 return new AccessibleGridControlTable( xCreator, m_aTable );
264 void AccessibleGridControl::commitCellEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue)
266 sal_Int64 nChildCount = implGetAccessibleChildCount();
267 if(nChildCount != 0)
269 for(sal_Int64 i=0;i<nChildCount;i++)
271 css::uno::Reference< css::accessibility::XAccessible > xAccessible = getAccessibleChild(i);
272 if(css::uno::Reference< css::accessibility::XAccessible >(m_xTable) == xAccessible)
274 Reference<XAccessible> xCell = m_xTable->getAccessibleCellAt(
275 m_aTable.GetCurrentRow(), m_aTable.GetCurrentColumn());
276 AccessibleGridControlTableCell* pCell = static_cast<AccessibleGridControlTableCell*>(xCell.get());
277 pCell->commitEvent(_nEventId, _rNewValue, _rOldValue);
281 else
283 if ( m_xTable.is() )
284 m_xTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
288 void AccessibleGridControl::commitTableEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue)
290 if ( !m_xTable.is() )
291 return;
293 if(_nEventId == AccessibleEventId::ACTIVE_DESCENDANT_CHANGED)
295 const sal_Int32 nCurrentRow = m_aTable.GetCurrentRow();
296 const sal_Int32 nCurrentCol = m_aTable.GetCurrentColumn();
297 css::uno::Reference< css::accessibility::XAccessible > xChild;
298 if (nCurrentRow > -1 && nCurrentCol > -1)
299 xChild = m_xTable->getAccessibleCellAt(nCurrentRow, nCurrentCol);
301 m_xTable->commitEvent(_nEventId, Any(xChild),_rOldValue);
303 else
304 m_xTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
307 // = AccessibleGridControlAccess
310 AccessibleGridControlAccess::AccessibleGridControlAccess(
311 css::uno::Reference< css::accessibility::XAccessible > xParent, ::vcl::table::IAccessibleTable& rTable )
312 : m_xParent(std::move( xParent ))
313 , m_pTable( & rTable )
318 AccessibleGridControlAccess::~AccessibleGridControlAccess()
323 void AccessibleGridControlAccess::DisposeAccessImpl()
325 SolarMutexGuard g;
327 m_pTable = nullptr;
328 if (m_xContext.is())
330 m_xContext->dispose();
331 m_xContext.clear();
336 css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL AccessibleGridControlAccess::getAccessibleContext()
338 SolarMutexGuard g;
340 // if the context died meanwhile (we're no listener, so it won't tell us explicitly when this happens),
341 // then reset and re-create.
342 if ( m_xContext.is() && !m_xContext->isAlive() )
343 m_xContext = nullptr;
345 if (!m_xContext.is() && m_pTable)
346 m_xContext = new AccessibleGridControl(m_xParent, this, *m_pTable);
348 return m_xContext;
352 } // namespace accessibility
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */