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