Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #include <svl/poolitem.hxx>
22 : #include <tools/stream.hxx>
23 :
24 : // STATIC DATA -----------------------------------------------------------
25 :
26 : DBG_NAME(SfxPoolItem)
27 : DBG_NAME(SfxVoidItem)
28 : // @@@ DBG_NAME(SfxInvalidItem);
29 : DBG_NAME(SfxItemHandle)
30 :
31 : // RTTI ------------------------------------------------------------------
32 :
33 4548681 : TYPEINIT0(SfxPoolItem);
34 15071782 : TYPEINIT1(SfxVoidItem, SfxPoolItem);
35 : // @@@ TYPEINIT1(SfxInvalidItem, SfxPoolItem);
36 1789598 : TYPEINIT1(SfxSetItem, SfxPoolItem);
37 : // @@@ TYPEINIT1(SfxItemChangedHint, SfxHint);
38 :
39 : // ------------------------------------------------------------------------
40 : #if OSL_DEBUG_LEVEL > 1
41 : static sal_uLong nItemCount = 0;
42 :
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!";
48 : #endif
49 :
50 289879 : IMPL_PTRHINT(SfxPoolItemHint,SfxPoolItem)
51 :
52 : // SfxPoolItem -----------------------------------------------------------
53 3458489 : SfxPoolItem::SfxPoolItem(sal_uInt16 const nWhich)
54 : : m_nRefCount(0)
55 : , m_nWhich(nWhich)
56 3458489 : , m_nKind(0)
57 : {
58 : DBG_CTOR(SfxPoolItem, 0);
59 : DBG_ASSERT(nWhich <= SHRT_MAX, "invalid WhichId");
60 : #if OSL_DEBUG_LEVEL > 1
61 : ++nItemCount;
62 : if ( pw1 && nItemCount>=10000 )
63 : {
64 : DBG_WARNING( pw1 );
65 : pw1 = NULL;
66 : }
67 : if ( pw2 && nItemCount>=100000 )
68 : {
69 : DBG_WARNING( pw2 );
70 : pw2 = NULL;
71 : }
72 : if ( pw3 && nItemCount>=1000000 )
73 : {
74 : DBG_WARNING( pw3 );
75 : pw3 = NULL;
76 : }
77 : if ( pw4 && nItemCount>=5000000 )
78 : {
79 : DBG_WARNING( pw4 );
80 : pw4 = NULL;
81 : }
82 : if ( pw5 && nItemCount>=10000000 )
83 : {
84 : DBG_WARNING( pw5 );
85 : pw5 = NULL;
86 : }
87 : #endif
88 3458489 : }
89 :
90 : // -----------------------------------------------------------------------
91 1670688 : SfxPoolItem::SfxPoolItem( const SfxPoolItem& rCpy )
92 : : m_nRefCount(0) // don't copy that
93 1670688 : , m_nWhich(rCpy.Which()) // call function because of ChkThis() (WTF does that mean?)
94 3341376 : , m_nKind( 0 )
95 : {
96 : DBG_CTOR(SfxPoolItem, 0);
97 : #if OSL_DEBUG_LEVEL > 1
98 : ++nItemCount;
99 : if ( pw1 && nItemCount>=10000 )
100 : {
101 : DBG_WARNING( pw1 );
102 : pw1 = NULL;
103 : }
104 : if ( pw2 && nItemCount>=100000 )
105 : {
106 : DBG_WARNING( pw2 );
107 : pw2 = NULL;
108 : }
109 : if ( pw3 && nItemCount>=1000000 )
110 : {
111 : DBG_WARNING( pw3 );
112 : pw3 = NULL;
113 : }
114 : if ( pw4 && nItemCount>=5000000 )
115 : {
116 : DBG_WARNING( pw4 );
117 : pw4 = NULL;
118 : }
119 : if ( pw5 && nItemCount>=10000000 )
120 : {
121 : DBG_WARNING( pw5 );
122 : pw5 = NULL;
123 : }
124 : #endif
125 1670688 : }
126 :
127 : // ------------------------------------------------------------------------
128 5096405 : SfxPoolItem::~SfxPoolItem()
129 : {
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
134 : --nItemCount;
135 : #endif
136 5096405 : }
137 :
138 : // ------------------------------------------------------------------------
139 0 : int SfxPoolItem::Compare( const SfxPoolItem& ) const
140 : {
141 0 : return 0;
142 : }
143 :
144 : // ------------------------------------------------------------------------
145 0 : int SfxPoolItem::Compare( const SfxPoolItem& rWith, const IntlWrapper& ) const
146 : {
147 0 : return Compare( rWith );
148 : }
149 :
150 : // ------------------------------------------------------------------------
151 18675 : int SfxPoolItem::operator==( const SfxPoolItem& rCmp ) const
152 : {
153 : DBG_CHKTHIS(SfxPoolItem, 0);
154 18675 : return rCmp.Type() == Type();
155 : }
156 :
157 : // -----------------------------------------------------------------------
158 0 : SfxPoolItem* SfxPoolItem::Create(SvStream &, sal_uInt16) const
159 : {
160 : DBG_CHKTHIS(SfxPoolItem, 0);
161 0 : return Clone(0);
162 : }
163 :
164 : // -----------------------------------------------------------------------
165 182374 : sal_uInt16 SfxPoolItem::GetVersion( sal_uInt16 ) const
166 : {
167 : DBG_CHKTHIS(SfxPoolItem, 0);
168 182374 : return 0;
169 : }
170 :
171 : // -----------------------------------------------------------------------
172 0 : SvStream& SfxPoolItem::Store(SvStream &rStream, sal_uInt16 ) const
173 : {
174 : DBG_CHKTHIS(SfxPoolItem, 0);
175 0 : return rStream;
176 : }
177 :
178 : //============================================================================
179 : // static
180 0 : OUString SfxPoolItem::readByteString(SvStream& rStream)
181 : {
182 0 : return rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
183 : }
184 :
185 : //============================================================================
186 : // static
187 2456 : void SfxPoolItem::writeByteString(SvStream & rStream, const OUString& rString)
188 : {
189 2456 : rStream.WriteUniOrByteString(rString, rStream.GetStreamCharSet());
190 2456 : }
191 :
192 : //============================================================================
193 : // static
194 0 : OUString SfxPoolItem::readUnicodeString(SvStream & rStream, bool bUnicode)
195 : {
196 : return rStream.ReadUniOrByteString(bUnicode ? RTL_TEXTENCODING_UCS2 :
197 0 : rStream.GetStreamCharSet());
198 : }
199 :
200 : //============================================================================
201 : // static
202 0 : void SfxPoolItem::writeUnicodeString(SvStream & rStream, const OUString& rString)
203 : {
204 0 : rStream.WriteUniOrByteString(rString, RTL_TEXTENCODING_UCS2);
205 0 : }
206 :
207 : // ------------------------------------------------------------------------
208 0 : SfxItemPresentation SfxPoolItem::GetPresentation
209 : (
210 : SfxItemPresentation /*ePresentation*/, // IN: wie formatiert werden soll
211 : SfxMapUnit /*eCoreMetric*/, // IN: Ma\seinheit des SfxPoolItems
212 : SfxMapUnit /*ePresentationMetric*/, // IN: Wunsch-Ma\einheit der Darstellung
213 : OUString& /*rText*/, // OUT: textuelle Darstellung
214 : const IntlWrapper *
215 : ) const
216 :
217 : /* [Beschreibung]
218 :
219 : "Uber diese virtuelle Methode kann von den SfxPoolItem-Subklassen
220 : eine textuelle Datstellung des Wertes erhalten werden. Sie sollte
221 : von allen UI-relevanten SfxPoolItem-Subklassen "uberladen werden.
222 :
223 : Da die Ma\seinheit des Wertes im SfxItemPool nur "uber
224 : <SfxItemPool::GetMetric(sal_uInt16)const> erfragbar ist, und nicht etwa
225 : in der SfxPoolItem-Instanz oder -Subklasse verf"ugbar ist, wird die
226 : eigene Ma\seinheit als 'eCoreMetric' "ubergeben.
227 :
228 : Die darzustellende Ma\seinheit wird als 'ePresentationMetric'
229 : "ubergeben.
230 :
231 :
232 : [R"uckgabewert]
233 :
234 : SfxItemPresentation SFX_ITEM_PRESENTATION_NONE
235 : es konnte keine Text-Darstellung erzeugt werden
236 :
237 : SFX_ITEM_PRESENTATION_NAMELESS
238 : es konnte eine Text-Darstellung (ggf. mit
239 : Ma\seinheit) erzeugt werden, die jedoch keine
240 : semantische Bedeutung enth"alt
241 :
242 : SFX_ITEM_PRESENTATION_COMPLETE
243 : es konnte eine komplette Text-Darstellung mit
244 : semantischer Bedeutung (und ggf. Ma\seinheit)
245 : erzeugt werden
246 :
247 :
248 : [Beispiele]
249 :
250 : pSvxFontItem->GetPresentation( SFX_PRESENTATION_NAMELESS, ... )
251 : "12pt" mit return SFX_ITEM_PRESENTATION_NAMELESS
252 :
253 : pSvxColorItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
254 : "rot" mit return SFX_ITEM_PRESENTATION_NAMELESS
255 : (das das SvxColorItem nicht wei\s, was f"ur eine Farbe es darstellt,
256 : kann es keinen Namen angeben, was durch den Returnwert mitgeteilt wird.
257 :
258 : pSvxBorderItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
259 : "1cm oberer Rand, 2cm linker Rand, 0,2cm unterer Rand, ..."
260 : */
261 :
262 : {
263 0 : return SFX_ITEM_PRESENTATION_NONE;
264 : }
265 :
266 : // SfxVoidItem ------------------------------------------------------------
267 372437 : SfxVoidItem::SfxVoidItem( sal_uInt16 which ):
268 372437 : SfxPoolItem(which)
269 : {
270 : DBG_CTOR(SfxVoidItem, 0);
271 372437 : }
272 :
273 : // SfxVoidItem ------------------------------------------------------------
274 29626 : SfxVoidItem::SfxVoidItem( const SfxVoidItem& rCopy):
275 29626 : SfxPoolItem(rCopy)
276 : {
277 : DBG_CTOR(SfxVoidItem, 0);
278 29626 : }
279 :
280 : // ------------------------------------------------------------------------
281 6876 : int SfxVoidItem::operator==( const SfxPoolItem&
282 : #ifdef DBG_UTIL
283 : rCmp
284 : #endif
285 : ) const
286 : {
287 : DBG_CHKTHIS(SfxVoidItem, 0);
288 : DBG_ASSERT( SfxPoolItem::operator==( rCmp ), "unequal type" );
289 6876 : return sal_True;
290 : }
291 :
292 : // ------------------------------------------------------------------------
293 0 : SfxItemPresentation SfxVoidItem::GetPresentation
294 : (
295 : SfxItemPresentation /*ePresentation*/,
296 : SfxMapUnit /*eCoreMetric*/,
297 : SfxMapUnit /*ePresentationMetric*/,
298 : OUString& rText,
299 : const IntlWrapper *
300 : ) const
301 : {
302 : DBG_CHKTHIS(SfxVoidItem, 0);
303 0 : rText = "Void";
304 0 : return SFX_ITEM_PRESENTATION_NAMELESS;
305 : }
306 :
307 : // ------------------------------------------------------------------------
308 29626 : SfxPoolItem* SfxVoidItem::Clone(SfxItemPool *) const
309 : {
310 : DBG_CHKTHIS(SfxVoidItem, 0);
311 29626 : return new SfxVoidItem(*this);
312 : }
313 :
314 : // SfxInvalidItem ---------------------------------------------------------
315 :
316 : // SfxItemHandle ----------------------------------------------------------
317 0 : SfxItemHandle::SfxItemHandle(SfxPoolItem &rItem):
318 : pRef(new sal_uInt16(1)),
319 0 : pItem(rItem.Clone(0))
320 : {
321 : DBG_CTOR(SfxItemHandle, 0);
322 0 : }
323 :
324 : // ------------------------------------------------------------------------
325 0 : SfxItemHandle::SfxItemHandle(const SfxItemHandle &rCopy):
326 : pRef(rCopy.pRef),
327 0 : pItem(rCopy.pItem)
328 : {
329 : DBG_CTOR(SfxItemHandle, 0);
330 0 : ++(*pRef);
331 0 : }
332 :
333 : // ------------------------------------------------------------------------
334 0 : const SfxItemHandle &SfxItemHandle::operator=(const SfxItemHandle &rCopy)
335 : {
336 : DBG_CHKTHIS(SfxItemHandle, 0);
337 0 : if(&rCopy == this || pItem == rCopy.pItem)
338 0 : return *this;
339 0 : --(*pRef);
340 0 : if(!(*pRef))
341 : {
342 0 : delete pItem;
343 0 : pItem = 0;
344 : }
345 0 : pRef = rCopy.pRef;
346 0 : ++(*pRef);
347 0 : pItem = rCopy.pItem;
348 0 : return *this;
349 : }
350 :
351 : // ------------------------------------------------------------------------
352 0 : SfxItemHandle::~SfxItemHandle()
353 : {
354 : DBG_DTOR(SfxItemHandle, 0);
355 0 : --(*pRef);
356 0 : if(!(*pRef)) {
357 0 : delete pRef; pRef = 0;
358 0 : delete pItem; pItem = 0;
359 : }
360 0 : }
361 :
362 : // ------------------------------------------------------------------------
363 0 : bool SfxPoolItem::ScaleMetrics( long /*lMult*/, long /*lDiv*/ )
364 : {
365 0 : return false;
366 : }
367 :
368 : // ------------------------------------------------------------------------
369 0 : bool SfxPoolItem::HasMetrics() const
370 : {
371 0 : return false;
372 : }
373 :
374 : // -----------------------------------------------------------------------
375 :
376 0 : bool SfxPoolItem::QueryValue( com::sun::star::uno::Any&, sal_uInt8 ) const
377 : {
378 : OSL_FAIL("There is no implementation for QueryValue for this item!");
379 0 : return false;
380 : }
381 :
382 : // -----------------------------------------------------------------------
383 :
384 0 : bool SfxPoolItem::PutValue( const com::sun::star::uno::Any&, sal_uInt8 )
385 : {
386 : OSL_FAIL("There is no implementation for PutValue for this item!");
387 0 : return false;
388 : }
389 :
390 458120 : SfxVoidItem::~SfxVoidItem()
391 : {
392 : DBG_DTOR(SfxVoidItem, 0);
393 458120 : }
394 :
395 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|