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