LibreOffice Module sc (master) 1
patattr.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <optional>
23
24#include <svl/setitem.hxx>
25#include <svl/itemset.hxx>
27#include <tools/degree.hxx>
28#include <editeng/svxenum.hxx>
29#include "scdllapi.h"
30#include "fonthelper.hxx"
31
32namespace vcl { class Font; }
33class OutputDevice;
34class Fraction;
35class ScStyleSheet;
37class ScDocument;
38enum class ScRotateDir : sal_uInt8;
39
41
43{
51};
52
54{
55 std::optional<OUString> pName;
56 mutable std::optional<size_t> mxHashCode;
58 sal_uInt64 mnKey;
59public:
60 ScPatternAttr(SfxItemSet&& pItemSet, const OUString& rStyleName);
61 ScPatternAttr(SfxItemSet&& pItemSet);
62 ScPatternAttr(SfxItemPool* pItemPool);
63 ScPatternAttr(const ScPatternAttr& rPatternAttr);
64
65 virtual ScPatternAttr* Clone( SfxItemPool *pPool = nullptr ) const override;
66
67 virtual bool operator==(const SfxPoolItem& rCmp) const override;
68 // Class cannot be IsSortable() because it's mutable, implement at least Lookup().
69 virtual bool HasLookup() const override { return true; }
70 virtual lookup_iterator Lookup(lookup_iterator begin, lookup_iterator end ) const override;
71
72 const SfxPoolItem& GetItem( sal_uInt16 nWhichP ) const
73 { return GetItemSet().Get(nWhichP); }
74 template<class T> const T& GetItem( TypedWhichId<T> nWhich ) const
75 { return static_cast<const T&>(GetItem(sal_uInt16(nWhich))); }
76
77 static const SfxPoolItem& GetItem( sal_uInt16 nWhich, const SfxItemSet& rItemSet, const SfxItemSet* pCondSet );
78 template<class T> static const T& GetItem( TypedWhichId<T> nWhich, const SfxItemSet& rItemSet, const SfxItemSet* pCondSet )
79 { return static_cast<const T&>(GetItem(sal_uInt16(nWhich), rItemSet, pCondSet)); }
80
81 const SfxPoolItem& GetItem( sal_uInt16 nWhich, const SfxItemSet* pCondSet ) const;
82 template<class T> const T& GetItem( TypedWhichId<T> nWhich, const SfxItemSet* pCondSet ) const
83 { return static_cast<const T&>(GetItem(sal_uInt16(nWhich), pCondSet)); }
84
86 bool HasItemsSet( const sal_uInt16* pWhich ) const;
87 void ClearItems( const sal_uInt16* pWhich );
88
89 void DeleteUnchanged( const ScPatternAttr* pOldAttrs );
90
91 static SvxCellOrientation GetCellOrientation( const SfxItemSet& rItemSet, const SfxItemSet* pCondSet );
92 SvxCellOrientation GetCellOrientation( const SfxItemSet* pCondSet = nullptr ) const;
93
95 static void GetFont( vcl::Font& rFont, const SfxItemSet& rItemSet,
96 ScAutoFontColorMode eAutoMode,
97 const OutputDevice* pOutDev = nullptr,
98 const Fraction* pScale = nullptr,
99 const SfxItemSet* pCondSet = nullptr,
100 SvtScriptType nScript = SvtScriptType::NONE, const Color* pBackConfigColor = nullptr,
101 const Color* pTextConfigColor = nullptr );
102
103 static ScDxfFont GetDxfFont(const SfxItemSet& rSet, SvtScriptType nScript);
105 void GetFont( vcl::Font& rFont, ScAutoFontColorMode eAutoMode,
106 const OutputDevice* pOutDev = nullptr,
107 const Fraction* pScale = nullptr,
108 const SfxItemSet* pCondSet = nullptr,
109 SvtScriptType nScript = SvtScriptType::NONE,
110 const Color* pBackConfigColor = nullptr,
111 const Color* pTextConfigColor = nullptr ) const;
112
114 static void FillToEditItemSet( SfxItemSet& rEditSet, const SfxItemSet& rSrcSet, const SfxItemSet* pCondSet = nullptr );
116 void FillEditItemSet( SfxItemSet* pEditSet, const SfxItemSet* pCondSet = nullptr ) const;
117
119 static void GetFromEditItemSet( SfxItemSet& rDestSet, const SfxItemSet& rEditSet );
121 void GetFromEditItemSet( const SfxItemSet* pEditSet );
122
123 void FillEditParaItems( SfxItemSet* pSet ) const;
124
125 ScPatternAttr* PutInPool( ScDocument* pDestDoc, ScDocument* pSrcDoc ) const;
126
127 void SetStyleSheet(ScStyleSheet* pNewStyle, bool bClearDirectFormat = true);
128 const ScStyleSheet* GetStyleSheet() const { return pStyle; }
129 const OUString* GetStyleName() const;
130 void UpdateStyleSheet(const ScDocument& rDoc);
131 void StyleToName();
132
133 bool IsVisible() const;
134 bool IsVisibleEqual( const ScPatternAttr& rOther ) const;
135
138 bool IsSymbolFont() const;
139
140 sal_uInt32 GetNumberFormat( SvNumberFormatter* ) const;
141 sal_uInt32 GetNumberFormat( SvNumberFormatter* pFormatter,
142 const SfxItemSet* pCondSet ) const;
143
144 Degree100 GetRotateVal( const SfxItemSet* pCondSet ) const;
145 ScRotateDir GetRotateDir( const SfxItemSet* pCondSet ) const;
146
147 void SetKey(sal_uInt64 nKey);
148 sal_uInt64 GetKey() const;
149
150 static std::optional<bool> FastEqualPatternSets( const SfxItemSet& rSet1, const SfxItemSet& rSet2 );
151
152 // TODO: tdf#135215: This is a band-aid to detect changes and invalidate the hash,
153 // a proper way would be probably to override SfxItemSet::Changed(), but 6cb400f41df0dd10
154 // hardcoded SfxSetItem to contain SfxItemSet.
155 SfxItemSet& GetItemSet() { mxHashCode.reset(); return SfxSetItem::GetItemSet(); }
157
158private:
159 void CalcHashCode() const;
160};
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt64 mnKey
Definition: patattr.hxx:58
const T & GetItem(TypedWhichId< T > nWhich, const SfxItemSet *pCondSet) const
Definition: patattr.hxx:82
std::optional< size_t > mxHashCode
Definition: patattr.hxx:56
ScStyleSheet * pStyle
Definition: patattr.hxx:57
std::optional< OUString > pName
Definition: patattr.hxx:55
const ScStyleSheet * GetStyleSheet() const
Definition: patattr.hxx:128
virtual bool HasLookup() const override
Definition: patattr.hxx:69
const T & GetItem(TypedWhichId< T > nWhich) const
Definition: patattr.hxx:74
SfxItemSet & GetItemSet()
Definition: patattr.hxx:155
const SfxPoolItem & GetItem(sal_uInt16 nWhichP) const
Definition: patattr.hxx:72
static const T & GetItem(TypedWhichId< T > nWhich, const SfxItemSet &rItemSet, const SfxItemSet *pCondSet)
Definition: patattr.hxx:78
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
virtual lookup_iterator Lookup(lookup_iterator, lookup_iterator end) const
virtual bool operator==(const SfxPoolItem &) const override
const SfxItemSet & GetItemSet() const
virtual SfxSetItem * Clone(SfxItemPool *pPool=nullptr) const override=0
ScRotateDir
Definition: fillinfo.hxx:40
SvtScriptType
const SfxPoolItem * GetItem(const SwTextAttr &rAttr, sal_uInt16 nWhich)
vcl::Font GetFont(vcl::Font const &rFont, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
ScAutoFontColorMode
how to treat COL_AUTO in GetFont:
Definition: patattr.hxx:43
@ SC_AUTOCOL_BLACK
always use black
Definition: patattr.hxx:45
@ SC_AUTOCOL_IGNOREBACK
like DISPLAY, but ignore stored background color (use configured color)
Definition: patattr.hxx:49
@ SC_AUTOCOL_DISPLAY
from style settings, or black/white if needed
Definition: patattr.hxx:47
@ SC_AUTOCOL_RAW
COL_AUTO is returned.
Definition: patattr.hxx:44
@ SC_AUTOCOL_IGNOREFONT
like DISPLAY, but ignore stored font color (assume COL_AUTO)
Definition: patattr.hxx:48
@ SC_AUTOCOL_PRINT
black or white, depending on background
Definition: patattr.hxx:46
@ SC_AUTOCOL_IGNOREALL
like DISPLAY, but ignore stored font and background colors
Definition: patattr.hxx:50
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
SvxCellOrientation
unsigned char sal_uInt8