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>
50 #include <vcl/unohelp.hxx>
56 using namespace ::com::sun::star
;
57 using namespace ::com::sun::star::uno
;
58 using namespace ::com::sun::star::lang
;
59 using namespace ::com::sun::star::i18n
;
60 using ::com::sun::star::awt::FontDescriptor
;
63 #define UNOCONTROL_STREAMVERSION (short)2
65 static void lcl_ImplMergeFontProperty( FontDescriptor
& rFD
, sal_uInt16 nPropId
, const Any
& rValue
)
67 // some props are defined with other types than the matching FontDescriptor members have
68 // (e.g. FontWidth, FontSlant)
69 // 78474 - 09/19/2000 - FS
70 float nExtractFloat
= 0;
71 sal_Int16 nExtractShort
= 0;
75 case BASEPROPERTY_FONTDESCRIPTORPART_NAME
: rValue
>>= rFD
.Name
;
77 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME
: rValue
>>= rFD
.StyleName
;
79 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY
: rValue
>>= rFD
.Family
;
81 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET
: rValue
>>= rFD
.CharSet
;
83 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT
: rValue
>>= nExtractFloat
; rFD
.Height
= (sal_Int16
)nExtractFloat
;
85 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT
: rValue
>>= rFD
.Weight
;
87 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT
: if ( rValue
>>= nExtractShort
)
88 rFD
.Slant
= (css::awt::FontSlant
)nExtractShort
;
92 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE
: rValue
>>= rFD
.Underline
;
94 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT
: rValue
>>= rFD
.Strikeout
;
96 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH
: rValue
>>= rFD
.Width
;
98 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH
: rValue
>>= rFD
.Pitch
;
100 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH
: rValue
>>= rFD
.CharacterWidth
;
102 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION
: rValue
>>= rFD
.Orientation
;
104 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING
: rValue
>>= rFD
.Kerning
;
106 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE
: rValue
>>= rFD
.WordLineMode
;
108 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE
: rValue
>>= rFD
.Type
;
110 default: OSL_FAIL( "FontProperty?!" );
115 // class UnoControlModel
117 UnoControlModel::UnoControlModel( const Reference
< XComponentContext
>& rxContext
)
118 :UnoControlModel_Base()
119 ,MutexAndBroadcastHelper()
120 ,OPropertySetHelper( BrdcstHelper
)
121 ,maDisposeListeners( *this )
122 ,m_xContext( rxContext
)
124 // Insert properties from Model into table,
125 // only existing properties are valid, even if they're VOID
128 UnoControlModel::UnoControlModel( const UnoControlModel
& rModel
)
129 : UnoControlModel_Base()
130 , MutexAndBroadcastHelper()
131 , OPropertySetHelper( BrdcstHelper
)
132 , maData( rModel
.maData
)
133 , maDisposeListeners( *this )
134 , m_xContext( rModel
.m_xContext
)
138 css::uno::Sequence
<sal_Int32
> UnoControlModel::ImplGetPropertyIds() const
140 sal_uInt32 nIDs
= maData
.size();
141 css::uno::Sequence
<sal_Int32
> aIDs( nIDs
);
142 sal_Int32
* pIDs
= aIDs
.getArray();
144 for ( ImplPropertyTable::const_iterator it
= maData
.begin(); it
!= maData
.end(); ++it
)
145 pIDs
[n
++] = it
->first
;
149 bool UnoControlModel::ImplHasProperty( sal_uInt16 nPropId
) const
151 if ( ( nPropId
>= BASEPROPERTY_FONTDESCRIPTORPART_START
) && ( nPropId
<= BASEPROPERTY_FONTDESCRIPTORPART_END
) )
152 nPropId
= BASEPROPERTY_FONTDESCRIPTOR
;
154 return maData
.find( nPropId
) != maData
.end();
157 css::uno::Any
UnoControlModel::ImplGetDefaultValue( sal_uInt16 nPropId
) const
159 css::uno::Any aDefault
;
162 (nPropId
== BASEPROPERTY_FONTDESCRIPTOR
) ||
164 (nPropId
>= BASEPROPERTY_FONTDESCRIPTORPART_START
) &&
165 (nPropId
<= BASEPROPERTY_FONTDESCRIPTORPART_END
)
169 EmptyFontDescriptor aFD
;
172 case BASEPROPERTY_FONTDESCRIPTOR
: aDefault
<<= aFD
; break;
173 case BASEPROPERTY_FONTDESCRIPTORPART_NAME
: aDefault
<<= aFD
.Name
; break;
174 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME
: aDefault
<<= aFD
.StyleName
; break;
175 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY
: aDefault
<<= aFD
.Family
; break;
176 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET
: aDefault
<<= aFD
.CharSet
; break;
177 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT
: aDefault
<<= (float)aFD
.Height
; break;
178 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT
: aDefault
<<= aFD
.Weight
; break;
179 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT
: aDefault
<<= (sal_Int16
)aFD
.Slant
; break;
180 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE
: aDefault
<<= aFD
.Underline
; break;
181 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT
: aDefault
<<= aFD
.Strikeout
; break;
182 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH
: aDefault
<<= aFD
.Width
; break;
183 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH
: aDefault
<<= aFD
.Pitch
; break;
184 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH
: aDefault
<<= aFD
.CharacterWidth
; break;
185 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION
: aDefault
<<= aFD
.Orientation
; break;
186 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING
: aDefault
<<= aFD
.Kerning
; break;
187 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE
: aDefault
<<= aFD
.WordLineMode
; break;
188 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE
: aDefault
<<= aFD
.Type
; break;
189 default: OSL_FAIL( "FontProperty?!" );
196 case BASEPROPERTY_GRAPHIC
:
197 aDefault
<<= Reference
< graphic::XGraphic
>();
200 case BASEPROPERTY_REFERENCE_DEVICE
:
201 aDefault
<<= Reference
< awt::XDevice
>();
204 case BASEPROPERTY_ITEM_SEPARATOR_POS
:
205 case BASEPROPERTY_VERTICALALIGN
:
206 case BASEPROPERTY_BORDERCOLOR
:
207 case BASEPROPERTY_SYMBOL_COLOR
:
208 case BASEPROPERTY_TABSTOP
:
209 case BASEPROPERTY_TEXTCOLOR
:
210 case BASEPROPERTY_TEXTLINECOLOR
:
211 case BASEPROPERTY_DATE
:
212 case BASEPROPERTY_DATESHOWCENTURY
:
213 case BASEPROPERTY_TIME
:
214 case BASEPROPERTY_VALUE_DOUBLE
:
215 case BASEPROPERTY_PROGRESSVALUE
:
216 case BASEPROPERTY_SCROLLVALUE
:
217 case BASEPROPERTY_VISIBLESIZE
:
218 case BASEPROPERTY_BACKGROUNDCOLOR
:
219 case BASEPROPERTY_FILLCOLOR
: break; // Void
221 case BASEPROPERTY_FONTRELIEF
:
222 case BASEPROPERTY_FONTEMPHASISMARK
:
223 case BASEPROPERTY_MAXTEXTLEN
:
224 case BASEPROPERTY_STATE
:
225 case BASEPROPERTY_EXTDATEFORMAT
:
226 case BASEPROPERTY_EXTTIMEFORMAT
:
227 case BASEPROPERTY_ECHOCHAR
: aDefault
<<= (sal_Int16
) 0; break;
228 case BASEPROPERTY_BORDER
: aDefault
<<= (sal_Int16
) 1; break;
229 case BASEPROPERTY_DECIMALACCURACY
: aDefault
<<= (sal_Int16
) 2; break;
230 case BASEPROPERTY_LINECOUNT
: aDefault
<<= (sal_Int16
) 5; break;
231 case BASEPROPERTY_ALIGN
: aDefault
<<= (sal_Int16
) PROPERTY_ALIGN_LEFT
; break;
232 case BASEPROPERTY_IMAGEALIGN
: aDefault
<<= (sal_Int16
) 1 /*ImageAlign::Top*/; break;
233 case BASEPROPERTY_IMAGEPOSITION
: aDefault
<<= (sal_Int16
) 12 /*ImagePosition::Centered*/; break;
234 case BASEPROPERTY_PUSHBUTTONTYPE
: aDefault
<<= (sal_Int16
) 0 /*PushButtonType::STANDARD*/; break;
235 case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR
:aDefault
<<= (sal_Int16
) awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY
; break;
237 case BASEPROPERTY_DATEMAX
: aDefault
<<= util::Date( 31, 12, 2200 ); break;
238 case BASEPROPERTY_DATEMIN
: aDefault
<<= util::Date( 1, 1, 1900 ); break;
239 case BASEPROPERTY_TIMEMAX
: aDefault
<<= util::Time(0, 0, 59, 23, false); break;
240 case BASEPROPERTY_TIMEMIN
: aDefault
<<= util::Time(); break;
241 case BASEPROPERTY_VALUEMAX_DOUBLE
: aDefault
<<= (double) 1000000; break;
242 case BASEPROPERTY_VALUEMIN_DOUBLE
: aDefault
<<= (double) -1000000; break;
243 case BASEPROPERTY_VALUESTEP_DOUBLE
: aDefault
<<= (double ) 1; break;
244 case BASEPROPERTY_PROGRESSVALUE_MAX
: aDefault
<<= (sal_Int32
) 100; break;
245 case BASEPROPERTY_PROGRESSVALUE_MIN
: aDefault
<<= (sal_Int32
) 0; break;
246 case BASEPROPERTY_SCROLLVALUE_MAX
: aDefault
<<= (sal_Int32
) 100; break;
247 case BASEPROPERTY_SCROLLVALUE_MIN
: aDefault
<<= (sal_Int32
) 0; break;
248 case BASEPROPERTY_LINEINCREMENT
: aDefault
<<= (sal_Int32
) 1; break;
249 case BASEPROPERTY_BLOCKINCREMENT
: aDefault
<<= (sal_Int32
) 10; break;
250 case BASEPROPERTY_ORIENTATION
: aDefault
<<= (sal_Int32
) 0; break;
251 case BASEPROPERTY_SPINVALUE
: aDefault
<<= (sal_Int32
) 0; break;
252 case BASEPROPERTY_SPININCREMENT
: aDefault
<<= (sal_Int32
) 1; break;
253 case BASEPROPERTY_SPINVALUE_MIN
: aDefault
<<= (sal_Int32
) 0; break;
254 case BASEPROPERTY_SPINVALUE_MAX
: aDefault
<<= (sal_Int32
) 100; break;
255 case BASEPROPERTY_REPEAT_DELAY
: aDefault
<<= (sal_Int32
) 50; break; // 50 milliseconds
256 case BASEPROPERTY_DEFAULTCONTROL
: aDefault
<<= const_cast<UnoControlModel
*>(this)->getServiceName(); break;
258 case BASEPROPERTY_AUTOHSCROLL
:
259 case BASEPROPERTY_AUTOVSCROLL
:
260 case BASEPROPERTY_MOVEABLE
:
261 case BASEPROPERTY_CLOSEABLE
:
262 case BASEPROPERTY_SIZEABLE
:
263 case BASEPROPERTY_HSCROLL
:
264 case BASEPROPERTY_DEFAULTBUTTON
:
265 case BASEPROPERTY_MULTILINE
:
266 case BASEPROPERTY_MULTISELECTION
:
267 case BASEPROPERTY_TRISTATE
:
268 case BASEPROPERTY_DROPDOWN
:
269 case BASEPROPERTY_SPIN
:
270 case BASEPROPERTY_READONLY
:
271 case BASEPROPERTY_VSCROLL
:
272 case BASEPROPERTY_NUMSHOWTHOUSANDSEP
:
273 case BASEPROPERTY_STRICTFORMAT
:
274 case BASEPROPERTY_REPEAT
:
275 case BASEPROPERTY_PAINTTRANSPARENT
:
276 case BASEPROPERTY_DESKTOP_AS_PARENT
:
277 case BASEPROPERTY_HARDLINEBREAKS
:
278 case BASEPROPERTY_NOLABEL
: aDefault
<<= false; break;
280 case BASEPROPERTY_MULTISELECTION_SIMPLEMODE
:
281 case BASEPROPERTY_HIDEINACTIVESELECTION
:
282 case BASEPROPERTY_ENFORCE_FORMAT
:
283 case BASEPROPERTY_AUTOCOMPLETE
:
284 case BASEPROPERTY_SCALEIMAGE
:
285 case BASEPROPERTY_ENABLED
:
286 case BASEPROPERTY_PRINTABLE
:
287 case BASEPROPERTY_ENABLEVISIBLE
:
288 case BASEPROPERTY_DECORATION
: aDefault
<<= true; break;
290 case BASEPROPERTY_GROUPNAME
:
291 case BASEPROPERTY_HELPTEXT
:
292 case BASEPROPERTY_HELPURL
:
293 case BASEPROPERTY_IMAGEURL
:
294 case BASEPROPERTY_DIALOGSOURCEURL
:
295 case BASEPROPERTY_EDITMASK
:
296 case BASEPROPERTY_LITERALMASK
:
297 case BASEPROPERTY_LABEL
:
298 case BASEPROPERTY_TITLE
:
299 case BASEPROPERTY_TEXT
: aDefault
<<= OUString(); break;
301 case BASEPROPERTY_WRITING_MODE
:
302 case BASEPROPERTY_CONTEXT_WRITING_MODE
:
303 aDefault
<<= text::WritingMode2::CONTEXT
;
306 case BASEPROPERTY_STRINGITEMLIST
:
308 css::uno::Sequence
< OUString
> aStringSeq
;
309 aDefault
<<= aStringSeq
;
313 case BASEPROPERTY_TYPEDITEMLIST
:
315 css::uno::Sequence
< css::uno::Any
> aAnySeq
;
316 aDefault
<<= aAnySeq
;
320 case BASEPROPERTY_SELECTEDITEMS
:
322 css::uno::Sequence
<sal_Int16
> aINT16Seq
;
323 aDefault
<<= aINT16Seq
;
326 case BASEPROPERTY_CURRENCYSYMBOL
:
328 OUString
sDefaultCurrency(
329 utl::ConfigManager::getDefaultCurrency() );
331 // extract the bank symbol
332 sal_Int32 nSepPos
= sDefaultCurrency
.indexOf( '-' );
333 OUString sBankSymbol
;
336 sBankSymbol
= sDefaultCurrency
.copy( 0, nSepPos
);
337 sDefaultCurrency
= sDefaultCurrency
.copy( nSepPos
+ 1 );
340 // the remaining is the locale
341 LanguageTag
aLanguageTag( sDefaultCurrency
);
342 LocaleDataWrapper
aLocaleInfo( m_xContext
, aLanguageTag
);
343 if ( sBankSymbol
.isEmpty() )
344 sBankSymbol
= aLocaleInfo
.getCurrBankSymbol();
346 // look for the currency entry (for this language) which has the given bank symbol
347 Sequence
< Currency2
> aAllCurrencies
= aLocaleInfo
.getAllCurrencies();
348 const Currency2
* pAllCurrencies
= aAllCurrencies
.getConstArray();
349 const Currency2
* pAllCurrenciesEnd
= pAllCurrencies
+ aAllCurrencies
.getLength();
351 OUString sCurrencySymbol
= aLocaleInfo
.getCurrSymbol();
352 if ( sBankSymbol
.isEmpty() )
354 DBG_ASSERT( pAllCurrencies
!= pAllCurrenciesEnd
, "UnoControlModel::ImplGetDefaultValue: no currencies at all!" );
355 if ( pAllCurrencies
!= pAllCurrenciesEnd
)
357 sBankSymbol
= pAllCurrencies
->BankSymbol
;
358 sCurrencySymbol
= pAllCurrencies
->Symbol
;
362 if ( !sBankSymbol
.isEmpty() )
364 bool bLegacy
= false;
365 for ( ;pAllCurrencies
!= pAllCurrenciesEnd
; ++pAllCurrencies
)
366 if ( pAllCurrencies
->BankSymbol
== sBankSymbol
)
368 sCurrencySymbol
= pAllCurrencies
->Symbol
;
369 if ( pAllCurrencies
->LegacyOnly
)
374 DBG_ASSERT( bLegacy
|| pAllCurrencies
!= pAllCurrenciesEnd
, "UnoControlModel::ImplGetDefaultValue: did not find the given bank symbol!" );
378 aDefault
<<= sCurrencySymbol
;
382 default: OSL_FAIL( "ImplGetDefaultValue - unknown Property" );
389 void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId
, const css::uno::Any
& rDefault
)
391 maData
[ nPropId
] = rDefault
;
394 void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId
)
396 ImplRegisterProperty( nPropId
, ImplGetDefaultValue( nPropId
) );
398 if ( nPropId
== BASEPROPERTY_FONTDESCRIPTOR
)
400 // some properties are not included in the FontDescriptor, but every time
401 // when we have a FontDescriptor we want to have these properties too.
402 // => Easier to register the here, instead everywhere where I register the FontDescriptor...
404 ImplRegisterProperty( BASEPROPERTY_TEXTCOLOR
);
405 ImplRegisterProperty( BASEPROPERTY_TEXTLINECOLOR
);
406 ImplRegisterProperty( BASEPROPERTY_FONTRELIEF
);
407 ImplRegisterProperty( BASEPROPERTY_FONTEMPHASISMARK
);
411 void UnoControlModel::ImplRegisterProperties( const std::vector
< sal_uInt16
> &rIds
)
413 std::vector
< sal_uInt16
>::const_iterator iter
;
414 for( iter
= rIds
.begin(); iter
!= rIds
.end(); ++iter
)
416 if( !ImplHasProperty( *iter
) )
417 ImplRegisterProperty( *iter
, ImplGetDefaultValue( *iter
) );
421 // css::uno::XInterface
422 css::uno::Any
UnoControlModel::queryAggregation( const css::uno::Type
& rType
)
424 Any aRet
= UnoControlModel_Base::queryAggregation( rType
);
425 if ( !aRet
.hasValue() )
426 aRet
= ::cppu::OPropertySetHelper::queryInterface( rType
);
430 // css::lang::XUnoTunnel
431 IMPL_XUNOTUNNEL_MINIMAL( UnoControlModel
)
434 IMPLEMENT_FORWARD_REFCOUNT( UnoControlModel
, UnoControlModel_Base
)
436 // css::lang::XTypeProvider
437 IMPLEMENT_FORWARD_XTYPEPROVIDER2( UnoControlModel
, UnoControlModel_Base
, ::cppu::OPropertySetHelper
)
440 uno::Reference
< util::XCloneable
> UnoControlModel::createClone()
442 UnoControlModel
* pClone
= Clone();
443 uno::Reference
< util::XCloneable
> xClone( static_cast<cppu::OWeakObject
*>(pClone
), uno::UNO_QUERY
);
447 // css::lang::XComponent
448 void UnoControlModel::dispose( )
450 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
452 css::lang::EventObject aEvt
;
453 aEvt
.Source
= static_cast<css::uno::XAggregation
*>(static_cast<cppu::OWeakAggObject
*>(this));
454 maDisposeListeners
.disposeAndClear( aEvt
);
456 BrdcstHelper
.aLC
.disposeAndClear( aEvt
);
458 // let the property set helper notify our property listeners
459 OPropertySetHelper::disposing();
462 void UnoControlModel::addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& rxListener
)
464 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
466 maDisposeListeners
.addInterface( rxListener
);
469 void UnoControlModel::removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& rxListener
)
471 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
473 maDisposeListeners
.removeInterface( rxListener
);
477 // css::beans::XPropertyState
478 css::beans::PropertyState
UnoControlModel::getPropertyState( const OUString
& PropertyName
)
480 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
482 sal_uInt16 nPropId
= GetPropertyId( PropertyName
);
484 css::uno::Any aValue
= getPropertyValue( PropertyName
);
485 css::uno::Any aDefault
= ImplGetDefaultValue( nPropId
);
487 return CompareProperties( aValue
, aDefault
) ? css::beans::PropertyState_DEFAULT_VALUE
: css::beans::PropertyState_DIRECT_VALUE
;
490 css::uno::Sequence
< css::beans::PropertyState
> UnoControlModel::getPropertyStates( const css::uno::Sequence
< OUString
>& PropertyNames
)
492 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
494 sal_uInt32 nNames
= PropertyNames
.getLength();
495 const OUString
* pNames
= PropertyNames
.getConstArray();
497 css::uno::Sequence
< css::beans::PropertyState
> aStates( nNames
);
498 css::beans::PropertyState
* pStates
= aStates
.getArray();
500 for ( sal_uInt32 n
= 0; n
< nNames
; n
++ )
501 pStates
[n
] = getPropertyState( pNames
[n
] );
506 void UnoControlModel::setPropertyToDefault( const OUString
& PropertyName
)
510 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
511 aDefaultValue
= ImplGetDefaultValue( GetPropertyId( PropertyName
) );
513 setPropertyValue( PropertyName
, aDefaultValue
);
516 css::uno::Any
UnoControlModel::getPropertyDefault( const OUString
& rPropertyName
)
518 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
520 return ImplGetDefaultValue( GetPropertyId( rPropertyName
) );
524 // css::io::XPersistObjec
525 OUString
UnoControlModel::getServiceName( )
527 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
529 OSL_FAIL( "ServiceName von UnoControlModel ?!" );
533 void UnoControlModel::write( const css::uno::Reference
< css::io::XObjectOutputStream
>& OutStream
)
535 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
537 css::uno::Reference
< css::io::XMarkableStream
> xMark( OutStream
, css::uno::UNO_QUERY
);
538 DBG_ASSERT( xMark
.is(), "write: no css::io::XMarkableStream!" );
540 OutStream
->writeShort( UNOCONTROL_STREAMVERSION
);
542 std::set
<sal_uInt16
> aProps
;
544 for (ImplPropertyTable::const_iterator it
= maData
.begin(); it
!= maData
.end(); ++it
)
546 if ( ( ( GetPropertyAttribs( it
->first
) & css::beans::PropertyAttribute::TRANSIENT
) == 0 )
547 && ( getPropertyState( GetPropertyName( it
->first
) ) != css::beans::PropertyState_DEFAULT_VALUE
) )
549 aProps
.insert( it
->first
);
553 sal_uInt32 nProps
= aProps
.size();
555 // Save FontProperty always in the old format (due to missing distinction
556 // between 5.0 and 5.1)
557 OutStream
->writeLong( ( aProps
.find( BASEPROPERTY_FONTDESCRIPTOR
) != aProps
.end() ) ? ( nProps
+ 3 ) : nProps
);
558 for ( std::set
<sal_uInt16
>::const_iterator it
= aProps
.begin(); it
!= aProps
.end(); ++it
)
560 sal_Int32 nPropDataBeginMark
= xMark
->createMark();
561 OutStream
->writeLong( 0L ); // DataLen
563 const css::uno::Any
* pProp
= &(maData
[*it
]);
564 OutStream
->writeShort( *it
);
566 bool bVoid
= pProp
->getValueType().getTypeClass() == css::uno::TypeClass_VOID
;
568 OutStream
->writeBoolean( bVoid
);
572 const css::uno::Any
& rValue
= *pProp
;
573 const css::uno::Type
& rType
= rValue
.getValueType();
575 if ( rType
== cppu::UnoType
< bool >::get() )
579 OutStream
->writeBoolean( b
);
581 else if ( rType
== ::cppu::UnoType
< OUString
>::get() )
585 OutStream
->writeUTF( aUString
);
587 else if ( rType
== ::cppu::UnoType
< ::cppu::UnoUnsignedShortType
>::get() )
591 OutStream
->writeShort( n
);
593 else if ( rType
== cppu::UnoType
<sal_Int16
>::get() )
597 OutStream
->writeShort( n
);
599 else if ( rType
== cppu::UnoType
<sal_uInt32
>::get() )
603 OutStream
->writeLong( n
);
605 else if ( rType
== cppu::UnoType
<sal_Int32
>::get() )
609 OutStream
->writeLong( n
);
611 else if ( rType
== cppu::UnoType
<double>::get() )
615 OutStream
->writeDouble( n
);
617 else if ( rType
== cppu::UnoType
< css::awt::FontDescriptor
>::get() )
619 css::awt::FontDescriptor aFD
;
621 OutStream
->writeUTF( aFD
.Name
);
622 OutStream
->writeShort( aFD
.Height
);
623 OutStream
->writeShort( aFD
.Width
);
624 OutStream
->writeUTF( aFD
.StyleName
);
625 OutStream
->writeShort( aFD
.Family
);
626 OutStream
->writeShort( aFD
.CharSet
);
627 OutStream
->writeShort( aFD
.Pitch
);
628 OutStream
->writeDouble( aFD
.CharacterWidth
);
629 OutStream
->writeDouble( aFD
.Weight
);
630 OutStream
->writeShort(
631 sal::static_int_cast
< sal_Int16
>(aFD
.Slant
) );
632 OutStream
->writeShort( aFD
.Underline
);
633 OutStream
->writeShort( aFD
.Strikeout
);
634 OutStream
->writeDouble( aFD
.Orientation
);
635 OutStream
->writeBoolean( aFD
.Kerning
);
636 OutStream
->writeBoolean( aFD
.WordLineMode
);
637 OutStream
->writeShort( aFD
.Type
);
639 else if ( rType
== cppu::UnoType
<css::util::Date
>::get() )
643 OutStream
->writeLong(d
.Day
+ 100 * d
.Month
+ 10000 * d
.Year
);
646 else if ( rType
== cppu::UnoType
<css::util::Time
>::get() )
650 OutStream
->writeLong(
651 t
.NanoSeconds
/ 1000000 + 100 * t
.Seconds
652 + 10000 * t
.Minutes
+ 1000000 * t
.Hours
); // HHMMSShh
654 else if ( rType
== cppu::UnoType
< css::uno::Sequence
< OUString
> >::get() )
656 css::uno::Sequence
< OUString
> aSeq
;
658 long nEntries
= aSeq
.getLength();
659 OutStream
->writeLong( nEntries
);
660 for ( long n
= 0; n
< nEntries
; n
++ )
661 OutStream
->writeUTF( aSeq
.getConstArray()[n
] );
663 else if ( rType
== cppu::UnoType
< cppu::UnoSequenceType
<cppu::UnoUnsignedShortType
> >::get() )
665 css::uno::Sequence
<sal_uInt16
> aSeq
;
667 long nEntries
= aSeq
.getLength();
668 OutStream
->writeLong( nEntries
);
669 for ( long n
= 0; n
< nEntries
; n
++ )
670 OutStream
->writeShort( aSeq
.getConstArray()[n
] );
672 else if ( rType
== cppu::UnoType
< css::uno::Sequence
<sal_Int16
> >::get() )
674 css::uno::Sequence
<sal_Int16
> aSeq
;
676 long nEntries
= aSeq
.getLength();
677 OutStream
->writeLong( nEntries
);
678 for ( long n
= 0; n
< nEntries
; n
++ )
679 OutStream
->writeShort( aSeq
.getConstArray()[n
] );
681 else if ( rType
.getTypeClass() == TypeClass_ENUM
)
683 sal_Int32 nAsInt
= 0;
684 ::cppu::enum2int( nAsInt
, rValue
);
685 OutStream
->writeLong( nAsInt
);
687 #if OSL_DEBUG_LEVEL > 0
690 OString
sMessage( "UnoControlModel::write: don't know how to handle a property of type '" );
691 OUString
sTypeName( rType
.getTypeName() );
692 sMessage
+= OString( sTypeName
.getStr(), sTypeName
.getLength(), RTL_TEXTENCODING_ASCII_US
);
693 sMessage
+= "'.\n(Currently handling property '";
694 const OUString
& sPropertyName( GetPropertyName( *it
) );
695 sMessage
+= OString( sPropertyName
.getStr(), sPropertyName
.getLength(), osl_getThreadTextEncoding() );
697 OSL_FAIL( sMessage
.getStr() );
702 sal_Int32 nPropDataLen
= xMark
->offsetToMark( nPropDataBeginMark
);
703 xMark
->jumpToMark( nPropDataBeginMark
);
704 OutStream
->writeLong( nPropDataLen
);
705 xMark
->jumpToFurthest();
706 xMark
->deleteMark(nPropDataBeginMark
);
709 if ( aProps
.find( BASEPROPERTY_FONTDESCRIPTOR
) != aProps
.end() )
711 const css::uno::Any
* pProp
= &maData
[ BASEPROPERTY_FONTDESCRIPTOR
];
712 // Until 5.0 export arrives, write old format..
713 css::awt::FontDescriptor aFD
;
716 for ( sal_uInt16 n
= BASEPROPERTY_FONT_TYPE
; n
<= BASEPROPERTY_FONT_ATTRIBS
; n
++ )
718 sal_Int32 nPropDataBeginMark
= xMark
->createMark();
719 OutStream
->writeLong( 0L ); // DataLen
720 OutStream
->writeShort( n
); // PropId
721 OutStream
->writeBoolean( false ); // Void
723 if ( n
== BASEPROPERTY_FONT_TYPE
)
725 OutStream
->writeUTF( aFD
.Name
);
726 OutStream
->writeUTF( aFD
.StyleName
);
727 OutStream
->writeShort( aFD
.Family
);
728 OutStream
->writeShort( aFD
.CharSet
);
729 OutStream
->writeShort( aFD
.Pitch
);
731 else if ( n
== BASEPROPERTY_FONT_SIZE
)
733 OutStream
->writeLong( aFD
.Width
);
734 OutStream
->writeLong( aFD
.Height
);
735 OutStream
->writeShort(
736 sal::static_int_cast
< sal_Int16
>(
737 vcl::unohelper::ConvertFontWidth(aFD
.CharacterWidth
)) );
739 else if ( n
== BASEPROPERTY_FONT_ATTRIBS
)
741 OutStream
->writeShort(
742 sal::static_int_cast
< sal_Int16
>(
743 vcl::unohelper::ConvertFontWeight(aFD
.Weight
)) );
744 OutStream
->writeShort(
745 sal::static_int_cast
< sal_Int16
>(aFD
.Slant
) );
746 OutStream
->writeShort( aFD
.Underline
);
747 OutStream
->writeShort( aFD
.Strikeout
);
748 OutStream
->writeShort( (short)(aFD
.Orientation
* 10) );
749 OutStream
->writeBoolean( aFD
.Kerning
);
750 OutStream
->writeBoolean( aFD
.WordLineMode
);
754 OSL_FAIL( "Property?!" );
757 sal_Int32 nPropDataLen
= xMark
->offsetToMark( nPropDataBeginMark
);
758 xMark
->jumpToMark( nPropDataBeginMark
);
759 OutStream
->writeLong( nPropDataLen
);
760 xMark
->jumpToFurthest();
761 xMark
->deleteMark(nPropDataBeginMark
);
766 void UnoControlModel::read( const css::uno::Reference
< css::io::XObjectInputStream
>& InStream
)
768 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
770 css::uno::Reference
< css::io::XMarkableStream
> xMark( InStream
, css::uno::UNO_QUERY
);
771 DBG_ASSERT( xMark
.is(), "read: no css::io::XMarkableStream!" );
773 short nVersion
= InStream
->readShort();
774 sal_uInt32 nProps
= (sal_uInt32
)InStream
->readLong();
775 css::uno::Sequence
< OUString
> aProps( nProps
);
776 css::uno::Sequence
< css::uno::Any
> aValues( nProps
);
777 bool bInvalidEntries
= false;
779 // Unfortunately, there's no mark for the whole block, thus only properties may be changed.
780 // No data for the model may be added following the properties
782 // Used for import of old parts in css::awt::FontDescriptor
783 css::awt::FontDescriptor
* pFD
= nullptr;
786 for ( i
= 0; i
< nProps
; i
++ )
788 sal_Int32 nPropDataBeginMark
= xMark
->createMark();
789 sal_Int32 nPropDataLen
= InStream
->readLong();
791 sal_uInt16 nPropId
= (sal_uInt16
)InStream
->readShort();
793 css::uno::Any aValue
;
794 bool bIsVoid
= InStream
->readBoolean();
797 if ( maData
.find( nPropId
) != maData
.end() )
799 const css::uno::Type
* pType
= GetPropertyType( nPropId
);
800 if ( *pType
== cppu::UnoType
<bool>::get() )
802 bool b
= InStream
->readBoolean();
805 else if ( *pType
== cppu::UnoType
<OUString
>::get() )
807 OUString aUTF
= InStream
->readUTF();
810 else if ( *pType
== ::cppu::UnoType
< ::cppu::UnoUnsignedShortType
>::get() )
812 sal_uInt16 n
= InStream
->readShort();
815 else if ( *pType
== cppu::UnoType
<sal_Int16
>::get() )
817 sal_Int16 n
= InStream
->readShort();
820 else if ( *pType
== cppu::UnoType
<sal_uInt32
>::get() )
822 sal_uInt32 n
= InStream
->readLong();
825 else if ( *pType
== cppu::UnoType
<sal_Int32
>::get() )
827 sal_Int32 n
= InStream
->readLong();
830 else if ( *pType
== cppu::UnoType
<double>::get() )
832 double n
= InStream
->readDouble();
835 else if ( *pType
== cppu::UnoType
< css::awt::FontDescriptor
>::get() )
837 css::awt::FontDescriptor aFD
;
838 aFD
.Name
= InStream
->readUTF();
839 aFD
.Height
= InStream
->readShort();
840 aFD
.Width
= InStream
->readShort();
841 aFD
.StyleName
= InStream
->readUTF();
842 aFD
.Family
= InStream
->readShort();
843 aFD
.CharSet
= InStream
->readShort();
844 aFD
.Pitch
= InStream
->readShort();
845 aFD
.CharacterWidth
= (float)InStream
->readDouble();
846 aFD
.Weight
= (float)InStream
->readDouble();
847 aFD
.Slant
= (css::awt::FontSlant
)InStream
->readShort();
848 aFD
.Underline
= InStream
->readShort();
849 aFD
.Strikeout
= InStream
->readShort();
850 aFD
.Orientation
= (float)InStream
->readDouble();
851 aFD
.Kerning
= InStream
->readBoolean() != 0;
852 aFD
.WordLineMode
= InStream
->readBoolean() != 0;
853 aFD
.Type
= InStream
->readShort();
856 else if ( *pType
== cppu::UnoType
<css::util::Date
>::get() )
858 sal_Int32 n
= InStream
->readLong(); // YYYYMMDD
859 aValue
<<= css::util::Date(
860 n
% 100, (n
/ 100) % 100, n
/ 10000);
862 else if ( *pType
== cppu::UnoType
<css::util::Time
>::get() )
864 sal_Int32 n
= InStream
->readLong(); // HHMMSShh
865 aValue
<<= css::util::Time(
866 (n
% 100) * 1000000, (n
/ 100) % 100, (n
/ 10000) % 100,
869 else if ( *pType
== cppu::UnoType
< css::uno::Sequence
< OUString
> >::get() )
871 long nEntries
= InStream
->readLong();
872 css::uno::Sequence
< OUString
> aSeq( nEntries
);
873 for ( long n
= 0; n
< nEntries
; n
++ )
874 aSeq
.getArray()[n
] = InStream
->readUTF();
878 else if ( *pType
== cppu::UnoType
< cppu::UnoSequenceType
<cppu::UnoUnsignedShortType
> >::get() )
881 long nEntries
= InStream
->readLong();
882 css::uno::Sequence
<sal_uInt16
> aSeq( nEntries
);
883 for ( long n
= 0; n
< nEntries
; n
++ )
884 aSeq
.getArray()[n
] = (sal_uInt16
)InStream
->readShort();
887 else if ( *pType
== cppu::UnoType
< css::uno::Sequence
<sal_Int16
> >::get() )
889 long nEntries
= InStream
->readLong();
890 css::uno::Sequence
<sal_Int16
> aSeq( nEntries
);
891 for ( long n
= 0; n
< nEntries
; n
++ )
892 aSeq
.getArray()[n
] = (sal_Int16
)InStream
->readShort();
895 else if ( pType
->getTypeClass() == TypeClass_ENUM
)
897 sal_Int32 nAsInt
= InStream
->readLong();
898 aValue
= ::cppu::int2enum( nAsInt
, *pType
);
902 OString
sMessage( "UnoControlModel::read: don't know how to handle a property of type '" );
903 OUString
sTypeName( pType
->getTypeName() );
904 sMessage
+= OString( sTypeName
.getStr(), sTypeName
.getLength(), RTL_TEXTENCODING_ASCII_US
);
905 sMessage
+= "'.\n(Currently handling property '";
906 const OUString
& sPropertyName( GetPropertyName( nPropId
) );
907 sMessage
+= OString( sPropertyName
.getStr(), sPropertyName
.getLength(), osl_getThreadTextEncoding() );
909 OSL_FAIL( sMessage
.getStr() );
914 // Old trash from 5.0
915 if ( nPropId
== BASEPROPERTY_FONT_TYPE
)
917 // Redundant information for older versions
918 // is skipped by MarkableStream
923 pFD
= new css::awt::FontDescriptor
;
924 if ( maData
.find( BASEPROPERTY_FONTDESCRIPTOR
) != maData
.end() ) // due to defaults...
925 maData
[ BASEPROPERTY_FONTDESCRIPTOR
] >>= *pFD
;
927 pFD
->Name
= InStream
->readUTF();
928 pFD
->StyleName
= InStream
->readUTF();
929 pFD
->Family
= InStream
->readShort();
930 pFD
->CharSet
= InStream
->readShort();
931 pFD
->Pitch
= InStream
->readShort();
934 else if ( nPropId
== BASEPROPERTY_FONT_SIZE
)
940 pFD
= new css::awt::FontDescriptor
;
941 if ( maData
.find(BASEPROPERTY_FONTDESCRIPTOR
) != maData
.end() ) // due to defaults...
942 maData
[BASEPROPERTY_FONTDESCRIPTOR
] >>= *pFD
;
944 pFD
->Width
= (sal_Int16
)InStream
->readLong();
945 pFD
->Height
= (sal_Int16
)InStream
->readLong();
946 InStream
->readShort(); // ignore css::awt::FontWidth - it was
947 // misspelled and is no longer needed
948 pFD
->CharacterWidth
= css::awt::FontWidth::DONTKNOW
;
951 else if ( nPropId
== BASEPROPERTY_FONT_ATTRIBS
)
957 pFD
= new css::awt::FontDescriptor
;
958 if ( maData
.find(BASEPROPERTY_FONTDESCRIPTOR
) != maData
.end() ) // due to defaults...
959 maData
[BASEPROPERTY_FONTDESCRIPTOR
] >>= *pFD
;
961 pFD
->Weight
= vcl::unohelper::ConvertFontWeight((FontWeight
) InStream
->readShort());
962 pFD
->Slant
= (css::awt::FontSlant
)InStream
->readShort();
963 pFD
->Underline
= InStream
->readShort();
964 pFD
->Strikeout
= InStream
->readShort();
965 pFD
->Orientation
= ( (float)(double)InStream
->readShort() ) / 10;
966 pFD
->Kerning
= InStream
->readBoolean() != 0;
967 pFD
->WordLineMode
= InStream
->readBoolean() != 0;
972 OSL_FAIL( "read: unknown Property!" );
978 if ( nPropId
== BASEPROPERTY_FONTDESCRIPTOR
)
980 EmptyFontDescriptor aFD
;
985 if ( maData
.find( nPropId
) != maData
.end() )
987 aProps
.getArray()[i
] = GetPropertyName( nPropId
);
988 aValues
.getArray()[i
] = aValue
;
992 bInvalidEntries
= true;
995 // Skip rest of input if there is more data in stream than this version can handle
996 xMark
->jumpToMark( nPropDataBeginMark
);
997 InStream
->skipBytes( nPropDataLen
);
998 xMark
->deleteMark(nPropDataBeginMark
);
1000 if ( bInvalidEntries
)
1002 for ( i
= 0; i
< (sal_uInt32
)aProps
.getLength(); i
++ )
1004 if ( aProps
.getConstArray()[i
].isEmpty() )
1006 ::comphelper::removeElementAt( aProps
, i
);
1007 ::comphelper::removeElementAt( aValues
, i
);
1015 setPropertyValues( aProps
, aValues
);
1017 catch ( const Exception
& )
1019 DBG_UNHANDLED_EXCEPTION();
1024 css::uno::Any aValue
;
1026 setPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR
), aValue
);
1032 // css::lang::XServiceInfo
1033 OUString
UnoControlModel::getImplementationName( )
1035 OSL_FAIL( "This method should be overridden!" );
1040 sal_Bool
UnoControlModel::supportsService( const OUString
& rServiceName
)
1042 return cppu::supportsService(this, rServiceName
);
1045 css::uno::Sequence
< OUString
> UnoControlModel::getSupportedServiceNames( )
1047 OUString
sName( "com.sun.star.awt.UnoControlModel" );
1048 return Sequence
< OUString
>( &sName
, 1 );
1051 sal_Bool
UnoControlModel::convertFastPropertyValue( Any
& rConvertedValue
, Any
& rOldValue
, sal_Int32 nPropId
, const Any
& rValue
)
1053 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1055 bool bVoid
= rValue
.getValueType().getTypeClass() == css::uno::TypeClass_VOID
;
1058 rConvertedValue
.clear();
1062 const css::uno::Type
* pDestType
= GetPropertyType( (sal_uInt16
)nPropId
);
1063 if ( pDestType
->getTypeClass() == TypeClass_ANY
)
1065 rConvertedValue
= rValue
;
1069 if ( pDestType
->equals( rValue
.getValueType() ) )
1071 rConvertedValue
= rValue
;
1075 bool bConverted
= false;
1076 // 13.03.2001 - 84923 - frank.schoenheit@germany.sun.com
1078 switch (pDestType
->getTypeClass())
1080 case TypeClass_DOUBLE
:
1083 double nAsDouble
= 0;
1084 bConverted
= ( rValue
>>= nAsDouble
);
1086 rConvertedValue
<<= nAsDouble
;
1089 sal_Int32 nAsInteger
= 0;
1090 bConverted
= ( rValue
>>= nAsInteger
);
1092 rConvertedValue
<<= (double)nAsInteger
;
1096 case TypeClass_SHORT
:
1099 bConverted
= ( rValue
>>= n
);
1101 rConvertedValue
<<= n
;
1104 case TypeClass_UNSIGNED_SHORT
:
1107 bConverted
= ( rValue
>>= n
);
1109 rConvertedValue
<<= n
;
1112 case TypeClass_LONG
:
1115 bConverted
= ( rValue
>>= n
);
1117 rConvertedValue
<<= n
;
1120 case TypeClass_UNSIGNED_LONG
:
1123 bConverted
= ( rValue
>>= n
);
1125 rConvertedValue
<<= n
;
1128 case TypeClass_INTERFACE
:
1130 if ( rValue
.getValueType().getTypeClass() == TypeClass_INTERFACE
)
1132 Reference
< XInterface
> xPure( rValue
, UNO_QUERY
);
1134 rConvertedValue
= xPure
->queryInterface( *pDestType
);
1136 rConvertedValue
.setValue( nullptr, *pDestType
);
1141 case TypeClass_ENUM
:
1143 sal_Int32 nValue
= 0;
1144 bConverted
= ( rValue
>>= nValue
);
1146 rConvertedValue
= ::cppu::int2enum( nValue
, *pDestType
);
1149 default: ; // avoid compiler warning
1154 throw css::lang::IllegalArgumentException(
1155 "Unable to convert the given value for the property "
1156 + GetPropertyName( (sal_uInt16
)nPropId
)
1157 + ".\nExpected type: " + pDestType
->getTypeName()
1158 + "\nFound type: " + rValue
.getValueType().getTypeName(),
1159 static_cast< css::beans::XPropertySet
* >(this),
1166 // the current value
1167 getFastPropertyValue( rOldValue
, nPropId
);
1168 return !CompareProperties( rConvertedValue
, rOldValue
);
1171 void UnoControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nPropId
, const css::uno::Any
& rValue
)
1173 // Missing: the fake solo properties of the FontDescriptor
1175 ImplPropertyTable::const_iterator it
= maData
.find( nPropId
);
1176 const css::uno::Any
* pProp
= it
== maData
.end() ? nullptr : &(it
->second
);
1177 ENSURE_OR_RETURN_VOID( pProp
, "UnoControlModel::setFastPropertyValue_NoBroadcast: invalid property id!" );
1179 DBG_ASSERT( ( rValue
.getValueType().getTypeClass() != css::uno::TypeClass_VOID
) || ( GetPropertyAttribs( (sal_uInt16
)nPropId
) & css::beans::PropertyAttribute::MAYBEVOID
), "Property should not be VOID!" );
1180 maData
[ nPropId
] = rValue
;
1183 void UnoControlModel::getFastPropertyValue( css::uno::Any
& rValue
, sal_Int32 nPropId
) const
1185 ::osl::Guard
< ::osl::Mutex
> aGuard( const_cast<UnoControlModel
*>(this)->GetMutex() );
1187 ImplPropertyTable::const_iterator it
= maData
.find( nPropId
);
1188 const css::uno::Any
* pProp
= it
== maData
.end() ? nullptr : &(it
->second
);
1192 else if ( ( nPropId
>= BASEPROPERTY_FONTDESCRIPTORPART_START
) && ( nPropId
<= BASEPROPERTY_FONTDESCRIPTORPART_END
) )
1194 pProp
= &( maData
.find( BASEPROPERTY_FONTDESCRIPTOR
)->second
);
1195 css::awt::FontDescriptor aFD
;
1199 case BASEPROPERTY_FONTDESCRIPTORPART_NAME
: rValue
<<= aFD
.Name
;
1201 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME
: rValue
<<= aFD
.StyleName
;
1203 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY
: rValue
<<= aFD
.Family
;
1205 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET
: rValue
<<= aFD
.CharSet
;
1207 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT
: rValue
<<= (float)aFD
.Height
;
1209 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT
: rValue
<<= aFD
.Weight
;
1211 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT
: rValue
<<= (sal_Int16
)aFD
.Slant
;
1213 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE
: rValue
<<= aFD
.Underline
;
1215 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT
: rValue
<<= aFD
.Strikeout
;
1217 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH
: rValue
<<= aFD
.Width
;
1219 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH
: rValue
<<= aFD
.Pitch
;
1221 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH
: rValue
<<= aFD
.CharacterWidth
;
1223 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION
: rValue
<<= aFD
.Orientation
;
1225 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING
: rValue
<<= aFD
.Kerning
;
1227 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE
: rValue
<<= aFD
.WordLineMode
;
1229 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE
: rValue
<<= aFD
.Type
;
1231 default: OSL_FAIL( "FontProperty?!" );
1236 OSL_FAIL( "getFastPropertyValue - invalid Property!" );
1240 // css::beans::XPropertySet
1241 void UnoControlModel::setPropertyValue( const OUString
& rPropertyName
, const css::uno::Any
& rValue
)
1243 sal_Int32 nPropId
= 0;
1245 ::osl::Guard
< ::osl::Mutex
> aGuard( GetMutex() );
1246 nPropId
= (sal_Int32
) GetPropertyId( rPropertyName
);
1247 DBG_ASSERT( nPropId
, "Invalid ID in UnoControlModel::setPropertyValue" );
1250 setFastPropertyValue( nPropId
, rValue
);
1252 throw css::beans::UnknownPropertyException();
1255 // css::beans::XFastPropertySet
1256 void UnoControlModel::setFastPropertyValue( sal_Int32 nPropId
, const css::uno::Any
& rValue
)
1258 if ( ( nPropId
>= BASEPROPERTY_FONTDESCRIPTORPART_START
) && ( nPropId
<= BASEPROPERTY_FONTDESCRIPTORPART_END
) )
1260 ::osl::ClearableMutexGuard
aGuard( GetMutex() );
1262 Any aOldSingleValue
;
1263 getFastPropertyValue( aOldSingleValue
, BASEPROPERTY_FONTDESCRIPTORPART_START
);
1265 css::uno::Any
* pProp
= &maData
[ BASEPROPERTY_FONTDESCRIPTOR
];
1266 FontDescriptor aOldFontDescriptor
;
1267 (*pProp
) >>= aOldFontDescriptor
;
1269 FontDescriptor
aNewFontDescriptor( aOldFontDescriptor
);
1270 lcl_ImplMergeFontProperty( aNewFontDescriptor
, (sal_uInt16
)nPropId
, rValue
);
1273 aNewValue
<<= aNewFontDescriptor
;
1274 sal_Int32
nDescriptorId( BASEPROPERTY_FONTDESCRIPTOR
);
1275 nDescriptorId
= BASEPROPERTY_FONTDESCRIPTOR
;
1277 // also, we need fire a propertyChange event for the single property, since with
1278 // the above line, only an event for the FontDescriptor property will be fired
1279 Any aNewSingleValue
;
1280 getFastPropertyValue( aNewSingleValue
, BASEPROPERTY_FONTDESCRIPTORPART_START
);
1283 setFastPropertyValues( 1, &nDescriptorId
, &aNewValue
, 1 );
1284 fire( &nPropId
, &aNewSingleValue
, &aOldSingleValue
, 1, false );
1287 setFastPropertyValues( 1, &nPropId
, &rValue
, 1 );
1290 // css::beans::XMultiPropertySet
1291 css::uno::Reference
< css::beans::XPropertySetInfo
> UnoControlModel::getPropertySetInfo( )
1293 OSL_FAIL( "UnoControlModel::getPropertySetInfo() not possible!" );
1294 return css::uno::Reference
< css::beans::XPropertySetInfo
>();
1297 void UnoControlModel::setPropertyValues( const css::uno::Sequence
< OUString
>& rPropertyNames
, const css::uno::Sequence
< css::uno::Any
>& Values
)
1299 ::osl::ClearableMutexGuard
aGuard( GetMutex() );
1301 sal_Int32 nProps
= rPropertyNames
.getLength();
1303 // sal_Int32* pHandles = new sal_Int32[nProps];
1304 // don't do this - it leaks in case of an exception
1305 Sequence
< sal_Int32
> aHandles( nProps
);
1306 sal_Int32
* pHandles
= aHandles
.getArray();
1308 // may need to change the order in the sequence, for this we need a non-const value sequence
1309 uno::Sequence
< uno::Any
> aValues( Values
);
1310 uno::Any
* pValues
= aValues
.getArray();
1312 sal_Int32 nValidHandles
= getInfoHelper().fillHandles( pHandles
, rPropertyNames
);
1314 if ( nValidHandles
)
1316 // if somebody sets properties which are single aspects of a font descriptor,
1317 // remove them, and build a font descriptor instead
1318 std::unique_ptr
< awt::FontDescriptor
> pFD
;
1319 for ( sal_Int32 n
= 0; n
< nProps
; ++n
)
1321 if ( ( pHandles
[n
] >= BASEPROPERTY_FONTDESCRIPTORPART_START
) && ( pHandles
[n
] <= BASEPROPERTY_FONTDESCRIPTORPART_END
) )
1325 css::uno::Any
* pProp
= &maData
[ BASEPROPERTY_FONTDESCRIPTOR
];
1326 pFD
.reset( new awt::FontDescriptor
);
1329 lcl_ImplMergeFontProperty( *pFD
, (sal_uInt16
)pHandles
[n
], pValues
[n
] );
1335 if ( nValidHandles
)
1337 ImplNormalizePropertySequence( nProps
, pHandles
, pValues
, &nValidHandles
);
1339 // clear our guard before calling into setFastPropertyValues - this method
1340 // will implicitly call property listeners, and this should not happen with
1343 setFastPropertyValues( nProps
, pHandles
, pValues
, nValidHandles
);
1347 // same as a few lines above
1349 // Don't merge FD property into array, as it is sorted
1352 css::uno::Any aValue
;
1354 sal_Int32 nHandle
= BASEPROPERTY_FONTDESCRIPTOR
;
1355 setFastPropertyValues( 1, &nHandle
, &aValue
, 1 );
1361 void UnoControlModel::ImplNormalizePropertySequence( const sal_Int32
, sal_Int32
*,
1362 uno::Any
*, sal_Int32
* ) const
1364 // nothing to do here
1367 void UnoControlModel::ImplEnsureHandleOrder( const sal_Int32 _nCount
, sal_Int32
* _pHandles
,
1368 uno::Any
* _pValues
, sal_Int32 _nFirstHandle
, sal_Int32 _nSecondHandle
)
1370 for ( sal_Int32 i
=0; i
< _nCount
; ++_pHandles
, ++_pValues
, ++i
)
1372 if ( _nSecondHandle
== *_pHandles
)
1374 sal_Int32
* pLaterHandles
= _pHandles
+ 1;
1375 uno::Any
* pLaterValues
= _pValues
+ 1;
1376 for ( sal_Int32 j
= i
+ 1; j
< _nCount
; ++j
, ++pLaterHandles
, ++pLaterValues
)
1378 if ( _nFirstHandle
== *pLaterHandles
)
1380 // indeed it is -> exchange the both places in the sequences
1381 sal_Int32
nHandle( *_pHandles
);
1382 *_pHandles
= *pLaterHandles
;
1383 *pLaterHandles
= nHandle
;
1385 uno::Any
aValue( *_pValues
);
1386 *_pValues
= *pLaterValues
;
1387 *pLaterValues
= aValue
;
1390 // this will leave the inner loop, and continue with the outer loop.
1391 // Note that this means we will encounter the _nSecondHandle handle, again, once we reached
1392 // (in the outer loop) the place where we just put it.
1399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */