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 .
24 #include <svl/itemset.hxx>
25 #include <svl/languageoptions.hxx>
26 #include <tools/degree.hxx>
27 #include <editeng/svxenum.hxx>
29 #include "fonthelper.hxx"
30 #include "scitems.hxx"
34 namespace vcl
{ class Font
; }
35 namespace model
{ class ComplexColor
; }
36 struct ScInterpreterContext
;
40 class SvNumberFormatter
;
42 enum class ScRotateDir
: sal_uInt8
;
44 /// how to treat COL_AUTO in GetFont:
46 enum class ScAutoFontColorMode
48 Raw
, ///< COL_AUTO is returned
49 Print
, ///< black or white, depending on background
50 Display
, ///< from style settings, or black/white if needed
51 IgnoreFont
, ///< like DISPLAY, but ignore stored font color (assume COL_AUTO)
52 IgnoreBack
, ///< like DISPLAY, but ignore stored background color (use configured color)
53 IgnoreAll
///< like DISPLAY, but ignore stored font and background colors
58 class SC_DLLPUBLIC CellAttributeHelper final
60 friend class CellAttributeHolder
;
62 // Data structure chosen so that
63 // (a) we can find by name
64 // (b) we can erase quickly, by using name and pointer.
65 // so we sort the set first by name, and then by pointer.
66 struct RegisteredAttrSetLess
68 bool operator()(const ScPatternAttr
* lhs
, const ScPatternAttr
* rhs
) const;
69 // so we can search in std::set without a ScPatternAttr
70 using is_transparent
= void;
71 bool operator()(const ScPatternAttr
* lhs
, const OUString
* rhs
) const;
72 bool operator()(const OUString
* lhs
, const ScPatternAttr
* rhs
) const;
74 typedef std::set
<const ScPatternAttr
*, RegisteredAttrSetLess
> RegisteredAttrSet
;
76 SfxItemPool
& mrSfxItemPool
;
77 mutable ScPatternAttr
* mpDefaultCellAttribute
;
78 mutable RegisteredAttrSet maRegisteredCellAttributes
;
79 mutable const ScPatternAttr
* mpLastHit
;
80 mutable sal_uInt64 mnCurrentMaxKey
;
82 // only to be used from CellAttributeHolder, so private
83 const ScPatternAttr
* registerAndCheck(const ScPatternAttr
& rCandidate
, bool bPassingOwnership
) const;
84 void doUnregister(const ScPatternAttr
& rCandidate
);
87 explicit CellAttributeHelper(SfxItemPool
& rSfxItemPool
);
88 ~CellAttributeHelper();
90 const ScPatternAttr
& getDefaultCellAttribute() const;
91 SfxItemPool
& GetPool() const { return mrSfxItemPool
; }
93 void CellStyleDeleted(const ScStyleSheet
& rStyle
);
94 void CellStyleCreated(ScDocument
& rDoc
, const OUString
& rName
);
95 void UpdateAllStyleSheets(ScDocument
& rDoc
);
96 void AllStylesToNames();
97 void ReIndexRegistered();
100 class SC_DLLPUBLIC CellAttributeHolder final
102 const ScPatternAttr
* mpScPatternAttr
;
105 CellAttributeHolder() : mpScPatternAttr(nullptr) {}
106 CellAttributeHolder(const ScPatternAttr
* pScPatternAttr
, bool bPassingOwnership
= false);
107 CellAttributeHolder(const CellAttributeHolder
& rHolder
);
108 CellAttributeHolder(CellAttributeHolder
&& rHolder
) noexcept
109 : mpScPatternAttr(rHolder
.mpScPatternAttr
)
110 { rHolder
.mpScPatternAttr
= nullptr; }
111 ~CellAttributeHolder();
113 CellAttributeHolder
& operator=(const CellAttributeHolder
& rHolder
);
114 CellAttributeHolder
& operator=(CellAttributeHolder
&& rHolder
) { std::swap(mpScPatternAttr
, rHolder
.mpScPatternAttr
); return *this; }
115 bool operator==(const CellAttributeHolder
& rHolder
) const;
117 const ScPatternAttr
* getScPatternAttr() const { return mpScPatternAttr
; }
118 void setScPatternAttr(const ScPatternAttr
* pNew
, bool bPassingOwnership
= false);
120 bool operator!() const { return nullptr == mpScPatternAttr
; }
121 explicit operator bool() const { return nullptr != mpScPatternAttr
; }
123 // version that allows nullptrs
124 static bool areSame(const CellAttributeHolder
* p1
, const CellAttributeHolder
* p2
);
127 class SAL_DLLPUBLIC_RTTI ScPatternAttr final
129 friend class CellAttributeHelper
;
131 SfxItemSet maLocalSfxItemSet
;
132 std::optional
<OUString
> moName
;
133 mutable std::optional
<bool> mxVisible
;
134 mutable std::optional
<sal_uInt32
> mxNumberFormatKey
;
135 mutable std::optional
<LanguageType
> mxLanguageType
;
136 ScStyleSheet
* pStyle
;
137 CellAttributeHelper
* pCellAttributeHelper
;
139 mutable size_t mnRefCount
;
141 sal_uInt32 m_nSerialNumber
;
146 SC_DLLPUBLIC
ScPatternAttr(CellAttributeHelper
& rHelper
, const SfxItemSet
* pItemSet
= nullptr, const OUString
* pStyleName
= nullptr);
147 SC_DLLPUBLIC
ScPatternAttr(const ScPatternAttr
& rPatternAttr
);
148 SC_DLLPUBLIC
~ScPatternAttr();
150 bool operator==(const ScPatternAttr
& rCmp
) const;
152 // version that allows nullptrs
153 SC_DLLPUBLIC
static bool areSame(const ScPatternAttr
* pItem1
, const ScPatternAttr
* pItem2
);
154 bool isRegistered() const { return 0 != mnRefCount
; }
155 bool isDefault() const { return this == &pCellAttributeHelper
->getDefaultCellAttribute(); }
156 CellAttributeHelper
& getCellAttributeHelper() const { return *pCellAttributeHelper
; }
158 const SfxItemSet
& GetItemSet() const { return maLocalSfxItemSet
; }
159 SfxItemSet
& GetItemSet() { return maLocalSfxItemSet
; }
161 const SfxPoolItem
& GetItem(sal_uInt16 nWhichP
) const
163 return maLocalSfxItemSet
.Get(nWhichP
, true); // GetByOffset used bSrchInParent==true
165 template<class T
> const T
& GetItem( TypedWhichId
<T
> nWhich
) const
166 { return static_cast<const T
&>(GetItem(sal_uInt16(nWhich
))); }
167 static const SfxPoolItem
& GetItem(sal_uInt16 nWhich
, const SfxItemSet
& rItemSet
, const SfxItemSet
* pCondSet
);
168 template<class T
> static const T
& GetItem(TypedWhichId
<T
> nWhich
, const SfxItemSet
& rItemSet
, const SfxItemSet
* pCondSet
)
169 { return static_cast<const T
&>(GetItem(sal_uInt16(nWhich
), rItemSet
, pCondSet
)); }
170 SC_DLLPUBLIC
const SfxPoolItem
& GetItem( sal_uInt16 nWhich
, const SfxItemSet
* pCondSet
) const;
171 template<class T
> const T
& GetItem(TypedWhichId
<T
> nWhich
, const SfxItemSet
* pCondSet
) const
172 { return static_cast<const T
&>(GetItem(sal_uInt16(nWhich
), pCondSet
)); }
174 /// @param pWhich are no ranges, but single IDs, 0-terminated
175 bool HasItemsSet( const sal_uInt16
* pWhich
) const;
176 void ClearItems( const sal_uInt16
* pWhich
);
177 void DeleteUnchanged( const ScPatternAttr
* pOldAttrs
);
179 static SvxCellOrientation
GetCellOrientation( const SfxItemSet
& rItemSet
, const SfxItemSet
* pCondSet
);
180 SvxCellOrientation
GetCellOrientation( const SfxItemSet
* pCondSet
= nullptr ) const;
182 /** Static helper function to fill a font object from the passed item set. */
183 SC_DLLPUBLIC
static void fillFontOnly(vcl::Font
& rFont
, const SfxItemSet
& rItemSet
,
184 const OutputDevice
* pOutDev
= nullptr,
185 const Fraction
* pScale
= nullptr,
186 const SfxItemSet
* pCondSet
= nullptr,
187 SvtScriptType nScript
= SvtScriptType::NONE
);
189 static void fillFont( vcl::Font
& rFont
, const SfxItemSet
& rItemSet
,
190 ScAutoFontColorMode eAutoMode
,
191 const OutputDevice
* pOutDev
= nullptr,
192 const Fraction
* pScale
= nullptr,
193 const SfxItemSet
* pCondSet
= nullptr,
194 SvtScriptType nScript
= SvtScriptType::NONE
, const Color
* pBackConfigColor
= nullptr,
195 const Color
* pTextConfigColor
= nullptr);
197 SC_DLLPUBLIC
static void fillColor(model::ComplexColor
& rComplexColor
,
198 const SfxItemSet
& rItemSet
,
199 ScAutoFontColorMode eAutoMode
,
200 const SfxItemSet
* pCondSet
= nullptr,
201 const Color
* pBackConfigColor
= nullptr,
202 const Color
* pTextConfigColor
= nullptr);
205 SC_DLLPUBLIC
static ScDxfFont
GetDxfFont(const SfxItemSet
& rSet
, SvtScriptType nScript
);
207 void fillColor(model::ComplexColor
& rComplexColor
,
208 ScAutoFontColorMode eAutoMode
,
209 const SfxItemSet
* pCondSet
= nullptr,
210 const Color
* pBackConfigColor
= nullptr,
211 const Color
* pTextConfigColor
= nullptr) const
213 fillColor(rComplexColor
, maLocalSfxItemSet
, eAutoMode
, pCondSet
, pBackConfigColor
, pTextConfigColor
);
216 void fillFontOnly(vcl::Font
& rFont
,
217 const OutputDevice
* pOutDev
= nullptr,
218 const Fraction
* pScale
= nullptr,
219 const SfxItemSet
* pCondSet
= nullptr,
220 SvtScriptType nScript
= SvtScriptType::NONE
) const
222 fillFontOnly(rFont
, maLocalSfxItemSet
, pOutDev
, pScale
, pCondSet
, nScript
);
225 /** Fills a font object from the own item set. */
226 void fillFont(vcl::Font
& rFont
, ScAutoFontColorMode eAutoMode
,
227 const OutputDevice
* pOutDev
= nullptr,
228 const Fraction
* pScale
= nullptr,
229 const SfxItemSet
* pCondSet
= nullptr,
230 SvtScriptType nScript
= SvtScriptType::NONE
,
231 const Color
* pBackConfigColor
= nullptr,
232 const Color
* pTextConfigColor
= nullptr) const
234 fillFont(rFont
, maLocalSfxItemSet
, eAutoMode
, pOutDev
, pScale
, pCondSet
, nScript
, pBackConfigColor
, pTextConfigColor
);
237 /** Converts all Calc items contained in rSrcSet to edit engine items and puts them into rEditSet. */
238 SC_DLLPUBLIC
static void FillToEditItemSet( SfxItemSet
& rEditSet
, const SfxItemSet
& rSrcSet
, const SfxItemSet
* pCondSet
= nullptr );
239 /** Converts all Calc items contained in the own item set to edit engine items and puts them into pEditSet. */
240 SC_DLLPUBLIC
void FillEditItemSet( SfxItemSet
* pEditSet
, const SfxItemSet
* pCondSet
= nullptr ) const;
242 /** Converts all edit engine items contained in rEditSet to Calc items and puts them into rDestSet. */
243 SC_DLLPUBLIC
static void GetFromEditItemSet( SfxItemSet
& rDestSet
, const SfxItemSet
& rEditSet
);
244 /** Converts all edit engine items contained in pEditSet to Calc items and puts them into the own item set. */
245 SC_DLLPUBLIC
void GetFromEditItemSet( const SfxItemSet
* pEditSet
);
247 void FillEditParaItems( SfxItemSet
* pSet
) const;
249 CellAttributeHolder
MigrateToDocument( ScDocument
* pDestDoc
, ScDocument
* pSrcDoc
) const;
251 SC_DLLPUBLIC
void SetStyleSheet(ScStyleSheet
* pNewStyle
, bool bClearDirectFormat
= true);
252 const ScStyleSheet
* GetStyleSheet() const { return pStyle
; }
253 SC_DLLPUBLIC
const OUString
* GetStyleName() const;
254 bool UpdateStyleSheet(const ScDocument
& rDoc
);
257 bool IsVisible() const;
258 bool IsVisibleEqual( const ScPatternAttr
& rOther
) const;
260 /** If font is an old symbol font StarBats/StarMath
261 with text encoding RTL_TEXTENC_SYMBOL */
262 bool IsSymbolFont() const;
264 SC_DLLPUBLIC sal_uInt32
GetNumberFormat( SvNumberFormatter
* ) const;
265 sal_uInt32
GetNumberFormat( const ScInterpreterContext
& rContext
) const;
266 sal_uInt32
GetNumberFormat( SvNumberFormatter
* pFormatter
,
267 const SfxItemSet
* pCondSet
) const;
268 SC_DLLPUBLIC sal_uInt32
GetNumberFormat( const ScInterpreterContext
& rContext
,
269 const SfxItemSet
* pCondSet
) const;
271 Degree100
GetRotateVal( const SfxItemSet
* pCondSet
) const;
272 ScRotateDir
GetRotateDir( const SfxItemSet
* pCondSet
) const;
274 void SetPAKey(sal_uInt64 nKey
);
275 sal_uInt64
GetPAKey() const;
278 bool CalcVisible() const;
279 sal_uInt32
GetNumberFormatKey() const;
280 LanguageType
GetLanguageType() const;
281 void InvalidateCaches();
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */