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 .
22 /*************************************************************************
23 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
25 The structure of auto formatting should not be changed. It is used
26 by various code of Writer and Calc. If a change is necessary, the
27 source code of both applications must be changed!
29 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
30 **************************************************************************/
32 #include <svl/poolitem.hxx>
33 #include <svx/autoformathelper.hxx>
36 #include "zforauto.hxx"
46 A binary blob of writer-specific data. This data typically consists of types that are
47 unavailable to Calc (e.g. SwFmtVertOrient), or that Calc doesn't care about.
49 @remarks Note that in autoformat versions prior to AUTOFORMAT_DATA_ID_31005, Calc
50 logic handled and stored several writer-specific items (such as ScAutoFormatDataField::aAdjust).
51 That logic was preserved. From _31005 onward, writer-specific data should be handled by
52 blobs to avoid needlessly complicating the Calc logic.
54 struct AutoFormatSwBlob
56 std::unique_ptr
<sal_uInt8
[]> pData
;
59 AutoFormatSwBlob() : size(0)
62 AutoFormatSwBlob(const AutoFormatSwBlob
&) = delete;
63 const AutoFormatSwBlob
& operator=(const AutoFormatSwBlob
&) = delete;
72 /// Struct with version numbers of the Items
73 struct ScAfVersions
: public AutoFormatVersions
76 AutoFormatSwBlob swVersions
;
81 void Load( SvStream
& rStream
, sal_uInt16 nVer
);
82 void Write(SvStream
& rStream
, sal_uInt16 fileVersion
);
85 /// Contains all items for one cell of a table autoformat.
86 class ScAutoFormatDataField
: public AutoFormatBase
89 AutoFormatSwBlob m_swFields
;
92 ScNumFormatAbbrev aNumFormat
;
95 ScAutoFormatDataField();
96 ScAutoFormatDataField( const ScAutoFormatDataField
& rCopy
);
97 ~ScAutoFormatDataField();
99 // block assignment operator
100 ScAutoFormatDataField
& operator=(const ScAutoFormatDataField
& rRef
) = delete;
103 const ScNumFormatAbbrev
& GetNumFormat() const { return aNumFormat
; }
106 void SetNumFormat( const ScNumFormatAbbrev
& rNumFormat
) { aNumFormat
= rNumFormat
; }
108 bool Load( SvStream
& rStream
, const ScAfVersions
& rVersions
, sal_uInt16 nVer
);
109 bool Save( SvStream
& rStream
, sal_uInt16 fileVersion
);
112 class SC_DLLPUBLIC ScAutoFormatData
116 sal_uInt16 nStrResId
;
117 // common flags of Calc and Writer
118 bool bIncludeFont
: 1;
119 bool bIncludeJustify
: 1;
120 bool bIncludeFrame
: 1;
121 bool bIncludeBackground
: 1;
123 // Calc specific flags
124 bool bIncludeValueFormat
: 1;
125 bool bIncludeWidthHeight
: 1;
127 // Writer-specific data
128 AutoFormatSwBlob m_swFields
;
130 std::array
<std::unique_ptr
<ScAutoFormatDataField
>,16> ppDataField
;
132 SAL_DLLPRIVATE ScAutoFormatDataField
& GetField( sal_uInt16 nIndex
);
133 SAL_DLLPRIVATE
const ScAutoFormatDataField
& GetField( sal_uInt16 nIndex
) const;
137 ScAutoFormatData( const ScAutoFormatData
& rData
);
140 void SetName( const OUString
& rName
) { aName
= rName
; nStrResId
= USHRT_MAX
; }
141 const OUString
& GetName() const { return aName
; }
143 bool GetIncludeValueFormat() const { return bIncludeValueFormat
; }
144 bool GetIncludeFont() const { return bIncludeFont
; }
145 bool GetIncludeJustify() const { return bIncludeJustify
; }
146 bool GetIncludeFrame() const { return bIncludeFrame
; }
147 bool GetIncludeBackground() const { return bIncludeBackground
; }
148 bool GetIncludeWidthHeight() const { return bIncludeWidthHeight
; }
150 void SetIncludeValueFormat( bool bValueFormat
) { bIncludeValueFormat
= bValueFormat
; }
151 void SetIncludeFont( bool bFont
) { bIncludeFont
= bFont
; }
152 void SetIncludeJustify( bool bJustify
) { bIncludeJustify
= bJustify
; }
153 void SetIncludeFrame( bool bFrame
) { bIncludeFrame
= bFrame
; }
154 void SetIncludeBackground( bool bBackground
) { bIncludeBackground
= bBackground
; }
155 void SetIncludeWidthHeight( bool bWidthHeight
) { bIncludeWidthHeight
= bWidthHeight
; }
157 const SfxPoolItem
* GetItem( sal_uInt16 nIndex
, sal_uInt16 nWhich
) const;
158 template<class T
> const T
* GetItem( sal_uInt16 nIndex
, TypedWhichId
<T
> nWhich
) const
160 return static_cast<const T
*>(GetItem(nIndex
, sal_uInt16(nWhich
)));
162 void PutItem( sal_uInt16 nIndex
, const SfxPoolItem
& rItem
);
163 void CopyItem( sal_uInt16 nToIndex
, sal_uInt16 nFromIndex
, sal_uInt16 nWhich
);
165 const ScNumFormatAbbrev
& GetNumFormat( sal_uInt16 nIndex
) const;
167 bool HasSameData( sal_uInt16 nIndex1
, sal_uInt16 nIndex2
) const;
169 void FillToItemSet( sal_uInt16 nIndex
, SfxItemSet
& rItemSet
, const ScDocument
& rDoc
) const;
170 void GetFromItemSet( sal_uInt16 nIndex
, const SfxItemSet
& rItemSet
, const ScNumFormatAbbrev
& rNumFormat
);
172 bool Load( SvStream
& rStream
, const ScAfVersions
& rVersions
);
173 bool Save( SvStream
& rStream
, sal_uInt16 fileVersion
);
176 struct DefaultFirstEntry
{
177 bool operator() (const OUString
& left
, const OUString
& right
) const;
180 class SC_DLLPUBLIC ScAutoFormat
182 typedef std::map
<OUString
, std::unique_ptr
<ScAutoFormatData
>, DefaultFirstEntry
> MapType
;
185 ScAfVersions m_aVersions
;
187 ScAutoFormat(const ScAutoFormat
&) = delete;
188 const ScAutoFormat
operator=(const ScAutoFormat
&) = delete;
191 typedef MapType::const_iterator const_iterator
;
192 typedef MapType::iterator iterator
;
198 void SetSaveLater( bool bSet
);
199 bool IsSaveLater() const { return mbSaveLater
; }
201 const ScAutoFormatData
* findByIndex(size_t nIndex
) const;
202 ScAutoFormatData
* findByIndex(size_t nIndex
);
203 iterator
find(const OUString
& rName
);
205 iterator
insert(std::unique_ptr
<ScAutoFormatData
> pNew
);
206 void erase(const iterator
& it
);
209 const_iterator
begin() const;
210 const_iterator
end() const;
215 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */