1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
24 // STATIC DATA -----------------------------------------------------------
28 // @@@ DBG_NAME(SfxInvalidItem);
29 DBG_NAME(SfxItemHandle
)
31 // RTTI ------------------------------------------------------------------
33 TYPEINIT0(SfxPoolItem
);
34 TYPEINIT1(SfxVoidItem
, SfxPoolItem
);
35 // @@@ TYPEINIT1(SfxInvalidItem, SfxPoolItem);
36 TYPEINIT1(SfxSetItem
, SfxPoolItem
);
37 // @@@ TYPEINIT1(SfxItemChangedHint, SfxHint);
39 // ------------------------------------------------------------------------
40 #if OSL_DEBUG_LEVEL > 1
41 static sal_uLong nItemCount
= 0;
43 const char* pw1
= "Wow! 10.000 items!";
44 const char* pw2
= "Wow! 100.000 items!";
45 const char* pw3
= "Wow! 1.000.000 items!";
46 const char* pw4
= "Wow! 50.000.000 items!";
47 const char* pw5
= "Wow! 10.000.000 items!";
50 IMPL_PTRHINT(SfxPoolItemHint
,SfxPoolItem
)
52 // SfxPoolItem -----------------------------------------------------------
53 SfxPoolItem::SfxPoolItem(sal_uInt16
const nWhich
)
58 DBG_CTOR(SfxPoolItem
, 0);
59 DBG_ASSERT(nWhich
<= SHRT_MAX
, "invalid WhichId");
60 #if OSL_DEBUG_LEVEL > 1
62 if ( pw1
&& nItemCount
>=10000 )
67 if ( pw2
&& nItemCount
>=100000 )
72 if ( pw3
&& nItemCount
>=1000000 )
77 if ( pw4
&& nItemCount
>=5000000 )
82 if ( pw5
&& nItemCount
>=10000000 )
90 // -----------------------------------------------------------------------
91 SfxPoolItem::SfxPoolItem( const SfxPoolItem
& rCpy
)
92 : m_nRefCount(0) // don't copy that
93 , m_nWhich(rCpy
.Which()) // call function because of ChkThis() (WTF does that mean?)
96 DBG_CTOR(SfxPoolItem
, 0);
97 #if OSL_DEBUG_LEVEL > 1
99 if ( pw1
&& nItemCount
>=10000 )
104 if ( pw2
&& nItemCount
>=100000 )
109 if ( pw3
&& nItemCount
>=1000000 )
114 if ( pw4
&& nItemCount
>=5000000 )
119 if ( pw5
&& nItemCount
>=10000000 )
127 // ------------------------------------------------------------------------
128 SfxPoolItem::~SfxPoolItem()
130 DBG_DTOR(SfxPoolItem
, 0);
131 DBG_ASSERT(m_nRefCount
== 0 || m_nRefCount
> SFX_ITEMS_MAXREF
,
132 "destroying item in use");
133 #if OSL_DEBUG_LEVEL > 1
138 // ------------------------------------------------------------------------
139 int SfxPoolItem::Compare( const SfxPoolItem
& ) const
144 // ------------------------------------------------------------------------
145 int SfxPoolItem::Compare( const SfxPoolItem
& rWith
, const IntlWrapper
& ) const
147 return Compare( rWith
);
150 // ------------------------------------------------------------------------
151 int SfxPoolItem::operator==( const SfxPoolItem
& rCmp
) const
153 DBG_CHKTHIS(SfxPoolItem
, 0);
154 return rCmp
.Type() == Type();
157 // -----------------------------------------------------------------------
158 SfxPoolItem
* SfxPoolItem::Create(SvStream
&, sal_uInt16
) const
160 DBG_CHKTHIS(SfxPoolItem
, 0);
164 // -----------------------------------------------------------------------
165 sal_uInt16
SfxPoolItem::GetVersion( sal_uInt16
) const
167 DBG_CHKTHIS(SfxPoolItem
, 0);
171 // -----------------------------------------------------------------------
172 SvStream
& SfxPoolItem::Store(SvStream
&rStream
, sal_uInt16
) const
174 DBG_CHKTHIS(SfxPoolItem
, 0);
179 OUString
SfxPoolItem::readByteString(SvStream
& rStream
)
181 return rStream
.ReadUniOrByteString(rStream
.GetStreamCharSet());
185 void SfxPoolItem::writeByteString(SvStream
& rStream
, const OUString
& rString
)
187 rStream
.WriteUniOrByteString(rString
, rStream
.GetStreamCharSet());
191 OUString
SfxPoolItem::readUnicodeString(SvStream
& rStream
, bool bUnicode
)
193 return rStream
.ReadUniOrByteString(bUnicode
? RTL_TEXTENCODING_UCS2
:
194 rStream
.GetStreamCharSet());
198 void SfxPoolItem::writeUnicodeString(SvStream
& rStream
, const OUString
& rString
)
200 rStream
.WriteUniOrByteString(rString
, RTL_TEXTENCODING_UCS2
);
203 // ------------------------------------------------------------------------
204 SfxItemPresentation
SfxPoolItem::GetPresentation
206 SfxItemPresentation
/*ePresentation*/, // IN: wie formatiert werden soll
207 SfxMapUnit
/*eCoreMetric*/, // IN: Ma\seinheit des SfxPoolItems
208 SfxMapUnit
/*ePresentationMetric*/, // IN: Wunsch-Ma\einheit der Darstellung
209 OUString
& /*rText*/, // OUT: textuelle Darstellung
215 "Uber diese virtuelle Methode kann von den SfxPoolItem-Subklassen
216 eine textuelle Datstellung des Wertes erhalten werden. Sie sollte
217 von allen UI-relevanten SfxPoolItem-Subklassen "uberladen werden.
219 Da die Ma\seinheit des Wertes im SfxItemPool nur "uber
220 <SfxItemPool::GetMetric(sal_uInt16)const> erfragbar ist, und nicht etwa
221 in der SfxPoolItem-Instanz oder -Subklasse verf"ugbar ist, wird die
222 eigene Ma\seinheit als 'eCoreMetric' "ubergeben.
224 Die darzustellende Ma\seinheit wird als 'ePresentationMetric'
230 SfxItemPresentation SFX_ITEM_PRESENTATION_NONE
231 es konnte keine Text-Darstellung erzeugt werden
233 SFX_ITEM_PRESENTATION_NAMELESS
234 es konnte eine Text-Darstellung (ggf. mit
235 Ma\seinheit) erzeugt werden, die jedoch keine
236 semantische Bedeutung enth"alt
238 SFX_ITEM_PRESENTATION_COMPLETE
239 es konnte eine komplette Text-Darstellung mit
240 semantischer Bedeutung (und ggf. Ma\seinheit)
246 pSvxFontItem->GetPresentation( SFX_PRESENTATION_NAMELESS, ... )
247 "12pt" mit return SFX_ITEM_PRESENTATION_NAMELESS
249 pSvxColorItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
250 "rot" mit return SFX_ITEM_PRESENTATION_NAMELESS
251 (das das SvxColorItem nicht wei\s, was f"ur eine Farbe es darstellt,
252 kann es keinen Namen angeben, was durch den Returnwert mitgeteilt wird.
254 pSvxBorderItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
255 "1cm oberer Rand, 2cm linker Rand, 0,2cm unterer Rand, ..."
259 return SFX_ITEM_PRESENTATION_NONE
;
262 // SfxVoidItem ------------------------------------------------------------
263 SfxVoidItem::SfxVoidItem( sal_uInt16 which
):
266 DBG_CTOR(SfxVoidItem
, 0);
269 // SfxVoidItem ------------------------------------------------------------
270 SfxVoidItem::SfxVoidItem( const SfxVoidItem
& rCopy
):
273 DBG_CTOR(SfxVoidItem
, 0);
276 // ------------------------------------------------------------------------
277 int SfxVoidItem::operator==( const SfxPoolItem
&
283 DBG_CHKTHIS(SfxVoidItem
, 0);
284 DBG_ASSERT( SfxPoolItem::operator==( rCmp
), "unequal type" );
288 // ------------------------------------------------------------------------
289 SfxItemPresentation
SfxVoidItem::GetPresentation
291 SfxItemPresentation
/*ePresentation*/,
292 SfxMapUnit
/*eCoreMetric*/,
293 SfxMapUnit
/*ePresentationMetric*/,
298 DBG_CHKTHIS(SfxVoidItem
, 0);
300 return SFX_ITEM_PRESENTATION_NAMELESS
;
303 // ------------------------------------------------------------------------
304 SfxPoolItem
* SfxVoidItem::Clone(SfxItemPool
*) const
306 DBG_CHKTHIS(SfxVoidItem
, 0);
307 return new SfxVoidItem(*this);
310 // SfxInvalidItem ---------------------------------------------------------
312 // SfxItemHandle ----------------------------------------------------------
313 SfxItemHandle::SfxItemHandle(SfxPoolItem
&rItem
):
314 pRef(new sal_uInt16(1)),
315 pItem(rItem
.Clone(0))
317 DBG_CTOR(SfxItemHandle
, 0);
320 // ------------------------------------------------------------------------
321 SfxItemHandle::SfxItemHandle(const SfxItemHandle
&rCopy
):
325 DBG_CTOR(SfxItemHandle
, 0);
329 // ------------------------------------------------------------------------
330 const SfxItemHandle
&SfxItemHandle::operator=(const SfxItemHandle
&rCopy
)
332 DBG_CHKTHIS(SfxItemHandle
, 0);
333 if(&rCopy
== this || pItem
== rCopy
.pItem
)
347 // ------------------------------------------------------------------------
348 SfxItemHandle::~SfxItemHandle()
350 DBG_DTOR(SfxItemHandle
, 0);
353 delete pRef
; pRef
= 0;
354 delete pItem
; pItem
= 0;
358 // ------------------------------------------------------------------------
359 bool SfxPoolItem::ScaleMetrics( long /*lMult*/, long /*lDiv*/ )
364 // ------------------------------------------------------------------------
365 bool SfxPoolItem::HasMetrics() const
370 // -----------------------------------------------------------------------
372 bool SfxPoolItem::QueryValue( com::sun::star::uno::Any
&, sal_uInt8
) const
374 OSL_FAIL("There is no implementation for QueryValue for this item!");
378 // -----------------------------------------------------------------------
380 bool SfxPoolItem::PutValue( const com::sun::star::uno::Any
&, sal_uInt8
)
382 OSL_FAIL("There is no implementation for PutValue for this item!");
386 SfxVoidItem::~SfxVoidItem()
388 DBG_DTOR(SfxVoidItem
, 0);
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */