build fix
[LibreOffice.git] / sc / inc / autoform.hxx
blob69dd61fc46da481917902f8a3e2d50736f1183bd
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 Die akt. Struktur der Autoformatierung darf nicht mehr veraendert werden.
27 Diese wird durch unterschiedlichen Code vom StartWriter und vom StarCalc
28 eingelesen/geschrieben.
29 Sollte sich doch mal eine Aenderung nicht vermeiden lassen, dann auf
30 jedenfall in beiden Applikationen aendern.
32 The structure of table auto formatting should not changed. It is used
33 by different code of Writer and Calc. If a change is necessary, the
34 source code of both applications must be changed!
36 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37 **************************************************************************/
39 #include "scitems.hxx"
40 #include <editeng/adjustitem.hxx>
41 #include <svx/algitem.hxx>
42 #include <editeng/boxitem.hxx>
43 #include <editeng/brushitem.hxx>
44 #include <editeng/contouritem.hxx>
45 #include <editeng/colritem.hxx>
46 #include <editeng/crossedoutitem.hxx>
47 #include <editeng/fhgtitem.hxx>
48 #include <editeng/fontitem.hxx>
49 #include <editeng/postitem.hxx>
50 #include <editeng/shdditem.hxx>
51 #include <editeng/udlnitem.hxx>
52 #include <editeng/wghtitem.hxx>
53 #include <editeng/justifyitem.hxx>
54 #include <svx/rotmodit.hxx>
55 #include <svl/intitem.hxx>
56 #include <editeng/lineitem.hxx>
57 #include "scdllapi.h"
58 #include "zforauto.hxx"
60 #include <memory>
61 #include <map>
63 class ScDocument;
65 /**
66 A binary blob of writer-specific data. This data typically consists of types that are
67 unavailable to Calc (e.g. SwFmtVertOrient), or that Calc doesn't care about.
69 @remarks Note that in autoformat versions prior to AUTOFORMAT_DATA_ID_31005, Calc
70 logic handled and stored several writer-specific items (such as ScAutoFormatDataField::aAdjust).
71 That logic was preserved. From _31005 onward, writer-specific data should be handled by
72 blobs to avoid needlessly complicating the Calc logic.
74 struct AutoFormatSwBlob
76 sal_uInt8 *pData;
77 std::size_t size;
79 AutoFormatSwBlob() : pData(nullptr), size(0)
82 AutoFormatSwBlob(const AutoFormatSwBlob&) = delete;
83 const AutoFormatSwBlob& operator=(const AutoFormatSwBlob&) = delete;
84 ~AutoFormatSwBlob()
86 Reset();
89 void Reset()
91 delete[] pData;
92 pData = nullptr;
93 size = 0;
97 /// Struct with version numbers of the Items
98 struct ScAfVersions
100 public:
101 sal_uInt16 nFontVersion;
102 sal_uInt16 nFontHeightVersion;
103 sal_uInt16 nWeightVersion;
104 sal_uInt16 nPostureVersion;
105 sal_uInt16 nUnderlineVersion;
106 sal_uInt16 nOverlineVersion;
107 sal_uInt16 nCrossedOutVersion;
108 sal_uInt16 nContourVersion;
109 sal_uInt16 nShadowedVersion;
110 sal_uInt16 nColorVersion;
111 sal_uInt16 nBoxVersion;
112 sal_uInt16 nLineVersion;
113 sal_uInt16 nBrushVersion;
115 sal_uInt16 nAdjustVersion;
116 AutoFormatSwBlob swVersions;
118 sal_uInt16 nHorJustifyVersion;
119 sal_uInt16 nVerJustifyVersion;
120 sal_uInt16 nOrientationVersion;
121 sal_uInt16 nMarginVersion;
122 sal_uInt16 nBoolVersion;
123 sal_uInt16 nInt32Version;
124 sal_uInt16 nRotateModeVersion;
126 sal_uInt16 nNumFmtVersion;
128 ScAfVersions();
129 void Load( SvStream& rStream, sal_uInt16 nVer );
130 void Write(SvStream& rStream, sal_uInt16 fileVersion);
133 /// Contains all items for one cell of a table autoformat.
134 class ScAutoFormatDataField
136 private:
137 SvxFontItem aFont;
138 SvxFontHeightItem aHeight;
139 SvxWeightItem aWeight;
140 SvxPostureItem aPosture;
142 SvxFontItem aCJKFont;
143 SvxFontHeightItem aCJKHeight;
144 SvxWeightItem aCJKWeight;
145 SvxPostureItem aCJKPosture;
147 SvxFontItem aCTLFont;
148 SvxFontHeightItem aCTLHeight;
149 SvxWeightItem aCTLWeight;
150 SvxPostureItem aCTLPosture;
152 SvxUnderlineItem aUnderline;
153 SvxOverlineItem aOverline;
154 SvxCrossedOutItem aCrossedOut;
155 SvxContourItem aContour;
156 SvxShadowedItem aShadowed;
157 SvxColorItem aColor;
158 SvxBoxItem aBox;
159 SvxLineItem aTLBR;
160 SvxLineItem aBLTR;
161 SvxBrushItem aBackground;
163 // Writer specific
164 SvxAdjustItem aAdjust;
165 AutoFormatSwBlob m_swFields;
167 // Calc specific
168 SvxHorJustifyItem aHorJustify;
169 SvxVerJustifyItem aVerJustify;
170 SfxBoolItem aStacked;
171 SvxMarginItem aMargin;
172 SfxBoolItem aLinebreak;
173 // from SO5, 504k on, rotated text
174 SfxInt32Item aRotateAngle;
175 SvxRotateModeItem aRotateMode;
177 // number format
178 ScNumFormatAbbrev aNumFormat;
180 public:
181 ScAutoFormatDataField();
182 ScAutoFormatDataField( const ScAutoFormatDataField& rCopy );
183 ~ScAutoFormatDataField();
185 const ScNumFormatAbbrev& GetNumFormat() const { return aNumFormat; }
186 const SvxFontItem& GetFont() const { return aFont; }
187 const SvxFontHeightItem& GetHeight() const { return aHeight; }
188 const SvxWeightItem& GetWeight() const { return aWeight; }
189 const SvxPostureItem& GetPosture() const { return aPosture; }
190 const SvxFontItem& GetCJKFont() const { return aCJKFont; }
191 const SvxFontHeightItem& GetCJKHeight() const { return aCJKHeight; }
192 const SvxWeightItem& GetCJKWeight() const { return aCJKWeight; }
193 const SvxPostureItem& GetCJKPosture() const { return aCJKPosture; }
194 const SvxFontItem& GetCTLFont() const { return aCTLFont; }
195 const SvxFontHeightItem& GetCTLHeight() const { return aCTLHeight; }
196 const SvxWeightItem& GetCTLWeight() const { return aCTLWeight; }
197 const SvxPostureItem& GetCTLPosture() const { return aCTLPosture; }
198 const SvxUnderlineItem& GetUnderline() const { return aUnderline; }
199 const SvxOverlineItem& GetOverline() const { return aOverline; }
200 const SvxCrossedOutItem& GetCrossedOut() const { return aCrossedOut; }
201 const SvxContourItem& GetContour() const { return aContour; }
202 const SvxShadowedItem& GetShadowed() const { return aShadowed; }
203 const SvxColorItem& GetColor() const { return aColor; }
204 const SvxHorJustifyItem& GetHorJustify() const { return aHorJustify; }
205 const SvxVerJustifyItem& GetVerJustify() const { return aVerJustify; }
206 const SfxBoolItem& GetStacked() const { return aStacked; }
207 const SfxBoolItem& GetLinebreak() const { return aLinebreak; }
208 const SvxMarginItem& GetMargin() const { return aMargin; }
209 const SvxBoxItem& GetBox() const { return aBox; }
210 const SvxLineItem& GetTLBR() const { return aTLBR; }
211 const SvxLineItem& GetBLTR() const { return aBLTR; }
212 const SvxBrushItem& GetBackground() const { return aBackground; }
213 const SfxInt32Item& GetRotateAngle() const { return aRotateAngle; }
214 const SvxRotateModeItem& GetRotateMode() const { return aRotateMode; }
216 void SetNumFormat( const ScNumFormatAbbrev& rNumFormat ) { aNumFormat = rNumFormat; }
217 void SetFont( const SvxFontItem& rFont ) { aFont = rFont; }
218 void SetHeight( const SvxFontHeightItem& rHeight ) { aHeight = rHeight; }
219 void SetWeight( const SvxWeightItem& rWeight ) { aWeight = rWeight; }
220 void SetPosture( const SvxPostureItem& rPosture ) { aPosture = rPosture; }
221 void SetCJKFont( const SvxFontItem& rCJKFont ) { aCJKFont = rCJKFont; }
222 void SetCJKHeight( const SvxFontHeightItem& rCJKHeight ) { aCJKHeight = rCJKHeight; }
223 void SetCJKWeight( const SvxWeightItem& rCJKWeight ) { aCJKWeight = rCJKWeight; }
224 void SetCJKPosture( const SvxPostureItem& rCJKPosture ) { aCJKPosture = rCJKPosture; }
225 void SetCTLFont( const SvxFontItem& rCTLFont ) { aCTLFont = rCTLFont; }
226 void SetCTLHeight( const SvxFontHeightItem& rCTLHeight ) { aCTLHeight = rCTLHeight; }
227 void SetCTLWeight( const SvxWeightItem& rCTLWeight ) { aCTLWeight = rCTLWeight; }
228 void SetCTLPosture( const SvxPostureItem& rCTLPosture ) { aCTLPosture = rCTLPosture; }
229 void SetUnderline( const SvxUnderlineItem& rUnderline ) { aUnderline = rUnderline; }
230 void SetOverline( const SvxOverlineItem& rOverline ) { aOverline = rOverline; }
231 void SetCrossedOut( const SvxCrossedOutItem& rCrossedOut ) { aCrossedOut = rCrossedOut; }
232 void SetContour( const SvxContourItem& rContour ) { aContour = rContour; }
233 void SetShadowed( const SvxShadowedItem& rShadowed ) { aShadowed = rShadowed; }
234 void SetColor( const SvxColorItem& rColor ) { aColor = rColor; }
235 void SetHorJustify( const SvxHorJustifyItem& rHorJustify ) { aHorJustify = rHorJustify; }
236 void SetVerJustify( const SvxVerJustifyItem& rVerJustify ) { aVerJustify = rVerJustify; }
237 void SetStacked( const SfxBoolItem& rStacked ) { aStacked.SetValue( rStacked.GetValue() ); }
238 void SetLinebreak( const SfxBoolItem& rLinebreak ) { aLinebreak.SetValue( rLinebreak.GetValue() ); }
239 void SetMargin( const SvxMarginItem& rMargin ) { aMargin = rMargin; }
240 void SetBox( const SvxBoxItem& rBox ) { aBox = rBox; }
241 void SetTLBR( const SvxLineItem& rTLBR ) { aTLBR = rTLBR; }
242 void SetBLTR( const SvxLineItem& rBLTR ) { aBLTR = rBLTR; }
243 void SetBackground( const SvxBrushItem& rBackground ) { aBackground = rBackground; }
244 void SetAdjust( const SvxAdjustItem& rAdjust );
245 void SetRotateAngle( const SfxInt32Item& rRotateAngle ) { aRotateAngle.SetValue( rRotateAngle.GetValue() ); }
246 void SetRotateMode( const SvxRotateModeItem& rRotateMode ) { aRotateMode.SetValue( rRotateMode.GetValue() ); }
248 bool Load( SvStream& rStream, const ScAfVersions& rVersions, sal_uInt16 nVer );
249 bool Save( SvStream& rStream, sal_uInt16 fileVersion );
252 class SC_DLLPUBLIC ScAutoFormatData
254 private:
255 OUString aName;
256 sal_uInt16 nStrResId;
257 // common flags of Calc and Writer
258 bool bIncludeFont : 1;
259 bool bIncludeJustify : 1;
260 bool bIncludeFrame : 1;
261 bool bIncludeBackground : 1;
263 // Calc specific flags
264 bool bIncludeValueFormat : 1;
265 bool bIncludeWidthHeight : 1;
267 // Writer-specific data
268 AutoFormatSwBlob m_swFields;
270 ScAutoFormatDataField** ppDataField;
272 SAL_DLLPRIVATE ScAutoFormatDataField& GetField( sal_uInt16 nIndex );
273 SAL_DLLPRIVATE const ScAutoFormatDataField& GetField( sal_uInt16 nIndex ) const;
275 public:
276 ScAutoFormatData();
277 ScAutoFormatData( const ScAutoFormatData& rData );
278 ~ScAutoFormatData();
280 void SetName( const OUString& rName ) { aName = rName; nStrResId = USHRT_MAX; }
281 const OUString& GetName() const { return aName; }
283 bool GetIncludeValueFormat() const { return bIncludeValueFormat; }
284 bool GetIncludeFont() const { return bIncludeFont; }
285 bool GetIncludeJustify() const { return bIncludeJustify; }
286 bool GetIncludeFrame() const { return bIncludeFrame; }
287 bool GetIncludeBackground() const { return bIncludeBackground; }
288 bool GetIncludeWidthHeight() const { return bIncludeWidthHeight; }
290 void SetIncludeValueFormat( bool bValueFormat ) { bIncludeValueFormat = bValueFormat; }
291 void SetIncludeFont( bool bFont ) { bIncludeFont = bFont; }
292 void SetIncludeJustify( bool bJustify ) { bIncludeJustify = bJustify; }
293 void SetIncludeFrame( bool bFrame ) { bIncludeFrame = bFrame; }
294 void SetIncludeBackground( bool bBackground ) { bIncludeBackground = bBackground; }
295 void SetIncludeWidthHeight( bool bWidthHeight ) { bIncludeWidthHeight = bWidthHeight; }
297 const SfxPoolItem* GetItem( sal_uInt16 nIndex, sal_uInt16 nWhich ) const;
298 void PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem );
299 void CopyItem( sal_uInt16 nToIndex, sal_uInt16 nFromIndex, sal_uInt16 nWhich );
301 const ScNumFormatAbbrev& GetNumFormat( sal_uInt16 nIndex ) const;
303 bool IsEqualData( sal_uInt16 nIndex1, sal_uInt16 nIndex2 ) const;
305 void FillToItemSet( sal_uInt16 nIndex, SfxItemSet& rItemSet, ScDocument& rDoc ) const;
306 void GetFromItemSet( sal_uInt16 nIndex, const SfxItemSet& rItemSet, const ScNumFormatAbbrev& rNumFormat );
308 bool Load( SvStream& rStream, const ScAfVersions& rVersions );
309 bool Save( SvStream& rStream, sal_uInt16 fileVersion );
312 struct DefaultFirstEntry {
313 bool operator() (const OUString& left, const OUString& right) const;
316 class SC_DLLPUBLIC ScAutoFormat
318 typedef std::map<OUString, std::unique_ptr<ScAutoFormatData>, DefaultFirstEntry> MapType;
319 MapType m_Data;
320 bool mbSaveLater;
321 ScAfVersions m_aVersions;
323 public:
324 typedef MapType::const_iterator const_iterator;
325 typedef MapType::iterator iterator;
327 ScAutoFormat();
328 ScAutoFormat(const ScAutoFormat& r);
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: */