build fix
[LibreOffice.git] / sc / inc / editutil.hxx
blob00f0029d3ebaf1a5615c6c782e76583f5626afb7
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 "scdllapi.h"
24 #include "address.hxx"
25 #include <editeng/editeng.hxx>
26 #include <svx/pageitem.hxx>
27 #include <tools/date.hxx>
28 #include <tools/time.hxx>
29 #include <tools/gen.hxx>
30 #include <tools/fract.hxx>
31 #include <vcl/outdev.hxx>
33 class ScDocument;
34 class ScPatternAttr;
35 class ScEditEngineDefaulter;
37 class ScEditUtil
39 ScDocument* pDoc;
40 SCCOL nCol;
41 SCROW nRow;
42 SCTAB nTab;
43 Point aScrPos;
44 VclPtr<OutputDevice> pDev; // MapMode has to be set
45 double nPPTX;
46 double nPPTY;
47 Fraction aZoomX;
48 Fraction aZoomY;
50 public:
51 static OUString ModifyDelimiters( const OUString& rOld );
53 /// Retrieves string with paragraphs delimited by spaces
54 static OUString GetSpaceDelimitedString( const EditEngine& rEngine );
56 /// Retrieves string with paragraphs delimited by new lines ('\n').
57 static OUString GetMultilineString( const EditEngine& rEngine );
58 static OUString GetMultilineString( const EditTextObject& rEdit );
60 /** Retrieves string with paragraphs delimited by new lines ('\n').
62 @param pDoc
63 If not NULL, use pDoc->GetEditEngine() to retrieve field content.
64 If NULL, a static mutex-guarded ScFieldEditEngine is used that
65 is not capable of resolving document specific fields; avoid.
67 SC_DLLPUBLIC static OUString GetString( const EditTextObject& rEditText, const ScDocument* pDoc );
69 static EditTextObject* CreateURLObjectFromURL(
70 ScDocument& rDoc, const OUString& rURL, const OUString& rText );
72 static void RemoveCharAttribs( EditTextObject& rEditText, const ScPatternAttr& rAttr );
74 static EditTextObject* Clone( const EditTextObject& rSrc, ScDocument& rDestDoc );
76 static OUString GetCellFieldValue(
77 const SvxFieldData& rFieldData, const ScDocument* pDoc, Color** ppTextColor );
79 public:
80 ScEditUtil( ScDocument* pDocument, SCCOL nX, SCROW nY, SCTAB nZ,
81 const Point& rScrPosPixel,
82 OutputDevice* pDevice, double nScaleX, double nScaleY,
83 const Fraction& rX, const Fraction& rY );
85 Rectangle GetEditArea( const ScPatternAttr* pPattern, bool bForceToTop );
88 class ScEditAttrTester
90 ScEditEngineDefaulter* pEngine;
91 std::unique_ptr<SfxItemSet> pEditAttrs;
92 bool bNeedsObject;
93 bool bNeedsCellAttr;
95 public:
96 ScEditAttrTester( ScEditEngineDefaulter* pEng );
97 ~ScEditAttrTester();
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
107 protected:
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
120 private:
121 using EditEngine::SetText;
123 public:
124 /// bDeleteEnginePool: Engine becomes the owner of the pool
125 /// and deletes it on destruction
126 ScEditEngineDefaulter( SfxItemPool* pEnginePool,
127 bool bDeleteEnginePool = false );
128 /// If rOrg.bDeleteEnginePool: pool gets cloned and will be
129 /// deleted on destruction. Defaults are not set.
130 ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg );
131 virtual ~ScEditEngineDefaulter() override;
133 /// Creates a copy of SfxItemSet if bRememberCopy set
134 void SetDefaults( const SfxItemSet& rDefaults, bool bRememberCopy = true );
136 /// Becomes the owner of the SfxItemSet
137 void SetDefaults( SfxItemSet* pDefaults );
139 /// Set the item in the default ItemSet which is created
140 /// if it doesn't exist yet.
141 /// The default ItemSet is then applied to each paragraph.
142 void SetDefaultItem( const SfxPoolItem& rItem );
144 /// Returns the stored defaults, used to find non-default character attributes
145 const SfxItemSet& GetDefaults();
147 /// Overwritten method to be able to apply defaults already set
148 void SetText( const EditTextObject& rTextObject );
149 /// Current defaults are not applied, new defaults are applied
150 void SetTextNewDefaults( const EditTextObject& rTextObject,
151 const SfxItemSet& rDefaults, bool bRememberCopy = true );
152 /// Current defaults are not applied, new defaults are applied
153 void SetTextNewDefaults( const EditTextObject& rTextObject,
154 SfxItemSet* pDefaults );
156 /// Overwritten method to be able to apply defaults already set
157 void SetText( const OUString& rText );
158 /// Current defaults are not applied, new defaults are applied
159 void SetTextNewDefaults( const OUString& rText,
160 const SfxItemSet& rDefaults );
161 /// Current defaults are not applied, new defaults are applied
162 void SetTextNewDefaults( const OUString& rText,
163 SfxItemSet* pDefaults );
165 /// Paragraph attributes that are not defaults are copied to
166 /// character attributes and all paragraph attributes reset
167 void RemoveParaAttribs();
169 /// Re-apply existing defaults if set, same as in SetText,
170 /// but without EnableUndo/SetUpdateMode.
171 void RepeatDefaults();
174 // 1/100 mm
175 class SC_DLLPUBLIC ScTabEditEngine : public ScEditEngineDefaulter
177 private:
178 void Init(const ScPatternAttr& rPattern);
179 public:
180 ScTabEditEngine( ScDocument* pDoc ); // Default
181 ScTabEditEngine( const ScPatternAttr& rPattern,
182 SfxItemPool* pEnginePool,
183 SfxItemPool* pTextObjectPool = nullptr );
186 struct ScHeaderFieldData
188 OUString aTitle; // title or file name (if no title)
189 OUString aLongDocName; // path and file name
190 OUString aShortDocName; // pure file name
191 OUString aTabName;
192 Date aDate;
193 tools::Time aTime;
194 long nPageNo;
195 long nTotalPages;
196 SvxNumType eNumType;
198 ScHeaderFieldData();
201 // for field commands (or just fields?) in a table
202 class SC_DLLPUBLIC ScFieldEditEngine : public ScEditEngineDefaulter
204 private:
205 ScDocument* mpDoc;
206 bool bExecuteURL;
208 public:
209 ScFieldEditEngine(
210 ScDocument* pDoc, SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool = nullptr,
211 bool bDeleteEnginePool = false);
213 void SetExecuteURL(bool bSet) { bExecuteURL = bSet; }
215 virtual void FieldClicked( const SvxFieldItem& rField, sal_Int32, sal_Int32 ) override;
216 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor ) override;
219 // for headers/footers with fields
220 class SC_DLLPUBLIC ScHeaderEditEngine : public ScEditEngineDefaulter
222 private:
223 ScHeaderFieldData aData;
225 public:
226 ScHeaderEditEngine( SfxItemPool* pEnginePool );
227 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor ) override;
229 void SetNumType(SvxNumType eNew) { aData.eNumType = eNew; }
230 void SetData(const ScHeaderFieldData& rNew) { aData = rNew; }
233 // for Note text objects.
234 class ScNoteEditEngine : public ScEditEngineDefaulter
237 public:
238 ScNoteEditEngine( SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool );
242 // SvxFieldData derivations were moved to Svx (comment can be deleted?)
244 #endif
246 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */