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>
22 #include <osl/diagnose.h>
28 ScExtDocSettings::ScExtDocSettings() :
29 mfTabBarWidth( -1.0 ),
35 ScExtTabSettings::ScExtTabSettings() :
36 maUsedArea( ScAddress::INITIALIZE_INVALID
),
37 maCursor( ScAddress::INITIALIZE_INVALID
),
38 maFirstVis( ScAddress::INITIALIZE_INVALID
),
39 maSecondVis( ScAddress::INITIALIZE_INVALID
),
40 maFreezePos( 0, 0, 0 ),
42 meActivePane( SCEXT_PANE_TOPLEFT
),
43 maGridColor( COL_AUTO
),
47 mbFrozenPanes( false ),
55 /** A container for ScExtTabSettings objects.
56 @descr Internally, a std::map with shared pointers to ScExtTabSettings is
57 used. The copy constructor and assignment operator make deep copies of the
59 class ScExtTabSettingsCont
62 explicit ScExtTabSettingsCont();
63 ScExtTabSettingsCont( const ScExtTabSettingsCont
& rSrc
);
64 ScExtTabSettingsCont
& operator=( const ScExtTabSettingsCont
& rSrc
);
66 const ScExtTabSettings
* GetTabSettings( SCTAB nTab
) const;
67 ScExtTabSettings
& GetOrCreateTabSettings( SCTAB nTab
);
69 SCTAB
GetLastTab() const;
72 typedef std::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
;
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()) ? nullptr : aIt
->second
.get();
104 ScExtTabSettings
& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab
)
106 ScExtTabSettingsRef
& rxTabSett
= maMap
[ nTab
];
108 rxTabSett
= std::make_shared
<ScExtTabSettings
>();
112 SCTAB
ScExtTabSettingsCont::GetLastTab() const
114 return maMap
.empty() ? -1 : maMap
.rbegin()->first
;
117 void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap
& rMap
)
120 for( const auto& [rTab
, rxSettings
] : rMap
)
121 maMap
[ rTab
] = std::make_shared
<ScExtTabSettings
>( *rxSettings
);
124 /** Implementation struct for ScExtDocOptions containing all members. */
125 struct ScExtDocOptionsImpl
127 ScExtDocSettings maDocSett
; /// Global document settings.
128 ScExtTabSettingsCont maTabSett
; /// Settings for all sheets.
129 std::vector
< OUString
> maCodeNames
; /// Codenames for all sheets (VBA module names).
130 bool mbChanged
; /// Use only if something has been changed.
132 explicit ScExtDocOptionsImpl();
135 ScExtDocOptionsImpl::ScExtDocOptionsImpl() :
140 ScExtDocOptions::ScExtDocOptions() :
141 mxImpl( new ScExtDocOptionsImpl
)
145 ScExtDocOptions::ScExtDocOptions( const ScExtDocOptions
& rSrc
) :
146 mxImpl( new ScExtDocOptionsImpl( *rSrc
.mxImpl
) )
150 ScExtDocOptions::~ScExtDocOptions()
154 ScExtDocOptions
& ScExtDocOptions::operator=( const ScExtDocOptions
& rSrc
)
156 *mxImpl
= *rSrc
.mxImpl
;
160 bool ScExtDocOptions::IsChanged() const
162 return mxImpl
->mbChanged
;
165 void ScExtDocOptions::SetChanged( bool bChanged
)
167 mxImpl
->mbChanged
= bChanged
;
170 const ScExtDocSettings
& ScExtDocOptions::GetDocSettings() const
172 return mxImpl
->maDocSett
;
175 ScExtDocSettings
& ScExtDocOptions::GetDocSettings()
177 return mxImpl
->maDocSett
;
180 const ScExtTabSettings
* ScExtDocOptions::GetTabSettings( SCTAB nTab
) const
182 return mxImpl
->maTabSett
.GetTabSettings( nTab
);
185 SCTAB
ScExtDocOptions::GetLastTab() const
187 return mxImpl
->maTabSett
.GetLastTab();
190 ScExtTabSettings
& ScExtDocOptions::GetOrCreateTabSettings( SCTAB nTab
)
192 return mxImpl
->maTabSett
.GetOrCreateTabSettings( nTab
);
195 SCTAB
ScExtDocOptions::GetCodeNameCount() const
197 return static_cast< SCTAB
>( mxImpl
->maCodeNames
.size() );
200 OUString
ScExtDocOptions::GetCodeName( SCTAB nTab
) const
202 OSL_ENSURE( (0 <= nTab
) && (nTab
< GetCodeNameCount()), "ScExtDocOptions::GetCodeName - invalid sheet index" );
203 return ((0 <= nTab
) && (nTab
< GetCodeNameCount())) ? mxImpl
->maCodeNames
[ static_cast< size_t >( nTab
) ] : OUString();
206 void ScExtDocOptions::SetCodeName( SCTAB nTab
, const OUString
& rCodeName
)
208 OSL_ENSURE( nTab
>= 0, "ScExtDocOptions::SetCodeName - invalid sheet index" );
211 size_t nIndex
= static_cast< size_t >( nTab
);
212 if( nIndex
>= mxImpl
->maCodeNames
.size() )
213 mxImpl
->maCodeNames
.resize( nIndex
+ 1 );
214 mxImpl
->maCodeNames
[ nIndex
] = rCodeName
;
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */