xref: /trunk/main/svl/source/items/poolitem.cxx (revision 40df464e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svl.hxx"
26 
27 #include <svl/poolitem.hxx>
28 #include <tools/stream.hxx>
29 
30 // STATIC DATA -----------------------------------------------------------
31 
32 DBG_NAME(SfxPoolItem)
33 DBG_NAME(SfxVoidItem)
34 // @@@ DBG_NAME(SfxInvalidItem);
35 DBG_NAME(SfxItemHandle)
36 
37 sal_uInt8 nSfxFlag8Val[8] =
38 {
39 	1, 2, 4, 8, 16, 32, 64, 128
40 };
41 
42 sal_uInt16 nSfxFlag16Val[16] =
43 {
44 	1, 2, 4, 8, 16, 32, 64, 128, 256, 512,
45 	1024, 2048, 4096, 8192, 16384, 32768
46 };
47 
48 sal_uLong nSfxFlag32Val[32] =
49 {
50 	0x1L, 0x2L, 0x4L, 0x8L,
51 	0x10L, 0x20L, 0x40L, 0x80L,
52 	0x100L, 0x200L, 0x400L, 0x800L,
53 	0x1000L, 0x2000L, 0x40000L, 0x8000L,
54 	0x10000L, 0x20000L, 0x40000L, 0x80000L,
55 	0x100000L, 0x200000L, 0x400000L, 0x800000L,
56 	0x1000000L, 0x2000000L, 0x4000000L, 0x8000000L,
57 	0x10000000L, 0x20000000L, 0x40000000L, 0x80000000L
58 };
59 
60 // RTTI ------------------------------------------------------------------
61 
62 TYPEINIT0(SfxPoolItem);
63 TYPEINIT1(SfxVoidItem, SfxPoolItem);
64 // @@@ TYPEINIT1(SfxInvalidItem, SfxPoolItem);
65 TYPEINIT1(SfxSetItem, SfxPoolItem);
66 // @@@ TYPEINIT1(SfxItemChangedHint, SfxHint);
67 
68 // ------------------------------------------------------------------------
69 #if OSL_DEBUG_LEVEL > 1
70 static sal_uLong nItemCount = 0;
71 
72 const char* pw1 = "Wow! 10.000 items!";
73 const char* pw2 = "Wow! 100.000 items!";
74 const char* pw3 = "Wow! 1.000.000 items!";
75 const char* pw4 = "Wow! 50.000.000 items!";
76 const char* pw5 = "Wow! 10.000.000 items!";
77 #endif
78 
IMPL_PTRHINT(SfxPoolItemHint,SfxPoolItem)79 IMPL_PTRHINT(SfxPoolItemHint,SfxPoolItem)
80 
81 // SfxPoolItem -----------------------------------------------------------
82 SfxPoolItem::SfxPoolItem( sal_uInt16 nW )
83 	: nRefCount( 0 ),
84 	  nWhich( nW )
85 	  , nKind( 0 )
86 {
87 	DBG_CTOR(SfxPoolItem, 0);
88 	DBG_ASSERT(nW <= SHRT_MAX, "Which Bereich ueberschritten");
89 #if OSL_DEBUG_LEVEL > 1
90 	++nItemCount;
91 	if ( pw1 && nItemCount>=10000 )
92 	{
93 		DBG_WARNING( pw1 );
94 		pw1 = NULL;
95 	}
96 	if ( pw2 && nItemCount>=100000 )
97 	{
98 		DBG_WARNING( pw2 );
99 		pw2 = NULL;
100 	}
101 	if ( pw3 && nItemCount>=1000000 )
102 	{
103 		DBG_WARNING( pw3 );
104 		pw3 = NULL;
105 	}
106 	if ( pw4 && nItemCount>=5000000 )
107 	{
108 		DBG_WARNING( pw4 );
109 		pw4 = NULL;
110 	}
111 	if ( pw5 && nItemCount>=10000000 )
112 	{
113 		DBG_WARNING( pw5 );
114 		pw5 = NULL;
115 	}
116 #endif
117 }
118 
119 // -----------------------------------------------------------------------
SfxPoolItem(const SfxPoolItem & rCpy)120 SfxPoolItem::SfxPoolItem( const SfxPoolItem& rCpy )
121 	: nRefCount( 0 ),				// wird ja ein neues Object!
122 	  nWhich( rCpy.Which() )	// Funktion rufen wg. ChkThis()
123 	  , nKind( 0 )
124 {
125 	DBG_CTOR(SfxPoolItem, 0);
126 #if OSL_DEBUG_LEVEL > 1
127 	++nItemCount;
128 	if ( pw1 && nItemCount>=10000 )
129 	{
130 		DBG_WARNING( pw1 );
131 		pw1 = NULL;
132 	}
133 	if ( pw2 && nItemCount>=100000 )
134 	{
135 		DBG_WARNING( pw2 );
136 		pw2 = NULL;
137 	}
138 	if ( pw3 && nItemCount>=1000000 )
139 	{
140 		DBG_WARNING( pw3 );
141 		pw3 = NULL;
142 	}
143 	if ( pw4 && nItemCount>=5000000 )
144 	{
145 		DBG_WARNING( pw4 );
146 		pw4 = NULL;
147 	}
148 	if ( pw5 && nItemCount>=10000000 )
149 	{
150 		DBG_WARNING( pw5 );
151 		pw5 = NULL;
152 	}
153 #endif
154 }
155 
156 // ------------------------------------------------------------------------
~SfxPoolItem()157 SfxPoolItem::~SfxPoolItem()
158 {
159 	DBG_DTOR(SfxPoolItem, 0);
160 	DBG_ASSERT(nRefCount == 0 || nRefCount > SFX_ITEMS_MAXREF, "destroying item in use" );
161 #if OSL_DEBUG_LEVEL > 1
162 	--nItemCount;
163 #endif
164 }
165 
166 // ------------------------------------------------------------------------
Compare(const SfxPoolItem &) const167 int SfxPoolItem::Compare( const SfxPoolItem& ) const
168 {
169 	return 0;
170 }
171 
172 // ------------------------------------------------------------------------
Compare(const SfxPoolItem & rWith,const IntlWrapper &) const173 int SfxPoolItem::Compare( const SfxPoolItem& rWith, const IntlWrapper& ) const
174 {
175 	return Compare( rWith );
176 }
177 
178 // ------------------------------------------------------------------------
operator ==(const SfxPoolItem & rCmp) const179 int SfxPoolItem::operator==( const SfxPoolItem& rCmp ) const
180 {
181 	DBG_CHKTHIS(SfxPoolItem, 0);
182 	return rCmp.Type() == Type();
183 }
184 
185 // -----------------------------------------------------------------------
186 #ifndef TF_POOLABLE
187 
IsPoolable() const188 int SfxPoolItem::IsPoolable() const
189 {
190 	DBG_CHKTHIS(SfxPoolItem, 0);
191 	return sal_True;
192 }
193 #endif
194 
195 // -----------------------------------------------------------------------
Create(SvStream &,sal_uInt16) const196 SfxPoolItem* SfxPoolItem::Create(SvStream &, sal_uInt16) const
197 {
198 	DBG_CHKTHIS(SfxPoolItem, 0);
199 	return Clone(0);
200 }
201 
202 // -----------------------------------------------------------------------
GetVersion(sal_uInt16) const203 sal_uInt16 SfxPoolItem::GetVersion( sal_uInt16 ) const
204 {
205 	DBG_CHKTHIS(SfxPoolItem, 0);
206 	return 0;
207 }
208 
209 // -----------------------------------------------------------------------
Store(SvStream & rStream,sal_uInt16) const210 SvStream& SfxPoolItem::Store(SvStream &rStream, sal_uInt16 ) const
211 {
212 	DBG_CHKTHIS(SfxPoolItem, 0);
213 	return rStream;
214 }
215 
216 //============================================================================
217 // static
readByteString(SvStream & rStream,UniString & rString)218 bool SfxPoolItem::readByteString(SvStream & rStream, UniString & rString)
219 {
220 	rStream.ReadByteString(rString);
221 	return rStream.GetError() == ERRCODE_NONE;
222 }
223 
224 //============================================================================
225 // static
writeByteString(SvStream & rStream,UniString const & rString)226 void SfxPoolItem::writeByteString(SvStream & rStream,
227 								  UniString const & rString)
228 {
229 	rStream.WriteByteString(rString);
230 }
231 
232 //============================================================================
233 // static
readUnicodeString(SvStream & rStream,UniString & rString,bool bUnicode)234 bool SfxPoolItem::readUnicodeString(SvStream & rStream, UniString & rString,
235 									bool bUnicode)
236 {
237 	rStream.ReadByteString(rString,
238 						   bUnicode ? RTL_TEXTENCODING_UCS2 :
239 						              rStream.GetStreamCharSet());
240 	return rStream.GetError() == ERRCODE_NONE;
241 }
242 
243 //============================================================================
244 // static
writeUnicodeString(SvStream & rStream,UniString const & rString)245 void SfxPoolItem::writeUnicodeString(SvStream & rStream,
246 									 UniString const & rString)
247 {
248 	rStream.WriteByteString(rString, RTL_TEXTENCODING_UCS2);
249 }
250 
251 // ------------------------------------------------------------------------
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString &,const IntlWrapper *) const252 SfxItemPresentation SfxPoolItem::GetPresentation
253 (
254 	SfxItemPresentation	/*ePresentation*/,       // IN:  wie formatiert werden soll
255 	SfxMapUnit			/*eCoreMetric*/,		 // IN:  Ma\seinheit des SfxPoolItems
256 	SfxMapUnit			/*ePresentationMetric*/, // IN:  Wunsch-Ma\einheit der Darstellung
257 	XubString&			/*rText*/,				 // OUT: textuelle Darstellung
258     const IntlWrapper *
259 ) 	const
260 
261 /*	[Beschreibung]
262 
263 	"Uber diese virtuelle Methode kann von den SfxPoolItem-Subklassen
264 	eine textuelle Datstellung des Wertes erhalten werden. Sie sollte
265 	von allen UI-relevanten SfxPoolItem-Subklassen "uberladen werden.
266 
267 	Da die Ma\seinheit des Wertes im SfxItemPool nur "uber
268 	<SfxItemPool::GetMetric(sal_uInt16)const> erfragbar ist, und nicht etwa
269 	in der SfxPoolItem-Instanz oder -Subklasse  verf"ugbar ist, wird die
270 	eigene Ma\seinheit als 'eCoreMetric' "ubergeben.
271 
272 	Die darzustellende Ma\seinheit wird als 'ePresentationMetric'
273 	"ubergeben.
274 
275 
276 	[R"uckgabewert]
277 
278 	SfxItemPresentation		SFX_ITEM_PRESENTATION_NONE
279 							es konnte keine Text-Darstellung erzeugt werden
280 
281 							SFX_ITEM_PRESENTATION_NAMELESS
282 							es konnte eine Text-Darstellung (ggf. mit
283 							Ma\seinheit) erzeugt werden, die jedoch keine
284 							semantische Bedeutung enth"alt
285 
286 							SFX_ITEM_PRESENTATION_COMPLETE
287 							es konnte eine komplette Text-Darstellung mit
288 							semantischer Bedeutung (und ggf. Ma\seinheit)
289 							erzeugt werden
290 
291 
292 	[Beispiele]
293 
294 	pSvxFontItem->GetPresentation( SFX_PRESENTATION_NAMELESS, ... )
295 		"12pt" mit return SFX_ITEM_PRESENTATION_NAMELESS
296 
297 	pSvxColorItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
298 		"rot" mit return SFX_ITEM_PRESENTATION_NAMELESS
299 		(das das SvxColorItem nicht wei\s, was f"ur eine Farbe es darstellt,
300 		kann es keinen Namen angeben, was durch den Returnwert mitgeteilt wird.
301 
302 	pSvxBorderItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
303 		"1cm oberer Rand, 2cm linker Rand, 0,2cm unterer Rand, ..."
304 */
305 
306 {
307 	return SFX_ITEM_PRESENTATION_NONE;
308 }
309 
310 // SfxVoidItem ------------------------------------------------------------
SfxVoidItem(sal_uInt16 which)311 SfxVoidItem::SfxVoidItem( sal_uInt16 which ):
312 	SfxPoolItem(which)
313 {
314 	DBG_CTOR(SfxVoidItem, 0);
315 }
316 
317 // SfxVoidItem ------------------------------------------------------------
SfxVoidItem(const SfxVoidItem & rCopy)318 SfxVoidItem::SfxVoidItem( const SfxVoidItem& rCopy):
319 	SfxPoolItem(rCopy)
320 {
321 	DBG_CTOR(SfxVoidItem, 0);
322 }
323 
324 // ------------------------------------------------------------------------
operator ==(const SfxPoolItem & rCmp) const325 int SfxVoidItem::operator==( const SfxPoolItem&
326 #ifdef DBG_UTIL
327 rCmp
328 #endif
329 ) const
330 {
331 	DBG_CHKTHIS(SfxVoidItem, 0);
332 	DBG_ASSERT( SfxPoolItem::operator==( rCmp ), "unequal type" );
333 	return sal_True;
334 }
335 
336 // ------------------------------------------------------------------------
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const337 SfxItemPresentation SfxVoidItem::GetPresentation
338 (
339 	SfxItemPresentation 	/*ePresentation*/,
340 	SfxMapUnit				/*eCoreMetric*/,
341 	SfxMapUnit				/*ePresentationMetric*/,
342 	XubString& 				rText,
343     const IntlWrapper *
344 )	const
345 {
346 	DBG_CHKTHIS(SfxVoidItem, 0);
347 	rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("Void"));
348 	return SFX_ITEM_PRESENTATION_NAMELESS;
349 }
350 
351 // ------------------------------------------------------------------------
Clone(SfxItemPool *) const352 SfxPoolItem* SfxVoidItem::Clone(SfxItemPool *) const
353 {
354 	DBG_CHKTHIS(SfxVoidItem, 0);
355 	return new SfxVoidItem(*this);
356 }
357 
358 // SfxInvalidItem ---------------------------------------------------------
359 #if 0  /* @@@ NOT USED @@@ */
360 SfxInvalidItem::SfxInvalidItem( sal_uInt16 nWhich, const SfxPoolItem &rDefault ):
361 	SfxPoolItem(nWhich),
362 	pDefaultItem(&rDefault)
363 {
364 	DBG_CTOR(SfxInvalidItem, 0);
365 }
366 
367 // ------------------------------------------------------------------------
368 SfxInvalidItem::SfxInvalidItem( const SfxInvalidItem& rCopy):
369 	SfxPoolItem(rCopy),
370 	pDefaultItem(rCopy.pDefaultItem)
371 {
372 	DBG_CTOR(SfxInvalidItem, 0);
373 	//! pDefaultItem->ReleaseRef?
374 }
375 
376 // ------------------------------------------------------------------------
377 SfxInvalidItem::~SfxInvalidItem()
378 {
379 	DBG_DTOR(SfxInvalidItem, 0);
380 }
381 
382 // ------------------------------------------------------------------------
383 int SfxInvalidItem::operator==( const SfxPoolItem& rCmp) const
384 {
385 	DBG_CHKTHIS(SfxInvalidItem, 0);
386 	DBG_ASSERT( SfxPoolItem::operator==(rCmp), "unequal type" );
387 	return *pDefaultItem == *((SfxInvalidItem&)rCmp).pDefaultItem;
388 }
389 
390 // ------------------------------------------------------------------------
391 SfxItemPresentation SfxInvalidItem::GetPresentation
392 (
393 	SfxItemPresentation 	ePresentation,
394 	SfxMapUnit				eCoreMetric,
395 	SfxMapUnit				ePresentationMetric,
396 	XubString& 				rText,
397     const IntlWrapper *
398 )	const
399 {
400 	DBG_CHKTHIS(SfxInvalidItem, 0);
401 	rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("Invalid"));
402 	return SFX_ITEM_PRESENTATION_NAMELESS;
403 }
404 
405 // ------------------------------------------------------------------------
406 SfxPoolItem* SfxInvalidItem::Clone(SfxItemPool *) const
407 {
408 	DBG_CHKTHIS(SfxInvalidItem, 0);
409 	return new SfxInvalidItem(*this);
410 }
411 
412 // ------------------------------------------------------------------------
413 SfxPoolItem* SfxInvalidItem::Create(SvStream &, sal_uInt16 nVersion) const
414 {
415 	DBG_CHKTHIS(SfxInvalidItem, 0);
416 	DBG_ERROR("SfxInvalidItem::Create() ist sinnlos");
417 	return Clone();
418 }
419 
420 // ------------------------------------------------------------------------
421 SvStream& SfxInvalidItem::Store(SvStream &rStream, sal_uInt16 nItemVersion ) const
422 {
423 	DBG_CHKTHIS(SfxInvalidItem, 0);
424 	DBG_ERROR("SfxInvalidItem::Store() ist sinnlos");
425 	return rStream;
426 }
427 #endif /* @@@ NOT USED @@@ */
428 
429 // SfxItemHandle ----------------------------------------------------------
SfxItemHandle(SfxPoolItem & rItem)430 SfxItemHandle::SfxItemHandle(SfxPoolItem &rItem):
431 	pRef(new sal_uInt16(1)),
432 	pItem(rItem.Clone(0))
433 {
434 	DBG_CTOR(SfxItemHandle, 0);
435 }
436 
437 // ------------------------------------------------------------------------
SfxItemHandle(const SfxItemHandle & rCopy)438 SfxItemHandle::SfxItemHandle(const SfxItemHandle &rCopy):
439 	pRef(rCopy.pRef),
440 	pItem(rCopy.pItem)
441 {
442 	DBG_CTOR(SfxItemHandle, 0);
443 	++(*pRef);
444 }
445 
446 // ------------------------------------------------------------------------
operator =(const SfxItemHandle & rCopy)447 const SfxItemHandle &SfxItemHandle::operator=(const SfxItemHandle &rCopy)
448 {
449 	DBG_CHKTHIS(SfxItemHandle, 0);
450 	if(&rCopy == this || pItem == rCopy.pItem)
451 		return *this;
452 	--(*pRef);
453 	if(!(*pRef))
454 	{
455 		delete pItem;
456 		pItem = 0;
457 	}
458 	pRef = rCopy.pRef;
459 	++(*pRef);
460 	pItem = rCopy.pItem;
461 	return *this;
462 }
463 
464 // ------------------------------------------------------------------------
~SfxItemHandle()465 SfxItemHandle::~SfxItemHandle()
466 {
467 	DBG_DTOR(SfxItemHandle, 0);
468 	--(*pRef);
469 	if(!(*pRef)) {
470 		delete pRef; pRef = 0;
471 		delete pItem; pItem = 0;
472 	}
473 }
474 
475 // ------------------------------------------------------------------------
ScaleMetrics(long,long)476 int SfxPoolItem::ScaleMetrics( long /*lMult*/, long /*lDiv*/ )
477 {
478 	return 0;
479 }
480 
481 // ------------------------------------------------------------------------
HasMetrics() const482 int SfxPoolItem::HasMetrics() const
483 {
484 	return 0;
485 }
486 
487 // -----------------------------------------------------------------------
488 #if 0  /* @@@ NOT USED @@@ */
489 void SfxPoolItem::GetVersion() const
490 {
491 	DBG_ERROR( "dummy called" );
492 }
493 
494 // -----------------------------------------------------------------------
495 void SfxPoolItem::Store(SvStream &rStream) const
496 {
497 	DBG_ERROR( "dummy called" );
498 }
499 #endif /* @@@ NOT USED @@@ */
500 
501 // -----------------------------------------------------------------------
502 
QueryValue(com::sun::star::uno::Any &,sal_uInt8) const503 sal_Bool SfxPoolItem::QueryValue( com::sun::star::uno::Any&, sal_uInt8 ) const
504 {
505 	DBG_ERROR("There is no implementation for QueryValue for this item!");
506 	return sal_False;
507 }
508 
509 // -----------------------------------------------------------------------
510 
PutValue(const com::sun::star::uno::Any &,sal_uInt8)511 sal_Bool SfxPoolItem::PutValue( const com::sun::star::uno::Any&, sal_uInt8 )
512 {
513 	DBG_ERROR("There is no implementation for PutValue for this item!");
514 	return sal_False;
515 }
516 
~SfxVoidItem()517 SfxVoidItem::~SfxVoidItem()
518 {
519 	DBG_DTOR(SfxVoidItem, 0);
520 }
521