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