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 :
20 : #include <tools/resid.hxx>
21 : #include <tools/stream.hxx>
22 : #include <tools/shl.hxx>
23 : #include <vcl/svapp.hxx>
24 : #include <sfx2/docfile.hxx>
25 : #include <svl/urihelper.hxx>
26 : #include <svl/zforlist.hxx>
27 : #include <svl/zformat.hxx>
28 : #include <unotools/pathoptions.hxx>
29 : #include <sfx2/app.hxx>
30 : #include <svx/dialmgr.hxx>
31 : #include <svx/dialogs.hrc>
32 : #include <swtable.hxx>
33 : #include <swtblfmt.hxx>
34 : #include <com/sun/star/text/VertOrientation.hpp>
35 : #include <swtypes.hxx>
36 : #include <doc.hxx>
37 : #include <poolfmt.hxx>
38 : #include <tblafmt.hxx>
39 : #include <cellatr.hxx>
40 : #include <SwStyleNameMapper.hxx>
41 : #include <hintids.hxx>
42 : #include <fmtornt.hxx>
43 : #include <editsh.hxx>
44 :
45 : /*
46 : * XXX: BIG RED NOTICE! Changes MUST be binary file format compatible and MUST
47 : * be synchronized with Calc's ScAutoFormat sc/source/core/tool/autoform.cxx
48 : */
49 :
50 : using ::editeng::SvxBorderLine;
51 :
52 : // until SO5PF
53 : const sal_uInt16 AUTOFORMAT_ID_X = 9501;
54 : const sal_uInt16 AUTOFORMAT_ID_358 = 9601;
55 : const sal_uInt16 AUTOFORMAT_DATA_ID_X = 9502;
56 :
57 : // from SO5
58 : //! In follow-up versions these IDs' values need to increase
59 : const sal_uInt16 AUTOFORMAT_ID_504 = 9801;
60 : const sal_uInt16 AUTOFORMAT_DATA_ID_504 = 9802;
61 :
62 : const sal_uInt16 AUTOFORMAT_DATA_ID_552 = 9902;
63 :
64 : // --- from 641 on: CJK and CTL font settings
65 : const sal_uInt16 AUTOFORMAT_DATA_ID_641 = 10002;
66 :
67 : // --- from 680/dr14 on: diagonal frame lines
68 : const sal_uInt16 AUTOFORMAT_ID_680DR14 = 10011;
69 : const sal_uInt16 AUTOFORMAT_DATA_ID_680DR14 = 10012;
70 :
71 : // --- from 680/dr25 on: store strings as UTF-8
72 : const sal_uInt16 AUTOFORMAT_ID_680DR25 = 10021;
73 :
74 : // --- from DEV300/overline2 on: overline
75 : const sal_uInt16 AUTOFORMAT_ID_300OVRLN = 10031;
76 : const sal_uInt16 AUTOFORMAT_DATA_ID_300OVRLN = 10032;
77 :
78 : // --- Bug fix to fdo#31005: Table Autoformats does not save/apply all properties (Writer and Calc)
79 : const sal_uInt16 AUTOFORMAT_ID_31005 = 10041;
80 : const sal_uInt16 AUTOFORMAT_DATA_ID_31005 = 10042;
81 :
82 : // current version
83 : const sal_uInt16 AUTOFORMAT_ID = AUTOFORMAT_ID_31005;
84 : const sal_uInt16 AUTOFORMAT_DATA_ID = AUTOFORMAT_DATA_ID_31005;
85 : const sal_uInt16 AUTOFORMAT_FILE_VERSION= SOFFICE_FILEFORMAT_50;
86 :
87 : SwBoxAutoFmt* SwTableAutoFmt::pDfltBoxAutoFmt = 0;
88 :
89 : #define AUTOTABLE_FORMAT_NAME "autotbl.fmt"
90 :
91 : namespace
92 : {
93 : /// Begins a writer-specific data block. Call before serializing any writer-specific properties.
94 0 : sal_uInt64 BeginSwBlock(SvStream& rStream)
95 : {
96 : // We need to write down the offset of the end of the writer-specific data, so that
97 : // calc can skip it. We'll only have that value after writing the data, so we
98 : // write a placeholder value first, write the data, then jump back and write the
99 : // real offset.
100 :
101 : // Note that we explicitly use sal_uInt64 instead of sal_Size (which can be 32
102 : // or 64 depending on platform) to ensure 64-bit portability on this front. I don't
103 : // actually know if autotbl.fmt as a whole is portable, since that requires all serialization
104 : // logic to be written with portability in mind.
105 0 : sal_uInt64 whereToWriteEndOfSwBlock = rStream.Tell();
106 :
107 0 : sal_uInt64 endOfSwBlock = 0;
108 0 : rStream.WriteUInt64( endOfSwBlock );
109 :
110 0 : return whereToWriteEndOfSwBlock;
111 : }
112 :
113 : /// Ends a writer-specific data block. Call after serializing writer-specific properties.
114 : /// Closes a corresponding BeginSwBlock call.
115 0 : void EndSwBlock(SvStream& rStream, sal_uInt64 whereToWriteEndOfSwBlock)
116 : {
117 0 : sal_uInt64 endOfSwBlock = rStream.Tell();
118 0 : rStream.Seek(whereToWriteEndOfSwBlock);
119 0 : rStream.WriteUInt64( endOfSwBlock );
120 0 : rStream.Seek(endOfSwBlock);
121 0 : }
122 :
123 : /**
124 : Helper class for writer-specific blocks. Begins a writer-specific block on construction,
125 : and closes it on destruction.
126 :
127 : See also: BeginSwBlock and EndSwBlock.
128 : */
129 : class WriterSpecificAutoFormatBlock : ::boost::noncopyable
130 : {
131 : public:
132 0 : WriterSpecificAutoFormatBlock(SvStream &rStream) : _rStream(rStream)
133 : {
134 0 : _whereToWriteEndOfBlock = BeginSwBlock(rStream);
135 0 : }
136 :
137 0 : ~WriterSpecificAutoFormatBlock()
138 : {
139 0 : EndSwBlock(_rStream, _whereToWriteEndOfBlock);
140 0 : }
141 :
142 : private:
143 : SvStream &_rStream;
144 : sal_uInt64 _whereToWriteEndOfBlock;
145 : };
146 :
147 : /// Checks whether a writer-specific block exists (i.e. size is not zero)
148 0 : bool WriterSpecificBlockExists(SvStream &stream)
149 : {
150 0 : sal_uInt64 endOfSwBlock = 0;
151 0 : stream.ReadUInt64( endOfSwBlock );
152 :
153 : // end-of-block pointing to itself indicates a zero-size block.
154 0 : return endOfSwBlock != stream.Tell();
155 : }
156 : }
157 :
158 : // Struct with version numbers of the Items
159 :
160 : struct SwAfVersions
161 : {
162 : public:
163 : sal_uInt16 nFontVersion;
164 : sal_uInt16 nFontHeightVersion;
165 : sal_uInt16 nWeightVersion;
166 : sal_uInt16 nPostureVersion;
167 : sal_uInt16 nUnderlineVersion;
168 : sal_uInt16 nOverlineVersion;
169 : sal_uInt16 nCrossedOutVersion;
170 : sal_uInt16 nContourVersion;
171 : sal_uInt16 nShadowedVersion;
172 : sal_uInt16 nColorVersion;
173 : sal_uInt16 nBoxVersion;
174 : sal_uInt16 nLineVersion;
175 : sal_uInt16 nBrushVersion;
176 :
177 : sal_uInt16 nAdjustVersion;
178 : sal_uInt16 m_nTextOrientationVersion;
179 : sal_uInt16 m_nVerticalAlignmentVersion;
180 :
181 : sal_uInt16 nHorJustifyVersion;
182 : sal_uInt16 nVerJustifyVersion;
183 : sal_uInt16 nOrientationVersion;
184 : sal_uInt16 nMarginVersion;
185 : sal_uInt16 nBoolVersion;
186 : sal_uInt16 nInt32Version;
187 : sal_uInt16 nRotateModeVersion;
188 :
189 : sal_uInt16 nNumFmtVersion;
190 :
191 : SwAfVersions();
192 : void Load( SvStream& rStream, sal_uInt16 nVer );
193 : };
194 :
195 0 : SwAfVersions::SwAfVersions() :
196 : nFontVersion(0),
197 : nFontHeightVersion(0),
198 : nWeightVersion(0),
199 : nPostureVersion(0),
200 : nUnderlineVersion(0),
201 : nOverlineVersion(0),
202 : nCrossedOutVersion(0),
203 : nContourVersion(0),
204 : nShadowedVersion(0),
205 : nColorVersion(0),
206 : nBoxVersion(0),
207 : nLineVersion(0),
208 : nBrushVersion(0),
209 : nAdjustVersion(0),
210 : m_nTextOrientationVersion(0),
211 : m_nVerticalAlignmentVersion(0),
212 : nHorJustifyVersion(0),
213 : nVerJustifyVersion(0),
214 : nOrientationVersion(0),
215 : nMarginVersion(0),
216 : nBoolVersion(0),
217 : nInt32Version(0),
218 : nRotateModeVersion(0),
219 0 : nNumFmtVersion(0)
220 : {
221 0 : }
222 :
223 0 : void SwAfVersions::Load( SvStream& rStream, sal_uInt16 nVer )
224 : {
225 0 : rStream.ReadUInt16( nFontVersion );
226 0 : rStream.ReadUInt16( nFontHeightVersion );
227 0 : rStream.ReadUInt16( nWeightVersion );
228 0 : rStream.ReadUInt16( nPostureVersion );
229 0 : rStream.ReadUInt16( nUnderlineVersion );
230 0 : if ( nVer >= AUTOFORMAT_ID_300OVRLN )
231 0 : rStream.ReadUInt16( nOverlineVersion );
232 0 : rStream.ReadUInt16( nCrossedOutVersion );
233 0 : rStream.ReadUInt16( nContourVersion );
234 0 : rStream.ReadUInt16( nShadowedVersion );
235 0 : rStream.ReadUInt16( nColorVersion );
236 0 : rStream.ReadUInt16( nBoxVersion );
237 0 : if ( nVer >= AUTOFORMAT_ID_680DR14 )
238 0 : rStream.ReadUInt16( nLineVersion );
239 0 : rStream.ReadUInt16( nBrushVersion );
240 0 : rStream.ReadUInt16( nAdjustVersion );
241 0 : if (nVer >= AUTOFORMAT_ID_31005 && WriterSpecificBlockExists(rStream))
242 : {
243 0 : rStream.ReadUInt16( m_nTextOrientationVersion );
244 0 : rStream.ReadUInt16( m_nVerticalAlignmentVersion );
245 : }
246 :
247 0 : rStream.ReadUInt16( nHorJustifyVersion );
248 0 : rStream.ReadUInt16( nVerJustifyVersion );
249 0 : rStream.ReadUInt16( nOrientationVersion );
250 0 : rStream.ReadUInt16( nMarginVersion );
251 0 : rStream.ReadUInt16( nBoolVersion );
252 0 : if ( nVer >= AUTOFORMAT_ID_504 )
253 : {
254 0 : rStream.ReadUInt16( nInt32Version );
255 0 : rStream.ReadUInt16( nRotateModeVersion );
256 : }
257 0 : rStream.ReadUInt16( nNumFmtVersion );
258 0 : }
259 :
260 0 : SwBoxAutoFmt::SwBoxAutoFmt()
261 0 : : aFont( *(SvxFontItem*)GetDfltAttr( RES_CHRATR_FONT ) ),
262 : aHeight( 240, 100, RES_CHRATR_FONTSIZE ),
263 : aWeight( WEIGHT_NORMAL, RES_CHRATR_WEIGHT ),
264 : aPosture( ITALIC_NONE, RES_CHRATR_POSTURE ),
265 :
266 0 : aCJKFont( *(SvxFontItem*)GetDfltAttr( RES_CHRATR_CJK_FONT ) ),
267 : aCJKHeight( 240, 100, RES_CHRATR_CJK_FONTSIZE ),
268 : aCJKWeight( WEIGHT_NORMAL, RES_CHRATR_CJK_WEIGHT ),
269 : aCJKPosture( ITALIC_NONE, RES_CHRATR_CJK_POSTURE ),
270 :
271 0 : aCTLFont( *(SvxFontItem*)GetDfltAttr( RES_CHRATR_CTL_FONT ) ),
272 : aCTLHeight( 240, 100, RES_CHRATR_CTL_FONTSIZE ),
273 : aCTLWeight( WEIGHT_NORMAL, RES_CHRATR_CTL_WEIGHT ),
274 : aCTLPosture( ITALIC_NONE, RES_CHRATR_CTL_POSTURE ),
275 :
276 : aUnderline( UNDERLINE_NONE, RES_CHRATR_UNDERLINE ),
277 : aOverline( UNDERLINE_NONE, RES_CHRATR_OVERLINE ),
278 : aCrossedOut( STRIKEOUT_NONE, RES_CHRATR_CROSSEDOUT ),
279 : aContour( false, RES_CHRATR_CONTOUR ),
280 : aShadowed( false, RES_CHRATR_SHADOWED ),
281 : aColor( RES_CHRATR_COLOR ),
282 : aBox( RES_BOX ),
283 : aTLBR( 0 ),
284 : aBLTR( 0 ),
285 : aBackground( RES_BACKGROUND ),
286 : aAdjust( SVX_ADJUST_LEFT, RES_PARATR_ADJUST ),
287 : m_aTextOrientation(FRMDIR_ENVIRONMENT, RES_FRAMEDIR),
288 : m_aVerticalAlignment(0, com::sun::star::text::VertOrientation::NONE, com::sun::star::text::RelOrientation::FRAME),
289 : aHorJustify( SVX_HOR_JUSTIFY_STANDARD, 0),
290 : aVerJustify( SVX_VER_JUSTIFY_STANDARD, 0),
291 : aStacked( 0 ),
292 : aMargin( 0 ),
293 : aLinebreak( 0 ),
294 : aRotateAngle( 0 ),
295 :
296 : // FIXME - add attribute IDs for the diagonal line items
297 : // aTLBR( RES_... ),
298 : // aBLTR( RES_... ),
299 0 : aRotateMode( SVX_ROTATE_MODE_STANDARD, 0 )
300 : {
301 0 : eSysLanguage = eNumFmtLanguage = ::GetAppLanguage();
302 0 : aBox.SetDistance( 55 );
303 0 : }
304 :
305 0 : SwBoxAutoFmt::SwBoxAutoFmt( const SwBoxAutoFmt& rNew )
306 : : aFont( rNew.aFont ),
307 : aHeight( rNew.aHeight ),
308 : aWeight( rNew.aWeight ),
309 : aPosture( rNew.aPosture ),
310 : aCJKFont( rNew.aCJKFont ),
311 : aCJKHeight( rNew.aCJKHeight ),
312 : aCJKWeight( rNew.aCJKWeight ),
313 : aCJKPosture( rNew.aCJKPosture ),
314 : aCTLFont( rNew.aCTLFont ),
315 : aCTLHeight( rNew.aCTLHeight ),
316 : aCTLWeight( rNew.aCTLWeight ),
317 : aCTLPosture( rNew.aCTLPosture ),
318 : aUnderline( rNew.aUnderline ),
319 : aOverline( rNew.aOverline ),
320 : aCrossedOut( rNew.aCrossedOut ),
321 : aContour( rNew.aContour ),
322 : aShadowed( rNew.aShadowed ),
323 : aColor( rNew.aColor ),
324 : aBox( rNew.aBox ),
325 : aTLBR( rNew.aTLBR ),
326 : aBLTR( rNew.aBLTR ),
327 : aBackground( rNew.aBackground ),
328 : aAdjust( rNew.aAdjust ),
329 : m_aTextOrientation(rNew.m_aTextOrientation),
330 : m_aVerticalAlignment(rNew.m_aVerticalAlignment),
331 : aHorJustify( rNew.aHorJustify ),
332 : aVerJustify( rNew.aVerJustify ),
333 : aStacked( rNew.aStacked ),
334 : aMargin( rNew.aMargin ),
335 : aLinebreak( rNew.aLinebreak ),
336 : aRotateAngle( rNew.aRotateAngle ),
337 : aRotateMode( rNew.aRotateMode ),
338 : sNumFmtString( rNew.sNumFmtString ),
339 : eSysLanguage( rNew.eSysLanguage ),
340 0 : eNumFmtLanguage( rNew.eNumFmtLanguage )
341 : {
342 0 : }
343 :
344 0 : SwBoxAutoFmt::~SwBoxAutoFmt()
345 : {
346 0 : }
347 :
348 0 : SwBoxAutoFmt& SwBoxAutoFmt::operator=( const SwBoxAutoFmt& rNew )
349 : {
350 0 : aFont = rNew.aFont;
351 0 : aHeight = rNew.aHeight;
352 0 : aWeight = rNew.aWeight;
353 0 : aPosture = rNew.aPosture;
354 0 : aCJKFont = rNew.aCJKFont;
355 0 : aCJKHeight = rNew.aCJKHeight;
356 0 : aCJKWeight = rNew.aCJKWeight;
357 0 : aCJKPosture = rNew.aCJKPosture;
358 0 : aCTLFont = rNew.aCTLFont;
359 0 : aCTLHeight = rNew.aCTLHeight;
360 0 : aCTLWeight = rNew.aCTLWeight;
361 0 : aCTLPosture = rNew.aCTLPosture;
362 0 : aUnderline = rNew.aUnderline;
363 0 : aOverline = rNew.aOverline;
364 0 : aCrossedOut = rNew.aCrossedOut;
365 0 : aContour = rNew.aContour;
366 0 : aShadowed = rNew.aShadowed;
367 0 : aColor = rNew.aColor;
368 0 : SetAdjust( rNew.aAdjust );
369 0 : m_aTextOrientation = rNew.m_aTextOrientation;
370 0 : m_aVerticalAlignment = rNew.m_aVerticalAlignment;
371 0 : aBox = rNew.aBox;
372 0 : aTLBR = rNew.aTLBR;
373 0 : aBLTR = rNew.aBLTR;
374 0 : aBackground = rNew.aBackground;
375 :
376 0 : aHorJustify = rNew.aHorJustify;
377 0 : aVerJustify = rNew.aVerJustify;
378 0 : aStacked.SetValue( rNew.aStacked.GetValue() );
379 0 : aMargin = rNew.aMargin;
380 0 : aLinebreak.SetValue( rNew.aLinebreak.GetValue() );
381 0 : aRotateAngle.SetValue( rNew.aRotateAngle.GetValue() );
382 0 : aRotateMode.SetValue( rNew.aRotateMode.GetValue() );
383 :
384 0 : sNumFmtString = rNew.sNumFmtString;
385 0 : eSysLanguage = rNew.eSysLanguage;
386 0 : eNumFmtLanguage = rNew.eNumFmtLanguage;
387 :
388 0 : return *this;
389 : }
390 :
391 : #define READ( aItem, aItemType, nVers )\
392 : pNew = aItem.Create(rStream, nVers ); \
393 : aItem = *(aItemType*)pNew; \
394 : delete pNew;
395 :
396 0 : sal_Bool SwBoxAutoFmt::Load( SvStream& rStream, const SwAfVersions& rVersions, sal_uInt16 nVer )
397 : {
398 : SfxPoolItem* pNew;
399 0 : SvxOrientationItem aOrientation( SVX_ORIENTATION_STANDARD, 0);
400 :
401 0 : READ( aFont, SvxFontItem , rVersions.nFontVersion)
402 :
403 0 : if( rStream.GetStreamCharSet() == aFont.GetCharSet() )
404 0 : aFont.SetCharSet(::osl_getThreadTextEncoding());
405 :
406 0 : READ( aHeight, SvxFontHeightItem , rVersions.nFontHeightVersion)
407 0 : READ( aWeight, SvxWeightItem , rVersions.nWeightVersion)
408 0 : READ( aPosture, SvxPostureItem , rVersions.nPostureVersion)
409 : // --- from 641 on: CJK and CTL font settings
410 0 : if( AUTOFORMAT_DATA_ID_641 <= nVer )
411 : {
412 0 : READ( aCJKFont, SvxFontItem , rVersions.nFontVersion)
413 0 : READ( aCJKHeight, SvxFontHeightItem , rVersions.nFontHeightVersion)
414 0 : READ( aCJKWeight, SvxWeightItem , rVersions.nWeightVersion)
415 0 : READ( aCJKPosture, SvxPostureItem , rVersions.nPostureVersion)
416 0 : READ( aCTLFont, SvxFontItem , rVersions.nFontVersion)
417 0 : READ( aCTLHeight, SvxFontHeightItem , rVersions.nFontHeightVersion)
418 0 : READ( aCTLWeight, SvxWeightItem , rVersions.nWeightVersion)
419 0 : READ( aCTLPosture, SvxPostureItem , rVersions.nPostureVersion)
420 : }
421 0 : READ( aUnderline, SvxUnderlineItem , rVersions.nUnderlineVersion)
422 0 : if( nVer >= AUTOFORMAT_DATA_ID_300OVRLN )
423 : {
424 0 : READ( aOverline, SvxOverlineItem , rVersions.nOverlineVersion)
425 : }
426 0 : READ( aCrossedOut, SvxCrossedOutItem , rVersions.nCrossedOutVersion)
427 0 : READ( aContour, SvxContourItem , rVersions.nContourVersion)
428 0 : READ( aShadowed, SvxShadowedItem , rVersions.nShadowedVersion)
429 0 : READ( aColor, SvxColorItem , rVersions.nColorVersion)
430 :
431 0 : READ( aBox, SvxBoxItem , rVersions.nBoxVersion)
432 :
433 : // --- from 680/dr14 on: diagonal frame lines
434 0 : if( nVer >= AUTOFORMAT_DATA_ID_680DR14 )
435 : {
436 0 : READ( aTLBR, SvxLineItem, rVersions.nLineVersion)
437 0 : READ( aBLTR, SvxLineItem, rVersions.nLineVersion)
438 : }
439 :
440 0 : READ( aBackground, SvxBrushItem , rVersions.nBrushVersion)
441 :
442 0 : pNew = aAdjust.Create(rStream, rVersions.nAdjustVersion );
443 0 : SetAdjust( *(SvxAdjustItem*)pNew );
444 0 : delete pNew;
445 :
446 0 : if (nVer >= AUTOFORMAT_DATA_ID_31005 && WriterSpecificBlockExists(rStream))
447 : {
448 0 : READ(m_aTextOrientation, SvxFrameDirectionItem, rVersions.m_nTextOrientationVersion);
449 0 : READ(m_aVerticalAlignment, SwFmtVertOrient, rVersions.m_nVerticalAlignmentVersion);
450 : }
451 :
452 0 : READ( aHorJustify, SvxHorJustifyItem , rVersions.nHorJustifyVersion)
453 0 : READ( aVerJustify, SvxVerJustifyItem , rVersions.nVerJustifyVersion)
454 :
455 0 : READ( aOrientation, SvxOrientationItem , rVersions.nOrientationVersion)
456 0 : READ( aMargin, SvxMarginItem , rVersions.nMarginVersion)
457 :
458 0 : pNew = aLinebreak.Create(rStream, rVersions.nBoolVersion );
459 0 : aLinebreak.SetValue( ((SfxBoolItem*)pNew)->GetValue() );
460 0 : delete pNew;
461 :
462 0 : if ( nVer >= AUTOFORMAT_DATA_ID_504 )
463 : {
464 0 : pNew = aRotateAngle.Create( rStream, rVersions.nInt32Version );
465 0 : aRotateAngle.SetValue( ((SfxInt32Item*)pNew)->GetValue() );
466 0 : delete pNew;
467 0 : pNew = aRotateMode.Create( rStream, rVersions.nRotateModeVersion );
468 0 : aRotateMode.SetValue( ((SvxRotateModeItem*)pNew)->GetValue() );
469 0 : delete pNew;
470 : }
471 :
472 0 : if( 0 == rVersions.nNumFmtVersion )
473 : {
474 : sal_uInt16 eSys, eLge;
475 : // --- from 680/dr25 on: store strings as UTF-8
476 0 : rtl_TextEncoding eCharSet = (nVer >= AUTOFORMAT_ID_680DR25) ? RTL_TEXTENCODING_UTF8 : rStream.GetStreamCharSet();
477 0 : sNumFmtString = rStream.ReadUniOrByteString( eCharSet );
478 0 : rStream.ReadUInt16( eSys ).ReadUInt16( eLge );
479 0 : eSysLanguage = (LanguageType) eSys;
480 0 : eNumFmtLanguage = (LanguageType) eLge;
481 0 : if ( eSysLanguage == LANGUAGE_SYSTEM ) // from old versions (Calc)
482 0 : eSysLanguage = ::GetAppLanguage();
483 : }
484 :
485 0 : aStacked.SetValue( aOrientation.IsStacked() );
486 0 : aRotateAngle.SetValue( aOrientation.GetRotation( aRotateAngle.GetValue() ) );
487 :
488 0 : return 0 == rStream.GetError();
489 : }
490 :
491 0 : sal_Bool SwBoxAutoFmt::Save( SvStream& rStream, sal_uInt16 fileVersion ) const
492 : {
493 0 : SvxOrientationItem aOrientation( aRotateAngle.GetValue(), aStacked.GetValue(), 0 );
494 :
495 0 : aFont.Store( rStream, aFont.GetVersion(fileVersion) );
496 0 : aHeight.Store( rStream, aHeight.GetVersion(fileVersion) );
497 0 : aWeight.Store( rStream, aWeight.GetVersion(fileVersion) );
498 0 : aPosture.Store( rStream, aPosture.GetVersion(fileVersion) );
499 0 : aCJKFont.Store( rStream, aCJKFont.GetVersion(fileVersion) );
500 0 : aCJKHeight.Store( rStream, aCJKHeight.GetVersion(fileVersion) );
501 0 : aCJKWeight.Store( rStream, aCJKWeight.GetVersion(fileVersion) );
502 0 : aCJKPosture.Store( rStream, aCJKPosture.GetVersion(fileVersion) );
503 0 : aCTLFont.Store( rStream, aCTLFont.GetVersion(fileVersion) );
504 0 : aCTLHeight.Store( rStream, aCTLHeight.GetVersion(fileVersion) );
505 0 : aCTLWeight.Store( rStream, aCTLWeight.GetVersion(fileVersion) );
506 0 : aCTLPosture.Store( rStream, aCTLPosture.GetVersion(fileVersion) );
507 0 : aUnderline.Store( rStream, aUnderline.GetVersion(fileVersion) );
508 0 : aOverline.Store( rStream, aOverline.GetVersion(fileVersion) );
509 0 : aCrossedOut.Store( rStream, aCrossedOut.GetVersion(fileVersion) );
510 0 : aContour.Store( rStream, aContour.GetVersion(fileVersion) );
511 0 : aShadowed.Store( rStream, aShadowed.GetVersion(fileVersion) );
512 0 : aColor.Store( rStream, aColor.GetVersion(fileVersion) );
513 0 : aBox.Store( rStream, aBox.GetVersion(fileVersion) );
514 0 : aTLBR.Store( rStream, aTLBR.GetVersion(fileVersion) );
515 0 : aBLTR.Store( rStream, aBLTR.GetVersion(fileVersion) );
516 0 : aBackground.Store( rStream, aBackground.GetVersion(fileVersion) );
517 :
518 0 : aAdjust.Store( rStream, aAdjust.GetVersion(fileVersion) );
519 0 : if (fileVersion >= SOFFICE_FILEFORMAT_50)
520 : {
521 0 : WriterSpecificAutoFormatBlock block(rStream);
522 :
523 0 : m_aTextOrientation.Store(rStream, m_aTextOrientation.GetVersion(fileVersion));
524 0 : m_aVerticalAlignment.Store(rStream, m_aVerticalAlignment.GetVersion(fileVersion));
525 : }
526 :
527 0 : aHorJustify.Store( rStream, aHorJustify.GetVersion(fileVersion) );
528 0 : aVerJustify.Store( rStream, aVerJustify.GetVersion(fileVersion) );
529 0 : aOrientation.Store( rStream, aOrientation.GetVersion(fileVersion) );
530 0 : aMargin.Store( rStream, aMargin.GetVersion(fileVersion) );
531 0 : aLinebreak.Store( rStream, aLinebreak.GetVersion(fileVersion) );
532 : // Calc Rotation from SO5
533 0 : aRotateAngle.Store( rStream, aRotateAngle.GetVersion(fileVersion) );
534 0 : aRotateMode.Store( rStream, aRotateMode.GetVersion(fileVersion) );
535 :
536 : // --- from 680/dr25 on: store strings as UTF-8
537 : write_uInt16_lenPrefixed_uInt8s_FromOUString(rStream, sNumFmtString,
538 0 : RTL_TEXTENCODING_UTF8);
539 0 : rStream.WriteUInt16( (sal_uInt16)eSysLanguage ).WriteUInt16( (sal_uInt16)eNumFmtLanguage );
540 :
541 0 : return 0 == rStream.GetError();
542 : }
543 :
544 0 : sal_Bool SwBoxAutoFmt::SaveVersionNo( SvStream& rStream, sal_uInt16 fileVersion ) const
545 : {
546 0 : rStream.WriteUInt16( aFont.GetVersion( fileVersion ) );
547 0 : rStream.WriteUInt16( aHeight.GetVersion( fileVersion ) );
548 0 : rStream.WriteUInt16( aWeight.GetVersion( fileVersion ) );
549 0 : rStream.WriteUInt16( aPosture.GetVersion( fileVersion ) );
550 0 : rStream.WriteUInt16( aUnderline.GetVersion( fileVersion ) );
551 0 : rStream.WriteUInt16( aOverline.GetVersion( fileVersion ) );
552 0 : rStream.WriteUInt16( aCrossedOut.GetVersion( fileVersion ) );
553 0 : rStream.WriteUInt16( aContour.GetVersion( fileVersion ) );
554 0 : rStream.WriteUInt16( aShadowed.GetVersion( fileVersion ) );
555 0 : rStream.WriteUInt16( aColor.GetVersion( fileVersion ) );
556 0 : rStream.WriteUInt16( aBox.GetVersion( fileVersion ) );
557 0 : rStream.WriteUInt16( aTLBR.GetVersion( fileVersion ) );
558 0 : rStream.WriteUInt16( aBackground.GetVersion( fileVersion ) );
559 :
560 0 : rStream.WriteUInt16( aAdjust.GetVersion( fileVersion ) );
561 :
562 0 : if (fileVersion >= SOFFICE_FILEFORMAT_50)
563 : {
564 0 : WriterSpecificAutoFormatBlock block(rStream);
565 :
566 0 : rStream.WriteUInt16( m_aTextOrientation.GetVersion(fileVersion) );
567 0 : rStream.WriteUInt16( m_aVerticalAlignment.GetVersion(fileVersion) );
568 : }
569 :
570 0 : rStream.WriteUInt16( aHorJustify.GetVersion( fileVersion ) );
571 0 : rStream.WriteUInt16( aVerJustify.GetVersion( fileVersion ) );
572 0 : rStream.WriteUInt16( SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0).GetVersion( fileVersion ) );
573 0 : rStream.WriteUInt16( aMargin.GetVersion( fileVersion ) );
574 0 : rStream.WriteUInt16( aLinebreak.GetVersion( fileVersion ) );
575 0 : rStream.WriteUInt16( aRotateAngle.GetVersion( fileVersion ) );
576 0 : rStream.WriteUInt16( aRotateMode.GetVersion( fileVersion ) );
577 :
578 0 : rStream.WriteUInt16( (sal_uInt16)0 ); // NumberFormat
579 :
580 0 : return 0 == rStream.GetError();
581 : }
582 :
583 0 : SwTableAutoFmt::SwTableAutoFmt( const OUString& rName )
584 : : m_aName( rName )
585 : , nStrResId( USHRT_MAX )
586 : , m_aBreak( SVX_BREAK_NONE, RES_BREAK )
587 : , m_aKeepWithNextPara( false, RES_KEEP )
588 : , m_aRepeatHeading( 0 )
589 : , m_bLayoutSplit( sal_True )
590 : , m_bRowSplit( sal_True )
591 : , m_bCollapsingBorders(sal_True)
592 0 : , m_aShadow( RES_SHADOW )
593 : {
594 0 : bInclFont = sal_True;
595 0 : bInclJustify = sal_True;
596 0 : bInclFrame = sal_True;
597 0 : bInclBackground = sal_True;
598 0 : bInclValueFormat = sal_True;
599 0 : bInclWidthHeight = sal_True;
600 :
601 0 : memset( aBoxAutoFmt, 0, sizeof( aBoxAutoFmt ) );
602 0 : }
603 :
604 0 : SwTableAutoFmt::SwTableAutoFmt( const SwTableAutoFmt& rNew )
605 : : m_aBreak( rNew.m_aBreak )
606 : , m_aKeepWithNextPara( false, RES_KEEP )
607 0 : , m_aShadow( RES_SHADOW )
608 : {
609 0 : for( sal_uInt8 n = 0; n < 16; ++n )
610 0 : aBoxAutoFmt[ n ] = 0;
611 0 : *this = rNew;
612 0 : }
613 :
614 0 : SwTableAutoFmt& SwTableAutoFmt::operator=( const SwTableAutoFmt& rNew )
615 : {
616 0 : if (&rNew == this)
617 0 : return *this;
618 :
619 0 : for( sal_uInt8 n = 0; n < 16; ++n )
620 : {
621 0 : if( aBoxAutoFmt[ n ] )
622 0 : delete aBoxAutoFmt[ n ];
623 :
624 0 : SwBoxAutoFmt* pFmt = rNew.aBoxAutoFmt[ n ];
625 0 : if( pFmt ) // if is set -> copy
626 0 : aBoxAutoFmt[ n ] = new SwBoxAutoFmt( *pFmt );
627 : else // else default
628 0 : aBoxAutoFmt[ n ] = 0;
629 : }
630 :
631 0 : m_aName = rNew.m_aName;
632 0 : nStrResId = rNew.nStrResId;
633 0 : bInclFont = rNew.bInclFont;
634 0 : bInclJustify = rNew.bInclJustify;
635 0 : bInclFrame = rNew.bInclFrame;
636 0 : bInclBackground = rNew.bInclBackground;
637 0 : bInclValueFormat = rNew.bInclValueFormat;
638 0 : bInclWidthHeight = rNew.bInclWidthHeight;
639 :
640 0 : m_aBreak = rNew.m_aBreak;
641 0 : m_aPageDesc = rNew.m_aPageDesc;
642 0 : m_aKeepWithNextPara = rNew.m_aKeepWithNextPara;
643 0 : m_aRepeatHeading = rNew.m_aRepeatHeading;
644 0 : m_bLayoutSplit = rNew.m_bLayoutSplit;
645 0 : m_bRowSplit = rNew.m_bRowSplit;
646 0 : m_bCollapsingBorders = rNew.m_bCollapsingBorders;
647 0 : m_aShadow = rNew.m_aShadow;
648 :
649 0 : return *this;
650 : }
651 :
652 0 : SwTableAutoFmt::~SwTableAutoFmt()
653 : {
654 0 : SwBoxAutoFmt** ppFmt = aBoxAutoFmt;
655 0 : for( sal_uInt8 n = 0; n < 16; ++n, ++ppFmt )
656 0 : if( *ppFmt )
657 0 : delete *ppFmt;
658 0 : }
659 :
660 0 : void SwTableAutoFmt::SetBoxFmt( const SwBoxAutoFmt& rNew, sal_uInt8 nPos )
661 : {
662 : OSL_ENSURE( nPos < 16, "wrong area" );
663 :
664 0 : SwBoxAutoFmt* pFmt = aBoxAutoFmt[ nPos ];
665 0 : if( pFmt ) // if is set -> copy
666 0 : *aBoxAutoFmt[ nPos ] = rNew;
667 : else // else set anew
668 0 : aBoxAutoFmt[ nPos ] = new SwBoxAutoFmt( rNew );
669 0 : }
670 :
671 0 : const SwBoxAutoFmt& SwTableAutoFmt::GetBoxFmt( sal_uInt8 nPos ) const
672 : {
673 : OSL_ENSURE( nPos < 16, "wrong area" );
674 :
675 0 : SwBoxAutoFmt* pFmt = aBoxAutoFmt[ nPos ];
676 0 : if( pFmt ) // if is set -> copy
677 0 : return *pFmt;
678 : else // else return the default
679 : {
680 : // If it doesn't exist yet:
681 0 : if( !pDfltBoxAutoFmt )
682 0 : pDfltBoxAutoFmt = new SwBoxAutoFmt;
683 0 : return *pDfltBoxAutoFmt;
684 : }
685 : }
686 :
687 0 : void SwTableAutoFmt::UpdateFromSet( sal_uInt8 nPos,
688 : const SfxItemSet& rSet,
689 : UpdateFlags eFlags,
690 : SvNumberFormatter* pNFmtr)
691 : {
692 : OSL_ENSURE( nPos < 16, "wrong area" );
693 :
694 0 : SwBoxAutoFmt* pFmt = aBoxAutoFmt[ nPos ];
695 0 : if( !pFmt ) // if is set -> copy
696 : {
697 0 : pFmt = new SwBoxAutoFmt;
698 0 : aBoxAutoFmt[ nPos ] = pFmt;
699 : }
700 :
701 0 : if( UPDATE_CHAR & eFlags )
702 : {
703 0 : pFmt->SetFont( (SvxFontItem&)rSet.Get( RES_CHRATR_FONT ) );
704 0 : pFmt->SetHeight( (SvxFontHeightItem&)rSet.Get( RES_CHRATR_FONTSIZE ) );
705 0 : pFmt->SetWeight( (SvxWeightItem&)rSet.Get( RES_CHRATR_WEIGHT ) );
706 0 : pFmt->SetPosture( (SvxPostureItem&)rSet.Get( RES_CHRATR_POSTURE ) );
707 0 : pFmt->SetCJKFont( (SvxFontItem&)rSet.Get( RES_CHRATR_CJK_FONT ) );
708 0 : pFmt->SetCJKHeight( (SvxFontHeightItem&)rSet.Get( RES_CHRATR_CJK_FONTSIZE ) );
709 0 : pFmt->SetCJKWeight( (SvxWeightItem&)rSet.Get( RES_CHRATR_CJK_WEIGHT ) );
710 0 : pFmt->SetCJKPosture( (SvxPostureItem&)rSet.Get( RES_CHRATR_CJK_POSTURE ) );
711 0 : pFmt->SetCTLFont( (SvxFontItem&)rSet.Get( RES_CHRATR_CTL_FONT ) );
712 0 : pFmt->SetCTLHeight( (SvxFontHeightItem&)rSet.Get( RES_CHRATR_CTL_FONTSIZE ) );
713 0 : pFmt->SetCTLWeight( (SvxWeightItem&)rSet.Get( RES_CHRATR_CTL_WEIGHT ) );
714 0 : pFmt->SetCTLPosture( (SvxPostureItem&)rSet.Get( RES_CHRATR_CTL_POSTURE ) );
715 0 : pFmt->SetUnderline( (SvxUnderlineItem&)rSet.Get( RES_CHRATR_UNDERLINE ) );
716 0 : pFmt->SetOverline( (SvxOverlineItem&)rSet.Get( RES_CHRATR_OVERLINE ) );
717 0 : pFmt->SetCrossedOut( (SvxCrossedOutItem&)rSet.Get( RES_CHRATR_CROSSEDOUT ) );
718 0 : pFmt->SetContour( (SvxContourItem&)rSet.Get( RES_CHRATR_CONTOUR ) );
719 0 : pFmt->SetShadowed( (SvxShadowedItem&)rSet.Get( RES_CHRATR_SHADOWED ) );
720 0 : pFmt->SetColor( (SvxColorItem&)rSet.Get( RES_CHRATR_COLOR ) );
721 0 : pFmt->SetAdjust( (SvxAdjustItem&)rSet.Get( RES_PARATR_ADJUST ) );
722 : }
723 0 : if( UPDATE_BOX & eFlags )
724 : {
725 0 : pFmt->SetBox( (SvxBoxItem&)rSet.Get( RES_BOX ) );
726 : // FIXME - add attribute IDs for the diagonal line items
727 : // pFmt->SetTLBR( (SvxLineItem&)rSet.Get( RES_... ) );
728 : // pFmt->SetBLTR( (SvxLineItem&)rSet.Get( RES_... ) );
729 0 : pFmt->SetBackground( (SvxBrushItem&)rSet.Get( RES_BACKGROUND ) );
730 0 : pFmt->SetTextOrientation(static_cast<const SvxFrameDirectionItem&>(rSet.Get(RES_FRAMEDIR)));
731 0 : pFmt->SetVerticalAlignment(static_cast<const SwFmtVertOrient&>(rSet.Get(RES_VERT_ORIENT)));
732 :
733 : const SwTblBoxNumFormat* pNumFmtItem;
734 0 : const SvNumberformat* pNumFormat = 0;
735 0 : if( SFX_ITEM_SET == rSet.GetItemState( RES_BOXATR_FORMAT, true,
736 0 : (const SfxPoolItem**)&pNumFmtItem ) && pNFmtr &&
737 0 : 0 != (pNumFormat = pNFmtr->GetEntry( pNumFmtItem->GetValue() )) )
738 0 : pFmt->SetValueFormat( ((SvNumberformat*)pNumFormat)->GetFormatstring(),
739 0 : pNumFormat->GetLanguage(),
740 0 : ::GetAppLanguage());
741 : else
742 : {
743 : // default
744 : pFmt->SetValueFormat( OUString(), LANGUAGE_SYSTEM,
745 0 : ::GetAppLanguage() );
746 : }
747 : }
748 :
749 : // we cannot handle the rest, that's specific to StarCalc
750 0 : }
751 :
752 0 : void SwTableAutoFmt::UpdateToSet(sal_uInt8 nPos, SfxItemSet& rSet,
753 : UpdateFlags eFlags, SvNumberFormatter* pNFmtr) const
754 : {
755 0 : const SwBoxAutoFmt& rChg = GetBoxFmt( nPos );
756 :
757 0 : if( UPDATE_CHAR & eFlags )
758 : {
759 0 : if( IsFont() )
760 : {
761 0 : rSet.Put( rChg.GetFont() );
762 0 : rSet.Put( rChg.GetHeight() );
763 0 : rSet.Put( rChg.GetWeight() );
764 0 : rSet.Put( rChg.GetPosture() );
765 : // do not insert empty CJK font
766 0 : const SvxFontItem& rCJKFont = rChg.GetCJKFont();
767 0 : if (!rCJKFont.GetStyleName().isEmpty())
768 : {
769 0 : rSet.Put( rChg.GetCJKFont() );
770 0 : rSet.Put( rChg.GetCJKHeight() );
771 0 : rSet.Put( rChg.GetCJKWeight() );
772 0 : rSet.Put( rChg.GetCJKPosture() );
773 : }
774 : else
775 : {
776 0 : rSet.Put( rChg.GetHeight(), RES_CHRATR_CJK_FONTSIZE );
777 0 : rSet.Put( rChg.GetWeight(), RES_CHRATR_CJK_WEIGHT );
778 0 : rSet.Put( rChg.GetPosture(), RES_CHRATR_CJK_POSTURE );
779 : }
780 : // do not insert empty CTL font
781 0 : const SvxFontItem& rCTLFont = rChg.GetCTLFont();
782 0 : if (!rCTLFont.GetStyleName().isEmpty())
783 : {
784 0 : rSet.Put( rChg.GetCTLFont() );
785 0 : rSet.Put( rChg.GetCTLHeight() );
786 0 : rSet.Put( rChg.GetCTLWeight() );
787 0 : rSet.Put( rChg.GetCTLPosture() );
788 : }
789 : else
790 : {
791 0 : rSet.Put( rChg.GetHeight(), RES_CHRATR_CTL_FONTSIZE );
792 0 : rSet.Put( rChg.GetWeight(), RES_CHRATR_CTL_WEIGHT );
793 0 : rSet.Put( rChg.GetPosture(), RES_CHRATR_CTL_POSTURE );
794 : }
795 0 : rSet.Put( rChg.GetUnderline() );
796 0 : rSet.Put( rChg.GetOverline() );
797 0 : rSet.Put( rChg.GetCrossedOut() );
798 0 : rSet.Put( rChg.GetContour() );
799 0 : rSet.Put( rChg.GetShadowed() );
800 0 : rSet.Put( rChg.GetColor() );
801 : }
802 0 : if( IsJustify() )
803 0 : rSet.Put( rChg.GetAdjust() );
804 : }
805 :
806 0 : if( UPDATE_BOX & eFlags )
807 : {
808 0 : if( IsFrame() )
809 : {
810 0 : rSet.Put( rChg.GetBox() );
811 : // FIXME - uncomment the lines to put the diagonal line items
812 : // rSet.Put( rChg.GetTLBR() );
813 : // rSet.Put( rChg.GetBLTR() );
814 : }
815 0 : if( IsBackground() )
816 0 : rSet.Put( rChg.GetBackground() );
817 :
818 0 : rSet.Put(rChg.GetTextOrientation());
819 0 : rSet.Put(rChg.GetVerticalAlignment());
820 :
821 0 : if( IsValueFormat() && pNFmtr )
822 : {
823 0 : OUString sFmt;
824 : LanguageType eLng, eSys;
825 0 : rChg.GetValueFormat( sFmt, eLng, eSys );
826 0 : if( !sFmt.isEmpty() )
827 : {
828 : short nType;
829 : bool bNew;
830 : sal_Int32 nCheckPos;
831 : sal_uInt32 nKey = pNFmtr->GetIndexPuttingAndConverting( sFmt, eLng,
832 0 : eSys, nType, bNew, nCheckPos);
833 0 : rSet.Put( SwTblBoxNumFormat( nKey ));
834 : }
835 : else
836 0 : rSet.ClearItem( RES_BOXATR_FORMAT );
837 : }
838 : }
839 :
840 : // we cannot handle the rest, that's specific to StarCalc
841 0 : }
842 :
843 0 : void SwTableAutoFmt::RestoreTableProperties(SwTable &table) const
844 : {
845 0 : SwTableFmt *pFormat = table.GetTableFmt();
846 0 : if (!pFormat)
847 0 : return;
848 :
849 0 : SwDoc *pDoc = pFormat->GetDoc();
850 0 : if (!pDoc)
851 0 : return;
852 :
853 0 : SfxItemSet rSet(pDoc->GetAttrPool(), aTableSetRange);
854 :
855 0 : rSet.Put(m_aBreak);
856 0 : rSet.Put(m_aPageDesc);
857 0 : rSet.Put(SwFmtLayoutSplit(m_bLayoutSplit));
858 0 : rSet.Put(SfxBoolItem(RES_COLLAPSING_BORDERS, m_bCollapsingBorders));
859 0 : rSet.Put(m_aKeepWithNextPara);
860 0 : rSet.Put(m_aShadow);
861 :
862 0 : pFormat->SetFmtAttr(rSet);
863 :
864 0 : SwEditShell *pShell = pDoc->GetEditShell();
865 0 : pDoc->SetRowSplit(*pShell->getShellCrsr(false), SwFmtRowSplit(m_bRowSplit));
866 :
867 0 : table.SetRowsToRepeat(m_aRepeatHeading);
868 : }
869 :
870 0 : void SwTableAutoFmt::StoreTableProperties(const SwTable &table)
871 : {
872 0 : SwTableFmt *pFormat = table.GetTableFmt();
873 0 : if (!pFormat)
874 0 : return;
875 :
876 0 : SwDoc *pDoc = pFormat->GetDoc();
877 0 : if (!pDoc)
878 0 : return;
879 :
880 0 : SwEditShell *pShell = pDoc->GetEditShell();
881 0 : SwFmtRowSplit *pRowSplit = 0;
882 0 : pDoc->GetRowSplit(*pShell->getShellCrsr(false), pRowSplit);
883 0 : m_bRowSplit = pRowSplit ? pRowSplit->GetValue() : sal_False;
884 0 : delete pRowSplit;
885 0 : pRowSplit = 0;
886 :
887 0 : const SfxItemSet &rSet = pFormat->GetAttrSet();
888 :
889 0 : m_aBreak = static_cast<const SvxFmtBreakItem&>(rSet.Get(RES_BREAK));
890 0 : m_aPageDesc = static_cast<const SwFmtPageDesc&>(rSet.Get(RES_PAGEDESC));
891 0 : const SwFmtLayoutSplit &layoutSplit = static_cast<const SwFmtLayoutSplit&>(rSet.Get(RES_LAYOUT_SPLIT));
892 0 : m_bLayoutSplit = layoutSplit.GetValue();
893 0 : m_bCollapsingBorders = static_cast<const SfxBoolItem&>(rSet.Get(RES_COLLAPSING_BORDERS)).GetValue();
894 :
895 0 : m_aKeepWithNextPara = static_cast<const SvxFmtKeepItem&>(rSet.Get(RES_KEEP));
896 0 : m_aRepeatHeading = table.GetRowsToRepeat();
897 0 : m_aShadow = static_cast<const SvxShadowItem&>(rSet.Get(RES_SHADOW));
898 : }
899 :
900 0 : sal_Bool SwTableAutoFmt::Load( SvStream& rStream, const SwAfVersions& rVersions )
901 : {
902 0 : sal_uInt16 nVal = 0;
903 0 : rStream.ReadUInt16( nVal );
904 0 : sal_Bool bRet = 0 == rStream.GetError();
905 :
906 0 : if( bRet && (nVal == AUTOFORMAT_DATA_ID_X ||
907 0 : (AUTOFORMAT_DATA_ID_504 <= nVal && nVal <= AUTOFORMAT_DATA_ID)) )
908 : {
909 : sal_Bool b;
910 : // --- from 680/dr25 on: store strings as UTF-8
911 0 : rtl_TextEncoding eCharSet = (nVal >= AUTOFORMAT_ID_680DR25) ? RTL_TEXTENCODING_UTF8 : rStream.GetStreamCharSet();
912 0 : m_aName = rStream.ReadUniOrByteString( eCharSet );
913 0 : if( AUTOFORMAT_DATA_ID_552 <= nVal )
914 : {
915 0 : rStream.ReadUInt16( nStrResId );
916 0 : sal_uInt16 nId = RID_SVXSTR_TBLAFMT_BEGIN + nStrResId;
917 0 : if( RID_SVXSTR_TBLAFMT_BEGIN <= nId &&
918 : nId < RID_SVXSTR_TBLAFMT_END )
919 : {
920 0 : m_aName = SVX_RESSTR( nId );
921 : }
922 : else
923 0 : nStrResId = USHRT_MAX;
924 : }
925 0 : rStream.ReadUChar( b ); bInclFont = b;
926 0 : rStream.ReadUChar( b ); bInclJustify = b;
927 0 : rStream.ReadUChar( b ); bInclFrame = b;
928 0 : rStream.ReadUChar( b ); bInclBackground = b;
929 0 : rStream.ReadUChar( b ); bInclValueFormat = b;
930 0 : rStream.ReadUChar( b ); bInclWidthHeight = b;
931 :
932 0 : if (nVal >= AUTOFORMAT_DATA_ID_31005 && WriterSpecificBlockExists(rStream))
933 : {
934 0 : SfxPoolItem* pNew = 0;
935 :
936 0 : READ(m_aBreak, SvxFmtBreakItem, AUTOFORMAT_FILE_VERSION);
937 0 : READ(m_aPageDesc, SwFmtPageDesc, AUTOFORMAT_FILE_VERSION);
938 0 : READ(m_aKeepWithNextPara, SvxFmtKeepItem, AUTOFORMAT_FILE_VERSION);
939 :
940 0 : rStream.ReadUInt16( m_aRepeatHeading ).ReadUChar( m_bLayoutSplit ).ReadUChar( m_bRowSplit ).ReadUChar( m_bCollapsingBorders );
941 :
942 0 : READ(m_aShadow, SvxShadowItem, AUTOFORMAT_FILE_VERSION);
943 : }
944 :
945 0 : bRet = 0 == rStream.GetError();
946 :
947 0 : for( sal_uInt8 i = 0; bRet && i < 16; ++i )
948 : {
949 0 : SwBoxAutoFmt* pFmt = new SwBoxAutoFmt;
950 0 : bRet = pFmt->Load( rStream, rVersions, nVal );
951 0 : if( bRet )
952 0 : aBoxAutoFmt[ i ] = pFmt;
953 : else
954 : {
955 0 : delete pFmt;
956 0 : break;
957 : }
958 : }
959 : }
960 0 : return bRet;
961 : }
962 :
963 0 : sal_Bool SwTableAutoFmt::Save( SvStream& rStream, sal_uInt16 fileVersion ) const
964 : {
965 0 : sal_uInt16 nVal = AUTOFORMAT_DATA_ID;
966 : sal_Bool b;
967 0 : rStream.WriteUInt16( nVal );
968 : // --- from 680/dr25 on: store strings as UTF-8
969 : write_uInt16_lenPrefixed_uInt8s_FromOUString(rStream, m_aName,
970 0 : RTL_TEXTENCODING_UTF8 );
971 0 : rStream.WriteUInt16( nStrResId );
972 0 : rStream.WriteUChar( ( b = bInclFont ) );
973 0 : rStream.WriteUChar( ( b = bInclJustify ) );
974 0 : rStream.WriteUChar( ( b = bInclFrame ) );
975 0 : rStream.WriteUChar( ( b = bInclBackground ) );
976 0 : rStream.WriteUChar( ( b = bInclValueFormat ) );
977 0 : rStream.WriteUChar( ( b = bInclWidthHeight ) );
978 :
979 : {
980 0 : WriterSpecificAutoFormatBlock block(rStream);
981 :
982 0 : m_aBreak.Store(rStream, m_aBreak.GetVersion(fileVersion));
983 0 : m_aPageDesc.Store(rStream, m_aPageDesc.GetVersion(fileVersion));
984 0 : m_aKeepWithNextPara.Store(rStream, m_aKeepWithNextPara.GetVersion(fileVersion));
985 0 : rStream.WriteUInt16( m_aRepeatHeading ).WriteUChar( m_bLayoutSplit ).WriteUChar( m_bRowSplit ).WriteUChar( m_bCollapsingBorders );
986 0 : m_aShadow.Store(rStream, m_aShadow.GetVersion(fileVersion));
987 : }
988 :
989 0 : sal_Bool bRet = 0 == rStream.GetError();
990 :
991 0 : for( int i = 0; bRet && i < 16; ++i )
992 : {
993 0 : SwBoxAutoFmt* pFmt = aBoxAutoFmt[ i ];
994 0 : if( !pFmt ) // if not set -> write default
995 : {
996 : // If it doesn't exist yet:
997 0 : if( !pDfltBoxAutoFmt )
998 0 : pDfltBoxAutoFmt = new SwBoxAutoFmt;
999 0 : pFmt = pDfltBoxAutoFmt;
1000 : }
1001 0 : bRet = pFmt->Save( rStream, fileVersion );
1002 : }
1003 0 : return bRet;
1004 : }
1005 :
1006 0 : struct SwTableAutoFmtTbl::Impl
1007 : {
1008 : boost::ptr_vector<SwTableAutoFmt> m_AutoFormats;
1009 : };
1010 :
1011 0 : size_t SwTableAutoFmtTbl::size() const
1012 : {
1013 0 : return m_pImpl->m_AutoFormats.size();
1014 : }
1015 :
1016 0 : SwTableAutoFmt const& SwTableAutoFmtTbl::operator[](size_t const i) const
1017 : {
1018 0 : return m_pImpl->m_AutoFormats[i];
1019 : }
1020 0 : SwTableAutoFmt & SwTableAutoFmtTbl::operator[](size_t const i)
1021 : {
1022 0 : return m_pImpl->m_AutoFormats[i];
1023 : }
1024 :
1025 : void
1026 0 : SwTableAutoFmtTbl::InsertAutoFmt(size_t const i, SwTableAutoFmt *const pFmt)
1027 : {
1028 0 : m_pImpl->m_AutoFormats.insert(m_pImpl->m_AutoFormats.begin() + i, pFmt);
1029 0 : }
1030 :
1031 0 : void SwTableAutoFmtTbl::EraseAutoFmt(size_t const i)
1032 : {
1033 0 : m_pImpl->m_AutoFormats.erase(m_pImpl->m_AutoFormats.begin() + i);
1034 0 : }
1035 :
1036 0 : SwTableAutoFmt* SwTableAutoFmtTbl::ReleaseAutoFmt(size_t const i)
1037 : {
1038 0 : return m_pImpl->m_AutoFormats.release(m_pImpl->m_AutoFormats.begin() + i).release();
1039 : }
1040 :
1041 0 : SwTableAutoFmtTbl::~SwTableAutoFmtTbl()
1042 : {
1043 0 : }
1044 :
1045 0 : SwTableAutoFmtTbl::SwTableAutoFmtTbl()
1046 0 : : m_pImpl(new Impl)
1047 : {
1048 0 : OUString sNm;
1049 : SwTableAutoFmt* pNew = new SwTableAutoFmt(
1050 0 : SwStyleNameMapper::GetUIName( RES_POOLCOLL_STANDARD, sNm ) );
1051 :
1052 0 : SwBoxAutoFmt aNew;
1053 :
1054 : sal_uInt8 i;
1055 :
1056 0 : Color aColor( COL_BLUE );
1057 0 : SvxBrushItem aBrushItem( aColor, RES_BACKGROUND );
1058 0 : aNew.SetBackground( aBrushItem );
1059 0 : aNew.SetColor( SvxColorItem(Color( COL_WHITE ), RES_CHRATR_COLOR) );
1060 :
1061 0 : for( i = 0; i < 4; ++i )
1062 0 : pNew->SetBoxFmt( aNew, i );
1063 :
1064 : // 70% gray
1065 0 : aBrushItem.SetColor( RGB_COLORDATA( 0x4d, 0x4d, 0x4d ) );
1066 0 : aNew.SetBackground( aBrushItem );
1067 0 : for( i = 4; i <= 12; i += 4 )
1068 0 : pNew->SetBoxFmt( aNew, i );
1069 :
1070 : // 20% gray
1071 0 : aBrushItem.SetColor( RGB_COLORDATA( 0xcc, 0xcc, 0xcc ) );
1072 0 : aNew.SetBackground( aBrushItem );
1073 0 : aColor.SetColor( COL_BLACK );
1074 0 : aNew.SetColor( SvxColorItem( aColor, RES_CHRATR_COLOR) );
1075 0 : for( i = 7; i <= 15; i += 4 )
1076 0 : pNew->SetBoxFmt( aNew, i );
1077 0 : for( i = 13; i <= 14; ++i )
1078 0 : pNew->SetBoxFmt( aNew, i );
1079 :
1080 0 : aBrushItem.SetColor( Color( COL_WHITE ) );
1081 0 : aNew.SetBackground( aBrushItem );
1082 0 : for( i = 5; i <= 6; ++i )
1083 0 : pNew->SetBoxFmt( aNew, i );
1084 0 : for( i = 9; i <= 10; ++i )
1085 0 : pNew->SetBoxFmt( aNew, i );
1086 :
1087 0 : SvxBoxItem aBox( RES_BOX );
1088 0 : aBox.SetDistance( 55 );
1089 0 : SvxBorderLine aLn( &aColor, DEF_LINE_WIDTH_0 );
1090 0 : aBox.SetLine( &aLn, BOX_LINE_LEFT );
1091 0 : aBox.SetLine( &aLn, BOX_LINE_BOTTOM );
1092 :
1093 0 : for( i = 0; i <= 15; ++i )
1094 : {
1095 0 : aBox.SetLine( i <= 3 ? &aLn : 0, BOX_LINE_TOP );
1096 0 : aBox.SetLine( (3 == ( i & 3 )) ? &aLn : 0, BOX_LINE_RIGHT );
1097 0 : ((SwBoxAutoFmt&)pNew->GetBoxFmt( i )).SetBox( aBox );
1098 : }
1099 :
1100 0 : m_pImpl->m_AutoFormats.push_back(pNew);
1101 0 : }
1102 :
1103 0 : sal_Bool SwTableAutoFmtTbl::Load()
1104 : {
1105 0 : sal_Bool bRet = sal_False;
1106 0 : OUString sNm(AUTOTABLE_FORMAT_NAME);
1107 0 : SvtPathOptions aOpt;
1108 0 : if( aOpt.SearchFile( sNm, SvtPathOptions::PATH_USERCONFIG ))
1109 : {
1110 0 : SfxMedium aStream( sNm, STREAM_STD_READ );
1111 0 : bRet = Load( *aStream.GetInStream() );
1112 : }
1113 : else
1114 0 : bRet = sal_False;
1115 0 : return bRet;
1116 : }
1117 :
1118 0 : sal_Bool SwTableAutoFmtTbl::Save() const
1119 : {
1120 0 : SvtPathOptions aPathOpt;
1121 0 : const OUString sNm( aPathOpt.GetUserConfigPath() + "/" + AUTOTABLE_FORMAT_NAME );
1122 0 : SfxMedium aStream(sNm, STREAM_STD_WRITE );
1123 0 : return Save( *aStream.GetOutStream() ) && aStream.Commit();
1124 : }
1125 :
1126 0 : sal_Bool SwTableAutoFmtTbl::Load( SvStream& rStream )
1127 : {
1128 0 : sal_Bool bRet = 0 == rStream.GetError();
1129 0 : if (bRet)
1130 : {
1131 : // Attention: We need to read a general Header here
1132 0 : sal_uInt16 nVal = 0;
1133 0 : rStream.ReadUInt16( nVal );
1134 0 : bRet = 0 == rStream.GetError();
1135 :
1136 0 : if( bRet )
1137 : {
1138 0 : SwAfVersions aVersions;
1139 :
1140 : // Default version is 5.0, unless we detect an old format ID.
1141 0 : sal_uInt16 nFileVers = SOFFICE_FILEFORMAT_50;
1142 0 : if(nVal < AUTOFORMAT_ID_31005)
1143 0 : nFileVers = SOFFICE_FILEFORMAT_40;
1144 :
1145 0 : if( nVal == AUTOFORMAT_ID_358 ||
1146 0 : (AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
1147 : {
1148 : sal_uInt8 nChrSet, nCnt;
1149 0 : long nPos = rStream.Tell();
1150 0 : rStream.ReadUChar( nCnt ).ReadUChar( nChrSet );
1151 0 : if( rStream.Tell() != sal_uLong(nPos + nCnt) )
1152 : {
1153 : OSL_ENSURE( !this, "The Header contains more or newer Data" );
1154 0 : rStream.Seek( nPos + nCnt );
1155 : }
1156 0 : rStream.SetStreamCharSet( (rtl_TextEncoding)nChrSet );
1157 0 : rStream.SetVersion( nFileVers );
1158 : }
1159 :
1160 0 : if( nVal == AUTOFORMAT_ID_358 || nVal == AUTOFORMAT_ID_X ||
1161 0 : (AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
1162 : {
1163 0 : aVersions.Load( rStream, nVal ); // Item versions
1164 :
1165 : SwTableAutoFmt* pNew;
1166 0 : sal_uInt16 nAnz = 0;
1167 0 : rStream.ReadUInt16( nAnz );
1168 :
1169 0 : bRet = 0 == rStream.GetError();
1170 :
1171 0 : for( sal_uInt16 i = 0; i < nAnz; ++i )
1172 : {
1173 0 : pNew = new SwTableAutoFmt( OUString() );
1174 0 : bRet = pNew->Load( rStream, aVersions );
1175 0 : if( bRet )
1176 : {
1177 0 : m_pImpl->m_AutoFormats.push_back(pNew);
1178 : }
1179 : else
1180 : {
1181 0 : delete pNew;
1182 0 : break;
1183 : }
1184 0 : }
1185 : }
1186 : else
1187 : {
1188 0 : bRet = false;
1189 : }
1190 : }
1191 : }
1192 0 : return bRet;
1193 : }
1194 :
1195 0 : sal_Bool SwTableAutoFmtTbl::Save( SvStream& rStream ) const
1196 : {
1197 0 : sal_Bool bRet = 0 == rStream.GetError();
1198 0 : if (bRet)
1199 : {
1200 0 : rStream.SetVersion(AUTOFORMAT_FILE_VERSION);
1201 :
1202 : // Attention: We need to save a general Header here
1203 0 : sal_uInt16 nVal = AUTOFORMAT_ID;
1204 0 : rStream.WriteUInt16( nVal )
1205 0 : .WriteUChar( (sal_uInt8)2 ) // Character count of the Header including this value
1206 0 : .WriteUChar( (sal_uInt8)GetStoreCharSet( ::osl_getThreadTextEncoding() ) );
1207 :
1208 0 : bRet = 0 == rStream.GetError();
1209 :
1210 : // Write this version number for all attributes
1211 0 : m_pImpl->m_AutoFormats[0].GetBoxFmt(0).SaveVersionNo(
1212 0 : rStream, AUTOFORMAT_FILE_VERSION);
1213 :
1214 0 : rStream.WriteUInt16( static_cast<sal_uInt16>(m_pImpl->m_AutoFormats.size() - 1) );
1215 0 : bRet = 0 == rStream.GetError();
1216 :
1217 0 : for (sal_uInt16 i = 1; bRet && i < m_pImpl->m_AutoFormats.size(); ++i)
1218 : {
1219 0 : SwTableAutoFmt const& rFmt = m_pImpl->m_AutoFormats[i];
1220 0 : bRet = rFmt.Save(rStream, AUTOFORMAT_FILE_VERSION);
1221 : }
1222 : }
1223 0 : rStream.Flush();
1224 0 : return bRet;
1225 : }
1226 :
1227 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|