Bump for 3.6-28
[LibreOffice.git] / editeng / source / items / bulitem.cxx
blob89913116c631efe05656573803a4c48e0390c2a6
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // include ---------------------------------------------------------------
31 #include <tools/stream.hxx>
32 #include <vcl/outdev.hxx>
34 #define _SVX_BULITEM_CXX
36 #include <editeng/bulitem.hxx>
37 #include <editeng/editrids.hrc>
39 #include <tools/tenccvt.hxx>
41 #define BULITEM_VERSION ((sal_uInt16)2)
43 // -----------------------------------------------------------------------
45 TYPEINIT1(SvxBulletItem,SfxPoolItem);
47 // -----------------------------------------------------------------------
49 void SvxBulletItem::StoreFont( SvStream& rStream, const Font& rFont )
51 sal_uInt16 nTemp;
53 rStream << rFont.GetColor();
54 nTemp = (sal_uInt16)rFont.GetFamily(); rStream << nTemp;
56 nTemp = (sal_uInt16)GetSOStoreTextEncoding((rtl_TextEncoding)rFont.GetCharSet());
57 rStream << nTemp;
59 nTemp = (sal_uInt16)rFont.GetPitch(); rStream << nTemp;
60 nTemp = (sal_uInt16)rFont.GetAlign(); rStream << nTemp;
61 nTemp = (sal_uInt16)rFont.GetWeight(); rStream << nTemp;
62 nTemp = (sal_uInt16)rFont.GetUnderline(); rStream << nTemp;
63 nTemp = (sal_uInt16)rFont.GetStrikeout(); rStream << nTemp;
64 nTemp = (sal_uInt16)rFont.GetItalic(); rStream << nTemp;
66 // UNICODE: rStream << rFont.GetName();
67 rStream.WriteUniOrByteString(rFont.GetName(), rStream.GetStreamCharSet());
69 rStream << rFont.IsOutline();
70 rStream << rFont.IsShadow();
71 rStream << rFont.IsTransparent();
74 // -----------------------------------------------------------------------
76 Font SvxBulletItem::CreateFont( SvStream& rStream, sal_uInt16 nVer )
78 Font aFont;
79 Color aColor;
80 rStream >> aColor; aFont.SetColor( aColor );
81 sal_uInt16 nTemp;
82 rStream >> nTemp; aFont.SetFamily((FontFamily)nTemp);
84 rStream >> nTemp;
85 nTemp = (sal_uInt16)GetSOLoadTextEncoding((rtl_TextEncoding)nTemp);
86 aFont.SetCharSet((rtl_TextEncoding)nTemp);
88 rStream >> nTemp; aFont.SetPitch((FontPitch)nTemp);
89 rStream >> nTemp; aFont.SetAlign((FontAlign)nTemp);
90 rStream >> nTemp; aFont.SetWeight((FontWeight)nTemp);
91 rStream >> nTemp; aFont.SetUnderline((FontUnderline)nTemp);
92 rStream >> nTemp; aFont.SetStrikeout((FontStrikeout)nTemp);
93 rStream >> nTemp; aFont.SetItalic((FontItalic)nTemp);
95 // UNICODE: rStream >> aName; aFont.SetName( aName );
96 String aName = rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
97 aFont.SetName( aName );
99 if( nVer == 1 )
101 //#fdo39428 SvStream no longer supports operator>>(long&)
102 sal_Int32 nHeight(0), nWidth(0);
103 rStream >> nHeight; rStream >> nWidth; Size aSize( nWidth, nHeight );
104 aFont.SetSize( aSize );
107 sal_Bool bTemp;
108 rStream >> bTemp; aFont.SetOutline( bTemp );
109 rStream >> bTemp; aFont.SetShadow( bTemp );
110 rStream >> bTemp; aFont.SetTransparent( bTemp );
111 return aFont;
115 // -----------------------------------------------------------------------
117 SvxBulletItem::SvxBulletItem( sal_uInt16 _nWhich ) : SfxPoolItem( _nWhich )
119 SetDefaultFont_Impl();
120 SetDefaults_Impl();
121 nValidMask = 0xFFFF;
124 // -----------------------------------------------------------------------
126 SvxBulletItem::SvxBulletItem( SvStream& rStrm, sal_uInt16 _nWhich ) :
127 SfxPoolItem( _nWhich ),
128 pGraphicObject( NULL )
130 rStrm >> nStyle;
132 if( nStyle != BS_BMP )
133 aFont = CreateFont( rStrm, BULITEM_VERSION );
134 else
136 // Safe Load with Test on empty Bitmap
137 Bitmap aBmp;
138 const sal_uInt32 nOldPos = rStrm.Tell();
139 // Ignore Errorcode when reading Bitmap,
140 // see comment in SvxBulletItem::Store()
141 sal_Bool bOldError = rStrm.GetError() ? sal_True : sal_False;
142 rStrm >> aBmp;
143 if ( !bOldError && rStrm.GetError() )
145 rStrm.ResetError();
148 if( aBmp.IsEmpty() )
150 rStrm.Seek( nOldPos );
151 nStyle = BS_NONE;
153 else
154 pGraphicObject = new GraphicObject( aBmp );
157 //#fdo39428 SvStream no longer supports operator>>(long&)
158 sal_Int32 nTmp(0);
159 rStrm >> nTmp; nWidth = nTmp;
160 rStrm >> nStart;
161 rStrm >> nJustify;
163 char cTmpSymbol;
164 rStrm >> cTmpSymbol;
165 //convert single byte to unicode
166 cSymbol = rtl::OUString(&cTmpSymbol, 1, aFont.GetCharSet()).toChar();
168 rStrm >> nScale;
170 // UNICODE: rStrm >> aPrevText;
171 aPrevText = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
173 // UNICODE: rStrm >> aFollowText;
174 aFollowText = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
176 nValidMask = 0xFFFF;
179 // -----------------------------------------------------------------------
181 SvxBulletItem::SvxBulletItem( const SvxBulletItem& rItem) : SfxPoolItem( rItem )
183 aFont = rItem.aFont;
184 pGraphicObject = ( rItem.pGraphicObject ? new GraphicObject( *rItem.pGraphicObject ) : NULL );
185 aPrevText = rItem.aPrevText;
186 aFollowText = rItem.aFollowText;
187 nStart = rItem.nStart;
188 nStyle = rItem.nStyle;
189 nWidth = rItem.nWidth;
190 nScale = rItem.nScale;
191 cSymbol = rItem.cSymbol;
192 nJustify = rItem.nJustify;
193 nValidMask = rItem.nValidMask;
196 // -----------------------------------------------------------------------
198 SvxBulletItem::~SvxBulletItem()
200 if( pGraphicObject )
201 delete pGraphicObject;
204 // -----------------------------------------------------------------------
206 SfxPoolItem* SvxBulletItem::Clone( SfxItemPool * /*pPool*/ ) const
208 return new SvxBulletItem( *this );
211 // -----------------------------------------------------------------------
213 SfxPoolItem* SvxBulletItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const
215 return new SvxBulletItem( rStrm, Which() );
218 // -----------------------------------------------------------------------
220 void SvxBulletItem::SetDefaultFont_Impl()
222 aFont = OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, LANGUAGE_SYSTEM, 0 );
223 aFont.SetAlign( ALIGN_BOTTOM);
224 aFont.SetTransparent( sal_True );
227 // -----------------------------------------------------------------------
229 void SvxBulletItem::SetDefaults_Impl()
231 pGraphicObject = NULL;
232 nWidth = 1200; // 1.2cm
233 nStart = 1;
234 nStyle = BS_123;
235 nJustify = BJ_HLEFT | BJ_VCENTER;
236 cSymbol = sal_Unicode(' ');
237 nScale = 75;
240 // -----------------------------------------------------------------------
242 sal_uInt16 SvxBulletItem::GetVersion( sal_uInt16 /*nVersion*/ ) const
244 return BULITEM_VERSION;
247 // -----------------------------------------------------------------------
249 void SvxBulletItem::CopyValidProperties( const SvxBulletItem& rCopyFrom )
251 Font _aFont = GetFont();
252 Font aNewFont = rCopyFrom.GetFont();
253 if ( rCopyFrom.IsValid( VALID_FONTNAME ) )
255 _aFont.SetName( aNewFont.GetName() );
256 _aFont.SetFamily( aNewFont.GetFamily() );
257 _aFont.SetStyleName( aNewFont.GetStyleName() );
259 if ( rCopyFrom.IsValid( VALID_FONTCOLOR ) )
260 _aFont.SetColor( aNewFont.GetColor() );
261 if ( rCopyFrom.IsValid( VALID_SYMBOL ) )
262 SetSymbol( rCopyFrom.GetSymbol() );
263 if ( rCopyFrom.IsValid( VALID_BITMAP ) )
264 SetGraphicObject( rCopyFrom.GetGraphicObject() );
265 if ( rCopyFrom.IsValid( VALID_SCALE ) )
266 SetScale( rCopyFrom.GetScale() );
267 if ( rCopyFrom.IsValid( VALID_START ) )
268 SetStart( rCopyFrom.GetStart() );
269 if ( rCopyFrom.IsValid( VALID_STYLE ) )
270 SetStyle( rCopyFrom.GetStyle() );
271 if ( rCopyFrom.IsValid( VALID_PREVTEXT ) )
272 SetPrevText( rCopyFrom.GetPrevText() );
273 if ( rCopyFrom.IsValid( VALID_FOLLOWTEXT ) )
274 SetFollowText( rCopyFrom.GetFollowText() );
276 SetFont( _aFont );
280 // -----------------------------------------------------------------------
282 int SvxBulletItem::operator==( const SfxPoolItem& rItem ) const
284 DBG_ASSERT(rItem.ISA(SvxBulletItem),"operator==Types not matching");
285 const SvxBulletItem& rBullet = (const SvxBulletItem&)rItem;
286 // Compare with ValidMask, otherwise no put possible in a AttrSet if the
287 // item differs only in terms of the ValidMask from an existing one.
288 if( nValidMask != rBullet.nValidMask ||
289 nStyle != rBullet.nStyle ||
290 nScale != rBullet.nScale ||
291 nJustify != rBullet.nJustify ||
292 nWidth != rBullet.nWidth ||
293 nStart != rBullet.nStart ||
294 cSymbol != rBullet.cSymbol ||
295 aPrevText != rBullet.aPrevText ||
296 aFollowText != rBullet.aFollowText )
297 return 0;
299 if( ( nStyle != BS_BMP ) && ( aFont != rBullet.aFont ) )
300 return 0;
302 if( nStyle == BS_BMP )
304 if( ( pGraphicObject && !rBullet.pGraphicObject ) || ( !pGraphicObject && rBullet.pGraphicObject ) )
305 return 0;
307 if( ( pGraphicObject && rBullet.pGraphicObject ) &&
308 ( ( *pGraphicObject != *rBullet.pGraphicObject ) ||
309 ( pGraphicObject->GetPrefSize() != rBullet.pGraphicObject->GetPrefSize() ) ) )
311 return 0;
315 return 1;
318 // -----------------------------------------------------------------------
320 SvStream& SvxBulletItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
322 // Correction for empty bitmap
323 if( ( nStyle == BS_BMP ) &&
324 ( !pGraphicObject || ( GRAPHIC_NONE == pGraphicObject->GetType() ) || ( GRAPHIC_DEFAULT == pGraphicObject->GetType() ) ) )
326 if( pGraphicObject )
328 delete( const_cast< SvxBulletItem* >( this )->pGraphicObject );
329 const_cast< SvxBulletItem* >( this )->pGraphicObject = NULL;
332 const_cast< SvxBulletItem* >( this )->nStyle = BS_NONE;
335 rStrm << nStyle;
337 if( nStyle != BS_BMP )
338 StoreFont( rStrm, aFont );
339 else
341 sal_uLong _nStart = rStrm.Tell();
343 // Small preliminary estimate of the size ...
344 sal_uInt16 nFac = ( rStrm.GetCompressMode() != COMPRESSMODE_NONE ) ? 3 : 1;
345 const Bitmap aBmp( pGraphicObject->GetGraphic().GetBitmap() );
346 sal_uLong nBytes = aBmp.GetSizeBytes();
347 if ( nBytes < sal_uLong(0xFF00*nFac) )
348 rStrm << aBmp;
350 sal_uLong nEnd = rStrm.Tell();
351 // Item can not write with an overhead more than 64K or SfxMultiRecord
352 // will crash. Then prefer to forego on the bitmap, it is only
353 // important for the outliner and only for <= 5.0.
354 // When reading, the stream-operator makes note of the bitmap and the
355 // fact that there is none. This is now the case how it works with
356 // large bitmap created from another file format, which do not occupy a
357 // 64K chunk, but if a bitmap > 64K is used, the SvxNumBulletItem will
358 // have problem loading it, but does not crash.
360 if ( (nEnd-_nStart) > 0xFF00 )
361 rStrm.Seek( _nStart );
363 rStrm << static_cast<sal_Int32>(nWidth);
364 rStrm << nStart;
365 rStrm << nJustify;
366 rStrm << rtl::OUStringToOString(rtl::OUString(cSymbol), aFont.GetCharSet()).toChar();
367 rStrm << nScale;
369 // UNICODE: rStrm << aPrevText;
370 rStrm.WriteUniOrByteString(aPrevText, rStrm.GetStreamCharSet());
372 // UNICODE: rStrm << aFollowText;
373 rStrm.WriteUniOrByteString(aFollowText, rStrm.GetStreamCharSet());
375 return rStrm;
378 //------------------------------------------------------------------------
380 XubString SvxBulletItem::GetFullText() const
382 XubString aStr( aPrevText );
383 aStr += cSymbol;
384 aStr += aFollowText;
385 return aStr;
388 //------------------------------------------------------------------------
390 SfxItemPresentation SvxBulletItem::GetPresentation
392 SfxItemPresentation ePres,
393 SfxMapUnit /*eCoreUnit*/,
394 SfxMapUnit /*ePresUnit*/,
395 XubString& rText, const IntlWrapper *
396 ) const
398 SfxItemPresentation eRet = SFX_ITEM_PRESENTATION_NONE;
399 switch ( ePres )
401 case SFX_ITEM_PRESENTATION_NONE:
402 rText.Erase();
403 eRet = SFX_ITEM_PRESENTATION_NONE;
404 break;
406 case SFX_ITEM_PRESENTATION_NAMELESS:
407 case SFX_ITEM_PRESENTATION_COMPLETE:
408 rText = GetFullText();
409 eRet = SFX_ITEM_PRESENTATION_COMPLETE;
410 break;
411 default: ; //prevent warning
413 return eRet;
416 //------------------------------------------------------------------------
418 const GraphicObject& SvxBulletItem::GetGraphicObject() const
420 if( pGraphicObject )
421 return *pGraphicObject;
422 else
424 static const GraphicObject aDefaultObject;
425 return aDefaultObject;
429 //------------------------------------------------------------------------
431 void SvxBulletItem::SetGraphicObject( const GraphicObject& rGraphicObject )
433 if( ( GRAPHIC_NONE == rGraphicObject.GetType() ) || ( GRAPHIC_DEFAULT == rGraphicObject.GetType() ) )
435 if( pGraphicObject )
437 delete pGraphicObject;
438 pGraphicObject = NULL;
441 else
443 delete pGraphicObject;
444 pGraphicObject = new GraphicObject( rGraphicObject );
448 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */