LibreOffice Module sc (master)  1
fielduno.hxx
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 #pragma once
21 
22 #include "address.hxx"
23 
24 #include <svl/lstner.hxx>
25 #include <editeng/editdata.hxx>
26 #include <com/sun/star/text/XTextField.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/container/XContainer.hpp>
29 #include <com/sun/star/lang/XUnoTunnel.hpp>
30 #include <com/sun/star/container/XEnumerationAccess.hpp>
31 #include <com/sun/star/container/XIndexAccess.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/util/XRefreshable.hpp>
34 #include <com/sun/star/util/DateTime.hpp>
37 #include <cppuhelper/component.hxx>
38 #include <cppuhelper/implbase.hxx>
39 #include <comphelper/compbase.hxx>
40 #include <osl/mutex.hxx>
41 
42 #include <memory>
43 
44 class ScEditSource;
45 class SvxFieldItem;
46 class SvxFieldData;
47 class ScDocShell;
49 class SfxItemPropertySet;
50 
51 class ScCellFieldsObj final : public cppu::WeakImplHelper<
52  css::container::XEnumerationAccess,
53  css::container::XIndexAccess,
54  css::container::XContainer,
55  css::util::XRefreshable,
56  css::lang::XServiceInfo >,
57  public SfxListener
58 {
59 private:
60  css::uno::Reference<css::text::XTextRange> mxContent;
63  std::unique_ptr<ScEditSource> mpEditSource;
65  std::unique_ptr<comphelper::OInterfaceContainerHelper3<css::util::XRefreshListener>> mpRefreshListeners;
67  osl::Mutex aMutex;
68 
69  css::uno::Reference<css::text::XTextField>
70  GetObjectByIndex_Impl(sal_Int32 Index) const;
71 
72 public:
74  const css::uno::Reference<css::text::XTextRange>& xContent,
75  ScDocShell* pDocSh, const ScAddress& rPos);
76  virtual ~ScCellFieldsObj() override;
77 
78  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
79 
80  // XIndexAccess
81  virtual sal_Int32 SAL_CALL getCount() override;
82  virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
83 
84  // XEnumerationAccess
85  virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
86  createEnumeration() override;
87 
88  // XElementAccess
89  virtual css::uno::Type SAL_CALL getElementType() override;
90  virtual sal_Bool SAL_CALL hasElements() override;
91 
92  // XContainer
93  virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
94  virtual void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
95 
96  // XRefreshable
97  virtual void SAL_CALL refresh( ) override;
98  virtual void SAL_CALL addRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
99  virtual void SAL_CALL removeRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
100 
101  // XServiceInfo
102  virtual OUString SAL_CALL getImplementationName() override;
103  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
104  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
105 };
106 
107 class ScHeaderFieldsObj final : public cppu::WeakImplHelper<
108  css::container::XEnumerationAccess,
109  css::container::XIndexAccess,
110  css::container::XContainer,
111  css::util::XRefreshable,
112  css::lang::XServiceInfo >
113 {
114 private:
116  std::unique_ptr<ScEditSource> mpEditSource;
117 
119  std::unique_ptr<comphelper::OInterfaceContainerHelper3<css::util::XRefreshListener>> mpRefreshListeners;
121  osl::Mutex aMutex;
122 
123  css::uno::Reference< css::text::XTextField>
124  GetObjectByIndex_Impl(sal_Int32 Index) const;
125 
126 public:
128  virtual ~ScHeaderFieldsObj() override;
129 
130  // XIndexAccess
131  virtual sal_Int32 SAL_CALL getCount() override;
132  virtual css::uno::Any SAL_CALL getByIndex( sal_Int32 Index ) override;
133 
134  // XEnumerationAccess
135  virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
136  createEnumeration() override;
137 
138  // XElementAccess
139  virtual css::uno::Type SAL_CALL getElementType() override;
140  virtual sal_Bool SAL_CALL hasElements() override;
141 
142  // XContainer
143  virtual void SAL_CALL addContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
144  virtual void SAL_CALL removeContainerListener( const css::uno::Reference< css::container::XContainerListener >& xListener ) override;
145 
146  // XRefreshable
147  virtual void SAL_CALL refresh( ) override;
148  virtual void SAL_CALL addRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
149  virtual void SAL_CALL removeRefreshListener( const css::uno::Reference< css::util::XRefreshListener >& l ) override;
150 
151  // XServiceInfo
152  virtual OUString SAL_CALL getImplementationName() override;
153  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
154  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
155 };
156 
162  css::text::XTextField,
163  css::beans::XPropertySet,
164  css::lang::XUnoTunnel,
165  css::lang::XServiceInfo> ScEditFieldObj_Base;
167 {
168  ScEditFieldObj() = delete;
169  ScEditFieldObj(const ScEditFieldObj&) = delete;
170  const ScEditFieldObj& operator=(const ScEditFieldObj&) = delete;
171 
173  std::unique_ptr<ScEditSource> mpEditSource;
175 
176  sal_Int32 meType;
177  std::unique_ptr<SvxFieldData> mpData;
178  css::uno::Reference<css::text::XTextRange> mpContent;
179 
180  css::util::DateTime maDateTime;
181  sal_Int32 mnNumFormat;
182  bool mbIsDate:1;
183  bool mbIsFixed:1;
184 
185 private:
187 
188  void setPropertyValueURL(const OUString& rName, const css::uno::Any& rVal);
189  css::uno::Any getPropertyValueURL(const OUString& rName);
190 
191  void setPropertyValueFile(const OUString& rName, const css::uno::Any& rVal);
192  css::uno::Any getPropertyValueFile(const OUString& rName);
193 
194  void setPropertyValueDateTime(const OUString& rName, const css::uno::Any& rVal);
195  css::uno::Any getPropertyValueDateTime(const OUString& rName);
196 
197  void setPropertyValueSheet(const OUString& rName, const css::uno::Any& rVal);
198 
199 public:
201  const css::uno::Reference<css::text::XTextRange>& rContent,
202  std::unique_ptr<ScEditSource> pEditSrc, sal_Int32 eType, const ESelection& rSel);
203  virtual ~ScEditFieldObj() override;
204 
205  sal_Int32 GetFieldType() const { return meType;}
206  void DeleteField();
207  bool IsInserted() const;
209  void InitDoc(
210  const css::uno::Reference<css::text::XTextRange>& rContent,
211  std::unique_ptr<ScEditSource> pEditSrc, const ESelection& rSel);
212 
213  // XTextField
214  virtual OUString SAL_CALL getPresentation( sal_Bool bShowCommand ) override;
215 
216  // XTextContent
217  virtual void SAL_CALL attach( const css::uno::Reference< css::text::XTextRange >& xTextRange ) override;
218  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
219  getAnchor() override;
220 
221  // XPropertySet
222  virtual css::uno::Reference< css::beans::XPropertySetInfo >
223  SAL_CALL getPropertySetInfo() override;
224  virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName,
225  const css::uno::Any& aValue ) override;
226  virtual css::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) override;
227  virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName,
228  const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
229  virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName,
230  const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
231  virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName,
232  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
233  virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName,
234  const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
235 
236  // XUnoTunnel
238 
239  // XServiceInfo
240  virtual OUString SAL_CALL getImplementationName() override;
241  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
242  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
243 
244  // XTypeProvider
245  virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override;
246  virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override;
247 };
248 
249 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::unique_ptr< ScEditSource > mpEditSource
Definition: fielduno.hxx:173
Type
virtual OUString SAL_CALL getPresentation(sal_Bool bShowCommand) override
Definition: fielduno.cxx:1119
virtual OUString SAL_CALL getImplementationName() override
std::unique_ptr< SvxFieldData > mpData
Definition: fielduno.hxx:177
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
std::unique_ptr< ScEditSource > mpEditSource
Definition: fielduno.hxx:63
osl::Mutex aMutex
mutex to lock the InterfaceContainerHelper
Definition: fielduno.hxx:121
virtual void SAL_CALL removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
Definition: fielduno.cxx:536
bool IsInserted() const
Definition: fielduno.cxx:1112
ESelection aSelection
Definition: fielduno.hxx:174
std::unique_ptr< ScEditSource > mpEditSource
Definition: fielduno.hxx:116
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getAnchor() override
Definition: fielduno.cxx:1170
signed char sal_Int8
const SfxItemPropertySet * pPropSet
Definition: fielduno.hxx:172
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: fielduno.cxx:1178
virtual void SAL_CALL refresh() override
Definition: fielduno.cxx:543
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: fielduno.cxx:373
ScHeaderFooterTextData & mrData
Definition: fielduno.hxx:115
virtual css::uno::Type SAL_CALL getElementType() override
Definition: fielduno.cxx:512
virtual ~ScCellFieldsObj() override
Definition: fielduno.cxx:284
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: fielduno.cxx:305
virtual void SAL_CALL addContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
Definition: fielduno.cxx:379
#define UNO3_GETIMPLEMENTATION_DECL(classname)
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
Definition: fielduno.cxx:1299
css::uno::Reference< css::text::XTextRange > mxContent
Definition: fielduno.hxx:60
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
void setPropertyValueURL(const OUString &rName, const css::uno::Any &rVal)
Definition: fielduno.cxx:622
css::uno::Reference< css::text::XTextRange > mpContent
Definition: fielduno.hxx:178
virtual OUString SAL_CALL getImplementationName() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: fielduno.cxx:524
ScAddress aCellPos
Definition: fielduno.hxx:62
comphelper::WeakComponentImplHelper< css::text::XTextField, css::beans::XPropertySet, css::lang::XUnoTunnel, css::lang::XServiceInfo > ScEditFieldObj_Base
Generic UNO wrapper for edit engine's field item in cells, headers, and footers.
Definition: fielduno.hxx:165
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL removeRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
Definition: fielduno.cxx:565
virtual void SAL_CALL attach(const css::uno::Reference< css::text::XTextRange > &xTextRange) override
Definition: fielduno.cxx:1157
css::uno::Reference< css::text::XTextField > GetObjectByIndex_Impl(sal_Int32 Index) const
Definition: fielduno.cxx:448
ScEditFieldObj()=delete
virtual void SAL_CALL removeContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
Definition: fielduno.cxx:385
SvxFieldItem CreateFieldItem()
Definition: fielduno.cxx:1090
sal_Int32 meType
Definition: fielduno.hxx:176
css::uno::Reference< css::text::XTextField > GetObjectByIndex_Impl(sal_Int32 Index) const
Definition: fielduno.cxx:321
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
Definition: fielduno.cxx:1286
css::uno::Any getPropertyValueFile(const OUString &rName)
Definition: fielduno.cxx:770
virtual void SAL_CALL refresh() override
Definition: fielduno.cxx:392
virtual sal_Int32 SAL_CALL getCount() override
Definition: fielduno.cxx:492
void InitDoc(const css::uno::Reference< css::text::XTextRange > &rContent, std::unique_ptr< ScEditSource > pEditSrc, const ESelection &rSel)
Definition: fielduno.cxx:1073
virtual ~ScHeaderFieldsObj() override
Definition: fielduno.cxx:430
virtual OUString SAL_CALL getImplementationName() override
Definition: fielduno.cxx:1270
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual void SAL_CALL addContainerListener(const css::uno::Reference< css::container::XContainerListener > &xListener) override
Definition: fielduno.cxx:530
osl::Mutex aMutex
mutex to lock the InterfaceContainerHelper
Definition: fielduno.hxx:67
unsigned char sal_Bool
virtual ~ScEditFieldObj() override
Definition: fielduno.cxx:1086
virtual sal_Bool SAL_CALL hasElements() override
Definition: fielduno.cxx:367
css::util::DateTime maDateTime
Definition: fielduno.hxx:180
SvxFieldData & getData()
Definition: fielduno.cxx:575
void setPropertyValueFile(const OUString &rName, const css::uno::Any &rVal)
Definition: fielduno.cxx:737
css::uno::Any getPropertyValueDateTime(const OUString &rName)
Definition: fielduno.cxx:894
virtual sal_Int32 SAL_CALL getCount() override
Definition: fielduno.cxx:340
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: fielduno.cxx:1275
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: fielduno.cxx:1280
ScHeaderFieldsObj(ScHeaderFooterTextData &rData)
Definition: fielduno.cxx:424
void DeleteField()
Definition: fielduno.cxx:1096
virtual void SAL_CALL addRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
Definition: fielduno.cxx:403
std::unique_ptr< comphelper::OInterfaceContainerHelper3< css::util::XRefreshListener > > mpRefreshListeners
List of refresh listeners.
Definition: fielduno.hxx:119
sal_Int32 GetFieldType() const
Definition: fielduno.hxx:205
css::uno::Any getPropertyValueURL(const OUString &rName)
Definition: fielduno.cxx:688
virtual void SAL_CALL removeRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
Definition: fielduno.cxx:414
sal_Int32 mnNumFormat
Definition: fielduno.hxx:181
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: fielduno.cxx:502
std::unique_ptr< comphelper::OInterfaceContainerHelper3< css::util::XRefreshListener > > mpRefreshListeners
List of refresh listeners.
Definition: fielduno.hxx:65
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
ScDocShell * pDocShell
Definition: fielduno.hxx:61
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
Definition: fielduno.cxx:1185
virtual void SAL_CALL addRefreshListener(const css::uno::Reference< css::util::XRefreshListener > &l) override
Definition: fielduno.cxx:554
virtual css::uno::Any SAL_CALL getByIndex(sal_Int32 Index) override
Definition: fielduno.cxx:351
virtual css::uno::Type SAL_CALL getElementType() override
Definition: fielduno.cxx:361
void setPropertyValueDateTime(const OUString &rName, const css::uno::Any &rVal)
Definition: fielduno.cxx:800
void setPropertyValueSheet(const OUString &rName, const css::uno::Any &rVal)
Definition: fielduno.cxx:999
struct _ADOIndex Index
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual sal_Bool SAL_CALL hasElements() override
Definition: fielduno.cxx:518
ScCellFieldsObj(const css::uno::Reference< css::text::XTextRange > &xContent, ScDocShell *pDocSh, const ScAddress &rPos)
Definition: fielduno.cxx:272
const ScEditFieldObj & operator=(const ScEditFieldObj &)=delete
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
Definition: fielduno.cxx:1217