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