Bump version to 4.3-4
[LibreOffice.git] / sc / inc / editutil.hxx
blob1dee434c12ffc1dfff4f3b7bdaaa01d1efb546d5
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>
33 class OutputDevice;
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 OutputDevice* pDev; // MapMode has to be set
46 double nPPTX;
47 double nPPTY;
48 Fraction aZoomX;
49 Fraction aZoomY;
51 static const char pCalcDelimiters[];
53 public:
54 static OUString ModifyDelimiters( const OUString& rOld );
56 /// Retrieves string with paragraphs delimited by spaces
57 static OUString GetSpaceDelimitedString( const EditEngine& rEngine );
59 /// Retrieves string with paragraphs delimited by new lines ('\n').
60 static OUString GetMultilineString( const EditEngine& rEngine );
61 static OUString GetMultilineString( const EditTextObject& rEdit );
63 /** Retrieves string with paragraphs delimited by new lines ('\n').
65 @param pDoc
66 If not NULL, use pDoc->GetEditEngine() to retrieve field content.
67 If NULL, a static mutex-guarded ScFieldEditEngine is used that
68 is not capable of resolving document specific fields; avoid.
70 SC_DLLPUBLIC static OUString GetString( const EditTextObject& rEditText, const ScDocument* pDoc );
72 static EditTextObject* CreateURLObjectFromURL(
73 ScDocument& rDoc, const OUString& rURL, const OUString& rText );
75 static void RemoveCharAttribs( EditTextObject& rEditText, const ScPatternAttr& rAttr );
77 static EditTextObject* Clone( const EditTextObject& rSrc, ScDocument& rDestDoc );
79 static OUString GetCellFieldValue(
80 const SvxFieldData& rFieldData, const ScDocument* pDoc, Color** ppTextColor );
82 public:
83 ScEditUtil( ScDocument* pDocument, SCCOL nX, SCROW nY, SCTAB nZ,
84 const Point& rScrPosPixel,
85 OutputDevice* pDevice, double nScaleX, double nScaleY,
86 const Fraction& rX, const Fraction& rY ) :
87 pDoc(pDocument),nCol(nX),nRow(nY),nTab(nZ),
88 aScrPos(rScrPosPixel),pDev(pDevice),
89 nPPTX(nScaleX),nPPTY(nScaleY),aZoomX(rX),aZoomY(rY) {}
91 Rectangle GetEditArea( const ScPatternAttr* pPattern, bool bForceToTop );
95 class ScEditAttrTester
97 ScEditEngineDefaulter* pEngine;
98 SfxItemSet* pEditAttrs;
99 bool bNeedsObject;
100 bool bNeedsCellAttr;
102 public:
103 ScEditAttrTester( ScEditEngineDefaulter* pEng );
104 ~ScEditAttrTester();
106 bool NeedsObject() const { return bNeedsObject; }
107 bool NeedsCellAttr() const { return bNeedsCellAttr; }
108 const SfxItemSet& GetAttribs() const { return *pEditAttrs; }
112 // construct pool before constructing EditEngine, destroy pool after EditEngine
113 class ScEnginePoolHelper
115 protected:
116 SfxItemPool* pEnginePool;
117 SfxItemSet* pDefaults;
118 bool bDeleteEnginePool;
119 bool bDeleteDefaults;
121 ScEnginePoolHelper( SfxItemPool* pEnginePool,
122 bool bDeleteEnginePool = false );
123 ScEnginePoolHelper( const ScEnginePoolHelper& rOrg );
124 virtual ~ScEnginePoolHelper();
128 class SC_DLLPUBLIC ScEditEngineDefaulter : public ScEnginePoolHelper, public EditEngine
130 private:
131 using EditEngine::SetText;
133 public:
134 /// bDeleteEnginePool: Engine becomes the owner of the pool
135 /// and deletes it on destruction
136 ScEditEngineDefaulter( SfxItemPool* pEnginePool,
137 bool bDeleteEnginePool = false );
138 /// If rOrg.bDeleteEnginePool: pool gets cloned and will be
139 /// deleted on destruction. Defaults are not set.
140 ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg );
141 virtual ~ScEditEngineDefaulter();
143 /// Creates a copy of SfxItemSet if bRememberCopy set
144 void SetDefaults( const SfxItemSet& rDefaults, bool bRememberCopy = true );
146 /// Becomes the owner of the SfxItemSet if bTakeOwnership set
147 void SetDefaults( SfxItemSet* pDefaults, bool bTakeOwnership = true );
149 /// Set the item in the default ItemSet which is created
150 /// if it doesn't exist yet.
151 /// The default ItemSet is then applied to each paragraph.
152 void SetDefaultItem( const SfxPoolItem& rItem );
154 /// Returns the stored defaults, used to find non-default character attributes
155 const SfxItemSet& GetDefaults();
157 /// Overwritten method to be able to apply defaults already set
158 void SetText( const EditTextObject& rTextObject );
159 /// Current defaults are not applied, new defaults are applied
160 void SetTextNewDefaults( const EditTextObject& rTextObject,
161 const SfxItemSet& rDefaults, bool bRememberCopy = true );
162 /// Current defaults are not applied, new defaults are applied
163 void SetTextNewDefaults( const EditTextObject& rTextObject,
164 SfxItemSet* pDefaults, bool bTakeOwnership = true );
166 /// Overwritten method to be able to apply defaults already set
167 void SetText( const OUString& rText );
168 /// Current defaults are not applied, new defaults are applied
169 void SetTextNewDefaults( const OUString& rText,
170 const SfxItemSet& rDefaults, bool bRememberCopy = true );
171 /// Current defaults are not applied, new defaults are applied
172 void SetTextNewDefaults( const OUString& rText,
173 SfxItemSet* pDefaults, bool bTakeOwnership = true );
175 /// Paragraph attributes that are not defaults are copied to
176 /// character attributes and all paragraph attributes reset
177 void RemoveParaAttribs();
179 /// Re-apply existing defaults if set, same as in SetText,
180 /// but without EnableUndo/SetUpdateMode.
181 void RepeatDefaults();
185 // 1/100 mm
186 class SC_DLLPUBLIC ScTabEditEngine : public ScEditEngineDefaulter
188 private:
189 void Init(const ScPatternAttr& rPattern);
190 public:
191 ScTabEditEngine( ScDocument* pDoc ); // Default
192 ScTabEditEngine( const ScPatternAttr& rPattern,
193 SfxItemPool* pEnginePool,
194 SfxItemPool* pTextObjectPool = NULL );
198 struct ScHeaderFieldData
200 OUString aTitle; // title or file name (if no title)
201 OUString aLongDocName; // path and file name
202 OUString aShortDocName; // pure file name
203 OUString aTabName;
204 Date aDate;
205 Time aTime;
206 long nPageNo;
207 long nTotalPages;
208 SvxNumType eNumType;
210 ScHeaderFieldData();
214 // for field commands (or just fields?) in a table
215 class SC_DLLPUBLIC ScFieldEditEngine : public ScEditEngineDefaulter
217 private:
218 ScDocument* mpDoc;
219 bool bExecuteURL;
221 public:
222 ScFieldEditEngine(
223 ScDocument* pDoc, SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool = NULL,
224 bool bDeleteEnginePool = false);
226 void SetExecuteURL(bool bSet) { bExecuteURL = bSet; }
228 virtual void FieldClicked( const SvxFieldItem& rField, sal_Int32, sal_Int32 ) SAL_OVERRIDE;
229 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor ) SAL_OVERRIDE;
233 // for headers/footers with fields
234 class SC_DLLPUBLIC ScHeaderEditEngine : public ScEditEngineDefaulter
236 private:
237 ScHeaderFieldData aData;
239 public:
240 ScHeaderEditEngine( SfxItemPool* pEnginePool, bool bDeleteEnginePool = false );
241 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor ) SAL_OVERRIDE;
243 void SetNumType(SvxNumType eNew) { aData.eNumType = eNew; }
244 void SetData(const ScHeaderFieldData& rNew) { aData = rNew; }
247 // for Note text objects.
248 class ScNoteEditEngine : public ScEditEngineDefaulter
251 public:
252 ScNoteEditEngine( SfxItemPool* pEnginePool,
253 SfxItemPool* pTextObjectPool = NULL,
254 bool bDeleteEnginePool = false );
258 // SvxFieldData derivations were moved to Svx (comment can be deleted?)
261 #endif
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */