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

Generated by: LCOV version 1.10