tdf#48459 sw inline heading: don't apply inside frames or over 120 chars
[LibreOffice.git] / sc / inc / textuno.hxx
blob87faca8649927acbb3298299622b54c6e687e285
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 #pragma once
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 <comphelper/servicehelper.hxx>
29 #include <cppuhelper/implbase.hxx>
30 #include <cppuhelper/weakref.hxx>
31 #include <unotools/weakref.hxx>
33 #include <rtl/ref.hxx>
35 #include <memory>
37 class EditEngine;
38 class EditTextObject;
39 class SvxEditEngineForwarder;
40 class ScDocShell;
41 class ScCellObj;
42 class ScSimpleEditSource;
43 class ScCellEditSource;
44 class ScEditEngineDefaulter;
45 class ScFieldEditEngine;
46 class ScHeaderFooterTextObj;
48 struct ScHeaderFieldData;
50 enum class ScHeaderFooterPart{ LEFT, CENTER, RIGHT };
52 // ScHeaderFooterContentObj is a dumb container which must be re-written into
53 // the page template using setPropertyValue
55 class ScHeaderFooterContentObj final : public cppu::WeakImplHelper<
56 css::sheet::XHeaderFooterContent,
57 css::lang::XServiceInfo >
59 private:
60 rtl::Reference<ScHeaderFooterTextObj> mxLeftText;
61 rtl::Reference<ScHeaderFooterTextObj> mxCenterText;
62 rtl::Reference<ScHeaderFooterTextObj> mxRightText;
64 public:
65 ScHeaderFooterContentObj();
66 virtual ~ScHeaderFooterContentObj() override;
68 // for ScPageHFItem (using getImplementation)
69 const EditTextObject* GetLeftEditObject() const;
70 const EditTextObject* GetCenterEditObject() const;
71 const EditTextObject* GetRightEditObject() const;
73 void Init( const EditTextObject* pLeft,
74 const EditTextObject* pCenter,
75 const EditTextObject* pRight);
77 // XHeaderFooterContent
78 virtual css::uno::Reference< css::text::XText > SAL_CALL
79 getLeftText() override;
80 virtual css::uno::Reference< css::text::XText > SAL_CALL
81 getCenterText() override;
82 virtual css::uno::Reference< css::text::XText > SAL_CALL
83 getRightText() override;
85 static rtl::Reference<ScHeaderFooterContentObj> getImplementation(const css::uno::Reference<css::sheet::XHeaderFooterContent>& rObj);
87 // XServiceInfo
88 virtual OUString SAL_CALL getImplementationName() override;
89 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
90 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
94 // ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
96 class ScHeaderFooterTextData
98 private:
99 std::unique_ptr<EditTextObject> mpTextObj;
100 unotools::WeakReference<ScHeaderFooterContentObj> xContentObj;
101 ScHeaderFooterPart nPart;
102 std::unique_ptr<ScEditEngineDefaulter> pEditEngine;
103 std::unique_ptr<SvxEditEngineForwarder> pForwarder;
104 bool bDataValid;
106 public:
107 ScHeaderFooterTextData(const ScHeaderFooterTextData&) = delete;
108 const ScHeaderFooterTextData& operator=(const ScHeaderFooterTextData&) = delete;
109 ScHeaderFooterTextData(
110 unotools::WeakReference<ScHeaderFooterContentObj> xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj);
111 ~ScHeaderFooterTextData();
113 // helper functions
114 SvxTextForwarder* GetTextForwarder();
115 void UpdateData();
116 void UpdateData(EditEngine& rEditEngine);
117 ScEditEngineDefaulter* GetEditEngine() { GetTextForwarder(); return pEditEngine.get(); }
119 ScHeaderFooterPart GetPart() const { return nPart; }
120 rtl::Reference<ScHeaderFooterContentObj> GetContentObj() const { return xContentObj; }
122 const EditTextObject* GetTextObject() const { return mpTextObj.get(); }
126 * Each of these instances represent, the left, center or right part of the
127 * header of footer of a page.
129 * ScHeaderFooterTextObj changes the text in a ScHeaderFooterContentObj.
131 class ScHeaderFooterTextObj final : public cppu::WeakImplHelper<
132 css::text::XText,
133 css::text::XTextRangeMover,
134 css::container::XEnumerationAccess,
135 css::text::XTextFieldsSupplier,
136 css::lang::XServiceInfo >
138 private:
139 ScHeaderFooterTextData aTextData;
140 rtl::Reference<SvxUnoText> mxUnoText;
142 void CreateUnoText_Impl();
144 public:
145 ScHeaderFooterTextObj(
146 const unotools::WeakReference<ScHeaderFooterContentObj>& xContent, ScHeaderFooterPart nP, const EditTextObject* pTextObj);
147 virtual ~ScHeaderFooterTextObj() override;
149 const EditTextObject* GetTextObject() const;
150 const SvxUnoText& GetUnoText();
152 static void FillDummyFieldData( ScHeaderFieldData& rData );
154 // XText
155 virtual void SAL_CALL insertTextContent( const css::uno::Reference< css::text::XTextRange >& xRange,
156 const css::uno::Reference< css::text::XTextContent >& xContent,
157 sal_Bool bAbsorb ) override;
158 virtual void SAL_CALL removeTextContent( const css::uno::Reference< css::text::XTextContent >& xContent ) override;
160 // XSimpleText
161 virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL
162 createTextCursor() override;
163 virtual css::uno::Reference< css::text::XTextCursor > SAL_CALL
164 createTextCursorByRange( const css::uno::Reference< css::text::XTextRange >& aTextPosition ) override;
165 virtual void SAL_CALL insertString( const css::uno::Reference< css::text::XTextRange >& xRange,
166 const OUString& aString, sal_Bool bAbsorb ) override;
167 virtual void SAL_CALL insertControlCharacter( const css::uno::Reference< css::text::XTextRange >& xRange,
168 sal_Int16 nControlCharacter, sal_Bool bAbsorb ) override;
170 // XTextRange
171 virtual css::uno::Reference< css::text::XText > SAL_CALL
172 getText() override;
173 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
174 getStart() override;
175 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
176 getEnd() override;
177 virtual OUString SAL_CALL getString() override;
178 virtual void SAL_CALL setString( const OUString& aString ) override;
180 // XTextRangeMover
181 virtual void SAL_CALL moveTextRange( const css::uno::Reference< css::text::XTextRange >& xRange,
182 sal_Int16 nParagraphs ) override;
184 // XEnumerationAccess
185 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL
186 createEnumeration() override;
188 // XElementAccess
189 virtual css::uno::Type SAL_CALL getElementType() override;
190 virtual sal_Bool SAL_CALL hasElements() override;
192 // XTextFieldsSupplier
193 virtual css::uno::Reference< css::container::XEnumerationAccess > SAL_CALL
194 getTextFields() override;
195 virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL
196 getTextFieldMasters() override;
198 // XServiceInfo
199 virtual OUString SAL_CALL getImplementationName() override;
200 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
201 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
205 // derived cursor objects for getImplementation and getText/getStart/getEnd
207 //! uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
209 class ScCellTextCursor final : public SvxUnoTextCursor
211 rtl::Reference<ScCellObj> mxTextObj;
213 public:
214 ScCellTextCursor(ScCellObj& rText);
215 virtual ~ScCellTextCursor() noexcept override;
217 ScCellTextCursor(ScCellTextCursor const &) = default;
218 ScCellTextCursor(ScCellTextCursor &&) = default;
219 ScCellTextCursor & operator =(ScCellTextCursor const &) = delete; // due to SvxUnoTextCursor
220 ScCellTextCursor & operator =(ScCellTextCursor &&) = delete; // due to SvxUnoTextCursor
222 ScCellObj& GetCellObj() const { return *mxTextObj; }
224 // SvxUnoTextCursor methods reimplemented here:
225 virtual css::uno::Reference< css::text::XText > SAL_CALL
226 getText() override;
227 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
228 getStart() override;
229 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
230 getEnd() override;
232 // XUnoTunnel
233 UNO3_GETIMPLEMENTATION_DECL(ScCellTextCursor)
236 class ScHeaderFooterTextCursor final : public SvxUnoTextCursor
238 private:
239 rtl::Reference<ScHeaderFooterTextObj> rTextObj;
241 public:
242 ScHeaderFooterTextCursor(rtl::Reference<ScHeaderFooterTextObj> const & rText);
243 virtual ~ScHeaderFooterTextCursor() noexcept override;
245 ScHeaderFooterTextCursor(ScHeaderFooterTextCursor const &) = default;
246 ScHeaderFooterTextCursor(ScHeaderFooterTextCursor &&) = default;
247 ScHeaderFooterTextCursor & operator =(ScHeaderFooterTextCursor const &) = delete; // due to SvxUnoTextCursor
248 ScHeaderFooterTextCursor & operator =(ScHeaderFooterTextCursor &&) = delete; // due to SvxUnoTextCursor
250 // SvxUnoTextCursor methods reimplemented here:
251 virtual css::uno::Reference< css::text::XText > SAL_CALL
252 getText() override;
253 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
254 getStart() override;
255 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
256 getEnd() override;
258 // XUnoTunnel
259 UNO3_GETIMPLEMENTATION_DECL(ScHeaderFooterTextCursor)
262 class ScDrawTextCursor final : public SvxUnoTextCursor
264 private:
265 css::uno::Reference< css::text::XText > xParentText;
267 public:
268 ScDrawTextCursor( css::uno::Reference< css::text::XText > xParent,
269 const SvxUnoTextBase& rText );
270 virtual ~ScDrawTextCursor() noexcept override;
272 ScDrawTextCursor(ScDrawTextCursor const &) = default;
273 ScDrawTextCursor(ScDrawTextCursor &&) = default;
274 ScDrawTextCursor & operator =(ScDrawTextCursor const &) = delete; // due to SvxUnoTextCursor
275 ScDrawTextCursor & operator =(ScDrawTextCursor &&) = delete; // due to SvxUnoTextCursor
277 // SvxUnoTextCursor methods reimplemented here:
278 virtual css::uno::Reference< css::text::XText > SAL_CALL
279 getText() override;
280 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
281 getStart() override;
282 virtual css::uno::Reference< css::text::XTextRange > SAL_CALL
283 getEnd() override;
285 // XUnoTunnel
286 UNO3_GETIMPLEMENTATION_DECL(ScDrawTextCursor)
289 // ScAnnotationTextCursor isn't needed anymore - SvxUnoTextCursor is used instead
291 // ScEditEngineTextObj for formatted cell content that is not inserted in a cell or header/footer
292 // (used for XML export of change tracking contents)
294 class ScSimpleEditSourceHelper
296 std::unique_ptr<ScEditEngineDefaulter> pEditEngine;
297 std::unique_ptr<SvxEditEngineForwarder> pForwarder;
298 std::unique_ptr<ScSimpleEditSource> pOriginalSource;
300 public:
301 ScSimpleEditSourceHelper();
302 ~ScSimpleEditSourceHelper();
304 ScSimpleEditSource* GetOriginalSource() const { return pOriginalSource.get(); }
305 ScEditEngineDefaulter* GetEditEngine() const { return pEditEngine.get(); }
308 class ScEditEngineTextObj final : public ScSimpleEditSourceHelper, public SvxUnoText
310 public:
311 ScEditEngineTextObj();
312 virtual ~ScEditEngineTextObj() noexcept override;
314 void SetText( const EditTextObject& rTextObject );
315 std::unique_ptr<EditTextObject> CreateTextObject();
318 // ScCellTextData: shared data between sub objects of a cell text object
320 class ScCellTextData : public SfxListener
322 protected:
323 ScDocShell* pDocShell;
324 ScAddress aCellPos;
325 std::unique_ptr<ScFieldEditEngine> pEditEngine;
326 std::unique_ptr<SvxEditEngineForwarder> pForwarder;
327 std::unique_ptr<ScCellEditSource> pOriginalSource;
328 bool bDataValid;
329 bool bInUpdate;
330 bool bDirty;
331 bool bDoUpdate;
333 public:
334 ScCellTextData(ScDocShell* pDocSh, const ScAddress& rP);
335 virtual ~ScCellTextData() override;
337 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ) override;
339 // helper functions for ScSharedCellEditSource:
340 virtual SvxTextForwarder* GetTextForwarder();
341 void UpdateData();
342 ScFieldEditEngine* GetEditEngine() { GetTextForwarder(); return pEditEngine.get(); }
344 ScCellEditSource* GetOriginalSource(); // used as argument for SvxUnoText ctor
346 // used for ScCellEditSource:
347 ScDocShell* GetDocShell() const { return pDocShell; }
348 const ScAddress& GetCellPos() const { return aCellPos; }
350 bool IsDirty() const { return bDirty; }
351 void SetDoUpdate(bool bValue) { bDoUpdate = bValue; }
354 class ScCellTextObj final : public ScCellTextData, public SvxUnoText
356 public:
357 ScCellTextObj(ScDocShell* pDocSh, const ScAddress& rP);
358 virtual ~ScCellTextObj() COVERITY_NOEXCEPT_FALSE override;
361 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */