1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
29 #include <comphelper/servicehelper.hxx>
30 #include <cppuhelper/implbase.hxx>
31 #include <cppuhelper/weakref.hxx>
33 #include <rtl/ref.hxx>
39 class SvxEditEngineForwarder
;
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::XUnoTunnel
,
58 css::lang::XServiceInfo
>
61 rtl::Reference
<ScHeaderFooterTextObj
> mxLeftText
;
62 rtl::Reference
<ScHeaderFooterTextObj
> mxCenterText
;
63 rtl::Reference
<ScHeaderFooterTextObj
> mxRightText
;
66 ScHeaderFooterContentObj();
67 virtual ~ScHeaderFooterContentObj() override
;
69 // for ScPageHFItem (using getImplementation)
70 const EditTextObject
* GetLeftEditObject() const;
71 const EditTextObject
* GetCenterEditObject() const;
72 const EditTextObject
* GetRightEditObject() const;
74 void Init( const EditTextObject
* pLeft
,
75 const EditTextObject
* pCenter
,
76 const EditTextObject
* pRight
);
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
;
87 virtual sal_Int64 SAL_CALL
getSomething( const css::uno::Sequence
<
88 sal_Int8
>& aIdentifier
) override
;
90 static const css::uno::Sequence
<sal_Int8
>& getUnoTunnelId();
91 static rtl::Reference
<ScHeaderFooterContentObj
> getImplementation(const css::uno::Reference
<css::sheet::XHeaderFooterContent
>& rObj
);
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
;
100 // ScHeaderFooterTextData: shared data between sub objects of a ScHeaderFooterTextObj
102 class ScHeaderFooterTextData
105 std::unique_ptr
<EditTextObject
> mpTextObj
;
106 css::uno::WeakReference
<css::sheet::XHeaderFooterContent
> xContentObj
;
107 ScHeaderFooterPart nPart
;
108 std::unique_ptr
<ScEditEngineDefaulter
> pEditEngine
;
109 std::unique_ptr
<SvxEditEngineForwarder
> pForwarder
;
113 ScHeaderFooterTextData(const ScHeaderFooterTextData
&) = delete;
114 const ScHeaderFooterTextData
& operator=(const ScHeaderFooterTextData
&) = delete;
115 ScHeaderFooterTextData(
116 css::uno::WeakReference
<css::sheet::XHeaderFooterContent
> const & xContent
, ScHeaderFooterPart nP
, const EditTextObject
* pTextObj
);
117 ~ScHeaderFooterTextData();
120 SvxTextForwarder
* GetTextForwarder();
122 void UpdateData(EditEngine
& rEditEngine
);
123 ScEditEngineDefaulter
* GetEditEngine() { GetTextForwarder(); return pEditEngine
.get(); }
125 ScHeaderFooterPart
GetPart() const { return nPart
; }
126 css::uno::Reference
<css::sheet::XHeaderFooterContent
> GetContentObj() const { return xContentObj
; }
128 const EditTextObject
* GetTextObject() const { return mpTextObj
.get(); }
132 * Each of these instances represent, the left, center or right part of the
133 * header of footer of a page.
135 * ScHeaderFooterTextObj changes the text in a ScHeaderFooterContentObj.
137 class ScHeaderFooterTextObj final
: public cppu::WeakImplHelper
<
139 css::text::XTextRangeMover
,
140 css::container::XEnumerationAccess
,
141 css::text::XTextFieldsSupplier
,
142 css::lang::XServiceInfo
>
145 ScHeaderFooterTextData aTextData
;
146 rtl::Reference
<SvxUnoText
> mxUnoText
;
148 void CreateUnoText_Impl();
151 ScHeaderFooterTextObj(
152 const css::uno::WeakReference
<css::sheet::XHeaderFooterContent
>& xContent
, ScHeaderFooterPart nP
, const EditTextObject
* pTextObj
);
153 virtual ~ScHeaderFooterTextObj() override
;
155 const EditTextObject
* GetTextObject() const;
156 const SvxUnoText
& GetUnoText();
158 static void FillDummyFieldData( ScHeaderFieldData
& rData
);
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
;
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
;
177 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
179 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
181 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
183 virtual OUString SAL_CALL
getString() override
;
184 virtual void SAL_CALL
setString( const OUString
& aString
) override
;
187 virtual void SAL_CALL
moveTextRange( const css::uno::Reference
< css::text::XTextRange
>& xRange
,
188 sal_Int16 nParagraphs
) override
;
190 // XEnumerationAccess
191 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
192 createEnumeration() override
;
195 virtual css::uno::Type SAL_CALL
getElementType() override
;
196 virtual sal_Bool SAL_CALL
hasElements() override
;
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
;
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
;
211 // derived cursor objects for getImplementation and getText/getStart/getEnd
213 //! uno3: SvxUnoTextCursor is not derived from XUnoTunnel, but should be (?)
215 class ScCellTextCursor final
: public SvxUnoTextCursor
217 rtl::Reference
<ScCellObj
> mxTextObj
;
220 ScCellTextCursor(ScCellObj
& rText
);
221 virtual ~ScCellTextCursor() noexcept override
;
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
228 ScCellObj
& GetCellObj() const { return *mxTextObj
; }
230 // SvxUnoTextCursor methods reimplemented here:
231 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
233 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
235 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
239 UNO3_GETIMPLEMENTATION_DECL(ScCellTextCursor
)
242 class ScHeaderFooterTextCursor final
: public SvxUnoTextCursor
245 rtl::Reference
<ScHeaderFooterTextObj
> rTextObj
;
248 ScHeaderFooterTextCursor(rtl::Reference
<ScHeaderFooterTextObj
> const & rText
);
249 virtual ~ScHeaderFooterTextCursor() noexcept override
;
251 ScHeaderFooterTextCursor(ScHeaderFooterTextCursor
const &) = default;
252 ScHeaderFooterTextCursor(ScHeaderFooterTextCursor
&&) = default;
253 ScHeaderFooterTextCursor
& operator =(ScHeaderFooterTextCursor
const &) = delete; // due to SvxUnoTextCursor
254 ScHeaderFooterTextCursor
& operator =(ScHeaderFooterTextCursor
&&) = delete; // due to SvxUnoTextCursor
256 // SvxUnoTextCursor methods reimplemented here:
257 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
259 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
261 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
265 UNO3_GETIMPLEMENTATION_DECL(ScHeaderFooterTextCursor
)
268 class ScDrawTextCursor final
: public SvxUnoTextCursor
271 css::uno::Reference
< css::text::XText
> xParentText
;
274 ScDrawTextCursor( const css::uno::Reference
< css::text::XText
>& xParent
,
275 const SvxUnoTextBase
& rText
);
276 virtual ~ScDrawTextCursor() noexcept override
;
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
283 // SvxUnoTextCursor methods reimplemented here:
284 virtual css::uno::Reference
< css::text::XText
> SAL_CALL
286 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
288 virtual css::uno::Reference
< css::text::XTextRange
> SAL_CALL
292 UNO3_GETIMPLEMENTATION_DECL(ScDrawTextCursor
)
295 // ScAnnotationTextCursor isn't needed anymore - SvxUnoTextCursor is used instead
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)
300 class ScSimpleEditSourceHelper
302 std::unique_ptr
<ScEditEngineDefaulter
> pEditEngine
;
303 std::unique_ptr
<SvxEditEngineForwarder
> pForwarder
;
304 std::unique_ptr
<ScSimpleEditSource
> pOriginalSource
;
307 ScSimpleEditSourceHelper();
308 ~ScSimpleEditSourceHelper();
310 ScSimpleEditSource
* GetOriginalSource() const { return pOriginalSource
.get(); }
311 ScEditEngineDefaulter
* GetEditEngine() const { return pEditEngine
.get(); }
314 class ScEditEngineTextObj final
: public ScSimpleEditSourceHelper
, public SvxUnoText
317 ScEditEngineTextObj();
318 virtual ~ScEditEngineTextObj() noexcept override
;
320 void SetText( const EditTextObject
& rTextObject
);
321 std::unique_ptr
<EditTextObject
> CreateTextObject();
324 // ScCellTextData: shared data between sub objects of a cell text object
326 class ScCellTextData
: public SfxListener
329 ScDocShell
* pDocShell
;
331 std::unique_ptr
<ScFieldEditEngine
> pEditEngine
;
332 std::unique_ptr
<SvxEditEngineForwarder
> pForwarder
;
333 std::unique_ptr
<ScCellEditSource
> pOriginalSource
;
340 ScCellTextData(ScDocShell
* pDocSh
, const ScAddress
& rP
);
341 virtual ~ScCellTextData() override
;
343 virtual void Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
) override
;
345 // helper functions for ScSharedCellEditSource:
346 virtual SvxTextForwarder
* GetTextForwarder();
348 ScFieldEditEngine
* GetEditEngine() { GetTextForwarder(); return pEditEngine
.get(); }
350 ScCellEditSource
* GetOriginalSource(); // used as argument for SvxUnoText ctor
352 // used for ScCellEditSource:
353 ScDocShell
* GetDocShell() const { return pDocShell
; }
354 const ScAddress
& GetCellPos() const { return aCellPos
; }
356 bool IsDirty() const { return bDirty
; }
357 void SetDoUpdate(bool bValue
) { bDoUpdate
= bValue
; }
360 class ScCellTextObj final
: public ScCellTextData
, public SvxUnoText
363 ScCellTextObj(ScDocShell
* pDocSh
, const ScAddress
& rP
);
364 virtual ~ScCellTextObj() COVERITY_NOEXCEPT_FALSE override
;
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */