Impress Remote 1.0.5, tag sdremote-1.0.5
[LibreOffice.git] / sc / inc / editutil.hxx
blob5fbf6dc8eb1cec57f94e00a1af2ff5de7df5a5c3
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 String GetSpaceDelimitedString( const EditEngine& rEngine );
59 /// Retrieves string with paragraphs delimited by new lines ('\n').
60 static String GetMultilineString( const EditEngine& rEngine );
62 public:
63 ScEditUtil( ScDocument* pDocument, SCCOL nX, SCROW nY, SCTAB nZ,
64 const Point& rScrPosPixel,
65 OutputDevice* pDevice, double nScaleX, double nScaleY,
66 const Fraction& rX, const Fraction& rY ) :
67 pDoc(pDocument),nCol(nX),nRow(nY),nTab(nZ),
68 aScrPos(rScrPosPixel),pDev(pDevice),
69 nPPTX(nScaleX),nPPTY(nScaleY),aZoomX(rX),aZoomY(rY) {}
71 Rectangle GetEditArea( const ScPatternAttr* pPattern, sal_Bool bForceToTop );
75 class ScEditAttrTester
77 ScEditEngineDefaulter* pEngine;
78 SfxItemSet* pEditAttrs;
79 sal_Bool bNeedsObject;
80 sal_Bool bNeedsCellAttr;
82 public:
83 ScEditAttrTester( ScEditEngineDefaulter* pEng );
84 ~ScEditAttrTester();
86 sal_Bool NeedsObject() const { return bNeedsObject; }
87 sal_Bool NeedsCellAttr() const { return bNeedsCellAttr; }
88 const SfxItemSet& GetAttribs() const { return *pEditAttrs; }
92 // construct pool before constructing EditEngine, destroy pool after EditEngine
93 class ScEnginePoolHelper
95 protected:
96 SfxItemPool* pEnginePool;
97 SfxItemSet* pDefaults;
98 sal_Bool bDeleteEnginePool;
99 sal_Bool bDeleteDefaults;
101 ScEnginePoolHelper( SfxItemPool* pEnginePool,
102 sal_Bool bDeleteEnginePool = false );
103 ScEnginePoolHelper( const ScEnginePoolHelper& rOrg );
104 virtual ~ScEnginePoolHelper();
108 class SC_DLLPUBLIC ScEditEngineDefaulter : public ScEnginePoolHelper, public EditEngine
110 private:
111 using EditEngine::SetText;
113 public:
114 /// bDeleteEnginePool: Engine becomes the owner of the pool
115 /// and deletes it on destruction
116 ScEditEngineDefaulter( SfxItemPool* pEnginePool,
117 sal_Bool bDeleteEnginePool = false );
118 /// If rOrg.bDeleteEnginePool: pool gets cloned and will be
119 /// deleted on destruction. Defaults are not set.
120 ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg );
121 virtual ~ScEditEngineDefaulter();
123 /// Creates a copy of SfxItemSet if bRememberCopy set
124 void SetDefaults( const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
126 /// Becomes the owner of the SfxItemSet if bTakeOwnership set
127 void SetDefaults( SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
129 /// Set the item in the default ItemSet which is created
130 /// if it doesn't exist yet.
131 /// The default ItemSet is then applied to each paragraph.
132 void SetDefaultItem( const SfxPoolItem& rItem );
134 /// Returns the stored defaults, used to find non-default character attributes
135 const SfxItemSet& GetDefaults();
137 /// Overwritten method to be able to apply defaults already set
138 void SetText( const EditTextObject& rTextObject );
139 /// Current defaults are not applied, new defaults are applied
140 void SetTextNewDefaults( const EditTextObject& rTextObject,
141 const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
142 /// Current defaults are not applied, new defaults are applied
143 void SetTextNewDefaults( const EditTextObject& rTextObject,
144 SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
146 /// Overwritten method to be able to apply defaults already set
147 void SetText( const String& rText );
148 /// Current defaults are not applied, new defaults are applied
149 void SetTextNewDefaults( const String& rText,
150 const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
151 /// Current defaults are not applied, new defaults are applied
152 void SetTextNewDefaults( const String& rText,
153 SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
155 /// Paragraph attributes that are not defaults are copied to
156 /// character attributes and all paragraph attributes reset
157 void RemoveParaAttribs();
159 /// Re-apply existing defaults if set, same as in SetText,
160 /// but without EnableUndo/SetUpdateMode.
161 void RepeatDefaults();
165 // 1/100 mm
166 class SC_DLLPUBLIC ScTabEditEngine : public ScEditEngineDefaulter
168 private:
169 void Init(const ScPatternAttr& rPattern);
170 public:
171 ScTabEditEngine( ScDocument* pDoc ); // Default
172 ScTabEditEngine( const ScPatternAttr& rPattern,
173 SfxItemPool* pEnginePool,
174 SfxItemPool* pTextObjectPool = NULL );
178 struct ScHeaderFieldData
180 String aTitle; // title or file name (if no title)
181 String aLongDocName; // path and file name
182 String aShortDocName; // pure file name
183 String aTabName;
184 Date aDate;
185 Time aTime;
186 long nPageNo;
187 long nTotalPages;
188 SvxNumType eNumType;
190 ScHeaderFieldData();
194 // for field commands (or just fields?) in a table
195 class SC_DLLPUBLIC ScFieldEditEngine : public ScEditEngineDefaulter
197 private:
198 ScDocument* mpDoc;
199 bool bExecuteURL;
201 public:
202 ScFieldEditEngine(
203 ScDocument* pDoc, SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool = NULL,
204 bool bDeleteEnginePool = false);
206 void SetExecuteURL(bool bSet) { bExecuteURL = bSet; }
208 virtual void FieldClicked( const SvxFieldItem& rField, sal_uInt16, sal_uInt16 );
209 virtual String CalcFieldValue( const SvxFieldItem& rField, sal_uInt16 nPara, sal_uInt16 nPos, Color*& rTxtColor, Color*& rFldColor );
213 // for headers/footers with fields
214 class SC_DLLPUBLIC ScHeaderEditEngine : public ScEditEngineDefaulter
216 private:
217 ScHeaderFieldData aData;
219 public:
220 ScHeaderEditEngine( SfxItemPool* pEnginePool, sal_Bool bDeleteEnginePool = false );
221 virtual String CalcFieldValue( const SvxFieldItem& rField, sal_uInt16 nPara, sal_uInt16 nPos, Color*& rTxtColor, Color*& rFldColor );
223 void SetNumType(SvxNumType eNew) { aData.eNumType = eNew; }
224 void SetData(const ScHeaderFieldData& rNew) { aData = rNew; }
227 // for Note text objects.
228 class ScNoteEditEngine : public ScEditEngineDefaulter
231 public:
232 ScNoteEditEngine( SfxItemPool* pEnginePool,
233 SfxItemPool* pTextObjectPool = NULL,
234 sal_Bool bDeleteEnginePool = false );
238 // SvxFieldData derivations were moved to Svx (comment can be deleted?)
241 #endif
244 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */