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 <svx/autoformathelper.hxx>
50 #include <svl/intitem.hxx>
51 #include <editeng/lineitem.hxx>
53 #include "zforauto.hxx"
63 A binary blob of writer-specific data. This data typically consists of types that are
64 unavailable to Calc (e.g. SwFmtVertOrient), or that Calc doesn't care about.
66 @remarks Note that in autoformat versions prior to AUTOFORMAT_DATA_ID_31005, Calc
67 logic handled and stored several writer-specific items (such as ScAutoFormatDataField::aAdjust).
68 That logic was preserved. From _31005 onward, writer-specific data should be handled by
69 blobs to avoid needlessly complicating the Calc logic.
71 struct AutoFormatSwBlob
73 std::unique_ptr
<sal_uInt8
[]> pData
;
76 AutoFormatSwBlob() : size(0)
79 AutoFormatSwBlob(const AutoFormatSwBlob
&) = delete;
80 const AutoFormatSwBlob
& operator=(const AutoFormatSwBlob
&) = delete;
89 /// Struct with version numbers of the Items
90 struct ScAfVersions
: public AutoFormatVersions
93 AutoFormatSwBlob swVersions
;
97 void Load( SvStream
& rStream
, sal_uInt16 nVer
);
98 void Write(SvStream
& rStream
, sal_uInt16 fileVersion
);
101 /// Contains all items for one cell of a table autoformat.
102 class ScAutoFormatDataField
: public AutoFormatBase
105 AutoFormatSwBlob m_swFields
;
108 ScNumFormatAbbrev aNumFormat
;
111 ScAutoFormatDataField();
112 ScAutoFormatDataField( const ScAutoFormatDataField
& rCopy
);
113 ~ScAutoFormatDataField();
115 // block assignment operator
116 ScAutoFormatDataField
& operator=(const ScAutoFormatDataField
& rRef
) = delete;
119 const ScNumFormatAbbrev
& GetNumFormat() const { return aNumFormat
; }
122 void SetNumFormat( const ScNumFormatAbbrev
& rNumFormat
) { aNumFormat
= rNumFormat
; }
124 bool Load( SvStream
& rStream
, const ScAfVersions
& rVersions
, sal_uInt16 nVer
);
125 bool Save( SvStream
& rStream
, sal_uInt16 fileVersion
);
128 class SC_DLLPUBLIC ScAutoFormatData
132 sal_uInt16 nStrResId
;
133 // common flags of Calc and Writer
134 bool bIncludeFont
: 1;
135 bool bIncludeJustify
: 1;
136 bool bIncludeFrame
: 1;
137 bool bIncludeBackground
: 1;
139 // Calc specific flags
140 bool bIncludeValueFormat
: 1;
141 bool bIncludeWidthHeight
: 1;
143 // Writer-specific data
144 AutoFormatSwBlob m_swFields
;
146 std::array
<std::unique_ptr
<ScAutoFormatDataField
>,16> ppDataField
;
148 SAL_DLLPRIVATE ScAutoFormatDataField
& GetField( sal_uInt16 nIndex
);
149 SAL_DLLPRIVATE
const ScAutoFormatDataField
& GetField( sal_uInt16 nIndex
) const;
153 ScAutoFormatData( const ScAutoFormatData
& rData
);
156 void SetName( const OUString
& rName
) { aName
= rName
; nStrResId
= USHRT_MAX
; }
157 const OUString
& GetName() const { return aName
; }
159 bool GetIncludeValueFormat() const { return bIncludeValueFormat
; }
160 bool GetIncludeFont() const { return bIncludeFont
; }
161 bool GetIncludeJustify() const { return bIncludeJustify
; }
162 bool GetIncludeFrame() const { return bIncludeFrame
; }
163 bool GetIncludeBackground() const { return bIncludeBackground
; }
164 bool GetIncludeWidthHeight() const { return bIncludeWidthHeight
; }
166 void SetIncludeValueFormat( bool bValueFormat
) { bIncludeValueFormat
= bValueFormat
; }
167 void SetIncludeFont( bool bFont
) { bIncludeFont
= bFont
; }
168 void SetIncludeJustify( bool bJustify
) { bIncludeJustify
= bJustify
; }
169 void SetIncludeFrame( bool bFrame
) { bIncludeFrame
= bFrame
; }
170 void SetIncludeBackground( bool bBackground
) { bIncludeBackground
= bBackground
; }
171 void SetIncludeWidthHeight( bool bWidthHeight
) { bIncludeWidthHeight
= bWidthHeight
; }
173 const SfxPoolItem
* GetItem( sal_uInt16 nIndex
, sal_uInt16 nWhich
) const;
174 template<class T
> const T
* GetItem( sal_uInt16 nIndex
, TypedWhichId
<T
> nWhich
) const
176 return static_cast<const T
*>(GetItem(nIndex
, sal_uInt16(nWhich
)));
178 void PutItem( sal_uInt16 nIndex
, const SfxPoolItem
& rItem
);
179 void CopyItem( sal_uInt16 nToIndex
, sal_uInt16 nFromIndex
, sal_uInt16 nWhich
);
181 const ScNumFormatAbbrev
& GetNumFormat( sal_uInt16 nIndex
) const;
183 bool IsEqualData( sal_uInt16 nIndex1
, sal_uInt16 nIndex2
) const;
185 void FillToItemSet( sal_uInt16 nIndex
, SfxItemSet
& rItemSet
, const ScDocument
& rDoc
) const;
186 void GetFromItemSet( sal_uInt16 nIndex
, const SfxItemSet
& rItemSet
, const ScNumFormatAbbrev
& rNumFormat
);
188 bool Load( SvStream
& rStream
, const ScAfVersions
& rVersions
);
189 bool Save( SvStream
& rStream
, sal_uInt16 fileVersion
);
192 struct DefaultFirstEntry
{
193 bool operator() (const OUString
& left
, const OUString
& right
) const;
196 class SC_DLLPUBLIC ScAutoFormat
198 typedef std::map
<OUString
, std::unique_ptr
<ScAutoFormatData
>, DefaultFirstEntry
> MapType
;
201 ScAfVersions m_aVersions
;
203 ScAutoFormat(const ScAutoFormat
&) = delete;
204 const ScAutoFormat
operator=(const ScAutoFormat
&) = delete;
207 typedef MapType::const_iterator const_iterator
;
208 typedef MapType::iterator iterator
;
214 void SetSaveLater( bool bSet
);
215 bool IsSaveLater() const { return mbSaveLater
; }
217 const ScAutoFormatData
* findByIndex(size_t nIndex
) const;
218 ScAutoFormatData
* findByIndex(size_t nIndex
);
219 iterator
find(const OUString
& rName
);
221 iterator
insert(std::unique_ptr
<ScAutoFormatData
> pNew
);
222 void erase(const iterator
& it
);
225 const_iterator
begin() const;
226 const_iterator
end() const;
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */