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