1*2a97ec55SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*2a97ec55SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*2a97ec55SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*2a97ec55SAndrew Rist  * distributed with this work for additional information
6*2a97ec55SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*2a97ec55SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*2a97ec55SAndrew Rist  * "License"); you may not use this file except in compliance
9*2a97ec55SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*2a97ec55SAndrew Rist  *
11*2a97ec55SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*2a97ec55SAndrew Rist  *
13*2a97ec55SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*2a97ec55SAndrew Rist  * software distributed under the License is distributed on an
15*2a97ec55SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*2a97ec55SAndrew Rist  * KIND, either express or implied.  See the License for the
17*2a97ec55SAndrew Rist  * specific language governing permissions and limitations
18*2a97ec55SAndrew Rist  * under the License.
19*2a97ec55SAndrew Rist  *
20*2a97ec55SAndrew Rist  *************************************************************/
21*2a97ec55SAndrew Rist 
22*2a97ec55SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_extensions.hxx"
26cdf0e10cSrcweir #include "cellbindinghandler.hxx"
27cdf0e10cSrcweir #include "formstrings.hxx"
28cdf0e10cSrcweir #include "formmetadata.hxx"
29cdf0e10cSrcweir #include "cellbindinghelper.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir /** === begin UNO includes === **/
32cdf0e10cSrcweir #include <com/sun/star/form/binding/XValueBinding.hpp>
33cdf0e10cSrcweir #include <com/sun/star/table/CellAddress.hpp>
34cdf0e10cSrcweir #include <com/sun/star/inspection/XObjectInspectorUI.hpp>
35cdf0e10cSrcweir /** === end UNO includes === **/
36cdf0e10cSrcweir #include <tools/debug.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir //------------------------------------------------------------------------
createRegistryInfo_CellBindingPropertyHandler()39cdf0e10cSrcweir extern "C" void SAL_CALL createRegistryInfo_CellBindingPropertyHandler()
40cdf0e10cSrcweir {
41cdf0e10cSrcweir     ::pcr::CellBindingPropertyHandler::registerImplementation();
42cdf0e10cSrcweir }
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //........................................................................
45cdf0e10cSrcweir namespace pcr
46cdf0e10cSrcweir {
47cdf0e10cSrcweir //........................................................................
48cdf0e10cSrcweir 
49cdf0e10cSrcweir     using namespace ::com::sun::star::uno;
50cdf0e10cSrcweir     using namespace ::com::sun::star::table;
51cdf0e10cSrcweir     using namespace ::com::sun::star::lang;
52cdf0e10cSrcweir     using namespace ::com::sun::star::beans;
53cdf0e10cSrcweir     using namespace ::com::sun::star::script;
54cdf0e10cSrcweir     using namespace ::com::sun::star::frame;
55cdf0e10cSrcweir     using namespace ::com::sun::star::inspection;
56cdf0e10cSrcweir     using namespace ::com::sun::star::form::binding;
57cdf0e10cSrcweir     using namespace ::comphelper;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	//====================================================================
60cdf0e10cSrcweir 	//= CellBindingPropertyHandler
61cdf0e10cSrcweir 	//====================================================================
DBG_NAME(CellBindingPropertyHandler)62cdf0e10cSrcweir     DBG_NAME( CellBindingPropertyHandler )
63cdf0e10cSrcweir 	//--------------------------------------------------------------------
64cdf0e10cSrcweir     CellBindingPropertyHandler::CellBindingPropertyHandler( const Reference< XComponentContext >& _rxContext )
65cdf0e10cSrcweir         :CellBindingPropertyHandler_Base( _rxContext )
66cdf0e10cSrcweir         ,m_pCellExchangeConverter( new DefaultEnumRepresentation( *m_pInfoService, ::getCppuType( static_cast< sal_Int16* >( NULL ) ), PROPERTY_ID_CELL_EXCHANGE_TYPE ) )
67cdf0e10cSrcweir     {
68cdf0e10cSrcweir         DBG_CTOR( CellBindingPropertyHandler, NULL );
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     //--------------------------------------------------------------------
getImplementationName_static()72cdf0e10cSrcweir     ::rtl::OUString SAL_CALL CellBindingPropertyHandler::getImplementationName_static(  ) throw (RuntimeException)
73cdf0e10cSrcweir     {
74cdf0e10cSrcweir         return ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.extensions.CellBindingPropertyHandler" ) );
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     //--------------------------------------------------------------------
getSupportedServiceNames_static()78cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL CellBindingPropertyHandler::getSupportedServiceNames_static(  ) throw (RuntimeException)
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir         Sequence< ::rtl::OUString > aSupported( 1 );
81cdf0e10cSrcweir         aSupported[0] = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.form.inspection.CellBindingPropertyHandler" ) );
82cdf0e10cSrcweir         return aSupported;
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     //--------------------------------------------------------------------
onNewComponent()86cdf0e10cSrcweir     void CellBindingPropertyHandler::onNewComponent()
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir         PropertyHandlerComponent::onNewComponent();
89cdf0e10cSrcweir 
90cdf0e10cSrcweir         Reference< XModel > xDocument( impl_getContextDocument_nothrow() );
91cdf0e10cSrcweir         DBG_ASSERT( xDocument.is(), "CellBindingPropertyHandler::onNewComponent: no document!" );
92cdf0e10cSrcweir         if ( CellBindingHelper::isSpreadsheetDocument( xDocument ) )
93cdf0e10cSrcweir             m_pHelper.reset( new CellBindingHelper( m_xComponent, xDocument ) );
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir 	//--------------------------------------------------------------------
~CellBindingPropertyHandler()97cdf0e10cSrcweir     CellBindingPropertyHandler::~CellBindingPropertyHandler( )
98cdf0e10cSrcweir     {
99cdf0e10cSrcweir         DBG_DTOR( CellBindingPropertyHandler, NULL );
100cdf0e10cSrcweir     }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     //--------------------------------------------------------------------
getActuatingProperties()103cdf0e10cSrcweir     Sequence< ::rtl::OUString > SAL_CALL CellBindingPropertyHandler::getActuatingProperties( ) throw (RuntimeException)
104cdf0e10cSrcweir     {
105cdf0e10cSrcweir         Sequence< ::rtl::OUString > aInterestingProperties( 3 );
106cdf0e10cSrcweir         aInterestingProperties[0] = PROPERTY_LIST_CELL_RANGE;
107cdf0e10cSrcweir         aInterestingProperties[1] = PROPERTY_BOUND_CELL;
108cdf0e10cSrcweir         aInterestingProperties[2] = PROPERTY_CONTROLSOURCE;
109cdf0e10cSrcweir         return aInterestingProperties;
110cdf0e10cSrcweir     }
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	//--------------------------------------------------------------------
actuatingPropertyChanged(const::rtl::OUString & _rActuatingPropertyName,const Any & _rNewValue,const Any &,const Reference<XObjectInspectorUI> & _rxInspectorUI,sal_Bool _bFirstTimeInit)113cdf0e10cSrcweir     void SAL_CALL CellBindingPropertyHandler::actuatingPropertyChanged( const ::rtl::OUString& _rActuatingPropertyName, const Any& _rNewValue, const Any& /*_rOldValue*/, const Reference< XObjectInspectorUI >& _rxInspectorUI, sal_Bool _bFirstTimeInit ) throw (NullPointerException, RuntimeException)
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
116cdf0e10cSrcweir         PropertyId nActuatingPropId( impl_getPropertyId_throw( _rActuatingPropertyName ) );
117cdf0e10cSrcweir         OSL_PRECOND( m_pHelper.get(), "CellBindingPropertyHandler::actuatingPropertyChanged: inconsistentcy!" );
118cdf0e10cSrcweir             // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         OSL_PRECOND( _rxInspectorUI.is(), "FormComponentPropertyHandler::actuatingPropertyChanged: no access to the UI!" );
121cdf0e10cSrcweir         if ( !_rxInspectorUI.is() )
122cdf0e10cSrcweir             throw NullPointerException();
123cdf0e10cSrcweir 
124cdf0e10cSrcweir         ::std::vector< PropertyId > aDependentProperties;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir         switch ( nActuatingPropId )
127cdf0e10cSrcweir         {
128cdf0e10cSrcweir         // ----- BoundCell -----
129cdf0e10cSrcweir         case PROPERTY_ID_BOUND_CELL:
130cdf0e10cSrcweir         {
131cdf0e10cSrcweir             // the SQL-data-binding related properties need to be enabled if and only if
132cdf0e10cSrcweir             // there is *no* valid cell binding
133cdf0e10cSrcweir             Reference< XValueBinding > xBinding;
134cdf0e10cSrcweir             _rNewValue >>= xBinding;
135cdf0e10cSrcweir 
136cdf0e10cSrcweir             if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_CELL_EXCHANGE_TYPE ) )
137cdf0e10cSrcweir                 _rxInspectorUI->enablePropertyUI( PROPERTY_CELL_EXCHANGE_TYPE, xBinding.is() );
138cdf0e10cSrcweir             if ( impl_componentHasProperty_throw( PROPERTY_CONTROLSOURCE ) )
139cdf0e10cSrcweir                 _rxInspectorUI->enablePropertyUI( PROPERTY_CONTROLSOURCE, !xBinding.is() );
140cdf0e10cSrcweir 
141cdf0e10cSrcweir             if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_FILTERPROPOSAL ) )
142cdf0e10cSrcweir                 _rxInspectorUI->enablePropertyUI( PROPERTY_FILTERPROPOSAL, !xBinding.is() );
143cdf0e10cSrcweir             if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_EMPTY_IS_NULL ) )
144cdf0e10cSrcweir                 _rxInspectorUI->enablePropertyUI( PROPERTY_EMPTY_IS_NULL, !xBinding.is() );
145cdf0e10cSrcweir 
146cdf0e10cSrcweir             aDependentProperties.push_back( PROPERTY_ID_BOUNDCOLUMN );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir             if ( !xBinding.is() && m_pHelper->getCurrentBinding().is() )
149cdf0e10cSrcweir             {
150cdf0e10cSrcweir                 // ensure that the "transfer selection as" property is reset. Since we can't remember
151cdf0e10cSrcweir                 // it at the object itself, but derive it from the binding only, we have to normalize
152cdf0e10cSrcweir                 // it now that there *is* no binding anymore.
153cdf0e10cSrcweir                 setPropertyValue( PROPERTY_CELL_EXCHANGE_TYPE, makeAny( (sal_Int16) 0 ) );
154cdf0e10cSrcweir             }
155cdf0e10cSrcweir         }
156cdf0e10cSrcweir         break;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         // ----- CellRange -----
159cdf0e10cSrcweir         case PROPERTY_ID_LIST_CELL_RANGE:
160cdf0e10cSrcweir         {
161cdf0e10cSrcweir             // the list source related properties need to be enabled if and only if
162cdf0e10cSrcweir             // there is *no* valid external list source for the control
163cdf0e10cSrcweir             Reference< XListEntrySource > xSource;
164cdf0e10cSrcweir             _rNewValue >>= xSource;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir             _rxInspectorUI->enablePropertyUI( PROPERTY_STRINGITEMLIST, !xSource.is() );
167cdf0e10cSrcweir             _rxInspectorUI->enablePropertyUI( PROPERTY_LISTSOURCE, !xSource.is() );
168cdf0e10cSrcweir             _rxInspectorUI->enablePropertyUI( PROPERTY_LISTSOURCETYPE, !xSource.is() );
169cdf0e10cSrcweir 
170cdf0e10cSrcweir             aDependentProperties.push_back( PROPERTY_ID_BOUNDCOLUMN );
171cdf0e10cSrcweir 
172cdf0e10cSrcweir             // also reset the list entries if the cell range is reset
173cdf0e10cSrcweir             // #i28319# - 2004-04-27 - fs@openoffice.org
174cdf0e10cSrcweir             if ( !_bFirstTimeInit )
175cdf0e10cSrcweir             {
176cdf0e10cSrcweir                 try
177cdf0e10cSrcweir                 {
178cdf0e10cSrcweir                     if ( !xSource.is() )
179cdf0e10cSrcweir                         setPropertyValue( PROPERTY_STRINGITEMLIST, makeAny( Sequence< ::rtl::OUString >() ) );
180cdf0e10cSrcweir                 }
181cdf0e10cSrcweir                 catch( const Exception& )
182cdf0e10cSrcweir                 {
183cdf0e10cSrcweir             	    OSL_ENSURE( sal_False, "OPropertyBrowserController::actuatingPropertyChanged( ListCellRange ): caught an exception while resetting the string items!" );
184cdf0e10cSrcweir                 }
185cdf0e10cSrcweir             }
186cdf0e10cSrcweir         }
187cdf0e10cSrcweir         break;  // case PROPERTY_ID_LIST_CELL_RANGE
188cdf0e10cSrcweir 
189cdf0e10cSrcweir         // ----- DataField -----
190cdf0e10cSrcweir         case PROPERTY_ID_CONTROLSOURCE:
191cdf0e10cSrcweir         {
192cdf0e10cSrcweir             ::rtl::OUString sControlSource;
193cdf0e10cSrcweir             _rNewValue >>= sControlSource;
194cdf0e10cSrcweir             if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_BOUND_CELL ) )
195cdf0e10cSrcweir                 _rxInspectorUI->enablePropertyUI( PROPERTY_BOUND_CELL, sControlSource.getLength() == 0 );
196cdf0e10cSrcweir         }
197cdf0e10cSrcweir         break;  // case PROPERTY_ID_CONTROLSOURCE
198cdf0e10cSrcweir 
199cdf0e10cSrcweir         default:
200cdf0e10cSrcweir             DBG_ERROR( "CellBindingPropertyHandler::actuatingPropertyChanged: did not register for this property!" );
201cdf0e10cSrcweir         }
202cdf0e10cSrcweir 
203cdf0e10cSrcweir         for ( ::std::vector< PropertyId >::const_iterator loopAffected = aDependentProperties.begin();
204cdf0e10cSrcweir               loopAffected != aDependentProperties.end();
205cdf0e10cSrcweir               ++loopAffected
206cdf0e10cSrcweir             )
207cdf0e10cSrcweir         {
208cdf0e10cSrcweir             impl_updateDependentProperty_nothrow( *loopAffected, _rxInspectorUI );
209cdf0e10cSrcweir         }
210cdf0e10cSrcweir     }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir 	//--------------------------------------------------------------------
impl_updateDependentProperty_nothrow(PropertyId _nPropId,const Reference<XObjectInspectorUI> & _rxInspectorUI) const213cdf0e10cSrcweir     void CellBindingPropertyHandler::impl_updateDependentProperty_nothrow( PropertyId _nPropId, const Reference< XObjectInspectorUI >& _rxInspectorUI ) const
214cdf0e10cSrcweir     {
215cdf0e10cSrcweir         try
216cdf0e10cSrcweir         {
217cdf0e10cSrcweir             switch ( _nPropId )
218cdf0e10cSrcweir             {
219cdf0e10cSrcweir             // ----- BoundColumn -----
220cdf0e10cSrcweir             case PROPERTY_ID_BOUNDCOLUMN:
221cdf0e10cSrcweir             {
222cdf0e10cSrcweir                 CellBindingPropertyHandler* pNonConstThis = const_cast< CellBindingPropertyHandler* >( this );
223cdf0e10cSrcweir                 Reference< XValueBinding > xBinding( pNonConstThis->getPropertyValue( PROPERTY_BOUND_CELL ), UNO_QUERY );
224cdf0e10cSrcweir                 Reference< XListEntrySource > xListSource( pNonConstThis->getPropertyValue( PROPERTY_LIST_CELL_RANGE ), UNO_QUERY );
225cdf0e10cSrcweir 
226cdf0e10cSrcweir                 if ( impl_isSupportedProperty_nothrow( PROPERTY_ID_BOUNDCOLUMN ) )
227cdf0e10cSrcweir                     _rxInspectorUI->enablePropertyUI( PROPERTY_BOUNDCOLUMN, !xBinding.is() && !xListSource.is() );
228cdf0e10cSrcweir             }
229cdf0e10cSrcweir             break;  // case PROPERTY_ID_BOUNDCOLUMN
230cdf0e10cSrcweir 
231cdf0e10cSrcweir             }   // switch
232cdf0e10cSrcweir 
233cdf0e10cSrcweir         }
234cdf0e10cSrcweir         catch( const Exception& )
235cdf0e10cSrcweir         {
236cdf0e10cSrcweir         	OSL_ENSURE( sal_False, "CellBindingPropertyHandler::impl_updateDependentProperty_nothrow: caught an exception!" );
237cdf0e10cSrcweir         }
238cdf0e10cSrcweir     }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 	//--------------------------------------------------------------------
getPropertyValue(const::rtl::OUString & _rPropertyName)241cdf0e10cSrcweir     Any SAL_CALL CellBindingPropertyHandler::getPropertyValue( const ::rtl::OUString& _rPropertyName ) throw (UnknownPropertyException, RuntimeException)
242cdf0e10cSrcweir     {
243cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
244cdf0e10cSrcweir         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
245cdf0e10cSrcweir 
246cdf0e10cSrcweir         OSL_ENSURE( m_pHelper.get(), "CellBindingPropertyHandler::getPropertyValue: inconsistency!" );
247cdf0e10cSrcweir             // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
248cdf0e10cSrcweir 
249cdf0e10cSrcweir         Any aReturn;
250cdf0e10cSrcweir         switch ( nPropId )
251cdf0e10cSrcweir         {
252cdf0e10cSrcweir         case PROPERTY_ID_BOUND_CELL:
253cdf0e10cSrcweir         {
254cdf0e10cSrcweir             Reference< XValueBinding > xBinding( m_pHelper->getCurrentBinding() );
255cdf0e10cSrcweir             if ( !m_pHelper->isCellBinding( xBinding ) )
256cdf0e10cSrcweir                 xBinding.clear();
257cdf0e10cSrcweir 
258cdf0e10cSrcweir             aReturn <<= xBinding;
259cdf0e10cSrcweir         }
260cdf0e10cSrcweir         break;
261cdf0e10cSrcweir 
262cdf0e10cSrcweir         case PROPERTY_ID_LIST_CELL_RANGE:
263cdf0e10cSrcweir         {
264cdf0e10cSrcweir             Reference< XListEntrySource > xSource( m_pHelper->getCurrentListSource() );
265cdf0e10cSrcweir             if ( !m_pHelper->isCellRangeListSource( xSource ) )
266cdf0e10cSrcweir                 xSource.clear();
267cdf0e10cSrcweir 
268cdf0e10cSrcweir             aReturn <<= xSource;
269cdf0e10cSrcweir         }
270cdf0e10cSrcweir         break;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir         case PROPERTY_ID_CELL_EXCHANGE_TYPE:
273cdf0e10cSrcweir         {
274cdf0e10cSrcweir             Reference< XValueBinding > xBinding( m_pHelper->getCurrentBinding() );
275cdf0e10cSrcweir             aReturn <<= (sal_Int16)( m_pHelper->isCellIntegerBinding( xBinding ) ? 1 : 0 );
276cdf0e10cSrcweir         }
277cdf0e10cSrcweir         break;
278cdf0e10cSrcweir 
279cdf0e10cSrcweir         default:
280cdf0e10cSrcweir             DBG_ERROR( "CellBindingPropertyHandler::getPropertyValue: cannot handle this!" );
281cdf0e10cSrcweir             break;
282cdf0e10cSrcweir         }
283cdf0e10cSrcweir         return aReturn;
284cdf0e10cSrcweir     }
285cdf0e10cSrcweir 
286cdf0e10cSrcweir     //--------------------------------------------------------------------
setPropertyValue(const::rtl::OUString & _rPropertyName,const Any & _rValue)287cdf0e10cSrcweir     void SAL_CALL CellBindingPropertyHandler::setPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rValue ) throw (UnknownPropertyException, RuntimeException)
288cdf0e10cSrcweir     {
289cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
290cdf0e10cSrcweir         PropertyId nPropId( impl_getPropertyId_throw( _rPropertyName ) );
291cdf0e10cSrcweir 
292cdf0e10cSrcweir         OSL_ENSURE( m_pHelper.get(), "CellBindingPropertyHandler::setPropertyValue: inconsistency!" );
293cdf0e10cSrcweir             // if we survived impl_getPropertyId_throw, we should have a helper, since no helper implies no properties
294cdf0e10cSrcweir 
295cdf0e10cSrcweir         try
296cdf0e10cSrcweir         {
297cdf0e10cSrcweir             Any aOldValue = getPropertyValue( _rPropertyName );
298cdf0e10cSrcweir 
299cdf0e10cSrcweir             switch ( nPropId )
300cdf0e10cSrcweir             {
301cdf0e10cSrcweir             case PROPERTY_ID_BOUND_CELL:
302cdf0e10cSrcweir             {
303cdf0e10cSrcweir                 Reference< XValueBinding > xBinding;
304cdf0e10cSrcweir                 _rValue >>= xBinding;
305cdf0e10cSrcweir                 m_pHelper->setBinding( xBinding );
306cdf0e10cSrcweir             }
307cdf0e10cSrcweir             break;
308cdf0e10cSrcweir 
309cdf0e10cSrcweir             case PROPERTY_ID_LIST_CELL_RANGE:
310cdf0e10cSrcweir             {
311cdf0e10cSrcweir                 Reference< XListEntrySource > xSource;
312cdf0e10cSrcweir                 _rValue >>= xSource;
313cdf0e10cSrcweir                 m_pHelper->setListSource( xSource );
314cdf0e10cSrcweir             }
315cdf0e10cSrcweir             break;
316cdf0e10cSrcweir 
317cdf0e10cSrcweir             case PROPERTY_ID_CELL_EXCHANGE_TYPE:
318cdf0e10cSrcweir             {
319cdf0e10cSrcweir                 sal_Int16 nExchangeType = 0;
320cdf0e10cSrcweir                 OSL_VERIFY( _rValue >>= nExchangeType );
321cdf0e10cSrcweir 
322cdf0e10cSrcweir                 Reference< XValueBinding > xBinding = m_pHelper->getCurrentBinding( );
323cdf0e10cSrcweir                 if ( xBinding.is() )
324cdf0e10cSrcweir                 {
325cdf0e10cSrcweir                     sal_Bool bNeedIntegerBinding = ( nExchangeType == 1 );
326cdf0e10cSrcweir                     if ( (bool)bNeedIntegerBinding != m_pHelper->isCellIntegerBinding( xBinding ) )
327cdf0e10cSrcweir                     {
328cdf0e10cSrcweir                         CellAddress aAddress;
329cdf0e10cSrcweir                         if ( m_pHelper->getAddressFromCellBinding( xBinding, aAddress ) )
330cdf0e10cSrcweir                         {
331cdf0e10cSrcweir                             xBinding = m_pHelper->createCellBindingFromAddress( aAddress, bNeedIntegerBinding );
332cdf0e10cSrcweir                             m_pHelper->setBinding( xBinding );
333cdf0e10cSrcweir                         }
334cdf0e10cSrcweir                     }
335cdf0e10cSrcweir                 }
336cdf0e10cSrcweir             }
337cdf0e10cSrcweir             break;
338cdf0e10cSrcweir 
339cdf0e10cSrcweir             default:
340cdf0e10cSrcweir                 DBG_ERROR( "CellBindingPropertyHandler::setPropertyValue: cannot handle this!" );
341cdf0e10cSrcweir                 break;
342cdf0e10cSrcweir             }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir             impl_setContextDocumentModified_nothrow();
345cdf0e10cSrcweir 
346cdf0e10cSrcweir             Any aNewValue( getPropertyValue( _rPropertyName ) );
347cdf0e10cSrcweir             firePropertyChange( _rPropertyName, nPropId, aOldValue, aNewValue );
348cdf0e10cSrcweir             // TODO/UNOize: can't we make this a part of the base class, for all those "virtual"
349cdf0e10cSrcweir             // properties? Base class'es |setPropertyValue| could call some |doSetPropertyValue|,
350cdf0e10cSrcweir             // and handle the listener notification itself
351cdf0e10cSrcweir         }
352cdf0e10cSrcweir         catch( const Exception& )
353cdf0e10cSrcweir         {
354cdf0e10cSrcweir         	OSL_ENSURE( sal_False, "CellBindingPropertyHandler::setPropertyValue: caught an exception!" );
355cdf0e10cSrcweir         }
356cdf0e10cSrcweir     }
357cdf0e10cSrcweir 
358cdf0e10cSrcweir     //--------------------------------------------------------------------
convertToPropertyValue(const::rtl::OUString & _rPropertyName,const Any & _rControlValue)359cdf0e10cSrcweir     Any SAL_CALL CellBindingPropertyHandler::convertToPropertyValue( const ::rtl::OUString& _rPropertyName, const Any& _rControlValue ) throw (UnknownPropertyException, RuntimeException)
360cdf0e10cSrcweir     {
361cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
362cdf0e10cSrcweir         Any aPropertyValue;
363cdf0e10cSrcweir 
364cdf0e10cSrcweir         OSL_ENSURE( m_pHelper.get(), "CellBindingPropertyHandler::convertToPropertyValue: we have no SupportedProperties!" );
365cdf0e10cSrcweir         if ( !m_pHelper.get() )
366cdf0e10cSrcweir             return aPropertyValue;
367cdf0e10cSrcweir 
368cdf0e10cSrcweir         PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) );
369cdf0e10cSrcweir 
370cdf0e10cSrcweir         ::rtl::OUString sControlValue;
371cdf0e10cSrcweir         OSL_VERIFY( _rControlValue >>= sControlValue );
372cdf0e10cSrcweir 		switch( nPropId )
373cdf0e10cSrcweir 		{
374cdf0e10cSrcweir             case PROPERTY_ID_LIST_CELL_RANGE:
375cdf0e10cSrcweir                 aPropertyValue <<= m_pHelper->createCellListSourceFromStringAddress( sControlValue );
376cdf0e10cSrcweir                 break;
377cdf0e10cSrcweir 
378cdf0e10cSrcweir 			case PROPERTY_ID_BOUND_CELL:
379cdf0e10cSrcweir             {
380cdf0e10cSrcweir                 // if we have the possibility of an integer binding, then we must preserve
381cdf0e10cSrcweir                 // this property's value (e.g. if the current binding is an integer binding, then
382cdf0e10cSrcweir                 // the newly created one must be, too)
383cdf0e10cSrcweir                 bool bIntegerBinding = false;
384cdf0e10cSrcweir                 if ( m_pHelper->isCellIntegerBindingAllowed() )
385cdf0e10cSrcweir                 {
386cdf0e10cSrcweir                     sal_Int16 nCurrentBindingType = 0;
387cdf0e10cSrcweir                     getPropertyValue( PROPERTY_CELL_EXCHANGE_TYPE ) >>= nCurrentBindingType;
388cdf0e10cSrcweir                     bIntegerBinding = ( nCurrentBindingType != 0 );
389cdf0e10cSrcweir                 }
390cdf0e10cSrcweir                 aPropertyValue <<= m_pHelper->createCellBindingFromStringAddress( sControlValue, bIntegerBinding );
391cdf0e10cSrcweir             }
392cdf0e10cSrcweir             break;
393cdf0e10cSrcweir 
394cdf0e10cSrcweir             case PROPERTY_ID_CELL_EXCHANGE_TYPE:
395cdf0e10cSrcweir                 m_pCellExchangeConverter->getValueFromDescription( sControlValue, aPropertyValue );
396cdf0e10cSrcweir                 break;
397cdf0e10cSrcweir 
398cdf0e10cSrcweir             default:
399cdf0e10cSrcweir                 DBG_ERROR( "CellBindingPropertyHandler::convertToPropertyValue: cannot handle this!" );
400cdf0e10cSrcweir                 break;
401cdf0e10cSrcweir         }
402cdf0e10cSrcweir 
403cdf0e10cSrcweir         return aPropertyValue;
404cdf0e10cSrcweir     }
405cdf0e10cSrcweir 
406cdf0e10cSrcweir     //--------------------------------------------------------------------
convertToControlValue(const::rtl::OUString & _rPropertyName,const Any & _rPropertyValue,const Type &)407cdf0e10cSrcweir     Any SAL_CALL CellBindingPropertyHandler::convertToControlValue( const ::rtl::OUString& _rPropertyName,
408cdf0e10cSrcweir         const Any& _rPropertyValue, const Type& /*_rControlValueType*/ ) throw (UnknownPropertyException, RuntimeException)
409cdf0e10cSrcweir     {
410cdf0e10cSrcweir         ::osl::MutexGuard aGuard( m_aMutex );
411cdf0e10cSrcweir         Any aControlValue;
412cdf0e10cSrcweir 
413cdf0e10cSrcweir         OSL_ENSURE( m_pHelper.get(), "CellBindingPropertyHandler::convertToControlValue: we have no SupportedProperties!" );
414cdf0e10cSrcweir         if ( !m_pHelper.get() )
415cdf0e10cSrcweir             return aControlValue;
416cdf0e10cSrcweir 
417cdf0e10cSrcweir         PropertyId nPropId( m_pInfoService->getPropertyId( _rPropertyName ) );
418cdf0e10cSrcweir 
419cdf0e10cSrcweir 		switch ( nPropId )
420cdf0e10cSrcweir 		{
421cdf0e10cSrcweir             case PROPERTY_ID_BOUND_CELL:
422cdf0e10cSrcweir             {
423cdf0e10cSrcweir                 Reference< XValueBinding > xBinding;
424cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
425cdf0e10cSrcweir                 sal_Bool bSuccess =
426cdf0e10cSrcweir #endif
427cdf0e10cSrcweir                 _rPropertyValue >>= xBinding;
428cdf0e10cSrcweir                 OSL_ENSURE( bSuccess, "CellBindingPropertyHandler::convertToControlValue: invalid value (1)!" );
429cdf0e10cSrcweir 
430cdf0e10cSrcweir                 // the only value binding we support so far is linking to spreadsheet cells
431cdf0e10cSrcweir                 aControlValue <<= m_pHelper->getStringAddressFromCellBinding( xBinding );
432cdf0e10cSrcweir             }
433cdf0e10cSrcweir             break;
434cdf0e10cSrcweir 
435cdf0e10cSrcweir             case PROPERTY_ID_LIST_CELL_RANGE:
436cdf0e10cSrcweir             {
437cdf0e10cSrcweir                 Reference< XListEntrySource > xSource;
438cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
439cdf0e10cSrcweir                 sal_Bool bSuccess =
440cdf0e10cSrcweir #endif
441cdf0e10cSrcweir                 _rPropertyValue >>= xSource;
442cdf0e10cSrcweir                 OSL_ENSURE( bSuccess, "CellBindingPropertyHandler::convertToControlValue: invalid value (2)!" );
443cdf0e10cSrcweir 
444cdf0e10cSrcweir                 // the only value binding we support so far is linking to spreadsheet cells
445cdf0e10cSrcweir                 aControlValue <<= m_pHelper->getStringAddressFromCellListSource( xSource );
446cdf0e10cSrcweir             }
447cdf0e10cSrcweir             break;
448cdf0e10cSrcweir 
449cdf0e10cSrcweir             case PROPERTY_ID_CELL_EXCHANGE_TYPE:
450cdf0e10cSrcweir                 aControlValue <<= m_pCellExchangeConverter->getDescriptionForValue( _rPropertyValue );
451cdf0e10cSrcweir                 break;
452cdf0e10cSrcweir 
453cdf0e10cSrcweir             default:
454cdf0e10cSrcweir                 DBG_ERROR( "CellBindingPropertyHandler::convertToControlValue: cannot handle this!" );
455cdf0e10cSrcweir                 break;
456cdf0e10cSrcweir 		}
457cdf0e10cSrcweir 
458cdf0e10cSrcweir         return aControlValue;
459cdf0e10cSrcweir     }
460cdf0e10cSrcweir 
461cdf0e10cSrcweir     //--------------------------------------------------------------------
doDescribeSupportedProperties() const462cdf0e10cSrcweir     Sequence< Property > SAL_CALL CellBindingPropertyHandler::doDescribeSupportedProperties() const
463cdf0e10cSrcweir     {
464cdf0e10cSrcweir         ::std::vector< Property > aProperties;
465cdf0e10cSrcweir 
466cdf0e10cSrcweir         bool bAllowCellLinking      = m_pHelper.get() && m_pHelper->isCellBindingAllowed();
467cdf0e10cSrcweir         bool bAllowCellIntLinking   = m_pHelper.get() && m_pHelper->isCellIntegerBindingAllowed();
468cdf0e10cSrcweir         bool bAllowListCellRange    = m_pHelper.get() && m_pHelper->isListCellRangeAllowed();
469cdf0e10cSrcweir         if ( bAllowCellLinking || bAllowListCellRange || bAllowCellIntLinking )
470cdf0e10cSrcweir         {
471cdf0e10cSrcweir             sal_Int32 nPos =  ( bAllowCellLinking    ? 1 : 0 )
472cdf0e10cSrcweir                             + ( bAllowListCellRange  ? 1 : 0 )
473cdf0e10cSrcweir                             + ( bAllowCellIntLinking ? 1 : 0 );
474cdf0e10cSrcweir             aProperties.resize( nPos );
475cdf0e10cSrcweir 
476cdf0e10cSrcweir             if ( bAllowCellLinking )
477cdf0e10cSrcweir             {
478cdf0e10cSrcweir                 aProperties[ --nPos ] = Property( PROPERTY_BOUND_CELL, PROPERTY_ID_BOUND_CELL,
479cdf0e10cSrcweir                     ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) ), 0 );
480cdf0e10cSrcweir             }
481cdf0e10cSrcweir             if ( bAllowCellIntLinking )
482cdf0e10cSrcweir             {
483cdf0e10cSrcweir                 aProperties[ --nPos ] = Property( PROPERTY_CELL_EXCHANGE_TYPE, PROPERTY_ID_CELL_EXCHANGE_TYPE,
484cdf0e10cSrcweir                     ::getCppuType( static_cast< sal_Int16* >( NULL ) ), 0 );
485cdf0e10cSrcweir             }
486cdf0e10cSrcweir             if ( bAllowListCellRange )
487cdf0e10cSrcweir             {
488cdf0e10cSrcweir                 aProperties[ --nPos ] = Property( PROPERTY_LIST_CELL_RANGE, PROPERTY_ID_LIST_CELL_RANGE,
489cdf0e10cSrcweir                     ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) ), 0 );
490cdf0e10cSrcweir             }
491cdf0e10cSrcweir         }
492cdf0e10cSrcweir 
493cdf0e10cSrcweir         if ( aProperties.empty() )
494cdf0e10cSrcweir             return Sequence< Property >();
495cdf0e10cSrcweir         return Sequence< Property >( &(*aProperties.begin()), aProperties.size() );
496cdf0e10cSrcweir     }
497cdf0e10cSrcweir 
498cdf0e10cSrcweir //........................................................................
499cdf0e10cSrcweir }   // namespace pcr
500cdf0e10cSrcweir //........................................................................
501