Prepare for removal of non-const operator[] from Sequence in drawinglayer
[LibreOffice.git] / sc / inc / autoform.hxx
blob15df248510d5ff7eec3bf7d8083f1555b0ffb54f
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 /*************************************************************************
23 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
25 The structure of auto formatting should not be changed. It is used
26 by various code of Writer and Calc. If a change is necessary, the
27 source code of both applications must be changed!
29 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
30 **************************************************************************/
32 #include <svl/poolitem.hxx>
33 #include <svx/autoformathelper.hxx>
35 #include "scdllapi.h"
36 #include "zforauto.hxx"
38 #include <array>
39 #include <memory>
40 #include <map>
41 #include <climits>
43 class ScDocument;
45 /**
46 A binary blob of writer-specific data. This data typically consists of types that are
47 unavailable to Calc (e.g. SwFmtVertOrient), or that Calc doesn't care about.
49 @remarks Note that in autoformat versions prior to AUTOFORMAT_DATA_ID_31005, Calc
50 logic handled and stored several writer-specific items (such as ScAutoFormatDataField::aAdjust).
51 That logic was preserved. From _31005 onward, writer-specific data should be handled by
52 blobs to avoid needlessly complicating the Calc logic.
54 struct AutoFormatSwBlob
56 std::unique_ptr<sal_uInt8[]> pData;
57 std::size_t size;
59 AutoFormatSwBlob() : size(0)
62 AutoFormatSwBlob(const AutoFormatSwBlob&) = delete;
63 const AutoFormatSwBlob& operator=(const AutoFormatSwBlob&) = delete;
65 void Reset()
67 pData.reset();
68 size = 0;
72 /// Struct with version numbers of the Items
73 struct ScAfVersions : public AutoFormatVersions
75 public:
76 AutoFormatSwBlob swVersions;
78 ScAfVersions();
80 void Load( SvStream& rStream, sal_uInt16 nVer );
81 void Write(SvStream& rStream, sal_uInt16 fileVersion);
84 /// Contains all items for one cell of a table autoformat.
85 class ScAutoFormatDataField : public AutoFormatBase
87 private:
88 AutoFormatSwBlob m_swFields;
90 // number format
91 ScNumFormatAbbrev aNumFormat;
93 public:
94 ScAutoFormatDataField();
95 ScAutoFormatDataField( const ScAutoFormatDataField& rCopy );
96 ~ScAutoFormatDataField();
98 // block assignment operator
99 ScAutoFormatDataField& operator=(const ScAutoFormatDataField& rRef) = delete;
101 // number format
102 const ScNumFormatAbbrev& GetNumFormat() const { return aNumFormat; }
104 // number format
105 void SetNumFormat( const ScNumFormatAbbrev& rNumFormat ) { aNumFormat = rNumFormat; }
107 bool Load( SvStream& rStream, const ScAfVersions& rVersions, sal_uInt16 nVer );
108 bool Save( SvStream& rStream, sal_uInt16 fileVersion );
111 class SC_DLLPUBLIC ScAutoFormatData
113 private:
114 OUString aName;
115 sal_uInt16 nStrResId;
116 // common flags of Calc and Writer
117 bool bIncludeFont : 1;
118 bool bIncludeJustify : 1;
119 bool bIncludeFrame : 1;
120 bool bIncludeBackground : 1;
122 // Calc specific flags
123 bool bIncludeValueFormat : 1;
124 bool bIncludeWidthHeight : 1;
126 // Writer-specific data
127 AutoFormatSwBlob m_swFields;
129 std::array<std::unique_ptr<ScAutoFormatDataField>,16> ppDataField;
131 SAL_DLLPRIVATE ScAutoFormatDataField& GetField( sal_uInt16 nIndex );
132 SAL_DLLPRIVATE const ScAutoFormatDataField& GetField( sal_uInt16 nIndex ) const;
134 public:
135 ScAutoFormatData();
136 ScAutoFormatData( const ScAutoFormatData& rData );
137 ~ScAutoFormatData();
139 void SetName( const OUString& rName ) { aName = rName; nStrResId = USHRT_MAX; }
140 const OUString& GetName() const { return aName; }
142 bool GetIncludeValueFormat() const { return bIncludeValueFormat; }
143 bool GetIncludeFont() const { return bIncludeFont; }
144 bool GetIncludeJustify() const { return bIncludeJustify; }
145 bool GetIncludeFrame() const { return bIncludeFrame; }
146 bool GetIncludeBackground() const { return bIncludeBackground; }
147 bool GetIncludeWidthHeight() const { return bIncludeWidthHeight; }
149 void SetIncludeValueFormat( bool bValueFormat ) { bIncludeValueFormat = bValueFormat; }
150 void SetIncludeFont( bool bFont ) { bIncludeFont = bFont; }
151 void SetIncludeJustify( bool bJustify ) { bIncludeJustify = bJustify; }
152 void SetIncludeFrame( bool bFrame ) { bIncludeFrame = bFrame; }
153 void SetIncludeBackground( bool bBackground ) { bIncludeBackground = bBackground; }
154 void SetIncludeWidthHeight( bool bWidthHeight ) { bIncludeWidthHeight = bWidthHeight; }
156 const SfxPoolItem* GetItem( sal_uInt16 nIndex, sal_uInt16 nWhich ) const;
157 template<class T> const T* GetItem( sal_uInt16 nIndex, TypedWhichId<T> nWhich ) const
159 return static_cast<const T*>(GetItem(nIndex, sal_uInt16(nWhich)));
161 void PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem );
162 void CopyItem( sal_uInt16 nToIndex, sal_uInt16 nFromIndex, sal_uInt16 nWhich );
164 const ScNumFormatAbbrev& GetNumFormat( sal_uInt16 nIndex ) const;
166 bool IsEqualData( sal_uInt16 nIndex1, sal_uInt16 nIndex2 ) const;
168 void FillToItemSet( sal_uInt16 nIndex, SfxItemSet& rItemSet, const ScDocument& rDoc ) const;
169 void GetFromItemSet( sal_uInt16 nIndex, const SfxItemSet& rItemSet, const ScNumFormatAbbrev& rNumFormat );
171 bool Load( SvStream& rStream, const ScAfVersions& rVersions );
172 bool Save( SvStream& rStream, sal_uInt16 fileVersion );
175 struct DefaultFirstEntry {
176 bool operator() (const OUString& left, const OUString& right) const;
179 class SC_DLLPUBLIC ScAutoFormat
181 typedef std::map<OUString, std::unique_ptr<ScAutoFormatData>, DefaultFirstEntry> MapType;
182 MapType m_Data;
183 bool mbSaveLater;
184 ScAfVersions m_aVersions;
186 ScAutoFormat(const ScAutoFormat&) = delete;
187 const ScAutoFormat operator=(const ScAutoFormat&) = delete;
189 public:
190 typedef MapType::const_iterator const_iterator;
191 typedef MapType::iterator iterator;
193 ScAutoFormat();
194 void Load();
195 bool Save();
197 void SetSaveLater( bool bSet );
198 bool IsSaveLater() const { return mbSaveLater; }
200 const ScAutoFormatData* findByIndex(size_t nIndex) const;
201 ScAutoFormatData* findByIndex(size_t nIndex);
202 iterator find(const OUString& rName);
204 iterator insert(std::unique_ptr<ScAutoFormatData> pNew);
205 void erase(const iterator& it);
207 size_t size() const;
208 const_iterator begin() const;
209 const_iterator end() const;
210 iterator begin();
211 iterator end();
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */