xref: /aoo42x/main/sc/inc/editutil.hxx (revision 7a980842)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_EDITUTIL_HXX
25 #define SC_EDITUTIL_HXX
26 
27 #include "scdllapi.h"
28 #include "address.hxx"
29 #include <editeng/editeng.hxx>
30 #include <svx/pageitem.hxx>
31 #include <tools/date.hxx>
32 #include <tools/time.hxx>
33 #include <tools/gen.hxx>
34 #include <tools/fract.hxx>
35 
36 
37 class OutputDevice;
38 class ScDocument;
39 class ScPatternAttr;
40 class ScEditEngineDefaulter;
41 
42 class ScEditUtil
43 {
44 	ScDocument*		pDoc;
45 	SCCOL			nCol;
46 	SCROW			nRow;
47 	SCTAB			nTab;
48 	Point			aScrPos;
49 	OutputDevice*	pDev;			// MapMode muss eingestellt sein
50 	double			nPPTX;
51 	double			nPPTY;
52 	Fraction		aZoomX;
53 	Fraction		aZoomY;
54 
55 	static const char __FAR_DATA pCalcDelimiters[];
56 
57 public:
58 	static String ModifyDelimiters( const String& rOld );
59 
60     /// Retrieves string with paragraphs delimited by spaces
61 	static String GetSpaceDelimitedString( const EditEngine& rEngine );
62 
63     /// Retrieves string with paragraphs delimited by new lines ('\n').
64     static String GetMultilineString( const EditEngine& rEngine );
65 
66 public:
ScEditUtil(ScDocument * pDocument,SCCOL nX,SCROW nY,SCTAB nZ,const Point & rScrPosPixel,OutputDevice * pDevice,double nScaleX,double nScaleY,const Fraction & rX,const Fraction & rY)67 				ScEditUtil( ScDocument* pDocument, SCCOL nX, SCROW nY, SCTAB nZ,
68 							const Point& rScrPosPixel,
69 							OutputDevice* pDevice, double nScaleX, double nScaleY,
70 							const Fraction& rX, const Fraction& rY ) :
71 					pDoc(pDocument),nCol(nX),nRow(nY),nTab(nZ),
72 					aScrPos(rScrPosPixel),pDev(pDevice),
73 					nPPTX(nScaleX),nPPTY(nScaleY),aZoomX(rX),aZoomY(rY) {}
74 
75 	Rectangle	GetEditArea( const ScPatternAttr* pPattern, sal_Bool bForceToTop );
76 };
77 
78 
79 class ScEditAttrTester
80 {
81 	ScEditEngineDefaulter* pEngine;
82 	SfxItemSet*	pEditAttrs;
83 	sal_Bool		bNeedsObject;
84 	sal_Bool		bNeedsCellAttr;
85 
86 public:
87 				ScEditAttrTester( ScEditEngineDefaulter* pEng );
88 				~ScEditAttrTester();
89 
NeedsObject() const90 	sal_Bool				NeedsObject() const		{ return bNeedsObject; }
NeedsCellAttr() const91 	sal_Bool				NeedsCellAttr() const	{ return bNeedsCellAttr; }
GetAttribs() const92 	const SfxItemSet&	GetAttribs() const		{ return *pEditAttrs; }
93 };
94 
95 
96 // construct pool before constructing EditEngine, destroy pool after EditEngine
97 class ScEnginePoolHelper
98 {
99 protected:
100 	SfxItemPool*	pEnginePool;
101 	SfxItemSet*		pDefaults;
102 	sal_Bool			bDeleteEnginePool;
103 	sal_Bool			bDeleteDefaults;
104 
105 					ScEnginePoolHelper( SfxItemPool* pEnginePool,
106 						sal_Bool bDeleteEnginePool = sal_False );
107 					ScEnginePoolHelper( const ScEnginePoolHelper& rOrg );
108 	virtual			~ScEnginePoolHelper();
109 };
110 
111 
112 class SC_DLLPUBLIC ScEditEngineDefaulter : public ScEnginePoolHelper, public EditEngine
113 {
114 private:
115     using EditEngine::SetText;
116 
117 public:
118 					/// bDeleteEnginePool: Engine becomes the owner of the pool
119 					/// and deletes it on destruction
120 					ScEditEngineDefaulter( SfxItemPool* pEnginePool,
121 						sal_Bool bDeleteEnginePool = sal_False );
122 					/// If rOrg.bDeleteEnginePool: pool gets cloned and will be
123 					/// deleted on destruction. Defaults are not set.
124 					ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg );
125 	virtual			~ScEditEngineDefaulter();
126 
127 					/// Creates a copy of SfxItemSet if bRememberCopy set
128 	void			SetDefaults( const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
129 
130 					/// Becomes the owner of the SfxItemSet if bTakeOwnership set
131 	void			SetDefaults( SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
132 
133 					/// Set the item in the default ItemSet which is created
134 					/// if it doesn't exist yet.
135 					/// The default ItemSet is then applied to each paragraph.
136 	void			SetDefaultItem( const SfxPoolItem& rItem );
137 
138                     /// Returns the stored defaults, used to find non-default character attributes
139     const SfxItemSet& GetDefaults();
140 
141 					/// Overwritten method to be able to apply defaults already set
142 	void			SetText( const EditTextObject& rTextObject );
143 					/// Current defaults are not applied, new defaults are applied
144 	void			SetTextNewDefaults( const EditTextObject& rTextObject,
145 						const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
146 					/// Current defaults are not applied, new defaults are applied
147 	void			SetTextNewDefaults( const EditTextObject& rTextObject,
148 						SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
149 
150 					/// Overwritten method to be able to apply defaults already set
151 	void			SetText( const String& rText );
152 					/// Current defaults are not applied, new defaults are applied
153 	void			SetTextNewDefaults( const String& rText,
154 						const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
155 					/// Current defaults are not applied, new defaults are applied
156 	void			SetTextNewDefaults( const String& rText,
157 						SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
158 
159 					/// Paragraph attributes that are not defaults are copied to
160 					/// character attributes and all paragraph attributes reset
161 	void			RemoveParaAttribs();
162 
163 					/// Re-apply existing defaults if set, same as in SetText,
164 					/// but without EnableUndo/SetUpdateMode.
165 	void			RepeatDefaults();
166 };
167 
168 
169 // 1/100 mm
170 class SC_DLLPUBLIC ScTabEditEngine : public ScEditEngineDefaulter
171 {
172 private:
173 	void	Init(const ScPatternAttr& rPattern);
174 public:
175 	ScTabEditEngine( ScDocument* pDoc );			// Default
176 	// pEnginePool = ScDocument.GetEnginePool()
177 	// pTextObjectPool = ScDocument.GetEditPool()
178 	ScTabEditEngine( const ScPatternAttr& rPattern,
179 					SfxItemPool* pEnginePool,
180 					SfxItemPool* pTextObjectPool = NULL );
181 };
182 
183 
184 struct ScHeaderFieldData
185 {
186 	String		aTitle;				// Titel oder Dateiname wenn kein Titel
187 	String		aLongDocName;		// Pfad und Dateiname
188 	String		aShortDocName;		// nur Dateiname
189 	String		aTabName;
190 	Date		aDate;
191 	Time		aTime;
192 	long		nPageNo;
193 	long		nTotalPages;
194 	SvxNumType	eNumType;
195 
196 	ScHeaderFieldData();
197 };
198 
199 
200 // fuer Feldbefehle in der Tabelle
201 class SC_DLLPUBLIC ScFieldEditEngine : public ScEditEngineDefaulter
202 {
203 private:
204 	sal_Bool	bExecuteURL;
205 
206 public:
207 	// pEnginePool = ScDocument.GetEnginePool()
208 	// pTextObjectPool = ScDocument.GetEditPool()
209 	ScFieldEditEngine( SfxItemPool* pEnginePool,
210 						SfxItemPool* pTextObjectPool = NULL,
211 						sal_Bool bDeleteEnginePool = sal_False );
212 
SetExecuteURL(sal_Bool bSet)213 	void	SetExecuteURL(sal_Bool bSet)	{ bExecuteURL = bSet; }
214 
215 	virtual void	FieldClicked( const SvxFieldItem& rField, sal_uInt32, sal_uInt16 );
216 	virtual String	CalcFieldValue( const SvxFieldItem& rField, sal_uInt32 nPara, sal_uInt16 nPos, Color*& rTxtColor, Color*& rFldColor );
217 };
218 
219 
220 // for headers/footers with fields
221 class SC_DLLPUBLIC ScHeaderEditEngine : public ScEditEngineDefaulter
222 {
223 private:
224 	ScHeaderFieldData	aData;
225 
226 public:
227 	ScHeaderEditEngine( SfxItemPool* pEnginePool, sal_Bool bDeleteEnginePool = sal_False );
228 	virtual String CalcFieldValue( const SvxFieldItem& rField, sal_uInt32 nPara, sal_uInt16 nPos, Color*& rTxtColor, Color*& rFldColor );
229 
SetTitle(const String & rNew)230 	void SetTitle(const String& rNew)				{ aData.aTitle = rNew; }
SetLongDocName(const String & rNew)231 	void SetLongDocName(const String& rNew)			{ aData.aLongDocName = rNew; }
SetShortDocName(const String & rNew)232 	void SetShortDocName(const String& rNew)		{ aData.aShortDocName = rNew; }
SetTabName(const String & rNew)233 	void SetTabName(const String& rNew)				{ aData.aTabName = rNew; }
SetDate(const Date & rNew)234 	void SetDate(const Date& rNew)					{ aData.aDate = rNew; }
SetTime(const Time & rNew)235 	void SetTime(const Time& rNew)					{ aData.aTime = rNew; }
SetPageNo(long nNew)236 	void SetPageNo(long nNew)						{ aData.nPageNo = nNew; }
SetTotalPages(long nNew)237 	void SetTotalPages(long nNew)					{ aData.nTotalPages = nNew; }
SetNumType(SvxNumType eNew)238 	void SetNumType(SvxNumType eNew)				{ aData.eNumType = eNew; }
SetData(const ScHeaderFieldData & rNew)239 	void SetData(const ScHeaderFieldData& rNew)		{ aData = rNew; }
240 };
241 
242 // for Note text objects.
243 class ScNoteEditEngine : public ScEditEngineDefaulter
244 {
245 
246 public:
247 	// pEnginePool = ScDocument.GetEnginePool()
248 	// pTextObjectPool = ScDocument.GetEditPool()
249 	ScNoteEditEngine( SfxItemPool* pEnginePool,
250 			    SfxItemPool* pTextObjectPool = NULL,
251 				sal_Bool bDeleteEnginePool = sal_False );
252 
253 };
254 
255 //	SvxFieldData-Ableitungen sind nach Svx verschoben
256 
257 
258 #endif
259 
260 
261