1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 INCLUDED_SC_INC_EDITUTIL_HXX
21 #define INCLUDED_SC_INC_EDITUTIL_HXX
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>
36 class ScEditEngineDefaulter
;
45 OutputDevice
* pDev
; // MapMode has to be set
51 static const char pCalcDelimiters
[];
54 static OUString
ModifyDelimiters( const OUString
& rOld
);
56 /// Retrieves string with paragraphs delimited by spaces
57 static OUString
GetSpaceDelimitedString( const EditEngine
& rEngine
);
59 /// Retrieves string with paragraphs delimited by new lines ('\n').
60 static OUString
GetMultilineString( const EditEngine
& rEngine
);
61 static OUString
GetMultilineString( const EditTextObject
& rEdit
);
63 /** Retrieves string with paragraphs delimited by new lines ('\n').
66 If not NULL, use pDoc->GetEditEngine() to retrieve field content.
67 If NULL, a static mutex-guarded ScFieldEditEngine is used that
68 is not capable of resolving document specific fields; avoid.
70 SC_DLLPUBLIC
static OUString
GetString( const EditTextObject
& rEditText
, const ScDocument
* pDoc
);
72 static EditTextObject
* CreateURLObjectFromURL(
73 ScDocument
& rDoc
, const OUString
& rURL
, const OUString
& rText
);
75 static void RemoveCharAttribs( EditTextObject
& rEditText
, const ScPatternAttr
& rAttr
);
77 static EditTextObject
* Clone( const EditTextObject
& rSrc
, ScDocument
& rDestDoc
);
79 static OUString
GetCellFieldValue(
80 const SvxFieldData
& rFieldData
, const ScDocument
* pDoc
, Color
** ppTextColor
);
83 ScEditUtil( ScDocument
* pDocument
, SCCOL nX
, SCROW nY
, SCTAB nZ
,
84 const Point
& rScrPosPixel
,
85 OutputDevice
* pDevice
, double nScaleX
, double nScaleY
,
86 const Fraction
& rX
, const Fraction
& rY
) :
87 pDoc(pDocument
),nCol(nX
),nRow(nY
),nTab(nZ
),
88 aScrPos(rScrPosPixel
),pDev(pDevice
),
89 nPPTX(nScaleX
),nPPTY(nScaleY
),aZoomX(rX
),aZoomY(rY
) {}
91 Rectangle
GetEditArea( const ScPatternAttr
* pPattern
, bool bForceToTop
);
95 class ScEditAttrTester
97 ScEditEngineDefaulter
* pEngine
;
98 SfxItemSet
* pEditAttrs
;
103 ScEditAttrTester( ScEditEngineDefaulter
* pEng
);
106 bool NeedsObject() const { return bNeedsObject
; }
107 bool NeedsCellAttr() const { return bNeedsCellAttr
; }
108 const SfxItemSet
& GetAttribs() const { return *pEditAttrs
; }
112 // construct pool before constructing EditEngine, destroy pool after EditEngine
113 class ScEnginePoolHelper
116 SfxItemPool
* pEnginePool
;
117 SfxItemSet
* pDefaults
;
118 bool bDeleteEnginePool
;
119 bool bDeleteDefaults
;
121 ScEnginePoolHelper( SfxItemPool
* pEnginePool
,
122 bool bDeleteEnginePool
= false );
123 ScEnginePoolHelper( const ScEnginePoolHelper
& rOrg
);
124 virtual ~ScEnginePoolHelper();
128 class SC_DLLPUBLIC ScEditEngineDefaulter
: public ScEnginePoolHelper
, public EditEngine
131 using EditEngine::SetText
;
134 /// bDeleteEnginePool: Engine becomes the owner of the pool
135 /// and deletes it on destruction
136 ScEditEngineDefaulter( SfxItemPool
* pEnginePool
,
137 bool bDeleteEnginePool
= false );
138 /// If rOrg.bDeleteEnginePool: pool gets cloned and will be
139 /// deleted on destruction. Defaults are not set.
140 ScEditEngineDefaulter( const ScEditEngineDefaulter
& rOrg
);
141 virtual ~ScEditEngineDefaulter();
143 /// Creates a copy of SfxItemSet if bRememberCopy set
144 void SetDefaults( const SfxItemSet
& rDefaults
, bool bRememberCopy
= true );
146 /// Becomes the owner of the SfxItemSet if bTakeOwnership set
147 void SetDefaults( SfxItemSet
* pDefaults
, bool bTakeOwnership
= true );
149 /// Set the item in the default ItemSet which is created
150 /// if it doesn't exist yet.
151 /// The default ItemSet is then applied to each paragraph.
152 void SetDefaultItem( const SfxPoolItem
& rItem
);
154 /// Returns the stored defaults, used to find non-default character attributes
155 const SfxItemSet
& GetDefaults();
157 /// Overwritten method to be able to apply defaults already set
158 void SetText( const EditTextObject
& rTextObject
);
159 /// Current defaults are not applied, new defaults are applied
160 void SetTextNewDefaults( const EditTextObject
& rTextObject
,
161 const SfxItemSet
& rDefaults
, bool bRememberCopy
= true );
162 /// Current defaults are not applied, new defaults are applied
163 void SetTextNewDefaults( const EditTextObject
& rTextObject
,
164 SfxItemSet
* pDefaults
, bool bTakeOwnership
= true );
166 /// Overwritten method to be able to apply defaults already set
167 void SetText( const OUString
& rText
);
168 /// Current defaults are not applied, new defaults are applied
169 void SetTextNewDefaults( const OUString
& rText
,
170 const SfxItemSet
& rDefaults
, bool bRememberCopy
= true );
171 /// Current defaults are not applied, new defaults are applied
172 void SetTextNewDefaults( const OUString
& rText
,
173 SfxItemSet
* pDefaults
, bool bTakeOwnership
= true );
175 /// Paragraph attributes that are not defaults are copied to
176 /// character attributes and all paragraph attributes reset
177 void RemoveParaAttribs();
179 /// Re-apply existing defaults if set, same as in SetText,
180 /// but without EnableUndo/SetUpdateMode.
181 void RepeatDefaults();
186 class SC_DLLPUBLIC ScTabEditEngine
: public ScEditEngineDefaulter
189 void Init(const ScPatternAttr
& rPattern
);
191 ScTabEditEngine( ScDocument
* pDoc
); // Default
192 ScTabEditEngine( const ScPatternAttr
& rPattern
,
193 SfxItemPool
* pEnginePool
,
194 SfxItemPool
* pTextObjectPool
= NULL
);
198 struct ScHeaderFieldData
200 OUString aTitle
; // title or file name (if no title)
201 OUString aLongDocName
; // path and file name
202 OUString aShortDocName
; // pure file name
214 // for field commands (or just fields?) in a table
215 class SC_DLLPUBLIC ScFieldEditEngine
: public ScEditEngineDefaulter
223 ScDocument
* pDoc
, SfxItemPool
* pEnginePool
, SfxItemPool
* pTextObjectPool
= NULL
,
224 bool bDeleteEnginePool
= false);
226 void SetExecuteURL(bool bSet
) { bExecuteURL
= bSet
; }
228 virtual void FieldClicked( const SvxFieldItem
& rField
, sal_Int32
, sal_Int32
) SAL_OVERRIDE
;
229 virtual OUString
CalcFieldValue( const SvxFieldItem
& rField
, sal_Int32 nPara
, sal_Int32 nPos
, Color
*& rTxtColor
, Color
*& rFldColor
) SAL_OVERRIDE
;
233 // for headers/footers with fields
234 class SC_DLLPUBLIC ScHeaderEditEngine
: public ScEditEngineDefaulter
237 ScHeaderFieldData aData
;
240 ScHeaderEditEngine( SfxItemPool
* pEnginePool
, bool bDeleteEnginePool
= false );
241 virtual OUString
CalcFieldValue( const SvxFieldItem
& rField
, sal_Int32 nPara
, sal_Int32 nPos
, Color
*& rTxtColor
, Color
*& rFldColor
) SAL_OVERRIDE
;
243 void SetNumType(SvxNumType eNew
) { aData
.eNumType
= eNew
; }
244 void SetData(const ScHeaderFieldData
& rNew
) { aData
= rNew
; }
247 // for Note text objects.
248 class ScNoteEditEngine
: public ScEditEngineDefaulter
252 ScNoteEditEngine( SfxItemPool
* pEnginePool
,
253 SfxItemPool
* pTextObjectPool
= NULL
,
254 bool bDeleteEnginePool
= false );
258 // SvxFieldData derivations were moved to Svx (comment can be deleted?)
264 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */