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 .
20 #ifndef INCLUDED_SC_INC_EDITUTIL_HXX
21 #define INCLUDED_SC_INC_EDITUTIL_HXX
26 #include <editeng/editeng.hxx>
27 #include <svx/pageitem.hxx>
28 #include <tools/datetime.hxx>
29 #include <tools/gen.hxx>
30 #include <tools/fract.hxx>
31 #include <vcl/outdev.hxx>
35 class ScEditEngineDefaulter
;
44 VclPtr
<OutputDevice
> pDev
; // MapMode has to be set
52 static OUString
ModifyDelimiters( const OUString
& rOld
);
54 /// Retrieves string with paragraphs delimited by spaces
55 static OUString
GetSpaceDelimitedString( const EditEngine
& rEngine
);
57 /// Retrieves string with paragraphs delimited by new lines ('\n').
58 static OUString
GetMultilineString( const EditEngine
& rEngine
);
59 static OUString
GetMultilineString( const EditTextObject
& rEdit
);
61 /** Retrieves string with paragraphs delimited by new lines ('\n').
64 If not NULL, use pDoc->GetEditEngine() to retrieve field content.
65 If NULL, a static mutex-guarded ScFieldEditEngine is used that
66 is not capable of resolving document specific fields; avoid.
68 SC_DLLPUBLIC
static OUString
GetString( const EditTextObject
& rEditText
, const ScDocument
* pDoc
);
70 static std::unique_ptr
<EditTextObject
> CreateURLObjectFromURL(
71 ScDocument
& rDoc
, const OUString
& rURL
, const OUString
& rText
);
73 static void RemoveCharAttribs( EditTextObject
& rEditText
, const ScPatternAttr
& rAttr
);
75 static std::unique_ptr
<EditTextObject
> Clone( const EditTextObject
& rSrc
, ScDocument
& rDestDoc
);
77 static OUString
GetCellFieldValue(
78 const SvxFieldData
& rFieldData
, const ScDocument
* pDoc
, std::optional
<Color
>* ppTextColor
);
81 ScEditUtil( ScDocument
* pDocument
, SCCOL nX
, SCROW nY
, SCTAB nZ
,
82 const Point
& rCellPos
,
83 OutputDevice
* pDevice
, double nScaleX
, double nScaleY
,
84 const Fraction
& rX
, const Fraction
& rY
, bool bPrintTwips
= false );
86 tools::Rectangle
GetEditArea( const ScPatternAttr
* pPattern
, bool bForceToTop
);
89 class ScEditAttrTester
91 std::unique_ptr
<SfxItemSet
> pEditAttrs
;
96 ScEditAttrTester( ScEditEngineDefaulter
* pEng
);
99 bool NeedsObject() const { return bNeedsObject
; }
100 bool NeedsCellAttr() const { return bNeedsCellAttr
; }
101 const SfxItemSet
& GetAttribs() const { return *pEditAttrs
; }
104 // construct pool before constructing EditEngine, destroy pool after EditEngine
105 class ScEnginePoolHelper
108 SfxItemPool
* pEnginePool
;
109 SfxItemSet
* pDefaults
;
110 bool bDeleteEnginePool
;
111 bool bDeleteDefaults
;
113 ScEnginePoolHelper( SfxItemPool
* pEnginePool
, bool bDeleteEnginePool
);
114 ScEnginePoolHelper( const ScEnginePoolHelper
& rOrg
);
115 virtual ~ScEnginePoolHelper();
118 class SC_DLLPUBLIC ScEditEngineDefaulter
: public ScEnginePoolHelper
, public EditEngine
121 using EditEngine::SetText
;
122 /// bDeleteEnginePool: Engine becomes the owner of the pool
123 /// and deletes it on destruction
124 ScEditEngineDefaulter( SfxItemPool
* pEnginePool
,
125 bool bDeleteEnginePool
= false );
126 /// If rOrg.bDeleteEnginePool: pool gets cloned and will be
127 /// deleted on destruction. Defaults are not set.
128 ScEditEngineDefaulter( const ScEditEngineDefaulter
& rOrg
);
129 virtual ~ScEditEngineDefaulter() override
;
131 /// Creates a copy of SfxItemSet if bRememberCopy set
132 void SetDefaults( const SfxItemSet
& rDefaults
, bool bRememberCopy
= true );
134 /// Becomes the owner of the SfxItemSet
135 void SetDefaults( std::unique_ptr
<SfxItemSet
> pDefaults
);
137 /// Set the item in the default ItemSet which is created
138 /// if it doesn't exist yet.
139 /// The default ItemSet is then applied to each paragraph.
140 void SetDefaultItem( const SfxPoolItem
& rItem
);
142 /// Returns the stored defaults, used to find non-default character attributes
143 const SfxItemSet
& GetDefaults();
145 /// SetText and apply defaults already set
146 void SetTextCurrentDefaults( const EditTextObject
& rTextObject
);
147 /// Current defaults are not applied, new defaults are applied
148 void SetTextNewDefaults( const EditTextObject
& rTextObject
,
149 const SfxItemSet
& rDefaults
, bool bRememberCopy
= true );
150 /// Current defaults are not applied, new defaults are applied
151 void SetTextNewDefaults( const EditTextObject
& rTextObject
,
152 std::unique_ptr
<SfxItemSet
> pDefaults
);
154 /// SetText and apply defaults already set
155 void SetTextCurrentDefaults( const OUString
& rText
);
156 /// Current defaults are not applied, new defaults are applied
157 void SetTextNewDefaults( const OUString
& rText
,
158 const SfxItemSet
& rDefaults
);
159 /// Current defaults are not applied, new defaults are applied
160 void SetTextNewDefaults( const OUString
& rText
,
161 std::unique_ptr
<SfxItemSet
> pDefaults
);
163 /// Paragraph attributes that are not defaults are copied to
164 /// character attributes and all paragraph attributes reset
165 void RemoveParaAttribs();
167 /// Re-apply existing defaults if set, same as in SetText,
168 /// but without EnableUndo/SetUpdateMode.
169 void RepeatDefaults();
172 // for field commands (or just fields?) in a table
173 class SC_DLLPUBLIC ScFieldEditEngine
: public ScEditEngineDefaulter
181 ScDocument
* pDoc
, SfxItemPool
* pEnginePool
, SfxItemPool
* pTextObjectPool
= nullptr,
182 bool bDeleteEnginePool
= false);
184 void SetExecuteURL(bool bSet
) { bExecuteURL
= bSet
; }
186 virtual void FieldClicked( const SvxFieldItem
& rField
) override
;
187 virtual OUString
CalcFieldValue( const SvxFieldItem
& rField
, sal_Int32 nPara
, sal_Int32 nPos
, std::optional
<Color
>& rTxtColor
, std::optional
<Color
>& rFldColor
) override
;
191 class SC_DLLPUBLIC ScTabEditEngine final
: public ScFieldEditEngine
194 void Init(const ScPatternAttr
& rPattern
);
196 ScTabEditEngine( ScDocument
* pDoc
); // Default
197 ScTabEditEngine(const ScPatternAttr
& rPattern
,
198 SfxItemPool
*pEngineItemPool
, ScDocument
*pDoc
,
199 SfxItemPool
* pTextObjectPool
= nullptr );
202 struct ScHeaderFieldData
204 OUString aTitle
; // title or file name (if no title)
205 OUString aLongDocName
; // path and file name
206 OUString aShortDocName
; // pure file name
210 tools::Long nTotalPages
;
216 // for headers/footers with fields
217 class SC_DLLPUBLIC ScHeaderEditEngine final
: public ScEditEngineDefaulter
220 ScHeaderFieldData aData
;
223 ScHeaderEditEngine( SfxItemPool
* pEnginePool
);
224 virtual OUString
CalcFieldValue( const SvxFieldItem
& rField
, sal_Int32 nPara
, sal_Int32 nPos
, std::optional
<Color
>& rTxtColor
, std::optional
<Color
>& rFldColor
) override
;
226 void SetNumType(SvxNumType eNew
) { aData
.eNumType
= eNew
; }
227 void SetData(const ScHeaderFieldData
& rNew
) { aData
= rNew
; }
230 // for Note text objects.
231 class ScNoteEditEngine final
: public ScEditEngineDefaulter
235 ScNoteEditEngine( SfxItemPool
* pEnginePool
, SfxItemPool
* pTextObjectPool
);
239 // SvxFieldData derivations were moved to Svx (comment can be deleted?)
243 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */