1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/supportsservice.hxx>
34 #include <cppuhelper/typeprovider.hxx>
36 #include <tools/diagnose_ex.h>
37 #include <tools/date.hxx>
38 #include <tools/time.hxx>
39 #include <tools/debug.hxx>
40 #include <toolkit/helper/property.hxx>
41 #include <toolkit/helper/vclunohelper.hxx>
42 #include <toolkit/helper/emptyfontdescriptor.hxx>
43 #include <com/sun/star/lang/Locale.hpp>
44 #include <unotools/localedatawrapper.hxx>
45 #include <unotools/configmgr.hxx>
46 #include <comphelper/processfactory.hxx>
47 #include <comphelper/sequence.hxx>
48 #include <comphelper/extract.hxx>
49 #include <vcl/svapp.hxx>
53 #include <boost/scoped_ptr.hpp>
55 using namespace ::com::sun::star
;
56 using namespace ::com::sun::star::uno
;
57 using namespace ::com::sun::star::lang
;
58 using namespace ::com::sun::star::i18n
;
59 using ::com::sun::star::awt::FontDescriptor
;
62 #define UNOCONTROL_STREAMVERSION (short)2
64 static void lcl_ImplMergeFontProperty( FontDescriptor
& rFD
, sal_uInt16 nPropId
, const Any
& rValue
)
66 // some props are defined with other types than the matching FontDescriptor members have
67 // (e.g. FontWidth, FontSlant)
68 // 78474 - 09/19/2000 - FS
69 float nExtractFloat
= 0;
70 sal_Int16 nExtractShort
= 0;
74 case BASEPROPERTY_FONTDESCRIPTORPART_NAME
: rValue
>>= rFD
.Name
;
76 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME
: rValue
>>= rFD
.StyleName
;
78 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY
: rValue
>>= rFD
.Family
;
80 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET
: rValue
>>= rFD
.CharSet
;
82 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT
: rValue
>>= nExtractFloat
; rFD
.Height
= (sal_Int16
)nExtractFloat
;
84 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT
: rValue
>>= rFD
.Weight
;
86 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT
: if ( rValue
>>= nExtractShort
)
87 rFD
.Slant
= (::com::sun::star::awt::FontSlant
)nExtractShort
;
91 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE
: rValue
>>= rFD
.Underline
;
93 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT
: rValue
>>= rFD
.Strikeout
;
95 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH
: rValue
>>= rFD
.Width
;
97 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH
: rValue
>>= rFD
.Pitch
;
99 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH
: rValue
>>= rFD
.CharacterWidth
;
101 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION
: rValue
>>= rFD
.Orientation
;
103 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING
: rValue
>>= rFD
.Kerning
;
105 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE
: rValue
>>= rFD
.WordLineMode
;
107 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE
: rValue
>>= rFD
.Type
;
109 default: OSL_FAIL( "FontProperty?!" );
114 // class UnoControlModel
116 UnoControlModel::UnoControlModel( const Reference
< XComponentContext
>& rxContext
)
117 :UnoControlModel_Base()
118 ,MutexAndBroadcastHelper()
119 ,OPropertySetHelper( BrdcstHelper
)
120 ,maDisposeListeners( *this )
121 ,m_xContext( rxContext
)
123 // Insert properties from Model into table,
124 // only existing properties are valid, even if they're VOID
127 UnoControlModel::UnoControlModel( const UnoControlModel
& rModel
)
128 : UnoControlModel_Base()
129 , MutexAndBroadcastHelper()
130 , OPropertySetHelper( BrdcstHelper
)
131 , maData( rModel
.maData
)
132 , maDisposeListeners( *this )
133 , m_xContext( rModel
.m_xContext
)
137 ::com::sun::star::uno::Sequence
<sal_Int32
> UnoControlModel::ImplGetPropertyIds() const
139 sal_uInt32 nIDs
= maData
.size();
140 ::com::sun::star::uno::Sequence
<sal_Int32
> aIDs( nIDs
);
141 sal_Int32
* pIDs
= aIDs
.getArray();
143 for ( ImplPropertyTable::const_iterator it
= maData
.begin(); it
!= maData
.end(); ++it
)
144 pIDs
[n
++] = it
->first
;
148 bool UnoControlModel::ImplHasProperty( sal_uInt16 nPropId
) const
150 if ( ( nPropId
>= BASEPROPERTY_FONTDESCRIPTORPART_START
) && ( nPropId
<= BASEPROPERTY_FONTDESCRIPTORPART_END
) )
151 nPropId
= BASEPROPERTY_FONTDESCRIPTOR
;
153 return maData
.find( nPropId
) != maData
.end();
156 ::com::sun::star::uno::Any
UnoControlModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
158 ::com::sun::star::uno::Any aDefault
;
161 (nPropId
== BASEPROPERTY_FONTDESCRIPTOR
) ||
163 (nPropId
>= BASEPROPERTY_FONTDESCRIPTORPART_START
) &&
164 (nPropId
<= BASEPROPERTY_FONTDESCRIPTORPART_END
)
168 EmptyFontDescriptor aFD
;
171 case BASEPROPERTY_FONTDESCRIPTOR
: aDefault
<<= aFD
; break;
172 case BASEPROPERTY_FONTDESCRIPTORPART_NAME
: aDefault
<<= aFD
.Name
; break;
173 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME
: aDefault
<<= aFD
.StyleName
; break;
174 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY
: aDefault
<<= aFD
.Family
; break;
175 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET
: aDefault
<<= aFD
.CharSet
; break;
176 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT
: aDefault
<<= (float)aFD
.Height
; break;
177 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT
: aDefault
<<= aFD
.Weight
; break;
178 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT
: aDefault
<<= (sal_Int16
)aFD
.Slant
; break;
179 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE
: aDefault
<<= aFD
.Underline
; break;
180 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT
: aDefault
<<= aFD
.Strikeout
; break;
181 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH
: aDefault
<<= aFD
.Width
; break;
182 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH
: aDefault
<<= aFD
.Pitch
; break;
183 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH
: aDefault
<<= aFD
.CharacterWidth
; break;
184 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION
: aDefault
<<= aFD
.Orientation
; break;
185 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING
: aDefault
<<= aFD
.Kerning
; break;
186 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE
: aDefault
<<= aFD
.WordLineMode
; break;
187 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE
: aDefault
<<= aFD
.Type
; break;
188 default: OSL_FAIL( "FontProperty?!" );
195 case BASEPROPERTY_GRAPHIC
:
196 aDefault
<<= Reference
< graphic::XGraphic
>();
199 case BASEPROPERTY_REFERENCE_DEVICE
:
200 aDefault
<<= Reference
< awt::XDevice
>();
203 case BASEPROPERTY_ITEM_SEPARATOR_POS
:
204 case BASEPROPERTY_VERTICALALIGN
:
205 case BASEPROPERTY_BORDERCOLOR
:
206 case BASEPROPERTY_SYMBOL_COLOR
:
207 case BASEPROPERTY_TABSTOP
:
208 case BASEPROPERTY_TEXTCOLOR
:
209 case BASEPROPERTY_TEXTLINECOLOR
:
210 case BASEPROPERTY_DATE
:
211 case BASEPROPERTY_DATESHOWCENTURY
:
212 case BASEPROPERTY_TIME
:
213 case BASEPROPERTY_VALUE_DOUBLE
:
214 case BASEPROPERTY_PROGRESSVALUE
:
215 case BASEPROPERTY_SCROLLVALUE
:
216 case BASEPROPERTY_VISIBLESIZE
:
217 case BASEPROPERTY_BACKGROUNDCOLOR
:
218 case BASEPROPERTY_FILLCOLOR
: break; // Void
220 case BASEPROPERTY_FONTRELIEF
:
221 case BASEPROPERTY_FONTEMPHASISMARK
:
222 case BASEPROPERTY_MAXTEXTLEN
:
223 case BASEPROPERTY_STATE
:
224 case BASEPROPERTY_EXTDATEFORMAT
:
225 case BASEPROPERTY_EXTTIMEFORMAT
:
226 case BASEPROPERTY_ECHOCHAR
: aDefault
<<= (sal_Int16
) 0; break;
227 case BASEPROPERTY_BORDER
: aDefault
<<= (sal_Int16
) 1; break;
228 case BASEPROPERTY_DECIMALACCURACY
: aDefault
<<= (sal_Int16
) 2; break;
229 case BASEPROPERTY_LINECOUNT
: aDefault
<<= (sal_Int16
) 5; break;
230 case BASEPROPERTY_ALIGN
: aDefault
<<= (sal_Int16
) PROPERTY_ALIGN_LEFT
; break;
231 case BASEPROPERTY_IMAGEALIGN
: aDefault
<<= (sal_Int16
) 1 /*ImageAlign::TOP*/; break;
232 case BASEPROPERTY_IMAGEPOSITION
: aDefault
<<= (sal_Int16
) 12 /*ImagePosition::Centered*/; break;
233 case BASEPROPERTY_PUSHBUTTONTYPE
: aDefault
<<= (sal_Int16
) 0 /*PushButtonType::STANDARD*/; break;
234 case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR
:aDefault
<<= (sal_Int16
) awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY
; break;
236 case BASEPROPERTY_DATEMAX
: aDefault
<<= util::Date( 31, 12, 2200 ); break;
237 case BASEPROPERTY_DATEMIN
: aDefault
<<= util::Date( 1, 1, 1900 ); break;
238 case BASEPROPERTY_TIMEMAX
: aDefault
<<= util::Time(0, 0, 59, 23, false); break;
239 case BASEPROPERTY_TIMEMIN
: aDefault
<<= util::Time(); break;
240 case BASEPROPERTY_VALUEMAX_DOUBLE
: aDefault
<<= (double) 1000000; break;
241 case BASEPROPERTY_VALUEMIN_DOUBLE
: aDefault
<<= (double) -1000000; break;
242 case BASEPROPERTY_VALUESTEP_DOUBLE
: aDefault
<<= (double ) 1; break;
243 case BASEPROPERTY_PROGRESSVALUE_MAX
: aDefault
<<= (sal_Int32
) 100; break;
244 case BASEPROPERTY_PROGRESSVALUE_MIN
: aDefault
<<= (sal_Int32
) 0; break;
245 case BASEPROPERTY_SCROLLVALUE_MAX
: aDefault
<<= (sal_Int32
) 100; break;
246 case BASEPROPERTY_SCROLLVALUE_MIN
: aDefault
<<= (sal_Int32
) 0; break;
247 case BASEPROPERTY_LINEINCREMENT
: aDefault
<<= (sal_Int32
) 1; break;
248 case BASEPROPERTY_BLOCKINCREMENT
: aDefault
<<= (sal_Int32
) 10; break;
249 case BASEPROPERTY_ORIENTATION
: aDefault
<<= (sal_Int32
) 0; break;
250 case BASEPROPERTY_SPINVALUE
: aDefault
<<= (sal_Int32
) 0; break;
251 case BASEPROPERTY_SPININCREMENT
: aDefault
<<= (sal_Int32
) 1; break;
252 case BASEPROPERTY_SPINVALUE_MIN
: aDefault
<<= (sal_Int32
) 0; break;
253 case BASEPROPERTY_SPINVALUE_MAX
: aDefault
<<= (sal_Int32
) 100; break;
254 case BASEPROPERTY_REPEAT_DELAY
: aDefault
<<= (sal_Int32
) 50; break; // 50 milliseconds
255 case BASEPROPERTY_DEFAULTCONTROL
: aDefault
<<= const_cast<UnoControlModel
*>(this)->getServiceName(); break;
257 case BASEPROPERTY_AUTOHSCROLL
:
258 case BASEPROPERTY_AUTOVSCROLL
:
259 case BASEPROPERTY_MOVEABLE
:
260 case BASEPROPERTY_CLOSEABLE
:
261 case BASEPROPERTY_SIZEABLE
:
262 case BASEPROPERTY_HSCROLL
:
263 case BASEPROPERTY_DEFAULTBUTTON
:
264 case BASEPROPERTY_MULTILINE
:
265 case BASEPROPERTY_MULTISELECTION
:
266 case BASEPROPERTY_TRISTATE
:
267 case BASEPROPERTY_DROPDOWN
:
268 case BASEPROPERTY_SPIN
:
269 case BASEPROPERTY_READONLY
:
270 case BASEPROPERTY_VSCROLL
:
271 case BASEPROPERTY_NUMSHOWTHOUSANDSEP
:
272 case BASEPROPERTY_STRICTFORMAT
:
273 case BASEPROPERTY_REPEAT
:
274 case BASEPROPERTY_PAINTTRANSPARENT
:
275 case BASEPROPERTY_DESKTOP_AS_PARENT
:
276 case BASEPROPERTY_HARDLINEBREAKS
:
277 case BASEPROPERTY_NOLABEL
: aDefault
<<= false; break;
279 case BASEPROPERTY_MULTISELECTION_SIMPLEMODE
:
280 case BASEPROPERTY_HIDEINACTIVESELECTION
:
281 case BASEPROPERTY_ENFORCE_FORMAT
:
282 case BASEPROPERTY_AUTOCOMPLETE
:
283 case BASEPROPERTY_SCALEIMAGE
:
284 case BASEPROPERTY_ENABLED
:
285 case BASEPROPERTY_PRINTABLE
:
286 case BASEPROPERTY_ENABLEVISIBLE
:
287 case BASEPROPERTY_DECORATION
: aDefault
<<= true; break;
289 case BASEPROPERTY_GROUPNAME
:
290 case BASEPROPERTY_HELPTEXT
:
291 case BASEPROPERTY_HELPURL
:
292 case BASEPROPERTY_IMAGEURL
:
293 case BASEPROPERTY_DIALOGSOURCEURL
:
294 case BASEPROPERTY_EDITMASK
:
295 case BASEPROPERTY_LITERALMASK
:
296 case BASEPROPERTY_LABEL
:
297 case BASEPROPERTY_TITLE
:
298 case BASEPROPERTY_TEXT
: aDefault
<<= OUString(); break;
300 case BASEPROPERTY_WRITING_MODE
:
301 case BASEPROPERTY_CONTEXT_WRITING_MODE
:
302 aDefault
<<= text::WritingMode2::CONTEXT
;
305 case BASEPROPERTY_STRINGITEMLIST
:
307 ::com::sun::star::uno::Sequence
< OUString
> aStringSeq
;
308 aDefault
<<= aStringSeq
;
312 case BASEPROPERTY_SELECTEDITEMS
:
314 ::com::sun::star::uno::Sequence
<sal_Int16
> aINT16Seq
;
315 aDefault
<<= aINT16Seq
;
318 case BASEPROPERTY_CURRENCYSYMBOL
:
320 OUString
sDefaultCurrency(
321 utl::ConfigManager::getDefaultCurrency() );
323 // extract the bank symbol
324 sal_Int32 nSepPos
= sDefaultCurrency
.indexOf( '-' );
325 OUString sBankSymbol
;
328 sBankSymbol
= sDefaultCurrency
.copy( 0, nSepPos
);
329 sDefaultCurrency
= sDefaultCurrency
.copy( nSepPos
+ 1 );
332 // the remaining is the locale
333 LanguageTag
aLanguageTag( sDefaultCurrency
);
334 LocaleDataWrapper
aLocaleInfo( m_xContext
, aLanguageTag
);
335 if ( sBankSymbol
.isEmpty() )
336 sBankSymbol
= aLocaleInfo
.getCurrBankSymbol();
338 // look for the currency entry (for this language) which has the given bank symbol
339 Sequence
< Currency2
> aAllCurrencies
= aLocaleInfo
.getAllCurrencies();
340 const Currency2
* pAllCurrencies
= aAllCurrencies
.getConstArray();
341 const Currency2
* pAllCurrenciesEnd
= pAllCurrencies
+ aAllCurrencies
.getLength();
343 OUString sCurrencySymbol
= aLocaleInfo
.getCurrSymbol();
344 if ( sBankSymbol
.isEmpty() )
346 DBG_ASSERT( pAllCurrencies
!= pAllCurrenciesEnd
, "UnoControlModel::ImplGetDefaultValue: no currencies at all!" );
347 if ( pAllCurrencies
!= pAllCurrenciesEnd
)
349 sBankSymbol
= pAllCurrencies
->BankSymbol
;
350 sCurrencySymbol
= pAllCurrencies
->Symbol
;
354 if ( !sBankSymbol
.isEmpty() )
356 bool bLegacy
= false;
357 for ( ;pAllCurrencies
!= pAllCurrenciesEnd
; ++pAllCurrencies
)
358 if ( pAllCurrencies
->BankSymbol
== sBankSymbol
)
360 sCurrencySymbol
= pAllCurrencies
->Symbol
;
361 if ( pAllCurrencies
->LegacyOnly
)
366 DBG_ASSERT( bLegacy
|| pAllCurrencies
!= pAllCurrenciesEnd
, "UnoControlModel::ImplGetDefaultValue: did not find the given bank symbol!" );
370 aDefault
<<= sCurrencySymbol
;
374 default: OSL_FAIL( "ImplGetDefaultValue - unknown Property" );
381 void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId
, const ::com::sun::star::uno::Any
& rDefault
)
383 maData
[ nPropId
] = rDefault
;
386 void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId
)
388 ImplRegisterProperty( nPropId
, ImplGetDefaultValue( nPropId
) );
390 if ( nPropId
== BASEPROPERTY_FONTDESCRIPTOR
)
392 // some properties are not included in the FontDescriptor, but every time
393 // when we have a FontDescriptor we want to have these properties too.
394 // => Easier to register the here, istead everywhere where I register the FontDescriptor...
396 ImplRegisterProperty( BASEPROPERTY_TEXTCOLOR
);
397 ImplRegisterProperty( BASEPROPERTY_TEXTLINECOLOR
);
398 ImplRegisterProperty( BASEPROPERTY_FONTRELIEF
);
399 ImplRegisterProperty( BASEPROPERTY_FONTEMPHASISMARK
);
403 void UnoControlModel::ImplRegisterProperties( const std::list
< sal_uInt16
> &rIds
)
405 std::list
< sal_uInt16
>::const_iterator iter
;
406 for( iter
= rIds
.begin(); iter
!= rIds
.end(); ++iter
)
408 if( !ImplHasProperty( *iter
) )
409 ImplRegisterProperty( *iter
, ImplGetDefaultValue( *iter
) );
413 // ::com::sun::star::uno::XInterface
414 ::com::sun::star::uno::Any
UnoControlModel::queryAggregation( const ::com::sun::star::uno::Type
& rType
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
416 Any aRet
= UnoControlModel_Base::queryAggregation( rType
);
417 if ( !aRet
.hasValue() )
418 aRet
= ::cppu::OPropertySetHelper::queryInterface( rType
);
422 // ::com::sun::star::lang::XUnoTunnel
423 IMPL_XUNOTUNNEL_MINIMAL( UnoControlModel
)
426 IMPLEMENT_FORWARD_REFCOUNT( UnoControlModel
, UnoControlModel_Base
)
428 // ::com::sun::star::lang::XTypeProvider
429 IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoControlModel
, UnoControlModel_Base
, ::cppu::OPropertySetHelper
)
432 uno::Reference
< util::XCloneable
> UnoControlModel::createClone() throw(::com::sun::star::uno::RuntimeException
, std::exception
)
434 UnoControlModel
* pClone
= Clone();
435 uno::Reference
< util::XCloneable
> xClone( (::cppu::OWeakObject
*) pClone
, uno::UNO_QUERY
);
439 // ::com::sun::star::lang::XComponent
440 void UnoControlModel::dispose( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
442 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
444 ::com::sun::star::lang::EventObject aEvt
;
445 aEvt
.Source
= (::com::sun::star::uno::XAggregation
*)(::cppu::OWeakAggObject
*)this;
446 maDisposeListeners
.disposeAndClear( aEvt
);
448 BrdcstHelper
.aLC
.disposeAndClear( aEvt
);
450 // let the property set helper notify our property listeners
451 OPropertySetHelper::disposing();
454 void UnoControlModel::addEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& rxListener
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
456 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
458 maDisposeListeners
.addInterface( rxListener
);
461 void UnoControlModel::removeEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& rxListener
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
463 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
465 maDisposeListeners
.removeInterface( rxListener
);
469 // ::com::sun::star::beans::XPropertyState
470 ::com::sun::star::beans::PropertyState
UnoControlModel::getPropertyState( const OUString
& PropertyName
) throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
472 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
474 sal_uInt16 nPropId
= GetPropertyId( PropertyName
);
476 ::com::sun::star::uno::Any aValue
= getPropertyValue( PropertyName
);
477 ::com::sun::star::uno::Any aDefault
= ImplGetDefaultValue( nPropId
);
479 return CompareProperties( aValue
, aDefault
) ? ::com::sun::star::beans::PropertyState_DEFAULT_VALUE
: ::com::sun::star::beans::PropertyState_DIRECT_VALUE
;
482 ::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
, std::exception
)
484 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
486 sal_uInt32 nNames
= PropertyNames
.getLength();
487 const OUString
* pNames
= PropertyNames
.getConstArray();
489 ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::PropertyState
> aStates( nNames
);
490 ::com::sun::star::beans::PropertyState
* pStates
= aStates
.getArray();
492 for ( sal_uInt32 n
= 0; n
< nNames
; n
++ )
493 pStates
[n
] = getPropertyState( pNames
[n
] );
498 void UnoControlModel::setPropertyToDefault( const OUString
& PropertyName
) throw(::com::sun::star::beans::UnknownPropertyException
, ::com::sun::star::uno::RuntimeException
, std::exception
)
502 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
503 aDefaultValue
= ImplGetDefaultValue( GetPropertyId( PropertyName
) );
505 setPropertyValue( PropertyName
, aDefaultValue
);
508 ::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
, std::exception
)
510 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
512 return ImplGetDefaultValue( GetPropertyId( rPropertyName
) );
516 // ::com::sun::star::io::XPersistObjec
517 OUString
UnoControlModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
519 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
521 OSL_FAIL( "ServiceName von UnoControlModel ?!" );
525 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
, std::exception
)
527 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
529 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XMarkableStream
> xMark( OutStream
, ::com::sun::star::uno::UNO_QUERY
);
530 DBG_ASSERT( xMark
.is(), "write: no ::com::sun::star::io::XMarkableStream!" );
532 OutStream
->writeShort( UNOCONTROL_STREAMVERSION
);
534 std::set
<sal_uInt16
> aProps
;
536 for (ImplPropertyTable::const_iterator it
= maData
.begin(); it
!= maData
.end(); ++it
)
538 if ( ( ( GetPropertyAttribs( it
->first
) & ::com::sun::star::beans::PropertyAttribute::TRANSIENT
) == 0 )
539 && ( getPropertyState( GetPropertyName( it
->first
) ) != ::com::sun::star::beans::PropertyState_DEFAULT_VALUE
) )
541 aProps
.insert( it
->first
);
545 sal_uInt32 nProps
= aProps
.size();
547 // Save FontProperty always in the old format (due to missing distinction
548 // between 5.0 and 5.1)
549 OutStream
->writeLong( ( aProps
.find( BASEPROPERTY_FONTDESCRIPTOR
) != aProps
.end() ) ? ( nProps
+ 3 ) : nProps
);
550 for ( std::set
<sal_uInt16
>::const_iterator it
= aProps
.begin(); it
!= aProps
.end(); ++it
)
552 sal_Int32 nPropDataBeginMark
= xMark
->createMark();
553 OutStream
->writeLong( 0L ); // DataLen
555 const ::com::sun::star::uno::Any
* pProp
= &(maData
[*it
]);
556 OutStream
->writeShort( *it
);
558 bool bVoid
= pProp
->getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID
;
560 OutStream
->writeBoolean( bVoid
);
564 const ::com::sun::star::uno::Any
& rValue
= *pProp
;
565 const ::com::sun::star::uno::Type
& rType
= rValue
.getValueType();
567 if ( rType
== cppu::UnoType
< bool >::get() )
571 OutStream
->writeBoolean( b
);
573 else if ( rType
== ::cppu::UnoType
< OUString
>::get() )
577 OutStream
->writeUTF( aUString
);
579 else if ( rType
== ::cppu::UnoType
< ::cppu::UnoUnsignedShortType
>::get() )
583 OutStream
->writeShort( n
);
585 else if ( rType
== cppu::UnoType
<sal_Int16
>::get() )
589 OutStream
->writeShort( n
);
591 else if ( rType
== cppu::UnoType
<sal_uInt32
>::get() )
595 OutStream
->writeLong( n
);
597 else if ( rType
== cppu::UnoType
<sal_Int32
>::get() )
601 OutStream
->writeLong( n
);
603 else if ( rType
== cppu::UnoType
<double>::get() )
607 OutStream
->writeDouble( n
);
609 else if ( rType
== cppu::UnoType
< ::com::sun::star::awt::FontDescriptor
>::get() )
611 ::com::sun::star::awt::FontDescriptor aFD
;
613 OutStream
->writeUTF( aFD
.Name
);
614 OutStream
->writeShort( aFD
.Height
);
615 OutStream
->writeShort( aFD
.Width
);
616 OutStream
->writeUTF( aFD
.StyleName
);
617 OutStream
->writeShort( aFD
.Family
);
618 OutStream
->writeShort( aFD
.CharSet
);
619 OutStream
->writeShort( aFD
.Pitch
);
620 OutStream
->writeDouble( aFD
.CharacterWidth
);
621 OutStream
->writeDouble( aFD
.Weight
);
622 OutStream
->writeShort(
623 sal::static_int_cast
< sal_Int16
>(aFD
.Slant
) );
624 OutStream
->writeShort( aFD
.Underline
);
625 OutStream
->writeShort( aFD
.Strikeout
);
626 OutStream
->writeDouble( aFD
.Orientation
);
627 OutStream
->writeBoolean( aFD
.Kerning
);
628 OutStream
->writeBoolean( aFD
.WordLineMode
);
629 OutStream
->writeShort( aFD
.Type
);
631 else if ( rType
== cppu::UnoType
<css::util::Date
>::get() )
635 OutStream
->writeLong(d
.Day
+ 100 * d
.Month
+ 10000 * d
.Year
);
638 else if ( rType
== cppu::UnoType
<css::util::Time
>::get() )
642 OutStream
->writeLong(
643 t
.NanoSeconds
/ 1000000 + 100 * t
.Seconds
644 + 10000 * t
.Minutes
+ 1000000 * t
.Hours
); // HHMMSShh
646 else if ( rType
== cppu::UnoType
< ::com::sun::star::uno::Sequence
< OUString
> >::get() )
648 ::com::sun::star::uno::Sequence
< OUString
> aSeq
;
650 long nEntries
= aSeq
.getLength();
651 OutStream
->writeLong( nEntries
);
652 for ( long n
= 0; n
< nEntries
; n
++ )
653 OutStream
->writeUTF( aSeq
.getConstArray()[n
] );
655 else if ( rType
== cppu::UnoType
< cppu::UnoSequenceType
<cppu::UnoUnsignedShortType
> >::get() )
657 ::com::sun::star::uno::Sequence
<sal_uInt16
> aSeq
;
659 long nEntries
= aSeq
.getLength();
660 OutStream
->writeLong( nEntries
);
661 for ( long n
= 0; n
< nEntries
; n
++ )
662 OutStream
->writeShort( aSeq
.getConstArray()[n
] );
664 else if ( rType
== cppu::UnoType
< ::com::sun::star::uno::Sequence
<sal_Int16
> >::get() )
666 ::com::sun::star::uno::Sequence
<sal_Int16
> aSeq
;
668 long nEntries
= aSeq
.getLength();
669 OutStream
->writeLong( nEntries
);
670 for ( long n
= 0; n
< nEntries
; n
++ )
671 OutStream
->writeShort( aSeq
.getConstArray()[n
] );
673 else if ( rType
.getTypeClass() == TypeClass_ENUM
)
675 sal_Int32 nAsInt
= 0;
676 ::cppu::enum2int( nAsInt
, rValue
);
677 OutStream
->writeLong( nAsInt
);
679 #if OSL_DEBUG_LEVEL > 0
682 OString
sMessage( "UnoControlModel::write: don't know how to handle a property of type '" );
683 OUString
sTypeName( rType
.getTypeName() );
684 sMessage
+= OString( sTypeName
.getStr(), sTypeName
.getLength(), RTL_TEXTENCODING_ASCII_US
);
685 sMessage
+= "'.\n(Currently handling property '";
686 OUString
sPropertyName( GetPropertyName( *it
) );
687 sMessage
+= OString( sPropertyName
.getStr(), sPropertyName
.getLength(), osl_getThreadTextEncoding() );
689 OSL_FAIL( sMessage
.getStr() );
694 sal_Int32 nPropDataLen
= xMark
->offsetToMark( nPropDataBeginMark
);
695 xMark
->jumpToMark( nPropDataBeginMark
);
696 OutStream
->writeLong( nPropDataLen
);
697 xMark
->jumpToFurthest();
698 xMark
->deleteMark(nPropDataBeginMark
);
701 if ( aProps
.find( BASEPROPERTY_FONTDESCRIPTOR
) != aProps
.end() )
703 const ::com::sun::star::uno::Any
* pProp
= &maData
[ BASEPROPERTY_FONTDESCRIPTOR
];
704 // Until 5.0 export arrives, write old format..
705 ::com::sun::star::awt::FontDescriptor aFD
;
708 for ( sal_uInt16 n
= BASEPROPERTY_FONT_TYPE
; n
<= BASEPROPERTY_FONT_ATTRIBS
; n
++ )
710 sal_Int32 nPropDataBeginMark
= xMark
->createMark();
711 OutStream
->writeLong( 0L ); // DataLen
712 OutStream
->writeShort( n
); // PropId
713 OutStream
->writeBoolean( sal_False
); // Void
715 if ( n
== BASEPROPERTY_FONT_TYPE
)
717 OutStream
->writeUTF( aFD
.Name
);
718 OutStream
->writeUTF( aFD
.StyleName
);
719 OutStream
->writeShort( aFD
.Family
);
720 OutStream
->writeShort( aFD
.CharSet
);
721 OutStream
->writeShort( aFD
.Pitch
);
723 else if ( n
== BASEPROPERTY_FONT_SIZE
)
725 OutStream
->writeLong( aFD
.Width
);
726 OutStream
->writeLong( aFD
.Height
);
727 OutStream
->writeShort(
728 sal::static_int_cast
< sal_Int16
>(
729 VCLUnoHelper::ConvertFontWidth( aFD
.CharacterWidth
)) );
731 else if ( n
== BASEPROPERTY_FONT_ATTRIBS
)
733 OutStream
->writeShort(
734 sal::static_int_cast
< sal_Int16
>(
735 VCLUnoHelper::ConvertFontWeight( aFD
.Weight
)) );
736 OutStream
->writeShort(
737 sal::static_int_cast
< sal_Int16
>(aFD
.Slant
) );
738 OutStream
->writeShort( aFD
.Underline
);
739 OutStream
->writeShort( aFD
.Strikeout
);
740 OutStream
->writeShort( (short)(aFD
.Orientation
* 10) );
741 OutStream
->writeBoolean( aFD
.Kerning
);
742 OutStream
->writeBoolean( aFD
.WordLineMode
);
746 OSL_FAIL( "Property?!" );
749 sal_Int32 nPropDataLen
= xMark
->offsetToMark( nPropDataBeginMark
);
750 xMark
->jumpToMark( nPropDataBeginMark
);
751 OutStream
->writeLong( nPropDataLen
);
752 xMark
->jumpToFurthest();
753 xMark
->deleteMark(nPropDataBeginMark
);
758 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
, std::exception
)
760 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
762 ::com::sun::star::uno::Reference
< ::com::sun::star::io::XMarkableStream
> xMark( InStream
, ::com::sun::star::uno::UNO_QUERY
);
763 DBG_ASSERT( xMark
.is(), "read: no ::com::sun::star::io::XMarkableStream!" );
765 short nVersion
= InStream
->readShort();
766 sal_uInt32 nProps
= (sal_uInt32
)InStream
->readLong();
767 ::com::sun::star::uno::Sequence
< OUString
> aProps( nProps
);
768 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Any
> aValues( nProps
);
769 bool bInvalidEntries
= false;
771 // Unfortunately, there's no mark for the whole block, thus only properties may be changed.
772 // No data for the model may be added following the properties
774 // Used for import of old parts in ::com::sun::star::awt::FontDescriptor
775 ::com::sun::star::awt::FontDescriptor
* pFD
= NULL
;
778 for ( i
= 0; i
< nProps
; i
++ )
780 sal_Int32 nPropDataBeginMark
= xMark
->createMark();
781 sal_Int32 nPropDataLen
= InStream
->readLong();
783 sal_uInt16 nPropId
= (sal_uInt16
)InStream
->readShort();
785 ::com::sun::star::uno::Any aValue
;
786 bool bIsVoid
= InStream
->readBoolean();
789 if ( maData
.find( nPropId
) != maData
.end() )
791 const ::com::sun::star::uno::Type
* pType
= GetPropertyType( nPropId
);
792 if ( *pType
== cppu::UnoType
<bool>::get() )
794 bool b
= InStream
->readBoolean();
797 else if ( *pType
== cppu::UnoType
<OUString
>::get() )
799 OUString aUTF
= InStream
->readUTF();
802 else if ( *pType
== ::cppu::UnoType
< ::cppu::UnoUnsignedShortType
>::get() )
804 sal_uInt16 n
= InStream
->readShort();
807 else if ( *pType
== cppu::UnoType
<sal_Int16
>::get() )
809 sal_Int16 n
= InStream
->readShort();
812 else if ( *pType
== cppu::UnoType
<sal_uInt32
>::get() )
814 sal_uInt32 n
= InStream
->readLong();
817 else if ( *pType
== cppu::UnoType
<sal_Int32
>::get() )
819 sal_Int32 n
= InStream
->readLong();
822 else if ( *pType
== cppu::UnoType
<double>::get() )
824 double n
= InStream
->readDouble();
827 else if ( *pType
== cppu::UnoType
< ::com::sun::star::awt::FontDescriptor
>::get() )
829 ::com::sun::star::awt::FontDescriptor aFD
;
830 aFD
.Name
= InStream
->readUTF();
831 aFD
.Height
= InStream
->readShort();
832 aFD
.Width
= InStream
->readShort();
833 aFD
.StyleName
= InStream
->readUTF();
834 aFD
.Family
= InStream
->readShort();
835 aFD
.CharSet
= InStream
->readShort();
836 aFD
.Pitch
= InStream
->readShort();
837 aFD
.CharacterWidth
= (float)InStream
->readDouble();
838 aFD
.Weight
= (float)InStream
->readDouble();
839 aFD
.Slant
= (::com::sun::star::awt::FontSlant
)InStream
->readShort();
840 aFD
.Underline
= InStream
->readShort();
841 aFD
.Strikeout
= InStream
->readShort();
842 aFD
.Orientation
= (float)InStream
->readDouble();
843 aFD
.Kerning
= InStream
->readBoolean();
844 aFD
.WordLineMode
= InStream
->readBoolean();
845 aFD
.Type
= InStream
->readShort();
848 else if ( *pType
== cppu::UnoType
<css::util::Date
>::get() )
850 sal_Int32 n
= InStream
->readLong(); // YYYYMMDD
851 aValue
<<= css::util::Date(
852 n
% 100, (n
/ 100) % 100, n
/ 10000);
854 else if ( *pType
== cppu::UnoType
<css::util::Time
>::get() )
856 sal_Int32 n
= InStream
->readLong(); // HHMMSShh
857 aValue
<<= css::util::Time(
858 (n
% 100) * 1000000, (n
/ 100) % 100, (n
/ 10000) % 100,
861 else if ( *pType
== cppu::UnoType
< ::com::sun::star::uno::Sequence
< OUString
> >::get() )
863 long nEntries
= InStream
->readLong();
864 ::com::sun::star::uno::Sequence
< OUString
> aSeq( nEntries
);
865 for ( long n
= 0; n
< nEntries
; n
++ )
866 aSeq
.getArray()[n
] = InStream
->readUTF();
870 else if ( *pType
== cppu::UnoType
< cppu::UnoSequenceType
<cppu::UnoUnsignedShortType
> >::get() )
873 long nEntries
= InStream
->readLong();
874 ::com::sun::star::uno::Sequence
<sal_uInt16
> aSeq( nEntries
);
875 for ( long n
= 0; n
< nEntries
; n
++ )
876 aSeq
.getArray()[n
] = (sal_uInt16
)InStream
->readShort();
879 else if ( *pType
== cppu::UnoType
< ::com::sun::star::uno::Sequence
<sal_Int16
> >::get() )
881 long nEntries
= InStream
->readLong();
882 ::com::sun::star::uno::Sequence
<sal_Int16
> aSeq( nEntries
);
883 for ( long n
= 0; n
< nEntries
; n
++ )
884 aSeq
.getArray()[n
] = (sal_Int16
)InStream
->readShort();
887 else if ( pType
->getTypeClass() == TypeClass_ENUM
)
889 sal_Int32 nAsInt
= InStream
->readLong();
890 aValue
= ::cppu::int2enum( nAsInt
, *pType
);
894 OString
sMessage( "UnoControlModel::read: don't know how to handle a property of type '" );
895 OUString
sTypeName( pType
->getTypeName() );
896 sMessage
+= OString( sTypeName
.getStr(), sTypeName
.getLength(), RTL_TEXTENCODING_ASCII_US
);
897 sMessage
+= "'.\n(Currently handling property '";
898 OUString
sPropertyName( GetPropertyName( nPropId
) );
899 sMessage
+= OString( sPropertyName
.getStr(), sPropertyName
.getLength(), osl_getThreadTextEncoding() );
901 OSL_FAIL( sMessage
.getStr() );
906 // Old trash from 5.0
907 if ( nPropId
== BASEPROPERTY_FONT_TYPE
)
909 // Redundant information for older versions
910 // is skipped by MarkableStream
915 pFD
= new ::com::sun::star::awt::FontDescriptor
;
916 if ( maData
.find( BASEPROPERTY_FONTDESCRIPTOR
) != maData
.end() ) // wegen den Defaults...
917 maData
[ BASEPROPERTY_FONTDESCRIPTOR
] >>= *pFD
;
919 pFD
->Name
= InStream
->readUTF();
920 pFD
->StyleName
= InStream
->readUTF();
921 pFD
->Family
= InStream
->readShort();
922 pFD
->CharSet
= InStream
->readShort();
923 pFD
->Pitch
= InStream
->readShort();
926 else if ( nPropId
== BASEPROPERTY_FONT_SIZE
)
932 pFD
= new ::com::sun::star::awt::FontDescriptor
;
933 if ( maData
.find(BASEPROPERTY_FONTDESCRIPTOR
) != maData
.end() ) // due to defaults...
934 maData
[BASEPROPERTY_FONTDESCRIPTOR
] >>= *pFD
;
936 pFD
->Width
= (sal_Int16
)InStream
->readLong();
937 pFD
->Height
= (sal_Int16
)InStream
->readLong();
938 InStream
->readShort(); // ignore ::com::sun::star::awt::FontWidth - it was
939 // misspelled and is no longer needed
940 pFD
->CharacterWidth
= ::com::sun::star::awt::FontWidth::DONTKNOW
;
943 else if ( nPropId
== BASEPROPERTY_FONT_ATTRIBS
)
949 pFD
= new ::com::sun::star::awt::FontDescriptor
;
950 if ( maData
.find(BASEPROPERTY_FONTDESCRIPTOR
) != maData
.end() ) // due to defaults...
951 maData
[BASEPROPERTY_FONTDESCRIPTOR
] >>= *pFD
;
953 pFD
->Weight
= VCLUnoHelper::ConvertFontWeight( (FontWeight
) InStream
->readShort() );
954 pFD
->Slant
= (::com::sun::star::awt::FontSlant
)InStream
->readShort();
955 pFD
->Underline
= InStream
->readShort();
956 pFD
->Strikeout
= InStream
->readShort();
957 pFD
->Orientation
= ( (float)(double)InStream
->readShort() ) / 10;
958 pFD
->Kerning
= InStream
->readBoolean();
959 pFD
->WordLineMode
= InStream
->readBoolean();
964 OSL_FAIL( "read: unknown Property!" );
970 if ( nPropId
== BASEPROPERTY_FONTDESCRIPTOR
)
972 EmptyFontDescriptor aFD
;
977 if ( maData
.find( nPropId
) != maData
.end() )
979 aProps
.getArray()[i
] = GetPropertyName( nPropId
);
980 aValues
.getArray()[i
] = aValue
;
984 bInvalidEntries
= true;
987 // Skip rest of input if there is more data in stream than this version can handle
988 xMark
->jumpToMark( nPropDataBeginMark
);
989 InStream
->skipBytes( nPropDataLen
);
990 xMark
->deleteMark(nPropDataBeginMark
);
992 if ( bInvalidEntries
)
994 for ( i
= 0; i
< (sal_uInt32
)aProps
.getLength(); i
++ )
996 if ( aProps
.getConstArray()[i
].isEmpty() )
998 ::comphelper::removeElementAt( aProps
, i
);
999 ::comphelper::removeElementAt( aValues
, i
);
1007 setPropertyValues( aProps
, aValues
);
1009 catch ( const Exception
& )
1011 DBG_UNHANDLED_EXCEPTION();
1016 ::com::sun::star::uno::Any aValue
;
1018 setPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR
), aValue
);
1024 // ::com::sun::star::lang::XServiceInfo
1025 OUString
UnoControlModel::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
1027 OSL_FAIL( "This method should be overridden!" );
1032 sal_Bool
UnoControlModel::supportsService( const OUString
& rServiceName
) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
1034 return cppu::supportsService(this, rServiceName
);
1037 ::com::sun::star::uno::Sequence
< OUString
> UnoControlModel::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
1039 OUString
sName( "com.sun.star.awt.UnoControlModel" );
1040 return Sequence
< OUString
>( &sName
, 1 );
1043 sal_Bool
UnoControlModel::convertFastPropertyValue( Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nPropId
, const Any
& rValue
) throw (IllegalArgumentException
)
1045 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1047 bool bVoid
= rValue
.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID
;
1050 rConvertedValue
.clear();
1054 const ::com::sun::star::uno::Type
* pDestType
= GetPropertyType( (sal_uInt16
)nPropId
);
1055 if ( pDestType
->getTypeClass() == TypeClass_ANY
)
1057 rConvertedValue
= rValue
;
1061 if ( pDestType
->equals( rValue
.getValueType() ) )
1063 rConvertedValue
= rValue
;
1067 bool bConverted
= false;
1068 // 13.03.2001 - 84923 - frank.schoenheit@germany.sun.com
1070 switch (pDestType
->getTypeClass())
1072 case TypeClass_DOUBLE
:
1075 double nAsDouble
= 0;
1076 bConverted
= ( rValue
>>= nAsDouble
);
1078 rConvertedValue
<<= nAsDouble
;
1081 sal_Int32 nAsInteger
= 0;
1082 bConverted
= ( rValue
>>= nAsInteger
);
1084 rConvertedValue
<<= (double)nAsInteger
;
1088 case TypeClass_SHORT
:
1091 bConverted
= ( rValue
>>= n
);
1093 rConvertedValue
<<= n
;
1096 case TypeClass_UNSIGNED_SHORT
:
1099 bConverted
= ( rValue
>>= n
);
1101 rConvertedValue
<<= n
;
1104 case TypeClass_LONG
:
1107 bConverted
= ( rValue
>>= n
);
1109 rConvertedValue
<<= n
;
1112 case TypeClass_UNSIGNED_LONG
:
1115 bConverted
= ( rValue
>>= n
);
1117 rConvertedValue
<<= n
;
1120 case TypeClass_INTERFACE
:
1122 if ( rValue
.getValueType().getTypeClass() == TypeClass_INTERFACE
)
1124 Reference
< XInterface
> xPure( rValue
, UNO_QUERY
);
1126 rConvertedValue
= xPure
->queryInterface( *pDestType
);
1128 rConvertedValue
.setValue( NULL
, *pDestType
);
1133 case TypeClass_ENUM
:
1135 sal_Int32 nValue
= 0;
1136 bConverted
= ( rValue
>>= nValue
);
1138 rConvertedValue
= ::cppu::int2enum( nValue
, *pDestType
);
1141 default: ; // avoid compiler warning
1146 OUStringBuffer aErrorMessage
;
1147 aErrorMessage
.appendAscii( "Unable to convert the given value for the property " );
1148 aErrorMessage
.append ( GetPropertyName( (sal_uInt16
)nPropId
) );
1149 aErrorMessage
.appendAscii( ".\n" );
1150 aErrorMessage
.appendAscii( "Expected type: " );
1151 aErrorMessage
.append ( pDestType
->getTypeName() );
1152 aErrorMessage
.appendAscii( "\n" );
1153 aErrorMessage
.appendAscii( "Found type: " );
1154 aErrorMessage
.append ( rValue
.getValueType().getTypeName() );
1155 throw ::com::sun::star::lang::IllegalArgumentException(
1156 aErrorMessage
.makeStringAndClear(),
1157 static_cast< ::com::sun::star::beans::XPropertySet
* >(this),
1164 // the current value
1165 getFastPropertyValue( rOldValue
, nPropId
);
1166 return !CompareProperties( rConvertedValue
, rOldValue
);
1169 void UnoControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nPropId
, const ::com::sun::star::uno::Any
& rValue
) throw (::com::sun::star::uno::Exception
, std::exception
)
1171 // Missing: the fake solo properties of the FontDescriptor
1173 ImplPropertyTable::const_iterator it
= maData
.find( nPropId
);
1174 const ::com::sun::star::uno::Any
* pProp
= it
== maData
.end() ? NULL
: &(it
->second
);
1175 ENSURE_OR_RETURN_VOID( pProp
, "UnoControlModel::setFastPropertyValue_NoBroadcast: invalid property id!" );
1177 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!" );
1178 maData
[ nPropId
] = rValue
;
1181 void UnoControlModel::getFastPropertyValue( ::com::sun::star::uno::Any
& rValue
, sal_Int32 nPropId
) const
1183 ::osl::Guard
< ::osl::Mutex
> aGuard( const_cast<UnoControlModel
*>(this)->GetMutex() );
1185 ImplPropertyTable::const_iterator it
= maData
.find( nPropId
);
1186 const ::com::sun::star::uno::Any
* pProp
= it
== maData
.end() ? NULL
: &(it
->second
);
1190 else if ( ( nPropId
>= BASEPROPERTY_FONTDESCRIPTORPART_START
) && ( nPropId
<= BASEPROPERTY_FONTDESCRIPTORPART_END
) )
1192 pProp
= &( maData
.find( BASEPROPERTY_FONTDESCRIPTOR
)->second
);
1193 ::com::sun::star::awt::FontDescriptor aFD
;
1197 case BASEPROPERTY_FONTDESCRIPTORPART_NAME
: rValue
<<= aFD
.Name
;
1199 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME
: rValue
<<= aFD
.StyleName
;
1201 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY
: rValue
<<= aFD
.Family
;
1203 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET
: rValue
<<= aFD
.CharSet
;
1205 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT
: rValue
<<= (float)aFD
.Height
;
1207 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT
: rValue
<<= aFD
.Weight
;
1209 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT
: rValue
<<= (sal_Int16
)aFD
.Slant
;
1211 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE
: rValue
<<= aFD
.Underline
;
1213 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT
: rValue
<<= aFD
.Strikeout
;
1215 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH
: rValue
<<= aFD
.Width
;
1217 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH
: rValue
<<= aFD
.Pitch
;
1219 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH
: rValue
<<= aFD
.CharacterWidth
;
1221 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION
: rValue
<<= aFD
.Orientation
;
1223 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING
: rValue
<<= aFD
.Kerning
;
1225 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE
: rValue
<<= aFD
.WordLineMode
;
1227 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE
: rValue
<<= aFD
.Type
;
1229 default: OSL_FAIL( "FontProperty?!" );
1234 OSL_FAIL( "getFastPropertyValue - invalid Property!" );
1238 // ::com::sun::star::beans::XPropertySet
1239 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
, std::exception
)
1241 sal_Int32 nPropId
= 0;
1243 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1244 nPropId
= (sal_Int32
) GetPropertyId( rPropertyName
);
1245 DBG_ASSERT( nPropId
, "Invalid ID in UnoControlModel::setPropertyValue" );
1248 setFastPropertyValue( nPropId
, rValue
);
1250 throw ::com::sun::star::beans::UnknownPropertyException();
1253 // ::com::sun::star::beans::XFastPropertySet
1254 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
, std::exception
)
1256 if ( ( nPropId
>= BASEPROPERTY_FONTDESCRIPTORPART_START
) && ( nPropId
<= BASEPROPERTY_FONTDESCRIPTORPART_END
) )
1258 ::osl::ClearableMutexGuard
aGuard( GetMutex() );
1260 Any aOldSingleValue
;
1261 getFastPropertyValue( aOldSingleValue
, BASEPROPERTY_FONTDESCRIPTORPART_START
);
1263 ::com::sun::star::uno::Any
* pProp
= &maData
[ BASEPROPERTY_FONTDESCRIPTOR
];
1264 FontDescriptor aOldFontDescriptor
;
1265 (*pProp
) >>= aOldFontDescriptor
;
1267 FontDescriptor
aNewFontDescriptor( aOldFontDescriptor
);
1268 lcl_ImplMergeFontProperty( aNewFontDescriptor
, (sal_uInt16
)nPropId
, rValue
);
1271 aNewValue
<<= aNewFontDescriptor
;
1272 sal_Int32
nDescriptorId( BASEPROPERTY_FONTDESCRIPTOR
);
1273 nDescriptorId
= BASEPROPERTY_FONTDESCRIPTOR
;
1275 // also, we need fire a propertyChange event for the single property, since with
1276 // the above line, only an event for the FontDescriptor property will be fired
1277 Any aNewSingleValue
;
1278 getFastPropertyValue( aNewSingleValue
, BASEPROPERTY_FONTDESCRIPTORPART_START
);
1281 setFastPropertyValues( 1, &nDescriptorId
, &aNewValue
, 1 );
1282 fire( &nPropId
, &aNewSingleValue
, &aOldSingleValue
, 1, sal_False
);
1285 setFastPropertyValues( 1, &nPropId
, &rValue
, 1 );
1288 // ::com::sun::star::beans::XMultiPropertySet
1289 ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
> UnoControlModel::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException
, std::exception
)
1291 OSL_FAIL( "UnoControlModel::getPropertySetInfo() not possible!" );
1292 return ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertySetInfo
>();
1295 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
, std::exception
)
1297 ::osl::ClearableMutexGuard
aGuard( GetMutex() );
1299 sal_Int32 nProps
= rPropertyNames
.getLength();
1301 // sal_Int32* pHandles = new sal_Int32[nProps];
1302 // don't do this - it leaks in case of an exception
1303 Sequence
< sal_Int32
> aHandles( nProps
);
1304 sal_Int32
* pHandles
= aHandles
.getArray();
1306 // may need to change the order in the sequence, for this we need a non-const value sequence
1307 uno::Sequence
< uno::Any
> aValues( Values
);
1308 uno::Any
* pValues
= aValues
.getArray();
1310 sal_Int32 nValidHandles
= getInfoHelper().fillHandles( pHandles
, rPropertyNames
);
1312 if ( nValidHandles
)
1314 // if somebody sets properties which are single aspects of a font descriptor,
1315 // remove them, and build a font descriptor instead
1316 boost::scoped_ptr
< awt::FontDescriptor
> pFD
;
1317 for ( sal_uInt16 n
= 0; n
< nProps
; ++n
)
1319 if ( ( pHandles
[n
] >= BASEPROPERTY_FONTDESCRIPTORPART_START
) && ( pHandles
[n
] <= BASEPROPERTY_FONTDESCRIPTORPART_END
) )
1323 ::com::sun::star::uno::Any
* pProp
= &maData
[ BASEPROPERTY_FONTDESCRIPTOR
];
1324 pFD
.reset( new awt::FontDescriptor
);
1327 lcl_ImplMergeFontProperty( *pFD
, (sal_uInt16
)pHandles
[n
], pValues
[n
] );
1333 if ( nValidHandles
)
1335 ImplNormalizePropertySequence( nProps
, pHandles
, pValues
, &nValidHandles
);
1337 // clear our guard before calling into setFastPropertyValues - this method
1338 // will implicitly call property listeners, and this should not happen with
1341 setFastPropertyValues( nProps
, pHandles
, pValues
, nValidHandles
);
1345 // same as a few lines above
1347 // Don't merge FD property into array, as it is sorted
1350 ::com::sun::star::uno::Any aValue
;
1352 sal_Int32 nHandle
= BASEPROPERTY_FONTDESCRIPTOR
;
1353 setFastPropertyValues( 1, &nHandle
, &aValue
, 1 );
1360 void UnoControlModel::ImplNormalizePropertySequence( const sal_Int32
, sal_Int32
*,
1361 uno::Any
*, sal_Int32
* ) const
1363 // nothing to do here
1366 void UnoControlModel::ImplEnsureHandleOrder( const sal_Int32 _nCount
, sal_Int32
* _pHandles
,
1367 uno::Any
* _pValues
, sal_Int32 _nFirstHandle
, sal_Int32 _nSecondHandle
)
1369 for ( sal_Int32 i
=0; i
< _nCount
; ++_pHandles
, ++_pValues
, ++i
)
1371 if ( _nSecondHandle
== *_pHandles
)
1373 sal_Int32
* pLaterHandles
= _pHandles
+ 1;
1374 uno::Any
* pLaterValues
= _pValues
+ 1;
1375 for ( sal_Int32 j
= i
+ 1; j
< _nCount
; ++j
, ++pLaterHandles
, ++pLaterValues
)
1377 if ( _nFirstHandle
== *pLaterHandles
)
1379 // indeed it is -> exchange the both places in the sequences
1380 sal_Int32
nHandle( *_pHandles
);
1381 *_pHandles
= *pLaterHandles
;
1382 *pLaterHandles
= nHandle
;
1384 uno::Any
aValue( *_pValues
);
1385 *_pValues
= *pLaterValues
;
1386 *pLaterValues
= aValue
;
1389 // this will leave the inner loop, and continue with the outer loop.
1390 // Note that this means we will encounter the _nSecondHandle handle, again, once we reached
1391 // (in the outer loop) the place where we just put it.
1398 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */