LibreOffice Module sc (master)  1
scextopt.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <scextopt.hxx>
21 
22 #include <osl/diagnose.h>
23 
24 #include <map>
25 #include <memory>
26 #include <vector>
27 
29  mfTabBarWidth( -1.0 ),
30  mnLinkCnt( 0 ),
31  mnDisplTab( -1 )
32 {
33 }
34 
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 ),
41  maSplitPos( 0, 0 ),
42  meActivePane( SCEXT_PANE_TOPLEFT ),
43  maGridColor( COL_AUTO ),
44  mnNormalZoom( 0 ),
45  mnPageZoom( 0 ),
46  mbSelected( false ),
47  mbFrozenPanes( false ),
48  mbPageMode( false ),
49  mbShowGrid( true )
50 {
51 }
52 
53 namespace {
54 
59 class ScExtTabSettingsCont
60 {
61 public:
62  explicit ScExtTabSettingsCont();
63  ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc );
64  ScExtTabSettingsCont& operator=( const ScExtTabSettingsCont& rSrc );
65 
66  const ScExtTabSettings* GetTabSettings( SCTAB nTab ) const;
67  ScExtTabSettings& GetOrCreateTabSettings( SCTAB nTab );
68 
69  SCTAB GetLastTab() const;
70 
71 private:
72  typedef std::shared_ptr< ScExtTabSettings > ScExtTabSettingsRef;
73  typedef ::std::map< SCTAB, ScExtTabSettingsRef > ScExtTabSettingsMap;
74 
76  void CopyFromMap( const ScExtTabSettingsMap& rMap );
77 
78  ScExtTabSettingsMap maMap;
79 };
80 
81 }
82 
83 ScExtTabSettingsCont::ScExtTabSettingsCont()
84 {
85 }
86 
87 ScExtTabSettingsCont::ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc )
88 {
89  CopyFromMap( rSrc.maMap );
90 }
91 
92 ScExtTabSettingsCont& ScExtTabSettingsCont::operator=( const ScExtTabSettingsCont& rSrc )
93 {
94  CopyFromMap( rSrc.maMap );
95  return *this;
96 }
97 
98 const ScExtTabSettings* ScExtTabSettingsCont::GetTabSettings( SCTAB nTab ) const
99 {
100  ScExtTabSettingsMap::const_iterator aIt = maMap.find( nTab );
101  return (aIt == maMap.end()) ? nullptr : aIt->second.get();
102 }
103 
104 ScExtTabSettings& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab )
105 {
106  ScExtTabSettingsRef& rxTabSett = maMap[ nTab ];
107  if( !rxTabSett )
108  rxTabSett = std::make_shared<ScExtTabSettings>();
109  return *rxTabSett;
110 }
111 
112 SCTAB ScExtTabSettingsCont::GetLastTab() const
113 {
114  return maMap.empty() ? -1 : maMap.rbegin()->first;
115 }
116 
117 void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap& rMap )
118 {
119  maMap.clear();
120  for( const auto& [rTab, rxSettings] : rMap )
121  maMap[ rTab ] = std::make_shared<ScExtTabSettings>( *rxSettings );
122 }
123 
126 {
128  ScExtTabSettingsCont maTabSett;
129  std::vector< OUString > maCodeNames;
130  bool mbChanged;
131 
132  explicit ScExtDocOptionsImpl();
133 };
134 
136  mbChanged( false )
137 {
138 }
139 
141  mxImpl( new ScExtDocOptionsImpl )
142 {
143 }
144 
146  mxImpl( new ScExtDocOptionsImpl( *rSrc.mxImpl ) )
147 {
148 }
149 
151 {
152 }
153 
155 {
156  *mxImpl = *rSrc.mxImpl;
157  return *this;
158 }
159 
161 {
162  return mxImpl->mbChanged;
163 }
164 
165 void ScExtDocOptions::SetChanged( bool bChanged )
166 {
167  mxImpl->mbChanged = bChanged;
168 }
169 
171 {
172  return mxImpl->maDocSett;
173 }
174 
176 {
177  return mxImpl->maDocSett;
178 }
179 
181 {
182  return mxImpl->maTabSett.GetTabSettings( nTab );
183 }
184 
186 {
187  return mxImpl->maTabSett.GetLastTab();
188 }
189 
191 {
192  return mxImpl->maTabSett.GetOrCreateTabSettings( nTab );
193 }
194 
196 {
197  return static_cast< SCTAB >( mxImpl->maCodeNames.size() );
198 }
199 
200 const OUString& ScExtDocOptions::GetCodeName( SCTAB nTab ) const
201 {
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 ) ] : EMPTY_OUSTRING;
204 }
205 
206 void ScExtDocOptions::SetCodeName( SCTAB nTab, const OUString& rCodeName )
207 {
208  OSL_ENSURE( nTab >= 0, "ScExtDocOptions::SetCodeName - invalid sheet index" );
209  if( nTab >= 0 )
210  {
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;
215  }
216 }
217 
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetChanged(bool bChanged)
If set to true, the data will be copied to the view data after import.
Definition: scextopt.cxx:165
::std::unique_ptr< ScExtDocOptionsImpl > mxImpl
Definition: scextopt.hxx:116
sal_Int32 nIndex
#define EMPTY_OUSTRING
Definition: global.hxx:214
SCTAB GetCodeNameCount() const
Definition: scextopt.cxx:195
bool IsChanged() const
Definition: scextopt.cxx:160
const ScExtDocSettings & GetDocSettings() const
Definition: scextopt.cxx:170
Extended options held by an ScDocument containing additional settings for filters.
Definition: scextopt.hxx:77
SCTAB GetLastTab() const
Definition: scextopt.cxx:185
constexpr::Color COL_AUTO(0xFF, 0xFF, 0xFF, 0xFF)
const OUString & GetCodeName(SCTAB nTab) const
Definition: scextopt.cxx:200
ScExtTabSettings & GetOrCreateTabSettings(SCTAB nTab)
Definition: scextopt.cxx:190
void SetCodeName(SCTAB nTab, const OUString &rCodeName)
Appends a codename for a sheet.
Definition: scextopt.cxx:206
bool mbChanged
Codenames for all sheets (VBA module names).
Definition: scextopt.cxx:130
Extended settings for the document, used in import/export filters.
Definition: scextopt.hxx:28
ScExtDocSettings maDocSett
Definition: scextopt.cxx:127
ScExtTabSettingsCont maTabSett
Global document settings.
Definition: scextopt.cxx:128
ScExtDocOptionsImpl()
Use only if something has been changed.
Definition: scextopt.cxx:135
const ScExtTabSettings * GetTabSettings(SCTAB nTab) const
Definition: scextopt.cxx:180
Extended settings for a sheet, used in import/export filters.
Definition: scextopt.hxx:48
Implementation struct for ScExtDocOptions containing all members.
Definition: scextopt.cxx:125
ScExtDocOptions & operator=(const ScExtDocOptions &rSrc)
Definition: scextopt.cxx:154
std::vector< OUString > maCodeNames
Settings for all sheets.
Definition: scextopt.cxx:129
bool mbChanged
Single, top, left, or top-left pane.
Definition: scextopt.hxx:41
sal_Int16 SCTAB
Definition: types.hxx:23