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