sync master with lastest vba changes
[ooovba.git] / toolkit / source / controls / unocontrolmodel.cxx
blob453be840e4eefb53dd5f5f559ab5ab0d55181cee
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: unocontrolmodel.cxx,v $
10 * $Revision: 1.62 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_toolkit.hxx"
33 #include <com/sun/star/beans/PropertyState.hpp>
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/awt/FontDescriptor.hpp>
36 #include <com/sun/star/awt/FontWidth.hpp>
37 #include <com/sun/star/awt/FontWeight.hpp>
38 #include <com/sun/star/awt/FontSlant.hpp>
39 #include <com/sun/star/graphic/XGraphicProvider.hpp>
40 #include <com/sun/star/text/WritingMode2.hpp>
41 #include <com/sun/star/io/XMarkableStream.hpp>
42 #include <toolkit/controls/unocontrolmodel.hxx>
43 #include <toolkit/helper/macros.hxx>
44 #include <cppuhelper/typeprovider.hxx>
45 #include <cppuhelper/extract.hxx>
46 #include <rtl/memory.h>
47 #include <rtl/uuid.h>
48 #include <tools/diagnose_ex.h>
49 #include <tools/string.hxx>
50 #include <tools/table.hxx>
51 #include <tools/date.hxx>
52 #include <tools/time.hxx>
53 #include <tools/urlobj.hxx>
54 #include <tools/debug.hxx>
55 #include <toolkit/helper/property.hxx>
56 #include <toolkit/helper/vclunohelper.hxx>
57 #include <toolkit/helper/emptyfontdescriptor.hxx>
58 #include <com/sun/star/lang/Locale.hpp>
59 #include <unotools/localedatawrapper.hxx>
60 #include <unotools/configmgr.hxx>
61 #include <comphelper/processfactory.hxx>
62 #include <comphelper/sequence.hxx>
63 #include <vcl/svapp.hxx>
64 #include <uno/data.h>
66 #include <memory>
68 using namespace ::com::sun::star;
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::lang;
71 using namespace ::com::sun::star::i18n;
72 using ::com::sun::star::awt::FontDescriptor;
74 struct ImplControlProperty
76 private:
77 sal_uInt16 nId;
78 ::com::sun::star::uno::Any aValue;
80 public:
81 ImplControlProperty( const ImplControlProperty& rProp ) : aValue( rProp.aValue )
83 nId = rProp.nId;
86 ImplControlProperty( sal_uInt16 nT )
88 nId = nT;
91 ImplControlProperty( sal_uInt16 nT, const ::com::sun::star::uno::Any& rValue ) : aValue( rValue )
93 nId = nT;
96 sal_uInt16 GetId() const { return nId; }
97 const ::com::sun::star::uno::Any& GetValue() const { return aValue; }
98 void SetValue( const ::com::sun::star::uno::Any& rValue ) { aValue = rValue; }
101 DECLARE_TABLE( ImplPropertyTable, ImplControlProperty* )
103 #define UNOCONTROL_STREAMVERSION (short)2
105 static void lcl_ImplMergeFontProperty( FontDescriptor& rFD, sal_uInt16 nPropId, const Any& rValue )
107 // some props are defined with other types than the matching FontDescriptor members have
108 // (e.g. FontWidth, FontSlant)
109 // 78474 - 09/19/2000 - FS
110 float nExtractFloat = 0;
111 sal_Int16 nExtractShort = 0;
113 switch ( nPropId )
115 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: rValue >>= rFD.Name;
116 break;
117 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: rValue >>= rFD.StyleName;
118 break;
119 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: rValue >>= rFD.Family;
120 break;
121 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: rValue >>= rFD.CharSet;
122 break;
123 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: rValue >>= nExtractFloat; rFD.Height = (sal_Int16)nExtractFloat;
124 break;
125 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: rValue >>= rFD.Weight;
126 break;
127 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: if ( rValue >>= nExtractShort )
128 rFD.Slant = (::com::sun::star::awt::FontSlant)nExtractShort;
129 else
130 rValue >>= rFD.Slant;
131 break;
132 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: rValue >>= rFD.Underline;
133 break;
134 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: rValue >>= rFD.Strikeout;
135 break;
136 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: rValue >>= rFD.Width;
137 break;
138 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: rValue >>= rFD.Pitch;
139 break;
140 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: rValue >>= rFD.CharacterWidth;
141 break;
142 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: rValue >>= rFD.Orientation;
143 break;
144 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: rValue >>= rFD.Kerning;
145 break;
146 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: rValue >>= rFD.WordLineMode;
147 break;
148 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: rValue >>= rFD.Type;
149 break;
150 default: DBG_ERROR( "FontProperty?!" );
154 // ----------------------------------------------------
155 // class UnoControlModel
156 // ----------------------------------------------------
157 UnoControlModel::UnoControlModel()
158 : OPropertySetHelper( BrdcstHelper ), maDisposeListeners( *this )
160 // Die Properties muessen vom Model in die Tabelle gestopft werden,
161 // nur vorhandene Properties sind gueltige Properties, auch wenn VOID.
162 mpData = new ImplPropertyTable;
165 UnoControlModel::UnoControlModel( const UnoControlModel& rModel )
166 : XControlModel()
167 , XPropertyState()
168 , XPersistObject()
169 , XComponent()
170 , XServiceInfo()
171 , XTypeProvider()
172 , XUnoTunnel()
173 , XCloneable()
174 , MutexAndBroadcastHelper()
175 , OPropertySetHelper( BrdcstHelper )
176 , OWeakAggObject()
177 , maDisposeListeners( *this )
179 mpData = new ImplPropertyTable;
181 for ( sal_uInt32 n = rModel.mpData->Count(); n; )
183 ImplControlProperty* pProp = rModel.mpData->GetObject( --n );
184 ImplControlProperty* pNew = new ImplControlProperty( *pProp );
185 mpData->Insert( pNew->GetId(), pNew );
189 UnoControlModel::~UnoControlModel()
191 for ( sal_uInt32 n = mpData->Count(); n; )
192 delete mpData->GetObject( --n );
193 delete mpData;
196 UnoControlModel* UnoControlModel::Clone() const
198 DBG_ERROR( "UnoControlModel::Clone() ?!" );
199 return NULL;
202 ::com::sun::star::uno::Sequence<sal_Int32> UnoControlModel::ImplGetPropertyIds() const
204 sal_uInt32 nIDs = mpData->Count();
205 ::com::sun::star::uno::Sequence<sal_Int32> aIDs( nIDs );
206 sal_Int32* pIDs = aIDs.getArray();
207 for ( sal_uInt32 n = 0; n < nIDs; n++ )
208 pIDs[n] = mpData->GetObjectKey( n );
209 return aIDs;
212 sal_Bool UnoControlModel::ImplHasProperty( sal_uInt16 nPropId ) const
214 if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
215 nPropId = BASEPROPERTY_FONTDESCRIPTOR;
217 return mpData->Get( nPropId ) ? sal_True : sal_False;
220 void UnoControlModel::ImplPropertyChanged( sal_uInt16 )
224 ::com::sun::star::uno::Any UnoControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
226 ::com::sun::star::uno::Any aDefault;
228 if (
229 (nPropId == BASEPROPERTY_FONTDESCRIPTOR) ||
231 (nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START) &&
232 (nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END)
236 EmptyFontDescriptor aFD;
237 switch ( nPropId )
239 case BASEPROPERTY_FONTDESCRIPTOR: aDefault <<= aFD; break;
240 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: aDefault <<= aFD.Name; break;
241 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: aDefault <<= aFD.StyleName; break;
242 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: aDefault <<= aFD.Family; break;
243 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: aDefault <<= aFD.CharSet; break;
244 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: aDefault <<= (float)aFD.Height; break;
245 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: aDefault <<= aFD.Weight; break;
246 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: aDefault <<= (sal_Int16)aFD.Slant; break;
247 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: aDefault <<= aFD.Underline; break;
248 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: aDefault <<= aFD.Strikeout; break;
249 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: aDefault <<= aFD.Width; break;
250 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: aDefault <<= aFD.Pitch; break;
251 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: aDefault <<= aFD.CharacterWidth; break;
252 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: aDefault <<= aFD.Orientation; break;
253 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: aDefault <<= aFD.Kerning; break;
254 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: aDefault <<= aFD.WordLineMode; break;
255 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: aDefault <<= aFD.Type; break;
256 default: DBG_ERROR( "FontProperty?!" );
259 else
261 switch ( nPropId )
263 case BASEPROPERTY_GRAPHIC:
264 aDefault <<= makeAny( Reference< graphic::XGraphic >() );
265 break;
267 case BASEPROPERTY_VERTICALALIGN:
268 case BASEPROPERTY_BORDERCOLOR:
269 case BASEPROPERTY_SYMBOL_COLOR:
270 case BASEPROPERTY_TABSTOP:
271 case BASEPROPERTY_TEXTCOLOR:
272 case BASEPROPERTY_TEXTLINECOLOR:
273 case BASEPROPERTY_DATE:
274 case BASEPROPERTY_DATESHOWCENTURY:
275 case BASEPROPERTY_TIME:
276 case BASEPROPERTY_VALUE_DOUBLE:
277 case BASEPROPERTY_PROGRESSVALUE:
278 case BASEPROPERTY_SCROLLVALUE:
279 case BASEPROPERTY_VISIBLESIZE:
280 case BASEPROPERTY_BACKGROUNDCOLOR:
281 case BASEPROPERTY_FILLCOLOR: break; // Void
283 case BASEPROPERTY_FONTRELIEF:
284 case BASEPROPERTY_FONTEMPHASISMARK:
285 case BASEPROPERTY_MAXTEXTLEN:
286 case BASEPROPERTY_STATE:
287 case BASEPROPERTY_EXTDATEFORMAT:
288 case BASEPROPERTY_EXTTIMEFORMAT:
289 case BASEPROPERTY_ECHOCHAR: aDefault <<= (sal_Int16) 0; break;
290 case BASEPROPERTY_BORDER: aDefault <<= (sal_Int16) 1; break;
291 case BASEPROPERTY_DECIMALACCURACY: aDefault <<= (sal_Int16) 2; break;
292 case BASEPROPERTY_LINECOUNT: aDefault <<= (sal_Int16) 5; break;
293 case BASEPROPERTY_ALIGN: aDefault <<= (sal_Int16) PROPERTY_ALIGN_LEFT; break;
294 case BASEPROPERTY_IMAGEALIGN: aDefault <<= (sal_Int16) 1 /*ImageAlign::TOP*/; break;
295 case BASEPROPERTY_IMAGEPOSITION: aDefault <<= (sal_Int16) 12 /*ImagePosition::Centered*/; break;
296 case BASEPROPERTY_PUSHBUTTONTYPE: aDefault <<= (sal_Int16) 0 /*PushButtonType::STANDARD*/; break;
298 case BASEPROPERTY_DATEMAX: aDefault <<= (sal_Int32) Date( 31, 12, 2200 ).GetDate(); break;
299 case BASEPROPERTY_DATEMIN: aDefault <<= (sal_Int32) Date( 1, 1, 1900 ).GetDate(); break;
300 case BASEPROPERTY_TIMEMAX: aDefault <<= (sal_Int32) Time( 23, 59 ).GetTime(); break;
301 case BASEPROPERTY_TIMEMIN: aDefault <<= (sal_Int32) 0; break;
302 case BASEPROPERTY_VALUEMAX_DOUBLE: aDefault <<= (double) 1000000; break;
303 case BASEPROPERTY_VALUEMIN_DOUBLE: aDefault <<= (double) -1000000; break;
304 case BASEPROPERTY_VALUESTEP_DOUBLE: aDefault <<= (double ) 1; break;
305 case BASEPROPERTY_PROGRESSVALUE_MAX: aDefault <<= (sal_Int32) 100; break;
306 case BASEPROPERTY_PROGRESSVALUE_MIN: aDefault <<= (sal_Int32) 0; break;
307 case BASEPROPERTY_SCROLLVALUE_MAX: aDefault <<= (sal_Int32) 100; break;
308 case BASEPROPERTY_SCROLLVALUE_MIN: aDefault <<= (sal_Int32) 0; break;
309 case BASEPROPERTY_LINEINCREMENT: aDefault <<= (sal_Int32) 1; break;
310 case BASEPROPERTY_BLOCKINCREMENT: aDefault <<= (sal_Int32) 10; break;
311 case BASEPROPERTY_ORIENTATION: aDefault <<= (sal_Int32) 0; break;
312 case BASEPROPERTY_SPINVALUE: aDefault <<= (sal_Int32) 0; break;
313 case BASEPROPERTY_SPININCREMENT: aDefault <<= (sal_Int32) 1; break;
314 case BASEPROPERTY_SPINVALUE_MIN: aDefault <<= (sal_Int32) 0; break;
315 case BASEPROPERTY_SPINVALUE_MAX: aDefault <<= (sal_Int32) 100; break;
316 case BASEPROPERTY_REPEAT_DELAY: aDefault <<= (sal_Int32) 50; break; // 50 milliseconds
317 case BASEPROPERTY_DEFAULTCONTROL: aDefault <<= ((UnoControlModel*)this)->getServiceName(); break;
319 case BASEPROPERTY_AUTOHSCROLL:
320 case BASEPROPERTY_AUTOVSCROLL:
321 case BASEPROPERTY_MOVEABLE:
322 case BASEPROPERTY_CLOSEABLE:
323 case BASEPROPERTY_SIZEABLE:
324 case BASEPROPERTY_HSCROLL:
325 case BASEPROPERTY_DEFAULTBUTTON:
326 case BASEPROPERTY_MULTILINE:
327 case BASEPROPERTY_MULTISELECTION:
328 case BASEPROPERTY_TRISTATE:
329 case BASEPROPERTY_DROPDOWN:
330 case BASEPROPERTY_SPIN:
331 case BASEPROPERTY_READONLY:
332 case BASEPROPERTY_VSCROLL:
333 case BASEPROPERTY_NUMSHOWTHOUSANDSEP:
334 case BASEPROPERTY_STRICTFORMAT:
335 case BASEPROPERTY_REPEAT:
336 case BASEPROPERTY_PAINTTRANSPARENT:
337 case BASEPROPERTY_DESKTOP_AS_PARENT:
338 case BASEPROPERTY_HARDLINEBREAKS:
339 case BASEPROPERTY_NOLABEL: aDefault <<= (sal_Bool) sal_False; break;
341 case BASEPROPERTY_WHEELWITHOUTFOCUS:
342 case BASEPROPERTY_HIDEINACTIVESELECTION:
343 case BASEPROPERTY_ENFORCE_FORMAT:
344 case BASEPROPERTY_AUTOCOMPLETE:
345 case BASEPROPERTY_SCALEIMAGE:
346 case BASEPROPERTY_ENABLED:
347 case BASEPROPERTY_PRINTABLE:
348 case BASEPROPERTY_ENABLEVISIBLE:
349 case BASEPROPERTY_DECORATION: aDefault <<= (sal_Bool) sal_True; break;
351 case BASEPROPERTY_GROUPNAME:
352 case BASEPROPERTY_HELPTEXT:
353 case BASEPROPERTY_HELPURL:
354 case BASEPROPERTY_IMAGEURL:
355 case BASEPROPERTY_DIALOGSOURCEURL:
356 case BASEPROPERTY_EDITMASK:
357 case BASEPROPERTY_LITERALMASK:
358 case BASEPROPERTY_LABEL:
359 case BASEPROPERTY_TITLE:
360 case BASEPROPERTY_TEXT: aDefault <<= ::rtl::OUString(); break;
362 case BASEPROPERTY_WRITING_MODE:
363 case BASEPROPERTY_CONTEXT_WRITING_MODE:
364 aDefault <<= text::WritingMode2::CONTEXT;
365 break;
367 case BASEPROPERTY_STRINGITEMLIST:
369 ::com::sun::star::uno::Sequence< ::rtl::OUString> aStringSeq;
370 aDefault <<= aStringSeq;
373 break;
374 case BASEPROPERTY_SELECTEDITEMS:
376 ::com::sun::star::uno::Sequence<sal_Int16> aINT16Seq;
377 aDefault <<= aINT16Seq;
379 break;
380 case BASEPROPERTY_CURRENCYSYMBOL:
382 Any aDefaultCurrency = ::utl::ConfigManager::GetDirectConfigProperty(::utl::ConfigManager::DEFAULTCURRENCY);
383 DBG_ASSERT( TypeClass_STRING == aDefaultCurrency.getValueTypeClass(), "UnoControlModel::ImplGetDefaultValue: invalid currency config value!" );
385 ::rtl::OUString sDefaultCurrency;
386 aDefaultCurrency >>= sDefaultCurrency;
388 // extract the bank symbol
389 sal_Int32 nSepPos = sDefaultCurrency.indexOf( '-' );
390 ::rtl::OUString sBankSymbol;
391 if ( nSepPos >= 0 )
393 sBankSymbol = sDefaultCurrency.copy( 0, nSepPos );
394 sDefaultCurrency = sDefaultCurrency.copy( nSepPos + 1 );
397 // the remaming is the locale
398 Locale aLocale;
399 nSepPos = sDefaultCurrency.indexOf( '-' );
400 if ( nSepPos >= 0 )
402 aLocale.Language = sDefaultCurrency.copy( 0, nSepPos );
403 aLocale.Country = sDefaultCurrency.copy( nSepPos + 1 );
406 LocaleDataWrapper aLocaleInfo( ::comphelper::getProcessServiceFactory(), aLocale );
407 if ( !sBankSymbol.getLength() )
408 sBankSymbol = aLocaleInfo.getCurrBankSymbol();
410 // look for the currency entry (for this language) which has the given bank symbol
411 Sequence< Currency2 > aAllCurrencies = aLocaleInfo.getAllCurrencies();
412 const Currency2* pAllCurrencies = aAllCurrencies.getConstArray();
413 const Currency2* pAllCurrenciesEnd = pAllCurrencies + aAllCurrencies.getLength();
415 ::rtl::OUString sCurrencySymbol = aLocaleInfo.getCurrSymbol();
416 if ( !sBankSymbol.getLength() )
418 DBG_ASSERT( pAllCurrencies != pAllCurrenciesEnd, "UnoControlModel::ImplGetDefaultValue: no currencies at all!" );
419 if ( pAllCurrencies != pAllCurrenciesEnd )
421 sBankSymbol = pAllCurrencies->BankSymbol;
422 sCurrencySymbol = pAllCurrencies->Symbol;
426 if ( sBankSymbol.getLength() )
428 bool bLegacy = false;
429 for ( ;pAllCurrencies != pAllCurrenciesEnd; ++pAllCurrencies )
430 if ( pAllCurrencies->BankSymbol == sBankSymbol )
432 sCurrencySymbol = pAllCurrencies->Symbol;
433 if ( pAllCurrencies->LegacyOnly )
434 bLegacy = true;
435 else
436 break;
438 DBG_ASSERT( bLegacy || pAllCurrencies != pAllCurrenciesEnd, "UnoControlModel::ImplGetDefaultValue: did not find the given bank symbol!" );
441 aDefault <<= sCurrencySymbol;
443 break;
445 default: DBG_ERROR( "ImplGetDefaultValue - unknown Property" );
449 return aDefault;
452 void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId, const ::com::sun::star::uno::Any& rDefault )
454 ImplControlProperty* pProp = new ImplControlProperty( nPropId, rDefault );
455 mpData->Insert( nPropId, pProp );
458 void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId )
460 ImplRegisterProperty( nPropId, ImplGetDefaultValue( nPropId ) );
462 if ( nPropId == BASEPROPERTY_FONTDESCRIPTOR )
464 // some properties are not included in the FontDescriptor, but everytime
465 // when we have a FontDescriptor we want to have these properties too.
466 // => Easier to register the here, istead everywhere where I register the FontDescriptor...
468 ImplRegisterProperty( BASEPROPERTY_TEXTCOLOR );
469 ImplRegisterProperty( BASEPROPERTY_TEXTLINECOLOR );
470 ImplRegisterProperty( BASEPROPERTY_FONTRELIEF );
471 ImplRegisterProperty( BASEPROPERTY_FONTEMPHASISMARK );
475 void UnoControlModel::ImplRegisterProperties( const std::list< sal_uInt16 > &rIds )
477 std::list< sal_uInt16 >::const_iterator iter;
478 for( iter = rIds.begin(); iter != rIds.end(); iter++) {
479 if( !ImplHasProperty( *iter ) )
480 ImplRegisterProperty( *iter, ImplGetDefaultValue( *iter ) );
484 // ::com::sun::star::uno::XInterface
485 ::com::sun::star::uno::Any UnoControlModel::queryAggregation( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
487 ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
488 SAL_STATIC_CAST( ::com::sun::star::awt::XControlModel*, this ),
489 SAL_STATIC_CAST( ::com::sun::star::io::XPersistObject*, this ),
490 SAL_STATIC_CAST( ::com::sun::star::lang::XComponent*, this ),
491 SAL_STATIC_CAST( ::com::sun::star::lang::XServiceInfo*, this ),
492 SAL_STATIC_CAST( ::com::sun::star::util::XCloneable*, this ),
493 SAL_STATIC_CAST( ::com::sun::star::beans::XPropertyState*, this ),
494 SAL_STATIC_CAST( ::com::sun::star::beans::XMultiPropertySet*, this ),
495 SAL_STATIC_CAST( ::com::sun::star::beans::XFastPropertySet*, this ),
496 SAL_STATIC_CAST( ::com::sun::star::beans::XPropertySet*, this ),
497 SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ),
498 SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ) );
499 return (aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( rType ));
502 // ::com::sun::star::lang::XUnoTunnel
503 IMPL_XUNOTUNNEL( UnoControlModel )
505 // ::com::sun::star::lang::XTypeProvider
506 IMPL_XTYPEPROVIDER_START( UnoControlModel )
507 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>* ) NULL ),
508 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::io::XPersistObject>* ) NULL ),
509 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>* ) NULL ),
510 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XServiceInfo>* ) NULL ),
511 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable>* ) NULL ),
512 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState>* ) NULL ),
513 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet>* ) NULL ),
514 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet>* ) NULL ),
515 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>* ) NULL )
516 IMPL_XTYPEPROVIDER_END
519 uno::Reference< util::XCloneable > UnoControlModel::createClone() throw(::com::sun::star::uno::RuntimeException)
521 UnoControlModel* pClone = Clone();
522 uno::Reference< util::XCloneable > xClone( (::cppu::OWeakObject*) pClone, uno::UNO_QUERY );
523 return xClone;
526 // ::com::sun::star::lang::XComponent
527 void UnoControlModel::dispose( ) throw(::com::sun::star::uno::RuntimeException)
529 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
531 ::com::sun::star::lang::EventObject aEvt;
532 aEvt.Source = (::com::sun::star::uno::XAggregation*)(::cppu::OWeakAggObject*)this;
533 maDisposeListeners.disposeAndClear( aEvt );
535 // let the property set helper notify our property listeners
536 OPropertySetHelper::disposing();
539 void UnoControlModel::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
541 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
543 maDisposeListeners.addInterface( rxListener );
546 void UnoControlModel::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
548 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
550 maDisposeListeners.removeInterface( rxListener );
554 // ::com::sun::star::beans::XPropertyState
555 ::com::sun::star::beans::PropertyState UnoControlModel::getPropertyState( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
557 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
559 sal_uInt16 nPropId = GetPropertyId( PropertyName );
561 ::com::sun::star::uno::Any aValue = getPropertyValue( PropertyName );
562 ::com::sun::star::uno::Any aDefault = ImplGetDefaultValue( nPropId );
564 return CompareProperties( aValue, aDefault ) ? ::com::sun::star::beans::PropertyState_DEFAULT_VALUE : ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
567 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > UnoControlModel::getPropertyStates( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& PropertyNames ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
569 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
571 sal_uInt32 nNames = PropertyNames.getLength();
572 const ::rtl::OUString* pNames = PropertyNames.getConstArray();
574 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > aStates( nNames );
575 ::com::sun::star::beans::PropertyState* pStates = aStates.getArray();
577 for ( sal_uInt32 n = 0; n < nNames; n++ )
578 pStates[n] = getPropertyState( pNames[n] );
580 return aStates;
583 void UnoControlModel::setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
585 Any aDefaultValue;
587 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
588 aDefaultValue = ImplGetDefaultValue( GetPropertyId( PropertyName ) );
590 setPropertyValue( PropertyName, aDefaultValue );
593 ::com::sun::star::uno::Any UnoControlModel::getPropertyDefault( const ::rtl::OUString& rPropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
595 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
597 return ImplGetDefaultValue( GetPropertyId( rPropertyName ) );
601 // ::com::sun::star::io::XPersistObjec
602 ::rtl::OUString UnoControlModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException)
604 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
606 DBG_ERROR( "ServiceName von UnoControlModel ?!" );
607 return ::rtl::OUString();
610 void UnoControlModel::write( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectOutputStream >& OutStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
612 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
614 ::com::sun::star::uno::Reference< ::com::sun::star::io::XMarkableStream > xMark( OutStream, ::com::sun::star::uno::UNO_QUERY );
615 DBG_ASSERT( xMark.is(), "write: no ::com::sun::star::io::XMarkableStream!" );
617 OutStream->writeShort( UNOCONTROL_STREAMVERSION );
619 ImplPropertyTable aProps;
620 sal_uInt32 i;
621 for ( i = mpData->Count(); i; )
623 ImplControlProperty* pProp = mpData->GetObject( --i );
624 if ( ( ( GetPropertyAttribs( pProp->GetId() ) & ::com::sun::star::beans::PropertyAttribute::TRANSIENT ) == 0 )
625 && ( getPropertyState( GetPropertyName( pProp->GetId() ) ) != ::com::sun::star::beans::PropertyState_DEFAULT_VALUE ) )
627 aProps.Insert( pProp->GetId(), pProp );
631 sal_uInt32 nProps = aProps.Count();
633 // FontProperty wegen fehlender Unterscheidung zwischen 5.0 / 5.1
634 // immer im alten Format mitspeichern.
635 OutStream->writeLong( (long) aProps.IsKeyValid( BASEPROPERTY_FONTDESCRIPTOR ) ? ( nProps + 3 ) : nProps );
636 for ( i = 0; i < nProps; i++ )
638 sal_Int32 nPropDataBeginMark = xMark->createMark();
639 OutStream->writeLong( 0L ); // DataLen
641 ImplControlProperty* pProp = aProps.GetObject( i );
642 OutStream->writeShort( pProp->GetId() );
644 sal_Bool bVoid = pProp->GetValue().getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID;
646 OutStream->writeBoolean( bVoid );
648 if ( !bVoid )
650 const ::com::sun::star::uno::Any& rValue = pProp->GetValue();
651 const ::com::sun::star::uno::Type& rType = rValue.getValueType();
653 if ( rType == ::getBooleanCppuType() )
655 sal_Bool b = false;
656 rValue >>= b;
657 OutStream->writeBoolean( b );
659 else if ( rType == ::getCppuType((const ::rtl::OUString*)0) )
661 ::rtl::OUString aUString;
662 rValue >>= aUString;
663 OutStream->writeUTF( aUString );
665 else if ( rType == ::getCppuType((const sal_uInt16*)0) )
667 sal_uInt16 n = 0;
668 rValue >>= n;
669 OutStream->writeShort( n );
671 else if ( rType == ::getCppuType((const sal_Int16*)0) )
673 sal_Int16 n = 0;
674 rValue >>= n;
675 OutStream->writeShort( n );
677 else if ( rType == ::getCppuType((const sal_uInt32*)0) )
679 sal_uInt32 n = 0;
680 rValue >>= n;
681 OutStream->writeLong( n );
683 else if ( rType == ::getCppuType((const sal_Int32*)0) )
685 sal_Int32 n = 0;
686 rValue >>= n;
687 OutStream->writeLong( n );
689 else if ( rType == ::getCppuType((const double*)0) )
691 double n = 0;
692 rValue >>= n;
693 OutStream->writeDouble( n );
695 else if ( rType == ::getCppuType((const ::com::sun::star::awt::FontDescriptor*)0) )
697 ::com::sun::star::awt::FontDescriptor aFD;
698 rValue >>= aFD;
699 OutStream->writeUTF( aFD.Name );
700 OutStream->writeShort( aFD.Height );
701 OutStream->writeShort( aFD.Width );
702 OutStream->writeUTF( aFD.StyleName );
703 OutStream->writeShort( aFD.Family );
704 OutStream->writeShort( aFD.CharSet );
705 OutStream->writeShort( aFD.Pitch );
706 OutStream->writeDouble( aFD.CharacterWidth );
707 OutStream->writeDouble( aFD.Weight );
708 OutStream->writeShort(
709 sal::static_int_cast< sal_Int16 >(aFD.Slant) );
710 OutStream->writeShort( aFD.Underline );
711 OutStream->writeShort( aFD.Strikeout );
712 OutStream->writeDouble( aFD.Orientation );
713 OutStream->writeBoolean( aFD.Kerning );
714 OutStream->writeBoolean( aFD.WordLineMode );
715 OutStream->writeShort( aFD.Type );
717 else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence< ::rtl::OUString>*)0 ) )
719 ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq;
720 rValue >>= aSeq;
721 long nEntries = aSeq.getLength();
722 OutStream->writeLong( nEntries );
723 for ( long n = 0; n < nEntries; n++ )
724 OutStream->writeUTF( aSeq.getConstArray()[n] );
726 else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_uInt16>*)0 ) )
728 ::com::sun::star::uno::Sequence<sal_uInt16> aSeq;
729 rValue >>= aSeq;
730 long nEntries = aSeq.getLength();
731 OutStream->writeLong( nEntries );
732 for ( long n = 0; n < nEntries; n++ )
733 OutStream->writeShort( aSeq.getConstArray()[n] );
735 else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_Int16>*)0 ) )
737 ::com::sun::star::uno::Sequence<sal_Int16> aSeq;
738 rValue >>= aSeq;
739 long nEntries = aSeq.getLength();
740 OutStream->writeLong( nEntries );
741 for ( long n = 0; n < nEntries; n++ )
742 OutStream->writeShort( aSeq.getConstArray()[n] );
744 else if ( rType.getTypeClass() == TypeClass_ENUM )
746 sal_Int32 nAsInt = 0;
747 ::cppu::enum2int( nAsInt, rValue );
748 OutStream->writeLong( nAsInt );
750 #if OSL_DEBUG_LEVEL > 0
751 else
753 ::rtl::OString sMessage( "UnoControlModel::write: don't know how to handle a property of type '" );
754 ::rtl::OUString sTypeName( rType.getTypeName() );
755 sMessage += ::rtl::OString( sTypeName.getStr(), sTypeName.getLength(), RTL_TEXTENCODING_ASCII_US );
756 sMessage += "'.\n(Currently handling property '";
757 ::rtl::OUString sPropertyName( GetPropertyName( pProp->GetId() ) );
758 sMessage += ::rtl::OString( sPropertyName.getStr(), sPropertyName.getLength(), osl_getThreadTextEncoding() );
759 sMessage += "'.)";
760 DBG_ERROR( sMessage );
762 #endif
765 sal_Int32 nPropDataLen = xMark->offsetToMark( nPropDataBeginMark );
766 xMark->jumpToMark( nPropDataBeginMark );
767 OutStream->writeLong( nPropDataLen );
768 xMark->jumpToFurthest();
769 xMark->deleteMark(nPropDataBeginMark);
772 ImplControlProperty* pProp = aProps.Get( BASEPROPERTY_FONTDESCRIPTOR );
773 if ( pProp )
775 // Solange wir keinen 5.0-Export haben, muss das alte
776 // Format mit rausgeschrieben werden...
777 ::com::sun::star::awt::FontDescriptor aFD;
778 pProp->GetValue() >>= aFD;
780 for ( sal_uInt16 n = BASEPROPERTY_FONT_TYPE; n <= BASEPROPERTY_FONT_ATTRIBS; n++ )
782 sal_Int32 nPropDataBeginMark = xMark->createMark();
783 OutStream->writeLong( 0L ); // DataLen
784 OutStream->writeShort( n ); // PropId
785 OutStream->writeBoolean( sal_False ); // Void
787 if ( n == BASEPROPERTY_FONT_TYPE )
789 OutStream->writeUTF( aFD.Name );
790 OutStream->writeUTF( aFD.StyleName );
791 OutStream->writeShort( aFD.Family );
792 OutStream->writeShort( aFD.CharSet );
793 OutStream->writeShort( aFD.Pitch );
795 else if ( n == BASEPROPERTY_FONT_SIZE )
797 OutStream->writeLong( aFD.Width );
798 OutStream->writeLong( aFD.Height );
799 OutStream->writeShort(
800 sal::static_int_cast< sal_Int16 >(
801 VCLUnoHelper::ConvertFontWidth( aFD.CharacterWidth )) );
803 else if ( n == BASEPROPERTY_FONT_ATTRIBS )
805 OutStream->writeShort(
806 sal::static_int_cast< sal_Int16 >(
807 VCLUnoHelper::ConvertFontWeight( aFD.Weight )) );
808 OutStream->writeShort(
809 sal::static_int_cast< sal_Int16 >(aFD.Slant) );
810 OutStream->writeShort( aFD.Underline );
811 OutStream->writeShort( aFD.Strikeout );
812 OutStream->writeShort( (short)(aFD.Orientation * 10) );
813 OutStream->writeBoolean( aFD.Kerning );
814 OutStream->writeBoolean( aFD.WordLineMode );
816 else
818 DBG_ERROR( "Property?!" );
821 sal_Int32 nPropDataLen = xMark->offsetToMark( nPropDataBeginMark );
822 xMark->jumpToMark( nPropDataBeginMark );
823 OutStream->writeLong( nPropDataLen );
824 xMark->jumpToFurthest();
825 xMark->deleteMark(nPropDataBeginMark);
830 void UnoControlModel::read( const ::com::sun::star::uno::Reference< ::com::sun::star::io::XObjectInputStream >& InStream ) throw(::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
832 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
834 ::com::sun::star::uno::Reference< ::com::sun::star::io::XMarkableStream > xMark( InStream, ::com::sun::star::uno::UNO_QUERY );
835 DBG_ASSERT( xMark.is(), "read: no ::com::sun::star::io::XMarkableStream!" );
837 short nVersion = InStream->readShort();
838 sal_uInt32 nProps = (sal_uInt32)InStream->readLong();
839 ::com::sun::star::uno::Sequence< ::rtl::OUString> aProps( nProps );
840 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> aValues( nProps );
841 sal_Bool bInvalidEntries = sal_False;
843 // Dummerweise kein Mark fuer den gesamten Block, es koennen also
844 // nur Properties geaendert werden, es koennen aber nicht spaeter mal Daten
845 // fuer das Model hinter den Properties geschrieben werden.
847 // Fuer den Import der alten ::com::sun::star::awt::FontDescriptor-Teile
848 ::com::sun::star::awt::FontDescriptor* pFD = NULL;
850 sal_uInt32 i;
851 for ( i = 0; i < nProps; i++ )
853 sal_Int32 nPropDataBeginMark = xMark->createMark();
854 sal_Int32 nPropDataLen = InStream->readLong();
856 sal_uInt16 nPropId = (sal_uInt16)InStream->readShort();
858 ::com::sun::star::uno::Any aValue;
859 sal_Bool bIsVoid = InStream->readBoolean();
860 if ( !bIsVoid )
862 const ::com::sun::star::uno::Type* pType = mpData->Get( nPropId ) ? GetPropertyType( nPropId ) : NULL;
863 if ( pType )
865 if ( *pType == ::getBooleanCppuType() )
867 sal_Bool b = InStream->readBoolean();
868 aValue <<= b;
870 else if ( *pType == ::getCppuType((const ::rtl::OUString*)0) )
872 ::rtl::OUString aUTF = InStream->readUTF();
873 aValue <<= aUTF;
875 else if ( *pType == ::getCppuType((const sal_uInt16*)0) )
877 sal_uInt16 n = InStream->readShort();
878 aValue <<= n;
880 else if ( *pType == ::getCppuType((const sal_Int16*)0) )
882 sal_Int16 n = InStream->readShort();
883 aValue <<= n;
885 else if ( *pType == ::getCppuType((const sal_uInt32*)0) )
887 sal_uInt32 n = InStream->readLong();
888 aValue <<= n;
890 else if ( *pType == ::getCppuType((const sal_Int32*)0) )
892 sal_Int32 n = InStream->readLong();
893 aValue <<= n;
895 else if ( *pType == ::getCppuType((const double*)0) )
897 double n = InStream->readDouble();
898 aValue <<= n;
900 else if ( *pType == ::getCppuType((const ::com::sun::star::awt::FontDescriptor*)0) )
902 ::com::sun::star::awt::FontDescriptor aFD;
903 aFD.Name = InStream->readUTF();
904 aFD.Height = InStream->readShort();
905 aFD.Width = InStream->readShort();
906 aFD.StyleName = InStream->readUTF();
907 aFD.Family = InStream->readShort();
908 aFD.CharSet = InStream->readShort();
909 aFD.Pitch = InStream->readShort();
910 aFD.CharacterWidth = (float)InStream->readDouble();
911 aFD.Weight = (float)InStream->readDouble();
912 aFD.Slant = (::com::sun::star::awt::FontSlant)InStream->readShort();
913 aFD.Underline = InStream->readShort();
914 aFD.Strikeout = InStream->readShort();
915 aFD.Orientation = (float)InStream->readDouble();
916 aFD.Kerning = InStream->readBoolean();
917 aFD.WordLineMode = InStream->readBoolean();
918 aFD.Type = InStream->readShort();
919 aValue <<= aFD;
921 else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence< ::rtl::OUString>*)0 ) )
923 long nEntries = InStream->readLong();
924 ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq( nEntries );
925 for ( long n = 0; n < nEntries; n++ )
926 aSeq.getArray()[n] = InStream->readUTF();
927 aValue <<= aSeq;
930 else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_uInt16>*)0 ) )
933 long nEntries = InStream->readLong();
934 ::com::sun::star::uno::Sequence<sal_uInt16> aSeq( nEntries );
935 for ( long n = 0; n < nEntries; n++ )
936 aSeq.getArray()[n] = (sal_uInt16)InStream->readShort();
937 aValue <<= aSeq;
939 else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_Int16>*)0 ) )
941 long nEntries = InStream->readLong();
942 ::com::sun::star::uno::Sequence<sal_Int16> aSeq( nEntries );
943 for ( long n = 0; n < nEntries; n++ )
944 aSeq.getArray()[n] = (sal_Int16)InStream->readShort();
945 aValue <<= aSeq;
947 else if ( pType->getTypeClass() == TypeClass_ENUM )
949 sal_Int32 nAsInt = InStream->readLong();
950 aValue = ::cppu::int2enum( nAsInt, *pType );
952 else
954 ::rtl::OString sMessage( "UnoControlModel::read: don't know how to handle a property of type '" );
955 ::rtl::OUString sTypeName( pType->getTypeName() );
956 sMessage += ::rtl::OString( sTypeName.getStr(), sTypeName.getLength(), RTL_TEXTENCODING_ASCII_US );
957 sMessage += "'.\n(Currently handling property '";
958 ::rtl::OUString sPropertyName( GetPropertyName( nPropId ) );
959 sMessage += ::rtl::OString( sPropertyName.getStr(), sPropertyName.getLength(), osl_getThreadTextEncoding() );
960 sMessage += "'.)";
961 DBG_ERROR( sMessage );
964 else
966 // Altes Geraffel aus 5.0
967 if ( nPropId == BASEPROPERTY_FONT_TYPE )
969 // Sonst ist es nur die redundante Info fuer alte Versionen
970 // Daten werden durch MarkableStream geskippt.
971 if ( nVersion < 2 )
973 if ( !pFD )
975 pFD = new ::com::sun::star::awt::FontDescriptor;
976 ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR );
977 if ( pProp ) // wegen den Defaults...
978 pProp->GetValue() >>= *pFD;
980 pFD->Name = InStream->readUTF();
981 pFD->StyleName = InStream->readUTF();
982 pFD->Family = InStream->readShort();
983 pFD->CharSet = InStream->readShort();
984 pFD->Pitch = InStream->readShort();
987 else if ( nPropId == BASEPROPERTY_FONT_SIZE )
989 if ( nVersion < 2 )
991 if ( !pFD )
993 pFD = new ::com::sun::star::awt::FontDescriptor;
994 ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR );
995 if ( pProp ) // wegen den Defaults...
996 pProp->GetValue() >>= *pFD;
998 pFD->Width = (sal_Int16)InStream->readLong();
999 pFD->Height = (sal_Int16)InStream->readLong();
1000 InStream->readShort(); // ::com::sun::star::awt::FontWidth ignorieren - wurde mal falsch geschrieben und wird nicht gebraucht.
1001 pFD->CharacterWidth = ::com::sun::star::awt::FontWidth::DONTKNOW;
1004 else if ( nPropId == BASEPROPERTY_FONT_ATTRIBS )
1006 if ( nVersion < 2 )
1008 if ( !pFD )
1010 pFD = new ::com::sun::star::awt::FontDescriptor;
1011 ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR );
1012 if ( pProp ) // wegen den Defaults...
1013 pProp->GetValue() >>= *pFD;
1015 pFD->Weight = VCLUnoHelper::ConvertFontWeight( (FontWeight) InStream->readShort() );
1016 pFD->Slant = (::com::sun::star::awt::FontSlant)InStream->readShort();
1017 pFD->Underline = InStream->readShort();
1018 pFD->Strikeout = InStream->readShort();
1019 pFD->Orientation = ( (float)(double)InStream->readShort() ) / 10;
1020 pFD->Kerning = InStream->readBoolean();
1021 pFD->WordLineMode = InStream->readBoolean();
1024 else
1026 DBG_ERROR( "read: unknown Property!" );
1030 else // bVoid
1032 if ( nPropId == BASEPROPERTY_FONTDESCRIPTOR )
1034 EmptyFontDescriptor aFD;
1035 aValue <<= aFD;
1039 if ( mpData->Get( nPropId ) )
1041 aProps.getArray()[i] = GetPropertyName( nPropId );
1042 aValues.getArray()[i] = aValue;
1044 else
1046 bInvalidEntries = sal_True;
1049 // Falls bereits mehr drinsteht als diese Version kennt:
1050 xMark->jumpToMark( nPropDataBeginMark );
1051 InStream->skipBytes( nPropDataLen );
1052 xMark->deleteMark(nPropDataBeginMark);
1054 if ( bInvalidEntries )
1056 for ( i = 0; i < (sal_uInt32)aProps.getLength(); i++ )
1058 if ( !aProps.getConstArray()[i].getLength() )
1060 ::comphelper::removeElementAt( aProps, i );
1061 ::comphelper::removeElementAt( aValues, i );
1062 i--;
1069 setPropertyValues( aProps, aValues );
1071 catch ( const Exception& )
1073 DBG_UNHANDLED_EXCEPTION();
1076 if ( pFD )
1078 ::com::sun::star::uno::Any aValue;
1079 aValue <<= *pFD;
1080 setPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR ), aValue );
1081 delete pFD;
1086 // ::com::sun::star::lang::XServiceInfo
1087 ::rtl::OUString UnoControlModel::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException)
1089 DBG_ERROR( "This method should be overloaded!" );
1090 return ::rtl::OUString();
1094 sal_Bool UnoControlModel::supportsService( const ::rtl::OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException)
1096 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1098 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
1099 const ::rtl::OUString * pArray = aSNL.getConstArray();
1100 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
1101 if( pArray[i] == rServiceName )
1102 return sal_True;
1103 return sal_False;
1106 ::com::sun::star::uno::Sequence< ::rtl::OUString > UnoControlModel::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
1108 ::rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlModel" ) );
1109 return Sequence< ::rtl::OUString >( &sName, 1 );
1112 // ::cppu::OPropertySetHelper
1113 ::cppu::IPropertyArrayHelper& UnoControlModel::getInfoHelper()
1115 DBG_ERROR( "UnoControlModel::getInfoHelper() not possible!" );
1116 return *(::cppu::IPropertyArrayHelper*) NULL;
1119 // ------------------------------------------------------------------
1120 template <class TYPE>
1121 sal_Bool convertType(Any& _rConvertedValue, const Any& _rNewValueTest, const TYPE* /* _pTypeDisambiguation */)
1123 TYPE tValue;
1124 if (_rNewValueTest >>= tValue)
1126 _rConvertedValue <<= tValue;
1127 return sal_True;
1131 // ..................................................................
1132 sal_Bool UnoControlModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nPropId, const Any& rValue ) throw (IllegalArgumentException)
1134 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1136 sal_Bool bVoid = rValue.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID;
1137 if ( bVoid )
1139 rConvertedValue.clear();
1141 else
1143 const ::com::sun::star::uno::Type* pDestType = GetPropertyType( (sal_uInt16)nPropId );
1144 if ( pDestType->getTypeClass() == TypeClass_ANY )
1146 rConvertedValue = rValue;
1148 else
1150 if ( pDestType->equals( rValue.getValueType() ) )
1152 rConvertedValue = rValue;
1154 else
1156 BOOL bConverted = FALSE;
1157 // 13.03.2001 - 84923 - frank.schoenheit@germany.sun.com
1159 switch (pDestType->getTypeClass())
1161 case TypeClass_DOUBLE:
1163 // try as double
1164 double nAsDouble = 0;
1165 bConverted = ( rValue >>= nAsDouble );
1166 if ( bConverted )
1167 rConvertedValue <<= nAsDouble;
1168 else
1169 { // try as integer - 96136 - 2002-10-08 - fs@openoffice.org
1170 sal_Int32 nAsInteger = 0;
1171 bConverted = ( rValue >>= nAsInteger );
1172 if ( bConverted )
1173 rConvertedValue <<= (double)nAsInteger;
1176 break;
1177 case TypeClass_SHORT:
1179 sal_Int16 n;
1180 bConverted = ( rValue >>= n );
1181 if ( bConverted )
1182 rConvertedValue <<= n;
1184 break;
1185 case TypeClass_UNSIGNED_SHORT:
1187 sal_uInt16 n;
1188 bConverted = ( rValue >>= n );
1189 if ( bConverted )
1190 rConvertedValue <<= n;
1192 break;
1193 case TypeClass_LONG:
1195 sal_Int32 n;
1196 bConverted = ( rValue >>= n );
1197 if ( bConverted )
1198 rConvertedValue <<= n;
1200 break;
1201 case TypeClass_UNSIGNED_LONG:
1203 sal_uInt32 n;
1204 bConverted = ( rValue >>= n );
1205 if ( bConverted )
1206 rConvertedValue <<= n;
1208 break;
1209 case TypeClass_INTERFACE:
1211 if ( rValue.getValueType().getTypeClass() == TypeClass_INTERFACE )
1213 Reference< XInterface > xPure( rValue, UNO_QUERY );
1214 if ( xPure.is() )
1215 rConvertedValue = xPure->queryInterface( *pDestType );
1216 else
1217 rConvertedValue.setValue( NULL, *pDestType );
1218 bConverted = sal_True;
1221 break;
1222 case TypeClass_ENUM:
1224 sal_Int32 nValue = 0;
1225 bConverted = ( rValue >>= nValue );
1226 if ( bConverted )
1227 rConvertedValue = ::cppu::int2enum( nValue, *pDestType );
1229 break;
1230 default: ; // avoid compiler warning
1233 if (!bConverted)
1235 ::rtl::OUStringBuffer aErrorMessage;
1236 aErrorMessage.appendAscii( "Unable to convert the given value for the property " );
1237 aErrorMessage.append ( GetPropertyName( (sal_uInt16)nPropId ) );
1238 aErrorMessage.appendAscii( ".\n" );
1239 aErrorMessage.appendAscii( "Expected type: " );
1240 aErrorMessage.append ( pDestType->getTypeName() );
1241 aErrorMessage.appendAscii( "\n" );
1242 aErrorMessage.appendAscii( "Found type: " );
1243 aErrorMessage.append ( rValue.getValueType().getTypeName() );
1244 throw ::com::sun::star::lang::IllegalArgumentException(
1245 aErrorMessage.makeStringAndClear(),
1246 static_cast< ::com::sun::star::beans::XPropertySet* >(this),
1253 // the current value
1254 getFastPropertyValue( rOldValue, nPropId );
1255 return !CompareProperties( rConvertedValue, rOldValue );
1258 void UnoControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception)
1260 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1262 // Fehlt: Die gefakten Einzelproperties des FontDescriptors...
1264 ImplControlProperty* pProp = mpData->Get( nPropId );
1265 if ( pProp )
1267 DBG_ASSERT( ( rValue.getValueType().getTypeClass() != ::com::sun::star::uno::TypeClass_VOID ) || ( GetPropertyAttribs( (sal_uInt16)nPropId ) & ::com::sun::star::beans::PropertyAttribute::MAYBEVOID ), "Property darf nicht VOID sein!" );
1268 ImplPropertyChanged( (sal_uInt16)nPropId );
1269 pProp->SetValue( rValue );
1271 else
1273 // exception...
1274 DBG_ERROR( "SetPropertyValues: Invalid Property!" );
1278 void UnoControlModel::getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nPropId ) const
1280 ::osl::Guard< ::osl::Mutex > aGuard( ((UnoControlModel*)this)->GetMutex() );
1282 ImplControlProperty* pProp = mpData->Get( nPropId );
1284 if ( pProp )
1285 rValue = pProp->GetValue();
1286 else if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1288 pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR );
1289 ::com::sun::star::awt::FontDescriptor aFD;
1290 pProp->GetValue() >>= aFD;
1291 switch ( nPropId )
1293 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: rValue <<= aFD.Name;
1294 break;
1295 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: rValue <<= aFD.StyleName;
1296 break;
1297 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: rValue <<= aFD.Family;
1298 break;
1299 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: rValue <<= aFD.CharSet;
1300 break;
1301 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: rValue <<= (float)aFD.Height;
1302 break;
1303 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: rValue <<= aFD.Weight;
1304 break;
1305 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: rValue <<= (sal_Int16)aFD.Slant;
1306 break;
1307 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: rValue <<= aFD.Underline;
1308 break;
1309 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: rValue <<= aFD.Strikeout;
1310 break;
1311 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: rValue <<= aFD.Width;
1312 break;
1313 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: rValue <<= aFD.Pitch;
1314 break;
1315 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: rValue <<= aFD.CharacterWidth;
1316 break;
1317 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: rValue <<= aFD.Orientation;
1318 break;
1319 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: rValue <<= aFD.Kerning;
1320 break;
1321 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: rValue <<= aFD.WordLineMode;
1322 break;
1323 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: rValue <<= aFD.Type;
1324 break;
1325 default: DBG_ERROR( "FontProperty?!" );
1328 else
1330 DBG_ERROR( "getFastPropertyValue - invalid Property!" );
1334 // ::com::sun::star::beans::XPropertySet
1335 void UnoControlModel::setPropertyValue( const ::rtl::OUString& rPropertyName, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1337 sal_Int32 nPropId = 0;
1339 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1340 nPropId = (sal_Int32) GetPropertyId( rPropertyName );
1341 DBG_ASSERT( nPropId, "Invalid ID in UnoControlModel::setPropertyValue" );
1343 if( nPropId )
1344 setFastPropertyValue( nPropId, rValue );
1345 else
1346 throw ::com::sun::star::beans::UnknownPropertyException();
1349 // ::com::sun::star::beans::XFastPropertySet
1350 void UnoControlModel::setFastPropertyValue( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1352 if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1354 ::osl::ClearableMutexGuard aGuard( GetMutex() );
1356 Any aOldSingleValue;
1357 getFastPropertyValue( aOldSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START );
1359 ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR );
1360 FontDescriptor aOldFontDescriptor;
1361 pProp->GetValue() >>= aOldFontDescriptor;
1363 FontDescriptor aNewFontDescriptor( aOldFontDescriptor );
1364 lcl_ImplMergeFontProperty( aNewFontDescriptor, (sal_uInt16)nPropId, rValue );
1366 Any aNewValue;
1367 aNewValue <<= aNewFontDescriptor;
1368 sal_Int32 nDescriptorId( BASEPROPERTY_FONTDESCRIPTOR );
1369 nDescriptorId = BASEPROPERTY_FONTDESCRIPTOR;
1371 // also, we need fire a propertyChange event for the single property, since with
1372 // the above line, only an event for the FontDescriptor property will be fired
1373 Any aNewSingleValue;
1374 getFastPropertyValue( aNewSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START );
1376 aGuard.clear();
1377 setFastPropertyValues( 1, &nDescriptorId, &aNewValue, 1 );
1378 fire( &nPropId, &aNewSingleValue, &aOldSingleValue, 1, sal_False );
1380 else
1381 setFastPropertyValues( 1, &nPropId, &rValue, 1 );
1384 // ::com::sun::star::beans::XMultiPropertySet
1385 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > UnoControlModel::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
1387 DBG_ERROR( "UnoControlModel::getPropertySetInfo() not possible!" );
1388 return ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >();
1391 void UnoControlModel::setPropertyValues( const ::com::sun::star::uno::Sequence< ::rtl::OUString >& rPropertyNames, const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Values ) throw(::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
1393 ::osl::ClearableMutexGuard aGuard( GetMutex() );
1395 sal_Int32 nProps = rPropertyNames.getLength();
1397 // sal_Int32* pHandles = new sal_Int32[nProps];
1398 // don't do this - it leaks in case of an exception
1399 Sequence< sal_Int32 > aHandles( nProps );
1400 sal_Int32* pHandles = aHandles.getArray();
1402 // may need to change the order in the sequence, for this we need a non-const value sequence
1403 // 15.05.2002 - 99314 - fs@openoffice.org
1404 uno::Sequence< uno::Any > aValues( Values );
1405 uno::Any* pValues = aValues.getArray();
1407 sal_Int32 nValidHandles = getInfoHelper().fillHandles( pHandles, rPropertyNames );
1409 if ( nValidHandles )
1411 // if somebody sets properties which are single aspects of a font descriptor,
1412 // remove them, and build a font descriptor instead
1413 ::std::auto_ptr< awt::FontDescriptor > pFD;
1414 for ( sal_uInt16 n = 0; n < nProps; ++n )
1416 if ( ( pHandles[n] >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( pHandles[n] <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1418 if ( !pFD.get() )
1420 ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR );
1421 pFD.reset( new awt::FontDescriptor );
1422 pProp->GetValue() >>= *pFD;
1424 lcl_ImplMergeFontProperty( *pFD, (sal_uInt16)pHandles[n], pValues[n] );
1425 pHandles[n] = -1;
1426 nValidHandles--;
1430 if ( nValidHandles )
1432 ImplNormalizePropertySequence( nProps, pHandles, pValues, &nValidHandles );
1433 aGuard.clear();
1434 // clear our guard before calling into setFastPropertyValues - this method
1435 // will implicitly call property listeners, and this should not happen with
1436 // our mutex locked
1437 // #i23451# - 2004-03-18 - fs@openoffice.org
1438 setFastPropertyValues( nProps, pHandles, pValues, nValidHandles );
1440 else
1441 aGuard.clear();
1442 // same as a few lines above
1444 // FD-Propertie nicht in das Array mergen, weil sortiert...
1445 if ( pFD.get() )
1447 ::com::sun::star::uno::Any aValue;
1448 aValue <<= *pFD;
1449 sal_Int32 nHandle = BASEPROPERTY_FONTDESCRIPTOR;
1450 setFastPropertyValues( 1, &nHandle, &aValue, 1 );
1457 void UnoControlModel::ImplNormalizePropertySequence( const sal_Int32, sal_Int32*,
1458 uno::Any*, sal_Int32* ) const SAL_THROW(())
1460 // nothing to do here
1463 void UnoControlModel::ImplEnsureHandleOrder( const sal_Int32 _nCount, sal_Int32* _pHandles,
1464 uno::Any* _pValues, sal_Int32 _nFirstHandle, sal_Int32 _nSecondHandle ) const
1466 for ( sal_Int32 i=0; i < _nCount; ++_pHandles, ++_pValues, ++i )
1468 if ( _nSecondHandle == *_pHandles )
1470 sal_Int32* pLaterHandles = _pHandles + 1;
1471 uno::Any* pLaterValues = _pValues + 1;
1472 for ( sal_Int32 j = i + 1; j < _nCount; ++j, ++pLaterHandles, ++pLaterValues )
1474 if ( _nFirstHandle == *pLaterHandles )
1476 // indeed it is -> exchange the both places in the sequences
1477 sal_Int32 nHandle( *_pHandles );
1478 *_pHandles = *pLaterHandles;
1479 *pLaterHandles = nHandle;
1481 uno::Any aValue( *_pValues );
1482 *_pValues = *pLaterValues;
1483 *pLaterValues = aValue;
1485 break;
1486 // this will leave the inner loop, and continue with the outer loop.
1487 // Note that this means we will encounter the _nSecondHandle handle, again, once we reached
1488 // (in the outer loop) the place where we just put it.