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