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 INCLUDED_SC_INC_EDITUTIL_HXX
21 : #define INCLUDED_SC_INC_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 : class OutputDevice;
33 : class ScDocument;
34 : class ScPatternAttr;
35 : class ScEditEngineDefaulter;
36 :
37 : class ScEditUtil
38 : {
39 : ScDocument* pDoc;
40 : SCCOL nCol;
41 : SCROW nRow;
42 : SCTAB nTab;
43 : Point aScrPos;
44 : OutputDevice* pDev; // MapMode has to be set
45 : double nPPTX;
46 : double nPPTY;
47 : Fraction aZoomX;
48 : Fraction aZoomY;
49 :
50 : static const char pCalcDelimiters[];
51 :
52 : public:
53 : static OUString ModifyDelimiters( const OUString& rOld );
54 :
55 : /// Retrieves string with paragraphs delimited by spaces
56 : static OUString GetSpaceDelimitedString( const EditEngine& rEngine );
57 :
58 : /// Retrieves string with paragraphs delimited by new lines ('\n').
59 : static OUString GetMultilineString( const EditEngine& rEngine );
60 : static OUString GetMultilineString( const EditTextObject& rEdit );
61 :
62 : /** Retrieves string with paragraphs delimited by new lines ('\n').
63 :
64 : @param pDoc
65 : If not NULL, use pDoc->GetEditEngine() to retrieve field content.
66 : If NULL, a static mutex-guarded ScFieldEditEngine is used that
67 : is not capable of resolving document specific fields; avoid.
68 : */
69 : SC_DLLPUBLIC static OUString GetString( const EditTextObject& rEditText, const ScDocument* pDoc );
70 :
71 : static EditTextObject* CreateURLObjectFromURL(
72 : ScDocument& rDoc, const OUString& rURL, const OUString& rText );
73 :
74 : static void RemoveCharAttribs( EditTextObject& rEditText, const ScPatternAttr& rAttr );
75 :
76 : static EditTextObject* Clone( const EditTextObject& rSrc, ScDocument& rDestDoc );
77 :
78 : static OUString GetCellFieldValue(
79 : const SvxFieldData& rFieldData, const ScDocument* pDoc, Color** ppTextColor );
80 :
81 : public:
82 0 : ScEditUtil( ScDocument* pDocument, SCCOL nX, SCROW nY, SCTAB nZ,
83 : const Point& rScrPosPixel,
84 : OutputDevice* pDevice, double nScaleX, double nScaleY,
85 : const Fraction& rX, const Fraction& rY ) :
86 : pDoc(pDocument),nCol(nX),nRow(nY),nTab(nZ),
87 : aScrPos(rScrPosPixel),pDev(pDevice),
88 0 : nPPTX(nScaleX),nPPTY(nScaleY),aZoomX(rX),aZoomY(rY) {}
89 :
90 : Rectangle GetEditArea( const ScPatternAttr* pPattern, bool bForceToTop );
91 : };
92 :
93 : class ScEditAttrTester
94 : {
95 : ScEditEngineDefaulter* pEngine;
96 : SfxItemSet* pEditAttrs;
97 : bool bNeedsObject;
98 : bool bNeedsCellAttr;
99 :
100 : public:
101 : ScEditAttrTester( ScEditEngineDefaulter* pEng );
102 : ~ScEditAttrTester();
103 :
104 434 : bool NeedsObject() const { return bNeedsObject; }
105 434 : bool NeedsCellAttr() const { return bNeedsCellAttr; }
106 346 : const SfxItemSet& GetAttribs() const { return *pEditAttrs; }
107 : };
108 :
109 : // construct pool before constructing EditEngine, destroy pool after EditEngine
110 : class ScEnginePoolHelper
111 : {
112 : protected:
113 : SfxItemPool* pEnginePool;
114 : SfxItemSet* pDefaults;
115 : bool bDeleteEnginePool;
116 : bool bDeleteDefaults;
117 :
118 : ScEnginePoolHelper( SfxItemPool* pEnginePool,
119 : bool bDeleteEnginePool = false );
120 : ScEnginePoolHelper( const ScEnginePoolHelper& rOrg );
121 : virtual ~ScEnginePoolHelper();
122 : };
123 :
124 : class SC_DLLPUBLIC ScEditEngineDefaulter : public ScEnginePoolHelper, public EditEngine
125 : {
126 : private:
127 : using EditEngine::SetText;
128 :
129 : public:
130 : /// bDeleteEnginePool: Engine becomes the owner of the pool
131 : /// and deletes it on destruction
132 : ScEditEngineDefaulter( SfxItemPool* pEnginePool,
133 : bool bDeleteEnginePool = false );
134 : /// If rOrg.bDeleteEnginePool: pool gets cloned and will be
135 : /// deleted on destruction. Defaults are not set.
136 : ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg );
137 : virtual ~ScEditEngineDefaulter();
138 :
139 : /// Creates a copy of SfxItemSet if bRememberCopy set
140 : void SetDefaults( const SfxItemSet& rDefaults, bool bRememberCopy = true );
141 :
142 : /// Becomes the owner of the SfxItemSet if bTakeOwnership set
143 : void SetDefaults( SfxItemSet* pDefaults, bool bTakeOwnership = true );
144 :
145 : /// Set the item in the default ItemSet which is created
146 : /// if it doesn't exist yet.
147 : /// The default ItemSet is then applied to each paragraph.
148 : void SetDefaultItem( const SfxPoolItem& rItem );
149 :
150 : /// Returns the stored defaults, used to find non-default character attributes
151 : const SfxItemSet& GetDefaults();
152 :
153 : /// Overwritten method to be able to apply defaults already set
154 : void SetText( const EditTextObject& rTextObject );
155 : /// Current defaults are not applied, new defaults are applied
156 : void SetTextNewDefaults( const EditTextObject& rTextObject,
157 : const SfxItemSet& rDefaults, bool bRememberCopy = true );
158 : /// Current defaults are not applied, new defaults are applied
159 : void SetTextNewDefaults( const EditTextObject& rTextObject,
160 : SfxItemSet* pDefaults, bool bTakeOwnership = true );
161 :
162 : /// Overwritten method to be able to apply defaults already set
163 : void SetText( const OUString& rText );
164 : /// Current defaults are not applied, new defaults are applied
165 : void SetTextNewDefaults( const OUString& rText,
166 : const SfxItemSet& rDefaults, bool bRememberCopy = true );
167 : /// Current defaults are not applied, new defaults are applied
168 : void SetTextNewDefaults( const OUString& rText,
169 : SfxItemSet* pDefaults, bool bTakeOwnership = true );
170 :
171 : /// Paragraph attributes that are not defaults are copied to
172 : /// character attributes and all paragraph attributes reset
173 : void RemoveParaAttribs();
174 :
175 : /// Re-apply existing defaults if set, same as in SetText,
176 : /// but without EnableUndo/SetUpdateMode.
177 : void RepeatDefaults();
178 : };
179 :
180 : // 1/100 mm
181 1818 : class SC_DLLPUBLIC ScTabEditEngine : public ScEditEngineDefaulter
182 : {
183 : private:
184 : void Init(const ScPatternAttr& rPattern);
185 : public:
186 : ScTabEditEngine( ScDocument* pDoc ); // Default
187 : ScTabEditEngine( const ScPatternAttr& rPattern,
188 : SfxItemPool* pEnginePool,
189 : SfxItemPool* pTextObjectPool = NULL );
190 : };
191 :
192 24310 : struct ScHeaderFieldData
193 : {
194 : OUString aTitle; // title or file name (if no title)
195 : OUString aLongDocName; // path and file name
196 : OUString aShortDocName; // pure file name
197 : OUString aTabName;
198 : Date aDate;
199 : tools::Time aTime;
200 : long nPageNo;
201 : long nTotalPages;
202 : SvxNumType eNumType;
203 :
204 : ScHeaderFieldData();
205 : };
206 :
207 : // for field commands (or just fields?) in a table
208 2548 : class SC_DLLPUBLIC ScFieldEditEngine : public ScEditEngineDefaulter
209 : {
210 : private:
211 : ScDocument* mpDoc;
212 : bool bExecuteURL;
213 :
214 : public:
215 : ScFieldEditEngine(
216 : ScDocument* pDoc, SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool = NULL,
217 : bool bDeleteEnginePool = false);
218 :
219 334 : void SetExecuteURL(bool bSet) { bExecuteURL = bSet; }
220 :
221 : virtual void FieldClicked( const SvxFieldItem& rField, sal_Int32, sal_Int32 ) SAL_OVERRIDE;
222 : virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor ) SAL_OVERRIDE;
223 : };
224 :
225 : // for headers/footers with fields
226 17332 : class SC_DLLPUBLIC ScHeaderEditEngine : public ScEditEngineDefaulter
227 : {
228 : private:
229 : ScHeaderFieldData aData;
230 :
231 : public:
232 : ScHeaderEditEngine( SfxItemPool* pEnginePool, bool bDeleteEnginePool = false );
233 : virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor ) SAL_OVERRIDE;
234 :
235 0 : void SetNumType(SvxNumType eNew) { aData.eNumType = eNew; }
236 6092 : void SetData(const ScHeaderFieldData& rNew) { aData = rNew; }
237 : };
238 :
239 : // for Note text objects.
240 38 : class ScNoteEditEngine : public ScEditEngineDefaulter
241 : {
242 :
243 : public:
244 : ScNoteEditEngine( SfxItemPool* pEnginePool,
245 : SfxItemPool* pTextObjectPool = NULL,
246 : bool bDeleteEnginePool = false );
247 :
248 : };
249 :
250 : // SvxFieldData derivations were moved to Svx (comment can be deleted?)
251 :
252 : #endif
253 :
254 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|