LCOV - code coverage report
Current view: top level - sc/source/ui/view - scextopt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 61 67 91.0 %
Date: 2012-08-25 Functions: 23 26 88.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 23 40 57.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "scextopt.hxx"
      30                 :            : 
      31                 :            : #include <vector>
      32                 :            : #include <map>
      33                 :            : #include <boost/shared_ptr.hpp>
      34                 :            : 
      35                 :            : // ============================================================================
      36                 :            : 
      37                 :         89 : ScExtDocSettings::ScExtDocSettings() :
      38                 :            :     mfTabBarWidth( -1.0 ),
      39                 :            :     mnLinkCnt( 0 ),
      40                 :         89 :     mnDisplTab( 0 )
      41                 :            : {
      42                 :         89 : }
      43                 :            : 
      44                 :            : // ============================================================================
      45                 :            : 
      46                 :        272 : ScExtTabSettings::ScExtTabSettings() :
      47                 :            :     maUsedArea( ScAddress::INITIALIZE_INVALID ),
      48                 :            :     maCursor( ScAddress::INITIALIZE_INVALID ),
      49                 :            :     maFirstVis( ScAddress::INITIALIZE_INVALID ),
      50                 :            :     maSecondVis( ScAddress::INITIALIZE_INVALID ),
      51                 :            :     maFreezePos( 0, 0, 0 ),
      52                 :            :     maSplitPos( 0, 0 ),
      53                 :            :     meActivePane( SCEXT_PANE_TOPLEFT ),
      54                 :            :     maGridColor( COL_AUTO ),
      55                 :            :     mnNormalZoom( 0 ),
      56                 :            :     mnPageZoom( 0 ),
      57                 :            :     mbSelected( false ),
      58                 :            :     mbFrozenPanes( false ),
      59                 :            :     mbPageMode( false ),
      60                 :        272 :     mbShowGrid( true )
      61                 :            : {
      62                 :        272 : }
      63                 :            : 
      64                 :            : // ============================================================================
      65                 :            : 
      66                 :            : /** A container for ScExtTabSettings objects.
      67                 :            :     @descr  Internally, a std::map with shared pointers to ScExtTabSettings is
      68                 :            :     used. The copy constructor and assignment operator make deep copies of the
      69                 :            :     objects. */
      70                 :        173 : class ScExtTabSettingsCont
      71                 :            : {
      72                 :            : public:
      73                 :            :     explicit            ScExtTabSettingsCont();
      74                 :            :                         ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc );
      75                 :            :     ScExtTabSettingsCont& operator=( const ScExtTabSettingsCont& rSrc );
      76                 :            : 
      77                 :            :     const ScExtTabSettings* GetTabSettings( SCTAB nTab ) const;
      78                 :            :     ScExtTabSettings&   GetOrCreateTabSettings( SCTAB nTab );
      79                 :            : 
      80                 :            : private:
      81                 :            :     typedef ::boost::shared_ptr< ScExtTabSettings >     ScExtTabSettingsRef;
      82                 :            :     typedef ::std::map< SCTAB, ScExtTabSettingsRef >    ScExtTabSettingsMap;
      83                 :            : 
      84                 :            :     /** Makes a deep copy of all objects in the passed map. */
      85                 :            :     void                CopyFromMap( const ScExtTabSettingsMap& rMap );
      86                 :            : 
      87                 :            :     ScExtTabSettingsMap maMap;
      88                 :            : };
      89                 :            : 
      90                 :            : // ----------------------------------------------------------------------------
      91                 :            : 
      92                 :         89 : ScExtTabSettingsCont::ScExtTabSettingsCont()
      93                 :            : {
      94                 :         89 : }
      95                 :            : 
      96                 :         89 : ScExtTabSettingsCont::ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc )
      97                 :            : {
      98         [ +  - ]:         89 :     CopyFromMap( rSrc.maMap );
      99                 :         89 : }
     100                 :            : 
     101                 :          0 : ScExtTabSettingsCont& ScExtTabSettingsCont::operator=( const ScExtTabSettingsCont& rSrc )
     102                 :            : {
     103                 :          0 :     CopyFromMap( rSrc.maMap );
     104                 :          0 :     return *this;
     105                 :            : }
     106                 :            : 
     107                 :         97 : const ScExtTabSettings* ScExtTabSettingsCont::GetTabSettings( SCTAB nTab ) const
     108                 :            : {
     109         [ +  - ]:         97 :     ScExtTabSettingsMap::const_iterator aIt = maMap.find( nTab );
     110         [ +  + ]:         97 :     return (aIt == maMap.end()) ? 0 : aIt->second.get();
     111                 :            : }
     112                 :            : 
     113                 :        523 : ScExtTabSettings& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab )
     114                 :            : {
     115                 :        523 :     ScExtTabSettingsRef& rxTabSett = maMap[ nTab ];
     116         [ +  + ]:        523 :     if( !rxTabSett )
     117         [ +  - ]:        272 :         rxTabSett.reset( new ScExtTabSettings );
     118                 :        523 :     return *rxTabSett;
     119                 :            : }
     120                 :            : 
     121                 :         89 : void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap& rMap )
     122                 :            : {
     123                 :         89 :     maMap.clear();
     124         [ +  + ]:        361 :     for( ScExtTabSettingsMap::const_iterator aIt = rMap.begin(), aEnd = rMap.end(); aIt != aEnd; ++aIt )
     125 [ +  - ][ +  - ]:        272 :         maMap[ aIt->first ].reset( new ScExtTabSettings( *aIt->second ) );
         [ +  - ][ +  - ]
     126                 :         89 : }
     127                 :            : 
     128                 :            : // ============================================================================
     129                 :            : 
     130                 :            : /** Implementation struct for ScExtDocOptions containing all members. */
     131 [ +  - ][ +  - ]:        262 : struct ScExtDocOptionsImpl
     132                 :            : {
     133                 :            :     typedef ::std::vector< String > StringVec;
     134                 :            : 
     135                 :            :     ScExtDocSettings    maDocSett;          /// Global document settings.
     136                 :            :     ScExtTabSettingsCont maTabSett;         /// Settings for all sheets.
     137                 :            :     StringVec           maCodeNames;        /// Codenames for all sheets (VBA module names).
     138                 :            :     bool                mbChanged;          /// Use only if something has been changed.
     139                 :            : 
     140                 :            :     explicit            ScExtDocOptionsImpl();
     141                 :            : };
     142                 :            : 
     143                 :         89 : ScExtDocOptionsImpl::ScExtDocOptionsImpl() :
     144 [ +  - ][ +  - ]:         89 :     mbChanged( false )
     145                 :            : {
     146                 :         89 : }
     147                 :            : 
     148                 :            : // ----------------------------------------------------------------------------
     149                 :            : 
     150                 :         89 : ScExtDocOptions::ScExtDocOptions() :
     151         [ +  - ]:         89 :     mxImpl( new ScExtDocOptionsImpl )
     152                 :            : {
     153                 :         89 : }
     154                 :            : 
     155                 :         89 : ScExtDocOptions::ScExtDocOptions( const ScExtDocOptions& rSrc ) :
     156         [ +  - ]:         89 :     mxImpl( new ScExtDocOptionsImpl( *rSrc.mxImpl ) )
     157                 :            : {
     158                 :         89 : }
     159                 :            : 
     160                 :        173 : ScExtDocOptions::~ScExtDocOptions()
     161                 :            : {
     162                 :        173 : }
     163                 :            : 
     164                 :          0 : ScExtDocOptions& ScExtDocOptions::operator=( const ScExtDocOptions& rSrc )
     165                 :            : {
     166                 :          0 :     *mxImpl = *rSrc.mxImpl;
     167                 :          0 :     return *this;
     168                 :            : }
     169                 :            : 
     170                 :          8 : bool ScExtDocOptions::IsChanged() const
     171                 :            : {
     172                 :          8 :     return mxImpl->mbChanged;
     173                 :            : }
     174                 :            : 
     175                 :         93 : void ScExtDocOptions::SetChanged( bool bChanged )
     176                 :            : {
     177                 :         93 :     mxImpl->mbChanged = bChanged;
     178                 :         93 : }
     179                 :            : 
     180                 :          4 : const ScExtDocSettings& ScExtDocOptions::GetDocSettings() const
     181                 :            : {
     182                 :          4 :     return mxImpl->maDocSett;
     183                 :            : }
     184                 :            : 
     185                 :        286 : ScExtDocSettings& ScExtDocOptions::GetDocSettings()
     186                 :            : {
     187                 :        286 :     return mxImpl->maDocSett;
     188                 :            : }
     189                 :            : 
     190                 :         97 : const ScExtTabSettings* ScExtDocOptions::GetTabSettings( SCTAB nTab ) const
     191                 :            : {
     192                 :         97 :     return mxImpl->maTabSett.GetTabSettings( nTab );
     193                 :            : }
     194                 :            : 
     195                 :        523 : ScExtTabSettings& ScExtDocOptions::GetOrCreateTabSettings( SCTAB nTab )
     196                 :            : {
     197                 :        523 :     return mxImpl->maTabSett.GetOrCreateTabSettings( nTab );
     198                 :            : }
     199                 :            : 
     200                 :         51 : SCTAB ScExtDocOptions::GetCodeNameCount() const
     201                 :            : {
     202                 :         51 :     return static_cast< SCTAB >( mxImpl->maCodeNames.size() );
     203                 :            : }
     204                 :            : 
     205                 :         51 : const String& ScExtDocOptions::GetCodeName( SCTAB nTab ) const
     206                 :            : {
     207                 :            :     OSL_ENSURE( (0 <= nTab) && (nTab < GetCodeNameCount()), "ScExtDocOptions::GetCodeName - invalid sheet index" );
     208 [ +  - ][ +  - ]:         51 :     return ((0 <= nTab) && (nTab < GetCodeNameCount())) ? mxImpl->maCodeNames[ static_cast< size_t >( nTab ) ] : EMPTY_STRING;
     209                 :            : }
     210                 :            : 
     211                 :         62 : void ScExtDocOptions::SetCodeName( SCTAB nTab, const String& rCodeName )
     212                 :            : {
     213                 :            :     OSL_ENSURE( nTab >= 0, "ScExtDocOptions::SetCodeName - invalid sheet index" );
     214         [ +  - ]:         62 :     if( nTab >= 0 )
     215                 :            :     {
     216                 :         62 :         size_t nIndex = static_cast< size_t >( nTab );
     217         [ +  - ]:         62 :         if( nIndex >= mxImpl->maCodeNames.size() )
     218                 :         62 :             mxImpl->maCodeNames.resize( nIndex + 1 );
     219                 :         62 :         mxImpl->maCodeNames[ nIndex ] = rCodeName;
     220                 :            :     }
     221                 :         62 : }
     222                 :            : 
     223                 :            : // ============================================================================
     224                 :            : 
     225                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10