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 "autoform.hxx"
21 :
22 : #include <sfx2/app.hxx>
23 : #include <sfx2/docfile.hxx>
24 : #include <unotools/pathoptions.hxx>
25 : #include <svl/itemset.hxx>
26 : #include <tools/shl.hxx>
27 : #include <vcl/svapp.hxx>
28 : #include <vcl/outdev.hxx>
29 : #include <svx/dialmgr.hxx>
30 : #include <svx/dialogs.hrc>
31 : #include <editeng/langitem.hxx>
32 : #include <tools/urlobj.hxx>
33 : #include <unotools/transliterationwrapper.hxx>
34 : #include <tools/tenccvt.hxx>
35 :
36 : #include "globstr.hrc"
37 : #include "document.hxx"
38 :
39 : //------------------------------------------------------------------------
40 :
41 : const sal_Char *linker_dummy = "";
42 :
43 : static const sal_Char sAutoTblFmtName[] = "autotbl.fmt";
44 :
45 : // till SO5PF
46 : const sal_uInt16 AUTOFORMAT_ID_X = 9501;
47 : const sal_uInt16 AUTOFORMAT_ID_358 = 9601;
48 : const sal_uInt16 AUTOFORMAT_DATA_ID_X = 9502;
49 :
50 : // from SO5 on
51 : // in following versions the value of the IDs must be higher
52 : const sal_uInt16 AUTOFORMAT_ID_504 = 9801;
53 : const sal_uInt16 AUTOFORMAT_DATA_ID_504 = 9802;
54 :
55 : const sal_uInt16 AUTOFORMAT_ID_552 = 9901;
56 : const sal_uInt16 AUTOFORMAT_DATA_ID_552 = 9902;
57 :
58 : // --- from 641 on: CJK and CTL font settings
59 : const sal_uInt16 AUTOFORMAT_ID_641 = 10001;
60 : const sal_uInt16 AUTOFORMAT_DATA_ID_641 = 10002;
61 :
62 : // --- from 680/dr14 on: diagonal frame lines
63 : const sal_uInt16 AUTOFORMAT_ID_680DR14 = 10011;
64 : const sal_uInt16 AUTOFORMAT_DATA_ID_680DR14 = 10012;
65 :
66 : // --- from 680/dr25 on: store strings as UTF-8
67 : const sal_uInt16 AUTOFORMAT_ID_680DR25 = 10021;
68 : const sal_uInt16 AUTOFORMAT_DATA_ID_680DR25 = 10022;
69 :
70 : // --- from DEV300/overline2 on: overline support
71 : const sal_uInt16 AUTOFORMAT_ID_300OVRLN = 10031;
72 : const sal_uInt16 AUTOFORMAT_DATA_ID_300OVRLN = 10032;
73 :
74 : // --- Bug fix to fdo#31005: Table Autoformats does not save/apply all properties (Writer and Calc)
75 : const sal_uInt16 AUTOFORMAT_ID_31005 = 10041;
76 : const sal_uInt16 AUTOFORMAT_DATA_ID_31005 = 10042;
77 :
78 : // current version
79 : const sal_uInt16 AUTOFORMAT_ID = AUTOFORMAT_ID_31005;
80 : const sal_uInt16 AUTOFORMAT_DATA_ID = AUTOFORMAT_DATA_ID_31005;
81 :
82 :
83 : namespace
84 : {
85 : /// Read an AutoFormatSwBlob from stream.
86 0 : SvStream& operator>>(SvStream &stream, AutoFormatSwBlob &blob)
87 : {
88 0 : blob.Reset();
89 :
90 0 : sal_uInt64 endOfBlob = 0;
91 0 : stream >> endOfBlob;
92 :
93 0 : const sal_uInt64 currentPosition = stream.Tell();
94 0 : const sal_uInt64 blobSize = endOfBlob - currentPosition;
95 : // A zero-size indicates an empty blob. This happens when Calc creates a new autoformat,
96 : // since it (naturally) doesn't have any writer-specific data to write.
97 0 : if (blobSize)
98 : {
99 0 : blob.pData = new sal_uInt8[blobSize];
100 0 : blob.size = static_cast<sal_Size>(blobSize);
101 0 : stream.Read(blob.pData, blob.size);
102 : }
103 :
104 0 : return stream;
105 : }
106 :
107 : /// Write an AutoFormatSwBlob to stream.
108 0 : SvStream& operator<<(SvStream &stream, AutoFormatSwBlob &blob)
109 : {
110 0 : const sal_uInt64 endOfBlob = stream.Tell() + sizeof(sal_uInt64) + blob.size;
111 0 : stream << endOfBlob;
112 0 : if (blob.size)
113 0 : stream.Write(blob.pData, blob.size);
114 :
115 0 : return stream;
116 : }
117 : }
118 :
119 0 : ScAfVersions::ScAfVersions() :
120 : nFontVersion(0),
121 : nFontHeightVersion(0),
122 : nWeightVersion(0),
123 : nPostureVersion(0),
124 : nUnderlineVersion(0),
125 : nOverlineVersion(0),
126 : nCrossedOutVersion(0),
127 : nContourVersion(0),
128 : nShadowedVersion(0),
129 : nColorVersion(0),
130 : nBoxVersion(0),
131 : nLineVersion(0),
132 : nBrushVersion(0),
133 : nAdjustVersion(0),
134 : nHorJustifyVersion(0),
135 : nVerJustifyVersion(0),
136 : nOrientationVersion(0),
137 : nMarginVersion(0),
138 : nBoolVersion(0),
139 : nInt32Version(0),
140 : nRotateModeVersion(0),
141 0 : nNumFmtVersion(0)
142 : {
143 0 : }
144 :
145 0 : void ScAfVersions::Load( SvStream& rStream, sal_uInt16 nVer )
146 : {
147 0 : rStream >> nFontVersion;
148 0 : rStream >> nFontHeightVersion;
149 0 : rStream >> nWeightVersion;
150 0 : rStream >> nPostureVersion;
151 0 : rStream >> nUnderlineVersion;
152 0 : if ( nVer >= AUTOFORMAT_ID_300OVRLN )
153 0 : rStream >> nOverlineVersion;
154 0 : rStream >> nCrossedOutVersion;
155 0 : rStream >> nContourVersion;
156 0 : rStream >> nShadowedVersion;
157 0 : rStream >> nColorVersion;
158 0 : rStream >> nBoxVersion;
159 0 : if ( nVer >= AUTOFORMAT_ID_680DR14 )
160 0 : rStream >> nLineVersion;
161 0 : rStream >> nBrushVersion;
162 0 : rStream >> nAdjustVersion;
163 0 : if (nVer >= AUTOFORMAT_ID_31005)
164 0 : rStream >> swVersions;
165 0 : rStream >> nHorJustifyVersion;
166 0 : rStream >> nVerJustifyVersion;
167 0 : rStream >> nOrientationVersion;
168 0 : rStream >> nMarginVersion;
169 0 : rStream >> nBoolVersion;
170 0 : if ( nVer >= AUTOFORMAT_ID_504 )
171 : {
172 0 : rStream >> nInt32Version;
173 0 : rStream >> nRotateModeVersion;
174 : }
175 0 : rStream >> nNumFmtVersion;
176 0 : }
177 :
178 0 : void ScAfVersions::Write(SvStream& rStream, sal_uInt16 fileVersion)
179 : {
180 0 : rStream << SvxFontItem(ATTR_FONT).GetVersion(fileVersion);
181 0 : rStream << SvxFontHeightItem(240, 100, ATTR_FONT_HEIGHT).GetVersion(fileVersion);
182 0 : rStream << SvxWeightItem(WEIGHT_NORMAL, ATTR_FONT_WEIGHT).GetVersion(fileVersion);
183 0 : rStream << SvxPostureItem(ITALIC_NONE, ATTR_FONT_POSTURE).GetVersion(fileVersion);
184 0 : rStream << SvxUnderlineItem(UNDERLINE_NONE, ATTR_FONT_UNDERLINE).GetVersion(fileVersion);
185 0 : rStream << SvxOverlineItem(UNDERLINE_NONE, ATTR_FONT_OVERLINE).GetVersion(fileVersion);
186 0 : rStream << SvxCrossedOutItem(STRIKEOUT_NONE, ATTR_FONT_CROSSEDOUT).GetVersion(fileVersion);
187 0 : rStream << SvxContourItem(false, ATTR_FONT_CONTOUR).GetVersion(fileVersion);
188 0 : rStream << SvxShadowedItem(false, ATTR_FONT_SHADOWED).GetVersion(fileVersion);
189 0 : rStream << SvxColorItem(ATTR_FONT_COLOR).GetVersion(fileVersion);
190 0 : rStream << SvxBoxItem(ATTR_BORDER).GetVersion(fileVersion);
191 0 : rStream << SvxLineItem(SID_FRAME_LINESTYLE).GetVersion(fileVersion);
192 0 : rStream << SvxBrushItem(ATTR_BACKGROUND).GetVersion(fileVersion);
193 :
194 0 : rStream << SvxAdjustItem(SVX_ADJUST_LEFT, 0).GetVersion(fileVersion);
195 0 : if (fileVersion >= SOFFICE_FILEFORMAT_50)
196 0 : rStream << swVersions;
197 :
198 0 : rStream << SvxHorJustifyItem(SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY).GetVersion(fileVersion);
199 0 : rStream << SvxVerJustifyItem(SVX_VER_JUSTIFY_STANDARD, ATTR_VER_JUSTIFY).GetVersion(fileVersion);
200 0 : rStream << SvxOrientationItem(SVX_ORIENTATION_STANDARD, 0).GetVersion(fileVersion);
201 0 : rStream << SvxMarginItem(ATTR_MARGIN).GetVersion(fileVersion);
202 0 : rStream << SfxBoolItem(ATTR_LINEBREAK).GetVersion(fileVersion);
203 0 : rStream << SfxInt32Item(ATTR_ROTATE_VALUE).GetVersion(fileVersion);
204 0 : rStream << SvxRotateModeItem(SVX_ROTATE_MODE_STANDARD,0).GetVersion(fileVersion);
205 :
206 0 : rStream << (sal_uInt16)0; // Num-Format
207 0 : }
208 :
209 : // ---------------------------------------------------------------------------
210 :
211 0 : ScAutoFormatDataField::ScAutoFormatDataField() :
212 : aFont( ATTR_FONT ),
213 : aHeight( 240, 100, ATTR_FONT_HEIGHT ),
214 : aWeight( WEIGHT_NORMAL, ATTR_FONT_WEIGHT ),
215 : aPosture( ITALIC_NONE, ATTR_FONT_POSTURE ),
216 :
217 : aCJKFont( ATTR_CJK_FONT ),
218 : aCJKHeight( 240, 100, ATTR_CJK_FONT_HEIGHT ),
219 : aCJKWeight( WEIGHT_NORMAL, ATTR_CJK_FONT_WEIGHT ),
220 : aCJKPosture( ITALIC_NONE, ATTR_CJK_FONT_POSTURE ),
221 :
222 : aCTLFont( ATTR_CTL_FONT ),
223 : aCTLHeight( 240, 100, ATTR_CTL_FONT_HEIGHT ),
224 : aCTLWeight( WEIGHT_NORMAL, ATTR_CTL_FONT_WEIGHT ),
225 : aCTLPosture( ITALIC_NONE, ATTR_CTL_FONT_POSTURE ),
226 :
227 : aUnderline( UNDERLINE_NONE,ATTR_FONT_UNDERLINE ),
228 : aOverline( UNDERLINE_NONE,ATTR_FONT_OVERLINE ),
229 : aCrossedOut( STRIKEOUT_NONE, ATTR_FONT_CROSSEDOUT ),
230 : aContour( false, ATTR_FONT_CONTOUR ),
231 : aShadowed( false, ATTR_FONT_SHADOWED ),
232 : aColor( ATTR_FONT_COLOR ),
233 : aBox( ATTR_BORDER ),
234 : aTLBR( ATTR_BORDER_TLBR ),
235 : aBLTR( ATTR_BORDER_BLTR ),
236 : aBackground( ATTR_BACKGROUND ),
237 : aAdjust( SVX_ADJUST_LEFT, 0 ),
238 : aHorJustify( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY ),
239 : aVerJustify( SVX_VER_JUSTIFY_STANDARD, ATTR_VER_JUSTIFY ),
240 : aMargin( ATTR_MARGIN ),
241 : aLinebreak( ATTR_LINEBREAK ),
242 : aRotateAngle( ATTR_ROTATE_VALUE ),
243 0 : aRotateMode( SVX_ROTATE_MODE_STANDARD, ATTR_ROTATE_MODE )
244 : {
245 0 : }
246 :
247 0 : ScAutoFormatDataField::ScAutoFormatDataField( const ScAutoFormatDataField& rCopy ) :
248 : aFont( rCopy.aFont ),
249 : aHeight( rCopy.aHeight ),
250 : aWeight( rCopy.aWeight ),
251 : aPosture( rCopy.aPosture ),
252 : aCJKFont( rCopy.aCJKFont ),
253 : aCJKHeight( rCopy.aCJKHeight ),
254 : aCJKWeight( rCopy.aCJKWeight ),
255 : aCJKPosture( rCopy.aCJKPosture ),
256 : aCTLFont( rCopy.aCTLFont ),
257 : aCTLHeight( rCopy.aCTLHeight ),
258 : aCTLWeight( rCopy.aCTLWeight ),
259 : aCTLPosture( rCopy.aCTLPosture ),
260 : aUnderline( rCopy.aUnderline ),
261 : aOverline( rCopy.aOverline ),
262 : aCrossedOut( rCopy.aCrossedOut ),
263 : aContour( rCopy.aContour ),
264 : aShadowed( rCopy.aShadowed ),
265 : aColor( rCopy.aColor ),
266 : aBox( rCopy.aBox ),
267 : aTLBR( rCopy.aTLBR ),
268 : aBLTR( rCopy.aBLTR ),
269 : aBackground( rCopy.aBackground ),
270 : aAdjust( rCopy.aAdjust ),
271 : aHorJustify( rCopy.aHorJustify ),
272 : aVerJustify( rCopy.aVerJustify ),
273 : aStacked( rCopy.aStacked ),
274 : aMargin( rCopy.aMargin ),
275 : aLinebreak( rCopy.aLinebreak ),
276 : aRotateAngle( rCopy.aRotateAngle ),
277 : aRotateMode( rCopy.aRotateMode ),
278 0 : aNumFormat( rCopy.aNumFormat )
279 : {
280 0 : }
281 :
282 0 : ScAutoFormatDataField::~ScAutoFormatDataField()
283 : {
284 0 : }
285 :
286 0 : void ScAutoFormatDataField::SetAdjust( const SvxAdjustItem& rAdjust )
287 : {
288 0 : aAdjust.SetAdjust( rAdjust.GetAdjust() );
289 0 : aAdjust.SetOneWord( rAdjust.GetOneWord() );
290 0 : aAdjust.SetLastBlock( rAdjust.GetLastBlock() );
291 0 : }
292 :
293 : #define READ( aItem, ItemType, nVers ) \
294 : pNew = aItem.Create( rStream, nVers ); \
295 : aItem = *(ItemType*)pNew; \
296 : delete pNew;
297 :
298 0 : sal_Bool ScAutoFormatDataField::Load( SvStream& rStream, const ScAfVersions& rVersions, sal_uInt16 nVer )
299 : {
300 : SfxPoolItem* pNew;
301 0 : SvxOrientationItem aOrientation( SVX_ORIENTATION_STANDARD, 0 );
302 :
303 0 : READ( aFont, SvxFontItem, rVersions.nFontVersion)
304 0 : READ( aHeight, SvxFontHeightItem, rVersions.nFontHeightVersion)
305 0 : READ( aWeight, SvxWeightItem, rVersions.nWeightVersion)
306 0 : READ( aPosture, SvxPostureItem, rVersions.nPostureVersion)
307 : // --- from 641 on: CJK and CTL font settings
308 0 : if( AUTOFORMAT_DATA_ID_641 <= nVer )
309 : {
310 0 : READ( aCJKFont, SvxFontItem, rVersions.nFontVersion)
311 0 : READ( aCJKHeight, SvxFontHeightItem, rVersions.nFontHeightVersion)
312 0 : READ( aCJKWeight, SvxWeightItem, rVersions.nWeightVersion)
313 0 : READ( aCJKPosture, SvxPostureItem, rVersions.nPostureVersion)
314 0 : READ( aCTLFont, SvxFontItem, rVersions.nFontVersion)
315 0 : READ( aCTLHeight, SvxFontHeightItem, rVersions.nFontHeightVersion)
316 0 : READ( aCTLWeight, SvxWeightItem, rVersions.nWeightVersion)
317 0 : READ( aCTLPosture, SvxPostureItem, rVersions.nPostureVersion)
318 : }
319 0 : READ( aUnderline, SvxUnderlineItem, rVersions.nUnderlineVersion)
320 0 : if ( nVer >= AUTOFORMAT_DATA_ID_300OVRLN )
321 : {
322 0 : READ( aOverline, SvxOverlineItem, rVersions.nOverlineVersion)
323 : }
324 0 : READ( aCrossedOut, SvxCrossedOutItem, rVersions.nCrossedOutVersion)
325 0 : READ( aContour, SvxContourItem, rVersions.nContourVersion)
326 0 : READ( aShadowed, SvxShadowedItem, rVersions.nShadowedVersion)
327 0 : READ( aColor, SvxColorItem, rVersions.nColorVersion)
328 0 : READ( aBox, SvxBoxItem, rVersions.nBoxVersion)
329 :
330 : // --- from 680/dr14 on: diagonal frame lines
331 0 : if( AUTOFORMAT_DATA_ID_680DR14 <= nVer )
332 : {
333 0 : READ( aTLBR, SvxLineItem, rVersions.nLineVersion)
334 0 : READ( aBLTR, SvxLineItem, rVersions.nLineVersion)
335 : }
336 :
337 0 : READ( aBackground, SvxBrushItem, rVersions.nBrushVersion)
338 :
339 0 : pNew = aAdjust.Create( rStream, rVersions.nAdjustVersion );
340 0 : SetAdjust( *(SvxAdjustItem*)pNew );
341 0 : delete pNew;
342 :
343 0 : if (nVer >= AUTOFORMAT_DATA_ID_31005)
344 0 : rStream >> m_swFields;
345 :
346 0 : READ( aHorJustify, SvxHorJustifyItem, rVersions.nHorJustifyVersion)
347 0 : READ( aVerJustify, SvxVerJustifyItem, rVersions.nVerJustifyVersion)
348 0 : READ( aOrientation, SvxOrientationItem, rVersions.nOrientationVersion)
349 0 : READ( aMargin, SvxMarginItem, rVersions.nMarginVersion)
350 :
351 0 : pNew = aLinebreak.Create( rStream, rVersions.nBoolVersion );
352 0 : SetLinebreak( *(SfxBoolItem*)pNew );
353 0 : delete pNew;
354 :
355 0 : if ( nVer >= AUTOFORMAT_DATA_ID_504 )
356 : {
357 0 : pNew = aRotateAngle.Create( rStream, rVersions.nInt32Version );
358 0 : SetRotateAngle( *(SfxInt32Item*)pNew );
359 0 : delete pNew;
360 0 : pNew = aRotateMode.Create( rStream, rVersions.nRotateModeVersion );
361 0 : SetRotateMode( *(SvxRotateModeItem*)pNew );
362 0 : delete pNew;
363 : }
364 :
365 0 : if( 0 == rVersions.nNumFmtVersion )
366 : {
367 : // --- from 680/dr25 on: store strings as UTF-8
368 0 : CharSet eCharSet = (nVer >= AUTOFORMAT_ID_680DR25) ? RTL_TEXTENCODING_UTF8 : rStream.GetStreamCharSet();
369 0 : aNumFormat.Load( rStream, eCharSet );
370 : }
371 :
372 : // adjust charset in font
373 0 : CharSet eSysSet = osl_getThreadTextEncoding();
374 0 : CharSet eSrcSet = rStream.GetStreamCharSet();
375 0 : if( eSrcSet != eSysSet && aFont.GetCharSet() == eSrcSet )
376 0 : aFont.SetCharSet(eSysSet);
377 :
378 0 : aStacked.SetValue( aOrientation.IsStacked() );
379 0 : aRotateAngle.SetValue( aOrientation.GetRotation( aRotateAngle.GetValue() ) );
380 :
381 0 : return (rStream.GetError() == 0);
382 : }
383 :
384 0 : sal_Bool ScAutoFormatDataField::Save( SvStream& rStream, sal_uInt16 fileVersion )
385 : {
386 0 : SvxOrientationItem aOrientation( aRotateAngle.GetValue(), aStacked.GetValue(), 0 );
387 :
388 0 : aFont.Store ( rStream, aFont.GetVersion( fileVersion ) );
389 0 : aHeight.Store ( rStream, aHeight.GetVersion( fileVersion ) );
390 0 : aWeight.Store ( rStream, aWeight.GetVersion( fileVersion ) );
391 0 : aPosture.Store ( rStream, aPosture.GetVersion( fileVersion ) );
392 : // --- from 641 on: CJK and CTL font settings
393 0 : aCJKFont.Store ( rStream, aCJKFont.GetVersion( fileVersion ) );
394 0 : aCJKHeight.Store ( rStream, aCJKHeight.GetVersion( fileVersion ) );
395 0 : aCJKWeight.Store ( rStream, aCJKWeight.GetVersion( fileVersion ) );
396 0 : aCJKPosture.Store ( rStream, aCJKPosture.GetVersion( fileVersion ) );
397 0 : aCTLFont.Store ( rStream, aCTLFont.GetVersion( fileVersion ) );
398 0 : aCTLHeight.Store ( rStream, aCTLHeight.GetVersion( fileVersion ) );
399 0 : aCTLWeight.Store ( rStream, aCTLWeight.GetVersion( fileVersion ) );
400 0 : aCTLPosture.Store ( rStream, aCTLPosture.GetVersion( fileVersion ) );
401 :
402 0 : aUnderline.Store ( rStream, aUnderline.GetVersion( fileVersion ) );
403 : // --- from DEV300/overline2 on: overline support
404 0 : aOverline.Store ( rStream, aOverline.GetVersion( fileVersion ) );
405 0 : aCrossedOut.Store ( rStream, aCrossedOut.GetVersion( fileVersion ) );
406 0 : aContour.Store ( rStream, aContour.GetVersion( fileVersion ) );
407 0 : aShadowed.Store ( rStream, aShadowed.GetVersion( fileVersion ) );
408 0 : aColor.Store ( rStream, aColor.GetVersion( fileVersion ) );
409 0 : aBox.Store ( rStream, aBox.GetVersion( fileVersion ) );
410 :
411 : // --- from 680/dr14 on: diagonal frame lines
412 0 : aTLBR.Store ( rStream, aTLBR.GetVersion( fileVersion ) );
413 0 : aBLTR.Store ( rStream, aBLTR.GetVersion( fileVersion ) );
414 :
415 0 : aBackground.Store ( rStream, aBackground.GetVersion( fileVersion ) );
416 :
417 0 : aAdjust.Store ( rStream, aAdjust.GetVersion( fileVersion ) );
418 0 : if (fileVersion >= SOFFICE_FILEFORMAT_50)
419 0 : rStream << m_swFields;
420 :
421 0 : aHorJustify.Store ( rStream, aHorJustify.GetVersion( fileVersion ) );
422 0 : aVerJustify.Store ( rStream, aVerJustify.GetVersion( fileVersion ) );
423 0 : aOrientation.Store ( rStream, aOrientation.GetVersion( fileVersion ) );
424 0 : aMargin.Store ( rStream, aMargin.GetVersion( fileVersion ) );
425 0 : aLinebreak.Store ( rStream, aLinebreak.GetVersion( fileVersion ) );
426 : // Rotation ab SO5
427 0 : aRotateAngle.Store ( rStream, aRotateAngle.GetVersion( fileVersion ) );
428 0 : aRotateMode.Store ( rStream, aRotateMode.GetVersion( fileVersion ) );
429 :
430 : // --- from 680/dr25 on: store strings as UTF-8
431 0 : aNumFormat.Save( rStream, RTL_TEXTENCODING_UTF8 );
432 :
433 0 : return (rStream.GetError() == 0);
434 : }
435 :
436 :
437 : // ---------------------------------------------------------------------------
438 :
439 0 : ScAutoFormatData::ScAutoFormatData()
440 : {
441 0 : nStrResId = USHRT_MAX;
442 :
443 : bIncludeValueFormat =
444 : bIncludeFont =
445 : bIncludeJustify =
446 : bIncludeFrame =
447 : bIncludeBackground =
448 0 : bIncludeWidthHeight = true;
449 :
450 0 : ppDataField = new ScAutoFormatDataField*[ 16 ];
451 0 : for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex )
452 0 : ppDataField[ nIndex ] = new ScAutoFormatDataField;
453 0 : }
454 :
455 0 : ScAutoFormatData::ScAutoFormatData( const ScAutoFormatData& rData ) :
456 : aName( rData.aName ),
457 : nStrResId( rData.nStrResId ),
458 : bIncludeFont( rData.bIncludeFont ),
459 : bIncludeJustify( rData.bIncludeJustify ),
460 : bIncludeFrame( rData.bIncludeFrame ),
461 : bIncludeBackground( rData.bIncludeBackground ),
462 : bIncludeValueFormat( rData.bIncludeValueFormat ),
463 0 : bIncludeWidthHeight( rData.bIncludeWidthHeight )
464 : {
465 0 : ppDataField = new ScAutoFormatDataField*[ 16 ];
466 0 : for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex )
467 0 : ppDataField[ nIndex ] = new ScAutoFormatDataField( rData.GetField( nIndex ) );
468 0 : }
469 :
470 0 : ScAutoFormatData::~ScAutoFormatData()
471 : {
472 0 : for( sal_uInt16 nIndex = 0; nIndex < 16; ++nIndex )
473 0 : delete ppDataField[ nIndex ];
474 0 : delete[] ppDataField;
475 0 : }
476 :
477 0 : ScAutoFormatDataField& ScAutoFormatData::GetField( sal_uInt16 nIndex )
478 : {
479 : OSL_ENSURE( nIndex < 16, "ScAutoFormatData::GetField - illegal index" );
480 : OSL_ENSURE( ppDataField && ppDataField[ nIndex ], "ScAutoFormatData::GetField - no data" );
481 0 : return *ppDataField[ nIndex ];
482 : }
483 :
484 0 : const ScAutoFormatDataField& ScAutoFormatData::GetField( sal_uInt16 nIndex ) const
485 : {
486 : OSL_ENSURE( nIndex < 16, "ScAutoFormatData::GetField - illegal index" );
487 : OSL_ENSURE( ppDataField && ppDataField[ nIndex ], "ScAutoFormatData::GetField - no data" );
488 0 : return *ppDataField[ nIndex ];
489 : }
490 :
491 0 : const SfxPoolItem* ScAutoFormatData::GetItem( sal_uInt16 nIndex, sal_uInt16 nWhich ) const
492 : {
493 0 : const ScAutoFormatDataField& rField = GetField( nIndex );
494 0 : switch( nWhich )
495 : {
496 0 : case ATTR_FONT: return &rField.GetFont();
497 0 : case ATTR_FONT_HEIGHT: return &rField.GetHeight();
498 0 : case ATTR_FONT_WEIGHT: return &rField.GetWeight();
499 0 : case ATTR_FONT_POSTURE: return &rField.GetPosture();
500 0 : case ATTR_CJK_FONT: return &rField.GetCJKFont();
501 0 : case ATTR_CJK_FONT_HEIGHT: return &rField.GetCJKHeight();
502 0 : case ATTR_CJK_FONT_WEIGHT: return &rField.GetCJKWeight();
503 0 : case ATTR_CJK_FONT_POSTURE: return &rField.GetCJKPosture();
504 0 : case ATTR_CTL_FONT: return &rField.GetCTLFont();
505 0 : case ATTR_CTL_FONT_HEIGHT: return &rField.GetCTLHeight();
506 0 : case ATTR_CTL_FONT_WEIGHT: return &rField.GetCTLWeight();
507 0 : case ATTR_CTL_FONT_POSTURE: return &rField.GetCTLPosture();
508 0 : case ATTR_FONT_UNDERLINE: return &rField.GetUnderline();
509 0 : case ATTR_FONT_OVERLINE: return &rField.GetOverline();
510 0 : case ATTR_FONT_CROSSEDOUT: return &rField.GetCrossedOut();
511 0 : case ATTR_FONT_CONTOUR: return &rField.GetContour();
512 0 : case ATTR_FONT_SHADOWED: return &rField.GetShadowed();
513 0 : case ATTR_FONT_COLOR: return &rField.GetColor();
514 0 : case ATTR_BORDER: return &rField.GetBox();
515 0 : case ATTR_BORDER_TLBR: return &rField.GetTLBR();
516 0 : case ATTR_BORDER_BLTR: return &rField.GetBLTR();
517 0 : case ATTR_BACKGROUND: return &rField.GetBackground();
518 0 : case ATTR_HOR_JUSTIFY: return &rField.GetHorJustify();
519 0 : case ATTR_VER_JUSTIFY: return &rField.GetVerJustify();
520 0 : case ATTR_STACKED: return &rField.GetStacked();
521 0 : case ATTR_MARGIN: return &rField.GetMargin();
522 0 : case ATTR_LINEBREAK: return &rField.GetLinebreak();
523 0 : case ATTR_ROTATE_VALUE: return &rField.GetRotateAngle();
524 0 : case ATTR_ROTATE_MODE: return &rField.GetRotateMode();
525 : }
526 0 : return NULL;
527 : }
528 :
529 0 : void ScAutoFormatData::PutItem( sal_uInt16 nIndex, const SfxPoolItem& rItem )
530 : {
531 0 : ScAutoFormatDataField& rField = GetField( nIndex );
532 0 : switch( rItem.Which() )
533 : {
534 0 : case ATTR_FONT: rField.SetFont( (const SvxFontItem&)rItem ); break;
535 0 : case ATTR_FONT_HEIGHT: rField.SetHeight( (const SvxFontHeightItem&)rItem ); break;
536 0 : case ATTR_FONT_WEIGHT: rField.SetWeight( (const SvxWeightItem&)rItem ); break;
537 0 : case ATTR_FONT_POSTURE: rField.SetPosture( (const SvxPostureItem&)rItem ); break;
538 0 : case ATTR_CJK_FONT: rField.SetCJKFont( (const SvxFontItem&)rItem ); break;
539 0 : case ATTR_CJK_FONT_HEIGHT: rField.SetCJKHeight( (const SvxFontHeightItem&)rItem ); break;
540 0 : case ATTR_CJK_FONT_WEIGHT: rField.SetCJKWeight( (const SvxWeightItem&)rItem ); break;
541 0 : case ATTR_CJK_FONT_POSTURE: rField.SetCJKPosture( (const SvxPostureItem&)rItem ); break;
542 0 : case ATTR_CTL_FONT: rField.SetCTLFont( (const SvxFontItem&)rItem ); break;
543 0 : case ATTR_CTL_FONT_HEIGHT: rField.SetCTLHeight( (const SvxFontHeightItem&)rItem ); break;
544 0 : case ATTR_CTL_FONT_WEIGHT: rField.SetCTLWeight( (const SvxWeightItem&)rItem ); break;
545 0 : case ATTR_CTL_FONT_POSTURE: rField.SetCTLPosture( (const SvxPostureItem&)rItem ); break;
546 0 : case ATTR_FONT_UNDERLINE: rField.SetUnderline( (const SvxUnderlineItem&)rItem ); break;
547 0 : case ATTR_FONT_OVERLINE: rField.SetOverline( (const SvxOverlineItem&)rItem ); break;
548 0 : case ATTR_FONT_CROSSEDOUT: rField.SetCrossedOut( (const SvxCrossedOutItem&)rItem ); break;
549 0 : case ATTR_FONT_CONTOUR: rField.SetContour( (const SvxContourItem&)rItem ); break;
550 0 : case ATTR_FONT_SHADOWED: rField.SetShadowed( (const SvxShadowedItem&)rItem ); break;
551 0 : case ATTR_FONT_COLOR: rField.SetColor( (const SvxColorItem&)rItem ); break;
552 0 : case ATTR_BORDER: rField.SetBox( (const SvxBoxItem&)rItem ); break;
553 0 : case ATTR_BORDER_TLBR: rField.SetTLBR( (const SvxLineItem&)rItem ); break;
554 0 : case ATTR_BORDER_BLTR: rField.SetBLTR( (const SvxLineItem&)rItem ); break;
555 0 : case ATTR_BACKGROUND: rField.SetBackground( (const SvxBrushItem&)rItem ); break;
556 0 : case ATTR_HOR_JUSTIFY: rField.SetHorJustify( (const SvxHorJustifyItem&)rItem ); break;
557 0 : case ATTR_VER_JUSTIFY: rField.SetVerJustify( (const SvxVerJustifyItem&)rItem ); break;
558 0 : case ATTR_STACKED: rField.SetStacked( (const SfxBoolItem&)rItem ); break;
559 0 : case ATTR_MARGIN: rField.SetMargin( (const SvxMarginItem&)rItem ); break;
560 0 : case ATTR_LINEBREAK: rField.SetLinebreak( (const SfxBoolItem&)rItem ); break;
561 0 : case ATTR_ROTATE_VALUE: rField.SetRotateAngle( (const SfxInt32Item&)rItem ); break;
562 0 : case ATTR_ROTATE_MODE: rField.SetRotateMode( (const SvxRotateModeItem&)rItem ); break;
563 : }
564 0 : }
565 :
566 0 : void ScAutoFormatData::CopyItem( sal_uInt16 nToIndex, sal_uInt16 nFromIndex, sal_uInt16 nWhich )
567 : {
568 0 : const SfxPoolItem* pItem = GetItem( nFromIndex, nWhich );
569 0 : if( pItem )
570 0 : PutItem( nToIndex, *pItem );
571 0 : }
572 :
573 0 : const ScNumFormatAbbrev& ScAutoFormatData::GetNumFormat( sal_uInt16 nIndex ) const
574 : {
575 0 : return GetField( nIndex ).GetNumFormat();
576 : }
577 :
578 0 : bool ScAutoFormatData::IsEqualData( sal_uInt16 nIndex1, sal_uInt16 nIndex2 ) const
579 : {
580 0 : bool bEqual = true;
581 0 : const ScAutoFormatDataField& rField1 = GetField( nIndex1 );
582 0 : const ScAutoFormatDataField& rField2 = GetField( nIndex2 );
583 :
584 0 : if( bIncludeValueFormat )
585 : {
586 : bEqual = bEqual
587 0 : && (rField1.GetNumFormat() == rField2.GetNumFormat());
588 : }
589 0 : if( bIncludeFont )
590 : {
591 : bEqual = bEqual
592 0 : && (rField1.GetFont() == rField2.GetFont())
593 0 : && (rField1.GetHeight() == rField2.GetHeight())
594 0 : && (rField1.GetWeight() == rField2.GetWeight())
595 0 : && (rField1.GetPosture() == rField2.GetPosture())
596 0 : && (rField1.GetCJKFont() == rField2.GetCJKFont())
597 0 : && (rField1.GetCJKHeight() == rField2.GetCJKHeight())
598 0 : && (rField1.GetCJKWeight() == rField2.GetCJKWeight())
599 0 : && (rField1.GetCJKPosture() == rField2.GetCJKPosture())
600 0 : && (rField1.GetCTLFont() == rField2.GetCTLFont())
601 0 : && (rField1.GetCTLHeight() == rField2.GetCTLHeight())
602 0 : && (rField1.GetCTLWeight() == rField2.GetCTLWeight())
603 0 : && (rField1.GetCTLPosture() == rField2.GetCTLPosture())
604 0 : && (rField1.GetUnderline() == rField2.GetUnderline())
605 0 : && (rField1.GetOverline() == rField2.GetOverline())
606 0 : && (rField1.GetCrossedOut() == rField2.GetCrossedOut())
607 0 : && (rField1.GetContour() == rField2.GetContour())
608 0 : && (rField1.GetShadowed() == rField2.GetShadowed())
609 0 : && (rField1.GetColor() == rField2.GetColor());
610 : }
611 0 : if( bIncludeJustify )
612 : {
613 : bEqual = bEqual
614 0 : && (rField1.GetHorJustify() == rField2.GetHorJustify())
615 0 : && (rField1.GetVerJustify() == rField2.GetVerJustify())
616 0 : && (rField1.GetStacked() == rField2.GetStacked())
617 0 : && (rField1.GetLinebreak() == rField2.GetLinebreak())
618 0 : && (rField1.GetMargin() == rField2.GetMargin())
619 0 : && (rField1.GetRotateAngle() == rField2.GetRotateAngle())
620 0 : && (rField1.GetRotateMode() == rField2.GetRotateMode());
621 : }
622 0 : if( bIncludeFrame )
623 : {
624 : bEqual = bEqual
625 0 : && (rField1.GetBox() == rField2.GetBox())
626 0 : && (rField1.GetTLBR() == rField2.GetTLBR())
627 0 : && (rField1.GetBLTR() == rField2.GetBLTR());
628 : }
629 0 : if( bIncludeBackground )
630 : {
631 : bEqual = bEqual
632 0 : && (rField1.GetBackground() == rField2.GetBackground());
633 : }
634 0 : return bEqual;
635 : }
636 :
637 0 : void ScAutoFormatData::FillToItemSet( sal_uInt16 nIndex, SfxItemSet& rItemSet, ScDocument& rDoc ) const
638 : {
639 0 : const ScAutoFormatDataField& rField = GetField( nIndex );
640 :
641 0 : if( bIncludeValueFormat )
642 : {
643 0 : ScNumFormatAbbrev& rNumFormat = (ScNumFormatAbbrev&)rField.GetNumFormat();
644 0 : SfxUInt32Item aValueFormat( ATTR_VALUE_FORMAT, 0 );
645 0 : aValueFormat.SetValue( rNumFormat.GetFormatIndex( *rDoc.GetFormatTable() ) );
646 0 : rItemSet.Put( aValueFormat );
647 0 : rItemSet.Put( SvxLanguageItem( rNumFormat.GetLanguage(), ATTR_LANGUAGE_FORMAT ) );
648 : }
649 0 : if( bIncludeFont )
650 : {
651 0 : rItemSet.Put( rField.GetFont() );
652 0 : rItemSet.Put( rField.GetHeight() );
653 0 : rItemSet.Put( rField.GetWeight() );
654 0 : rItemSet.Put( rField.GetPosture() );
655 : // do not insert empty CJK font
656 0 : const SvxFontItem& rCJKFont = rField.GetCJKFont();
657 0 : if( rCJKFont.GetStyleName().Len() )
658 : {
659 0 : rItemSet.Put( rCJKFont );
660 0 : rItemSet.Put( rField.GetCJKHeight() );
661 0 : rItemSet.Put( rField.GetCJKWeight() );
662 0 : rItemSet.Put( rField.GetCJKPosture() );
663 : }
664 : else
665 : {
666 0 : rItemSet.Put( rField.GetHeight(), ATTR_CJK_FONT_HEIGHT );
667 0 : rItemSet.Put( rField.GetWeight(), ATTR_CJK_FONT_WEIGHT );
668 0 : rItemSet.Put( rField.GetPosture(), ATTR_CJK_FONT_POSTURE );
669 : }
670 : // do not insert empty CTL font
671 0 : const SvxFontItem& rCTLFont = rField.GetCTLFont();
672 0 : if( rCTLFont.GetStyleName().Len() )
673 : {
674 0 : rItemSet.Put( rCTLFont );
675 0 : rItemSet.Put( rField.GetCTLHeight() );
676 0 : rItemSet.Put( rField.GetCTLWeight() );
677 0 : rItemSet.Put( rField.GetCTLPosture() );
678 : }
679 : else
680 : {
681 0 : rItemSet.Put( rField.GetHeight(), ATTR_CTL_FONT_HEIGHT );
682 0 : rItemSet.Put( rField.GetWeight(), ATTR_CTL_FONT_WEIGHT );
683 0 : rItemSet.Put( rField.GetPosture(), ATTR_CTL_FONT_POSTURE );
684 : }
685 0 : rItemSet.Put( rField.GetUnderline() );
686 0 : rItemSet.Put( rField.GetOverline() );
687 0 : rItemSet.Put( rField.GetCrossedOut() );
688 0 : rItemSet.Put( rField.GetContour() );
689 0 : rItemSet.Put( rField.GetShadowed() );
690 0 : rItemSet.Put( rField.GetColor() );
691 : }
692 0 : if( bIncludeJustify )
693 : {
694 0 : rItemSet.Put( rField.GetHorJustify() );
695 0 : rItemSet.Put( rField.GetVerJustify() );
696 0 : rItemSet.Put( rField.GetStacked() );
697 0 : rItemSet.Put( rField.GetLinebreak() );
698 0 : rItemSet.Put( rField.GetMargin() );
699 0 : rItemSet.Put( rField.GetRotateAngle() );
700 0 : rItemSet.Put( rField.GetRotateMode() );
701 : }
702 0 : if( bIncludeFrame )
703 : {
704 0 : rItemSet.Put( rField.GetBox() );
705 0 : rItemSet.Put( rField.GetTLBR() );
706 0 : rItemSet.Put( rField.GetBLTR() );
707 : }
708 0 : if( bIncludeBackground )
709 0 : rItemSet.Put( rField.GetBackground() );
710 0 : }
711 :
712 0 : void ScAutoFormatData::GetFromItemSet( sal_uInt16 nIndex, const SfxItemSet& rItemSet, const ScNumFormatAbbrev& rNumFormat )
713 : {
714 0 : ScAutoFormatDataField& rField = GetField( nIndex );
715 :
716 0 : rField.SetNumFormat ( rNumFormat);
717 0 : rField.SetFont ( (const SvxFontItem&) rItemSet.Get( ATTR_FONT ) );
718 0 : rField.SetHeight ( (const SvxFontHeightItem&) rItemSet.Get( ATTR_FONT_HEIGHT ) );
719 0 : rField.SetWeight ( (const SvxWeightItem&) rItemSet.Get( ATTR_FONT_WEIGHT ) );
720 0 : rField.SetPosture ( (const SvxPostureItem&) rItemSet.Get( ATTR_FONT_POSTURE ) );
721 0 : rField.SetCJKFont ( (const SvxFontItem&) rItemSet.Get( ATTR_CJK_FONT ) );
722 0 : rField.SetCJKHeight ( (const SvxFontHeightItem&) rItemSet.Get( ATTR_CJK_FONT_HEIGHT ) );
723 0 : rField.SetCJKWeight ( (const SvxWeightItem&) rItemSet.Get( ATTR_CJK_FONT_WEIGHT ) );
724 0 : rField.SetCJKPosture ( (const SvxPostureItem&) rItemSet.Get( ATTR_CJK_FONT_POSTURE ) );
725 0 : rField.SetCTLFont ( (const SvxFontItem&) rItemSet.Get( ATTR_CTL_FONT ) );
726 0 : rField.SetCTLHeight ( (const SvxFontHeightItem&) rItemSet.Get( ATTR_CTL_FONT_HEIGHT ) );
727 0 : rField.SetCTLWeight ( (const SvxWeightItem&) rItemSet.Get( ATTR_CTL_FONT_WEIGHT ) );
728 0 : rField.SetCTLPosture ( (const SvxPostureItem&) rItemSet.Get( ATTR_CTL_FONT_POSTURE ) );
729 0 : rField.SetUnderline ( (const SvxUnderlineItem&) rItemSet.Get( ATTR_FONT_UNDERLINE ) );
730 0 : rField.SetOverline ( (const SvxOverlineItem&) rItemSet.Get( ATTR_FONT_OVERLINE ) );
731 0 : rField.SetCrossedOut ( (const SvxCrossedOutItem&) rItemSet.Get( ATTR_FONT_CROSSEDOUT ) );
732 0 : rField.SetContour ( (const SvxContourItem&) rItemSet.Get( ATTR_FONT_CONTOUR ) );
733 0 : rField.SetShadowed ( (const SvxShadowedItem&) rItemSet.Get( ATTR_FONT_SHADOWED ) );
734 0 : rField.SetColor ( (const SvxColorItem&) rItemSet.Get( ATTR_FONT_COLOR ) );
735 0 : rField.SetTLBR ( (const SvxLineItem&) rItemSet.Get( ATTR_BORDER_TLBR ) );
736 0 : rField.SetBLTR ( (const SvxLineItem&) rItemSet.Get( ATTR_BORDER_BLTR ) );
737 0 : rField.SetHorJustify ( (const SvxHorJustifyItem&) rItemSet.Get( ATTR_HOR_JUSTIFY ) );
738 0 : rField.SetVerJustify ( (const SvxVerJustifyItem&) rItemSet.Get( ATTR_VER_JUSTIFY ) );
739 0 : rField.SetStacked ( (const SfxBoolItem&) rItemSet.Get( ATTR_STACKED ) );
740 0 : rField.SetLinebreak ( (const SfxBoolItem&) rItemSet.Get( ATTR_LINEBREAK ) );
741 0 : rField.SetMargin ( (const SvxMarginItem&) rItemSet.Get( ATTR_MARGIN ) );
742 0 : rField.SetBackground ( (const SvxBrushItem&) rItemSet.Get( ATTR_BACKGROUND ) );
743 0 : rField.SetRotateAngle ( (const SfxInt32Item&) rItemSet.Get( ATTR_ROTATE_VALUE ) );
744 0 : rField.SetRotateMode ( (const SvxRotateModeItem&) rItemSet.Get( ATTR_ROTATE_MODE ) );
745 0 : }
746 :
747 0 : bool ScAutoFormatData::Load( SvStream& rStream, const ScAfVersions& rVersions )
748 : {
749 0 : sal_Bool bRet = true;
750 0 : sal_uInt16 nVer = 0;
751 0 : rStream >> nVer;
752 0 : bRet = 0 == rStream.GetError();
753 0 : if( bRet && (nVer == AUTOFORMAT_DATA_ID_X ||
754 : (AUTOFORMAT_DATA_ID_504 <= nVer && nVer <= AUTOFORMAT_DATA_ID)) )
755 : {
756 : // --- from 680/dr25 on: store strings as UTF-8
757 0 : if (nVer >= AUTOFORMAT_ID_680DR25)
758 : {
759 : aName = read_lenPrefixed_uInt8s_ToOUString<sal_uInt16>(rStream,
760 0 : RTL_TEXTENCODING_UTF8);
761 : }
762 : else
763 0 : aName = rStream.ReadUniOrByteString( rStream.GetStreamCharSet() );
764 :
765 0 : if( AUTOFORMAT_DATA_ID_552 <= nVer )
766 : {
767 0 : rStream >> nStrResId;
768 0 : sal_uInt16 nId = RID_SVXSTR_TBLAFMT_BEGIN + nStrResId;
769 0 : if( RID_SVXSTR_TBLAFMT_BEGIN <= nId &&
770 : nId < RID_SVXSTR_TBLAFMT_END )
771 : {
772 0 : aName = SVX_RESSTR( nId );
773 : }
774 : else
775 0 : nStrResId = USHRT_MAX;
776 : }
777 :
778 : sal_Bool b;
779 0 : rStream >> b; bIncludeFont = b;
780 0 : rStream >> b; bIncludeJustify = b;
781 0 : rStream >> b; bIncludeFrame = b;
782 0 : rStream >> b; bIncludeBackground = b;
783 0 : rStream >> b; bIncludeValueFormat = b;
784 0 : rStream >> b; bIncludeWidthHeight = b;
785 :
786 0 : if (nVer >= AUTOFORMAT_DATA_ID_31005)
787 0 : rStream >> m_swFields;
788 :
789 0 : bRet = 0 == rStream.GetError();
790 0 : for( sal_uInt16 i = 0; bRet && i < 16; ++i )
791 0 : bRet = GetField( i ).Load( rStream, rVersions, nVer );
792 : }
793 : else
794 0 : bRet = false;
795 0 : return bRet;
796 : }
797 :
798 0 : bool ScAutoFormatData::Save(SvStream& rStream, sal_uInt16 fileVersion)
799 : {
800 0 : sal_uInt16 nVal = AUTOFORMAT_DATA_ID;
801 : sal_Bool b;
802 0 : rStream << nVal;
803 : // --- from 680/dr25 on: store strings as UTF-8
804 0 : write_lenPrefixed_uInt8s_FromOUString<sal_uInt16>(rStream, aName, RTL_TEXTENCODING_UTF8);
805 :
806 0 : rStream << nStrResId;
807 0 : rStream << ( b = bIncludeFont );
808 0 : rStream << ( b = bIncludeJustify );
809 0 : rStream << ( b = bIncludeFrame );
810 0 : rStream << ( b = bIncludeBackground );
811 0 : rStream << ( b = bIncludeValueFormat );
812 0 : rStream << ( b = bIncludeWidthHeight );
813 :
814 0 : if (fileVersion >= SOFFICE_FILEFORMAT_50)
815 0 : rStream << m_swFields;
816 :
817 0 : sal_Bool bRet = 0 == rStream.GetError();
818 0 : for (sal_uInt16 i = 0; bRet && (i < 16); i++)
819 0 : bRet = GetField( i ).Save( rStream, fileVersion );
820 :
821 0 : return bRet;
822 : }
823 :
824 : //---------------------------------------------------------------------------------------
825 : //---------------------------------------------------------------------------------------
826 :
827 0 : ScAutoFormat::ScAutoFormat() :
828 0 : mbSaveLater(false)
829 : {
830 : // create default autoformat
831 0 : ScAutoFormatData* pData = new ScAutoFormatData;
832 0 : String aName(ScGlobal::GetRscString(STR_STYLENAME_STANDARD));
833 0 : pData->SetName(aName);
834 :
835 : // default font, default height
836 : Font aStdFont = OutputDevice::GetDefaultFont(
837 0 : DEFAULTFONT_LATIN_SPREADSHEET, LANGUAGE_ENGLISH_US, DEFAULTFONT_FLAGS_ONLYONE );
838 : SvxFontItem aFontItem(
839 0 : aStdFont.GetFamily(), aStdFont.GetName(), aStdFont.GetStyleName(),
840 0 : aStdFont.GetPitch(), aStdFont.GetCharSet(), ATTR_FONT );
841 :
842 : aStdFont = OutputDevice::GetDefaultFont(
843 0 : DEFAULTFONT_CJK_SPREADSHEET, LANGUAGE_ENGLISH_US, DEFAULTFONT_FLAGS_ONLYONE );
844 : SvxFontItem aCJKFontItem(
845 0 : aStdFont.GetFamily(), aStdFont.GetName(), aStdFont.GetStyleName(),
846 0 : aStdFont.GetPitch(), aStdFont.GetCharSet(), ATTR_CJK_FONT );
847 :
848 : aStdFont = OutputDevice::GetDefaultFont(
849 0 : DEFAULTFONT_CTL_SPREADSHEET, LANGUAGE_ENGLISH_US, DEFAULTFONT_FLAGS_ONLYONE );
850 : SvxFontItem aCTLFontItem(
851 0 : aStdFont.GetFamily(), aStdFont.GetName(), aStdFont.GetStyleName(),
852 0 : aStdFont.GetPitch(), aStdFont.GetCharSet(), ATTR_CTL_FONT );
853 :
854 0 : SvxFontHeightItem aHeight( 200, 100, ATTR_FONT_HEIGHT ); // 10 pt;
855 :
856 : // black thin border
857 0 : Color aBlack( COL_BLACK );
858 0 : ::editeng::SvxBorderLine aLine( &aBlack, DEF_LINE_WIDTH_0 );
859 0 : SvxBoxItem aBox( ATTR_BORDER );
860 0 : aBox.SetLine(&aLine, BOX_LINE_LEFT);
861 0 : aBox.SetLine(&aLine, BOX_LINE_TOP);
862 0 : aBox.SetLine(&aLine, BOX_LINE_RIGHT);
863 0 : aBox.SetLine(&aLine, BOX_LINE_BOTTOM);
864 :
865 0 : Color aWhite(COL_WHITE);
866 0 : Color aBlue(COL_BLUE);
867 0 : SvxColorItem aWhiteText( aWhite, ATTR_FONT_COLOR );
868 0 : SvxColorItem aBlackText( aBlack, ATTR_FONT_COLOR );
869 0 : SvxBrushItem aBlueBack( aBlue, ATTR_BACKGROUND );
870 0 : SvxBrushItem aWhiteBack( aWhite, ATTR_BACKGROUND );
871 0 : SvxBrushItem aGray70Back( Color(0x4d, 0x4d, 0x4d), ATTR_BACKGROUND );
872 0 : SvxBrushItem aGray20Back( Color(0xcc, 0xcc, 0xcc), ATTR_BACKGROUND );
873 :
874 0 : for (sal_uInt16 i=0; i<16; i++)
875 : {
876 0 : pData->PutItem( i, aBox );
877 0 : pData->PutItem( i, aFontItem );
878 0 : pData->PutItem( i, aCJKFontItem );
879 0 : pData->PutItem( i, aCTLFontItem );
880 0 : aHeight.SetWhich( ATTR_FONT_HEIGHT );
881 0 : pData->PutItem( i, aHeight );
882 0 : aHeight.SetWhich( ATTR_CJK_FONT_HEIGHT );
883 0 : pData->PutItem( i, aHeight );
884 0 : aHeight.SetWhich( ATTR_CTL_FONT_HEIGHT );
885 0 : pData->PutItem( i, aHeight );
886 0 : if (i<4) // top: white on blue
887 : {
888 0 : pData->PutItem( i, aWhiteText );
889 0 : pData->PutItem( i, aBlueBack );
890 : }
891 0 : else if ( i%4 == 0 ) // left: white on gray70
892 : {
893 0 : pData->PutItem( i, aWhiteText );
894 0 : pData->PutItem( i, aGray70Back );
895 : }
896 0 : else if ( i%4 == 3 || i >= 12 ) // right and bottom: black on gray20
897 : {
898 0 : pData->PutItem( i, aBlackText );
899 0 : pData->PutItem( i, aGray20Back );
900 : }
901 : else // center: black on white
902 : {
903 0 : pData->PutItem( i, aBlackText );
904 0 : pData->PutItem( i, aWhiteBack );
905 : }
906 : }
907 :
908 0 : insert(pData);
909 0 : }
910 :
911 0 : ScAutoFormat::ScAutoFormat(const ScAutoFormat& r) :
912 : maData(r.maData),
913 0 : mbSaveLater(false) {}
914 :
915 0 : ScAutoFormat::~ScAutoFormat()
916 : {
917 : // When modified via StarOne then only the SaveLater flag is set and no saving is done.
918 : // If the flag is set then save now.
919 :
920 0 : if (mbSaveLater)
921 0 : Save();
922 0 : }
923 :
924 0 : void ScAutoFormat::SetSaveLater( bool bSet )
925 : {
926 0 : mbSaveLater = bSet;
927 0 : }
928 :
929 0 : const ScAutoFormatData* ScAutoFormat::findByIndex(size_t nIndex) const
930 : {
931 0 : if (nIndex >= maData.size())
932 0 : return NULL;
933 :
934 0 : MapType::const_iterator it = maData.begin();
935 0 : std::advance(it, nIndex);
936 0 : return it->second;
937 : }
938 :
939 0 : ScAutoFormatData* ScAutoFormat::findByIndex(size_t nIndex)
940 : {
941 0 : if (nIndex >= maData.size())
942 0 : return NULL;
943 :
944 0 : MapType::iterator it = maData.begin();
945 0 : std::advance(it, nIndex);
946 0 : return it->second;
947 : }
948 :
949 0 : ScAutoFormat::const_iterator ScAutoFormat::find(const ScAutoFormatData* pData) const
950 : {
951 0 : MapType::const_iterator it = maData.begin(), itEnd = maData.end();
952 0 : for (; it != itEnd; ++it)
953 : {
954 0 : if (it->second == pData)
955 0 : return it;
956 : }
957 0 : return itEnd;
958 : }
959 :
960 0 : ScAutoFormat::iterator ScAutoFormat::find(const ScAutoFormatData* pData)
961 : {
962 0 : MapType::iterator it = maData.begin(), itEnd = maData.end();
963 0 : for (; it != itEnd; ++it)
964 : {
965 0 : if (it->second == pData)
966 0 : return it;
967 : }
968 0 : return itEnd;
969 : }
970 :
971 0 : ScAutoFormat::const_iterator ScAutoFormat::find(const rtl::OUString& rName) const
972 : {
973 0 : return maData.find(rName);
974 : }
975 :
976 0 : ScAutoFormat::iterator ScAutoFormat::find(const rtl::OUString& rName)
977 : {
978 0 : return maData.find(rName);
979 : }
980 :
981 0 : bool ScAutoFormat::insert(ScAutoFormatData* pNew)
982 : {
983 0 : rtl::OUString aName = pNew->GetName();
984 0 : return maData.insert(aName, pNew).second;
985 : }
986 :
987 0 : void ScAutoFormat::erase(const iterator& it)
988 : {
989 0 : maData.erase(it);
990 0 : }
991 :
992 0 : size_t ScAutoFormat::size() const
993 : {
994 0 : return maData.size();
995 : }
996 :
997 0 : ScAutoFormat::const_iterator ScAutoFormat::begin() const
998 : {
999 0 : return maData.begin();
1000 : }
1001 :
1002 0 : ScAutoFormat::const_iterator ScAutoFormat::end() const
1003 : {
1004 0 : return maData.end();
1005 : }
1006 :
1007 0 : ScAutoFormat::iterator ScAutoFormat::begin()
1008 : {
1009 0 : return maData.begin();
1010 : }
1011 :
1012 0 : ScAutoFormat::iterator ScAutoFormat::end()
1013 : {
1014 0 : return maData.end();
1015 : }
1016 :
1017 0 : bool ScAutoFormat::Load()
1018 : {
1019 0 : bool bRet = true;
1020 :
1021 0 : INetURLObject aURL;
1022 0 : SvtPathOptions aPathOpt;
1023 0 : aURL.SetSmartURL( aPathOpt.GetUserConfigPath() );
1024 0 : aURL.setFinalSlash();
1025 0 : aURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( sAutoTblFmtName ) ) );
1026 :
1027 0 : SfxMedium aMedium( aURL.GetMainURL(INetURLObject::NO_DECODE), STREAM_READ );
1028 0 : SvStream* pStream = aMedium.GetInStream();
1029 0 : bRet = (pStream && pStream->GetError() == 0);
1030 0 : if (bRet)
1031 : {
1032 0 : SvStream& rStream = *pStream;
1033 : // Attention: A common header has to be read
1034 0 : sal_uInt16 nVal = 0;
1035 0 : rStream >> nVal;
1036 0 : bRet = 0 == rStream.GetError();
1037 :
1038 0 : if (bRet)
1039 : {
1040 0 : if( nVal == AUTOFORMAT_ID_358 ||
1041 : (AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
1042 : {
1043 0 : sal_uInt16 nFileVers = SOFFICE_FILEFORMAT_40;
1044 : sal_uInt8 nChrSet, nCnt;
1045 0 : long nPos = rStream.Tell();
1046 0 : rStream >> nCnt >> nChrSet;
1047 0 : if( rStream.Tell() != sal_uLong(nPos + nCnt) )
1048 : {
1049 : OSL_FAIL( "Der Header enthaelt mehr/neuere Daten" );
1050 0 : rStream.Seek( nPos + nCnt );
1051 : }
1052 0 : rStream.SetStreamCharSet( GetSOLoadTextEncoding( nChrSet ) );
1053 0 : rStream.SetVersion( nFileVers );
1054 : }
1055 :
1056 0 : if( nVal == AUTOFORMAT_ID_358 || nVal == AUTOFORMAT_ID_X ||
1057 : (AUTOFORMAT_ID_504 <= nVal && nVal <= AUTOFORMAT_ID) )
1058 : {
1059 0 : m_aVersions.Load( rStream, nVal ); // Item-Versionen
1060 :
1061 : ScAutoFormatData* pData;
1062 0 : sal_uInt16 nAnz = 0;
1063 0 : rStream >> nAnz;
1064 0 : bRet = (rStream.GetError() == 0);
1065 0 : for (sal_uInt16 i=0; bRet && (i < nAnz); i++)
1066 : {
1067 0 : pData = new ScAutoFormatData();
1068 0 : bRet = pData->Load(rStream, m_aVersions);
1069 0 : insert(pData);
1070 0 : }
1071 : }
1072 : else
1073 0 : bRet = false;
1074 : }
1075 : }
1076 0 : mbSaveLater = false;
1077 0 : return bRet;
1078 : }
1079 :
1080 0 : bool ScAutoFormat::Save()
1081 : {
1082 0 : bool bRet = true;
1083 :
1084 0 : INetURLObject aURL;
1085 0 : SvtPathOptions aPathOpt;
1086 0 : aURL.SetSmartURL( aPathOpt.GetUserConfigPath() );
1087 0 : aURL.setFinalSlash();
1088 0 : aURL.Append( String( RTL_CONSTASCII_USTRINGPARAM( sAutoTblFmtName ) ) );
1089 :
1090 0 : SfxMedium aMedium( aURL.GetMainURL(INetURLObject::NO_DECODE), STREAM_WRITE );
1091 0 : SvStream* pStream = aMedium.GetOutStream();
1092 0 : bRet = (pStream && pStream->GetError() == 0);
1093 0 : if (bRet)
1094 : {
1095 0 : const sal_uInt16 fileVersion = SOFFICE_FILEFORMAT_50;
1096 0 : SvStream& rStream = *pStream;
1097 0 : rStream.SetVersion( fileVersion );
1098 :
1099 : // Attention: A common header has to be saved
1100 0 : sal_uInt16 nVal = AUTOFORMAT_ID;
1101 0 : rStream << nVal
1102 0 : << (sal_uInt8)2 // Number of chars of the header including this
1103 : << (sal_uInt8)::GetSOStoreTextEncoding(
1104 0 : osl_getThreadTextEncoding() );
1105 0 : m_aVersions.Write(rStream, fileVersion);
1106 :
1107 0 : bRet = (rStream.GetError() == 0);
1108 : //-----------------------------------------------------------
1109 0 : rStream << (sal_uInt16)(maData.size() - 1);
1110 0 : bRet = (rStream.GetError() == 0);
1111 0 : MapType::iterator it = maData.begin(), itEnd = maData.end();
1112 0 : for (++it; bRet && it != itEnd; ++it) // Skip the first item.
1113 0 : bRet = it->second->Save(rStream, fileVersion);
1114 :
1115 0 : rStream.Flush();
1116 :
1117 0 : aMedium.Commit();
1118 : }
1119 0 : mbSaveLater = false;
1120 0 : return bRet;
1121 : }
1122 :
1123 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|