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 
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 	// -----------------------------------------------------------------------------
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 	// -----------------------------------------------------------------------------
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 	// -----------------------------------------------------------------------------
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 	// -----------------------------------------------------------------------------
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 	// -----------------------------------------------------------------------------
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 	// -----------------------------------------------------------------------------
115 	Reference< XAccessible > SAL_CALL EditBrowseBoxTableCell::getAccessibleParent(  ) throw (RuntimeException)
116 	{
117 		return m_xParentAccessible;
118 	}
119 
120 	// -----------------------------------------------------------------------------
121 	::rtl::OUString SAL_CALL EditBrowseBoxTableCell::getAccessibleDescription()	throw ( RuntimeException )
122 	{
123 		SolarMethodGuard aGuard( *this );
124 		return m_xInnerContext->getAccessibleDescription();
125 	}
126 
127 	// -----------------------------------------------------------------------------
128 	::rtl::OUString SAL_CALL EditBrowseBoxTableCell::getAccessibleName() throw ( RuntimeException )
129 	{
130 		SolarMethodGuard aGuard( *this );
131 
132         // TODO: localize this!
133         String sName = mpBrowseBox->GetColumnDescription( ::sal::static_int_cast< sal_uInt16 >( getColumnPos() ) );
134         if ( 0 == sName.Len() )
135         {
136             sName = String::CreateFromAscii( "Column " );
137             sName += String::CreateFromInt32( getColumnPos( ) );
138         }
139 
140         sName += String::CreateFromAscii( ", Row " );
141         sName += String::CreateFromInt32( getRowPos( ) );
142 
143         return ::rtl::OUString( sName );
144 	}
145 
146 	// -----------------------------------------------------------------------------
147 	Reference< XAccessibleRelationSet > SAL_CALL EditBrowseBoxTableCell::getAccessibleRelationSet()	throw ( RuntimeException )
148 	{
149 		SolarMethodGuard aGuard( *this );
150 		return OAccessibleContextWrapperHelper::getAccessibleRelationSet( );
151 	}
152 
153 	// -----------------------------------------------------------------------------
154 	Reference<XAccessibleStateSet > SAL_CALL EditBrowseBoxTableCell::getAccessibleStateSet() throw ( RuntimeException )
155 	{
156 		SolarMethodGuard aGuard( *this );
157 		return m_xInnerContext->getAccessibleStateSet();
158 			// TODO: shouldn't we add an ACTIVE here? Isn't the EditBrowseBoxTableCell always ACTIVE?
159 	}
160 
161 	// -----------------------------------------------------------------------------
162 	sal_Int32 SAL_CALL EditBrowseBoxTableCell::getAccessibleChildCount(  ) throw (RuntimeException)
163 	{
164 		SolarMethodGuard aGuard( *this );
165 		return OAccessibleContextWrapperHelper::getAccessibleChildCount();
166 	}
167 
168 	// -----------------------------------------------------------------------------
169 	Reference< XAccessible > SAL_CALL EditBrowseBoxTableCell::getAccessibleChild( sal_Int32 i ) throw (::com::sun::star::lang::IndexOutOfBoundsException, RuntimeException)
170 	{
171 		SolarMethodGuard aGuard( *this );
172 		return OAccessibleContextWrapperHelper::getAccessibleChild( i );
173 	}
174 
175 	// -----------------------------------------------------------------------------
176 	sal_Int16 SAL_CALL EditBrowseBoxTableCell::getAccessibleRole() throw ( RuntimeException )
177 	{
178 		SolarMethodGuard aGuard( *this );
179 		return m_xInnerContext->getAccessibleRole( );
180 	}
181 	// -----------------------------------------------------------------------------
182 	void SAL_CALL EditBrowseBoxTableCell::dispose() throw( RuntimeException )
183 	{
184 		// simply disambiguate. Note that the OComponentHelper base in AccessibleBrowseBoxCell
185 		// will call our "disposing()", which will call "dispose()" on the OAccessibleContextWrapperHelper
186 		// so there is no need to do this here.
187 		AccessibleBrowseBoxCell::dispose();
188 	}
189 	// -----------------------------------------------------------------------------
190 	void SAL_CALL EditBrowseBoxTableCell::disposing( const EventObject& _rSource ) throw (RuntimeException)
191 	{
192 		AccessibleBrowseBoxCell::disposing( _rSource );
193 		OAccessibleContextWrapperHelper::disposing( _rSource );
194 	}
195 	// -----------------------------------------------------------------------------
196 	void SAL_CALL EditBrowseBoxTableCell::disposing()
197 	{
198 		SolarMethodGuard aGuard( *this, false );
199 		OAccessibleContextWrapperHelper::dispose();
200 			// TODO: do we need to dispose our inner object? The base class does this, but is it a good idea?
201 		AccessibleBrowseBoxCell::disposing();
202 	}
203 	// =============================================================================
204 	// = EditBrowseBoxTableCell
205 	// =============================================================================
206 	DBG_NAME( EditBrowseBoxTableCellAccess )
207 	// -----------------------------------------------------------------------------
208 	EditBrowseBoxTableCellAccess::EditBrowseBoxTableCellAccess(
209 			const Reference< XAccessible >& _rxParent, const Reference< XAccessible > _rxControlAccessible,
210 			const Reference< XWindow >& _rxFocusWindow,
211 			IAccessibleTableProvider& _rBrowseBox, sal_Int32 _nRowPos, sal_uInt16 _nColPos )
212 		:EditBrowseBoxTableCellAccess_Base( m_aMutex )
213 		,m_xParent( _rxParent )
214 		,m_xControlAccessible( _rxControlAccessible )
215 		,m_xFocusWindow( _rxFocusWindow )
216 		,m_pBrowseBox( &_rBrowseBox )
217 		,m_nRowPos( _nRowPos )
218 		,m_nColPos( _nColPos )
219 	{
220 		DBG_CTOR( EditBrowseBoxTableCellAccess, NULL );
221 	}
222 	// -----------------------------------------------------------------------------
223 	EditBrowseBoxTableCellAccess::~EditBrowseBoxTableCellAccess( )
224 	{
225 		DBG_DTOR( EditBrowseBoxTableCellAccess, NULL );
226 	}
227 	//--------------------------------------------------------------------
228 	Reference< XAccessibleContext > SAL_CALL EditBrowseBoxTableCellAccess::getAccessibleContext(  ) throw (RuntimeException)
229 	{
230 		if ( !m_pBrowseBox || !m_xControlAccessible.is() )
231 			throw DisposedException();
232 	        Reference< XAccessibleContext > xMyContext( m_aContext );
233         	if ( !xMyContext.is() )
234 	        {
235 		    Reference< XAccessibleContext > xInnerContext = m_xControlAccessible->getAccessibleContext();
236 		    Reference< XAccessible > xMe( this );
237 
238         	    xMyContext = new EditBrowseBoxTableCell( m_xParent, xMe, xInnerContext, *m_pBrowseBox, m_xFocusWindow, m_nRowPos, m_nColPos );
239            	 m_aContext = xMyContext;
240         	}
241 		return xMyContext;
242 	}
243 	//--------------------------------------------------------------------
244 	void SAL_CALL EditBrowseBoxTableCellAccess::disposing()
245 	{
246         // dispose our context, if it still alive
247         Reference< XComponent > xMyContext( (Reference< XAccessibleContext >)m_aContext, UNO_QUERY );
248         if ( xMyContext.is() )
249         {
250             try
251             {
252                 xMyContext->dispose();
253             }
254             catch( const Exception& e )
255             {
256                 (void)e;
257                 OSL_ENSURE( false, "EditBrowseBoxTableCellAccess::disposing: caught an exception while disposing the context!" );
258             }
259         }
260 
261         m_pBrowseBox = NULL;
262         m_xControlAccessible.clear();
263         m_aContext = Reference< XAccessibleContext >( );
264         // NO dispose of the inner object there: it is the XAccessible of an window, and disposing
265         // it would delete the respective VCL window
266 	}
267 // .................................................................................
268 } // namespace accessibility
269 // .................................................................................
270