Bump version to 4.3-4
[LibreOffice.git] / sc / source / ui / view / scextopt.cxx
blob1dad56395ffc21b4d5a19616c7ba87b28f8d5a01
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "scextopt.hxx"
22 #include <vector>
23 #include <map>
24 #include <boost/shared_ptr.hpp>
26 ScExtDocSettings::ScExtDocSettings() :
27 mfTabBarWidth( -1.0 ),
28 mnLinkCnt( 0 ),
29 mnDisplTab( 0 )
33 ScExtTabSettings::ScExtTabSettings() :
34 maUsedArea( ScAddress::INITIALIZE_INVALID ),
35 maCursor( ScAddress::INITIALIZE_INVALID ),
36 maFirstVis( ScAddress::INITIALIZE_INVALID ),
37 maSecondVis( ScAddress::INITIALIZE_INVALID ),
38 maFreezePos( 0, 0, 0 ),
39 maSplitPos( 0, 0 ),
40 meActivePane( SCEXT_PANE_TOPLEFT ),
41 maGridColor( COL_AUTO ),
42 mnNormalZoom( 0 ),
43 mnPageZoom( 0 ),
44 mbSelected( false ),
45 mbFrozenPanes( false ),
46 mbPageMode( false ),
47 mbShowGrid( true )
51 /** A container for ScExtTabSettings objects.
52 @descr Internally, a std::map with shared pointers to ScExtTabSettings is
53 used. The copy constructor and assignment operator make deep copies of the
54 objects. */
55 class ScExtTabSettingsCont
57 public:
58 explicit ScExtTabSettingsCont();
59 ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc );
60 ScExtTabSettingsCont& operator=( const ScExtTabSettingsCont& rSrc );
62 const ScExtTabSettings* GetTabSettings( SCTAB nTab ) const;
63 ScExtTabSettings& GetOrCreateTabSettings( SCTAB nTab );
65 SCTAB GetLastTab() const;
67 private:
68 typedef ::boost::shared_ptr< ScExtTabSettings > ScExtTabSettingsRef;
69 typedef ::std::map< SCTAB, ScExtTabSettingsRef > ScExtTabSettingsMap;
71 /** Makes a deep copy of all objects in the passed map. */
72 void CopyFromMap( const ScExtTabSettingsMap& rMap );
74 ScExtTabSettingsMap maMap;
77 ScExtTabSettingsCont::ScExtTabSettingsCont()
81 ScExtTabSettingsCont::ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc )
83 CopyFromMap( rSrc.maMap );
86 ScExtTabSettingsCont& ScExtTabSettingsCont::operator=( const ScExtTabSettingsCont& rSrc )
88 CopyFromMap( rSrc.maMap );
89 return *this;
92 const ScExtTabSettings* ScExtTabSettingsCont::GetTabSettings( SCTAB nTab ) const
94 ScExtTabSettingsMap::const_iterator aIt = maMap.find( nTab );
95 return (aIt == maMap.end()) ? 0 : aIt->second.get();
98 ScExtTabSettings& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab )
100 ScExtTabSettingsRef& rxTabSett = maMap[ nTab ];
101 if( !rxTabSett )
102 rxTabSett.reset( new ScExtTabSettings );
103 return *rxTabSett;
106 SCTAB ScExtTabSettingsCont::GetLastTab() const
108 return maMap.empty() ? -1 : maMap.rbegin()->first;
111 void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap& rMap )
113 maMap.clear();
114 for( ScExtTabSettingsMap::const_iterator aIt = rMap.begin(), aEnd = rMap.end(); aIt != aEnd; ++aIt )
115 maMap[ aIt->first ].reset( new ScExtTabSettings( *aIt->second ) );
118 /** Implementation struct for ScExtDocOptions containing all members. */
119 struct ScExtDocOptionsImpl
121 typedef ::std::vector< OUString > StringVec;
123 ScExtDocSettings maDocSett; /// Global document settings.
124 ScExtTabSettingsCont maTabSett; /// Settings for all sheets.
125 StringVec maCodeNames; /// Codenames for all sheets (VBA module names).
126 bool mbChanged; /// Use only if something has been changed.
128 explicit ScExtDocOptionsImpl();
131 ScExtDocOptionsImpl::ScExtDocOptionsImpl() :
132 mbChanged( false )
136 ScExtDocOptions::ScExtDocOptions() :
137 mxImpl( new ScExtDocOptionsImpl )
141 ScExtDocOptions::ScExtDocOptions( const ScExtDocOptions& rSrc ) :
142 mxImpl( new ScExtDocOptionsImpl( *rSrc.mxImpl ) )
146 ScExtDocOptions::~ScExtDocOptions()
150 ScExtDocOptions& ScExtDocOptions::operator=( const ScExtDocOptions& rSrc )
152 *mxImpl = *rSrc.mxImpl;
153 return *this;
156 bool ScExtDocOptions::IsChanged() const
158 return mxImpl->mbChanged;
161 void ScExtDocOptions::SetChanged( bool bChanged )
163 mxImpl->mbChanged = bChanged;
166 const ScExtDocSettings& ScExtDocOptions::GetDocSettings() const
168 return mxImpl->maDocSett;
171 ScExtDocSettings& ScExtDocOptions::GetDocSettings()
173 return mxImpl->maDocSett;
176 const ScExtTabSettings* ScExtDocOptions::GetTabSettings( SCTAB nTab ) const
178 return mxImpl->maTabSett.GetTabSettings( nTab );
181 SCTAB ScExtDocOptions::GetLastTab() const
183 return mxImpl->maTabSett.GetLastTab();
186 ScExtTabSettings& ScExtDocOptions::GetOrCreateTabSettings( SCTAB nTab )
188 return mxImpl->maTabSett.GetOrCreateTabSettings( nTab );
191 SCTAB ScExtDocOptions::GetCodeNameCount() const
193 return static_cast< SCTAB >( mxImpl->maCodeNames.size() );
196 const OUString& ScExtDocOptions::GetCodeName( SCTAB nTab ) const
198 OSL_ENSURE( (0 <= nTab) && (nTab < GetCodeNameCount()), "ScExtDocOptions::GetCodeName - invalid sheet index" );
199 return ((0 <= nTab) && (nTab < GetCodeNameCount())) ? mxImpl->maCodeNames[ static_cast< size_t >( nTab ) ] : EMPTY_OUSTRING;
202 void ScExtDocOptions::SetCodeName( SCTAB nTab, const OUString& rCodeName )
204 OSL_ENSURE( nTab >= 0, "ScExtDocOptions::SetCodeName - invalid sheet index" );
205 if( nTab >= 0 )
207 size_t nIndex = static_cast< size_t >( nTab );
208 if( nIndex >= mxImpl->maCodeNames.size() )
209 mxImpl->maCodeNames.resize( nIndex + 1 );
210 mxImpl->maCodeNames[ nIndex ] = rCodeName;
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */