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 SW_TBLAFMT_HXX
20 #define SW_TBLAFMT_HXX
21 /*************************************************************************
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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
29 **************************************************************************/
31 #include <boost/scoped_ptr.hpp>
33 #include "hintids.hxx" // _Always_ before the solar-items!
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 SwFmtVertOrient m_aVerticalAlignment
;
101 SvxHorJustifyItem aHorJustify
;
102 SvxVerJustifyItem aVerJustify
;
103 SfxBoolItem aStacked
;
104 SvxMarginItem aMargin
;
105 SfxBoolItem aLinebreak
;
106 SfxInt32Item aRotateAngle
;
107 SvxRotateModeItem aRotateMode
;
110 String sNumFmtString
;
111 LanguageType eSysLanguage
, eNumFmtLanguage
;
115 SwBoxAutoFmt( const SwBoxAutoFmt
& rNew
);
118 int operator==( const SwBoxAutoFmt
& rCmp
) const;
119 SwBoxAutoFmt
& operator=( const SwBoxAutoFmt
& 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 SwFmtVertOrient
& 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( String
& rFmt
, LanguageType
& rLng
, LanguageType
& rSys
) const
148 { rFmt
= sNumFmtString
; rLng
= eNumFmtLanguage
; 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 SwFmtVertOrient
& rNew
) { m_aVerticalAlignment
= rNew
; }
177 void SetBox( const SvxBoxItem
& rNew
) { aBox
= rNew
; }
178 void SetBackground( const SvxBrushItem
& rNew
) { aBackground
= rNew
; }
179 void SetValueFormat( const String
& rFmt
, LanguageType eLng
, LanguageType eSys
)
180 { sNumFmtString
= rFmt
; eNumFmtLanguage
= eLng
; eSysLanguage
= eSys
; }
182 sal_Bool
Load( SvStream
& rStream
, const SwAfVersions
& rVersions
, sal_uInt16 nVer
);
183 sal_Bool
Save( SvStream
& rStream
, sal_uInt16 fileVersion
) const;
184 sal_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 SwTableAutoFmt
233 friend void _FinitCore(); // To destroy dflt. pointer.
234 static SwBoxAutoFmt
* pDfltBoxAutoFmt
;
237 sal_uInt16 nStrResId
;
239 // Common flags of Calc and Writer.
240 sal_Bool bInclFont
: 1;
241 sal_Bool bInclJustify
: 1;
242 sal_Bool bInclFrame
: 1;
243 sal_Bool bInclBackground
: 1;
244 sal_Bool bInclValueFormat
: 1;
246 // Calc specific flags.
247 sal_Bool bInclWidthHeight
: 1;
249 SwBoxAutoFmt
* aBoxAutoFmt
[ 16 ];
251 // Writer-specific options
252 SvxFmtBreakItem m_aBreak
;
253 SwFmtPageDesc m_aPageDesc
;
254 SvxFmtKeepItem m_aKeepWithNextPara
;
255 sal_uInt16 m_aRepeatHeading
;
256 sal_Bool m_bLayoutSplit
;
257 sal_Bool m_bRowSplit
;
258 sal_Bool m_bCollapsingBorders
;
259 SvxShadowItem m_aShadow
;
262 SwTableAutoFmt( const String
& rName
);
263 SwTableAutoFmt( const SwTableAutoFmt
& rNew
);
266 SwTableAutoFmt
& operator=( const SwTableAutoFmt
& rNew
);
268 void SetBoxFmt( const SwBoxAutoFmt
& rNew
, sal_uInt8 nPos
);
269 const SwBoxAutoFmt
& GetBoxFmt( sal_uInt8 nPos
) const;
271 void SetName( const String
& rNew
) { aName
= rNew
; nStrResId
= USHRT_MAX
; }
272 const String
& GetName() const { return 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 sal_Bool
IsFont() const { return bInclFont
; }
284 sal_Bool
IsJustify() const { return bInclJustify
; }
285 sal_Bool
IsFrame() const { return bInclFrame
; }
286 sal_Bool
IsBackground() const { return bInclBackground
; }
287 sal_Bool
IsValueFormat() const { return bInclValueFormat
; }
289 void SetFont( const sal_Bool bNew
) { bInclFont
= bNew
; }
290 void SetJustify( const sal_Bool bNew
) { bInclJustify
= bNew
; }
291 void SetFrame( const sal_Bool bNew
) { bInclFrame
= bNew
; }
292 void SetBackground( const sal_Bool bNew
) { bInclBackground
= bNew
; }
293 void SetValueFormat( const sal_Bool bNew
) { bInclValueFormat
= bNew
; }
294 void SetWidthHeight( const sal_Bool bNew
) { bInclWidthHeight
= bNew
; }
296 sal_Bool
Load( SvStream
& rStream
, const SwAfVersions
& );
297 sal_Bool
Save( SvStream
& rStream
, sal_uInt16 fileVersion
) const;
300 class SW_DLLPUBLIC SwTableAutoFmtTbl
303 ::boost::scoped_ptr
<Impl
> m_pImpl
;
305 SW_DLLPRIVATE sal_Bool
Load( SvStream
& rStream
);
306 SW_DLLPRIVATE sal_Bool
Save( SvStream
& rStream
) const;
309 explicit SwTableAutoFmtTbl();
310 ~SwTableAutoFmtTbl();
313 SwTableAutoFmt
const& operator[](size_t i
) const;
314 SwTableAutoFmt
& operator[](size_t i
);
315 void InsertAutoFmt(size_t i
, SwTableAutoFmt
* pFmt
);
316 void EraseAutoFmt(size_t i
);
317 SwTableAutoFmt
* ReleaseAutoFmt(size_t i
);
320 sal_Bool
Save() const;
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */