xref: /aoo42x/main/sc/source/ui/view/scextopt.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 #include "scextopt.hxx"
31 
32 #include <vector>
33 #include <map>
34 #include <boost/shared_ptr.hpp>
35 
36 // ============================================================================
37 
38 ScExtDocSettings::ScExtDocSettings() :
39     mfTabBarWidth( -1.0 ),
40     mnLinkCnt( 0 ),
41     mnDisplTab( 0 )
42 {
43 }
44 
45 // ============================================================================
46 
47 ScExtTabSettings::ScExtTabSettings() :
48     maUsedArea( ScAddress::INITIALIZE_INVALID ),
49     maCursor( ScAddress::INITIALIZE_INVALID ),
50     maFirstVis( ScAddress::INITIALIZE_INVALID ),
51     maSecondVis( ScAddress::INITIALIZE_INVALID ),
52     maFreezePos( 0, 0, 0 ),
53     maSplitPos( 0, 0 ),
54     meActivePane( SCEXT_PANE_TOPLEFT ),
55     maGridColor( COL_AUTO ),
56     mnNormalZoom( 0 ),
57     mnPageZoom( 0 ),
58     mbSelected( false ),
59     mbFrozenPanes( false ),
60     mbPageMode( false )
61 {
62 }
63 
64 // ============================================================================
65 
66 /** A container for ScExtTabSettings objects.
67     @descr  Internally, a std::map with shared pointers to ScExtTabSettings is
68     used. The copy constructor and assignment operator make deep copies of the
69     objects. */
70 class ScExtTabSettingsCont
71 {
72 public:
73     explicit            ScExtTabSettingsCont();
74                         ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc );
75     ScExtTabSettingsCont& operator=( const ScExtTabSettingsCont& rSrc );
76 
77     const ScExtTabSettings* GetTabSettings( SCTAB nTab ) const;
78     ScExtTabSettings&   GetOrCreateTabSettings( SCTAB nTab );
79 
80 private:
81     typedef ::boost::shared_ptr< ScExtTabSettings >     ScExtTabSettingsRef;
82     typedef ::std::map< SCTAB, ScExtTabSettingsRef >    ScExtTabSettingsMap;
83 
84     /** Makes a deep copy of all objects in the passed map. */
85     void                CopyFromMap( const ScExtTabSettingsMap& rMap );
86 
87     ScExtTabSettingsMap maMap;
88 };
89 
90 // ----------------------------------------------------------------------------
91 
92 ScExtTabSettingsCont::ScExtTabSettingsCont()
93 {
94 }
95 
96 ScExtTabSettingsCont::ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc )
97 {
98     CopyFromMap( rSrc.maMap );
99 }
100 
101 ScExtTabSettingsCont& ScExtTabSettingsCont::operator=( const ScExtTabSettingsCont& rSrc )
102 {
103     CopyFromMap( rSrc.maMap );
104     return *this;
105 }
106 
107 const ScExtTabSettings* ScExtTabSettingsCont::GetTabSettings( SCTAB nTab ) const
108 {
109     ScExtTabSettingsMap::const_iterator aIt = maMap.find( nTab );
110     return (aIt == maMap.end()) ? 0 : aIt->second.get();
111 }
112 
113 ScExtTabSettings& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab )
114 {
115     ScExtTabSettingsRef& rxTabSett = maMap[ nTab ];
116     if( !rxTabSett )
117         rxTabSett.reset( new ScExtTabSettings );
118     return *rxTabSett;
119 }
120 
121 void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap& rMap )
122 {
123     maMap.clear();
124     for( ScExtTabSettingsMap::const_iterator aIt = rMap.begin(), aEnd = rMap.end(); aIt != aEnd; ++aIt )
125         maMap[ aIt->first ].reset( new ScExtTabSettings( *aIt->second ) );
126 }
127 
128 // ============================================================================
129 
130 /** Implementation struct for ScExtDocOptions containing all members. */
131 struct ScExtDocOptionsImpl
132 {
133     typedef ::std::vector< String > StringVec;
134 
135     ScExtDocSettings    maDocSett;          /// Global document settings.
136     ScExtTabSettingsCont maTabSett;         /// Settings for all sheets.
137     StringVec           maCodeNames;        /// Codenames for all sheets (VBA module names).
138     bool                mbChanged;          /// Use only if something has been changed.
139 
140     explicit            ScExtDocOptionsImpl();
141 };
142 
143 ScExtDocOptionsImpl::ScExtDocOptionsImpl() :
144     mbChanged( false )
145 {
146 }
147 
148 // ----------------------------------------------------------------------------
149 
150 ScExtDocOptions::ScExtDocOptions() :
151     mxImpl( new ScExtDocOptionsImpl )
152 {
153 }
154 
155 ScExtDocOptions::ScExtDocOptions( const ScExtDocOptions& rSrc ) :
156     mxImpl( new ScExtDocOptionsImpl( *rSrc.mxImpl ) )
157 {
158 }
159 
160 ScExtDocOptions::~ScExtDocOptions()
161 {
162 }
163 
164 ScExtDocOptions& ScExtDocOptions::operator=( const ScExtDocOptions& rSrc )
165 {
166     *mxImpl = *rSrc.mxImpl;
167     return *this;
168 }
169 
170 bool ScExtDocOptions::IsChanged() const
171 {
172     return mxImpl->mbChanged;
173 }
174 
175 void ScExtDocOptions::SetChanged( bool bChanged )
176 {
177     mxImpl->mbChanged = bChanged;
178 }
179 
180 const ScExtDocSettings& ScExtDocOptions::GetDocSettings() const
181 {
182     return mxImpl->maDocSett;
183 }
184 
185 ScExtDocSettings& ScExtDocOptions::GetDocSettings()
186 {
187     return mxImpl->maDocSett;
188 }
189 
190 const ScExtTabSettings* ScExtDocOptions::GetTabSettings( SCTAB nTab ) const
191 {
192     return mxImpl->maTabSett.GetTabSettings( nTab );
193 }
194 
195 ScExtTabSettings& ScExtDocOptions::GetOrCreateTabSettings( SCTAB nTab )
196 {
197     return mxImpl->maTabSett.GetOrCreateTabSettings( nTab );
198 }
199 
200 SCTAB ScExtDocOptions::GetCodeNameCount() const
201 {
202     return static_cast< SCTAB >( mxImpl->maCodeNames.size() );
203 }
204 
205 const String& ScExtDocOptions::GetCodeName( SCTAB nTab ) const
206 {
207     DBG_ASSERT( (0 <= nTab) && (nTab < GetCodeNameCount()), "ScExtDocOptions::GetCodeName - invalid sheet index" );
208     return ((0 <= nTab) && (nTab < GetCodeNameCount())) ? mxImpl->maCodeNames[ static_cast< size_t >( nTab ) ] : EMPTY_STRING;
209 }
210 
211 void ScExtDocOptions::SetCodeName( SCTAB nTab, const String& rCodeName )
212 {
213     DBG_ASSERT( nTab >= 0, "ScExtDocOptions::SetCodeName - invalid sheet index" );
214     if( nTab >= 0 )
215     {
216         size_t nIndex = static_cast< size_t >( nTab );
217         if( nIndex >= mxImpl->maCodeNames.size() )
218             mxImpl->maCodeNames.resize( nIndex + 1 );
219         mxImpl->maCodeNames[ nIndex ] = rCodeName;
220     }
221 }
222 
223 // ============================================================================
224 
225