Coverage Report

Created: 2025-07-07 10:01

/src/libreoffice/sc/inc/nameuno.hxx
Line
Count
Source (jump to first uncovered line)
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
#pragma once
21
22
#include <svl/lstner.hxx>
23
#include "address.hxx"
24
#include "rangenam.hxx"
25
#include <formula/grammar.hxx>
26
#include <com/sun/star/sheet/XLabelRange.hpp>
27
#include <com/sun/star/sheet/XLabelRanges.hpp>
28
#include <com/sun/star/sheet/XCellRangeReferrer.hpp>
29
#include <com/sun/star/sheet/XNamedRange.hpp>
30
#include <com/sun/star/sheet/XFormulaTokens.hpp>
31
#include <com/sun/star/sheet/XNamedRanges.hpp>
32
#include <com/sun/star/container/XEnumerationAccess.hpp>
33
#include <com/sun/star/lang/XServiceInfo.hpp>
34
#include <com/sun/star/beans/XPropertySet.hpp>
35
#include <com/sun/star/document/XActionLockable.hpp>
36
#include <cppuhelper/implbase.hxx>
37
#include <rtl/ref.hxx>
38
39
namespace com::sun::star::container { class XNamed; }
40
41
class ScDocShell;
42
class ScNamedRangesObj;
43
44
class SAL_DLLPUBLIC_RTTI ScNamedRangeObj final : public ::cppu::WeakImplHelper<
45
                            css::sheet::XNamedRange,
46
                            css::sheet::XFormulaTokens,
47
                            css::sheet::XCellRangeReferrer,
48
                            css::beans::XPropertySet,
49
                            css::lang::XServiceInfo >,
50
                        public SfxListener
51
{
52
private:
53
    rtl::Reference< ScNamedRangesObj > mxParent;
54
    ScDocShell*             pDocShell;
55
    OUString                aName;
56
    css::uno::Reference< css::container::XNamed > mxSheet;
57
58
private:
59
friend class ScVbaName;
60
    SC_DLLPUBLIC ScRangeData* GetRangeData_Impl();
61
    void                    Modify_Impl( const OUString* pNewName,
62
                                        const ScTokenArray* pNewTokens, const OUString* pNewContent,
63
                                        const ScAddress* pNewPos, const ScRangeData::Type* pNewType,
64
                                        const formula::FormulaGrammar::Grammar eGrammar );
65
    SCTAB                   GetTab_Impl();
66
67
public:
68
                            ScNamedRangeObj( rtl::Reference< ScNamedRangesObj > xParent, ScDocShell* pDocSh, OUString aNm,
69
                                    css::uno::Reference< css::container::XNamed > const & xSheet = css::uno::Reference< css::container::XNamed > ());
70
    virtual                 ~ScNamedRangeObj() override;
71
72
    virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
73
74
                            /// XNamedRange
75
    virtual OUString SAL_CALL getContent() override;
76
    virtual void SAL_CALL   setContent( const OUString& aContent ) override;
77
    virtual css::table::CellAddress SAL_CALL getReferencePosition() override;
78
    virtual void SAL_CALL   setReferencePosition(
79
                                const css::table::CellAddress& aReferencePosition ) override;
80
    virtual sal_Int32       SAL_CALL getType() override;
81
    virtual void SAL_CALL   setType( sal_Int32 nType ) override;
82
83
                            /// XFormulaTokens
84
    virtual css::uno::Sequence< css::sheet::FormulaToken > SAL_CALL getTokens() override;
85
    virtual void SAL_CALL   setTokens( const css::uno::Sequence< css::sheet::FormulaToken >& aTokens ) override;
86
87
                            /// XNamed
88
    virtual OUString SAL_CALL getName() override;
89
    virtual void SAL_CALL   setName( const OUString& aName ) override;
90
91
                            /// XCellRangeReferrer
92
    virtual css::uno::Reference< css::table::XCellRange > SAL_CALL
93
                            getReferredCells() override;
94
95
                            /// XPropertySet
96
    virtual css::uno::Reference< css::beans::XPropertySetInfo >
97
                            SAL_CALL getPropertySetInfo() override;
98
    virtual void SAL_CALL   setPropertyValue( const OUString& aPropertyName,
99
                                    const css::uno::Any& aValue ) override;
100
    virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
101
    virtual void SAL_CALL   addPropertyChangeListener( const OUString& aPropertyName,
102
                                    const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
103
    virtual void SAL_CALL   removePropertyChangeListener( const OUString& aPropertyName,
104
                                    const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
105
    virtual void SAL_CALL   addVetoableChangeListener( const OUString& PropertyName,
106
                                    const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
107
    virtual void SAL_CALL   removeVetoableChangeListener( const OUString& PropertyName,
108
                                    const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
109
110
                            /// XServiceInfo
111
    virtual OUString SAL_CALL getImplementationName() override;
112
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
113
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
114
};
115
116
class ScNamedRangesObj : public ::cppu::WeakImplHelper<
117
                            css::sheet::XNamedRanges,
118
                            css::container::XEnumerationAccess,
119
                            css::container::XIndexAccess,
120
                            css::beans::XPropertySet,
121
                            css::document::XActionLockable,
122
                            css::lang::XServiceInfo >,
123
                        public SfxListener
124
{
125
private:
126
127
     /** if true, adding new name or modifying existing one will set the
128
         document 'modified' and broadcast the change.  We turn this off during
129
         import. */
130
    bool                    mbModifyAndBroadcast;
131
132
    virtual rtl::Reference<ScNamedRangeObj> GetObjectByIndex_Impl(sal_uInt16 nIndex) = 0;
133
    virtual rtl::Reference<ScNamedRangeObj> GetObjectByName_Impl(const OUString& aName) = 0;
134
135
    virtual ScRangeName*    GetRangeName_Impl() = 0;
136
    virtual SCTAB           GetTab_Impl() = 0;
137
138
protected:
139
140
    ScDocShell*             pDocShell;
141
    /** called from the XActionLockable interface methods on initial locking */
142
    void            lock();
143
144
    /** called from the XActionLockable interface methods on final unlock */
145
    void            unlock();
146
147
public:
148
                            ScNamedRangesObj(ScDocShell* pDocSh);
149
    virtual                 ~ScNamedRangesObj() override;
150
151
    virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
152
153
0
    bool                    IsModifyAndBroadcast() const { return mbModifyAndBroadcast;}
154
155
                            /// XNamedRanges
156
    virtual void SAL_CALL   addNewByName( const OUString& aName, const OUString& aContent,
157
                                const css::table::CellAddress& aPosition, sal_Int32 nType ) override;
158
    virtual void SAL_CALL   addNewFromTitles( const css::table::CellRangeAddress& aSource,
159
                                css::sheet::Border aBorder ) override;
160
    virtual void SAL_CALL   removeByName( const OUString& aName ) override;
161
    virtual void SAL_CALL   outputList( const css::table::CellAddress& aOutputPosition ) override;
162
163
                            /// XNameAccess
164
    virtual css::uno::Any SAL_CALL getByName( const OUString& aName ) override;
165
    virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override;
166
    virtual sal_Bool SAL_CALL hasByName( const OUString& aName ) override;
167
168
                            /// XIndexAccess
169
    virtual sal_Int32 SAL_CALL getCount() override;
170
    virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
171
172
                            /// XEnumerationAccess
173
    virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
174
                            createEnumeration() override;
175
176
                            /// XElementAccess
177
    virtual css::uno::Type SAL_CALL getElementType() override;
178
    virtual sal_Bool SAL_CALL hasElements() override;
179
180
                            /// XPropertySet
181
    virtual css::uno::Reference< css::beans::XPropertySetInfo >
182
                            SAL_CALL getPropertySetInfo() override;
183
    virtual void SAL_CALL   setPropertyValue( const OUString& aPropertyName,
184
                                    const css::uno::Any& aValue ) override;
185
    virtual css::uno::Any SAL_CALL getPropertyValue(
186
                                    const OUString& PropertyName ) override;
187
    virtual void SAL_CALL   addPropertyChangeListener( const OUString& aPropertyName,
188
                                    const css::uno::Reference<
189
                                        css::beans::XPropertyChangeListener >& xListener ) override;
190
    virtual void SAL_CALL   removePropertyChangeListener( const OUString& aPropertyName,
191
                                    const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
192
    virtual void SAL_CALL   addVetoableChangeListener( const OUString& PropertyName,
193
                                    const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
194
    virtual void SAL_CALL   removeVetoableChangeListener( const OUString& PropertyName,
195
                                    const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
196
197
                            /// XActionLockable
198
    virtual sal_Bool SAL_CALL isActionLocked() override;
199
    virtual void SAL_CALL addActionLock() override;
200
    virtual void SAL_CALL removeActionLock() override;
201
    virtual void SAL_CALL setActionLocks( sal_Int16 nLock ) override;
202
    virtual sal_Int16 SAL_CALL resetActionLocks() override;
203
204
                            /// XServiceInfo
205
    virtual OUString SAL_CALL getImplementationName() override;
206
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
207
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
208
};
209
210
class ScGlobalNamedRangesObj final : public ScNamedRangesObj
211
{
212
private:
213
214
    virtual rtl::Reference<ScNamedRangeObj> GetObjectByIndex_Impl(sal_uInt16 nIndex) override;
215
    virtual rtl::Reference<ScNamedRangeObj> GetObjectByName_Impl(const OUString& aName) override;
216
217
    virtual ScRangeName*    GetRangeName_Impl() override;
218
    virtual SCTAB           GetTab_Impl() override;
219
220
public:
221
                            ScGlobalNamedRangesObj(ScDocShell* pDocSh);
222
    virtual                 ~ScGlobalNamedRangesObj() override;
223
};
224
225
class ScLocalNamedRangesObj final : public ScNamedRangesObj
226
{
227
private:
228
229
    virtual rtl::Reference<ScNamedRangeObj> GetObjectByIndex_Impl(sal_uInt16 nIndex) override;
230
    virtual rtl::Reference<ScNamedRangeObj> GetObjectByName_Impl(const OUString& aName) override;
231
232
    virtual ScRangeName*    GetRangeName_Impl() override;
233
    virtual SCTAB           GetTab_Impl() override;
234
235
    css::uno::Reference< css::container::XNamed > mxSheet;
236
public:
237
                            ScLocalNamedRangesObj(ScDocShell* pDocSh, css::uno::Reference< css::container::XNamed > xNamed );
238
    virtual                 ~ScLocalNamedRangesObj() override;
239
};
240
241
class ScLabelRangeObj final : public ::cppu::WeakImplHelper<
242
                            css::sheet::XLabelRange,
243
                            css::lang::XServiceInfo >,
244
                        public SfxListener
245
{
246
private:
247
    ScDocShell*             pDocShell;
248
    bool                    bColumn;
249
    ScRange                 aRange;         ///< criterion to find range
250
251
private:
252
    ScRangePair*            GetData_Impl();
253
    void                    Modify_Impl( const ScRange* pLabel, const ScRange* pData );
254
255
public:
256
                            ScLabelRangeObj(ScDocShell* pDocSh, bool bCol, const ScRange& rR);
257
    virtual                 ~ScLabelRangeObj() override;
258
259
    virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
260
261
                            /// XLabelRange
262
    virtual css::table::CellRangeAddress SAL_CALL getLabelArea() override;
263
    virtual void SAL_CALL   setLabelArea( const css::table::CellRangeAddress& aLabelArea ) override;
264
    virtual css::table::CellRangeAddress SAL_CALL getDataArea() override;
265
    virtual void SAL_CALL   setDataArea( const css::table::CellRangeAddress& aDataArea ) override;
266
267
                            /// XServiceInfo
268
    virtual OUString SAL_CALL getImplementationName() override;
269
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
270
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
271
};
272
273
class ScLabelRangesObj final : public ::cppu::WeakImplHelper<
274
                            css::sheet::XLabelRanges,
275
                            css::container::XEnumerationAccess,
276
                            css::lang::XServiceInfo >,
277
                        public SfxListener
278
{
279
private:
280
    ScDocShell*             pDocShell;
281
    bool                    bColumn;
282
283
    rtl::Reference<ScLabelRangeObj> GetObjectByIndex_Impl(size_t nIndex);
284
285
public:
286
                            ScLabelRangesObj(ScDocShell* pDocSh, bool bCol);
287
    virtual                 ~ScLabelRangesObj() override;
288
289
    virtual void            Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
290
291
                            /// XLabelRanges
292
    virtual void SAL_CALL   addNew( const css::table::CellRangeAddress& aLabelArea,
293
                                const css::table::CellRangeAddress& aDataArea ) override;
294
    virtual void SAL_CALL   removeByIndex( sal_Int32 nIndex ) override;
295
296
                            /// XIndexAccess
297
    virtual sal_Int32 SAL_CALL getCount() override;
298
    virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
299
300
                            /// XEnumerationAccess
301
    virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
302
                            createEnumeration() override;
303
304
                            /// XElementAccess
305
    virtual css::uno::Type SAL_CALL getElementType() override;
306
    virtual sal_Bool SAL_CALL hasElements() override;
307
308
                            /// XServiceInfo
309
    virtual OUString SAL_CALL getImplementationName() override;
310
    virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
311
    virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
312
};
313
314
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */