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/lang/XUnoTunnel.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/document/XActionLockable.hpp>
37 #include <cppuhelper/implbase.hxx>
38 #include <rtl/ref.hxx>
40 namespace com::sun::star::container
{ class XNamed
; }
43 class ScNamedRangesObj
;
45 class SC_DLLPUBLIC ScNamedRangeObj final
: public ::cppu::WeakImplHelper
<
46 css::sheet::XNamedRange
,
47 css::sheet::XFormulaTokens
,
48 css::sheet::XCellRangeReferrer
,
49 css::beans::XPropertySet
,
50 css::lang::XUnoTunnel
,
51 css::lang::XServiceInfo
>,
55 rtl::Reference
< ScNamedRangesObj
> mxParent
;
56 ScDocShell
* pDocShell
;
58 css::uno::Reference
< css::container::XNamed
> mxSheet
;
61 friend class ScVbaName
;
62 ScRangeData
* GetRangeData_Impl();
63 void Modify_Impl( const OUString
* pNewName
,
64 const ScTokenArray
* pNewTokens
, const OUString
* pNewContent
,
65 const ScAddress
* pNewPos
, const ScRangeData::Type
* pNewType
,
66 const formula::FormulaGrammar::Grammar eGrammar
);
70 ScNamedRangeObj( rtl::Reference
< ScNamedRangesObj
> const & xParent
, ScDocShell
* pDocSh
, const OUString
& rNm
,
71 css::uno::Reference
< css::container::XNamed
> const & xSheet
= css::uno::Reference
< css::container::XNamed
> ());
72 virtual ~ScNamedRangeObj() override
;
74 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
77 virtual OUString SAL_CALL
getContent() override
;
78 virtual void SAL_CALL
setContent( const OUString
& aContent
) override
;
79 virtual css::table::CellAddress SAL_CALL
getReferencePosition() override
;
80 virtual void SAL_CALL
setReferencePosition(
81 const css::table::CellAddress
& aReferencePosition
) override
;
82 virtual sal_Int32 SAL_CALL
getType() override
;
83 virtual void SAL_CALL
setType( sal_Int32 nType
) override
;
86 virtual css::uno::Sequence
< css::sheet::FormulaToken
> SAL_CALL
getTokens() override
;
87 virtual void SAL_CALL
setTokens( const css::uno::Sequence
< css::sheet::FormulaToken
>& aTokens
) override
;
90 virtual OUString SAL_CALL
getName() override
;
91 virtual void SAL_CALL
setName( const OUString
& aName
) override
;
93 /// XCellRangeReferrer
94 virtual css::uno::Reference
< css::table::XCellRange
> SAL_CALL
95 getReferredCells() override
;
98 virtual css::uno::Reference
< css::beans::XPropertySetInfo
>
99 SAL_CALL
getPropertySetInfo() override
;
100 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
,
101 const css::uno::Any
& aValue
) override
;
102 virtual css::uno::Any SAL_CALL
getPropertyValue( const OUString
& PropertyName
) override
;
103 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
,
104 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
;
105 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
,
106 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& aListener
) override
;
107 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
,
108 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
109 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
,
110 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
113 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
< sal_Int8
>& aIdentifier
) override
;
115 static const css::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
118 virtual OUString SAL_CALL
getImplementationName() override
;
119 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
120 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
123 class ScNamedRangesObj
: public ::cppu::WeakImplHelper
<
124 css::sheet::XNamedRanges
,
125 css::container::XEnumerationAccess
,
126 css::container::XIndexAccess
,
127 css::beans::XPropertySet
,
128 css::document::XActionLockable
,
129 css::lang::XServiceInfo
>,
134 /** if true, adding new name or modifying existing one will set the
135 document 'modified' and broadcast the change. We turn this off during
137 bool mbModifyAndBroadcast
;
139 virtual rtl::Reference
<ScNamedRangeObj
> GetObjectByIndex_Impl(sal_uInt16 nIndex
) = 0;
140 virtual rtl::Reference
<ScNamedRangeObj
> GetObjectByName_Impl(const OUString
& aName
) = 0;
142 virtual ScRangeName
* GetRangeName_Impl() = 0;
143 virtual SCTAB
GetTab_Impl() = 0;
147 ScDocShell
* pDocShell
;
148 /** called from the XActionLockable interface methods on initial locking */
151 /** called from the XActionLockable interface methods on final unlock */
155 ScNamedRangesObj(ScDocShell
* pDocSh
);
156 virtual ~ScNamedRangesObj() override
;
158 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
160 bool IsModifyAndBroadcast() const { return mbModifyAndBroadcast
;}
163 virtual void SAL_CALL
addNewByName( const OUString
& aName
, const OUString
& aContent
,
164 const css::table::CellAddress
& aPosition
, sal_Int32 nType
) override
;
165 virtual void SAL_CALL
addNewFromTitles( const css::table::CellRangeAddress
& aSource
,
166 css::sheet::Border aBorder
) override
;
167 virtual void SAL_CALL
removeByName( const OUString
& aName
) override
;
168 virtual void SAL_CALL
outputList( const css::table::CellAddress
& aOutputPosition
) override
;
171 virtual css::uno::Any SAL_CALL
getByName( const OUString
& aName
) override
;
172 virtual css::uno::Sequence
< OUString
> SAL_CALL
getElementNames() override
;
173 virtual sal_Bool SAL_CALL
hasByName( const OUString
& aName
) override
;
176 virtual sal_Int32 SAL_CALL
getCount() override
;
177 virtual css::uno::Any SAL_CALL
getByIndex( sal_Int32 Index
) override
;
179 /// XEnumerationAccess
180 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
181 createEnumeration() override
;
184 virtual css::uno::Type SAL_CALL
getElementType() override
;
185 virtual sal_Bool SAL_CALL
hasElements() override
;
188 virtual css::uno::Reference
< css::beans::XPropertySetInfo
>
189 SAL_CALL
getPropertySetInfo() override
;
190 virtual void SAL_CALL
setPropertyValue( const OUString
& aPropertyName
,
191 const css::uno::Any
& aValue
) override
;
192 virtual css::uno::Any SAL_CALL
getPropertyValue(
193 const OUString
& PropertyName
) override
;
194 virtual void SAL_CALL
addPropertyChangeListener( const OUString
& aPropertyName
,
195 const css::uno::Reference
<
196 css::beans::XPropertyChangeListener
>& xListener
) override
;
197 virtual void SAL_CALL
removePropertyChangeListener( const OUString
& aPropertyName
,
198 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& aListener
) override
;
199 virtual void SAL_CALL
addVetoableChangeListener( const OUString
& PropertyName
,
200 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
201 virtual void SAL_CALL
removeVetoableChangeListener( const OUString
& PropertyName
,
202 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
205 virtual sal_Bool SAL_CALL
isActionLocked() override
;
206 virtual void SAL_CALL
addActionLock() override
;
207 virtual void SAL_CALL
removeActionLock() override
;
208 virtual void SAL_CALL
setActionLocks( sal_Int16 nLock
) override
;
209 virtual sal_Int16 SAL_CALL
resetActionLocks() override
;
212 virtual OUString SAL_CALL
getImplementationName() override
;
213 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
214 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
217 class ScGlobalNamedRangesObj final
: public ScNamedRangesObj
221 virtual rtl::Reference
<ScNamedRangeObj
> GetObjectByIndex_Impl(sal_uInt16 nIndex
) override
;
222 virtual rtl::Reference
<ScNamedRangeObj
> GetObjectByName_Impl(const OUString
& aName
) override
;
224 virtual ScRangeName
* GetRangeName_Impl() override
;
225 virtual SCTAB
GetTab_Impl() override
;
228 ScGlobalNamedRangesObj(ScDocShell
* pDocSh
);
229 virtual ~ScGlobalNamedRangesObj() override
;
232 class ScLocalNamedRangesObj final
: public ScNamedRangesObj
236 virtual rtl::Reference
<ScNamedRangeObj
> GetObjectByIndex_Impl(sal_uInt16 nIndex
) override
;
237 virtual rtl::Reference
<ScNamedRangeObj
> GetObjectByName_Impl(const OUString
& aName
) override
;
239 virtual ScRangeName
* GetRangeName_Impl() override
;
240 virtual SCTAB
GetTab_Impl() override
;
242 css::uno::Reference
< css::container::XNamed
> mxSheet
;
244 ScLocalNamedRangesObj(ScDocShell
* pDocSh
, css::uno::Reference
< css::container::XNamed
> const & xNamed
);
245 virtual ~ScLocalNamedRangesObj() override
;
248 class ScLabelRangeObj final
: public ::cppu::WeakImplHelper
<
249 css::sheet::XLabelRange
,
250 css::lang::XServiceInfo
>,
254 ScDocShell
* pDocShell
;
256 ScRange aRange
; ///< criterion to find range
259 ScRangePair
* GetData_Impl();
260 void Modify_Impl( const ScRange
* pLabel
, const ScRange
* pData
);
263 ScLabelRangeObj(ScDocShell
* pDocSh
, bool bCol
, const ScRange
& rR
);
264 virtual ~ScLabelRangeObj() override
;
266 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
269 virtual css::table::CellRangeAddress SAL_CALL
getLabelArea() override
;
270 virtual void SAL_CALL
setLabelArea( const css::table::CellRangeAddress
& aLabelArea
) override
;
271 virtual css::table::CellRangeAddress SAL_CALL
getDataArea() override
;
272 virtual void SAL_CALL
setDataArea( const css::table::CellRangeAddress
& aDataArea
) override
;
275 virtual OUString SAL_CALL
getImplementationName() override
;
276 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
277 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
280 class ScLabelRangesObj final
: public ::cppu::WeakImplHelper
<
281 css::sheet::XLabelRanges
,
282 css::container::XEnumerationAccess
,
283 css::lang::XServiceInfo
>,
287 ScDocShell
* pDocShell
;
290 rtl::Reference
<ScLabelRangeObj
> GetObjectByIndex_Impl(size_t nIndex
);
293 ScLabelRangesObj(ScDocShell
* pDocSh
, bool bCol
);
294 virtual ~ScLabelRangesObj() override
;
296 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
299 virtual void SAL_CALL
addNew( const css::table::CellRangeAddress
& aLabelArea
,
300 const css::table::CellRangeAddress
& aDataArea
) override
;
301 virtual void SAL_CALL
removeByIndex( sal_Int32 nIndex
) override
;
304 virtual sal_Int32 SAL_CALL
getCount() override
;
305 virtual css::uno::Any SAL_CALL
getByIndex( sal_Int32 Index
) override
;
307 /// XEnumerationAccess
308 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
309 createEnumeration() override
;
312 virtual css::uno::Type SAL_CALL
getElementType() override
;
313 virtual sal_Bool SAL_CALL
hasElements() override
;
316 virtual OUString SAL_CALL
getImplementationName() override
;
317 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
318 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
321 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */