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