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