xref: /AOO41X/main/svl/source/items/poolitem.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svl.hxx"
30 
31 #include <svl/poolitem.hxx>
32 #include <tools/stream.hxx>
33 
34 // STATIC DATA -----------------------------------------------------------
35 
36 DBG_NAME(SfxPoolItem)
37 DBG_NAME(SfxVoidItem)
38 // @@@ DBG_NAME(SfxInvalidItem);
39 DBG_NAME(SfxItemHandle)
40 
41 sal_uInt8 nSfxFlag8Val[8] =
42 {
43     1, 2, 4, 8, 16, 32, 64, 128
44 };
45 
46 sal_uInt16 nSfxFlag16Val[16] =
47 {
48     1, 2, 4, 8, 16, 32, 64, 128, 256, 512,
49     1024, 2048, 4096, 8192, 16384, 32768
50 };
51 
52 sal_uLong nSfxFlag32Val[32] =
53 {
54     0x1L, 0x2L, 0x4L, 0x8L,
55     0x10L, 0x20L, 0x40L, 0x80L,
56     0x100L, 0x200L, 0x400L, 0x800L,
57     0x1000L, 0x2000L, 0x40000L, 0x8000L,
58     0x10000L, 0x20000L, 0x40000L, 0x80000L,
59     0x100000L, 0x200000L, 0x400000L, 0x800000L,
60     0x1000000L, 0x2000000L, 0x4000000L, 0x8000000L,
61     0x10000000L, 0x20000000L, 0x40000000L, 0x80000000L
62 };
63 
64 // RTTI ------------------------------------------------------------------
65 
66 TYPEINIT0(SfxPoolItem);
67 TYPEINIT1(SfxVoidItem, SfxPoolItem);
68 // @@@ TYPEINIT1(SfxInvalidItem, SfxPoolItem);
69 TYPEINIT1(SfxSetItem, SfxPoolItem);
70 // @@@ TYPEINIT1(SfxItemChangedHint, SfxHint);
71 
72 // ------------------------------------------------------------------------
73 #if OSL_DEBUG_LEVEL > 1
74 static sal_uLong nItemCount = 0;
75 
76 const char* pw1 = "Wow! 10.000 items!";
77 const char* pw2 = "Wow! 100.000 items!";
78 const char* pw3 = "Wow! 1.000.000 items!";
79 const char* pw4 = "Wow! 50.000.000 items!";
80 const char* pw5 = "Wow! 10.000.000 items!";
81 #endif
82 
83 IMPL_PTRHINT(SfxPoolItemHint,SfxPoolItem)
84 
85 // SfxPoolItem -----------------------------------------------------------
86 SfxPoolItem::SfxPoolItem( sal_uInt16 nW )
87     : nRefCount( 0 ),
88       nWhich( nW )
89       , nKind( 0 )
90 {
91     DBG_CTOR(SfxPoolItem, 0);
92     DBG_ASSERT(nW <= SHRT_MAX, "Which Bereich ueberschritten");
93 #if OSL_DEBUG_LEVEL > 1
94     ++nItemCount;
95     if ( pw1 && nItemCount>=10000 )
96     {
97         DBG_WARNING( pw1 );
98         pw1 = NULL;
99     }
100     if ( pw2 && nItemCount>=100000 )
101     {
102         DBG_WARNING( pw2 );
103         pw2 = NULL;
104     }
105     if ( pw3 && nItemCount>=1000000 )
106     {
107         DBG_WARNING( pw3 );
108         pw3 = NULL;
109     }
110     if ( pw4 && nItemCount>=5000000 )
111     {
112         DBG_WARNING( pw4 );
113         pw4 = NULL;
114     }
115     if ( pw5 && nItemCount>=10000000 )
116     {
117         DBG_WARNING( pw5 );
118         pw5 = NULL;
119     }
120 #endif
121 }
122 
123 // -----------------------------------------------------------------------
124 SfxPoolItem::SfxPoolItem( const SfxPoolItem& rCpy )
125     : nRefCount( 0 ),               // wird ja ein neues Object!
126       nWhich( rCpy.Which() )    // Funktion rufen wg. ChkThis()
127       , nKind( 0 )
128 {
129     DBG_CTOR(SfxPoolItem, 0);
130 #if OSL_DEBUG_LEVEL > 1
131     ++nItemCount;
132     if ( pw1 && nItemCount>=10000 )
133     {
134         DBG_WARNING( pw1 );
135         pw1 = NULL;
136     }
137     if ( pw2 && nItemCount>=100000 )
138     {
139         DBG_WARNING( pw2 );
140         pw2 = NULL;
141     }
142     if ( pw3 && nItemCount>=1000000 )
143     {
144         DBG_WARNING( pw3 );
145         pw3 = NULL;
146     }
147     if ( pw4 && nItemCount>=5000000 )
148     {
149         DBG_WARNING( pw4 );
150         pw4 = NULL;
151     }
152     if ( pw5 && nItemCount>=10000000 )
153     {
154         DBG_WARNING( pw5 );
155         pw5 = NULL;
156     }
157 #endif
158 }
159 
160 // ------------------------------------------------------------------------
161 SfxPoolItem::~SfxPoolItem()
162 {
163     DBG_DTOR(SfxPoolItem, 0);
164     DBG_ASSERT(nRefCount == 0 || nRefCount > SFX_ITEMS_MAXREF, "destroying item in use" );
165 #if OSL_DEBUG_LEVEL > 1
166     --nItemCount;
167 #endif
168 }
169 
170 // ------------------------------------------------------------------------
171 int SfxPoolItem::Compare( const SfxPoolItem& ) const
172 {
173     return 0;
174 }
175 
176 // ------------------------------------------------------------------------
177 int SfxPoolItem::Compare( const SfxPoolItem& rWith, const IntlWrapper& ) const
178 {
179     return Compare( rWith );
180 }
181 
182 // ------------------------------------------------------------------------
183 int SfxPoolItem::operator==( const SfxPoolItem& rCmp ) const
184 {
185     DBG_CHKTHIS(SfxPoolItem, 0);
186     return rCmp.Type() == Type();
187 }
188 
189 // -----------------------------------------------------------------------
190 #ifndef TF_POOLABLE
191 
192 int SfxPoolItem::IsPoolable() const
193 {
194     DBG_CHKTHIS(SfxPoolItem, 0);
195     return sal_True;
196 }
197 #endif
198 
199 // -----------------------------------------------------------------------
200 SfxPoolItem* SfxPoolItem::Create(SvStream &, sal_uInt16) const
201 {
202     DBG_CHKTHIS(SfxPoolItem, 0);
203     return Clone(0);
204 }
205 
206 // -----------------------------------------------------------------------
207 sal_uInt16 SfxPoolItem::GetVersion( sal_uInt16 ) const
208 {
209     DBG_CHKTHIS(SfxPoolItem, 0);
210     return 0;
211 }
212 
213 // -----------------------------------------------------------------------
214 SvStream& SfxPoolItem::Store(SvStream &rStream, sal_uInt16 ) const
215 {
216     DBG_CHKTHIS(SfxPoolItem, 0);
217     return rStream;
218 }
219 
220 //============================================================================
221 // static
222 bool SfxPoolItem::readByteString(SvStream & rStream, UniString & rString)
223 {
224     rStream.ReadByteString(rString);
225     return rStream.GetError() == ERRCODE_NONE;
226 }
227 
228 //============================================================================
229 // static
230 void SfxPoolItem::writeByteString(SvStream & rStream,
231                                   UniString const & rString)
232 {
233     rStream.WriteByteString(rString);
234 }
235 
236 //============================================================================
237 // static
238 bool SfxPoolItem::readUnicodeString(SvStream & rStream, UniString & rString,
239                                     bool bUnicode)
240 {
241     rStream.ReadByteString(rString,
242                            bUnicode ? RTL_TEXTENCODING_UCS2 :
243                                       rStream.GetStreamCharSet());
244     return rStream.GetError() == ERRCODE_NONE;
245 }
246 
247 //============================================================================
248 // static
249 void SfxPoolItem::writeUnicodeString(SvStream & rStream,
250                                      UniString const & rString)
251 {
252     rStream.WriteByteString(rString, RTL_TEXTENCODING_UCS2);
253 }
254 
255 // ------------------------------------------------------------------------
256 SfxItemPresentation SfxPoolItem::GetPresentation
257 (
258     SfxItemPresentation /*ePresentation*/,       // IN:  wie formatiert werden soll
259     SfxMapUnit          /*eCoreMetric*/,         // IN:  Ma\seinheit des SfxPoolItems
260     SfxMapUnit          /*ePresentationMetric*/, // IN:  Wunsch-Ma\einheit der Darstellung
261     XubString&          /*rText*/,               // OUT: textuelle Darstellung
262     const IntlWrapper *
263 )   const
264 
265 /*  [Beschreibung]
266 
267     "Uber diese virtuelle Methode kann von den SfxPoolItem-Subklassen
268     eine textuelle Datstellung des Wertes erhalten werden. Sie sollte
269     von allen UI-relevanten SfxPoolItem-Subklassen "uberladen werden.
270 
271     Da die Ma\seinheit des Wertes im SfxItemPool nur "uber
272     <SfxItemPool::GetMetric(sal_uInt16)const> erfragbar ist, und nicht etwa
273     in der SfxPoolItem-Instanz oder -Subklasse  verf"ugbar ist, wird die
274     eigene Ma\seinheit als 'eCoreMetric' "ubergeben.
275 
276     Die darzustellende Ma\seinheit wird als 'ePresentationMetric'
277     "ubergeben.
278 
279 
280     [R"uckgabewert]
281 
282     SfxItemPresentation     SFX_ITEM_PRESENTATION_NONE
283                             es konnte keine Text-Darstellung erzeugt werden
284 
285                             SFX_ITEM_PRESENTATION_NAMELESS
286                             es konnte eine Text-Darstellung (ggf. mit
287                             Ma\seinheit) erzeugt werden, die jedoch keine
288                             semantische Bedeutung enth"alt
289 
290                             SFX_ITEM_PRESENTATION_COMPLETE
291                             es konnte eine komplette Text-Darstellung mit
292                             semantischer Bedeutung (und ggf. Ma\seinheit)
293                             erzeugt werden
294 
295 
296     [Beispiele]
297 
298     pSvxFontItem->GetPresentation( SFX_PRESENTATION_NAMELESS, ... )
299         "12pt" mit return SFX_ITEM_PRESENTATION_NAMELESS
300 
301     pSvxColorItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
302         "rot" mit return SFX_ITEM_PRESENTATION_NAMELESS
303         (das das SvxColorItem nicht wei\s, was f"ur eine Farbe es darstellt,
304         kann es keinen Namen angeben, was durch den Returnwert mitgeteilt wird.
305 
306     pSvxBorderItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
307         "1cm oberer Rand, 2cm linker Rand, 0,2cm unterer Rand, ..."
308 */
309 
310 {
311     return SFX_ITEM_PRESENTATION_NONE;
312 }
313 
314 // SfxVoidItem ------------------------------------------------------------
315 SfxVoidItem::SfxVoidItem( sal_uInt16 which ):
316     SfxPoolItem(which)
317 {
318     DBG_CTOR(SfxVoidItem, 0);
319 }
320 
321 // SfxVoidItem ------------------------------------------------------------
322 SfxVoidItem::SfxVoidItem( const SfxVoidItem& rCopy):
323     SfxPoolItem(rCopy)
324 {
325     DBG_CTOR(SfxVoidItem, 0);
326 }
327 
328 // ------------------------------------------------------------------------
329 int SfxVoidItem::operator==( const SfxPoolItem&
330 #ifdef DBG_UTIL
331 rCmp
332 #endif
333 ) const
334 {
335     DBG_CHKTHIS(SfxVoidItem, 0);
336     DBG_ASSERT( SfxPoolItem::operator==( rCmp ), "unequal type" );
337     return sal_True;
338 }
339 
340 // ------------------------------------------------------------------------
341 SfxItemPresentation SfxVoidItem::GetPresentation
342 (
343     SfxItemPresentation     /*ePresentation*/,
344     SfxMapUnit              /*eCoreMetric*/,
345     SfxMapUnit              /*ePresentationMetric*/,
346     XubString&              rText,
347     const IntlWrapper *
348 )   const
349 {
350     DBG_CHKTHIS(SfxVoidItem, 0);
351     rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("Void"));
352     return SFX_ITEM_PRESENTATION_NAMELESS;
353 }
354 
355 // ------------------------------------------------------------------------
356 SfxPoolItem* SfxVoidItem::Clone(SfxItemPool *) const
357 {
358     DBG_CHKTHIS(SfxVoidItem, 0);
359     return new SfxVoidItem(*this);
360 }
361 
362 // SfxInvalidItem ---------------------------------------------------------
363 #if 0  /* @@@ NOT USED @@@ */
364 SfxInvalidItem::SfxInvalidItem( sal_uInt16 nWhich, const SfxPoolItem &rDefault ):
365     SfxPoolItem(nWhich),
366     pDefaultItem(&rDefault)
367 {
368     DBG_CTOR(SfxInvalidItem, 0);
369 }
370 
371 // ------------------------------------------------------------------------
372 SfxInvalidItem::SfxInvalidItem( const SfxInvalidItem& rCopy):
373     SfxPoolItem(rCopy),
374     pDefaultItem(rCopy.pDefaultItem)
375 {
376     DBG_CTOR(SfxInvalidItem, 0);
377     //! pDefaultItem->ReleaseRef?
378 }
379 
380 // ------------------------------------------------------------------------
381 SfxInvalidItem::~SfxInvalidItem()
382 {
383     DBG_DTOR(SfxInvalidItem, 0);
384 }
385 
386 // ------------------------------------------------------------------------
387 int SfxInvalidItem::operator==( const SfxPoolItem& rCmp) const
388 {
389     DBG_CHKTHIS(SfxInvalidItem, 0);
390     DBG_ASSERT( SfxPoolItem::operator==(rCmp), "unequal type" );
391     return *pDefaultItem == *((SfxInvalidItem&)rCmp).pDefaultItem;
392 }
393 
394 // ------------------------------------------------------------------------
395 SfxItemPresentation SfxInvalidItem::GetPresentation
396 (
397     SfxItemPresentation     ePresentation,
398     SfxMapUnit              eCoreMetric,
399     SfxMapUnit              ePresentationMetric,
400     XubString&              rText,
401     const IntlWrapper *
402 )   const
403 {
404     DBG_CHKTHIS(SfxInvalidItem, 0);
405     rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("Invalid"));
406     return SFX_ITEM_PRESENTATION_NAMELESS;
407 }
408 
409 // ------------------------------------------------------------------------
410 SfxPoolItem* SfxInvalidItem::Clone(SfxItemPool *) const
411 {
412     DBG_CHKTHIS(SfxInvalidItem, 0);
413     return new SfxInvalidItem(*this);
414 }
415 
416 // ------------------------------------------------------------------------
417 SfxPoolItem* SfxInvalidItem::Create(SvStream &, sal_uInt16 nVersion) const
418 {
419     DBG_CHKTHIS(SfxInvalidItem, 0);
420     DBG_ERROR("SfxInvalidItem::Create() ist sinnlos");
421     return Clone();
422 }
423 
424 // ------------------------------------------------------------------------
425 SvStream& SfxInvalidItem::Store(SvStream &rStream, sal_uInt16 nItemVersion ) const
426 {
427     DBG_CHKTHIS(SfxInvalidItem, 0);
428     DBG_ERROR("SfxInvalidItem::Store() ist sinnlos");
429     return rStream;
430 }
431 #endif /* @@@ NOT USED @@@ */
432 
433 // SfxItemHandle ----------------------------------------------------------
434 SfxItemHandle::SfxItemHandle(SfxPoolItem &rItem):
435     pRef(new sal_uInt16(1)),
436     pItem(rItem.Clone(0))
437 {
438     DBG_CTOR(SfxItemHandle, 0);
439 }
440 
441 // ------------------------------------------------------------------------
442 SfxItemHandle::SfxItemHandle(const SfxItemHandle &rCopy):
443     pRef(rCopy.pRef),
444     pItem(rCopy.pItem)
445 {
446     DBG_CTOR(SfxItemHandle, 0);
447     ++(*pRef);
448 }
449 
450 // ------------------------------------------------------------------------
451 const SfxItemHandle &SfxItemHandle::operator=(const SfxItemHandle &rCopy)
452 {
453     DBG_CHKTHIS(SfxItemHandle, 0);
454     if(&rCopy == this || pItem == rCopy.pItem)
455         return *this;
456     --(*pRef);
457     if(!(*pRef))
458     {
459         delete pItem;
460         pItem = 0;
461     }
462     pRef = rCopy.pRef;
463     ++(*pRef);
464     pItem = rCopy.pItem;
465     return *this;
466 }
467 
468 // ------------------------------------------------------------------------
469 SfxItemHandle::~SfxItemHandle()
470 {
471     DBG_DTOR(SfxItemHandle, 0);
472     --(*pRef);
473     if(!(*pRef)) {
474         delete pRef; pRef = 0;
475         delete pItem; pItem = 0;
476     }
477 }
478 
479 // ------------------------------------------------------------------------
480 int SfxPoolItem::ScaleMetrics( long /*lMult*/, long /*lDiv*/ )
481 {
482     return 0;
483 }
484 
485 // ------------------------------------------------------------------------
486 int SfxPoolItem::HasMetrics() const
487 {
488     return 0;
489 }
490 
491 // -----------------------------------------------------------------------
492 #if 0  /* @@@ NOT USED @@@ */
493 void SfxPoolItem::GetVersion() const
494 {
495     DBG_ERROR( "dummy called" );
496 }
497 
498 // -----------------------------------------------------------------------
499 void SfxPoolItem::Store(SvStream &rStream) const
500 {
501     DBG_ERROR( "dummy called" );
502 }
503 #endif /* @@@ NOT USED @@@ */
504 
505 // -----------------------------------------------------------------------
506 
507 sal_Bool SfxPoolItem::QueryValue( com::sun::star::uno::Any&, sal_uInt8 ) const
508 {
509     DBG_ERROR("There is no implementation for QueryValue for this item!");
510     return sal_False;
511 }
512 
513 // -----------------------------------------------------------------------
514 
515 sal_Bool SfxPoolItem::PutValue( const com::sun::star::uno::Any&, sal_uInt8 )
516 {
517     DBG_ERROR("There is no implementation for PutValue for this item!");
518     return sal_False;
519 }
520 
521 SfxVoidItem::~SfxVoidItem()
522 {
523     DBG_DTOR(SfxVoidItem, 0);
524 }
525