LibreOffice Module toolkit (master) 1
unocontrolmodel.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
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/FontSlant.hpp>
25#include <com/sun/star/awt/MouseWheelBehavior.hpp>
26#include <com/sun/star/graphic/XGraphic.hpp>
27#include <com/sun/star/awt/XDevice.hpp>
28#include <com/sun/star/text/WritingMode2.hpp>
29#include <com/sun/star/io/XMarkableStream.hpp>
30#include <com/sun/star/i18n/Currency2.hpp>
31#include <com/sun/star/util/Date.hpp>
32#include <com/sun/star/util/Time.hpp>
35#include <sal/log.hxx>
37#include <tools/debug.hxx>
38#include <tools/long.hxx>
39#include <helper/property.hxx>
46#include <vcl/unohelp.hxx>
47
48#include <memory>
50
51using namespace ::com::sun::star;
52using namespace ::com::sun::star::uno;
53using namespace ::com::sun::star::lang;
54using namespace ::com::sun::star::i18n;
55using ::com::sun::star::awt::FontDescriptor;
56
57
58#define UNOCONTROL_STREAMVERSION short(2)
59
60static void lcl_ImplMergeFontProperty( FontDescriptor& rFD, sal_uInt16 nPropId, const Any& rValue )
61{
62 // some props are defined with other types than the matching FontDescriptor members have
63 // (e.g. FontWidth, FontSlant)
64 // 78474 - 09/19/2000 - FS
65 float nExtractFloat = 0;
66 sal_Int16 nExtractShort = 0;
67
68 switch ( nPropId )
69 {
70 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: rValue >>= rFD.Name;
71 break;
72 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: rValue >>= rFD.StyleName;
73 break;
74 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: rValue >>= rFD.Family;
75 break;
76 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: rValue >>= rFD.CharSet;
77 break;
78 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: rValue >>= nExtractFloat; rFD.Height = static_cast<sal_Int16>(nExtractFloat);
79 break;
80 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: rValue >>= rFD.Weight;
81 break;
82 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: if ( rValue >>= nExtractShort )
83 rFD.Slant = static_cast<css::awt::FontSlant>(nExtractShort);
84 else
85 rValue >>= rFD.Slant;
86 break;
87 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: rValue >>= rFD.Underline;
88 break;
89 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: rValue >>= rFD.Strikeout;
90 break;
91 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: rValue >>= rFD.Width;
92 break;
93 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: rValue >>= rFD.Pitch;
94 break;
95 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: rValue >>= rFD.CharacterWidth;
96 break;
97 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: rValue >>= rFD.Orientation;
98 break;
99 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: rValue >>= rFD.Kerning;
100 break;
101 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: rValue >>= rFD.WordLineMode;
102 break;
103 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: rValue >>= rFD.Type;
104 break;
105 default: OSL_FAIL( "FontProperty?!" );
106 }
107}
108
109
110
111UnoControlModel::UnoControlModel( const Reference< XComponentContext >& rxContext )
113 ,maDisposeListeners( *this )
114 ,m_xContext( rxContext )
115{
116 // Insert properties from Model into table,
117 // only existing properties are valid, even if they're VOID
118}
119
121 : UnoControlModel_Base(), OPropertySetHelper()
122 , maData( rModel.maData )
123 , maDisposeListeners( *this )
124 , m_xContext( rModel.m_xContext )
125{
126}
127
128css::uno::Sequence<sal_Int32> UnoControlModel::ImplGetPropertyIds() const
129{
130 sal_uInt32 nIDs = maData.size();
131 css::uno::Sequence<sal_Int32> aIDs( nIDs );
132 sal_Int32* pIDs = aIDs.getArray();
133 sal_uInt32 n = 0;
134 for ( const auto& rData : maData )
135 pIDs[n++] = rData.first;
136 return aIDs;
137}
138
139bool UnoControlModel::ImplHasProperty( sal_uInt16 nPropId ) const
140{
143
144 return maData.find( nPropId ) != maData.end();
145}
146
147css::uno::Any UnoControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
148{
149 css::uno::Any aDefault;
150
151 if (
152 (nPropId == BASEPROPERTY_FONTDESCRIPTOR) ||
153 (
156 )
157 )
158 {
160 switch ( nPropId )
161 {
162 case BASEPROPERTY_FONTDESCRIPTOR: aDefault <<= aFD; break;
163 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: aDefault <<= aFD.Name; break;
164 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: aDefault <<= aFD.StyleName; break;
165 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: aDefault <<= aFD.Family; break;
166 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: aDefault <<= aFD.CharSet; break;
167 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: aDefault <<= static_cast<float>(aFD.Height); break;
168 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: aDefault <<= aFD.Weight; break;
169 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: aDefault <<= static_cast<sal_Int16>(aFD.Slant); break;
170 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: aDefault <<= aFD.Underline; break;
171 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: aDefault <<= aFD.Strikeout; break;
172 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: aDefault <<= aFD.Width; break;
173 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: aDefault <<= aFD.Pitch; break;
174 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: aDefault <<= aFD.CharacterWidth; break;
175 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: aDefault <<= aFD.Orientation; break;
176 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: aDefault <<= aFD.Kerning; break;
177 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: aDefault <<= aFD.WordLineMode; break;
178 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: aDefault <<= aFD.Type; break;
179 default: OSL_FAIL( "FontProperty?!" );
180 }
181 }
182 else
183 {
184 switch ( nPropId )
185 {
187 aDefault <<= Reference< graphic::XGraphic >();
188 break;
189
191 aDefault <<= Reference< awt::XDevice >();
192 break;
193
211 case BASEPROPERTY_HIGHLIGHT_TEXT_COLOR: break; // Void
212
219 case BASEPROPERTY_ECHOCHAR: aDefault <<= sal_Int16(0); break;
220 case BASEPROPERTY_BORDER: aDefault <<= sal_Int16(1); break;
221 case BASEPROPERTY_DECIMALACCURACY: aDefault <<= sal_Int16(2); break;
222 case BASEPROPERTY_LINECOUNT: aDefault <<= sal_Int16(5); break;
223 case BASEPROPERTY_ALIGN: aDefault <<= sal_Int16(PROPERTY_ALIGN_LEFT); break;
224 case BASEPROPERTY_IMAGEALIGN: aDefault <<= sal_Int16(1) /*ImageAlign::Top*/; break;
225 case BASEPROPERTY_IMAGEPOSITION: aDefault <<= sal_Int16(12) /*ImagePosition::Centered*/; break;
226 case BASEPROPERTY_PUSHBUTTONTYPE: aDefault <<= sal_Int16(0) /*PushButtonType::STANDARD*/; break;
227 case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR:aDefault <<= sal_Int16(awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY); break;
228
229 case BASEPROPERTY_DATEMAX: aDefault <<= util::Date( 31, 12, 2200 ); break;
230 case BASEPROPERTY_DATEMIN: aDefault <<= util::Date( 1, 1, 1900 ); break;
231 case BASEPROPERTY_TIMEMAX: aDefault <<= util::Time(0, 0, 59, 23, false); break;
232 case BASEPROPERTY_TIMEMIN: aDefault <<= util::Time(); break;
233 case BASEPROPERTY_VALUEMAX_DOUBLE: aDefault <<= double(1000000); break;
234 case BASEPROPERTY_VALUEMIN_DOUBLE: aDefault <<= double(-1000000); break;
235 case BASEPROPERTY_VALUESTEP_DOUBLE: aDefault <<= double(1); break;
236 case BASEPROPERTY_PROGRESSVALUE_MAX: aDefault <<= sal_Int32(100); break;
237 case BASEPROPERTY_PROGRESSVALUE_MIN: aDefault <<= sal_Int32(0); break;
238 case BASEPROPERTY_SCROLLVALUE_MAX: aDefault <<= sal_Int32(100); break;
239 case BASEPROPERTY_SCROLLVALUE_MIN: aDefault <<= sal_Int32(0); break;
240 case BASEPROPERTY_LINEINCREMENT: aDefault <<= sal_Int32(1); break;
241 case BASEPROPERTY_BLOCKINCREMENT: aDefault <<= sal_Int32(10); break;
242 case BASEPROPERTY_ORIENTATION: aDefault <<= sal_Int32(0); break;
243 case BASEPROPERTY_SPINVALUE: aDefault <<= sal_Int32(0); break;
244 case BASEPROPERTY_SPININCREMENT: aDefault <<= sal_Int32(1); break;
245 case BASEPROPERTY_SPINVALUE_MIN: aDefault <<= sal_Int32(0); break;
246 case BASEPROPERTY_SPINVALUE_MAX: aDefault <<= sal_Int32(100); break;
247 case BASEPROPERTY_REPEAT_DELAY: aDefault <<= sal_Int32(50); break; // 50 milliseconds
248 case BASEPROPERTY_DEFAULTCONTROL: aDefault <<= const_cast<UnoControlModel*>(this)->getServiceName(); break;
249
270 case BASEPROPERTY_NOLABEL: aDefault <<= false; break;
271
280 case BASEPROPERTY_DECORATION: aDefault <<= true; break;
281
291 case BASEPROPERTY_TEXT: aDefault <<= OUString(); break;
292
295 aDefault <<= text::WritingMode2::CONTEXT;
296 break;
297
299 {
300 css::uno::Sequence< OUString> aStringSeq;
301 aDefault <<= aStringSeq;
302
303 }
304 break;
306 {
307 css::uno::Sequence< css::uno::Any > aAnySeq;
308 aDefault <<= aAnySeq;
309
310 }
311 break;
313 {
314 css::uno::Sequence<sal_Int16> aINT16Seq;
315 aDefault <<= aINT16Seq;
316 }
317 break;
319 {
320 OUString sDefaultCurrency(
322
323 // extract the bank symbol
324 sal_Int32 nSepPos = sDefaultCurrency.indexOf( '-' );
325 OUString sBankSymbol;
326 if ( nSepPos >= 0 )
327 {
328 sBankSymbol = sDefaultCurrency.copy( 0, nSepPos );
329 sDefaultCurrency = sDefaultCurrency.copy( nSepPos + 1 );
330 }
331
332 // the remaining is the locale
333 LocaleDataWrapper aLocaleInfo( m_xContext, LanguageTag(sDefaultCurrency) );
334 if ( sBankSymbol.isEmpty() )
335 sBankSymbol = aLocaleInfo.getCurrBankSymbol();
336
337 // look for the currency entry (for this language) which has the given bank symbol
338 const Sequence< Currency2 > aAllCurrencies = aLocaleInfo.getAllCurrencies();
339
340 OUString sCurrencySymbol = aLocaleInfo.getCurrSymbol();
341 if ( sBankSymbol.isEmpty() )
342 {
343 DBG_ASSERT( aAllCurrencies.hasElements(), "UnoControlModel::ImplGetDefaultValue: no currencies at all!" );
344 if ( aAllCurrencies.hasElements() )
345 {
346 sBankSymbol = aAllCurrencies[0].BankSymbol;
347 sCurrencySymbol = aAllCurrencies[0].Symbol;
348 }
349 }
350
351 if ( !sBankSymbol.isEmpty() )
352 {
353 bool bLegacy = false;
354 bool bFound = false;
355 for ( const Currency2& rCurrency : aAllCurrencies )
356 if ( rCurrency.BankSymbol == sBankSymbol )
357 {
358 sCurrencySymbol = rCurrency.Symbol;
359 if ( rCurrency.LegacyOnly )
360 bLegacy = true;
361 else
362 {
363 bFound = true;
364 break;
365 }
366 }
367 DBG_ASSERT( bLegacy || bFound, "UnoControlModel::ImplGetDefaultValue: did not find the given bank symbol!" );
368 }
369
370 aDefault <<= sCurrencySymbol;
371 }
372 break;
373
374 default: OSL_FAIL( "ImplGetDefaultValue - unknown Property" );
375 }
376 }
377
378 return aDefault;
379}
380
381void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId, const css::uno::Any& rDefault )
382{
383 maData[ nPropId ] = rDefault;
384}
385
387{
388 ImplRegisterProperty( nPropId, ImplGetDefaultValue( nPropId ) );
389
390 if ( nPropId == BASEPROPERTY_FONTDESCRIPTOR )
391 {
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, instead everywhere where I register the FontDescriptor...
395
400 }
401}
402
403void UnoControlModel::ImplRegisterProperties( const std::vector< sal_uInt16 > &rIds )
404{
405 for (const auto& rId : rIds)
406 {
407 if( !ImplHasProperty( rId ) )
409 }
410}
411
412// css::uno::XInterface
413css::uno::Any UnoControlModel::queryAggregation( const css::uno::Type & rType )
414{
416 if ( !aRet.hasValue() )
418 return aRet;
419}
420
421// XInterface
423
424// css::lang::XTypeProvider
426
427
428uno::Reference< util::XCloneable > UnoControlModel::createClone()
429{
431 return pClone;
432}
433
434// css::lang::XComponent
436{
437 std::unique_lock aGuard( m_aMutex );
438
439 css::lang::EventObject aEvt;
440 aEvt.Source = static_cast<css::uno::XAggregation*>(static_cast<cppu::OWeakAggObject*>(this));
441 maDisposeListeners.disposeAndClear( aGuard, aEvt );
442
443 // let the property set helper notify our property listeners
444 OPropertySetHelper::disposing(aGuard);
445}
446
447void UnoControlModel::addEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener )
448{
449 std::unique_lock aGuard( m_aMutex );
450
451 maDisposeListeners.addInterface( rxListener );
452}
453
454void UnoControlModel::removeEventListener( const css::uno::Reference< css::lang::XEventListener >& rxListener )
455{
456 std::unique_lock aGuard( m_aMutex );
457
458 maDisposeListeners.removeInterface( rxListener );
459}
460
461
462// css::beans::XPropertyState
463css::beans::PropertyState UnoControlModel::getPropertyState( const OUString& PropertyName )
464{
465 std::unique_lock aGuard( m_aMutex );
466 return getPropertyStateImpl(aGuard, PropertyName);
467}
468
469css::beans::PropertyState UnoControlModel::getPropertyStateImpl( std::unique_lock<std::mutex>& rGuard, const OUString& PropertyName )
470{
471 sal_uInt16 nPropId = GetPropertyId( PropertyName );
472
473 css::uno::Any aValue = getPropertyValueImpl( rGuard, PropertyName );
474 css::uno::Any aDefault = ImplGetDefaultValue( nPropId );
475
476 return CompareProperties( aValue, aDefault ) ? css::beans::PropertyState_DEFAULT_VALUE : css::beans::PropertyState_DIRECT_VALUE;
477}
478
479css::uno::Sequence< css::beans::PropertyState > UnoControlModel::getPropertyStates( const css::uno::Sequence< OUString >& PropertyNames )
480{
481 std::unique_lock aGuard( m_aMutex );
482
483 sal_Int32 nNames = PropertyNames.getLength();
484
485 css::uno::Sequence< css::beans::PropertyState > aStates( nNames );
486
487 std::transform(PropertyNames.begin(), PropertyNames.end(), aStates.getArray(),
488 [this, &aGuard](const OUString& rName) -> css::beans::PropertyState
489 { return getPropertyStateImpl(aGuard, rName); });
490
491 return aStates;
492}
493
494void UnoControlModel::setPropertyToDefault( const OUString& PropertyName )
495{
496 Any aDefaultValue;
497 {
498 std::unique_lock aGuard( m_aMutex );
499 aDefaultValue = ImplGetDefaultValue( GetPropertyId( PropertyName ) );
500 }
501 setPropertyValue( PropertyName, aDefaultValue );
502}
503
504css::uno::Any UnoControlModel::getPropertyDefault( const OUString& rPropertyName )
505{
506 std::unique_lock aGuard( m_aMutex );
507
508 return ImplGetDefaultValue( GetPropertyId( rPropertyName ) );
509}
510
511
512// css::io::XPersistObjec
514{
515 OSL_FAIL( "ServiceName of UnoControlModel ?!" );
516 return OUString();
517}
518
519void UnoControlModel::write( const css::uno::Reference< css::io::XObjectOutputStream >& OutStream )
520{
521 std::unique_lock aGuard( m_aMutex );
522
523 css::uno::Reference< css::io::XMarkableStream > xMark( OutStream, css::uno::UNO_QUERY );
524 DBG_ASSERT( xMark.is(), "write: no css::io::XMarkableStream!" );
525
526 OutStream->writeShort( UNOCONTROL_STREAMVERSION );
527
529
530 for (const auto& rData : maData)
531 {
532 if ( ( ( GetPropertyAttribs( rData.first ) & css::beans::PropertyAttribute::TRANSIENT ) == 0 )
533 && ( getPropertyStateImpl( aGuard, GetPropertyName( rData.first ) ) != css::beans::PropertyState_DEFAULT_VALUE ) )
534 {
535 aProps.insert( rData.first );
536 }
537 }
538
539 sal_uInt32 nProps = aProps.size();
540
541 // Save FontProperty always in the old format (due to missing distinction
542 // between 5.0 and 5.1)
543 OutStream->writeLong( ( aProps.find( BASEPROPERTY_FONTDESCRIPTOR ) != aProps.end() ) ? ( nProps + 3 ) : nProps );
544 for ( const auto& rProp : aProps )
545 {
546 sal_Int32 nPropDataBeginMark = xMark->createMark();
547 OutStream->writeLong( 0 ); // DataLen
548
549 const css::uno::Any* pProp = &(maData[rProp]);
550 OutStream->writeShort( rProp );
551
552 bool bVoid = pProp->getValueType().getTypeClass() == css::uno::TypeClass_VOID;
553
554 OutStream->writeBoolean( bVoid );
555
556 if ( !bVoid )
557 {
558 const css::uno::Any& rValue = *pProp;
559 const css::uno::Type& rType = rValue.getValueType();
560
561 if ( rType == cppu::UnoType< bool >::get() )
562 {
563 bool b = false;
564 rValue >>= b;
565 OutStream->writeBoolean( b );
566 }
567 else if ( rType == ::cppu::UnoType< OUString >::get() )
568 {
569 OUString aUString;
570 rValue >>= aUString;
571 OutStream->writeUTF( aUString );
572 }
574 {
575 sal_uInt16 n = 0;
576 rValue >>= n;
577 OutStream->writeShort( n );
578 }
579 else if ( rType == cppu::UnoType<sal_Int16>::get() )
580 {
581 sal_Int16 n = 0;
582 rValue >>= n;
583 OutStream->writeShort( n );
584 }
585 else if ( rType == cppu::UnoType<sal_uInt32>::get() )
586 {
587 sal_uInt32 n = 0;
588 rValue >>= n;
589 OutStream->writeLong( n );
590 }
591 else if ( rType == cppu::UnoType<sal_Int32>::get() )
592 {
593 sal_Int32 n = 0;
594 rValue >>= n;
595 OutStream->writeLong( n );
596 }
597 else if ( rType == cppu::UnoType<double>::get() )
598 {
599 double n = 0;
600 rValue >>= n;
601 OutStream->writeDouble( n );
602 }
604 {
605 css::awt::FontDescriptor aFD;
606 rValue >>= aFD;
607 OutStream->writeUTF( aFD.Name );
608 OutStream->writeShort( aFD.Height );
609 OutStream->writeShort( aFD.Width );
610 OutStream->writeUTF( aFD.StyleName );
611 OutStream->writeShort( aFD.Family );
612 OutStream->writeShort( aFD.CharSet );
613 OutStream->writeShort( aFD.Pitch );
614 OutStream->writeDouble( aFD.CharacterWidth );
615 OutStream->writeDouble( aFD.Weight );
616 OutStream->writeShort(
617 sal::static_int_cast< sal_Int16 >(aFD.Slant) );
618 OutStream->writeShort( aFD.Underline );
619 OutStream->writeShort( aFD.Strikeout );
620 OutStream->writeDouble( aFD.Orientation );
621 OutStream->writeBoolean( aFD.Kerning );
622 OutStream->writeBoolean( aFD.WordLineMode );
623 OutStream->writeShort( aFD.Type );
624 }
625 else if ( rType == cppu::UnoType<css::util::Date>::get() )
626 {
627 css::util::Date d;
628 rValue >>= d;
629 OutStream->writeLong(d.Day + 100 * d.Month + 10000 * d.Year);
630 // YYYYMMDD
631 }
632 else if ( rType == cppu::UnoType<css::util::Time>::get() )
633 {
634 css::util::Time t;
635 rValue >>= t;
636 OutStream->writeLong(
637 t.NanoSeconds / 1000000 + 100 * t.Seconds
638 + 10000 * t.Minutes + 1000000 * t.Hours); // HHMMSShh
639 }
640 else if ( rType == cppu::UnoType< css::uno::Sequence< OUString> >::get() )
641 {
642 css::uno::Sequence< OUString> aSeq;
643 rValue >>= aSeq;
644 tools::Long nEntries = aSeq.getLength();
645 OutStream->writeLong( nEntries );
646 for ( const auto& rVal : std::as_const(aSeq) )
647 OutStream->writeUTF( rVal );
648 }
650 {
651 css::uno::Sequence<sal_uInt16> aSeq;
652 rValue >>= aSeq;
653 tools::Long nEntries = aSeq.getLength();
654 OutStream->writeLong( nEntries );
655 for ( const auto nVal : std::as_const(aSeq) )
656 OutStream->writeShort( nVal );
657 }
658 else if ( rType == cppu::UnoType< css::uno::Sequence<sal_Int16> >::get() )
659 {
660 css::uno::Sequence<sal_Int16> aSeq;
661 rValue >>= aSeq;
662 tools::Long nEntries = aSeq.getLength();
663 OutStream->writeLong( nEntries );
664 for ( const auto nVal : std::as_const(aSeq) )
665 OutStream->writeShort( nVal );
666 }
667 else if ( rType.getTypeClass() == TypeClass_ENUM )
668 {
669 sal_Int32 nAsInt = 0;
670 ::cppu::enum2int( nAsInt, rValue );
671 OutStream->writeLong( nAsInt );
672 }
673#if OSL_DEBUG_LEVEL > 0
674 else
675 {
676 SAL_WARN( "toolkit", "UnoControlModel::write: don't know how to handle a property of type '"
677 << rType.getTypeName()
678 << "'.\n(Currently handling property '"
679 << GetPropertyName( rProp )
680 << "'.)");
681 }
682#endif
683 }
684
685 sal_Int32 nPropDataLen = xMark->offsetToMark( nPropDataBeginMark );
686 xMark->jumpToMark( nPropDataBeginMark );
687 OutStream->writeLong( nPropDataLen );
688 xMark->jumpToFurthest();
689 xMark->deleteMark(nPropDataBeginMark);
690 }
691
692 if ( aProps.find( BASEPROPERTY_FONTDESCRIPTOR ) == aProps.end() )
693 return;
694
695 const css::uno::Any* pProp = &maData[ BASEPROPERTY_FONTDESCRIPTOR ];
696 // Until 5.0 export arrives, write old format...
697 css::awt::FontDescriptor aFD;
698 (*pProp) >>= aFD;
699
700 for ( sal_uInt16 n = BASEPROPERTY_FONT_TYPE; n <= BASEPROPERTY_FONT_ATTRIBS; n++ )
701 {
702 sal_Int32 nPropDataBeginMark = xMark->createMark();
703 OutStream->writeLong( 0 ); // DataLen
704 OutStream->writeShort( n ); // PropId
705 OutStream->writeBoolean( false ); // Void
706
707 if ( n == BASEPROPERTY_FONT_TYPE )
708 {
709 OutStream->writeUTF( aFD.Name );
710 OutStream->writeUTF( aFD.StyleName );
711 OutStream->writeShort( aFD.Family );
712 OutStream->writeShort( aFD.CharSet );
713 OutStream->writeShort( aFD.Pitch );
714 }
715 else if ( n == BASEPROPERTY_FONT_SIZE )
716 {
717 OutStream->writeLong( aFD.Width );
718 OutStream->writeLong( aFD.Height );
719 OutStream->writeShort(
720 sal::static_int_cast< sal_Int16 >(
721 vcl::unohelper::ConvertFontWidth(aFD.CharacterWidth)) );
722 }
723 else if ( n == BASEPROPERTY_FONT_ATTRIBS )
724 {
725 OutStream->writeShort(
726 sal::static_int_cast< sal_Int16 >(
728 OutStream->writeShort(
729 sal::static_int_cast< sal_Int16 >(aFD.Slant) );
730 OutStream->writeShort( aFD.Underline );
731 OutStream->writeShort( aFD.Strikeout );
732 OutStream->writeShort( static_cast<short>(aFD.Orientation * 10) );
733 OutStream->writeBoolean( aFD.Kerning );
734 OutStream->writeBoolean( aFD.WordLineMode );
735 }
736 else
737 {
738 OSL_FAIL( "Property?!" );
739 }
740
741 sal_Int32 nPropDataLen = xMark->offsetToMark( nPropDataBeginMark );
742 xMark->jumpToMark( nPropDataBeginMark );
743 OutStream->writeLong( nPropDataLen );
744 xMark->jumpToFurthest();
745 xMark->deleteMark(nPropDataBeginMark);
746 }
747}
748
749void UnoControlModel::read( const css::uno::Reference< css::io::XObjectInputStream >& InStream )
750{
751 std::unique_lock aGuard( m_aMutex );
752
753 css::uno::Reference< css::io::XMarkableStream > xMark( InStream, css::uno::UNO_QUERY );
754 DBG_ASSERT( xMark.is(), "read: no css::io::XMarkableStream!" );
755
756 short nVersion = InStream->readShort();
757 sal_uInt32 nProps = static_cast<sal_uInt32>(InStream->readLong());
758 css::uno::Sequence< OUString> aProps( nProps );
759 css::uno::Sequence< css::uno::Any> aValues( nProps );
760 bool bInvalidEntries = false;
761
762 // Unfortunately, there's no mark for the whole block, thus only properties may be changed.
763 // No data for the model may be added following the properties
764
765 // Used for import of old parts in css::awt::FontDescriptor
766 std::unique_ptr<css::awt::FontDescriptor> pFD;
767
768 for ( sal_uInt32 i = 0; i < nProps; i++ )
769 {
770 sal_Int32 nPropDataBeginMark = xMark->createMark();
771 sal_Int32 nPropDataLen = InStream->readLong();
772
773 sal_uInt16 nPropId = static_cast<sal_uInt16>(InStream->readShort());
774
775 css::uno::Any aValue;
776 bool bIsVoid = InStream->readBoolean();
777 if ( !bIsVoid )
778 {
779 if ( maData.find( nPropId ) != maData.end() )
780 {
781 const css::uno::Type* pType = GetPropertyType( nPropId );
782 if ( *pType == cppu::UnoType<bool>::get() )
783 {
784 bool b = InStream->readBoolean();
785 aValue <<= b;
786 }
787 else if ( *pType == cppu::UnoType<OUString>::get() )
788 {
789 OUString aUTF = InStream->readUTF();
790 aValue <<= aUTF;
791 }
793 {
794 sal_uInt16 n = InStream->readShort();
795 aValue <<= n;
796 }
797 else if ( *pType == cppu::UnoType<sal_Int16>::get() )
798 {
799 sal_Int16 n = InStream->readShort();
800 aValue <<= n;
801 }
802 else if ( *pType == cppu::UnoType<sal_uInt32>::get() )
803 {
804 sal_uInt32 n = InStream->readLong();
805 aValue <<= n;
806 }
807 else if ( *pType == cppu::UnoType<sal_Int32>::get() )
808 {
809 sal_Int32 n = InStream->readLong();
810 aValue <<= n;
811 }
812 else if ( *pType == cppu::UnoType<double>::get() )
813 {
814 double n = InStream->readDouble();
815 aValue <<= n;
816 }
818 {
819 css::awt::FontDescriptor aFD;
820 aFD.Name = InStream->readUTF();
821 aFD.Height = InStream->readShort();
822 aFD.Width = InStream->readShort();
823 aFD.StyleName = InStream->readUTF();
824 aFD.Family = InStream->readShort();
825 aFD.CharSet = InStream->readShort();
826 aFD.Pitch = InStream->readShort();
827 aFD.CharacterWidth = static_cast<float>(InStream->readDouble());
828 aFD.Weight = static_cast<float>(InStream->readDouble());
829 aFD.Slant = static_cast<css::awt::FontSlant>(InStream->readShort());
830 aFD.Underline = InStream->readShort();
831 aFD.Strikeout = InStream->readShort();
832 aFD.Orientation = static_cast<float>(InStream->readDouble());
833 aFD.Kerning = InStream->readBoolean() != 0;
834 aFD.WordLineMode = InStream->readBoolean() != 0;
835 aFD.Type = InStream->readShort();
836 aValue <<= aFD;
837 }
838 else if ( *pType == cppu::UnoType<css::util::Date>::get() )
839 {
840 sal_Int32 n = InStream->readLong(); // YYYYMMDD
841 aValue <<= css::util::Date(
842 n % 100, (n / 100) % 100, n / 10000);
843 }
844 else if ( *pType == cppu::UnoType<css::util::Time>::get() )
845 {
846 sal_Int32 n = InStream->readLong(); // HHMMSShh
847 aValue <<= css::util::Time(
848 (n % 100) * 1000000, (n / 100) % 100, (n / 10000) % 100,
849 n / 1000000, false);
850 }
851 else if ( *pType == cppu::UnoType< css::uno::Sequence< OUString> >::get() )
852 {
853 tools::Long nEntries = InStream->readLong();
854 css::uno::Sequence< OUString> aSeq( nEntries );
855 for ( tools::Long n = 0; n < nEntries; n++ )
856 aSeq.getArray()[n] = InStream->readUTF();
857 aValue <<= aSeq;
858
859 }
861
862 {
863 tools::Long nEntries = InStream->readLong();
864 css::uno::Sequence<sal_uInt16> aSeq( nEntries );
865 for ( tools::Long n = 0; n < nEntries; n++ )
866 aSeq.getArray()[n] = static_cast<sal_uInt16>(InStream->readShort());
867 aValue <<= aSeq;
868 }
869 else if ( *pType == cppu::UnoType< css::uno::Sequence<sal_Int16> >::get() )
870 {
871 tools::Long nEntries = InStream->readLong();
872 css::uno::Sequence<sal_Int16> aSeq( nEntries );
873 for ( tools::Long n = 0; n < nEntries; n++ )
874 aSeq.getArray()[n] = InStream->readShort();
875 aValue <<= aSeq;
876 }
877 else if ( pType->getTypeClass() == TypeClass_ENUM )
878 {
879 sal_Int32 nAsInt = InStream->readLong();
880 aValue = ::cppu::int2enum( nAsInt, *pType );
881 }
882 else
883 {
884 SAL_WARN( "toolkit", "UnoControlModel::read: don't know how to handle a property of type '"
885 << pType->getTypeName()
886 << "'.\n(Currently handling property '"
887 << GetPropertyName( nPropId )
888 << "'.)");
889 }
890 }
891 else
892 {
893 // Old trash from 5.0
894 if ( nPropId == BASEPROPERTY_FONT_TYPE )
895 {
896 // Redundant information for older versions
897 // is skipped by MarkableStream
898 if ( nVersion < 2 )
899 {
900 if ( !pFD )
901 {
902 pFD.reset(new css::awt::FontDescriptor);
903 if ( maData.find( BASEPROPERTY_FONTDESCRIPTOR ) != maData.end() ) // due to defaults...
905 }
906 pFD->Name = InStream->readUTF();
907 pFD->StyleName = InStream->readUTF();
908 pFD->Family = InStream->readShort();
909 pFD->CharSet = InStream->readShort();
910 pFD->Pitch = InStream->readShort();
911 }
912 }
913 else if ( nPropId == BASEPROPERTY_FONT_SIZE )
914 {
915 if ( nVersion < 2 )
916 {
917 if ( !pFD )
918 {
919 pFD.reset(new css::awt::FontDescriptor);
920 if ( maData.find(BASEPROPERTY_FONTDESCRIPTOR) != maData.end() ) // due to defaults...
922 }
923 pFD->Width = static_cast<sal_Int16>(InStream->readLong());
924 pFD->Height = static_cast<sal_Int16>(InStream->readLong());
925 InStream->readShort(); // ignore css::awt::FontWidth - it was
926 // misspelled and is no longer needed
927 pFD->CharacterWidth = css::awt::FontWidth::DONTKNOW;
928 }
929 }
930 else if ( nPropId == BASEPROPERTY_FONT_ATTRIBS )
931 {
932 if ( nVersion < 2 )
933 {
934 if ( !pFD )
935 {
936 pFD.reset(new css::awt::FontDescriptor);
937 if ( maData.find(BASEPROPERTY_FONTDESCRIPTOR) != maData.end() ) // due to defaults...
939 }
940 pFD->Weight = vcl::unohelper::ConvertFontWeight(static_cast<FontWeight>(InStream->readShort()));
941 pFD->Slant = static_cast<css::awt::FontSlant>(InStream->readShort());
942 pFD->Underline = InStream->readShort();
943 pFD->Strikeout = InStream->readShort();
944 pFD->Orientation = static_cast<float>(static_cast<double>(InStream->readShort())) / 10;
945 pFD->Kerning = InStream->readBoolean() != 0;
946 pFD->WordLineMode = InStream->readBoolean() != 0;
947 }
948 }
949 else
950 {
951 OSL_FAIL( "read: unknown Property!" );
952 }
953 }
954 }
955 else // bVoid
956 {
957 if ( nPropId == BASEPROPERTY_FONTDESCRIPTOR )
958 {
960 aValue <<= aFD;
961 }
962 }
963
964 if ( maData.find( nPropId ) != maData.end() )
965 {
966 aProps.getArray()[i] = GetPropertyName( nPropId );
967 aValues.getArray()[i] = aValue;
968 }
969 else
970 {
971 bInvalidEntries = true;
972 }
973
974 // Skip rest of input if there is more data in stream than this version can handle
975 xMark->jumpToMark( nPropDataBeginMark );
976 InStream->skipBytes( nPropDataLen );
977 xMark->deleteMark(nPropDataBeginMark);
978 }
979 if ( bInvalidEntries )
980 {
981 for ( sal_Int32 i = 0; i < aProps.getLength(); i++ )
982 {
983 if ( aProps.getConstArray()[i].isEmpty() )
984 {
985 ::comphelper::removeElementAt( aProps, i );
986 ::comphelper::removeElementAt( aValues, i );
987 i--;
988 }
989 }
990 }
991
992 try
993 {
994 setPropertyValuesImpl( aGuard, aProps, aValues );
995 }
996 catch ( const Exception& )
997 {
998 DBG_UNHANDLED_EXCEPTION("toolkit.controls");
999 }
1000
1001 if ( pFD )
1002 {
1003 css::uno::Any aValue;
1004 aValue <<= *pFD;
1006 }
1007}
1008
1009
1010// css::lang::XServiceInfo
1012{
1013 OSL_FAIL( "This method should be overridden!" );
1014 return OUString();
1015
1016}
1017
1018sal_Bool UnoControlModel::supportsService( const OUString& rServiceName )
1019{
1020 return cppu::supportsService(this, rServiceName);
1021}
1022
1023css::uno::Sequence< OUString > UnoControlModel::getSupportedServiceNames( )
1024{
1025 return { "com.sun.star.awt.UnoControlModel" };
1026}
1027
1028bool UnoControlModel::convertFastPropertyValue( std::unique_lock<std::mutex>& rGuard, Any & rConvertedValue, Any & rOldValue, sal_Int32 nPropId, const Any& rValue )
1029{
1030 bool bVoid = rValue.getValueType().getTypeClass() == css::uno::TypeClass_VOID;
1031 if ( bVoid )
1032 {
1033 rConvertedValue.clear();
1034 }
1035 else
1036 {
1037 const css::uno::Type* pDestType = GetPropertyType( static_cast<sal_uInt16>(nPropId) );
1038 if ( pDestType->getTypeClass() == TypeClass_ANY )
1039 {
1040 rConvertedValue = rValue;
1041 }
1042 else
1043 {
1044 if ( pDestType->equals( rValue.getValueType() ) )
1045 {
1046 rConvertedValue = rValue;
1047 }
1048 else
1049 {
1050 bool bConverted = false;
1051 // 13.03.2001 - 84923 - frank.schoenheit@germany.sun.com
1052
1053 switch (pDestType->getTypeClass())
1054 {
1055 case TypeClass_DOUBLE:
1056 {
1057 // try as double
1058 double nAsDouble = 0;
1059 bConverted = ( rValue >>= nAsDouble );
1060 if ( bConverted )
1061 rConvertedValue <<= nAsDouble;
1062 else
1063 { // try as integer
1064 sal_Int32 nAsInteger = 0;
1065 bConverted = ( rValue >>= nAsInteger );
1066 if ( bConverted )
1067 rConvertedValue <<= static_cast<double>(nAsInteger);
1068 }
1069 }
1070 break;
1071 case TypeClass_SHORT:
1072 {
1073 sal_Int16 n;
1074 bConverted = ( rValue >>= n );
1075 if ( bConverted )
1076 rConvertedValue <<= n;
1077 }
1078 break;
1079 case TypeClass_UNSIGNED_SHORT:
1080 {
1081 sal_uInt16 n;
1082 bConverted = ( rValue >>= n );
1083 if ( bConverted )
1084 rConvertedValue <<= n;
1085 }
1086 break;
1087 case TypeClass_LONG:
1088 {
1089 sal_Int32 n;
1090 bConverted = ( rValue >>= n );
1091 if ( bConverted )
1092 rConvertedValue <<= n;
1093 }
1094 break;
1095 case TypeClass_UNSIGNED_LONG:
1096 {
1097 sal_uInt32 n;
1098 bConverted = ( rValue >>= n );
1099 if ( bConverted )
1100 rConvertedValue <<= n;
1101 }
1102 break;
1103 case TypeClass_INTERFACE:
1104 {
1105 if ( rValue.getValueType().getTypeClass() == TypeClass_INTERFACE )
1106 {
1107 Reference< XInterface > xPure( rValue, UNO_QUERY );
1108 if ( xPure.is() )
1109 rConvertedValue = xPure->queryInterface( *pDestType );
1110 else
1111 rConvertedValue.setValue( nullptr, *pDestType );
1112 bConverted = true;
1113 }
1114 }
1115 break;
1116 case TypeClass_ENUM:
1117 {
1118 sal_Int32 nValue = 0;
1119 bConverted = ( rValue >>= nValue );
1120 if ( bConverted )
1121 rConvertedValue = ::cppu::int2enum( nValue, *pDestType );
1122 }
1123 break;
1124 default: ; // avoid compiler warning
1125 }
1126
1127 if (!bConverted)
1128 {
1129 throw css::lang::IllegalArgumentException(
1130 "Unable to convert the given value for the property "
1131 + GetPropertyName( static_cast<sal_uInt16>(nPropId) )
1132 + ".\nExpected type: " + pDestType->getTypeName()
1133 + "\nFound type: " + rValue.getValueType().getTypeName(),
1134 static_cast< css::beans::XPropertySet* >(this),
1135 1);
1136 }
1137 }
1138 }
1139 }
1140
1141 // the current value
1142 getFastPropertyValue( rGuard, rOldValue, nPropId );
1143 return !CompareProperties( rConvertedValue, rOldValue );
1144}
1145
1146void UnoControlModel::setFastPropertyValue_NoBroadcast( std::unique_lock<std::mutex>& /*rGuard*/, sal_Int32 nPropId, const css::uno::Any& rValue )
1147{
1148 // Missing: the fake solo properties of the FontDescriptor
1149
1150 ImplPropertyTable::const_iterator it = maData.find( nPropId );
1151 const css::uno::Any* pProp = it == maData.end() ? nullptr : &(it->second);
1152 ENSURE_OR_RETURN_VOID( pProp, "UnoControlModel::setFastPropertyValue_NoBroadcast: invalid property id!" );
1153
1154 DBG_ASSERT( ( rValue.getValueType().getTypeClass() != css::uno::TypeClass_VOID ) || ( GetPropertyAttribs( static_cast<sal_uInt16>(nPropId) ) & css::beans::PropertyAttribute::MAYBEVOID ), "Property should not be VOID!" );
1155 maData[ nPropId ] = rValue;
1156}
1157
1158void UnoControlModel::getFastPropertyValue( std::unique_lock<std::mutex>& /*rGuard*/, css::uno::Any& rValue, sal_Int32 nPropId ) const
1159{
1160 ImplPropertyTable::const_iterator it = maData.find( nPropId );
1161 const css::uno::Any* pProp = it == maData.end() ? nullptr : &(it->second);
1162
1163 if ( pProp )
1164 rValue = *pProp;
1165 else if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1166 {
1167 pProp = &( maData.find( BASEPROPERTY_FONTDESCRIPTOR )->second );
1168 css::awt::FontDescriptor aFD;
1169 (*pProp) >>= aFD;
1170 switch ( nPropId )
1171 {
1172 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: rValue <<= aFD.Name;
1173 break;
1174 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: rValue <<= aFD.StyleName;
1175 break;
1176 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: rValue <<= aFD.Family;
1177 break;
1178 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: rValue <<= aFD.CharSet;
1179 break;
1180 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: rValue <<= static_cast<float>(aFD.Height);
1181 break;
1182 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: rValue <<= aFD.Weight;
1183 break;
1184 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: rValue <<= static_cast<sal_Int16>(aFD.Slant);
1185 break;
1186 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: rValue <<= aFD.Underline;
1187 break;
1188 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: rValue <<= aFD.Strikeout;
1189 break;
1190 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: rValue <<= aFD.Width;
1191 break;
1192 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: rValue <<= aFD.Pitch;
1193 break;
1194 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: rValue <<= aFD.CharacterWidth;
1195 break;
1196 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: rValue <<= aFD.Orientation;
1197 break;
1198 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: rValue <<= aFD.Kerning;
1199 break;
1200 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: rValue <<= aFD.WordLineMode;
1201 break;
1202 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: rValue <<= aFD.Type;
1203 break;
1204 default: OSL_FAIL( "FontProperty?!" );
1205 }
1206 }
1207 else
1208 {
1209 OSL_FAIL( "getFastPropertyValue - invalid Property!" );
1210 }
1211}
1212
1213// css::beans::XFastPropertySet
1214void UnoControlModel::setFastPropertyValueImpl( std::unique_lock<std::mutex>& rGuard, sal_Int32 nPropId, const css::uno::Any& rValue )
1215{
1217 {
1218 Any aOldSingleValue;
1220
1221 css::uno::Any* pProp = &maData[ BASEPROPERTY_FONTDESCRIPTOR ];
1222 FontDescriptor aOldFontDescriptor;
1223 (*pProp) >>= aOldFontDescriptor;
1224
1225 FontDescriptor aNewFontDescriptor( aOldFontDescriptor );
1226 lcl_ImplMergeFontProperty( aNewFontDescriptor, static_cast<sal_uInt16>(nPropId), rValue );
1227
1228 Any aNewValue;
1229 aNewValue <<= aNewFontDescriptor;
1230 sal_Int32 nDescriptorId = BASEPROPERTY_FONTDESCRIPTOR;
1231
1232 // also, we need fire a propertyChange event for the single property, since with
1233 // the above line, only an event for the FontDescriptor property will be fired
1234 Any aNewSingleValue;
1236
1237 setFastPropertyValues( rGuard, 1, &nDescriptorId, &aNewValue, 1 );
1238 fire( rGuard, &nPropId, &aNewSingleValue, &aOldSingleValue, 1, false );
1239 }
1240 else
1241 setFastPropertyValues( rGuard, 1, &nPropId, &rValue, 1 );
1242}
1243
1244// css::beans::XMultiPropertySet
1245css::uno::Reference< css::beans::XPropertySetInfo > UnoControlModel::getPropertySetInfo( )
1246{
1247 OSL_FAIL( "UnoControlModel::getPropertySetInfo() not possible!" );
1248 return css::uno::Reference< css::beans::XPropertySetInfo >();
1249}
1250
1251void UnoControlModel::setPropertyValues( const css::uno::Sequence< OUString >& rPropertyNames, const css::uno::Sequence< css::uno::Any >& Values )
1252{
1253 std::unique_lock aGuard( m_aMutex );
1254 setPropertyValuesImpl(aGuard, rPropertyNames, Values);
1255}
1256
1257void UnoControlModel::setPropertyValuesImpl( std::unique_lock<std::mutex>& rGuard, const css::uno::Sequence< OUString >& rPropertyNames, const css::uno::Sequence< css::uno::Any >& Values )
1258{
1259 sal_Int32 nProps = rPropertyNames.getLength();
1260 if (nProps != Values.getLength())
1261 throw css::lang::IllegalArgumentException("lengths do not match",
1262 static_cast<cppu::OWeakObject*>(this), -1);
1263
1264// sal_Int32* pHandles = new sal_Int32[nProps];
1265 // don't do this - it leaks in case of an exception
1266 Sequence< sal_Int32 > aHandles( nProps );
1267 sal_Int32* pHandles = aHandles.getArray();
1268
1269 // may need to change the order in the sequence, for this we need a non-const value sequence
1270 uno::Sequence< uno::Any > aValues( Values );
1271 uno::Any* pValues = aValues.getArray();
1272
1273 sal_Int32 nValidHandles = getInfoHelper().fillHandles( pHandles, rPropertyNames );
1274
1275 if ( !nValidHandles )
1276 return;
1277
1278 // if somebody sets properties which are single aspects of a font descriptor,
1279 // remove them, and build a font descriptor instead
1280 std::unique_ptr< awt::FontDescriptor > pFD;
1281 for ( sal_Int32 n = 0; n < nProps; ++n )
1282 {
1283 if ( ( pHandles[n] >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( pHandles[n] <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1284 {
1285 if (!pFD)
1286 {
1287 css::uno::Any* pProp = &maData[ BASEPROPERTY_FONTDESCRIPTOR ];
1288 pFD.reset( new awt::FontDescriptor );
1289 (*pProp) >>= *pFD;
1290 }
1291 lcl_ImplMergeFontProperty( *pFD, static_cast<sal_uInt16>(pHandles[n]), pValues[n] );
1292 pHandles[n] = -1;
1293 nValidHandles--;
1294 }
1295 }
1296
1297 if ( nValidHandles )
1298 {
1299 ImplNormalizePropertySequence( nProps, pHandles, pValues, &nValidHandles );
1300 setFastPropertyValues( rGuard, nProps, pHandles, pValues, nValidHandles );
1301 }
1302
1303 // Don't merge FD property into array, as it is sorted
1304 if (pFD)
1305 {
1306 css::uno::Any aValue;
1307 aValue <<= *pFD;
1309 setFastPropertyValues( rGuard, 1, &nHandle, &aValue, 1 );
1310 }
1311}
1312
1313
1314void UnoControlModel::ImplNormalizePropertySequence( const sal_Int32, sal_Int32*,
1315 uno::Any*, sal_Int32* ) const
1316{
1317 // nothing to do here
1318}
1319
1320void UnoControlModel::ImplEnsureHandleOrder( const sal_Int32 _nCount, sal_Int32* _pHandles,
1321 uno::Any* _pValues, sal_Int32 _nFirstHandle, sal_Int32 _nSecondHandle )
1322{
1323 for ( sal_Int32 i=0; i < _nCount; ++_pHandles, ++_pValues, ++i )
1324 {
1325 if ( _nSecondHandle == *_pHandles )
1326 {
1327 sal_Int32* pLaterHandles = _pHandles + 1;
1328 uno::Any* pLaterValues = _pValues + 1;
1329 for ( sal_Int32 j = i + 1; j < _nCount; ++j, ++pLaterHandles, ++pLaterValues )
1330 {
1331 if ( _nFirstHandle == *pLaterHandles )
1332 {
1333 // indeed it is -> exchange the both places in the sequences
1334 sal_Int32 nHandle( *_pHandles );
1335 *_pHandles = *pLaterHandles;
1336 *pLaterHandles = nHandle;
1337
1338 uno::Any aValue( *_pValues );
1339 *_pValues = *pLaterValues;
1340 *pLaterValues = aValue;
1341
1342 break;
1343 // this will leave the inner loop, and continue with the outer loop.
1344 // Note that this means we will encounter the _nSecondHandle handle, again, once we reached
1345 // (in the outer loop) the place where we just put it.
1346 }
1347 }
1348 }
1349 }
1350}
1351
1352/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const PropertyValue * pValues
Reference< XComponentContext > m_xContext
XPropertyListType t
double d
const OUString & getCurrBankSymbol() const
css::uno::Sequence< css::i18n::Currency2 > getAllCurrencies() const
const OUString & getCurrSymbol() const
void setPropertyValuesImpl(std::unique_lock< std::mutex > &rGuard, const css::uno::Sequence< OUString > &PropertyNames, const css::uno::Sequence< css::uno::Any > &Values)
css::uno::Sequence< sal_Int32 > ImplGetPropertyIds() const
sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
void ImplRegisterProperty(sal_uInt16 nPropType)
void SAL_CALL setPropertyToDefault(const OUString &PropertyName) override
css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
void SAL_CALL dispose() override
css::uno::Any SAL_CALL getPropertyDefault(const OUString &aPropertyName) override
void setFastPropertyValue_NoBroadcast(std::unique_lock< std::mutex > &rGuard, sal_Int32 nHandle, const css::uno::Any &rValue) override
css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &aPropertyName) override
OUString SAL_CALL getServiceName() override
void SAL_CALL read(const css::uno::Reference< css::io::XObjectInputStream > &InStream) override
void setFastPropertyValueImpl(std::unique_lock< std::mutex > &rGuard, sal_Int32 nHandle, const css::uno::Any &aValue) override
UnoControlModel(const css::uno::Reference< css::uno::XComponentContext > &rxContext)
ImplPropertyTable maData
virtual css::uno::Any ImplGetDefaultValue(sal_uInt16 nPropId) const
::cppu::IPropertyArrayHelper & getInfoHelper() override=0
void SAL_CALL setPropertyValues(const css::uno::Sequence< OUString > &PropertyNames, const css::uno::Sequence< css::uno::Any > &Values) override
void getFastPropertyValue(std::unique_lock< std::mutex > &rGuard, css::uno::Any &rValue, sal_Int32 nHandle) const override
void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
css::beans::PropertyState SAL_CALL getPropertyState(const OUString &PropertyName) override
virtual void ImplNormalizePropertySequence(const sal_Int32 _nCount, sal_Int32 *_pHandles, css::uno::Any *_pValues, sal_Int32 *_pValidHandles) const
called before setting multiple properties, allows to care for property dependencies
css::uno::Any SAL_CALL queryAggregation(const css::uno::Type &rType) override
static void ImplEnsureHandleOrder(const sal_Int32 _nCount, sal_Int32 *_pHandles, css::uno::Any *_pValues, sal_Int32 _nFirstHandle, sal_Int32 _nSecondHandle)
ensures that two property values in a sequence have a certain order
bool ImplHasProperty(sal_uInt16 nPropId) const
void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
void SAL_CALL write(const css::uno::Reference< css::io::XObjectOutputStream > &OutStream) override
EventListenerMultiplexer maDisposeListeners
bool convertFastPropertyValue(std::unique_lock< std::mutex > &rGuard, css::uno::Any &rConvertedValue, css::uno::Any &rOldValue, sal_Int32 nHandle, const css::uno::Any &rValue) override
css::beans::PropertyState getPropertyStateImpl(std::unique_lock< std::mutex > &rGuard, const OUString &PropertyName)
OUString SAL_CALL getImplementationName() override
void ImplRegisterProperties(const std::vector< sal_uInt16 > &rIds)
virtual void SAL_CALL setPropertyValue(const ::rtl::OUString &rPropertyName, const css::uno::Any &aValue) override final
void setFastPropertyValues(std::unique_lock< std::mutex > &rGuard, sal_Int32 nSeqLen, sal_Int32 *pHandles, const css::uno::Any *pValues, sal_Int32 nHitCount)
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType) override
virtual css::uno::Any getPropertyValueImpl(std::unique_lock< std::mutex > &rGuard, const ::rtl::OUString &aPropertyName)
void fire(std::unique_lock< std::mutex > &rGuard, sal_Int32 *pnHandles, const css::uno::Any *pNewValues, const css::uno::Any *pOldValues, sal_Int32 nCount, bool bVetoable)
virtual sal_Int32 SAL_CALL fillHandles(sal_Int32 *pHandles, const css::uno::Sequence< ::rtl::OUString > &rPropNames)=0
virtual css::uno::Any SAL_CALL queryAggregation(css::uno::Type const &rType) SAL_OVERRIDE
const_iterator find(const Value &x) const
const_iterator end() const
size_type size() const
std::pair< const_iterator, bool > insert(Value &&x)
static OUString getDefaultCurrency()
#define DBG_ASSERT(sCon, aError)
#define DBG_UNHANDLED_EXCEPTION(...)
#define ENSURE_OR_RETURN_VOID(c, m)
sal_Int16 nVersion
sal_Int16 nValue
sal_Int64 n
Sequence< sal_Int8 > aSeq
#define SAL_WARN(area, stream)
std::vector< sal_Int8, boost::noinit_adaptor< std::allocator< sal_Int8 > > > maData
@ Exception
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
int i
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
FontWeight
long Long
VCL_DLLPUBLIC float ConvertFontWidth(FontWidth eWidth)
VCL_DLLPUBLIC float ConvertFontWeight(FontWeight eWeight)
sal_Int16 GetPropertyAttribs(sal_uInt16 nPropertyId)
Definition: property.cxx:315
bool CompareProperties(const css::uno::Any &r1, const css::uno::Any &r2)
Definition: property.cxx:329
const OUString & GetPropertyName(sal_uInt16 nPropertyId)
Definition: property.cxx:295
const css::uno::Type * GetPropertyType(sal_uInt16 nPropertyId)
Definition: property.cxx:308
sal_uInt16 GetPropertyId(const OUString &rPropertyName)
Definition: property.cxx:278
#define BASEPROPERTY_DEFAULTBUTTON
Definition: property.hxx:90
#define BASEPROPERTY_FONT_SIZE
Definition: property.hxx:50
#define BASEPROPERTY_MULTILINE
Definition: property.hxx:43
#define BASEPROPERTY_SCROLLVALUE_MIN
Definition: property.hxx:127
#define BASEPROPERTY_LITERALMASK
Definition: property.hxx:74
#define BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME
Definition: property.hxx:213
#define BASEPROPERTY_LINEINCREMENT
Definition: property.hxx:112
#define BASEPROPERTY_TEXTLINECOLOR
Definition: property.hxx:118
#define BASEPROPERTY_CURRENCYSYMBOL
Definition: property.hxx:59
#define BASEPROPERTY_SPININCREMENT
Definition: property.hxx:133
#define BASEPROPERTY_VISIBLESIZE
Definition: property.hxx:114
#define BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION
Definition: property.hxx:224
#define BASEPROPERTY_EDITMASK
Definition: property.hxx:73
#define BASEPROPERTY_SPINVALUE
Definition: property.hxx:130
#define BASEPROPERTY_BORDER
Definition: property.hxx:39
#define BASEPROPERTY_SPIN
Definition: property.hxx:60
#define BASEPROPERTY_HSCROLL
Definition: property.hxx:45
#define BASEPROPERTY_PAINTTRANSPARENT
Definition: property.hxx:153
#define BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR
Definition: property.hxx:149
#define BASEPROPERTY_FILLCOLOR
Definition: property.hxx:36
#define BASEPROPERTY_STRINGITEMLIST
Definition: property.hxx:44
#define BASEPROPERTY_HIDEINACTIVESELECTION
Definition: property.hxx:143
#define BASEPROPERTY_ENFORCE_FORMAT
Definition: property.hxx:135
#define BASEPROPERTY_SCALEIMAGE
Definition: property.hxx:120
#define BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH
Definition: property.hxx:223
#define BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE
Definition: property.hxx:219
#define BASEPROPERTY_ORIENTATION
Definition: property.hxx:115
#define BASEPROPERTY_ECHOCHAR
Definition: property.hxx:79
#define BASEPROPERTY_CONTEXT_WRITING_MODE
Definition: property.hxx:174
#define BASEPROPERTY_HIGHLIGHT_COLOR
Definition: property.hxx:205
#define BASEPROPERTY_DATESHOWCENTURY
Definition: property.hxx:56
#define BASEPROPERTY_EXTTIMEFORMAT
Definition: property.hxx:57
#define BASEPROPERTY_TIMEMIN
Definition: property.hxx:67
#define BASEPROPERTY_TEXT
Definition: property.hxx:34
#define BASEPROPERTY_BLOCKINCREMENT
Definition: property.hxx:113
#define BASEPROPERTY_READONLY
Definition: property.hxx:76
#define BASEPROPERTY_DATEMAX
Definition: property.hxx:65
#define BASEPROPERTY_TITLE
Definition: property.hxx:102
#define BASEPROPERTY_FONTDESCRIPTORPART_START
Definition: property.hxx:211
#define BASEPROPERTY_SCROLLVALUE_MAX
Definition: property.hxx:111
#define BASEPROPERTY_ALIGN
Definition: property.hxx:40
#define BASEPROPERTY_IMAGEPOSITION
Definition: property.hxx:146
#define BASEPROPERTY_HELPURL
Definition: property.hxx:91
#define BASEPROPERTY_EXTDATEFORMAT
Definition: property.hxx:55
#define BASEPROPERTY_AUTOCOMPLETE
Definition: property.hxx:82
#define BASEPROPERTY_FONT_ATTRIBS
Definition: property.hxx:51
#define BASEPROPERTY_REPEAT
Definition: property.hxx:134
#define BASEPROPERTY_LINECOUNT
Definition: property.hxx:54
#define BASEPROPERTY_TIME
Definition: property.hxx:66
#define BASEPROPERTY_PROGRESSVALUE_MIN
Definition: property.hxx:108
#define BASEPROPERTY_FONTDESCRIPTORPART_SLANT
Definition: property.hxx:218
#define BASEPROPERTY_GROUPNAME
Definition: property.hxx:190
#define BASEPROPERTY_SYMBOL_COLOR
Definition: property.hxx:129
#define BASEPROPERTY_IMAGEURL
Definition: property.hxx:75
#define BASEPROPERTY_DESKTOP_AS_PARENT
Definition: property.hxx:156
#define BASEPROPERTY_VALUEMIN_DOUBLE
Definition: property.hxx:86
#define BASEPROPERTY_BACKGROUNDCOLOR
Definition: property.hxx:35
#define BASEPROPERTY_FONTDESCRIPTORPART_FAMILY
Definition: property.hxx:214
#define BASEPROPERTY_TYPEDITEMLIST
Definition: property.hxx:207
#define BASEPROPERTY_FONTDESCRIPTORPART_PITCH
Definition: property.hxx:222
#define BASEPROPERTY_FONTDESCRIPTORPART_NAME
Definition: property.hxx:212
#define BASEPROPERTY_MULTISELECTION_SIMPLEMODE
Definition: property.hxx:188
#define BASEPROPERTY_MULTISELECTION
Definition: property.hxx:83
#define BASEPROPERTY_PROGRESSVALUE
Definition: property.hxx:107
#define BASEPROPERTY_SPINVALUE_MAX
Definition: property.hxx:132
#define BASEPROPERTY_TABSTOP
Definition: property.hxx:47
#define BASEPROPERTY_FONTRELIEF
Definition: property.hxx:116
#define BASEPROPERTY_ENABLED
Definition: property.hxx:77
#define BASEPROPERTY_STRICTFORMAT
Definition: property.hxx:61
#define BASEPROPERTY_DROPDOWN
Definition: property.hxx:42
#define BASEPROPERTY_FONTDESCRIPTORPART_KERNING
Definition: property.hxx:225
#define BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT
Definition: property.hxx:220
#define BASEPROPERTY_CLOSEABLE
Definition: property.hxx:104
#define BASEPROPERTY_DEFAULTCONTROL
Definition: property.hxx:52
#define BASEPROPERTY_VERTICALALIGN
Definition: property.hxx:148
#define BASEPROPERTY_PROGRESSVALUE_MAX
Definition: property.hxx:109
#define BASEPROPERTY_FONTDESCRIPTORPART_WIDTH
Definition: property.hxx:221
#define BASEPROPERTY_TRISTATE
Definition: property.hxx:89
#define BASEPROPERTY_ITEM_SEPARATOR_POS
Definition: property.hxx:189
#define BASEPROPERTY_SCROLLVALUE
Definition: property.hxx:110
#define BASEPROPERTY_WRITING_MODE
Definition: property.hxx:173
#define BASEPROPERTY_HIGHLIGHT_TEXT_COLOR
Definition: property.hxx:206
#define BASEPROPERTY_GRAPHIC
Definition: property.hxx:150
#define BASEPROPERTY_LABEL
Definition: property.hxx:53
#define BASEPROPERTY_DATE
Definition: property.hxx:63
#define BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE
Definition: property.hxx:226
#define BASEPROPERTY_FONTDESCRIPTORPART_END
Definition: property.hxx:228
#define BASEPROPERTY_FONT_TYPE
Definition: property.hxx:49
#define BASEPROPERTY_FONTDESCRIPTORPART_CHARSET
Definition: property.hxx:215
#define BASEPROPERTY_BORDERCOLOR
Definition: property.hxx:145
#define BASEPROPERTY_FONTDESCRIPTOR
Definition: property.hxx:41
#define BASEPROPERTY_NUMSHOWTHOUSANDSEP
Definition: property.hxx:58
#define BASEPROPERTY_MAXTEXTLEN
Definition: property.hxx:80
#define BASEPROPERTY_DATEMIN
Definition: property.hxx:64
#define BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT
Definition: property.hxx:216
#define BASEPROPERTY_DECIMALACCURACY
Definition: property.hxx:62
#define BASEPROPERTY_VSCROLL
Definition: property.hxx:46
#define BASEPROPERTY_ENABLEVISIBLE
Definition: property.hxx:180
#define BASEPROPERTY_NOLABEL
Definition: property.hxx:168
#define BASEPROPERTY_FONTDESCRIPTORPART_TYPE
Definition: property.hxx:227
#define BASEPROPERTY_AUTOHSCROLL
Definition: property.hxx:154
#define BASEPROPERTY_AUTOVSCROLL
Definition: property.hxx:155
#define BASEPROPERTY_HELPTEXT
Definition: property.hxx:106
#define BASEPROPERTY_VALUEMAX_DOUBLE
Definition: property.hxx:87
#define BASEPROPERTY_VALUE_DOUBLE
Definition: property.hxx:85
#define BASEPROPERTY_STATE
Definition: property.hxx:48
#define BASEPROPERTY_SELECTEDITEMS
Definition: property.hxx:84
#define BASEPROPERTY_SIZEABLE
Definition: property.hxx:105
#define BASEPROPERTY_REFERENCE_DEVICE
Definition: property.hxx:181
#define BASEPROPERTY_MOVEABLE
Definition: property.hxx:103
#define BASEPROPERTY_HARDLINEBREAKS
Definition: property.hxx:81
#define BASEPROPERTY_DECORATION
Definition: property.hxx:152
#define BASEPROPERTY_IMAGEALIGN
Definition: property.hxx:119
#define BASEPROPERTY_FONTEMPHASISMARK
Definition: property.hxx:117
#define BASEPROPERTY_TIMEMAX
Definition: property.hxx:68
#define BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT
Definition: property.hxx:217
#define BASEPROPERTY_REPEAT_DELAY
Definition: property.hxx:128
#define BASEPROPERTY_DIALOGSOURCEURL
Definition: property.hxx:167
#define BASEPROPERTY_TEXTCOLOR
Definition: property.hxx:37
#define PROPERTY_ALIGN_LEFT
Definition: property.hxx:230
#define BASEPROPERTY_PUSHBUTTONTYPE
Definition: property.hxx:121
#define BASEPROPERTY_PRINTABLE
Definition: property.hxx:78
#define BASEPROPERTY_VALUESTEP_DOUBLE
Definition: property.hxx:88
#define BASEPROPERTY_SPINVALUE_MIN
Definition: property.hxx:131
sal_Int32 nHandle
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ORoadmapEntry, ORoadmapEntry_Base, ::comphelper::OPropertyContainer)
unsigned char sal_Bool
#define IMPLEMENT_FORWARD_REFCOUNT(classname, refcountbase)
#define UNOCONTROL_STREAMVERSION
static void lcl_ImplMergeFontProperty(FontDescriptor &rFD, sal_uInt16 nPropId, const Any &rValue)