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