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/AccessibleTableModelChange.hpp>
25 #include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp>
26 #include <vcl/accessibletable.hxx>
27 #include <comphelper/types.hxx>
29 namespace accessibility
32 using namespace ::com::sun::star::uno
;
33 using namespace ::com::sun::star
;
34 using namespace ::com::sun::star::lang
;
35 using namespace ::com::sun::star::accessibility
;
36 using namespace ::vcl
;
37 using namespace ::vcl::table
;
39 AccessibleGridControl::AccessibleGridControl(
40 const css::uno::Reference
< css::accessibility::XAccessible
>& _rxParent
, const css::uno::Reference
< css::accessibility::XAccessible
>& _rxCreator
,
41 ::vcl::table::IAccessibleTable
& _rTable
)
42 : AccessibleGridControlBase( _rxParent
, _rTable
, TCTYPE_GRIDCONTROL
),
43 m_aCreator(_rxCreator
)
48 void SAL_CALL
AccessibleGridControl::disposing()
64 if ( m_xRowHeaderBar
.is() )
66 m_xRowHeaderBar
->dispose();
67 m_xRowHeaderBar
.clear();
69 if ( m_xColumnHeaderBar
.is() )
71 m_xColumnHeaderBar
->dispose();
72 m_xColumnHeaderBar
.clear();
74 AccessibleGridControlBase::disposing();
78 // css::accessibility::XAccessibleContext ---------------------------------------------------------
80 sal_Int32 SAL_CALL
AccessibleGridControl::getAccessibleChildCount()
82 SolarMutexGuard aSolarGuard
;
84 return m_aTable
.GetAccessibleControlCount();
88 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
89 AccessibleGridControl::getAccessibleChild( sal_Int32 nChildIndex
)
91 SolarMutexGuard aSolarGuard
;
93 if (nChildIndex
<0 || nChildIndex
>=getAccessibleChildCount())
94 throw IndexOutOfBoundsException();
96 css::uno::Reference
< css::accessibility::XAccessible
> xChild
;
99 if(nChildIndex
== 0 && m_aTable
.HasColHeader())
101 if(!m_xColumnHeaderBar
.is())
103 m_xColumnHeaderBar
= new AccessibleGridControlHeader(m_aCreator
, m_aTable
, vcl::table::TCTYPE_COLUMNHEADERBAR
);
105 xChild
= m_xColumnHeaderBar
.get();
107 else if(m_aTable
.HasRowHeader() && (nChildIndex
== 1 || nChildIndex
== 0))
109 if(!m_xRowHeaderBar
.is())
111 m_xRowHeaderBar
= new AccessibleGridControlHeader(m_aCreator
, m_aTable
, vcl::table::TCTYPE_ROWHEADERBAR
);
113 xChild
= m_xRowHeaderBar
.get();
119 m_xTable
= new AccessibleGridControlTable(m_aCreator
, m_aTable
);
121 xChild
= m_xTable
.get();
128 sal_Int16 SAL_CALL
AccessibleGridControl::getAccessibleRole()
133 return AccessibleRole::PANEL
;
137 // css::accessibility::XAccessibleComponent -------------------------------------------------------
139 css::uno::Reference
< css::accessibility::XAccessible
> SAL_CALL
140 AccessibleGridControl::getAccessibleAtPoint( const awt::Point
& rPoint
)
142 SolarMutexGuard aSolarGuard
;
145 css::uno::Reference
< css::accessibility::XAccessible
> xChild
;
146 sal_Int32 nIndex
= 0;
147 if( m_aTable
.ConvertPointToControlIndex( nIndex
, VCLPoint( rPoint
) ) )
148 xChild
= m_aTable
.CreateAccessibleControl( nIndex
);
151 // try whether point is in one of the fixed children
152 // (table, header bars, corner control)
153 Point
aPoint( VCLPoint( rPoint
) );
154 for( nIndex
= 0; (nIndex
< 3) && !xChild
.is(); ++nIndex
)
156 css::uno::Reference
< css::accessibility::XAccessible
> xCurrChild( implGetFixedChild( nIndex
) );
157 css::uno::Reference
< css::accessibility::XAccessibleComponent
>
158 xCurrChildComp( xCurrChild
, uno::UNO_QUERY
);
160 if( xCurrChildComp
.is() &&
161 VCLRectangle( xCurrChildComp
->getBounds() ).IsInside( aPoint
) )
169 void SAL_CALL
AccessibleGridControl::grabFocus()
171 SolarMutexGuard aSolarGuard
;
173 m_aTable
.GrabFocus();
176 // XServiceInfo ---------------------------------------------------------------
178 OUString SAL_CALL
AccessibleGridControl::getImplementationName()
180 return OUString( "com.sun.star.accessibility.AccessibleGridControl" );
184 // internal virtual methods ---------------------------------------------------
186 tools::Rectangle
AccessibleGridControl::implGetBoundingBox()
188 vcl::Window
* pParent
= m_aTable
.GetAccessibleParentWindow();
189 OSL_ENSURE( pParent
, "implGetBoundingBox - missing parent window" );
190 return m_aTable
.GetWindowExtentsRelative( pParent
);
194 tools::Rectangle
AccessibleGridControl::implGetBoundingBoxOnScreen()
196 return m_aTable
.GetWindowExtentsRelative( nullptr );
198 // internal helper methods ----------------------------------------------------
200 css::uno::Reference
< css::accessibility::XAccessible
> AccessibleGridControl::implGetTable()
204 m_xTable
= createAccessibleTable();
206 return m_xTable
.get();
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
== TCTYPE_ROWHEADERBAR
)
217 pxMember
= &m_xRowHeaderBar
;
218 else if( eObjType
== TCTYPE_COLUMNHEADERBAR
)
219 pxMember
= &m_xColumnHeaderBar
;
223 if( !pxMember
->is() )
225 *pxMember
= new AccessibleGridControlHeader(
226 m_aCreator
, m_aTable
, eObjType
);
228 xRet
= pxMember
->get();
233 css::uno::Reference
< css::accessibility::XAccessible
>
234 AccessibleGridControl::implGetFixedChild( sal_Int32 nChildIndex
)
236 css::uno::Reference
< css::accessibility::XAccessible
> xRet
;
237 switch( nChildIndex
)
239 /** Child index of the column header bar (first row). */
241 xRet
= implGetHeaderBar( TCTYPE_COLUMNHEADERBAR
);
243 /** Child index of the row header bar ("handle column"). */
245 xRet
= implGetHeaderBar( TCTYPE_ROWHEADERBAR
);
247 /** Child index of the data table. */
249 xRet
= implGetTable();
255 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_Int32 nChildCount
= getAccessibleChildCount();
267 for(sal_Int32 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
.get()) == xAccessible
)
272 std::vector
< AccessibleGridControlTableCell
* >& rCells
=
273 m_xTable
->getCellVector();
274 size_t nIndex
= m_aTable
.GetCurrentRow() * m_aTable
.GetColumnCount()
275 + m_aTable
.GetCurrentColumn();
276 if (nIndex
< rCells
.size() && rCells
[nIndex
])
278 m_xCell
= rCells
[nIndex
];
279 m_xCell
->commitEvent( _nEventId
, _rNewValue
, _rOldValue
);
287 m_xTable
->commitEvent(_nEventId
,_rNewValue
,_rOldValue
);
291 void AccessibleGridControl::commitTableEvent(sal_Int16 _nEventId
,const Any
& _rNewValue
,const Any
& _rOldValue
)
295 if(_nEventId
== AccessibleEventId::ACTIVE_DESCENDANT_CHANGED
)
297 const sal_Int32 nCurrentRow
= m_aTable
.GetCurrentRow();
298 const sal_Int32 nCurrentCol
= m_aTable
.GetCurrentColumn();
299 css::uno::Reference
< css::accessibility::XAccessible
> xChild
;
300 if (nCurrentRow
> -1 && nCurrentCol
> -1)
302 sal_Int32 nColumnCount
= m_aTable
.GetColumnCount();
303 xChild
= m_xTable
->getAccessibleChild(nCurrentRow
* nColumnCount
+ nCurrentCol
);
305 m_xTable
->commitEvent(_nEventId
, Any(xChild
),_rOldValue
);
307 else if(_nEventId
== AccessibleEventId::TABLE_MODEL_CHANGED
)
309 AccessibleTableModelChange aChange
;
310 if(_rNewValue
>>= aChange
)
312 if(aChange
.Type
== AccessibleTableModelChangeType::DELETE
)
314 std::vector
< AccessibleGridControlTableCell
* >& rCells
=
315 m_xTable
->getCellVector();
316 std::vector
< css::uno::Reference
< css::accessibility::XAccessible
> >& rAccCells
=
317 m_xTable
->getAccessibleCellVector();
318 int nColCount
= m_aTable
.GetColumnCount();
319 // check valid index - entries are inserted lazily
320 size_t const nStart
= nColCount
* aChange
.FirstRow
;
321 size_t const nEnd
= nColCount
* aChange
.LastRow
;
322 if (nStart
< rCells
.size())
324 m_xTable
->getCellVector().erase(
325 rCells
.begin() + nStart
,
326 rCells
.begin() + std::min(rCells
.size(), nEnd
));
328 if (nStart
< rAccCells
.size())
330 m_xTable
->getAccessibleCellVector().erase(
331 rAccCells
.begin() + nStart
,
332 rAccCells
.begin() + std::min(rAccCells
.size(), nEnd
));
334 m_xTable
->commitEvent(_nEventId
,_rNewValue
,_rOldValue
);
337 m_xTable
->commitEvent(_nEventId
,_rNewValue
,_rOldValue
);
341 m_xTable
->commitEvent(_nEventId
,_rNewValue
,_rOldValue
);
345 // = AccessibleGridControlAccess
348 AccessibleGridControlAccess::AccessibleGridControlAccess(
349 const css::uno::Reference
< css::accessibility::XAccessible
>& rxParent
, ::vcl::table::IAccessibleTable
& rTable
)
350 : m_xParent( rxParent
)
351 , m_pTable( & rTable
)
356 AccessibleGridControlAccess::~AccessibleGridControlAccess()
361 void AccessibleGridControlAccess::DisposeAccessImpl()
368 m_xContext
->dispose();
374 css::uno::Reference
< css::accessibility::XAccessibleContext
> SAL_CALL
AccessibleGridControlAccess::getAccessibleContext()
378 // if the context died meanwhile (we're no listener, so it won't tell us explicitly when this happens),
379 // then reset an re-create.
380 if ( m_xContext
.is() && !m_xContext
->isAlive() )
381 m_xContext
= nullptr;
383 if (!m_xContext
.is() && m_pTable
)
384 m_xContext
= new AccessibleGridControl(m_xParent
, this, *m_pTable
);
386 return m_xContext
.get();
390 } // namespace accessibility
392 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */