update dev300-m58
[ooovba.git] / toolkit / source / controls / unocontrolmodel.cxx
blob782e5c3d5e0110b9d128be4406ff4693ab89c7f4
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/awt/MouseWheelBehavior.hpp>
40 #include <com/sun/star/graphic/XGraphicProvider.hpp>
41 #include <com/sun/star/text/WritingMode2.hpp>
42 #include <com/sun/star/io/XMarkableStream.hpp>
43 #include <toolkit/controls/unocontrolmodel.hxx>
44 #include <toolkit/helper/macros.hxx>
45 #include <cppuhelper/typeprovider.hxx>
46 #include <cppuhelper/extract.hxx>
47 #include <rtl/memory.h>
48 #include <rtl/uuid.h>
49 #include <tools/diagnose_ex.h>
50 #include <tools/string.hxx>
51 #include <tools/table.hxx>
52 #include <tools/date.hxx>
53 #include <tools/time.hxx>
54 #include <tools/urlobj.hxx>
55 #include <tools/debug.hxx>
56 #include <toolkit/helper/property.hxx>
57 #include <toolkit/helper/vclunohelper.hxx>
58 #include <toolkit/helper/emptyfontdescriptor.hxx>
59 #include <com/sun/star/lang/Locale.hpp>
60 #include <unotools/localedatawrapper.hxx>
61 #include <unotools/configmgr.hxx>
62 #include <comphelper/processfactory.hxx>
63 #include <comphelper/sequence.hxx>
64 #include <vcl/svapp.hxx>
65 #include <uno/data.h>
67 #include <memory>
69 using namespace ::com::sun::star;
70 using namespace ::com::sun::star::uno;
71 using namespace ::com::sun::star::lang;
72 using namespace ::com::sun::star::i18n;
73 using ::com::sun::star::awt::FontDescriptor;
75 struct ImplControlProperty
77 private:
78 sal_uInt16 nId;
79 ::com::sun::star::uno::Any aValue;
81 public:
82 ImplControlProperty( const ImplControlProperty& rProp ) : aValue( rProp.aValue )
84 nId = rProp.nId;
87 ImplControlProperty( sal_uInt16 nT )
89 nId = nT;
92 ImplControlProperty( sal_uInt16 nT, const ::com::sun::star::uno::Any& rValue ) : aValue( rValue )
94 nId = nT;
97 sal_uInt16 GetId() const { return nId; }
98 const ::com::sun::star::uno::Any& GetValue() const { return aValue; }
99 void SetValue( const ::com::sun::star::uno::Any& rValue ) { aValue = rValue; }
102 DECLARE_TABLE( ImplPropertyTable, ImplControlProperty* )
104 #define UNOCONTROL_STREAMVERSION (short)2
106 static void lcl_ImplMergeFontProperty( FontDescriptor& rFD, sal_uInt16 nPropId, const Any& rValue )
108 // some props are defined with other types than the matching FontDescriptor members have
109 // (e.g. FontWidth, FontSlant)
110 // 78474 - 09/19/2000 - FS
111 float nExtractFloat = 0;
112 sal_Int16 nExtractShort = 0;
114 switch ( nPropId )
116 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: rValue >>= rFD.Name;
117 break;
118 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: rValue >>= rFD.StyleName;
119 break;
120 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: rValue >>= rFD.Family;
121 break;
122 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: rValue >>= rFD.CharSet;
123 break;
124 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: rValue >>= nExtractFloat; rFD.Height = (sal_Int16)nExtractFloat;
125 break;
126 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: rValue >>= rFD.Weight;
127 break;
128 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: if ( rValue >>= nExtractShort )
129 rFD.Slant = (::com::sun::star::awt::FontSlant)nExtractShort;
130 else
131 rValue >>= rFD.Slant;
132 break;
133 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: rValue >>= rFD.Underline;
134 break;
135 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: rValue >>= rFD.Strikeout;
136 break;
137 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: rValue >>= rFD.Width;
138 break;
139 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: rValue >>= rFD.Pitch;
140 break;
141 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: rValue >>= rFD.CharacterWidth;
142 break;
143 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: rValue >>= rFD.Orientation;
144 break;
145 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: rValue >>= rFD.Kerning;
146 break;
147 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: rValue >>= rFD.WordLineMode;
148 break;
149 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: rValue >>= rFD.Type;
150 break;
151 default: DBG_ERROR( "FontProperty?!" );
155 // ----------------------------------------------------
156 // class UnoControlModel
157 // ----------------------------------------------------
158 UnoControlModel::UnoControlModel()
159 : OPropertySetHelper( BrdcstHelper ), maDisposeListeners( *this )
161 // Die Properties muessen vom Model in die Tabelle gestopft werden,
162 // nur vorhandene Properties sind gueltige Properties, auch wenn VOID.
163 mpData = new ImplPropertyTable;
166 UnoControlModel::UnoControlModel( const UnoControlModel& rModel )
167 : XControlModel()
168 , XPropertyState()
169 , XPersistObject()
170 , XComponent()
171 , XServiceInfo()
172 , XTypeProvider()
173 , XUnoTunnel()
174 , XCloneable()
175 , MutexAndBroadcastHelper()
176 , OPropertySetHelper( BrdcstHelper )
177 , OWeakAggObject()
178 , maDisposeListeners( *this )
180 mpData = new ImplPropertyTable;
182 for ( sal_uInt32 n = rModel.mpData->Count(); n; )
184 ImplControlProperty* pProp = rModel.mpData->GetObject( --n );
185 ImplControlProperty* pNew = new ImplControlProperty( *pProp );
186 mpData->Insert( pNew->GetId(), pNew );
190 UnoControlModel::~UnoControlModel()
192 for ( sal_uInt32 n = mpData->Count(); n; )
193 delete mpData->GetObject( --n );
194 delete mpData;
197 UnoControlModel* UnoControlModel::Clone() const
199 DBG_ERROR( "UnoControlModel::Clone() ?!" );
200 return NULL;
203 ::com::sun::star::uno::Sequence<sal_Int32> UnoControlModel::ImplGetPropertyIds() const
205 sal_uInt32 nIDs = mpData->Count();
206 ::com::sun::star::uno::Sequence<sal_Int32> aIDs( nIDs );
207 sal_Int32* pIDs = aIDs.getArray();
208 for ( sal_uInt32 n = 0; n < nIDs; n++ )
209 pIDs[n] = mpData->GetObjectKey( n );
210 return aIDs;
213 sal_Bool UnoControlModel::ImplHasProperty( sal_uInt16 nPropId ) const
215 if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
216 nPropId = BASEPROPERTY_FONTDESCRIPTOR;
218 return mpData->Get( nPropId ) ? sal_True : sal_False;
221 void UnoControlModel::ImplPropertyChanged( sal_uInt16 )
225 ::com::sun::star::uno::Any UnoControlModel::ImplGetDefaultValue( sal_uInt16 nPropId ) const
227 ::com::sun::star::uno::Any aDefault;
229 if (
230 (nPropId == BASEPROPERTY_FONTDESCRIPTOR) ||
232 (nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START) &&
233 (nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END)
237 EmptyFontDescriptor aFD;
238 switch ( nPropId )
240 case BASEPROPERTY_FONTDESCRIPTOR: aDefault <<= aFD; break;
241 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: aDefault <<= aFD.Name; break;
242 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: aDefault <<= aFD.StyleName; break;
243 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: aDefault <<= aFD.Family; break;
244 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: aDefault <<= aFD.CharSet; break;
245 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: aDefault <<= (float)aFD.Height; break;
246 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: aDefault <<= aFD.Weight; break;
247 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: aDefault <<= (sal_Int16)aFD.Slant; break;
248 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: aDefault <<= aFD.Underline; break;
249 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: aDefault <<= aFD.Strikeout; break;
250 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: aDefault <<= aFD.Width; break;
251 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: aDefault <<= aFD.Pitch; break;
252 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: aDefault <<= aFD.CharacterWidth; break;
253 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: aDefault <<= aFD.Orientation; break;
254 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: aDefault <<= aFD.Kerning; break;
255 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: aDefault <<= aFD.WordLineMode; break;
256 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: aDefault <<= aFD.Type; break;
257 default: DBG_ERROR( "FontProperty?!" );
260 else
262 switch ( nPropId )
264 case BASEPROPERTY_GRAPHIC:
265 aDefault <<= makeAny( Reference< graphic::XGraphic >() );
266 break;
268 case BASEPROPERTY_VERTICALALIGN:
269 case BASEPROPERTY_BORDERCOLOR:
270 case BASEPROPERTY_SYMBOL_COLOR:
271 case BASEPROPERTY_TABSTOP:
272 case BASEPROPERTY_TEXTCOLOR:
273 case BASEPROPERTY_TEXTLINECOLOR:
274 case BASEPROPERTY_DATE:
275 case BASEPROPERTY_DATESHOWCENTURY:
276 case BASEPROPERTY_TIME:
277 case BASEPROPERTY_VALUE_DOUBLE:
278 case BASEPROPERTY_PROGRESSVALUE:
279 case BASEPROPERTY_SCROLLVALUE:
280 case BASEPROPERTY_VISIBLESIZE:
281 case BASEPROPERTY_BACKGROUNDCOLOR:
282 case BASEPROPERTY_FILLCOLOR: break; // Void
284 case BASEPROPERTY_FONTRELIEF:
285 case BASEPROPERTY_FONTEMPHASISMARK:
286 case BASEPROPERTY_MAXTEXTLEN:
287 case BASEPROPERTY_STATE:
288 case BASEPROPERTY_EXTDATEFORMAT:
289 case BASEPROPERTY_EXTTIMEFORMAT:
290 case BASEPROPERTY_ECHOCHAR: aDefault <<= (sal_Int16) 0; break;
291 case BASEPROPERTY_BORDER: aDefault <<= (sal_Int16) 1; break;
292 case BASEPROPERTY_DECIMALACCURACY: aDefault <<= (sal_Int16) 2; break;
293 case BASEPROPERTY_LINECOUNT: aDefault <<= (sal_Int16) 5; break;
294 case BASEPROPERTY_ALIGN: aDefault <<= (sal_Int16) PROPERTY_ALIGN_LEFT; break;
295 case BASEPROPERTY_IMAGEALIGN: aDefault <<= (sal_Int16) 1 /*ImageAlign::TOP*/; break;
296 case BASEPROPERTY_IMAGEPOSITION: aDefault <<= (sal_Int16) 12 /*ImagePosition::Centered*/; break;
297 case BASEPROPERTY_PUSHBUTTONTYPE: aDefault <<= (sal_Int16) 0 /*PushButtonType::STANDARD*/; break;
298 case BASEPROPERTY_MOUSE_WHEEL_BEHAVIOUR:aDefault <<= (sal_Int16) awt::MouseWheelBehavior::SCROLL_FOCUS_ONLY; break;
300 case BASEPROPERTY_DATEMAX: aDefault <<= (sal_Int32) Date( 31, 12, 2200 ).GetDate(); break;
301 case BASEPROPERTY_DATEMIN: aDefault <<= (sal_Int32) Date( 1, 1, 1900 ).GetDate(); break;
302 case BASEPROPERTY_TIMEMAX: aDefault <<= (sal_Int32) Time( 23, 59 ).GetTime(); break;
303 case BASEPROPERTY_TIMEMIN: aDefault <<= (sal_Int32) 0; break;
304 case BASEPROPERTY_VALUEMAX_DOUBLE: aDefault <<= (double) 1000000; break;
305 case BASEPROPERTY_VALUEMIN_DOUBLE: aDefault <<= (double) -1000000; break;
306 case BASEPROPERTY_VALUESTEP_DOUBLE: aDefault <<= (double ) 1; break;
307 case BASEPROPERTY_PROGRESSVALUE_MAX: aDefault <<= (sal_Int32) 100; break;
308 case BASEPROPERTY_PROGRESSVALUE_MIN: aDefault <<= (sal_Int32) 0; break;
309 case BASEPROPERTY_SCROLLVALUE_MAX: aDefault <<= (sal_Int32) 100; break;
310 case BASEPROPERTY_SCROLLVALUE_MIN: aDefault <<= (sal_Int32) 0; break;
311 case BASEPROPERTY_LINEINCREMENT: aDefault <<= (sal_Int32) 1; break;
312 case BASEPROPERTY_BLOCKINCREMENT: aDefault <<= (sal_Int32) 10; break;
313 case BASEPROPERTY_ORIENTATION: aDefault <<= (sal_Int32) 0; break;
314 case BASEPROPERTY_SPINVALUE: aDefault <<= (sal_Int32) 0; break;
315 case BASEPROPERTY_SPININCREMENT: aDefault <<= (sal_Int32) 1; break;
316 case BASEPROPERTY_SPINVALUE_MIN: aDefault <<= (sal_Int32) 0; break;
317 case BASEPROPERTY_SPINVALUE_MAX: aDefault <<= (sal_Int32) 100; break;
318 case BASEPROPERTY_REPEAT_DELAY: aDefault <<= (sal_Int32) 50; break; // 50 milliseconds
319 case BASEPROPERTY_DEFAULTCONTROL: aDefault <<= ((UnoControlModel*)this)->getServiceName(); break;
321 case BASEPROPERTY_AUTOHSCROLL:
322 case BASEPROPERTY_AUTOVSCROLL:
323 case BASEPROPERTY_MOVEABLE:
324 case BASEPROPERTY_CLOSEABLE:
325 case BASEPROPERTY_SIZEABLE:
326 case BASEPROPERTY_HSCROLL:
327 case BASEPROPERTY_DEFAULTBUTTON:
328 case BASEPROPERTY_MULTILINE:
329 case BASEPROPERTY_MULTISELECTION:
330 case BASEPROPERTY_TRISTATE:
331 case BASEPROPERTY_DROPDOWN:
332 case BASEPROPERTY_SPIN:
333 case BASEPROPERTY_READONLY:
334 case BASEPROPERTY_VSCROLL:
335 case BASEPROPERTY_NUMSHOWTHOUSANDSEP:
336 case BASEPROPERTY_STRICTFORMAT:
337 case BASEPROPERTY_REPEAT:
338 case BASEPROPERTY_PAINTTRANSPARENT:
339 case BASEPROPERTY_DESKTOP_AS_PARENT:
340 case BASEPROPERTY_HARDLINEBREAKS:
341 case BASEPROPERTY_NOLABEL: aDefault <<= (sal_Bool) sal_False; break;
343 case BASEPROPERTY_HIDEINACTIVESELECTION:
344 case BASEPROPERTY_ENFORCE_FORMAT:
345 case BASEPROPERTY_AUTOCOMPLETE:
346 case BASEPROPERTY_SCALEIMAGE:
347 case BASEPROPERTY_ENABLED:
348 case BASEPROPERTY_PRINTABLE:
349 case BASEPROPERTY_ENABLEVISIBLE:
350 case BASEPROPERTY_DECORATION: aDefault <<= (sal_Bool) sal_True; break;
352 case BASEPROPERTY_GROUPNAME:
353 case BASEPROPERTY_HELPTEXT:
354 case BASEPROPERTY_HELPURL:
355 case BASEPROPERTY_IMAGEURL:
356 case BASEPROPERTY_DIALOGSOURCEURL:
357 case BASEPROPERTY_EDITMASK:
358 case BASEPROPERTY_LITERALMASK:
359 case BASEPROPERTY_LABEL:
360 case BASEPROPERTY_TITLE:
361 case BASEPROPERTY_TEXT: aDefault <<= ::rtl::OUString(); break;
363 case BASEPROPERTY_WRITING_MODE:
364 case BASEPROPERTY_CONTEXT_WRITING_MODE:
365 aDefault <<= text::WritingMode2::CONTEXT;
366 break;
368 case BASEPROPERTY_STRINGITEMLIST:
370 ::com::sun::star::uno::Sequence< ::rtl::OUString> aStringSeq;
371 aDefault <<= aStringSeq;
374 break;
375 case BASEPROPERTY_SELECTEDITEMS:
377 ::com::sun::star::uno::Sequence<sal_Int16> aINT16Seq;
378 aDefault <<= aINT16Seq;
380 break;
381 case BASEPROPERTY_CURRENCYSYMBOL:
383 Any aDefaultCurrency = ::utl::ConfigManager::GetDirectConfigProperty(::utl::ConfigManager::DEFAULTCURRENCY);
384 DBG_ASSERT( TypeClass_STRING == aDefaultCurrency.getValueTypeClass(), "UnoControlModel::ImplGetDefaultValue: invalid currency config value!" );
386 ::rtl::OUString sDefaultCurrency;
387 aDefaultCurrency >>= sDefaultCurrency;
389 // extract the bank symbol
390 sal_Int32 nSepPos = sDefaultCurrency.indexOf( '-' );
391 ::rtl::OUString sBankSymbol;
392 if ( nSepPos >= 0 )
394 sBankSymbol = sDefaultCurrency.copy( 0, nSepPos );
395 sDefaultCurrency = sDefaultCurrency.copy( nSepPos + 1 );
398 // the remaming is the locale
399 Locale aLocale;
400 nSepPos = sDefaultCurrency.indexOf( '-' );
401 if ( nSepPos >= 0 )
403 aLocale.Language = sDefaultCurrency.copy( 0, nSepPos );
404 aLocale.Country = sDefaultCurrency.copy( nSepPos + 1 );
407 LocaleDataWrapper aLocaleInfo( ::comphelper::getProcessServiceFactory(), aLocale );
408 if ( !sBankSymbol.getLength() )
409 sBankSymbol = aLocaleInfo.getCurrBankSymbol();
411 // look for the currency entry (for this language) which has the given bank symbol
412 Sequence< Currency2 > aAllCurrencies = aLocaleInfo.getAllCurrencies();
413 const Currency2* pAllCurrencies = aAllCurrencies.getConstArray();
414 const Currency2* pAllCurrenciesEnd = pAllCurrencies + aAllCurrencies.getLength();
416 ::rtl::OUString sCurrencySymbol = aLocaleInfo.getCurrSymbol();
417 if ( !sBankSymbol.getLength() )
419 DBG_ASSERT( pAllCurrencies != pAllCurrenciesEnd, "UnoControlModel::ImplGetDefaultValue: no currencies at all!" );
420 if ( pAllCurrencies != pAllCurrenciesEnd )
422 sBankSymbol = pAllCurrencies->BankSymbol;
423 sCurrencySymbol = pAllCurrencies->Symbol;
427 if ( sBankSymbol.getLength() )
429 bool bLegacy = false;
430 for ( ;pAllCurrencies != pAllCurrenciesEnd; ++pAllCurrencies )
431 if ( pAllCurrencies->BankSymbol == sBankSymbol )
433 sCurrencySymbol = pAllCurrencies->Symbol;
434 if ( pAllCurrencies->LegacyOnly )
435 bLegacy = true;
436 else
437 break;
439 DBG_ASSERT( bLegacy || pAllCurrencies != pAllCurrenciesEnd, "UnoControlModel::ImplGetDefaultValue: did not find the given bank symbol!" );
442 aDefault <<= sCurrencySymbol;
444 break;
446 default: DBG_ERROR( "ImplGetDefaultValue - unknown Property" );
450 return aDefault;
453 void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId, const ::com::sun::star::uno::Any& rDefault )
455 ImplControlProperty* pProp = new ImplControlProperty( nPropId, rDefault );
456 mpData->Insert( nPropId, pProp );
459 void UnoControlModel::ImplRegisterProperty( sal_uInt16 nPropId )
461 ImplRegisterProperty( nPropId, ImplGetDefaultValue( nPropId ) );
463 if ( nPropId == BASEPROPERTY_FONTDESCRIPTOR )
465 // some properties are not included in the FontDescriptor, but everytime
466 // when we have a FontDescriptor we want to have these properties too.
467 // => Easier to register the here, istead everywhere where I register the FontDescriptor...
469 ImplRegisterProperty( BASEPROPERTY_TEXTCOLOR );
470 ImplRegisterProperty( BASEPROPERTY_TEXTLINECOLOR );
471 ImplRegisterProperty( BASEPROPERTY_FONTRELIEF );
472 ImplRegisterProperty( BASEPROPERTY_FONTEMPHASISMARK );
476 void UnoControlModel::ImplRegisterProperties( const std::list< sal_uInt16 > &rIds )
478 std::list< sal_uInt16 >::const_iterator iter;
479 for( iter = rIds.begin(); iter != rIds.end(); iter++) {
480 if( !ImplHasProperty( *iter ) )
481 ImplRegisterProperty( *iter, ImplGetDefaultValue( *iter ) );
485 // ::com::sun::star::uno::XInterface
486 ::com::sun::star::uno::Any UnoControlModel::queryAggregation( const ::com::sun::star::uno::Type & rType ) throw(::com::sun::star::uno::RuntimeException)
488 ::com::sun::star::uno::Any aRet = ::cppu::queryInterface( rType,
489 SAL_STATIC_CAST( ::com::sun::star::awt::XControlModel*, this ),
490 SAL_STATIC_CAST( ::com::sun::star::io::XPersistObject*, this ),
491 SAL_STATIC_CAST( ::com::sun::star::lang::XComponent*, this ),
492 SAL_STATIC_CAST( ::com::sun::star::lang::XServiceInfo*, this ),
493 SAL_STATIC_CAST( ::com::sun::star::util::XCloneable*, this ),
494 SAL_STATIC_CAST( ::com::sun::star::beans::XPropertyState*, this ),
495 SAL_STATIC_CAST( ::com::sun::star::beans::XMultiPropertySet*, this ),
496 SAL_STATIC_CAST( ::com::sun::star::beans::XFastPropertySet*, this ),
497 SAL_STATIC_CAST( ::com::sun::star::beans::XPropertySet*, this ),
498 SAL_STATIC_CAST( ::com::sun::star::lang::XTypeProvider*, this ),
499 SAL_STATIC_CAST( ::com::sun::star::lang::XUnoTunnel*, this ) );
500 return (aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( rType ));
503 // ::com::sun::star::lang::XUnoTunnel
504 IMPL_XUNOTUNNEL( UnoControlModel )
506 // ::com::sun::star::lang::XTypeProvider
507 IMPL_XTYPEPROVIDER_START( UnoControlModel )
508 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControlModel>* ) NULL ),
509 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::io::XPersistObject>* ) NULL ),
510 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>* ) NULL ),
511 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::lang::XServiceInfo>* ) NULL ),
512 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable>* ) NULL ),
513 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState>* ) NULL ),
514 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XMultiPropertySet>* ) NULL ),
515 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XFastPropertySet>* ) NULL ),
516 getCppuType( ( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet>* ) NULL )
517 IMPL_XTYPEPROVIDER_END
520 uno::Reference< util::XCloneable > UnoControlModel::createClone() throw(::com::sun::star::uno::RuntimeException)
522 UnoControlModel* pClone = Clone();
523 uno::Reference< util::XCloneable > xClone( (::cppu::OWeakObject*) pClone, uno::UNO_QUERY );
524 return xClone;
527 // ::com::sun::star::lang::XComponent
528 void UnoControlModel::dispose( ) throw(::com::sun::star::uno::RuntimeException)
530 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
532 ::com::sun::star::lang::EventObject aEvt;
533 aEvt.Source = (::com::sun::star::uno::XAggregation*)(::cppu::OWeakAggObject*)this;
534 maDisposeListeners.disposeAndClear( aEvt );
536 // let the property set helper notify our property listeners
537 OPropertySetHelper::disposing();
540 void UnoControlModel::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
542 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
544 maDisposeListeners.addInterface( rxListener );
547 void UnoControlModel::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& rxListener ) throw(::com::sun::star::uno::RuntimeException)
549 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
551 maDisposeListeners.removeInterface( rxListener );
555 // ::com::sun::star::beans::XPropertyState
556 ::com::sun::star::beans::PropertyState UnoControlModel::getPropertyState( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
558 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
560 sal_uInt16 nPropId = GetPropertyId( PropertyName );
562 ::com::sun::star::uno::Any aValue = getPropertyValue( PropertyName );
563 ::com::sun::star::uno::Any aDefault = ImplGetDefaultValue( nPropId );
565 return CompareProperties( aValue, aDefault ) ? ::com::sun::star::beans::PropertyState_DEFAULT_VALUE : ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
568 ::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)
570 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
572 sal_uInt32 nNames = PropertyNames.getLength();
573 const ::rtl::OUString* pNames = PropertyNames.getConstArray();
575 ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyState > aStates( nNames );
576 ::com::sun::star::beans::PropertyState* pStates = aStates.getArray();
578 for ( sal_uInt32 n = 0; n < nNames; n++ )
579 pStates[n] = getPropertyState( pNames[n] );
581 return aStates;
584 void UnoControlModel::setPropertyToDefault( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
586 Any aDefaultValue;
588 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
589 aDefaultValue = ImplGetDefaultValue( GetPropertyId( PropertyName ) );
591 setPropertyValue( PropertyName, aDefaultValue );
594 ::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)
596 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
598 return ImplGetDefaultValue( GetPropertyId( rPropertyName ) );
602 // ::com::sun::star::io::XPersistObjec
603 ::rtl::OUString UnoControlModel::getServiceName( ) throw(::com::sun::star::uno::RuntimeException)
605 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
607 DBG_ERROR( "ServiceName von UnoControlModel ?!" );
608 return ::rtl::OUString();
611 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)
613 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
615 ::com::sun::star::uno::Reference< ::com::sun::star::io::XMarkableStream > xMark( OutStream, ::com::sun::star::uno::UNO_QUERY );
616 DBG_ASSERT( xMark.is(), "write: no ::com::sun::star::io::XMarkableStream!" );
618 OutStream->writeShort( UNOCONTROL_STREAMVERSION );
620 ImplPropertyTable aProps;
621 sal_uInt32 i;
622 for ( i = mpData->Count(); i; )
624 ImplControlProperty* pProp = mpData->GetObject( --i );
625 if ( ( ( GetPropertyAttribs( pProp->GetId() ) & ::com::sun::star::beans::PropertyAttribute::TRANSIENT ) == 0 )
626 && ( getPropertyState( GetPropertyName( pProp->GetId() ) ) != ::com::sun::star::beans::PropertyState_DEFAULT_VALUE ) )
628 aProps.Insert( pProp->GetId(), pProp );
632 sal_uInt32 nProps = aProps.Count();
634 // FontProperty wegen fehlender Unterscheidung zwischen 5.0 / 5.1
635 // immer im alten Format mitspeichern.
636 OutStream->writeLong( (long) aProps.IsKeyValid( BASEPROPERTY_FONTDESCRIPTOR ) ? ( nProps + 3 ) : nProps );
637 for ( i = 0; i < nProps; i++ )
639 sal_Int32 nPropDataBeginMark = xMark->createMark();
640 OutStream->writeLong( 0L ); // DataLen
642 ImplControlProperty* pProp = aProps.GetObject( i );
643 OutStream->writeShort( pProp->GetId() );
645 sal_Bool bVoid = pProp->GetValue().getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID;
647 OutStream->writeBoolean( bVoid );
649 if ( !bVoid )
651 const ::com::sun::star::uno::Any& rValue = pProp->GetValue();
652 const ::com::sun::star::uno::Type& rType = rValue.getValueType();
654 if ( rType == ::getBooleanCppuType() )
656 sal_Bool b = false;
657 rValue >>= b;
658 OutStream->writeBoolean( b );
660 else if ( rType == ::getCppuType((const ::rtl::OUString*)0) )
662 ::rtl::OUString aUString;
663 rValue >>= aUString;
664 OutStream->writeUTF( aUString );
666 else if ( rType == ::getCppuType((const sal_uInt16*)0) )
668 sal_uInt16 n = 0;
669 rValue >>= n;
670 OutStream->writeShort( n );
672 else if ( rType == ::getCppuType((const sal_Int16*)0) )
674 sal_Int16 n = 0;
675 rValue >>= n;
676 OutStream->writeShort( n );
678 else if ( rType == ::getCppuType((const sal_uInt32*)0) )
680 sal_uInt32 n = 0;
681 rValue >>= n;
682 OutStream->writeLong( n );
684 else if ( rType == ::getCppuType((const sal_Int32*)0) )
686 sal_Int32 n = 0;
687 rValue >>= n;
688 OutStream->writeLong( n );
690 else if ( rType == ::getCppuType((const double*)0) )
692 double n = 0;
693 rValue >>= n;
694 OutStream->writeDouble( n );
696 else if ( rType == ::getCppuType((const ::com::sun::star::awt::FontDescriptor*)0) )
698 ::com::sun::star::awt::FontDescriptor aFD;
699 rValue >>= aFD;
700 OutStream->writeUTF( aFD.Name );
701 OutStream->writeShort( aFD.Height );
702 OutStream->writeShort( aFD.Width );
703 OutStream->writeUTF( aFD.StyleName );
704 OutStream->writeShort( aFD.Family );
705 OutStream->writeShort( aFD.CharSet );
706 OutStream->writeShort( aFD.Pitch );
707 OutStream->writeDouble( aFD.CharacterWidth );
708 OutStream->writeDouble( aFD.Weight );
709 OutStream->writeShort(
710 sal::static_int_cast< sal_Int16 >(aFD.Slant) );
711 OutStream->writeShort( aFD.Underline );
712 OutStream->writeShort( aFD.Strikeout );
713 OutStream->writeDouble( aFD.Orientation );
714 OutStream->writeBoolean( aFD.Kerning );
715 OutStream->writeBoolean( aFD.WordLineMode );
716 OutStream->writeShort( aFD.Type );
718 else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence< ::rtl::OUString>*)0 ) )
720 ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq;
721 rValue >>= aSeq;
722 long nEntries = aSeq.getLength();
723 OutStream->writeLong( nEntries );
724 for ( long n = 0; n < nEntries; n++ )
725 OutStream->writeUTF( aSeq.getConstArray()[n] );
727 else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_uInt16>*)0 ) )
729 ::com::sun::star::uno::Sequence<sal_uInt16> aSeq;
730 rValue >>= aSeq;
731 long nEntries = aSeq.getLength();
732 OutStream->writeLong( nEntries );
733 for ( long n = 0; n < nEntries; n++ )
734 OutStream->writeShort( aSeq.getConstArray()[n] );
736 else if ( rType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_Int16>*)0 ) )
738 ::com::sun::star::uno::Sequence<sal_Int16> aSeq;
739 rValue >>= aSeq;
740 long nEntries = aSeq.getLength();
741 OutStream->writeLong( nEntries );
742 for ( long n = 0; n < nEntries; n++ )
743 OutStream->writeShort( aSeq.getConstArray()[n] );
745 else if ( rType.getTypeClass() == TypeClass_ENUM )
747 sal_Int32 nAsInt = 0;
748 ::cppu::enum2int( nAsInt, rValue );
749 OutStream->writeLong( nAsInt );
751 #if OSL_DEBUG_LEVEL > 0
752 else
754 ::rtl::OString sMessage( "UnoControlModel::write: don't know how to handle a property of type '" );
755 ::rtl::OUString sTypeName( rType.getTypeName() );
756 sMessage += ::rtl::OString( sTypeName.getStr(), sTypeName.getLength(), RTL_TEXTENCODING_ASCII_US );
757 sMessage += "'.\n(Currently handling property '";
758 ::rtl::OUString sPropertyName( GetPropertyName( pProp->GetId() ) );
759 sMessage += ::rtl::OString( sPropertyName.getStr(), sPropertyName.getLength(), osl_getThreadTextEncoding() );
760 sMessage += "'.)";
761 DBG_ERROR( sMessage );
763 #endif
766 sal_Int32 nPropDataLen = xMark->offsetToMark( nPropDataBeginMark );
767 xMark->jumpToMark( nPropDataBeginMark );
768 OutStream->writeLong( nPropDataLen );
769 xMark->jumpToFurthest();
770 xMark->deleteMark(nPropDataBeginMark);
773 ImplControlProperty* pProp = aProps.Get( BASEPROPERTY_FONTDESCRIPTOR );
774 if ( pProp )
776 // Solange wir keinen 5.0-Export haben, muss das alte
777 // Format mit rausgeschrieben werden...
778 ::com::sun::star::awt::FontDescriptor aFD;
779 pProp->GetValue() >>= aFD;
781 for ( sal_uInt16 n = BASEPROPERTY_FONT_TYPE; n <= BASEPROPERTY_FONT_ATTRIBS; n++ )
783 sal_Int32 nPropDataBeginMark = xMark->createMark();
784 OutStream->writeLong( 0L ); // DataLen
785 OutStream->writeShort( n ); // PropId
786 OutStream->writeBoolean( sal_False ); // Void
788 if ( n == BASEPROPERTY_FONT_TYPE )
790 OutStream->writeUTF( aFD.Name );
791 OutStream->writeUTF( aFD.StyleName );
792 OutStream->writeShort( aFD.Family );
793 OutStream->writeShort( aFD.CharSet );
794 OutStream->writeShort( aFD.Pitch );
796 else if ( n == BASEPROPERTY_FONT_SIZE )
798 OutStream->writeLong( aFD.Width );
799 OutStream->writeLong( aFD.Height );
800 OutStream->writeShort(
801 sal::static_int_cast< sal_Int16 >(
802 VCLUnoHelper::ConvertFontWidth( aFD.CharacterWidth )) );
804 else if ( n == BASEPROPERTY_FONT_ATTRIBS )
806 OutStream->writeShort(
807 sal::static_int_cast< sal_Int16 >(
808 VCLUnoHelper::ConvertFontWeight( aFD.Weight )) );
809 OutStream->writeShort(
810 sal::static_int_cast< sal_Int16 >(aFD.Slant) );
811 OutStream->writeShort( aFD.Underline );
812 OutStream->writeShort( aFD.Strikeout );
813 OutStream->writeShort( (short)(aFD.Orientation * 10) );
814 OutStream->writeBoolean( aFD.Kerning );
815 OutStream->writeBoolean( aFD.WordLineMode );
817 else
819 DBG_ERROR( "Property?!" );
822 sal_Int32 nPropDataLen = xMark->offsetToMark( nPropDataBeginMark );
823 xMark->jumpToMark( nPropDataBeginMark );
824 OutStream->writeLong( nPropDataLen );
825 xMark->jumpToFurthest();
826 xMark->deleteMark(nPropDataBeginMark);
831 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)
833 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
835 ::com::sun::star::uno::Reference< ::com::sun::star::io::XMarkableStream > xMark( InStream, ::com::sun::star::uno::UNO_QUERY );
836 DBG_ASSERT( xMark.is(), "read: no ::com::sun::star::io::XMarkableStream!" );
838 short nVersion = InStream->readShort();
839 sal_uInt32 nProps = (sal_uInt32)InStream->readLong();
840 ::com::sun::star::uno::Sequence< ::rtl::OUString> aProps( nProps );
841 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any> aValues( nProps );
842 sal_Bool bInvalidEntries = sal_False;
844 // Dummerweise kein Mark fuer den gesamten Block, es koennen also
845 // nur Properties geaendert werden, es koennen aber nicht spaeter mal Daten
846 // fuer das Model hinter den Properties geschrieben werden.
848 // Fuer den Import der alten ::com::sun::star::awt::FontDescriptor-Teile
849 ::com::sun::star::awt::FontDescriptor* pFD = NULL;
851 sal_uInt32 i;
852 for ( i = 0; i < nProps; i++ )
854 sal_Int32 nPropDataBeginMark = xMark->createMark();
855 sal_Int32 nPropDataLen = InStream->readLong();
857 sal_uInt16 nPropId = (sal_uInt16)InStream->readShort();
859 ::com::sun::star::uno::Any aValue;
860 sal_Bool bIsVoid = InStream->readBoolean();
861 if ( !bIsVoid )
863 const ::com::sun::star::uno::Type* pType = mpData->Get( nPropId ) ? GetPropertyType( nPropId ) : NULL;
864 if ( pType )
866 if ( *pType == ::getBooleanCppuType() )
868 sal_Bool b = InStream->readBoolean();
869 aValue <<= b;
871 else if ( *pType == ::getCppuType((const ::rtl::OUString*)0) )
873 ::rtl::OUString aUTF = InStream->readUTF();
874 aValue <<= aUTF;
876 else if ( *pType == ::getCppuType((const sal_uInt16*)0) )
878 sal_uInt16 n = InStream->readShort();
879 aValue <<= n;
881 else if ( *pType == ::getCppuType((const sal_Int16*)0) )
883 sal_Int16 n = InStream->readShort();
884 aValue <<= n;
886 else if ( *pType == ::getCppuType((const sal_uInt32*)0) )
888 sal_uInt32 n = InStream->readLong();
889 aValue <<= n;
891 else if ( *pType == ::getCppuType((const sal_Int32*)0) )
893 sal_Int32 n = InStream->readLong();
894 aValue <<= n;
896 else if ( *pType == ::getCppuType((const double*)0) )
898 double n = InStream->readDouble();
899 aValue <<= n;
901 else if ( *pType == ::getCppuType((const ::com::sun::star::awt::FontDescriptor*)0) )
903 ::com::sun::star::awt::FontDescriptor aFD;
904 aFD.Name = InStream->readUTF();
905 aFD.Height = InStream->readShort();
906 aFD.Width = InStream->readShort();
907 aFD.StyleName = InStream->readUTF();
908 aFD.Family = InStream->readShort();
909 aFD.CharSet = InStream->readShort();
910 aFD.Pitch = InStream->readShort();
911 aFD.CharacterWidth = (float)InStream->readDouble();
912 aFD.Weight = (float)InStream->readDouble();
913 aFD.Slant = (::com::sun::star::awt::FontSlant)InStream->readShort();
914 aFD.Underline = InStream->readShort();
915 aFD.Strikeout = InStream->readShort();
916 aFD.Orientation = (float)InStream->readDouble();
917 aFD.Kerning = InStream->readBoolean();
918 aFD.WordLineMode = InStream->readBoolean();
919 aFD.Type = InStream->readShort();
920 aValue <<= aFD;
922 else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence< ::rtl::OUString>*)0 ) )
924 long nEntries = InStream->readLong();
925 ::com::sun::star::uno::Sequence< ::rtl::OUString> aSeq( nEntries );
926 for ( long n = 0; n < nEntries; n++ )
927 aSeq.getArray()[n] = InStream->readUTF();
928 aValue <<= aSeq;
931 else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_uInt16>*)0 ) )
934 long nEntries = InStream->readLong();
935 ::com::sun::star::uno::Sequence<sal_uInt16> aSeq( nEntries );
936 for ( long n = 0; n < nEntries; n++ )
937 aSeq.getArray()[n] = (sal_uInt16)InStream->readShort();
938 aValue <<= aSeq;
940 else if ( *pType == ::getCppuType((const ::com::sun::star::uno::Sequence<sal_Int16>*)0 ) )
942 long nEntries = InStream->readLong();
943 ::com::sun::star::uno::Sequence<sal_Int16> aSeq( nEntries );
944 for ( long n = 0; n < nEntries; n++ )
945 aSeq.getArray()[n] = (sal_Int16)InStream->readShort();
946 aValue <<= aSeq;
948 else if ( pType->getTypeClass() == TypeClass_ENUM )
950 sal_Int32 nAsInt = InStream->readLong();
951 aValue = ::cppu::int2enum( nAsInt, *pType );
953 else
955 ::rtl::OString sMessage( "UnoControlModel::read: don't know how to handle a property of type '" );
956 ::rtl::OUString sTypeName( pType->getTypeName() );
957 sMessage += ::rtl::OString( sTypeName.getStr(), sTypeName.getLength(), RTL_TEXTENCODING_ASCII_US );
958 sMessage += "'.\n(Currently handling property '";
959 ::rtl::OUString sPropertyName( GetPropertyName( nPropId ) );
960 sMessage += ::rtl::OString( sPropertyName.getStr(), sPropertyName.getLength(), osl_getThreadTextEncoding() );
961 sMessage += "'.)";
962 DBG_ERROR( sMessage );
965 else
967 // Altes Geraffel aus 5.0
968 if ( nPropId == BASEPROPERTY_FONT_TYPE )
970 // Sonst ist es nur die redundante Info fuer alte Versionen
971 // Daten werden durch MarkableStream geskippt.
972 if ( nVersion < 2 )
974 if ( !pFD )
976 pFD = new ::com::sun::star::awt::FontDescriptor;
977 ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR );
978 if ( pProp ) // wegen den Defaults...
979 pProp->GetValue() >>= *pFD;
981 pFD->Name = InStream->readUTF();
982 pFD->StyleName = InStream->readUTF();
983 pFD->Family = InStream->readShort();
984 pFD->CharSet = InStream->readShort();
985 pFD->Pitch = InStream->readShort();
988 else if ( nPropId == BASEPROPERTY_FONT_SIZE )
990 if ( nVersion < 2 )
992 if ( !pFD )
994 pFD = new ::com::sun::star::awt::FontDescriptor;
995 ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR );
996 if ( pProp ) // wegen den Defaults...
997 pProp->GetValue() >>= *pFD;
999 pFD->Width = (sal_Int16)InStream->readLong();
1000 pFD->Height = (sal_Int16)InStream->readLong();
1001 InStream->readShort(); // ::com::sun::star::awt::FontWidth ignorieren - wurde mal falsch geschrieben und wird nicht gebraucht.
1002 pFD->CharacterWidth = ::com::sun::star::awt::FontWidth::DONTKNOW;
1005 else if ( nPropId == BASEPROPERTY_FONT_ATTRIBS )
1007 if ( nVersion < 2 )
1009 if ( !pFD )
1011 pFD = new ::com::sun::star::awt::FontDescriptor;
1012 ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR );
1013 if ( pProp ) // wegen den Defaults...
1014 pProp->GetValue() >>= *pFD;
1016 pFD->Weight = VCLUnoHelper::ConvertFontWeight( (FontWeight) InStream->readShort() );
1017 pFD->Slant = (::com::sun::star::awt::FontSlant)InStream->readShort();
1018 pFD->Underline = InStream->readShort();
1019 pFD->Strikeout = InStream->readShort();
1020 pFD->Orientation = ( (float)(double)InStream->readShort() ) / 10;
1021 pFD->Kerning = InStream->readBoolean();
1022 pFD->WordLineMode = InStream->readBoolean();
1025 else
1027 DBG_ERROR( "read: unknown Property!" );
1031 else // bVoid
1033 if ( nPropId == BASEPROPERTY_FONTDESCRIPTOR )
1035 EmptyFontDescriptor aFD;
1036 aValue <<= aFD;
1040 if ( mpData->Get( nPropId ) )
1042 aProps.getArray()[i] = GetPropertyName( nPropId );
1043 aValues.getArray()[i] = aValue;
1045 else
1047 bInvalidEntries = sal_True;
1050 // Falls bereits mehr drinsteht als diese Version kennt:
1051 xMark->jumpToMark( nPropDataBeginMark );
1052 InStream->skipBytes( nPropDataLen );
1053 xMark->deleteMark(nPropDataBeginMark);
1055 if ( bInvalidEntries )
1057 for ( i = 0; i < (sal_uInt32)aProps.getLength(); i++ )
1059 if ( !aProps.getConstArray()[i].getLength() )
1061 ::comphelper::removeElementAt( aProps, i );
1062 ::comphelper::removeElementAt( aValues, i );
1063 i--;
1070 setPropertyValues( aProps, aValues );
1072 catch ( const Exception& )
1074 DBG_UNHANDLED_EXCEPTION();
1077 if ( pFD )
1079 ::com::sun::star::uno::Any aValue;
1080 aValue <<= *pFD;
1081 setPropertyValue( GetPropertyName( BASEPROPERTY_FONTDESCRIPTOR ), aValue );
1082 delete pFD;
1087 // ::com::sun::star::lang::XServiceInfo
1088 ::rtl::OUString UnoControlModel::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException)
1090 DBG_ERROR( "This method should be overloaded!" );
1091 return ::rtl::OUString();
1095 sal_Bool UnoControlModel::supportsService( const ::rtl::OUString& rServiceName ) throw(::com::sun::star::uno::RuntimeException)
1097 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1099 ::com::sun::star::uno::Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
1100 const ::rtl::OUString * pArray = aSNL.getConstArray();
1101 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
1102 if( pArray[i] == rServiceName )
1103 return sal_True;
1104 return sal_False;
1107 ::com::sun::star::uno::Sequence< ::rtl::OUString > UnoControlModel::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException)
1109 ::rtl::OUString sName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.awt.UnoControlModel" ) );
1110 return Sequence< ::rtl::OUString >( &sName, 1 );
1113 // ::cppu::OPropertySetHelper
1114 ::cppu::IPropertyArrayHelper& UnoControlModel::getInfoHelper()
1116 DBG_ERROR( "UnoControlModel::getInfoHelper() not possible!" );
1117 return *(::cppu::IPropertyArrayHelper*) NULL;
1120 // ------------------------------------------------------------------
1121 template <class TYPE>
1122 sal_Bool convertType(Any& _rConvertedValue, const Any& _rNewValueTest, const TYPE* /* _pTypeDisambiguation */)
1124 TYPE tValue;
1125 if (_rNewValueTest >>= tValue)
1127 _rConvertedValue <<= tValue;
1128 return sal_True;
1132 // ..................................................................
1133 sal_Bool UnoControlModel::convertFastPropertyValue( Any & rConvertedValue, Any & rOldValue, sal_Int32 nPropId, const Any& rValue ) throw (IllegalArgumentException)
1135 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1137 sal_Bool bVoid = rValue.getValueType().getTypeClass() == ::com::sun::star::uno::TypeClass_VOID;
1138 if ( bVoid )
1140 rConvertedValue.clear();
1142 else
1144 const ::com::sun::star::uno::Type* pDestType = GetPropertyType( (sal_uInt16)nPropId );
1145 if ( pDestType->getTypeClass() == TypeClass_ANY )
1147 rConvertedValue = rValue;
1149 else
1151 if ( pDestType->equals( rValue.getValueType() ) )
1153 rConvertedValue = rValue;
1155 else
1157 BOOL bConverted = FALSE;
1158 // 13.03.2001 - 84923 - frank.schoenheit@germany.sun.com
1160 switch (pDestType->getTypeClass())
1162 case TypeClass_DOUBLE:
1164 // try as double
1165 double nAsDouble = 0;
1166 bConverted = ( rValue >>= nAsDouble );
1167 if ( bConverted )
1168 rConvertedValue <<= nAsDouble;
1169 else
1170 { // try as integer - 96136 - 2002-10-08 - fs@openoffice.org
1171 sal_Int32 nAsInteger = 0;
1172 bConverted = ( rValue >>= nAsInteger );
1173 if ( bConverted )
1174 rConvertedValue <<= (double)nAsInteger;
1177 break;
1178 case TypeClass_SHORT:
1180 sal_Int16 n;
1181 bConverted = ( rValue >>= n );
1182 if ( bConverted )
1183 rConvertedValue <<= n;
1185 break;
1186 case TypeClass_UNSIGNED_SHORT:
1188 sal_uInt16 n;
1189 bConverted = ( rValue >>= n );
1190 if ( bConverted )
1191 rConvertedValue <<= n;
1193 break;
1194 case TypeClass_LONG:
1196 sal_Int32 n;
1197 bConverted = ( rValue >>= n );
1198 if ( bConverted )
1199 rConvertedValue <<= n;
1201 break;
1202 case TypeClass_UNSIGNED_LONG:
1204 sal_uInt32 n;
1205 bConverted = ( rValue >>= n );
1206 if ( bConverted )
1207 rConvertedValue <<= n;
1209 break;
1210 case TypeClass_INTERFACE:
1212 if ( rValue.getValueType().getTypeClass() == TypeClass_INTERFACE )
1214 Reference< XInterface > xPure( rValue, UNO_QUERY );
1215 if ( xPure.is() )
1216 rConvertedValue = xPure->queryInterface( *pDestType );
1217 else
1218 rConvertedValue.setValue( NULL, *pDestType );
1219 bConverted = sal_True;
1222 break;
1223 case TypeClass_ENUM:
1225 sal_Int32 nValue = 0;
1226 bConverted = ( rValue >>= nValue );
1227 if ( bConverted )
1228 rConvertedValue = ::cppu::int2enum( nValue, *pDestType );
1230 break;
1231 default: ; // avoid compiler warning
1234 if (!bConverted)
1236 ::rtl::OUStringBuffer aErrorMessage;
1237 aErrorMessage.appendAscii( "Unable to convert the given value for the property " );
1238 aErrorMessage.append ( GetPropertyName( (sal_uInt16)nPropId ) );
1239 aErrorMessage.appendAscii( ".\n" );
1240 aErrorMessage.appendAscii( "Expected type: " );
1241 aErrorMessage.append ( pDestType->getTypeName() );
1242 aErrorMessage.appendAscii( "\n" );
1243 aErrorMessage.appendAscii( "Found type: " );
1244 aErrorMessage.append ( rValue.getValueType().getTypeName() );
1245 throw ::com::sun::star::lang::IllegalArgumentException(
1246 aErrorMessage.makeStringAndClear(),
1247 static_cast< ::com::sun::star::beans::XPropertySet* >(this),
1254 // the current value
1255 getFastPropertyValue( rOldValue, nPropId );
1256 return !CompareProperties( rConvertedValue, rOldValue );
1259 void UnoControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 nPropId, const ::com::sun::star::uno::Any& rValue ) throw (::com::sun::star::uno::Exception)
1261 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1263 // Fehlt: Die gefakten Einzelproperties des FontDescriptors...
1265 ImplControlProperty* pProp = mpData->Get( nPropId );
1266 if ( pProp )
1268 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!" );
1269 ImplPropertyChanged( (sal_uInt16)nPropId );
1270 pProp->SetValue( rValue );
1272 else
1274 // exception...
1275 DBG_ERROR( "SetPropertyValues: Invalid Property!" );
1279 void UnoControlModel::getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nPropId ) const
1281 ::osl::Guard< ::osl::Mutex > aGuard( ((UnoControlModel*)this)->GetMutex() );
1283 ImplControlProperty* pProp = mpData->Get( nPropId );
1285 if ( pProp )
1286 rValue = pProp->GetValue();
1287 else if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1289 pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR );
1290 ::com::sun::star::awt::FontDescriptor aFD;
1291 pProp->GetValue() >>= aFD;
1292 switch ( nPropId )
1294 case BASEPROPERTY_FONTDESCRIPTORPART_NAME: rValue <<= aFD.Name;
1295 break;
1296 case BASEPROPERTY_FONTDESCRIPTORPART_STYLENAME: rValue <<= aFD.StyleName;
1297 break;
1298 case BASEPROPERTY_FONTDESCRIPTORPART_FAMILY: rValue <<= aFD.Family;
1299 break;
1300 case BASEPROPERTY_FONTDESCRIPTORPART_CHARSET: rValue <<= aFD.CharSet;
1301 break;
1302 case BASEPROPERTY_FONTDESCRIPTORPART_HEIGHT: rValue <<= (float)aFD.Height;
1303 break;
1304 case BASEPROPERTY_FONTDESCRIPTORPART_WEIGHT: rValue <<= aFD.Weight;
1305 break;
1306 case BASEPROPERTY_FONTDESCRIPTORPART_SLANT: rValue <<= (sal_Int16)aFD.Slant;
1307 break;
1308 case BASEPROPERTY_FONTDESCRIPTORPART_UNDERLINE: rValue <<= aFD.Underline;
1309 break;
1310 case BASEPROPERTY_FONTDESCRIPTORPART_STRIKEOUT: rValue <<= aFD.Strikeout;
1311 break;
1312 case BASEPROPERTY_FONTDESCRIPTORPART_WIDTH: rValue <<= aFD.Width;
1313 break;
1314 case BASEPROPERTY_FONTDESCRIPTORPART_PITCH: rValue <<= aFD.Pitch;
1315 break;
1316 case BASEPROPERTY_FONTDESCRIPTORPART_CHARWIDTH: rValue <<= aFD.CharacterWidth;
1317 break;
1318 case BASEPROPERTY_FONTDESCRIPTORPART_ORIENTATION: rValue <<= aFD.Orientation;
1319 break;
1320 case BASEPROPERTY_FONTDESCRIPTORPART_KERNING: rValue <<= aFD.Kerning;
1321 break;
1322 case BASEPROPERTY_FONTDESCRIPTORPART_WORDLINEMODE: rValue <<= aFD.WordLineMode;
1323 break;
1324 case BASEPROPERTY_FONTDESCRIPTORPART_TYPE: rValue <<= aFD.Type;
1325 break;
1326 default: DBG_ERROR( "FontProperty?!" );
1329 else
1331 DBG_ERROR( "getFastPropertyValue - invalid Property!" );
1335 // ::com::sun::star::beans::XPropertySet
1336 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)
1338 sal_Int32 nPropId = 0;
1340 ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
1341 nPropId = (sal_Int32) GetPropertyId( rPropertyName );
1342 DBG_ASSERT( nPropId, "Invalid ID in UnoControlModel::setPropertyValue" );
1344 if( nPropId )
1345 setFastPropertyValue( nPropId, rValue );
1346 else
1347 throw ::com::sun::star::beans::UnknownPropertyException();
1350 // ::com::sun::star::beans::XFastPropertySet
1351 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)
1353 if ( ( nPropId >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( nPropId <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1355 ::osl::ClearableMutexGuard aGuard( GetMutex() );
1357 Any aOldSingleValue;
1358 getFastPropertyValue( aOldSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START );
1360 ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR );
1361 FontDescriptor aOldFontDescriptor;
1362 pProp->GetValue() >>= aOldFontDescriptor;
1364 FontDescriptor aNewFontDescriptor( aOldFontDescriptor );
1365 lcl_ImplMergeFontProperty( aNewFontDescriptor, (sal_uInt16)nPropId, rValue );
1367 Any aNewValue;
1368 aNewValue <<= aNewFontDescriptor;
1369 sal_Int32 nDescriptorId( BASEPROPERTY_FONTDESCRIPTOR );
1370 nDescriptorId = BASEPROPERTY_FONTDESCRIPTOR;
1372 // also, we need fire a propertyChange event for the single property, since with
1373 // the above line, only an event for the FontDescriptor property will be fired
1374 Any aNewSingleValue;
1375 getFastPropertyValue( aNewSingleValue, BASEPROPERTY_FONTDESCRIPTORPART_START );
1377 aGuard.clear();
1378 setFastPropertyValues( 1, &nDescriptorId, &aNewValue, 1 );
1379 fire( &nPropId, &aNewSingleValue, &aOldSingleValue, 1, sal_False );
1381 else
1382 setFastPropertyValues( 1, &nPropId, &rValue, 1 );
1385 // ::com::sun::star::beans::XMultiPropertySet
1386 ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > UnoControlModel::getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException)
1388 DBG_ERROR( "UnoControlModel::getPropertySetInfo() not possible!" );
1389 return ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo >();
1392 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)
1394 ::osl::ClearableMutexGuard aGuard( GetMutex() );
1396 sal_Int32 nProps = rPropertyNames.getLength();
1398 // sal_Int32* pHandles = new sal_Int32[nProps];
1399 // don't do this - it leaks in case of an exception
1400 Sequence< sal_Int32 > aHandles( nProps );
1401 sal_Int32* pHandles = aHandles.getArray();
1403 // may need to change the order in the sequence, for this we need a non-const value sequence
1404 // 15.05.2002 - 99314 - fs@openoffice.org
1405 uno::Sequence< uno::Any > aValues( Values );
1406 uno::Any* pValues = aValues.getArray();
1408 sal_Int32 nValidHandles = getInfoHelper().fillHandles( pHandles, rPropertyNames );
1410 if ( nValidHandles )
1412 // if somebody sets properties which are single aspects of a font descriptor,
1413 // remove them, and build a font descriptor instead
1414 ::std::auto_ptr< awt::FontDescriptor > pFD;
1415 for ( sal_uInt16 n = 0; n < nProps; ++n )
1417 if ( ( pHandles[n] >= BASEPROPERTY_FONTDESCRIPTORPART_START ) && ( pHandles[n] <= BASEPROPERTY_FONTDESCRIPTORPART_END ) )
1419 if ( !pFD.get() )
1421 ImplControlProperty* pProp = mpData->Get( BASEPROPERTY_FONTDESCRIPTOR );
1422 pFD.reset( new awt::FontDescriptor );
1423 pProp->GetValue() >>= *pFD;
1425 lcl_ImplMergeFontProperty( *pFD, (sal_uInt16)pHandles[n], pValues[n] );
1426 pHandles[n] = -1;
1427 nValidHandles--;
1431 if ( nValidHandles )
1433 ImplNormalizePropertySequence( nProps, pHandles, pValues, &nValidHandles );
1434 aGuard.clear();
1435 // clear our guard before calling into setFastPropertyValues - this method
1436 // will implicitly call property listeners, and this should not happen with
1437 // our mutex locked
1438 // #i23451# - 2004-03-18 - fs@openoffice.org
1439 setFastPropertyValues( nProps, pHandles, pValues, nValidHandles );
1441 else
1442 aGuard.clear();
1443 // same as a few lines above
1445 // FD-Propertie nicht in das Array mergen, weil sortiert...
1446 if ( pFD.get() )
1448 ::com::sun::star::uno::Any aValue;
1449 aValue <<= *pFD;
1450 sal_Int32 nHandle = BASEPROPERTY_FONTDESCRIPTOR;
1451 setFastPropertyValues( 1, &nHandle, &aValue, 1 );
1458 void UnoControlModel::ImplNormalizePropertySequence( const sal_Int32, sal_Int32*,
1459 uno::Any*, sal_Int32* ) const SAL_THROW(())
1461 // nothing to do here
1464 void UnoControlModel::ImplEnsureHandleOrder( const sal_Int32 _nCount, sal_Int32* _pHandles,
1465 uno::Any* _pValues, sal_Int32 _nFirstHandle, sal_Int32 _nSecondHandle ) const
1467 for ( sal_Int32 i=0; i < _nCount; ++_pHandles, ++_pValues, ++i )
1469 if ( _nSecondHandle == *_pHandles )
1471 sal_Int32* pLaterHandles = _pHandles + 1;
1472 uno::Any* pLaterValues = _pValues + 1;
1473 for ( sal_Int32 j = i + 1; j < _nCount; ++j, ++pLaterHandles, ++pLaterValues )
1475 if ( _nFirstHandle == *pLaterHandles )
1477 // indeed it is -> exchange the both places in the sequences
1478 sal_Int32 nHandle( *_pHandles );
1479 *_pHandles = *pLaterHandles;
1480 *pLaterHandles = nHandle;
1482 uno::Any aValue( *_pValues );
1483 *_pValues = *pLaterValues;
1484 *pLaterValues = aValue;
1486 break;
1487 // this will leave the inner loop, and continue with the outer loop.
1488 // Note that this means we will encounter the _nSecondHandle handle, again, once we reached
1489 // (in the outer loop) the place where we just put it.