merge the formfield patch from ooo-build
[ooovba.git] / svx / source / items / bulitem.cxx
blob36ca6126a03f330e7d078d1dc5228c5a09c2cf2e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bulitem.cxx,v $
10 * $Revision: 1.12 $
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_svx.hxx"
34 // include ---------------------------------------------------------------
35 #include <tools/stream.hxx>
37 #include <vcl/outdev.hxx>
39 #define _SVX_BULITEM_CXX
41 #include "bulitem.hxx"
42 #include "svxerr.hxx"
44 // #90477#
45 #include <tools/tenccvt.hxx>
47 #define BULITEM_VERSION ((USHORT)2)
49 // -----------------------------------------------------------------------
51 TYPEINIT1(SvxBulletItem,SfxPoolItem);
53 // -----------------------------------------------------------------------
55 void SvxBulletItem::StoreFont( SvStream& rStream, const Font& rFont )
57 USHORT nTemp;
59 rStream << rFont.GetColor();
60 nTemp = (USHORT)rFont.GetFamily(); rStream << nTemp;
62 // #90477# nTemp = (USHORT)GetStoreCharSet( rFont.GetCharSet(), rStream.GetVersion() );
63 nTemp = (USHORT)GetSOStoreTextEncoding((rtl_TextEncoding)rFont.GetCharSet(), (sal_uInt16)rStream.GetVersion());
64 rStream << nTemp;
66 nTemp = (USHORT)rFont.GetPitch(); rStream << nTemp;
67 nTemp = (USHORT)rFont.GetAlign(); rStream << nTemp;
68 nTemp = (USHORT)rFont.GetWeight(); rStream << nTemp;
69 nTemp = (USHORT)rFont.GetUnderline(); rStream << nTemp;
70 nTemp = (USHORT)rFont.GetStrikeout(); rStream << nTemp;
71 nTemp = (USHORT)rFont.GetItalic(); rStream << nTemp;
73 // UNICODE: rStream << rFont.GetName();
74 rStream.WriteByteString(rFont.GetName());
76 rStream << rFont.IsOutline();
77 rStream << rFont.IsShadow();
78 rStream << rFont.IsTransparent();
81 // -----------------------------------------------------------------------
83 Font SvxBulletItem::CreateFont( SvStream& rStream, USHORT nVer )
85 Font aFont;
86 Color aColor;
87 rStream >> aColor; aFont.SetColor( aColor );
88 USHORT nTemp;
89 rStream >> nTemp; aFont.SetFamily((FontFamily)nTemp);
91 // #90477#
92 rStream >> nTemp;
93 nTemp = (sal_uInt16)GetSOLoadTextEncoding((rtl_TextEncoding)nTemp, (sal_uInt16)rStream.GetVersion());
94 aFont.SetCharSet((rtl_TextEncoding)nTemp);
96 rStream >> nTemp; aFont.SetPitch((FontPitch)nTemp);
97 rStream >> nTemp; aFont.SetAlign((FontAlign)nTemp);
98 rStream >> nTemp; aFont.SetWeight((FontWeight)nTemp);
99 rStream >> nTemp; aFont.SetUnderline((FontUnderline)nTemp);
100 rStream >> nTemp; aFont.SetStrikeout((FontStrikeout)nTemp);
101 rStream >> nTemp; aFont.SetItalic((FontItalic)nTemp);
103 // UNICODE: rStream >> aName; aFont.SetName( aName );
104 String aName;
105 rStream.ReadByteString(aName);
106 aFont.SetName( aName );
108 if( nVer == 1 )
110 long nHeight, nWidth;
111 rStream >> nHeight; rStream >> nWidth; Size aSize( nWidth, nHeight );
112 aFont.SetSize( aSize );
115 BOOL bTemp;
116 rStream >> bTemp; aFont.SetOutline( bTemp );
117 rStream >> bTemp; aFont.SetShadow( bTemp );
118 rStream >> bTemp; aFont.SetTransparent( bTemp );
119 return aFont;
123 // -----------------------------------------------------------------------
125 SvxBulletItem::SvxBulletItem( USHORT _nWhich ) : SfxPoolItem( _nWhich )
127 SetDefaultFont_Impl();
128 SetDefaults_Impl();
129 nValidMask = 0xFFFF;
132 // -----------------------------------------------------------------------
134 SvxBulletItem::SvxBulletItem( BYTE nNewStyle, const Font& rFont, USHORT /*nStart*/, USHORT _nWhich ) : SfxPoolItem( _nWhich )
136 SetDefaults_Impl();
137 nStyle = nNewStyle;
138 aFont = rFont;
139 nValidMask = 0xFFFF;
142 // -----------------------------------------------------------------------
144 SvxBulletItem::SvxBulletItem( const Font& rFont, xub_Unicode cSymb, USHORT _nWhich ) : SfxPoolItem( _nWhich )
146 SetDefaults_Impl();
147 aFont = rFont;
148 cSymbol = cSymb;
149 nStyle = BS_BULLET;
150 nValidMask = 0xFFFF;
153 // -----------------------------------------------------------------------
155 SvxBulletItem::SvxBulletItem( const Bitmap& rBmp, USHORT _nWhich ) : SfxPoolItem( _nWhich )
157 SetDefaults_Impl();
159 if( !rBmp.IsEmpty() )
161 pGraphicObject = new GraphicObject( rBmp );
162 nStyle = BS_BMP;
165 nValidMask = 0xFFFF;
168 // -----------------------------------------------------------------------
170 SvxBulletItem::SvxBulletItem( const GraphicObject& rGraphicObject, USHORT _nWhich ) : SfxPoolItem( _nWhich )
172 SetDefaults_Impl();
174 if( ( GRAPHIC_NONE != pGraphicObject->GetType() ) && ( GRAPHIC_DEFAULT != pGraphicObject->GetType() ) )
176 pGraphicObject = new GraphicObject( rGraphicObject );
177 nStyle = BS_BMP;
180 nValidMask = 0xFFFF;
183 // -----------------------------------------------------------------------
185 SvxBulletItem::SvxBulletItem( SvStream& rStrm, USHORT _nWhich ) :
186 SfxPoolItem( _nWhich ),
187 pGraphicObject( NULL )
189 rStrm >> nStyle;
191 if( nStyle != BS_BMP )
192 aFont = CreateFont( rStrm, BULITEM_VERSION );
193 else
195 // Sicheres Laden mit Test auf leere Bitmap
196 Bitmap aBmp;
197 const UINT32 nOldPos = rStrm.Tell();
198 // #69345# Errorcode beim Bitmap lesen ignorieren,
199 // siehe Kommentar #67581# in SvxBulletItem::Store()
200 BOOL bOldError = rStrm.GetError() ? TRUE : FALSE;
201 rStrm >> aBmp;
202 if ( !bOldError && rStrm.GetError() )
204 rStrm.ResetError();
205 // #71493# Keine Warnung: Das BulletItem interessiert seit 5.0 im Dateiformat nicht mehr.
206 // rStrm.SetError(ERRCODE_CLASS_READ | ERRCODE_SVX_BULLETITEM_NOBULLET | ERRCODE_WARNING_MASK);
209 if( aBmp.IsEmpty() )
211 rStrm.Seek( nOldPos );
212 nStyle = BS_NONE;
214 else
215 pGraphicObject = new GraphicObject( aBmp );
218 rStrm >> nWidth;
219 rStrm >> nStart;
220 rStrm >> nJustify;
222 char cTmpSymbol;
223 rStrm >> cTmpSymbol;
224 cSymbol = ByteString::ConvertToUnicode( cTmpSymbol, aFont.GetCharSet() );
226 rStrm >> nScale;
228 // UNICODE: rStrm >> aPrevText;
229 rStrm.ReadByteString(aPrevText);
231 // UNICODE: rStrm >> aFollowText;
232 rStrm.ReadByteString(aFollowText);
234 nValidMask = 0xFFFF;
237 // -----------------------------------------------------------------------
239 SvxBulletItem::SvxBulletItem( const SvxBulletItem& rItem) : SfxPoolItem( rItem )
241 aFont = rItem.aFont;
242 pGraphicObject = ( rItem.pGraphicObject ? new GraphicObject( *rItem.pGraphicObject ) : NULL );
243 aPrevText = rItem.aPrevText;
244 aFollowText = rItem.aFollowText;
245 nStart = rItem.nStart;
246 nStyle = rItem.nStyle;
247 nWidth = rItem.nWidth;
248 nScale = rItem.nScale;
249 cSymbol = rItem.cSymbol;
250 nJustify = rItem.nJustify;
251 nValidMask = rItem.nValidMask;
254 // -----------------------------------------------------------------------
256 SvxBulletItem::~SvxBulletItem()
258 if( pGraphicObject )
259 delete pGraphicObject;
262 // -----------------------------------------------------------------------
264 SfxPoolItem* SvxBulletItem::Clone( SfxItemPool * /*pPool*/ ) const
266 return new SvxBulletItem( *this );
269 // -----------------------------------------------------------------------
271 SfxPoolItem* SvxBulletItem::Create( SvStream& rStrm, USHORT /*nVersion*/ ) const
273 return new SvxBulletItem( rStrm, Which() );
276 // -----------------------------------------------------------------------
278 void SvxBulletItem::SetDefaultFont_Impl()
280 aFont = OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, LANGUAGE_SYSTEM, 0 );
281 aFont.SetAlign( ALIGN_BOTTOM);
282 aFont.SetTransparent( TRUE );
285 // -----------------------------------------------------------------------
287 void SvxBulletItem::SetDefaults_Impl()
289 pGraphicObject = NULL;
290 nWidth = 1200; // 1.2cm
291 nStart = 1;
292 nStyle = BS_123;
293 nJustify = BJ_HLEFT | BJ_VCENTER;
294 cSymbol = sal_Unicode(' ');
295 nScale = 75;
298 // -----------------------------------------------------------------------
300 USHORT SvxBulletItem::GetVersion( USHORT /*nVersion*/ ) const
302 return BULITEM_VERSION;
305 // -----------------------------------------------------------------------
307 void SvxBulletItem::CopyValidProperties( const SvxBulletItem& rCopyFrom )
309 Font _aFont = GetFont();
310 Font aNewFont = rCopyFrom.GetFont();
311 if ( rCopyFrom.IsValid( VALID_FONTNAME ) )
313 _aFont.SetName( aNewFont.GetName() );
314 _aFont.SetFamily( aNewFont.GetFamily() );
315 _aFont.SetStyleName( aNewFont.GetStyleName() );
317 if ( rCopyFrom.IsValid( VALID_FONTCOLOR ) )
318 _aFont.SetColor( aNewFont.GetColor() );
319 if ( rCopyFrom.IsValid( VALID_SYMBOL ) )
320 SetSymbol( rCopyFrom.GetSymbol() );
321 if ( rCopyFrom.IsValid( VALID_BITMAP ) )
322 SetGraphicObject( rCopyFrom.GetGraphicObject() );
323 if ( rCopyFrom.IsValid( VALID_SCALE ) )
324 SetScale( rCopyFrom.GetScale() );
325 if ( rCopyFrom.IsValid( VALID_START ) )
326 SetStart( rCopyFrom.GetStart() );
327 if ( rCopyFrom.IsValid( VALID_STYLE ) )
328 SetStyle( rCopyFrom.GetStyle() );
329 if ( rCopyFrom.IsValid( VALID_PREVTEXT ) )
330 SetPrevText( rCopyFrom.GetPrevText() );
331 if ( rCopyFrom.IsValid( VALID_FOLLOWTEXT ) )
332 SetFollowText( rCopyFrom.GetFollowText() );
334 SetFont( _aFont );
338 // -----------------------------------------------------------------------
340 int SvxBulletItem::operator==( const SfxPoolItem& rItem ) const
342 DBG_ASSERT(rItem.ISA(SvxBulletItem),"operator==Types not matching");
343 const SvxBulletItem& rBullet = (const SvxBulletItem&)rItem;
344 // ValidMask mitvergleichen, da sonst kein Putten in ein AttrSet moeglich,
345 // wenn sich das Item nur in der ValidMask von einem existierenden unterscheidet.
346 if( nValidMask != rBullet.nValidMask ||
347 nStyle != rBullet.nStyle ||
348 nScale != rBullet.nScale ||
349 nJustify != rBullet.nJustify ||
350 nWidth != rBullet.nWidth ||
351 nStart != rBullet.nStart ||
352 cSymbol != rBullet.cSymbol ||
353 aPrevText != rBullet.aPrevText ||
354 aFollowText != rBullet.aFollowText )
355 return 0;
357 if( ( nStyle != BS_BMP ) && ( aFont != rBullet.aFont ) )
358 return 0;
360 if( nStyle == BS_BMP )
362 if( ( pGraphicObject && !rBullet.pGraphicObject ) || ( !pGraphicObject && rBullet.pGraphicObject ) )
363 return 0;
365 if( ( pGraphicObject && rBullet.pGraphicObject ) &&
366 ( ( *pGraphicObject != *rBullet.pGraphicObject ) ||
367 ( pGraphicObject->GetPrefSize() != rBullet.pGraphicObject->GetPrefSize() ) ) )
369 return 0;
373 return 1;
376 // -----------------------------------------------------------------------
378 SvStream& SvxBulletItem::Store( SvStream& rStrm, USHORT /*nItemVersion*/ ) const
380 // Korrektur bei leerer Bitmap
381 if( ( nStyle == BS_BMP ) &&
382 ( !pGraphicObject || ( GRAPHIC_NONE == pGraphicObject->GetType() ) || ( GRAPHIC_DEFAULT == pGraphicObject->GetType() ) ) )
384 if( pGraphicObject )
386 delete( const_cast< SvxBulletItem* >( this )->pGraphicObject );
387 const_cast< SvxBulletItem* >( this )->pGraphicObject = NULL;
390 const_cast< SvxBulletItem* >( this )->nStyle = BS_NONE;
393 rStrm << nStyle;
395 if( nStyle != BS_BMP )
396 StoreFont( rStrm, aFont );
397 else
399 ULONG _nStart = rStrm.Tell();
401 // Kleine Vorab-Schaetzung der Groesse...
402 USHORT nFac = ( rStrm.GetCompressMode() != COMPRESSMODE_NONE ) ? 3 : 1;
403 const Bitmap aBmp( pGraphicObject->GetGraphic().GetBitmap() );
404 ULONG nBytes = aBmp.GetSizeBytes();
405 if ( nBytes < ULONG(0xFF00*nFac) )
406 rStrm << aBmp;
408 ULONG nEnd = rStrm.Tell();
409 // #67581# Item darf mit Overhead nicht mehr als 64K schreiben,
410 // sonst platzt der SfxMultiRecord
411 // Dann lieber auf die Bitmap verzichten, ist nur fuer Outliner
412 // und auch nur fuer <= 5.0 wichtig.
413 // Beim Einlesen merkt der Stream-Operator der Bitmap, dass dort keine steht.
414 // Hiermit funktioniert jetzt der Fall das die grosse Bitmap aus einem anderen
415 // Fileformat entstanden ist, welches keine 64K belegt, aber wenn eine
416 // Bitmap > 64K verwendet wird, hat das SvxNumBulletItem beim Laden ein Problem,
417 // stuerzt aber nicht ab.
419 if ( (nEnd-_nStart) > 0xFF00 )
420 rStrm.Seek( _nStart );
422 rStrm << nWidth;
423 rStrm << nStart;
424 rStrm << nJustify;
425 rStrm << (char)ByteString::ConvertFromUnicode( cSymbol, aFont.GetCharSet() );
426 rStrm << nScale;
428 // UNICODE: rStrm << aPrevText;
429 rStrm.WriteByteString(aPrevText);
431 // UNICODE: rStrm << aFollowText;
432 rStrm.WriteByteString(aFollowText);
434 return rStrm;
437 //------------------------------------------------------------------------
439 XubString SvxBulletItem::GetFullText() const
441 XubString aStr( aPrevText );
442 aStr += cSymbol;
443 aStr += aFollowText;
444 return aStr;
447 //------------------------------------------------------------------------
449 SfxItemPresentation SvxBulletItem::GetPresentation
451 SfxItemPresentation ePres,
452 SfxMapUnit /*eCoreUnit*/,
453 SfxMapUnit /*ePresUnit*/,
454 XubString& rText, const IntlWrapper *
455 ) const
457 SfxItemPresentation eRet = SFX_ITEM_PRESENTATION_NONE;
458 switch ( ePres )
460 case SFX_ITEM_PRESENTATION_NONE:
461 rText.Erase();
462 eRet = SFX_ITEM_PRESENTATION_NONE;
463 break;
465 case SFX_ITEM_PRESENTATION_NAMELESS:
466 case SFX_ITEM_PRESENTATION_COMPLETE:
467 rText = GetFullText();
468 eRet = SFX_ITEM_PRESENTATION_COMPLETE;
469 break;
470 default: ; //prevent warning
472 return eRet;
475 //------------------------------------------------------------------------
477 Bitmap SvxBulletItem::GetBitmap() const
479 if( pGraphicObject )
480 return pGraphicObject->GetGraphic().GetBitmap();
481 else
483 const Bitmap aDefaultBitmap;
484 return aDefaultBitmap;
488 //------------------------------------------------------------------------
490 void SvxBulletItem::SetBitmap( const Bitmap& rBmp )
492 if( rBmp.IsEmpty() )
494 if( pGraphicObject )
496 delete pGraphicObject;
497 pGraphicObject = NULL;
500 else
502 delete pGraphicObject;
503 pGraphicObject = new GraphicObject( rBmp );
508 //------------------------------------------------------------------------
510 const GraphicObject& SvxBulletItem::GetGraphicObject() const
512 if( pGraphicObject )
513 return *pGraphicObject;
514 else
516 static const GraphicObject aDefaultObject;
517 return aDefaultObject;
521 //------------------------------------------------------------------------
523 void SvxBulletItem::SetGraphicObject( const GraphicObject& rGraphicObject )
525 if( ( GRAPHIC_NONE == rGraphicObject.GetType() ) || ( GRAPHIC_DEFAULT == rGraphicObject.GetType() ) )
527 if( pGraphicObject )
529 delete pGraphicObject;
530 pGraphicObject = NULL;
533 else
535 delete pGraphicObject;
536 pGraphicObject = new GraphicObject( rGraphicObject );