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