xref: /trunk/main/sc/source/ui/view/scextopt.cxx (revision ffd38472365e95f6a578737bc9a5eb0fac624a86)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_sc.hxx"
24 #include "scextopt.hxx"
25 
26 #include <vector>
27 #include <map>
28 #include <boost/shared_ptr.hpp>
29 
30 // ============================================================================
31 
32 ScExtDocSettings::ScExtDocSettings() :
33     mfTabBarWidth( -1.0 ),
34     mnLinkCnt( 0 ),
35     mnDisplTab( 0 )
36 {
37 }
38 
39 // ============================================================================
40 
41 ScExtTabSettings::ScExtTabSettings() :
42     maUsedArea( ScAddress::INITIALIZE_INVALID ),
43     maCursor( ScAddress::INITIALIZE_INVALID ),
44     maFirstVis( ScAddress::INITIALIZE_INVALID ),
45     maSecondVis( ScAddress::INITIALIZE_INVALID ),
46     maFreezePos( 0, 0, 0 ),
47     maSplitPos( 0, 0 ),
48     meActivePane( SCEXT_PANE_TOPLEFT ),
49     maGridColor( COL_AUTO ),
50     mnNormalZoom( 0 ),
51     mnPageZoom( 0 ),
52     mbSelected( false ),
53     mbFrozenPanes( false ),
54     mbPageMode( false )
55 {
56 }
57 
58 // ============================================================================
59 
60 /** A container for ScExtTabSettings objects.
61     @descr  Internally, a std::map with shared pointers to ScExtTabSettings is
62     used. The copy constructor and assignment operator make deep copies of the
63     objects. */
64 class ScExtTabSettingsCont
65 {
66 public:
67     explicit            ScExtTabSettingsCont();
68                         ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc );
69     ScExtTabSettingsCont& operator=( const ScExtTabSettingsCont& rSrc );
70 
71     const ScExtTabSettings* GetTabSettings( SCTAB nTab ) const;
72     ScExtTabSettings&   GetOrCreateTabSettings( SCTAB nTab );
73 
74 private:
75     typedef ::boost::shared_ptr< ScExtTabSettings >     ScExtTabSettingsRef;
76     typedef ::std::map< SCTAB, ScExtTabSettingsRef >    ScExtTabSettingsMap;
77 
78     /** Makes a deep copy of all objects in the passed map. */
79     void                CopyFromMap( const ScExtTabSettingsMap& rMap );
80 
81     ScExtTabSettingsMap maMap;
82 };
83 
84 // ----------------------------------------------------------------------------
85 
86 ScExtTabSettingsCont::ScExtTabSettingsCont()
87 {
88 }
89 
90 ScExtTabSettingsCont::ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc )
91 {
92     CopyFromMap( rSrc.maMap );
93 }
94 
95 ScExtTabSettingsCont& ScExtTabSettingsCont::operator=( const ScExtTabSettingsCont& rSrc )
96 {
97     CopyFromMap( rSrc.maMap );
98     return *this;
99 }
100 
101 const ScExtTabSettings* ScExtTabSettingsCont::GetTabSettings( SCTAB nTab ) const
102 {
103     ScExtTabSettingsMap::const_iterator aIt = maMap.find( nTab );
104     return (aIt == maMap.end()) ? 0 : aIt->second.get();
105 }
106 
107 ScExtTabSettings& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab )
108 {
109     ScExtTabSettingsRef& rxTabSett = maMap[ nTab ];
110     if( !rxTabSett )
111         rxTabSett.reset( new ScExtTabSettings );
112     return *rxTabSett;
113 }
114 
115 void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap& rMap )
116 {
117     maMap.clear();
118     for( ScExtTabSettingsMap::const_iterator aIt = rMap.begin(), aEnd = rMap.end(); aIt != aEnd; ++aIt )
119         maMap[ aIt->first ].reset( new ScExtTabSettings( *aIt->second ) );
120 }
121 
122 // ============================================================================
123 
124 /** Implementation struct for ScExtDocOptions containing all members. */
125 struct ScExtDocOptionsImpl
126 {
127     typedef ::std::vector< String > StringVec;
128 
129     ScExtDocSettings    maDocSett;          // Global document settings.
130     ScExtTabSettingsCont maTabSett;         // Settings for all sheets.
131     StringVec           maCodeNames;        // Codenames for all sheets (VBA module names).
132     bool                mbChanged;          // Use only if something has been changed.
133 
134     explicit            ScExtDocOptionsImpl();
135 };
136 
137 ScExtDocOptionsImpl::ScExtDocOptionsImpl() :
138     mbChanged( false )
139 {
140 }
141 
142 // ----------------------------------------------------------------------------
143 
144 ScExtDocOptions::ScExtDocOptions() :
145     mxImpl( new ScExtDocOptionsImpl )
146 {
147 }
148 
149 ScExtDocOptions::ScExtDocOptions( const ScExtDocOptions& rSrc ) :
150     mxImpl( new ScExtDocOptionsImpl( *rSrc.mxImpl ) )
151 {
152 }
153 
154 ScExtDocOptions::~ScExtDocOptions()
155 {
156 }
157 
158 ScExtDocOptions& ScExtDocOptions::operator=( const ScExtDocOptions& rSrc )
159 {
160     *mxImpl = *rSrc.mxImpl;
161     return *this;
162 }
163 
164 bool ScExtDocOptions::IsChanged() const
165 {
166     return mxImpl->mbChanged;
167 }
168 
169 void ScExtDocOptions::SetChanged( bool bChanged )
170 {
171     mxImpl->mbChanged = bChanged;
172 }
173 
174 const ScExtDocSettings& ScExtDocOptions::GetDocSettings() const
175 {
176     return mxImpl->maDocSett;
177 }
178 
179 ScExtDocSettings& ScExtDocOptions::GetDocSettings()
180 {
181     return mxImpl->maDocSett;
182 }
183 
184 const ScExtTabSettings* ScExtDocOptions::GetTabSettings( SCTAB nTab ) const
185 {
186     return mxImpl->maTabSett.GetTabSettings( nTab );
187 }
188 
189 ScExtTabSettings& ScExtDocOptions::GetOrCreateTabSettings( SCTAB nTab )
190 {
191     return mxImpl->maTabSett.GetOrCreateTabSettings( nTab );
192 }
193 
194 SCTAB ScExtDocOptions::GetCodeNameCount() const
195 {
196     return static_cast< SCTAB >( mxImpl->maCodeNames.size() );
197 }
198 
199 const String& ScExtDocOptions::GetCodeName( SCTAB nTab ) const
200 {
201     DBG_ASSERT( (0 <= nTab) && (nTab < GetCodeNameCount()), "ScExtDocOptions::GetCodeName - invalid sheet index" );
202     return ((0 <= nTab) && (nTab < GetCodeNameCount())) ? mxImpl->maCodeNames[ static_cast< size_t >( nTab ) ] : EMPTY_STRING;
203 }
204 
205 void ScExtDocOptions::SetCodeName( SCTAB nTab, const String& rCodeName )
206 {
207     DBG_ASSERT( nTab >= 0, "ScExtDocOptions::SetCodeName - invalid sheet index" );
208     if( nTab >= 0 )
209     {
210         size_t nIndex = static_cast< size_t >( nTab );
211         if( nIndex >= mxImpl->maCodeNames.size() )
212             mxImpl->maCodeNames.resize( nIndex + 1 );
213         mxImpl->maCodeNames[ nIndex ] = rCodeName;
214     }
215 }
216 
217 /* vim: set noet sw=4 ts=4: */
218