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 $
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
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
53 #include <poolfmt.hxx>
54 #include <charfmt.hxx>
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
),
98 /*-----------------26.06.97 08.30-------------------
100 --------------------------------------------------*/
101 SwBaseNumRules::~SwBaseNumRules()
105 SvtPathOptions aPathOpt
;
106 String
sNm( aPathOpt
.GetUserConfigPath() );
107 sNm
+= INET_PATH_TOKEN
;
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
)
120 /*------------------------------------------------------------------------
122 ------------------------------------------------------------------------*/
123 void SwBaseNumRules::Init()
125 for(USHORT i
= 0; i
< nMaxRules
; ++i
)
128 String
sNm( sFileName
);
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
);
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
)
164 rStream
<< (unsigned char) TRUE
;
165 pNumRules
[i
]->Store( rStream
);
168 rStream
<< (unsigned char) FALSE
;
175 /*------------------------------------------------------------------------
176 Beschreibung: Speichern / Laden
177 ------------------------------------------------------------------------*/
180 int SwBaseNumRules::Load(SvStream
&rStream
)
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
)
200 pNumRules
[i
] = new SwNumRulesWithName( rStream
, nVersion
);
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
)
235 SwBaseNumRules::ApplyNumRules(rCopy
, nIdx
);
238 /*------------------------------------------------------------------------*/
240 SwNumRulesWithName::SwNumRulesWithName( const SwNumRule
&rCopy
,
241 const String
&rName
)
244 for( USHORT n
= 0; n
< MAXLEVEL
; ++n
)
246 const SwNumFmt
* pFmt
= rCopy
.GetNumFmt( n
);
248 aFmts
[ n
] = new _SwNumFmtGlobal( *pFmt
);
254 /*------------------------------------------------------------------------
256 ------------------------------------------------------------------------*/
257 SwNumRulesWithName::SwNumRulesWithName( const SwNumRulesWithName
& rCopy
)
259 memset( aFmts
, 0, sizeof( aFmts
));
264 /*------------------------------------------------------------------------
266 ------------------------------------------------------------------------*/
267 SwNumRulesWithName::~SwNumRulesWithName()
269 for( int n
= 0; n
< MAXLEVEL
; ++n
)
273 /*------------------------------------------------------------------------
275 ------------------------------------------------------------------------*/
276 const SwNumRulesWithName
& SwNumRulesWithName::operator=(const SwNumRulesWithName
&rCopy
)
281 for( int n
= 0; n
< MAXLEVEL
; ++n
)
285 _SwNumFmtGlobal
* pFmt
= rCopy
.aFmts
[ n
];
287 aFmts
[ n
] = new _SwNumFmtGlobal( *pFmt
);
295 /*------------------------------------------------------------------------
297 ------------------------------------------------------------------------*/
298 SwNumRulesWithName::SwNumRulesWithName( SvStream
&rStream
, USHORT nVersion
)
300 CharSet eEncoding
= gsl_getSystemTextEncoding();
301 rStream
.ReadByteString(aName
, eEncoding
);
304 for(USHORT n
= 0; n
< MAXLEVEL
; ++n
)
306 if( VERSION_30B
== nVersion
)
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)
317 aFmts
[ n
] = new _SwNumFmtGlobal( rStream
, nVersion
);
323 /*------------------------------------------------------------------------
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() );
333 rChg
.SetAutoRule( FALSE
);
334 _SwNumFmtGlobal
* pFmt
;
335 for( USHORT n
= 0; n
< MAXLEVEL
; ++n
)
336 if( 0 != ( pFmt
= aFmts
[ n
] ) )
339 pFmt
->ChgNumFmt( rSh
, aNew
);
344 /*------------------------------------------------------------------------
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
];
358 pFmt
->Store( rStream
);
364 /*------------------------------------------------------------------------
366 ------------------------------------------------------------------------*/
369 SwNumRulesWithName::_SwNumFmtGlobal::_SwNumFmtGlobal( const SwNumFmt
& rFmt
)
370 : aFmt( rFmt
), nCharPoolId( USHRT_MAX
)
372 // relative Abstaende ?????
374 SwCharFmt
* pFmt
= rFmt
.GetCharFmt();
377 sCharFmtName
= pFmt
->GetName();
378 nCharPoolId
= pFmt
->GetPoolFmtId();
379 if( pFmt
->GetAttrSet().Count() )
381 SfxItemIter
aIter( pFmt
->GetAttrSet() );
382 const SfxPoolItem
*pCurr
= aIter
.GetCurItem();
385 aItems
.Insert( pCurr
->Clone(), aItems
.Count() );
386 if( aIter
.IsAtEnd() )
388 pCurr
= aIter
.NextItem();
392 aFmt
.SetCharFmt( 0 );
396 /*------------------------------------------------------------------------
398 ------------------------------------------------------------------------*/
400 SwNumRulesWithName::_SwNumFmtGlobal::_SwNumFmtGlobal( const _SwNumFmtGlobal
& rFmt
)
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 /*------------------------------------------------------------------------
412 ------------------------------------------------------------------------*/
414 SwNumRulesWithName::_SwNumFmtGlobal::_SwNumFmtGlobal( SvStream
& rStream
,
416 : nCharPoolId( USHRT_MAX
)
418 CharSet eEncoding
= gsl_getSystemTextEncoding();
426 rStream
>> nUS
; aFmt
.SetNumberingType((sal_Int16
)nUS
);
427 if( VERSION_53A
> nVersion
)
429 rStream
>> cChar
; aFmt
.SetBulletChar( cChar
);
433 rStream
>> nUS
; aFmt
.SetBulletChar( nUS
);
436 rStream
>> bFlag
; aFmt
.SetIncludeUpperLevels( bFlag
);
438 if( VERSION_30B
== nVersion
)
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
);
473 rStream
.ReadByteString(aName
, eEncoding
);
474 rStream
>> nFamily
>> nCharSet
>> nWidth
>> nHeight
>> nPitch
;
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
);
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
)
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
),
509 if( VERSION_40A
== nVersion
&& SVX_NUM_BITMAP
== aFmt
.GetNumberingType() )
514 rStream
>> aSz
.Width() >> aSz
.Height();
519 SvxBrushItem
* pBrush
= 0;
520 SwFmtVertOrient
* pVOrient
= 0;
526 pBrush
= (SvxBrushItem
*)GetDfltAttr( RES_BACKGROUND
)
527 ->Create( rStream
, nVer
);
533 pVOrient
= (SwFmtVertOrient
*)GetDfltAttr( RES_VERT_ORIENT
)
534 ->Create( rStream
, nVer
);
536 sal_Int16 eOrient
= text::VertOrientation::NONE
;
538 eOrient
= (sal_Int16
)pVOrient
->GetVertOrient();
539 aFmt
.SetGraphicBrush( pBrush
, &aSz
, pVOrient
? &eOrient
: 0 );
545 /*------------------------------------------------------------------------
547 ------------------------------------------------------------------------*/
549 SwNumRulesWithName::_SwNumFmtGlobal::~_SwNumFmtGlobal()
552 /*------------------------------------------------------------------------
554 ------------------------------------------------------------------------*/
557 void SwNumRulesWithName::_SwNumFmtGlobal::Store( SvStream
& rStream
)
559 CharSet eEncoding
= gsl_getSystemTextEncoding();
562 USHORT nFamily
= FAMILY_DONTKNOW
, nCharSet
= 0, nPitch
= 0;
563 short nWidth
= 0, nHeight
= 0;
565 const Font
* pFnt
= aFmt
.GetBulletFont();
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)
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()
587 << FALSE
;//aFmt.IsRelLSpace();
588 rStream
.WriteByteString( aName
, eEncoding
);
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()
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 );
620 if( aFmt
.GetBrush() )
622 USHORT nVersion
= aFmt
.GetBrush()->GetVersion( SOFFICE_FILEFORMAT_50
);
624 aFmt
.GetBrush()->Store( rStream
, nVersion
);
626 if( aFmt
.GetGraphicOrientation() )
628 USHORT nVersion
= aFmt
.GetGraphicOrientation()->GetVersion( SOFFICE_FILEFORMAT_50
);
630 aFmt
.GetGraphicOrientation()->Store( rStream
, nVersion
);
635 /*------------------------------------------------------------------------
637 ------------------------------------------------------------------------*/
639 void SwNumRulesWithName::_SwNumFmtGlobal::ChgNumFmt( SwWrtShell
& rSh
,
640 SwNumFmt
& rNew
) const
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!
658 if( IsPoolUserFmt( nCharPoolId
) )
660 pFmt
= rSh
.MakeCharFmt( sCharFmtName
);
661 pFmt
->SetAuto( FALSE
);
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
);
674 ((SwNumFmt
&)aFmt
).SetCharFmt( 0 );