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 "fmtornt.hxx"
38#include "swdllapi.h"
39
40struct SwAfVersions;
41
43class SwTable;
44
46{
47private:
48 // Writer specific
49 std::unique_ptr<SvxFrameDirectionItem> m_aTextOrientation;
50 std::unique_ptr<SwFormatVertOrient> m_aVerticalAlignment;
51
52 // number format
56
57 css::uno::WeakReference<css::uno::XInterface> m_wXObject;
58
59public:
61 SwBoxAutoFormat( const SwBoxAutoFormat& rNew );
63
66
68 bool operator==(const SwBoxAutoFormat& rRight) const;
69
70 // The get-methods.
73
74 void GetValueFormat( OUString& rFormat, LanguageType& rLng, LanguageType& rSys ) const
75 { rFormat = m_sNumFormatString; rLng = m_eNumFormatLanguage; rSys = m_eSysLanguage; }
76
77 const OUString& GetNumFormatString() const { return m_sNumFormatString; }
78 const LanguageType& GetSysLanguage() const { return m_eSysLanguage; }
80
81 // The set-methods.
84
85 void SetValueFormat( const OUString& rFormat, LanguageType eLng, LanguageType eSys )
86 { m_sNumFormatString = rFormat; m_eNumFormatLanguage = eLng; m_eSysLanguage = eSys; }
87
88 void SetNumFormatString(const OUString& rNew) { m_sNumFormatString = rNew; }
89 void SetSysLanguage(const LanguageType& rNew) { m_eSysLanguage = rNew; }
91
92 css::uno::WeakReference<css::uno::XInterface> const& GetXObject() const
93 { return m_wXObject; }
94 void SetXObject(css::uno::Reference<css::uno::XInterface> const& xObject)
95 { m_wXObject = xObject; }
96
97 bool Load( SvStream& rStream, const SwAfVersions& rVersions, sal_uInt16 nVer );
98 bool Save( SvStream& rStream, sal_uInt16 fileVersion ) const;
99};
100
101enum class SwTableAutoFormatUpdateFlags { Char = 1, Box = 2 };
102namespace o3tl {
103 template<> struct typed_flags<SwTableAutoFormatUpdateFlags> : is_typed_flags<SwTableAutoFormatUpdateFlags, 0x03> {};
104};
105
106/*
107@remarks
108A table has a number of lines. These lines seem to correspond with rows, except in the case of
109rows spanning more than one line. Each line contains a number of boxes/cells.
110
111AutoFormat properties are retrieved and stored in a grid of 16 table boxes. A sampling approach
112is used to read the data. 4 lines are picked, and 4 boxes are picked from each.
113
114The line picking and box picking algorithms are similar. We start at the first line/box, and pick
115lines/boxes one by one for a maximum of 3. The 4th line/box is the last line/box in the current
116table/line. If we hit the end of lines/boxes, the last line/box encountered is picked several times.
117
118For example, in a 2x3 table, the 4 lines will be [0, 1, 1, 1]. In each line, the boxes will be
119[0, 1, 2, 2]. In a 6x5 table, the 4 lines will be [0, 1, 2, 4] and the boxes per line will be
120[0, 1, 2, 5].
121
122As you can see, property extraction/application is lossless for tables that are 4x4 or smaller
123(and in fact has a bit of redundancy). For larger tables, we lose any individual cell formatting
124for the range [(3,rows - 1) -> (3, cols - 1)]. That formatting is replaced by formatting from
125the saved cells:
126
127 0 1 2 3 4 5
128 +-----------------------------------------------------------------------+
129 0 | Saved | Saved | Saved | | | Saved |
130 +-----------------------------------------------------------------------+
131 1 | Saved | Saved | Saved | | | Saved |
132 +-----------------------------------------------------------------------+
133 2 | Saved | Saved | Saved | | | Saved |
134 +-----------------------------------------------------------------------+
135 3 | | | | | | |
136 +-----------------------------------------------------------------------+
137 4 | | | | | | |
138 +-----------------------------------------------------------------------+
139 5 | Saved | Saved | Saved | | | Saved |
140 +-----------+-----------+-----------+-----------+-----------+-----------+
141
142The properties saved are divided into three categories:
143 1. Character properties: Font, font size, weight, etc.
144 2. Box properties: Box, cell background
145 3. Table properties: Properties that are set in the Table->Table Properties dialog.
146
147Character and box properties are stored per cell (and are lossy for tables larger than 4x4). Table
148properties are stored per-table, and are lossless.
149*/
151{
152 friend class SwDocTest;
153 friend void FinitCore(); // To destroy default pointer.
155
156 css::uno::WeakReference<css::uno::XInterface> m_wXObject;
157
158 OUString m_aName;
159 sal_uInt16 m_nStrResId;
160
161 // Common flags of Calc and Writer.
162 bool m_bInclFont : 1;
164 bool m_bInclFrame : 1;
167
168 // Calc specific flags.
170
171 SwBoxAutoFormat* m_aBoxAutoFormat[ 16 ] = {};
172
173 // Writer-specific options
174 std::shared_ptr<SvxFormatKeepItem> m_aKeepWithNextPara;
179 std::shared_ptr<SvxShadowItem> m_aShadow;
180
183public:
184 SwTableAutoFormat( OUString aName );
187
188 SwTableAutoFormat& operator=( const SwTableAutoFormat& rNew );
189
190 const SvxFormatKeepItem& GetKeepWithNextPara() const { return *m_aKeepWithNextPara; }
191 const SvxShadowItem& GetShadow() const { return *m_aShadow; }
192
193 void SetKeepWithNextPara(const SvxFormatKeepItem& rNew) { m_aKeepWithNextPara.reset(rNew.Clone()); }
194 void SetShadow(const SvxShadowItem& rNew) { m_aShadow.reset(rNew.Clone()); }
195
196 void SetBoxFormat( const SwBoxAutoFormat& rNew, sal_uInt8 nPos );
197 const SwBoxAutoFormat& GetBoxFormat( sal_uInt8 nPos ) const;
198 SwBoxAutoFormat& GetBoxFormat( sal_uInt8 nPos );
199 static const SwBoxAutoFormat& GetDefaultBoxFormat();
200
201 void SetName( const OUString& rNew ) { m_aName = rNew; m_nStrResId = USHRT_MAX; }
202 const OUString& GetName() const { return m_aName; }
203
204 void UpdateFromSet( sal_uInt8 nPos, const SfxItemSet& rSet,
206 void UpdateToSet( const sal_uInt8 nPos, const bool bSingleRowTable, const bool bSingleColTable,
208 SvNumberFormatter* ) const ;
209
210 void RestoreTableProperties(SwTable &table) const;
211 void StoreTableProperties(const SwTable &table);
212
213 bool IsFont() const { return m_bInclFont; }
214 bool IsJustify() const { return m_bInclJustify; }
215 bool IsFrame() const { return m_bInclFrame; }
216 bool IsBackground() const { return m_bInclBackground; }
217 bool IsValueFormat() const { return m_bInclValueFormat; }
218
220 bool IsHidden() const { return m_bHidden; }
222 bool IsUserDefined() const { return m_bUserDefined; }
223
224 void SetFont( const bool bNew ) { m_bInclFont = bNew; }
225 void SetJustify( const bool bNew ) { m_bInclJustify = bNew; }
226 void SetFrame( const bool bNew ) { m_bInclFrame = bNew; }
227 void SetBackground( const bool bNew ) { m_bInclBackground = bNew; }
228 void SetValueFormat( const bool bNew ) { m_bInclValueFormat = bNew; }
229 void SetWidthHeight( const bool bNew ) { m_bInclWidthHeight = bNew; }
230
232 void SetHidden(bool bHidden) { m_bHidden = bHidden; }
234 void SetUserDefined(bool bUserDefined) { m_bUserDefined = bUserDefined; }
235
237 bool FirstRowEndColumnIsRow();
238 bool FirstRowStartColumnIsRow();
239 bool LastRowEndColumnIsRow();
240 bool LastRowStartColumnIsRow();
241
242 bool Load( SvStream& rStream, const SwAfVersions& );
243 bool Save( SvStream& rStream, sal_uInt16 fileVersion ) const;
244
245 css::uno::WeakReference<css::uno::XInterface> const& GetXObject() const
246 { return m_wXObject; }
247 void SetXObject(css::uno::Reference<css::uno::XInterface> const& xObject)
248 { m_wXObject = xObject; }
249
251 OUString GetTableTemplateCellSubName(const SwBoxAutoFormat& rBoxFormat) const;
253 static const std::vector<sal_Int32>& GetTableTemplateMap();
254
259 static sal_uInt8 CountPos(sal_uInt32 nCol, sal_uInt32 nCols, sal_uInt32 nRow, sal_uInt32 nRows);
260};
261
263{
264 struct Impl;
265 std::unique_ptr<Impl> m_pImpl;
266
267 SAL_DLLPRIVATE bool Load( SvStream& rStream );
268 SAL_DLLPRIVATE bool Save( SvStream& rStream ) const;
269
270public:
271 explicit SwTableAutoFormatTable();
273
274 size_t size() const;
275 SwTableAutoFormat const& operator[](size_t i) const;
276 SwTableAutoFormat & operator[](size_t i);
277
279 void AddAutoFormat(const SwTableAutoFormat& rFormat);
280
281 void InsertAutoFormat(size_t i, std::unique_ptr<SwTableAutoFormat> pFormat);
282 void EraseAutoFormat(size_t i);
283 void EraseAutoFormat(const OUString& rName);
284 std::unique_ptr<SwTableAutoFormat> ReleaseAutoFormat(size_t i);
286 std::unique_ptr<SwTableAutoFormat> ReleaseAutoFormat(const OUString& rName);
287
289 SwTableAutoFormat* FindAutoFormat(std::u16string_view rName) const;
290
291 void Load();
292 bool Save() const;
293};
294
296{
297 const std::pair<OUString, std::unique_ptr<SwBoxAutoFormat>>& m_rCellStyleDesc;
298public:
299 SwCellStyleDescriptor(const std::pair<OUString, std::unique_ptr<SwBoxAutoFormat>>& rCellStyleDesc) : m_rCellStyleDesc(rCellStyleDesc) { }
300
301 const OUString& GetName() const { return m_rCellStyleDesc.first; }
302};
303
305{
306 std::vector<std::pair<OUString, std::unique_ptr<SwBoxAutoFormat>>> m_aCellStyles;
307public:
310
311 size_t size() const;
312 SwCellStyleDescriptor operator[](size_t i) const;
313 void clear();
314
316 void AddBoxFormat(const SwBoxAutoFormat& rBoxFormat, const OUString& sName);
317 void RemoveBoxFormat(const OUString& sName);
318 void ChangeBoxFormatName(std::u16string_view sFromName, const OUString& sToName);
320 OUString GetBoxFormatName(const SwBoxAutoFormat& rBoxFormat) const;
322 SwBoxAutoFormat* GetBoxFormat(std::u16string_view sName) const;
323};
324
325#endif
326
327/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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:77
void SetTextOrientation(const SvxFrameDirectionItem &rNew)
Definition: tblafmt.hxx:82
OUString m_sNumFormatString
Definition: tblafmt.hxx:53
const LanguageType & GetNumFormatLanguage() const
Definition: tblafmt.hxx:79
const LanguageType & GetSysLanguage() const
Definition: tblafmt.hxx:78
void GetValueFormat(OUString &rFormat, LanguageType &rLng, LanguageType &rSys) const
Definition: tblafmt.hxx:74
void SetSysLanguage(const LanguageType &rNew)
Definition: tblafmt.hxx:89
std::unique_ptr< SwFormatVertOrient > m_aVerticalAlignment
Definition: tblafmt.hxx:50
css::uno::WeakReference< css::uno::XInterface > const & GetXObject() const
Definition: tblafmt.hxx:92
css::uno::WeakReference< css::uno::XInterface > m_wXObject
Definition: tblafmt.hxx:57
void SetNumFormatString(const OUString &rNew)
Definition: tblafmt.hxx:88
void SetXObject(css::uno::Reference< css::uno::XInterface > const &xObject)
Definition: tblafmt.hxx:94
std::unique_ptr< SvxFrameDirectionItem > m_aTextOrientation
Definition: tblafmt.hxx:49
const SwFormatVertOrient & GetVerticalAlignment() const
Definition: tblafmt.hxx:72
LanguageType m_eNumFormatLanguage
Definition: tblafmt.hxx:55
void SetVerticalAlignment(const SwFormatVertOrient &rNew)
Definition: tblafmt.hxx:83
bool Load(SvStream &rStream, const SwAfVersions &rVersions, sal_uInt16 nVer)
Definition: tblafmt.cxx:309
SwBoxAutoFormat & operator=(const SwBoxAutoFormat &rRef)
assignment-op (still used)
Definition: tblafmt.cxx:279
void SetNumFormatLanguage(const LanguageType &rNew)
Definition: tblafmt.hxx:90
LanguageType m_eSysLanguage
Definition: tblafmt.hxx:54
void SetValueFormat(const OUString &rFormat, LanguageType eLng, LanguageType eSys)
Definition: tblafmt.hxx:85
bool operator==(const SwBoxAutoFormat &rRight) const
Comparing based of boxes backgrounds.
Definition: tblafmt.cxx:304
bool Save(SvStream &rStream, sal_uInt16 fileVersion) const
Definition: tblafmt.cxx:342
const SvxFrameDirectionItem & GetTextOrientation() const
Definition: tblafmt.hxx:71
const std::pair< OUString, std::unique_ptr< SwBoxAutoFormat > > & m_rCellStyleDesc
Definition: tblafmt.hxx:297
const OUString & GetName() const
Definition: tblafmt.hxx:301
SwCellStyleDescriptor(const std::pair< OUString, std::unique_ptr< SwBoxAutoFormat > > &rCellStyleDesc)
Definition: tblafmt.hxx:299
OUString GetBoxFormatName(const SwBoxAutoFormat &rBoxFormat) const
If found returns its name. If not found returns an empty OUString.
Definition: tblafmt.cxx:1197
void ChangeBoxFormatName(std::u16string_view sFromName, const OUString &sToName)
Definition: tblafmt.cxx:1220
size_t size() const
Definition: tblafmt.cxx:1165
void AddBoxFormat(const SwBoxAutoFormat &rBoxFormat, const OUString &sName)
Add a copy of rBoxFormat.
Definition: tblafmt.cxx:1180
SwCellStyleDescriptor operator[](size_t i) const
Definition: tblafmt.cxx:1175
std::vector< std::pair< OUString, std::unique_ptr< SwBoxAutoFormat > > > m_aCellStyles
Definition: tblafmt.hxx:306
SwBoxAutoFormat * GetBoxFormat(std::u16string_view sName) const
If found returns a ptr to a BoxFormat. If not found returns nullptr.
Definition: tblafmt.cxx:1209
void RemoveBoxFormat(const OUString &sName)
Definition: tblafmt.cxx:1185
virtual SwFormatVertOrient * Clone(SfxItemPool *pPool=nullptr) const override
Definition: atrfrm.cxx:1386
std::unique_ptr< Impl > m_pImpl
Definition: tblafmt.hxx:264
void SetBackground(const bool bNew)
Definition: tblafmt.hxx:227
void SetWidthHeight(const bool bNew)
Definition: tblafmt.hxx:229
bool IsJustify() const
Definition: tblafmt.hxx:214
bool m_bInclWidthHeight
Definition: tblafmt.hxx:169
const SvxShadowItem & GetShadow() const
Definition: tblafmt.hxx:191
bool m_bInclValueFormat
Definition: tblafmt.hxx:166
sal_uInt16 m_aRepeatHeading
Definition: tblafmt.hxx:175
void SetName(const OUString &rNew)
Definition: tblafmt.hxx:201
css::uno::WeakReference< css::uno::XInterface > const & GetXObject() const
Definition: tblafmt.hxx:245
bool IsUserDefined() const
Check if style is defined by user.
Definition: tblafmt.hxx:222
const SvxFormatKeepItem & GetKeepWithNextPara() const
Definition: tblafmt.hxx:190
bool m_bCollapsingBorders
Definition: tblafmt.hxx:178
std::shared_ptr< SvxShadowItem > m_aShadow
Definition: tblafmt.hxx:179
bool IsValueFormat() const
Definition: tblafmt.hxx:217
sal_uInt16 m_nStrResId
Definition: tblafmt.hxx:159
bool IsBackground() const
Definition: tblafmt.hxx:216
void SetShadow(const SvxShadowItem &rNew)
Definition: tblafmt.hxx:194
void SetFrame(const bool bNew)
Definition: tblafmt.hxx:226
void SetValueFormat(const bool bNew)
Definition: tblafmt.hxx:228
bool IsFont() const
Definition: tblafmt.hxx:213
css::uno::WeakReference< css::uno::XInterface > m_wXObject
Definition: tblafmt.hxx:156
void SetXObject(css::uno::Reference< css::uno::XInterface > const &xObject)
Definition: tblafmt.hxx:247
OUString m_aName
Definition: tblafmt.hxx:158
const OUString & GetName() const
Definition: tblafmt.hxx:202
bool m_bInclBackground
Definition: tblafmt.hxx:165
void SetJustify(const bool bNew)
Definition: tblafmt.hxx:225
bool IsFrame() const
Definition: tblafmt.hxx:215
void SetFont(const bool bNew)
Definition: tblafmt.hxx:224
void SetHidden(bool bHidden)
Set if style is hidden.
Definition: tblafmt.hxx:232
std::shared_ptr< SvxFormatKeepItem > m_aKeepWithNextPara
Definition: tblafmt.hxx:174
static SwBoxAutoFormat * s_pDefaultBoxAutoFormat
Definition: tblafmt.hxx:154
void SetKeepWithNextPara(const SvxFormatKeepItem &rNew)
Definition: tblafmt.hxx:193
void SetUserDefined(bool bUserDefined)
Set if style is user defined.
Definition: tblafmt.hxx:234
bool IsHidden() const
Check if style is hidden.
Definition: tblafmt.hxx:220
SwTable is one table in the document model, containing rows (which contain cells).
Definition: swtable.hxx:113
void FinitCore()
Definition: init.cxx:668
size
OUString m_aName
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwTableAutoFormatUpdateFlags
Definition: tblafmt.hxx:101
unsigned char sal_uInt8