1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "scextopt.hxx"
24 #include <boost/shared_ptr.hpp>
26 // ============================================================================
28 ScExtDocSettings::ScExtDocSettings() :
29 mfTabBarWidth( -1.0 ),
35 // ============================================================================
37 ScExtTabSettings::ScExtTabSettings() :
38 maUsedArea( ScAddress::INITIALIZE_INVALID
),
39 maCursor( ScAddress::INITIALIZE_INVALID
),
40 maFirstVis( ScAddress::INITIALIZE_INVALID
),
41 maSecondVis( ScAddress::INITIALIZE_INVALID
),
42 maFreezePos( 0, 0, 0 ),
44 meActivePane( SCEXT_PANE_TOPLEFT
),
45 maGridColor( COL_AUTO
),
49 mbFrozenPanes( false ),
55 // ============================================================================
57 /** A container for ScExtTabSettings objects.
58 @descr Internally, a std::map with shared pointers to ScExtTabSettings is
59 used. The copy constructor and assignment operator make deep copies of the
61 class ScExtTabSettingsCont
64 explicit ScExtTabSettingsCont();
65 ScExtTabSettingsCont( const ScExtTabSettingsCont
& rSrc
);
66 ScExtTabSettingsCont
& operator=( const ScExtTabSettingsCont
& rSrc
);
68 const ScExtTabSettings
* GetTabSettings( SCTAB nTab
) const;
69 ScExtTabSettings
& GetOrCreateTabSettings( SCTAB nTab
);
71 SCTAB
GetLastTab() const;
74 typedef ::boost::shared_ptr
< ScExtTabSettings
> ScExtTabSettingsRef
;
75 typedef ::std::map
< SCTAB
, ScExtTabSettingsRef
> ScExtTabSettingsMap
;
77 /** Makes a deep copy of all objects in the passed map. */
78 void CopyFromMap( const ScExtTabSettingsMap
& rMap
);
80 ScExtTabSettingsMap maMap
;
83 // ----------------------------------------------------------------------------
85 ScExtTabSettingsCont::ScExtTabSettingsCont()
89 ScExtTabSettingsCont::ScExtTabSettingsCont( const ScExtTabSettingsCont
& rSrc
)
91 CopyFromMap( rSrc
.maMap
);
94 ScExtTabSettingsCont
& ScExtTabSettingsCont::operator=( const ScExtTabSettingsCont
& rSrc
)
96 CopyFromMap( rSrc
.maMap
);
100 const ScExtTabSettings
* ScExtTabSettingsCont::GetTabSettings( SCTAB nTab
) const
102 ScExtTabSettingsMap::const_iterator aIt
= maMap
.find( nTab
);
103 return (aIt
== maMap
.end()) ? 0 : aIt
->second
.get();
106 ScExtTabSettings
& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab
)
108 ScExtTabSettingsRef
& rxTabSett
= maMap
[ nTab
];
110 rxTabSett
.reset( new ScExtTabSettings
);
114 SCTAB
ScExtTabSettingsCont::GetLastTab() const
116 return maMap
.empty() ? -1 : maMap
.rbegin()->first
;
119 void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap
& rMap
)
122 for( ScExtTabSettingsMap::const_iterator aIt
= rMap
.begin(), aEnd
= rMap
.end(); aIt
!= aEnd
; ++aIt
)
123 maMap
[ aIt
->first
].reset( new ScExtTabSettings( *aIt
->second
) );
126 // ============================================================================
128 /** Implementation struct for ScExtDocOptions containing all members. */
129 struct ScExtDocOptionsImpl
131 typedef ::std::vector
< String
> StringVec
;
133 ScExtDocSettings maDocSett
; /// Global document settings.
134 ScExtTabSettingsCont maTabSett
; /// Settings for all sheets.
135 StringVec maCodeNames
; /// Codenames for all sheets (VBA module names).
136 bool mbChanged
; /// Use only if something has been changed.
138 explicit ScExtDocOptionsImpl();
141 ScExtDocOptionsImpl::ScExtDocOptionsImpl() :
146 // ----------------------------------------------------------------------------
148 ScExtDocOptions::ScExtDocOptions() :
149 mxImpl( new ScExtDocOptionsImpl
)
153 ScExtDocOptions::ScExtDocOptions( const ScExtDocOptions
& rSrc
) :
154 mxImpl( new ScExtDocOptionsImpl( *rSrc
.mxImpl
) )
158 ScExtDocOptions::~ScExtDocOptions()
162 ScExtDocOptions
& ScExtDocOptions::operator=( const ScExtDocOptions
& rSrc
)
164 *mxImpl
= *rSrc
.mxImpl
;
168 bool ScExtDocOptions::IsChanged() const
170 return mxImpl
->mbChanged
;
173 void ScExtDocOptions::SetChanged( bool bChanged
)
175 mxImpl
->mbChanged
= bChanged
;
178 const ScExtDocSettings
& ScExtDocOptions::GetDocSettings() const
180 return mxImpl
->maDocSett
;
183 ScExtDocSettings
& ScExtDocOptions::GetDocSettings()
185 return mxImpl
->maDocSett
;
188 const ScExtTabSettings
* ScExtDocOptions::GetTabSettings( SCTAB nTab
) const
190 return mxImpl
->maTabSett
.GetTabSettings( nTab
);
193 SCTAB
ScExtDocOptions::GetLastTab() const
195 return mxImpl
->maTabSett
.GetLastTab();
198 ScExtTabSettings
& ScExtDocOptions::GetOrCreateTabSettings( SCTAB nTab
)
200 return mxImpl
->maTabSett
.GetOrCreateTabSettings( nTab
);
203 SCTAB
ScExtDocOptions::GetCodeNameCount() const
205 return static_cast< SCTAB
>( mxImpl
->maCodeNames
.size() );
208 const String
& ScExtDocOptions::GetCodeName( SCTAB nTab
) const
210 OSL_ENSURE( (0 <= nTab
) && (nTab
< GetCodeNameCount()), "ScExtDocOptions::GetCodeName - invalid sheet index" );
211 return ((0 <= nTab
) && (nTab
< GetCodeNameCount())) ? mxImpl
->maCodeNames
[ static_cast< size_t >( nTab
) ] : EMPTY_STRING
;
214 void ScExtDocOptions::SetCodeName( SCTAB nTab
, const String
& rCodeName
)
216 OSL_ENSURE( nTab
>= 0, "ScExtDocOptions::SetCodeName - invalid sheet index" );
219 size_t nIndex
= static_cast< size_t >( nTab
);
220 if( nIndex
>= mxImpl
->maCodeNames
.size() )
221 mxImpl
->maCodeNames
.resize( nIndex
+ 1 );
222 mxImpl
->maCodeNames
[ nIndex
] = rCodeName
;
226 // ============================================================================
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */