Update ooo320-m1
[ooovba.git] / svtools / source / items1 / poolitem.cxx
blobdc0b167ceea8df58a6c3db97c8e46aad27c00ca2
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: poolitem.cxx,v $
10 * $Revision: 1.8 $
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_svtools.hxx"
34 #include <svtools/poolitem.hxx>
35 #include <tools/stream.hxx>
37 // STATIC DATA -----------------------------------------------------------
39 DBG_NAME(SfxPoolItem)
40 DBG_NAME(SfxVoidItem)
41 // @@@ DBG_NAME(SfxInvalidItem);
42 DBG_NAME(SfxItemHandle)
44 BYTE nSfxFlag8Val[8] =
46 1, 2, 4, 8, 16, 32, 64, 128
49 USHORT nSfxFlag16Val[16] =
51 1, 2, 4, 8, 16, 32, 64, 128, 256, 512,
52 1024, 2048, 4096, 8192, 16384, 32768
55 ULONG nSfxFlag32Val[32] =
57 0x1L, 0x2L, 0x4L, 0x8L,
58 0x10L, 0x20L, 0x40L, 0x80L,
59 0x100L, 0x200L, 0x400L, 0x800L,
60 0x1000L, 0x2000L, 0x40000L, 0x8000L,
61 0x10000L, 0x20000L, 0x40000L, 0x80000L,
62 0x100000L, 0x200000L, 0x400000L, 0x800000L,
63 0x1000000L, 0x2000000L, 0x4000000L, 0x8000000L,
64 0x10000000L, 0x20000000L, 0x40000000L, 0x80000000L
67 // RTTI ------------------------------------------------------------------
69 TYPEINIT0(SfxPoolItem);
70 TYPEINIT1(SfxVoidItem, SfxPoolItem);
71 // @@@ TYPEINIT1(SfxInvalidItem, SfxPoolItem);
72 TYPEINIT1(SfxSetItem, SfxPoolItem);
73 // @@@ TYPEINIT1(SfxItemChangedHint, SfxHint);
75 // ------------------------------------------------------------------------
76 #if OSL_DEBUG_LEVEL > 1
77 static ULONG nItemCount = 0;
79 const char* pw1 = "Wow! 10.000 items!";
80 const char* pw2 = "Wow! 100.000 items!";
81 const char* pw3 = "Wow! 1.000.000 items!";
82 const char* pw4 = "Wow! 50.000.000 items!";
83 const char* pw5 = "Wow! 10.000.000 items!";
84 #endif
86 IMPL_PTRHINT(SfxPoolItemHint,SfxPoolItem)
88 // SfxPoolItem -----------------------------------------------------------
89 SfxPoolItem::SfxPoolItem( USHORT nW )
90 : nRefCount( 0 ),
91 nWhich( nW )
92 , nKind( 0 )
94 DBG_CTOR(SfxPoolItem, 0);
95 DBG_ASSERT(nW <= SHRT_MAX, "Which Bereich ueberschritten");
96 #if OSL_DEBUG_LEVEL > 1
97 ++nItemCount;
98 if ( pw1 && nItemCount>=10000 )
100 DBG_WARNING( pw1 );
101 pw1 = NULL;
103 if ( pw2 && nItemCount>=100000 )
105 DBG_WARNING( pw2 );
106 pw2 = NULL;
108 if ( pw3 && nItemCount>=1000000 )
110 DBG_WARNING( pw3 );
111 pw3 = NULL;
113 if ( pw4 && nItemCount>=5000000 )
115 DBG_WARNING( pw4 );
116 pw4 = NULL;
118 if ( pw5 && nItemCount>=10000000 )
120 DBG_WARNING( pw5 );
121 pw5 = NULL;
123 #endif
126 // -----------------------------------------------------------------------
127 SfxPoolItem::SfxPoolItem( const SfxPoolItem& rCpy )
128 : nRefCount( 0 ), // wird ja ein neues Object!
129 nWhich( rCpy.Which() ) // Funktion rufen wg. ChkThis()
130 , nKind( 0 )
132 DBG_CTOR(SfxPoolItem, 0);
133 #if OSL_DEBUG_LEVEL > 1
134 ++nItemCount;
135 if ( pw1 && nItemCount>=10000 )
137 DBG_WARNING( pw1 );
138 pw1 = NULL;
140 if ( pw2 && nItemCount>=100000 )
142 DBG_WARNING( pw2 );
143 pw2 = NULL;
145 if ( pw3 && nItemCount>=1000000 )
147 DBG_WARNING( pw3 );
148 pw3 = NULL;
150 if ( pw4 && nItemCount>=5000000 )
152 DBG_WARNING( pw4 );
153 pw4 = NULL;
155 if ( pw5 && nItemCount>=10000000 )
157 DBG_WARNING( pw5 );
158 pw5 = NULL;
160 #endif
163 // ------------------------------------------------------------------------
164 SfxPoolItem::~SfxPoolItem()
166 DBG_DTOR(SfxPoolItem, 0);
167 DBG_ASSERT(nRefCount == 0 || nRefCount > SFX_ITEMS_MAXREF, "destroying item in use" );
168 #if OSL_DEBUG_LEVEL > 1
169 --nItemCount;
170 #endif
173 // ------------------------------------------------------------------------
174 int SfxPoolItem::Compare( const SfxPoolItem& ) const
176 return 0;
179 // ------------------------------------------------------------------------
180 int SfxPoolItem::Compare( const SfxPoolItem& rWith, const IntlWrapper& ) const
182 return Compare( rWith );
185 // ------------------------------------------------------------------------
186 int SfxPoolItem::operator==( const SfxPoolItem& rCmp ) const
188 DBG_CHKTHIS(SfxPoolItem, 0);
189 return rCmp.Type() == Type();
192 // -----------------------------------------------------------------------
193 #ifndef TF_POOLABLE
195 int SfxPoolItem::IsPoolable() const
197 DBG_CHKTHIS(SfxPoolItem, 0);
198 return TRUE;
200 #endif
202 // -----------------------------------------------------------------------
203 SfxPoolItem* SfxPoolItem::Create(SvStream &, USHORT) const
205 DBG_CHKTHIS(SfxPoolItem, 0);
206 return Clone(0);
209 // -----------------------------------------------------------------------
210 USHORT SfxPoolItem::GetVersion( USHORT ) const
212 DBG_CHKTHIS(SfxPoolItem, 0);
213 return 0;
216 // -----------------------------------------------------------------------
217 SvStream& SfxPoolItem::Store(SvStream &rStream, USHORT ) const
219 DBG_CHKTHIS(SfxPoolItem, 0);
220 return rStream;
223 //============================================================================
224 // static
225 bool SfxPoolItem::readByteString(SvStream & rStream, UniString & rString)
227 rStream.ReadByteString(rString);
228 return rStream.GetError() == ERRCODE_NONE;
231 //============================================================================
232 // static
233 void SfxPoolItem::writeByteString(SvStream & rStream,
234 UniString const & rString)
236 rStream.WriteByteString(rString);
239 //============================================================================
240 // static
241 bool SfxPoolItem::readUnicodeString(SvStream & rStream, UniString & rString,
242 bool bUnicode)
244 rStream.ReadByteString(rString,
245 bUnicode ? RTL_TEXTENCODING_UCS2 :
246 rStream.GetStreamCharSet());
247 return rStream.GetError() == ERRCODE_NONE;
250 //============================================================================
251 // static
252 void SfxPoolItem::writeUnicodeString(SvStream & rStream,
253 UniString const & rString)
255 rStream.WriteByteString(rString, RTL_TEXTENCODING_UCS2);
258 // ------------------------------------------------------------------------
259 SfxItemPresentation SfxPoolItem::GetPresentation
261 SfxItemPresentation /*ePresentation*/, // IN: wie formatiert werden soll
262 SfxMapUnit /*eCoreMetric*/, // IN: Ma\seinheit des SfxPoolItems
263 SfxMapUnit /*ePresentationMetric*/, // IN: Wunsch-Ma\einheit der Darstellung
264 XubString& /*rText*/, // OUT: textuelle Darstellung
265 const IntlWrapper *
266 ) const
268 /* [Beschreibung]
270 "Uber diese virtuelle Methode kann von den SfxPoolItem-Subklassen
271 eine textuelle Datstellung des Wertes erhalten werden. Sie sollte
272 von allen UI-relevanten SfxPoolItem-Subklassen "uberladen werden.
274 Da die Ma\seinheit des Wertes im SfxItemPool nur "uber
275 <SfxItemPool::GetMetric(USHORT)const> erfragbar ist, und nicht etwa
276 in der SfxPoolItem-Instanz oder -Subklasse verf"ugbar ist, wird die
277 eigene Ma\seinheit als 'eCoreMetric' "ubergeben.
279 Die darzustellende Ma\seinheit wird als 'ePresentationMetric'
280 "ubergeben.
283 [R"uckgabewert]
285 SfxItemPresentation SFX_ITEM_PRESENTATION_NONE
286 es konnte keine Text-Darstellung erzeugt werden
288 SFX_ITEM_PRESENTATION_NAMELESS
289 es konnte eine Text-Darstellung (ggf. mit
290 Ma\seinheit) erzeugt werden, die jedoch keine
291 semantische Bedeutung enth"alt
293 SFX_ITEM_PRESENTATION_COMPLETE
294 es konnte eine komplette Text-Darstellung mit
295 semantischer Bedeutung (und ggf. Ma\seinheit)
296 erzeugt werden
299 [Beispiele]
301 pSvxFontItem->GetPresentation( SFX_PRESENTATION_NAMELESS, ... )
302 "12pt" mit return SFX_ITEM_PRESENTATION_NAMELESS
304 pSvxColorItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
305 "rot" mit return SFX_ITEM_PRESENTATION_NAMELESS
306 (das das SvxColorItem nicht wei\s, was f"ur eine Farbe es darstellt,
307 kann es keinen Namen angeben, was durch den Returnwert mitgeteilt wird.
309 pSvxBorderItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
310 "1cm oberer Rand, 2cm linker Rand, 0,2cm unterer Rand, ..."
314 return SFX_ITEM_PRESENTATION_NONE;
317 // SfxVoidItem ------------------------------------------------------------
318 SfxVoidItem::SfxVoidItem( USHORT which ):
319 SfxPoolItem(which)
321 DBG_CTOR(SfxVoidItem, 0);
324 // SfxVoidItem ------------------------------------------------------------
325 SfxVoidItem::SfxVoidItem( const SfxVoidItem& rCopy):
326 SfxPoolItem(rCopy)
328 DBG_CTOR(SfxVoidItem, 0);
331 // ------------------------------------------------------------------------
332 int SfxVoidItem::operator==( const SfxPoolItem&
333 #ifdef DBG_UTIL
334 rCmp
335 #endif
336 ) const
338 DBG_CHKTHIS(SfxVoidItem, 0);
339 DBG_ASSERT( SfxPoolItem::operator==( rCmp ), "unequal type" );
340 return TRUE;
343 // ------------------------------------------------------------------------
344 SfxItemPresentation SfxVoidItem::GetPresentation
346 SfxItemPresentation /*ePresentation*/,
347 SfxMapUnit /*eCoreMetric*/,
348 SfxMapUnit /*ePresentationMetric*/,
349 XubString& rText,
350 const IntlWrapper *
351 ) const
353 DBG_CHKTHIS(SfxVoidItem, 0);
354 rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("Void"));
355 return SFX_ITEM_PRESENTATION_NAMELESS;
358 // ------------------------------------------------------------------------
359 SfxPoolItem* SfxVoidItem::Clone(SfxItemPool *) const
361 DBG_CHKTHIS(SfxVoidItem, 0);
362 return new SfxVoidItem(*this);
365 // SfxInvalidItem ---------------------------------------------------------
366 #if 0 /* @@@ NOT USED @@@ */
367 SfxInvalidItem::SfxInvalidItem( USHORT nWhich, const SfxPoolItem &rDefault ):
368 SfxPoolItem(nWhich),
369 pDefaultItem(&rDefault)
371 DBG_CTOR(SfxInvalidItem, 0);
374 // ------------------------------------------------------------------------
375 SfxInvalidItem::SfxInvalidItem( const SfxInvalidItem& rCopy):
376 SfxPoolItem(rCopy),
377 pDefaultItem(rCopy.pDefaultItem)
379 DBG_CTOR(SfxInvalidItem, 0);
380 //! pDefaultItem->ReleaseRef?
383 // ------------------------------------------------------------------------
384 SfxInvalidItem::~SfxInvalidItem()
386 DBG_DTOR(SfxInvalidItem, 0);
389 // ------------------------------------------------------------------------
390 int SfxInvalidItem::operator==( const SfxPoolItem& rCmp) const
392 DBG_CHKTHIS(SfxInvalidItem, 0);
393 DBG_ASSERT( SfxPoolItem::operator==(rCmp), "unequal type" );
394 return *pDefaultItem == *((SfxInvalidItem&)rCmp).pDefaultItem;
397 // ------------------------------------------------------------------------
398 SfxItemPresentation SfxInvalidItem::GetPresentation
400 SfxItemPresentation ePresentation,
401 SfxMapUnit eCoreMetric,
402 SfxMapUnit ePresentationMetric,
403 XubString& rText,
404 const IntlWrapper *
405 ) const
407 DBG_CHKTHIS(SfxInvalidItem, 0);
408 rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("Invalid"));
409 return SFX_ITEM_PRESENTATION_NAMELESS;
412 // ------------------------------------------------------------------------
413 SfxPoolItem* SfxInvalidItem::Clone(SfxItemPool *) const
415 DBG_CHKTHIS(SfxInvalidItem, 0);
416 return new SfxInvalidItem(*this);
419 // ------------------------------------------------------------------------
420 SfxPoolItem* SfxInvalidItem::Create(SvStream &, USHORT nVersion) const
422 DBG_CHKTHIS(SfxInvalidItem, 0);
423 DBG_ERROR("SfxInvalidItem::Create() ist sinnlos");
424 return Clone();
427 // ------------------------------------------------------------------------
428 SvStream& SfxInvalidItem::Store(SvStream &rStream, USHORT nItemVersion ) const
430 DBG_CHKTHIS(SfxInvalidItem, 0);
431 DBG_ERROR("SfxInvalidItem::Store() ist sinnlos");
432 return rStream;
434 #endif /* @@@ NOT USED @@@ */
436 // SfxItemHandle ----------------------------------------------------------
437 SfxItemHandle::SfxItemHandle(SfxPoolItem &rItem):
438 pRef(new USHORT(1)),
439 pItem(rItem.Clone(0))
441 DBG_CTOR(SfxItemHandle, 0);
444 // ------------------------------------------------------------------------
445 SfxItemHandle::SfxItemHandle(const SfxItemHandle &rCopy):
446 pRef(rCopy.pRef),
447 pItem(rCopy.pItem)
449 DBG_CTOR(SfxItemHandle, 0);
450 ++(*pRef);
453 // ------------------------------------------------------------------------
454 const SfxItemHandle &SfxItemHandle::operator=(const SfxItemHandle &rCopy)
456 DBG_CHKTHIS(SfxItemHandle, 0);
457 if(&rCopy == this || pItem == rCopy.pItem)
458 return *this;
459 --(*pRef);
460 if(!(*pRef))
462 delete pItem;
463 pItem = 0;
465 pRef = rCopy.pRef;
466 ++(*pRef);
467 pItem = rCopy.pItem;
468 return *this;
471 // ------------------------------------------------------------------------
472 SfxItemHandle::~SfxItemHandle()
474 DBG_DTOR(SfxItemHandle, 0);
475 --(*pRef);
476 if(!(*pRef)) {
477 delete pRef; pRef = 0;
478 delete pItem; pItem = 0;
482 // ------------------------------------------------------------------------
483 int SfxPoolItem::ScaleMetrics( long /*lMult*/, long /*lDiv*/ )
485 return 0;
488 // ------------------------------------------------------------------------
489 int SfxPoolItem::HasMetrics() const
491 return 0;
494 // -----------------------------------------------------------------------
495 #if 0 /* @@@ NOT USED @@@ */
496 void SfxPoolItem::GetVersion() const
498 DBG_ERROR( "dummy called" );
501 // -----------------------------------------------------------------------
502 void SfxPoolItem::Store(SvStream &rStream) const
504 DBG_ERROR( "dummy called" );
506 #endif /* @@@ NOT USED @@@ */
508 // -----------------------------------------------------------------------
510 BOOL SfxPoolItem::QueryValue( com::sun::star::uno::Any&, BYTE ) const
512 DBG_ERROR("There is no implementation for QueryValue for this item!");
513 return FALSE;
516 // -----------------------------------------------------------------------
518 BOOL SfxPoolItem::PutValue( const com::sun::star::uno::Any&, BYTE )
520 DBG_ERROR("There is no implementation for PutValue for this item!");
521 return FALSE;
524 SfxVoidItem::~SfxVoidItem()
526 DBG_DTOR(SfxVoidItem, 0);