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