1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bulitem.cxx,v $
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"
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
)
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());
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
)
87 rStream
>> aColor
; aFont
.SetColor( aColor
);
89 rStream
>> nTemp
; aFont
.SetFamily((FontFamily
)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 );
105 rStream
.ReadByteString(aName
);
106 aFont
.SetName( aName
);
110 long nHeight
, nWidth
;
111 rStream
>> nHeight
; rStream
>> nWidth
; Size
aSize( nWidth
, nHeight
);
112 aFont
.SetSize( aSize
);
116 rStream
>> bTemp
; aFont
.SetOutline( bTemp
);
117 rStream
>> bTemp
; aFont
.SetShadow( bTemp
);
118 rStream
>> bTemp
; aFont
.SetTransparent( bTemp
);
123 // -----------------------------------------------------------------------
125 SvxBulletItem::SvxBulletItem( USHORT _nWhich
) : SfxPoolItem( _nWhich
)
127 SetDefaultFont_Impl();
132 // -----------------------------------------------------------------------
134 SvxBulletItem::SvxBulletItem( BYTE nNewStyle
, const Font
& rFont
, USHORT
/*nStart*/, USHORT _nWhich
) : SfxPoolItem( _nWhich
)
142 // -----------------------------------------------------------------------
144 SvxBulletItem::SvxBulletItem( const Font
& rFont
, xub_Unicode cSymb
, USHORT _nWhich
) : SfxPoolItem( _nWhich
)
153 // -----------------------------------------------------------------------
155 SvxBulletItem::SvxBulletItem( const Bitmap
& rBmp
, USHORT _nWhich
) : SfxPoolItem( _nWhich
)
159 if( !rBmp
.IsEmpty() )
161 pGraphicObject
= new GraphicObject( rBmp
);
168 // -----------------------------------------------------------------------
170 SvxBulletItem::SvxBulletItem( const GraphicObject
& rGraphicObject
, USHORT _nWhich
) : SfxPoolItem( _nWhich
)
174 if( ( GRAPHIC_NONE
!= pGraphicObject
->GetType() ) && ( GRAPHIC_DEFAULT
!= pGraphicObject
->GetType() ) )
176 pGraphicObject
= new GraphicObject( rGraphicObject
);
183 // -----------------------------------------------------------------------
185 SvxBulletItem::SvxBulletItem( SvStream
& rStrm
, USHORT _nWhich
) :
186 SfxPoolItem( _nWhich
),
187 pGraphicObject( NULL
)
191 if( nStyle
!= BS_BMP
)
192 aFont
= CreateFont( rStrm
, BULITEM_VERSION
);
195 // Sicheres Laden mit Test auf leere Bitmap
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
;
202 if ( !bOldError
&& rStrm
.GetError() )
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);
211 rStrm
.Seek( nOldPos
);
215 pGraphicObject
= new GraphicObject( aBmp
);
224 cSymbol
= ByteString::ConvertToUnicode( cTmpSymbol
, aFont
.GetCharSet() );
228 // UNICODE: rStrm >> aPrevText;
229 rStrm
.ReadByteString(aPrevText
);
231 // UNICODE: rStrm >> aFollowText;
232 rStrm
.ReadByteString(aFollowText
);
237 // -----------------------------------------------------------------------
239 SvxBulletItem::SvxBulletItem( const SvxBulletItem
& rItem
) : SfxPoolItem( rItem
)
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()
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
293 nJustify
= BJ_HLEFT
| BJ_VCENTER
;
294 cSymbol
= sal_Unicode(' ');
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() );
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
)
357 if( ( nStyle
!= BS_BMP
) && ( aFont
!= rBullet
.aFont
) )
360 if( nStyle
== BS_BMP
)
362 if( ( pGraphicObject
&& !rBullet
.pGraphicObject
) || ( !pGraphicObject
&& rBullet
.pGraphicObject
) )
365 if( ( pGraphicObject
&& rBullet
.pGraphicObject
) &&
366 ( ( *pGraphicObject
!= *rBullet
.pGraphicObject
) ||
367 ( pGraphicObject
->GetPrefSize() != rBullet
.pGraphicObject
->GetPrefSize() ) ) )
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() ) ) )
386 delete( const_cast< SvxBulletItem
* >( this )->pGraphicObject
);
387 const_cast< SvxBulletItem
* >( this )->pGraphicObject
= NULL
;
390 const_cast< SvxBulletItem
* >( this )->nStyle
= BS_NONE
;
395 if( nStyle
!= BS_BMP
)
396 StoreFont( rStrm
, aFont
);
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
) )
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
);
425 rStrm
<< (char)ByteString::ConvertFromUnicode( cSymbol
, aFont
.GetCharSet() );
428 // UNICODE: rStrm << aPrevText;
429 rStrm
.WriteByteString(aPrevText
);
431 // UNICODE: rStrm << aFollowText;
432 rStrm
.WriteByteString(aFollowText
);
437 //------------------------------------------------------------------------
439 XubString
SvxBulletItem::GetFullText() const
441 XubString
aStr( aPrevText
);
447 //------------------------------------------------------------------------
449 SfxItemPresentation
SvxBulletItem::GetPresentation
451 SfxItemPresentation ePres
,
452 SfxMapUnit
/*eCoreUnit*/,
453 SfxMapUnit
/*ePresUnit*/,
454 XubString
& rText
, const IntlWrapper
*
457 SfxItemPresentation eRet
= SFX_ITEM_PRESENTATION_NONE
;
460 case SFX_ITEM_PRESENTATION_NONE
:
462 eRet
= SFX_ITEM_PRESENTATION_NONE
;
465 case SFX_ITEM_PRESENTATION_NAMELESS
:
466 case SFX_ITEM_PRESENTATION_COMPLETE
:
467 rText
= GetFullText();
468 eRet
= SFX_ITEM_PRESENTATION_COMPLETE
;
470 default: ; //prevent warning
475 //------------------------------------------------------------------------
477 Bitmap
SvxBulletItem::GetBitmap() const
480 return pGraphicObject
->GetGraphic().GetBitmap();
483 const Bitmap aDefaultBitmap
;
484 return aDefaultBitmap
;
488 //------------------------------------------------------------------------
490 void SvxBulletItem::SetBitmap( const Bitmap
& rBmp
)
496 delete pGraphicObject
;
497 pGraphicObject
= NULL
;
502 delete pGraphicObject
;
503 pGraphicObject
= new GraphicObject( rBmp
);
508 //------------------------------------------------------------------------
510 const GraphicObject
& SvxBulletItem::GetGraphicObject() const
513 return *pGraphicObject
;
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() ) )
529 delete pGraphicObject
;
530 pGraphicObject
= NULL
;
535 delete pGraphicObject
;
536 pGraphicObject
= new GraphicObject( rGraphicObject
);