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

Generated by: LCOV version 1.10