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
);
72 typedef ::boost::shared_ptr
< ScExtTabSettings
> ScExtTabSettingsRef
;
73 typedef ::std::map
< SCTAB
, ScExtTabSettingsRef
> ScExtTabSettingsMap
;
75 /** Makes a deep copy of all objects in the passed map. */
76 void CopyFromMap( const ScExtTabSettingsMap
& rMap
);
78 ScExtTabSettingsMap maMap
;
81 // ----------------------------------------------------------------------------
83 ScExtTabSettingsCont::ScExtTabSettingsCont()
87 ScExtTabSettingsCont::ScExtTabSettingsCont( const ScExtTabSettingsCont
& rSrc
)
89 CopyFromMap( rSrc
.maMap
);
92 ScExtTabSettingsCont
& ScExtTabSettingsCont::operator=( const ScExtTabSettingsCont
& rSrc
)
94 CopyFromMap( rSrc
.maMap
);
98 const ScExtTabSettings
* ScExtTabSettingsCont::GetTabSettings( SCTAB nTab
) const
100 ScExtTabSettingsMap::const_iterator aIt
= maMap
.find( nTab
);
101 return (aIt
== maMap
.end()) ? 0 : aIt
->second
.get();
104 ScExtTabSettings
& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab
)
106 ScExtTabSettingsRef
& rxTabSett
= maMap
[ nTab
];
108 rxTabSett
.reset( new ScExtTabSettings
);
112 void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap
& rMap
)
115 for( ScExtTabSettingsMap::const_iterator aIt
= rMap
.begin(), aEnd
= rMap
.end(); aIt
!= aEnd
; ++aIt
)
116 maMap
[ aIt
->first
].reset( new ScExtTabSettings( *aIt
->second
) );
119 // ============================================================================
121 /** Implementation struct for ScExtDocOptions containing all members. */
122 struct ScExtDocOptionsImpl
124 typedef ::std::vector
< String
> StringVec
;
126 ScExtDocSettings maDocSett
; /// Global document settings.
127 ScExtTabSettingsCont maTabSett
; /// Settings for all sheets.
128 StringVec maCodeNames
; /// Codenames for all sheets (VBA module names).
129 bool mbChanged
; /// Use only if something has been changed.
131 explicit ScExtDocOptionsImpl();
134 ScExtDocOptionsImpl::ScExtDocOptionsImpl() :
139 // ----------------------------------------------------------------------------
141 ScExtDocOptions::ScExtDocOptions() :
142 mxImpl( new ScExtDocOptionsImpl
)
146 ScExtDocOptions::ScExtDocOptions( const ScExtDocOptions
& rSrc
) :
147 mxImpl( new ScExtDocOptionsImpl( *rSrc
.mxImpl
) )
151 ScExtDocOptions::~ScExtDocOptions()
155 ScExtDocOptions
& ScExtDocOptions::operator=( const ScExtDocOptions
& rSrc
)
157 *mxImpl
= *rSrc
.mxImpl
;
161 bool ScExtDocOptions::IsChanged() const
163 return mxImpl
->mbChanged
;
166 void ScExtDocOptions::SetChanged( bool bChanged
)
168 mxImpl
->mbChanged
= bChanged
;
171 const ScExtDocSettings
& ScExtDocOptions::GetDocSettings() const
173 return mxImpl
->maDocSett
;
176 ScExtDocSettings
& ScExtDocOptions::GetDocSettings()
178 return mxImpl
->maDocSett
;
181 const ScExtTabSettings
* ScExtDocOptions::GetTabSettings( SCTAB nTab
) const
183 return mxImpl
->maTabSett
.GetTabSettings( nTab
);
186 ScExtTabSettings
& ScExtDocOptions::GetOrCreateTabSettings( SCTAB nTab
)
188 return mxImpl
->maTabSett
.GetOrCreateTabSettings( nTab
);
191 SCTAB
ScExtDocOptions::GetCodeNameCount() const
193 return static_cast< SCTAB
>( mxImpl
->maCodeNames
.size() );
196 const String
& ScExtDocOptions::GetCodeName( SCTAB nTab
) const
198 OSL_ENSURE( (0 <= nTab
) && (nTab
< GetCodeNameCount()), "ScExtDocOptions::GetCodeName - invalid sheet index" );
199 return ((0 <= nTab
) && (nTab
< GetCodeNameCount())) ? mxImpl
->maCodeNames
[ static_cast< size_t >( nTab
) ] : EMPTY_STRING
;
202 void ScExtDocOptions::SetCodeName( SCTAB nTab
, const String
& rCodeName
)
204 OSL_ENSURE( nTab
>= 0, "ScExtDocOptions::SetCodeName - invalid sheet index" );
207 size_t nIndex
= static_cast< size_t >( nTab
);
208 if( nIndex
>= mxImpl
->maCodeNames
.size() )
209 mxImpl
->maCodeNames
.resize( nIndex
+ 1 );
210 mxImpl
->maCodeNames
[ nIndex
] = rCodeName
;
214 // ============================================================================
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */