LCOV - code coverage report
Current view: top level - svl/source/items - ctypeitm.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 72 0.0 %
Date: 2014-11-03 Functions: 0 20 0.0 %
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 <com/sun/star/uno/Any.hxx>
      21             : 
      22             : #include <unotools/intlwrapper.hxx>
      23             : #include <tools/stream.hxx>
      24             : #include <svl/ctypeitm.hxx>
      25             : #include <stringio.hxx>
      26             : 
      27             : // The following defines are copied from chaos/source/items/cstritem.cxx:
      28             : #define CNTSTRINGITEM_STREAM_MAGIC   ( (sal_uInt32)0xfefefefe )
      29             : #define CNTSTRINGITEM_STREAM_SEEKREL (-( (long)( sizeof( sal_uInt32 ) ) ) )
      30             : 
      31             : 
      32             : // class CntContentTypeItem Implementation.
      33             : 
      34             : 
      35           0 : TYPEINIT1_AUTOFACTORY( CntContentTypeItem, CntUnencodedStringItem );
      36             : 
      37             : #define CONTENT_TYPE_NOT_INIT ( (INetContentType)-1 )
      38             : 
      39           0 : CntContentTypeItem::CntContentTypeItem()
      40             : : CntUnencodedStringItem(),
      41           0 :   _eType( CONTENT_TYPE_NOT_INIT )
      42             : {
      43           0 : }
      44             : 
      45           0 : CntContentTypeItem::CntContentTypeItem( sal_uInt16 which, const OUString& rType )
      46             : : CntUnencodedStringItem( which, rType ),
      47           0 :   _eType( CONTENT_TYPE_NOT_INIT )
      48             : {
      49           0 : }
      50             : 
      51           0 : CntContentTypeItem::CntContentTypeItem( const CntContentTypeItem& rOrig )
      52             : : CntUnencodedStringItem( rOrig ),
      53             :   _eType( rOrig._eType ),
      54           0 :   _aPresentation( rOrig._aPresentation )
      55             : {
      56           0 : }
      57             : 
      58             : // virtual
      59           0 : sal_uInt16 CntContentTypeItem::GetVersion(sal_uInt16) const
      60             : {
      61           0 :     return 1; // because it uses SfxPoolItem::read/writeUnicodeString()
      62             : }
      63             : 
      64             : // virtual
      65           0 : SfxPoolItem* CntContentTypeItem::Create( SvStream& rStream,
      66             :                                          sal_uInt16 nItemVersion ) const
      67             : {
      68             :     // CntContentTypeItem used to be derived from CntStringItem, so take that
      69             :     // into account:
      70           0 :     OUString aValue = readUnicodeString(rStream, nItemVersion >= 1);
      71           0 :     sal_uInt32 nMagic = 0;
      72           0 :     rStream.ReadUInt32( nMagic );
      73           0 :     if (nMagic == CNTSTRINGITEM_STREAM_MAGIC)
      74             :     {
      75           0 :         bool bEncrypted = false;
      76           0 :         rStream.ReadCharAsBool( bEncrypted );
      77             :         DBG_ASSERT(!bEncrypted,
      78             :                    "CntContentTypeItem::Create() reads encrypted data");
      79             :     }
      80             :     else
      81           0 :         rStream.SeekRel(CNTSTRINGITEM_STREAM_SEEKREL);
      82             : 
      83           0 :     return new CntContentTypeItem(Which(), aValue);
      84             : }
      85             : 
      86             : // virtual
      87           0 : SvStream & CntContentTypeItem::Store(SvStream & rStream, sal_uInt16) const
      88             : {
      89             :     // CntContentTypeItem used to be derived from CntStringItem, so take that
      90             :     // into account:
      91           0 :     writeUnicodeString(rStream, GetValue());
      92           0 :     rStream.WriteUInt32( CNTSTRINGITEM_STREAM_MAGIC ).WriteUChar( false );
      93           0 :     return rStream;
      94             : }
      95             : 
      96             : // virtual
      97           0 : bool CntContentTypeItem::operator==( const SfxPoolItem& rOrig ) const
      98             : {
      99           0 :     const CntContentTypeItem& rOther = static_cast<const CntContentTypeItem&>(rOrig);
     100             : 
     101           0 :     if ( ( _eType != CONTENT_TYPE_NOT_INIT ) &&
     102           0 :          ( rOther._eType != CONTENT_TYPE_NOT_INIT ) )
     103           0 :         return _eType == rOther._eType;
     104             :     else
     105           0 :         return CntUnencodedStringItem::operator==( rOther );
     106             : }
     107             : 
     108             : // virtual
     109           0 : SfxPoolItem* CntContentTypeItem::Clone( SfxItemPool* /* pPool */ ) const
     110             : {
     111           0 :     return new CntContentTypeItem( *this );
     112             : }
     113             : 
     114           0 : void CntContentTypeItem::SetValue( const OUString& rNewVal )
     115             : {
     116             :     // De-initialize enum type and presentation.
     117           0 :     _eType = CONTENT_TYPE_NOT_INIT;
     118           0 :     _aPresentation = OUString();
     119             : 
     120           0 :     CntUnencodedStringItem::SetValue( rNewVal );
     121           0 : }
     122             : 
     123           0 : int CntContentTypeItem::Compare( const SfxPoolItem &rWith, const IntlWrapper& rIntlWrapper ) const
     124             : {
     125           0 :     OUString aOwnText, aWithText;
     126             :     GetPresentation( SFX_ITEM_PRESENTATION_NAMELESS,
     127           0 :                      SFX_MAPUNIT_APPFONT, SFX_MAPUNIT_APPFONT, aOwnText, &rIntlWrapper );
     128             :     rWith.GetPresentation( SFX_ITEM_PRESENTATION_NAMELESS,
     129           0 :                            SFX_MAPUNIT_APPFONT, SFX_MAPUNIT_APPFONT, aWithText, &rIntlWrapper );
     130           0 :     return rIntlWrapper.getCollator()->compareString( aOwnText, aWithText );
     131             : }
     132             : 
     133           0 : bool CntContentTypeItem::GetPresentation(
     134             :     SfxItemPresentation ePres,
     135             :     SfxMapUnit          eCoreMetric,
     136             :     SfxMapUnit          ePresMetric,
     137             :     OUString          & rText,
     138             :     const IntlWrapper * pIntlWrapper) const
     139             : {
     140           0 :     if (_aPresentation.isEmpty())
     141             :     {
     142             :         DBG_ASSERT(pIntlWrapper,
     143             :                    "CntContentTypeItem::GetPresentation(): No IntlWrapper");
     144           0 :         if (pIntlWrapper)
     145             :             (const_cast< CntContentTypeItem * >(this))->_aPresentation
     146           0 :              = INetContentTypes::GetPresentation(GetEnumValue(),
     147           0 :                      pIntlWrapper->getLanguageTag());
     148             :     }
     149           0 :     if (!_aPresentation.isEmpty())
     150             :     {
     151           0 :         rText = _aPresentation;
     152           0 :         return true;
     153             :     }
     154             :     else
     155             :         return CntUnencodedStringItem::GetPresentation(ePres, eCoreMetric,
     156             :                                                        ePresMetric, rText,
     157           0 :                                                        pIntlWrapper);
     158             : }
     159             : 
     160           0 : INetContentType CntContentTypeItem::GetEnumValue() const
     161             : {
     162           0 :     if ( _eType == CONTENT_TYPE_NOT_INIT )
     163             :     {
     164             :         // Not yet initialized... Get enum value for string content type.
     165             : 
     166           0 :         CntContentTypeItem* pVarThis = (const_cast< CntContentTypeItem* >(this));
     167             : 
     168           0 :         pVarThis->_eType = INetContentTypes::GetContentType( GetValue() );
     169             :     }
     170             : 
     171           0 :     return _eType;
     172             : }
     173             : 
     174           0 : void CntContentTypeItem::SetValue( const INetContentType eType )
     175             : {
     176           0 :     SetValue( INetContentTypes::GetContentType( eType ) );
     177             : 
     178             :     // Note: SetValue( const String& ....) resets _eType. Set new enum value
     179             :     //       after(!) calling it.
     180           0 :     _eType = eType;
     181           0 : }
     182             : 
     183             : // virtual
     184           0 : bool CntContentTypeItem::QueryValue( com::sun::star::uno::Any& rVal, sal_uInt8) const
     185             : {
     186           0 :     rVal <<= OUString(GetValue());
     187           0 :     return true;
     188             : }
     189             : 
     190             : // virtual
     191           0 : bool CntContentTypeItem::PutValue( const com::sun::star::uno::Any& rVal, sal_uInt8)
     192             : {
     193           0 :     OUString aValue;
     194           0 :     if ( rVal >>= aValue )
     195             :     {
     196             :         // SetValue with an empty string resets the item; so call that
     197             :         // function when PutValue is called with an empty string
     198           0 :         if (aValue.isEmpty())
     199           0 :             SetValue(aValue);
     200             :         else
     201             :             SetValue(
     202           0 :                 INetContentTypes::RegisterContentType(aValue, OUString()));
     203           0 :         return true;
     204             :     }
     205             : 
     206             :     OSL_FAIL( "CntContentTypeItem::PutValue - Wrong type!" );
     207           0 :     return false;
     208             : }
     209             : 
     210             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10