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
)
53 rStream
<< rFont
.GetColor();
54 nTemp
= (sal_uInt16
)rFont
.GetFamily(); rStream
<< nTemp
;
56 nTemp
= (sal_uInt16
)GetSOStoreTextEncoding((rtl_TextEncoding
)rFont
.GetCharSet());
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
)
80 rStream
>> aColor
; aFont
.SetColor( aColor
);
82 rStream
>> nTemp
; aFont
.SetFamily((FontFamily
)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
);
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
);
108 rStream
>> bTemp
; aFont
.SetOutline( bTemp
);
109 rStream
>> bTemp
; aFont
.SetShadow( bTemp
);
110 rStream
>> bTemp
; aFont
.SetTransparent( bTemp
);
115 // -----------------------------------------------------------------------
117 SvxBulletItem::SvxBulletItem( sal_uInt16 _nWhich
) : SfxPoolItem( _nWhich
)
119 SetDefaultFont_Impl();
124 // -----------------------------------------------------------------------
126 SvxBulletItem::SvxBulletItem( SvStream
& rStrm
, sal_uInt16 _nWhich
) :
127 SfxPoolItem( _nWhich
),
128 pGraphicObject( NULL
)
132 if( nStyle
!= BS_BMP
)
133 aFont
= CreateFont( rStrm
, BULITEM_VERSION
);
136 // Safe Load with Test on empty Bitmap
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
;
143 if ( !bOldError
&& rStrm
.GetError() )
150 rStrm
.Seek( nOldPos
);
154 pGraphicObject
= new GraphicObject( aBmp
);
157 //#fdo39428 SvStream no longer supports operator>>(long&)
159 rStrm
>> nTmp
; nWidth
= nTmp
;
165 //convert single byte to unicode
166 cSymbol
= rtl::OUString(&cTmpSymbol
, 1, aFont
.GetCharSet()).toChar();
170 // UNICODE: rStrm >> aPrevText;
171 aPrevText
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
173 // UNICODE: rStrm >> aFollowText;
174 aFollowText
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
179 // -----------------------------------------------------------------------
181 SvxBulletItem::SvxBulletItem( const SvxBulletItem
& rItem
) : SfxPoolItem( rItem
)
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()
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
235 nJustify
= BJ_HLEFT
| BJ_VCENTER
;
236 cSymbol
= sal_Unicode(' ');
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() );
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
)
299 if( ( nStyle
!= BS_BMP
) && ( aFont
!= rBullet
.aFont
) )
302 if( nStyle
== BS_BMP
)
304 if( ( pGraphicObject
&& !rBullet
.pGraphicObject
) || ( !pGraphicObject
&& rBullet
.pGraphicObject
) )
307 if( ( pGraphicObject
&& rBullet
.pGraphicObject
) &&
308 ( ( *pGraphicObject
!= *rBullet
.pGraphicObject
) ||
309 ( pGraphicObject
->GetPrefSize() != rBullet
.pGraphicObject
->GetPrefSize() ) ) )
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() ) ) )
328 delete( const_cast< SvxBulletItem
* >( this )->pGraphicObject
);
329 const_cast< SvxBulletItem
* >( this )->pGraphicObject
= NULL
;
332 const_cast< SvxBulletItem
* >( this )->nStyle
= BS_NONE
;
337 if( nStyle
!= BS_BMP
)
338 StoreFont( rStrm
, aFont
);
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
) )
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
);
366 rStrm
<< rtl::OUStringToOString(rtl::OUString(cSymbol
), aFont
.GetCharSet()).toChar();
369 // UNICODE: rStrm << aPrevText;
370 rStrm
.WriteUniOrByteString(aPrevText
, rStrm
.GetStreamCharSet());
372 // UNICODE: rStrm << aFollowText;
373 rStrm
.WriteUniOrByteString(aFollowText
, rStrm
.GetStreamCharSet());
378 //------------------------------------------------------------------------
380 XubString
SvxBulletItem::GetFullText() const
382 XubString
aStr( aPrevText
);
388 //------------------------------------------------------------------------
390 SfxItemPresentation
SvxBulletItem::GetPresentation
392 SfxItemPresentation ePres
,
393 SfxMapUnit
/*eCoreUnit*/,
394 SfxMapUnit
/*ePresUnit*/,
395 XubString
& rText
, const IntlWrapper
*
398 SfxItemPresentation eRet
= SFX_ITEM_PRESENTATION_NONE
;
401 case SFX_ITEM_PRESENTATION_NONE
:
403 eRet
= SFX_ITEM_PRESENTATION_NONE
;
406 case SFX_ITEM_PRESENTATION_NAMELESS
:
407 case SFX_ITEM_PRESENTATION_COMPLETE
:
408 rText
= GetFullText();
409 eRet
= SFX_ITEM_PRESENTATION_COMPLETE
;
411 default: ; //prevent warning
416 //------------------------------------------------------------------------
418 const GraphicObject
& SvxBulletItem::GetGraphicObject() const
421 return *pGraphicObject
;
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() ) )
437 delete pGraphicObject
;
438 pGraphicObject
= NULL
;
443 delete pGraphicObject
;
444 pGraphicObject
= new GraphicObject( rGraphicObject
);
448 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */