update dev300-m58
[ooovba.git] / sw / source / ui / config / uinums.cxx
blobf11ccd86fc37cbe081e03663aeb15d83ae437b5c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: uinums.cxx,v $
10 * $Revision: 1.17 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
37 #include <hintids.hxx>
38 #include <svtools/urihelper.hxx>
39 #include <svtools/pathoptions.hxx>
40 #include <tools/stream.hxx>
41 #ifndef _SFX_INIMGR_HXX
42 #endif
43 #include <sfx2/docfile.hxx>
44 #include <svtools/itemiter.hxx>
45 #include <svx/brshitem.hxx>
48 #include <tools/resid.hxx>
49 #include <fmtornt.hxx>
50 #include <swtypes.hxx> // Leerstring
51 #include <wrtsh.hxx>
52 #include <uinums.hxx>
53 #include <poolfmt.hxx>
54 #include <charfmt.hxx>
55 #include <frmatr.hxx>
57 #include <unomid.h>
59 using namespace ::com::sun::star;
62 #define VERSION_30B ((USHORT)250)
63 #define VERSION_31B ((USHORT)326)
64 #define VERSION_40A ((USHORT)364)
65 #define VERSION_50A ((USHORT)373)
66 #define VERSION_53A ((USHORT)596)
67 #define ACT_NUM_VERSION VERSION_53A
69 #define NUMRULE_FILENAME "numrule.cfg"
70 #define CHAPTER_FILENAME "chapter.cfg"
72 /*------------------------------------------------------------------------
73 Beschreibung: Ops. zum Laden / Speichern
74 ------------------------------------------------------------------------*/
77 SV_IMPL_PTRARR( _SwNumFmtsAttrs, SfxPoolItem* )
80 // SwNumRulesWithName ----------------------------------------------------
81 // PUBLIC METHODES -------------------------------------------------------
82 /*------------------------------------------------------------------------
83 Beschreibung: Speichern einer Regel
84 Parameter: rCopy -- die zu speichernde Regel
85 nIdx -- Position, an der die Regel zu speichern ist.
86 Eine alte Regel an dieser Position wird ueberschrieben.
87 ------------------------------------------------------------------------*/
89 SwBaseNumRules::SwBaseNumRules( const String& rFileName )
91 sFileName( rFileName ),
92 nVersion(0),
93 bModified( FALSE )
95 Init();
98 /*-----------------26.06.97 08.30-------------------
100 --------------------------------------------------*/
101 SwBaseNumRules::~SwBaseNumRules()
103 if( bModified )
105 SvtPathOptions aPathOpt;
106 String sNm( aPathOpt.GetUserConfigPath() );
107 sNm += INET_PATH_TOKEN;
108 sNm += sFileName;
109 INetURLObject aTempObj(sNm);
110 sNm = aTempObj.GetFull();
111 SfxMedium aStrm( sNm, STREAM_WRITE | STREAM_TRUNC |
112 STREAM_SHARE_DENYALL, TRUE );
113 Store( *aStrm.GetOutStream() );
116 for( USHORT i = 0; i < nMaxRules; ++i )
117 delete pNumRules[i];
120 /*------------------------------------------------------------------------
121 Beschreibung:
122 ------------------------------------------------------------------------*/
123 void SwBaseNumRules::Init()
125 for(USHORT i = 0; i < nMaxRules; ++i )
126 pNumRules[i] = 0;
128 String sNm( sFileName );
129 SvtPathOptions aOpt;
130 if( aOpt.SearchFile( sNm, SvtPathOptions::PATH_USERCONFIG ))
132 SfxMedium aStrm( sNm, STREAM_STD_READ, TRUE );
133 Load( *aStrm.GetInStream() );
137 /*-----------------26.06.97 08.30-------------------
139 --------------------------------------------------*/
141 void SwBaseNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, USHORT nIdx)
143 ASSERT(nIdx < nMaxRules, Array der NumRules ueberindiziert.);
144 if( !pNumRules[nIdx] )
145 pNumRules[nIdx] = new SwNumRulesWithName( rCopy );
146 else
147 *pNumRules[nIdx] = rCopy;
150 // PROTECTED METHODES ----------------------------------------------------
151 /*------------------------------------------------------------------------
152 Beschreibung: Speichern
153 ------------------------------------------------------------------------*/
155 BOOL /**/ SwBaseNumRules::Store(SvStream &rStream)
157 rStream << ACT_NUM_VERSION;
158 // Schreiben, welche Positionen durch eine Regel belegt sind
159 // Anschliessend Schreiben der einzelnen Rules
160 for(USHORT i = 0; i < nMaxRules; ++i)
162 if(pNumRules[i])
164 rStream << (unsigned char) TRUE;
165 pNumRules[i]->Store( rStream );
167 else
168 rStream << (unsigned char) FALSE;
170 return TRUE;
175 /*------------------------------------------------------------------------
176 Beschreibung: Speichern / Laden
177 ------------------------------------------------------------------------*/
180 int SwBaseNumRules::Load(SvStream &rStream)
182 int rc = 0;
184 rStream >> nVersion;
186 // wegen eines kleinen aber schweren Fehlers schreibt die PreFinal die
187 // gleiche VERSION_40A wie das SP2 #55402#
188 if(VERSION_40A == nVersion)
190 DBG_ERROR("Version 364 ist nicht eindeutig #55402#");
192 else if( VERSION_30B == nVersion || VERSION_31B == nVersion ||
193 ACT_NUM_VERSION >= nVersion )
195 unsigned char bRule = FALSE;
196 for(USHORT i = 0; i < nMaxRules; ++i)
198 rStream >> bRule;
199 if(bRule)
200 pNumRules[i] = new SwNumRulesWithName( rStream, nVersion );
203 else
205 rc = 1;
208 return rc;
211 /*-----------------26.06.97 08.34-------------------
213 --------------------------------------------------*/
215 /*------------------------------------------------------------------------*/
218 SwChapterNumRules::SwChapterNumRules() :
219 SwBaseNumRules(C2S(CHAPTER_FILENAME))
223 /*------------------------------------------------------------------------*/
225 SwChapterNumRules::~SwChapterNumRules()
229 /*-----------------26.06.97 08.23-------------------
231 --------------------------------------------------*/
232 void SwChapterNumRules::ApplyNumRules(const SwNumRulesWithName &rCopy, USHORT nIdx)
234 bModified = TRUE;
235 SwBaseNumRules::ApplyNumRules(rCopy, nIdx);
238 /*------------------------------------------------------------------------*/
240 SwNumRulesWithName::SwNumRulesWithName( const SwNumRule &rCopy,
241 const String &rName )
242 : aName(rName)
244 for( USHORT n = 0; n < MAXLEVEL; ++n )
246 const SwNumFmt* pFmt = rCopy.GetNumFmt( n );
247 if( pFmt )
248 aFmts[ n ] = new _SwNumFmtGlobal( *pFmt );
249 else
250 aFmts[ n ] = 0;
254 /*------------------------------------------------------------------------
255 Beschreibung:
256 ------------------------------------------------------------------------*/
257 SwNumRulesWithName::SwNumRulesWithName( const SwNumRulesWithName& rCopy )
259 memset( aFmts, 0, sizeof( aFmts ));
260 *this = rCopy;
264 /*------------------------------------------------------------------------
265 Beschreibung:
266 ------------------------------------------------------------------------*/
267 SwNumRulesWithName::~SwNumRulesWithName()
269 for( int n = 0; n < MAXLEVEL; ++n )
270 delete aFmts[ n ];
273 /*------------------------------------------------------------------------
274 Beschreibung:
275 ------------------------------------------------------------------------*/
276 const SwNumRulesWithName& SwNumRulesWithName::operator=(const SwNumRulesWithName &rCopy)
278 if( this != &rCopy )
280 aName = rCopy.aName;
281 for( int n = 0; n < MAXLEVEL; ++n )
283 delete aFmts[ n ];
285 _SwNumFmtGlobal* pFmt = rCopy.aFmts[ n ];
286 if( pFmt )
287 aFmts[ n ] = new _SwNumFmtGlobal( *pFmt );
288 else
289 aFmts[ n ] = 0;
292 return *this;
295 /*------------------------------------------------------------------------
296 Beschreibung:
297 ------------------------------------------------------------------------*/
298 SwNumRulesWithName::SwNumRulesWithName( SvStream &rStream, USHORT nVersion )
300 CharSet eEncoding = gsl_getSystemTextEncoding();
301 rStream.ReadByteString(aName, eEncoding);
303 char c;
304 for(USHORT n = 0; n < MAXLEVEL; ++n )
306 if( VERSION_30B == nVersion )
307 c = 1;
308 // wegen eines kleinen aber schweren Fehlers schreibt die PreFinal die
309 // gleiche VERSION_40A wie das SP2 #55402#
310 else if(nVersion < VERSION_40A && n > 5)
311 // else if(nVersion < VERSION_50A && n > 5)
312 c = 0;
313 else
314 rStream >> c;
316 if( c )
317 aFmts[ n ] = new _SwNumFmtGlobal( rStream, nVersion );
318 else
319 aFmts[ n ] = 0;
323 /*------------------------------------------------------------------------
324 Beschreibung:
325 ------------------------------------------------------------------------*/
327 void SwNumRulesWithName::MakeNumRule( SwWrtShell& rSh, SwNumRule& rChg ) const
329 // --> OD 2008-02-11 #newlistlevelattrs#
330 // --> OD 2008-06-06 #i89178#
331 rChg = SwNumRule( aName, numfunc::GetDefaultPositionAndSpaceMode() );
332 // <--
333 rChg.SetAutoRule( FALSE );
334 _SwNumFmtGlobal* pFmt;
335 for( USHORT n = 0; n < MAXLEVEL; ++n )
336 if( 0 != ( pFmt = aFmts[ n ] ) )
338 SwNumFmt aNew;
339 pFmt->ChgNumFmt( rSh, aNew );
340 rChg.Set( n, aNew );
344 /*------------------------------------------------------------------------
345 Beschreibung:
346 ------------------------------------------------------------------------*/
347 void SwNumRulesWithName::Store( SvStream &rStream )
349 CharSet eEncoding = gsl_getSystemTextEncoding();
350 rStream.WriteByteString(aName, eEncoding);
352 for( USHORT n = 0; n < MAXLEVEL; ++n )
354 _SwNumFmtGlobal* pFmt = aFmts[ n ];
355 if( pFmt )
357 rStream << (char)1;
358 pFmt->Store( rStream );
360 else
361 rStream << (char)0;
364 /*------------------------------------------------------------------------
365 Beschreibung:
366 ------------------------------------------------------------------------*/
369 SwNumRulesWithName::_SwNumFmtGlobal::_SwNumFmtGlobal( const SwNumFmt& rFmt )
370 : aFmt( rFmt ), nCharPoolId( USHRT_MAX )
372 // relative Abstaende ?????
374 SwCharFmt* pFmt = rFmt.GetCharFmt();
375 if( pFmt )
377 sCharFmtName = pFmt->GetName();
378 nCharPoolId = pFmt->GetPoolFmtId();
379 if( pFmt->GetAttrSet().Count() )
381 SfxItemIter aIter( pFmt->GetAttrSet() );
382 const SfxPoolItem *pCurr = aIter.GetCurItem();
383 while( TRUE )
385 aItems.Insert( pCurr->Clone(), aItems.Count() );
386 if( aIter.IsAtEnd() )
387 break;
388 pCurr = aIter.NextItem();
392 aFmt.SetCharFmt( 0 );
396 /*------------------------------------------------------------------------
397 Beschreibung:
398 ------------------------------------------------------------------------*/
400 SwNumRulesWithName::_SwNumFmtGlobal::_SwNumFmtGlobal( const _SwNumFmtGlobal& rFmt )
402 aFmt( rFmt.aFmt ),
403 sCharFmtName( rFmt.sCharFmtName ),
404 nCharPoolId( rFmt.nCharPoolId )
406 for( USHORT n = rFmt.aItems.Count(); n; )
407 aItems.Insert( rFmt.aItems[ --n ]->Clone(), aItems.Count() );
410 /*------------------------------------------------------------------------
411 Beschreibung:
412 ------------------------------------------------------------------------*/
414 SwNumRulesWithName::_SwNumFmtGlobal::_SwNumFmtGlobal( SvStream& rStream,
415 USHORT nVersion )
416 : nCharPoolId( USHRT_MAX )
418 CharSet eEncoding = gsl_getSystemTextEncoding();
420 USHORT nUS;
421 sal_Char cChar;
422 short nShort;
423 BOOL bFlag;
424 String sStr;
426 rStream >> nUS; aFmt.SetNumberingType((sal_Int16)nUS );
427 if( VERSION_53A > nVersion )
429 rStream >> cChar; aFmt.SetBulletChar( cChar );
431 else
433 rStream >> nUS; aFmt.SetBulletChar( nUS );
436 rStream >> bFlag; aFmt.SetIncludeUpperLevels( bFlag );
438 if( VERSION_30B == nVersion )
440 long nL;
441 rStream >> cChar; aFmt.SetStart( (USHORT)cChar );
443 rStream.ReadByteString(sStr, eEncoding);
444 aFmt.SetPrefix( sStr );
445 rStream.ReadByteString(sStr, eEncoding);
446 aFmt.SetSuffix( sStr );
447 rStream >> nUS; aFmt.SetNumAdjust( SvxAdjust( nUS ) );
448 rStream >> nL; aFmt.SetLSpace( lNumIndent );
449 rStream >> nL; aFmt.SetFirstLineOffset( (short)nL );
451 else // alter StartWert war ein Byte
453 rStream >> nUS; aFmt.SetStart( nUS );
454 rStream.ReadByteString(sStr, eEncoding);
455 aFmt.SetPrefix( sStr );
456 rStream.ReadByteString(sStr, eEncoding);
457 aFmt.SetSuffix( sStr );
458 rStream >> nUS; aFmt.SetNumAdjust( SvxAdjust( nUS ) );
459 rStream >> nUS; aFmt.SetAbsLSpace( nUS );
460 rStream >> nShort; aFmt.SetFirstLineOffset( nShort );
461 rStream >> nUS; aFmt.SetCharTextDistance( nUS );
462 rStream >> nShort; aFmt.SetLSpace( nShort );
463 rStream >> bFlag;
466 USHORT nFamily;
467 USHORT nCharSet;
468 short nWidth;
469 short nHeight;
470 USHORT nPitch;
471 String aName;
473 rStream.ReadByteString(aName, eEncoding);
474 rStream >> nFamily >> nCharSet >> nWidth >> nHeight >> nPitch;
476 if( aName.Len() )
478 Font aFont( nFamily, Size( nWidth, nHeight ) );
479 aFont.SetName( aName );
480 aFont.SetCharSet( (CharSet)nCharSet );
481 aFont.SetPitch( (FontPitch)nPitch );
483 aFmt.SetBulletFont( &aFont );
485 else
486 nCharSet = RTL_TEXTENCODING_SYMBOL;
488 if( VERSION_53A > nVersion )
489 aFmt.SetBulletChar( ByteString::ConvertToUnicode(
490 sal_Char(aFmt.GetBulletChar()), nCharSet ));
493 if( VERSION_30B != nVersion )
495 USHORT nItemCount;
496 rStream >> nCharPoolId;
497 rStream.ReadByteString(sCharFmtName, eEncoding);
498 rStream >> nItemCount;
500 while( nItemCount-- )
502 USHORT nWhich, nVers;
503 rStream >> nWhich >> nVers;
504 aItems.Insert( GetDfltAttr( nWhich )->Create( rStream, nVers ),
505 aItems.Count() );
509 if( VERSION_40A == nVersion && SVX_NUM_BITMAP == aFmt.GetNumberingType() )
511 BYTE cF;
512 Size aSz;
514 rStream >> aSz.Width() >> aSz.Height();
516 rStream >> cF;
517 if( cF )
519 SvxBrushItem* pBrush = 0;
520 SwFmtVertOrient* pVOrient = 0;
521 USHORT nVer;
523 if( cF & 1 )
525 rStream >> nVer;
526 pBrush = (SvxBrushItem*)GetDfltAttr( RES_BACKGROUND )
527 ->Create( rStream, nVer );
530 if( cF & 2 )
532 rStream >> nVer;
533 pVOrient = (SwFmtVertOrient*)GetDfltAttr( RES_VERT_ORIENT )
534 ->Create( rStream, nVer );
536 sal_Int16 eOrient = text::VertOrientation::NONE;
537 if(pVOrient)
538 eOrient = (sal_Int16)pVOrient->GetVertOrient();
539 aFmt.SetGraphicBrush( pBrush, &aSz, pVOrient ? &eOrient : 0 );
545 /*------------------------------------------------------------------------
546 Beschreibung:
547 ------------------------------------------------------------------------*/
549 SwNumRulesWithName::_SwNumFmtGlobal::~_SwNumFmtGlobal()
552 /*------------------------------------------------------------------------
553 Beschreibung:
554 ------------------------------------------------------------------------*/
557 void SwNumRulesWithName::_SwNumFmtGlobal::Store( SvStream& rStream )
559 CharSet eEncoding = gsl_getSystemTextEncoding();
561 String aName;
562 USHORT nFamily = FAMILY_DONTKNOW, nCharSet = 0, nPitch = 0;
563 short nWidth = 0, nHeight = 0;
565 const Font* pFnt = aFmt.GetBulletFont();
566 if( pFnt )
568 aName = pFnt->GetName();
569 nFamily = (USHORT)pFnt->GetFamily();
570 nCharSet = (USHORT)pFnt->GetCharSet();
571 nWidth = (short)pFnt->GetSize().Width();
572 nHeight = (short)pFnt->GetSize().Height();
573 nPitch = (USHORT)pFnt->GetPitch();
576 rStream << USHORT(aFmt.GetNumberingType())
577 << aFmt.GetBulletChar()
578 << (aFmt.GetIncludeUpperLevels() > 0)
579 << aFmt.GetStart();
580 rStream.WriteByteString( aFmt.GetPrefix(), eEncoding );
581 rStream.WriteByteString( aFmt.GetSuffix(), eEncoding );
582 rStream << USHORT( aFmt.GetNumAdjust() )
583 << aFmt.GetAbsLSpace()
584 << aFmt.GetFirstLineOffset()
585 << aFmt.GetCharTextDistance()
586 << aFmt.GetLSpace()
587 << FALSE;//aFmt.IsRelLSpace();
588 rStream.WriteByteString( aName, eEncoding );
589 rStream << nFamily
590 << nCharSet
591 << nWidth
592 << nHeight
593 << nPitch;
595 rStream << nCharPoolId;
596 rStream.WriteByteString( sCharFmtName, eEncoding );
597 rStream << aItems.Count();
599 for( USHORT n = aItems.Count(); n; )
601 SfxPoolItem* pItem = aItems[ --n ];
602 USHORT nIVers = pItem->GetVersion( SOFFICE_FILEFORMAT_50 );
603 ASSERT( nIVers != USHRT_MAX,
604 "Was'n das: Item-Version USHRT_MAX in der aktuellen Version" );
605 rStream << pItem->Which()
606 << nIVers;
607 pItem->Store( rStream, nIVers );
610 // Erweiterungen fuer Version 40A
612 if( SVX_NUM_BITMAP == aFmt.GetNumberingType() )
614 rStream << (INT32)aFmt.GetGraphicSize().Width()
615 << (INT32)aFmt.GetGraphicSize().Height();
616 BYTE cFlg = ( 0 != aFmt.GetBrush() ? 1 : 0 ) +
617 ( 0 != aFmt.GetGraphicOrientation() ? 2 : 0 );
618 rStream << cFlg;
620 if( aFmt.GetBrush() )
622 USHORT nVersion = aFmt.GetBrush()->GetVersion( SOFFICE_FILEFORMAT_50 );
623 rStream << nVersion;
624 aFmt.GetBrush()->Store( rStream, nVersion );
626 if( aFmt.GetGraphicOrientation() )
628 USHORT nVersion = aFmt.GetGraphicOrientation()->GetVersion( SOFFICE_FILEFORMAT_50 );
629 rStream << nVersion;
630 aFmt.GetGraphicOrientation()->Store( rStream, nVersion );
635 /*------------------------------------------------------------------------
636 Beschreibung:
637 ------------------------------------------------------------------------*/
639 void SwNumRulesWithName::_SwNumFmtGlobal::ChgNumFmt( SwWrtShell& rSh,
640 SwNumFmt& rNew ) const
642 SwCharFmt* pFmt = 0;
643 if( sCharFmtName.Len() )
645 // suche erstmal ueber den Namen
646 USHORT nArrLen = rSh.GetCharFmtCount();
647 for( USHORT i = 1; i < nArrLen; ++i )
649 pFmt = &rSh.GetCharFmt( i );
650 if( COMPARE_EQUAL == pFmt->GetName().CompareTo( sCharFmtName ))
651 // ist vorhanden, also belasse die Attribute wie sie sind!
652 break;
653 pFmt = 0;
656 if( !pFmt )
658 if( IsPoolUserFmt( nCharPoolId ) )
660 pFmt = rSh.MakeCharFmt( sCharFmtName );
661 pFmt->SetAuto( FALSE );
663 else
664 pFmt = rSh.GetCharFmtFromPool( nCharPoolId );
666 if( !pFmt->GetDepends() ) // Attribute setzen
667 for( USHORT n = aItems.Count(); n; )
668 pFmt->SetFmtAttr( *aItems[ --n ] );
671 ((SwNumFmt&)aFmt).SetCharFmt( pFmt );
672 rNew = aFmt;
673 if( pFmt )
674 ((SwNumFmt&)aFmt).SetCharFmt( 0 );