xref: /AOO41X/main/editeng/source/items/bulitem.cxx (revision 47148b3bc50811ceb41802e4cc50a5db21535900)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_editeng.hxx"
24 
25 #include <tools/stream.hxx>
26 #include <vcl/outdev.hxx>
27 #define _SVX_BULITEM_CXX
28 #include <editeng/bulitem.hxx>
29 #include <editeng/editrids.hrc>
30 #include <tools/tenccvt.hxx>
31 #include <vcl/dibtools.hxx>
32 
33 #define BULITEM_VERSION     ((sal_uInt16)2)
34 
35 // -----------------------------------------------------------------------
36 
37 TYPEINIT1(SvxBulletItem,SfxPoolItem);
38 
39 // -----------------------------------------------------------------------
40 
StoreFont(SvStream & rStream,const Font & rFont)41 void SvxBulletItem::StoreFont( SvStream& rStream, const Font& rFont )
42 {
43     sal_uInt16 nTemp;
44 
45     rStream << rFont.GetColor();
46     nTemp = (sal_uInt16)rFont.GetFamily(); rStream << nTemp;
47 
48     // #90477# nTemp = (sal_uInt16)GetStoreCharSet( rFont.GetCharSet(), rStream.GetVersion() );
49     nTemp = (sal_uInt16)GetSOStoreTextEncoding((rtl_TextEncoding)rFont.GetCharSet(), (sal_uInt16)rStream.GetVersion());
50     rStream << nTemp;
51 
52     nTemp = (sal_uInt16)rFont.GetPitch(); rStream << nTemp;
53     nTemp = (sal_uInt16)rFont.GetAlign(); rStream << nTemp;
54     nTemp = (sal_uInt16)rFont.GetWeight(); rStream << nTemp;
55     nTemp = (sal_uInt16)rFont.GetUnderline(); rStream << nTemp;
56     nTemp = (sal_uInt16)rFont.GetStrikeout(); rStream << nTemp;
57     nTemp = (sal_uInt16)rFont.GetItalic(); rStream << nTemp;
58 
59     // UNICODE: rStream << rFont.GetName();
60     rStream.WriteByteString(rFont.GetName());
61 
62     rStream << rFont.IsOutline();
63     rStream << rFont.IsShadow();
64     rStream << rFont.IsTransparent();
65 }
66 
67 // -----------------------------------------------------------------------
68 
CreateFont(SvStream & rStream,sal_uInt16 nVer)69 Font SvxBulletItem::CreateFont( SvStream& rStream, sal_uInt16 nVer )
70 {
71     Font aFont;
72     Color aColor;
73     rStream >> aColor;    aFont.SetColor( aColor );
74     sal_uInt16 nTemp;
75     rStream >> nTemp; aFont.SetFamily((FontFamily)nTemp);
76 
77     // #90477#
78     rStream >> nTemp;
79     nTemp = (sal_uInt16)GetSOLoadTextEncoding((rtl_TextEncoding)nTemp, (sal_uInt16)rStream.GetVersion());
80     aFont.SetCharSet((rtl_TextEncoding)nTemp);
81 
82     rStream >> nTemp; aFont.SetPitch((FontPitch)nTemp);
83     rStream >> nTemp; aFont.SetAlign((FontAlign)nTemp);
84     rStream >> nTemp; aFont.SetWeight((FontWeight)nTemp);
85     rStream >> nTemp; aFont.SetUnderline((FontUnderline)nTemp);
86     rStream >> nTemp; aFont.SetStrikeout((FontStrikeout)nTemp);
87     rStream >> nTemp; aFont.SetItalic((FontItalic)nTemp);
88 
89     // UNICODE: rStream >> aName; aFont.SetName( aName );
90     String aName;
91     rStream.ReadByteString(aName);
92     aFont.SetName( aName );
93 
94     if( nVer == 1 )
95     {
96         long nHeight, nWidth;
97         rStream >> nHeight; rStream >> nWidth; Size aSize( nWidth, nHeight );
98         aFont.SetSize( aSize );
99     }
100 
101     sal_Bool bTemp;
102     rStream >> bTemp; aFont.SetOutline( bTemp );
103     rStream >> bTemp; aFont.SetShadow( bTemp );
104     rStream >> bTemp; aFont.SetTransparent( bTemp );
105     return aFont;
106 }
107 
108 
109 // -----------------------------------------------------------------------
110 
SvxBulletItem(sal_uInt16 _nWhich)111 SvxBulletItem::SvxBulletItem( sal_uInt16 _nWhich ) : SfxPoolItem( _nWhich )
112 {
113     SetDefaultFont_Impl();
114     SetDefaults_Impl();
115     nValidMask = 0xFFFF;
116 }
117 
118 // -----------------------------------------------------------------------
119 
SvxBulletItem(sal_uInt8 nNewStyle,const Font & rFont,sal_uInt16,sal_uInt16 _nWhich)120 SvxBulletItem::SvxBulletItem( sal_uInt8 nNewStyle, const Font& rFont, sal_uInt16 /*nStart*/, sal_uInt16 _nWhich ) : SfxPoolItem( _nWhich )
121 {
122     SetDefaults_Impl();
123     nStyle = nNewStyle;
124     aFont  = rFont;
125     nValidMask = 0xFFFF;
126 }
127 
128 // -----------------------------------------------------------------------
129 
SvxBulletItem(const Font & rFont,xub_Unicode cSymb,sal_uInt16 _nWhich)130 SvxBulletItem::SvxBulletItem( const Font& rFont, xub_Unicode cSymb, sal_uInt16 _nWhich ) : SfxPoolItem( _nWhich )
131 {
132     SetDefaults_Impl();
133     aFont   = rFont;
134     cSymbol = cSymb;
135     nStyle  = BS_BULLET;
136     nValidMask = 0xFFFF;
137 }
138 
139 // -----------------------------------------------------------------------
140 
SvxBulletItem(const Bitmap & rBmp,sal_uInt16 _nWhich)141 SvxBulletItem::SvxBulletItem( const Bitmap& rBmp, sal_uInt16 _nWhich ) : SfxPoolItem( _nWhich )
142 {
143     SetDefaults_Impl();
144 
145     if( !rBmp.IsEmpty() )
146     {
147         pGraphicObject = new GraphicObject( rBmp );
148         nStyle = BS_BMP;
149     }
150 
151     nValidMask = 0xFFFF;
152 }
153 
154 // -----------------------------------------------------------------------
155 
SvxBulletItem(const GraphicObject & rGraphicObject,sal_uInt16 _nWhich)156 SvxBulletItem::SvxBulletItem( const GraphicObject& rGraphicObject, sal_uInt16 _nWhich ) : SfxPoolItem( _nWhich )
157 {
158     SetDefaults_Impl();
159 
160     if( ( GRAPHIC_NONE != pGraphicObject->GetType() ) && ( GRAPHIC_DEFAULT != pGraphicObject->GetType() ) )
161     {
162         pGraphicObject = new GraphicObject( rGraphicObject );
163         nStyle = BS_BMP;
164     }
165 
166     nValidMask = 0xFFFF;
167 }
168 
169 // -----------------------------------------------------------------------
170 
SvxBulletItem(SvStream & rStrm,sal_uInt16 _nWhich)171 SvxBulletItem::SvxBulletItem( SvStream& rStrm, sal_uInt16 _nWhich ) :
172     SfxPoolItem( _nWhich ),
173     pGraphicObject( NULL )
174 {
175     rStrm >> nStyle;
176 
177     if( nStyle != BS_BMP )
178         aFont = CreateFont( rStrm, BULITEM_VERSION );
179     else
180     {
181         // Sicheres Laden mit Test auf leere Bitmap
182         Bitmap          aBmp;
183         const sal_uInt32    nOldPos = rStrm.Tell();
184         // #69345# Errorcode beim Bitmap lesen ignorieren,
185         // siehe Kommentar #67581# in SvxBulletItem::Store()
186         sal_Bool bOldError = rStrm.GetError() ? sal_True : sal_False;
187         ReadDIB(aBmp, rStrm, true);
188 
189         if ( !bOldError && rStrm.GetError() )
190         {
191             rStrm.ResetError();
192             // #71493# Keine Warnung: Das BulletItem interessiert seit 5.0 im Dateiformat nicht mehr.
193             // rStrm.SetError(ERRCODE_CLASS_READ | ERRCODE_SVX_BULLETITEM_NOBULLET | ERRCODE_WARNING_MASK);
194         }
195 
196         if( aBmp.IsEmpty() )
197         {
198             rStrm.Seek( nOldPos );
199             nStyle = BS_NONE;
200         }
201         else
202             pGraphicObject = new GraphicObject( aBmp );
203     }
204 
205     rStrm >> nWidth;
206     rStrm >> nStart;
207     rStrm >> nJustify;
208 
209     char cTmpSymbol;
210     rStrm >> cTmpSymbol;
211     cSymbol = ByteString::ConvertToUnicode( cTmpSymbol, aFont.GetCharSet() );
212 
213     rStrm >> nScale;
214 
215     // UNICODE: rStrm >> aPrevText;
216     rStrm.ReadByteString(aPrevText);
217 
218     // UNICODE: rStrm >> aFollowText;
219     rStrm.ReadByteString(aFollowText);
220 
221     nValidMask = 0xFFFF;
222 }
223 
224 // -----------------------------------------------------------------------
225 
SvxBulletItem(const SvxBulletItem & rItem)226 SvxBulletItem::SvxBulletItem( const SvxBulletItem& rItem) : SfxPoolItem( rItem )
227 {
228     aFont           = rItem.aFont;
229     pGraphicObject  = ( rItem.pGraphicObject ? new GraphicObject( *rItem.pGraphicObject ) : NULL );
230     aPrevText       = rItem.aPrevText;
231     aFollowText     = rItem.aFollowText;
232     nStart          = rItem.nStart;
233     nStyle          = rItem.nStyle;
234     nWidth          = rItem.nWidth;
235     nScale          = rItem.nScale;
236     cSymbol         = rItem.cSymbol;
237     nJustify        = rItem.nJustify;
238     nValidMask      = rItem.nValidMask;
239 }
240 
241 // -----------------------------------------------------------------------
242 
~SvxBulletItem()243 SvxBulletItem::~SvxBulletItem()
244 {
245     if( pGraphicObject )
246         delete pGraphicObject;
247 }
248 
249 // -----------------------------------------------------------------------
250 
Clone(SfxItemPool *) const251 SfxPoolItem* SvxBulletItem::Clone( SfxItemPool * /*pPool*/ ) const
252 {
253     return new SvxBulletItem( *this );
254 }
255 
256 // -----------------------------------------------------------------------
257 
Create(SvStream & rStrm,sal_uInt16) const258 SfxPoolItem* SvxBulletItem::Create( SvStream& rStrm, sal_uInt16 /*nVersion*/ ) const
259 {
260     return new SvxBulletItem( rStrm, Which() );
261 }
262 
263 // -----------------------------------------------------------------------
264 
SetDefaultFont_Impl()265 void SvxBulletItem::SetDefaultFont_Impl()
266 {
267     aFont = OutputDevice::GetDefaultFont( DEFAULTFONT_FIXED, LANGUAGE_SYSTEM, 0 );
268     aFont.SetAlign( ALIGN_BOTTOM);
269     aFont.SetTransparent( sal_True );
270 }
271 
272 // -----------------------------------------------------------------------
273 
SetDefaults_Impl()274 void SvxBulletItem::SetDefaults_Impl()
275 {
276     pGraphicObject  = NULL;
277     nWidth          = 1200;  // 1.2cm
278     nStart          = 1;
279     nStyle          = BS_123;
280     nJustify        = BJ_HLEFT | BJ_VCENTER;
281     cSymbol         = sal_Unicode(' ');
282     nScale          = 75;
283 }
284 
285 // -----------------------------------------------------------------------
286 
GetVersion(sal_uInt16) const287 sal_uInt16 SvxBulletItem::GetVersion( sal_uInt16 /*nVersion*/ ) const
288 {
289     return BULITEM_VERSION;
290 }
291 
292 // -----------------------------------------------------------------------
293 
CopyValidProperties(const SvxBulletItem & rCopyFrom)294 void SvxBulletItem::CopyValidProperties( const SvxBulletItem& rCopyFrom )
295 {
296     Font _aFont = GetFont();
297     Font aNewFont = rCopyFrom.GetFont();
298     if ( rCopyFrom.IsValid( VALID_FONTNAME ) )
299     {
300         _aFont.SetName( aNewFont.GetName() );
301         _aFont.SetFamily( aNewFont.GetFamily() );
302         _aFont.SetStyleName( aNewFont.GetStyleName() );
303     }
304     if ( rCopyFrom.IsValid( VALID_FONTCOLOR ) )
305         _aFont.SetColor( aNewFont.GetColor() );
306     if ( rCopyFrom.IsValid( VALID_SYMBOL ) )
307         SetSymbol( rCopyFrom.GetSymbol() );
308     if ( rCopyFrom.IsValid( VALID_BITMAP ) )
309         SetGraphicObject( rCopyFrom.GetGraphicObject() );
310     if ( rCopyFrom.IsValid( VALID_SCALE ) )
311         SetScale( rCopyFrom.GetScale() );
312     if ( rCopyFrom.IsValid( VALID_START ) )
313         SetStart( rCopyFrom.GetStart() );
314     if ( rCopyFrom.IsValid( VALID_STYLE ) )
315         SetStyle( rCopyFrom.GetStyle() );
316     if ( rCopyFrom.IsValid( VALID_PREVTEXT ) )
317         SetPrevText( rCopyFrom.GetPrevText() );
318     if ( rCopyFrom.IsValid( VALID_FOLLOWTEXT ) )
319         SetFollowText( rCopyFrom.GetFollowText() );
320 
321     SetFont( _aFont );
322 }
323 
324 
325 // -----------------------------------------------------------------------
326 
operator ==(const SfxPoolItem & rItem) const327 int SvxBulletItem::operator==( const SfxPoolItem& rItem ) const
328 {
329     DBG_ASSERT(rItem.ISA(SvxBulletItem),"operator==Types not matching");
330     const SvxBulletItem& rBullet = (const SvxBulletItem&)rItem;
331     // ValidMask mitvergleichen, da sonst kein Putten in ein AttrSet moeglich,
332     // wenn sich das Item nur in der ValidMask von einem existierenden unterscheidet.
333     if( nValidMask != rBullet.nValidMask    ||
334         nStyle != rBullet.nStyle            ||
335         nScale != rBullet.nScale            ||
336         nJustify != rBullet.nJustify        ||
337         nWidth != rBullet.nWidth            ||
338         nStart != rBullet.nStart            ||
339         cSymbol != rBullet.cSymbol          ||
340         aPrevText != rBullet.aPrevText      ||
341         aFollowText != rBullet.aFollowText )
342             return 0;
343 
344     if( ( nStyle != BS_BMP ) && ( aFont != rBullet.aFont ) )
345         return 0;
346 
347     if( nStyle == BS_BMP )
348     {
349         if( ( pGraphicObject && !rBullet.pGraphicObject ) || ( !pGraphicObject && rBullet.pGraphicObject ) )
350             return 0;
351 
352         if( ( pGraphicObject && rBullet.pGraphicObject ) &&
353             ( ( *pGraphicObject != *rBullet.pGraphicObject ) ||
354               ( pGraphicObject->GetPrefSize() != rBullet.pGraphicObject->GetPrefSize() ) ) )
355         {
356             return 0;
357         }
358     }
359 
360     return 1;
361 }
362 
363 // -----------------------------------------------------------------------
364 
Store(SvStream & rStrm,sal_uInt16) const365 SvStream& SvxBulletItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const
366 {
367     // Korrektur bei leerer Bitmap
368     if( ( nStyle == BS_BMP ) &&
369         ( !pGraphicObject || ( GRAPHIC_NONE == pGraphicObject->GetType() ) || ( GRAPHIC_DEFAULT == pGraphicObject->GetType() ) ) )
370     {
371         if( pGraphicObject )
372         {
373             delete( const_cast< SvxBulletItem* >( this )->pGraphicObject );
374             const_cast< SvxBulletItem* >( this )->pGraphicObject = NULL;
375         }
376 
377         const_cast< SvxBulletItem* >( this )->nStyle = BS_NONE;
378     }
379 
380     rStrm << nStyle;
381 
382     if( nStyle != BS_BMP )
383         StoreFont( rStrm, aFont );
384     else
385     {
386         sal_uLong _nStart = rStrm.Tell();
387 
388         // Kleine Vorab-Schaetzung der Groesse...
389         sal_uInt16 nFac = ( rStrm.GetCompressMode() != COMPRESSMODE_NONE ) ? 3 : 1;
390         const Bitmap aBmp( pGraphicObject->GetGraphic().GetBitmap() );
391         sal_uLong nBytes = aBmp.GetSizeBytes();
392         if ( nBytes < sal_uLong(0xFF00*nFac) )
393         {
394             WriteDIB(aBmp, rStrm, false, true);
395         }
396 
397         sal_uLong nEnd = rStrm.Tell();
398         // #67581# Item darf mit Overhead nicht mehr als 64K schreiben,
399         // sonst platzt der SfxMultiRecord
400         // Dann lieber auf die Bitmap verzichten, ist nur fuer Outliner
401         // und auch nur fuer <= 5.0 wichtig.
402         // Beim Einlesen merkt der Stream-Operator der Bitmap, dass dort keine steht.
403         // Hiermit funktioniert jetzt der Fall das die grosse Bitmap aus einem anderen
404         // Fileformat entstanden ist, welches keine 64K belegt, aber wenn eine
405         // Bitmap > 64K verwendet wird, hat das SvxNumBulletItem beim Laden ein Problem,
406         // stuerzt aber nicht ab.
407 
408         if ( (nEnd-_nStart) > 0xFF00 )
409             rStrm.Seek( _nStart );
410     }
411     rStrm << nWidth;
412     rStrm << nStart;
413     rStrm << nJustify;
414     rStrm << (char)ByteString::ConvertFromUnicode( cSymbol, aFont.GetCharSet() );
415     rStrm << nScale;
416 
417     // UNICODE: rStrm << aPrevText;
418     rStrm.WriteByteString(aPrevText);
419 
420     // UNICODE: rStrm << aFollowText;
421     rStrm.WriteByteString(aFollowText);
422 
423     return rStrm;
424 }
425 
426 //------------------------------------------------------------------------
427 
GetFullText() const428 XubString SvxBulletItem::GetFullText() const
429 {
430     XubString aStr( aPrevText );
431     aStr += cSymbol;
432     aStr += aFollowText;
433     return aStr;
434 }
435 
436 //------------------------------------------------------------------------
437 
GetPresentation(SfxItemPresentation ePres,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const438 SfxItemPresentation SvxBulletItem::GetPresentation
439 (
440     SfxItemPresentation ePres,
441     SfxMapUnit          /*eCoreUnit*/,
442     SfxMapUnit          /*ePresUnit*/,
443     XubString&          rText, const IntlWrapper *
444 )   const
445 {
446     SfxItemPresentation eRet = SFX_ITEM_PRESENTATION_NONE;
447     switch ( ePres )
448     {
449         case SFX_ITEM_PRESENTATION_NONE:
450             rText.Erase();
451             eRet = SFX_ITEM_PRESENTATION_NONE;
452             break;
453 
454         case SFX_ITEM_PRESENTATION_NAMELESS:
455         case SFX_ITEM_PRESENTATION_COMPLETE:
456             rText = GetFullText();
457             eRet = SFX_ITEM_PRESENTATION_COMPLETE;
458             break;
459         default: ; //prevent warning
460     }
461     return eRet;
462 }
463 
464 //------------------------------------------------------------------------
465 
GetBitmap() const466 Bitmap SvxBulletItem::GetBitmap() const
467 {
468     if( pGraphicObject )
469         return pGraphicObject->GetGraphic().GetBitmap();
470     else
471     {
472         const Bitmap aDefaultBitmap;
473         return aDefaultBitmap;
474     }
475 }
476 
477 //------------------------------------------------------------------------
478 
SetBitmap(const Bitmap & rBmp)479 void SvxBulletItem::SetBitmap( const Bitmap& rBmp )
480 {
481     if( rBmp.IsEmpty() )
482     {
483         if( pGraphicObject )
484         {
485             delete pGraphicObject;
486             pGraphicObject = NULL;
487         }
488     }
489     else
490     {
491         delete pGraphicObject;
492         pGraphicObject = new GraphicObject( rBmp );
493 
494     }
495 }
496 
497 //------------------------------------------------------------------------
498 
GetGraphicObject() const499 const GraphicObject& SvxBulletItem::GetGraphicObject() const
500 {
501     if( pGraphicObject )
502         return *pGraphicObject;
503     else
504     {
505         static const GraphicObject aDefaultObject;
506         return aDefaultObject;
507     }
508 }
509 
510 //------------------------------------------------------------------------
511 
SetGraphicObject(const GraphicObject & rGraphicObject)512 void SvxBulletItem::SetGraphicObject( const GraphicObject& rGraphicObject )
513 {
514     if( ( GRAPHIC_NONE == rGraphicObject.GetType() ) || ( GRAPHIC_DEFAULT == rGraphicObject.GetType() ) )
515     {
516         if( pGraphicObject )
517         {
518             delete pGraphicObject;
519             pGraphicObject = NULL;
520         }
521     }
522     else
523     {
524         delete pGraphicObject;
525         pGraphicObject = new GraphicObject( rGraphicObject );
526     }
527 }
528