Updated core
[LibreOffice.git] / toolkit / source / controls / unocontrolmodel.cxx
blob782922bb54641d62e2d3bdef8e9746d6b473b68f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/beans/PropertyState.hpp>
21 #include <com/sun/star/beans/PropertyAttribute.hpp>
22 #include <com/sun/star/awt/FontDescriptor.hpp>
23 #include <com/sun/star/awt/FontWidth.hpp>
24 #include <com/sun/star/awt/FontWeight.hpp>
25 #include <com/sun/star/awt/FontSlant.hpp>
26 #include <com/sun/star/awt/MouseWheelBehavior.hpp>
27 #include <com/sun/star/graphic/XGraphicProvider.hpp>
28 #include <com/sun/star/awt/XDevice.hpp>
29 #include <com/sun/star/text/WritingMode2.hpp>
30 #include <com/sun/star/io/XMarkableStream.hpp>
31 #include <toolkit/controls/unocontrolmodel.hxx>
32 #include <toolkit/helper/macros.hxx>
33 #include <cppuhelper/typeprovider.hxx>
34 #include <rtl/uuid.h>
35 #include <tools/diagnose_ex.h>
36 #include <tools/date.hxx>
37 #include <tools/time.hxx>
38 #include <tools/debug.hxx>
39 #include <toolkit/helper/property.hxx>
40 #include <toolkit/helper/vclunohelper.hxx>
41 #include <toolkit/helper/emptyfontdescriptor.hxx>
42 #include <com/sun/star/lang/Locale.hpp>
43 #include <unotools/localedatawrapper.hxx>
44 #include <unotools/configmgr.hxx>
45 #include <comphelper/processfactory.hxx>
46 #include <comphelper/sequence.hxx>
47 #include <comphelper/extract.hxx>
48 #include <vcl/svapp.hxx>
49 #include <uno/data.h>
51 #include <memory>
52 #include <set>
54 using namespace ::com::sun::star;
55 using namespace ::com::sun::star::uno;
56 using namespace ::com::sun::star::lang;
57 using namespace ::com::sun::star::i18n;
58 using ::com::sun::star::awt::FontDescriptor;
61 #define UNOCONTROL_STREAMVERSION (short)2
63 static void lcl_ImplMergeFontProperty( FontDescriptor& rFD, sal_uInt16 nPropId, const Any& rValue )
65 // some props are defined with other types than the matching FontDescriptor members have
66 // (e.g. FontWidth, FontSlant)
67 // 78474 - 09/19/2000 - FS
68 float nExtractFloat = 0;
69 sal_Int16 nExtractShort = 0;
71 switch ( nPropId )
73 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: rValue >>= rFD.Name;
74 break;
75 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: rValue >>= rFD.StyleName;
76 break;
77 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: rValue >>= rFD.Family;
78 break;
79 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: rValue >>= rFD.CharSet;
80 break;
81 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: rValue >>= nExtractFloat; rFD.Height = (sal_Int16)nExtractFloat;
82 break;
83 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: rValue >>= rFD.Weight;
84 break;
85 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: if ( rValue >>= nExtractShort )
86 rFD.Slant = (::com::sun::star::awt::FontSlant)nExtractShort;
87 else
88 rValue >>= rFD.Slant;
89 break;
90 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: rValue >>= rFD.Underline;
91 break;
92 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: rValue >>= rFD.Strikeout;
93 break;
94 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: rValue >>= rFD.Width;
95 break;
96 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: rValue >>= rFD.Pitch;
97 break;
98 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: rValue >>= rFD.CharacterWidth;
99 break;
100 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: rValue >>= rFD.Orientation;
101 break;
102 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: rValue >>= rFD.Kerning;
103 break;
104 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: rValue >>= rFD.WordLineMode;
105 break;
106 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: rValue >>= rFD.Type;
107 break;
108 default: OSL_FAIL( "FontProperty?!" );
112 // ----------------------------------------------------
113 // class UnoControlModel
114 // ----------------------------------------------------
115 UnoControlModel::UnoControlModel( const Reference< XComponentContext >& rxContext )
116 :UnoControlModel_Base()
117 ,MutexAndBroadcastHelper()
118 ,OPropertySetHelper( BrdcstHelper )
119 ,maDisposeListeners( *this )
120 ,m_xContext( rxContext )
122 // Insert properties from Model into table,
123 // only existing properties are valid, even if they're VOID
126 UnoControlModel::UnoControlModel( const UnoControlModel& rModel )
127 : UnoControlModel_Base()
128 , MutexAndBroadcastHelper()
129 , OPropertySetHelper( BrdcstHelper )
130 , maData( rModel.maData )
131 , maDisposeListeners( *this )
132 , m_xContext( rModel.m_xContext )
136 ::com::sun::star::uno::Sequence<sal_Int32> UnoControlModel::ImplGetPropertyIds() const
138 sal_uInt32 nIDs = maData.size();
139 ::com::sun::star::uno::Sequence<sal_Int32> aIDs( nIDs );
140 sal_Int32* pIDs = aIDs.getArray();
141 sal_uInt32 n = 0;
142 for ( ImplPropertyTable::const_iterator it = maData.begin(); it != maData.end(); ++it )
143 pIDs[n++] = it->first;
144 return aIDs;
147 sal_Bool UnoControlModel::ImplHasProperty( sal_uInt16 nPropId ) const
149 if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
150 nPropId = BASEPROPERTY_FONTDESCRIPTOR;
152 return maData.find( nPropId ) != maData.end() ? sal_True : sal_False;
155 ::com::sun::star::uno::Any UnoControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
157 ::com::sun::star::uno::Any aDefault;
159 if (
160 (nPropId == BASEPROPERTY_FONTDESCRIPTOR) ||
162 (nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START) &&
163 (nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END)
167 EmptyFontDescriptor aFD;
168 switch ( nPropId )
170 case BASEPROPERTY_FONTDESCRIPTOR: aDefault <<= aFD; break;
171 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: aDefault <<= aFD.Name; break;
172 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: aDefault <<= aFD.StyleName; break;
173 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: aDefault <<= aFD.Family; break;
174 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: aDefault <<= aFD.CharSet; break;
175 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: aDefault <<= (float)aFD.Height; break;
176 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: aDefault <<= aFD.Weight; break;
177 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: aDefault <<= (sal_Int16)aFD.Slant; break;
178 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: aDefault <<= aFD.Underline; break;
179 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: aDefault <<= aFD.Strikeout; break;
180 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: aDefault <<= aFD.Width; break;
181 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: aDefault <<= aFD.Pitch; break;
182 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: aDefault <<= aFD.CharacterWidth; break;
183 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: aDefault <<= aFD.Orientation; break;
184 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: aDefault <<= aFD.Kerning; break;
185 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: aDefault <<= aFD.WordLineMode; break;
186 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: aDefault <<= aFD.Type; break;
187 default: OSL_FAIL( "FontProperty?!" );
190 else
192 switch ( nPropId )
194 case BASEPROPERTY_GRAPHIC:
195 aDefault <<= Reference< graphic::XGraphic >();
196 break;
198 case BASEPROPERTY_REFERENCE_DEVICE:
199 aDefault <<= Reference< awt::XDevice >();
200 break;
202 case BASEPROPERTY_ITEM_SEPARATOR_POS:
203 case BASEPROPERTY_VERTICALALIGN:
204 case BASEPROPERTY_BORDERCOLOR:
205 case BASEPROPERTY_SYMBOL_COLOR:
206 case BASEPROPERTY_TABSTOP:
207 case BASEPROPERTY_TEXTCOLOR:
208 case BASEPROPERTY_TEXTLINECOLOR:
209 case BASEPROPERTY_DATE:
210 case BASEPROPERTY_DATESHOWCENTURY:
211 case BASEPROPERTY_TIME:
212 case BASEPROPERTY_VALUE_DOUBLE:
213 case BASEPROPERTY_PROGRESSVALUE:
214 case BASEPROPERTY_SCROLLVALUE:
215 case BASEPROPERTY_VISIBLESIZE:
216 case BASEPROPERTY_BACKGROUNDCOLOR:
217 case BASEPROPERTY_FILLCOLOR: break; // Void
219 case BASEPROPERTY_FONTRELIEF:
220 case BASEPROPERTY_FONTEMPHASISMARK:
221 case BASEPROPERTY_MAXTEXTLEN:
222 case BASEPROPERTY_STATE:
223 case BASEPROPERTY_EXTDATEFORMAT:
224 case BASEPROPERTY_EXTTIMEFORMAT:
225 case BASEPROPERTY_ECHOCHAR: aDefault <<= (sal_Int16) 0; break;
226 case BASEPROPERTY_BORDER: aDefault <<= (sal_Int16) 1; break;
227 case BASEPROPERTY_DECIMALACCURACY: aDefault <<= (sal_Int16) 2; break;
228 case BASEPROPERTY_LINECOUNT: aDefault <<= (sal_Int16) 5; break;
229 case BASEPROPERTY_ALIGN: aDefault <<= (sal_Int16) PROPERTY_ALIGN_LEFT; break;
230 case BASEPROPERTY_IMAGEALIGN: aDefault <<= (sal_Int16) 1 /*ImageAlign::TOP*/; break;
231 case BASEPROPERTY_IMAGEPOSITION: aDefault <<= (sal_Int16) 12 /*ImagePosition::Centered*/; break;
232 case BASEPROPERTY_PUSHBUTTONTYPE: aDefault <<= (sal_Int16) 0 /*PushButtonType::STANDARD*/; break;
233 case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR:aDefault <<= (sal_Int16) awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY; break;
235 case BASEPROPERTY_DATEMAX: aDefault <<= util::Date( 31, 12, 2200 ); break;
236 case BASEPROPERTY_DATEMIN: aDefault <<= util::Date( 1, 1, 1900 ); break;
237 case BASEPROPERTY_TIMEMAX: aDefault <<= util::Time(0, 0, 59, 23, false); break;
238 case BASEPROPERTY_TIMEMIN: aDefault <<= util::Time(); break;
239 case BASEPROPERTY_VALUEMAX_DOUBLE: aDefault <<= (double) 1000000; break;
240 case BASEPROPERTY_VALUEMIN_DOUBLE: aDefault <<= (double) -1000000; break;
241 case BASEPROPERTY_VALUESTEP_DOUBLE: aDefault <<= (double ) 1; break;
242 case BASEPROPERTY_PROGRESSVALUE_MAX: aDefault <<= (sal_Int32) 100; break;
243 case BASEPROPERTY_PROGRESSVALUE_MIN: aDefault <<= (sal_Int32) 0; break;
244 case BASEPROPERTY_SCROLLVALUE_MAX: aDefault <<= (sal_Int32) 100; break;
245 case BASEPROPERTY_SCROLLVALUE_MIN: aDefault <<= (sal_Int32) 0; break;
246 case BASEPROPERTY_LINEINCREMENT: aDefault <<= (sal_Int32) 1; break;
247 case BASEPROPERTY_BLOCKINCREMENT: aDefault <<= (sal_Int32) 10; break;
248 case BASEPROPERTY_ORIENTATION: aDefault <<= (sal_Int32) 0; break;
249 case BASEPROPERTY_SPINVALUE: aDefault <<= (sal_Int32) 0; break;
250 case BASEPROPERTY_SPININCREMENT: aDefault <<= (sal_Int32) 1; break;
251 case BASEPROPERTY_SPINVALUE_MIN: aDefault <<= (sal_Int32) 0; break;
252 case BASEPROPERTY_SPINVALUE_MAX: aDefault <<= (sal_Int32) 100; break;
253 case BASEPROPERTY_REPEAT_DELAY: aDefault <<= (sal_Int32) 50; break; // 50 milliseconds
254 case BASEPROPERTY_DEFAULTCONTROL: aDefault <<= ((UnoControlModel*)this)->getServiceName(); break;
256 case BASEPROPERTY_AUTOHSCROLL:
257 case BASEPROPERTY_AUTOVSCROLL:
258 case BASEPROPERTY_MOVEABLE:
259 case BASEPROPERTY_CLOSEABLE:
260 case BASEPROPERTY_SIZEABLE:
261 case BASEPROPERTY_HSCROLL:
262 case BASEPROPERTY_DEFAULTBUTTON:
263 case BASEPROPERTY_MULTILINE:
264 case BASEPROPERTY_MULTISELECTION:
265 case BASEPROPERTY_TRISTATE:
266 case BASEPROPERTY_DROPDOWN:
267 case BASEPROPERTY_SPIN:
268 case BASEPROPERTY_READONLY:
269 case BASEPROPERTY_VSCROLL:
270 case BASEPROPERTY_NUMSHOWTHOUSANDSEP:
271 case BASEPROPERTY_STRICTFORMAT:
272 case BASEPROPERTY_REPEAT:
273 case BASEPROPERTY_PAINTTRANSPARENT:
274 case BASEPROPERTY_DESKTOP_AS_PARENT:
275 case BASEPROPERTY_HARDLINEBREAKS:
276 case BASEPROPERTY_NOLABEL: aDefault <<= (sal_Bool) sal_False; break;
278 case BASEPROPERTY_MULTISELECTION_SIMPLEMODE:
279 case BASEPROPERTY_HIDEINACTIVESELECTION:
280 case BASEPROPERTY_ENFORCE_FORMAT:
281 case BASEPROPERTY_AUTOCOMPLETE:
282 case BASEPROPERTY_SCALEIMAGE:
283 case BASEPROPERTY_ENABLED:
284 case BASEPROPERTY_PRINTABLE:
285 case BASEPROPERTY_ENABLEVISIBLE:
286 case BASEPROPERTY_DECORATION: aDefault <<= (sal_Bool) sal_True; break;
288 case BASEPROPERTY_GROUPNAME:
289 case BASEPROPERTY_HELPTEXT:
290 case BASEPROPERTY_HELPURL:
291 case BASEPROPERTY_IMAGEURL:
292 case BASEPROPERTY_DIALOGSOURCEURL:
293 case BASEPROPERTY_EDITMASK:
294 case BASEPROPERTY_LITERALMASK:
295 case BASEPROPERTY_LABEL:
296 case BASEPROPERTY_TITLE:
297 case BASEPROPERTY_TEXT: aDefault <<= OUString(); break;
299 case BASEPROPERTY_WRITING_MODE:
300 case BASEPROPERTY_CONTEXT_WRITING_MODE:
301 aDefault <<= text::WritingMode2::CONTEXT;
302 break;
304 case BASEPROPERTY_STRINGITEMLIST:
306 ::com::sun::star::uno::Sequence< OUString> aStringSeq;
307 aDefault <<= aStringSeq;
310 break;
311 case BASEPROPERTY_SELECTEDITEMS:
313 ::com::sun::star::uno::Sequence<sal_Int16> aINT16Seq;
314 aDefault <<= aINT16Seq;
316 break;
317 case BASEPROPERTY_CURRENCYSYMBOL:
319 OUString sDefaultCurrency(
320 utl::ConfigManager::getDefaultCurrency() );
322 // extract the bank symbol
323 sal_Int32 nSepPos = sDefaultCurrency.indexOf( '-' );
324 OUString sBankSymbol;
325 if ( nSepPos >= 0 )
327 sBankSymbol = sDefaultCurrency.copy( 0, nSepPos );
328 sDefaultCurrency = sDefaultCurrency.copy( nSepPos + 1 );
331 // the remaining is the locale
332 LanguageTag aLanguageTag( sDefaultCurrency);
333 LocaleDataWrapper aLocaleInfo( m_xContext, aLanguageTag );
334 if ( sBankSymbol.isEmpty() )
335 sBankSymbol = aLocaleInfo.getCurrBankSymbol();
337 // look for the currency entry (for this language) which has the given bank symbol
338 Sequence< Currency2 > aAllCurrencies = aLocaleInfo.getAllCurrencies();
339 const Currency2* pAllCurrencies = aAllCurrencies.getConstArray();
340 const Currency2* pAllCurrenciesEnd = pAllCurrencies + aAllCurrencies.getLength();
342 OUString sCurrencySymbol = aLocaleInfo.getCurrSymbol();
343 if ( sBankSymbol.isEmpty() )
345 DBG_ASSERT( pAllCurrencies != pAllCurrenciesEnd, "UnoControlModel::ImplGetDefaultValue: no currencies at all!" );
346 if ( pAllCurrencies != pAllCurrenciesEnd )
348 sBankSymbol = pAllCurrencies->BankSymbol;
349 sCurrencySymbol = pAllCurrencies->Symbol;
353 if ( !sBankSymbol.isEmpty() )
355 bool bLegacy = false;
356 for ( ;pAllCurrencies != pAllCurrenciesEnd; ++pAllCurrencies )
357 if ( pAllCurrencies->BankSymbol == sBankSymbol )
359 sCurrencySymbol = pAllCurrencies->Symbol;
360 if ( pAllCurrencies->LegacyOnly )
361 bLegacy = true;
362 else
363 break;
365 DBG_ASSERT( bLegacy || pAllCurrencies != pAllCurrenciesEnd, "UnoControlModel::ImplGetDefaultValue: did not find the given bank symbol!" );
366 (void)bLegacy;
369 aDefault <<= sCurrencySymbol;
371 break;
373 default: OSL_FAIL( "ImplGetDefaultValue - unknown Property" );
377 return aDefault;
380 void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId, const ::com::sun::star::uno::Any& rDefault )
382 maData[ nPropId ] = rDefault;
385 void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId )
387 ImplRegisterProperty( nPropId, ImplGetDefaultValue( nPropId ) );
389 if ( nPropId == BASEPROPERTY_FONTDESCRIPTOR )
391 // some properties are not included in the FontDescriptor, but everytime
392 // when we have a FontDescriptor we want to have these properties too.
393 // => Easier to register the here, istead everywhere where I register the FontDescriptor...
395 ImplRegisterProperty( BASEPROPERTY_TEXTCOLOR );
396 ImplRegisterProperty( BASEPROPERTY_TEXTLINECOLOR );
397 ImplRegisterProperty( BASEPROPERTY_FONTRELIEF );
398 ImplRegisterProperty( BASEPROPERTY_FONTEMPHASISMARK );
402 void UnoControlModel::ImplRegisterProperties( const std::list< sal_uInt16 > &rIds )
404 std::list< sal_uInt16 >::const_iterator iter;
405 for( iter = rIds.begin(); iter != rIds.end(); ++iter)
407 if( !ImplHasProperty( *iter ) )
408 ImplRegisterProperty( *iter, ImplGetDefaultValue( *iter ) );
412 // ::com::sun::star::uno::XInterface
413 ::com::sun::star::uno::Any UnoControlModel::queryAggregation( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
415 Any aRet = UnoControlModel_Base::queryAggregation( rType );
416 if ( !aRet.hasValue() )
417 aRet = ::cppu::OPropertySetHelper::queryInterface( rType );
418 return aRet;
421 // ::com::sun::star::lang::XUnoTunnel
422 IMPL_XUNOTUNNEL_MINIMAL( UnoControlModel )
424 // XInterface
425 IMPLEMENT_FORWARD_REFCOUNT( UnoControlModel, UnoControlModel_Base )
427 // ::com::sun::star::lang::XTypeProvider
428 IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoControlModel, UnoControlModel_Base, ::cppu::OPropertySetHelper )
431 uno::Reference< util::XCloneable > UnoControlModel::createClone() throw(::com::sun::star::uno::RuntimeException)
433 UnoControlModel* pClone = Clone();
434 uno::Reference< util::XCloneable > xClone( (::cppu::OWeakObject*) pClone, uno::UNO_QUERY );
435 return xClone;
438 // ::com::sun::star::lang::XComponent
439 void UnoControlModel::dispose( ) throw(::com::sun::star::uno::RuntimeException)
441 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
443 ::com::sun::star::lang::EventObject aEvt;
444 aEvt.Source = (::com::sun::star::uno::XAggregation*)(::cppu::OWeakAggObject*)this;
445 maDisposeListeners.disposeAndClear( aEvt );
447 BrdcstHelper.aLC.disposeAndClear( aEvt );
449 // let the property set helper notify our property listeners
450 OPropertySetHelper::disposing();
453 void UnoControlModel::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
455 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
457 maDisposeListeners.addInterface( rxListener );
460 void UnoControlModel::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
462 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
464 maDisposeListeners.removeInterface( rxListener );
468 // ::com::sun::star::beans::XPropertyState
469 ::com::sun::star::beans::PropertyState UnoControlModel::getPropertyState( const OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
471 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
473 sal_uInt16 nPropId = GetPropertyId( PropertyName );
475 ::com::sun::star::uno::Any aValue = getPropertyValue( PropertyName );
476 ::com::sun::star::uno::Any aDefault = ImplGetDefaultValue( nPropId );
478 return CompareProperties( aValue, aDefault ) ? ::com::sun::star::beans::PropertyState_DEFAULT_VALUE : ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
481 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > UnoControlModel::getPropertyStates( const ::com::sun::star::uno::Sequence< OUString >& PropertyNames ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
483 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
485 sal_uInt32 nNames = PropertyNames.getLength();
486 const OUString* pNames = PropertyNames.getConstArray();
488 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > aStates( nNames );
489 ::com::sun::star::beans::PropertyState* pStates = aStates.getArray();
491 for ( sal_uInt32 n = 0; n < nNames; n++ )
492 pStates[n] = getPropertyState( pNames[n] );
494 return aStates;
497 void UnoControlModel::setPropertyToDefault( const OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
499 Any aDefaultValue;
501 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
502 aDefaultValue = ImplGetDefaultValue( GetPropertyId( PropertyName ) );
504 setPropertyValue( PropertyName, aDefaultValue );
507 ::com::sun::star::uno::Any UnoControlModel::getPropertyDefault( const OUString& rPropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
509 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
511 return ImplGetDefaultValue( GetPropertyId( rPropertyName ) );
515 // ::com::sun::star::io::XPersistObjec
516 OUString UnoControlModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException)
518 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
520 OSL_FAIL( "ServiceName von UnoControlModel ?!" );
521 return OUString();
524 void UnoControlModel::write( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream >& OutStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
526 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
528 ::com::sun::star::uno::Reference< ::com::sun::star::io::XMarkableStream > xMark( OutStream, ::com::sun::star::uno::UNO_QUERY );
529 DBG_ASSERT( xMark.is(), "write: no ::com::sun::star::io::XMarkableStream!" );
531 OutStream->writeShort( UNOCONTROL_STREAMVERSION );
533 std::set<sal_uInt16> aProps;
535 for (ImplPropertyTable::const_iterator it = maData.begin(); it != maData.end(); ++it )
537 if ( ( ( GetPropertyAttribs( it->first ) & ::com::sun::star::beans::PropertyAttribute::TRANSIENT ) == 0 )
538 && ( getPropertyState( GetPropertyName( it->first ) ) != ::com::sun::star::beans::PropertyState_DEFAULT_VALUE ) )
540 aProps.insert( it->first );
544 sal_uInt32 nProps = aProps.size();
546 // Save FontProperty always in the old format (due to missing distinction
547 // between 5.0 and 5.1)
548 OutStream->writeLong( (long) ( aProps.find( BASEPROPERTY_FONTDESCRIPTOR ) != aProps.end() ) ? ( nProps + 3 ) : nProps );
549 for ( std::set<sal_uInt16>::const_iterator it = aProps.begin(); it != aProps.end(); ++it )
551 sal_Int32 nPropDataBeginMark = xMark->createMark();
552 OutStream->writeLong( 0L ); // DataLen
554 const ::com::sun::star::uno::Any* pProp = &(maData[*it]);
555 OutStream->writeShort( *it );
557 sal_Bool bVoid = pProp->getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID;
559 OutStream->writeBoolean( bVoid );
561 if ( !bVoid )
563 const ::com::sun::star::uno::Any& rValue = *pProp;
564 const ::com::sun::star::uno::Type& rType = rValue.getValueType();
566 if ( rType == ::getBooleanCppuType() )
568 sal_Bool b = false;
569 rValue >>= b;
570 OutStream->writeBoolean( b );
572 else if ( rType == ::getCppuType((const OUString*)0) )
574 OUString aUString;
575 rValue >>= aUString;
576 OutStream->writeUTF( aUString );
578 else if ( rType == ::getCppuType((const sal_uInt16*)0) )
580 sal_uInt16 n = 0;
581 rValue >>= n;
582 OutStream->writeShort( n );
584 else if ( rType == ::getCppuType((const sal_Int16*)0) )
586 sal_Int16 n = 0;
587 rValue >>= n;
588 OutStream->writeShort( n );
590 else if ( rType == ::getCppuType((const sal_uInt32*)0) )
592 sal_uInt32 n = 0;
593 rValue >>= n;
594 OutStream->writeLong( n );
596 else if ( rType == ::getCppuType((const sal_Int32*)0) )
598 sal_Int32 n = 0;
599 rValue >>= n;
600 OutStream->writeLong( n );
602 else if ( rType == ::getCppuType((const double*)0) )
604 double n = 0;
605 rValue >>= n;
606 OutStream->writeDouble( n );
608 else if ( rType == ::getCppuType((const ::com::sun::star::awt::FontDescriptor*)0) )
610 ::com::sun::star::awt::FontDescriptor aFD;
611 rValue >>= aFD;
612 OutStream->writeUTF( aFD.Name );
613 OutStream->writeShort( aFD.Height );
614 OutStream->writeShort( aFD.Width );
615 OutStream->writeUTF( aFD.StyleName );
616 OutStream->writeShort( aFD.Family );
617 OutStream->writeShort( aFD.CharSet );
618 OutStream->writeShort( aFD.Pitch );
619 OutStream->writeDouble( aFD.CharacterWidth );
620 OutStream->writeDouble( aFD.Weight );
621 OutStream->writeShort(
622 sal::static_int_cast< sal_Int16 >(aFD.Slant) );
623 OutStream->writeShort( aFD.Underline );
624 OutStream->writeShort( aFD.Strikeout );
625 OutStream->writeDouble( aFD.Orientation );
626 OutStream->writeBoolean( aFD.Kerning );
627 OutStream->writeBoolean( aFD.WordLineMode );
628 OutStream->writeShort( aFD.Type );
630 else if ( rType == cppu::UnoType<css::util::Date>::get() )
632 css::util::Date d;
633 rValue >>= d;
634 OutStream->writeLong(d.Day + 100 * d.Month + 10000 * d.Year);
635 // YYYYMMDD
637 else if ( rType == cppu::UnoType<css::util::Time>::get() )
639 css::util::Time t;
640 rValue >>= t;
641 OutStream->writeLong(
642 t.NanoSeconds / 1000000 + 100 * t.Seconds
643 + 10000 * t.Minutes + 1000000 * t.Hours); // HHMMSShh
645 else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence< OUString>*)0 ) )
647 ::com::sun::star::uno::Sequence< OUString> aSeq;
648 rValue >>= aSeq;
649 long nEntries = aSeq.getLength();
650 OutStream->writeLong( nEntries );
651 for ( long n = 0; n < nEntries; n++ )
652 OutStream->writeUTF( aSeq.getConstArray()[n] );
654 else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_uInt16>*)0 ) )
656 ::com::sun::star::uno::Sequence<sal_uInt16> aSeq;
657 rValue >>= aSeq;
658 long nEntries = aSeq.getLength();
659 OutStream->writeLong( nEntries );
660 for ( long n = 0; n < nEntries; n++ )
661 OutStream->writeShort( aSeq.getConstArray()[n] );
663 else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_Int16>*)0 ) )
665 ::com::sun::star::uno::Sequence<sal_Int16> aSeq;
666 rValue >>= aSeq;
667 long nEntries = aSeq.getLength();
668 OutStream->writeLong( nEntries );
669 for ( long n = 0; n < nEntries; n++ )
670 OutStream->writeShort( aSeq.getConstArray()[n] );
672 else if ( rType.getTypeClass() == TypeClass_ENUM )
674 sal_Int32 nAsInt = 0;
675 ::cppu::enum2int( nAsInt, rValue );
676 OutStream->writeLong( nAsInt );
678 #if OSL_DEBUG_LEVEL > 0
679 else
681 OString sMessage( "UnoControlModel::write: don't know how to handle a property of type '" );
682 OUString sTypeName( rType.getTypeName() );
683 sMessage += OString( sTypeName.getStr(), sTypeName.getLength(), RTL_TEXTENCODING_ASCII_US );
684 sMessage += "'.\n(Currently handling property '";
685 OUString sPropertyName( GetPropertyName( *it ) );
686 sMessage += OString( sPropertyName.getStr(), sPropertyName.getLength(), osl_getThreadTextEncoding() );
687 sMessage += "'.)";
688 OSL_FAIL( sMessage.getStr() );
690 #endif
693 sal_Int32 nPropDataLen = xMark->offsetToMark( nPropDataBeginMark );
694 xMark->jumpToMark( nPropDataBeginMark );
695 OutStream->writeLong( nPropDataLen );
696 xMark->jumpToFurthest();
697 xMark->deleteMark(nPropDataBeginMark);
700 if ( aProps.find( BASEPROPERTY_FONTDESCRIPTOR ) != aProps.end() )
702 const ::com::sun::star::uno::Any* pProp = &maData[ BASEPROPERTY_FONTDESCRIPTOR ];
703 // Until 5.0 export arrives, write old format..
704 ::com::sun::star::awt::FontDescriptor aFD;
705 (*pProp) >>= aFD;
707 for ( sal_uInt16 n = BASEPROPERTY_FONT_TYPE; n <= BASEPROPERTY_FONT_ATTRIBS; n++ )
709 sal_Int32 nPropDataBeginMark = xMark->createMark();
710 OutStream->writeLong( 0L ); // DataLen
711 OutStream->writeShort( n ); // PropId
712 OutStream->writeBoolean( sal_False ); // Void
714 if ( n == BASEPROPERTY_FONT_TYPE )
716 OutStream->writeUTF( aFD.Name );
717 OutStream->writeUTF( aFD.StyleName );
718 OutStream->writeShort( aFD.Family );
719 OutStream->writeShort( aFD.CharSet );
720 OutStream->writeShort( aFD.Pitch );
722 else if ( n == BASEPROPERTY_FONT_SIZE )
724 OutStream->writeLong( aFD.Width );
725 OutStream->writeLong( aFD.Height );
726 OutStream->writeShort(
727 sal::static_int_cast< sal_Int16 >(
728 VCLUnoHelper::ConvertFontWidth( aFD.CharacterWidth )) );
730 else if ( n == BASEPROPERTY_FONT_ATTRIBS )
732 OutStream->writeShort(
733 sal::static_int_cast< sal_Int16 >(
734 VCLUnoHelper::ConvertFontWeight( aFD.Weight )) );
735 OutStream->writeShort(
736 sal::static_int_cast< sal_Int16 >(aFD.Slant) );
737 OutStream->writeShort( aFD.Underline );
738 OutStream->writeShort( aFD.Strikeout );
739 OutStream->writeShort( (short)(aFD.Orientation * 10) );
740 OutStream->writeBoolean( aFD.Kerning );
741 OutStream->writeBoolean( aFD.WordLineMode );
743 else
745 OSL_FAIL( "Property?!" );
748 sal_Int32 nPropDataLen = xMark->offsetToMark( nPropDataBeginMark );
749 xMark->jumpToMark( nPropDataBeginMark );
750 OutStream->writeLong( nPropDataLen );
751 xMark->jumpToFurthest();
752 xMark->deleteMark(nPropDataBeginMark);
757 void UnoControlModel::read( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream >& InStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
759 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
761 ::com::sun::star::uno::Reference< ::com::sun::star::io::XMarkableStream > xMark( InStream, ::com::sun::star::uno::UNO_QUERY );
762 DBG_ASSERT( xMark.is(), "read: no ::com::sun::star::io::XMarkableStream!" );
764 short nVersion = InStream->readShort();
765 sal_uInt32 nProps = (sal_uInt32)InStream->readLong();
766 ::com::sun::star::uno::Sequence< OUString> aProps( nProps );
767 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> aValues( nProps );
768 sal_Bool bInvalidEntries = sal_False;
770 // Unfortunately, there's no mark for the whole block, thus only properties may be changed.
771 // No data for the model may be added following the properties
773 // Used for import of old parts in ::com::sun::star::awt::FontDescriptor
774 ::com::sun::star::awt::FontDescriptor* pFD = NULL;
776 sal_uInt32 i;
777 for ( i = 0; i < nProps; i++ )
779 sal_Int32 nPropDataBeginMark = xMark->createMark();
780 sal_Int32 nPropDataLen = InStream->readLong();
782 sal_uInt16 nPropId = (sal_uInt16)InStream->readShort();
784 ::com::sun::star::uno::Any aValue;
785 sal_Bool bIsVoid = InStream->readBoolean();
786 if ( !bIsVoid )
788 if ( maData.find( nPropId ) != maData.end() )
790 const ::com::sun::star::uno::Type* pType = GetPropertyType( nPropId );
791 if ( *pType == ::getBooleanCppuType() )
793 sal_Bool b = InStream->readBoolean();
794 aValue <<= b;
796 else if ( *pType == ::getCppuType((const OUString*)0) )
798 OUString aUTF = InStream->readUTF();
799 aValue <<= aUTF;
801 else if ( *pType == ::getCppuType((const sal_uInt16*)0) )
803 sal_uInt16 n = InStream->readShort();
804 aValue <<= n;
806 else if ( *pType == ::getCppuType((const sal_Int16*)0) )
808 sal_Int16 n = InStream->readShort();
809 aValue <<= n;
811 else if ( *pType == ::getCppuType((const sal_uInt32*)0) )
813 sal_uInt32 n = InStream->readLong();
814 aValue <<= n;
816 else if ( *pType == ::getCppuType((const sal_Int32*)0) )
818 sal_Int32 n = InStream->readLong();
819 aValue <<= n;
821 else if ( *pType == ::getCppuType((const double*)0) )
823 double n = InStream->readDouble();
824 aValue <<= n;
826 else if ( *pType == ::getCppuType((const ::com::sun::star::awt::FontDescriptor*)0) )
828 ::com::sun::star::awt::FontDescriptor aFD;
829 aFD.Name = InStream->readUTF();
830 aFD.Height = InStream->readShort();
831 aFD.Width = InStream->readShort();
832 aFD.StyleName = InStream->readUTF();
833 aFD.Family = InStream->readShort();
834 aFD.CharSet = InStream->readShort();
835 aFD.Pitch = InStream->readShort();
836 aFD.CharacterWidth = (float)InStream->readDouble();
837 aFD.Weight = (float)InStream->readDouble();
838 aFD.Slant = (::com::sun::star::awt::FontSlant)InStream->readShort();
839 aFD.Underline = InStream->readShort();
840 aFD.Strikeout = InStream->readShort();
841 aFD.Orientation = (float)InStream->readDouble();
842 aFD.Kerning = InStream->readBoolean();
843 aFD.WordLineMode = InStream->readBoolean();
844 aFD.Type = InStream->readShort();
845 aValue <<= aFD;
847 else if ( *pType == cppu::UnoType<css::util::Date>::get() )
849 sal_Int32 n = InStream->readLong(); // YYYYMMDD
850 aValue <<= css::util::Date(
851 n % 100, (n / 100) % 100, n / 10000);
853 else if ( *pType == cppu::UnoType<css::util::Time>::get() )
855 sal_Int32 n = InStream->readLong(); // HHMMSShh
856 aValue <<= css::util::Time(
857 (n % 100) * 1000000, (n / 100) % 100, (n / 10000) % 100,
858 n / 1000000, false);
860 else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence< OUString>*)0 ) )
862 long nEntries = InStream->readLong();
863 ::com::sun::star::uno::Sequence< OUString> aSeq( nEntries );
864 for ( long n = 0; n < nEntries; n++ )
865 aSeq.getArray()[n] = InStream->readUTF();
866 aValue <<= aSeq;
869 else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_uInt16>*)0 ) )
872 long nEntries = InStream->readLong();
873 ::com::sun::star::uno::Sequence<sal_uInt16> aSeq( nEntries );
874 for ( long n = 0; n < nEntries; n++ )
875 aSeq.getArray()[n] = (sal_uInt16)InStream->readShort();
876 aValue <<= aSeq;
878 else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_Int16>*)0 ) )
880 long nEntries = InStream->readLong();
881 ::com::sun::star::uno::Sequence<sal_Int16> aSeq( nEntries );
882 for ( long n = 0; n < nEntries; n++ )
883 aSeq.getArray()[n] = (sal_Int16)InStream->readShort();
884 aValue <<= aSeq;
886 else if ( pType->getTypeClass() == TypeClass_ENUM )
888 sal_Int32 nAsInt = InStream->readLong();
889 aValue = ::cppu::int2enum( nAsInt, *pType );
891 else
893 OString sMessage( "UnoControlModel::read: don't know how to handle a property of type '" );
894 OUString sTypeName( pType->getTypeName() );
895 sMessage += OString( sTypeName.getStr(), sTypeName.getLength(), RTL_TEXTENCODING_ASCII_US );
896 sMessage += "'.\n(Currently handling property '";
897 OUString sPropertyName( GetPropertyName( nPropId ) );
898 sMessage += OString( sPropertyName.getStr(), sPropertyName.getLength(), osl_getThreadTextEncoding() );
899 sMessage += "'.)";
900 OSL_FAIL( sMessage.getStr() );
903 else
905 // Old trash from 5.0
906 if ( nPropId == BASEPROPERTY_FONT_TYPE )
908 // Redundant information for older versions
909 // is skipped by MarkableStream
910 if ( nVersion < 2 )
912 if ( !pFD )
914 pFD = new ::com::sun::star::awt::FontDescriptor;
915 if ( maData.find( BASEPROPERTY_FONTDESCRIPTOR ) != maData.end() ) // wegen den Defaults...
916 maData[ BASEPROPERTY_FONTDESCRIPTOR ] >>= *pFD;
918 pFD->Name = InStream->readUTF();
919 pFD->StyleName = InStream->readUTF();
920 pFD->Family = InStream->readShort();
921 pFD->CharSet = InStream->readShort();
922 pFD->Pitch = InStream->readShort();
925 else if ( nPropId == BASEPROPERTY_FONT_SIZE )
927 if ( nVersion < 2 )
929 if ( !pFD )
931 pFD = new ::com::sun::star::awt::FontDescriptor;
932 if ( maData.find(BASEPROPERTY_FONTDESCRIPTOR) != maData.end() ) // due to defaults...
933 maData[BASEPROPERTY_FONTDESCRIPTOR] >>= *pFD;
935 pFD->Width = (sal_Int16)InStream->readLong();
936 pFD->Height = (sal_Int16)InStream->readLong();
937 InStream->readShort(); // ignore ::com::sun::star::awt::FontWidth - it was
938 // misspelled and is no longer needed
939 pFD->CharacterWidth = ::com::sun::star::awt::FontWidth::DONTKNOW;
942 else if ( nPropId == BASEPROPERTY_FONT_ATTRIBS )
944 if ( nVersion < 2 )
946 if ( !pFD )
948 pFD = new ::com::sun::star::awt::FontDescriptor;
949 if ( maData.find(BASEPROPERTY_FONTDESCRIPTOR) != maData.end() ) // due to defaults...
950 maData[BASEPROPERTY_FONTDESCRIPTOR] >>= *pFD;
952 pFD->Weight = VCLUnoHelper::ConvertFontWeight( (FontWeight) InStream->readShort() );
953 pFD->Slant = (::com::sun::star::awt::FontSlant)InStream->readShort();
954 pFD->Underline = InStream->readShort();
955 pFD->Strikeout = InStream->readShort();
956 pFD->Orientation = ( (float)(double)InStream->readShort() ) / 10;
957 pFD->Kerning = InStream->readBoolean();
958 pFD->WordLineMode = InStream->readBoolean();
961 else
963 OSL_FAIL( "read: unknown Property!" );
967 else // bVoid
969 if ( nPropId == BASEPROPERTY_FONTDESCRIPTOR )
971 EmptyFontDescriptor aFD;
972 aValue <<= aFD;
976 if ( maData.find( nPropId ) != maData.end() )
978 aProps.getArray()[i] = GetPropertyName( nPropId );
979 aValues.getArray()[i] = aValue;
981 else
983 bInvalidEntries = sal_True;
986 // Skip rest of input if there is more data in stream than this version can handle
987 xMark->jumpToMark( nPropDataBeginMark );
988 InStream->skipBytes( nPropDataLen );
989 xMark->deleteMark(nPropDataBeginMark);
991 if ( bInvalidEntries )
993 for ( i = 0; i < (sal_uInt32)aProps.getLength(); i++ )
995 if ( aProps.getConstArray()[i].isEmpty() )
997 ::comphelper::removeElementAt( aProps, i );
998 ::comphelper::removeElementAt( aValues, i );
999 i--;
1006 setPropertyValues( aProps, aValues );
1008 catch ( const Exception& )
1010 DBG_UNHANDLED_EXCEPTION();
1013 if ( pFD )
1015 ::com::sun::star::uno::Any aValue;
1016 aValue <<= *pFD;
1017 setPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR ), aValue );
1018 delete pFD;
1023 // ::com::sun::star::lang::XServiceInfo
1024 OUString UnoControlModel::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException)
1026 OSL_FAIL( "This method should be overloaded!" );
1027 return OUString();
1031 sal_Bool UnoControlModel::supportsService( const OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException)
1033 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1035 ::com::sun::star::uno::Sequence< OUString > aSNL = getSupportedServiceNames();
1036 const OUString * pArray = aSNL.getConstArray();
1037 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
1038 if( pArray[i] == rServiceName )
1039 return sal_True;
1040 return sal_False;
1043 ::com::sun::star::uno::Sequence< OUString > UnoControlModel::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
1045 OUString sName( "com.sun.star.awt.UnoControlModel" );
1046 return Sequence< OUString >( &sName, 1 );
1049 // ------------------------------------------------------------------
1050 template <class TYPE>
1051 sal_Bool convertType(Any& _rConvertedValue, const Any& _rNewValueTest, const TYPE* /* _pTypeDisambiguation */)
1053 TYPE tValue;
1054 if (_rNewValueTest >>= tValue)
1056 _rConvertedValue <<= tValue;
1057 return sal_True;
1061 // ..................................................................
1062 sal_Bool UnoControlModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nPropId, const Any& rValue ) throw (IllegalArgumentException)
1064 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1066 sal_Bool bVoid = rValue.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID;
1067 if ( bVoid )
1069 rConvertedValue.clear();
1071 else
1073 const ::com::sun::star::uno::Type* pDestType = GetPropertyType( (sal_uInt16)nPropId );
1074 if ( pDestType->getTypeClass() == TypeClass_ANY )
1076 rConvertedValue = rValue;
1078 else
1080 if ( pDestType->equals( rValue.getValueType() ) )
1082 rConvertedValue = rValue;
1084 else
1086 sal_Bool bConverted = sal_False;
1087 // 13.03.2001 - 84923 - frank.schoenheit@germany.sun.com
1089 switch (pDestType->getTypeClass())
1091 case TypeClass_DOUBLE:
1093 // try as double
1094 double nAsDouble = 0;
1095 bConverted = ( rValue >>= nAsDouble );
1096 if ( bConverted )
1097 rConvertedValue <<= nAsDouble;
1098 else
1099 { // try as integer
1100 sal_Int32 nAsInteger = 0;
1101 bConverted = ( rValue >>= nAsInteger );
1102 if ( bConverted )
1103 rConvertedValue <<= (double)nAsInteger;
1106 break;
1107 case TypeClass_SHORT:
1109 sal_Int16 n;
1110 bConverted = ( rValue >>= n );
1111 if ( bConverted )
1112 rConvertedValue <<= n;
1114 break;
1115 case TypeClass_UNSIGNED_SHORT:
1117 sal_uInt16 n;
1118 bConverted = ( rValue >>= n );
1119 if ( bConverted )
1120 rConvertedValue <<= n;
1122 break;
1123 case TypeClass_LONG:
1125 sal_Int32 n;
1126 bConverted = ( rValue >>= n );
1127 if ( bConverted )
1128 rConvertedValue <<= n;
1130 break;
1131 case TypeClass_UNSIGNED_LONG:
1133 sal_uInt32 n;
1134 bConverted = ( rValue >>= n );
1135 if ( bConverted )
1136 rConvertedValue <<= n;
1138 break;
1139 case TypeClass_INTERFACE:
1141 if ( rValue.getValueType().getTypeClass() == TypeClass_INTERFACE )
1143 Reference< XInterface > xPure( rValue, UNO_QUERY );
1144 if ( xPure.is() )
1145 rConvertedValue = xPure->queryInterface( *pDestType );
1146 else
1147 rConvertedValue.setValue( NULL, *pDestType );
1148 bConverted = sal_True;
1151 break;
1152 case TypeClass_ENUM:
1154 sal_Int32 nValue = 0;
1155 bConverted = ( rValue >>= nValue );
1156 if ( bConverted )
1157 rConvertedValue = ::cppu::int2enum( nValue, *pDestType );
1159 break;
1160 default: ; // avoid compiler warning
1163 if (!bConverted)
1165 OUStringBuffer aErrorMessage;
1166 aErrorMessage.appendAscii( "Unable to convert the given value for the property " );
1167 aErrorMessage.append ( GetPropertyName( (sal_uInt16)nPropId ) );
1168 aErrorMessage.appendAscii( ".\n" );
1169 aErrorMessage.appendAscii( "Expected type: " );
1170 aErrorMessage.append ( pDestType->getTypeName() );
1171 aErrorMessage.appendAscii( "\n" );
1172 aErrorMessage.appendAscii( "Found type: " );
1173 aErrorMessage.append ( rValue.getValueType().getTypeName() );
1174 throw ::com::sun::star::lang::IllegalArgumentException(
1175 aErrorMessage.makeStringAndClear(),
1176 static_cast< ::com::sun::star::beans::XPropertySet* >(this),
1183 // the current value
1184 getFastPropertyValue( rOldValue, nPropId );
1185 return !CompareProperties( rConvertedValue, rOldValue );
1188 void UnoControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception)
1190 // Missing: the fake solo properties of the FontDescriptor
1192 ImplPropertyTable::const_iterator it = maData.find( nPropId );
1193 const ::com::sun::star::uno::Any* pProp = it == maData.end() ? NULL : &(it->second);
1194 ENSURE_OR_RETURN_VOID( pProp, "UnoControlModel::setFastPropertyValue_NoBroadcast: invalid property id!" );
1196 DBG_ASSERT( ( rValue.getValueType().getTypeClass() != ::com::sun::star::uno::TypeClass_VOID ) || ( GetPropertyAttribs( (sal_uInt16)nPropId ) & ::com::sun::star::beans::PropertyAttribute::MAYBEVOID ), "Property darf nicht VOID sein!" );
1197 maData[ nPropId ] = rValue;
1200 void UnoControlModel::getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nPropId ) const
1202 ::osl::Guard< ::osl::Mutex > aGuard( ((UnoControlModel*)this)->GetMutex() );
1204 ImplPropertyTable::const_iterator it = maData.find( nPropId );
1205 const ::com::sun::star::uno::Any* pProp = it == maData.end() ? NULL : &(it->second);
1207 if ( pProp )
1208 rValue = *pProp;
1209 else if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1211 pProp = &( maData.find( BASEPROPERTY_FONTDESCRIPTOR )->second );
1212 ::com::sun::star::awt::FontDescriptor aFD;
1213 (*pProp) >>= aFD;
1214 switch ( nPropId )
1216 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: rValue <<= aFD.Name;
1217 break;
1218 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: rValue <<= aFD.StyleName;
1219 break;
1220 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: rValue <<= aFD.Family;
1221 break;
1222 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: rValue <<= aFD.CharSet;
1223 break;
1224 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: rValue <<= (float)aFD.Height;
1225 break;
1226 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: rValue <<= aFD.Weight;
1227 break;
1228 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: rValue <<= (sal_Int16)aFD.Slant;
1229 break;
1230 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: rValue <<= aFD.Underline;
1231 break;
1232 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: rValue <<= aFD.Strikeout;
1233 break;
1234 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: rValue <<= aFD.Width;
1235 break;
1236 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: rValue <<= aFD.Pitch;
1237 break;
1238 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: rValue <<= aFD.CharacterWidth;
1239 break;
1240 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: rValue <<= aFD.Orientation;
1241 break;
1242 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: rValue <<= aFD.Kerning;
1243 break;
1244 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: rValue <<= aFD.WordLineMode;
1245 break;
1246 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: rValue <<= aFD.Type;
1247 break;
1248 default: OSL_FAIL( "FontProperty?!" );
1251 else
1253 OSL_FAIL( "getFastPropertyValue - invalid Property!" );
1257 // ::com::sun::star::beans::XPropertySet
1258 void UnoControlModel::setPropertyValue( const OUString& rPropertyName, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1260 sal_Int32 nPropId = 0;
1262 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1263 nPropId = (sal_Int32) GetPropertyId( rPropertyName );
1264 DBG_ASSERT( nPropId, "Invalid ID in UnoControlModel::setPropertyValue" );
1266 if( nPropId )
1267 setFastPropertyValue( nPropId, rValue );
1268 else
1269 throw ::com::sun::star::beans::UnknownPropertyException();
1272 // ::com::sun::star::beans::XFastPropertySet
1273 void UnoControlModel::setFastPropertyValue( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1275 if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1277 ::osl::ClearableMutexGuard aGuard( GetMutex() );
1279 Any aOldSingleValue;
1280 getFastPropertyValue( aOldSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START );
1282 ::com::sun::star::uno::Any* pProp = &maData[ BASEPROPERTY_FONTDESCRIPTOR ];
1283 FontDescriptor aOldFontDescriptor;
1284 (*pProp) >>= aOldFontDescriptor;
1286 FontDescriptor aNewFontDescriptor( aOldFontDescriptor );
1287 lcl_ImplMergeFontProperty( aNewFontDescriptor, (sal_uInt16)nPropId, rValue );
1289 Any aNewValue;
1290 aNewValue <<= aNewFontDescriptor;
1291 sal_Int32 nDescriptorId( BASEPROPERTY_FONTDESCRIPTOR );
1292 nDescriptorId = BASEPROPERTY_FONTDESCRIPTOR;
1294 // also, we need fire a propertyChange event for the single property, since with
1295 // the above line, only an event for the FontDescriptor property will be fired
1296 Any aNewSingleValue;
1297 getFastPropertyValue( aNewSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START );
1299 aGuard.clear();
1300 setFastPropertyValues( 1, &nDescriptorId, &aNewValue, 1 );
1301 fire( &nPropId, &aNewSingleValue, &aOldSingleValue, 1, sal_False );
1303 else
1304 setFastPropertyValues( 1, &nPropId, &rValue, 1 );
1307 // ::com::sun::star::beans::XMultiPropertySet
1308 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > UnoControlModel::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
1310 OSL_FAIL( "UnoControlModel::getPropertySetInfo() not possible!" );
1311 return ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >();
1314 void UnoControlModel::setPropertyValues( const ::com::sun::star::uno::Sequence< OUString >& rPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Values ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1316 ::osl::ClearableMutexGuard aGuard( GetMutex() );
1318 sal_Int32 nProps = rPropertyNames.getLength();
1320 // sal_Int32* pHandles = new sal_Int32[nProps];
1321 // don't do this - it leaks in case of an exception
1322 Sequence< sal_Int32 > aHandles( nProps );
1323 sal_Int32* pHandles = aHandles.getArray();
1325 // may need to change the order in the sequence, for this we need a non-const value sequence
1326 uno::Sequence< uno::Any > aValues( Values );
1327 uno::Any* pValues = aValues.getArray();
1329 sal_Int32 nValidHandles = getInfoHelper().fillHandles( pHandles, rPropertyNames );
1331 if ( nValidHandles )
1333 // if somebody sets properties which are single aspects of a font descriptor,
1334 // remove them, and build a font descriptor instead
1335 ::std::auto_ptr< awt::FontDescriptor > pFD;
1336 for ( sal_uInt16 n = 0; n < nProps; ++n )
1338 if ( ( pHandles[n] >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( pHandles[n] <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1340 if ( !pFD.get() )
1342 ::com::sun::star::uno::Any* pProp = &maData[ BASEPROPERTY_FONTDESCRIPTOR ];
1343 pFD.reset( new awt::FontDescriptor );
1344 (*pProp) >>= *pFD;
1346 lcl_ImplMergeFontProperty( *pFD, (sal_uInt16)pHandles[n], pValues[n] );
1347 pHandles[n] = -1;
1348 nValidHandles--;
1352 if ( nValidHandles )
1354 ImplNormalizePropertySequence( nProps, pHandles, pValues, &nValidHandles );
1355 aGuard.clear();
1356 // clear our guard before calling into setFastPropertyValues - this method
1357 // will implicitly call property listeners, and this should not happen with
1358 // our mutex locked
1359 // #i23451#
1360 setFastPropertyValues( nProps, pHandles, pValues, nValidHandles );
1362 else
1363 aGuard.clear();
1364 // same as a few lines above
1366 // Don't merge FD property into array, as it is sorted
1367 if ( pFD.get() )
1369 ::com::sun::star::uno::Any aValue;
1370 aValue <<= *pFD;
1371 sal_Int32 nHandle = BASEPROPERTY_FONTDESCRIPTOR;
1372 setFastPropertyValues( 1, &nHandle, &aValue, 1 );
1379 void UnoControlModel::ImplNormalizePropertySequence( const sal_Int32, sal_Int32*,
1380 uno::Any*, sal_Int32* ) const SAL_THROW(())
1382 // nothing to do here
1385 void UnoControlModel::ImplEnsureHandleOrder( const sal_Int32 _nCount, sal_Int32* _pHandles,
1386 uno::Any* _pValues, sal_Int32 _nFirstHandle, sal_Int32 _nSecondHandle ) const
1388 for ( sal_Int32 i=0; i < _nCount; ++_pHandles, ++_pValues, ++i )
1390 if ( _nSecondHandle == *_pHandles )
1392 sal_Int32* pLaterHandles = _pHandles + 1;
1393 uno::Any* pLaterValues = _pValues + 1;
1394 for ( sal_Int32 j = i + 1; j < _nCount; ++j, ++pLaterHandles, ++pLaterValues )
1396 if ( _nFirstHandle == *pLaterHandles )
1398 // indeed it is -> exchange the both places in the sequences
1399 sal_Int32 nHandle( *_pHandles );
1400 *_pHandles = *pLaterHandles;
1401 *pLaterHandles = nHandle;
1403 uno::Any aValue( *_pValues );
1404 *_pValues = *pLaterValues;
1405 *pLaterValues = aValue;
1407 break;
1408 // this will leave the inner loop, and continue with the outer loop.
1409 // Note that this means we will encounter the _nSecondHandle handle, again, once we reached
1410 // (in the outer loop) the place where we just put it.
1417 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */