1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
52 #include "zforauto.hxx"
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 std::unique_ptr
<sal_uInt8
[]> pData
;
74 AutoFormatSwBlob() : size(0)
77 AutoFormatSwBlob(const AutoFormatSwBlob
&) = delete;
78 const AutoFormatSwBlob
& operator=(const AutoFormatSwBlob
&) = delete;
87 /// Struct with version numbers of the Items
91 sal_uInt16 nFontVersion
;
92 sal_uInt16 nFontHeightVersion
;
93 sal_uInt16 nWeightVersion
;
94 sal_uInt16 nPostureVersion
;
95 sal_uInt16 nUnderlineVersion
;
96 sal_uInt16 nOverlineVersion
;
97 sal_uInt16 nCrossedOutVersion
;
98 sal_uInt16 nContourVersion
;
99 sal_uInt16 nShadowedVersion
;
100 sal_uInt16 nColorVersion
;
101 sal_uInt16 nBoxVersion
;
102 sal_uInt16 nLineVersion
;
103 sal_uInt16 nBrushVersion
;
105 sal_uInt16 nAdjustVersion
;
106 AutoFormatSwBlob swVersions
;
108 sal_uInt16 nHorJustifyVersion
;
109 sal_uInt16 nVerJustifyVersion
;
110 sal_uInt16 nOrientationVersion
;
111 sal_uInt16 nMarginVersion
;
112 sal_uInt16 nBoolVersion
;
113 sal_uInt16 nInt32Version
;
114 sal_uInt16 nRotateModeVersion
;
116 sal_uInt16 nNumFmtVersion
;
119 void Load( SvStream
& rStream
, sal_uInt16 nVer
);
120 void Write(SvStream
& rStream
, sal_uInt16 fileVersion
);
123 /// Contains all items for one cell of a table autoformat.
124 class ScAutoFormatDataField
128 SvxFontHeightItem aHeight
;
129 SvxWeightItem aWeight
;
130 SvxPostureItem aPosture
;
132 SvxFontItem aCJKFont
;
133 SvxFontHeightItem aCJKHeight
;
134 SvxWeightItem aCJKWeight
;
135 SvxPostureItem aCJKPosture
;
137 SvxFontItem aCTLFont
;
138 SvxFontHeightItem aCTLHeight
;
139 SvxWeightItem aCTLWeight
;
140 SvxPostureItem aCTLPosture
;
142 SvxUnderlineItem aUnderline
;
143 SvxOverlineItem aOverline
;
144 SvxCrossedOutItem aCrossedOut
;
145 SvxContourItem aContour
;
146 SvxShadowedItem aShadowed
;
151 SvxBrushItem aBackground
;
154 SvxAdjustItem aAdjust
;
155 AutoFormatSwBlob m_swFields
;
158 SvxHorJustifyItem aHorJustify
;
159 SvxVerJustifyItem aVerJustify
;
160 SfxBoolItem aStacked
;
161 SvxMarginItem aMargin
;
162 SfxBoolItem aLinebreak
;
163 // from SO5, 504k on, rotated text
164 SfxInt32Item aRotateAngle
;
165 SvxRotateModeItem aRotateMode
;
168 ScNumFormatAbbrev aNumFormat
;
171 ScAutoFormatDataField();
172 ScAutoFormatDataField( const ScAutoFormatDataField
& rCopy
);
173 ~ScAutoFormatDataField();
175 const ScNumFormatAbbrev
& GetNumFormat() const { return aNumFormat
; }
176 const SvxFontItem
& GetFont() const { return aFont
; }
177 const SvxFontHeightItem
& GetHeight() const { return aHeight
; }
178 const SvxWeightItem
& GetWeight() const { return aWeight
; }
179 const SvxPostureItem
& GetPosture() const { return aPosture
; }
180 const SvxFontItem
& GetCJKFont() const { return aCJKFont
; }
181 const SvxFontHeightItem
& GetCJKHeight() const { return aCJKHeight
; }
182 const SvxWeightItem
& GetCJKWeight() const { return aCJKWeight
; }
183 const SvxPostureItem
& GetCJKPosture() const { return aCJKPosture
; }
184 const SvxFontItem
& GetCTLFont() const { return aCTLFont
; }
185 const SvxFontHeightItem
& GetCTLHeight() const { return aCTLHeight
; }
186 const SvxWeightItem
& GetCTLWeight() const { return aCTLWeight
; }
187 const SvxPostureItem
& GetCTLPosture() const { return aCTLPosture
; }
188 const SvxUnderlineItem
& GetUnderline() const { return aUnderline
; }
189 const SvxOverlineItem
& GetOverline() const { return aOverline
; }
190 const SvxCrossedOutItem
& GetCrossedOut() const { return aCrossedOut
; }
191 const SvxContourItem
& GetContour() const { return aContour
; }
192 const SvxShadowedItem
& GetShadowed() const { return aShadowed
; }
193 const SvxColorItem
& GetColor() const { return aColor
; }
194 const SvxHorJustifyItem
& GetHorJustify() const { return aHorJustify
; }
195 const SvxVerJustifyItem
& GetVerJustify() const { return aVerJustify
; }
196 const SfxBoolItem
& GetStacked() const { return aStacked
; }
197 const SfxBoolItem
& GetLinebreak() const { return aLinebreak
; }
198 const SvxMarginItem
& GetMargin() const { return aMargin
; }
199 const SvxBoxItem
& GetBox() const { return aBox
; }
200 const SvxLineItem
& GetTLBR() const { return aTLBR
; }
201 const SvxLineItem
& GetBLTR() const { return aBLTR
; }
202 const SvxBrushItem
& GetBackground() const { return aBackground
; }
203 const SfxInt32Item
& GetRotateAngle() const { return aRotateAngle
; }
204 const SvxRotateModeItem
& GetRotateMode() const { return aRotateMode
; }
206 void SetNumFormat( const ScNumFormatAbbrev
& rNumFormat
) { aNumFormat
= rNumFormat
; }
207 void SetFont( const SvxFontItem
& rFont
) { aFont
= rFont
; }
208 void SetHeight( const SvxFontHeightItem
& rHeight
) { aHeight
= rHeight
; }
209 void SetWeight( const SvxWeightItem
& rWeight
) { aWeight
= rWeight
; }
210 void SetPosture( const SvxPostureItem
& rPosture
) { aPosture
= rPosture
; }
211 void SetCJKFont( const SvxFontItem
& rCJKFont
) { aCJKFont
= rCJKFont
; }
212 void SetCJKHeight( const SvxFontHeightItem
& rCJKHeight
) { aCJKHeight
= rCJKHeight
; }
213 void SetCJKWeight( const SvxWeightItem
& rCJKWeight
) { aCJKWeight
= rCJKWeight
; }
214 void SetCJKPosture( const SvxPostureItem
& rCJKPosture
) { aCJKPosture
= rCJKPosture
; }
215 void SetCTLFont( const SvxFontItem
& rCTLFont
) { aCTLFont
= rCTLFont
; }
216 void SetCTLHeight( const SvxFontHeightItem
& rCTLHeight
) { aCTLHeight
= rCTLHeight
; }
217 void SetCTLWeight( const SvxWeightItem
& rCTLWeight
) { aCTLWeight
= rCTLWeight
; }
218 void SetCTLPosture( const SvxPostureItem
& rCTLPosture
) { aCTLPosture
= rCTLPosture
; }
219 void SetUnderline( const SvxUnderlineItem
& rUnderline
) { aUnderline
= rUnderline
; }
220 void SetOverline( const SvxOverlineItem
& rOverline
) { aOverline
= rOverline
; }
221 void SetCrossedOut( const SvxCrossedOutItem
& rCrossedOut
) { aCrossedOut
= rCrossedOut
; }
222 void SetContour( const SvxContourItem
& rContour
) { aContour
= rContour
; }
223 void SetShadowed( const SvxShadowedItem
& rShadowed
) { aShadowed
= rShadowed
; }
224 void SetColor( const SvxColorItem
& rColor
) { aColor
= rColor
; }
225 void SetHorJustify( const SvxHorJustifyItem
& rHorJustify
) { aHorJustify
= rHorJustify
; }
226 void SetVerJustify( const SvxVerJustifyItem
& rVerJustify
) { aVerJustify
= rVerJustify
; }
227 void SetStacked( const SfxBoolItem
& rStacked
) { aStacked
.SetValue( rStacked
.GetValue() ); }
228 void SetLinebreak( const SfxBoolItem
& rLinebreak
) { aLinebreak
.SetValue( rLinebreak
.GetValue() ); }
229 void SetMargin( const SvxMarginItem
& rMargin
) { aMargin
= rMargin
; }
230 void SetBox( const SvxBoxItem
& rBox
) { aBox
= rBox
; }
231 void SetTLBR( const SvxLineItem
& rTLBR
) { aTLBR
= rTLBR
; }
232 void SetBLTR( const SvxLineItem
& rBLTR
) { aBLTR
= rBLTR
; }
233 void SetBackground( const SvxBrushItem
& rBackground
) { aBackground
= rBackground
; }
234 void SetAdjust( const SvxAdjustItem
& rAdjust
);
235 void SetRotateAngle( const SfxInt32Item
& rRotateAngle
) { aRotateAngle
.SetValue( rRotateAngle
.GetValue() ); }
236 void SetRotateMode( const SvxRotateModeItem
& rRotateMode
) { aRotateMode
.SetValue( rRotateMode
.GetValue() ); }
238 bool Load( SvStream
& rStream
, const ScAfVersions
& rVersions
, sal_uInt16 nVer
);
239 bool Save( SvStream
& rStream
, sal_uInt16 fileVersion
);
242 class SC_DLLPUBLIC ScAutoFormatData
246 sal_uInt16 nStrResId
;
247 // common flags of Calc and Writer
248 bool bIncludeFont
: 1;
249 bool bIncludeJustify
: 1;
250 bool bIncludeFrame
: 1;
251 bool bIncludeBackground
: 1;
253 // Calc specific flags
254 bool bIncludeValueFormat
: 1;
255 bool bIncludeWidthHeight
: 1;
257 // Writer-specific data
258 AutoFormatSwBlob m_swFields
;
260 std::array
<std::unique_ptr
<ScAutoFormatDataField
>,16> ppDataField
;
262 SAL_DLLPRIVATE ScAutoFormatDataField
& GetField( sal_uInt16 nIndex
);
263 SAL_DLLPRIVATE
const ScAutoFormatDataField
& GetField( sal_uInt16 nIndex
) const;
267 ScAutoFormatData( const ScAutoFormatData
& rData
);
270 void SetName( const OUString
& rName
) { aName
= rName
; nStrResId
= USHRT_MAX
; }
271 const OUString
& GetName() const { return aName
; }
273 bool GetIncludeValueFormat() const { return bIncludeValueFormat
; }
274 bool GetIncludeFont() const { return bIncludeFont
; }
275 bool GetIncludeJustify() const { return bIncludeJustify
; }
276 bool GetIncludeFrame() const { return bIncludeFrame
; }
277 bool GetIncludeBackground() const { return bIncludeBackground
; }
278 bool GetIncludeWidthHeight() const { return bIncludeWidthHeight
; }
280 void SetIncludeValueFormat( bool bValueFormat
) { bIncludeValueFormat
= bValueFormat
; }
281 void SetIncludeFont( bool bFont
) { bIncludeFont
= bFont
; }
282 void SetIncludeJustify( bool bJustify
) { bIncludeJustify
= bJustify
; }
283 void SetIncludeFrame( bool bFrame
) { bIncludeFrame
= bFrame
; }
284 void SetIncludeBackground( bool bBackground
) { bIncludeBackground
= bBackground
; }
285 void SetIncludeWidthHeight( bool bWidthHeight
) { bIncludeWidthHeight
= bWidthHeight
; }
287 const SfxPoolItem
* GetItem( sal_uInt16 nIndex
, sal_uInt16 nWhich
) const;
288 template<class T
> const T
* GetItem( sal_uInt16 nIndex
, TypedWhichId
<T
> nWhich
) const
290 return static_cast<const T
*>(GetItem(nIndex
, sal_uInt16(nWhich
)));
292 void PutItem( sal_uInt16 nIndex
, const SfxPoolItem
& rItem
);
293 void CopyItem( sal_uInt16 nToIndex
, sal_uInt16 nFromIndex
, sal_uInt16 nWhich
);
295 const ScNumFormatAbbrev
& GetNumFormat( sal_uInt16 nIndex
) const;
297 bool IsEqualData( sal_uInt16 nIndex1
, sal_uInt16 nIndex2
) const;
299 void FillToItemSet( sal_uInt16 nIndex
, SfxItemSet
& rItemSet
, const ScDocument
& rDoc
) const;
300 void GetFromItemSet( sal_uInt16 nIndex
, const SfxItemSet
& rItemSet
, const ScNumFormatAbbrev
& rNumFormat
);
302 bool Load( SvStream
& rStream
, const ScAfVersions
& rVersions
);
303 bool Save( SvStream
& rStream
, sal_uInt16 fileVersion
);
306 struct DefaultFirstEntry
{
307 bool operator() (const OUString
& left
, const OUString
& right
) const;
310 class SC_DLLPUBLIC ScAutoFormat
312 typedef std::map
<OUString
, std::unique_ptr
<ScAutoFormatData
>, DefaultFirstEntry
> MapType
;
315 ScAfVersions m_aVersions
;
317 ScAutoFormat(const ScAutoFormat
&) = delete;
318 const ScAutoFormat
operator=(const ScAutoFormat
&) = delete;
321 typedef MapType::const_iterator const_iterator
;
322 typedef MapType::iterator iterator
;
328 void SetSaveLater( bool bSet
);
329 bool IsSaveLater() const { return mbSaveLater
; }
331 const ScAutoFormatData
* findByIndex(size_t nIndex
) const;
332 ScAutoFormatData
* findByIndex(size_t nIndex
);
333 iterator
find(const ScAutoFormatData
* pData
);
334 iterator
find(const OUString
& rName
);
336 iterator
insert(std::unique_ptr
<ScAutoFormatData
> pNew
);
337 void erase(const iterator
& it
);
340 const_iterator
begin() const;
341 const_iterator
end() const;
348 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */