1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <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>
49 #include <tools/diagnose_ex.h>
50 #include <tools/UnitConversion.hxx>
51 
52 #include <editeng/lrspitem.hxx>
53 #include <editeng/adjustitem.hxx>
54 #include <editeng/numdef.hxx>
55 #include <svl/itempool.hxx>
56 #include <svl/IndexedStyleSheets.hxx>
57 
58 #include <stlpool.hxx>
59 #include <sdresid.hxx>
60 #include <stlsheet.hxx>
61 #include <strings.hrc>
62 #include <glob.hxx>
63 #include <drawdoc.hxx>
64 #include <svl/itemset.hxx>
65 #include <app.hrc>
66 #include <strings.hxx>
67 
68 #include <com/sun/star/drawing/LineStyle.hpp>
69 #include <com/sun/star/drawing/TextFitToSizeType.hpp>
70 
71 using namespace ::com::sun::star;
72 using namespace ::com::sun::star::uno;
73 using namespace ::com::sun::star::lang;
74 using namespace ::com::sun::star::style;
75 using namespace ::com::sun::star::container;
76 
77 namespace
78 {
79 
lcl_findRenamedStyleName(std::vector<std::pair<OUString,OUString>> & rRenamedList,OUString const & aOriginalName)80 OUString lcl_findRenamedStyleName(std::vector< std::pair< OUString, OUString > > &rRenamedList, OUString const & aOriginalName )
81 {
82     auto aIter = std::find_if(rRenamedList.begin(), rRenamedList.end(),
83         [&aOriginalName](const std::pair<OUString, OUString>& rItem) { return rItem.first == aOriginalName; });
84     if (aIter != rRenamedList.end())
85         return (*aIter).second;
86     return OUString();
87 }
88 
lcl_findStyle(StyleSheetCopyResultVector & rStyles,std::u16string_view aStyleName)89 SfxStyleSheet *lcl_findStyle(StyleSheetCopyResultVector& rStyles, std::u16string_view aStyleName)
90 {
91     if( aStyleName.empty() )
92         return nullptr;
93     for (const auto& a : rStyles)
94     {
95         if (a.m_xStyleSheet->GetName() == aStyleName)
96             return a.m_xStyleSheet.get();
97     }
98     return nullptr;
99 }
100 
101 }
102 
SdStyleSheetPool(SfxItemPool const & _rPool,SdDrawDocument * pDocument)103 SdStyleSheetPool::SdStyleSheetPool(SfxItemPool const& _rPool, SdDrawDocument* pDocument)
104 :   SdStyleSheetPoolBase( _rPool )
105 ,   mpActualStyleSheet(nullptr)
106 ,   mpDoc(pDocument)
107 {
108     if( !mpDoc )
109         return;
110 
111     rtl::Reference< SfxStyleSheetPool > xPool( this );
112 
113     // create graphics family
114     mxGraphicFamily = new SdStyleFamily( xPool, SfxStyleFamily::Para );
115     mxCellFamily = new SdStyleFamily( xPool, SfxStyleFamily::Frame );
116 
117     mxTableFamily = sdr::table::CreateTableDesignFamily();
118     Reference< XNamed > xNamed( mxTableFamily, UNO_QUERY );
119     if( xNamed.is() )
120         msTableFamilyName = xNamed->getName();
121 
122     // create presentation families, one for each master page
123     const sal_uInt16 nCount = mpDoc->GetMasterSdPageCount(PageKind::Standard);
124     for( sal_uInt16 nPage = 0; nPage < nCount; ++nPage )
125         AddStyleFamily( mpDoc->GetMasterSdPage(nPage,PageKind::Standard) );
126 }
127 
~SdStyleSheetPool()128 SdStyleSheetPool::~SdStyleSheetPool()
129 {
130     DBG_ASSERT( mpDoc == nullptr, "sd::SdStyleSheetPool::~SdStyleSheetPool(), dispose me first!" );
131 }
132 
Create(const OUString & rName,SfxStyleFamily eFamily,SfxStyleSearchBits _nMask)133 rtl::Reference<SfxStyleSheetBase> SdStyleSheetPool::Create(const OUString& rName, SfxStyleFamily eFamily, SfxStyleSearchBits _nMask )
134 {
135     return new SdStyleSheet(rName, *this, eFamily, _nMask);
136 }
137 
GetTitleSheet(std::u16string_view rLayoutName)138 SfxStyleSheetBase* SdStyleSheetPool::GetTitleSheet(std::u16string_view rLayoutName)
139 {
140     OUString aName = OUString::Concat(rLayoutName) + SD_LT_SEPARATOR STR_LAYOUT_TITLE;
141     SfxStyleSheetBase* pResult = Find(aName, SfxStyleFamily::Page);
142     return pResult;
143 }
144 
145 /*************************************************************************
146 |*
147 |* Create a list of outline text templates for a presentation layout.
148 |* The caller has to delete the list.
149 |*
150 \************************************************************************/
151 
CreateOutlineSheetList(std::u16string_view rLayoutName,std::vector<SfxStyleSheetBase * > & rOutlineStyles)152 void SdStyleSheetPool::CreateOutlineSheetList (std::u16string_view rLayoutName, std::vector<SfxStyleSheetBase*> &rOutlineStyles)
153 {
154     OUString aName = OUString::Concat(rLayoutName) + SD_LT_SEPARATOR STR_LAYOUT_OUTLINE;
155 
156     for (sal_Int32 nSheet = 1; nSheet < 10; nSheet++)
157     {
158         OUString aFullName(aName + " " + OUString::number( nSheet ) );
159         SfxStyleSheetBase* pSheet = Find(aFullName, SfxStyleFamily::Page);
160 
161         if (pSheet)
162             rOutlineStyles.push_back(pSheet);
163     }
164 }
165 
166 /*************************************************************************
167 |*
168 |* Create style sheets with default values for the named presentation layout
169 |*
170 \************************************************************************/
171 
CreateLayoutStyleSheets(std::u16string_view rLayoutName,bool bCheck)172 void SdStyleSheetPool::CreateLayoutStyleSheets(std::u16string_view rLayoutName, bool bCheck /*= sal_False*/ )
173 {
174     const SfxStyleSearchBits nUsedMask = SfxStyleSearchBits::All & ~SfxStyleSearchBits::UserDefined;
175 
176     bool bCreated = false;
177 
178     SfxStyleSheetBase* pSheet = nullptr;
179 
180     OUString aPrefix(OUString::Concat(rLayoutName) + SD_LT_SEPARATOR);
181 
182     vcl::Font aLatinFont, aCJKFont, aCTLFont;
183 
184     mpDoc->getDefaultFonts( aLatinFont, aCJKFont, aCTLFont );
185 
186     // Font for title and outline
187     SvxFontItem aSvxFontItem( aLatinFont.GetFamilyType(), aLatinFont.GetFamilyName(), aLatinFont.GetStyleName(), aLatinFont.GetPitch(),
188                               aLatinFont.GetCharSet(), EE_CHAR_FONTINFO );
189 
190     SvxFontItem aSvxFontItemCJK( aCJKFont.GetFamilyType(), aCJKFont.GetFamilyName(), aCJKFont.GetStyleName(), aCJKFont.GetPitch(),
191                                  aCJKFont.GetCharSet(), EE_CHAR_FONTINFO_CJK );
192 
193     SvxFontItem aSvxFontItemCTL( aCTLFont.GetFamilyType(), aCTLFont.GetFamilyName(), aCTLFont.GetStyleName(), aCTLFont.GetPitch(),
194                                  aCTLFont.GetCharSet(), EE_CHAR_FONTINFO_CTL );
195 
196     vcl::Font aBulletFont( GetBulletFont() );
197 
198     /**************************************************************************
199     * outline levels
200     **************************************************************************/
201     OUString aName(STR_LAYOUT_OUTLINE);
202     const OUString aHelpFile;
203 
204     SvxLRSpaceItem aSvxLRSpaceItem( EE_PARA_LRSPACE );
205     SvxULSpaceItem aSvxULSpaceItem( EE_PARA_ULSPACE );
206 
207     for( sal_Int32 nLevel = 1; nLevel < 10; nLevel++)
208     {
209         OUString aLevelName( aPrefix + aName + " " + OUString::number( nLevel ) ) ;
210 
211         if (!Find(aLevelName, SfxStyleFamily::Page))
212         {
213             bCreated = true;
214             pSheet = &Make(aLevelName, SfxStyleFamily::Page,nUsedMask);
215             pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_OUTLINE + nLevel );
216 
217             pSheet->SetParent( OUString() );
218 
219             // attributing for level 1, the others levels inherit
220             if (nLevel == 1)
221             {
222                 SfxItemSet&     rSet = pSheet->GetItemSet();
223 
224                 rSet.Put(aSvxFontItem);
225                 rSet.Put(aSvxFontItemCJK);
226                 rSet.Put(aSvxFontItemCTL);
227                 rSet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC ) );
228                 rSet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CJK ) );
229                 rSet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CTL ) );
230                 rSet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
231                 rSet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ) );
232                 rSet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ) );
233                 rSet.Put( SvxUnderlineItem(LINESTYLE_NONE, EE_CHAR_UNDERLINE ) );
234                 rSet.Put( SvxOverlineItem(LINESTYLE_NONE, EE_CHAR_OVERLINE ) );
235                 rSet.Put( SvxCrossedOutItem(STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ) );
236                 rSet.Put( SvxCaseMapItem(SvxCaseMap::NotMapped, EE_CHAR_CASEMAP ) );
237                 rSet.Put( SvxShadowedItem(false, EE_CHAR_SHADOW ) );
238                 rSet.Put( SvxContourItem(false, EE_CHAR_OUTLINE ) );
239                 rSet.Put( SvxEmphasisMarkItem(FontEmphasisMark::NONE, EE_CHAR_EMPHASISMARK ) );
240                 rSet.Put( SvxCharReliefItem(FontRelief::NONE, EE_CHAR_RELIEF) );
241                 rSet.Put( SvxColorItem( COL_AUTO, EE_CHAR_COLOR) );
242                 rSet.Put( SvxColorItem( COL_AUTO, EE_CHAR_BKGCOLOR )  );
243                 rSet.Put( XLineStyleItem(css::drawing::LineStyle_NONE) );
244                 rSet.Put( XFillStyleItem(drawing::FillStyle_NONE) );
245                 rSet.Put( SdrTextFitToSizeTypeItem(drawing::TextFitToSizeType_AUTOFIT) );
246                 rSet.Put( makeSdrTextAutoGrowHeightItem(false) );
247                 // #i16874# enable kerning by default but only for new documents
248                 rSet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
249 
250                 vcl::Font f( GetBulletFont() );
251                 PutNumBulletItem( pSheet, f );
252             }
253 
254             sal_uLong nFontSize = 20;
255             sal_uInt16 nUpper = 100;
256 
257             switch (nLevel)
258             {
259                 case 1:
260                 {
261                     nFontSize = 32;
262                     nUpper = 500;
263                 }
264                 break;
265 
266                 case 2:
267                 {
268                     nFontSize = 28;
269                     nUpper = 400;
270                 }
271                 break;
272 
273                 case 3:
274                 {
275                     nFontSize = 24;
276                     nUpper = 300;
277                 }
278                 break;
279 
280                 case 4:
281                 {
282                     nUpper = 200;
283                 }
284                 break;
285             }
286 
287             // FontSize
288             nFontSize = static_cast<sal_uInt16>(convertPointToMm100(nFontSize));
289             SfxItemSet& rOutlineSet = pSheet->GetItemSet();
290             rOutlineSet.Put( SvxFontHeightItem( nFontSize, 100, EE_CHAR_FONTHEIGHT ) );
291             rOutlineSet.Put( SvxFontHeightItem( nFontSize, 100, EE_CHAR_FONTHEIGHT_CJK ) );
292             rOutlineSet.Put( SvxFontHeightItem( SdDrawDocument::convertFontHeightToCTL( nFontSize ), 100, EE_CHAR_FONTHEIGHT_CTL ) );
293 
294             // Line distance (upwards). Stuff around here cleaned up in i35937
295             aSvxULSpaceItem.SetUpper(nUpper);
296             pSheet->GetItemSet().Put(aSvxULSpaceItem);
297         }
298     }
299 
300     // if we created outline styles, we need to chain them
301     if( bCreated )
302     {
303         SfxStyleSheetBase* pParent = nullptr;
304         for (sal_Int32 nLevel = 1; nLevel < 10; nLevel++)
305         {
306             OUString aLevelName( aPrefix + aName + " " + OUString::number( nLevel ) );
307 
308             pSheet = Find(aLevelName, SfxStyleFamily::Page);
309 
310             DBG_ASSERT( pSheet, "missing layout style!");
311 
312             if( pSheet )
313             {
314                 if (pParent)
315                     pSheet->SetParent(pParent->GetName());
316                 pParent = pSheet;
317             }
318         }
319     }
320 
321     /**************************************************************************
322     * Title
323     **************************************************************************/
324     aName = aPrefix + STR_LAYOUT_TITLE;
325 
326     if (!Find(aName, SfxStyleFamily::Page))
327     {
328         bCreated = true;
329 
330         pSheet = &Make(aName, SfxStyleFamily::Page,nUsedMask);
331         pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_TITLE );
332         pSheet->SetParent( OUString() );
333         SfxItemSet& rTitleSet = pSheet->GetItemSet();
334         rTitleSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
335         rTitleSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
336         rTitleSet.Put(aSvxFontItem);
337         rTitleSet.Put(aSvxFontItemCJK);
338         rTitleSet.Put(aSvxFontItemCTL);
339         rTitleSet.Put(SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC ) );
340         rTitleSet.Put(SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CJK ) );
341         rTitleSet.Put(SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CTL ) );
342         rTitleSet.Put(SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
343         rTitleSet.Put(SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ) );
344         rTitleSet.Put(SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ) );
345         rTitleSet.Put(SvxFontHeightItem( 1552, 100, EE_CHAR_FONTHEIGHT ) );                 // 44 pt
346         rTitleSet.Put(SvxFontHeightItem( 1552, 100, EE_CHAR_FONTHEIGHT_CJK ) );                 // 44 pt
347         rTitleSet.Put(SvxFontHeightItem( SdDrawDocument::convertFontHeightToCTL( 1552 ), 100, EE_CHAR_FONTHEIGHT_CTL ) );                   // 44 pt
348         rTitleSet.Put(SvxUnderlineItem(LINESTYLE_NONE, EE_CHAR_UNDERLINE ));
349         rTitleSet.Put(SvxOverlineItem(LINESTYLE_NONE, EE_CHAR_OVERLINE ));
350         rTitleSet.Put(SvxCrossedOutItem(STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ));
351         rTitleSet.Put(SvxCaseMapItem(SvxCaseMap::NotMapped, EE_CHAR_CASEMAP ));
352         rTitleSet.Put(SvxShadowedItem(false, EE_CHAR_SHADOW ));
353         rTitleSet.Put(SvxContourItem(false, EE_CHAR_OUTLINE ));
354         rTitleSet.Put( SvxEmphasisMarkItem(FontEmphasisMark::NONE, EE_CHAR_EMPHASISMARK ) );
355         rTitleSet.Put( SvxCharReliefItem(FontRelief::NONE, EE_CHAR_RELIEF ) );
356         rTitleSet.Put(SvxColorItem( COL_AUTO, EE_CHAR_COLOR ));
357         rTitleSet.Put(SvxColorItem( COL_AUTO, EE_CHAR_BKGCOLOR ));
358         rTitleSet.Put(SvxAdjustItem(SvxAdjust::Center, EE_PARA_JUST ));
359         rTitleSet.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
360         // #i16874# enable kerning by default but only for new documents
361         rTitleSet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
362 
363         aBulletFont.SetFontSize(Size(0,1552));                  // 44 pt
364         PutNumBulletItem( pSheet, aBulletFont );
365     }
366 
367     /**************************************************************************
368     * Subtitle
369     **************************************************************************/
370     aName = aPrefix + STR_LAYOUT_SUBTITLE;
371 
372     if (!Find(aName, SfxStyleFamily::Page))
373     {
374         bCreated = true;
375 
376         pSheet = &Make(aName, SfxStyleFamily::Page,nUsedMask);
377         pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_SUBTITLE );
378         pSheet->SetParent( OUString() );
379         SfxItemSet& rSubtitleSet = pSheet->GetItemSet();
380         rSubtitleSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
381         rSubtitleSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
382         rSubtitleSet.Put(aSvxFontItem);
383         rSubtitleSet.Put(aSvxFontItemCJK);
384         rSubtitleSet.Put(aSvxFontItemCTL);
385         rSubtitleSet.Put(SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC ) );
386         rSubtitleSet.Put(SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CJK ) );
387         rSubtitleSet.Put(SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CTL ) );
388         rSubtitleSet.Put(SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
389         rSubtitleSet.Put(SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ) );
390         rSubtitleSet.Put(SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ) );
391         rSubtitleSet.Put( SvxFontHeightItem( 1129, 100, EE_CHAR_FONTHEIGHT ) );     // 32 pt
392         rSubtitleSet.Put( SvxFontHeightItem( 1129, 100, EE_CHAR_FONTHEIGHT_CJK ) ); // 32 pt
393         rSubtitleSet.Put( SvxFontHeightItem( SdDrawDocument::convertFontHeightToCTL( 1129 ), 100, EE_CHAR_FONTHEIGHT_CTL ) ); // 32 pt
394         rSubtitleSet.Put(SvxUnderlineItem(LINESTYLE_NONE, EE_CHAR_UNDERLINE ));
395         rSubtitleSet.Put(SvxOverlineItem(LINESTYLE_NONE, EE_CHAR_OVERLINE ));
396         rSubtitleSet.Put(SvxCrossedOutItem(STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ));
397         rSubtitleSet.Put(SvxCaseMapItem(SvxCaseMap::NotMapped, EE_CHAR_CASEMAP ));
398         rSubtitleSet.Put(SvxShadowedItem(false, EE_CHAR_SHADOW ));
399         rSubtitleSet.Put(SvxContourItem(false, EE_CHAR_OUTLINE ));
400         rSubtitleSet.Put( SvxEmphasisMarkItem(FontEmphasisMark::NONE, EE_CHAR_EMPHASISMARK ) );
401         rSubtitleSet.Put( SvxCharReliefItem(FontRelief::NONE, EE_CHAR_RELIEF ) );
402         rSubtitleSet.Put(SvxColorItem( COL_AUTO, EE_CHAR_COLOR ));
403         rSubtitleSet.Put(SvxColorItem( COL_AUTO, EE_CHAR_BKGCOLOR ));
404         rSubtitleSet.Put(SvxAdjustItem(SvxAdjust::Center, EE_PARA_JUST ));
405         rSubtitleSet.Put( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
406         // #i16874# enable kerning by default but only for new documents
407         rSubtitleSet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
408         aSvxLRSpaceItem.SetTextLeft(0);
409         rSubtitleSet.Put(aSvxLRSpaceItem);
410 
411         vcl::Font aTmpFont( GetBulletFont() );
412         aTmpFont.SetFontSize(Size(0, 1129));        // 32 pt
413         PutNumBulletItem( pSheet, aTmpFont );
414     }
415 
416     /**************************************************************************
417     * Notes
418     **************************************************************************/
419     aName = aPrefix + STR_LAYOUT_NOTES;
420 
421     if (!Find(aName, SfxStyleFamily::Page))
422     {
423         bCreated = true;
424 
425         pSheet = &Make(aName, SfxStyleFamily::Page,nUsedMask);
426         pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_NOTES );
427         pSheet->SetParent( OUString() );
428         SfxItemSet& rNotesSet = pSheet->GetItemSet();
429         rNotesSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
430         rNotesSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
431         rNotesSet.Put(aSvxFontItem);
432         rNotesSet.Put(aSvxFontItemCJK);
433         rNotesSet.Put(aSvxFontItemCTL);
434         rNotesSet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC ) );
435         rNotesSet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CJK ) );
436         rNotesSet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CTL ) );
437         rNotesSet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
438         rNotesSet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ) );
439         rNotesSet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ) );
440         rNotesSet.Put( SvxFontHeightItem( 705, 100, EE_CHAR_FONTHEIGHT ) );     // 20 pt
441         rNotesSet.Put( SvxFontHeightItem( 705, 100, EE_CHAR_FONTHEIGHT_CJK ) ); // 20 pt
442         rNotesSet.Put( SvxFontHeightItem( SdDrawDocument::convertFontHeightToCTL( 705 ), 100, EE_CHAR_FONTHEIGHT_CTL ) ); // 20 pt
443         rNotesSet.Put( SvxUnderlineItem(LINESTYLE_NONE, EE_CHAR_UNDERLINE ) );
444         rNotesSet.Put( SvxOverlineItem(LINESTYLE_NONE, EE_CHAR_OVERLINE ) );
445         rNotesSet.Put( SvxCrossedOutItem(STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ) );
446         rNotesSet.Put( SvxCaseMapItem(SvxCaseMap::NotMapped, EE_CHAR_CASEMAP ) );
447         rNotesSet.Put( SvxShadowedItem(false, EE_CHAR_SHADOW ) );
448         rNotesSet.Put( SvxContourItem(false, EE_CHAR_OUTLINE ) );
449         rNotesSet.Put( SvxEmphasisMarkItem(FontEmphasisMark::NONE, EE_CHAR_EMPHASISMARK ) );
450         rNotesSet.Put( SvxCharReliefItem(FontRelief::NONE, EE_CHAR_RELIEF) );
451         rNotesSet.Put( SvxColorItem( COL_AUTO, EE_CHAR_COLOR ) );
452         rNotesSet.Put( SvxColorItem( COL_AUTO, EE_CHAR_BKGCOLOR ) );
453         rNotesSet.Put( SvxLRSpaceItem( 0, 0, 600, -600, EE_PARA_LRSPACE  ) );
454         // #i16874# enable kerning by default but only for new documents
455         rNotesSet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
456 
457 /* #i35937# */
458 
459     }
460 
461     /**************************************************************************
462     * Background objects
463     **************************************************************************/
464     aName = aPrefix + STR_LAYOUT_BACKGROUNDOBJECTS;
465 
466     if (!Find(aName, SfxStyleFamily::Page))
467     {
468         bCreated = true;
469 
470         pSheet = &Make(aName, SfxStyleFamily::Page,nUsedMask);
471         pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_BACKGROUNDOBJECTS );
472         pSheet->SetParent( OUString() );
473         SfxItemSet& rBackgroundObjectsSet = pSheet->GetItemSet();
474         rBackgroundObjectsSet.Put(makeSdrShadowItem(false));
475         rBackgroundObjectsSet.Put(makeSdrShadowColorItem(COL_GRAY));
476         rBackgroundObjectsSet.Put(makeSdrShadowXDistItem(200)); // 3 mm shadow distance
477         rBackgroundObjectsSet.Put(makeSdrShadowYDistItem(200));
478         // #i16874# enable kerning by default but only for new documents
479         rBackgroundObjectsSet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
480         rBackgroundObjectsSet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_BLOCK));
481     }
482 
483     /**************************************************************************
484     * Background
485     **************************************************************************/
486     aName = aPrefix + STR_LAYOUT_BACKGROUND;
487 
488     if (!Find(aName, SfxStyleFamily::Page))
489     {
490         bCreated = true;
491 
492         pSheet = &Make(aName, SfxStyleFamily::Page,nUsedMask);
493         pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_BACKGROUND );
494         pSheet->SetParent( OUString() );
495         SfxItemSet& rBackgroundSet = pSheet->GetItemSet();
496         rBackgroundSet.Put(XLineStyleItem(drawing::LineStyle_NONE));
497         rBackgroundSet.Put(XFillStyleItem(drawing::FillStyle_NONE));
498         // #i16874# enable kerning by default but only for new documents
499         rBackgroundSet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
500     }
501 
502     DBG_ASSERT( !bCheck || !bCreated, "missing layout style sheets detected!" );
503 }
504 
505 /*************************************************************************
506 |*
507 |* Copy graphic style sheets from source pool into this pool
508 |*
509 |* (rSourcePool can not be const since SfxStyleSheetPoolBase::Find isn't const)
510 |*
511 \************************************************************************/
512 
CopyGraphicSheets(SdStyleSheetPool & rSourcePool)513 void SdStyleSheetPool::CopyGraphicSheets(SdStyleSheetPool& rSourcePool)
514 {
515     CopySheets( rSourcePool, SfxStyleFamily::Para );
516 }
517 
CopyCellSheets(SdStyleSheetPool & rSourcePool)518 void SdStyleSheetPool::CopyCellSheets(SdStyleSheetPool& rSourcePool)
519 {
520     CopySheets( rSourcePool, SfxStyleFamily::Frame );
521 }
522 
CopyTableStyles(SdStyleSheetPool const & rSourcePool)523 void SdStyleSheetPool::CopyTableStyles(SdStyleSheetPool const & rSourcePool)
524 {
525     Reference< XIndexAccess > xSource( rSourcePool.mxTableFamily, UNO_QUERY );
526     Reference< XNameContainer > xTarget( mxTableFamily, UNO_QUERY );
527     Reference< XSingleServiceFactory > xFactory( mxTableFamily, UNO_QUERY );
528 
529     if( !(xSource.is() && xFactory.is() && mxTableFamily.is()) )
530         return;
531 
532     for( sal_Int32 nIndex = 0; nIndex < xSource->getCount(); nIndex++ ) try
533     {
534         Reference< XStyle > xSourceTableStyle( xSource->getByIndex( nIndex ), UNO_QUERY );
535         if( xSourceTableStyle.is() )
536         {
537             Reference< XStyle > xNewTableStyle( xFactory->createInstance(), UNO_QUERY );
538             if( xNewTableStyle.is() )
539             {
540                 Reference< XNameAccess> xSourceNames( xSourceTableStyle, UNO_QUERY_THROW );
541 
542                 const Sequence< OUString > aStyleNames( xSourceNames->getElementNames() );
543 
544                 Reference< XNameReplace > xTargetNames( xNewTableStyle, UNO_QUERY );
545 
546                 for( const OUString& aName : aStyleNames )
547                 {
548                     Reference< XStyle > xSourceStyle( xSourceNames->getByName( aName ), UNO_QUERY );
549                     Reference< XStyle > xTargetStyle;
550                     if( xSourceStyle.is() ) try
551                     {
552                         mxCellFamily->getByName( xSourceStyle->getName() ) >>= xTargetStyle;
553                     }
554                     catch( Exception& )
555                     {
556                         TOOLS_WARN_EXCEPTION( "sd", "sd::SdStyleSheetPool::CopyTableStyles()" );
557                     }
558 
559                     if( xTargetStyle.is() )
560                         xTargetNames->replaceByName( aName, Any( xTargetStyle ) );
561                 }
562             }
563 
564             OUString sName( xSourceTableStyle->getName() );
565             if( xTarget->hasByName( sName ) )
566                 xTarget->replaceByName( sName, Any( xNewTableStyle ) );
567             else
568                 xTarget->insertByName( sName, Any( xNewTableStyle ) );
569         }
570     }
571     catch( Exception& )
572     {
573         TOOLS_WARN_EXCEPTION( "sd", "sd::SdStyleSheetPool::CopyTableStyles()");
574     }
575 }
576 
CopyCellSheets(SdStyleSheetPool & rSourcePool,StyleSheetCopyResultVector & rCreatedSheets)577 void SdStyleSheetPool::CopyCellSheets(SdStyleSheetPool& rSourcePool, StyleSheetCopyResultVector& rCreatedSheets)
578 {
579     CopySheets( rSourcePool, SfxStyleFamily::Frame, rCreatedSheets );
580 }
581 
RenameAndCopyGraphicSheets(SdStyleSheetPool & rSourcePool,StyleSheetCopyResultVector & rCreatedSheets,std::u16string_view rRenameSuffix)582 void SdStyleSheetPool::RenameAndCopyGraphicSheets(SdStyleSheetPool& rSourcePool, StyleSheetCopyResultVector& rCreatedSheets, std::u16string_view rRenameSuffix)
583 {
584     CopySheets( rSourcePool, SfxStyleFamily::Para, rCreatedSheets, rRenameSuffix );
585 }
586 
CopySheets(SdStyleSheetPool & rSourcePool,SfxStyleFamily eFamily)587 void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily )
588 {
589     StyleSheetCopyResultVector aTmpSheets;
590     CopySheets(rSourcePool, eFamily, aTmpSheets);
591 }
592 
CopySheets(SdStyleSheetPool & rSourcePool,SfxStyleFamily eFamily,StyleSheetCopyResultVector & rCreatedSheets)593 void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, StyleSheetCopyResultVector& rCreatedSheets)
594 {
595     CopySheets(rSourcePool, eFamily, rCreatedSheets, u"");
596 }
597 
598 namespace
599 {
600 
601 struct HasFamilyPredicate : svl::StyleSheetPredicate
602 {
HasFamilyPredicate__anon42339b390311::HasFamilyPredicate603     explicit HasFamilyPredicate(SfxStyleFamily eFamily)
604     : meFamily(eFamily) {}
605 
Check__anon42339b390311::HasFamilyPredicate606     bool Check(const SfxStyleSheetBase& sheet) override
607     {
608         return sheet.GetFamily() == meFamily;
609     }
610     SfxStyleFamily meFamily;
611 };
612 
613 }
614 
CopySheets(SdStyleSheetPool & rSourcePool,SfxStyleFamily eFamily,StyleSheetCopyResultVector & rCreatedSheets,std::u16string_view rRenameSuffix)615 void SdStyleSheetPool::CopySheets(SdStyleSheetPool& rSourcePool, SfxStyleFamily eFamily, StyleSheetCopyResultVector& rCreatedSheets, std::u16string_view rRenameSuffix)
616 {
617     std::vector< std::pair< rtl::Reference< SfxStyleSheetBase >, OUString > > aNewStyles;
618     std::vector< std::pair< OUString, OUString > > aRenamedList;
619 
620     // find all style sheets of the source pool which have the same family
621     HasFamilyPredicate aHasFamilyPredicate(eFamily);
622     std::vector<sal_Int32> aSheetsWithFamily = rSourcePool.GetIndexedStyleSheets().FindPositionsByPredicate(aHasFamilyPredicate);
623 
624     for (const auto& rPos : aSheetsWithFamily)
625     {
626         SfxStyleSheetBase* pSheet = rSourcePool.GetStyleSheetByPositionInIndex( rPos );
627         if( !pSheet )
628             continue;
629         OUString aName( pSheet->GetName() );
630 
631         // now check whether we already have a sheet with the same name
632         std::vector<sal_Int32> aSheetsWithName = GetIndexedStyleSheets().FindPositionsByName(aName);
633         bool bAddToList = false;
634         SfxStyleSheetBase * pExistingSheet = nullptr;
635         if (!aSheetsWithName.empty())
636         {
637             // if we have a rename suffix, try to find a new name
638             pExistingSheet =
639                 GetStyleSheetByPositionInIndex(aSheetsWithName.front());
640             if (!rRenameSuffix.empty() &&
641                 !pExistingSheet->GetItemSet().Equals(pSheet->GetItemSet(), false))
642             {
643                 // we have found a sheet with the same name, but different contents. Try to find a new name.
644                 // If we already have a sheet with the new name, and it is equal to the one in the source pool,
645                 // do nothing.
646                 OUString aTmpName = aName + rRenameSuffix;
647                 sal_Int32 nSuffix = 1;
648                 do
649                 {
650                     aTmpName = aName + rRenameSuffix + OUString::number(nSuffix);
651                     pExistingSheet = Find(aTmpName, eFamily);
652                     nSuffix++;
653                 } while (pExistingSheet &&
654                         !pExistingSheet->GetItemSet().Equals(pSheet->GetItemSet(), false));
655                 aName = aTmpName;
656                 bAddToList = true;
657             }
658         }
659         // we do not already have a sheet with the same name and contents. Create a new one.
660         if (!pExistingSheet)
661         {
662             assert(!Find(aName, eFamily));
663             rtl::Reference< SfxStyleSheetBase > xNewSheet( &Make( aName, eFamily ) );
664 
665             xNewSheet->SetMask( pSheet->GetMask() );
666 
667             // Also set parent relation for copied style sheets
668             OUString aParent( pSheet->GetParent() );
669             if( !aParent.isEmpty() )
670                 aNewStyles.emplace_back( xNewSheet, aParent );
671 
672             if( !bAddToList )
673             {
674                 OUString aHelpFile;
675                 xNewSheet->SetHelpId( aHelpFile, pSheet->GetHelpId( aHelpFile ) );
676             }
677             xNewSheet->GetItemSet().Put( pSheet->GetItemSet() );
678 
679             rCreatedSheets.emplace_back(static_cast<SdStyleSheet*>(xNewSheet.get()), true);
680             aRenamedList.emplace_back( pSheet->GetName(), aName );
681         }
682         else if (bAddToList)
683         {
684             // Add to list - used for renaming
685             rCreatedSheets.emplace_back(static_cast<SdStyleSheet*>(pExistingSheet), false);
686             aRenamedList.emplace_back( pSheet->GetName(), aName );
687         }
688     }
689 
690     // set parents on newly added stylesheets
691     for( auto& rStyle : aNewStyles )
692     {
693         if( !rRenameSuffix.empty() )
694         {
695             SfxStyleSheet *pParent = lcl_findStyle(rCreatedSheets, lcl_findRenamedStyleName(aRenamedList, rStyle.second));
696             if( pParent )
697             {
698                 rStyle.first->SetParent( pParent->GetName() );
699                 continue;
700             }
701         }
702         DBG_ASSERT( rSourcePool.Find( rStyle.second, eFamily ), "StyleSheet has invalid parent: Family mismatch" );
703         rStyle.first->SetParent( rStyle.second );
704     }
705     // we have changed names of style sheets. Trigger reindexing.
706     Reindex();
707 }
708 
709 /*************************************************************************
710 |*
711 |* Copy style sheets of the named presentation layout from the source pool into
712 |* this pool. Copies only the style sheets which aren't yet in this pool.
713 |* If not NULL, pCreatedSheets is filled with pointers to the created style
714 |* sheets.
715 |*
716 |* (rSourcePool can not be const since SfxStyleSheetPoolBase::Find isn't const)
717 |*
718 \************************************************************************/
719 
CopyLayoutSheets(std::u16string_view rLayoutName,SdStyleSheetPool & rSourcePool,StyleSheetCopyResultVector & rCreatedSheets)720 void SdStyleSheetPool::CopyLayoutSheets(std::u16string_view rLayoutName, SdStyleSheetPool& rSourcePool, StyleSheetCopyResultVector& rCreatedSheets)
721 {
722     SfxStyleSheetBase* pSheet = nullptr;
723 
724     std::vector<OUString> aNameList;
725     CreateLayoutSheetNames(rLayoutName,aNameList);
726 
727     for (const auto& rName : aNameList)
728     {
729         pSheet = Find(rName, SfxStyleFamily::Page);
730         if (!pSheet)
731         {
732             SfxStyleSheetBase* pSourceSheet = rSourcePool.Find(rName, SfxStyleFamily::Page);
733             DBG_ASSERT(pSourceSheet, "CopyLayoutSheets: Style sheet missing");
734             if (pSourceSheet)
735             {
736                 // In the case one comes with Methusalem-Docs.
737                 SfxStyleSheetBase& rNewSheet = Make(rName, SfxStyleFamily::Page);
738                 OUString file;
739                 rNewSheet.SetHelpId( file, pSourceSheet->GetHelpId( file ) );
740                 rNewSheet.GetItemSet().Put(pSourceSheet->GetItemSet());
741                 rCreatedSheets.emplace_back(static_cast<SdStyleSheet*>(&rNewSheet), true);
742             }
743         }
744     }
745 
746     // Special treatment for outline templates: create parent relation
747     std::vector<SfxStyleSheetBase*> aOutlineSheets;
748     CreateOutlineSheetList(rLayoutName,aOutlineSheets);
749 
750     if( aOutlineSheets.empty() )
751         return;
752 
753     std::vector<SfxStyleSheetBase*>::iterator it = aOutlineSheets.begin();
754     SfxStyleSheetBase* pParent = *it;
755     ++it;
756 
757     while (it != aOutlineSheets.end())
758     {
759         pSheet = *it;
760 
761         if (!pSheet)
762             break;
763 
764         if (pSheet->GetParent().isEmpty())
765             pSheet->SetParent(pParent->GetName());
766 
767         pParent = pSheet;
768 
769         ++it;
770     }
771 }
772 
773 /*************************************************************************
774 |*
775 |* Create list with names of the presentation templates of a layout.
776 |* The list and the containing strings are owned by the caller!
777 |*
778 \************************************************************************/
779 
CreateLayoutSheetNames(std::u16string_view rLayoutName,std::vector<OUString> & aNameList)780 void SdStyleSheetPool::CreateLayoutSheetNames(std::u16string_view rLayoutName, std::vector<OUString> &aNameList)
781 {
782     OUString aPrefix(OUString::Concat(rLayoutName) + SD_LT_SEPARATOR);
783 
784     for (sal_Int32 nLevel = 1; nLevel < 10; nLevel++)
785         aNameList.emplace_back(aPrefix + STR_LAYOUT_OUTLINE " " + OUString::number( nLevel ) );
786 
787     aNameList.emplace_back(aPrefix + STR_LAYOUT_TITLE);
788     aNameList.emplace_back(aPrefix + STR_LAYOUT_SUBTITLE);
789     aNameList.emplace_back(aPrefix + STR_LAYOUT_NOTES);
790     aNameList.emplace_back(aPrefix + STR_LAYOUT_BACKGROUNDOBJECTS);
791     aNameList.emplace_back(aPrefix + STR_LAYOUT_BACKGROUND);
792 }
793 
794 /*************************************************************************
795 |*
796 |* Create a list with pointer to presentation templates of a layout.
797 |* The list is owned by the caller!
798 |*
799 \************************************************************************/
800 
CreateLayoutSheetList(std::u16string_view rLayoutName,SdStyleSheetVector & rLayoutSheets)801 void SdStyleSheetPool::CreateLayoutSheetList(std::u16string_view rLayoutName, SdStyleSheetVector& rLayoutSheets )
802 {
803     OUString aLayoutNameWithSep(OUString::Concat(rLayoutName) + SD_LT_SEPARATOR);
804 
805     SfxStyleSheetIterator aIter(this, SfxStyleFamily::Page);
806     SfxStyleSheetBase* pSheet = aIter.First();
807 
808     while (pSheet)
809     {
810         if (pSheet->GetName().startsWith(aLayoutNameWithSep))
811             rLayoutSheets.emplace_back( static_cast< SdStyleSheet* >( pSheet ) );
812         pSheet = aIter.Next();
813     }
814 }
815 
816 /*************************************************************************
817 |*
818 |* Create pseudo style sheets if necessary
819 |*
820 \************************************************************************/
821 
CreatePseudosIfNecessary()822 void SdStyleSheetPool::CreatePseudosIfNecessary()
823 {
824     OUString aName;
825     const OUString aHelpFile;
826     SfxStyleSheetBase* pSheet = nullptr;
827     SfxStyleSheetBase* pParent = nullptr;
828 
829     SfxStyleSearchBits nUsedMask = SfxStyleSearchBits::Used;
830 
831     aName = SdResId(STR_PSEUDOSHEET_TITLE);
832     if( (pSheet = Find(aName, SfxStyleFamily::Pseudo)) == nullptr )
833     {
834         pSheet = &Make(aName, SfxStyleFamily::Pseudo, nUsedMask);
835         pSheet->SetParent( OUString() );
836         static_cast<SfxStyleSheet*>(pSheet)->StartListening(*this);
837     }
838     pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_TITLE );
839 
840     aName = SdResId(STR_PSEUDOSHEET_SUBTITLE);
841     if( (pSheet = Find(aName, SfxStyleFamily::Pseudo)) == nullptr )
842     {
843         pSheet = &Make(aName, SfxStyleFamily::Pseudo, nUsedMask);
844         pSheet->SetParent( OUString() );
845         static_cast<SfxStyleSheet*>(pSheet)->StartListening(*this);
846     }
847     pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_SUBTITLE );
848 
849     aName = SdResId(STR_PSEUDOSHEET_BACKGROUNDOBJECTS);
850     if( (pSheet = Find(aName, SfxStyleFamily::Pseudo)) == nullptr )
851     {
852         pSheet = &Make(aName, SfxStyleFamily::Pseudo, nUsedMask);
853         pSheet->SetParent( OUString() );
854         static_cast<SfxStyleSheet*>(pSheet)->StartListening(*this);
855     }
856     pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_BACKGROUNDOBJECTS );
857 
858     aName = SdResId(STR_PSEUDOSHEET_BACKGROUND);
859     if( (pSheet = Find(aName, SfxStyleFamily::Pseudo)) == nullptr )
860     {
861         pSheet = &Make(aName, SfxStyleFamily::Pseudo, nUsedMask);
862         pSheet->SetParent( OUString() );
863         static_cast<SfxStyleSheet*>(pSheet)->StartListening(*this);
864     }
865     pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_BACKGROUND );
866 
867     aName = SdResId(STR_PSEUDOSHEET_NOTES);
868     if( (pSheet = Find(aName, SfxStyleFamily::Pseudo)) == nullptr )
869     {
870         pSheet = &Make(aName, SfxStyleFamily::Pseudo, nUsedMask);
871         pSheet->SetParent( OUString() );
872         static_cast<SfxStyleSheet*>(pSheet)->StartListening(*this);
873     }
874     pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_NOTES );
875 
876     pParent = nullptr;
877     aName = SdResId(STR_PSEUDOSHEET_OUTLINE);
878     for (sal_Int32 nLevel = 1; nLevel < 10; nLevel++)
879     {
880         OUString aLevelName( aName + " " + OUString::number( nLevel ) );
881 
882         if( (pSheet = Find(aLevelName, SfxStyleFamily::Pseudo)) == nullptr )
883         {
884             pSheet = &Make(aLevelName, SfxStyleFamily::Pseudo, nUsedMask);
885 
886             if (pParent)
887                 pSheet->SetParent(pParent->GetName());
888             pParent = pSheet;
889             static_cast<SfxStyleSheet*>(pSheet)->StartListening(*this);
890         }
891         pSheet->SetHelpId( aHelpFile, HID_PSEUDOSHEET_OUTLINE + nLevel );
892     }
893 }
894 
895 /*************************************************************************
896 |*
897 |* Set the correct name in the program language to the standard styles
898 |*
899 \************************************************************************/
900 
901 namespace
902 {
903 struct StyleSheetIsUserDefinedPredicate : svl::StyleSheetPredicate
904 {
StyleSheetIsUserDefinedPredicate__anon42339b390411::StyleSheetIsUserDefinedPredicate905     StyleSheetIsUserDefinedPredicate()
906     {}
907 
Check__anon42339b390411::StyleSheetIsUserDefinedPredicate908     bool Check(const SfxStyleSheetBase& sheet) override
909     {
910         return sheet.IsUserDefined();
911     }
912 };
913 }
914 
UpdateStdNames()915 void SdStyleSheetPool::UpdateStdNames()
916 {
917     OUString aHelpFile;
918     StyleSheetIsUserDefinedPredicate aPredicate;
919     std::vector<SfxStyleSheetBase*> aEraseList;
920     std::vector<sal_Int32> aUserDefinedStyles = GetIndexedStyleSheets().FindPositionsByPredicate(aPredicate);
921     for (const auto& rStyle : aUserDefinedStyles)
922     {
923         SfxStyleSheetBase* pStyle = GetStyleSheetByPositionInIndex(rStyle);
924 
925         if( !pStyle->IsUserDefined() )
926         {
927             OUString aOldName   = pStyle->GetName();
928             sal_uLong nHelpId   = pStyle->GetHelpId( aHelpFile );
929             SfxStyleFamily eFam = pStyle->GetFamily();
930 
931             bool bHelpKnown = true;
932             const char* pNameId = nullptr;
933             switch( nHelpId )
934             {
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;
962 
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;
975 
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;
982 
983                 default:
984                     // 0 or wrong (old) HelpId
985                     bHelpKnown = false;
986             }
987             if( bHelpKnown )
988             {
989                 OUString aNewName;
990                 if (pNameId)
991                 {
992                     if (strcmp(pNameId, STR_PSEUDOSHEET_OUTLINE) == 0)
993                     {
994                         aNewName += " " + OUString::number( sal_Int32( nHelpId - HID_PSEUDOSHEET_OUTLINE ) );
995                     }
996                 }
997 
998                 if( !aNewName.isEmpty() && aNewName != aOldName )
999                 {
1000                     SfxStyleSheetBase* pSheetFound = Find( aNewName, eFam );
1001 
1002                     if ( !pSheetFound )
1003                     {
1004                         // Sheet does not yet exist: rename old sheet
1005                         pStyle->SetName( aNewName );    // transform also parents
1006                     }
1007                     else
1008                     {
1009                         // Sheet does exist: old sheet has to be removed
1010                         aEraseList.push_back( pStyle );
1011                     }
1012                 }
1013             }
1014         }
1015     }
1016 
1017     if (!aEraseList.empty())
1018     {
1019         // styles that could not be renamed, must be removed
1020         for (SfxStyleSheetBase* p : aEraseList)
1021             Remove( p );
1022         Reindex();
1023     }
1024 }
1025 
setDefaultOutlineNumberFormatBulletAndIndent(sal_uInt16 i,SvxNumberFormat & rNumberFormat)1026 void SdStyleSheetPool::setDefaultOutlineNumberFormatBulletAndIndent(sal_uInt16 i, SvxNumberFormat &rNumberFormat)
1027 {
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;
1033 
1034     switch(i)
1035     {
1036         case 0:
1037         {
1038             nFirstLineOffset = -900;
1039         }
1040         break;
1041 
1042         case 1:
1043         {
1044             rNumberFormat.SetBulletChar( 0x2013 );  // StarBats: 0xF000 + 150
1045             rNumberFormat.SetBulletRelSize(75);
1046             nFirstLineOffset = -900;
1047         }
1048         break;
1049 
1050         case 2:
1051         {
1052             nFirstLineOffset = -800;
1053         }
1054         break;
1055 
1056         case 3:
1057         {
1058             rNumberFormat.SetBulletChar( 0x2013 );  // StarBats: 0xF000 + 150
1059             rNumberFormat.SetBulletRelSize(75);
1060         }
1061         break;
1062     }
1063 
1064     rNumberFormat.SetFirstLineOffset(nFirstLineOffset);
1065 }
1066 
1067 // Set new SvxNumBulletItem for the respective style sheet
PutNumBulletItem(SfxStyleSheetBase * pSheet,vcl::Font & rBulletFont)1068 void SdStyleSheetPool::PutNumBulletItem( SfxStyleSheetBase* pSheet,
1069                                          vcl::Font& rBulletFont )
1070 {
1071     OUString aHelpFile;
1072     sal_uLong nHelpId = pSheet->GetHelpId( aHelpFile );
1073     SfxItemSet& rSet = pSheet->GetItemSet();
1074 
1075     switch ( nHelpId )
1076     {
1077         case HID_STANDARD_STYLESHEET_NAME :
1078         {
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);
1087 
1088             SvxNumRule aNumRule( SvxNumRuleFlags::BULLET_REL_SIZE | SvxNumRuleFlags::BULLET_COLOR, SVX_MAX_NUM, false);
1089 
1090             for( sal_uInt16 i = 0; i < aNumRule.GetLevelCount(); i++ )
1091             {
1092                 const auto nLSpace = (i + 1) * 600;
1093                 aNumberFormat.SetAbsLSpace(nLSpace);
1094                 aNumberFormat.SetFirstLineOffset(-600);
1095                 aNumRule.SetLevel( i, aNumberFormat );
1096             }
1097 
1098             rSet.Put( SvxNumBulletItem( aNumRule, EE_PARA_NUMBULLET ) );
1099             static_cast<SfxStyleSheet*>(pSheet)->Broadcast(SfxHint( SfxHintId::DataChanged ) );
1100         }
1101         break;
1102 
1103         case HID_PSEUDOSHEET_TITLE:
1104             /* title gets same bullet as subtitle and not that page symbol anymore */
1105         case HID_PSEUDOSHEET_SUBTITLE :
1106         {
1107             // Subtitle template
1108             SvxNumBulletItem const*const pItem(
1109                     rSet.GetPool()->GetSecondaryPool()->GetPoolDefaultItem(EE_PARA_NUMBULLET));
1110             const SvxNumRule *const pDefaultRule = pItem ? &pItem->GetNumRule() : nullptr;
1111             DBG_ASSERT( pDefaultRule, "Where is my default template? [CL]" );
1112 
1113             if(pDefaultRule)
1114             {
1115                 SvxNumRule aNumRule(pDefaultRule->GetFeatureFlags(), 10, false);
1116                 for(sal_uInt16 i=0; i < aNumRule.GetLevelCount(); i++)
1117                 {
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);
1128                 }
1129 
1130                 rSet.Put( SvxNumBulletItem( aNumRule, EE_PARA_NUMBULLET ) );
1131                 static_cast<SfxStyleSheet*>(pSheet)->Broadcast(SfxHint( SfxHintId::DataChanged ) );
1132             }
1133         }
1134         break;
1135 
1136         case HID_PSEUDOSHEET_OUTLINE + 1 :
1137         {
1138             // Outline template
1139             SvxNumberFormat aNumberFormat(SVX_NUM_CHAR_SPECIAL);
1140             aNumberFormat.SetBulletColor(COL_AUTO);
1141             aNumberFormat.SetStart(1);
1142             aNumberFormat.SetNumAdjust(SvxAdjust::Left);
1143 
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++ )
1147             {
1148                 setDefaultOutlineNumberFormatBulletAndIndent(i, aNumberFormat);
1149                 rBulletFont.SetFontSize(Size(0,846));       // 24 pt
1150                 aNumberFormat.SetBulletFont(&rBulletFont);
1151                 aNumRule.SetLevel( i, aNumberFormat );
1152             }
1153 
1154             rSet.Put( SvxNumBulletItem( aNumRule, EE_PARA_NUMBULLET ) );
1155             static_cast<SfxStyleSheet*>(pSheet)->Broadcast(SfxHint( SfxHintId::DataChanged ) );
1156         }
1157         break;
1158     }
1159 }
1160 
1161 /*************************************************************************
1162 |*
1163 |* Create standard bullet font (without size)
1164 |*
1165 \************************************************************************/
1166 
GetBulletFont()1167 vcl::Font SdStyleSheetPool::GetBulletFont()
1168 {
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);
1180 
1181     return aBulletFont;
1182 }
1183 
AddStyleFamily(const SdPage * pPage)1184 void SdStyleSheetPool::AddStyleFamily( const SdPage* pPage )
1185 {
1186     rtl::Reference< SfxStyleSheetPool > xPool( this );
1187     maStyleFamilyMap[pPage] = new SdStyleFamily( xPool, pPage );
1188 }
1189 
RemoveStyleFamily(const SdPage * pPage)1190 void SdStyleSheetPool::RemoveStyleFamily( const SdPage* pPage )
1191 {
1192     SdStyleFamilyMap::iterator iter( maStyleFamilyMap.find( pPage ) );
1193     if( iter == maStyleFamilyMap.end() )
1194         return;
1195 
1196     SdStyleFamilyRef xStyle( (*iter).second );
1197     maStyleFamilyMap.erase( iter );
1198 
1199     if( xStyle.is() ) try
1200     {
1201         xStyle->dispose();
1202     }
1203     catch( Exception& )
1204     {
1205     }
1206 }
1207 
throwIfDisposed()1208 void SdStyleSheetPool::throwIfDisposed()
1209 {
1210     if( mpDoc == nullptr )
1211         throw DisposedException();
1212 }
1213 
1214 // XServiceInfo
getImplementationName()1215 OUString SAL_CALL SdStyleSheetPool::getImplementationName()
1216 {
1217     return "SdStyleSheetPool";
1218 }
1219 
supportsService(const OUString & ServiceName)1220 sal_Bool SAL_CALL SdStyleSheetPool::supportsService( const OUString& ServiceName )
1221 {
1222     return cppu::supportsService(this, ServiceName);
1223 }
1224 
getSupportedServiceNames()1225 Sequence< OUString > SAL_CALL SdStyleSheetPool::getSupportedServiceNames()
1226 {
1227     return { "com.sun.star.style.StyleFamilies" };
1228 }
1229 
1230 // XNameAccess
getByName(const OUString & aName)1231 Any SAL_CALL SdStyleSheetPool::getByName( const OUString& aName )
1232 {
1233     throwIfDisposed();
1234 
1235     if( mxGraphicFamily->getName() == aName )
1236         return Any( Reference< XNameAccess >( static_cast< XNameAccess* >( mxGraphicFamily.get() ) ) );
1237 
1238     if( mxCellFamily->getName() == aName )
1239         return Any( Reference< XNameAccess >( static_cast< XNameAccess* >( mxCellFamily.get() ) ) );
1240 
1241     if( msTableFamilyName == aName )
1242         return Any( mxTableFamily );
1243 
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() ) ) );
1248 
1249     throw NoSuchElementException();
1250 }
1251 
getElementNames()1252 Sequence< OUString > SAL_CALL SdStyleSheetPool::getElementNames()
1253 {
1254     throwIfDisposed();
1255 
1256     Sequence< OUString > aNames( maStyleFamilyMap.size() + 3 );
1257     OUString* pNames = aNames.getArray();
1258 
1259     *pNames++ = mxGraphicFamily->getName();
1260     *pNames++ = mxCellFamily->getName();
1261     *pNames++ = msTableFamilyName;
1262 
1263     for( const auto& rEntry : maStyleFamilyMap )
1264     {
1265         *pNames++ = rEntry.second->getName();
1266     }
1267 
1268     return aNames;
1269 }
1270 
hasByName(const OUString & aName)1271 sal_Bool SAL_CALL SdStyleSheetPool::hasByName( const OUString& aName )
1272 {
1273     throwIfDisposed();
1274 
1275     if( mxGraphicFamily->getName() == aName )
1276         return true;
1277 
1278     if( mxCellFamily->getName() == aName )
1279         return true;
1280 
1281     if( msTableFamilyName == aName )
1282         return true;
1283 
1284     return std::any_of(maStyleFamilyMap.begin(), maStyleFamilyMap.end(),
1285         [&aName](const SdStyleFamilyMap::value_type& rEntry) { return rEntry.second->getName() == aName; });
1286 }
1287 
1288 // XElementAccess
1289 
getElementType()1290 Type SAL_CALL SdStyleSheetPool::getElementType()
1291 {
1292     throwIfDisposed();
1293 
1294     return cppu::UnoType<XNameAccess>::get();
1295 }
1296 
hasElements()1297 sal_Bool SAL_CALL SdStyleSheetPool::hasElements()
1298 {
1299     return true;
1300 }
1301 
1302 // XIndexAccess
1303 
getCount()1304 sal_Int32 SAL_CALL SdStyleSheetPool::getCount()
1305 {
1306     throwIfDisposed();
1307 
1308     return maStyleFamilyMap.size() + 3;
1309 }
1310 
getByIndex(sal_Int32 Index)1311 Any SAL_CALL SdStyleSheetPool::getByIndex( sal_Int32 Index )
1312 {
1313     switch( Index )
1314     {
1315     case 0:
1316         return Any( Reference< XNameAccess >( static_cast< XNameAccess* >( mxGraphicFamily.get() ) ) );
1317 
1318     case 1:
1319         return Any( Reference< XNameAccess >( static_cast< XNameAccess* >( mxCellFamily.get() ) ) );
1320 
1321     case 2:
1322         return Any( mxTableFamily );
1323 
1324     default:
1325         {
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);
1331 
1332             return Any( Reference< XNameAccess >( static_cast< XNameAccess* >( (*iter).second.get() ) ) );
1333         }
1334     }
1335 }
1336 
1337 // XComponent
1338 
dispose()1339 void SAL_CALL SdStyleSheetPool::dispose()
1340 {
1341     if( !mpDoc )
1342         return;
1343 
1344     mxGraphicFamily->dispose();
1345     mxGraphicFamily.clear();
1346     mxCellFamily->dispose();
1347     mxCellFamily.clear();
1348 
1349     Reference< XComponent > xComp( mxTableFamily, UNO_QUERY );
1350     if( xComp.is() )
1351         xComp->dispose();
1352     mxTableFamily = nullptr;
1353 
1354     SdStyleFamilyMap aTempMap;
1355     aTempMap.swap( maStyleFamilyMap );
1356 
1357     for( auto& rEntry : aTempMap ) try
1358     {
1359         rEntry.second->dispose();
1360     }
1361     catch( Exception& )
1362     {
1363     }
1364 
1365     mpDoc = nullptr;
1366 
1367     Clear();
1368 }
1369 
addEventListener(const Reference<XEventListener> &)1370 void SAL_CALL SdStyleSheetPool::addEventListener( const Reference< XEventListener >& /*xListener*/ )
1371 {
1372 }
1373 
removeEventListener(const Reference<XEventListener> &)1374 void SAL_CALL SdStyleSheetPool::removeEventListener( const Reference< XEventListener >& /*aListener*/ )
1375 {
1376 }
1377 
CreateChildList(SdStyleSheet const * pSheet)1378 SdStyleSheetVector SdStyleSheetPool::CreateChildList( SdStyleSheet const * pSheet )
1379 {
1380     SdStyleSheetVector aResult;
1381 
1382     const size_t nListenerCount = pSheet->GetSizeOfVector();
1383     for (size_t n = 0; n < nListenerCount; ++n)
1384     {
1385         SdStyleSheet* pChild = dynamic_cast< SdStyleSheet* >( pSheet->GetListener(n) );
1386         if(pChild && pChild->GetParent() == pSheet->GetName())
1387         {
1388             aResult.emplace_back( pChild );
1389         }
1390     }
1391 
1392     return aResult;
1393 }
1394 
1395 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1396