Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
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.
15 : : *
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).
21 : : *
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.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <tools/stream.hxx>
30 : : #include <vcl/outdev.hxx>
31 : :
32 : : #define _SVX_BULITEM_CXX
33 : :
34 : : #include <editeng/bulitem.hxx>
35 : : #include <editeng/editrids.hrc>
36 : :
37 : : #include <tools/tenccvt.hxx>
38 : :
39 : : #define BULITEM_VERSION ((sal_uInt16)2)
40 : :
41 : : // -----------------------------------------------------------------------
42 : :
43 [ - + ][ - + ]: 102065 : TYPEINIT1(SvxBulletItem,SfxPoolItem);
44 : :
45 : : // -----------------------------------------------------------------------
46 : :
47 : 0 : void SvxBulletItem::StoreFont( SvStream& rStream, const Font& rFont )
48 : : {
49 : : sal_uInt16 nTemp;
50 : :
51 : 0 : rStream << rFont.GetColor();
52 : 0 : nTemp = (sal_uInt16)rFont.GetFamily(); rStream << nTemp;
53 : :
54 : 0 : nTemp = (sal_uInt16)GetSOStoreTextEncoding((rtl_TextEncoding)rFont.GetCharSet());
55 : 0 : rStream << nTemp;
56 : :
57 : 0 : nTemp = (sal_uInt16)rFont.GetPitch(); rStream << nTemp;
58 : 0 : nTemp = (sal_uInt16)rFont.GetAlign(); rStream << nTemp;
59 : 0 : nTemp = (sal_uInt16)rFont.GetWeight(); rStream << nTemp;
60 : 0 : nTemp = (sal_uInt16)rFont.GetUnderline(); rStream << nTemp;
61 : 0 : nTemp = (sal_uInt16)rFont.GetStrikeout(); rStream << nTemp;
62 : 0 : nTemp = (sal_uInt16)rFont.GetItalic(); rStream << nTemp;
63 : :
64 : : // UNICODE: rStream << rFont.GetName();
65 [ # # ]: 0 : rStream.WriteUniOrByteString(rFont.GetName(), rStream.GetStreamCharSet());
66 : :
67 : 0 : rStream << rFont.IsOutline();
68 : 0 : rStream << rFont.IsShadow();
69 : 0 : rStream << rFont.IsTransparent();
70 : 0 : }
71 : :
72 : : // -----------------------------------------------------------------------
73 : :
74 : 0 : Font SvxBulletItem::CreateFont( SvStream& rStream, sal_uInt16 nVer )
75 : : {
76 [ # # ]: 0 : Font aFont;
77 : 0 : Color aColor;
78 [ # # ][ # # ]: 0 : rStream >> aColor; aFont.SetColor( aColor );
79 : : sal_uInt16 nTemp;
80 [ # # ][ # # ]: 0 : rStream >> nTemp; aFont.SetFamily((FontFamily)nTemp);
81 : :
82 [ # # ]: 0 : rStream >> nTemp;
83 [ # # ]: 0 : nTemp = (sal_uInt16)GetSOLoadTextEncoding((rtl_TextEncoding)nTemp);
84 [ # # ]: 0 : aFont.SetCharSet((rtl_TextEncoding)nTemp);
85 : :
86 [ # # ][ # # ]: 0 : rStream >> nTemp; aFont.SetPitch((FontPitch)nTemp);
87 [ # # ][ # # ]: 0 : rStream >> nTemp; aFont.SetAlign((FontAlign)nTemp);
88 [ # # ][ # # ]: 0 : rStream >> nTemp; aFont.SetWeight((FontWeight)nTemp);
89 [ # # ][ # # ]: 0 : rStream >> nTemp; aFont.SetUnderline((FontUnderline)nTemp);
90 [ # # ][ # # ]: 0 : rStream >> nTemp; aFont.SetStrikeout((FontStrikeout)nTemp);
91 [ # # ][ # # ]: 0 : rStream >> nTemp; aFont.SetItalic((FontItalic)nTemp);
92 : :
93 : : // UNICODE: rStream >> aName; aFont.SetName( aName );
94 [ # # ][ # # ]: 0 : String aName = rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
95 [ # # ][ # # ]: 0 : aFont.SetName( aName );
96 : :
97 [ # # ]: 0 : if( nVer == 1 )
98 : : {
99 : : //#fdo39428 SvStream no longer supports operator>>(long&)
100 : 0 : sal_Int32 nHeight(0), nWidth(0);
101 [ # # ][ # # ]: 0 : rStream >> nHeight; rStream >> nWidth; Size aSize( nWidth, nHeight );
102 [ # # ]: 0 : aFont.SetSize( aSize );
103 : : }
104 : :
105 : : sal_Bool bTemp;
106 [ # # ][ # # ]: 0 : rStream >> bTemp; aFont.SetOutline( bTemp );
107 [ # # ][ # # ]: 0 : rStream >> bTemp; aFont.SetShadow( bTemp );
108 [ # # ][ # # ]: 0 : rStream >> bTemp; aFont.SetTransparent( bTemp );
109 [ # # ]: 0 : return aFont;
110 : : }
111 : :
112 : :
113 : : // -----------------------------------------------------------------------
114 : :
115 [ + - ][ + - ]: 472 : SvxBulletItem::SvxBulletItem( sal_uInt16 _nWhich ) : SfxPoolItem( _nWhich )
[ + - ]
116 : : {
117 [ + - ]: 472 : SetDefaultFont_Impl();
118 [ + - ]: 472 : SetDefaults_Impl();
119 : 472 : nValidMask = 0xFFFF;
120 : 472 : }
121 : :
122 : : // -----------------------------------------------------------------------
123 : :
124 : 0 : SvxBulletItem::SvxBulletItem( SvStream& rStrm, sal_uInt16 _nWhich ) :
125 : : SfxPoolItem( _nWhich ),
126 [ # # ][ # # ]: 0 : pGraphicObject( NULL )
[ # # ]
127 : : {
128 [ # # ]: 0 : rStrm >> nStyle;
129 : :
130 [ # # ]: 0 : if( nStyle != BS_BMP )
131 [ # # ][ # # ]: 0 : aFont = CreateFont( rStrm, BULITEM_VERSION );
[ # # ]
132 : : else
133 : : {
134 : : // Safe Load with Test on empty Bitmap
135 [ # # ]: 0 : Bitmap aBmp;
136 : 0 : const sal_uInt32 nOldPos = rStrm.Tell();
137 : : // Ignore Errorcode when reading Bitmap,
138 : : // see comment in SvxBulletItem::Store()
139 [ # # ]: 0 : sal_Bool bOldError = rStrm.GetError() ? sal_True : sal_False;
140 [ # # ]: 0 : rStrm >> aBmp;
141 [ # # ][ # # ]: 0 : if ( !bOldError && rStrm.GetError() )
[ # # ]
142 : : {
143 [ # # ]: 0 : rStrm.ResetError();
144 : : }
145 : :
146 [ # # ]: 0 : if( aBmp.IsEmpty() )
147 : : {
148 [ # # ]: 0 : rStrm.Seek( nOldPos );
149 : 0 : nStyle = BS_NONE;
150 : : }
151 : : else
152 [ # # ][ # # ]: 0 : pGraphicObject = new GraphicObject( aBmp );
[ # # ][ # # ]
[ # # ]
153 : : }
154 : :
155 : : //#fdo39428 SvStream no longer supports operator>>(long&)
156 : 0 : sal_Int32 nTmp(0);
157 [ # # ]: 0 : rStrm >> nTmp; nWidth = nTmp;
158 [ # # ]: 0 : rStrm >> nStart;
159 [ # # ]: 0 : rStrm >> nJustify;
160 : :
161 : : char cTmpSymbol;
162 [ # # ]: 0 : rStrm >> cTmpSymbol;
163 : : //convert single byte to unicode
164 [ # # ][ # # ]: 0 : cSymbol = rtl::OUString(&cTmpSymbol, 1, aFont.GetCharSet()).toChar();
165 : :
166 [ # # ]: 0 : rStrm >> nScale;
167 : :
168 : : // UNICODE: rStrm >> aPrevText;
169 [ # # ][ # # ]: 0 : aPrevText = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
170 : :
171 : : // UNICODE: rStrm >> aFollowText;
172 [ # # ][ # # ]: 0 : aFollowText = rStrm.ReadUniOrByteString(rStrm.GetStreamCharSet());
173 : :
174 : 0 : nValidMask = 0xFFFF;
175 : 0 : }
176 : :
177 : : // -----------------------------------------------------------------------
178 : :
179 [ + - ][ + - ]: 601 : SvxBulletItem::SvxBulletItem( const SvxBulletItem& rItem) : SfxPoolItem( rItem )
[ + - ]
180 : : {
181 [ + - ]: 601 : aFont = rItem.aFont;
182 [ - + ][ # # ]: 601 : pGraphicObject = ( rItem.pGraphicObject ? new GraphicObject( *rItem.pGraphicObject ) : NULL );
[ # # ]
183 [ + - ]: 601 : aPrevText = rItem.aPrevText;
184 [ + - ]: 601 : aFollowText = rItem.aFollowText;
185 : 601 : nStart = rItem.nStart;
186 : 601 : nStyle = rItem.nStyle;
187 : 601 : nWidth = rItem.nWidth;
188 : 601 : nScale = rItem.nScale;
189 : 601 : cSymbol = rItem.cSymbol;
190 : 601 : nJustify = rItem.nJustify;
191 : 601 : nValidMask = rItem.nValidMask;
192 : 601 : }
193 : :
194 : : // -----------------------------------------------------------------------
195 : :
196 [ + - ][ + - ]: 1061 : SvxBulletItem::~SvxBulletItem()
[ + - ]
197 : : {
198 [ - + ]: 1061 : if( pGraphicObject )
199 [ # # ][ # # ]: 0 : delete pGraphicObject;
200 [ - + ]: 1787 : }
201 : :
202 : : // -----------------------------------------------------------------------
203 : :
204 : 601 : SfxPoolItem* SvxBulletItem::Clone( SfxItemPool * /*pPool*/ ) const
205 : : {
206 [ + - ]: 601 : return new SvxBulletItem( *this );
207 : : }
208 : :
209 : : // -----------------------------------------------------------------------
210 : :
211 : 0 : SfxPoolItem* SvxBulletItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const
212 : : {
213 [ # # ]: 0 : return new SvxBulletItem( rStrm, Which() );
214 : : }
215 : :
216 : : // -----------------------------------------------------------------------
217 : :
218 : 472 : void SvxBulletItem::SetDefaultFont_Impl()
219 : : {
220 [ + - ]: 472 : aFont = OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, LANGUAGE_SYSTEM, 0 );
221 : 472 : aFont.SetAlign( ALIGN_BOTTOM);
222 : 472 : aFont.SetTransparent( sal_True );
223 : 472 : }
224 : :
225 : : // -----------------------------------------------------------------------
226 : :
227 : 472 : void SvxBulletItem::SetDefaults_Impl()
228 : : {
229 : 472 : pGraphicObject = NULL;
230 : 472 : nWidth = 1200; // 1.2cm
231 : 472 : nStart = 1;
232 : 472 : nStyle = BS_123;
233 : 472 : nJustify = BJ_HLEFT | BJ_VCENTER;
234 : 472 : cSymbol = sal_Unicode(' ');
235 : 472 : nScale = 75;
236 : 472 : }
237 : :
238 : : // -----------------------------------------------------------------------
239 : :
240 : 7116 : sal_uInt16 SvxBulletItem::GetVersion( sal_uInt16 /*nVersion*/ ) const
241 : : {
242 : 7116 : return BULITEM_VERSION;
243 : : }
244 : :
245 : : // -----------------------------------------------------------------------
246 : :
247 : 0 : void SvxBulletItem::CopyValidProperties( const SvxBulletItem& rCopyFrom )
248 : : {
249 [ # # ]: 0 : Font _aFont = GetFont();
250 [ # # ]: 0 : Font aNewFont = rCopyFrom.GetFont();
251 [ # # ]: 0 : if ( rCopyFrom.IsValid( VALID_FONTNAME ) )
252 : : {
253 [ # # ][ # # ]: 0 : _aFont.SetName( aNewFont.GetName() );
[ # # ]
254 [ # # ][ # # ]: 0 : _aFont.SetFamily( aNewFont.GetFamily() );
255 [ # # ][ # # ]: 0 : _aFont.SetStyleName( aNewFont.GetStyleName() );
256 : : }
257 [ # # ]: 0 : if ( rCopyFrom.IsValid( VALID_FONTCOLOR ) )
258 [ # # ][ # # ]: 0 : _aFont.SetColor( aNewFont.GetColor() );
259 [ # # ]: 0 : if ( rCopyFrom.IsValid( VALID_SYMBOL ) )
260 : 0 : SetSymbol( rCopyFrom.GetSymbol() );
261 [ # # ]: 0 : if ( rCopyFrom.IsValid( VALID_BITMAP ) )
262 [ # # ][ # # ]: 0 : SetGraphicObject( rCopyFrom.GetGraphicObject() );
263 [ # # ]: 0 : if ( rCopyFrom.IsValid( VALID_SCALE ) )
264 : 0 : SetScale( rCopyFrom.GetScale() );
265 [ # # ]: 0 : if ( rCopyFrom.IsValid( VALID_START ) )
266 : 0 : SetStart( rCopyFrom.GetStart() );
267 [ # # ]: 0 : if ( rCopyFrom.IsValid( VALID_STYLE ) )
268 : 0 : SetStyle( rCopyFrom.GetStyle() );
269 [ # # ]: 0 : if ( rCopyFrom.IsValid( VALID_PREVTEXT ) )
270 [ # # ][ # # ]: 0 : SetPrevText( rCopyFrom.GetPrevText() );
[ # # ]
271 [ # # ]: 0 : if ( rCopyFrom.IsValid( VALID_FOLLOWTEXT ) )
272 [ # # ][ # # ]: 0 : SetFollowText( rCopyFrom.GetFollowText() );
[ # # ]
273 : :
274 [ # # ][ # # ]: 0 : SetFont( _aFont );
[ # # ]
275 : 0 : }
276 : :
277 : :
278 : : // -----------------------------------------------------------------------
279 : :
280 : 6202 : int SvxBulletItem::operator==( const SfxPoolItem& rItem ) const
281 : : {
282 : : DBG_ASSERT(rItem.ISA(SvxBulletItem),"operator==Types not matching");
283 : 6202 : const SvxBulletItem& rBullet = (const SvxBulletItem&)rItem;
284 : : // Compare with ValidMask, otherwise no put possible in a AttrSet if the
285 : : // item differs only in terms of the ValidMask from an existing one.
286 [ + - ][ + - ]: 18606 : if( nValidMask != rBullet.nValidMask ||
[ + - ][ + - ]
[ + - ][ + - ]
[ + - + -
- + ][ - + ]
287 : : nStyle != rBullet.nStyle ||
288 : : nScale != rBullet.nScale ||
289 : : nJustify != rBullet.nJustify ||
290 : : nWidth != rBullet.nWidth ||
291 : : nStart != rBullet.nStart ||
292 : : cSymbol != rBullet.cSymbol ||
293 : 6202 : aPrevText != rBullet.aPrevText ||
294 : 6202 : aFollowText != rBullet.aFollowText )
295 : 0 : return 0;
296 : :
297 [ + - ][ + + ]: 6202 : if( ( nStyle != BS_BMP ) && ( aFont != rBullet.aFont ) )
[ + + ]
298 : 2618 : return 0;
299 : :
300 [ - + ]: 3584 : if( nStyle == BS_BMP )
301 : : {
302 [ # # ][ # # ]: 0 : if( ( pGraphicObject && !rBullet.pGraphicObject ) || ( !pGraphicObject && rBullet.pGraphicObject ) )
[ # # ][ # # ]
303 : 0 : return 0;
304 : :
305 [ # # ][ # # : 0 : if( ( pGraphicObject && rBullet.pGraphicObject ) &&
# # # # ]
[ # # ]
306 : 0 : ( ( *pGraphicObject != *rBullet.pGraphicObject ) ||
307 : 0 : ( pGraphicObject->GetPrefSize() != rBullet.pGraphicObject->GetPrefSize() ) ) )
308 : : {
309 : 0 : return 0;
310 : : }
311 : : }
312 : :
313 : 6202 : return 1;
314 : : }
315 : :
316 : : // -----------------------------------------------------------------------
317 : :
318 : 0 : SvStream& SvxBulletItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
319 : : {
320 : : // Correction for empty bitmap
321 [ # # ][ # # : 0 : if( ( nStyle == BS_BMP ) &&
# # # # ]
[ # # ]
322 : 0 : ( !pGraphicObject || ( GRAPHIC_NONE == pGraphicObject->GetType() ) || ( GRAPHIC_DEFAULT == pGraphicObject->GetType() ) ) )
323 : : {
324 [ # # ]: 0 : if( pGraphicObject )
325 : : {
326 [ # # ]: 0 : delete( const_cast< SvxBulletItem* >( this )->pGraphicObject );
327 : 0 : const_cast< SvxBulletItem* >( this )->pGraphicObject = NULL;
328 : : }
329 : :
330 : 0 : const_cast< SvxBulletItem* >( this )->nStyle = BS_NONE;
331 : : }
332 : :
333 : 0 : rStrm << nStyle;
334 : :
335 [ # # ]: 0 : if( nStyle != BS_BMP )
336 : 0 : StoreFont( rStrm, aFont );
337 : : else
338 : : {
339 : 0 : sal_uLong _nStart = rStrm.Tell();
340 : :
341 : : // Small preliminary estimate of the size ...
342 [ # # ]: 0 : sal_uInt16 nFac = ( rStrm.GetCompressMode() != COMPRESSMODE_NONE ) ? 3 : 1;
343 [ # # ][ # # ]: 0 : const Bitmap aBmp( pGraphicObject->GetGraphic().GetBitmap() );
344 [ # # ]: 0 : sal_uLong nBytes = aBmp.GetSizeBytes();
345 [ # # ]: 0 : if ( nBytes < sal_uLong(0xFF00*nFac) )
346 [ # # ]: 0 : rStrm << aBmp;
347 : :
348 : 0 : sal_uLong nEnd = rStrm.Tell();
349 : : // Item can not write with an overhead more than 64K or SfxMultiRecord
350 : : // will crash. Then prefer to forego on the bitmap, it is only
351 : : // important for the outliner and only for <= 5.0.
352 : : // When reading, the stream-operator makes note of the bitmap and the
353 : : // fact that there is none. This is now the case how it works with
354 : : // large bitmap created from another file format, which do not occupy a
355 : : // 64K chunk, but if a bitmap > 64K is used, the SvxNumBulletItem will
356 : : // have problem loading it, but does not crash.
357 : :
358 [ # # ]: 0 : if ( (nEnd-_nStart) > 0xFF00 )
359 [ # # ][ # # ]: 0 : rStrm.Seek( _nStart );
360 : : }
361 : 0 : rStrm << static_cast<sal_Int32>(nWidth);
362 : 0 : rStrm << nStart;
363 : 0 : rStrm << nJustify;
364 [ # # ][ # # ]: 0 : rStrm << rtl::OUStringToOString(rtl::OUString(cSymbol), aFont.GetCharSet()).toChar();
365 : 0 : rStrm << nScale;
366 : :
367 : : // UNICODE: rStrm << aPrevText;
368 [ # # ]: 0 : rStrm.WriteUniOrByteString(aPrevText, rStrm.GetStreamCharSet());
369 : :
370 : : // UNICODE: rStrm << aFollowText;
371 [ # # ]: 0 : rStrm.WriteUniOrByteString(aFollowText, rStrm.GetStreamCharSet());
372 : :
373 : 0 : return rStrm;
374 : : }
375 : :
376 : : //------------------------------------------------------------------------
377 : :
378 : 0 : XubString SvxBulletItem::GetFullText() const
379 : : {
380 : 0 : XubString aStr( aPrevText );
381 [ # # ]: 0 : aStr += cSymbol;
382 [ # # ]: 0 : aStr += aFollowText;
383 : 0 : return aStr;
384 : : }
385 : :
386 : : //------------------------------------------------------------------------
387 : :
388 : 0 : SfxItemPresentation SvxBulletItem::GetPresentation
389 : : (
390 : : SfxItemPresentation ePres,
391 : : SfxMapUnit /*eCoreUnit*/,
392 : : SfxMapUnit /*ePresUnit*/,
393 : : XubString& rText, const IntlWrapper *
394 : : ) const
395 : : {
396 : 0 : SfxItemPresentation eRet = SFX_ITEM_PRESENTATION_NONE;
397 [ # # # ]: 0 : switch ( ePres )
398 : : {
399 : : case SFX_ITEM_PRESENTATION_NONE:
400 : 0 : rText.Erase();
401 : 0 : eRet = SFX_ITEM_PRESENTATION_NONE;
402 : 0 : break;
403 : :
404 : : case SFX_ITEM_PRESENTATION_NAMELESS:
405 : : case SFX_ITEM_PRESENTATION_COMPLETE:
406 [ # # ]: 0 : rText = GetFullText();
407 : 0 : eRet = SFX_ITEM_PRESENTATION_COMPLETE;
408 : 0 : break;
409 : : default: ; //prevent warning
410 : : }
411 : 0 : return eRet;
412 : : }
413 : :
414 : : //------------------------------------------------------------------------
415 : :
416 : 0 : const GraphicObject& SvxBulletItem::GetGraphicObject() const
417 : : {
418 [ # # ]: 0 : if( pGraphicObject )
419 : 0 : return *pGraphicObject;
420 : : else
421 : : {
422 [ # # ][ # # ]: 0 : static const GraphicObject aDefaultObject;
[ # # ][ # # ]
423 : 0 : return aDefaultObject;
424 : : }
425 : : }
426 : :
427 : : //------------------------------------------------------------------------
428 : :
429 : 0 : void SvxBulletItem::SetGraphicObject( const GraphicObject& rGraphicObject )
430 : : {
431 [ # # ][ # # ]: 0 : if( ( GRAPHIC_NONE == rGraphicObject.GetType() ) || ( GRAPHIC_DEFAULT == rGraphicObject.GetType() ) )
[ # # ]
432 : : {
433 [ # # ]: 0 : if( pGraphicObject )
434 : : {
435 [ # # ]: 0 : delete pGraphicObject;
436 : 0 : pGraphicObject = NULL;
437 : : }
438 : : }
439 : : else
440 : : {
441 [ # # ]: 0 : delete pGraphicObject;
442 [ # # ]: 0 : pGraphicObject = new GraphicObject( rGraphicObject );
443 : : }
444 : 0 : }
445 : :
446 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|