LCOV - code coverage report
Current view: top level - svl/source/items - macitem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 34 107 31.8 %
Date: 2014-11-03 Functions: 11 24 45.8 %
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             : 
      22             : #include <svl/macitem.hxx>
      23             : #include <stringio.hxx>
      24             : 
      25       15399 : TYPEINIT1_FACTORY(SvxMacroItem, SfxPoolItem, new SvxMacroItem(0));
      26             : 
      27             : 
      28             : 
      29        1448 : SvxMacro::SvxMacro( const OUString &rMacName, const OUString &rLanguage)
      30             :     : aMacName( rMacName ), aLibName( rLanguage),
      31        1448 :       eType( EXTENDED_STYPE)
      32             : {
      33        1448 :     if ( rLanguage == SVX_MACRO_LANGUAGE_STARBASIC )
      34           0 :         eType=STARBASIC;
      35        1448 :     else if ( rLanguage == SVX_MACRO_LANGUAGE_JAVASCRIPT )
      36           0 :         eType=JAVASCRIPT;
      37        1448 : }
      38             : 
      39           0 : OUString SvxMacro::GetLanguage()const
      40             : {
      41           0 :     if(eType==STARBASIC)
      42             :     {
      43           0 :         return OUString(SVX_MACRO_LANGUAGE_STARBASIC);
      44             :     }
      45           0 :     else if(eType==JAVASCRIPT)
      46             :     {
      47           0 :         return OUString(SVX_MACRO_LANGUAGE_JAVASCRIPT);
      48             :     }
      49           0 :     else if(eType==EXTENDED_STYPE)
      50             :     {
      51           0 :         return OUString(SVX_MACRO_LANGUAGE_SF);
      52             : 
      53             :     }
      54           0 :     return aLibName;
      55             : }
      56             : 
      57         720 : SvxMacro& SvxMacro::operator=( const SvxMacro& rBase )
      58             : {
      59         720 :     if( this != &rBase )
      60             :     {
      61         720 :         aMacName = rBase.aMacName;
      62         720 :         aLibName = rBase.aLibName;
      63         720 :         eType = rBase.eType;
      64             :     }
      65         720 :     return *this;
      66             : }
      67             : 
      68             : 
      69             : 
      70           4 : SvxMacroTableDtor& SvxMacroTableDtor::operator=( const SvxMacroTableDtor& rTbl )
      71             : {
      72           4 :     aSvxMacroTable.clear();
      73           4 :     aSvxMacroTable.insert(rTbl.aSvxMacroTable.begin(), rTbl.aSvxMacroTable.end());
      74           4 :     return *this;
      75             : }
      76             : 
      77          16 : int SvxMacroTableDtor::operator==( const SvxMacroTableDtor& rOther ) const
      78             : {
      79             :     // Count different => odd in any case
      80          16 :     if ( aSvxMacroTable.size() != rOther.aSvxMacroTable.size() )
      81           0 :         return sal_False;
      82             : 
      83             :     // Compare single ones; the sequence matters due to performance reasons
      84          16 :     SvxMacroTable::const_iterator it1 = aSvxMacroTable.begin();
      85          16 :     SvxMacroTable::const_iterator it2 = rOther.aSvxMacroTable.begin();
      86          16 :     for ( ; it1 != aSvxMacroTable.end(); ++it1, ++it2 )
      87             :     {
      88           0 :         const SvxMacro& rOwnMac = it1->second;
      89           0 :         const SvxMacro& rOtherMac = it2->second;
      90           0 :         if (    it1->first != it2->first ||
      91           0 :                 rOwnMac.GetLibName() != rOtherMac.GetLibName() ||
      92           0 :                 rOwnMac.GetMacName() != rOtherMac.GetMacName() )
      93           0 :             return sal_False;
      94             :     }
      95             : 
      96          16 :     return sal_True;
      97             : }
      98             : 
      99           0 : SvStream& SvxMacroTableDtor::Read( SvStream& rStrm, sal_uInt16 nVersion )
     100             : {
     101           0 :     if( SVX_MACROTBL_VERSION40 <= nVersion )
     102           0 :         rStrm.ReadUInt16( nVersion );
     103             :     short nMacro;
     104           0 :     rStrm.ReadInt16( nMacro );
     105             : 
     106           0 :     for( short i = 0; i < nMacro; ++i )
     107             :     {
     108           0 :         sal_uInt16 nCurKey, eType = STARBASIC;
     109           0 :         OUString aLibName, aMacName;
     110           0 :         rStrm.ReadUInt16( nCurKey );
     111           0 :         aLibName = readByteString(rStrm);
     112           0 :         aMacName = readByteString(rStrm);
     113             : 
     114           0 :         if( SVX_MACROTBL_VERSION40 <= nVersion )
     115           0 :             rStrm.ReadUInt16( eType );
     116             : 
     117           0 :         aSvxMacroTable.insert( SvxMacroTable::value_type(nCurKey, SvxMacro( aMacName, aLibName, (ScriptType)eType ) ));
     118           0 :     }
     119           0 :     return rStrm;
     120             : }
     121             : 
     122             : 
     123           0 : SvStream& SvxMacroTableDtor::Write( SvStream& rStream ) const
     124             : {
     125           0 :     sal_uInt16 nVersion = SOFFICE_FILEFORMAT_31 == rStream.GetVersion()
     126             :                                     ? SVX_MACROTBL_VERSION31
     127           0 :                                     : SVX_MACROTBL_AKTVERSION;
     128             : 
     129           0 :     if( SVX_MACROTBL_VERSION40 <= nVersion )
     130           0 :         rStream.WriteUInt16( nVersion );
     131             : 
     132           0 :     rStream.WriteUInt16( aSvxMacroTable.size() );
     133             : 
     134           0 :     SvxMacroTable::const_iterator it = aSvxMacroTable.begin();
     135           0 :     while( it != aSvxMacroTable.end() && rStream.GetError() == SVSTREAM_OK )
     136             :     {
     137           0 :         const SvxMacro& rMac = it->second;
     138           0 :         rStream.WriteUInt16( it->first );
     139           0 :         writeByteString(rStream, rMac.GetLibName());
     140           0 :         writeByteString(rStream, rMac.GetMacName());
     141             : 
     142           0 :         if( SVX_MACROTBL_VERSION40 <= nVersion )
     143           0 :             rStream.WriteUInt16( rMac.GetScriptType() );
     144           0 :         ++it;
     145             :     }
     146           0 :     return rStream;
     147             : }
     148             : 
     149             : // returns NULL if no entry exists, or a pointer to the internal value
     150           4 : const SvxMacro* SvxMacroTableDtor::Get(sal_uInt16 nEvent) const
     151             : {
     152           4 :     SvxMacroTable::const_iterator it = aSvxMacroTable.find(nEvent);
     153           4 :     return it == aSvxMacroTable.end() ? NULL : &(it->second);
     154             : }
     155             : 
     156             : // returns NULL if no entry exists, or a pointer to the internal value
     157           0 : SvxMacro* SvxMacroTableDtor::Get(sal_uInt16 nEvent)
     158             : {
     159           0 :     SvxMacroTable::iterator it = aSvxMacroTable.find(nEvent);
     160           0 :     return it == aSvxMacroTable.end() ? NULL : &(it->second);
     161             : }
     162             : 
     163             : // return true if the key exists
     164         732 : bool SvxMacroTableDtor::IsKeyValid(sal_uInt16 nEvent) const
     165             : {
     166         732 :     SvxMacroTable::const_iterator it = aSvxMacroTable.find(nEvent);
     167         732 :     return it != aSvxMacroTable.end();
     168             : }
     169             : 
     170             : // This stores a copy of the rMacro parameter
     171           0 : SvxMacro& SvxMacroTableDtor::Insert(sal_uInt16 nEvent, const SvxMacro& rMacro)
     172             : {
     173           0 :     return aSvxMacroTable.insert( SvxMacroTable::value_type( nEvent, rMacro ) ).first->second;
     174             : }
     175             : 
     176             : // If the entry exists, remove it from the map and release it's storage
     177           0 : bool SvxMacroTableDtor::Erase(sal_uInt16 nEvent)
     178             : {
     179           0 :     SvxMacroTable::iterator it = aSvxMacroTable.find(nEvent);
     180           0 :     if ( it != aSvxMacroTable.end())
     181             :     {
     182           0 :         aSvxMacroTable.erase(it);
     183           0 :         return true;
     184             :     }
     185           0 :     return false;
     186             : }
     187             : 
     188             : 
     189             : 
     190          16 : bool SvxMacroItem::operator==( const SfxPoolItem& rAttr ) const
     191             : {
     192             :     DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
     193             : 
     194          16 :     const SvxMacroTableDtor& rOwn = aMacroTable;
     195          16 :     const SvxMacroTableDtor& rOther = static_cast<const SvxMacroItem&>(rAttr).aMacroTable;
     196             : 
     197          16 :     return rOwn == rOther;
     198             : }
     199             : 
     200             : 
     201             : 
     202           2 : SfxPoolItem* SvxMacroItem::Clone( SfxItemPool* ) const
     203             : {
     204           2 :     return new SvxMacroItem( *this );
     205             : }
     206             : 
     207             : 
     208           0 : bool SvxMacroItem::GetPresentation
     209             : (
     210             :     SfxItemPresentation /*ePres*/,
     211             :     SfxMapUnit          /*eCoreUnit*/,
     212             :     SfxMapUnit          /*ePresUnit*/,
     213             :     OUString&           rText,
     214             :     const IntlWrapper *
     215             : )   const
     216             : {
     217             : /*!!!
     218             :     SvxMacroTableDtor& rTbl = (SvxMacroTableDtor&)GetMacroTable();
     219             :     SvxMacro* pMac = rTbl.First();
     220             : 
     221             :     while ( pMac )
     222             :     {
     223             :         rText += pMac->GetLibName();
     224             :         rText += cpDelim;
     225             :         rText += pMac->GetMacName();
     226             :         pMac = rTbl.Next();
     227             :         if ( pMac )
     228             :             rText += cpDelim;
     229             :     }
     230             : */
     231           0 :     rText = OUString();
     232           0 :     return false;
     233             : }
     234             : 
     235             : 
     236             : 
     237           0 : SvStream& SvxMacroItem::Store( SvStream& rStrm , sal_uInt16 ) const
     238             : {
     239           0 :     return aMacroTable.Write( rStrm );
     240             : }
     241             : 
     242             : 
     243             : 
     244           0 : SfxPoolItem* SvxMacroItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
     245             : {
     246           0 :     SvxMacroItem* pAttr = new SvxMacroItem( Which() );
     247           0 :     pAttr->aMacroTable.Read( rStrm, nVersion );
     248           0 :     return pAttr;
     249             : }
     250             : 
     251             : 
     252             : 
     253           0 : void SvxMacroItem::SetMacro( sal_uInt16 nEvent, const SvxMacro& rMacro )
     254             : {
     255           0 :     aMacroTable.Insert( nEvent, rMacro);
     256           0 : }
     257             : 
     258             : 
     259             : 
     260           0 : sal_uInt16 SvxMacroItem::GetVersion( sal_uInt16 nFileFormatVersion ) const
     261             : {
     262             :     return SOFFICE_FILEFORMAT_31 == nFileFormatVersion
     263           0 :                 ? 0 : aMacroTable.GetVersion();
     264             : }
     265             : 
     266             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10