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

Generated by: LCOV version 1.10