1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: poolitem.cxx,v $
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 -----------------------------------------------------------
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!";
86 IMPL_PTRHINT(SfxPoolItemHint
,SfxPoolItem
)
88 // SfxPoolItem -----------------------------------------------------------
89 SfxPoolItem::SfxPoolItem( USHORT nW
)
94 DBG_CTOR(SfxPoolItem
, 0);
95 DBG_ASSERT(nW
<= SHRT_MAX
, "Which Bereich ueberschritten");
96 #if OSL_DEBUG_LEVEL > 1
98 if ( pw1
&& nItemCount
>=10000 )
103 if ( pw2
&& nItemCount
>=100000 )
108 if ( pw3
&& nItemCount
>=1000000 )
113 if ( pw4
&& nItemCount
>=5000000 )
118 if ( pw5
&& nItemCount
>=10000000 )
126 // -----------------------------------------------------------------------
127 SfxPoolItem::SfxPoolItem( const SfxPoolItem
& rCpy
)
128 : nRefCount( 0 ), // wird ja ein neues Object!
129 nWhich( rCpy
.Which() ) // Funktion rufen wg. ChkThis()
132 DBG_CTOR(SfxPoolItem
, 0);
133 #if OSL_DEBUG_LEVEL > 1
135 if ( pw1
&& nItemCount
>=10000 )
140 if ( pw2
&& nItemCount
>=100000 )
145 if ( pw3
&& nItemCount
>=1000000 )
150 if ( pw4
&& nItemCount
>=5000000 )
155 if ( pw5
&& nItemCount
>=10000000 )
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
173 // ------------------------------------------------------------------------
174 int SfxPoolItem::Compare( const SfxPoolItem
& ) const
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 // -----------------------------------------------------------------------
195 int SfxPoolItem::IsPoolable() const
197 DBG_CHKTHIS(SfxPoolItem
, 0);
202 // -----------------------------------------------------------------------
203 SfxPoolItem
* SfxPoolItem::Create(SvStream
&, USHORT
) const
205 DBG_CHKTHIS(SfxPoolItem
, 0);
209 // -----------------------------------------------------------------------
210 USHORT
SfxPoolItem::GetVersion( USHORT
) const
212 DBG_CHKTHIS(SfxPoolItem
, 0);
216 // -----------------------------------------------------------------------
217 SvStream
& SfxPoolItem::Store(SvStream
&rStream
, USHORT
) const
219 DBG_CHKTHIS(SfxPoolItem
, 0);
223 //============================================================================
225 bool SfxPoolItem::readByteString(SvStream
& rStream
, UniString
& rString
)
227 rStream
.ReadByteString(rString
);
228 return rStream
.GetError() == ERRCODE_NONE
;
231 //============================================================================
233 void SfxPoolItem::writeByteString(SvStream
& rStream
,
234 UniString
const & rString
)
236 rStream
.WriteByteString(rString
);
239 //============================================================================
241 bool SfxPoolItem::readUnicodeString(SvStream
& rStream
, UniString
& rString
,
244 rStream
.ReadByteString(rString
,
245 bUnicode
? RTL_TEXTENCODING_UCS2
:
246 rStream
.GetStreamCharSet());
247 return rStream
.GetError() == ERRCODE_NONE
;
250 //============================================================================
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
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'
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)
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
):
321 DBG_CTOR(SfxVoidItem
, 0);
324 // SfxVoidItem ------------------------------------------------------------
325 SfxVoidItem::SfxVoidItem( const SfxVoidItem
& rCopy
):
328 DBG_CTOR(SfxVoidItem
, 0);
331 // ------------------------------------------------------------------------
332 int SfxVoidItem::operator==( const SfxPoolItem
&
338 DBG_CHKTHIS(SfxVoidItem
, 0);
339 DBG_ASSERT( SfxPoolItem::operator==( rCmp
), "unequal type" );
343 // ------------------------------------------------------------------------
344 SfxItemPresentation
SfxVoidItem::GetPresentation
346 SfxItemPresentation
/*ePresentation*/,
347 SfxMapUnit
/*eCoreMetric*/,
348 SfxMapUnit
/*ePresentationMetric*/,
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
):
369 pDefaultItem(&rDefault
)
371 DBG_CTOR(SfxInvalidItem
, 0);
374 // ------------------------------------------------------------------------
375 SfxInvalidItem::SfxInvalidItem( const SfxInvalidItem
& 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
,
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");
427 // ------------------------------------------------------------------------
428 SvStream
& SfxInvalidItem::Store(SvStream
&rStream
, USHORT nItemVersion
) const
430 DBG_CHKTHIS(SfxInvalidItem
, 0);
431 DBG_ERROR("SfxInvalidItem::Store() ist sinnlos");
434 #endif /* @@@ NOT USED @@@ */
436 // SfxItemHandle ----------------------------------------------------------
437 SfxItemHandle::SfxItemHandle(SfxPoolItem
&rItem
):
439 pItem(rItem
.Clone(0))
441 DBG_CTOR(SfxItemHandle
, 0);
444 // ------------------------------------------------------------------------
445 SfxItemHandle::SfxItemHandle(const SfxItemHandle
&rCopy
):
449 DBG_CTOR(SfxItemHandle
, 0);
453 // ------------------------------------------------------------------------
454 const SfxItemHandle
&SfxItemHandle::operator=(const SfxItemHandle
&rCopy
)
456 DBG_CHKTHIS(SfxItemHandle
, 0);
457 if(&rCopy
== this || pItem
== rCopy
.pItem
)
471 // ------------------------------------------------------------------------
472 SfxItemHandle::~SfxItemHandle()
474 DBG_DTOR(SfxItemHandle
, 0);
477 delete pRef
; pRef
= 0;
478 delete pItem
; pItem
= 0;
482 // ------------------------------------------------------------------------
483 int SfxPoolItem::ScaleMetrics( long /*lMult*/, long /*lDiv*/ )
488 // ------------------------------------------------------------------------
489 int SfxPoolItem::HasMetrics() const
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!");
516 // -----------------------------------------------------------------------
518 BOOL
SfxPoolItem::PutValue( const com::sun::star::uno::Any
&, BYTE
)
520 DBG_ERROR("There is no implementation for PutValue for this item!");
524 SfxVoidItem::~SfxVoidItem()
526 DBG_DTOR(SfxVoidItem
, 0);