LCOV - code coverage report
Current view: top level - libreoffice/editeng/source/items - bulitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 49 205 23.9 %
Date: 2012-12-27 Functions: 13 24 54.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10