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 198 : ScExtDocSettings::ScExtDocSettings() :
27 : mfTabBarWidth( -1.0 ),
28 : mnLinkCnt( 0 ),
29 198 : mnDisplTab( 0 )
30 : {
31 198 : }
32 :
33 434 : 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 434 : mbShowGrid( true )
48 : {
49 434 : }
50 :
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 358 : class ScExtTabSettingsCont
56 : {
57 : public:
58 : explicit ScExtTabSettingsCont();
59 : ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc );
60 : ScExtTabSettingsCont& operator=( const ScExtTabSettingsCont& rSrc );
61 :
62 : const ScExtTabSettings* GetTabSettings( SCTAB nTab ) const;
63 : ScExtTabSettings& GetOrCreateTabSettings( SCTAB nTab );
64 :
65 : SCTAB GetLastTab() const;
66 :
67 : private:
68 : typedef ::boost::shared_ptr< ScExtTabSettings > ScExtTabSettingsRef;
69 : typedef ::std::map< SCTAB, ScExtTabSettingsRef > ScExtTabSettingsMap;
70 :
71 : /** Makes a deep copy of all objects in the passed map. */
72 : void CopyFromMap( const ScExtTabSettingsMap& rMap );
73 :
74 : ScExtTabSettingsMap maMap;
75 : };
76 :
77 198 : ScExtTabSettingsCont::ScExtTabSettingsCont()
78 : {
79 198 : }
80 :
81 160 : ScExtTabSettingsCont::ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc )
82 : {
83 160 : CopyFromMap( rSrc.maMap );
84 160 : }
85 :
86 0 : ScExtTabSettingsCont& ScExtTabSettingsCont::operator=( const ScExtTabSettingsCont& rSrc )
87 : {
88 0 : CopyFromMap( rSrc.maMap );
89 0 : return *this;
90 : }
91 :
92 552 : const ScExtTabSettings* ScExtTabSettingsCont::GetTabSettings( SCTAB nTab ) const
93 : {
94 552 : ScExtTabSettingsMap::const_iterator aIt = maMap.find( nTab );
95 552 : return (aIt == maMap.end()) ? 0 : aIt->second.get();
96 : }
97 :
98 750 : ScExtTabSettings& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab )
99 : {
100 750 : ScExtTabSettingsRef& rxTabSett = maMap[ nTab ];
101 750 : if( !rxTabSett )
102 434 : rxTabSett.reset( new ScExtTabSettings );
103 750 : return *rxTabSett;
104 : }
105 :
106 52 : SCTAB ScExtTabSettingsCont::GetLastTab() const
107 : {
108 52 : return maMap.empty() ? -1 : maMap.rbegin()->first;
109 : }
110 :
111 160 : void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap& rMap )
112 : {
113 160 : maMap.clear();
114 608 : for( ScExtTabSettingsMap::const_iterator aIt = rMap.begin(), aEnd = rMap.end(); aIt != aEnd; ++aIt )
115 448 : maMap[ aIt->first ].reset( new ScExtTabSettings( *aIt->second ) );
116 160 : }
117 :
118 : /** Implementation struct for ScExtDocOptions containing all members. */
119 518 : struct ScExtDocOptionsImpl
120 : {
121 : typedef ::std::vector< OUString > StringVec;
122 :
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.
127 :
128 : explicit ScExtDocOptionsImpl();
129 : };
130 :
131 198 : ScExtDocOptionsImpl::ScExtDocOptionsImpl() :
132 198 : mbChanged( false )
133 : {
134 198 : }
135 :
136 198 : ScExtDocOptions::ScExtDocOptions() :
137 198 : mxImpl( new ScExtDocOptionsImpl )
138 : {
139 198 : }
140 :
141 160 : ScExtDocOptions::ScExtDocOptions( const ScExtDocOptions& rSrc ) :
142 160 : mxImpl( new ScExtDocOptionsImpl( *rSrc.mxImpl ) )
143 : {
144 160 : }
145 :
146 358 : ScExtDocOptions::~ScExtDocOptions()
147 : {
148 358 : }
149 :
150 0 : ScExtDocOptions& ScExtDocOptions::operator=( const ScExtDocOptions& rSrc )
151 : {
152 0 : *mxImpl = *rSrc.mxImpl;
153 0 : return *this;
154 : }
155 :
156 104 : bool ScExtDocOptions::IsChanged() const
157 : {
158 104 : return mxImpl->mbChanged;
159 : }
160 :
161 196 : void ScExtDocOptions::SetChanged( bool bChanged )
162 : {
163 196 : mxImpl->mbChanged = bChanged;
164 196 : }
165 :
166 52 : const ScExtDocSettings& ScExtDocOptions::GetDocSettings() const
167 : {
168 52 : return mxImpl->maDocSett;
169 : }
170 :
171 636 : ScExtDocSettings& ScExtDocOptions::GetDocSettings()
172 : {
173 636 : return mxImpl->maDocSett;
174 : }
175 :
176 552 : const ScExtTabSettings* ScExtDocOptions::GetTabSettings( SCTAB nTab ) const
177 : {
178 552 : return mxImpl->maTabSett.GetTabSettings( nTab );
179 : }
180 :
181 52 : SCTAB ScExtDocOptions::GetLastTab() const
182 : {
183 52 : return mxImpl->maTabSett.GetLastTab();
184 : }
185 :
186 750 : ScExtTabSettings& ScExtDocOptions::GetOrCreateTabSettings( SCTAB nTab )
187 : {
188 750 : return mxImpl->maTabSett.GetOrCreateTabSettings( nTab );
189 : }
190 :
191 366 : SCTAB ScExtDocOptions::GetCodeNameCount() const
192 : {
193 366 : return static_cast< SCTAB >( mxImpl->maCodeNames.size() );
194 : }
195 :
196 174 : const OUString& ScExtDocOptions::GetCodeName( SCTAB nTab ) const
197 : {
198 : OSL_ENSURE( (0 <= nTab) && (nTab < GetCodeNameCount()), "ScExtDocOptions::GetCodeName - invalid sheet index" );
199 174 : return ((0 <= nTab) && (nTab < GetCodeNameCount())) ? mxImpl->maCodeNames[ static_cast< size_t >( nTab ) ] : EMPTY_OUSTRING;
200 : }
201 :
202 178 : void ScExtDocOptions::SetCodeName( SCTAB nTab, const OUString& rCodeName )
203 : {
204 : OSL_ENSURE( nTab >= 0, "ScExtDocOptions::SetCodeName - invalid sheet index" );
205 178 : if( nTab >= 0 )
206 : {
207 178 : size_t nIndex = static_cast< size_t >( nTab );
208 178 : if( nIndex >= mxImpl->maCodeNames.size() )
209 178 : mxImpl->maCodeNames.resize( nIndex + 1 );
210 178 : mxImpl->maCodeNames[ nIndex ] = rCodeName;
211 : }
212 406 : }
213 :
214 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|