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 .
19 #ifndef INCLUDED_SW_INC_TBLAFMT_HXX
20 #define INCLUDED_SW_INC_TBLAFMT_HXX
22 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
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!
28 * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
31 #include <boost/scoped_ptr.hpp>
33 #include "hintids.hxx"
34 #include <svx/algitem.hxx>
35 #include <editeng/fontitem.hxx>
36 #include <editeng/fhgtitem.hxx>
37 #include <editeng/wghtitem.hxx>
38 #include <editeng/postitem.hxx>
39 #include <editeng/udlnitem.hxx>
40 #include <editeng/crossedoutitem.hxx>
41 #include <editeng/contouritem.hxx>
42 #include <editeng/shdditem.hxx>
43 #include <editeng/colritem.hxx>
44 #include <editeng/boxitem.hxx>
45 #include <editeng/brushitem.hxx>
46 #include <editeng/adjustitem.hxx>
47 #include <editeng/justifyitem.hxx>
48 #include <editeng/formatbreakitem.hxx>
49 #include <editeng/keepitem.hxx>
50 #include <editeng/frmdiritem.hxx>
51 #include <editeng/shaditem.hxx>
52 #include <svx/rotmodit.hxx>
53 #include <svl/intitem.hxx>
54 #include <editeng/lineitem.hxx>
55 #include <fmtpdsc.hxx>
56 #include <fmtlsplt.hxx>
57 #include <fmtrowsplt.hxx>
58 #include <fmtornt.hxx>
63 class SvNumberFormatter
;
67 // common attributes of Calc and Writer
68 // --- from 641 on: CJK and CTL font settings
70 SvxFontHeightItem aHeight
;
71 SvxWeightItem aWeight
;
72 SvxPostureItem aPosture
;
75 SvxFontHeightItem aCJKHeight
;
76 SvxWeightItem aCJKWeight
;
77 SvxPostureItem aCJKPosture
;
80 SvxFontHeightItem aCTLHeight
;
81 SvxWeightItem aCTLWeight
;
82 SvxPostureItem aCTLPosture
;
84 SvxUnderlineItem aUnderline
;
85 SvxOverlineItem aOverline
;
86 SvxCrossedOutItem aCrossedOut
;
87 SvxContourItem aContour
;
88 SvxShadowedItem aShadowed
;
93 SvxBrushItem aBackground
;
96 SvxAdjustItem aAdjust
;
97 SvxFrameDirectionItem m_aTextOrientation
;
98 SwFormatVertOrient m_aVerticalAlignment
;
101 SvxHorJustifyItem aHorJustify
;
102 SvxVerJustifyItem aVerJustify
;
103 SfxBoolItem aStacked
;
104 SvxMarginItem aMargin
;
105 SfxBoolItem aLinebreak
;
106 SfxInt32Item aRotateAngle
;
107 SvxRotateModeItem aRotateMode
;
110 OUString sNumFormatString
;
111 LanguageType eSysLanguage
, eNumFormatLanguage
;
115 SwBoxAutoFormat( const SwBoxAutoFormat
& rNew
);
118 int operator==( const SwBoxAutoFormat
& rCmp
) const;
119 SwBoxAutoFormat
& operator=( const SwBoxAutoFormat
& rNew
);
122 const SvxFontItem
&GetFont() const { return aFont
; }
123 const SvxFontHeightItem
&GetHeight() const { return aHeight
; }
124 const SvxWeightItem
&GetWeight() const { return aWeight
; }
125 const SvxPostureItem
&GetPosture() const { return aPosture
; }
126 const SvxFontItem
&GetCJKFont() const { return aCJKFont
; }
127 const SvxFontHeightItem
&GetCJKHeight() const { return aCJKHeight
; }
128 const SvxWeightItem
&GetCJKWeight() const { return aCJKWeight
; }
129 const SvxPostureItem
&GetCJKPosture() const { return aCJKPosture
; }
130 const SvxFontItem
&GetCTLFont() const { return aCTLFont
; }
131 const SvxFontHeightItem
&GetCTLHeight() const { return aCTLHeight
; }
132 const SvxWeightItem
&GetCTLWeight() const { return aCTLWeight
; }
133 const SvxPostureItem
&GetCTLPosture() const { return aCTLPosture
; }
134 const SvxUnderlineItem
&GetUnderline() const { return aUnderline
; }
135 const SvxOverlineItem
&GetOverline() const { return aOverline
; }
136 const SvxCrossedOutItem
&GetCrossedOut() const { return aCrossedOut
; }
137 const SvxContourItem
&GetContour() const { return aContour
; }
138 const SvxShadowedItem
&GetShadowed() const { return aShadowed
; }
139 const SvxColorItem
&GetColor() const { return aColor
; }
140 const SvxAdjustItem
&GetAdjust() const { return aAdjust
; }
141 const SvxFrameDirectionItem
& GetTextOrientation() const { return m_aTextOrientation
; }
142 const SwFormatVertOrient
& GetVerticalAlignment() const { return m_aVerticalAlignment
; }
143 const SvxBoxItem
&GetBox() const { return aBox
; }
144 const SvxLineItem
&GetTLBR() const { return aTLBR
; }
145 const SvxLineItem
&GetBLTR() const { return aBLTR
; }
146 const SvxBrushItem
&GetBackground() const { return aBackground
; }
147 void GetValueFormat( OUString
& rFormat
, LanguageType
& rLng
, LanguageType
& rSys
) const
148 { rFormat
= sNumFormatString
; rLng
= eNumFormatLanguage
; rSys
= eSysLanguage
; }
151 void SetFont( const SvxFontItem
& rNew
) { aFont
= rNew
; }
152 void SetHeight( const SvxFontHeightItem
& rNew
) { aHeight
= rNew
; }
153 void SetWeight( const SvxWeightItem
& rNew
) { aWeight
= rNew
; }
154 void SetPosture( const SvxPostureItem
& rNew
) { aPosture
= rNew
; }
155 void SetCJKFont( const SvxFontItem
& rNew
) { aCJKFont
= rNew
; }
156 void SetCJKHeight( const SvxFontHeightItem
& rNew
) { aCJKHeight
= rNew
; }
157 void SetCJKWeight( const SvxWeightItem
& rNew
) { aCJKWeight
= rNew
; }
158 void SetCJKPosture( const SvxPostureItem
& rNew
) { aCJKPosture
= rNew
; }
159 void SetCTLFont( const SvxFontItem
& rNew
) { aCTLFont
= rNew
; }
160 void SetCTLHeight( const SvxFontHeightItem
& rNew
) { aCTLHeight
= rNew
; }
161 void SetCTLWeight( const SvxWeightItem
& rNew
) { aCTLWeight
= rNew
; }
162 void SetCTLPosture( const SvxPostureItem
& rNew
) { aCTLPosture
= rNew
; }
163 void SetUnderline( const SvxUnderlineItem
& rNew
) { aUnderline
= rNew
; }
164 void SetOverline( const SvxOverlineItem
& rNew
) { aOverline
= rNew
; }
165 void SetCrossedOut( const SvxCrossedOutItem
& rNew
) { aCrossedOut
= rNew
; }
166 void SetContour( const SvxContourItem
& rNew
) { aContour
= rNew
; }
167 void SetShadowed( const SvxShadowedItem
& rNew
) { aShadowed
= rNew
; }
168 void SetColor( const SvxColorItem
& rNew
) { aColor
= rNew
; }
169 void SetAdjust( const SvxAdjustItem
& rNew
)
171 aAdjust
.SetAdjust( rNew
.GetAdjust() );
172 aAdjust
.SetOneWord( rNew
.GetOneWord() );
173 aAdjust
.SetLastBlock( rNew
.GetLastBlock() );
175 void SetTextOrientation(const SvxFrameDirectionItem
& rNew
) { m_aTextOrientation
= rNew
; }
176 void SetVerticalAlignment(const SwFormatVertOrient
& rNew
) { m_aVerticalAlignment
= rNew
; }
177 void SetBox( const SvxBoxItem
& rNew
) { aBox
= rNew
; }
178 void SetBackground( const SvxBrushItem
& rNew
) { aBackground
= rNew
; }
179 void SetValueFormat( const OUString
& rFormat
, LanguageType eLng
, LanguageType eSys
)
180 { sNumFormatString
= rFormat
; eNumFormatLanguage
= eLng
; eSysLanguage
= eSys
; }
182 bool Load( SvStream
& rStream
, const SwAfVersions
& rVersions
, sal_uInt16 nVer
);
183 bool Save( SvStream
& rStream
, sal_uInt16 fileVersion
) const;
184 bool SaveVersionNo( SvStream
& rStream
, sal_uInt16 fileVersion
) const;
189 A table has a number of lines. These lines seem to correspond with rows, except in the case of
190 rows spanning more than one line. Each line contains a number of boxes/cells.
192 AutoFormat properties are retrieved and stored in a grid of 16 table boxes. A sampling approach
193 is used to read the data. 4 lines are picked, and 4 boxes are picked from each.
195 The line picking and box picking algorithms are similar. We start at the first line/box, and pick
196 lines/boxes one by one for a maximum of 3. The 4th line/box is the last line/box in the current
197 table/line. If we hit the end of lines/boxes, the last line/box encountered is picked several times.
199 For example, in a 2x3 table, the 4 lines will be [0, 1, 1, 1]. In each line, the boxes will be
200 [0, 1, 2, 2]. In a 6x5 table, the 4 lines will be [0, 1, 2, 4] and the boxes per line will be
203 As you can see, property extraction/application is lossless for tables that are 4x4 or smaller
204 (and in fact has a bit of redundnacy). For larger tables, we lose any individual cell formatting
205 for the range [(3,rows - 1) -> (3, cols - 1)]. That formatting is replaced by formatting from
209 +-----------------------------------------------------------------------+
210 0 | Saved | Saved | Saved | | | Saved |
211 +-----------------------------------------------------------------------+
212 1 | Saved | Saved | Saved | | | Saved |
213 +-----------------------------------------------------------------------+
214 2 | Saved | Saved | Saved | | | Saved |
215 +-----------------------------------------------------------------------+
217 +-----------------------------------------------------------------------+
219 +-----------------------------------------------------------------------+
220 5 | Saved | Saved | Saved | | | Saved |
221 +-----------+-----------+-----------+-----------+-----------+-----------+
223 The properties saved are divided into three categories:
224 1. Character properties: Font, font size, weight, etc.
225 2. Box properties: Box, cell background
226 3. Table properties: Properties that are set in the Table->Table Properties dialog.
228 Character and box properties are stored per cell (and are lossy for tables larger than 4x4). Table
229 properties are stored per-table, and are lossless.
231 class SW_DLLPUBLIC SwTableAutoFormat
233 friend void _FinitCore(); // To destroy default pointer.
234 static SwBoxAutoFormat
* pDfltBoxAutoFormat
;
237 sal_uInt16 nStrResId
;
239 // Common flags of Calc and Writer.
241 bool bInclJustify
: 1;
243 bool bInclBackground
: 1;
244 bool bInclValueFormat
: 1;
246 // Calc specific flags.
247 bool bInclWidthHeight
: 1;
249 SwBoxAutoFormat
* aBoxAutoFormat
[ 16 ];
251 // Writer-specific options
252 SvxFormatBreakItem m_aBreak
;
253 SwFormatPageDesc m_aPageDesc
;
254 SvxFormatKeepItem m_aKeepWithNextPara
;
255 sal_uInt16 m_aRepeatHeading
;
258 bool m_bCollapsingBorders
;
259 SvxShadowItem m_aShadow
;
262 SwTableAutoFormat( const OUString
& rName
);
263 SwTableAutoFormat( const SwTableAutoFormat
& rNew
);
264 ~SwTableAutoFormat();
266 SwTableAutoFormat
& operator=( const SwTableAutoFormat
& rNew
);
268 void SetBoxFormat( const SwBoxAutoFormat
& rNew
, sal_uInt8 nPos
);
269 const SwBoxAutoFormat
& GetBoxFormat( sal_uInt8 nPos
) const;
271 void SetName( const OUString
& rNew
) { m_aName
= rNew
; nStrResId
= USHRT_MAX
; }
272 OUString
GetName() const { return m_aName
; }
274 enum UpdateFlags
{ UPDATE_CHAR
= 1, UPDATE_BOX
= 2, UPDATE_ALL
= 3 };
275 void UpdateFromSet( sal_uInt8 nPos
, const SfxItemSet
& rSet
,
276 UpdateFlags eFlags
, SvNumberFormatter
* );
277 void UpdateToSet( sal_uInt8 nPos
, SfxItemSet
& rSet
, UpdateFlags eFlags
,
278 SvNumberFormatter
* ) const ;
280 void RestoreTableProperties(SwTable
&table
) const;
281 void StoreTableProperties(const SwTable
&table
);
283 bool IsFont() const { return bInclFont
; }
284 bool IsJustify() const { return bInclJustify
; }
285 bool IsFrame() const { return bInclFrame
; }
286 bool IsBackground() const { return bInclBackground
; }
287 bool IsValueFormat() const { return bInclValueFormat
; }
289 void SetFont( const bool bNew
) { bInclFont
= bNew
; }
290 void SetJustify( const bool bNew
) { bInclJustify
= bNew
; }
291 void SetFrame( const bool bNew
) { bInclFrame
= bNew
; }
292 void SetBackground( const bool bNew
) { bInclBackground
= bNew
; }
293 void SetValueFormat( const bool bNew
) { bInclValueFormat
= bNew
; }
294 void SetWidthHeight( const bool bNew
) { bInclWidthHeight
= bNew
; }
296 bool Load( SvStream
& rStream
, const SwAfVersions
& );
297 bool Save( SvStream
& rStream
, sal_uInt16 fileVersion
) const;
300 class SW_DLLPUBLIC SwTableAutoFormatTable
303 ::boost::scoped_ptr
<Impl
> m_pImpl
;
305 SAL_DLLPRIVATE
bool Load( SvStream
& rStream
);
306 SAL_DLLPRIVATE
bool Save( SvStream
& rStream
) const;
309 explicit SwTableAutoFormatTable();
310 ~SwTableAutoFormatTable();
313 SwTableAutoFormat
const& operator[](size_t i
) const;
314 SwTableAutoFormat
& operator[](size_t i
);
315 void InsertAutoFormat(size_t i
, SwTableAutoFormat
* pFormat
);
316 void EraseAutoFormat(size_t i
);
317 SwTableAutoFormat
* ReleaseAutoFormat(size_t i
);
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */