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>
26 #include <boost/shared_ptr.hpp>
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 ),
53 /** A container for ScExtTabSettings objects.
54 @descr Internally, a std::map with shared pointers to ScExtTabSettings is
55 used. The copy constructor and assignment operator make deep copies of the
57 class ScExtTabSettingsCont
60 explicit ScExtTabSettingsCont();
61 ScExtTabSettingsCont( const ScExtTabSettingsCont
& rSrc
);
62 ScExtTabSettingsCont
& operator=( const ScExtTabSettingsCont
& rSrc
);
64 const ScExtTabSettings
* GetTabSettings( SCTAB nTab
) const;
65 ScExtTabSettings
& GetOrCreateTabSettings( SCTAB nTab
);
67 SCTAB
GetLastTab() const;
70 typedef ::boost::shared_ptr
< ScExtTabSettings
> ScExtTabSettingsRef
;
71 typedef ::std::map
< SCTAB
, ScExtTabSettingsRef
> ScExtTabSettingsMap
;
73 /** Makes a deep copy of all objects in the passed map. */
74 void CopyFromMap( const ScExtTabSettingsMap
& rMap
);
76 ScExtTabSettingsMap maMap
;
79 ScExtTabSettingsCont::ScExtTabSettingsCont()
83 ScExtTabSettingsCont::ScExtTabSettingsCont( const ScExtTabSettingsCont
& rSrc
)
85 CopyFromMap( rSrc
.maMap
);
88 ScExtTabSettingsCont
& ScExtTabSettingsCont::operator=( const ScExtTabSettingsCont
& rSrc
)
90 CopyFromMap( rSrc
.maMap
);
94 const ScExtTabSettings
* ScExtTabSettingsCont::GetTabSettings( SCTAB nTab
) const
96 ScExtTabSettingsMap::const_iterator aIt
= maMap
.find( nTab
);
97 return (aIt
== maMap
.end()) ? 0 : aIt
->second
.get();
100 ScExtTabSettings
& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab
)
102 ScExtTabSettingsRef
& rxTabSett
= maMap
[ nTab
];
104 rxTabSett
.reset( new ScExtTabSettings
);
108 SCTAB
ScExtTabSettingsCont::GetLastTab() const
110 return maMap
.empty() ? -1 : maMap
.rbegin()->first
;
113 void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap
& rMap
)
116 for( ScExtTabSettingsMap::const_iterator aIt
= rMap
.begin(), aEnd
= rMap
.end(); aIt
!= aEnd
; ++aIt
)
117 maMap
[ aIt
->first
].reset( new ScExtTabSettings( *aIt
->second
) );
120 /** Implementation struct for ScExtDocOptions containing all members. */
121 struct ScExtDocOptionsImpl
123 typedef ::std::vector
< OUString
> StringVec
;
125 ScExtDocSettings maDocSett
; /// Global document settings.
126 ScExtTabSettingsCont maTabSett
; /// Settings for all sheets.
127 StringVec maCodeNames
; /// Codenames for all sheets (VBA module names).
128 bool mbChanged
; /// Use only if something has been changed.
130 explicit ScExtDocOptionsImpl();
133 ScExtDocOptionsImpl::ScExtDocOptionsImpl() :
138 ScExtDocOptions::ScExtDocOptions() :
139 mxImpl( new ScExtDocOptionsImpl
)
143 ScExtDocOptions::ScExtDocOptions( const ScExtDocOptions
& rSrc
) :
144 mxImpl( new ScExtDocOptionsImpl( *rSrc
.mxImpl
) )
148 ScExtDocOptions::~ScExtDocOptions()
152 ScExtDocOptions
& ScExtDocOptions::operator=( const ScExtDocOptions
& rSrc
)
154 *mxImpl
= *rSrc
.mxImpl
;
158 bool ScExtDocOptions::IsChanged() const
160 return mxImpl
->mbChanged
;
163 void ScExtDocOptions::SetChanged( bool bChanged
)
165 mxImpl
->mbChanged
= bChanged
;
168 const ScExtDocSettings
& ScExtDocOptions::GetDocSettings() const
170 return mxImpl
->maDocSett
;
173 ScExtDocSettings
& ScExtDocOptions::GetDocSettings()
175 return mxImpl
->maDocSett
;
178 const ScExtTabSettings
* ScExtDocOptions::GetTabSettings( SCTAB nTab
) const
180 return mxImpl
->maTabSett
.GetTabSettings( nTab
);
183 SCTAB
ScExtDocOptions::GetLastTab() const
185 return mxImpl
->maTabSett
.GetLastTab();
188 ScExtTabSettings
& ScExtDocOptions::GetOrCreateTabSettings( SCTAB nTab
)
190 return mxImpl
->maTabSett
.GetOrCreateTabSettings( nTab
);
193 SCTAB
ScExtDocOptions::GetCodeNameCount() const
195 return static_cast< SCTAB
>( mxImpl
->maCodeNames
.size() );
198 const OUString
& ScExtDocOptions::GetCodeName( SCTAB nTab
) const
200 OSL_ENSURE( (0 <= nTab
) && (nTab
< GetCodeNameCount()), "ScExtDocOptions::GetCodeName - invalid sheet index" );
201 return ((0 <= nTab
) && (nTab
< GetCodeNameCount())) ? mxImpl
->maCodeNames
[ static_cast< size_t >( nTab
) ] : EMPTY_OUSTRING
;
204 void ScExtDocOptions::SetCodeName( SCTAB nTab
, const OUString
& rCodeName
)
206 OSL_ENSURE( nTab
>= 0, "ScExtDocOptions::SetCodeName - invalid sheet index" );
209 size_t nIndex
= static_cast< size_t >( nTab
);
210 if( nIndex
>= mxImpl
->maCodeNames
.size() )
211 mxImpl
->maCodeNames
.resize( nIndex
+ 1 );
212 mxImpl
->maCodeNames
[ nIndex
] = rCodeName
;
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */