1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/stream.hxx>
21 #include <vcl/outdev.hxx>
23 #include <editeng/bulletitem.hxx>
24 #include <editeng/editrids.hrc>
26 #include <tools/tenccvt.hxx>
28 #define BULITEM_VERSION ((sal_uInt16)2)
30 // -----------------------------------------------------------------------
32 TYPEINIT1(SvxBulletItem
,SfxPoolItem
);
34 // -----------------------------------------------------------------------
36 void SvxBulletItem::StoreFont( SvStream
& rStream
, const Font
& rFont
)
40 rStream
<< rFont
.GetColor();
41 nTemp
= (sal_uInt16
)rFont
.GetFamily(); rStream
<< nTemp
;
43 nTemp
= (sal_uInt16
)GetSOStoreTextEncoding((rtl_TextEncoding
)rFont
.GetCharSet());
46 nTemp
= (sal_uInt16
)rFont
.GetPitch(); rStream
<< nTemp
;
47 nTemp
= (sal_uInt16
)rFont
.GetAlign(); rStream
<< nTemp
;
48 nTemp
= (sal_uInt16
)rFont
.GetWeight(); rStream
<< nTemp
;
49 nTemp
= (sal_uInt16
)rFont
.GetUnderline(); rStream
<< nTemp
;
50 nTemp
= (sal_uInt16
)rFont
.GetStrikeout(); rStream
<< nTemp
;
51 nTemp
= (sal_uInt16
)rFont
.GetItalic(); rStream
<< nTemp
;
53 // UNICODE: rStream << rFont.GetName();
54 rStream
.WriteUniOrByteString(rFont
.GetName(), rStream
.GetStreamCharSet());
56 rStream
<< rFont
.IsOutline();
57 rStream
<< rFont
.IsShadow();
58 rStream
<< rFont
.IsTransparent();
61 // -----------------------------------------------------------------------
63 Font
SvxBulletItem::CreateFont( SvStream
& rStream
, sal_uInt16 nVer
)
67 rStream
>> aColor
; aFont
.SetColor( aColor
);
69 rStream
>> nTemp
; aFont
.SetFamily((FontFamily
)nTemp
);
72 nTemp
= (sal_uInt16
)GetSOLoadTextEncoding((rtl_TextEncoding
)nTemp
);
73 aFont
.SetCharSet((rtl_TextEncoding
)nTemp
);
75 rStream
>> nTemp
; aFont
.SetPitch((FontPitch
)nTemp
);
76 rStream
>> nTemp
; aFont
.SetAlign((FontAlign
)nTemp
);
77 rStream
>> nTemp
; aFont
.SetWeight((FontWeight
)nTemp
);
78 rStream
>> nTemp
; aFont
.SetUnderline((FontUnderline
)nTemp
);
79 rStream
>> nTemp
; aFont
.SetStrikeout((FontStrikeout
)nTemp
);
80 rStream
>> nTemp
; aFont
.SetItalic((FontItalic
)nTemp
);
82 // UNICODE: rStream >> aName; aFont.SetName( aName );
83 String aName
= rStream
.ReadUniOrByteString(rStream
.GetStreamCharSet());
84 aFont
.SetName( aName
);
88 //#fdo39428 SvStream no longer supports operator>>(long&)
89 sal_Int32
nHeight(0), nWidth(0);
90 rStream
>> nHeight
; rStream
>> nWidth
; Size
aSize( nWidth
, nHeight
);
91 aFont
.SetSize( aSize
);
95 rStream
>> bTemp
; aFont
.SetOutline( bTemp
);
96 rStream
>> bTemp
; aFont
.SetShadow( bTemp
);
97 rStream
>> bTemp
; aFont
.SetTransparent( bTemp
);
102 // -----------------------------------------------------------------------
104 SvxBulletItem::SvxBulletItem( sal_uInt16 _nWhich
) : SfxPoolItem( _nWhich
)
106 SetDefaultFont_Impl();
111 // -----------------------------------------------------------------------
113 SvxBulletItem::SvxBulletItem( SvStream
& rStrm
, sal_uInt16 _nWhich
) :
114 SfxPoolItem( _nWhich
),
115 pGraphicObject( NULL
)
119 if( nStyle
!= BS_BMP
)
120 aFont
= CreateFont( rStrm
, BULITEM_VERSION
);
123 // Safe Load with Test on empty Bitmap
125 const sal_uInt32 nOldPos
= rStrm
.Tell();
126 // Ignore Errorcode when reading Bitmap,
127 // see comment in SvxBulletItem::Store()
128 sal_Bool bOldError
= rStrm
.GetError() ? sal_True
: sal_False
;
130 if ( !bOldError
&& rStrm
.GetError() )
137 rStrm
.Seek( nOldPos
);
141 pGraphicObject
= new GraphicObject( aBmp
);
144 //#fdo39428 SvStream no longer supports operator>>(long&)
146 rStrm
>> nTmp
; nWidth
= nTmp
;
152 //convert single byte to unicode
153 cSymbol
= OUString(&cTmpSymbol
, 1, aFont
.GetCharSet()).toChar();
157 // UNICODE: rStrm >> aPrevText;
158 aPrevText
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
160 // UNICODE: rStrm >> aFollowText;
161 aFollowText
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
166 // -----------------------------------------------------------------------
168 SvxBulletItem::SvxBulletItem( const SvxBulletItem
& rItem
) : SfxPoolItem( rItem
)
171 pGraphicObject
= ( rItem
.pGraphicObject
? new GraphicObject( *rItem
.pGraphicObject
) : NULL
);
172 aPrevText
= rItem
.aPrevText
;
173 aFollowText
= rItem
.aFollowText
;
174 nStart
= rItem
.nStart
;
175 nStyle
= rItem
.nStyle
;
176 nWidth
= rItem
.nWidth
;
177 nScale
= rItem
.nScale
;
178 cSymbol
= rItem
.cSymbol
;
179 nJustify
= rItem
.nJustify
;
180 nValidMask
= rItem
.nValidMask
;
183 // -----------------------------------------------------------------------
185 SvxBulletItem::~SvxBulletItem()
188 delete pGraphicObject
;
191 // -----------------------------------------------------------------------
193 SfxPoolItem
* SvxBulletItem::Clone( SfxItemPool
* /*pPool*/ ) const
195 return new SvxBulletItem( *this );
198 // -----------------------------------------------------------------------
200 SfxPoolItem
* SvxBulletItem::Create( SvStream
& rStrm
, sal_uInt16
/*nVersion*/ ) const
202 return new SvxBulletItem( rStrm
, Which() );
205 // -----------------------------------------------------------------------
207 void SvxBulletItem::SetDefaultFont_Impl()
209 aFont
= OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED
, LANGUAGE_SYSTEM
, 0 );
210 aFont
.SetAlign( ALIGN_BOTTOM
);
211 aFont
.SetTransparent( sal_True
);
214 // -----------------------------------------------------------------------
216 void SvxBulletItem::SetDefaults_Impl()
218 pGraphicObject
= NULL
;
219 nWidth
= 1200; // 1.2cm
222 nJustify
= BJ_HLEFT
| BJ_VCENTER
;
223 cSymbol
= sal_Unicode(' ');
227 // -----------------------------------------------------------------------
229 sal_uInt16
SvxBulletItem::GetVersion( sal_uInt16
/*nVersion*/ ) const
231 return BULITEM_VERSION
;
234 // -----------------------------------------------------------------------
236 void SvxBulletItem::CopyValidProperties( const SvxBulletItem
& rCopyFrom
)
238 Font _aFont
= GetFont();
239 Font aNewFont
= rCopyFrom
.GetFont();
240 if ( rCopyFrom
.IsValid( VALID_FONTNAME
) )
242 _aFont
.SetName( aNewFont
.GetName() );
243 _aFont
.SetFamily( aNewFont
.GetFamily() );
244 _aFont
.SetStyleName( aNewFont
.GetStyleName() );
246 if ( rCopyFrom
.IsValid( VALID_FONTCOLOR
) )
247 _aFont
.SetColor( aNewFont
.GetColor() );
248 if ( rCopyFrom
.IsValid( VALID_SYMBOL
) )
249 SetSymbol( rCopyFrom
.GetSymbol() );
250 if ( rCopyFrom
.IsValid( VALID_BITMAP
) )
251 SetGraphicObject( rCopyFrom
.GetGraphicObject() );
252 if ( rCopyFrom
.IsValid( VALID_SCALE
) )
253 SetScale( rCopyFrom
.GetScale() );
254 if ( rCopyFrom
.IsValid( VALID_START
) )
255 SetStart( rCopyFrom
.GetStart() );
256 if ( rCopyFrom
.IsValid( VALID_STYLE
) )
257 SetStyle( rCopyFrom
.GetStyle() );
258 if ( rCopyFrom
.IsValid( VALID_PREVTEXT
) )
259 SetPrevText( rCopyFrom
.GetPrevText() );
260 if ( rCopyFrom
.IsValid( VALID_FOLLOWTEXT
) )
261 SetFollowText( rCopyFrom
.GetFollowText() );
267 // -----------------------------------------------------------------------
269 int SvxBulletItem::operator==( const SfxPoolItem
& rItem
) const
271 DBG_ASSERT(rItem
.ISA(SvxBulletItem
),"operator==Types not matching");
272 const SvxBulletItem
& rBullet
= (const SvxBulletItem
&)rItem
;
273 // Compare with ValidMask, otherwise no put possible in a AttrSet if the
274 // item differs only in terms of the ValidMask from an existing one.
275 if( nValidMask
!= rBullet
.nValidMask
||
276 nStyle
!= rBullet
.nStyle
||
277 nScale
!= rBullet
.nScale
||
278 nJustify
!= rBullet
.nJustify
||
279 nWidth
!= rBullet
.nWidth
||
280 nStart
!= rBullet
.nStart
||
281 cSymbol
!= rBullet
.cSymbol
||
282 aPrevText
!= rBullet
.aPrevText
||
283 aFollowText
!= rBullet
.aFollowText
)
286 if( ( nStyle
!= BS_BMP
) && ( aFont
!= rBullet
.aFont
) )
289 if( nStyle
== BS_BMP
)
291 if( ( pGraphicObject
&& !rBullet
.pGraphicObject
) || ( !pGraphicObject
&& rBullet
.pGraphicObject
) )
294 if( ( pGraphicObject
&& rBullet
.pGraphicObject
) &&
295 ( ( *pGraphicObject
!= *rBullet
.pGraphicObject
) ||
296 ( pGraphicObject
->GetPrefSize() != rBullet
.pGraphicObject
->GetPrefSize() ) ) )
305 // -----------------------------------------------------------------------
307 SvStream
& SvxBulletItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
309 // Correction for empty bitmap
310 if( ( nStyle
== BS_BMP
) &&
311 ( !pGraphicObject
|| ( GRAPHIC_NONE
== pGraphicObject
->GetType() ) || ( GRAPHIC_DEFAULT
== pGraphicObject
->GetType() ) ) )
315 delete( const_cast< SvxBulletItem
* >( this )->pGraphicObject
);
316 const_cast< SvxBulletItem
* >( this )->pGraphicObject
= NULL
;
319 const_cast< SvxBulletItem
* >( this )->nStyle
= BS_NONE
;
324 if( nStyle
!= BS_BMP
)
325 StoreFont( rStrm
, aFont
);
328 sal_uLong _nStart
= rStrm
.Tell();
330 // Small preliminary estimate of the size ...
331 sal_uInt16 nFac
= ( rStrm
.GetCompressMode() != COMPRESSMODE_NONE
) ? 3 : 1;
332 const Bitmap
aBmp( pGraphicObject
->GetGraphic().GetBitmap() );
333 sal_uLong nBytes
= aBmp
.GetSizeBytes();
334 if ( nBytes
< sal_uLong(0xFF00*nFac
) )
337 sal_uLong nEnd
= rStrm
.Tell();
338 // Item can not write with an overhead more than 64K or SfxMultiRecord
339 // will crash. Then prefer to forego on the bitmap, it is only
340 // important for the outliner and only for <= 5.0.
341 // When reading, the stream-operator makes note of the bitmap and the
342 // fact that there is none. This is now the case how it works with
343 // large bitmap created from another file format, which do not occupy a
344 // 64K chunk, but if a bitmap > 64K is used, the SvxNumBulletItem will
345 // have problem loading it, but does not crash.
347 if ( (nEnd
-_nStart
) > 0xFF00 )
348 rStrm
.Seek( _nStart
);
350 rStrm
<< static_cast<sal_Int32
>(nWidth
);
353 rStrm
<< OUStringToOString(OUString(cSymbol
), aFont
.GetCharSet()).toChar();
356 // UNICODE: rStrm << aPrevText;
357 rStrm
.WriteUniOrByteString(aPrevText
, rStrm
.GetStreamCharSet());
359 // UNICODE: rStrm << aFollowText;
360 rStrm
.WriteUniOrByteString(aFollowText
, rStrm
.GetStreamCharSet());
365 //------------------------------------------------------------------------
367 XubString
SvxBulletItem::GetFullText() const
369 XubString
aStr( aPrevText
);
375 //------------------------------------------------------------------------
377 SfxItemPresentation
SvxBulletItem::GetPresentation
379 SfxItemPresentation ePres
,
380 SfxMapUnit
/*eCoreUnit*/,
381 SfxMapUnit
/*ePresUnit*/,
382 OUString
& rText
, const IntlWrapper
*
385 SfxItemPresentation eRet
= SFX_ITEM_PRESENTATION_NONE
;
388 case SFX_ITEM_PRESENTATION_NONE
:
390 eRet
= SFX_ITEM_PRESENTATION_NONE
;
393 case SFX_ITEM_PRESENTATION_NAMELESS
:
394 case SFX_ITEM_PRESENTATION_COMPLETE
:
395 rText
= GetFullText();
396 eRet
= SFX_ITEM_PRESENTATION_COMPLETE
;
398 default: ; //prevent warning
403 //------------------------------------------------------------------------
405 const GraphicObject
& SvxBulletItem::GetGraphicObject() const
408 return *pGraphicObject
;
411 static const GraphicObject aDefaultObject
;
412 return aDefaultObject
;
416 //------------------------------------------------------------------------
418 void SvxBulletItem::SetGraphicObject( const GraphicObject
& rGraphicObject
)
420 if( ( GRAPHIC_NONE
== rGraphicObject
.GetType() ) || ( GRAPHIC_DEFAULT
== rGraphicObject
.GetType() ) )
424 delete pGraphicObject
;
425 pGraphicObject
= NULL
;
430 delete pGraphicObject
;
431 pGraphicObject
= new GraphicObject( rGraphicObject
);
435 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */