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 .
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>
39 namespace com::sun::star::container
{ class XNamed
; }
42 class ScNamedRangesObj
;
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
>,
53 rtl::Reference
< ScNamedRangesObj
> mxParent
;
54 ScDocShell
* pDocShell
;
56 css::uno::Reference
< css::container::XNamed
> mxSheet
;
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
);
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
;
72 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
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
;
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
;
88 virtual OUString SAL_CALL
getName() override
;
89 virtual void SAL_CALL
setName( const OUString
& aName
) override
;
91 /// XCellRangeReferrer
92 virtual css::uno::Reference
< css::table::XCellRange
> SAL_CALL
93 getReferredCells() override
;
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
;
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
;
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
>,
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
130 bool mbModifyAndBroadcast
;
132 virtual rtl::Reference
<ScNamedRangeObj
> GetObjectByIndex_Impl(sal_uInt16 nIndex
) = 0;
133 virtual rtl::Reference
<ScNamedRangeObj
> GetObjectByName_Impl(const OUString
& aName
) = 0;
135 virtual ScRangeName
* GetRangeName_Impl() = 0;
136 virtual SCTAB
GetTab_Impl() = 0;
140 ScDocShell
* pDocShell
;
141 /** called from the XActionLockable interface methods on initial locking */
144 /** called from the XActionLockable interface methods on final unlock */
148 ScNamedRangesObj(ScDocShell
* pDocSh
);
149 virtual ~ScNamedRangesObj() override
;
151 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
153 bool IsModifyAndBroadcast() const { return mbModifyAndBroadcast
;}
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
;
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
;
169 virtual sal_Int32 SAL_CALL
getCount() override
;
170 virtual css::uno::Any SAL_CALL
getByIndex( sal_Int32 Index
) override
;
172 /// XEnumerationAccess
173 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
174 createEnumeration() override
;
177 virtual css::uno::Type SAL_CALL
getElementType() override
;
178 virtual sal_Bool SAL_CALL
hasElements() override
;
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
;
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
;
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
;
210 class ScGlobalNamedRangesObj final
: public ScNamedRangesObj
214 virtual rtl::Reference
<ScNamedRangeObj
> GetObjectByIndex_Impl(sal_uInt16 nIndex
) override
;
215 virtual rtl::Reference
<ScNamedRangeObj
> GetObjectByName_Impl(const OUString
& aName
) override
;
217 virtual ScRangeName
* GetRangeName_Impl() override
;
218 virtual SCTAB
GetTab_Impl() override
;
221 ScGlobalNamedRangesObj(ScDocShell
* pDocSh
);
222 virtual ~ScGlobalNamedRangesObj() override
;
225 class ScLocalNamedRangesObj final
: public ScNamedRangesObj
229 virtual rtl::Reference
<ScNamedRangeObj
> GetObjectByIndex_Impl(sal_uInt16 nIndex
) override
;
230 virtual rtl::Reference
<ScNamedRangeObj
> GetObjectByName_Impl(const OUString
& aName
) override
;
232 virtual ScRangeName
* GetRangeName_Impl() override
;
233 virtual SCTAB
GetTab_Impl() override
;
235 css::uno::Reference
< css::container::XNamed
> mxSheet
;
237 ScLocalNamedRangesObj(ScDocShell
* pDocSh
, css::uno::Reference
< css::container::XNamed
> xNamed
);
238 virtual ~ScLocalNamedRangesObj() override
;
241 class ScLabelRangeObj final
: public ::cppu::WeakImplHelper
<
242 css::sheet::XLabelRange
,
243 css::lang::XServiceInfo
>,
247 ScDocShell
* pDocShell
;
249 ScRange aRange
; ///< criterion to find range
252 ScRangePair
* GetData_Impl();
253 void Modify_Impl( const ScRange
* pLabel
, const ScRange
* pData
);
256 ScLabelRangeObj(ScDocShell
* pDocSh
, bool bCol
, const ScRange
& rR
);
257 virtual ~ScLabelRangeObj() override
;
259 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
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
;
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
;
273 class ScLabelRangesObj final
: public ::cppu::WeakImplHelper
<
274 css::sheet::XLabelRanges
,
275 css::container::XEnumerationAccess
,
276 css::lang::XServiceInfo
>,
280 ScDocShell
* pDocShell
;
283 rtl::Reference
<ScLabelRangeObj
> GetObjectByIndex_Impl(size_t nIndex
);
286 ScLabelRangesObj(ScDocShell
* pDocSh
, bool bCol
);
287 virtual ~ScLabelRangesObj() override
;
289 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
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
;
297 virtual sal_Int32 SAL_CALL
getCount() override
;
298 virtual css::uno::Any SAL_CALL
getByIndex( sal_Int32 Index
) override
;
300 /// XEnumerationAccess
301 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
302 createEnumeration() override
;
305 virtual css::uno::Type SAL_CALL
getElementType() override
;
306 virtual sal_Bool SAL_CALL
hasElements() override
;
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
;
314 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */