tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / accessibility / source / extended / AccessibleGridControl.cxx
blob0f9e352e7c461d2ef0171a112c36aa2bc842a586
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 <utility>
27 #include <vcl/accessibletable.hxx>
28 #include <vcl/svapp.hxx>
29 #include <vcl/unohelp.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, AccessibleTableControlObjType::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,
106 vcl::table::AccessibleTableControlObjType::COLUMNHEADERBAR);
108 xChild = m_xColumnHeaderBar.get();
110 else if(m_aTable.HasRowHeader() && (nChildIndex == 1 || nChildIndex == 0))
112 if(!m_xRowHeaderBar.is())
114 m_xRowHeaderBar = new AccessibleGridControlHeader(m_aCreator, m_aTable,
115 vcl::table::AccessibleTableControlObjType::ROWHEADERBAR);
117 xChild = m_xRowHeaderBar.get();
119 else
121 if(!m_xTable.is())
123 m_xTable = new AccessibleGridControlTable(m_aCreator, m_aTable);
125 xChild = m_xTable.get();
128 return xChild;
132 sal_Int16 SAL_CALL AccessibleGridControl::getAccessibleRole()
134 SolarMutexGuard g;
136 ensureIsAlive();
137 return AccessibleRole::PANEL;
141 // css::accessibility::XAccessibleComponent -------------------------------------------------------
143 css::uno::Reference< css::accessibility::XAccessible > SAL_CALL
144 AccessibleGridControl::getAccessibleAtPoint( const awt::Point& rPoint )
146 SolarMutexGuard aSolarGuard;
147 ensureIsAlive();
149 sal_Int32 nIndex = 0;
150 if (m_aTable.ConvertPointToControlIndex(nIndex, vcl::unohelper::ConvertToVCLPoint(rPoint)))
151 return m_aTable.CreateAccessibleControl(nIndex);
152 else
154 // try whether point is in one of the fixed children
155 // (table, header bars, corner control)
156 Point aPoint(vcl::unohelper::ConvertToVCLPoint(rPoint));
157 for (nIndex = 0; nIndex < 3; ++nIndex)
159 css::uno::Reference< css::accessibility::XAccessible > xCurrChild( implGetFixedChild( nIndex ) );
160 css::uno::Reference< css::accessibility::XAccessibleComponent >
161 xCurrChildComp( xCurrChild, uno::UNO_QUERY );
163 if (xCurrChildComp.is()
164 && vcl::unohelper::ConvertToVCLRect(xCurrChildComp->getBounds()).Contains(aPoint))
165 return xCurrChild;
168 return nullptr;
172 void SAL_CALL AccessibleGridControl::grabFocus()
174 SolarMutexGuard aSolarGuard;
175 ensureIsAlive();
176 m_aTable.GrabFocus();
179 // XServiceInfo ---------------------------------------------------------------
180 OUString SAL_CALL AccessibleGridControl::getImplementationName()
182 return u"com.sun.star.accessibility.AccessibleGridControl"_ustr;
185 // internal virtual methods ---------------------------------------------------
187 tools::Rectangle AccessibleGridControl::implGetBoundingBox()
189 vcl::Window* pParent = m_aTable.GetAccessibleParentWindow();
190 assert(pParent && "implGetBoundingBox - missing parent window");
191 return m_aTable.GetWindowExtentsRelative( *pParent );
194 AbsoluteScreenPixelRectangle AccessibleGridControl::implGetBoundingBoxOnScreen()
196 return m_aTable.GetWindowExtentsAbsolute();
199 // internal helper methods ----------------------------------------------------
201 css::uno::Reference< css::accessibility::XAccessible > AccessibleGridControl::implGetTable()
203 if( !m_xTable.is() )
205 m_xTable = createAccessibleTable();
207 return m_xTable;
210 css::uno::Reference< css::accessibility::XAccessible >
211 AccessibleGridControl::implGetHeaderBar( AccessibleTableControlObjType eObjType )
213 css::uno::Reference< css::accessibility::XAccessible > xRet;
214 rtl::Reference< AccessibleGridControlHeader >* pxMember = nullptr;
216 if (eObjType == AccessibleTableControlObjType::ROWHEADERBAR)
217 pxMember = &m_xRowHeaderBar;
218 else if (eObjType == AccessibleTableControlObjType::COLUMNHEADERBAR)
219 pxMember = &m_xColumnHeaderBar;
221 if( pxMember )
223 if( !pxMember->is() )
225 *pxMember = new AccessibleGridControlHeader(
226 m_aCreator, m_aTable, eObjType );
228 xRet = pxMember->get();
230 return xRet;
233 css::uno::Reference< css::accessibility::XAccessible >
234 AccessibleGridControl::implGetFixedChild( sal_Int64 nChildIndex )
236 css::uno::Reference< css::accessibility::XAccessible > xRet;
237 switch( nChildIndex )
239 /** Child index of the column header bar (first row). */
240 case 0:
241 xRet = implGetHeaderBar(AccessibleTableControlObjType::COLUMNHEADERBAR);
242 break;
243 /** Child index of the row header bar ("handle column"). */
244 case 1:
245 xRet = implGetHeaderBar(AccessibleTableControlObjType::ROWHEADERBAR);
246 break;
247 /** Child index of the data table. */
248 case 2:
249 xRet = implGetTable();
250 break;
252 return xRet;
255 rtl::Reference<AccessibleGridControlTable> AccessibleGridControl::createAccessibleTable()
257 css::uno::Reference< css::accessibility::XAccessible > xCreator(m_aCreator);
258 OSL_ENSURE( xCreator.is(), "extended/AccessibleGridControl::createAccessibleTable: my creator died - how this?" );
259 return new AccessibleGridControlTable( xCreator, m_aTable );
262 void AccessibleGridControl::commitCellEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue)
264 sal_Int64 nChildCount = implGetAccessibleChildCount();
265 if(nChildCount != 0)
267 for(sal_Int64 i=0;i<nChildCount;i++)
269 css::uno::Reference< css::accessibility::XAccessible > xAccessible = getAccessibleChild(i);
270 if(css::uno::Reference< css::accessibility::XAccessible >(m_xTable) == xAccessible)
272 Reference<XAccessible> xCell = m_xTable->getAccessibleCellAt(
273 m_aTable.GetCurrentRow(), m_aTable.GetCurrentColumn());
274 AccessibleGridControlTableCell* pCell = static_cast<AccessibleGridControlTableCell*>(xCell.get());
275 pCell->commitEvent(_nEventId, _rNewValue, _rOldValue);
279 else
281 if ( m_xTable.is() )
282 m_xTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
286 void AccessibleGridControl::commitTableEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue)
288 if ( !m_xTable.is() )
289 return;
291 if(_nEventId == AccessibleEventId::ACTIVE_DESCENDANT_CHANGED)
293 const sal_Int32 nCurrentRow = m_aTable.GetCurrentRow();
294 const sal_Int32 nCurrentCol = m_aTable.GetCurrentColumn();
295 css::uno::Reference< css::accessibility::XAccessible > xChild;
296 if (nCurrentRow > -1 && nCurrentCol > -1)
297 xChild = m_xTable->getAccessibleCellAt(nCurrentRow, nCurrentCol);
299 m_xTable->commitEvent(_nEventId, Any(xChild),_rOldValue);
301 else
302 m_xTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
305 // = AccessibleGridControlAccess
308 AccessibleGridControlAccess::AccessibleGridControlAccess(
309 css::uno::Reference< css::accessibility::XAccessible > xParent, ::vcl::table::IAccessibleTable& rTable )
310 : m_xParent(std::move( xParent ))
311 , m_pTable( & rTable )
316 AccessibleGridControlAccess::~AccessibleGridControlAccess()
321 void AccessibleGridControlAccess::DisposeAccessImpl()
323 SolarMutexGuard g;
325 m_pTable = nullptr;
326 if (m_xContext.is())
328 m_xContext->dispose();
329 m_xContext.clear();
334 css::uno::Reference< css::accessibility::XAccessibleContext > SAL_CALL AccessibleGridControlAccess::getAccessibleContext()
336 SolarMutexGuard g;
338 // if the context died meanwhile (we're no listener, so it won't tell us explicitly when this happens),
339 // then reset and re-create.
340 if ( m_xContext.is() && !m_xContext->isAlive() )
341 m_xContext = nullptr;
343 if (!m_xContext.is() && m_pTable)
344 m_xContext = new AccessibleGridControl(m_xParent, this, *m_pTable);
346 return m_xContext;
350 } // namespace accessibility
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */