LibreOffice Module sw (master) 1
tblafmt.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#ifndef INCLUDED_SW_INC_TBLAFMT_HXX
20#define INCLUDED_SW_INC_TBLAFMT_HXX
21/*
22 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
23 *
24 * The structure of table auto formatting should not be changed. It is used
25 * by different code of Writer and Calc. If a change is necessary, the
26 * source code of both applications must be changed!
27 *
28 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
29 */
30
31#include <memory>
32
33#include <editeng/keepitem.hxx>
35#include <editeng/shaditem.hxx>
37#include <unotools/weakref.hxx>
38#include <rtl/ref.hxx>
39#include "fmtornt.hxx"
40#include "swdllapi.h"
41
42struct SwAfVersions;
43
45class SwTable;
48
50{
51private:
52 // Writer specific
53 std::unique_ptr<SvxFrameDirectionItem> m_aTextOrientation;
54 std::unique_ptr<SwFormatVertOrient> m_aVerticalAlignment;
55
56 // number format
60
61 // associated UNO object, if such exists
63
64public:
66 SwBoxAutoFormat( const SwBoxAutoFormat& rNew );
68
71
73 bool operator==(const SwBoxAutoFormat& rRight) const;
74
75 // The get-methods.
76 const SvxFrameDirectionItem& GetTextOrientation() const { return *m_aTextOrientation; }
77 const SwFormatVertOrient& GetVerticalAlignment() const { return *m_aVerticalAlignment; }
78
79 void GetValueFormat( OUString& rFormat, LanguageType& rLng, LanguageType& rSys ) const
80 { rFormat = m_sNumFormatString; rLng = m_eNumFormatLanguage; rSys = m_eSysLanguage; }
81
82 const OUString& GetNumFormatString() const { return m_sNumFormatString; }
83 const LanguageType& GetSysLanguage() const { return m_eSysLanguage; }
84 const LanguageType& GetNumFormatLanguage() const { return m_eNumFormatLanguage; }
85
86 // The set-methods.
87 void SetTextOrientation( const SvxFrameDirectionItem& rNew ) { m_aTextOrientation.reset(rNew.Clone()); }
88 void SetVerticalAlignment( const SwFormatVertOrient& rNew ) { m_aVerticalAlignment.reset(rNew.Clone()); }
89
90 void SetValueFormat( const OUString& rFormat, LanguageType eLng, LanguageType eSys )
91 { m_sNumFormatString = rFormat; m_eNumFormatLanguage = eLng; m_eSysLanguage = eSys; }
92
93 void SetNumFormatString(const OUString& rNew) { m_sNumFormatString = rNew; }
94 void SetSysLanguage(const LanguageType& rNew) { m_eSysLanguage = rNew; }
95 void SetNumFormatLanguage(const LanguageType& rNew) { m_eNumFormatLanguage = rNew; }
96
98 { return m_xAutoFormatUnoObject; }
99 void SetXObject(rtl::Reference<SwXTextCellStyle> const& xObject);
100
101 bool Load( SvStream& rStream, const SwAfVersions& rVersions, sal_uInt16 nVer );
102 bool Save( SvStream& rStream, sal_uInt16 fileVersion ) const;
103};
104
105enum class SwTableAutoFormatUpdateFlags { Char = 1, Box = 2 };
106namespace o3tl {
107 template<> struct typed_flags<SwTableAutoFormatUpdateFlags> : is_typed_flags<SwTableAutoFormatUpdateFlags, 0x03> {};
108};
109
110/*
111@remarks
112A table has a number of lines. These lines seem to correspond with rows, except in the case of
113rows spanning more than one line. Each line contains a number of boxes/cells.
114
115AutoFormat properties are retrieved and stored in a grid of 16 table boxes. A sampling approach
116is used to read the data. 4 lines are picked, and 4 boxes are picked from each.
117
118The line picking and box picking algorithms are similar. We start at the first line/box, and pick
119lines/boxes one by one for a maximum of 3. The 4th line/box is the last line/box in the current
120table/line. If we hit the end of lines/boxes, the last line/box encountered is picked several times.
121
122For example, in a 2x3 table, the 4 lines will be [0, 1, 1, 1]. In each line, the boxes will be
123[0, 1, 2, 2]. In a 6x5 table, the 4 lines will be [0, 1, 2, 4] and the boxes per line will be
124[0, 1, 2, 5].
125
126As you can see, property extraction/application is lossless for tables that are 4x4 or smaller
127(and in fact has a bit of redundancy). For larger tables, we lose any individual cell formatting
128for the range [(3,rows - 1) -> (3, cols - 1)]. That formatting is replaced by formatting from
129the saved cells:
130
131 0 1 2 3 4 5
132 +-----------------------------------------------------------------------+
133 0 | Saved | Saved | Saved | | | Saved |
134 +-----------------------------------------------------------------------+
135 1 | Saved | Saved | Saved | | | Saved |
136 +-----------------------------------------------------------------------+
137 2 | Saved | Saved | Saved | | | Saved |
138 +-----------------------------------------------------------------------+
139 3 | | | | | | |
140 +-----------------------------------------------------------------------+
141 4 | | | | | | |
142 +-----------------------------------------------------------------------+
143 5 | Saved | Saved | Saved | | | Saved |
144 +-----------+-----------+-----------+-----------+-----------+-----------+
145
146The properties saved are divided into three categories:
147 1. Character properties: Font, font size, weight, etc.
148 2. Box properties: Box, cell background
149 3. Table properties: Properties that are set in the Table->Table Properties dialog.
150
151Character and box properties are stored per cell (and are lossy for tables larger than 4x4). Table
152properties are stored per-table, and are lossless.
153*/
155{
156 friend class SwDocTest;
157 friend void FinitCore(); // To destroy default pointer.
159
161
162 OUString m_aName;
163 sal_uInt16 m_nStrResId;
164
165 // Common flags of Calc and Writer.
166 bool m_bInclFont : 1;
168 bool m_bInclFrame : 1;
171
172 // Calc specific flags.
174
175 SwBoxAutoFormat* m_aBoxAutoFormat[ 16 ] = {};
176
177 // Writer-specific options
178 std::shared_ptr<SvxFormatKeepItem> m_aKeepWithNextPara;
183 std::shared_ptr<SvxShadowItem> m_aShadow;
184
187public:
188 SwTableAutoFormat( OUString aName );
191
193
194 const SvxFormatKeepItem& GetKeepWithNextPara() const { return *m_aKeepWithNextPara; }
195 const SvxShadowItem& GetShadow() const { return *m_aShadow; }
196
197 void SetKeepWithNextPara(const SvxFormatKeepItem& rNew) { m_aKeepWithNextPara.reset(rNew.Clone()); }
198 void SetShadow(const SvxShadowItem& rNew) { m_aShadow.reset(rNew.Clone()); }
199
200 void SetBoxFormat( const SwBoxAutoFormat& rNew, sal_uInt8 nPos );
201 const SwBoxAutoFormat& GetBoxFormat( sal_uInt8 nPos ) const;
202 SwBoxAutoFormat& GetBoxFormat( sal_uInt8 nPos );
203 static const SwBoxAutoFormat& GetDefaultBoxFormat();
204
205 void SetName( const OUString& rNew ) { m_aName = rNew; m_nStrResId = USHRT_MAX; }
206 const OUString& GetName() const { return m_aName; }
207
208 void UpdateFromSet( sal_uInt8 nPos, const SfxItemSet& rSet,
210 void UpdateToSet( const sal_uInt8 nPos, const bool bSingleRowTable, const bool bSingleColTable,
212 SvNumberFormatter* ) const ;
213
214 void RestoreTableProperties(SwTable &table) const;
215 void StoreTableProperties(const SwTable &table);
216
217 bool IsFont() const { return m_bInclFont; }
218 bool IsJustify() const { return m_bInclJustify; }
219 bool IsFrame() const { return m_bInclFrame; }
220 bool IsBackground() const { return m_bInclBackground; }
221 bool IsValueFormat() const { return m_bInclValueFormat; }
222
224 bool IsHidden() const { return m_bHidden; }
226 bool IsUserDefined() const { return m_bUserDefined; }
227
228 void SetFont( const bool bNew ) { m_bInclFont = bNew; }
229 void SetJustify( const bool bNew ) { m_bInclJustify = bNew; }
230 void SetFrame( const bool bNew ) { m_bInclFrame = bNew; }
231 void SetBackground( const bool bNew ) { m_bInclBackground = bNew; }
232 void SetValueFormat( const bool bNew ) { m_bInclValueFormat = bNew; }
233 void SetWidthHeight( const bool bNew ) { m_bInclWidthHeight = bNew; }
234
236 void SetHidden(bool bHidden) { m_bHidden = bHidden; }
238 void SetUserDefined(bool bUserDefined) { m_bUserDefined = bUserDefined; }
239
241 bool FirstRowEndColumnIsRow();
242 bool FirstRowStartColumnIsRow();
243 bool LastRowEndColumnIsRow();
244 bool LastRowStartColumnIsRow();
245 bool HasHeaderRow() const;
246
247 bool Load( SvStream& rStream, const SwAfVersions& );
248 bool Save( SvStream& rStream, sal_uInt16 fileVersion ) const;
249
251 { return m_xUnoTextTableStyle; }
252 void SetXObject(rtl::Reference<SwXTextTableStyle> const& xObject);
253
255 OUString GetTableTemplateCellSubName(const SwBoxAutoFormat& rBoxFormat) const;
257 static const std::vector<sal_Int32>& GetTableTemplateMap();
258
263 static sal_uInt8 CountPos(sal_uInt32 nCol, sal_uInt32 nCols, sal_uInt32 nRow, sal_uInt32 nRows);
264};
265
267{
268 struct Impl;
269 std::unique_ptr<Impl> m_pImpl;
270
271 SAL_DLLPRIVATE bool Load( SvStream& rStream );
272 SAL_DLLPRIVATE bool Save( SvStream& rStream ) const;
273
274public:
275 explicit SwTableAutoFormatTable();
277
278 size_t size() const;
279 SwTableAutoFormat const& operator[](size_t i) const;
280 SwTableAutoFormat & operator[](size_t i);
281
283 void AddAutoFormat(const SwTableAutoFormat& rFormat);
284
285 void InsertAutoFormat(size_t i, std::unique_ptr<SwTableAutoFormat> pFormat);
286 void EraseAutoFormat(size_t i);
287 void EraseAutoFormat(const OUString& rName);
288 std::unique_ptr<SwTableAutoFormat> ReleaseAutoFormat(size_t i);
290 std::unique_ptr<SwTableAutoFormat> ReleaseAutoFormat(const OUString& rName);
291
293 SwTableAutoFormat* FindAutoFormat(std::u16string_view rName) const;
294
295 void Load();
296 bool Save() const;
297};
298
300{
301 const std::pair<OUString, std::unique_ptr<SwBoxAutoFormat>>& m_rCellStyleDesc;
302public:
303 SwCellStyleDescriptor(const std::pair<OUString, std::unique_ptr<SwBoxAutoFormat>>& rCellStyleDesc) : m_rCellStyleDesc(rCellStyleDesc) { }
304
305 const OUString& GetName() const { return m_rCellStyleDesc.first; }
306};
307
309{
310 std::vector<std::pair<OUString, std::unique_ptr<SwBoxAutoFormat>>> m_aCellStyles;
311public:
314
315 size_t size() const;
316 SwCellStyleDescriptor operator[](size_t i) const;
317 void clear();
318
320 void AddBoxFormat(const SwBoxAutoFormat& rBoxFormat, const OUString& sName);
321 void RemoveBoxFormat(const OUString& sName);
322 void ChangeBoxFormatName(std::u16string_view sFromName, const OUString& sToName);
324 OUString GetBoxFormatName(const SwBoxAutoFormat& rBoxFormat) const;
326 SwBoxAutoFormat* GetBoxFormat(std::u16string_view sName) const;
327};
328
329#endif
330
331/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator==(const AutoFormatBase &rRight) const
AutoFormatBase & operator=(const AutoFormatBase &)
virtual SvxFormatKeepItem * Clone(SfxItemPool *pPool=nullptr) const override
virtual SvxFrameDirectionItem * Clone(SfxItemPool *pPool=nullptr) const override
virtual SvxShadowItem * Clone(SfxItemPool *pPool=nullptr) const override
const OUString & GetNumFormatString() const
Definition: tblafmt.hxx:82
void SetTextOrientation(const SvxFrameDirectionItem &rNew)
Definition: tblafmt.hxx:87
OUString m_sNumFormatString
Definition: tblafmt.hxx:57
const LanguageType & GetNumFormatLanguage() const
Definition: tblafmt.hxx:84
const LanguageType & GetSysLanguage() const
Definition: tblafmt.hxx:83
void GetValueFormat(OUString &rFormat, LanguageType &rLng, LanguageType &rSys) const
Definition: tblafmt.hxx:79
void SetSysLanguage(const LanguageType &rNew)
Definition: tblafmt.hxx:94
std::unique_ptr< SwFormatVertOrient > m_aVerticalAlignment
Definition: tblafmt.hxx:54
void SetNumFormatString(const OUString &rNew)
Definition: tblafmt.hxx:93
std::unique_ptr< SvxFrameDirectionItem > m_aTextOrientation
Definition: tblafmt.hxx:53
const SwFormatVertOrient & GetVerticalAlignment() const
Definition: tblafmt.hxx:77
unotools::WeakReference< SwXTextCellStyle > m_xAutoFormatUnoObject
Definition: tblafmt.hxx:62
LanguageType m_eNumFormatLanguage
Definition: tblafmt.hxx:59
void SetVerticalAlignment(const SwFormatVertOrient &rNew)
Definition: tblafmt.hxx:88
void SetNumFormatLanguage(const LanguageType &rNew)
Definition: tblafmt.hxx:95
LanguageType m_eSysLanguage
Definition: tblafmt.hxx:58
void SetValueFormat(const OUString &rFormat, LanguageType eLng, LanguageType eSys)
Definition: tblafmt.hxx:90
unotools::WeakReference< SwXTextCellStyle > const & GetXObject() const
Definition: tblafmt.hxx:97
const SvxFrameDirectionItem & GetTextOrientation() const
Definition: tblafmt.hxx:76
const std::pair< OUString, std::unique_ptr< SwBoxAutoFormat > > & m_rCellStyleDesc
Definition: tblafmt.hxx:301
const OUString & GetName() const
Definition: tblafmt.hxx:305
SwCellStyleDescriptor(const std::pair< OUString, std::unique_ptr< SwBoxAutoFormat > > &rCellStyleDesc)
Definition: tblafmt.hxx:303
OUString GetBoxFormatName(const SwBoxAutoFormat &rBoxFormat) const
If found returns its name. If not found returns an empty OUString.
Definition: tblafmt.cxx:1215
void ChangeBoxFormatName(std::u16string_view sFromName, const OUString &sToName)
Definition: tblafmt.cxx:1238
size_t size() const
Definition: tblafmt.cxx:1183
void AddBoxFormat(const SwBoxAutoFormat &rBoxFormat, const OUString &sName)
Add a copy of rBoxFormat.
Definition: tblafmt.cxx:1198
SwCellStyleDescriptor operator[](size_t i) const
Definition: tblafmt.cxx:1193
std::vector< std::pair< OUString, std::unique_ptr< SwBoxAutoFormat > > > m_aCellStyles
Definition: tblafmt.hxx:310
SwBoxAutoFormat * GetBoxFormat(std::u16string_view sName) const
If found returns a ptr to a BoxFormat. If not found returns nullptr.
Definition: tblafmt.cxx:1227
void RemoveBoxFormat(const OUString &sName)
Definition: tblafmt.cxx:1203
Defines the vertical position of a fly frame.
Definition: fmtornt.hxx:37
virtual SwFormatVertOrient * Clone(SfxItemPool *pPool=nullptr) const override
Definition: atrfrm.cxx:1386
std::unique_ptr< Impl > m_pImpl
Definition: tblafmt.hxx:268
void SetBackground(const bool bNew)
Definition: tblafmt.hxx:231
void SetWidthHeight(const bool bNew)
Definition: tblafmt.hxx:233
bool IsJustify() const
Definition: tblafmt.hxx:218
bool m_bInclWidthHeight
Definition: tblafmt.hxx:173
unotools::WeakReference< SwXTextTableStyle > m_xUnoTextTableStyle
Definition: tblafmt.hxx:160
const SvxShadowItem & GetShadow() const
Definition: tblafmt.hxx:195
bool m_bInclValueFormat
Definition: tblafmt.hxx:170
sal_uInt16 m_aRepeatHeading
Definition: tblafmt.hxx:179
void SetName(const OUString &rNew)
Definition: tblafmt.hxx:205
bool IsUserDefined() const
Check if style is defined by user.
Definition: tblafmt.hxx:226
const SvxFormatKeepItem & GetKeepWithNextPara() const
Definition: tblafmt.hxx:194
bool m_bCollapsingBorders
Definition: tblafmt.hxx:182
std::shared_ptr< SvxShadowItem > m_aShadow
Definition: tblafmt.hxx:183
bool IsValueFormat() const
Definition: tblafmt.hxx:221
sal_uInt16 m_nStrResId
Definition: tblafmt.hxx:163
bool IsBackground() const
Definition: tblafmt.hxx:220
void SetShadow(const SvxShadowItem &rNew)
Definition: tblafmt.hxx:198
void SetFrame(const bool bNew)
Definition: tblafmt.hxx:230
void SetValueFormat(const bool bNew)
Definition: tblafmt.hxx:232
unotools::WeakReference< SwXTextTableStyle > const & GetXObject() const
Definition: tblafmt.hxx:250
bool IsFont() const
Definition: tblafmt.hxx:217
OUString m_aName
Definition: tblafmt.hxx:162
const OUString & GetName() const
Definition: tblafmt.hxx:206
bool m_bInclBackground
Definition: tblafmt.hxx:169
void SetJustify(const bool bNew)
Definition: tblafmt.hxx:229
bool IsFrame() const
Definition: tblafmt.hxx:219
void SetFont(const bool bNew)
Definition: tblafmt.hxx:228
void SetHidden(bool bHidden)
Set if style is hidden.
Definition: tblafmt.hxx:236
std::shared_ptr< SvxFormatKeepItem > m_aKeepWithNextPara
Definition: tblafmt.hxx:178
static SwBoxAutoFormat * s_pDefaultBoxAutoFormat
Definition: tblafmt.hxx:158
void SetKeepWithNextPara(const SvxFormatKeepItem &rNew)
Definition: tblafmt.hxx:197
void SetUserDefined(bool bUserDefined)
Set if style is user defined.
Definition: tblafmt.hxx:238
bool IsHidden() const
Check if style is hidden.
Definition: tblafmt.hxx:224
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:113
A text cell style is a UNO API wrapper for a SwBoxAutoFormat core class.
Definition: unostyle.hxx:332
A text table style is a UNO API wrapper for a SwTableAutoFormat.
Definition: unostyle.hxx:239
void FinitCore()
Definition: init.cxx:684
size
OUString m_aName
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwTableAutoFormatUpdateFlags
Definition: tblafmt.hxx:105
unsigned char sal_uInt8