update credits
[LibreOffice.git] / sc / inc / editutil.hxx
blobf27bbf8e680fc6d23b6c3d3fe2b29e5dc6d5ecfb
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 String ModifyDelimiters( const String& 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 );
62 /** Retrieves string with paragraphs delimited by new lines ('\n').
64 @param pDoc
65 If not NULL, use pDoc->GetEditEngine() to retrieve field content.
66 If NULL, a static mutex-guarded ScFieldEditEngine is used that
67 is not capable of resolving document specific fields; avoid.
69 SC_DLLPUBLIC static OUString GetString( const EditTextObject& rEditText, const ScDocument* pDoc );
71 static EditTextObject* CreateURLObjectFromURL(
72 ScDocument& rDoc, const OUString& rURL, const OUString& rText );
74 static void RemoveCharAttribs( EditTextObject& rEditText, const ScPatternAttr& rAttr );
76 public:
77 ScEditUtil( ScDocument* pDocument, SCCOL nX, SCROW nY, SCTAB nZ,
78 const Point& rScrPosPixel,
79 OutputDevice* pDevice, double nScaleX, double nScaleY,
80 const Fraction& rX, const Fraction& rY ) :
81 pDoc(pDocument),nCol(nX),nRow(nY),nTab(nZ),
82 aScrPos(rScrPosPixel),pDev(pDevice),
83 nPPTX(nScaleX),nPPTY(nScaleY),aZoomX(rX),aZoomY(rY) {}
85 Rectangle GetEditArea( const ScPatternAttr* pPattern, sal_Bool bForceToTop );
89 class ScEditAttrTester
91 ScEditEngineDefaulter* pEngine;
92 SfxItemSet* pEditAttrs;
93 sal_Bool bNeedsObject;
94 sal_Bool bNeedsCellAttr;
96 public:
97 ScEditAttrTester( ScEditEngineDefaulter* pEng );
98 ~ScEditAttrTester();
100 sal_Bool NeedsObject() const { return bNeedsObject; }
101 sal_Bool NeedsCellAttr() const { return bNeedsCellAttr; }
102 const SfxItemSet& GetAttribs() const { return *pEditAttrs; }
106 // construct pool before constructing EditEngine, destroy pool after EditEngine
107 class ScEnginePoolHelper
109 protected:
110 SfxItemPool* pEnginePool;
111 SfxItemSet* pDefaults;
112 sal_Bool bDeleteEnginePool;
113 sal_Bool bDeleteDefaults;
115 ScEnginePoolHelper( SfxItemPool* pEnginePool,
116 sal_Bool bDeleteEnginePool = false );
117 ScEnginePoolHelper( const ScEnginePoolHelper& rOrg );
118 virtual ~ScEnginePoolHelper();
122 class SC_DLLPUBLIC ScEditEngineDefaulter : public ScEnginePoolHelper, public EditEngine
124 private:
125 using EditEngine::SetText;
127 public:
128 /// bDeleteEnginePool: Engine becomes the owner of the pool
129 /// and deletes it on destruction
130 ScEditEngineDefaulter( SfxItemPool* pEnginePool,
131 sal_Bool bDeleteEnginePool = false );
132 /// If rOrg.bDeleteEnginePool: pool gets cloned and will be
133 /// deleted on destruction. Defaults are not set.
134 ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg );
135 virtual ~ScEditEngineDefaulter();
137 /// Creates a copy of SfxItemSet if bRememberCopy set
138 void SetDefaults( const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
140 /// Becomes the owner of the SfxItemSet if bTakeOwnership set
141 void SetDefaults( SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
143 /// Set the item in the default ItemSet which is created
144 /// if it doesn't exist yet.
145 /// The default ItemSet is then applied to each paragraph.
146 void SetDefaultItem( const SfxPoolItem& rItem );
148 /// Returns the stored defaults, used to find non-default character attributes
149 const SfxItemSet& GetDefaults();
151 /// Overwritten method to be able to apply defaults already set
152 void SetText( const EditTextObject& rTextObject );
153 /// Current defaults are not applied, new defaults are applied
154 void SetTextNewDefaults( const EditTextObject& rTextObject,
155 const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
156 /// Current defaults are not applied, new defaults are applied
157 void SetTextNewDefaults( const EditTextObject& rTextObject,
158 SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
160 /// Overwritten method to be able to apply defaults already set
161 void SetText( const OUString& rText );
162 /// Current defaults are not applied, new defaults are applied
163 void SetTextNewDefaults( const String& rText,
164 const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
165 /// Current defaults are not applied, new defaults are applied
166 void SetTextNewDefaults( const String& rText,
167 SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
169 /// Paragraph attributes that are not defaults are copied to
170 /// character attributes and all paragraph attributes reset
171 void RemoveParaAttribs();
173 /// Re-apply existing defaults if set, same as in SetText,
174 /// but without EnableUndo/SetUpdateMode.
175 void RepeatDefaults();
179 // 1/100 mm
180 class SC_DLLPUBLIC ScTabEditEngine : public ScEditEngineDefaulter
182 private:
183 void Init(const ScPatternAttr& rPattern);
184 public:
185 ScTabEditEngine( ScDocument* pDoc ); // Default
186 ScTabEditEngine( const ScPatternAttr& rPattern,
187 SfxItemPool* pEnginePool,
188 SfxItemPool* pTextObjectPool = NULL );
192 struct ScHeaderFieldData
194 String aTitle; // title or file name (if no title)
195 String aLongDocName; // path and file name
196 String aShortDocName; // pure file name
197 String aTabName;
198 Date aDate;
199 Time aTime;
200 long nPageNo;
201 long nTotalPages;
202 SvxNumType eNumType;
204 ScHeaderFieldData();
208 // for field commands (or just fields?) in a table
209 class SC_DLLPUBLIC ScFieldEditEngine : public ScEditEngineDefaulter
211 private:
212 ScDocument* mpDoc;
213 bool bExecuteURL;
215 public:
216 ScFieldEditEngine(
217 ScDocument* pDoc, SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool = NULL,
218 bool bDeleteEnginePool = false);
220 void SetExecuteURL(bool bSet) { bExecuteURL = bSet; }
222 virtual void FieldClicked( const SvxFieldItem& rField, sal_Int32, sal_uInt16 );
223 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_uInt16 nPos, Color*& rTxtColor, Color*& rFldColor );
227 // for headers/footers with fields
228 class SC_DLLPUBLIC ScHeaderEditEngine : public ScEditEngineDefaulter
230 private:
231 ScHeaderFieldData aData;
233 public:
234 ScHeaderEditEngine( SfxItemPool* pEnginePool, sal_Bool bDeleteEnginePool = false );
235 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_uInt16 nPos, Color*& rTxtColor, Color*& rFldColor );
237 void SetNumType(SvxNumType eNew) { aData.eNumType = eNew; }
238 void SetData(const ScHeaderFieldData& rNew) { aData = rNew; }
241 // for Note text objects.
242 class ScNoteEditEngine : public ScEditEngineDefaulter
245 public:
246 ScNoteEditEngine( SfxItemPool* pEnginePool,
247 SfxItemPool* pTextObjectPool = NULL,
248 sal_Bool bDeleteEnginePool = false );
252 // SvxFieldData derivations were moved to Svx (comment can be deleted?)
255 #endif
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */