bump product version to 5.0.4.1
[LibreOffice.git] / svl / source / items / poolitem.cxx
blobd6480b01cd4182a64031917194f7230656ceb936
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svl/poolitem.hxx>
22 #include <tools/stream.hxx>
23 #include <osl/diagnose.h>
24 #include <libxml/xmlwriter.h>
26 TYPEINIT0(SfxPoolItem);
27 TYPEINIT1(SfxVoidItem, SfxPoolItem);
28 // @@@ TYPEINIT1(SfxInvalidItem, SfxPoolItem);
29 TYPEINIT1(SfxSetItem, SfxPoolItem);
30 // @@@ TYPEINIT1(SfxItemChangedHint, SfxHint);
33 #if OSL_DEBUG_LEVEL > 1
34 static sal_uLong nItemCount = 0;
36 const char* pw1 = "Wow! 10.000 items!";
37 const char* pw2 = "Wow! 100.000 items!";
38 const char* pw3 = "Wow! 1.000.000 items!";
39 const char* pw4 = "Wow! 50.000.000 items!";
40 const char* pw5 = "Wow! 10.000.000 items!";
41 #endif
43 SfxPoolItem::SfxPoolItem(sal_uInt16 const nWhich)
44 : m_nRefCount(0)
45 , m_nWhich(nWhich)
46 , m_nKind(SFX_ITEMS_NONE)
48 DBG_ASSERT(nWhich <= SHRT_MAX, "invalid WhichId");
49 #if OSL_DEBUG_LEVEL > 1
50 ++nItemCount;
51 if ( pw1 && nItemCount>=10000 )
53 DBG_WARNING( pw1 );
54 pw1 = NULL;
56 if ( pw2 && nItemCount>=100000 )
58 DBG_WARNING( pw2 );
59 pw2 = NULL;
61 if ( pw3 && nItemCount>=1000000 )
63 DBG_WARNING( pw3 );
64 pw3 = NULL;
66 if ( pw4 && nItemCount>=5000000 )
68 DBG_WARNING( pw4 );
69 pw4 = NULL;
71 if ( pw5 && nItemCount>=10000000 )
73 DBG_WARNING( pw5 );
74 pw5 = NULL;
76 #endif
80 SfxPoolItem::SfxPoolItem( const SfxPoolItem& rCpy )
81 : m_nRefCount(0) // don't copy that
82 , m_nWhich(rCpy.Which()) // call function because of ChkThis() (WTF does that mean?)
83 , m_nKind( SFX_ITEMS_NONE )
85 #if OSL_DEBUG_LEVEL > 1
86 ++nItemCount;
87 if ( pw1 && nItemCount>=10000 )
89 DBG_WARNING( pw1 );
90 pw1 = NULL;
92 if ( pw2 && nItemCount>=100000 )
94 DBG_WARNING( pw2 );
95 pw2 = NULL;
97 if ( pw3 && nItemCount>=1000000 )
99 DBG_WARNING( pw3 );
100 pw3 = NULL;
102 if ( pw4 && nItemCount>=5000000 )
104 DBG_WARNING( pw4 );
105 pw4 = NULL;
107 if ( pw5 && nItemCount>=10000000 )
109 DBG_WARNING( pw5 );
110 pw5 = NULL;
112 #endif
116 SfxPoolItem::~SfxPoolItem()
118 DBG_ASSERT(m_nRefCount == 0 || m_nRefCount > SFX_ITEMS_MAXREF,
119 "destroying item in use");
120 #if OSL_DEBUG_LEVEL > 1
121 --nItemCount;
122 #endif
126 int SfxPoolItem::Compare( const SfxPoolItem& ) const
128 return 0;
132 int SfxPoolItem::Compare( const SfxPoolItem& rWith, const IntlWrapper& ) const
134 return Compare( rWith );
138 bool SfxPoolItem::operator==( const SfxPoolItem& rCmp ) const
140 return rCmp.Type() == Type();
144 SfxPoolItem* SfxPoolItem::Create(SvStream &, sal_uInt16) const
146 return Clone();
150 sal_uInt16 SfxPoolItem::GetVersion( sal_uInt16 ) const
152 return 0;
156 SvStream& SfxPoolItem::Store(SvStream &rStream, sal_uInt16 ) const
158 return rStream;
162 * This virtual method allows to get a textual representation of the value
163 * for the SfxPoolItem subclasses. It should be overridden by all UI-relevant
164 * SfxPoolItem subclasses.
166 * Because the unit of measure of the value in the SfxItemPool is only
167 * queryable via @see SfxItemPool::GetMetric(sal_uInt16) const (and not
168 * via the SfxPoolItem instance or subclass, the own unit of measure is
169 * passed to 'eCoreMetric'.
171 * The corresponding unit of measure is passed as 'ePresentationMetric'.
174 * @return SfxItemPresentation SFX_ITEM_PRESENTATION_NAMELESS
175 * A textual representation (if applicable
176 * with a unit of measure) could be created,
177 * but it doesn't contain any semantic meaning
179 * SFX_ITEM_PRESENTATION_COMPLETE
180 * A complete textual representation could be
181 * created with semantic meaning (if applicable
182 * with unit of measure)
184 * Example:
186 * pSvxFontItem->GetPresentation( SFX_PRESENTATION_NAMELESS, ... )
187 * "12pt" with return SFX_ITEM_PRESENTATION_NAMELESS
189 * pSvxColorItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
190 * "red" with return SFX_ITEM_PRESENTATION_NAMELESS
191 * Because the SvxColorItem does not know which color it represents
192 * it cannot provide a name, which is communicated by the return value
194 * pSvxBorderItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
195 * "1cm top border, 2cm left border, 0.2cm bottom border, ..."
197 bool SfxPoolItem::GetPresentation
199 SfxItemPresentation /*ePresentation*/, // IN: how we should format
200 SfxMapUnit /*eCoreMetric*/, // IN: current metric of the SfxPoolItems
201 SfxMapUnit /*ePresentationMetric*/, // IN: target metric of the presentation
202 OUString& /*rText*/, // OUT: textual representation
203 const IntlWrapper *
204 ) const
206 return false;
209 void SfxPoolItem::dumpAsXml(xmlTextWriterPtr pWriter) const
211 xmlTextWriterStartElement(pWriter, BAD_CAST("sfxPoolItem"));
212 xmlTextWriterWriteAttribute(pWriter, BAD_CAST("whichId"), BAD_CAST(OString::number(Which()).getStr()));
213 xmlTextWriterEndElement(pWriter);
216 SfxVoidItem::SfxVoidItem( sal_uInt16 which ):
217 SfxPoolItem(which)
221 SfxVoidItem::SfxVoidItem( const SfxVoidItem& rCopy):
222 SfxPoolItem(rCopy)
227 bool SfxVoidItem::operator==( const SfxPoolItem&
228 #ifdef DBG_UTIL
229 rCmp
230 #endif
231 ) const
233 DBG_ASSERT( SfxPoolItem::operator==( rCmp ), "unequal type" );
234 return true;
238 bool SfxVoidItem::GetPresentation
240 SfxItemPresentation /*ePresentation*/,
241 SfxMapUnit /*eCoreMetric*/,
242 SfxMapUnit /*ePresentationMetric*/,
243 OUString& rText,
244 const IntlWrapper *
245 ) const
247 rText = "Void";
248 return true;
252 SfxPoolItem* SfxVoidItem::Clone(SfxItemPool *) const
254 return new SfxVoidItem(*this);
257 bool SfxPoolItem::ScaleMetrics( long /*lMult*/, long /*lDiv*/ )
259 return false;
263 bool SfxPoolItem::HasMetrics() const
265 return false;
270 bool SfxPoolItem::QueryValue( com::sun::star::uno::Any&, sal_uInt8 ) const
272 OSL_FAIL("There is no implementation for QueryValue for this item!");
273 return false;
278 bool SfxPoolItem::PutValue( const com::sun::star::uno::Any&, sal_uInt8 )
280 OSL_FAIL("There is no implementation for PutValue for this item!");
281 return false;
284 SfxVoidItem::~SfxVoidItem()
288 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */