tdf#125800: accessing cond format props in UNO throws error
[LibreOffice.git] / sc / inc / editutil.hxx
blobf2b7ae0a01a4baafde7e6493bd778b0e4a673e9f
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 INCLUDED_SC_INC_EDITUTIL_HXX
21 #define INCLUDED_SC_INC_EDITUTIL_HXX
23 #include <memory>
24 #include "scdllapi.h"
25 #include "types.hxx"
26 #include <editeng/editeng.hxx>
27 #include <svx/pageitem.hxx>
28 #include <tools/datetime.hxx>
29 #include <tools/gen.hxx>
30 #include <tools/fract.hxx>
31 #include <vcl/outdev.hxx>
33 class ScDocument;
34 class ScPatternAttr;
35 class ScEditEngineDefaulter;
37 class ScEditUtil
39 ScDocument* pDoc;
40 SCCOL const nCol;
41 SCROW const nRow;
42 SCTAB const nTab;
43 Point const aScrPos;
44 VclPtr<OutputDevice> pDev; // MapMode has to be set
45 double const nPPTX;
46 double const nPPTY;
47 Fraction const aZoomX;
48 Fraction aZoomY;
50 public:
51 static OUString ModifyDelimiters( const OUString& rOld );
53 /// Retrieves string with paragraphs delimited by spaces
54 static OUString GetSpaceDelimitedString( const EditEngine& rEngine );
56 /// Retrieves string with paragraphs delimited by new lines ('\n').
57 static OUString GetMultilineString( const EditEngine& rEngine );
58 static OUString GetMultilineString( const EditTextObject& rEdit );
60 /** Retrieves string with paragraphs delimited by new lines ('\n').
62 @param pDoc
63 If not NULL, use pDoc->GetEditEngine() to retrieve field content.
64 If NULL, a static mutex-guarded ScFieldEditEngine is used that
65 is not capable of resolving document specific fields; avoid.
67 SC_DLLPUBLIC static OUString GetString( const EditTextObject& rEditText, const ScDocument* pDoc );
69 static std::unique_ptr<EditTextObject> CreateURLObjectFromURL(
70 ScDocument& rDoc, const OUString& rURL, const OUString& rText );
72 static void RemoveCharAttribs( EditTextObject& rEditText, const ScPatternAttr& rAttr );
74 static std::unique_ptr<EditTextObject> Clone( const EditTextObject& rSrc, ScDocument& rDestDoc );
76 static OUString GetCellFieldValue(
77 const SvxFieldData& rFieldData, const ScDocument* pDoc, boost::optional<Color>* ppTextColor );
79 public:
80 ScEditUtil( ScDocument* pDocument, SCCOL nX, SCROW nY, SCTAB nZ,
81 const Point& rScrPosPixel,
82 OutputDevice* pDevice, double nScaleX, double nScaleY,
83 const Fraction& rX, const Fraction& rY );
85 tools::Rectangle GetEditArea( const ScPatternAttr* pPattern, bool bForceToTop );
88 class ScEditAttrTester
90 ScEditEngineDefaulter* pEngine;
91 std::unique_ptr<SfxItemSet> pEditAttrs;
92 bool bNeedsObject;
93 bool bNeedsCellAttr;
95 public:
96 ScEditAttrTester( ScEditEngineDefaulter* pEng );
97 ~ScEditAttrTester();
99 bool NeedsObject() const { return bNeedsObject; }
100 bool NeedsCellAttr() const { return bNeedsCellAttr; }
101 const SfxItemSet& GetAttribs() const { return *pEditAttrs; }
104 // construct pool before constructing EditEngine, destroy pool after EditEngine
105 class ScEnginePoolHelper
107 protected:
108 SfxItemPool* const pEnginePool;
109 SfxItemSet* pDefaults;
110 bool const bDeleteEnginePool;
111 bool bDeleteDefaults;
113 ScEnginePoolHelper( SfxItemPool* pEnginePool, bool bDeleteEnginePool );
114 ScEnginePoolHelper( const ScEnginePoolHelper& rOrg );
115 virtual ~ScEnginePoolHelper();
118 class SC_DLLPUBLIC ScEditEngineDefaulter : public ScEnginePoolHelper, public EditEngine
120 private:
121 using EditEngine::SetText;
123 public:
124 /// bDeleteEnginePool: Engine becomes the owner of the pool
125 /// and deletes it on destruction
126 ScEditEngineDefaulter( SfxItemPool* pEnginePool,
127 bool bDeleteEnginePool = false );
128 /// If rOrg.bDeleteEnginePool: pool gets cloned and will be
129 /// deleted on destruction. Defaults are not set.
130 ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg );
131 virtual ~ScEditEngineDefaulter() override;
133 /// Creates a copy of SfxItemSet if bRememberCopy set
134 void SetDefaults( const SfxItemSet& rDefaults, bool bRememberCopy = true );
136 /// Becomes the owner of the SfxItemSet
137 void SetDefaults( std::unique_ptr<SfxItemSet> pDefaults );
139 /// Set the item in the default ItemSet which is created
140 /// if it doesn't exist yet.
141 /// The default ItemSet is then applied to each paragraph.
142 void SetDefaultItem( const SfxPoolItem& rItem );
144 /// Returns the stored defaults, used to find non-default character attributes
145 const SfxItemSet& GetDefaults();
147 /// Overwritten method to be able to apply defaults already set
148 void SetText( const EditTextObject& rTextObject );
149 /// Current defaults are not applied, new defaults are applied
150 void SetTextNewDefaults( const EditTextObject& rTextObject,
151 const SfxItemSet& rDefaults, bool bRememberCopy = true );
152 /// Current defaults are not applied, new defaults are applied
153 void SetTextNewDefaults( const EditTextObject& rTextObject,
154 std::unique_ptr<SfxItemSet> pDefaults );
156 /// Overwritten method to be able to apply defaults already set
157 void SetText( const OUString& rText );
158 /// Current defaults are not applied, new defaults are applied
159 void SetTextNewDefaults( const OUString& rText,
160 const SfxItemSet& rDefaults );
161 /// Current defaults are not applied, new defaults are applied
162 void SetTextNewDefaults( const OUString& rText,
163 std::unique_ptr<SfxItemSet> pDefaults );
165 /// Paragraph attributes that are not defaults are copied to
166 /// character attributes and all paragraph attributes reset
167 void RemoveParaAttribs();
169 /// Re-apply existing defaults if set, same as in SetText,
170 /// but without EnableUndo/SetUpdateMode.
171 void RepeatDefaults();
174 // for field commands (or just fields?) in a table
175 class SC_DLLPUBLIC ScFieldEditEngine : public ScEditEngineDefaulter
177 private:
178 ScDocument* const mpDoc;
179 bool bExecuteURL;
181 public:
182 ScFieldEditEngine(
183 ScDocument* pDoc, SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool = nullptr,
184 bool bDeleteEnginePool = false);
186 void SetExecuteURL(bool bSet) { bExecuteURL = bSet; }
188 virtual void FieldClicked( const SvxFieldItem& rField, sal_Int32, sal_Int32 ) override;
189 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rTxtColor, boost::optional<Color>& rFldColor ) override;
192 // 1/100 mm
193 class SC_DLLPUBLIC ScTabEditEngine : public ScFieldEditEngine
195 private:
196 void Init(const ScPatternAttr& rPattern);
197 public:
198 ScTabEditEngine( ScDocument* pDoc ); // Default
199 ScTabEditEngine(const ScPatternAttr& rPattern,
200 SfxItemPool *pEngineItemPool, ScDocument *pDoc,
201 SfxItemPool* pTextObjectPool = nullptr );
204 struct ScHeaderFieldData
206 OUString aTitle; // title or file name (if no title)
207 OUString aLongDocName; // path and file name
208 OUString aShortDocName; // pure file name
209 OUString aTabName;
210 DateTime aDateTime;
211 long nPageNo;
212 long nTotalPages;
213 SvxNumType eNumType;
215 ScHeaderFieldData();
218 // for headers/footers with fields
219 class SC_DLLPUBLIC ScHeaderEditEngine : public ScEditEngineDefaulter
221 private:
222 ScHeaderFieldData aData;
224 public:
225 ScHeaderEditEngine( SfxItemPool* pEnginePool );
226 virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rTxtColor, boost::optional<Color>& rFldColor ) override;
228 void SetNumType(SvxNumType eNew) { aData.eNumType = eNew; }
229 void SetData(const ScHeaderFieldData& rNew) { aData = rNew; }
232 // for Note text objects.
233 class ScNoteEditEngine : public ScEditEngineDefaulter
236 public:
237 ScNoteEditEngine( SfxItemPool* pEnginePool, SfxItemPool* pTextObjectPool );
241 // SvxFieldData derivations were moved to Svx (comment can be deleted?)
243 #endif
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */