Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / toolkit / source / controls / unocontrolmodel.cxx
blob4bff901525830ed567269c35bf6045dc1246bfe4
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< XMultiServiceFactory >& i_factory )
116 :UnoControlModel_Base()
117 ,MutexAndBroadcastHelper()
118 ,OPropertySetHelper( BrdcstHelper )
119 ,maDisposeListeners( *this )
120 ,maContext( i_factory )
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 , maContext( rModel.maContext )
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 <<= (sal_Int32) Date( 31, 12, 2200 ).GetDate(); break;
236 case BASEPROPERTY_DATEMIN: aDefault <<= (sal_Int32) Date( 1, 1, 1900 ).GetDate(); break;
237 case BASEPROPERTY_TIMEMAX: aDefault <<= (sal_Int32) Time( 23, 59 ).GetTime(); break;
238 case BASEPROPERTY_TIMEMIN: aDefault <<= (sal_Int32) 0; 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 <<= ::rtl::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< ::rtl::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 rtl::OUString sDefaultCurrency(
320 utl::ConfigManager::getDefaultCurrency() );
322 // extract the bank symbol
323 sal_Int32 nSepPos = sDefaultCurrency.indexOf( '-' );
324 ::rtl::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( maContext.getUNOContext(), 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 ::rtl::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 ::rtl::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< ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::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 ::rtl::OUString UnoControlModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException)
518 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
520 OSL_FAIL( "ServiceName von UnoControlModel ?!" );
521 return ::rtl::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 ::rtl::OUString*)0) )
574 ::rtl::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 == ::getCppuType((const ::com::sun::star::uno::Sequence< ::rtl::OUString>*)0 ) )
632 ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq;
633 rValue >>= aSeq;
634 long nEntries = aSeq.getLength();
635 OutStream->writeLong( nEntries );
636 for ( long n = 0; n < nEntries; n++ )
637 OutStream->writeUTF( aSeq.getConstArray()[n] );
639 else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_uInt16>*)0 ) )
641 ::com::sun::star::uno::Sequence<sal_uInt16> aSeq;
642 rValue >>= aSeq;
643 long nEntries = aSeq.getLength();
644 OutStream->writeLong( nEntries );
645 for ( long n = 0; n < nEntries; n++ )
646 OutStream->writeShort( aSeq.getConstArray()[n] );
648 else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_Int16>*)0 ) )
650 ::com::sun::star::uno::Sequence<sal_Int16> aSeq;
651 rValue >>= aSeq;
652 long nEntries = aSeq.getLength();
653 OutStream->writeLong( nEntries );
654 for ( long n = 0; n < nEntries; n++ )
655 OutStream->writeShort( aSeq.getConstArray()[n] );
657 else if ( rType.getTypeClass() == TypeClass_ENUM )
659 sal_Int32 nAsInt = 0;
660 ::cppu::enum2int( nAsInt, rValue );
661 OutStream->writeLong( nAsInt );
663 #if OSL_DEBUG_LEVEL > 0
664 else
666 ::rtl::OString sMessage( "UnoControlModel::write: don't know how to handle a property of type '" );
667 ::rtl::OUString sTypeName( rType.getTypeName() );
668 sMessage += ::rtl::OString( sTypeName.getStr(), sTypeName.getLength(), RTL_TEXTENCODING_ASCII_US );
669 sMessage += "'.\n(Currently handling property '";
670 ::rtl::OUString sPropertyName( GetPropertyName( *it ) );
671 sMessage += ::rtl::OString( sPropertyName.getStr(), sPropertyName.getLength(), osl_getThreadTextEncoding() );
672 sMessage += "'.)";
673 OSL_FAIL( sMessage.getStr() );
675 #endif
678 sal_Int32 nPropDataLen = xMark->offsetToMark( nPropDataBeginMark );
679 xMark->jumpToMark( nPropDataBeginMark );
680 OutStream->writeLong( nPropDataLen );
681 xMark->jumpToFurthest();
682 xMark->deleteMark(nPropDataBeginMark);
685 if ( aProps.find( BASEPROPERTY_FONTDESCRIPTOR ) != aProps.end() )
687 const ::com::sun::star::uno::Any* pProp = &maData[ BASEPROPERTY_FONTDESCRIPTOR ];
688 // Until 5.0 export arrives, write old format..
689 ::com::sun::star::awt::FontDescriptor aFD;
690 (*pProp) >>= aFD;
692 for ( sal_uInt16 n = BASEPROPERTY_FONT_TYPE; n <= BASEPROPERTY_FONT_ATTRIBS; n++ )
694 sal_Int32 nPropDataBeginMark = xMark->createMark();
695 OutStream->writeLong( 0L ); // DataLen
696 OutStream->writeShort( n ); // PropId
697 OutStream->writeBoolean( sal_False ); // Void
699 if ( n == BASEPROPERTY_FONT_TYPE )
701 OutStream->writeUTF( aFD.Name );
702 OutStream->writeUTF( aFD.StyleName );
703 OutStream->writeShort( aFD.Family );
704 OutStream->writeShort( aFD.CharSet );
705 OutStream->writeShort( aFD.Pitch );
707 else if ( n == BASEPROPERTY_FONT_SIZE )
709 OutStream->writeLong( aFD.Width );
710 OutStream->writeLong( aFD.Height );
711 OutStream->writeShort(
712 sal::static_int_cast< sal_Int16 >(
713 VCLUnoHelper::ConvertFontWidth( aFD.CharacterWidth )) );
715 else if ( n == BASEPROPERTY_FONT_ATTRIBS )
717 OutStream->writeShort(
718 sal::static_int_cast< sal_Int16 >(
719 VCLUnoHelper::ConvertFontWeight( aFD.Weight )) );
720 OutStream->writeShort(
721 sal::static_int_cast< sal_Int16 >(aFD.Slant) );
722 OutStream->writeShort( aFD.Underline );
723 OutStream->writeShort( aFD.Strikeout );
724 OutStream->writeShort( (short)(aFD.Orientation * 10) );
725 OutStream->writeBoolean( aFD.Kerning );
726 OutStream->writeBoolean( aFD.WordLineMode );
728 else
730 OSL_FAIL( "Property?!" );
733 sal_Int32 nPropDataLen = xMark->offsetToMark( nPropDataBeginMark );
734 xMark->jumpToMark( nPropDataBeginMark );
735 OutStream->writeLong( nPropDataLen );
736 xMark->jumpToFurthest();
737 xMark->deleteMark(nPropDataBeginMark);
742 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)
744 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
746 ::com::sun::star::uno::Reference< ::com::sun::star::io::XMarkableStream > xMark( InStream, ::com::sun::star::uno::UNO_QUERY );
747 DBG_ASSERT( xMark.is(), "read: no ::com::sun::star::io::XMarkableStream!" );
749 short nVersion = InStream->readShort();
750 sal_uInt32 nProps = (sal_uInt32)InStream->readLong();
751 ::com::sun::star::uno::Sequence< ::rtl::OUString> aProps( nProps );
752 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> aValues( nProps );
753 sal_Bool bInvalidEntries = sal_False;
755 // Unfortunately, there's no mark for the whole block, thus only properties may be changed.
756 // No data for the model may be added following the properties
758 // Used for import of old parts in ::com::sun::star::awt::FontDescriptor
759 ::com::sun::star::awt::FontDescriptor* pFD = NULL;
761 sal_uInt32 i;
762 for ( i = 0; i < nProps; i++ )
764 sal_Int32 nPropDataBeginMark = xMark->createMark();
765 sal_Int32 nPropDataLen = InStream->readLong();
767 sal_uInt16 nPropId = (sal_uInt16)InStream->readShort();
769 ::com::sun::star::uno::Any aValue;
770 sal_Bool bIsVoid = InStream->readBoolean();
771 if ( !bIsVoid )
773 if ( maData.find( nPropId ) != maData.end() )
775 const ::com::sun::star::uno::Type* pType = GetPropertyType( nPropId );
776 if ( *pType == ::getBooleanCppuType() )
778 sal_Bool b = InStream->readBoolean();
779 aValue <<= b;
781 else if ( *pType == ::getCppuType((const ::rtl::OUString*)0) )
783 ::rtl::OUString aUTF = InStream->readUTF();
784 aValue <<= aUTF;
786 else if ( *pType == ::getCppuType((const sal_uInt16*)0) )
788 sal_uInt16 n = InStream->readShort();
789 aValue <<= n;
791 else if ( *pType == ::getCppuType((const sal_Int16*)0) )
793 sal_Int16 n = InStream->readShort();
794 aValue <<= n;
796 else if ( *pType == ::getCppuType((const sal_uInt32*)0) )
798 sal_uInt32 n = InStream->readLong();
799 aValue <<= n;
801 else if ( *pType == ::getCppuType((const sal_Int32*)0) )
803 sal_Int32 n = InStream->readLong();
804 aValue <<= n;
806 else if ( *pType == ::getCppuType((const double*)0) )
808 double n = InStream->readDouble();
809 aValue <<= n;
811 else if ( *pType == ::getCppuType((const ::com::sun::star::awt::FontDescriptor*)0) )
813 ::com::sun::star::awt::FontDescriptor aFD;
814 aFD.Name = InStream->readUTF();
815 aFD.Height = InStream->readShort();
816 aFD.Width = InStream->readShort();
817 aFD.StyleName = InStream->readUTF();
818 aFD.Family = InStream->readShort();
819 aFD.CharSet = InStream->readShort();
820 aFD.Pitch = InStream->readShort();
821 aFD.CharacterWidth = (float)InStream->readDouble();
822 aFD.Weight = (float)InStream->readDouble();
823 aFD.Slant = (::com::sun::star::awt::FontSlant)InStream->readShort();
824 aFD.Underline = InStream->readShort();
825 aFD.Strikeout = InStream->readShort();
826 aFD.Orientation = (float)InStream->readDouble();
827 aFD.Kerning = InStream->readBoolean();
828 aFD.WordLineMode = InStream->readBoolean();
829 aFD.Type = InStream->readShort();
830 aValue <<= aFD;
832 else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence< ::rtl::OUString>*)0 ) )
834 long nEntries = InStream->readLong();
835 ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq( nEntries );
836 for ( long n = 0; n < nEntries; n++ )
837 aSeq.getArray()[n] = InStream->readUTF();
838 aValue <<= aSeq;
841 else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_uInt16>*)0 ) )
844 long nEntries = InStream->readLong();
845 ::com::sun::star::uno::Sequence<sal_uInt16> aSeq( nEntries );
846 for ( long n = 0; n < nEntries; n++ )
847 aSeq.getArray()[n] = (sal_uInt16)InStream->readShort();
848 aValue <<= aSeq;
850 else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_Int16>*)0 ) )
852 long nEntries = InStream->readLong();
853 ::com::sun::star::uno::Sequence<sal_Int16> aSeq( nEntries );
854 for ( long n = 0; n < nEntries; n++ )
855 aSeq.getArray()[n] = (sal_Int16)InStream->readShort();
856 aValue <<= aSeq;
858 else if ( pType->getTypeClass() == TypeClass_ENUM )
860 sal_Int32 nAsInt = InStream->readLong();
861 aValue = ::cppu::int2enum( nAsInt, *pType );
863 else
865 ::rtl::OString sMessage( "UnoControlModel::read: don't know how to handle a property of type '" );
866 ::rtl::OUString sTypeName( pType->getTypeName() );
867 sMessage += ::rtl::OString( sTypeName.getStr(), sTypeName.getLength(), RTL_TEXTENCODING_ASCII_US );
868 sMessage += "'.\n(Currently handling property '";
869 ::rtl::OUString sPropertyName( GetPropertyName( nPropId ) );
870 sMessage += ::rtl::OString( sPropertyName.getStr(), sPropertyName.getLength(), osl_getThreadTextEncoding() );
871 sMessage += "'.)";
872 OSL_FAIL( sMessage.getStr() );
875 else
877 // Old trash from 5.0
878 if ( nPropId == BASEPROPERTY_FONT_TYPE )
880 // Redundant information for older versions
881 // is skipped by MarkableStream
882 if ( nVersion < 2 )
884 if ( !pFD )
886 pFD = new ::com::sun::star::awt::FontDescriptor;
887 if ( maData.find( BASEPROPERTY_FONTDESCRIPTOR ) != maData.end() ) // wegen den Defaults...
888 maData[ BASEPROPERTY_FONTDESCRIPTOR ] >>= *pFD;
890 pFD->Name = InStream->readUTF();
891 pFD->StyleName = InStream->readUTF();
892 pFD->Family = InStream->readShort();
893 pFD->CharSet = InStream->readShort();
894 pFD->Pitch = InStream->readShort();
897 else if ( nPropId == BASEPROPERTY_FONT_SIZE )
899 if ( nVersion < 2 )
901 if ( !pFD )
903 pFD = new ::com::sun::star::awt::FontDescriptor;
904 if ( maData.find(BASEPROPERTY_FONTDESCRIPTOR) != maData.end() ) // due to defaults...
905 maData[BASEPROPERTY_FONTDESCRIPTOR] >>= *pFD;
907 pFD->Width = (sal_Int16)InStream->readLong();
908 pFD->Height = (sal_Int16)InStream->readLong();
909 InStream->readShort(); // ignore ::com::sun::star::awt::FontWidth - it was
910 // misspelled and is no longer needed
911 pFD->CharacterWidth = ::com::sun::star::awt::FontWidth::DONTKNOW;
914 else if ( nPropId == BASEPROPERTY_FONT_ATTRIBS )
916 if ( nVersion < 2 )
918 if ( !pFD )
920 pFD = new ::com::sun::star::awt::FontDescriptor;
921 if ( maData.find(BASEPROPERTY_FONTDESCRIPTOR) != maData.end() ) // due to defaults...
922 maData[BASEPROPERTY_FONTDESCRIPTOR] >>= *pFD;
924 pFD->Weight = VCLUnoHelper::ConvertFontWeight( (FontWeight) InStream->readShort() );
925 pFD->Slant = (::com::sun::star::awt::FontSlant)InStream->readShort();
926 pFD->Underline = InStream->readShort();
927 pFD->Strikeout = InStream->readShort();
928 pFD->Orientation = ( (float)(double)InStream->readShort() ) / 10;
929 pFD->Kerning = InStream->readBoolean();
930 pFD->WordLineMode = InStream->readBoolean();
933 else
935 OSL_FAIL( "read: unknown Property!" );
939 else // bVoid
941 if ( nPropId == BASEPROPERTY_FONTDESCRIPTOR )
943 EmptyFontDescriptor aFD;
944 aValue <<= aFD;
948 if ( maData.find( nPropId ) != maData.end() )
950 aProps.getArray()[i] = GetPropertyName( nPropId );
951 aValues.getArray()[i] = aValue;
953 else
955 bInvalidEntries = sal_True;
958 // Skip rest of input if there is more data in stream than this version can handle
959 xMark->jumpToMark( nPropDataBeginMark );
960 InStream->skipBytes( nPropDataLen );
961 xMark->deleteMark(nPropDataBeginMark);
963 if ( bInvalidEntries )
965 for ( i = 0; i < (sal_uInt32)aProps.getLength(); i++ )
967 if ( aProps.getConstArray()[i].isEmpty() )
969 ::comphelper::removeElementAt( aProps, i );
970 ::comphelper::removeElementAt( aValues, i );
971 i--;
978 setPropertyValues( aProps, aValues );
980 catch ( const Exception& )
982 DBG_UNHANDLED_EXCEPTION();
985 if ( pFD )
987 ::com::sun::star::uno::Any aValue;
988 aValue <<= *pFD;
989 setPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR ), aValue );
990 delete pFD;
995 // ::com::sun::star::lang::XServiceInfo
996 ::rtl::OUString UnoControlModel::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException)
998 OSL_FAIL( "This method should be overloaded!" );
999 return ::rtl::OUString();
1003 sal_Bool UnoControlModel::supportsService( const ::rtl::OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException)
1005 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1007 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
1008 const ::rtl::OUString * pArray = aSNL.getConstArray();
1009 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
1010 if( pArray[i] == rServiceName )
1011 return sal_True;
1012 return sal_False;
1015 ::com::sun::star::uno::Sequence< ::rtl::OUString > UnoControlModel::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
1017 ::rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlModel" ) );
1018 return Sequence< ::rtl::OUString >( &sName, 1 );
1021 // ------------------------------------------------------------------
1022 template <class TYPE>
1023 sal_Bool convertType(Any& _rConvertedValue, const Any& _rNewValueTest, const TYPE* /* _pTypeDisambiguation */)
1025 TYPE tValue;
1026 if (_rNewValueTest >>= tValue)
1028 _rConvertedValue <<= tValue;
1029 return sal_True;
1033 // ..................................................................
1034 sal_Bool UnoControlModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nPropId, const Any& rValue ) throw (IllegalArgumentException)
1036 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1038 sal_Bool bVoid = rValue.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID;
1039 if ( bVoid )
1041 rConvertedValue.clear();
1043 else
1045 const ::com::sun::star::uno::Type* pDestType = GetPropertyType( (sal_uInt16)nPropId );
1046 if ( pDestType->getTypeClass() == TypeClass_ANY )
1048 rConvertedValue = rValue;
1050 else
1052 if ( pDestType->equals( rValue.getValueType() ) )
1054 rConvertedValue = rValue;
1056 else
1058 sal_Bool bConverted = sal_False;
1059 // 13.03.2001 - 84923 - frank.schoenheit@germany.sun.com
1061 switch (pDestType->getTypeClass())
1063 case TypeClass_DOUBLE:
1065 // try as double
1066 double nAsDouble = 0;
1067 bConverted = ( rValue >>= nAsDouble );
1068 if ( bConverted )
1069 rConvertedValue <<= nAsDouble;
1070 else
1071 { // try as integer
1072 sal_Int32 nAsInteger = 0;
1073 bConverted = ( rValue >>= nAsInteger );
1074 if ( bConverted )
1075 rConvertedValue <<= (double)nAsInteger;
1078 break;
1079 case TypeClass_SHORT:
1081 sal_Int16 n;
1082 bConverted = ( rValue >>= n );
1083 if ( bConverted )
1084 rConvertedValue <<= n;
1086 break;
1087 case TypeClass_UNSIGNED_SHORT:
1089 sal_uInt16 n;
1090 bConverted = ( rValue >>= n );
1091 if ( bConverted )
1092 rConvertedValue <<= n;
1094 break;
1095 case TypeClass_LONG:
1097 sal_Int32 n;
1098 bConverted = ( rValue >>= n );
1099 if ( bConverted )
1100 rConvertedValue <<= n;
1102 break;
1103 case TypeClass_UNSIGNED_LONG:
1105 sal_uInt32 n;
1106 bConverted = ( rValue >>= n );
1107 if ( bConverted )
1108 rConvertedValue <<= n;
1110 break;
1111 case TypeClass_INTERFACE:
1113 if ( rValue.getValueType().getTypeClass() == TypeClass_INTERFACE )
1115 Reference< XInterface > xPure( rValue, UNO_QUERY );
1116 if ( xPure.is() )
1117 rConvertedValue = xPure->queryInterface( *pDestType );
1118 else
1119 rConvertedValue.setValue( NULL, *pDestType );
1120 bConverted = sal_True;
1123 break;
1124 case TypeClass_ENUM:
1126 sal_Int32 nValue = 0;
1127 bConverted = ( rValue >>= nValue );
1128 if ( bConverted )
1129 rConvertedValue = ::cppu::int2enum( nValue, *pDestType );
1131 break;
1132 default: ; // avoid compiler warning
1135 if (!bConverted)
1137 ::rtl::OUStringBuffer aErrorMessage;
1138 aErrorMessage.appendAscii( "Unable to convert the given value for the property " );
1139 aErrorMessage.append ( GetPropertyName( (sal_uInt16)nPropId ) );
1140 aErrorMessage.appendAscii( ".\n" );
1141 aErrorMessage.appendAscii( "Expected type: " );
1142 aErrorMessage.append ( pDestType->getTypeName() );
1143 aErrorMessage.appendAscii( "\n" );
1144 aErrorMessage.appendAscii( "Found type: " );
1145 aErrorMessage.append ( rValue.getValueType().getTypeName() );
1146 throw ::com::sun::star::lang::IllegalArgumentException(
1147 aErrorMessage.makeStringAndClear(),
1148 static_cast< ::com::sun::star::beans::XPropertySet* >(this),
1155 // the current value
1156 getFastPropertyValue( rOldValue, nPropId );
1157 return !CompareProperties( rConvertedValue, rOldValue );
1160 void UnoControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception)
1162 // Missing: the fake solo properties of the FontDescriptor
1164 ImplPropertyTable::const_iterator it = maData.find( nPropId );
1165 const ::com::sun::star::uno::Any* pProp = it == maData.end() ? NULL : &(it->second);
1166 ENSURE_OR_RETURN_VOID( pProp, "UnoControlModel::setFastPropertyValue_NoBroadcast: invalid property id!" );
1168 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!" );
1169 maData[ nPropId ] = rValue;
1172 void UnoControlModel::getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nPropId ) const
1174 ::osl::Guard< ::osl::Mutex > aGuard( ((UnoControlModel*)this)->GetMutex() );
1176 ImplPropertyTable::const_iterator it = maData.find( nPropId );
1177 const ::com::sun::star::uno::Any* pProp = it == maData.end() ? NULL : &(it->second);
1179 if ( pProp )
1180 rValue = *pProp;
1181 else if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1183 pProp = &( maData.find( BASEPROPERTY_FONTDESCRIPTOR )->second );
1184 ::com::sun::star::awt::FontDescriptor aFD;
1185 (*pProp) >>= aFD;
1186 switch ( nPropId )
1188 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: rValue <<= aFD.Name;
1189 break;
1190 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: rValue <<= aFD.StyleName;
1191 break;
1192 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: rValue <<= aFD.Family;
1193 break;
1194 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: rValue <<= aFD.CharSet;
1195 break;
1196 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: rValue <<= (float)aFD.Height;
1197 break;
1198 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: rValue <<= aFD.Weight;
1199 break;
1200 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: rValue <<= (sal_Int16)aFD.Slant;
1201 break;
1202 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: rValue <<= aFD.Underline;
1203 break;
1204 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: rValue <<= aFD.Strikeout;
1205 break;
1206 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: rValue <<= aFD.Width;
1207 break;
1208 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: rValue <<= aFD.Pitch;
1209 break;
1210 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: rValue <<= aFD.CharacterWidth;
1211 break;
1212 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: rValue <<= aFD.Orientation;
1213 break;
1214 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: rValue <<= aFD.Kerning;
1215 break;
1216 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: rValue <<= aFD.WordLineMode;
1217 break;
1218 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: rValue <<= aFD.Type;
1219 break;
1220 default: OSL_FAIL( "FontProperty?!" );
1223 else
1225 OSL_FAIL( "getFastPropertyValue - invalid Property!" );
1229 // ::com::sun::star::beans::XPropertySet
1230 void UnoControlModel::setPropertyValue( const ::rtl::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)
1232 sal_Int32 nPropId = 0;
1234 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1235 nPropId = (sal_Int32) GetPropertyId( rPropertyName );
1236 DBG_ASSERT( nPropId, "Invalid ID in UnoControlModel::setPropertyValue" );
1238 if( nPropId )
1239 setFastPropertyValue( nPropId, rValue );
1240 else
1241 throw ::com::sun::star::beans::UnknownPropertyException();
1244 // ::com::sun::star::beans::XFastPropertySet
1245 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)
1247 if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1249 ::osl::ClearableMutexGuard aGuard( GetMutex() );
1251 Any aOldSingleValue;
1252 getFastPropertyValue( aOldSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START );
1254 ::com::sun::star::uno::Any* pProp = &maData[ BASEPROPERTY_FONTDESCRIPTOR ];
1255 FontDescriptor aOldFontDescriptor;
1256 (*pProp) >>= aOldFontDescriptor;
1258 FontDescriptor aNewFontDescriptor( aOldFontDescriptor );
1259 lcl_ImplMergeFontProperty( aNewFontDescriptor, (sal_uInt16)nPropId, rValue );
1261 Any aNewValue;
1262 aNewValue <<= aNewFontDescriptor;
1263 sal_Int32 nDescriptorId( BASEPROPERTY_FONTDESCRIPTOR );
1264 nDescriptorId = BASEPROPERTY_FONTDESCRIPTOR;
1266 // also, we need fire a propertyChange event for the single property, since with
1267 // the above line, only an event for the FontDescriptor property will be fired
1268 Any aNewSingleValue;
1269 getFastPropertyValue( aNewSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START );
1271 aGuard.clear();
1272 setFastPropertyValues( 1, &nDescriptorId, &aNewValue, 1 );
1273 fire( &nPropId, &aNewSingleValue, &aOldSingleValue, 1, sal_False );
1275 else
1276 setFastPropertyValues( 1, &nPropId, &rValue, 1 );
1279 // ::com::sun::star::beans::XMultiPropertySet
1280 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > UnoControlModel::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
1282 OSL_FAIL( "UnoControlModel::getPropertySetInfo() not possible!" );
1283 return ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >();
1286 void UnoControlModel::setPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::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)
1288 ::osl::ClearableMutexGuard aGuard( GetMutex() );
1290 sal_Int32 nProps = rPropertyNames.getLength();
1292 // sal_Int32* pHandles = new sal_Int32[nProps];
1293 // don't do this - it leaks in case of an exception
1294 Sequence< sal_Int32 > aHandles( nProps );
1295 sal_Int32* pHandles = aHandles.getArray();
1297 // may need to change the order in the sequence, for this we need a non-const value sequence
1298 uno::Sequence< uno::Any > aValues( Values );
1299 uno::Any* pValues = aValues.getArray();
1301 sal_Int32 nValidHandles = getInfoHelper().fillHandles( pHandles, rPropertyNames );
1303 if ( nValidHandles )
1305 // if somebody sets properties which are single aspects of a font descriptor,
1306 // remove them, and build a font descriptor instead
1307 ::std::auto_ptr< awt::FontDescriptor > pFD;
1308 for ( sal_uInt16 n = 0; n < nProps; ++n )
1310 if ( ( pHandles[n] >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( pHandles[n] <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1312 if ( !pFD.get() )
1314 ::com::sun::star::uno::Any* pProp = &maData[ BASEPROPERTY_FONTDESCRIPTOR ];
1315 pFD.reset( new awt::FontDescriptor );
1316 (*pProp) >>= *pFD;
1318 lcl_ImplMergeFontProperty( *pFD, (sal_uInt16)pHandles[n], pValues[n] );
1319 pHandles[n] = -1;
1320 nValidHandles--;
1324 if ( nValidHandles )
1326 ImplNormalizePropertySequence( nProps, pHandles, pValues, &nValidHandles );
1327 aGuard.clear();
1328 // clear our guard before calling into setFastPropertyValues - this method
1329 // will implicitly call property listeners, and this should not happen with
1330 // our mutex locked
1331 // #i23451#
1332 setFastPropertyValues( nProps, pHandles, pValues, nValidHandles );
1334 else
1335 aGuard.clear();
1336 // same as a few lines above
1338 // Don't merge FD property into array, as it is sorted
1339 if ( pFD.get() )
1341 ::com::sun::star::uno::Any aValue;
1342 aValue <<= *pFD;
1343 sal_Int32 nHandle = BASEPROPERTY_FONTDESCRIPTOR;
1344 setFastPropertyValues( 1, &nHandle, &aValue, 1 );
1351 void UnoControlModel::ImplNormalizePropertySequence( const sal_Int32, sal_Int32*,
1352 uno::Any*, sal_Int32* ) const SAL_THROW(())
1354 // nothing to do here
1357 void UnoControlModel::ImplEnsureHandleOrder( const sal_Int32 _nCount, sal_Int32* _pHandles,
1358 uno::Any* _pValues, sal_Int32 _nFirstHandle, sal_Int32 _nSecondHandle ) const
1360 for ( sal_Int32 i=0; i < _nCount; ++_pHandles, ++_pValues, ++i )
1362 if ( _nSecondHandle == *_pHandles )
1364 sal_Int32* pLaterHandles = _pHandles + 1;
1365 uno::Any* pLaterValues = _pValues + 1;
1366 for ( sal_Int32 j = i + 1; j < _nCount; ++j, ++pLaterHandles, ++pLaterValues )
1368 if ( _nFirstHandle == *pLaterHandles )
1370 // indeed it is -> exchange the both places in the sequences
1371 sal_Int32 nHandle( *_pHandles );
1372 *_pHandles = *pLaterHandles;
1373 *pLaterHandles = nHandle;
1375 uno::Any aValue( *_pValues );
1376 *_pValues = *pLaterValues;
1377 *pLaterValues = aValue;
1379 break;
1380 // this will leave the inner loop, and continue with the outer loop.
1381 // Note that this means we will encounter the _nSecondHandle handle, again, once we reached
1382 // (in the outer loop) the place where we just put it.
1389 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */