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/accessibleeditbrowseboxcell.hxx>
27cdf0e10cSrcweir #include <svtools/editbrowsebox.hxx>
28cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
29cdf0e10cSrcweir #include <com/sun/star/accessibility/XAccessibleText.hpp>
30cdf0e10cSrcweir #include <com/sun/star/accessibility/AccessibleEventId.hpp>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir 
33cdf0e10cSrcweir // .................................................................................
34cdf0e10cSrcweir namespace accessibility
35cdf0e10cSrcweir {
36cdf0e10cSrcweir // .................................................................................
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 	using namespace com::sun::star::accessibility;
39cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
41cdf0e10cSrcweir 	using namespace ::com::sun::star::awt;
42cdf0e10cSrcweir 	using namespace ::comphelper;
43cdf0e10cSrcweir 	using namespace ::svt;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 	DBG_NAME( acc_EditBrowseBoxTableCell )
46cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
47cdf0e10cSrcweir 	EditBrowseBoxTableCell::EditBrowseBoxTableCell(
48cdf0e10cSrcweir 				const com::sun::star::uno::Reference< XAccessible >& _rxParent,
49cdf0e10cSrcweir 				const com::sun::star::uno::Reference< XAccessible >& _rxOwningAccessible,
50cdf0e10cSrcweir 				const com::sun::star::uno::Reference< XAccessibleContext >& _xControlChild,
51cdf0e10cSrcweir 				IAccessibleTableProvider& _rBrowseBox,
52cdf0e10cSrcweir 				const Reference< XWindow >& _xFocusWindow,
53cdf0e10cSrcweir 				sal_Int32 _nRowPos,
54cdf0e10cSrcweir 				sal_uInt16 _nColPos)
55cdf0e10cSrcweir 		:AccessibleBrowseBoxCell( _rxParent, _rBrowseBox, _xFocusWindow, _nRowPos, _nColPos )
56cdf0e10cSrcweir 		,OAccessibleContextWrapperHelper( ::comphelper::getProcessServiceFactory(), rBHelper, _xControlChild, _rxOwningAccessible, _rxParent )
57cdf0e10cSrcweir 	{
58cdf0e10cSrcweir 		DBG_CTOR( acc_EditBrowseBoxTableCell, NULL );
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 		aggregateProxy( m_refCount, *this );
61cdf0e10cSrcweir 	}
62cdf0e10cSrcweir 
63cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
64cdf0e10cSrcweir 	EditBrowseBoxTableCell::~EditBrowseBoxTableCell()
65cdf0e10cSrcweir 	{
66cdf0e10cSrcweir 		if ( !rBHelper.bDisposed )
67cdf0e10cSrcweir 		{
68cdf0e10cSrcweir 			acquire();	// to prevent duplicate dtor calls
69cdf0e10cSrcweir 			dispose();
70cdf0e10cSrcweir 		}
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 		DBG_DTOR( acc_EditBrowseBoxTableCell, NULL );
73cdf0e10cSrcweir 	}
74cdf0e10cSrcweir 
75cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
76cdf0e10cSrcweir 	::rtl::OUString SAL_CALL EditBrowseBoxTableCell::getImplementationName() throw ( ::com::sun::star::uno::RuntimeException )
77cdf0e10cSrcweir 	{
78cdf0e10cSrcweir 		return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.svtools.TableCellProxy" ) );
79cdf0e10cSrcweir 	}
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
82cdf0e10cSrcweir 	IMPLEMENT_FORWARD_XINTERFACE2( EditBrowseBoxTableCell, AccessibleBrowseBoxCell, OAccessibleContextWrapperHelper )
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
85cdf0e10cSrcweir 	IMPLEMENT_FORWARD_XTYPEPROVIDER2( EditBrowseBoxTableCell, AccessibleBrowseBoxCell, OAccessibleContextWrapperHelper )
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
88cdf0e10cSrcweir 	void EditBrowseBoxTableCell::notifyTranslatedEvent( const AccessibleEventObject& _rEvent ) throw (RuntimeException)
89cdf0e10cSrcweir 	{
90cdf0e10cSrcweir 		commitEvent( _rEvent.EventId, _rEvent.NewValue, _rEvent.OldValue );
91cdf0e10cSrcweir 	}
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	// XAccessibleComponent
94cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
95cdf0e10cSrcweir 	sal_Int32 SAL_CALL EditBrowseBoxTableCell::getForeground(  ) throw (RuntimeException)
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		SolarMethodGuard aGuard( *this );
98cdf0e10cSrcweir 		Reference< XAccessibleComponent > xAccComp( m_xInnerContext, UNO_QUERY );
99cdf0e10cSrcweir 		if ( xAccComp.is() )
100cdf0e10cSrcweir 			return xAccComp->getForeground();
101cdf0e10cSrcweir 		return 0;
102cdf0e10cSrcweir 	}
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
105cdf0e10cSrcweir 	sal_Int32 SAL_CALL EditBrowseBoxTableCell::getBackground(  ) throw (RuntimeException)
106cdf0e10cSrcweir 	{
107cdf0e10cSrcweir 		SolarMethodGuard aGuard( *this );
108cdf0e10cSrcweir 		Reference< XAccessibleComponent > xAccComp( m_xInnerContext, UNO_QUERY );
109cdf0e10cSrcweir 		if ( xAccComp.is() )
110cdf0e10cSrcweir 			return xAccComp->getBackground();
111cdf0e10cSrcweir 		return 0;
112cdf0e10cSrcweir 	}
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
115cdf0e10cSrcweir 	Reference< XAccessible > SAL_CALL EditBrowseBoxTableCell::getAccessibleParent(  ) throw (RuntimeException)
116cdf0e10cSrcweir 	{
117cdf0e10cSrcweir 		return m_xParentAccessible;
118cdf0e10cSrcweir 	}
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
121cdf0e10cSrcweir 	::rtl::OUString SAL_CALL EditBrowseBoxTableCell::getAccessibleDescription()	throw ( RuntimeException )
122cdf0e10cSrcweir 	{
123cdf0e10cSrcweir 		SolarMethodGuard aGuard( *this );
124cdf0e10cSrcweir 		return m_xInnerContext->getAccessibleDescription();
125cdf0e10cSrcweir 	}
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
128cdf0e10cSrcweir 	::rtl::OUString SAL_CALL EditBrowseBoxTableCell::getAccessibleName() throw ( RuntimeException )
129cdf0e10cSrcweir 	{
130cdf0e10cSrcweir 		SolarMethodGuard aGuard( *this );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         // TODO: localize this!
133cdf0e10cSrcweir         String sName = mpBrowseBox->GetColumnDescription( ::sal::static_int_cast< sal_uInt16 >( getColumnPos() ) );
134cdf0e10cSrcweir         if ( 0 == sName.Len() )
135cdf0e10cSrcweir         {
136cdf0e10cSrcweir             sName = String::CreateFromAscii( "Column " );
137cdf0e10cSrcweir             sName += String::CreateFromInt32( getColumnPos( ) );
138cdf0e10cSrcweir         }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir         sName += String::CreateFromAscii( ", Row " );
141cdf0e10cSrcweir         sName += String::CreateFromInt32( getRowPos( ) );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir         return ::rtl::OUString( sName );
144cdf0e10cSrcweir 	}
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
147cdf0e10cSrcweir 	Reference< XAccessibleRelationSet > SAL_CALL EditBrowseBoxTableCell::getAccessibleRelationSet()	throw ( RuntimeException )
148cdf0e10cSrcweir 	{
149cdf0e10cSrcweir 		SolarMethodGuard aGuard( *this );
150cdf0e10cSrcweir 		return OAccessibleContextWrapperHelper::getAccessibleRelationSet( );
151cdf0e10cSrcweir 	}
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
154cdf0e10cSrcweir 	Reference<XAccessibleStateSet > SAL_CALL EditBrowseBoxTableCell::getAccessibleStateSet() throw ( RuntimeException )
155cdf0e10cSrcweir 	{
156cdf0e10cSrcweir 		SolarMethodGuard aGuard( *this );
157cdf0e10cSrcweir 		return m_xInnerContext->getAccessibleStateSet();
158cdf0e10cSrcweir 			// TODO: shouldn't we add an ACTIVE here? Isn't the EditBrowseBoxTableCell always ACTIVE?
159cdf0e10cSrcweir 	}
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
162cdf0e10cSrcweir 	sal_Int32 SAL_CALL EditBrowseBoxTableCell::getAccessibleChildCount(  ) throw (RuntimeException)
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		SolarMethodGuard aGuard( *this );
165cdf0e10cSrcweir 		return OAccessibleContextWrapperHelper::getAccessibleChildCount();
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
169cdf0e10cSrcweir 	Reference< XAccessible > SAL_CALL EditBrowseBoxTableCell::getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException)
170cdf0e10cSrcweir 	{
171cdf0e10cSrcweir 		SolarMethodGuard aGuard( *this );
172cdf0e10cSrcweir 		return OAccessibleContextWrapperHelper::getAccessibleChild( i );
173cdf0e10cSrcweir 	}
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
176cdf0e10cSrcweir 	sal_Int16 SAL_CALL EditBrowseBoxTableCell::getAccessibleRole() throw ( RuntimeException )
177cdf0e10cSrcweir 	{
178cdf0e10cSrcweir 		SolarMethodGuard aGuard( *this );
179cdf0e10cSrcweir 		return m_xInnerContext->getAccessibleRole( );
180cdf0e10cSrcweir 	}
181cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
182cdf0e10cSrcweir 	void SAL_CALL EditBrowseBoxTableCell::dispose() throw( RuntimeException )
183cdf0e10cSrcweir 	{
184cdf0e10cSrcweir 		// simply disambiguate. Note that the OComponentHelper base in AccessibleBrowseBoxCell
185cdf0e10cSrcweir 		// will call our "disposing()", which will call "dispose()" on the OAccessibleContextWrapperHelper
186cdf0e10cSrcweir 		// so there is no need to do this here.
187cdf0e10cSrcweir 		AccessibleBrowseBoxCell::dispose();
188cdf0e10cSrcweir 	}
189cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
190cdf0e10cSrcweir 	void SAL_CALL EditBrowseBoxTableCell::disposing( const EventObject& _rSource ) throw (RuntimeException)
191cdf0e10cSrcweir 	{
192cdf0e10cSrcweir 		AccessibleBrowseBoxCell::disposing( _rSource );
193cdf0e10cSrcweir 		OAccessibleContextWrapperHelper::disposing( _rSource );
194cdf0e10cSrcweir 	}
195cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
196cdf0e10cSrcweir 	void SAL_CALL EditBrowseBoxTableCell::disposing()
197cdf0e10cSrcweir 	{
198cdf0e10cSrcweir 		SolarMethodGuard aGuard( *this, false );
199cdf0e10cSrcweir 		OAccessibleContextWrapperHelper::dispose();
200cdf0e10cSrcweir 			// TODO: do we need to dispose our inner object? The base class does this, but is it a good idea?
201cdf0e10cSrcweir 		AccessibleBrowseBoxCell::disposing();
202cdf0e10cSrcweir 	}
203cdf0e10cSrcweir 	// =============================================================================
204cdf0e10cSrcweir 	// = EditBrowseBoxTableCell
205cdf0e10cSrcweir 	// =============================================================================
206cdf0e10cSrcweir 	DBG_NAME( EditBrowseBoxTableCellAccess )
207cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
208cdf0e10cSrcweir 	EditBrowseBoxTableCellAccess::EditBrowseBoxTableCellAccess(
209cdf0e10cSrcweir 			const Reference< XAccessible >& _rxParent, const Reference< XAccessible > _rxControlAccessible,
210cdf0e10cSrcweir 			const Reference< XWindow >& _rxFocusWindow,
211cdf0e10cSrcweir 			IAccessibleTableProvider& _rBrowseBox, sal_Int32 _nRowPos, sal_uInt16 _nColPos )
212cdf0e10cSrcweir 		:EditBrowseBoxTableCellAccess_Base( m_aMutex )
213cdf0e10cSrcweir 		,m_xParent( _rxParent )
214cdf0e10cSrcweir 		,m_xControlAccessible( _rxControlAccessible )
215cdf0e10cSrcweir 		,m_xFocusWindow( _rxFocusWindow )
216cdf0e10cSrcweir 		,m_pBrowseBox( &_rBrowseBox )
217cdf0e10cSrcweir 		,m_nRowPos( _nRowPos )
218cdf0e10cSrcweir 		,m_nColPos( _nColPos )
219cdf0e10cSrcweir 	{
220cdf0e10cSrcweir 		DBG_CTOR( EditBrowseBoxTableCellAccess, NULL );
221cdf0e10cSrcweir 	}
222cdf0e10cSrcweir 	// -----------------------------------------------------------------------------
223cdf0e10cSrcweir 	EditBrowseBoxTableCellAccess::~EditBrowseBoxTableCellAccess( )
224cdf0e10cSrcweir 	{
225cdf0e10cSrcweir 		DBG_DTOR( EditBrowseBoxTableCellAccess, NULL );
226cdf0e10cSrcweir 	}
227cdf0e10cSrcweir 	//--------------------------------------------------------------------
228cdf0e10cSrcweir 	Reference< XAccessibleContext > SAL_CALL EditBrowseBoxTableCellAccess::getAccessibleContext(  ) throw (RuntimeException)
229cdf0e10cSrcweir 	{
230cdf0e10cSrcweir 		if ( !m_pBrowseBox || !m_xControlAccessible.is() )
231cdf0e10cSrcweir 			throw DisposedException();
232cdf0e10cSrcweir 	        Reference< XAccessibleContext > xMyContext( m_aContext );
233cdf0e10cSrcweir         	if ( !xMyContext.is() )
234cdf0e10cSrcweir 	        {
235cdf0e10cSrcweir 		    Reference< XAccessibleContext > xInnerContext = m_xControlAccessible->getAccessibleContext();
236cdf0e10cSrcweir 		    Reference< XAccessible > xMe( this );
237cdf0e10cSrcweir 
238cdf0e10cSrcweir         	    xMyContext = new EditBrowseBoxTableCell( m_xParent, xMe, xInnerContext, *m_pBrowseBox, m_xFocusWindow, m_nRowPos, m_nColPos );
239cdf0e10cSrcweir            	 m_aContext = xMyContext;
240cdf0e10cSrcweir         	}
241cdf0e10cSrcweir 		return xMyContext;
242cdf0e10cSrcweir 	}
243cdf0e10cSrcweir 	//--------------------------------------------------------------------
244cdf0e10cSrcweir 	void SAL_CALL EditBrowseBoxTableCellAccess::disposing()
245cdf0e10cSrcweir 	{
246cdf0e10cSrcweir         // dispose our context, if it still alive
247cdf0e10cSrcweir         Reference< XComponent > xMyContext( (Reference< XAccessibleContext >)m_aContext, UNO_QUERY );
248cdf0e10cSrcweir         if ( xMyContext.is() )
249cdf0e10cSrcweir         {
250cdf0e10cSrcweir             try
251cdf0e10cSrcweir             {
252cdf0e10cSrcweir                 xMyContext->dispose();
253cdf0e10cSrcweir             }
254cdf0e10cSrcweir             catch( const Exception& e )
255cdf0e10cSrcweir             {
256cdf0e10cSrcweir                 (void)e;
257cdf0e10cSrcweir                 OSL_ENSURE( false, "EditBrowseBoxTableCellAccess::disposing: caught an exception while disposing the context!" );
258cdf0e10cSrcweir             }
259cdf0e10cSrcweir         }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir         m_pBrowseBox = NULL;
262cdf0e10cSrcweir         m_xControlAccessible.clear();
263cdf0e10cSrcweir         m_aContext = Reference< XAccessibleContext >( );
264cdf0e10cSrcweir         // NO dispose of the inner object there: it is the XAccessible of an window, and disposing
265cdf0e10cSrcweir         // it would delete the respective VCL window
266cdf0e10cSrcweir 	}
267cdf0e10cSrcweir // .................................................................................
268cdf0e10cSrcweir } // namespace accessibility
269cdf0e10cSrcweir // .................................................................................
270