1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "scitems.hxx"
21 #include <editeng/eeitem.hxx>
22 #include <i18nlangtag/mslangid.hxx>
23 #include <svx/algitem.hxx>
24 #include <editeng/boxitem.hxx>
25 #include <editeng/brushitem.hxx>
26 #include <editeng/editdata.hxx>
27 #include <editeng/editeng.hxx>
28 #include <editeng/editobj.hxx>
29 #include <editeng/fhgtitem.hxx>
30 #include <editeng/flditem.hxx>
31 #include <editeng/fontitem.hxx>
32 #include <svx/pageitem.hxx>
33 #include <editeng/postitem.hxx>
34 #include <editeng/udlnitem.hxx>
35 #include <editeng/wghtitem.hxx>
36 #include <editeng/justifyitem.hxx>
37 #include <svl/itemset.hxx>
38 #include <svl/zforlist.hxx>
39 #include <unotools/charclass.hxx>
40 #include <unotools/fontcvt.hxx>
41 #include <vcl/outdev.hxx>
42 #include <vcl/svapp.hxx>
47 #include "globstr.hrc"
48 #include "document.hxx"
49 #include "docpool.hxx"
50 #include "stlpool.hxx"
51 #include "stlsheet.hxx"
52 #include "rechead.hxx"
53 #include "editutil.hxx"
54 #include "patattr.hxx"
57 //========================================================================
59 ScStyleSheetPool::ScStyleSheetPool( SfxItemPool
& rPoolP
,
60 ScDocument
* pDocument
)
61 : SfxStyleSheetPool( rPoolP
),
62 pActualStyleSheet( NULL
),
68 //------------------------------------------------------------------------
70 ScStyleSheetPool::~ScStyleSheetPool()
74 //------------------------------------------------------------------------
76 void ScStyleSheetPool::SetDocument( ScDocument
* pDocument
)
81 //------------------------------------------------------------------------
83 SfxStyleSheetBase
& ScStyleSheetPool::Make( const OUString
& rName
,
84 SfxStyleFamily eFam
, sal_uInt16 mask
)
86 // When updating styles from a template, Office 5.1 sometimes created
87 // files with multiple default styles.
88 // Create new styles in that case:
90 //! only when loading?
92 if ( rName
== STRING_STANDARD
&& Find( rName
, eFam
) != NULL
)
94 OSL_FAIL("renaming additional default style");
95 sal_uInt32 nCount
= aStyles
.size();
96 for ( sal_uInt32 nAdd
= 1; nAdd
<= nCount
; nAdd
++ )
98 OUString aNewName
= ScGlobal::GetRscString(STR_STYLENAME_STANDARD
);
99 aNewName
+= OUString::number( nAdd
);
100 if ( Find( aNewName
, eFam
) == NULL
)
101 return SfxStyleSheetPool::Make(aNewName
, eFam
, mask
);
105 return SfxStyleSheetPool::Make(rName
, eFam
, mask
);
108 //------------------------------------------------------------------------
110 SfxStyleSheetBase
* ScStyleSheetPool::Create( const OUString
& rName
,
111 SfxStyleFamily eFamily
,
114 ScStyleSheet
* pSheet
= new ScStyleSheet( rName
, *this, eFamily
, nMaskP
);
115 if ( eFamily
== SFX_STYLE_FAMILY_PARA
&& ScGlobal::GetRscString(STR_STYLENAME_STANDARD
) != rName
)
116 pSheet
->SetParent( ScGlobal::GetRscString(STR_STYLENAME_STANDARD
) );
121 //------------------------------------------------------------------------
123 SfxStyleSheetBase
* ScStyleSheetPool::Create( const SfxStyleSheetBase
& rStyle
)
125 OSL_ENSURE( rStyle
.ISA(ScStyleSheet
), "Invalid StyleSheet-class! :-/" );
126 return new ScStyleSheet( (const ScStyleSheet
&) rStyle
);
129 //------------------------------------------------------------------------
131 void ScStyleSheetPool::Remove( SfxStyleSheetBase
* pStyle
)
135 OSL_ENSURE( IS_SET( SFXSTYLEBIT_USERDEF
, pStyle
->GetMask() ),
136 "SFXSTYLEBIT_USERDEF not set!" );
138 ((ScDocumentPool
&)rPool
).StyleDeleted((ScStyleSheet
*)pStyle
);
139 SfxStyleSheetPool::Remove(pStyle
);
143 //------------------------------------------------------------------------
145 void ScStyleSheetPool::CopyStyleFrom( ScStyleSheetPool
* pSrcPool
,
146 const OUString
& rName
, SfxStyleFamily eFamily
)
148 // this ist Dest-Pool
150 SfxStyleSheetBase
* pStyleSheet
= pSrcPool
->Find( rName
, eFamily
);
153 const SfxItemSet
& rSourceSet
= pStyleSheet
->GetItemSet();
154 SfxStyleSheetBase
* pDestSheet
= Find( rName
, eFamily
);
156 pDestSheet
= &Make( rName
, eFamily
);
157 SfxItemSet
& rDestSet
= pDestSheet
->GetItemSet();
158 rDestSet
.PutExtended( rSourceSet
, SFX_ITEM_DONTCARE
, SFX_ITEM_DEFAULT
);
160 const SfxPoolItem
* pItem
;
161 if ( eFamily
== SFX_STYLE_FAMILY_PAGE
)
165 if ( rSourceSet
.GetItemState( ATTR_PAGE_HEADERSET
, false, &pItem
) == SFX_ITEM_SET
)
167 const SfxItemSet
& rSrcSub
= ((const SvxSetItem
*) pItem
)->GetItemSet();
168 SfxItemSet
aDestSub( *rDestSet
.GetPool(), rSrcSub
.GetRanges() );
169 aDestSub
.PutExtended( rSrcSub
, SFX_ITEM_DONTCARE
, SFX_ITEM_DEFAULT
);
170 rDestSet
.Put( SvxSetItem( ATTR_PAGE_HEADERSET
, aDestSub
) );
172 if ( rSourceSet
.GetItemState( ATTR_PAGE_FOOTERSET
, false, &pItem
) == SFX_ITEM_SET
)
174 const SfxItemSet
& rSrcSub
= ((const SvxSetItem
*) pItem
)->GetItemSet();
175 SfxItemSet
aDestSub( *rDestSet
.GetPool(), rSrcSub
.GetRanges() );
176 aDestSub
.PutExtended( rSrcSub
, SFX_ITEM_DONTCARE
, SFX_ITEM_DEFAULT
);
177 rDestSet
.Put( SvxSetItem( ATTR_PAGE_FOOTERSET
, aDestSub
) );
182 // number format exchange list has to be handled here, too
184 if ( pDoc
&& pDoc
->GetFormatExchangeList() &&
185 rSourceSet
.GetItemState( ATTR_VALUE_FORMAT
, false, &pItem
) == SFX_ITEM_SET
)
187 sal_uLong nOldFormat
= static_cast<const SfxUInt32Item
*>(pItem
)->GetValue();
188 SvNumberFormatterIndexTable::const_iterator it
= pDoc
->GetFormatExchangeList()->find(nOldFormat
);
189 if (it
!= pDoc
->GetFormatExchangeList()->end())
191 sal_uInt32 nNewFormat
= it
->second
;
192 rDestSet
.Put( SfxUInt32Item( ATTR_VALUE_FORMAT
, nNewFormat
) );
199 //------------------------------------------------------------------------
203 //------------------------------------------------------------------------
205 #define SCSTR(id) ScGlobal::GetRscString(id)
207 void ScStyleSheetPool::CopyStdStylesFrom( ScStyleSheetPool
* pSrcPool
)
209 // Default-Styles kopieren
211 CopyStyleFrom( pSrcPool
, SCSTR(STR_STYLENAME_STANDARD
), SFX_STYLE_FAMILY_PARA
);
212 CopyStyleFrom( pSrcPool
, SCSTR(STR_STYLENAME_RESULT
), SFX_STYLE_FAMILY_PARA
);
213 CopyStyleFrom( pSrcPool
, SCSTR(STR_STYLENAME_RESULT1
), SFX_STYLE_FAMILY_PARA
);
214 CopyStyleFrom( pSrcPool
, SCSTR(STR_STYLENAME_HEADLINE
), SFX_STYLE_FAMILY_PARA
);
215 CopyStyleFrom( pSrcPool
, SCSTR(STR_STYLENAME_HEADLINE1
), SFX_STYLE_FAMILY_PARA
);
216 CopyStyleFrom( pSrcPool
, SCSTR(STR_STYLENAME_STANDARD
), SFX_STYLE_FAMILY_PAGE
);
217 CopyStyleFrom( pSrcPool
, SCSTR(STR_STYLENAME_REPORT
), SFX_STYLE_FAMILY_PAGE
);
220 //------------------------------------------------------------------------
222 static void lcl_CheckFont( SfxItemSet
& rSet
, LanguageType eLang
, sal_uInt16 nFontType
, sal_uInt16 nItemId
)
224 if ( eLang
!= LANGUAGE_NONE
&& eLang
!= LANGUAGE_DONTKNOW
&& eLang
!= LANGUAGE_SYSTEM
)
226 Font aDefFont
= OutputDevice::GetDefaultFont( nFontType
, eLang
, DEFAULTFONT_FLAGS_ONLYONE
);
227 SvxFontItem
aNewItem( aDefFont
.GetFamily(), aDefFont
.GetName(), aDefFont
.GetStyleName(),
228 aDefFont
.GetPitch(), aDefFont
.GetCharSet(), nItemId
);
229 if ( aNewItem
!= rSet
.Get( nItemId
) )
231 // put item into style's ItemSet only if different from (static) default
232 rSet
.Put( aNewItem
);
237 void ScStyleSheetPool::CreateStandardStyles()
239 // neue Eintraege auch bei CopyStdStylesFrom eintragen
241 Color
aColBlack ( COL_BLACK
);
242 Color
aColGrey ( COL_LIGHTGRAY
);
245 OUString aHelpFile
;//XXX JN welcher Text???
246 SfxItemSet
* pSet
= NULL
;
247 SfxItemSet
* pHFSet
= NULL
;
248 SvxSetItem
* pHFSetItem
= NULL
;
249 ScEditEngineDefaulter
* pEdEngine
= new ScEditEngineDefaulter( EditEngine::CreatePool(), sal_True
);
250 pEdEngine
->SetUpdateMode( false );
251 EditTextObject
* pEmptyTxtObj
= pEdEngine
->CreateTextObject();
252 EditTextObject
* pTxtObj
= NULL
;
253 ScPageHFItem
* pHeaderItem
= new ScPageHFItem( ATTR_PAGE_HEADERRIGHT
);
254 ScPageHFItem
* pFooterItem
= new ScPageHFItem( ATTR_PAGE_FOOTERRIGHT
);
255 ScStyleSheet
* pSheet
= NULL
;
256 ::editeng::SvxBorderLine
aBorderLine ( &aColBlack
, DEF_LINE_WIDTH_2
);
257 SvxBoxItem
aBoxItem ( ATTR_BORDER
);
258 SvxBoxInfoItem
aBoxInfoItem ( ATTR_BORDER_INNER
);
260 OUString aStrStandard
= ScGlobal::GetRscString(STR_STYLENAME_STANDARD
);
262 //==========================================================
263 // Zellformatvorlagen:
264 //==========================================================
269 pSheet
= (ScStyleSheet
*) &Make( aStrStandard
, SFX_STYLE_FAMILY_PARA
, SCSTYLEBIT_STANDARD
);
270 pSheet
->SetHelpId( aHelpFile
, HID_SC_SHEET_CELL_STD
);
272 // if default fonts for the document's languages are different from the pool default,
273 // put them into the default style
274 // (not as pool defaults, because pool defaults can't be changed by the user)
275 // the document languages must be set before creating the default styles!
277 pSet
= &pSheet
->GetItemSet();
278 LanguageType eLatin
, eCjk
, eCtl
;
279 pDoc
->GetLanguage( eLatin
, eCjk
, eCtl
);
281 // If the UI language is Korean, the default Latin font has to
282 // be queried for Korean, too (the Latin language from the document can't be Korean).
283 // This is the same logic as in SwDocShell::InitNew.
284 LanguageType eUiLanguage
= Application::GetSettings().GetUILanguageTag().getLanguageType();
285 if (MsLangId::isKorean(eUiLanguage
))
286 eLatin
= eUiLanguage
;
288 lcl_CheckFont( *pSet
, eLatin
, DEFAULTFONT_LATIN_SPREADSHEET
, ATTR_FONT
);
289 lcl_CheckFont( *pSet
, eCjk
, DEFAULTFONT_CJK_SPREADSHEET
, ATTR_CJK_FONT
);
290 lcl_CheckFont( *pSet
, eCtl
, DEFAULTFONT_CTL_SPREADSHEET
, ATTR_CTL_FONT
);
292 // #i55300# default CTL font size for Thai has to be larger
293 // #i59408# The 15 point size causes problems with row heights, so no different
294 // size is used for Thai in Calc for now.
295 // if ( eCtl == LANGUAGE_THAI )
296 // pSet->Put( SvxFontHeightItem( 300, 100, ATTR_CTL_FONT_HEIGHT ) ); // 15 pt
302 pSheet
= (ScStyleSheet
*) &Make( SCSTR( STR_STYLENAME_RESULT
),
303 SFX_STYLE_FAMILY_PARA
,
304 SCSTYLEBIT_STANDARD
);
305 pSheet
->SetParent( aStrStandard
);
306 pSheet
->SetHelpId( aHelpFile
, HID_SC_SHEET_CELL_ERG
);
307 pSet
= &pSheet
->GetItemSet();
308 pSet
->Put( SvxWeightItem( WEIGHT_BOLD
, ATTR_FONT_WEIGHT
) );
309 pSet
->Put( SvxPostureItem( ITALIC_NORMAL
, ATTR_FONT_POSTURE
) );
310 pSet
->Put( SvxUnderlineItem( UNDERLINE_SINGLE
, ATTR_FONT_UNDERLINE
) );
316 pSheet
= (ScStyleSheet
*) &Make( SCSTR( STR_STYLENAME_RESULT1
),
317 SFX_STYLE_FAMILY_PARA
,
318 SCSTYLEBIT_STANDARD
);
320 pSheet
->SetParent( SCSTR( STR_STYLENAME_RESULT
) );
321 pSheet
->SetHelpId( aHelpFile
, HID_SC_SHEET_CELL_ERG1
);
327 pSheet
= (ScStyleSheet
*) &Make( SCSTR( STR_STYLENAME_HEADLINE
),
328 SFX_STYLE_FAMILY_PARA
,
329 SCSTYLEBIT_STANDARD
);
331 pSheet
->SetParent( aStrStandard
);
332 pSheet
->SetHelpId( aHelpFile
, HID_SC_SHEET_CELL_UEB
);
333 pSet
= &pSheet
->GetItemSet();
334 pSet
->Put( SvxFontHeightItem( 320, 100, ATTR_FONT_HEIGHT
) ); // 16pt
335 pSet
->Put( SvxWeightItem( WEIGHT_BOLD
, ATTR_FONT_WEIGHT
) );
336 pSet
->Put( SvxPostureItem( ITALIC_NORMAL
, ATTR_FONT_POSTURE
) );
337 pSet
->Put( SvxHorJustifyItem( SVX_HOR_JUSTIFY_CENTER
, ATTR_HOR_JUSTIFY
) );
343 pSheet
= (ScStyleSheet
*) &Make( SCSTR( STR_STYLENAME_HEADLINE1
),
344 SFX_STYLE_FAMILY_PARA
,
345 SCSTYLEBIT_STANDARD
);
347 pSheet
->SetParent( SCSTR( STR_STYLENAME_HEADLINE
) );
348 pSheet
->SetHelpId( aHelpFile
, HID_SC_SHEET_CELL_UEB1
);
349 pSet
= &pSheet
->GetItemSet();
350 pSet
->Put( SfxInt32Item( ATTR_ROTATE_VALUE
, 9000 ) );
352 //==========================================================
353 // Seitenformat-Vorlagen:
354 //==========================================================
360 pSheet
= (ScStyleSheet
*) &Make( aStrStandard
,
361 SFX_STYLE_FAMILY_PAGE
,
362 SCSTYLEBIT_STANDARD
);
364 pSet
= &pSheet
->GetItemSet();
365 pSheet
->SetHelpId( aHelpFile
, HID_SC_SHEET_PAGE_STD
);
367 // Abstand der Kopf-/Fusszeilen von der Tabelle
368 pHFSetItem
= new SvxSetItem( ((SvxSetItem
&)pSet
->Get( ATTR_PAGE_HEADERSET
) ) );
369 pSet
->Put( *pHFSetItem
, ATTR_PAGE_HEADERSET
);
370 pSet
->Put( *pHFSetItem
, ATTR_PAGE_FOOTERSET
);
371 DELETEZ( pHFSetItem
);
373 //----------------------------------------
375 // [leer][\TABELLE\][leer]
376 //----------------------------------------
377 pEdEngine
->SetText(EMPTY_OUSTRING
);
378 pEdEngine
->QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD
), ESelection() );
379 pTxtObj
= pEdEngine
->CreateTextObject();
380 pHeaderItem
->SetLeftArea ( *pEmptyTxtObj
);
381 pHeaderItem
->SetCenterArea( *pTxtObj
);
382 pHeaderItem
->SetRightArea ( *pEmptyTxtObj
);
383 pSet
->Put( *pHeaderItem
);
386 //----------------------------------------
388 // [leer][Seite \SEITE\][leer]
389 //----------------------------------------
390 aStr
= SCSTR( STR_PAGE
) + " ";
391 pEdEngine
->SetText( aStr
);
392 nStrLen
= aStr
.getLength();
393 pEdEngine
->QuickInsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD
), ESelection(0,nStrLen
,0,nStrLen
) );
394 pTxtObj
= pEdEngine
->CreateTextObject();
395 pFooterItem
->SetLeftArea ( *pEmptyTxtObj
);
396 pFooterItem
->SetCenterArea( *pTxtObj
);
397 pFooterItem
->SetRightArea ( *pEmptyTxtObj
);
398 pSet
->Put( *pFooterItem
);
405 pSheet
= (ScStyleSheet
*) &Make( SCSTR( STR_STYLENAME_REPORT
),
406 SFX_STYLE_FAMILY_PAGE
,
407 SCSTYLEBIT_STANDARD
);
408 pSet
= &pSheet
->GetItemSet();
409 pSheet
->SetHelpId( aHelpFile
, HID_SC_SHEET_PAGE_REP
);
411 // Hintergrund und Umrandung
412 aBoxItem
.SetLine( &aBorderLine
, BOX_LINE_TOP
);
413 aBoxItem
.SetLine( &aBorderLine
, BOX_LINE_BOTTOM
);
414 aBoxItem
.SetLine( &aBorderLine
, BOX_LINE_LEFT
);
415 aBoxItem
.SetLine( &aBorderLine
, BOX_LINE_RIGHT
);
416 aBoxItem
.SetDistance( 10 ); // 0.2mm
417 aBoxInfoItem
.SetValid( VALID_TOP
, sal_True
);
418 aBoxInfoItem
.SetValid( VALID_BOTTOM
, sal_True
);
419 aBoxInfoItem
.SetValid( VALID_LEFT
, sal_True
);
420 aBoxInfoItem
.SetValid( VALID_RIGHT
, sal_True
);
421 aBoxInfoItem
.SetValid( VALID_DISTANCE
, sal_True
);
422 aBoxInfoItem
.SetTable( false );
423 aBoxInfoItem
.SetDist ( sal_True
);
425 pHFSetItem
= new SvxSetItem( ((SvxSetItem
&)pSet
->Get( ATTR_PAGE_HEADERSET
) ) );
426 pHFSet
= &(pHFSetItem
->GetItemSet());
428 pHFSet
->Put( SvxBrushItem( aColGrey
, ATTR_BACKGROUND
) );
429 pHFSet
->Put( aBoxItem
);
430 pHFSet
->Put( aBoxInfoItem
);
431 pSet
->Put( *pHFSetItem
, ATTR_PAGE_HEADERSET
);
432 pSet
->Put( *pHFSetItem
, ATTR_PAGE_FOOTERSET
);
433 DELETEZ( pHFSetItem
);
435 //----------------------------------------
437 // [\TABELLE\ (\DATEI\)][leer][\DATUM\, \ZEIT\]
438 //----------------------------------------
440 pEdEngine
->SetText( aStr
);
441 pEdEngine
->QuickInsertField( SvxFieldItem(SvxFileField(), EE_FEATURE_FIELD
), ESelection(0,2,0,2) );
442 pEdEngine
->QuickInsertField( SvxFieldItem(SvxTableField(), EE_FEATURE_FIELD
), ESelection() );
443 pTxtObj
= pEdEngine
->CreateTextObject();
444 pHeaderItem
->SetLeftArea( *pTxtObj
);
445 pHeaderItem
->SetCenterArea( *pEmptyTxtObj
);
448 pEdEngine
->SetText( aStr
);
449 pEdEngine
->QuickInsertField( SvxFieldItem(SvxTimeField(), EE_FEATURE_FIELD
), ESelection(0,2,0,2) );
450 pEdEngine
->QuickInsertField( SvxFieldItem(SvxDateField(Date( Date::SYSTEM
),SVXDATETYPE_VAR
), EE_FEATURE_FIELD
),
452 pTxtObj
= pEdEngine
->CreateTextObject();
453 pHeaderItem
->SetRightArea( *pTxtObj
);
455 pSet
->Put( *pHeaderItem
);
457 //----------------------------------------
459 // [leer][Seite: \SEITE\ / \SEITEN\][leer]
460 //----------------------------------------
461 aStr
= SCSTR( STR_PAGE
) + " ";
462 nStrLen
= aStr
.getLength();
464 sal_Int32 nStrLen2
= aStr
.getLength();
465 pEdEngine
->SetText( aStr
);
466 pEdEngine
->QuickInsertField( SvxFieldItem(SvxPagesField(), EE_FEATURE_FIELD
), ESelection(0,nStrLen2
,0,nStrLen2
) );
467 pEdEngine
->QuickInsertField( SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD
), ESelection(0,nStrLen
,0,nStrLen
) );
468 pTxtObj
= pEdEngine
->CreateTextObject();
469 pFooterItem
->SetLeftArea ( *pEmptyTxtObj
);
470 pFooterItem
->SetCenterArea( *pTxtObj
);
471 pFooterItem
->SetRightArea ( *pEmptyTxtObj
);
472 pSet
->Put( *pFooterItem
);
475 //----------------------------------------------------
476 DELETEZ( pEmptyTxtObj
);
477 DELETEZ( pHeaderItem
);
478 DELETEZ( pFooterItem
);
479 DELETEZ( pEdEngine
);
482 //------------------------------------------------------------------------
485 ScStyleSheet
* ScStyleSheetPool::FindCaseIns( const OUString
& rName
, SfxStyleFamily eFam
)
487 OUString aUpSearch
= ScGlobal::pCharClass
->uppercase(rName
);
489 sal_uInt32 nCount
= aStyles
.size();
490 for (sal_uInt32 n
=0; n
<nCount
; n
++)
492 SfxStyleSheetBase
* pStyle
= aStyles
[n
].get();
493 if ( pStyle
->GetFamily() == eFam
)
495 OUString aUpName
= ScGlobal::pCharClass
->uppercase(pStyle
->GetName());
496 if (aUpName
== aUpSearch
)
497 return (ScStyleSheet
*)pStyle
;
504 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */