LibreOffice Module sc (master)  1
textuno.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 #include <editeng/unotext.hxx>
24 #include <svl/lstner.hxx>
25 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
26 #include <com/sun/star/sheet/XHeaderFooterContent.hpp>
27 #include <com/sun/star/lang/XServiceInfo.hpp>
28 #include <com/sun/star/lang/XUnoTunnel.hpp>
30 #include <cppuhelper/implbase.hxx>
31 #include <cppuhelper/weakref.hxx>
32 
33 #include <rtl/ref.hxx>
34 
35 #include <memory>
36 
37 class EditEngine;
38 class EditTextObject;
40 class ScDocShell;
41 class ScCellObj;
42 class ScSimpleEditSource;
43 class ScCellEditSource;
45 class ScFieldEditEngine;
47 
48 struct ScHeaderFieldData;
49 
51 
52 // ScHeaderFooterContentObj is a dumb container which must be re-written into
53 // the page template using setPropertyValue
54 
55 class ScHeaderFooterContentObj final : public cppu::WeakImplHelper<
56  css::sheet::XHeaderFooterContent,
57  css::lang::XUnoTunnel,
58  css::lang::XServiceInfo >
59 {
60 private:
64 
65 public:
67  virtual ~ScHeaderFooterContentObj() override;
68 
69  // for ScPageHFItem (using getImplementation)
70  const EditTextObject* GetLeftEditObject() const;
71  const EditTextObject* GetCenterEditObject() const;
72  const EditTextObject* GetRightEditObject() const;
73 
74  void Init( const EditTextObject* pLeft,
75  const EditTextObject* pCenter,
76  const EditTextObject* pRight);
77 
78  // XHeaderFooterContent
79  virtual css::uno::Reference< css::text::XText > SAL_CALL
80  getLeftText() override;
81  virtual css::uno::Reference< css::text::XText > SAL_CALL
82  getCenterText() override;
83  virtual css::uno::Reference< css::text::XText > SAL_CALL
84  getRightText() override;
85 
86  // XUnoTunnel
87  virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence<
88  sal_Int8 >& aIdentifier ) override;
89 
90  static const css::uno::Sequence<sal_Int8>& getUnoTunnelId();
91  static rtl::Reference<ScHeaderFooterContentObj> getImplementation(const css::uno::Reference<css::sheet::XHeaderFooterContent>& rObj);
92 
93  // XServiceInfo
94  virtual OUString SAL_CALL getImplementationName() override;
95  virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
96  virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
97 
98 };
99 
100 // ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
101 
103 {
104 private:
105  std::unique_ptr<EditTextObject> mpTextObj;
106  css::uno::WeakReference<css::sheet::XHeaderFooterContent> xContentObj;
108  std::unique_ptr<ScEditEngineDefaulter> pEditEngine;
109  std::unique_ptr<SvxEditEngineForwarder> pForwarder;
111 
112 public:
116  css::uno::WeakReference<css::sheet::XHeaderFooterContent> const & xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj);
118 
119  // helper functions
121  void UpdateData();
122  void UpdateData(EditEngine& rEditEngine);
123  ScEditEngineDefaulter* GetEditEngine() { GetTextForwarder(); return pEditEngine.get(); }
124 
125  ScHeaderFooterPart GetPart() const { return nPart; }
126  css::uno::Reference<css::sheet::XHeaderFooterContent> GetContentObj() const { return xContentObj; }
127 
128  const EditTextObject* GetTextObject() const { return mpTextObj.get(); }
129 };
130 
137 class ScHeaderFooterTextObj : public cppu::WeakImplHelper<
138  css::text::XText,
139  css::text::XTextRangeMover,
140  css::container::XEnumerationAccess,
141  css::text::XTextFieldsSupplier,
142  css::lang::XServiceInfo >
143 {
144 private:
147 
148  void CreateUnoText_Impl();
149 
150 public:
152  const css::uno::WeakReference<css::sheet::XHeaderFooterContent>& xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj);
153  virtual ~ScHeaderFooterTextObj() override;
154 
155  const EditTextObject* GetTextObject() const;
156  const SvxUnoText& GetUnoText();
157 
158  static void FillDummyFieldData( ScHeaderFieldData& rData );
159 
160  // XText
161  virtual void SAL_CALL insertTextContent( const css::uno::Reference< css::text::XTextRange >& xRange,
162  const css::uno::Reference< css::text::XTextContent >& xContent,
163  sal_Bool bAbsorb ) override;
164  virtual void SAL_CALL removeTextContent( const css::uno::Reference< css::text::XTextContent >& xContent ) override;
165 
166  // XSimpleText
167  virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL
168  createTextCursor() override;
169  virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL
170  createTextCursorByRange( const css::uno::Reference< css::text::XTextRange >& aTextPosition ) override;
171  virtual void SAL_CALL insertString( const css::uno::Reference< css::text::XTextRange >& xRange,
172  const OUString& aString, sal_Bool bAbsorb ) override;
173  virtual void SAL_CALL insertControlCharacter( const css::uno::Reference< css::text::XTextRange >& xRange,
174  sal_Int16 nControlCharacter, sal_Bool bAbsorb ) override;
175 
176  // XTextRange
177  virtual css::uno::Reference< css::text::XText > SAL_CALL
178  getText() override;
179  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
180  getStart() override;
181  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
182  getEnd() override;
183  virtual OUString SAL_CALL getString() override;
184  virtual void SAL_CALL setString( const OUString& aString ) override;
185 
186  // XTextRangeMover
187  virtual void SAL_CALL moveTextRange( const css::uno::Reference< css::text::XTextRange >& xRange,
188  sal_Int16 nParagraphs ) override;
189 
190  // XEnumerationAccess
191  virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
192  createEnumeration() override;
193 
194  // XElementAccess
195  virtual css::uno::Type SAL_CALL getElementType() override;
196  virtual sal_Bool SAL_CALL hasElements() override;
197 
198  // XTextFieldsSupplier
199  virtual css::uno::Reference< css::container::XEnumerationAccess > SAL_CALL
200  getTextFields() override;
201  virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL
202  getTextFieldMasters() 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 
211 // derived cursor objects for getImplementation and getText/getStart/getEnd
212 
214 
215 class ScCellTextCursor final : public SvxUnoTextCursor
216 {
218 
219 public:
220  ScCellTextCursor(ScCellObj& rText);
221  virtual ~ScCellTextCursor() throw() override;
222 
223  ScCellTextCursor(ScCellTextCursor const &) = default;
224  ScCellTextCursor(ScCellTextCursor &&) = default;
225  ScCellTextCursor & operator =(ScCellTextCursor const &) = delete; // due to SvxUnoTextCursor
226  ScCellTextCursor & operator =(ScCellTextCursor &&) = delete; // due to SvxUnoTextCursor
227 
228  ScCellObj& GetCellObj() const { return *mxTextObj; }
229 
230  // SvxUnoTextCursor methods reimplemented here:
231  virtual css::uno::Reference< css::text::XText > SAL_CALL
232  getText() override;
233  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
234  getStart() override;
235  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
236  getEnd() override;
237 
238  // XUnoTunnel
240 };
241 
243 {
244 private:
246 
247 public:
249  virtual ~ScHeaderFooterTextCursor() throw() override;
250 
253  ScHeaderFooterTextCursor & operator =(ScHeaderFooterTextCursor const &) = delete; // due to SvxUnoTextCursor
254  ScHeaderFooterTextCursor & operator =(ScHeaderFooterTextCursor &&) = delete; // due to SvxUnoTextCursor
255 
256  // SvxUnoTextCursor methods reimplemented here:
257  virtual css::uno::Reference< css::text::XText > SAL_CALL
258  getText() override;
259  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
260  getStart() override;
261  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
262  getEnd() override;
263 
264  // XUnoTunnel
265  UNO3_GETIMPLEMENTATION_DECL(ScHeaderFooterTextCursor)
266 };
267 
268 class ScDrawTextCursor final : public SvxUnoTextCursor
269 {
270 private:
271  css::uno::Reference< css::text::XText > xParentText;
272 
273 public:
274  ScDrawTextCursor( const css::uno::Reference< css::text::XText >& xParent,
275  const SvxUnoTextBase& rText );
276  virtual ~ScDrawTextCursor() throw() override;
277 
278  ScDrawTextCursor(ScDrawTextCursor const &) = default;
279  ScDrawTextCursor(ScDrawTextCursor &&) = default;
280  ScDrawTextCursor & operator =(ScDrawTextCursor const &) = delete; // due to SvxUnoTextCursor
281  ScDrawTextCursor & operator =(ScDrawTextCursor &&) = delete; // due to SvxUnoTextCursor
282 
283  // SvxUnoTextCursor methods reimplemented here:
284  virtual css::uno::Reference< css::text::XText > SAL_CALL
285  getText() override;
286  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
287  getStart() override;
288  virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
289  getEnd() override;
290 
291  // XUnoTunnel
292  UNO3_GETIMPLEMENTATION_DECL(ScDrawTextCursor)
293 };
294 
295 // ScAnnotationTextCursor isn't needed anymore - SvxUnoTextCursor is used instead
296 
297 // ScEditEngineTextObj for formatted cell content that is not inserted in a cell or header/footer
298 // (used for XML export of change tracking contents)
299 
301 {
302  std::unique_ptr<ScEditEngineDefaulter> pEditEngine;
303  std::unique_ptr<SvxEditEngineForwarder> pForwarder;
304  std::unique_ptr<ScSimpleEditSource> pOriginalSource;
305 
306 public:
307  ScSimpleEditSourceHelper();
308  ~ScSimpleEditSourceHelper();
309 
310  ScSimpleEditSource* GetOriginalSource() const { return pOriginalSource.get(); }
311  ScEditEngineDefaulter* GetEditEngine() const { return pEditEngine.get(); }
312 };
313 
315 {
316 public:
318  virtual ~ScEditEngineTextObj() throw() override;
319 
320  void SetText( const EditTextObject& rTextObject );
321  std::unique_ptr<EditTextObject> CreateTextObject();
322 };
323 
324 // ScCellTextData: shared data between sub objects of a cell text object
325 
327 {
328 protected:
331  std::unique_ptr<ScFieldEditEngine> pEditEngine;
332  std::unique_ptr<SvxEditEngineForwarder> pForwarder;
333  std::unique_ptr<ScCellEditSource> pOriginalSource;
335  bool bInUpdate;
336  bool bDirty;
337  bool bDoUpdate;
338 
339 public:
340  ScCellTextData(ScDocShell* pDocSh, const ScAddress& rP);
341  virtual ~ScCellTextData() override;
342 
343  virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
344 
345  // helper functions for ScSharedCellEditSource:
346  virtual SvxTextForwarder* GetTextForwarder();
347  void UpdateData();
348  ScFieldEditEngine* GetEditEngine() { GetTextForwarder(); return pEditEngine.get(); }
349 
350  ScCellEditSource* GetOriginalSource(); // used as argument for SvxUnoText ctor
351 
352  // used for ScCellEditSource:
353  ScDocShell* GetDocShell() const { return pDocShell; }
354  const ScAddress& GetCellPos() const { return aCellPos; }
355 
356  bool IsDirty() const { return bDirty; }
357  void SetDoUpdate(bool bValue) { bDoUpdate = bValue; }
358 };
359 
360 class ScCellTextObj final : public ScCellTextData, public SvxUnoText
361 {
362 public:
363  ScCellTextObj(ScDocShell* pDocSh, const ScAddress& rP);
364  virtual ~ScCellTextObj() COVERITY_NOEXCEPT_FALSE override;
365 };
366 
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
ScDocShell * pDocShell
Definition: textuno.hxx:329
virtual css::uno::Type SAL_CALL getElementType() override
Definition: textuno.cxx:525
virtual ~ScHeaderFooterTextCursor() override
Definition: textuno.cxx:599
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: textuno.cxx:609
Data (incl.
Definition: editsrc.hxx:73
bool IsDirty() const
Definition: textuno.hxx:356
uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
Definition: textuno.hxx:215
signed char sal_Int8
std::unique_ptr< EditTextObject > mpTextObj
Definition: textuno.hxx:105
void SetDoUpdate(bool bValue)
Definition: textuno.hxx:357
const ScHeaderFooterTextData & operator=(const ScHeaderFooterTextData &)=delete
std::unique_ptr< SvxEditEngineForwarder > pForwarder
Definition: textuno.hxx:332
ScHeaderFooterTextCursor(rtl::Reference< ScHeaderFooterTextObj > const &rText)
Definition: textuno.cxx:594
virtual css::uno::Reference< css::text::XText > SAL_CALL getLeftText() override
Definition: textuno.cxx:112
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: textuno.cxx:558
rtl::Reference< ScHeaderFooterTextObj > rTextObj
Definition: textuno.hxx:245
ScAddress aCellPos
Definition: textuno.hxx:330
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: textuno.cxx:574
ScHeaderFooterPart
Definition: textuno.hxx:50
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: textuno.cxx:603
css::uno::Reference< css::sheet::XHeaderFooterContent > GetContentObj() const
Definition: textuno.hxx:126
#define UNO3_GETIMPLEMENTATION_DECL(classname)
static const css::uno::Sequence< sal_Int8 > & getUnoTunnelId()
Definition: textuno.cxx:145
virtual sal_Bool SAL_CALL hasElements() override
Definition: textuno.cxx:533
virtual ~ScHeaderFooterContentObj() override
Definition: textuno.cxx:93
std::unique_ptr< ScCellEditSource > pOriginalSource
Definition: textuno.hxx:333
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
rtl::Reference< SvxUnoText > mxUnoText
Definition: textuno.hxx:146
const EditTextObject * GetRightEditObject() const
Definition: textuno.cxx:105
ScHeaderFooterTextData(const ScHeaderFooterTextData &)=delete
std::unique_ptr< SvxEditEngineForwarder > pForwarder
Definition: textuno.hxx:303
virtual void SAL_CALL insertControlCharacter(const css::uno::Reference< css::text::XTextRange > &xRange, sal_Int16 nControlCharacter, sal_Bool bAbsorb) override
Definition: textuno.cxx:364
virtual ~ScHeaderFooterTextObj() override
Definition: textuno.cxx:258
const EditTextObject * GetLeftEditObject() const
Definition: textuno.cxx:95
void Init(const EditTextObject *pLeft, const EditTextObject *pCenter, const EditTextObject *pRight)
Definition: textuno.cxx:157
static void FillDummyFieldData(ScHeaderFieldData &rData)
Definition: textuno.cxx:290
virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createEnumeration() override
Definition: textuno.cxx:515
virtual void SAL_CALL removeTextContent(const css::uno::Reference< css::text::XTextContent > &xContent) override
Definition: textuno.cxx:443
virtual css::uno::Reference< css::container::XEnumerationAccess > SAL_CALL getTextFields() override
Definition: textuno.cxx:488
static rtl::Reference< ScHeaderFooterContentObj > getImplementation(const css::uno::Reference< css::sheet::XHeaderFooterContent > &rObj)
Definition: textuno.cxx:151
std::unique_ptr< ScEditEngineDefaulter > pEditEngine
Definition: textuno.hxx:108
ScFieldEditEngine * GetEditEngine()
Definition: textuno.hxx:348
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: textuno.cxx:478
ScCellTextCursor(ScCellObj &rText)
Definition: textuno.cxx:541
void Notify(ScModelObj &rModelObj, const ScRangeList &rChangeRanges, const OUString &rType=OUString("cell-change"), const css::uno::Sequence< css::beans::PropertyValue > &rProperties=css::uno::Sequence< css::beans::PropertyValue >())
Definition: docsh.hxx:478
ScHeaderFooterTextObj(const css::uno::WeakReference< css::sheet::XHeaderFooterContent > &xContent, ScHeaderFooterPart nP, const EditTextObject *pTextObj)
Definition: textuno.cxx:240
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getTextFieldMasters() override
Definition: textuno.cxx:495
rtl::Reference< ScCellObj > mxTextObj
Definition: textuno.hxx:217
ScSimpleEditSource * GetOriginalSource() const
Definition: textuno.hxx:310
unsigned char sal_Bool
virtual OUString SAL_CALL getImplementationName() override
rtl::Reference< ScHeaderFooterTextObj > mxCenterText
Definition: textuno.hxx:62
const EditTextObject * GetTextObject() const
Definition: textuno.hxx:128
Each of these instances represent, the left, center or right part of the header of footer of a page...
Definition: textuno.hxx:137
css::uno::Reference< css::text::XText > xParentText
Definition: textuno.hxx:271
const SvxUnoText & GetUnoText()
Definition: textuno.cxx:265
rtl::Reference< ScHeaderFooterTextObj > mxRightText
Definition: textuno.hxx:63
ScHeaderFooterPart nPart
Definition: textuno.hxx:107
ScEditEngineDefaulter * GetEditEngine() const
Definition: textuno.hxx:311
ScEditEngineDefaulter * GetEditEngine()
Definition: textuno.hxx:123
virtual void SAL_CALL insertTextContent(const css::uno::Reference< css::text::XTextRange > &xRange, const css::uno::Reference< css::text::XTextContent > &xContent, sal_Bool bAbsorb) override
Definition: textuno.cxx:374
ScHeaderFooterTextData aTextData
Definition: textuno.hxx:145
css::uno::WeakReference< css::sheet::XHeaderFooterContent > xContentObj
Definition: textuno.hxx:106
std::unique_ptr< ScFieldEditEngine > pEditEngine
Definition: textuno.hxx:331
virtual ~ScCellTextCursor() override
Definition: textuno.cxx:547
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursorByRange(const css::uno::Reference< css::text::XTextRange > &aTextPosition) override
Definition: textuno.cxx:280
virtual sal_Int64 SAL_CALL getSomething(const css::uno::Sequence< sal_Int8 > &aIdentifier) override
Definition: textuno.cxx:135
const ScAddress & GetCellPos() const
Definition: textuno.hxx:354
const EditTextObject * GetTextObject() const
Definition: textuno.cxx:260
const EditTextObject * GetCenterEditObject() const
Definition: textuno.cxx:100
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: textuno.cxx:553
really derive cell from range?
Definition: cellsuno.hxx:628
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getStart() override
Definition: textuno.cxx:470
SvxTextForwarder * GetTextForwarder()
Definition: textuno.cxx:184
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
std::unique_ptr< ScSimpleEditSource > pOriginalSource
Definition: textuno.hxx:304
virtual css::uno::Reference< css::text::XText > SAL_CALL getRightText() override
Definition: textuno.cxx:126
virtual void SAL_CALL insertString(const css::uno::Reference< css::text::XTextRange > &xRange, const OUString &aString, sal_Bool bAbsorb) override
Definition: textuno.cxx:355
virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL createTextCursor() override
Definition: textuno.cxx:274
ScDocShell * GetDocShell() const
Definition: textuno.hxx:353
virtual void SAL_CALL moveTextRange(const css::uno::Reference< css::text::XTextRange > &xRange, sal_Int16 nParagraphs) override
Definition: textuno.cxx:503
virtual css::uno::Reference< css::text::XText > SAL_CALL getText() override
Definition: textuno.cxx:462
virtual OUString SAL_CALL getString() override
Definition: textuno.cxx:301
virtual css::uno::Reference< css::text::XTextRange > SAL_CALL getEnd() override
Definition: textuno.cxx:625
std::unique_ptr< ScEditEngineDefaulter > pEditEngine
Definition: textuno.hxx:302
virtual css::uno::Reference< css::text::XText > SAL_CALL getCenterText() override
Definition: textuno.cxx:119
rtl::Reference< ScHeaderFooterTextObj > mxLeftText
Definition: textuno.hxx:61
ScHeaderFooterPart GetPart() const
Definition: textuno.hxx:125
std::unique_ptr< SvxEditEngineForwarder > pForwarder
Definition: textuno.hxx:109
ScCellObj & GetCellObj() const
Definition: textuno.hxx:228
virtual void SAL_CALL setString(const OUString &aString) override
Definition: textuno.cxx:345