1*0841af79SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*0841af79SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*0841af79SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*0841af79SAndrew Rist  * distributed with this work for additional information
6*0841af79SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*0841af79SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*0841af79SAndrew Rist  * "License"); you may not use this file except in compliance
9*0841af79SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*0841af79SAndrew Rist  *
11*0841af79SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*0841af79SAndrew Rist  *
13*0841af79SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*0841af79SAndrew Rist  * software distributed under the License is distributed on an
15*0841af79SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*0841af79SAndrew Rist  * KIND, either express or implied.  See the License for the
17*0841af79SAndrew Rist  * specific language governing permissions and limitations
18*0841af79SAndrew Rist  * under the License.
19*0841af79SAndrew Rist  *
20*0841af79SAndrew Rist  *************************************************************/
21*0841af79SAndrew Rist 
22*0841af79SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_accessibility.hxx"
26cdf0e10cSrcweir #include "accessibility/extended/AccessibleGridControl.hxx"
27cdf0e10cSrcweir #include "accessibility/extended/AccessibleGridControlTable.hxx"
28cdf0e10cSrcweir #include "accessibility/extended/AccessibleGridControlHeader.hxx"
29cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
30cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleTableModelChange.hpp>
31cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp>
32cdf0e10cSrcweir #include <svtools/accessibletable.hxx>
33cdf0e10cSrcweir #include <comphelper/types.hxx>
34cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir // ============================================================================
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace accessibility
39cdf0e10cSrcweir {
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // ============================================================================
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using ::rtl::OUString;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46cdf0e10cSrcweir using namespace ::com::sun::star;
47cdf0e10cSrcweir using namespace ::com::sun::star::lang;
48cdf0e10cSrcweir using namespace ::com::sun::star::accessibility;
49cdf0e10cSrcweir using namespace ::svt;
50cdf0e10cSrcweir using namespace ::svt::table;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir // ============================================================================
53cdf0e10cSrcweir class AccessibleGridControl_Impl
54cdf0e10cSrcweir {
55cdf0e10cSrcweir public:
56cdf0e10cSrcweir     /// the XAccessible which created the AccessibleGridControl
57cdf0e10cSrcweir     WeakReference< XAccessible >                                m_aCreator;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	/** The data table child. */
60cdf0e10cSrcweir     Reference<
61cdf0e10cSrcweir         ::com::sun::star::accessibility::XAccessible >          m_xTable;
62cdf0e10cSrcweir 	AccessibleGridControlTable*				m_pTable;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir     /** The header bar for rows. */
65cdf0e10cSrcweir     Reference<
66cdf0e10cSrcweir         ::com::sun::star::accessibility::XAccessible >	        m_xRowHeaderBar;
67cdf0e10cSrcweir 	AccessibleGridControlHeader*				m_pRowHeaderBar;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir     /** The header bar for columns (first row of the table). */
70cdf0e10cSrcweir     Reference<
71cdf0e10cSrcweir         ::com::sun::star::accessibility::XAccessible >	        m_xColumnHeaderBar;
72cdf0e10cSrcweir 	AccessibleGridControlHeader*				m_pColumnHeaderBar;
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	/** The table cell child. */
75cdf0e10cSrcweir     Reference<
76cdf0e10cSrcweir         ::com::sun::star::accessibility::XAccessible >          m_xCell;
77cdf0e10cSrcweir 	AccessibleGridControlTableCell*				m_pCell;
78cdf0e10cSrcweir };
79cdf0e10cSrcweir 
DBG_NAME(AccessibleGridControl)80cdf0e10cSrcweir DBG_NAME( AccessibleGridControl )
81cdf0e10cSrcweir 
82cdf0e10cSrcweir AccessibleGridControl::AccessibleGridControl(
83cdf0e10cSrcweir             const Reference< XAccessible >& _rxParent, const Reference< XAccessible >& _rxCreator,
84cdf0e10cSrcweir             IAccessibleTable& _rTable )
85cdf0e10cSrcweir     : AccessibleGridControlBase( _rxParent, _rTable, TCTYPE_GRIDCONTROL )
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	m_pImpl.reset( new AccessibleGridControl_Impl() );
88cdf0e10cSrcweir 	m_pImpl->m_aCreator = _rxCreator;
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir // -----------------------------------------------------------------------------
~AccessibleGridControl()92cdf0e10cSrcweir AccessibleGridControl::~AccessibleGridControl()
93cdf0e10cSrcweir {
94cdf0e10cSrcweir }
95cdf0e10cSrcweir // -----------------------------------------------------------------------------
96cdf0e10cSrcweir 
disposing()97cdf0e10cSrcweir void SAL_CALL AccessibleGridControl::disposing()
98cdf0e10cSrcweir {
99cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getOslMutex() );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	m_pImpl->m_pTable		= NULL;
102cdf0e10cSrcweir 	m_pImpl->m_pColumnHeaderBar	= NULL;
103cdf0e10cSrcweir 	m_pImpl->m_pRowHeaderBar	= NULL;
104cdf0e10cSrcweir 	m_pImpl->m_pCell			= NULL;
105cdf0e10cSrcweir 	m_pImpl->m_aCreator         = Reference< XAccessible >();
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	Reference< XAccessible >  xTable = m_pImpl->m_xTable;
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	Reference< XComponent > xComp( m_pImpl->m_xTable, UNO_QUERY );
110cdf0e10cSrcweir 	if ( xComp.is() )
111cdf0e10cSrcweir 	{
112cdf0e10cSrcweir 		xComp->dispose();
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 	Reference< XAccessible >  xCell = m_pImpl->m_xCell;
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	Reference< XComponent > xCellComp( m_pImpl->m_xCell, UNO_QUERY );
117cdf0e10cSrcweir 	if ( xCellComp.is() )
118cdf0e10cSrcweir 	{
119cdf0e10cSrcweir 		xCellComp->dispose();
120cdf0e10cSrcweir 	}
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 	::comphelper::disposeComponent(m_pImpl->m_xRowHeaderBar);
123cdf0e10cSrcweir     ::comphelper::disposeComponent(m_pImpl->m_xColumnHeaderBar);
124cdf0e10cSrcweir 	AccessibleGridControlBase::disposing();
125cdf0e10cSrcweir }
126cdf0e10cSrcweir // -----------------------------------------------------------------------------
127cdf0e10cSrcweir 
128cdf0e10cSrcweir // XAccessibleContext ---------------------------------------------------------
129cdf0e10cSrcweir 
getAccessibleChildCount()130cdf0e10cSrcweir sal_Int32 SAL_CALL AccessibleGridControl::getAccessibleChildCount()
131cdf0e10cSrcweir     throw ( uno::RuntimeException )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	TCSolarGuard aSolarGuard;
134cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getOslMutex() );
135cdf0e10cSrcweir 	ensureIsAlive();
136cdf0e10cSrcweir 	return m_aTable.GetAccessibleControlCount();
137cdf0e10cSrcweir }
138cdf0e10cSrcweir // -----------------------------------------------------------------------------
139cdf0e10cSrcweir 
140cdf0e10cSrcweir Reference< XAccessible > SAL_CALL
getAccessibleChild(sal_Int32 nChildIndex)141cdf0e10cSrcweir AccessibleGridControl::getAccessibleChild( sal_Int32 nChildIndex )
142cdf0e10cSrcweir     throw ( lang::IndexOutOfBoundsException, uno::RuntimeException )
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	TCSolarGuard aSolarGuard;
145cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getOslMutex() );
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 	if (nChildIndex<0 || nChildIndex>=getAccessibleChildCount())
148cdf0e10cSrcweir 		throw IndexOutOfBoundsException();
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 	Reference< XAccessible > xChild;
151cdf0e10cSrcweir 	if (isAlive())
152cdf0e10cSrcweir 	{
153cdf0e10cSrcweir 		if(nChildIndex == 0 && m_aTable.HasColHeader())
154cdf0e10cSrcweir 		{
155cdf0e10cSrcweir 			if(!m_pImpl->m_xColumnHeaderBar.is())
156cdf0e10cSrcweir 			{
157cdf0e10cSrcweir 				AccessibleGridControlHeader* pColHeaderBar = new AccessibleGridControlHeader(m_pImpl->m_aCreator, m_aTable, svt::table::TCTYPE_COLUMNHEADERBAR);
158cdf0e10cSrcweir 				m_pImpl->m_xColumnHeaderBar = pColHeaderBar;
159cdf0e10cSrcweir 			}
160cdf0e10cSrcweir 			xChild = m_pImpl->m_xColumnHeaderBar;
161cdf0e10cSrcweir 		}
162cdf0e10cSrcweir 		else if(m_aTable.HasRowHeader() && (nChildIndex == 1 || nChildIndex == 0))
163cdf0e10cSrcweir 		{
164cdf0e10cSrcweir 			if(!m_pImpl->m_xRowHeaderBar.is())
165cdf0e10cSrcweir 			{
166cdf0e10cSrcweir 				AccessibleGridControlHeader* pRowHeaderBar = new AccessibleGridControlHeader(m_pImpl->m_aCreator, m_aTable, svt::table::TCTYPE_ROWHEADERBAR);
167cdf0e10cSrcweir 				m_pImpl->m_xRowHeaderBar = pRowHeaderBar;
168cdf0e10cSrcweir 			}
169cdf0e10cSrcweir 			xChild = m_pImpl->m_xRowHeaderBar;
170cdf0e10cSrcweir 		}
171cdf0e10cSrcweir 		else
172cdf0e10cSrcweir 		{
173cdf0e10cSrcweir 			if(!m_pImpl->m_xTable.is())
174cdf0e10cSrcweir 			{
175cdf0e10cSrcweir 			AccessibleGridControlTable* pTable = new AccessibleGridControlTable(m_pImpl->m_aCreator, m_aTable, svt::table::TCTYPE_TABLE);
176cdf0e10cSrcweir 			m_pImpl->m_xTable = pTable;
177cdf0e10cSrcweir 				m_pImpl->m_pTable = pTable;
178cdf0e10cSrcweir 			}
179cdf0e10cSrcweir 			xChild = m_pImpl->m_xTable;
180cdf0e10cSrcweir 		}
181cdf0e10cSrcweir 	}
182cdf0e10cSrcweir 	return xChild;
183cdf0e10cSrcweir }
184cdf0e10cSrcweir // -----------------------------------------------------------------------------
185cdf0e10cSrcweir 
getAccessibleRole()186cdf0e10cSrcweir sal_Int16 SAL_CALL AccessibleGridControl::getAccessibleRole()
187cdf0e10cSrcweir     throw ( uno::RuntimeException )
188cdf0e10cSrcweir {
189cdf0e10cSrcweir 	ensureIsAlive();
190cdf0e10cSrcweir 	return AccessibleRole::PANEL;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir // -----------------------------------------------------------------------------
193cdf0e10cSrcweir 
194cdf0e10cSrcweir // XAccessibleComponent -------------------------------------------------------
195cdf0e10cSrcweir 
196cdf0e10cSrcweir Reference< XAccessible > SAL_CALL
getAccessibleAtPoint(const awt::Point & rPoint)197cdf0e10cSrcweir AccessibleGridControl::getAccessibleAtPoint( const awt::Point& rPoint )
198cdf0e10cSrcweir     throw ( uno::RuntimeException )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	TCSolarGuard aSolarGuard;
201cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getOslMutex() );
202cdf0e10cSrcweir 	ensureIsAlive();
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 	Reference< XAccessible > xChild;
205cdf0e10cSrcweir 	sal_Int32 nIndex = 0;
206cdf0e10cSrcweir 	if( m_aTable.ConvertPointToControlIndex( nIndex, VCLPoint( rPoint ) ) )
207cdf0e10cSrcweir 		xChild = m_aTable.CreateAccessibleControl( nIndex );
208cdf0e10cSrcweir 	else
209cdf0e10cSrcweir 	{
210cdf0e10cSrcweir 		// try whether point is in one of the fixed children
211cdf0e10cSrcweir 		// (table, header bars, corner control)
212cdf0e10cSrcweir 		Point aPoint( VCLPoint( rPoint ) );
213cdf0e10cSrcweir 		for( nIndex = 0; (nIndex < 3) && !xChild.is(); ++nIndex )
214cdf0e10cSrcweir 		{
215cdf0e10cSrcweir 			Reference< XAccessible > xCurrChild( implGetFixedChild( nIndex ) );
216cdf0e10cSrcweir 			Reference< XAccessibleComponent >
217cdf0e10cSrcweir 			xCurrChildComp( xCurrChild, uno::UNO_QUERY );
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 			if( xCurrChildComp.is() &&
220cdf0e10cSrcweir 				VCLRectangle( xCurrChildComp->getBounds() ).IsInside( aPoint ) )
221cdf0e10cSrcweir 			xChild = xCurrChild;
222cdf0e10cSrcweir 		}
223cdf0e10cSrcweir 	}
224cdf0e10cSrcweir 	return xChild;
225cdf0e10cSrcweir }
226cdf0e10cSrcweir // -----------------------------------------------------------------------------
227cdf0e10cSrcweir 
grabFocus()228cdf0e10cSrcweir void SAL_CALL AccessibleGridControl::grabFocus()
229cdf0e10cSrcweir     throw ( uno::RuntimeException )
230cdf0e10cSrcweir {
231cdf0e10cSrcweir 	TCSolarGuard aSolarGuard;
232cdf0e10cSrcweir 	::osl::MutexGuard aGuard( getOslMutex() );
233cdf0e10cSrcweir 	ensureIsAlive();
234cdf0e10cSrcweir     	m_aTable.GrabFocus();
235cdf0e10cSrcweir }
236cdf0e10cSrcweir // -----------------------------------------------------------------------------
237cdf0e10cSrcweir 
getAccessibleKeyBinding()238cdf0e10cSrcweir Any SAL_CALL AccessibleGridControl::getAccessibleKeyBinding()
239cdf0e10cSrcweir     throw ( uno::RuntimeException )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir 	ensureIsAlive();
242cdf0e10cSrcweir 	return Any();
243cdf0e10cSrcweir }
244cdf0e10cSrcweir // -----------------------------------------------------------------------------
245cdf0e10cSrcweir 
246cdf0e10cSrcweir // XServiceInfo ---------------------------------------------------------------
247cdf0e10cSrcweir 
getImplementationName()248cdf0e10cSrcweir OUString SAL_CALL AccessibleGridControl::getImplementationName()
249cdf0e10cSrcweir     throw ( uno::RuntimeException )
250cdf0e10cSrcweir {
251cdf0e10cSrcweir 	return OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.accessibility.AccessibleGridControl" ) );
252cdf0e10cSrcweir }
253cdf0e10cSrcweir // -----------------------------------------------------------------------------
254cdf0e10cSrcweir 
255cdf0e10cSrcweir // internal virtual methods ---------------------------------------------------
256cdf0e10cSrcweir 
implGetBoundingBox()257cdf0e10cSrcweir Rectangle AccessibleGridControl::implGetBoundingBox()
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	Window* pParent = m_aTable.GetAccessibleParentWindow();
260cdf0e10cSrcweir 	DBG_ASSERT( pParent, "implGetBoundingBox - missing parent window" );
261cdf0e10cSrcweir 	return m_aTable.GetWindowExtentsRelative( pParent );
262cdf0e10cSrcweir }
263cdf0e10cSrcweir // -----------------------------------------------------------------------------
264cdf0e10cSrcweir 
implGetBoundingBoxOnScreen()265cdf0e10cSrcweir Rectangle AccessibleGridControl::implGetBoundingBoxOnScreen()
266cdf0e10cSrcweir {
267cdf0e10cSrcweir 	return m_aTable.GetWindowExtentsRelative( NULL );
268cdf0e10cSrcweir }
269cdf0e10cSrcweir // internal helper methods ----------------------------------------------------
270cdf0e10cSrcweir 
implGetTable()271cdf0e10cSrcweir Reference< XAccessible > AccessibleGridControl::implGetTable()
272cdf0e10cSrcweir {
273cdf0e10cSrcweir 	if( !m_pImpl->m_xTable.is() )
274cdf0e10cSrcweir 	{
275cdf0e10cSrcweir 		m_pImpl->m_pTable = createAccessibleTable();
276cdf0e10cSrcweir 		m_pImpl->m_xTable  = m_pImpl->m_pTable;
277cdf0e10cSrcweir 	}
278cdf0e10cSrcweir 	return m_pImpl->m_xTable;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir // -----------------------------------------------------------------------------
281cdf0e10cSrcweir 
282cdf0e10cSrcweir Reference< XAccessible >
implGetHeaderBar(AccessibleTableControlObjType eObjType)283cdf0e10cSrcweir AccessibleGridControl::implGetHeaderBar( AccessibleTableControlObjType eObjType )
284cdf0e10cSrcweir {
285cdf0e10cSrcweir 	Reference< XAccessible > xRet;
286cdf0e10cSrcweir 	Reference< XAccessible >* pxMember = NULL;
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 	if( eObjType == TCTYPE_ROWHEADERBAR )
289cdf0e10cSrcweir 		pxMember = &m_pImpl->m_xRowHeaderBar;
290cdf0e10cSrcweir 	else if( eObjType ==  TCTYPE_COLUMNHEADERBAR )
291cdf0e10cSrcweir 		pxMember = &m_pImpl->m_xColumnHeaderBar;
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 	if( pxMember )
294cdf0e10cSrcweir 	{
295cdf0e10cSrcweir 		if( !pxMember->is() )
296cdf0e10cSrcweir 		{
297cdf0e10cSrcweir 			AccessibleGridControlHeader* pHeaderBar = new AccessibleGridControlHeader(
298cdf0e10cSrcweir 				(Reference< XAccessible >)m_pImpl->m_aCreator, m_aTable, eObjType );
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 			if ( TCTYPE_COLUMNHEADERBAR == eObjType)
301cdf0e10cSrcweir 				m_pImpl->m_pColumnHeaderBar = pHeaderBar;
302cdf0e10cSrcweir 			else
303cdf0e10cSrcweir 				m_pImpl->m_pRowHeaderBar	= pHeaderBar;
304cdf0e10cSrcweir 
305cdf0e10cSrcweir 			*pxMember = pHeaderBar;
306cdf0e10cSrcweir 		}
307cdf0e10cSrcweir 		xRet = *pxMember;
308cdf0e10cSrcweir 	}
309cdf0e10cSrcweir 	return xRet;
310cdf0e10cSrcweir }
311cdf0e10cSrcweir // -----------------------------------------------------------------------------
312cdf0e10cSrcweir Reference< XAccessible >
implGetFixedChild(sal_Int32 nChildIndex)313cdf0e10cSrcweir AccessibleGridControl::implGetFixedChild( sal_Int32 nChildIndex )
314cdf0e10cSrcweir {
315cdf0e10cSrcweir 	Reference< XAccessible > xRet;
316cdf0e10cSrcweir 	switch( nChildIndex )
317cdf0e10cSrcweir 	{
318cdf0e10cSrcweir       	case TCINDEX_COLUMNHEADERBAR:
319cdf0e10cSrcweir             xRet = implGetHeaderBar( TCTYPE_COLUMNHEADERBAR );
320cdf0e10cSrcweir 	    break;
321cdf0e10cSrcweir         case TCINDEX_ROWHEADERBAR:
322cdf0e10cSrcweir             xRet = implGetHeaderBar( TCTYPE_ROWHEADERBAR );
323cdf0e10cSrcweir 	    break;
324cdf0e10cSrcweir         case TCINDEX_TABLE:
325cdf0e10cSrcweir             xRet = implGetTable();
326cdf0e10cSrcweir 	    break;
327cdf0e10cSrcweir 	}
328cdf0e10cSrcweir 	return xRet;
329cdf0e10cSrcweir }
330cdf0e10cSrcweir // -----------------------------------------------------------------------------
createAccessibleTable()331cdf0e10cSrcweir AccessibleGridControlTable* AccessibleGridControl::createAccessibleTable()
332cdf0e10cSrcweir {
333cdf0e10cSrcweir 	Reference< XAccessible > xCreator = (Reference< XAccessible >)m_pImpl->m_aCreator;
334cdf0e10cSrcweir     	DBG_ASSERT( xCreator.is(), "accessibility/extended/AccessibleGirdControl::createAccessibleTable: my creator died - how this?" );
335cdf0e10cSrcweir 	return new AccessibleGridControlTable( xCreator, m_aTable, TCTYPE_TABLE );
336cdf0e10cSrcweir }
337cdf0e10cSrcweir // -----------------------------------------------------------------------------
commitCellEvent(sal_Int16 _nEventId,const Any & _rNewValue,const Any & _rOldValue)338cdf0e10cSrcweir void AccessibleGridControl::commitCellEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue)
339cdf0e10cSrcweir {
340cdf0e10cSrcweir 	sal_Int32 nChildCount = getAccessibleChildCount();
341cdf0e10cSrcweir     if(nChildCount != 0)
342cdf0e10cSrcweir 	{
343cdf0e10cSrcweir 		for(sal_Int32 i=0;i<nChildCount;i++)
344cdf0e10cSrcweir 		{
345cdf0e10cSrcweir 			Reference< XAccessible > xAccessible = getAccessibleChild(i);
346cdf0e10cSrcweir 			com::sun::star::uno::Reference< com::sun::star::accessibility::XAccessibleContext > xAccessibleChild = xAccessible->getAccessibleContext();
347cdf0e10cSrcweir 			if(m_pImpl->m_xTable == xAccessible)
348cdf0e10cSrcweir 			{
349cdf0e10cSrcweir 				std::vector< AccessibleGridControlTableCell* > xCellCont = m_pImpl->m_pTable->getCellVector();
350cdf0e10cSrcweir 				int nIndex = m_aTable.GetCurrentRow()*m_aTable.GetColumnCount()+m_aTable.GetCurrentColumn();
351cdf0e10cSrcweir 				if(!xCellCont.empty() && xCellCont[nIndex])
352cdf0e10cSrcweir 				{
353cdf0e10cSrcweir 					m_pImpl->m_pCell = xCellCont[nIndex];
354cdf0e10cSrcweir 					m_pImpl->m_pCell->commitEvent( _nEventId, _rNewValue, _rOldValue );
355cdf0e10cSrcweir 				}
356cdf0e10cSrcweir 			}
357cdf0e10cSrcweir 		}
358cdf0e10cSrcweir 	}
359cdf0e10cSrcweir 	else
360cdf0e10cSrcweir 	{
361cdf0e10cSrcweir 		if ( m_pImpl->m_xTable.is() )
362cdf0e10cSrcweir 			m_pImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
363cdf0e10cSrcweir 	}
364cdf0e10cSrcweir }
commitTableEvent(sal_Int16 _nEventId,const Any & _rNewValue,const Any & _rOldValue)365cdf0e10cSrcweir void AccessibleGridControl::commitTableEvent(sal_Int16 _nEventId,const Any& _rNewValue,const Any& _rOldValue)
366cdf0e10cSrcweir {
367cdf0e10cSrcweir 	if ( m_pImpl->m_xTable.is() )
368cdf0e10cSrcweir 	{
369cdf0e10cSrcweir 		if(_nEventId == AccessibleEventId::ACTIVE_DESCENDANT_CHANGED)
370cdf0e10cSrcweir 		{
371cdf0e10cSrcweir 			Reference< XAccessible > xChild = m_pImpl->m_pTable->getAccessibleChild(m_aTable.GetCurrentRow()*m_aTable.GetColumnCount()+m_aTable.GetCurrentColumn());
372cdf0e10cSrcweir 			m_pImpl->m_pTable->commitEvent(_nEventId, makeAny(xChild),_rOldValue);
373cdf0e10cSrcweir 		}
374cdf0e10cSrcweir 		else if(_nEventId == AccessibleEventId::TABLE_MODEL_CHANGED)
375cdf0e10cSrcweir 		{
376cdf0e10cSrcweir 			AccessibleTableModelChange aChange;
377cdf0e10cSrcweir 			if(_rNewValue >>= aChange)
378cdf0e10cSrcweir 			{
379cdf0e10cSrcweir 				if(aChange.Type == AccessibleTableModelChangeType::DELETE)
380cdf0e10cSrcweir 				{
381cdf0e10cSrcweir 					std::vector< AccessibleGridControlTableCell* >::iterator m_pCell = m_pImpl->m_pTable->getCellVector().begin();
382cdf0e10cSrcweir 					std::vector< Reference< XAccessible > >::iterator m_xAccessibleVector = m_pImpl->m_pTable->getAccessibleCellVector().begin();
383cdf0e10cSrcweir 					int nColCount = m_aTable.GetColumnCount();
384cdf0e10cSrcweir 					m_pImpl->m_pTable->getCellVector().erase(m_pCell+nColCount*aChange.FirstRow, m_pCell+nColCount*aChange.LastRow );
385cdf0e10cSrcweir 					m_pImpl->m_pTable->getAccessibleCellVector().erase(m_xAccessibleVector+nColCount*aChange.FirstRow, m_xAccessibleVector+nColCount*aChange.LastRow);
386cdf0e10cSrcweir 					m_pImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
387cdf0e10cSrcweir 				}
388cdf0e10cSrcweir 				else
389cdf0e10cSrcweir 					m_pImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
390cdf0e10cSrcweir 			}
391cdf0e10cSrcweir 		}
392cdf0e10cSrcweir 		else
393cdf0e10cSrcweir 			m_pImpl->m_pTable->commitEvent(_nEventId,_rNewValue,_rOldValue);
394cdf0e10cSrcweir 	}
395cdf0e10cSrcweir }
396cdf0e10cSrcweir // ============================================================================
397cdf0e10cSrcweir // = AccessibleGridControlAccess
398cdf0e10cSrcweir // ============================================================================
DBG_NAME(AccessibleGridControlAccess)399cdf0e10cSrcweir DBG_NAME( AccessibleGridControlAccess )
400cdf0e10cSrcweir // -----------------------------------------------------------------------------
401cdf0e10cSrcweir AccessibleGridControlAccess::AccessibleGridControlAccess( const Reference< XAccessible >& _rxParent, IAccessibleTable& _rTable )
402cdf0e10cSrcweir         :m_xParent( _rxParent )
403cdf0e10cSrcweir         ,m_rTable( _rTable )
404cdf0e10cSrcweir         ,m_pContext( NULL )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir }
407cdf0e10cSrcweir 
408cdf0e10cSrcweir // -----------------------------------------------------------------------------
~AccessibleGridControlAccess()409cdf0e10cSrcweir AccessibleGridControlAccess::~AccessibleGridControlAccess()
410cdf0e10cSrcweir {
411cdf0e10cSrcweir }
412cdf0e10cSrcweir 
413cdf0e10cSrcweir // -----------------------------------------------------------------------------
dispose()414cdf0e10cSrcweir void AccessibleGridControlAccess::dispose()
415cdf0e10cSrcweir {
416cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
417cdf0e10cSrcweir 
418cdf0e10cSrcweir 	m_pContext = NULL;
419cdf0e10cSrcweir 	::comphelper::disposeComponent( m_xContext );
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
422cdf0e10cSrcweir // -----------------------------------------------------------------------------
getAccessibleContext()423cdf0e10cSrcweir Reference< XAccessibleContext > SAL_CALL AccessibleGridControlAccess::getAccessibleContext() throw ( RuntimeException )
424cdf0e10cSrcweir {
425cdf0e10cSrcweir 	::osl::MutexGuard aGuard( m_aMutex );
426cdf0e10cSrcweir 
427cdf0e10cSrcweir 	DBG_ASSERT( ( m_pContext && m_xContext.is() ) || ( !m_pContext && !m_xContext.is() ),
428cdf0e10cSrcweir         "accessibility/extended/AccessibleGridControlAccess::getAccessibleContext: inconsistency!" );
429cdf0e10cSrcweir 
430cdf0e10cSrcweir 	// if the context died meanwhile (we're no listener, so it won't tell us explicitily when this happens),
431cdf0e10cSrcweir 	// then reset an re-create.
432cdf0e10cSrcweir 	if ( m_pContext && !m_pContext->isAlive() )
433cdf0e10cSrcweir 		m_xContext = m_pContext = NULL;
434cdf0e10cSrcweir 
435cdf0e10cSrcweir 	if ( !m_xContext.is() )
436cdf0e10cSrcweir 		m_xContext = m_pContext = new AccessibleGridControl( m_xParent, this, m_rTable );
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 	return m_xContext;
439cdf0e10cSrcweir }
440cdf0e10cSrcweir 
441cdf0e10cSrcweir // -----------------------------------------------------------------------------
isContextAlive() const442cdf0e10cSrcweir bool AccessibleGridControlAccess::isContextAlive() const
443cdf0e10cSrcweir {
444cdf0e10cSrcweir 	return  ( NULL != m_pContext ) && m_pContext->isAlive();
445cdf0e10cSrcweir }
446cdf0e10cSrcweir 
447cdf0e10cSrcweir // ============================================================================
448cdf0e10cSrcweir 
449cdf0e10cSrcweir }   // namespace accessibility
450