LCOV - code coverage report
Current view: top level - svl/source/items - slstitm.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 45 116 38.8 %
Date: 2014-04-11 Functions: 15 26 57.7 %
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             : 
      21             : #include <svl/slstitm.hxx>
      22             : #include <svl/poolitem.hxx>
      23             : #include <com/sun/star/uno/Any.hxx>
      24             : #include <com/sun/star/uno/Sequence.hxx>
      25             : #include <tools/stream.hxx>
      26             : 
      27        2547 : TYPEINIT1_AUTOFACTORY(SfxStringListItem, SfxPoolItem);
      28             : 
      29             : class SfxImpStringList
      30             : {
      31             : public:
      32             :     sal_uInt16  nRefCount;
      33             :     std::vector<OUString>  aList;
      34             : 
      35         313 :             SfxImpStringList() { nRefCount = 1; }
      36             :             ~SfxImpStringList();
      37             : };
      38             : 
      39             : 
      40         626 : SfxImpStringList::~SfxImpStringList()
      41             : {
      42             :     DBG_ASSERT(nRefCount!=0xffff,"ImpList already deleted");
      43         313 :     nRefCount = 0xffff;
      44         313 : }
      45             : 
      46             : // class SfxStringListItem -----------------------------------------------
      47             : 
      48           0 : SfxStringListItem::SfxStringListItem() :
      49           0 :     pImp(NULL)
      50             : {
      51           0 : }
      52             : 
      53             : 
      54         313 : SfxStringListItem::SfxStringListItem( sal_uInt16 which, const std::vector<OUString>* pList ) :
      55             :     SfxPoolItem( which ),
      56         313 :     pImp(NULL)
      57             : {
      58             :     // PB: das Putten einer leeren Liste funktionierte nicht,
      59             :     // deshalb habe ich hier die Abfrage nach dem Count auskommentiert
      60         313 :     if( pList /*!!! && pList->Count() */ )
      61             :     {
      62           0 :         pImp = new SfxImpStringList;
      63             : 
      64           0 :         if (pImp)
      65           0 :             pImp->aList = *pList;
      66             :     }
      67         313 : }
      68             : 
      69             : 
      70           0 : SfxStringListItem::SfxStringListItem( sal_uInt16 which, SvStream& rStream ) :
      71             :     SfxPoolItem( which ),
      72           0 :     pImp(NULL)
      73             : {
      74             :     //fdo#39428 SvStream no longer supports operator>>(long&)
      75             :     sal_Int32 nEntryCount;
      76           0 :     rStream.ReadInt32( nEntryCount );
      77             : 
      78           0 :     if( nEntryCount )
      79           0 :         pImp = new SfxImpStringList;
      80             : 
      81           0 :     if (pImp)
      82             :     {
      83           0 :         for( sal_Int32 i=0; i < nEntryCount; i++ )
      84             :         {
      85           0 :             pImp->aList.push_back( readByteString(rStream) );
      86             :         }
      87             :     }
      88           0 : }
      89             : 
      90             : 
      91         939 : SfxStringListItem::SfxStringListItem( const SfxStringListItem& rItem ) :
      92             :     SfxPoolItem( rItem ),
      93         939 :     pImp(rItem.pImp)
      94             : {
      95         939 :     if( pImp )
      96             :     {
      97             :         DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
      98         939 :         pImp->nRefCount++;
      99             :     }
     100         939 : }
     101             : 
     102             : 
     103        3443 : SfxStringListItem::~SfxStringListItem()
     104             : {
     105        1252 :     if( pImp )
     106             :     {
     107             :         DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
     108        1252 :         if( pImp->nRefCount > 1 )
     109         939 :             pImp->nRefCount--;
     110             :         else
     111         313 :             delete pImp;
     112             :     }
     113        2191 : }
     114             : 
     115             : 
     116           0 : std::vector<OUString>& SfxStringListItem::GetList()
     117             : {
     118           0 :     if( !pImp )
     119           0 :         pImp = new SfxImpStringList;
     120             :     DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
     121           0 :     return pImp->aList;
     122             : }
     123             : 
     124           0 : const std::vector<OUString>& SfxStringListItem::GetList () const
     125             : {
     126           0 :     return (const_cast< SfxStringListItem * >(this))->GetList();
     127             : }
     128             : 
     129             : 
     130         130 : bool SfxStringListItem::operator==( const SfxPoolItem& rItem ) const
     131             : {
     132             :     DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
     133             : 
     134         130 :     SfxStringListItem* pItem = (SfxStringListItem*)&rItem;
     135             : 
     136         130 :     return pImp == pItem->pImp;
     137             : }
     138             : 
     139             : 
     140           0 : SfxItemPresentation SfxStringListItem::GetPresentation
     141             : (
     142             :     SfxItemPresentation     /*ePresentation*/,
     143             :     SfxMapUnit              /*eCoreMetric*/,
     144             :     SfxMapUnit              /*ePresentationMetric*/,
     145             :     OUString&               rText,
     146             :     const IntlWrapper *
     147             : )   const
     148             : {
     149           0 :     rText = "(List)";
     150           0 :     return SFX_ITEM_PRESENTATION_NONE;
     151             : }
     152             : 
     153             : 
     154         939 : SfxPoolItem* SfxStringListItem::Clone( SfxItemPool *) const
     155             : {
     156         939 :     return new SfxStringListItem( *this );
     157             :     /*
     158             :     if( pImp )
     159             :         return new SfxStringListItem( Which(), &(pImp->aList) );
     160             :     else
     161             :         return new SfxStringListItem( Which(), NULL );
     162             :     */
     163             : 
     164             : }
     165             : 
     166             : 
     167           0 : SfxPoolItem* SfxStringListItem::Create( SvStream & rStream, sal_uInt16 ) const
     168             : {
     169           0 :     return new SfxStringListItem( Which(), rStream );
     170             : }
     171             : 
     172             : 
     173           0 : SvStream& SfxStringListItem::Store( SvStream & rStream, sal_uInt16 ) const
     174             : {
     175           0 :     if( !pImp )
     176             :     {
     177             :         //fdo#39428 SvStream no longer supports operator<<(long)
     178           0 :         rStream.WriteInt32( (sal_Int32) 0 );
     179           0 :         return rStream;
     180             :     }
     181             : 
     182             :     DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
     183             : 
     184           0 :     sal_uInt32 nCount = pImp->aList.size();
     185           0 :     rStream.WriteUInt32( nCount );
     186             : 
     187           0 :     for( sal_uInt32 i=0; i < nCount; i++ )
     188           0 :         writeByteString(rStream, pImp->aList[i]);
     189             : 
     190           0 :     return rStream;
     191             : }
     192             : 
     193             : 
     194           0 : void SfxStringListItem::SetString( const OUString& rStr )
     195             : {
     196             :     DBG_ASSERT(GetRefCount()==0,"SetString:RefCount!=0");
     197             : 
     198           0 :     if ( pImp && (pImp->nRefCount == 1) )
     199           0 :         delete pImp;
     200           0 :     else if( pImp )
     201           0 :         pImp->nRefCount--;
     202           0 :     pImp = new SfxImpStringList;
     203             : 
     204           0 :     sal_Int32 nStart = 0;
     205           0 :     OUString aStr(convertLineEnd(rStr, LINEEND_CR));
     206             :     for (;;)
     207             :     {
     208           0 :         const sal_Int32 nDelimPos = aStr.indexOf( '\r', nStart );
     209           0 :         if ( nDelimPos < 0 )
     210             :         {
     211           0 :             if (nStart<aStr.getLength())
     212             :             {
     213             :                 // put last string only if not empty
     214           0 :                 pImp->aList.push_back(aStr.copy(nStart));
     215             :             }
     216           0 :             break;
     217             :         }
     218             : 
     219           0 :         pImp->aList.push_back(aStr.copy(nStart, nDelimPos-nStart));
     220             : 
     221             :         // skip both inserted string and delimiter
     222           0 :         nStart = nDelimPos + 1 ;
     223           0 :     }
     224           0 : }
     225             : 
     226             : 
     227           0 : OUString SfxStringListItem::GetString()
     228             : {
     229           0 :     OUString aStr;
     230           0 :     if ( pImp )
     231             :     {
     232             :         DBG_ASSERT(pImp->nRefCount!=0xffff,"ImpList not valid");
     233             : 
     234           0 :         std::vector<OUString>::iterator iter = pImp->aList.begin();
     235             :         for (;;)
     236             :         {
     237           0 :             aStr += *iter;
     238           0 :             ++iter;
     239             : 
     240           0 :             if (iter == pImp->aList.end())
     241           0 :                 break;
     242             : 
     243           0 :             aStr += "\r";
     244           0 :         }
     245             :     }
     246           0 :     return convertLineEnd(aStr, GetSystemLineEnd());
     247             : }
     248             : 
     249             : 
     250         313 : void SfxStringListItem::SetStringList( const com::sun::star::uno::Sequence< OUString >& rList )
     251             : {
     252             :     DBG_ASSERT(GetRefCount()==0,"SetString:RefCount!=0");
     253             : 
     254         313 :     if ( pImp && (pImp->nRefCount == 1) )
     255           0 :         delete pImp;
     256         313 :     else if( pImp )
     257           0 :         pImp->nRefCount--;
     258         313 :     pImp = new SfxImpStringList;
     259             : 
     260         313 :     if (pImp)
     261             :     {
     262             :         // String gehoert der Liste
     263        1565 :         for ( sal_Int32 n = 0; n < rList.getLength(); n++ )
     264        1252 :             pImp->aList.push_back(rList[n]);
     265             :     }
     266         313 : }
     267             : 
     268         313 : void SfxStringListItem::GetStringList( com::sun::star::uno::Sequence< OUString >& rList ) const
     269             : {
     270         313 :     long nCount = pImp->aList.size();
     271             : 
     272         313 :     rList.realloc( nCount );
     273        1565 :     for( long i=0; i < nCount; i++ )
     274        1252 :         rList[i] = pImp->aList[i];
     275         313 : }
     276             : 
     277             : // virtual
     278           0 : bool SfxStringListItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8 )
     279             : {
     280           0 :     com::sun::star::uno::Sequence< OUString > aValue;
     281           0 :     if ( rVal >>= aValue )
     282             :     {
     283           0 :         SetStringList( aValue );
     284           0 :         return true;
     285             :     }
     286             : 
     287             :     OSL_FAIL( "SfxStringListItem::PutValue - Wrong type!" );
     288           0 :     return false;
     289             : }
     290             : 
     291             : // virtual
     292         313 : bool SfxStringListItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8 ) const
     293             : {
     294             :     // GetString() is not const!!!
     295         313 :     SfxStringListItem* pThis = const_cast< SfxStringListItem * >( this );
     296             : 
     297         313 :     com::sun::star::uno::Sequence< OUString > aStringList;
     298         313 :     pThis->GetStringList( aStringList );
     299         313 :     rVal = ::com::sun::star::uno::makeAny( aStringList );
     300         313 :     return true;
     301             : }
     302             : 
     303             : 
     304             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10