LCOV - code coverage report
Current view: top level - svl/source/items - macitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 21 116 18.1 %
Date: 2012-08-25 Functions: 9 28 32.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 11 170 6.5 %

           Branch data     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                 :            : 
      24                 :            : // STATIC DATA -----------------------------------------------------------
      25                 :            : 
      26                 :            : DBG_NAME(SvxMacroItem);
      27                 :            : 
      28                 :            : // -----------------------------------------------------------------------
      29                 :            : 
      30 [ -  + ][ -  + ]:       5601 : TYPEINIT1_FACTORY(SvxMacroItem, SfxPoolItem, new SvxMacroItem(0));
                 [ #  # ]
      31                 :            : 
      32                 :            : // -----------------------------------------------------------------------
      33                 :            : 
      34                 :            : 
      35                 :          0 : SjJSbxObjectBase::~SjJSbxObjectBase()
      36                 :            : {
      37         [ #  # ]:          0 : }
      38                 :            : 
      39                 :          0 : SjJSbxObjectBase* SjJSbxObjectBase::Clone( void )
      40                 :            : {
      41                 :          0 :     return NULL;
      42                 :            : }
      43                 :            : 
      44                 :          8 : SvxMacro::SvxMacro( const ::rtl::OUString &rMacName, const ::rtl::OUString &rLanguage)
      45                 :            :     : aMacName( rMacName ), aLibName( rLanguage),
      46                 :          8 :       pFunctionObject(NULL), eType( EXTENDED_STYPE)
      47                 :            : {
      48         [ -  + ]:          8 :     if ( rLanguage == SVX_MACRO_LANGUAGE_STARBASIC )
      49                 :          0 :         eType=STARBASIC;
      50         [ -  + ]:          8 :     else if ( rLanguage == SVX_MACRO_LANGUAGE_JAVASCRIPT )
      51                 :          0 :         eType=JAVASCRIPT;
      52                 :          8 : }
      53                 :            : 
      54                 :            : 
      55                 :          8 : SvxMacro::~SvxMacro()
      56                 :            : {
      57 [ -  + ][ #  # ]:          8 :     delete pFunctionObject;
      58                 :          8 : }
      59                 :            : 
      60                 :          0 : ::rtl::OUString SvxMacro::GetLanguage()const
      61                 :            : {
      62         [ #  # ]:          0 :     if(eType==STARBASIC)
      63                 :            :     {
      64                 :          0 :         return ::rtl::OUString(SVX_MACRO_LANGUAGE_STARBASIC);
      65                 :            :     }
      66         [ #  # ]:          0 :     else if(eType==JAVASCRIPT)
      67                 :            :     {
      68                 :          0 :         return ::rtl::OUString(SVX_MACRO_LANGUAGE_JAVASCRIPT);
      69                 :            :     }
      70         [ #  # ]:          0 :     else if(eType==EXTENDED_STYPE)
      71                 :            :     {
      72                 :          0 :         return ::rtl::OUString(SVX_MACRO_LANGUAGE_SF);
      73                 :            : 
      74                 :            :     }
      75                 :          0 :     return aLibName;
      76                 :            : }
      77                 :            : 
      78                 :            : 
      79                 :            : 
      80                 :          0 : SvxMacro& SvxMacro::operator=( const SvxMacro& rBase )
      81                 :            : {
      82         [ #  # ]:          0 :     if( this != &rBase )
      83                 :            :     {
      84                 :          0 :         aMacName = rBase.aMacName;
      85                 :          0 :         aLibName = rBase.aLibName;
      86         [ #  # ]:          0 :         delete pFunctionObject;
      87         [ #  # ]:          0 :         pFunctionObject = rBase.pFunctionObject ? rBase.pFunctionObject->Clone() : NULL;
      88                 :          0 :         eType = rBase.eType;
      89                 :            :     }
      90                 :          0 :     return *this;
      91                 :            : }
      92                 :            : 
      93                 :            : // -----------------------------------------------------------------------
      94                 :            : 
      95                 :          2 : SvxMacroTableDtor& SvxMacroTableDtor::operator=( const SvxMacroTableDtor& rTbl )
      96                 :            : {
      97                 :          2 :     aSvxMacroTable.clear();
      98                 :          2 :     aSvxMacroTable.insert(rTbl.aSvxMacroTable.begin(), rTbl.aSvxMacroTable.end());
      99                 :          2 :     return *this;
     100                 :            : }
     101                 :            : 
     102                 :          0 : int SvxMacroTableDtor::operator==( const SvxMacroTableDtor& rOther ) const
     103                 :            : {
     104                 :            :     // Anzahl unterschiedlich => auf jeden Fall ungleich
     105         [ #  # ]:          0 :     if ( aSvxMacroTable.size() != rOther.aSvxMacroTable.size() )
     106                 :          0 :         return sal_False;
     107                 :            : 
     108                 :            :     // einzeln verleichen; wegen Performance ist die Reihenfolge wichtig
     109                 :          0 :     SvxMacroTable::const_iterator it1 = aSvxMacroTable.begin();
     110                 :          0 :     SvxMacroTable::const_iterator it2 = rOther.aSvxMacroTable.begin();
     111 [ #  # ][ #  # ]:          0 :     for ( ; it1 != aSvxMacroTable.end(); ++it1, ++it2 )
         [ #  # ][ #  # ]
     112                 :            :     {
     113         [ #  # ]:          0 :         const SvxMacro& rOwnMac = it1->second;
     114         [ #  # ]:          0 :         const SvxMacro& rOtherMac = it2->second;
     115 [ #  # ][ #  # ]:          0 :         if (    it1->first != it2->first ||
           [ #  #  #  #  
           #  # ][ #  # ]
     116                 :          0 :                 rOwnMac.GetLibName() != rOtherMac.GetLibName() ||
     117                 :          0 :                 rOwnMac.GetMacName() != rOtherMac.GetMacName() )
     118                 :          0 :             return sal_False;
     119                 :            :     }
     120                 :            : 
     121                 :          0 :     return sal_True;
     122                 :            : }
     123                 :            : 
     124                 :          0 : SvStream& SvxMacroTableDtor::Read( SvStream& rStrm, sal_uInt16 nVersion )
     125                 :            : {
     126         [ #  # ]:          0 :     if( SVX_MACROTBL_VERSION40 <= nVersion )
     127         [ #  # ]:          0 :         rStrm >> nVersion;
     128                 :            :     short nMacro;
     129         [ #  # ]:          0 :     rStrm >> nMacro;
     130                 :            : 
     131         [ #  # ]:          0 :     for( short i = 0; i < nMacro; ++i )
     132                 :            :     {
     133                 :          0 :         sal_uInt16 nCurKey, eType = STARBASIC;
     134 [ #  # ][ #  # ]:          0 :         String aLibName, aMacName;
     135         [ #  # ]:          0 :         rStrm >> nCurKey;
     136 [ #  # ][ #  # ]:          0 :         aLibName = SfxPoolItem::readByteString(rStrm);
     137 [ #  # ][ #  # ]:          0 :         aMacName = SfxPoolItem::readByteString(rStrm);
     138                 :            : 
     139         [ #  # ]:          0 :         if( SVX_MACROTBL_VERSION40 <= nVersion )
     140         [ #  # ]:          0 :             rStrm >> eType;
     141                 :            : 
     142 [ #  # ][ #  # ]:          0 :         aSvxMacroTable.insert( SvxMacroTable::value_type(nCurKey, SvxMacro( aMacName, aLibName, (ScriptType)eType ) ));
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     143 [ #  # ][ #  # ]:          0 :     }
     144                 :          0 :     return rStrm;
     145                 :            : }
     146                 :            : 
     147                 :            : 
     148                 :          0 : SvStream& SvxMacroTableDtor::Write( SvStream& rStream ) const
     149                 :            : {
     150                 :          0 :     sal_uInt16 nVersion = SOFFICE_FILEFORMAT_31 == rStream.GetVersion()
     151                 :            :                                     ? SVX_MACROTBL_VERSION31
     152                 :          0 :                                     : SVX_MACROTBL_AKTVERSION;
     153                 :            : 
     154         [ #  # ]:          0 :     if( SVX_MACROTBL_VERSION40 <= nVersion )
     155         [ #  # ]:          0 :         rStream << nVersion;
     156                 :            : 
     157         [ #  # ]:          0 :     rStream << (sal_uInt16)aSvxMacroTable.size();
     158                 :            : 
     159                 :          0 :     SvxMacroTable::const_iterator it = aSvxMacroTable.begin();
     160 [ #  # ][ #  # ]:          0 :     while( it != aSvxMacroTable.end() && rStream.GetError() == SVSTREAM_OK )
         [ #  # ][ #  # ]
           [ #  #  #  # ]
     161                 :            :     {
     162         [ #  # ]:          0 :         const SvxMacro& rMac = it->second;
     163 [ #  # ][ #  # ]:          0 :         rStream << it->first;
     164         [ #  # ]:          0 :         SfxPoolItem::writeByteString(rStream, rMac.GetLibName());
     165         [ #  # ]:          0 :         SfxPoolItem::writeByteString(rStream, rMac.GetMacName());
     166                 :            : 
     167         [ #  # ]:          0 :         if( SVX_MACROTBL_VERSION40 <= nVersion )
     168         [ #  # ]:          0 :             rStream << (sal_uInt16)rMac.GetScriptType();
     169         [ #  # ]:          0 :         ++it;
     170                 :            :     }
     171                 :          0 :     return rStream;
     172                 :            : }
     173                 :            : 
     174                 :            : // returns NULL if no entry exists, or a pointer to the internal value
     175                 :          4 : const SvxMacro* SvxMacroTableDtor::Get(sal_uInt16 nEvent) const
     176                 :            : {
     177         [ +  - ]:          4 :     SvxMacroTable::const_iterator it = aSvxMacroTable.find(nEvent);
     178 [ +  - ][ +  - ]:          4 :     return it == aSvxMacroTable.end() ? NULL : &(it->second);
                 [ #  # ]
     179                 :            : }
     180                 :            : 
     181                 :            : // returns NULL if no entry exists, or a pointer to the internal value
     182                 :          0 : SvxMacro* SvxMacroTableDtor::Get(sal_uInt16 nEvent)
     183                 :            : {
     184         [ #  # ]:          0 :     SvxMacroTable::iterator it = aSvxMacroTable.find(nEvent);
     185 [ #  # ][ #  # ]:          0 :     return it == aSvxMacroTable.end() ? NULL : &(it->second);
                 [ #  # ]
     186                 :            : }
     187                 :            : 
     188                 :            : // return true if the key exists
     189                 :         12 : bool SvxMacroTableDtor::IsKeyValid(sal_uInt16 nEvent) const
     190                 :            : {
     191         [ +  - ]:         12 :     SvxMacroTable::const_iterator it = aSvxMacroTable.find(nEvent);
     192         [ +  - ]:         12 :     return it != aSvxMacroTable.end();
     193                 :            : }
     194                 :            : 
     195                 :            : // This stores a copy of the rMacro parameter
     196                 :          0 : SvxMacro& SvxMacroTableDtor::Insert(sal_uInt16 nEvent, const SvxMacro& rMacro)
     197                 :            : {
     198 [ #  # ][ #  # ]:          0 :     return aSvxMacroTable.insert( SvxMacroTable::value_type( nEvent, rMacro ) ).first->second;
     199                 :            : }
     200                 :            : 
     201                 :            : // If the entry exists, remove it from the map and release it's storage
     202                 :          0 : sal_Bool SvxMacroTableDtor::Erase(sal_uInt16 nEvent)
     203                 :            : {
     204         [ #  # ]:          0 :     SvxMacroTable::iterator it = aSvxMacroTable.find(nEvent);
     205 [ #  # ][ #  # ]:          0 :     if ( it != aSvxMacroTable.end())
     206                 :            :     {
     207         [ #  # ]:          0 :         aSvxMacroTable.erase(it);
     208                 :          0 :         return sal_True;
     209                 :            :     }
     210                 :          0 :     return sal_False;
     211                 :            : }
     212                 :            : 
     213                 :            : // -----------------------------------------------------------------------
     214                 :            : 
     215                 :          0 : int SvxMacroItem::operator==( const SfxPoolItem& rAttr ) const
     216                 :            : {
     217                 :            :     DBG_ASSERT( SfxPoolItem::operator==(rAttr), "unequal types" );
     218                 :            : 
     219                 :          0 :     const SvxMacroTableDtor& rOwn = aMacroTable;
     220                 :          0 :     const SvxMacroTableDtor& rOther = ( (SvxMacroItem&) rAttr ).aMacroTable;
     221                 :            : 
     222                 :          0 :     return rOwn == rOther;
     223                 :            : }
     224                 :            : 
     225                 :            : // -----------------------------------------------------------------------
     226                 :            : 
     227                 :          2 : SfxPoolItem* SvxMacroItem::Clone( SfxItemPool* ) const
     228                 :            : {
     229         [ +  - ]:          2 :     return new SvxMacroItem( *this );
     230                 :            : }
     231                 :            : 
     232                 :            : //------------------------------------------------------------------------
     233                 :            : 
     234                 :          0 : SfxItemPresentation SvxMacroItem::GetPresentation
     235                 :            : (
     236                 :            :     SfxItemPresentation /*ePres*/,
     237                 :            :     SfxMapUnit          /*eCoreUnit*/,
     238                 :            :     SfxMapUnit          /*ePresUnit*/,
     239                 :            :     XubString&          rText,
     240                 :            :     const IntlWrapper *
     241                 :            : )   const
     242                 :            : {
     243                 :            : /*!!!
     244                 :            :     SvxMacroTableDtor& rTbl = (SvxMacroTableDtor&)GetMacroTable();
     245                 :            :     SvxMacro* pMac = rTbl.First();
     246                 :            : 
     247                 :            :     while ( pMac )
     248                 :            :     {
     249                 :            :         rText += pMac->GetLibName();
     250                 :            :         rText += cpDelim;
     251                 :            :         rText += pMac->GetMacName();
     252                 :            :         pMac = rTbl.Next();
     253                 :            :         if ( pMac )
     254                 :            :             rText += cpDelim;
     255                 :            :     }
     256                 :            : */
     257                 :          0 :     rText.Erase();
     258                 :          0 :     return SFX_ITEM_PRESENTATION_NONE;
     259                 :            : }
     260                 :            : 
     261                 :            : // -----------------------------------------------------------------------
     262                 :            : 
     263                 :          0 : SvStream& SvxMacroItem::Store( SvStream& rStrm , sal_uInt16 ) const
     264                 :            : {
     265                 :          0 :     return aMacroTable.Write( rStrm );
     266                 :            : }
     267                 :            : 
     268                 :            : // -----------------------------------------------------------------------
     269                 :            : 
     270                 :          0 : SfxPoolItem* SvxMacroItem::Create( SvStream& rStrm, sal_uInt16 nVersion ) const
     271                 :            : {
     272         [ #  # ]:          0 :     SvxMacroItem* pAttr = new SvxMacroItem( Which() );
     273                 :          0 :     pAttr->aMacroTable.Read( rStrm, nVersion );
     274                 :          0 :     return pAttr;
     275                 :            : }
     276                 :            : 
     277                 :            : // -----------------------------------------------------------------------
     278                 :            : 
     279                 :          0 : void SvxMacroItem::SetMacro( sal_uInt16 nEvent, const SvxMacro& rMacro )
     280                 :            : {
     281                 :          0 :     aMacroTable.Insert( nEvent, rMacro);
     282                 :          0 : }
     283                 :            : 
     284                 :            : // -----------------------------------------------------------------------
     285                 :            : 
     286                 :          0 : sal_uInt16 SvxMacroItem::GetVersion( sal_uInt16 nFileFormatVersion ) const
     287                 :            : {
     288                 :            :     return SOFFICE_FILEFORMAT_31 == nFileFormatVersion
     289         [ #  # ]:          0 :                 ? 0 : aMacroTable.GetVersion();
     290                 :            : }
     291                 :            : 
     292                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10