Line data Source code
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 SW_TBLAFMT_HXX
20 : #define SW_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 <boost/scoped_ptr.hpp>
32 :
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>
59 : #include "swdllapi.h"
60 :
61 : struct SwAfVersions;
62 :
63 : class SvNumberFormatter;
64 :
65 : class SwBoxAutoFmt
66 : {
67 : // common attributes of Calc and Writer
68 : // --- from 641 on: CJK and CTL font settings
69 : SvxFontItem aFont;
70 : SvxFontHeightItem aHeight;
71 : SvxWeightItem aWeight;
72 : SvxPostureItem aPosture;
73 :
74 : SvxFontItem aCJKFont;
75 : SvxFontHeightItem aCJKHeight;
76 : SvxWeightItem aCJKWeight;
77 : SvxPostureItem aCJKPosture;
78 :
79 : SvxFontItem aCTLFont;
80 : SvxFontHeightItem aCTLHeight;
81 : SvxWeightItem aCTLWeight;
82 : SvxPostureItem aCTLPosture;
83 :
84 : SvxUnderlineItem aUnderline;
85 : SvxOverlineItem aOverline;
86 : SvxCrossedOutItem aCrossedOut;
87 : SvxContourItem aContour;
88 : SvxShadowedItem aShadowed;
89 : SvxColorItem aColor;
90 : SvxBoxItem aBox;
91 : SvxLineItem aTLBR;
92 : SvxLineItem aBLTR;
93 : SvxBrushItem aBackground;
94 :
95 : // Writer specific
96 : SvxAdjustItem aAdjust;
97 : SvxFrameDirectionItem m_aTextOrientation;
98 : SwFmtVertOrient m_aVerticalAlignment;
99 :
100 : // Calc specific
101 : SvxHorJustifyItem aHorJustify;
102 : SvxVerJustifyItem aVerJustify;
103 : SfxBoolItem aStacked;
104 : SvxMarginItem aMargin;
105 : SfxBoolItem aLinebreak;
106 : SfxInt32Item aRotateAngle;
107 : SvxRotateModeItem aRotateMode;
108 :
109 : // number format
110 : String sNumFmtString;
111 : LanguageType eSysLanguage, eNumFmtLanguage;
112 :
113 : public:
114 : SwBoxAutoFmt();
115 : SwBoxAutoFmt( const SwBoxAutoFmt& rNew );
116 : ~SwBoxAutoFmt();
117 :
118 : int operator==( const SwBoxAutoFmt& rCmp ) const;
119 : SwBoxAutoFmt& operator=( const SwBoxAutoFmt& rNew );
120 :
121 : // The get-methods.
122 0 : const SvxFontItem &GetFont() const { return aFont; }
123 0 : const SvxFontHeightItem &GetHeight() const { return aHeight; }
124 0 : const SvxWeightItem &GetWeight() const { return aWeight; }
125 0 : const SvxPostureItem &GetPosture() const { return aPosture; }
126 0 : const SvxFontItem &GetCJKFont() const { return aCJKFont; }
127 0 : const SvxFontHeightItem &GetCJKHeight() const { return aCJKHeight; }
128 0 : const SvxWeightItem &GetCJKWeight() const { return aCJKWeight; }
129 0 : const SvxPostureItem &GetCJKPosture() const { return aCJKPosture; }
130 0 : const SvxFontItem &GetCTLFont() const { return aCTLFont; }
131 0 : const SvxFontHeightItem &GetCTLHeight() const { return aCTLHeight; }
132 0 : const SvxWeightItem &GetCTLWeight() const { return aCTLWeight; }
133 0 : const SvxPostureItem &GetCTLPosture() const { return aCTLPosture; }
134 0 : const SvxUnderlineItem &GetUnderline() const { return aUnderline; }
135 0 : const SvxOverlineItem &GetOverline() const { return aOverline; }
136 0 : const SvxCrossedOutItem &GetCrossedOut() const { return aCrossedOut; }
137 0 : const SvxContourItem &GetContour() const { return aContour; }
138 0 : const SvxShadowedItem &GetShadowed() const { return aShadowed; }
139 0 : const SvxColorItem &GetColor() const { return aColor; }
140 0 : const SvxAdjustItem &GetAdjust() const { return aAdjust; }
141 0 : const SvxFrameDirectionItem& GetTextOrientation() const { return m_aTextOrientation; }
142 0 : const SwFmtVertOrient& GetVerticalAlignment() const { return m_aVerticalAlignment; }
143 0 : const SvxBoxItem &GetBox() const { return aBox; }
144 : const SvxLineItem &GetTLBR() const { return aTLBR; }
145 : const SvxLineItem &GetBLTR() const { return aBLTR; }
146 0 : const SvxBrushItem &GetBackground() const { return aBackground; }
147 0 : void GetValueFormat( OUString& rFmt, LanguageType& rLng, LanguageType& rSys ) const
148 0 : { rFmt = sNumFmtString; rLng = eNumFmtLanguage; rSys = eSysLanguage; }
149 :
150 : // The set-methods.
151 0 : void SetFont( const SvxFontItem& rNew ) { aFont = rNew; }
152 0 : void SetHeight( const SvxFontHeightItem& rNew ) { aHeight = rNew; }
153 0 : void SetWeight( const SvxWeightItem& rNew ) { aWeight = rNew; }
154 0 : void SetPosture( const SvxPostureItem& rNew ) { aPosture = rNew; }
155 0 : void SetCJKFont( const SvxFontItem& rNew ) { aCJKFont = rNew; }
156 0 : void SetCJKHeight( const SvxFontHeightItem& rNew ) { aCJKHeight = rNew; }
157 0 : void SetCJKWeight( const SvxWeightItem& rNew ) { aCJKWeight = rNew; }
158 0 : void SetCJKPosture( const SvxPostureItem& rNew ) { aCJKPosture = rNew; }
159 0 : void SetCTLFont( const SvxFontItem& rNew ) { aCTLFont = rNew; }
160 0 : void SetCTLHeight( const SvxFontHeightItem& rNew ) { aCTLHeight = rNew; }
161 0 : void SetCTLWeight( const SvxWeightItem& rNew ) { aCTLWeight = rNew; }
162 0 : void SetCTLPosture( const SvxPostureItem& rNew ) { aCTLPosture = rNew; }
163 0 : void SetUnderline( const SvxUnderlineItem& rNew ) { aUnderline = rNew; }
164 0 : void SetOverline( const SvxOverlineItem& rNew ) { aOverline = rNew; }
165 0 : void SetCrossedOut( const SvxCrossedOutItem& rNew ) { aCrossedOut = rNew; }
166 0 : void SetContour( const SvxContourItem& rNew ) { aContour = rNew; }
167 0 : void SetShadowed( const SvxShadowedItem& rNew ) { aShadowed = rNew; }
168 0 : void SetColor( const SvxColorItem& rNew ) { aColor = rNew; }
169 0 : void SetAdjust( const SvxAdjustItem& rNew )
170 : {
171 0 : aAdjust.SetAdjust( rNew.GetAdjust() );
172 0 : aAdjust.SetOneWord( rNew.GetOneWord() );
173 0 : aAdjust.SetLastBlock( rNew.GetLastBlock() );
174 0 : }
175 0 : void SetTextOrientation(const SvxFrameDirectionItem& rNew) { m_aTextOrientation = rNew; }
176 0 : void SetVerticalAlignment(const SwFmtVertOrient& rNew) { m_aVerticalAlignment = rNew; }
177 0 : void SetBox( const SvxBoxItem& rNew ) { aBox = rNew; }
178 0 : void SetBackground( const SvxBrushItem& rNew ) { aBackground = rNew; }
179 0 : void SetValueFormat( const String& rFmt, LanguageType eLng, LanguageType eSys )
180 0 : { sNumFmtString = rFmt; eNumFmtLanguage = eLng; eSysLanguage = eSys; }
181 :
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;
185 : };
186 :
187 : /*
188 : @remarks
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.
191 :
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.
194 :
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.
198 :
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
201 : [0, 1, 2, 5].
202 :
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
206 : the saved cells:
207 :
208 : 0 1 2 3 4 5
209 : +-----------------------------------------------------------------------+
210 : 0 | Saved | Saved | Saved | | | Saved |
211 : +-----------------------------------------------------------------------+
212 : 1 | Saved | Saved | Saved | | | Saved |
213 : +-----------------------------------------------------------------------+
214 : 2 | Saved | Saved | Saved | | | Saved |
215 : +-----------------------------------------------------------------------+
216 : 3 | | | | | | |
217 : +-----------------------------------------------------------------------+
218 : 4 | | | | | | |
219 : +-----------------------------------------------------------------------+
220 : 5 | Saved | Saved | Saved | | | Saved |
221 : +-----------+-----------+-----------+-----------+-----------+-----------+
222 :
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.
227 :
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.
230 : */
231 : class SW_DLLPUBLIC SwTableAutoFmt
232 : {
233 : friend void _FinitCore(); // To destroy dflt. pointer.
234 : static SwBoxAutoFmt* pDfltBoxAutoFmt;
235 :
236 : String aName;
237 : sal_uInt16 nStrResId;
238 :
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;
245 :
246 : // Calc specific flags.
247 : sal_Bool bInclWidthHeight : 1;
248 :
249 : SwBoxAutoFmt* aBoxAutoFmt[ 16 ];
250 :
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;
260 :
261 : public:
262 : SwTableAutoFmt( const String& rName );
263 : SwTableAutoFmt( const SwTableAutoFmt& rNew );
264 : ~SwTableAutoFmt();
265 :
266 : SwTableAutoFmt& operator=( const SwTableAutoFmt& rNew );
267 :
268 : void SetBoxFmt( const SwBoxAutoFmt& rNew, sal_uInt8 nPos );
269 : const SwBoxAutoFmt& GetBoxFmt( sal_uInt8 nPos ) const;
270 :
271 0 : void SetName( const String& rNew ) { aName = rNew; nStrResId = USHRT_MAX; }
272 0 : const String& GetName() const { return aName; }
273 :
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 ;
279 :
280 : void RestoreTableProperties(SwTable &table) const;
281 : void StoreTableProperties(const SwTable &table);
282 :
283 0 : sal_Bool IsFont() const { return bInclFont; }
284 0 : sal_Bool IsJustify() const { return bInclJustify; }
285 0 : sal_Bool IsFrame() const { return bInclFrame; }
286 0 : sal_Bool IsBackground() const { return bInclBackground; }
287 0 : sal_Bool IsValueFormat() const { return bInclValueFormat; }
288 :
289 0 : void SetFont( const sal_Bool bNew ) { bInclFont = bNew; }
290 0 : void SetJustify( const sal_Bool bNew ) { bInclJustify = bNew; }
291 0 : void SetFrame( const sal_Bool bNew ) { bInclFrame = bNew; }
292 0 : void SetBackground( const sal_Bool bNew ) { bInclBackground = bNew; }
293 0 : void SetValueFormat( const sal_Bool bNew ) { bInclValueFormat = bNew; }
294 0 : void SetWidthHeight( const sal_Bool bNew ) { bInclWidthHeight = bNew; }
295 :
296 : sal_Bool Load( SvStream& rStream, const SwAfVersions& );
297 : sal_Bool Save( SvStream& rStream, sal_uInt16 fileVersion ) const;
298 : };
299 :
300 : class SW_DLLPUBLIC SwTableAutoFmtTbl
301 : {
302 : struct Impl;
303 : ::boost::scoped_ptr<Impl> m_pImpl;
304 :
305 : SW_DLLPRIVATE sal_Bool Load( SvStream& rStream );
306 : SW_DLLPRIVATE sal_Bool Save( SvStream& rStream ) const;
307 :
308 : public:
309 : explicit SwTableAutoFmtTbl();
310 : ~SwTableAutoFmtTbl();
311 :
312 : size_t size() const;
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 : void MoveAutoFmt(size_t target, size_t source);
318 :
319 : sal_Bool Load();
320 : sal_Bool Save() const;
321 : };
322 :
323 : #endif
324 :
325 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|