Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sc / inc / editutil.hxx
blob6aac49e77f512e3335e90c9a2741f036fbc1bfd6
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_EDITUTIL_HXX
21 #define INCLUDED_SC_INC_EDITUTIL_HXX
23 #include <memory>
24 #include "scdllapi.h"
25 #include "types.hxx"
26 #include <editeng/editeng.hxx>
27 #include <svx/pageitem.hxx>
28 #include <tools/date.hxx>
29 #include <tools/time.hxx>
30 #include <tools/gen.hxx>
31 #include <tools/fract.hxx>
32 #include <vcl/outdev.hxx>
34 class ScDocument;
35 class ScPatternAttr;
36 class ScEditEngineDefaulter;
38 class ScEditUtil
40 ScDocument* pDoc;
41 SCCOL nCol;
42 SCROW nRow;
43 SCTAB nTab;
44 Point aScrPos;
45 VclPtr<OutputDevice> pDev; // MapMode has to be set
46 double nPPTX;
47 double nPPTY;
48 Fraction aZoomX;
49 Fraction aZoomY;
51 public:
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').
63 @param pDoc
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, boost::optional<Color>* ppTextColor );
80 public:
81 ScEditUtil( ScDocument* pDocument, SCCOL nX, SCROW nY, SCTAB nZ,
82 const Point& rScrPosPixel,
83 OutputDevice* pDevice, double nScaleX, double nScaleY,
84 const Fraction& rX, const Fraction& rY );
86 tools::Rectangle GetEditArea( const ScPatternAttr* pPattern, bool bForceToTop );
89 class ScEditAttrTester
91 ScEditEngineDefaulter* pEngine;
92 std::unique_ptr<SfxItemSet> pEditAttrs;
93 bool bNeedsObject;
94 bool bNeedsCellAttr;
96 public:
97 ScEditAttrTester( ScEditEngineDefaulter* pEng );
98 ~ScEditAttrTester();
100 bool NeedsObject() const { return bNeedsObject; }
101 bool NeedsCellAttr() const { return bNeedsCellAttr; }
102 const SfxItemSet& GetAttribs() const { return *pEditAttrs; }
105 // construct pool before constructing EditEngine, destroy pool after EditEngine
106 class ScEnginePoolHelper
108 protected:
109 SfxItemPool* pEnginePool;
110 SfxItemSet* pDefaults;
111 bool bDeleteEnginePool;
112 bool bDeleteDefaults;
114 ScEnginePoolHelper( SfxItemPool* pEnginePool, bool bDeleteEnginePool );
115 ScEnginePoolHelper( const ScEnginePoolHelper& rOrg );
116 virtual ~ScEnginePoolHelper();
119 class SC_DLLPUBLIC ScEditEngineDefaulter : public ScEnginePoolHelper, public EditEngine
121 private:
122 using EditEngine::SetText;
124 public:
125 /// bDeleteEnginePool: Engine becomes the owner of the pool
126 /// and deletes it on destruction
127 ScEditEngineDefaulter( SfxItemPool* pEnginePool,
128 bool bDeleteEnginePool = false );
129 /// If rOrg.bDeleteEnginePool: pool gets cloned and will be
130 /// deleted on destruction. Defaults are not set.
131 ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg );
132 virtual ~ScEditEngineDefaulter() override;
134 /// Creates a copy of SfxItemSet if bRememberCopy set
135 void SetDefaults( const SfxItemSet& rDefaults, bool bRememberCopy = true );
137 /// Becomes the owner of the SfxItemSet
138 void SetDefaults( SfxItemSet* pDefaults );
140 /// Set the item in the default ItemSet which is created
141 /// if it doesn't exist yet.
142 /// The default ItemSet is then applied to each paragraph.
143 void SetDefaultItem( const SfxPoolItem& rItem );
145 /// Returns the stored defaults, used to find non-default character attributes
146 const SfxItemSet& GetDefaults();
148 /// Overwritten method to be able to apply defaults already set
149 void SetText( const EditTextObject& rTextObject );
150 /// Current defaults are not applied, new defaults are applied
151 void SetTextNewDefaults( const EditTextObject& rTextObject,
152 const SfxItemSet& rDefaults, bool bRememberCopy = true );
153 /// Current defaults are not applied, new defaults are applied
154 void SetTextNewDefaults( const EditTextObject& rTextObject,
155 SfxItemSet* pDefaults );
157 /// Overwritten method to be able to apply defaults already set
158 void SetText( const OUString& rText );
159 /// Current defaults are not applied, new defaults are applied
160 void SetTextNewDefaults( const OUString& rText,
161 const SfxItemSet& rDefaults );
162 /// Current defaults are not applied, new defaults are applied
163 void SetTextNewDefaults( const OUString& rText,
164 SfxItemSet* pDefaults );
166 /// Paragraph attributes that are not defaults are copied to
167 /// character attributes and all paragraph attributes reset
168 void RemoveParaAttribs();
170 /// Re-apply existing defaults if set, same as in SetText,
171 /// but without EnableUndo/SetUpdateMode.
172 void RepeatDefaults();
175 // 1/100 mm
176 class SC_DLLPUBLIC ScTabEditEngine : public ScEditEngineDefaulter
178 private:
179 void Init(const ScPatternAttr& rPattern);
180 public:
181 ScTabEditEngine( ScDocument* pDoc ); // Default
182 ScTabEditEngine( const ScPatternAttr& rPattern,
183 SfxItemPool* pEnginePool,
184 SfxItemPool* pTextObjectPool = nullptr );
187 struct ScHeaderFieldData
189 OUString aTitle; // title or file name (if no title)
190 OUString aLongDocName; // path and file name
191 OUString aShortDocName; // pure file name
192 OUString aTabName;
193 Date aDate;
194 tools::Time aTime;
195 long nPageNo;
196 long nTotalPages;
197 SvxNumType eNumType;
199 ScHeaderFieldData();
202 // for field commands (or just fields?) in a table
203 class SC_DLLPUBLIC ScFieldEditEngine : public ScEditEngineDefaulter
205 private:
206 ScDocument* mpDoc;
207 bool bExecuteURL;
209 public:
210 ScFieldEditEngine(
211 ScDocument* pDoc, SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool = nullptr,
212 bool bDeleteEnginePool = false);
214 void SetExecuteURL(bool bSet) { bExecuteURL = bSet; }
216 virtual void FieldClicked( const SvxFieldItem& rField, sal_Int32, sal_Int32 ) override;
217 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rTxtColor, boost::optional<Color>& rFldColor ) override;
220 // for headers/footers with fields
221 class SC_DLLPUBLIC ScHeaderEditEngine : public ScEditEngineDefaulter
223 private:
224 ScHeaderFieldData aData;
226 public:
227 ScHeaderEditEngine( SfxItemPool* pEnginePool );
228 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rTxtColor, boost::optional<Color>& rFldColor ) override;
230 void SetNumType(SvxNumType eNew) { aData.eNumType = eNew; }
231 void SetData(const ScHeaderFieldData& rNew) { aData = rNew; }
234 // for Note text objects.
235 class ScNoteEditEngine : public ScEditEngineDefaulter
238 public:
239 ScNoteEditEngine( SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool );
243 // SvxFieldData derivations were moved to Svx (comment can be deleted?)
245 #endif
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */