Coverage Report

Created: 2025-12-08 09:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/view/scextopt.cxx
Line
Count
Source
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
28
ScExtDocSettings::ScExtDocSettings() :
29
14.4k
    mfTabBarWidth( -1.0 ),
30
14.4k
    mnLinkCnt( 0 ),
31
14.4k
    mnDisplTab( -1 )
32
14.4k
{
33
14.4k
}
34
35
ScExtTabSettings::ScExtTabSettings() :
36
15.3k
    maUsedArea( ScAddress::INITIALIZE_INVALID ),
37
15.3k
    maCursor( ScAddress::INITIALIZE_INVALID ),
38
15.3k
    maFirstVis( ScAddress::INITIALIZE_INVALID ),
39
15.3k
    maSecondVis( ScAddress::INITIALIZE_INVALID ),
40
15.3k
    maFreezePos( 0, 0, 0 ),
41
15.3k
    maSplitPos( 0, 0 ),
42
15.3k
    meActivePane( SCEXT_PANE_TOPLEFT ),
43
15.3k
    maGridColor( COL_AUTO ),
44
15.3k
    mnNormalZoom( 0 ),
45
15.3k
    mnPageZoom( 0 ),
46
15.3k
    mbSelected( false ),
47
15.3k
    mbFrozenPanes( false ),
48
15.3k
    mbPageMode( false ),
49
15.3k
    mbShowGrid( true )
50
15.3k
{
51
15.3k
}
52
53
namespace {
54
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
58
    objects. */
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
75
    /** Makes a deep copy of all objects in the passed map. */
76
    void                CopyFromMap( const ScExtTabSettingsMap& rMap );
77
78
    ScExtTabSettingsMap maMap;
79
};
80
81
}
82
83
ScExtTabSettingsCont::ScExtTabSettingsCont()
84
14.4k
{
85
14.4k
}
86
87
ScExtTabSettingsCont::ScExtTabSettingsCont( const ScExtTabSettingsCont& rSrc )
88
14.4k
{
89
14.4k
    CopyFromMap( rSrc.maMap );
90
14.4k
}
91
92
ScExtTabSettingsCont& ScExtTabSettingsCont::operator=( const ScExtTabSettingsCont& rSrc )
93
0
{
94
0
    CopyFromMap( rSrc.maMap );
95
0
    return *this;
96
0
}
97
98
const ScExtTabSettings* ScExtTabSettingsCont::GetTabSettings( SCTAB nTab ) const
99
14.4k
{
100
14.4k
    ScExtTabSettingsMap::const_iterator aIt = maMap.find( nTab );
101
14.4k
    return (aIt == maMap.end()) ? nullptr : aIt->second.get();
102
14.4k
}
103
104
ScExtTabSettings& ScExtTabSettingsCont::GetOrCreateTabSettings( SCTAB nTab )
105
20.4k
{
106
20.4k
    ScExtTabSettingsRef& rxTabSett = maMap[ nTab ];
107
20.4k
    if( !rxTabSett )
108
15.3k
        rxTabSett = std::make_shared<ScExtTabSettings>();
109
20.4k
    return *rxTabSett;
110
20.4k
}
111
112
SCTAB ScExtTabSettingsCont::GetLastTab() const
113
0
{
114
0
    return maMap.empty() ? -1 : maMap.rbegin()->first;
115
0
}
116
117
void ScExtTabSettingsCont::CopyFromMap( const ScExtTabSettingsMap& rMap )
118
14.4k
{
119
14.4k
    maMap.clear();
120
14.4k
    for( const auto& [rTab, rxSettings] : rMap )
121
15.2k
        maMap[ rTab ] = std::make_shared<ScExtTabSettings>( *rxSettings );
122
14.4k
}
123
124
/** Implementation struct for ScExtDocOptions containing all members. */
125
struct ScExtDocOptionsImpl
126
{
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.
131
132
    explicit            ScExtDocOptionsImpl();
133
};
134
135
ScExtDocOptionsImpl::ScExtDocOptionsImpl() :
136
14.4k
    mbChanged( false )
137
14.4k
{
138
14.4k
}
139
140
ScExtDocOptions::ScExtDocOptions() :
141
14.4k
    mxImpl( new ScExtDocOptionsImpl )
142
14.4k
{
143
14.4k
}
144
145
ScExtDocOptions::ScExtDocOptions( const ScExtDocOptions& rSrc ) :
146
14.4k
    mxImpl( new ScExtDocOptionsImpl( *rSrc.mxImpl ) )
147
14.4k
{
148
14.4k
}
149
150
ScExtDocOptions::~ScExtDocOptions()
151
28.9k
{
152
28.9k
}
153
154
ScExtDocOptions& ScExtDocOptions::operator=( const ScExtDocOptions& rSrc )
155
0
{
156
0
    *mxImpl = *rSrc.mxImpl;
157
0
    return *this;
158
0
}
159
160
bool ScExtDocOptions::IsChanged() const
161
0
{
162
0
    return mxImpl->mbChanged;
163
0
}
164
165
void ScExtDocOptions::SetChanged( bool bChanged )
166
14.4k
{
167
14.4k
    mxImpl->mbChanged = bChanged;
168
14.4k
}
169
170
const ScExtDocSettings& ScExtDocOptions::GetDocSettings() const
171
0
{
172
0
    return mxImpl->maDocSett;
173
0
}
174
175
ScExtDocSettings& ScExtDocOptions::GetDocSettings()
176
45.9k
{
177
45.9k
    return mxImpl->maDocSett;
178
45.9k
}
179
180
const ScExtTabSettings* ScExtDocOptions::GetTabSettings( SCTAB nTab ) const
181
14.4k
{
182
14.4k
    return mxImpl->maTabSett.GetTabSettings( nTab );
183
14.4k
}
184
185
SCTAB ScExtDocOptions::GetLastTab() const
186
0
{
187
0
    return mxImpl->maTabSett.GetLastTab();
188
0
}
189
190
ScExtTabSettings& ScExtDocOptions::GetOrCreateTabSettings( SCTAB nTab )
191
20.4k
{
192
20.4k
    return mxImpl->maTabSett.GetOrCreateTabSettings( nTab );
193
20.4k
}
194
195
SCTAB ScExtDocOptions::GetCodeNameCount() const
196
0
{
197
0
    return static_cast< SCTAB >( mxImpl->maCodeNames.size() );
198
0
}
199
200
OUString ScExtDocOptions::GetCodeName( SCTAB nTab ) const
201
0
{
202
0
    OSL_ENSURE( (0 <= nTab) && (nTab < GetCodeNameCount()), "ScExtDocOptions::GetCodeName - invalid sheet index" );
203
0
    return ((0 <= nTab) && (nTab < GetCodeNameCount())) ? mxImpl->maCodeNames[ static_cast< size_t >( nTab ) ] : OUString();
204
0
}
205
206
void ScExtDocOptions::SetCodeName( SCTAB nTab, const OUString& rCodeName )
207
7
{
208
7
    OSL_ENSURE( nTab >= 0, "ScExtDocOptions::SetCodeName - invalid sheet index" );
209
7
    if( nTab >= 0 )
210
7
    {
211
7
        size_t nIndex = static_cast< size_t >( nTab );
212
7
        if( nIndex >= mxImpl->maCodeNames.size() )
213
7
            mxImpl->maCodeNames.resize( nIndex + 1 );
214
7
        mxImpl->maCodeNames[ nIndex ] = rCodeName;
215
7
    }
216
7
}
217
218
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */