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 #define _SVX_BULITEM_CXX
25 #include <editeng/bulitem.hxx>
26 #include <editeng/editrids.hrc>
28 #include <tools/tenccvt.hxx>
30 #define BULITEM_VERSION ((sal_uInt16)2)
32 // -----------------------------------------------------------------------
34 TYPEINIT1(SvxBulletItem
,SfxPoolItem
);
36 // -----------------------------------------------------------------------
38 void SvxBulletItem::StoreFont( SvStream
& rStream
, const Font
& rFont
)
42 rStream
<< rFont
.GetColor();
43 nTemp
= (sal_uInt16
)rFont
.GetFamily(); rStream
<< nTemp
;
45 nTemp
= (sal_uInt16
)GetSOStoreTextEncoding((rtl_TextEncoding
)rFont
.GetCharSet());
48 nTemp
= (sal_uInt16
)rFont
.GetPitch(); rStream
<< nTemp
;
49 nTemp
= (sal_uInt16
)rFont
.GetAlign(); rStream
<< nTemp
;
50 nTemp
= (sal_uInt16
)rFont
.GetWeight(); rStream
<< nTemp
;
51 nTemp
= (sal_uInt16
)rFont
.GetUnderline(); rStream
<< nTemp
;
52 nTemp
= (sal_uInt16
)rFont
.GetStrikeout(); rStream
<< nTemp
;
53 nTemp
= (sal_uInt16
)rFont
.GetItalic(); rStream
<< nTemp
;
55 // UNICODE: rStream << rFont.GetName();
56 rStream
.WriteUniOrByteString(rFont
.GetName(), rStream
.GetStreamCharSet());
58 rStream
<< rFont
.IsOutline();
59 rStream
<< rFont
.IsShadow();
60 rStream
<< rFont
.IsTransparent();
63 // -----------------------------------------------------------------------
65 Font
SvxBulletItem::CreateFont( SvStream
& rStream
, sal_uInt16 nVer
)
69 rStream
>> aColor
; aFont
.SetColor( aColor
);
71 rStream
>> nTemp
; aFont
.SetFamily((FontFamily
)nTemp
);
74 nTemp
= (sal_uInt16
)GetSOLoadTextEncoding((rtl_TextEncoding
)nTemp
);
75 aFont
.SetCharSet((rtl_TextEncoding
)nTemp
);
77 rStream
>> nTemp
; aFont
.SetPitch((FontPitch
)nTemp
);
78 rStream
>> nTemp
; aFont
.SetAlign((FontAlign
)nTemp
);
79 rStream
>> nTemp
; aFont
.SetWeight((FontWeight
)nTemp
);
80 rStream
>> nTemp
; aFont
.SetUnderline((FontUnderline
)nTemp
);
81 rStream
>> nTemp
; aFont
.SetStrikeout((FontStrikeout
)nTemp
);
82 rStream
>> nTemp
; aFont
.SetItalic((FontItalic
)nTemp
);
84 // UNICODE: rStream >> aName; aFont.SetName( aName );
85 String aName
= rStream
.ReadUniOrByteString(rStream
.GetStreamCharSet());
86 aFont
.SetName( aName
);
90 //#fdo39428 SvStream no longer supports operator>>(long&)
91 sal_Int32
nHeight(0), nWidth(0);
92 rStream
>> nHeight
; rStream
>> nWidth
; Size
aSize( nWidth
, nHeight
);
93 aFont
.SetSize( aSize
);
97 rStream
>> bTemp
; aFont
.SetOutline( bTemp
);
98 rStream
>> bTemp
; aFont
.SetShadow( bTemp
);
99 rStream
>> bTemp
; aFont
.SetTransparent( bTemp
);
104 // -----------------------------------------------------------------------
106 SvxBulletItem::SvxBulletItem( sal_uInt16 _nWhich
) : SfxPoolItem( _nWhich
)
108 SetDefaultFont_Impl();
113 // -----------------------------------------------------------------------
115 SvxBulletItem::SvxBulletItem( SvStream
& rStrm
, sal_uInt16 _nWhich
) :
116 SfxPoolItem( _nWhich
),
117 pGraphicObject( NULL
)
121 if( nStyle
!= BS_BMP
)
122 aFont
= CreateFont( rStrm
, BULITEM_VERSION
);
125 // Safe Load with Test on empty Bitmap
127 const sal_uInt32 nOldPos
= rStrm
.Tell();
128 // Ignore Errorcode when reading Bitmap,
129 // see comment in SvxBulletItem::Store()
130 sal_Bool bOldError
= rStrm
.GetError() ? sal_True
: sal_False
;
132 if ( !bOldError
&& rStrm
.GetError() )
139 rStrm
.Seek( nOldPos
);
143 pGraphicObject
= new GraphicObject( aBmp
);
146 //#fdo39428 SvStream no longer supports operator>>(long&)
148 rStrm
>> nTmp
; nWidth
= nTmp
;
154 //convert single byte to unicode
155 cSymbol
= rtl::OUString(&cTmpSymbol
, 1, aFont
.GetCharSet()).toChar();
159 // UNICODE: rStrm >> aPrevText;
160 aPrevText
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
162 // UNICODE: rStrm >> aFollowText;
163 aFollowText
= rStrm
.ReadUniOrByteString(rStrm
.GetStreamCharSet());
168 // -----------------------------------------------------------------------
170 SvxBulletItem::SvxBulletItem( const SvxBulletItem
& rItem
) : SfxPoolItem( rItem
)
173 pGraphicObject
= ( rItem
.pGraphicObject
? new GraphicObject( *rItem
.pGraphicObject
) : NULL
);
174 aPrevText
= rItem
.aPrevText
;
175 aFollowText
= rItem
.aFollowText
;
176 nStart
= rItem
.nStart
;
177 nStyle
= rItem
.nStyle
;
178 nWidth
= rItem
.nWidth
;
179 nScale
= rItem
.nScale
;
180 cSymbol
= rItem
.cSymbol
;
181 nJustify
= rItem
.nJustify
;
182 nValidMask
= rItem
.nValidMask
;
185 // -----------------------------------------------------------------------
187 SvxBulletItem::~SvxBulletItem()
190 delete pGraphicObject
;
193 // -----------------------------------------------------------------------
195 SfxPoolItem
* SvxBulletItem::Clone( SfxItemPool
* /*pPool*/ ) const
197 return new SvxBulletItem( *this );
200 // -----------------------------------------------------------------------
202 SfxPoolItem
* SvxBulletItem::Create( SvStream
& rStrm
, sal_uInt16
/*nVersion*/ ) const
204 return new SvxBulletItem( rStrm
, Which() );
207 // -----------------------------------------------------------------------
209 void SvxBulletItem::SetDefaultFont_Impl()
211 aFont
= OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED
, LANGUAGE_SYSTEM
, 0 );
212 aFont
.SetAlign( ALIGN_BOTTOM
);
213 aFont
.SetTransparent( sal_True
);
216 // -----------------------------------------------------------------------
218 void SvxBulletItem::SetDefaults_Impl()
220 pGraphicObject
= NULL
;
221 nWidth
= 1200; // 1.2cm
224 nJustify
= BJ_HLEFT
| BJ_VCENTER
;
225 cSymbol
= sal_Unicode(' ');
229 // -----------------------------------------------------------------------
231 sal_uInt16
SvxBulletItem::GetVersion( sal_uInt16
/*nVersion*/ ) const
233 return BULITEM_VERSION
;
236 // -----------------------------------------------------------------------
238 void SvxBulletItem::CopyValidProperties( const SvxBulletItem
& rCopyFrom
)
240 Font _aFont
= GetFont();
241 Font aNewFont
= rCopyFrom
.GetFont();
242 if ( rCopyFrom
.IsValid( VALID_FONTNAME
) )
244 _aFont
.SetName( aNewFont
.GetName() );
245 _aFont
.SetFamily( aNewFont
.GetFamily() );
246 _aFont
.SetStyleName( aNewFont
.GetStyleName() );
248 if ( rCopyFrom
.IsValid( VALID_FONTCOLOR
) )
249 _aFont
.SetColor( aNewFont
.GetColor() );
250 if ( rCopyFrom
.IsValid( VALID_SYMBOL
) )
251 SetSymbol( rCopyFrom
.GetSymbol() );
252 if ( rCopyFrom
.IsValid( VALID_BITMAP
) )
253 SetGraphicObject( rCopyFrom
.GetGraphicObject() );
254 if ( rCopyFrom
.IsValid( VALID_SCALE
) )
255 SetScale( rCopyFrom
.GetScale() );
256 if ( rCopyFrom
.IsValid( VALID_START
) )
257 SetStart( rCopyFrom
.GetStart() );
258 if ( rCopyFrom
.IsValid( VALID_STYLE
) )
259 SetStyle( rCopyFrom
.GetStyle() );
260 if ( rCopyFrom
.IsValid( VALID_PREVTEXT
) )
261 SetPrevText( rCopyFrom
.GetPrevText() );
262 if ( rCopyFrom
.IsValid( VALID_FOLLOWTEXT
) )
263 SetFollowText( rCopyFrom
.GetFollowText() );
269 // -----------------------------------------------------------------------
271 int SvxBulletItem::operator==( const SfxPoolItem
& rItem
) const
273 DBG_ASSERT(rItem
.ISA(SvxBulletItem
),"operator==Types not matching");
274 const SvxBulletItem
& rBullet
= (const SvxBulletItem
&)rItem
;
275 // Compare with ValidMask, otherwise no put possible in a AttrSet if the
276 // item differs only in terms of the ValidMask from an existing one.
277 if( nValidMask
!= rBullet
.nValidMask
||
278 nStyle
!= rBullet
.nStyle
||
279 nScale
!= rBullet
.nScale
||
280 nJustify
!= rBullet
.nJustify
||
281 nWidth
!= rBullet
.nWidth
||
282 nStart
!= rBullet
.nStart
||
283 cSymbol
!= rBullet
.cSymbol
||
284 aPrevText
!= rBullet
.aPrevText
||
285 aFollowText
!= rBullet
.aFollowText
)
288 if( ( nStyle
!= BS_BMP
) && ( aFont
!= rBullet
.aFont
) )
291 if( nStyle
== BS_BMP
)
293 if( ( pGraphicObject
&& !rBullet
.pGraphicObject
) || ( !pGraphicObject
&& rBullet
.pGraphicObject
) )
296 if( ( pGraphicObject
&& rBullet
.pGraphicObject
) &&
297 ( ( *pGraphicObject
!= *rBullet
.pGraphicObject
) ||
298 ( pGraphicObject
->GetPrefSize() != rBullet
.pGraphicObject
->GetPrefSize() ) ) )
307 // -----------------------------------------------------------------------
309 SvStream
& SvxBulletItem::Store( SvStream
& rStrm
, sal_uInt16
/*nItemVersion*/ ) const
311 // Correction for empty bitmap
312 if( ( nStyle
== BS_BMP
) &&
313 ( !pGraphicObject
|| ( GRAPHIC_NONE
== pGraphicObject
->GetType() ) || ( GRAPHIC_DEFAULT
== pGraphicObject
->GetType() ) ) )
317 delete( const_cast< SvxBulletItem
* >( this )->pGraphicObject
);
318 const_cast< SvxBulletItem
* >( this )->pGraphicObject
= NULL
;
321 const_cast< SvxBulletItem
* >( this )->nStyle
= BS_NONE
;
326 if( nStyle
!= BS_BMP
)
327 StoreFont( rStrm
, aFont
);
330 sal_uLong _nStart
= rStrm
.Tell();
332 // Small preliminary estimate of the size ...
333 sal_uInt16 nFac
= ( rStrm
.GetCompressMode() != COMPRESSMODE_NONE
) ? 3 : 1;
334 const Bitmap
aBmp( pGraphicObject
->GetGraphic().GetBitmap() );
335 sal_uLong nBytes
= aBmp
.GetSizeBytes();
336 if ( nBytes
< sal_uLong(0xFF00*nFac
) )
339 sal_uLong nEnd
= rStrm
.Tell();
340 // Item can not write with an overhead more than 64K or SfxMultiRecord
341 // will crash. Then prefer to forego on the bitmap, it is only
342 // important for the outliner and only for <= 5.0.
343 // When reading, the stream-operator makes note of the bitmap and the
344 // fact that there is none. This is now the case how it works with
345 // large bitmap created from another file format, which do not occupy a
346 // 64K chunk, but if a bitmap > 64K is used, the SvxNumBulletItem will
347 // have problem loading it, but does not crash.
349 if ( (nEnd
-_nStart
) > 0xFF00 )
350 rStrm
.Seek( _nStart
);
352 rStrm
<< static_cast<sal_Int32
>(nWidth
);
355 rStrm
<< rtl::OUStringToOString(rtl::OUString(cSymbol
), aFont
.GetCharSet()).toChar();
358 // UNICODE: rStrm << aPrevText;
359 rStrm
.WriteUniOrByteString(aPrevText
, rStrm
.GetStreamCharSet());
361 // UNICODE: rStrm << aFollowText;
362 rStrm
.WriteUniOrByteString(aFollowText
, rStrm
.GetStreamCharSet());
367 //------------------------------------------------------------------------
369 XubString
SvxBulletItem::GetFullText() const
371 XubString
aStr( aPrevText
);
377 //------------------------------------------------------------------------
379 SfxItemPresentation
SvxBulletItem::GetPresentation
381 SfxItemPresentation ePres
,
382 SfxMapUnit
/*eCoreUnit*/,
383 SfxMapUnit
/*ePresUnit*/,
384 XubString
& rText
, const IntlWrapper
*
387 SfxItemPresentation eRet
= SFX_ITEM_PRESENTATION_NONE
;
390 case SFX_ITEM_PRESENTATION_NONE
:
392 eRet
= SFX_ITEM_PRESENTATION_NONE
;
395 case SFX_ITEM_PRESENTATION_NAMELESS
:
396 case SFX_ITEM_PRESENTATION_COMPLETE
:
397 rText
= GetFullText();
398 eRet
= SFX_ITEM_PRESENTATION_COMPLETE
;
400 default: ; //prevent warning
405 //------------------------------------------------------------------------
407 const GraphicObject
& SvxBulletItem::GetGraphicObject() const
410 return *pGraphicObject
;
413 static const GraphicObject aDefaultObject
;
414 return aDefaultObject
;
418 //------------------------------------------------------------------------
420 void SvxBulletItem::SetGraphicObject( const GraphicObject
& rGraphicObject
)
422 if( ( GRAPHIC_NONE
== rGraphicObject
.GetType() ) || ( GRAPHIC_DEFAULT
== rGraphicObject
.GetType() ) )
426 delete pGraphicObject
;
427 pGraphicObject
= NULL
;
432 delete pGraphicObject
;
433 pGraphicObject
= new GraphicObject( rGraphicObject
);
437 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */