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