update dev300-m58
[ooovba.git] / sc / source / ui / view / scextopt.cxx
blob8ca5fc2c7a26b983150c8c0ec6dbf8f6406248d5
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scextopt.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
33 #include "scextopt.hxx"
35 #include <vector>
36 #include <map>
37 #include <boost/shared_ptr.hpp>
39 // ============================================================================
41 ScExtDocSettings::ScExtDocSettings() :
42 maOleSize( ScAddress::INITIALIZE_INVALID ),
43 mfTabBarWidth( -1.0 ),
44 mnLinkCnt( 0 ),
45 mnDisplTab( 0 )
49 // ============================================================================
51 ScExtTabSettings::ScExtTabSettings() :
52 maUsedArea( ScAddress::INITIALIZE_INVALID ),
53 maCursor( ScAddress::INITIALIZE_INVALID ),
54 maFirstVis( ScAddress::INITIALIZE_INVALID ),
55 maSecondVis( ScAddress::INITIALIZE_INVALID ),
56 maFreezePos( 0, 0, 0 ),
57 maSplitPos( 0, 0 ),
58 meActivePane( SCEXT_PANE_TOPLEFT ),
59 maGridColor( COL_AUTO ),
60 mnNormalZoom( 0 ),
61 mnPageZoom( 0 ),
62 mbSelected( false ),
63 mbFrozenPanes( false ),
64 mbPageMode( false ),
65 mbShowGrid( true ),
66 maTabBgColor( COL_AUTO)
70 // ============================================================================
72 /** A container for ScExtTabSettings objects.
73 @descr Internally, a std::map with shared pointers to ScExtTabSettings is
74 used. The copy constructor and assignment operator make deep copies of the
75 objects. */
76 class ScExtTabSettingsCont
78 public:
79 explicit ScExtTabSettingsCont();
80 ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc );
81 ScExtTabSettingsCont& operator=( const ScExtTabSettingsCont& rSrc );
83 const ScExtTabSettings* GetTabSettings( SCTAB nTab ) const;
84 ScExtTabSettings& GetOrCreateTabSettings( SCTAB nTab );
86 private:
87 typedef ::boost::shared_ptr< ScExtTabSettings > ScExtTabSettingsRef;
88 typedef ::std::map< SCTAB, ScExtTabSettingsRef > ScExtTabSettingsMap;
90 /** Makes a deep copy of all objects in the passed map. */
91 void CopyFromMap( const ScExtTabSettingsMap& rMap );
93 ScExtTabSettingsMap maMap;
96 // ----------------------------------------------------------------------------
98 ScExtTabSettingsCont::ScExtTabSettingsCont()
102 ScExtTabSettingsCont::ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc )
104 CopyFromMap( rSrc.maMap );
107 ScExtTabSettingsCont& ScExtTabSettingsCont::operator=( const ScExtTabSettingsCont& rSrc )
109 CopyFromMap( rSrc.maMap );
110 return *this;
113 const ScExtTabSettings* ScExtTabSettingsCont::GetTabSettings( SCTAB nTab ) const
115 ScExtTabSettingsMap::const_iterator aIt = maMap.find( nTab );
116 return (aIt == maMap.end()) ? 0 : aIt->second.get();
119 ScExtTabSettings& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab )
121 ScExtTabSettingsRef& rxTabSett = maMap[ nTab ];
122 if( !rxTabSett )
123 rxTabSett.reset( new ScExtTabSettings );
124 return *rxTabSett;
127 void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap& rMap )
129 maMap.clear();
130 for( ScExtTabSettingsMap::const_iterator aIt = rMap.begin(), aEnd = rMap.end(); aIt != aEnd; ++aIt )
131 maMap[ aIt->first ].reset( new ScExtTabSettings( *aIt->second ) );
134 // ============================================================================
136 /** Implementation struct for ScExtDocOptions containing all members. */
137 struct ScExtDocOptionsImpl
139 typedef ::std::vector< String > StringVec;
141 ScExtDocSettings maDocSett; /// Global document settings.
142 ScExtTabSettingsCont maTabSett; /// Settings for all sheets.
143 StringVec maCodeNames; /// Codenames for all sheets (VBA module names).
144 bool mbChanged; /// Use only if something has been changed.
146 explicit ScExtDocOptionsImpl();
149 ScExtDocOptionsImpl::ScExtDocOptionsImpl() :
150 mbChanged( false )
154 // ----------------------------------------------------------------------------
156 ScExtDocOptions::ScExtDocOptions() :
157 mxImpl( new ScExtDocOptionsImpl )
161 ScExtDocOptions::ScExtDocOptions( const ScExtDocOptions& rSrc ) :
162 mxImpl( new ScExtDocOptionsImpl( *rSrc.mxImpl ) )
166 ScExtDocOptions::~ScExtDocOptions()
170 ScExtDocOptions& ScExtDocOptions::operator=( const ScExtDocOptions& rSrc )
172 *mxImpl = *rSrc.mxImpl;
173 return *this;
176 bool ScExtDocOptions::IsChanged() const
178 return mxImpl->mbChanged;
181 void ScExtDocOptions::SetChanged( bool bChanged )
183 mxImpl->mbChanged = bChanged;
186 const ScExtDocSettings& ScExtDocOptions::GetDocSettings() const
188 return mxImpl->maDocSett;
191 ScExtDocSettings& ScExtDocOptions::GetDocSettings()
193 return mxImpl->maDocSett;
196 const ScExtTabSettings* ScExtDocOptions::GetTabSettings( SCTAB nTab ) const
198 return mxImpl->maTabSett.GetTabSettings( nTab );
201 ScExtTabSettings& ScExtDocOptions::GetOrCreateTabSettings( SCTAB nTab )
203 return mxImpl->maTabSett.GetOrCreateTabSettings( nTab );
206 size_t ScExtDocOptions::GetCodeNameCount() const
208 return mxImpl->maCodeNames.size();
211 const String& ScExtDocOptions::GetCodeName( size_t nIdx ) const
213 DBG_ASSERT( nIdx < GetCodeNameCount(), "ScExtDocOptions::GetCodeName - invalid index" );
214 return (nIdx < GetCodeNameCount()) ? mxImpl->maCodeNames[ nIdx ] : EMPTY_STRING;
217 void ScExtDocOptions::AppendCodeName( const String& rCodeName )
219 mxImpl->maCodeNames.push_back( rCodeName );
222 // ============================================================================