Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sc / inc / autoform.hxx
blobb1559dc264de5a2cd897d9a95b50d055fef3a9e0
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_AUTOFORM_HXX
21 #define INCLUDED_SC_INC_AUTOFORM_HXX
23 /*************************************************************************
24 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
26 The structure of auto formatting should not be changed. It is used
27 by various code of Writer and Calc. If a change is necessary, the
28 source code of both applications must be changed!
30 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
31 **************************************************************************/
33 #include "scitems.hxx"
34 #include <editeng/adjustitem.hxx>
35 #include <svx/algitem.hxx>
36 #include <editeng/boxitem.hxx>
37 #include <editeng/brushitem.hxx>
38 #include <editeng/contouritem.hxx>
39 #include <editeng/colritem.hxx>
40 #include <editeng/crossedoutitem.hxx>
41 #include <editeng/fhgtitem.hxx>
42 #include <editeng/fontitem.hxx>
43 #include <editeng/postitem.hxx>
44 #include <editeng/shdditem.hxx>
45 #include <editeng/udlnitem.hxx>
46 #include <editeng/wghtitem.hxx>
47 #include <editeng/justifyitem.hxx>
48 #include <svx/rotmodit.hxx>
49 #include <svl/intitem.hxx>
50 #include <editeng/lineitem.hxx>
51 #include "scdllapi.h"
52 #include "zforauto.hxx"
54 #include <array>
55 #include <memory>
56 #include <map>
58 class ScDocument;
60 /**
61 A binary blob of writer-specific data. This data typically consists of types that are
62 unavailable to Calc (e.g. SwFmtVertOrient), or that Calc doesn't care about.
64 @remarks Note that in autoformat versions prior to AUTOFORMAT_DATA_ID_31005, Calc
65 logic handled and stored several writer-specific items (such as ScAutoFormatDataField::aAdjust).
66 That logic was preserved. From _31005 onward, writer-specific data should be handled by
67 blobs to avoid needlessly complicating the Calc logic.
69 struct AutoFormatSwBlob
71 sal_uInt8 *pData;
72 std::size_t size;
74 AutoFormatSwBlob() : pData(nullptr), size(0)
77 AutoFormatSwBlob(const AutoFormatSwBlob&) = delete;
78 const AutoFormatSwBlob& operator=(const AutoFormatSwBlob&) = delete;
79 ~AutoFormatSwBlob()
81 Reset();
84 void Reset()
86 delete[] pData;
87 pData = nullptr;
88 size = 0;
92 /// Struct with version numbers of the Items
93 struct ScAfVersions
95 public:
96 sal_uInt16 nFontVersion;
97 sal_uInt16 nFontHeightVersion;
98 sal_uInt16 nWeightVersion;
99 sal_uInt16 nPostureVersion;
100 sal_uInt16 nUnderlineVersion;
101 sal_uInt16 nOverlineVersion;
102 sal_uInt16 nCrossedOutVersion;
103 sal_uInt16 nContourVersion;
104 sal_uInt16 nShadowedVersion;
105 sal_uInt16 nColorVersion;
106 sal_uInt16 nBoxVersion;
107 sal_uInt16 nLineVersion;
108 sal_uInt16 nBrushVersion;
110 sal_uInt16 nAdjustVersion;
111 AutoFormatSwBlob swVersions;
113 sal_uInt16 nHorJustifyVersion;
114 sal_uInt16 nVerJustifyVersion;
115 sal_uInt16 nOrientationVersion;
116 sal_uInt16 nMarginVersion;
117 sal_uInt16 nBoolVersion;
118 sal_uInt16 nInt32Version;
119 sal_uInt16 nRotateModeVersion;
121 sal_uInt16 nNumFmtVersion;
123 ScAfVersions();
124 void Load( SvStream& rStream, sal_uInt16 nVer );
125 void Write(SvStream& rStream, sal_uInt16 fileVersion);
128 /// Contains all items for one cell of a table autoformat.
129 class ScAutoFormatDataField
131 private:
132 SvxFontItem aFont;
133 SvxFontHeightItem aHeight;
134 SvxWeightItem aWeight;
135 SvxPostureItem aPosture;
137 SvxFontItem aCJKFont;
138 SvxFontHeightItem aCJKHeight;
139 SvxWeightItem aCJKWeight;
140 SvxPostureItem aCJKPosture;
142 SvxFontItem aCTLFont;
143 SvxFontHeightItem aCTLHeight;
144 SvxWeightItem aCTLWeight;
145 SvxPostureItem aCTLPosture;
147 SvxUnderlineItem aUnderline;
148 SvxOverlineItem aOverline;
149 SvxCrossedOutItem aCrossedOut;
150 SvxContourItem aContour;
151 SvxShadowedItem aShadowed;
152 SvxColorItem aColor;
153 SvxBoxItem aBox;
154 SvxLineItem aTLBR;
155 SvxLineItem aBLTR;
156 SvxBrushItem aBackground;
158 // Writer specific
159 SvxAdjustItem aAdjust;
160 AutoFormatSwBlob m_swFields;
162 // Calc specific
163 SvxHorJustifyItem aHorJustify;
164 SvxVerJustifyItem aVerJustify;
165 SfxBoolItem aStacked;
166 SvxMarginItem aMargin;
167 SfxBoolItem aLinebreak;
168 // from SO5, 504k on, rotated text
169 SfxInt32Item aRotateAngle;
170 SvxRotateModeItem aRotateMode;
172 // number format
173 ScNumFormatAbbrev aNumFormat;
175 public:
176 ScAutoFormatDataField();
177 ScAutoFormatDataField( const ScAutoFormatDataField& rCopy );
178 ~ScAutoFormatDataField();
180 const ScNumFormatAbbrev& GetNumFormat() const { return aNumFormat; }
181 const SvxFontItem& GetFont() const { return aFont; }
182 const SvxFontHeightItem& GetHeight() const { return aHeight; }
183 const SvxWeightItem& GetWeight() const { return aWeight; }
184 const SvxPostureItem& GetPosture() const { return aPosture; }
185 const SvxFontItem& GetCJKFont() const { return aCJKFont; }
186 const SvxFontHeightItem& GetCJKHeight() const { return aCJKHeight; }
187 const SvxWeightItem& GetCJKWeight() const { return aCJKWeight; }
188 const SvxPostureItem& GetCJKPosture() const { return aCJKPosture; }
189 const SvxFontItem& GetCTLFont() const { return aCTLFont; }
190 const SvxFontHeightItem& GetCTLHeight() const { return aCTLHeight; }
191 const SvxWeightItem& GetCTLWeight() const { return aCTLWeight; }
192 const SvxPostureItem& GetCTLPosture() const { return aCTLPosture; }
193 const SvxUnderlineItem& GetUnderline() const { return aUnderline; }
194 const SvxOverlineItem& GetOverline() const { return aOverline; }
195 const SvxCrossedOutItem& GetCrossedOut() const { return aCrossedOut; }
196 const SvxContourItem& GetContour() const { return aContour; }
197 const SvxShadowedItem& GetShadowed() const { return aShadowed; }
198 const SvxColorItem& GetColor() const { return aColor; }
199 const SvxHorJustifyItem& GetHorJustify() const { return aHorJustify; }
200 const SvxVerJustifyItem& GetVerJustify() const { return aVerJustify; }
201 const SfxBoolItem& GetStacked() const { return aStacked; }
202 const SfxBoolItem& GetLinebreak() const { return aLinebreak; }
203 const SvxMarginItem& GetMargin() const { return aMargin; }
204 const SvxBoxItem& GetBox() const { return aBox; }
205 const SvxLineItem& GetTLBR() const { return aTLBR; }
206 const SvxLineItem& GetBLTR() const { return aBLTR; }
207 const SvxBrushItem& GetBackground() const { return aBackground; }
208 const SfxInt32Item& GetRotateAngle() const { return aRotateAngle; }
209 const SvxRotateModeItem& GetRotateMode() const { return aRotateMode; }
211 void SetNumFormat( const ScNumFormatAbbrev& rNumFormat ) { aNumFormat = rNumFormat; }
212 void SetFont( const SvxFontItem& rFont ) { aFont = rFont; }
213 void SetHeight( const SvxFontHeightItem& rHeight ) { aHeight = rHeight; }
214 void SetWeight( const SvxWeightItem& rWeight ) { aWeight = rWeight; }
215 void SetPosture( const SvxPostureItem& rPosture ) { aPosture = rPosture; }
216 void SetCJKFont( const SvxFontItem& rCJKFont ) { aCJKFont = rCJKFont; }
217 void SetCJKHeight( const SvxFontHeightItem& rCJKHeight ) { aCJKHeight = rCJKHeight; }
218 void SetCJKWeight( const SvxWeightItem& rCJKWeight ) { aCJKWeight = rCJKWeight; }
219 void SetCJKPosture( const SvxPostureItem& rCJKPosture ) { aCJKPosture = rCJKPosture; }
220 void SetCTLFont( const SvxFontItem& rCTLFont ) { aCTLFont = rCTLFont; }
221 void SetCTLHeight( const SvxFontHeightItem& rCTLHeight ) { aCTLHeight = rCTLHeight; }
222 void SetCTLWeight( const SvxWeightItem& rCTLWeight ) { aCTLWeight = rCTLWeight; }
223 void SetCTLPosture( const SvxPostureItem& rCTLPosture ) { aCTLPosture = rCTLPosture; }
224 void SetUnderline( const SvxUnderlineItem& rUnderline ) { aUnderline = rUnderline; }
225 void SetOverline( const SvxOverlineItem& rOverline ) { aOverline = rOverline; }
226 void SetCrossedOut( const SvxCrossedOutItem& rCrossedOut ) { aCrossedOut = rCrossedOut; }
227 void SetContour( const SvxContourItem& rContour ) { aContour = rContour; }
228 void SetShadowed( const SvxShadowedItem& rShadowed ) { aShadowed = rShadowed; }
229 void SetColor( const SvxColorItem& rColor ) { aColor = rColor; }
230 void SetHorJustify( const SvxHorJustifyItem& rHorJustify ) { aHorJustify = rHorJustify; }
231 void SetVerJustify( const SvxVerJustifyItem& rVerJustify ) { aVerJustify = rVerJustify; }
232 void SetStacked( const SfxBoolItem& rStacked ) { aStacked.SetValue( rStacked.GetValue() ); }
233 void SetLinebreak( const SfxBoolItem& rLinebreak ) { aLinebreak.SetValue( rLinebreak.GetValue() ); }
234 void SetMargin( const SvxMarginItem& rMargin ) { aMargin = rMargin; }
235 void SetBox( const SvxBoxItem& rBox ) { aBox = rBox; }
236 void SetTLBR( const SvxLineItem& rTLBR ) { aTLBR = rTLBR; }
237 void SetBLTR( const SvxLineItem& rBLTR ) { aBLTR = rBLTR; }
238 void SetBackground( const SvxBrushItem& rBackground ) { aBackground = rBackground; }
239 void SetAdjust( const SvxAdjustItem& rAdjust );
240 void SetRotateAngle( const SfxInt32Item& rRotateAngle ) { aRotateAngle.SetValue( rRotateAngle.GetValue() ); }
241 void SetRotateMode( const SvxRotateModeItem& rRotateMode ) { aRotateMode.SetValue( rRotateMode.GetValue() ); }
243 bool Load( SvStream& rStream, const ScAfVersions& rVersions, sal_uInt16 nVer );
244 bool Save( SvStream& rStream, sal_uInt16 fileVersion );
247 class SC_DLLPUBLIC ScAutoFormatData
249 private:
250 OUString aName;
251 sal_uInt16 nStrResId;
252 // common flags of Calc and Writer
253 bool bIncludeFont : 1;
254 bool bIncludeJustify : 1;
255 bool bIncludeFrame : 1;
256 bool bIncludeBackground : 1;
258 // Calc specific flags
259 bool bIncludeValueFormat : 1;
260 bool bIncludeWidthHeight : 1;
262 // Writer-specific data
263 AutoFormatSwBlob m_swFields;
265 std::array<std::unique_ptr<ScAutoFormatDataField>,16> ppDataField;
267 SAL_DLLPRIVATE ScAutoFormatDataField& GetField( sal_uInt16 nIndex );
268 SAL_DLLPRIVATE const ScAutoFormatDataField& GetField( sal_uInt16 nIndex ) const;
270 public:
271 ScAutoFormatData();
272 ScAutoFormatData( const ScAutoFormatData& rData );
273 ~ScAutoFormatData();
275 void SetName( const OUString& rName ) { aName = rName; nStrResId = USHRT_MAX; }
276 const OUString& GetName() const { return aName; }
278 bool GetIncludeValueFormat() const { return bIncludeValueFormat; }
279 bool GetIncludeFont() const { return bIncludeFont; }
280 bool GetIncludeJustify() const { return bIncludeJustify; }
281 bool GetIncludeFrame() const { return bIncludeFrame; }
282 bool GetIncludeBackground() const { return bIncludeBackground; }
283 bool GetIncludeWidthHeight() const { return bIncludeWidthHeight; }
285 void SetIncludeValueFormat( bool bValueFormat ) { bIncludeValueFormat = bValueFormat; }
286 void SetIncludeFont( bool bFont ) { bIncludeFont = bFont; }
287 void SetIncludeJustify( bool bJustify ) { bIncludeJustify = bJustify; }
288 void SetIncludeFrame( bool bFrame ) { bIncludeFrame = bFrame; }
289 void SetIncludeBackground( bool bBackground ) { bIncludeBackground = bBackground; }
290 void SetIncludeWidthHeight( bool bWidthHeight ) { bIncludeWidthHeight = bWidthHeight; }
292 const SfxPoolItem* GetItem( sal_uInt16 nIndex, sal_uInt16 nWhich ) const;
293 template<class T> const T* GetItem( sal_uInt16 nIndex, TypedWhichId<T> nWhich ) const
295 return static_cast<const T*>(GetItem(nIndex, sal_uInt16(nWhich)));
297 void PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem );
298 void CopyItem( sal_uInt16 nToIndex, sal_uInt16 nFromIndex, sal_uInt16 nWhich );
300 const ScNumFormatAbbrev& GetNumFormat( sal_uInt16 nIndex ) const;
302 bool IsEqualData( sal_uInt16 nIndex1, sal_uInt16 nIndex2 ) const;
304 void FillToItemSet( sal_uInt16 nIndex, SfxItemSet& rItemSet, const ScDocument& rDoc ) const;
305 void GetFromItemSet( sal_uInt16 nIndex, const SfxItemSet& rItemSet, const ScNumFormatAbbrev& rNumFormat );
307 bool Load( SvStream& rStream, const ScAfVersions& rVersions );
308 bool Save( SvStream& rStream, sal_uInt16 fileVersion );
311 struct DefaultFirstEntry {
312 bool operator() (const OUString& left, const OUString& right) const;
315 class SC_DLLPUBLIC ScAutoFormat
317 typedef std::map<OUString, std::unique_ptr<ScAutoFormatData>, DefaultFirstEntry> MapType;
318 MapType m_Data;
319 bool mbSaveLater;
320 ScAfVersions m_aVersions;
322 ScAutoFormat(const ScAutoFormat&) = delete;
323 const ScAutoFormat operator=(const ScAutoFormat&) = delete;
325 public:
326 typedef MapType::const_iterator const_iterator;
327 typedef MapType::iterator iterator;
329 ScAutoFormat();
330 void Load();
331 bool Save();
333 void SetSaveLater( bool bSet );
334 bool IsSaveLater() const { return mbSaveLater; }
336 const ScAutoFormatData* findByIndex(size_t nIndex) const;
337 ScAutoFormatData* findByIndex(size_t nIndex);
338 iterator find(const ScAutoFormatData* pData);
339 iterator find(const OUString& rName);
341 bool insert(ScAutoFormatData* pNew);
342 void erase(const iterator& it);
344 size_t size() const;
345 const_iterator begin() const;
346 const_iterator end() const;
347 iterator begin();
348 iterator end();
351 #endif
353 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */