Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #ifndef SC_EDITUTIL_HXX
21 : #define SC_EDITUTIL_HXX
22 :
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>
31 :
32 :
33 : class OutputDevice;
34 : class ScDocument;
35 : class ScPatternAttr;
36 : class ScEditEngineDefaulter;
37 :
38 : class ScEditUtil
39 : {
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;
50 :
51 : static const char pCalcDelimiters[];
52 :
53 : public:
54 : static String ModifyDelimiters( const String& rOld );
55 :
56 : /// Retrieves string with paragraphs delimited by spaces
57 : static String GetSpaceDelimitedString( const EditEngine& rEngine );
58 :
59 : /// Retrieves string with paragraphs delimited by new lines ('\n').
60 : static String GetMultilineString( const EditEngine& rEngine );
61 :
62 : public:
63 0 : 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 0 : nPPTX(nScaleX),nPPTY(nScaleY),aZoomX(rX),aZoomY(rY) {}
70 :
71 : Rectangle GetEditArea( const ScPatternAttr* pPattern, sal_Bool bForceToTop );
72 : };
73 :
74 :
75 : class ScEditAttrTester
76 : {
77 : ScEditEngineDefaulter* pEngine;
78 : SfxItemSet* pEditAttrs;
79 : sal_Bool bNeedsObject;
80 : sal_Bool bNeedsCellAttr;
81 :
82 : public:
83 : ScEditAttrTester( ScEditEngineDefaulter* pEng );
84 : ~ScEditAttrTester();
85 :
86 16 : sal_Bool NeedsObject() const { return bNeedsObject; }
87 16 : sal_Bool NeedsCellAttr() const { return bNeedsCellAttr; }
88 0 : const SfxItemSet& GetAttribs() const { return *pEditAttrs; }
89 : };
90 :
91 :
92 : // construct pool before constructing EditEngine, destroy pool after EditEngine
93 : class ScEnginePoolHelper
94 : {
95 : protected:
96 : SfxItemPool* pEnginePool;
97 : SfxItemSet* pDefaults;
98 : sal_Bool bDeleteEnginePool;
99 : sal_Bool bDeleteDefaults;
100 :
101 : ScEnginePoolHelper( SfxItemPool* pEnginePool,
102 : sal_Bool bDeleteEnginePool = false );
103 : ScEnginePoolHelper( const ScEnginePoolHelper& rOrg );
104 : virtual ~ScEnginePoolHelper();
105 : };
106 :
107 :
108 : class SC_DLLPUBLIC ScEditEngineDefaulter : public ScEnginePoolHelper, public EditEngine
109 : {
110 : private:
111 : using EditEngine::SetText;
112 :
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();
122 :
123 : /// Creates a copy of SfxItemSet if bRememberCopy set
124 : void SetDefaults( const SfxItemSet& rDefaults, sal_Bool bRememberCopy = sal_True );
125 :
126 : /// Becomes the owner of the SfxItemSet if bTakeOwnership set
127 : void SetDefaults( SfxItemSet* pDefaults, sal_Bool bTakeOwnership = sal_True );
128 :
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 );
133 :
134 : /// Returns the stored defaults, used to find non-default character attributes
135 : const SfxItemSet& GetDefaults();
136 :
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 );
145 :
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 );
154 :
155 : /// Paragraph attributes that are not defaults are copied to
156 : /// character attributes and all paragraph attributes reset
157 : void RemoveParaAttribs();
158 :
159 : /// Re-apply existing defaults if set, same as in SetText,
160 : /// but without EnableUndo/SetUpdateMode.
161 : void RepeatDefaults();
162 : };
163 :
164 :
165 : // 1/100 mm
166 2 : class SC_DLLPUBLIC ScTabEditEngine : public ScEditEngineDefaulter
167 : {
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 );
175 : };
176 :
177 :
178 1749 : struct ScHeaderFieldData
179 : {
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;
189 :
190 : ScHeaderFieldData();
191 : };
192 :
193 :
194 : // for field commands (or just fields?) in a table
195 40 : class SC_DLLPUBLIC ScFieldEditEngine : public ScEditEngineDefaulter
196 : {
197 : private:
198 : ScDocument* mpDoc;
199 : bool bExecuteURL;
200 :
201 : public:
202 : ScFieldEditEngine(
203 : ScDocument* pDoc, SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool = NULL,
204 : bool bDeleteEnginePool = false);
205 :
206 0 : void SetExecuteURL(bool bSet) { bExecuteURL = bSet; }
207 :
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 );
210 : };
211 :
212 :
213 : // for headers/footers with fields
214 1280 : class SC_DLLPUBLIC ScHeaderEditEngine : public ScEditEngineDefaulter
215 : {
216 : private:
217 : ScHeaderFieldData aData;
218 :
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 );
222 :
223 0 : void SetNumType(SvxNumType eNew) { aData.eNumType = eNew; }
224 458 : void SetData(const ScHeaderFieldData& rNew) { aData = rNew; }
225 : };
226 :
227 : // for Note text objects.
228 0 : class ScNoteEditEngine : public ScEditEngineDefaulter
229 : {
230 :
231 : public:
232 : ScNoteEditEngine( SfxItemPool* pEnginePool,
233 : SfxItemPool* pTextObjectPool = NULL,
234 : sal_Bool bDeleteEnginePool = false );
235 :
236 : };
237 :
238 : // SvxFieldData derivations were moved to Svx (comment can be deleted?)
239 :
240 :
241 : #endif
242 :
243 :
244 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|