1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b0724fc6SAndrew Rist  * distributed with this work for additional information
6*b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b0724fc6SAndrew Rist  *
11*b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b0724fc6SAndrew Rist  *
13*b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist  * under the License.
19*b0724fc6SAndrew Rist  *
20*b0724fc6SAndrew Rist  *************************************************************/
21*b0724fc6SAndrew Rist 
22*b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_toolkit.hxx"
26cdf0e10cSrcweir #include <toolkit/controls/formattedcontrol.hxx>
27cdf0e10cSrcweir #include <toolkit/helper/unopropertyarrayhelper.hxx>
28cdf0e10cSrcweir #include <toolkit/helper/property.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <com/sun/star/awt/XVclWindowPeer.hpp>
31cdf0e10cSrcweir #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <tools/diagnose_ex.h>
34cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
35cdf0e10cSrcweir #include <osl/diagnose.h>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //........................................................................
38cdf0e10cSrcweir namespace toolkit
39cdf0e10cSrcweir {
40cdf0e10cSrcweir //........................................................................
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 	using namespace ::com::sun::star::uno;
43cdf0e10cSrcweir 	using namespace ::com::sun::star::awt;
44cdf0e10cSrcweir 	using namespace ::com::sun::star::lang;
45cdf0e10cSrcweir 	using namespace ::com::sun::star::beans;
46cdf0e10cSrcweir 	using namespace ::com::sun::star::util;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 	// -------------------------------------------------------------------
49cdf0e10cSrcweir     namespace
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir 	    // ...............................................................
getDefaultFormatsMutex()52cdf0e10cSrcweir         ::osl::Mutex& getDefaultFormatsMutex()
53cdf0e10cSrcweir         {
54cdf0e10cSrcweir             static ::osl::Mutex s_aDefaultFormatsMutex;
55cdf0e10cSrcweir             return s_aDefaultFormatsMutex;
56cdf0e10cSrcweir         }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir         // ...............................................................
lcl_getDefaultFormatsAccess_nothrow()59cdf0e10cSrcweir         Reference< XNumberFormatsSupplier >& lcl_getDefaultFormatsAccess_nothrow()
60cdf0e10cSrcweir         {
61cdf0e10cSrcweir             static Reference< XNumberFormatsSupplier > s_xDefaultFormats;
62cdf0e10cSrcweir             return s_xDefaultFormats;
63cdf0e10cSrcweir         }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         // ...............................................................
lcl_getTriedCreation()66cdf0e10cSrcweir         bool& lcl_getTriedCreation()
67cdf0e10cSrcweir         {
68cdf0e10cSrcweir             static bool s_bTriedCreation = false;
69cdf0e10cSrcweir             return s_bTriedCreation;
70cdf0e10cSrcweir         }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	    // ...............................................................
lcl_getDefaultFormats_throw()73cdf0e10cSrcweir         const Reference< XNumberFormatsSupplier >& lcl_getDefaultFormats_throw()
74cdf0e10cSrcweir         {
75cdf0e10cSrcweir             ::osl::MutexGuard aGuard( getDefaultFormatsMutex() );
76cdf0e10cSrcweir 
77cdf0e10cSrcweir             bool& rbTriedCreation = lcl_getTriedCreation();
78cdf0e10cSrcweir             Reference< XNumberFormatsSupplier >& rDefaultFormats( lcl_getDefaultFormatsAccess_nothrow() );
79cdf0e10cSrcweir             if ( !rDefaultFormats.is() && !rbTriedCreation )
80cdf0e10cSrcweir             {
81cdf0e10cSrcweir                 rbTriedCreation = true;
82cdf0e10cSrcweir                 rDefaultFormats = Reference< XNumberFormatsSupplier >(
83cdf0e10cSrcweir                     ::comphelper::createProcessComponent(
84cdf0e10cSrcweir                         ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.NumberFormatsSupplier" ) ) ),
85cdf0e10cSrcweir                     UNO_QUERY_THROW
86cdf0e10cSrcweir                 );
87cdf0e10cSrcweir             }
88cdf0e10cSrcweir             if ( !rDefaultFormats.is() )
89cdf0e10cSrcweir                 throw RuntimeException();
90cdf0e10cSrcweir 
91cdf0e10cSrcweir             return rDefaultFormats;
92cdf0e10cSrcweir         }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir         // ...............................................................
95cdf0e10cSrcweir         static oslInterlockedCount  s_refCount(0);
96cdf0e10cSrcweir 
97cdf0e10cSrcweir         // ...............................................................
lcl_registerDefaultFormatsClient()98cdf0e10cSrcweir         void    lcl_registerDefaultFormatsClient()
99cdf0e10cSrcweir         {
100cdf0e10cSrcweir             osl_incrementInterlockedCount( &s_refCount );
101cdf0e10cSrcweir         }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir         // ...............................................................
lcl_revokeDefaultFormatsClient()104cdf0e10cSrcweir         void    lcl_revokeDefaultFormatsClient()
105cdf0e10cSrcweir         {
106cdf0e10cSrcweir             ::osl::ClearableMutexGuard aGuard( getDefaultFormatsMutex() );
107cdf0e10cSrcweir             if ( 0 == osl_decrementInterlockedCount( &s_refCount ) )
108cdf0e10cSrcweir             {
109cdf0e10cSrcweir                 Reference< XNumberFormatsSupplier >& rDefaultFormats( lcl_getDefaultFormatsAccess_nothrow() );
110cdf0e10cSrcweir                 Reference< XNumberFormatsSupplier > xReleasePotentialLastReference( rDefaultFormats );
111cdf0e10cSrcweir                 rDefaultFormats.clear();
112cdf0e10cSrcweir                 lcl_getTriedCreation() = false;
113cdf0e10cSrcweir 
114cdf0e10cSrcweir                 aGuard.clear();
115cdf0e10cSrcweir                 xReleasePotentialLastReference.clear();
116cdf0e10cSrcweir             }
117cdf0e10cSrcweir         }
118cdf0e10cSrcweir     }
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	// ===================================================================
121cdf0e10cSrcweir 	// = UnoControlFormattedFieldModel
122cdf0e10cSrcweir 	// ===================================================================
123cdf0e10cSrcweir 	// -------------------------------------------------------------------
UnoControlFormattedFieldModel(const Reference<XMultiServiceFactory> & i_factory)124cdf0e10cSrcweir 	UnoControlFormattedFieldModel::UnoControlFormattedFieldModel( const Reference< XMultiServiceFactory >& i_factory )
125cdf0e10cSrcweir         :UnoControlModel( i_factory )
126cdf0e10cSrcweir         ,m_bRevokedAsClient( false )
127cdf0e10cSrcweir         ,m_bSettingValueAndText( false )
128cdf0e10cSrcweir 	{
129cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_ALIGN );
130cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_BACKGROUNDCOLOR );
131cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_BORDER );
132cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_BORDERCOLOR );
133cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_DEFAULTCONTROL );
134cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_EFFECTIVE_DEFAULT );
135cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_EFFECTIVE_VALUE );
136cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_EFFECTIVE_MAX );
137cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_EFFECTIVE_MIN );
138cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_ENABLED );
139cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_ENABLEVISIBLE );
140cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_FONTDESCRIPTOR );
141cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_FORMATKEY );
142cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_FORMATSSUPPLIER );
143cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_HELPTEXT );
144cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_HELPURL );
145cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_MAXTEXTLEN );
146cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_PRINTABLE );
147cdf0e10cSrcweir     	ImplRegisterProperty( BASEPROPERTY_REPEAT );
148cdf0e10cSrcweir         ImplRegisterProperty( BASEPROPERTY_REPEAT_DELAY );
149cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_READONLY );
150cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_SPIN );
151cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_STRICTFORMAT );
152cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_TABSTOP );
153cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_TEXT );
154cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_TEXTCOLOR );
155cdf0e10cSrcweir     	ImplRegisterProperty( BASEPROPERTY_HIDEINACTIVESELECTION );
156cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_ENFORCE_FORMAT );
157cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_VERTICALALIGN );
158cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_WRITING_MODE );
159cdf0e10cSrcweir         ImplRegisterProperty( BASEPROPERTY_CONTEXT_WRITING_MODE );
160cdf0e10cSrcweir         ImplRegisterProperty( BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 		Any aTreatAsNumber;
163cdf0e10cSrcweir 		aTreatAsNumber <<= (sal_Bool) sal_True;
164cdf0e10cSrcweir 		ImplRegisterProperty( BASEPROPERTY_TREATASNUMBER, aTreatAsNumber );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         lcl_registerDefaultFormatsClient();
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 	// -------------------------------------------------------------------
~UnoControlFormattedFieldModel()170cdf0e10cSrcweir     UnoControlFormattedFieldModel::~UnoControlFormattedFieldModel()
171cdf0e10cSrcweir     {
172cdf0e10cSrcweir     }
173cdf0e10cSrcweir 
174cdf0e10cSrcweir 	// -------------------------------------------------------------------
getServiceName()175cdf0e10cSrcweir 	::rtl::OUString UnoControlFormattedFieldModel::getServiceName() throw(RuntimeException)
176cdf0e10cSrcweir 	{
177cdf0e10cSrcweir 		return ::rtl::OUString::createFromAscii( szServiceName_UnoControlFormattedFieldModel );
178cdf0e10cSrcweir 	}
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	// -------------------------------------------------------------------
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any & rValue)181cdf0e10cSrcweir     void SAL_CALL UnoControlFormattedFieldModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const Any& rValue ) throw (Exception)
182cdf0e10cSrcweir     {
183cdf0e10cSrcweir         UnoControlModel::setFastPropertyValue_NoBroadcast( nHandle, rValue );
184cdf0e10cSrcweir 
185cdf0e10cSrcweir         switch ( nHandle )
186cdf0e10cSrcweir         {
187cdf0e10cSrcweir         case BASEPROPERTY_EFFECTIVE_VALUE:
188cdf0e10cSrcweir             if ( !m_bSettingValueAndText )
189cdf0e10cSrcweir                 impl_updateTextFromValue_nothrow();
190cdf0e10cSrcweir             break;
191cdf0e10cSrcweir         case BASEPROPERTY_FORMATSSUPPLIER:
192cdf0e10cSrcweir             impl_updateCachedFormatter_nothrow();
193cdf0e10cSrcweir             impl_updateTextFromValue_nothrow();
194cdf0e10cSrcweir             break;
195cdf0e10cSrcweir         case BASEPROPERTY_FORMATKEY:
196cdf0e10cSrcweir             impl_updateCachedFormatKey_nothrow();
197cdf0e10cSrcweir             impl_updateTextFromValue_nothrow();
198cdf0e10cSrcweir             break;
199cdf0e10cSrcweir         }
200cdf0e10cSrcweir     }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 	// -------------------------------------------------------------------
impl_updateTextFromValue_nothrow()203cdf0e10cSrcweir     void UnoControlFormattedFieldModel::impl_updateTextFromValue_nothrow()
204cdf0e10cSrcweir     {
205cdf0e10cSrcweir         if ( !m_xCachedFormatter.is() )
206cdf0e10cSrcweir             impl_updateCachedFormatter_nothrow();
207cdf0e10cSrcweir         if ( !m_xCachedFormatter.is() )
208cdf0e10cSrcweir             return;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir         try
211cdf0e10cSrcweir         {
212cdf0e10cSrcweir             Any aEffectiveValue;
213cdf0e10cSrcweir             getFastPropertyValue( aEffectiveValue, BASEPROPERTY_EFFECTIVE_VALUE );
214cdf0e10cSrcweir 
215cdf0e10cSrcweir             ::rtl::OUString sStringValue;
216cdf0e10cSrcweir             if ( !( aEffectiveValue >>= sStringValue ) )
217cdf0e10cSrcweir             {
218cdf0e10cSrcweir                 double nDoubleValue(0);
219cdf0e10cSrcweir                 if ( aEffectiveValue >>= nDoubleValue )
220cdf0e10cSrcweir                 {
221cdf0e10cSrcweir                     sal_Int32 nFormatKey( 0 );
222cdf0e10cSrcweir                     if ( m_aCachedFormat.hasValue() )
223cdf0e10cSrcweir                         m_aCachedFormat >>= nFormatKey;
224cdf0e10cSrcweir                     sStringValue = m_xCachedFormatter->convertNumberToString( nFormatKey, nDoubleValue );
225cdf0e10cSrcweir                 }
226cdf0e10cSrcweir             }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir             Reference< XPropertySet > xThis( *this, UNO_QUERY );
229cdf0e10cSrcweir             xThis->setPropertyValue( GetPropertyName( BASEPROPERTY_TEXT ), makeAny( sStringValue ) );
230cdf0e10cSrcweir         }
231cdf0e10cSrcweir         catch( const Exception& )
232cdf0e10cSrcweir         {
233cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
234cdf0e10cSrcweir         }
235cdf0e10cSrcweir     }
236cdf0e10cSrcweir 
237cdf0e10cSrcweir 	// -------------------------------------------------------------------
impl_updateCachedFormatter_nothrow()238cdf0e10cSrcweir     void UnoControlFormattedFieldModel::impl_updateCachedFormatter_nothrow()
239cdf0e10cSrcweir     {
240cdf0e10cSrcweir         Any aFormatsSupplier;
241cdf0e10cSrcweir         getFastPropertyValue( aFormatsSupplier, BASEPROPERTY_FORMATSSUPPLIER );
242cdf0e10cSrcweir         try
243cdf0e10cSrcweir         {
244cdf0e10cSrcweir             Reference< XNumberFormatsSupplier > xSupplier( aFormatsSupplier, UNO_QUERY );
245cdf0e10cSrcweir             if ( !xSupplier.is() )
246cdf0e10cSrcweir                 xSupplier = lcl_getDefaultFormats_throw();
247cdf0e10cSrcweir 
248cdf0e10cSrcweir             if ( !m_xCachedFormatter.is() )
249cdf0e10cSrcweir             {
250cdf0e10cSrcweir                 m_xCachedFormatter = Reference< XNumberFormatter >(
251cdf0e10cSrcweir                     ::comphelper::createProcessComponent( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.util.NumberFormatter" ) ) ),
252cdf0e10cSrcweir                     UNO_QUERY_THROW
253cdf0e10cSrcweir                 );
254cdf0e10cSrcweir             }
255cdf0e10cSrcweir             m_xCachedFormatter->attachNumberFormatsSupplier( xSupplier );
256cdf0e10cSrcweir         }
257cdf0e10cSrcweir         catch( const Exception& )
258cdf0e10cSrcweir         {
259cdf0e10cSrcweir         	DBG_UNHANDLED_EXCEPTION();
260cdf0e10cSrcweir         }
261cdf0e10cSrcweir     }
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	// -------------------------------------------------------------------
impl_updateCachedFormatKey_nothrow()264cdf0e10cSrcweir     void UnoControlFormattedFieldModel::impl_updateCachedFormatKey_nothrow()
265cdf0e10cSrcweir     {
266cdf0e10cSrcweir         Any aFormatKey;
267cdf0e10cSrcweir         getFastPropertyValue( aFormatKey, BASEPROPERTY_FORMATKEY );
268cdf0e10cSrcweir         m_aCachedFormat = aFormatKey;
269cdf0e10cSrcweir     }
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	// -------------------------------------------------------------------
dispose()272cdf0e10cSrcweir 	void UnoControlFormattedFieldModel::dispose(  ) throw(RuntimeException)
273cdf0e10cSrcweir     {
274cdf0e10cSrcweir         UnoControlModel::dispose();
275cdf0e10cSrcweir 
276cdf0e10cSrcweir         ::osl::MutexGuard aGuard( GetMutex() );
277cdf0e10cSrcweir         if ( !m_bRevokedAsClient )
278cdf0e10cSrcweir         {
279cdf0e10cSrcweir             lcl_revokeDefaultFormatsClient();
280cdf0e10cSrcweir             m_bRevokedAsClient = true;
281cdf0e10cSrcweir         }
282cdf0e10cSrcweir     }
283cdf0e10cSrcweir 
284cdf0e10cSrcweir     // -------------------------------------------------------------------
ImplNormalizePropertySequence(const sal_Int32 _nCount,sal_Int32 * _pHandles,Any * _pValues,sal_Int32 * _pValidHandles) const285cdf0e10cSrcweir     void UnoControlFormattedFieldModel::ImplNormalizePropertySequence( const sal_Int32 _nCount, sal_Int32* _pHandles,
286cdf0e10cSrcweir 	    Any* _pValues, sal_Int32* _pValidHandles ) const SAL_THROW(())
287cdf0e10cSrcweir     {
288cdf0e10cSrcweir         ImplEnsureHandleOrder( _nCount, _pHandles, _pValues, BASEPROPERTY_EFFECTIVE_VALUE, BASEPROPERTY_TEXT );
289cdf0e10cSrcweir 
290cdf0e10cSrcweir         UnoControlModel::ImplNormalizePropertySequence( _nCount, _pHandles, _pValues, _pValidHandles );
291cdf0e10cSrcweir     }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir     // -------------------------------------------------------------------
294cdf0e10cSrcweir     namespace
295cdf0e10cSrcweir     {
296cdf0e10cSrcweir         class ResetFlagOnExit
297cdf0e10cSrcweir         {
298cdf0e10cSrcweir         private:
299cdf0e10cSrcweir             bool&   m_rFlag;
300cdf0e10cSrcweir 
301cdf0e10cSrcweir         public:
ResetFlagOnExit(bool & _rFlag)302cdf0e10cSrcweir             ResetFlagOnExit( bool& _rFlag )
303cdf0e10cSrcweir                 :m_rFlag( _rFlag )
304cdf0e10cSrcweir             {
305cdf0e10cSrcweir             }
~ResetFlagOnExit()306cdf0e10cSrcweir             ~ResetFlagOnExit()
307cdf0e10cSrcweir             {
308cdf0e10cSrcweir                 m_rFlag = false;
309cdf0e10cSrcweir             }
310cdf0e10cSrcweir         };
311cdf0e10cSrcweir     }
312cdf0e10cSrcweir 
313cdf0e10cSrcweir     // -------------------------------------------------------------------
setPropertyValues(const Sequence<::rtl::OUString> & _rPropertyNames,const Sequence<Any> & _rValues)314cdf0e10cSrcweir 	void SAL_CALL UnoControlFormattedFieldModel::setPropertyValues( const Sequence< ::rtl::OUString >& _rPropertyNames, const Sequence< Any >& _rValues ) throw(PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException)
315cdf0e10cSrcweir     {
316cdf0e10cSrcweir         bool bSettingValue = false;
317cdf0e10cSrcweir         bool bSettingText = false;
318cdf0e10cSrcweir         for (   const ::rtl::OUString* pPropertyNames = _rPropertyNames.getConstArray();
319cdf0e10cSrcweir                 pPropertyNames != _rPropertyNames.getConstArray() + _rPropertyNames.getLength();
320cdf0e10cSrcweir                 ++pPropertyNames
321cdf0e10cSrcweir             )
322cdf0e10cSrcweir         {
323cdf0e10cSrcweir             if ( BASEPROPERTY_EFFECTIVE_VALUE == GetPropertyId( *pPropertyNames ) )
324cdf0e10cSrcweir                 bSettingValue = true;
325cdf0e10cSrcweir 
326cdf0e10cSrcweir             if ( BASEPROPERTY_TEXT == GetPropertyId( *pPropertyNames ) )
327cdf0e10cSrcweir                 bSettingText = true;
328cdf0e10cSrcweir         }
329cdf0e10cSrcweir 
330cdf0e10cSrcweir         m_bSettingValueAndText = ( bSettingValue && bSettingText );
331cdf0e10cSrcweir         ResetFlagOnExit aResetFlag( m_bSettingValueAndText );
332cdf0e10cSrcweir         UnoControlModel::setPropertyValues( _rPropertyNames, _rValues );
333cdf0e10cSrcweir     }
334cdf0e10cSrcweir 
335cdf0e10cSrcweir     // -------------------------------------------------------------------
convertFastPropertyValue(Any & rConvertedValue,Any & rOldValue,sal_Int32 nPropId,const Any & rValue)336cdf0e10cSrcweir 	sal_Bool UnoControlFormattedFieldModel::convertFastPropertyValue(
337cdf0e10cSrcweir 				Any& rConvertedValue, Any& rOldValue, sal_Int32 nPropId,
338cdf0e10cSrcweir 				const Any& rValue ) throw (IllegalArgumentException)
339cdf0e10cSrcweir 	{
340cdf0e10cSrcweir 		if ( BASEPROPERTY_EFFECTIVE_DEFAULT == nPropId && rValue.hasValue() )
341cdf0e10cSrcweir 		{
342cdf0e10cSrcweir 			double dVal = 0;
343cdf0e10cSrcweir 			sal_Int32  nVal = 0;
344cdf0e10cSrcweir 			::rtl::OUString sVal;
345cdf0e10cSrcweir 			sal_Bool bStreamed = (rValue >>= dVal);
346cdf0e10cSrcweir 			if ( bStreamed )
347cdf0e10cSrcweir             {
348cdf0e10cSrcweir 				rConvertedValue <<= dVal;
349cdf0e10cSrcweir             }
350cdf0e10cSrcweir 			else
351cdf0e10cSrcweir             {
352cdf0e10cSrcweir                 bStreamed = (rValue >>= nVal);
353cdf0e10cSrcweir                 if ( bStreamed )
354cdf0e10cSrcweir                 {
355cdf0e10cSrcweir                     rConvertedValue <<= static_cast<double>(nVal);
356cdf0e10cSrcweir                 }
357cdf0e10cSrcweir                 else
358cdf0e10cSrcweir                 {
359cdf0e10cSrcweir                     bStreamed = (rValue >>= sVal);
360cdf0e10cSrcweir                     if ( bStreamed )
361cdf0e10cSrcweir                     {
362cdf0e10cSrcweir                         rConvertedValue <<= sVal;
363cdf0e10cSrcweir                     }
364cdf0e10cSrcweir                 }
365cdf0e10cSrcweir             }
366cdf0e10cSrcweir 
367cdf0e10cSrcweir 			if ( bStreamed )
368cdf0e10cSrcweir 			{
369cdf0e10cSrcweir 				getFastPropertyValue( rOldValue, nPropId );
370cdf0e10cSrcweir 				return !CompareProperties( rConvertedValue, rOldValue );
371cdf0e10cSrcweir 			}
372cdf0e10cSrcweir 
373cdf0e10cSrcweir 			throw IllegalArgumentException(
374cdf0e10cSrcweir 						( ::rtl::OUString::createFromAscii("Unable to convert the given value for the property ")
375cdf0e10cSrcweir 					+=	GetPropertyName((sal_uInt16)nPropId) )
376cdf0e10cSrcweir 					+=  ::rtl::OUString::createFromAscii(" (double, integer, or string expected)."),
377cdf0e10cSrcweir 				static_cast< XPropertySet* >(this),
378cdf0e10cSrcweir 				1);
379cdf0e10cSrcweir 		}
380cdf0e10cSrcweir 
381cdf0e10cSrcweir 		return UnoControlModel::convertFastPropertyValue( rConvertedValue, rOldValue, nPropId, rValue );
382cdf0e10cSrcweir 	}
383cdf0e10cSrcweir 
384cdf0e10cSrcweir 	// -------------------------------------------------------------------
ImplGetDefaultValue(sal_uInt16 nPropId) const385cdf0e10cSrcweir 	Any UnoControlFormattedFieldModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
386cdf0e10cSrcweir 	{
387cdf0e10cSrcweir 		Any aReturn;
388cdf0e10cSrcweir 		switch (nPropId)
389cdf0e10cSrcweir 		{
390cdf0e10cSrcweir 			case BASEPROPERTY_DEFAULTCONTROL: aReturn <<= ::rtl::OUString( ::rtl::OUString::createFromAscii( szServiceName_UnoControlFormattedField ) ); break;
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 			case BASEPROPERTY_TREATASNUMBER: aReturn <<= (sal_Bool)sal_True; break;
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 			case BASEPROPERTY_EFFECTIVE_DEFAULT:
395cdf0e10cSrcweir 			case BASEPROPERTY_EFFECTIVE_VALUE:
396cdf0e10cSrcweir 			case BASEPROPERTY_EFFECTIVE_MAX:
397cdf0e10cSrcweir 			case BASEPROPERTY_EFFECTIVE_MIN:
398cdf0e10cSrcweir 			case BASEPROPERTY_FORMATKEY:
399cdf0e10cSrcweir 			case BASEPROPERTY_FORMATSSUPPLIER:
400cdf0e10cSrcweir 				// (void)
401cdf0e10cSrcweir 				break;
402cdf0e10cSrcweir 
403cdf0e10cSrcweir 			default : aReturn = UnoControlModel::ImplGetDefaultValue( nPropId ); break;
404cdf0e10cSrcweir 		}
405cdf0e10cSrcweir 
406cdf0e10cSrcweir 		return aReturn;
407cdf0e10cSrcweir 	}
408cdf0e10cSrcweir 
409cdf0e10cSrcweir 	// -------------------------------------------------------------------
getInfoHelper()410cdf0e10cSrcweir 	::cppu::IPropertyArrayHelper& UnoControlFormattedFieldModel::getInfoHelper()
411cdf0e10cSrcweir 	{
412cdf0e10cSrcweir 		static UnoPropertyArrayHelper* pHelper = NULL;
413cdf0e10cSrcweir 		if ( !pHelper )
414cdf0e10cSrcweir 		{
415cdf0e10cSrcweir 			Sequence<sal_Int32>	aIDs = ImplGetPropertyIds();
416cdf0e10cSrcweir 			pHelper = new UnoPropertyArrayHelper( aIDs );
417cdf0e10cSrcweir 		}
418cdf0e10cSrcweir 		return *pHelper;
419cdf0e10cSrcweir 	}
420cdf0e10cSrcweir 
421cdf0e10cSrcweir 	// beans::XMultiPropertySet
422cdf0e10cSrcweir 	// -------------------------------------------------------------------
getPropertySetInfo()423cdf0e10cSrcweir 	Reference< XPropertySetInfo > UnoControlFormattedFieldModel::getPropertySetInfo(  ) throw(RuntimeException)
424cdf0e10cSrcweir 	{
425cdf0e10cSrcweir 		static Reference< XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
426cdf0e10cSrcweir 		return xInfo;
427cdf0e10cSrcweir 	}
428cdf0e10cSrcweir 
429cdf0e10cSrcweir 	// ===================================================================
430cdf0e10cSrcweir 	// = UnoFormattedFieldControl
431cdf0e10cSrcweir 	// ===================================================================
432cdf0e10cSrcweir 	// -------------------------------------------------------------------
UnoFormattedFieldControl(const Reference<XMultiServiceFactory> & i_factory)433cdf0e10cSrcweir 	UnoFormattedFieldControl::UnoFormattedFieldControl( const Reference< XMultiServiceFactory >& i_factory )
434cdf0e10cSrcweir         :UnoSpinFieldControl( i_factory )
435cdf0e10cSrcweir 	{
436cdf0e10cSrcweir 	}
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 	// -------------------------------------------------------------------
GetComponentServiceName()439cdf0e10cSrcweir 	::rtl::OUString UnoFormattedFieldControl::GetComponentServiceName()
440cdf0e10cSrcweir 	{
441cdf0e10cSrcweir 		return ::rtl::OUString::createFromAscii( "FormattedField" );
442cdf0e10cSrcweir 	}
443cdf0e10cSrcweir 
444cdf0e10cSrcweir 	// -------------------------------------------------------------------
textChanged(const TextEvent & e)445cdf0e10cSrcweir 	void UnoFormattedFieldControl::textChanged(const TextEvent& e) throw(RuntimeException)
446cdf0e10cSrcweir 	{
447cdf0e10cSrcweir 		Reference< XVclWindowPeer >  xPeer(getPeer(), UNO_QUERY);
448cdf0e10cSrcweir 		OSL_ENSURE(xPeer.is(), "UnoFormattedFieldControl::textChanged : what kind of peer do I have ?");
449cdf0e10cSrcweir 
450cdf0e10cSrcweir         Sequence< ::rtl::OUString > aNames( 2 );
451cdf0e10cSrcweir         aNames[0] = GetPropertyName( BASEPROPERTY_EFFECTIVE_VALUE );
452cdf0e10cSrcweir         aNames[1] = GetPropertyName( BASEPROPERTY_TEXT );
453cdf0e10cSrcweir 
454cdf0e10cSrcweir         Sequence< Any > aValues( 2 );
455cdf0e10cSrcweir         aValues[0] = xPeer->getProperty( aNames[0] );
456cdf0e10cSrcweir         aValues[1] = xPeer->getProperty( aNames[1] );
457cdf0e10cSrcweir 
458cdf0e10cSrcweir         ImplSetPropertyValues( aNames, aValues, sal_False );
459cdf0e10cSrcweir 
460cdf0e10cSrcweir 		if ( GetTextListeners().getLength() )
461cdf0e10cSrcweir 			GetTextListeners().textChanged( e );
462cdf0e10cSrcweir 	}
463cdf0e10cSrcweir 
464cdf0e10cSrcweir //........................................................................
465cdf0e10cSrcweir }	// namespace toolkit
466cdf0e10cSrcweir //........................................................................
467