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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27 Die akt. Struktur der Autoformatierung darf nicht mehr veraendert werden.
28 Diese wird durch unterschiedlichen Code vom StartWriter und vom StarCalc
29 eingelesen/geschrieben.
30 Sollte sich doch mal eine Aenderung nicht vermeiden lassen, dann auf
31 jedenfall in beiden Applikationen aendern.
33 The structure of table auto formatting should not changed. It is used
34 by different code of Writer and Calc. If a change is necessary, the
35 source code of both applications must be changed!
37 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
38 **************************************************************************/
40 #include "scitems.hxx"
41 #include <editeng/adjustitem.hxx>
42 #include <svx/algitem.hxx>
43 #include <editeng/boxitem.hxx>
44 #include <editeng/brushitem.hxx>
45 #include <editeng/contouritem.hxx>
46 #include <editeng/colritem.hxx>
47 #include <editeng/crossedoutitem.hxx>
48 #include <editeng/fhgtitem.hxx>
49 #include <editeng/fontitem.hxx>
50 #include <editeng/postitem.hxx>
51 #include <editeng/shdditem.hxx>
52 #include <editeng/udlnitem.hxx>
53 #include <editeng/wghtitem.hxx>
54 #include <editeng/justifyitem.hxx>
55 #include <svx/rotmodit.hxx>
56 #include <svl/intitem.hxx>
57 #include <editeng/lineitem.hxx>
60 #include "zforauto.hxx"
62 #include <boost/ptr_container/ptr_map.hpp>
65 A binary blob of writer-specific data. This data typically consists of types that are
66 unavailable to Calc (e.g. SwFmtVertOrient), or that Calc doesn't care about.
68 @remarks Note that in autoformat versions prior to AUTOFORMAT_DATA_ID_31005, Calc
69 logic handled and stored several writer-specific items (such as ScAutoFormatDataField::aAdjust).
70 That logic was preserved. From _31005 onward, writer-specific data should be handled by
71 blobs to avoid needlessly complicating the Calc logic.
73 struct AutoFormatSwBlob
: ::boost::noncopyable
78 AutoFormatSwBlob() : pData(0), size(0)
95 /// Struct with version numbers of the Items
99 sal_uInt16 nFontVersion
;
100 sal_uInt16 nFontHeightVersion
;
101 sal_uInt16 nWeightVersion
;
102 sal_uInt16 nPostureVersion
;
103 sal_uInt16 nUnderlineVersion
;
104 sal_uInt16 nOverlineVersion
;
105 sal_uInt16 nCrossedOutVersion
;
106 sal_uInt16 nContourVersion
;
107 sal_uInt16 nShadowedVersion
;
108 sal_uInt16 nColorVersion
;
109 sal_uInt16 nBoxVersion
;
110 sal_uInt16 nLineVersion
;
111 sal_uInt16 nBrushVersion
;
113 sal_uInt16 nAdjustVersion
;
114 AutoFormatSwBlob swVersions
;
116 sal_uInt16 nHorJustifyVersion
;
117 sal_uInt16 nVerJustifyVersion
;
118 sal_uInt16 nOrientationVersion
;
119 sal_uInt16 nMarginVersion
;
120 sal_uInt16 nBoolVersion
;
121 sal_uInt16 nInt32Version
;
122 sal_uInt16 nRotateModeVersion
;
124 sal_uInt16 nNumFmtVersion
;
127 void Load( SvStream
& rStream
, sal_uInt16 nVer
);
128 void Write(SvStream
& rStream
, sal_uInt16 fileVersion
);
131 /// Contains all items for one cell of a table autoformat.
132 class ScAutoFormatDataField
136 SvxFontHeightItem aHeight
;
137 SvxWeightItem aWeight
;
138 SvxPostureItem aPosture
;
140 SvxFontItem aCJKFont
;
141 SvxFontHeightItem aCJKHeight
;
142 SvxWeightItem aCJKWeight
;
143 SvxPostureItem aCJKPosture
;
145 SvxFontItem aCTLFont
;
146 SvxFontHeightItem aCTLHeight
;
147 SvxWeightItem aCTLWeight
;
148 SvxPostureItem aCTLPosture
;
150 SvxUnderlineItem aUnderline
;
151 SvxOverlineItem aOverline
;
152 SvxCrossedOutItem aCrossedOut
;
153 SvxContourItem aContour
;
154 SvxShadowedItem aShadowed
;
159 SvxBrushItem aBackground
;
162 SvxAdjustItem aAdjust
;
163 AutoFormatSwBlob m_swFields
;
166 SvxHorJustifyItem aHorJustify
;
167 SvxVerJustifyItem aVerJustify
;
168 SfxBoolItem aStacked
;
169 SvxMarginItem aMargin
;
170 SfxBoolItem aLinebreak
;
171 // from SO5, 504k on, rotated text
172 SfxInt32Item aRotateAngle
;
173 SvxRotateModeItem aRotateMode
;
176 ScNumFormatAbbrev aNumFormat
;
179 ScAutoFormatDataField();
180 ScAutoFormatDataField( const ScAutoFormatDataField
& rCopy
);
181 ~ScAutoFormatDataField();
183 const ScNumFormatAbbrev
& GetNumFormat() const { return aNumFormat
; }
184 const SvxFontItem
& GetFont() const { return aFont
; }
185 const SvxFontHeightItem
& GetHeight() const { return aHeight
; }
186 const SvxWeightItem
& GetWeight() const { return aWeight
; }
187 const SvxPostureItem
& GetPosture() const { return aPosture
; }
188 const SvxFontItem
& GetCJKFont() const { return aCJKFont
; }
189 const SvxFontHeightItem
& GetCJKHeight() const { return aCJKHeight
; }
190 const SvxWeightItem
& GetCJKWeight() const { return aCJKWeight
; }
191 const SvxPostureItem
& GetCJKPosture() const { return aCJKPosture
; }
192 const SvxFontItem
& GetCTLFont() const { return aCTLFont
; }
193 const SvxFontHeightItem
& GetCTLHeight() const { return aCTLHeight
; }
194 const SvxWeightItem
& GetCTLWeight() const { return aCTLWeight
; }
195 const SvxPostureItem
& GetCTLPosture() const { return aCTLPosture
; }
196 const SvxUnderlineItem
& GetUnderline() const { return aUnderline
; }
197 const SvxOverlineItem
& GetOverline() const { return aOverline
; }
198 const SvxCrossedOutItem
& GetCrossedOut() const { return aCrossedOut
; }
199 const SvxContourItem
& GetContour() const { return aContour
; }
200 const SvxShadowedItem
& GetShadowed() const { return aShadowed
; }
201 const SvxColorItem
& GetColor() const { return aColor
; }
202 const SvxHorJustifyItem
& GetHorJustify() const { return aHorJustify
; }
203 const SvxVerJustifyItem
& GetVerJustify() const { return aVerJustify
; }
204 const SfxBoolItem
& GetStacked() const { return aStacked
; }
205 const SfxBoolItem
& GetLinebreak() const { return aLinebreak
; }
206 const SvxMarginItem
& GetMargin() const { return aMargin
; }
207 const SvxBoxItem
& GetBox() const { return aBox
; }
208 const SvxLineItem
& GetTLBR() const { return aTLBR
; }
209 const SvxLineItem
& GetBLTR() const { return aBLTR
; }
210 const SvxBrushItem
& GetBackground() const { return aBackground
; }
211 const SvxAdjustItem
& GetAdjust() const { return aAdjust
; }
212 const SfxInt32Item
& GetRotateAngle() const { return aRotateAngle
; }
213 const SvxRotateModeItem
& GetRotateMode() const { return aRotateMode
; }
215 void SetNumFormat( const ScNumFormatAbbrev
& rNumFormat
) { aNumFormat
= rNumFormat
; }
216 void SetFont( const SvxFontItem
& rFont
) { aFont
= rFont
; }
217 void SetHeight( const SvxFontHeightItem
& rHeight
) { aHeight
= rHeight
; }
218 void SetWeight( const SvxWeightItem
& rWeight
) { aWeight
= rWeight
; }
219 void SetPosture( const SvxPostureItem
& rPosture
) { aPosture
= rPosture
; }
220 void SetCJKFont( const SvxFontItem
& rCJKFont
) { aCJKFont
= rCJKFont
; }
221 void SetCJKHeight( const SvxFontHeightItem
& rCJKHeight
) { aCJKHeight
= rCJKHeight
; }
222 void SetCJKWeight( const SvxWeightItem
& rCJKWeight
) { aCJKWeight
= rCJKWeight
; }
223 void SetCJKPosture( const SvxPostureItem
& rCJKPosture
) { aCJKPosture
= rCJKPosture
; }
224 void SetCTLFont( const SvxFontItem
& rCTLFont
) { aCTLFont
= rCTLFont
; }
225 void SetCTLHeight( const SvxFontHeightItem
& rCTLHeight
) { aCTLHeight
= rCTLHeight
; }
226 void SetCTLWeight( const SvxWeightItem
& rCTLWeight
) { aCTLWeight
= rCTLWeight
; }
227 void SetCTLPosture( const SvxPostureItem
& rCTLPosture
) { aCTLPosture
= rCTLPosture
; }
228 void SetUnderline( const SvxUnderlineItem
& rUnderline
) { aUnderline
= rUnderline
; }
229 void SetOverline( const SvxOverlineItem
& rOverline
) { aOverline
= rOverline
; }
230 void SetCrossedOut( const SvxCrossedOutItem
& rCrossedOut
) { aCrossedOut
= rCrossedOut
; }
231 void SetContour( const SvxContourItem
& rContour
) { aContour
= rContour
; }
232 void SetShadowed( const SvxShadowedItem
& rShadowed
) { aShadowed
= rShadowed
; }
233 void SetColor( const SvxColorItem
& rColor
) { aColor
= rColor
; }
234 void SetHorJustify( const SvxHorJustifyItem
& rHorJustify
) { aHorJustify
= rHorJustify
; }
235 void SetVerJustify( const SvxVerJustifyItem
& rVerJustify
) { aVerJustify
= rVerJustify
; }
236 void SetStacked( const SfxBoolItem
& rStacked
) { aStacked
.SetValue( rStacked
.GetValue() ); }
237 void SetLinebreak( const SfxBoolItem
& rLinebreak
) { aLinebreak
.SetValue( rLinebreak
.GetValue() ); }
238 void SetMargin( const SvxMarginItem
& rMargin
) { aMargin
= rMargin
; }
239 void SetBox( const SvxBoxItem
& rBox
) { aBox
= rBox
; }
240 void SetTLBR( const SvxLineItem
& rTLBR
) { aTLBR
= rTLBR
; }
241 void SetBLTR( const SvxLineItem
& rBLTR
) { aBLTR
= rBLTR
; }
242 void SetBackground( const SvxBrushItem
& rBackground
) { aBackground
= rBackground
; }
243 void SetAdjust( const SvxAdjustItem
& rAdjust
);
244 void SetRotateAngle( const SfxInt32Item
& rRotateAngle
) { aRotateAngle
.SetValue( rRotateAngle
.GetValue() ); }
245 void SetRotateMode( const SvxRotateModeItem
& rRotateMode
) { aRotateMode
.SetValue( rRotateMode
.GetValue() ); }
247 bool Load( SvStream
& rStream
, const ScAfVersions
& rVersions
, sal_uInt16 nVer
);
248 bool Save( SvStream
& rStream
, sal_uInt16 fileVersion
);
252 class SC_DLLPUBLIC ScAutoFormatData
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;
277 ScAutoFormatData( const ScAutoFormatData
& rData
);
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 class SC_DLLPUBLIC ScAutoFormat
314 typedef boost::ptr_map
<OUString
, ScAutoFormatData
> MapType
;
317 ScAfVersions m_aVersions
;
320 typedef MapType::const_iterator const_iterator
;
321 typedef MapType::iterator iterator
;
324 ScAutoFormat(const ScAutoFormat
& r
);
329 void SetSaveLater( bool bSet
);
330 bool IsSaveLater() const { return mbSaveLater
; }
332 const ScAutoFormatData
* findByIndex(size_t nIndex
) const;
333 ScAutoFormatData
* findByIndex(size_t nIndex
);
334 const_iterator
find(const ScAutoFormatData
* pData
) const;
335 iterator
find(const ScAutoFormatData
* pData
);
336 const_iterator
find(const OUString
& rName
) const;
337 iterator
find(const OUString
& rName
);
339 bool insert(ScAutoFormatData
* pNew
);
340 void erase(const iterator
& it
);
343 const_iterator
begin() const;
344 const_iterator
end() const;
352 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */