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