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