Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / inc / editutil.hxx
blob2d3d4ce36cc28e396b979203fc6df04d20d83f71
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 SC_EDITUTIL_HXX
21 #define SC_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 );
58 static OUString GetSpaceDelimitedString( const EditTextObject& rEdit );
60 /// Retrieves string with paragraphs delimited by new lines ('\n').
61 static OUString GetMultilineString( const EditEngine& rEngine );
62 static OUString GetMultilineString( const EditTextObject& rEdit );
64 /** Retrieves string with paragraphs delimited by new lines ('\n').
66 @param pDoc
67 If not NULL, use pDoc->GetEditEngine() to retrieve field content.
68 If NULL, a static mutex-guarded ScFieldEditEngine is used that
69 is not capable of resolving document specific fields; avoid.
71 SC_DLLPUBLIC static OUString GetString( const EditTextObject& rEditText, const ScDocument* pDoc );
73 static EditTextObject* CreateURLObjectFromURL(
74 ScDocument& rDoc, const OUString& rURL, const OUString& rText );
76 static void RemoveCharAttribs( EditTextObject& rEditText, const ScPatternAttr& rAttr );
78 static EditTextObject* Clone( const EditTextObject& rSrc, ScDocument& rDestDoc );
80 static OUString GetCellFieldValue(
81 const SvxFieldData& rFieldData, const ScDocument* pDoc, Color** ppTextColor );
83 public:
84 ScEditUtil( ScDocument* pDocument, SCCOL nX, SCROW nY, SCTAB nZ,
85 const Point& rScrPosPixel,
86 OutputDevice* pDevice, double nScaleX, double nScaleY,
87 const Fraction& rX, const Fraction& rY ) :
88 pDoc(pDocument),nCol(nX),nRow(nY),nTab(nZ),
89 aScrPos(rScrPosPixel),pDev(pDevice),
90 nPPTX(nScaleX),nPPTY(nScaleY),aZoomX(rX),aZoomY(rY) {}
92 Rectangle GetEditArea( const ScPatternAttr* pPattern, sal_Bool bForceToTop );
96 class ScEditAttrTester
98 ScEditEngineDefaulter* pEngine;
99 SfxItemSet* pEditAttrs;
100 sal_Bool bNeedsObject;
101 sal_Bool bNeedsCellAttr;
103 public:
104 ScEditAttrTester( ScEditEngineDefaulter* pEng );
105 ~ScEditAttrTester();
107 sal_Bool NeedsObject() const { return bNeedsObject; }
108 sal_Bool NeedsCellAttr() const { return bNeedsCellAttr; }
109 const SfxItemSet& GetAttribs() const { return *pEditAttrs; }
113 // construct pool before constructing EditEngine, destroy pool after EditEngine
114 class ScEnginePoolHelper
116 protected:
117 SfxItemPool* pEnginePool;
118 SfxItemSet* pDefaults;
119 sal_Bool bDeleteEnginePool;
120 sal_Bool bDeleteDefaults;
122 ScEnginePoolHelper( SfxItemPool* pEnginePool,
123 sal_Bool bDeleteEnginePool = false );
124 ScEnginePoolHelper( const ScEnginePoolHelper& rOrg );
125 virtual ~ScEnginePoolHelper();
129 class SC_DLLPUBLIC ScEditEngineDefaulter : public ScEnginePoolHelper, public EditEngine
131 private:
132 using EditEngine::SetText;
134 public:
135 /// bDeleteEnginePool: Engine becomes the owner of the pool
136 /// and deletes it on destruction
137 ScEditEngineDefaulter( SfxItemPool* pEnginePool,
138 sal_Bool bDeleteEnginePool = false );
139 /// If rOrg.bDeleteEnginePool: pool gets cloned and will be
140 /// deleted on destruction. Defaults are not set.
141 ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg );
142 virtual ~ScEditEngineDefaulter();
144 /// Creates a copy of SfxItemSet if bRememberCopy set
145 void SetDefaults( const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
147 /// Becomes the owner of the SfxItemSet if bTakeOwnership set
148 void SetDefaults( SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
150 /// Set the item in the default ItemSet which is created
151 /// if it doesn't exist yet.
152 /// The default ItemSet is then applied to each paragraph.
153 void SetDefaultItem( const SfxPoolItem& rItem );
155 /// Returns the stored defaults, used to find non-default character attributes
156 const SfxItemSet& GetDefaults();
158 /// Overwritten method to be able to apply defaults already set
159 void SetText( const EditTextObject& rTextObject );
160 /// Current defaults are not applied, new defaults are applied
161 void SetTextNewDefaults( const EditTextObject& rTextObject,
162 const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
163 /// Current defaults are not applied, new defaults are applied
164 void SetTextNewDefaults( const EditTextObject& rTextObject,
165 SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
167 /// Overwritten method to be able to apply defaults already set
168 void SetText( const OUString& rText );
169 /// Current defaults are not applied, new defaults are applied
170 void SetTextNewDefaults( const OUString& rText,
171 const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
172 /// Current defaults are not applied, new defaults are applied
173 void SetTextNewDefaults( const OUString& rText,
174 SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
176 /// Paragraph attributes that are not defaults are copied to
177 /// character attributes and all paragraph attributes reset
178 void RemoveParaAttribs();
180 /// Re-apply existing defaults if set, same as in SetText,
181 /// but without EnableUndo/SetUpdateMode.
182 void RepeatDefaults();
186 // 1/100 mm
187 class SC_DLLPUBLIC ScTabEditEngine : public ScEditEngineDefaulter
189 private:
190 void Init(const ScPatternAttr& rPattern);
191 public:
192 ScTabEditEngine( ScDocument* pDoc ); // Default
193 ScTabEditEngine( const ScPatternAttr& rPattern,
194 SfxItemPool* pEnginePool,
195 SfxItemPool* pTextObjectPool = NULL );
199 struct ScHeaderFieldData
201 OUString aTitle; // title or file name (if no title)
202 OUString aLongDocName; // path and file name
203 OUString aShortDocName; // pure file name
204 OUString aTabName;
205 Date aDate;
206 Time aTime;
207 long nPageNo;
208 long nTotalPages;
209 SvxNumType eNumType;
211 ScHeaderFieldData();
215 // for field commands (or just fields?) in a table
216 class SC_DLLPUBLIC ScFieldEditEngine : public ScEditEngineDefaulter
218 private:
219 ScDocument* mpDoc;
220 bool bExecuteURL;
222 public:
223 ScFieldEditEngine(
224 ScDocument* pDoc, SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool = NULL,
225 bool bDeleteEnginePool = false);
227 void SetExecuteURL(bool bSet) { bExecuteURL = bSet; }
229 virtual void FieldClicked( const SvxFieldItem& rField, sal_Int32, sal_uInt16 );
230 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_uInt16 nPos, Color*& rTxtColor, Color*& rFldColor );
234 // for headers/footers with fields
235 class SC_DLLPUBLIC ScHeaderEditEngine : public ScEditEngineDefaulter
237 private:
238 ScHeaderFieldData aData;
240 public:
241 ScHeaderEditEngine( SfxItemPool* pEnginePool, sal_Bool bDeleteEnginePool = false );
242 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_uInt16 nPos, Color*& rTxtColor, Color*& rFldColor );
244 void SetNumType(SvxNumType eNew) { aData.eNumType = eNew; }
245 void SetData(const ScHeaderFieldData& rNew) { aData = rNew; }
248 // for Note text objects.
249 class ScNoteEditEngine : public ScEditEngineDefaulter
252 public:
253 ScNoteEditEngine( SfxItemPool* pEnginePool,
254 SfxItemPool* pTextObjectPool = NULL,
255 sal_Bool bDeleteEnginePool = false );
259 // SvxFieldData derivations were moved to Svx (comment can be deleted?)
262 #endif
265 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */