update credits
[LibreOffice.git] / sc / inc / autoform.hxx
bloba0831161dd1b4d5df5cb1504c162d2e5ead72812
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 "global.hxx"
59 #include "zforauto.hxx"
61 #include <boost/ptr_container/ptr_map.hpp>
63 /**
64 A binary blob of writer-specific data. This data typically consists of types that are
65 unavailable to Calc (e.g. SwFmtVertOrient), or that Calc doesn't care about.
67 @remarks Note that in autoformat versions prior to AUTOFORMAT_DATA_ID_31005, Calc
68 logic handled and stored several writer-specific items (such as ScAutoFormatDataField::aAdjust).
69 That logic was preserved. From _31005 onward, writer-specific data should be handled by
70 blobs to avoid needlessly complicating the Calc logic.
72 struct AutoFormatSwBlob : ::boost::noncopyable
74 sal_uInt8 *pData;
75 sal_Size size;
77 AutoFormatSwBlob() : pData(0), size(0)
81 ~AutoFormatSwBlob()
83 Reset();
86 void Reset()
88 delete[] pData;
89 pData = 0;
90 size = 0;
94 /// Struct with version numbers of the Items
95 struct ScAfVersions
97 public:
98 sal_uInt16 nFontVersion;
99 sal_uInt16 nFontHeightVersion;
100 sal_uInt16 nWeightVersion;
101 sal_uInt16 nPostureVersion;
102 sal_uInt16 nUnderlineVersion;
103 sal_uInt16 nOverlineVersion;
104 sal_uInt16 nCrossedOutVersion;
105 sal_uInt16 nContourVersion;
106 sal_uInt16 nShadowedVersion;
107 sal_uInt16 nColorVersion;
108 sal_uInt16 nBoxVersion;
109 sal_uInt16 nLineVersion;
110 sal_uInt16 nBrushVersion;
112 sal_uInt16 nAdjustVersion;
113 AutoFormatSwBlob swVersions;
115 sal_uInt16 nHorJustifyVersion;
116 sal_uInt16 nVerJustifyVersion;
117 sal_uInt16 nOrientationVersion;
118 sal_uInt16 nMarginVersion;
119 sal_uInt16 nBoolVersion;
120 sal_uInt16 nInt32Version;
121 sal_uInt16 nRotateModeVersion;
123 sal_uInt16 nNumFmtVersion;
125 ScAfVersions();
126 void Load( SvStream& rStream, sal_uInt16 nVer );
127 void Write(SvStream& rStream, sal_uInt16 fileVersion);
130 /// Contains all items for one cell of a table autoformat.
131 class ScAutoFormatDataField
133 private:
134 SvxFontItem aFont;
135 SvxFontHeightItem aHeight;
136 SvxWeightItem aWeight;
137 SvxPostureItem aPosture;
139 SvxFontItem aCJKFont;
140 SvxFontHeightItem aCJKHeight;
141 SvxWeightItem aCJKWeight;
142 SvxPostureItem aCJKPosture;
144 SvxFontItem aCTLFont;
145 SvxFontHeightItem aCTLHeight;
146 SvxWeightItem aCTLWeight;
147 SvxPostureItem aCTLPosture;
149 SvxUnderlineItem aUnderline;
150 SvxOverlineItem aOverline;
151 SvxCrossedOutItem aCrossedOut;
152 SvxContourItem aContour;
153 SvxShadowedItem aShadowed;
154 SvxColorItem aColor;
155 SvxBoxItem aBox;
156 SvxLineItem aTLBR;
157 SvxLineItem aBLTR;
158 SvxBrushItem aBackground;
160 // Writer specific
161 SvxAdjustItem aAdjust;
162 AutoFormatSwBlob m_swFields;
164 // Calc specific
165 SvxHorJustifyItem aHorJustify;
166 SvxVerJustifyItem aVerJustify;
167 SfxBoolItem aStacked;
168 SvxMarginItem aMargin;
169 SfxBoolItem aLinebreak;
170 // from SO5, 504k on, rotated text
171 SfxInt32Item aRotateAngle;
172 SvxRotateModeItem aRotateMode;
174 // number format
175 ScNumFormatAbbrev aNumFormat;
177 public:
178 ScAutoFormatDataField();
179 ScAutoFormatDataField( const ScAutoFormatDataField& rCopy );
180 ~ScAutoFormatDataField();
182 const ScNumFormatAbbrev& GetNumFormat() const { return aNumFormat; }
183 const SvxFontItem& GetFont() const { return aFont; }
184 const SvxFontHeightItem& GetHeight() const { return aHeight; }
185 const SvxWeightItem& GetWeight() const { return aWeight; }
186 const SvxPostureItem& GetPosture() const { return aPosture; }
187 const SvxFontItem& GetCJKFont() const { return aCJKFont; }
188 const SvxFontHeightItem& GetCJKHeight() const { return aCJKHeight; }
189 const SvxWeightItem& GetCJKWeight() const { return aCJKWeight; }
190 const SvxPostureItem& GetCJKPosture() const { return aCJKPosture; }
191 const SvxFontItem& GetCTLFont() const { return aCTLFont; }
192 const SvxFontHeightItem& GetCTLHeight() const { return aCTLHeight; }
193 const SvxWeightItem& GetCTLWeight() const { return aCTLWeight; }
194 const SvxPostureItem& GetCTLPosture() const { return aCTLPosture; }
195 const SvxUnderlineItem& GetUnderline() const { return aUnderline; }
196 const SvxOverlineItem& GetOverline() const { return aOverline; }
197 const SvxCrossedOutItem& GetCrossedOut() const { return aCrossedOut; }
198 const SvxContourItem& GetContour() const { return aContour; }
199 const SvxShadowedItem& GetShadowed() const { return aShadowed; }
200 const SvxColorItem& GetColor() const { return aColor; }
201 const SvxHorJustifyItem& GetHorJustify() const { return aHorJustify; }
202 const SvxVerJustifyItem& GetVerJustify() const { return aVerJustify; }
203 const SfxBoolItem& GetStacked() const { return aStacked; }
204 const SfxBoolItem& GetLinebreak() const { return aLinebreak; }
205 const SvxMarginItem& GetMargin() const { return aMargin; }
206 const SvxBoxItem& GetBox() const { return aBox; }
207 const SvxLineItem& GetTLBR() const { return aTLBR; }
208 const SvxLineItem& GetBLTR() const { return aBLTR; }
209 const SvxBrushItem& GetBackground() const { return aBackground; }
210 const SvxAdjustItem& GetAdjust() const { return aAdjust; }
211 const SfxInt32Item& GetRotateAngle() const { return aRotateAngle; }
212 const SvxRotateModeItem& GetRotateMode() const { return aRotateMode; }
214 void SetNumFormat( const ScNumFormatAbbrev& rNumFormat ) { aNumFormat = rNumFormat; }
215 void SetFont( const SvxFontItem& rFont ) { aFont = rFont; }
216 void SetHeight( const SvxFontHeightItem& rHeight ) { aHeight = rHeight; }
217 void SetWeight( const SvxWeightItem& rWeight ) { aWeight = rWeight; }
218 void SetPosture( const SvxPostureItem& rPosture ) { aPosture = rPosture; }
219 void SetCJKFont( const SvxFontItem& rCJKFont ) { aCJKFont = rCJKFont; }
220 void SetCJKHeight( const SvxFontHeightItem& rCJKHeight ) { aCJKHeight = rCJKHeight; }
221 void SetCJKWeight( const SvxWeightItem& rCJKWeight ) { aCJKWeight = rCJKWeight; }
222 void SetCJKPosture( const SvxPostureItem& rCJKPosture ) { aCJKPosture = rCJKPosture; }
223 void SetCTLFont( const SvxFontItem& rCTLFont ) { aCTLFont = rCTLFont; }
224 void SetCTLHeight( const SvxFontHeightItem& rCTLHeight ) { aCTLHeight = rCTLHeight; }
225 void SetCTLWeight( const SvxWeightItem& rCTLWeight ) { aCTLWeight = rCTLWeight; }
226 void SetCTLPosture( const SvxPostureItem& rCTLPosture ) { aCTLPosture = rCTLPosture; }
227 void SetUnderline( const SvxUnderlineItem& rUnderline ) { aUnderline = rUnderline; }
228 void SetOverline( const SvxOverlineItem& rOverline ) { aOverline = rOverline; }
229 void SetCrossedOut( const SvxCrossedOutItem& rCrossedOut ) { aCrossedOut = rCrossedOut; }
230 void SetContour( const SvxContourItem& rContour ) { aContour = rContour; }
231 void SetShadowed( const SvxShadowedItem& rShadowed ) { aShadowed = rShadowed; }
232 void SetColor( const SvxColorItem& rColor ) { aColor = rColor; }
233 void SetHorJustify( const SvxHorJustifyItem& rHorJustify ) { aHorJustify = rHorJustify; }
234 void SetVerJustify( const SvxVerJustifyItem& rVerJustify ) { aVerJustify = rVerJustify; }
235 void SetStacked( const SfxBoolItem& rStacked ) { aStacked.SetValue( rStacked.GetValue() ); }
236 void SetLinebreak( const SfxBoolItem& rLinebreak ) { aLinebreak.SetValue( rLinebreak.GetValue() ); }
237 void SetMargin( const SvxMarginItem& rMargin ) { aMargin = rMargin; }
238 void SetBox( const SvxBoxItem& rBox ) { aBox = rBox; }
239 void SetTLBR( const SvxLineItem& rTLBR ) { aTLBR = rTLBR; }
240 void SetBLTR( const SvxLineItem& rBLTR ) { aBLTR = rBLTR; }
241 void SetBackground( const SvxBrushItem& rBackground ) { aBackground = rBackground; }
242 void SetAdjust( const SvxAdjustItem& rAdjust );
243 void SetRotateAngle( const SfxInt32Item& rRotateAngle ) { aRotateAngle.SetValue( rRotateAngle.GetValue() ); }
244 void SetRotateMode( const SvxRotateModeItem& rRotateMode ) { aRotateMode.SetValue( rRotateMode.GetValue() ); }
246 bool Load( SvStream& rStream, const ScAfVersions& rVersions, sal_uInt16 nVer );
247 bool Save( SvStream& rStream, sal_uInt16 fileVersion );
250 class SC_DLLPUBLIC ScAutoFormatData
252 private:
253 OUString aName;
254 sal_uInt16 nStrResId;
255 // common flags of Calc and Writer
256 bool bIncludeFont : 1;
257 bool bIncludeJustify : 1;
258 bool bIncludeFrame : 1;
259 bool bIncludeBackground : 1;
261 // Calc specific flags
262 bool bIncludeValueFormat : 1;
263 bool bIncludeWidthHeight : 1;
265 // Writer-specific data
266 AutoFormatSwBlob m_swFields;
268 ScAutoFormatDataField** ppDataField;
270 SAL_DLLPRIVATE ScAutoFormatDataField& GetField( sal_uInt16 nIndex );
271 SAL_DLLPRIVATE const ScAutoFormatDataField& GetField( sal_uInt16 nIndex ) const;
273 public:
274 ScAutoFormatData();
275 ScAutoFormatData( const ScAutoFormatData& rData );
276 ~ScAutoFormatData();
278 void SetName( const OUString& rName ) { aName = rName; nStrResId = USHRT_MAX; }
279 const OUString& GetName() const { return aName; }
281 bool GetIncludeValueFormat() const { return bIncludeValueFormat; }
282 bool GetIncludeFont() const { return bIncludeFont; }
283 bool GetIncludeJustify() const { return bIncludeJustify; }
284 bool GetIncludeFrame() const { return bIncludeFrame; }
285 bool GetIncludeBackground() const { return bIncludeBackground; }
286 bool GetIncludeWidthHeight() const { return bIncludeWidthHeight; }
288 void SetIncludeValueFormat( bool bValueFormat ) { bIncludeValueFormat = bValueFormat; }
289 void SetIncludeFont( bool bFont ) { bIncludeFont = bFont; }
290 void SetIncludeJustify( bool bJustify ) { bIncludeJustify = bJustify; }
291 void SetIncludeFrame( bool bFrame ) { bIncludeFrame = bFrame; }
292 void SetIncludeBackground( bool bBackground ) { bIncludeBackground = bBackground; }
293 void SetIncludeWidthHeight( bool bWidthHeight ) { bIncludeWidthHeight = bWidthHeight; }
295 const SfxPoolItem* GetItem( sal_uInt16 nIndex, sal_uInt16 nWhich ) const;
296 void PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem );
297 void CopyItem( sal_uInt16 nToIndex, sal_uInt16 nFromIndex, sal_uInt16 nWhich );
299 const ScNumFormatAbbrev& GetNumFormat( sal_uInt16 nIndex ) const;
301 bool IsEqualData( sal_uInt16 nIndex1, sal_uInt16 nIndex2 ) const;
303 void FillToItemSet( sal_uInt16 nIndex, SfxItemSet& rItemSet, ScDocument& rDoc ) const;
304 void GetFromItemSet( sal_uInt16 nIndex, const SfxItemSet& rItemSet, const ScNumFormatAbbrev& rNumFormat );
306 bool Load( SvStream& rStream, const ScAfVersions& rVersions );
307 bool Save( SvStream& rStream, sal_uInt16 fileVersion );
310 struct DefaultFirstEntry {
311 bool operator() (const OUString& left, const OUString& right) const;
314 class SC_DLLPUBLIC ScAutoFormat
316 typedef boost::ptr_map<OUString, ScAutoFormatData, DefaultFirstEntry> MapType;
317 MapType maData;
318 bool mbSaveLater;
319 ScAfVersions m_aVersions;
321 public:
322 typedef MapType::const_iterator const_iterator;
323 typedef MapType::iterator iterator;
325 ScAutoFormat();
326 ScAutoFormat(const ScAutoFormat& r);
327 ~ScAutoFormat();
328 bool Load();
329 bool Save();
331 void SetSaveLater( bool bSet );
332 bool IsSaveLater() const { return mbSaveLater; }
334 const ScAutoFormatData* findByIndex(size_t nIndex) const;
335 ScAutoFormatData* findByIndex(size_t nIndex);
336 const_iterator find(const ScAutoFormatData* pData) const;
337 iterator find(const ScAutoFormatData* pData);
338 const_iterator find(const OUString& rName) const;
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: */