bump product version to 6.4.0.3
[LibreOffice.git] / sd / source / core / stlpool.cxx
blob4562a27df9817ac68f735079e396d6babff95122
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <com/sun/star/lang/DisposedException.hpp>
21 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <editeng/eeitem.hxx>
24 #include <editeng/fhgtitem.hxx>
25 #include <editeng/colritem.hxx>
26 #include <editeng/contouritem.hxx>
27 #include <editeng/shdditem.hxx>
28 #include <editeng/crossedoutitem.hxx>
29 #include <editeng/udlnitem.hxx>
30 #include <editeng/wghtitem.hxx>
31 #include <editeng/postitem.hxx>
32 #include <editeng/fontitem.hxx>
33 #include <svx/xfillit0.hxx>
34 #include <svx/xlineit0.hxx>
35 #include <svx/sdtaitm.hxx>
36 #include <svx/sdtfsitm.hxx>
37 #include <svx/sdtagitm.hxx>
38 #include <svx/sdshitm.hxx>
39 #include <svx/sdshcitm.hxx>
40 #include <svx/sdsxyitm.hxx>
41 #include <editeng/ulspitem.hxx>
42 #include <editeng/numitem.hxx>
43 #include <editeng/cmapitem.hxx>
44 #include <svl/hint.hxx>
45 #include <editeng/charreliefitem.hxx>
46 #include <editeng/emphasismarkitem.hxx>
47 #include <svx/sdr/table/tabledesign.hxx>
48 #include <editeng/autokernitem.hxx>
50 #include <editeng/lrspitem.hxx>
51 #include <editeng/adjustitem.hxx>
52 #include <editeng/numdef.hxx>
53 #include <svl/itempool.hxx>
54 #include <svl/IndexedStyleSheets.hxx>
56 #include <stlpool.hxx>
57 #include <sdresid.hxx>
58 #include <stlsheet.hxx>
59 #include <strings.hrc>
60 #include <glob.hxx>
61 #include <drawdoc.hxx>
62 #include <svl/itemset.hxx>
63 #include <app.hrc>
64 #include <strings.hxx>
66 #include <com/sun/star/drawing/LineStyle.hpp>
67 #include <com/sun/star/drawing/TextFitToSizeType.hpp>
69 using namespace ::com::sun::star;
70 using namespace ::com::sun::star::uno;
71 using namespace ::com::sun::star::lang;
72 using namespace ::com::sun::star::style;
73 using namespace ::com::sun::star::container;
75 namespace
78 OUString lcl_findRenamedStyleName(std::vector< std::pair< OUString, OUString > > &rRenamedList, OUString const & aOriginalName )
80 auto aIter = std::find_if(rRenamedList.begin(), rRenamedList.end(),
81 [&aOriginalName](const std::pair<OUString, OUString>& rItem) { return rItem.first == aOriginalName; });
82 if (aIter != rRenamedList.end())
83 return (*aIter).second;
84 return OUString();
87 SfxStyleSheet *lcl_findStyle(StyleSheetCopyResultVector& rStyles, const OUString& aStyleName)
89 if( aStyleName.isEmpty() )
90 return nullptr;
91 for (const auto& a : rStyles)
93 if (a.m_xStyleSheet->GetName() == aStyleName)
94 return a.m_xStyleSheet.get();
96 return nullptr;
101 SdStyleSheetPool::SdStyleSheetPool(SfxItemPool const& _rPool, SdDrawDocument* pDocument)
102 : SdStyleSheetPoolBase( _rPool )
103 , mpActualStyleSheet(nullptr)
104 , mpDoc(pDocument)
106 if( !mpDoc )
107 return;
109 rtl::Reference< SfxStyleSheetPool > xPool( this );
111 // create graphics family
112 mxGraphicFamily = new SdStyleFamily( xPool, SfxStyleFamily::Para );
113 mxCellFamily = new SdStyleFamily( xPool, SfxStyleFamily::Frame );
115 mxTableFamily = sdr::table::CreateTableDesignFamily();
116 Reference< XNamed > xNamed( mxTableFamily, UNO_QUERY );
117 if( xNamed.is() )
118 msTableFamilyName = xNamed->getName();
120 // create presentation families, one for each master page
121 const sal_uInt16 nCount = mpDoc->GetMasterSdPageCount(PageKind::Standard);
122 for( sal_uInt16 nPage = 0; nPage < nCount; ++nPage )
123 AddStyleFamily( mpDoc->GetMasterSdPage(nPage,PageKind::Standard) );
126 SdStyleSheetPool::~SdStyleSheetPool()
128 DBG_ASSERT( mpDoc == nullptr, "sd::SdStyleSheetPool::~SdStyleSheetPool(), dispose me first!" );
131 SfxStyleSheetBase* SdStyleSheetPool::Create(const OUString& rName, SfxStyleFamily eFamily, SfxStyleSearchBits _nMask )
133 return new SdStyleSheet(rName, *this, eFamily, _nMask);
136 SfxStyleSheetBase* SdStyleSheetPool::GetTitleSheet(const OUString& rLayoutName)
138 OUString aName = rLayoutName + SD_LT_SEPARATOR STR_LAYOUT_TITLE;
139 SfxStyleSheetBase* pResult = Find(aName, SfxStyleFamily::Page);
140 return pResult;
143 /*************************************************************************
145 |* Create a list of outline text templates for a presentation layout.
146 |* The caller has to delete the list.
148 \************************************************************************/
150 void SdStyleSheetPool::CreateOutlineSheetList (const OUString& rLayoutName, std::vector<SfxStyleSheetBase*> &rOutlineStyles)
152 OUString aName = rLayoutName + SD_LT_SEPARATOR STR_LAYOUT_OUTLINE;
154 for (sal_Int32 nSheet = 1; nSheet < 10; nSheet++)
156 OUString aFullName(aName + " " + OUString::number( nSheet ) );
157 SfxStyleSheetBase* pSheet = Find(aFullName, SfxStyleFamily::Page);
159 if (pSheet)
160 rOutlineStyles.push_back(pSheet);
164 /*************************************************************************
166 |* Create style sheets with default values for the named presentation layout
168 \************************************************************************/
170 void SdStyleSheetPool::CreateLayoutStyleSheets(const OUString& rLayoutName, bool bCheck /*= sal_False*/ )
172 const SfxStyleSearchBits nUsedMask = SfxStyleSearchBits::All & ~SfxStyleSearchBits::UserDefined;
174 bool bCreated = false;
176 SfxStyleSheetBase* pSheet = nullptr;
178 OUString aPrefix(rLayoutName + SD_LT_SEPARATOR);
180 vcl::Font aLatinFont, aCJKFont, aCTLFont;
182 mpDoc->getDefaultFonts( aLatinFont, aCJKFont, aCTLFont );
184 // Font for title and outline
185 SvxFontItem aSvxFontItem( aLatinFont.GetFamilyType(), aLatinFont.GetFamilyName(), aLatinFont.GetStyleName(), aLatinFont.GetPitch(),
186 aLatinFont.GetCharSet(), EE_CHAR_FONTINFO );
188 SvxFontItem aSvxFontItemCJK( aCJKFont.GetFamilyType(), aCJKFont.GetFamilyName(), aCJKFont.GetStyleName(), aCJKFont.GetPitch(),
189 aCJKFont.GetCharSet(), EE_CHAR_FONTINFO_CJK );
191 SvxFontItem aSvxFontItemCTL( aCTLFont.GetFamilyType(), aCTLFont.GetFamilyName(), aCTLFont.GetStyleName(), aCTLFont.GetPitch(),
192 aCTLFont.GetCharSet(), EE_CHAR_FONTINFO_CTL );
194 vcl::Font aBulletFont( GetBulletFont() );
196 /**************************************************************************
197 * outline levels
198 **************************************************************************/
199 OUString aName(STR_LAYOUT_OUTLINE);
200 OUString aHelpFile;
202 SvxLRSpaceItem aSvxLRSpaceItem( EE_PARA_LRSPACE );
203 SvxULSpaceItem aSvxULSpaceItem( EE_PARA_ULSPACE );
205 for( sal_Int32 nLevel = 1; nLevel < 10; nLevel++)
207 OUString aLevelName( aPrefix + aName + " " + OUString::number( nLevel ) ) ;
209 if (!Find(aLevelName, SfxStyleFamily::Page))
211 bCreated = true;
212 pSheet = &Make(aLevelName, SfxStyleFamily::Page,nUsedMask);
213 pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_OUTLINE + nLevel );
215 pSheet->SetParent( OUString() );
217 // attributing for level 1, the others levels inherit
218 if (nLevel == 1)
220 SfxItemSet& rSet = pSheet->GetItemSet();
222 rSet.Put(aSvxFontItem);
223 rSet.Put(aSvxFontItemCJK);
224 rSet.Put(aSvxFontItemCTL);
225 rSet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC ) );
226 rSet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CJK ) );
227 rSet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CTL ) );
228 rSet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
229 rSet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ) );
230 rSet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ) );
231 rSet.Put( SvxUnderlineItem(LINESTYLE_NONE, EE_CHAR_UNDERLINE ) );
232 rSet.Put( SvxOverlineItem(LINESTYLE_NONE, EE_CHAR_OVERLINE ) );
233 rSet.Put( SvxCrossedOutItem(STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ) );
234 rSet.Put( SvxCaseMapItem(SvxCaseMap::NotMapped, EE_CHAR_CASEMAP ) );
235 rSet.Put( SvxShadowedItem(false, EE_CHAR_SHADOW ) );
236 rSet.Put( SvxContourItem(false, EE_CHAR_OUTLINE ) );
237 rSet.Put( SvxEmphasisMarkItem(FontEmphasisMark::NONE, EE_CHAR_EMPHASISMARK ) );
238 rSet.Put( SvxCharReliefItem(FontRelief::NONE, EE_CHAR_RELIEF) );
239 rSet.Put( SvxColorItem( COL_AUTO, EE_CHAR_COLOR) );
240 rSet.Put( SvxBackgroundColorItem( COL_AUTO, EE_CHAR_BKGCOLOR ) );
241 rSet.Put( XLineStyleItem(css::drawing::LineStyle_NONE) );
242 rSet.Put( XFillStyleItem(drawing::FillStyle_NONE) );
243 rSet.Put( SdrTextFitToSizeTypeItem(drawing::TextFitToSizeType_AUTOFIT) );
244 rSet.Put( makeSdrTextAutoGrowHeightItem(false) );
245 // #i16874# enable kerning by default but only for new documents
246 rSet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
248 vcl::Font f( GetBulletFont() );
249 PutNumBulletItem( pSheet, f );
252 sal_uLong nFontSize = 20;
253 sal_uInt16 nUpper = 100;
255 switch (nLevel)
257 case 1:
259 nFontSize = 32;
260 nUpper = 500;
262 break;
264 case 2:
266 nFontSize = 28;
267 nUpper = 400;
269 break;
271 case 3:
273 nFontSize = 24;
274 nUpper = 300;
276 break;
278 case 4:
280 nUpper = 200;
282 break;
285 // FontSize
286 nFontSize = static_cast<sal_uInt16>((nFontSize * 2540L) / 72); // Pt --> 1/100 mm
287 SfxItemSet& rOutlineSet = pSheet->GetItemSet();
288 rOutlineSet.Put( SvxFontHeightItem( nFontSize, 100, EE_CHAR_FONTHEIGHT ) );
289 rOutlineSet.Put( SvxFontHeightItem( nFontSize, 100, EE_CHAR_FONTHEIGHT_CJK ) );
290 rOutlineSet.Put( SvxFontHeightItem( SdDrawDocument::convertFontHeightToCTL( nFontSize ), 100, EE_CHAR_FONTHEIGHT_CTL ) );
292 // Line distance (upwards). Stuff around here cleaned up in i35937
293 aSvxULSpaceItem.SetUpper(nUpper);
294 pSheet->GetItemSet().Put(aSvxULSpaceItem);
298 // if we created outline styles, we need to chain them
299 if( bCreated )
301 SfxStyleSheetBase* pParent = nullptr;
302 for (sal_Int32 nLevel = 1; nLevel < 10; nLevel++)
304 OUString aLevelName( aPrefix + aName + " " + OUString::number( nLevel ) );
306 pSheet = Find(aLevelName, SfxStyleFamily::Page);
308 DBG_ASSERT( pSheet, "missing layout style!");
310 if( pSheet )
312 if (pParent)
313 pSheet->SetParent(pParent->GetName());
314 pParent = pSheet;
319 /**************************************************************************
320 * Title
321 **************************************************************************/
322 aName = aPrefix + STR_LAYOUT_TITLE;
324 if (!Find(aName, SfxStyleFamily::Page))
326 bCreated = true;
328 pSheet = &Make(aName, SfxStyleFamily::Page,nUsedMask);
329 pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_TITLE );
330 pSheet->SetParent( OUString() );
331 SfxItemSet& rTitleSet = pSheet->GetItemSet();
332 rTitleSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
333 rTitleSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
334 rTitleSet.Put(aSvxFontItem);
335 rTitleSet.Put(aSvxFontItemCJK);
336 rTitleSet.Put(aSvxFontItemCTL);
337 rTitleSet.Put(SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC ) );
338 rTitleSet.Put(SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CJK ) );
339 rTitleSet.Put(SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CTL ) );
340 rTitleSet.Put(SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
341 rTitleSet.Put(SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ) );
342 rTitleSet.Put(SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ) );
343 rTitleSet.Put(SvxFontHeightItem( 1552, 100, EE_CHAR_FONTHEIGHT ) ); // 44 pt
344 rTitleSet.Put(SvxFontHeightItem( 1552, 100, EE_CHAR_FONTHEIGHT_CJK ) ); // 44 pt
345 rTitleSet.Put(SvxFontHeightItem( SdDrawDocument::convertFontHeightToCTL( 1552 ), 100, EE_CHAR_FONTHEIGHT_CTL ) ); // 44 pt
346 rTitleSet.Put(SvxUnderlineItem(LINESTYLE_NONE, EE_CHAR_UNDERLINE ));
347 rTitleSet.Put(SvxOverlineItem(LINESTYLE_NONE, EE_CHAR_OVERLINE ));
348 rTitleSet.Put(SvxCrossedOutItem(STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ));
349 rTitleSet.Put(SvxCaseMapItem(SvxCaseMap::NotMapped, EE_CHAR_CASEMAP ));
350 rTitleSet.Put(SvxShadowedItem(false, EE_CHAR_SHADOW ));
351 rTitleSet.Put(SvxContourItem(false, EE_CHAR_OUTLINE ));
352 rTitleSet.Put( SvxEmphasisMarkItem(FontEmphasisMark::NONE, EE_CHAR_EMPHASISMARK ) );
353 rTitleSet.Put( SvxCharReliefItem(FontRelief::NONE, EE_CHAR_RELIEF ) );
354 rTitleSet.Put(SvxColorItem( COL_AUTO, EE_CHAR_COLOR ));
355 rTitleSet.Put(SvxBackgroundColorItem( COL_AUTO, EE_CHAR_BKGCOLOR ));
356 rTitleSet.Put(SvxAdjustItem(SvxAdjust::Center, EE_PARA_JUST ));
357 rTitleSet.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
358 // #i16874# enable kerning by default but only for new documents
359 rTitleSet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
361 aBulletFont.SetFontSize(Size(0,1552)); // 44 pt
362 PutNumBulletItem( pSheet, aBulletFont );
365 /**************************************************************************
366 * Subtitle
367 **************************************************************************/
368 aName = aPrefix + STR_LAYOUT_SUBTITLE;
370 if (!Find(aName, SfxStyleFamily::Page))
372 bCreated = true;
374 pSheet = &Make(aName, SfxStyleFamily::Page,nUsedMask);
375 pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_SUBTITLE );
376 pSheet->SetParent( OUString() );
377 SfxItemSet& rSubtitleSet = pSheet->GetItemSet();
378 rSubtitleSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
379 rSubtitleSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
380 rSubtitleSet.Put(aSvxFontItem);
381 rSubtitleSet.Put(aSvxFontItemCJK);
382 rSubtitleSet.Put(aSvxFontItemCTL);
383 rSubtitleSet.Put(SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC ) );
384 rSubtitleSet.Put(SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CJK ) );
385 rSubtitleSet.Put(SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CTL ) );
386 rSubtitleSet.Put(SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
387 rSubtitleSet.Put(SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ) );
388 rSubtitleSet.Put(SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ) );
389 rSubtitleSet.Put( SvxFontHeightItem( 1129, 100, EE_CHAR_FONTHEIGHT ) ); // 32 pt
390 rSubtitleSet.Put( SvxFontHeightItem( 1129, 100, EE_CHAR_FONTHEIGHT_CJK ) ); // 32 pt
391 rSubtitleSet.Put( SvxFontHeightItem( SdDrawDocument::convertFontHeightToCTL( 1129 ), 100, EE_CHAR_FONTHEIGHT_CTL ) ); // 32 pt
392 rSubtitleSet.Put(SvxUnderlineItem(LINESTYLE_NONE, EE_CHAR_UNDERLINE ));
393 rSubtitleSet.Put(SvxOverlineItem(LINESTYLE_NONE, EE_CHAR_OVERLINE ));
394 rSubtitleSet.Put(SvxCrossedOutItem(STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ));
395 rSubtitleSet.Put(SvxCaseMapItem(SvxCaseMap::NotMapped, EE_CHAR_CASEMAP ));
396 rSubtitleSet.Put(SvxShadowedItem(false, EE_CHAR_SHADOW ));
397 rSubtitleSet.Put(SvxContourItem(false, EE_CHAR_OUTLINE ));
398 rSubtitleSet.Put( SvxEmphasisMarkItem(FontEmphasisMark::NONE, EE_CHAR_EMPHASISMARK ) );
399 rSubtitleSet.Put( SvxCharReliefItem(FontRelief::NONE, EE_CHAR_RELIEF ) );
400 rSubtitleSet.Put(SvxColorItem( COL_AUTO, EE_CHAR_COLOR ));
401 rSubtitleSet.Put(SvxBackgroundColorItem( COL_AUTO, EE_CHAR_BKGCOLOR ));
402 rSubtitleSet.Put(SvxAdjustItem(SvxAdjust::Center, EE_PARA_JUST ));
403 rSubtitleSet.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
404 // #i16874# enable kerning by default but only for new documents
405 rSubtitleSet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
406 aSvxLRSpaceItem.SetTextLeft(0);
407 rSubtitleSet.Put(aSvxLRSpaceItem);
409 vcl::Font aTmpFont( GetBulletFont() );
410 aTmpFont.SetFontSize(Size(0, 1129)); // 32 pt
411 PutNumBulletItem( pSheet, aTmpFont );
414 /**************************************************************************
415 * Notes
416 **************************************************************************/
417 aName = aPrefix + STR_LAYOUT_NOTES;
419 if (!Find(aName, SfxStyleFamily::Page))
421 bCreated = true;
423 pSheet = &Make(aName, SfxStyleFamily::Page,nUsedMask);
424 pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_NOTES );
425 pSheet->SetParent( OUString() );
426 SfxItemSet& rNotesSet = pSheet->GetItemSet();
427 rNotesSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
428 rNotesSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
429 rNotesSet.Put(aSvxFontItem);
430 rNotesSet.Put(aSvxFontItemCJK);
431 rNotesSet.Put(aSvxFontItemCTL);
432 rNotesSet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC ) );
433 rNotesSet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CJK ) );
434 rNotesSet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CTL ) );
435 rNotesSet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
436 rNotesSet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ) );
437 rNotesSet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ) );
438 rNotesSet.Put( SvxFontHeightItem( 705, 100, EE_CHAR_FONTHEIGHT ) ); // 20 pt
439 rNotesSet.Put( SvxFontHeightItem( 705, 100, EE_CHAR_FONTHEIGHT_CJK ) ); // 20 pt
440 rNotesSet.Put( SvxFontHeightItem( SdDrawDocument::convertFontHeightToCTL( 705 ), 100, EE_CHAR_FONTHEIGHT_CTL ) ); // 20 pt
441 rNotesSet.Put( SvxUnderlineItem(LINESTYLE_NONE, EE_CHAR_UNDERLINE ) );
442 rNotesSet.Put( SvxOverlineItem(LINESTYLE_NONE, EE_CHAR_OVERLINE ) );
443 rNotesSet.Put( SvxCrossedOutItem(STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ) );
444 rNotesSet.Put( SvxCaseMapItem(SvxCaseMap::NotMapped, EE_CHAR_CASEMAP ) );
445 rNotesSet.Put( SvxShadowedItem(false, EE_CHAR_SHADOW ) );
446 rNotesSet.Put( SvxContourItem(false, EE_CHAR_OUTLINE ) );
447 rNotesSet.Put( SvxEmphasisMarkItem(FontEmphasisMark::NONE, EE_CHAR_EMPHASISMARK ) );
448 rNotesSet.Put( SvxCharReliefItem(FontRelief::NONE, EE_CHAR_RELIEF) );
449 rNotesSet.Put( SvxColorItem( COL_AUTO, EE_CHAR_COLOR ) );
450 rNotesSet.Put( SvxBackgroundColorItem( COL_AUTO, EE_CHAR_BKGCOLOR ) );
451 rNotesSet.Put( SvxLRSpaceItem( 0, 0, 600, -600, EE_PARA_LRSPACE ) );
452 // #i16874# enable kerning by default but only for new documents
453 rNotesSet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
455 /* #i35937# */
459 /**************************************************************************
460 * Background objects
461 **************************************************************************/
462 aName = aPrefix + STR_LAYOUT_BACKGROUNDOBJECTS;
464 if (!Find(aName, SfxStyleFamily::Page))
466 bCreated = true;
468 pSheet = &Make(aName, SfxStyleFamily::Page,nUsedMask);
469 pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_BACKGROUNDOBJECTS );
470 pSheet->SetParent( OUString() );
471 SfxItemSet& rBackgroundObjectsSet = pSheet->GetItemSet();
472 rBackgroundObjectsSet.Put(makeSdrShadowItem(false));
473 rBackgroundObjectsSet.Put(makeSdrShadowColorItem(COL_GRAY));
474 rBackgroundObjectsSet.Put(makeSdrShadowXDistItem(200)); // 3 mm shadow distance
475 rBackgroundObjectsSet.Put(makeSdrShadowYDistItem(200));
476 // #i16874# enable kerning by default but only for new documents
477 rBackgroundObjectsSet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
478 rBackgroundObjectsSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_BLOCK));
481 /**************************************************************************
482 * Background
483 **************************************************************************/
484 aName = aPrefix + STR_LAYOUT_BACKGROUND;
486 if (!Find(aName, SfxStyleFamily::Page))
488 bCreated = true;
490 pSheet = &Make(aName, SfxStyleFamily::Page,nUsedMask);
491 pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_BACKGROUND );
492 pSheet->SetParent( OUString() );
493 SfxItemSet& rBackgroundSet = pSheet->GetItemSet();
494 rBackgroundSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
495 rBackgroundSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
496 // #i16874# enable kerning by default but only for new documents
497 rBackgroundSet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
500 DBG_ASSERT( !bCheck || !bCreated, "missing layout style sheets detected!" );
503 /*************************************************************************
505 |* Copy graphic style sheets from source pool into this pool
507 |* (rSourcePool can not be const since SfxStyleSheetPoolBase::Find isn't const)
509 \************************************************************************/
511 void SdStyleSheetPool::CopyGraphicSheets(SdStyleSheetPool& rSourcePool)
513 CopySheets( rSourcePool, SfxStyleFamily::Para );
516 void SdStyleSheetPool::CopyCellSheets(SdStyleSheetPool& rSourcePool)
518 CopySheets( rSourcePool, SfxStyleFamily::Frame );
521 void SdStyleSheetPool::CopyTableStyles(SdStyleSheetPool const & rSourcePool)
523 Reference< XIndexAccess > xSource( rSourcePool.mxTableFamily, UNO_QUERY );
524 Reference< XNameContainer > xTarget( mxTableFamily, UNO_QUERY );
525 Reference< XSingleServiceFactory > xFactory( mxTableFamily, UNO_QUERY );
527 if( !(xSource.is() && xFactory.is() && mxTableFamily.is()) )
528 return;
530 for( sal_Int32 nIndex = 0; nIndex < xSource->getCount(); nIndex++ ) try
532 Reference< XStyle > xSourceTableStyle( xSource->getByIndex( nIndex ), UNO_QUERY );
533 if( xSourceTableStyle.is() )
535 Reference< XStyle > xNewTableStyle( xFactory->createInstance(), UNO_QUERY );
536 if( xNewTableStyle.is() )
538 Reference< XNameAccess> xSourceNames( xSourceTableStyle, UNO_QUERY_THROW );
540 const Sequence< OUString > aStyleNames( xSourceNames->getElementNames() );
542 Reference< XNameReplace > xTargetNames( xNewTableStyle, UNO_QUERY );
544 for( const OUString& aName : aStyleNames )
546 Reference< XStyle > xSourceStyle( xSourceNames->getByName( aName ), UNO_QUERY );
547 Reference< XStyle > xTargetStyle;
548 if( xSourceStyle.is() ) try
550 mxCellFamily->getByName( xSourceStyle->getName() ) >>= xTargetStyle;
552 catch( Exception& )
554 OSL_FAIL( "sd::SdStyleSheetPool::CopyTableStyles(), exception caught!" );
557 if( xTargetStyle.is() )
558 xTargetNames->replaceByName( aName, Any( xTargetStyle ) );
562 OUString sName( xSourceTableStyle->getName() );
563 if( xTarget->hasByName( sName ) )
564 xTarget->replaceByName( sName, Any( xNewTableStyle ) );
565 else
566 xTarget->insertByName( sName, Any( xNewTableStyle ) );
569 catch( Exception& )
571 OSL_FAIL("sd::SdStyleSheetPool::CopyTableStyles(), exception caught!");
575 void SdStyleSheetPool::CopyCellSheets(SdStyleSheetPool& rSourcePool, StyleSheetCopyResultVector& rCreatedSheets)
577 CopySheets( rSourcePool, SfxStyleFamily::Frame, rCreatedSheets );
580 void SdStyleSheetPool::RenameAndCopyGraphicSheets(SdStyleSheetPool& rSourcePool, StyleSheetCopyResultVector& rCreatedSheets, OUString const &rRenameSuffix)
582 CopySheets( rSourcePool, SfxStyleFamily::Para, rCreatedSheets, rRenameSuffix );
585 void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily )
587 StyleSheetCopyResultVector aTmpSheets;
588 CopySheets(rSourcePool, eFamily, aTmpSheets);
591 void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, StyleSheetCopyResultVector& rCreatedSheets)
593 CopySheets(rSourcePool, eFamily, rCreatedSheets, "");
596 namespace
599 struct HasFamilyPredicate : svl::StyleSheetPredicate
601 explicit HasFamilyPredicate(SfxStyleFamily eFamily)
602 : meFamily(eFamily) {}
604 bool Check(const SfxStyleSheetBase& sheet) override
606 return sheet.GetFamily() == meFamily;
608 SfxStyleFamily const meFamily;
613 void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, StyleSheetCopyResultVector& rCreatedSheets, const OUString& rRenameSuffix)
615 std::vector< std::pair< rtl::Reference< SfxStyleSheetBase >, OUString > > aNewStyles;
616 std::vector< std::pair< OUString, OUString > > aRenamedList;
618 // find all style sheets of the source pool which have the same family
619 HasFamilyPredicate aHasFamilyPredicate(eFamily);
620 std::vector<unsigned> aSheetsWithFamily = rSourcePool.GetIndexedStyleSheets().FindPositionsByPredicate(aHasFamilyPredicate);
622 for (const auto& rPos : aSheetsWithFamily)
624 SfxStyleSheetBase* pSheet = rSourcePool.GetStyleSheetByPositionInIndex( rPos );
625 if( !pSheet )
626 continue;
627 OUString aName( pSheet->GetName() );
629 // now check whether we already have a sheet with the same name
630 std::vector<unsigned> aSheetsWithName = GetIndexedStyleSheets().FindPositionsByName(aName);
631 bool bAddToList = false;
632 SfxStyleSheetBase * pExistingSheet = nullptr;
633 if (!aSheetsWithName.empty())
635 // if we have a rename suffix, try to find a new name
636 pExistingSheet =
637 GetStyleSheetByPositionInIndex(aSheetsWithName.front());
638 if (!rRenameSuffix.isEmpty() &&
639 !pExistingSheet->GetItemSet().Equals(pSheet->GetItemSet(), false))
641 // we have found a sheet with the same name, but different contents. Try to find a new name.
642 // If we already have a sheet with the new name, and it is equal to the one in the source pool,
643 // do nothing.
644 OUString aTmpName = aName + rRenameSuffix;
645 sal_Int32 nSuffix = 1;
648 aTmpName = aName + rRenameSuffix + OUString::number(nSuffix);
649 pExistingSheet = Find(aTmpName, eFamily);
650 nSuffix++;
651 } while (pExistingSheet &&
652 !pExistingSheet->GetItemSet().Equals(pSheet->GetItemSet(), false));
653 aName = aTmpName;
654 bAddToList = true;
657 // we do not already have a sheet with the same name and contents. Create a new one.
658 if (!pExistingSheet)
660 assert(!Find(aName, eFamily));
661 rtl::Reference< SfxStyleSheetBase > xNewSheet( &Make( aName, eFamily ) );
663 xNewSheet->SetMask( pSheet->GetMask() );
665 // Also set parent relation for copied style sheets
666 OUString aParent( pSheet->GetParent() );
667 if( !aParent.isEmpty() )
668 aNewStyles.emplace_back( xNewSheet, aParent );
670 if( !bAddToList )
672 OUString aHelpFile;
673 xNewSheet->SetHelpId( aHelpFile, pSheet->GetHelpId( aHelpFile ) );
675 xNewSheet->GetItemSet().Put( pSheet->GetItemSet() );
677 rCreatedSheets.emplace_back(static_cast<SdStyleSheet*>(xNewSheet.get()), true);
678 aRenamedList.emplace_back( pSheet->GetName(), aName );
680 else if (bAddToList)
682 // Add to list - used for renaming
683 rCreatedSheets.emplace_back(static_cast<SdStyleSheet*>(pExistingSheet), false);
684 aRenamedList.emplace_back( pSheet->GetName(), aName );
688 // set parents on newly added stylesheets
689 for( auto& rStyle : aNewStyles )
691 if( !rRenameSuffix.isEmpty() )
693 SfxStyleSheet *pParent = lcl_findStyle(rCreatedSheets, lcl_findRenamedStyleName(aRenamedList, rStyle.second));
694 if( pParent )
696 rStyle.first->SetParent( pParent->GetName() );
697 continue;
700 DBG_ASSERT( rSourcePool.Find( rStyle.second, eFamily ), "StyleSheet has invalid parent: Family mismatch" );
701 rStyle.first->SetParent( rStyle.second );
703 // we have changed names of style sheets. Trigger reindexing.
704 Reindex();
707 /*************************************************************************
709 |* Copy style sheets of the named presentation layout from the source pool into
710 |* this pool. Copies only the style sheets which aren't yet in this pool.
711 |* If not NULL, pCreatedSheets is filled with pointers to the created style
712 |* sheets.
714 |* (rSourcePool can not be const since SfxStyleSheetPoolBase::Find isn't const)
716 \************************************************************************/
718 void SdStyleSheetPool::CopyLayoutSheets(const OUString& rLayoutName, SdStyleSheetPool& rSourcePool, StyleSheetCopyResultVector& rCreatedSheets)
720 SfxStyleSheetBase* pSheet = nullptr;
722 std::vector<OUString> aNameList;
723 CreateLayoutSheetNames(rLayoutName,aNameList);
725 for (const auto& rName : aNameList)
727 pSheet = Find(rName, SfxStyleFamily::Page);
728 if (!pSheet)
730 SfxStyleSheetBase* pSourceSheet = rSourcePool.Find(rName, SfxStyleFamily::Page);
731 DBG_ASSERT(pSourceSheet, "CopyLayoutSheets: Style sheet missing");
732 if (pSourceSheet)
734 // In the case one comes with Methusalem-Docs.
735 SfxStyleSheetBase& rNewSheet = Make(rName, SfxStyleFamily::Page);
736 OUString file;
737 rNewSheet.SetHelpId( file, pSourceSheet->GetHelpId( file ) );
738 rNewSheet.GetItemSet().Put(pSourceSheet->GetItemSet());
739 rCreatedSheets.emplace_back(static_cast<SdStyleSheet*>(&rNewSheet), true);
744 // Special treatment for outline templates: create parent relation
745 std::vector<SfxStyleSheetBase*> aOutlineSheets;
746 CreateOutlineSheetList(rLayoutName,aOutlineSheets);
748 if( aOutlineSheets.empty() )
749 return;
751 std::vector<SfxStyleSheetBase*>::iterator it = aOutlineSheets.begin();
752 SfxStyleSheetBase* pParent = *it;
753 ++it;
755 while (it != aOutlineSheets.end())
757 pSheet = *it;
759 if (!pSheet)
760 break;
762 if (pSheet->GetParent().isEmpty())
763 pSheet->SetParent(pParent->GetName());
765 pParent = pSheet;
767 ++it;
771 /*************************************************************************
773 |* Create list with names of the presentation templates of a layout.
774 |* The list and the containing strings are owned by the caller!
776 \************************************************************************/
778 void SdStyleSheetPool::CreateLayoutSheetNames(const OUString& rLayoutName, std::vector<OUString> &aNameList)
780 OUString aPrefix(rLayoutName + SD_LT_SEPARATOR);
782 for (sal_Int32 nLevel = 1; nLevel < 10; nLevel++)
783 aNameList.emplace_back(aPrefix + STR_LAYOUT_OUTLINE " " + OUString::number( nLevel ) );
785 aNameList.emplace_back(aPrefix + STR_LAYOUT_TITLE);
786 aNameList.emplace_back(aPrefix + STR_LAYOUT_SUBTITLE);
787 aNameList.emplace_back(aPrefix + STR_LAYOUT_NOTES);
788 aNameList.emplace_back(aPrefix + STR_LAYOUT_BACKGROUNDOBJECTS);
789 aNameList.emplace_back(aPrefix + STR_LAYOUT_BACKGROUND);
792 /*************************************************************************
794 |* Create a list with pointer to presentation templates of a layout.
795 |* The list is owned by the caller!
797 \************************************************************************/
799 void SdStyleSheetPool::CreateLayoutSheetList(const OUString& rLayoutName, SdStyleSheetVector& rLayoutSheets )
801 OUString aLayoutNameWithSep(rLayoutName + SD_LT_SEPARATOR);
803 SfxStyleSheetIterator aIter(this, SfxStyleFamily::Page);
804 SfxStyleSheetBase* pSheet = aIter.First();
806 while (pSheet)
808 if (pSheet->GetName().startsWith(aLayoutNameWithSep))
809 rLayoutSheets.emplace_back( static_cast< SdStyleSheet* >( pSheet ) );
810 pSheet = aIter.Next();
814 /*************************************************************************
816 |* Create pseudo style sheets if necessary
818 \************************************************************************/
820 void SdStyleSheetPool::CreatePseudosIfNecessary()
822 OUString aName;
823 OUString aHelpFile;
824 SfxStyleSheetBase* pSheet = nullptr;
825 SfxStyleSheetBase* pParent = nullptr;
827 SfxStyleSearchBits nUsedMask = SfxStyleSearchBits::Used;
829 aName = SdResId(STR_PSEUDOSHEET_TITLE);
830 if( (pSheet = Find(aName, SfxStyleFamily::Pseudo)) == nullptr )
832 pSheet = &Make(aName, SfxStyleFamily::Pseudo, nUsedMask);
833 pSheet->SetParent( OUString() );
834 static_cast<SfxStyleSheet*>(pSheet)->StartListening(*this);
836 pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_TITLE );
838 aName = SdResId(STR_PSEUDOSHEET_SUBTITLE);
839 if( (pSheet = Find(aName, SfxStyleFamily::Pseudo)) == nullptr )
841 pSheet = &Make(aName, SfxStyleFamily::Pseudo, nUsedMask);
842 pSheet->SetParent( OUString() );
843 static_cast<SfxStyleSheet*>(pSheet)->StartListening(*this);
845 pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_SUBTITLE );
847 aName = SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS);
848 if( (pSheet = Find(aName, SfxStyleFamily::Pseudo)) == nullptr )
850 pSheet = &Make(aName, SfxStyleFamily::Pseudo, nUsedMask);
851 pSheet->SetParent( OUString() );
852 static_cast<SfxStyleSheet*>(pSheet)->StartListening(*this);
854 pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_BACKGROUNDOBJECTS );
856 aName = SdResId(STR_PSEUDOSHEET_BACKGROUND);
857 if( (pSheet = Find(aName, SfxStyleFamily::Pseudo)) == nullptr )
859 pSheet = &Make(aName, SfxStyleFamily::Pseudo, nUsedMask);
860 pSheet->SetParent( OUString() );
861 static_cast<SfxStyleSheet*>(pSheet)->StartListening(*this);
863 pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_BACKGROUND );
865 aName = SdResId(STR_PSEUDOSHEET_NOTES);
866 if( (pSheet = Find(aName, SfxStyleFamily::Pseudo)) == nullptr )
868 pSheet = &Make(aName, SfxStyleFamily::Pseudo, nUsedMask);
869 pSheet->SetParent( OUString() );
870 static_cast<SfxStyleSheet*>(pSheet)->StartListening(*this);
872 pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_NOTES );
874 pParent = nullptr;
875 SetSearchMask(SfxStyleFamily::Pseudo);
876 aName = SdResId(STR_PSEUDOSHEET_OUTLINE);
877 for (sal_Int32 nLevel = 1; nLevel < 10; nLevel++)
879 OUString aLevelName( aName + " " + OUString::number( nLevel ) );
881 if( (pSheet = Find(aLevelName, SfxStyleFamily::Pseudo)) == nullptr )
883 pSheet = &Make(aLevelName, SfxStyleFamily::Pseudo, nUsedMask);
885 if (pParent)
886 pSheet->SetParent(pParent->GetName());
887 pParent = pSheet;
888 static_cast<SfxStyleSheet*>(pSheet)->StartListening(*this);
890 pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_OUTLINE + nLevel );
894 /*************************************************************************
896 |* Set the correct name in the program language to the standard styles
898 \************************************************************************/
900 namespace
902 struct StyleSheetIsUserDefinedPredicate : svl::StyleSheetPredicate
904 StyleSheetIsUserDefinedPredicate()
907 bool Check(const SfxStyleSheetBase& sheet) override
909 return sheet.IsUserDefined();
914 void SdStyleSheetPool::UpdateStdNames()
916 OUString aHelpFile;
917 StyleSheetIsUserDefinedPredicate aPredicate;
918 std::vector<SfxStyleSheetBase*> aEraseList;
919 std::vector<unsigned> aUserDefinedStyles = GetIndexedStyleSheets().FindPositionsByPredicate(aPredicate);
920 for (const auto& rStyle : aUserDefinedStyles)
922 SfxStyleSheetBase* pStyle = GetStyleSheetByPositionInIndex(rStyle);
924 if( !pStyle->IsUserDefined() )
926 OUString aOldName = pStyle->GetName();
927 sal_uLong nHelpId = pStyle->GetHelpId( aHelpFile );
928 SfxStyleFamily eFam = pStyle->GetFamily();
930 bool bHelpKnown = true;
931 OUString aNewName;
932 const char* pNameId = nullptr;
933 switch( nHelpId )
935 case HID_STANDARD_STYLESHEET_NAME: pNameId = STR_STANDARD_STYLESHEET_NAME; break;
936 case HID_POOLSHEET_OBJWITHOUTFILL: pNameId = STR_POOLSHEET_OBJWITHOUTFILL; break;
937 case HID_POOLSHEET_OBJNOLINENOFILL: pNameId = STR_POOLSHEET_OBJNOLINENOFILL;break;
938 case HID_POOLSHEET_TEXT: pNameId = STR_POOLSHEET_TEXT; break;
939 case HID_POOLSHEET_A4: pNameId = STR_POOLSHEET_A4; break;
940 case HID_POOLSHEET_A4_TITLE: pNameId = STR_POOLSHEET_A4_TITLE; break;
941 case HID_POOLSHEET_A4_HEADLINE: pNameId = STR_POOLSHEET_A4_HEADLINE; break;
942 case HID_POOLSHEET_A4_TEXT: pNameId = STR_POOLSHEET_A4_TEXT; break;
943 case HID_POOLSHEET_A0: pNameId = STR_POOLSHEET_A0; break;
944 case HID_POOLSHEET_A0_TITLE: pNameId = STR_POOLSHEET_A0_TITLE; break;
945 case HID_POOLSHEET_A0_HEADLINE: pNameId = STR_POOLSHEET_A0_HEADLINE; break;
946 case HID_POOLSHEET_A0_TEXT: pNameId = STR_POOLSHEET_A0_TEXT; break;
947 case HID_POOLSHEET_GRAPHIC: pNameId = STR_POOLSHEET_GRAPHIC; break;
948 case HID_POOLSHEET_SHAPES: pNameId = STR_POOLSHEET_SHAPES; break;
949 case HID_POOLSHEET_FILLED: pNameId = STR_POOLSHEET_FILLED; break;
950 case HID_POOLSHEET_FILLED_BLUE: pNameId = STR_POOLSHEET_FILLED_BLUE; break;
951 case HID_POOLSHEET_FILLED_GREEN: pNameId = STR_POOLSHEET_FILLED_GREEN; break;
952 case HID_POOLSHEET_FILLED_RED: pNameId = STR_POOLSHEET_FILLED_RED; break;
953 case HID_POOLSHEET_FILLED_YELLOW: pNameId = STR_POOLSHEET_FILLED_YELLOW; break;
954 case HID_POOLSHEET_OUTLINE: pNameId = STR_POOLSHEET_OUTLINE; break;
955 case HID_POOLSHEET_OUTLINE_BLUE: pNameId = STR_POOLSHEET_OUTLINE_BLUE; break;
956 case HID_POOLSHEET_OUTLINE_GREEN: pNameId = STR_POOLSHEET_OUTLINE_GREEN; break;
957 case HID_POOLSHEET_OUTLINE_RED: pNameId = STR_POOLSHEET_OUTLINE_RED; break;
958 case HID_POOLSHEET_OUTLINE_YELLOW: pNameId = STR_POOLSHEET_OUTLINE_YELLOW; break;
959 case HID_POOLSHEET_LINES: pNameId = STR_POOLSHEET_LINES; break;
960 case HID_POOLSHEET_MEASURE: pNameId = STR_POOLSHEET_MEASURE; break;
961 case HID_POOLSHEET_LINES_DASHED: pNameId = STR_POOLSHEET_LINES_DASHED; break;
963 case HID_PSEUDOSHEET_OUTLINE1:
964 case HID_PSEUDOSHEET_OUTLINE2:
965 case HID_PSEUDOSHEET_OUTLINE3:
966 case HID_PSEUDOSHEET_OUTLINE4:
967 case HID_PSEUDOSHEET_OUTLINE5:
968 case HID_PSEUDOSHEET_OUTLINE6:
969 case HID_PSEUDOSHEET_OUTLINE7:
970 case HID_PSEUDOSHEET_OUTLINE8:
971 case HID_PSEUDOSHEET_OUTLINE9: pNameId = STR_PSEUDOSHEET_OUTLINE; break;
972 case HID_PSEUDOSHEET_BACKGROUNDOBJECTS: pNameId = STR_PSEUDOSHEET_BACKGROUNDOBJECTS; break;
973 case HID_PSEUDOSHEET_BACKGROUND: pNameId = STR_PSEUDOSHEET_BACKGROUND; break;
974 case HID_PSEUDOSHEET_NOTES: pNameId = STR_PSEUDOSHEET_NOTES; break;
976 case HID_SD_CELL_STYLE_DEFAULT: pNameId = STR_STANDARD_STYLESHEET_NAME; break;
977 case HID_SD_CELL_STYLE_BANDED: pNameId = STR_POOLSHEET_BANDED_CELL; break;
978 case HID_SD_CELL_STYLE_HEADER: pNameId = STR_POOLSHEET_HEADER; break;
979 case HID_SD_CELL_STYLE_TOTAL: pNameId = STR_POOLSHEET_TOTAL; break;
980 case HID_SD_CELL_STYLE_FIRST_COLUMN: pNameId = STR_POOLSHEET_FIRST_COLUMN; break;
981 case HID_SD_CELL_STYLE_LAST_COLUMN: pNameId = STR_POOLSHEET_LAST_COLUMN; break;
983 default:
984 // 0 or wrong (old) HelpId
985 bHelpKnown = false;
987 if( bHelpKnown )
989 if (pNameId)
991 aNewName = SdResId(pNameId);
992 if (strcmp(pNameId, STR_PSEUDOSHEET_OUTLINE) == 0)
994 aNewName += " " + OUString::number( sal_Int32( nHelpId - HID_PSEUDOSHEET_OUTLINE ) );
998 if( !aNewName.isEmpty() && aNewName != aOldName )
1000 SfxStyleSheetBase* pSheetFound = Find( aNewName, eFam );
1002 if ( !pSheetFound )
1004 // Sheet does not yet exist: rename old sheet
1005 pStyle->SetName( aNewName ); // transform also parents
1007 else
1009 // Sheet does exist: old sheet has to be removed
1010 aEraseList.push_back( pStyle );
1017 if (!aEraseList.empty())
1019 // styles that could not be renamed, must be removed
1020 for (SfxStyleSheetBase* p : aEraseList)
1021 Remove( p );
1022 Reindex();
1026 void SdStyleSheetPool::setDefaultOutlineNumberFormatBulletAndIndent(sal_uInt16 i, SvxNumberFormat &rNumberFormat)
1028 rNumberFormat.SetBulletChar( 0x25CF ); // StarBats: 0xF000 + 34
1029 rNumberFormat.SetBulletRelSize(45);
1030 const auto nLSpace = (i + 1) * 1200;
1031 rNumberFormat.SetAbsLSpace(nLSpace);
1032 sal_Int32 nFirstLineOffset = -600;
1034 switch(i)
1036 case 0:
1038 nFirstLineOffset = -900;
1040 break;
1042 case 1:
1044 rNumberFormat.SetBulletChar( 0x2013 ); // StarBats: 0xF000 + 150
1045 rNumberFormat.SetBulletRelSize(75);
1046 nFirstLineOffset = -900;
1048 break;
1050 case 2:
1052 nFirstLineOffset = -800;
1054 break;
1056 case 3:
1058 rNumberFormat.SetBulletChar( 0x2013 ); // StarBats: 0xF000 + 150
1059 rNumberFormat.SetBulletRelSize(75);
1061 break;
1064 rNumberFormat.SetFirstLineOffset(nFirstLineOffset);
1067 // Set new SvxNumBulletItem for the respective style sheet
1068 void SdStyleSheetPool::PutNumBulletItem( SfxStyleSheetBase* pSheet,
1069 vcl::Font& rBulletFont )
1071 OUString aHelpFile;
1072 sal_uLong nHelpId = pSheet->GetHelpId( aHelpFile );
1073 SfxItemSet& rSet = pSheet->GetItemSet();
1075 switch ( nHelpId )
1077 case HID_STANDARD_STYLESHEET_NAME :
1079 // Standard template
1080 SvxNumberFormat aNumberFormat(SVX_NUM_CHAR_SPECIAL);
1081 aNumberFormat.SetBulletFont(&rBulletFont);
1082 aNumberFormat.SetBulletChar( 0x25CF ); // StarBats: 0xF000 + 34
1083 aNumberFormat.SetBulletRelSize(45);
1084 aNumberFormat.SetBulletColor(COL_AUTO);
1085 aNumberFormat.SetStart(1);
1086 aNumberFormat.SetNumAdjust(SvxAdjust::Left);
1088 SvxNumRule aNumRule( SvxNumRuleFlags::BULLET_REL_SIZE | SvxNumRuleFlags::BULLET_COLOR, SVX_MAX_NUM, false);
1090 for( sal_uInt16 i = 0; i < aNumRule.GetLevelCount(); i++ )
1092 const auto nLSpace = (i + 1) * 600;
1093 aNumberFormat.SetAbsLSpace(nLSpace);
1094 aNumberFormat.SetFirstLineOffset(-600);
1095 aNumRule.SetLevel( i, aNumberFormat );
1098 rSet.Put( SvxNumBulletItem( aNumRule, EE_PARA_NUMBULLET ) );
1099 static_cast<SfxStyleSheet*>(pSheet)->Broadcast(SfxHint( SfxHintId::DataChanged ) );
1101 break;
1103 case HID_PSEUDOSHEET_TITLE:
1104 /* title gets same bullet as subtitle and not that page symbol anymore */
1105 case HID_PSEUDOSHEET_SUBTITLE :
1107 // Subtitle template
1108 SvxNumBulletItem const*const pItem(
1109 rSet.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET));
1110 SvxNumRule *const pDefaultRule = pItem ? pItem->GetNumRule() : nullptr;
1111 DBG_ASSERT( pDefaultRule, "Where is my default template? [CL]" );
1113 if(pDefaultRule)
1115 SvxNumRule aNumRule(pDefaultRule->GetFeatureFlags(), 10, false);
1116 for(sal_uInt16 i=0; i < aNumRule.GetLevelCount(); i++)
1118 SvxNumberFormat aFrmt( pDefaultRule->GetLevel(i) );
1119 aFrmt.SetNumberingType(SVX_NUM_CHAR_SPECIAL);
1120 // #i93908# clear suffix for bullet lists
1121 aFrmt.SetPrefix(OUString());
1122 aFrmt.SetSuffix(OUString());
1123 aFrmt.SetStart(1);
1124 aFrmt.SetBulletRelSize(45);
1125 aFrmt.SetBulletChar( 0x25CF ); // StarBats: 0xF000 + 34
1126 aFrmt.SetBulletFont(&rBulletFont);
1127 aNumRule.SetLevel(i, aFrmt);
1130 rSet.Put( SvxNumBulletItem( aNumRule, EE_PARA_NUMBULLET ) );
1131 static_cast<SfxStyleSheet*>(pSheet)->Broadcast(SfxHint( SfxHintId::DataChanged ) );
1134 break;
1136 case HID_PSEUDOSHEET_OUTLINE + 1 :
1138 // Outline template
1139 SvxNumberFormat aNumberFormat(SVX_NUM_CHAR_SPECIAL);
1140 aNumberFormat.SetBulletColor(COL_AUTO);
1141 aNumberFormat.SetStart(1);
1142 aNumberFormat.SetNumAdjust(SvxAdjust::Left);
1144 SvxNumRule aNumRule( SvxNumRuleFlags::BULLET_REL_SIZE | SvxNumRuleFlags::BULLET_COLOR,
1145 SVX_MAX_NUM, false );
1146 for( sal_uInt16 i = 0; i < aNumRule.GetLevelCount(); i++ )
1148 setDefaultOutlineNumberFormatBulletAndIndent(i, aNumberFormat);
1149 rBulletFont.SetFontSize(Size(0,846)); // 24 pt
1150 aNumberFormat.SetBulletFont(&rBulletFont);
1151 aNumRule.SetLevel( i, aNumberFormat );
1154 rSet.Put( SvxNumBulletItem( aNumRule, EE_PARA_NUMBULLET ) );
1155 static_cast<SfxStyleSheet*>(pSheet)->Broadcast(SfxHint( SfxHintId::DataChanged ) );
1157 break;
1161 /*************************************************************************
1163 |* Create standard bullet font (without size)
1165 \************************************************************************/
1167 vcl::Font SdStyleSheetPool::GetBulletFont()
1169 vcl::Font aBulletFont( "StarSymbol", Size(0, 1000) );
1170 aBulletFont.SetCharSet(RTL_TEXTENCODING_UNICODE);
1171 aBulletFont.SetWeight(WEIGHT_NORMAL);
1172 aBulletFont.SetUnderline(LINESTYLE_NONE);
1173 aBulletFont.SetOverline(LINESTYLE_NONE);
1174 aBulletFont.SetStrikeout(STRIKEOUT_NONE);
1175 aBulletFont.SetItalic(ITALIC_NONE);
1176 aBulletFont.SetOutline(false);
1177 aBulletFont.SetShadow(false);
1178 aBulletFont.SetColor(COL_AUTO);
1179 aBulletFont.SetTransparent(true);
1181 return aBulletFont;
1184 void SdStyleSheetPool::AddStyleFamily( const SdPage* pPage )
1186 rtl::Reference< SfxStyleSheetPool > xPool( this );
1187 maStyleFamilyMap[pPage] = new SdStyleFamily( xPool, pPage );
1190 void SdStyleSheetPool::RemoveStyleFamily( const SdPage* pPage )
1192 SdStyleFamilyMap::iterator iter( maStyleFamilyMap.find( pPage ) );
1193 if( iter == maStyleFamilyMap.end() )
1194 return;
1196 SdStyleFamilyRef xStyle( (*iter).second );
1197 maStyleFamilyMap.erase( iter );
1199 if( xStyle.is() ) try
1201 xStyle->dispose();
1203 catch( Exception& )
1208 void SdStyleSheetPool::throwIfDisposed()
1210 if( mpDoc == nullptr )
1211 throw DisposedException();
1214 // XServiceInfo
1215 OUString SAL_CALL SdStyleSheetPool::getImplementationName()
1217 return "SdStyleSheetPool";
1220 sal_Bool SAL_CALL SdStyleSheetPool::supportsService( const OUString& ServiceName )
1222 return cppu::supportsService(this, ServiceName);
1225 Sequence< OUString > SAL_CALL SdStyleSheetPool::getSupportedServiceNames()
1227 return { "com.sun.star.style.StyleFamilies" };
1230 // XNameAccess
1231 Any SAL_CALL SdStyleSheetPool::getByName( const OUString& aName )
1233 throwIfDisposed();
1235 if( mxGraphicFamily->getName() == aName )
1236 return Any( Reference< XNameAccess >( static_cast< XNameAccess* >( mxGraphicFamily.get() ) ) );
1238 if( mxCellFamily->getName() == aName )
1239 return Any( Reference< XNameAccess >( static_cast< XNameAccess* >( mxCellFamily.get() ) ) );
1241 if( msTableFamilyName == aName )
1242 return Any( mxTableFamily );
1244 auto iter = std::find_if(maStyleFamilyMap.begin(), maStyleFamilyMap.end(),
1245 [&aName](const SdStyleFamilyMap::value_type& rEntry) { return rEntry.second->getName() == aName; });
1246 if (iter != maStyleFamilyMap.end())
1247 return Any( Reference< XNameAccess >( static_cast< XNameAccess* >( (*iter).second.get() ) ) );
1249 throw NoSuchElementException();
1252 Sequence< OUString > SAL_CALL SdStyleSheetPool::getElementNames()
1254 throwIfDisposed();
1256 Sequence< OUString > aNames( maStyleFamilyMap.size() + 3 );
1257 OUString* pNames = aNames.getArray();
1259 *pNames++ = mxGraphicFamily->getName();
1260 *pNames++ = mxCellFamily->getName();
1261 *pNames++ = msTableFamilyName;
1263 for( const auto& rEntry : maStyleFamilyMap )
1265 *pNames++ = rEntry.second->getName();
1268 return aNames;
1271 sal_Bool SAL_CALL SdStyleSheetPool::hasByName( const OUString& aName )
1273 throwIfDisposed();
1275 if( mxGraphicFamily->getName() == aName )
1276 return true;
1278 if( mxCellFamily->getName() == aName )
1279 return true;
1281 if( msTableFamilyName == aName )
1282 return true;
1284 return std::any_of(maStyleFamilyMap.begin(), maStyleFamilyMap.end(),
1285 [&aName](const SdStyleFamilyMap::value_type& rEntry) { return rEntry.second->getName() == aName; });
1288 // XElementAccess
1290 Type SAL_CALL SdStyleSheetPool::getElementType()
1292 throwIfDisposed();
1294 return cppu::UnoType<XNameAccess>::get();
1297 sal_Bool SAL_CALL SdStyleSheetPool::hasElements()
1299 return true;
1302 // XIndexAccess
1304 sal_Int32 SAL_CALL SdStyleSheetPool::getCount()
1306 throwIfDisposed();
1308 return maStyleFamilyMap.size() + 3;
1311 Any SAL_CALL SdStyleSheetPool::getByIndex( sal_Int32 Index )
1313 switch( Index )
1315 case 0:
1316 return Any( Reference< XNameAccess >( static_cast< XNameAccess* >( mxGraphicFamily.get() ) ) );
1318 case 1:
1319 return Any( Reference< XNameAccess >( static_cast< XNameAccess* >( mxCellFamily.get() ) ) );
1321 case 2:
1322 return Any( mxTableFamily );
1324 default:
1326 Index -= 3;
1327 if( (Index < 0) || (Index >= sal::static_int_cast<sal_Int32>(maStyleFamilyMap.size())) )
1328 throw IndexOutOfBoundsException();
1329 SdStyleFamilyMap::iterator iter( maStyleFamilyMap.begin() );
1330 std::advance(iter, Index);
1332 return Any( Reference< XNameAccess >( static_cast< XNameAccess* >( (*iter).second.get() ) ) );
1337 // XComponent
1339 void SAL_CALL SdStyleSheetPool::dispose()
1341 if( !mpDoc )
1342 return;
1344 mxGraphicFamily->dispose();
1345 mxGraphicFamily.clear();
1346 mxCellFamily->dispose();
1347 mxCellFamily.clear();
1349 Reference< XComponent > xComp( mxTableFamily, UNO_QUERY );
1350 if( xComp.is() )
1351 xComp->dispose();
1352 mxTableFamily = nullptr;
1354 SdStyleFamilyMap aTempMap;
1355 aTempMap.swap( maStyleFamilyMap );
1357 for( auto& rEntry : aTempMap ) try
1359 rEntry.second->dispose();
1361 catch( Exception& )
1365 mpDoc = nullptr;
1367 Clear();
1370 void SAL_CALL SdStyleSheetPool::addEventListener( const Reference< XEventListener >& /*xListener*/ )
1374 void SAL_CALL SdStyleSheetPool::removeEventListener( const Reference< XEventListener >& /*aListener*/ )
1378 SdStyleSheetVector SdStyleSheetPool::CreateChildList( SdStyleSheet const * pSheet )
1380 SdStyleSheetVector aResult;
1382 const size_t nListenerCount = pSheet->GetSizeOfVector();
1383 for (size_t n = 0; n < nListenerCount; ++n)
1385 SdStyleSheet* pChild = dynamic_cast< SdStyleSheet* >( pSheet->GetListener(n) );
1386 if(pChild && pChild->GetParent() == pSheet->GetName())
1388 aResult.emplace_back( pChild );
1392 return aResult;
1395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */