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