nss: upgrade to release 3.73
[LibreOffice.git] / sc / inc / textuno.hxx
blob401387b8dcca70c8dc5c386248468000d120281a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #ifndef INCLUDED_SC_INC_TEXTUNO_HXX
21 #define INCLUDED_SC_INC_TEXTUNO_HXX
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>
30 #include <comphelper/servicehelper.hxx>
31 #include <cppuhelper/implbase.hxx>
32 #include <cppuhelper/weakref.hxx>
34 #include <rtl/ref.hxx>
36 #include <memory>
38 class EditEngine;
39 class EditTextObject;
40 class SvxEditEngineForwarder;
41 class ScDocShell;
42 class ScCellObj;
43 class ScSimpleEditSource;
44 class ScCellEditSource;
45 class ScEditEngineDefaulter;
46 class ScFieldEditEngine;
47 class ScHeaderFooterTextObj;
49 struct ScHeaderFieldData;
51 enum class ScHeaderFooterPart{ LEFT, CENTER, RIGHT };
53 // ScHeaderFooterContentObj is a dumb container which must be re-written into
54 // the page template using setPropertyValue
56 class ScHeaderFooterContentObj final : public cppu::WeakImplHelper<
57 css::sheet::XHeaderFooterContent,
58 css::lang::XUnoTunnel,
59 css::lang::XServiceInfo >
61 private:
62 rtl::Reference<ScHeaderFooterTextObj> mxLeftText;
63 rtl::Reference<ScHeaderFooterTextObj> mxCenterText;
64 rtl::Reference<ScHeaderFooterTextObj> mxRightText;
66 public:
67 ScHeaderFooterContentObj();
68 virtual ~ScHeaderFooterContentObj() override;
70 // for ScPageHFItem (using getImplementation)
71 const EditTextObject* GetLeftEditObject() const;
72 const EditTextObject* GetCenterEditObject() const;
73 const EditTextObject* GetRightEditObject() const;
75 void Init( const EditTextObject* pLeft,
76 const EditTextObject* pCenter,
77 const EditTextObject* pRight);
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;
87 // XUnoTunnel
88 virtual sal_Int64 SAL_CALL getSomething( const css::uno::Sequence<
89 sal_Int8 >& aIdentifier ) override;
91 static const css::uno::Sequence<sal_Int8>& getUnoTunnelId();
92 static rtl::Reference<ScHeaderFooterContentObj> getImplementation(const css::uno::Reference<css::sheet::XHeaderFooterContent>& rObj);
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;
101 // ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
103 class ScHeaderFooterTextData
105 private:
106 std::unique_ptr<EditTextObject> mpTextObj;
107 css::uno::WeakReference<css::sheet::XHeaderFooterContent> xContentObj;
108 ScHeaderFooterPart nPart;
109 std::unique_ptr<ScEditEngineDefaulter> pEditEngine;
110 std::unique_ptr<SvxEditEngineForwarder> pForwarder;
111 bool bDataValid;
113 public:
114 ScHeaderFooterTextData(const ScHeaderFooterTextData&) = delete;
115 const ScHeaderFooterTextData& operator=(const ScHeaderFooterTextData&) = delete;
116 ScHeaderFooterTextData(
117 css::uno::WeakReference<css::sheet::XHeaderFooterContent> const & xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj);
118 ~ScHeaderFooterTextData();
120 // helper functions
121 SvxTextForwarder* GetTextForwarder();
122 void UpdateData();
123 void UpdateData(EditEngine& rEditEngine);
124 ScEditEngineDefaulter* GetEditEngine() { GetTextForwarder(); return pEditEngine.get(); }
126 ScHeaderFooterPart GetPart() const { return nPart; }
127 css::uno::Reference<css::sheet::XHeaderFooterContent> GetContentObj() const { return xContentObj; }
129 const EditTextObject* GetTextObject() const { return mpTextObj.get(); }
133 * Each of these instances represent, the left, center or right part of the
134 * header of footer of a page.
136 * ScHeaderFooterTextObj changes the text in a ScHeaderFooterContentObj.
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 >
145 private:
146 ScHeaderFooterTextData aTextData;
147 rtl::Reference<SvxUnoText> mxUnoText;
149 void CreateUnoText_Impl();
151 public:
152 ScHeaderFooterTextObj(
153 const css::uno::WeakReference<css::sheet::XHeaderFooterContent>& xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj);
154 virtual ~ScHeaderFooterTextObj() override;
156 const EditTextObject* GetTextObject() const;
157 const SvxUnoText& GetUnoText();
159 static void FillDummyFieldData( ScHeaderFieldData& rData );
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;
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;
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;
187 // XTextRangeMover
188 virtual void SAL_CALL moveTextRange( const css::uno::Reference< css::text::XTextRange >& xRange,
189 sal_Int16 nParagraphs ) override;
191 // XEnumerationAccess
192 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
193 createEnumeration() override;
195 // XElementAccess
196 virtual css::uno::Type SAL_CALL getElementType() override;
197 virtual sal_Bool SAL_CALL hasElements() override;
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;
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;
212 // derived cursor objects for getImplementation and getText/getStart/getEnd
214 //! uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
216 class ScCellTextCursor final : public SvxUnoTextCursor
218 rtl::Reference<ScCellObj> mxTextObj;
220 public:
221 ScCellTextCursor(ScCellObj& rText);
222 virtual ~ScCellTextCursor() throw() override;
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
229 ScCellObj& GetCellObj() const { return *mxTextObj; }
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;
239 // XUnoTunnel
240 UNO3_GETIMPLEMENTATION_DECL(ScCellTextCursor)
243 class ScHeaderFooterTextCursor final : public SvxUnoTextCursor
245 private:
246 rtl::Reference<ScHeaderFooterTextObj> rTextObj;
248 public:
249 ScHeaderFooterTextCursor(rtl::Reference<ScHeaderFooterTextObj> const & rText);
250 virtual ~ScHeaderFooterTextCursor() throw() override;
252 ScHeaderFooterTextCursor(ScHeaderFooterTextCursor const &) = default;
253 ScHeaderFooterTextCursor(ScHeaderFooterTextCursor &&) = default;
254 ScHeaderFooterTextCursor & operator =(ScHeaderFooterTextCursor const &) = delete; // due to SvxUnoTextCursor
255 ScHeaderFooterTextCursor & operator =(ScHeaderFooterTextCursor &&) = delete; // due to SvxUnoTextCursor
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;
265 // XUnoTunnel
266 UNO3_GETIMPLEMENTATION_DECL(ScHeaderFooterTextCursor)
269 class ScDrawTextCursor final : public SvxUnoTextCursor
271 private:
272 css::uno::Reference< css::text::XText > xParentText;
274 public:
275 ScDrawTextCursor( const css::uno::Reference< css::text::XText >& xParent,
276 const SvxUnoTextBase& rText );
277 virtual ~ScDrawTextCursor() throw() override;
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
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;
292 // XUnoTunnel
293 UNO3_GETIMPLEMENTATION_DECL(ScDrawTextCursor)
296 // ScAnnotationTextCursor isn't needed anymore - SvxUnoTextCursor is used instead
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)
301 class ScSimpleEditSourceHelper
303 std::unique_ptr<ScEditEngineDefaulter> pEditEngine;
304 std::unique_ptr<SvxEditEngineForwarder> pForwarder;
305 std::unique_ptr<ScSimpleEditSource> pOriginalSource;
307 public:
308 ScSimpleEditSourceHelper();
309 ~ScSimpleEditSourceHelper();
311 ScSimpleEditSource* GetOriginalSource() const { return pOriginalSource.get(); }
312 ScEditEngineDefaulter* GetEditEngine() const { return pEditEngine.get(); }
315 class ScEditEngineTextObj final : public ScSimpleEditSourceHelper, public SvxUnoText
317 public:
318 ScEditEngineTextObj();
319 virtual ~ScEditEngineTextObj() throw() override;
321 void SetText( const EditTextObject& rTextObject );
322 std::unique_ptr<EditTextObject> CreateTextObject();
325 // ScCellTextData: shared data between sub objects of a cell text object
327 class ScCellTextData : public SfxListener
329 protected:
330 ScDocShell* pDocShell;
331 ScAddress aCellPos;
332 std::unique_ptr<ScFieldEditEngine> pEditEngine;
333 std::unique_ptr<SvxEditEngineForwarder> pForwarder;
334 std::unique_ptr<ScCellEditSource> pOriginalSource;
335 bool bDataValid;
336 bool bInUpdate;
337 bool bDirty;
338 bool bDoUpdate;
340 public:
341 ScCellTextData(ScDocShell* pDocSh, const ScAddress& rP);
342 virtual ~ScCellTextData() override;
344 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
346 // helper functions for ScSharedCellEditSource:
347 virtual SvxTextForwarder* GetTextForwarder();
348 void UpdateData();
349 ScFieldEditEngine* GetEditEngine() { GetTextForwarder(); return pEditEngine.get(); }
351 ScCellEditSource* GetOriginalSource(); // used as argument for SvxUnoText ctor
353 // used for ScCellEditSource:
354 ScDocShell* GetDocShell() const { return pDocShell; }
355 const ScAddress& GetCellPos() const { return aCellPos; }
357 bool IsDirty() const { return bDirty; }
358 void SetDoUpdate(bool bValue) { bDoUpdate = bValue; }
361 class ScCellTextObj final : public ScCellTextData, public SvxUnoText
363 public:
364 ScCellTextObj(ScDocShell* pDocSh, const ScAddress& rP);
365 virtual ~ScCellTextObj() COVERITY_NOEXCEPT_FALSE override;
368 #endif
370 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */