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 <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>
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()
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
;
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
;
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();
121 m_xTable
= new AccessibleGridControlTable(m_aCreator
, m_aTable
);
123 xChild
= m_xTable
.get();
130 sal_Int16 SAL_CALL
AccessibleGridControl::getAccessibleRole()
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
;
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
);
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
) )
171 void SAL_CALL
AccessibleGridControl::grabFocus()
173 SolarMutexGuard aSolarGuard
;
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()
206 m_xTable
= createAccessibleTable();
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
;
225 if( !pxMember
->is() )
227 *pxMember
= new AccessibleGridControlHeader(
228 m_aCreator
, m_aTable
, eObjType
);
230 xRet
= pxMember
->get();
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). */
243 xRet
= implGetHeaderBar( TCTYPE_COLUMNHEADERBAR
);
245 /** Child index of the row header bar ("handle column"). */
247 xRet
= implGetHeaderBar( TCTYPE_ROWHEADERBAR
);
249 /** Child index of the data table. */
251 xRet
= implGetTable();
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();
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
);
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() )
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
);
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()
330 m_xContext
->dispose();
336 css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
AccessibleGridControlAccess::getAccessibleContext()
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
);
352 } // namespace accessibility
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */