Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / inc / patattr.hxx
blobe4b149516c0f2390c98699d60bf66638d126caad
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 #pragma once
22 #include <optional>
24 #include <svl/setitem.hxx>
25 #include <svl/itemset.hxx>
26 #include <svl/languageoptions.hxx>
27 #include <tools/degree.hxx>
28 #include <editeng/svxenum.hxx>
29 #include "scdllapi.h"
30 #include "fonthelper.hxx"
32 namespace vcl { class Font; }
33 namespace model { class ComplexColor; }
34 struct ScInterpreterContext;
35 class OutputDevice;
36 class Fraction;
37 class ScStyleSheet;
38 class SvNumberFormatter;
39 class ScDocument;
40 enum class ScRotateDir : sal_uInt8;
42 /// how to treat COL_AUTO in GetFont:
44 enum class ScAutoFontColorMode
46 Raw, ///< COL_AUTO is returned
47 Print, ///< black or white, depending on background
48 Display, ///< from style settings, or black/white if needed
49 IgnoreFont, ///< like DISPLAY, but ignore stored font color (assume COL_AUTO)
50 IgnoreBack, ///< like DISPLAY, but ignore stored background color (use configured color)
51 IgnoreAll ///< like DISPLAY, but ignore stored font and background colors
54 class SC_DLLPUBLIC ScPatternAttr final : public SfxSetItem
56 std::optional<OUString> pName;
57 mutable std::optional<bool> mxVisible;
58 ScStyleSheet* pStyle;
59 sal_uInt64 mnPAKey;
60 public:
61 ScPatternAttr(SfxItemSet&& pItemSet, const OUString& rStyleName);
62 ScPatternAttr(SfxItemSet&& pItemSet);
63 ScPatternAttr(SfxItemPool* pItemPool);
64 ScPatternAttr(const ScPatternAttr& rPatternAttr);
66 virtual ScPatternAttr* Clone( SfxItemPool *pPool = nullptr ) const override;
68 virtual bool operator==(const SfxPoolItem& rCmp) const override;
70 const SfxPoolItem& GetItem( sal_uInt16 nWhichP ) const
71 { return GetItemSet().Get(nWhichP); }
72 template<class T> const T& GetItem( TypedWhichId<T> nWhich ) const
73 { return static_cast<const T&>(GetItem(sal_uInt16(nWhich))); }
75 static const SfxPoolItem& GetItem( sal_uInt16 nWhich, const SfxItemSet& rItemSet, const SfxItemSet* pCondSet );
76 template<class T> static const T& GetItem( TypedWhichId<T> nWhich, const SfxItemSet& rItemSet, const SfxItemSet* pCondSet )
77 { return static_cast<const T&>(GetItem(sal_uInt16(nWhich), rItemSet, pCondSet)); }
79 const SfxPoolItem& GetItem( sal_uInt16 nWhich, const SfxItemSet* pCondSet ) const;
80 template<class T> const T& GetItem( TypedWhichId<T> nWhich, const SfxItemSet* pCondSet ) const
81 { return static_cast<const T&>(GetItem(sal_uInt16(nWhich), pCondSet)); }
83 /// @param pWhich are no ranges, but single IDs, 0-terminated
84 bool HasItemsSet( const sal_uInt16* pWhich ) const;
85 void ClearItems( const sal_uInt16* pWhich );
87 void DeleteUnchanged( const ScPatternAttr* pOldAttrs );
89 static SvxCellOrientation GetCellOrientation( const SfxItemSet& rItemSet, const SfxItemSet* pCondSet );
90 SvxCellOrientation GetCellOrientation( const SfxItemSet* pCondSet = nullptr ) const;
92 /** Static helper function to fill a font object from the passed item set. */
93 static void fillFontOnly(vcl::Font& rFont, const SfxItemSet& rItemSet,
94 const OutputDevice* pOutDev = nullptr,
95 const Fraction* pScale = nullptr,
96 const SfxItemSet* pCondSet = nullptr,
97 SvtScriptType nScript = SvtScriptType::NONE);
99 static void fillFont( vcl::Font& rFont, const SfxItemSet& rItemSet,
100 ScAutoFontColorMode eAutoMode,
101 const OutputDevice* pOutDev = nullptr,
102 const Fraction* pScale = nullptr,
103 const SfxItemSet* pCondSet = nullptr,
104 SvtScriptType nScript = SvtScriptType::NONE, const Color* pBackConfigColor = nullptr,
105 const Color* pTextConfigColor = nullptr);
107 static void fillColor(model::ComplexColor& rComplexColor,
108 const SfxItemSet& rItemSet,
109 ScAutoFontColorMode eAutoMode,
110 const SfxItemSet* pCondSet = nullptr,
111 const Color* pBackConfigColor = nullptr,
112 const Color* pTextConfigColor = nullptr);
115 static ScDxfFont GetDxfFont(const SfxItemSet& rSet, SvtScriptType nScript);
117 void fillColor(model::ComplexColor& rComplexColor,
118 ScAutoFontColorMode eAutoMode,
119 const SfxItemSet* pCondSet = nullptr,
120 const Color* pBackConfigColor = nullptr,
121 const Color* pTextConfigColor = nullptr) const
123 fillColor(rComplexColor, GetItemSet(), eAutoMode, pCondSet, pBackConfigColor, pTextConfigColor);
126 void fillFontOnly(vcl::Font& rFont,
127 const OutputDevice* pOutDev = nullptr,
128 const Fraction* pScale = nullptr,
129 const SfxItemSet* pCondSet = nullptr,
130 SvtScriptType nScript = SvtScriptType::NONE) const
132 fillFontOnly(rFont, GetItemSet(), pOutDev, pScale, pCondSet, nScript);
135 /** Fills a font object from the own item set. */
136 void fillFont(vcl::Font& rFont, ScAutoFontColorMode eAutoMode,
137 const OutputDevice* pOutDev = nullptr,
138 const Fraction* pScale = nullptr,
139 const SfxItemSet* pCondSet = nullptr,
140 SvtScriptType nScript = SvtScriptType::NONE,
141 const Color* pBackConfigColor = nullptr,
142 const Color* pTextConfigColor = nullptr) const
144 fillFont(rFont, GetItemSet(), eAutoMode, pOutDev, pScale, pCondSet, nScript, pBackConfigColor, pTextConfigColor);
147 /** Converts all Calc items contained in rSrcSet to edit engine items and puts them into rEditSet. */
148 static void FillToEditItemSet( SfxItemSet& rEditSet, const SfxItemSet& rSrcSet, const SfxItemSet* pCondSet = nullptr );
149 /** Converts all Calc items contained in the own item set to edit engine items and puts them into pEditSet. */
150 void FillEditItemSet( SfxItemSet* pEditSet, const SfxItemSet* pCondSet = nullptr ) const;
152 /** Converts all edit engine items contained in rEditSet to Calc items and puts them into rDestSet. */
153 static void GetFromEditItemSet( SfxItemSet& rDestSet, const SfxItemSet& rEditSet );
154 /** Converts all edit engine items contained in pEditSet to Calc items and puts them into the own item set. */
155 void GetFromEditItemSet( const SfxItemSet* pEditSet );
157 void FillEditParaItems( SfxItemSet* pSet ) const;
159 ScPatternAttr* PutInPool( ScDocument* pDestDoc, ScDocument* pSrcDoc ) const;
161 void SetStyleSheet(ScStyleSheet* pNewStyle, bool bClearDirectFormat = true);
162 const ScStyleSheet* GetStyleSheet() const { return pStyle; }
163 const OUString* GetStyleName() const;
164 void UpdateStyleSheet(const ScDocument& rDoc);
165 void StyleToName();
167 bool IsVisible() const;
168 bool IsVisibleEqual( const ScPatternAttr& rOther ) const;
170 /** If font is an old symbol font StarBats/StarMath
171 with text encoding RTL_TEXTENC_SYMBOL */
172 bool IsSymbolFont() const;
174 sal_uInt32 GetNumberFormat( SvNumberFormatter* ) const;
175 sal_uInt32 GetNumberFormat( const ScInterpreterContext& rContext ) const;
176 sal_uInt32 GetNumberFormat( SvNumberFormatter* pFormatter,
177 const SfxItemSet* pCondSet ) const;
179 Degree100 GetRotateVal( const SfxItemSet* pCondSet ) const;
180 ScRotateDir GetRotateDir( const SfxItemSet* pCondSet ) const;
182 void SetPAKey(sal_uInt64 nKey);
183 sal_uInt64 GetPAKey() const;
185 // TODO: tdf#135215: This is a band-aid to detect changes and invalidate the hash,
186 // a proper way would be probably to override SfxItemSet::Changed(), but 6cb400f41df0dd10
187 // hardcoded SfxSetItem to contain SfxItemSet.
188 SfxItemSet& GetItemSet() { mxVisible.reset(); return SfxSetItem::GetItemSet(); }
189 using SfxSetItem::GetItemSet;
191 private:
192 bool CalcVisible() const;
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */