LCOV - code coverage report
Current view: top level - libreoffice/sc/source/ui/view - scextopt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 57 67 85.1 %
Date: 2012-12-27 Functions: 21 26 80.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 "scextopt.hxx"
      21             : 
      22             : #include <vector>
      23             : #include <map>
      24             : #include <boost/shared_ptr.hpp>
      25             : 
      26             : // ============================================================================
      27             : 
      28          21 : ScExtDocSettings::ScExtDocSettings() :
      29             :     mfTabBarWidth( -1.0 ),
      30             :     mnLinkCnt( 0 ),
      31          21 :     mnDisplTab( 0 )
      32             : {
      33          21 : }
      34             : 
      35             : // ============================================================================
      36             : 
      37          76 : ScExtTabSettings::ScExtTabSettings() :
      38             :     maUsedArea( ScAddress::INITIALIZE_INVALID ),
      39             :     maCursor( ScAddress::INITIALIZE_INVALID ),
      40             :     maFirstVis( ScAddress::INITIALIZE_INVALID ),
      41             :     maSecondVis( ScAddress::INITIALIZE_INVALID ),
      42             :     maFreezePos( 0, 0, 0 ),
      43             :     maSplitPos( 0, 0 ),
      44             :     meActivePane( SCEXT_PANE_TOPLEFT ),
      45             :     maGridColor( COL_AUTO ),
      46             :     mnNormalZoom( 0 ),
      47             :     mnPageZoom( 0 ),
      48             :     mbSelected( false ),
      49             :     mbFrozenPanes( false ),
      50             :     mbPageMode( false ),
      51          76 :     mbShowGrid( true )
      52             : {
      53          76 : }
      54             : 
      55             : // ============================================================================
      56             : 
      57             : /** A container for ScExtTabSettings objects.
      58             :     @descr  Internally, a std::map with shared pointers to ScExtTabSettings is
      59             :     used. The copy constructor and assignment operator make deep copies of the
      60             :     objects. */
      61          40 : class ScExtTabSettingsCont
      62             : {
      63             : public:
      64             :     explicit            ScExtTabSettingsCont();
      65             :                         ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc );
      66             :     ScExtTabSettingsCont& operator=( const ScExtTabSettingsCont& rSrc );
      67             : 
      68             :     const ScExtTabSettings* GetTabSettings( SCTAB nTab ) const;
      69             :     ScExtTabSettings&   GetOrCreateTabSettings( SCTAB nTab );
      70             : 
      71             : private:
      72             :     typedef ::boost::shared_ptr< ScExtTabSettings >     ScExtTabSettingsRef;
      73             :     typedef ::std::map< SCTAB, ScExtTabSettingsRef >    ScExtTabSettingsMap;
      74             : 
      75             :     /** Makes a deep copy of all objects in the passed map. */
      76             :     void                CopyFromMap( const ScExtTabSettingsMap& rMap );
      77             : 
      78             :     ScExtTabSettingsMap maMap;
      79             : };
      80             : 
      81             : // ----------------------------------------------------------------------------
      82             : 
      83          21 : ScExtTabSettingsCont::ScExtTabSettingsCont()
      84             : {
      85          21 : }
      86             : 
      87          20 : ScExtTabSettingsCont::ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc )
      88             : {
      89          20 :     CopyFromMap( rSrc.maMap );
      90          20 : }
      91             : 
      92           0 : ScExtTabSettingsCont& ScExtTabSettingsCont::operator=( const ScExtTabSettingsCont& rSrc )
      93             : {
      94           0 :     CopyFromMap( rSrc.maMap );
      95           0 :     return *this;
      96             : }
      97             : 
      98          22 : const ScExtTabSettings* ScExtTabSettingsCont::GetTabSettings( SCTAB nTab ) const
      99             : {
     100          22 :     ScExtTabSettingsMap::const_iterator aIt = maMap.find( nTab );
     101          22 :     return (aIt == maMap.end()) ? 0 : aIt->second.get();
     102             : }
     103             : 
     104         166 : ScExtTabSettings& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab )
     105             : {
     106         166 :     ScExtTabSettingsRef& rxTabSett = maMap[ nTab ];
     107         166 :     if( !rxTabSett )
     108          76 :         rxTabSett.reset( new ScExtTabSettings );
     109         166 :     return *rxTabSett;
     110             : }
     111             : 
     112          20 : void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap& rMap )
     113             : {
     114          20 :     maMap.clear();
     115          96 :     for( ScExtTabSettingsMap::const_iterator aIt = rMap.begin(), aEnd = rMap.end(); aIt != aEnd; ++aIt )
     116          76 :         maMap[ aIt->first ].reset( new ScExtTabSettings( *aIt->second ) );
     117          20 : }
     118             : 
     119             : // ============================================================================
     120             : 
     121             : /** Implementation struct for ScExtDocOptions containing all members. */
     122          60 : struct ScExtDocOptionsImpl
     123             : {
     124             :     typedef ::std::vector< String > StringVec;
     125             : 
     126             :     ScExtDocSettings    maDocSett;          /// Global document settings.
     127             :     ScExtTabSettingsCont maTabSett;         /// Settings for all sheets.
     128             :     StringVec           maCodeNames;        /// Codenames for all sheets (VBA module names).
     129             :     bool                mbChanged;          /// Use only if something has been changed.
     130             : 
     131             :     explicit            ScExtDocOptionsImpl();
     132             : };
     133             : 
     134          21 : ScExtDocOptionsImpl::ScExtDocOptionsImpl() :
     135          21 :     mbChanged( false )
     136             : {
     137          21 : }
     138             : 
     139             : // ----------------------------------------------------------------------------
     140             : 
     141          21 : ScExtDocOptions::ScExtDocOptions() :
     142          21 :     mxImpl( new ScExtDocOptionsImpl )
     143             : {
     144          21 : }
     145             : 
     146          20 : ScExtDocOptions::ScExtDocOptions( const ScExtDocOptions& rSrc ) :
     147          20 :     mxImpl( new ScExtDocOptionsImpl( *rSrc.mxImpl ) )
     148             : {
     149          20 : }
     150             : 
     151          40 : ScExtDocOptions::~ScExtDocOptions()
     152             : {
     153          40 : }
     154             : 
     155           0 : ScExtDocOptions& ScExtDocOptions::operator=( const ScExtDocOptions& rSrc )
     156             : {
     157           0 :     *mxImpl = *rSrc.mxImpl;
     158           0 :     return *this;
     159             : }
     160             : 
     161           0 : bool ScExtDocOptions::IsChanged() const
     162             : {
     163           0 :     return mxImpl->mbChanged;
     164             : }
     165             : 
     166          20 : void ScExtDocOptions::SetChanged( bool bChanged )
     167             : {
     168          20 :     mxImpl->mbChanged = bChanged;
     169          20 : }
     170             : 
     171           0 : const ScExtDocSettings& ScExtDocOptions::GetDocSettings() const
     172             : {
     173           0 :     return mxImpl->maDocSett;
     174             : }
     175             : 
     176          65 : ScExtDocSettings& ScExtDocOptions::GetDocSettings()
     177             : {
     178          65 :     return mxImpl->maDocSett;
     179             : }
     180             : 
     181          22 : const ScExtTabSettings* ScExtDocOptions::GetTabSettings( SCTAB nTab ) const
     182             : {
     183          22 :     return mxImpl->maTabSett.GetTabSettings( nTab );
     184             : }
     185             : 
     186         166 : ScExtTabSettings& ScExtDocOptions::GetOrCreateTabSettings( SCTAB nTab )
     187             : {
     188         166 :     return mxImpl->maTabSett.GetOrCreateTabSettings( nTab );
     189             : }
     190             : 
     191          12 : SCTAB ScExtDocOptions::GetCodeNameCount() const
     192             : {
     193          12 :     return static_cast< SCTAB >( mxImpl->maCodeNames.size() );
     194             : }
     195             : 
     196           9 : const String& ScExtDocOptions::GetCodeName( SCTAB nTab ) const
     197             : {
     198             :     OSL_ENSURE( (0 <= nTab) && (nTab < GetCodeNameCount()), "ScExtDocOptions::GetCodeName - invalid sheet index" );
     199           9 :     return ((0 <= nTab) && (nTab < GetCodeNameCount())) ? mxImpl->maCodeNames[ static_cast< size_t >( nTab ) ] : EMPTY_STRING;
     200             : }
     201             : 
     202          10 : void ScExtDocOptions::SetCodeName( SCTAB nTab, const String& rCodeName )
     203             : {
     204             :     OSL_ENSURE( nTab >= 0, "ScExtDocOptions::SetCodeName - invalid sheet index" );
     205          10 :     if( nTab >= 0 )
     206             :     {
     207          10 :         size_t nIndex = static_cast< size_t >( nTab );
     208          10 :         if( nIndex >= mxImpl->maCodeNames.size() )
     209          10 :             mxImpl->maCodeNames.resize( nIndex + 1 );
     210          10 :         mxImpl->maCodeNames[ nIndex ] = rCodeName;
     211             :     }
     212          10 : }
     213             : 
     214             : // ============================================================================
     215             : 
     216             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10