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