xref: /core/sd/source/core/drawdoc4.cxx (revision 599ab8dc3ae9d8b8749b6400e87d98a6dad2a03c)
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 <sal/config.h>
21 #include <config_folders.h>
22 
23 #include <com/sun/star/style/XStyle.hpp>
24 #include <com/sun/star/drawing/LineStyle.hpp>
25 #include <com/sun/star/form/XReset.hpp>
26 #include <com/sun/star/document/XImporter.hpp>
27 #include <com/sun/star/uno/XComponentContext.hpp>
28 #include <com/sun/star/xml/sax/XFastParser.hpp>
29 #include <i18nlangtag/languagetag.hxx>
30 #include <i18nlangtag/mslangid.hxx>
31 #include <sfx2/dispatch.hxx>
32 #include <Outliner.hxx>
33 #include <editeng/outliner.hxx>
34 
35 #include <DrawDocShell.hxx>
36 #include <editeng/eeitem.hxx>
37 #include <comphelper/diagnose_ex.hxx>
38 #include <comphelper/processfactory.hxx>
39 #include <comphelper/propertyvalue.hxx>
40 #include <rtl/bootstrap.hxx>
41 #include <comphelper/configuration.hxx>
42 #include <unotools/streamwrap.hxx>
43 #include <tools/stream.hxx>
44 #include <tools/UnitConversion.hxx>
45 
46 #include <vcl/idle.hxx>
47 #include <vcl/settings.hxx>
48 #include <vcl/svapp.hxx>
49 
50 #include <editeng/autokernitem.hxx>
51 
52 #include <svx/svxids.hrc>
53 #include <svl/srchitem.hxx>
54 #include <editeng/lrspitem.hxx>
55 #include <editeng/ulspitem.hxx>
56 #include <editeng/lspcitem.hxx>
57 #include <editeng/adjustitem.hxx>
58 #include <editeng/numdef.hxx>
59 #include <svx/strings.hrc>
60 #include <svx/dialmgr.hxx>
61 #include <editeng/bulletitem.hxx>
62 #include <editeng/borderline.hxx>
63 #include <editeng/boxitem.hxx>
64 #include <svx/xlineit0.hxx>
65 #include <svx/sdshitm.hxx>
66 #include <svx/svdotext.hxx>
67 #include <svx/xfillit0.hxx>
68 #include <svx/sdshcitm.hxx>
69 #include <editeng/editstat.hxx>
70 #include <editeng/colritem.hxx>
71 #include <editeng/fhgtitem.hxx>
72 #include <editeng/wghtitem.hxx>
73 #include <editeng/postitem.hxx>
74 #include <editeng/crossedoutitem.hxx>
75 #include <editeng/udlnitem.hxx>
76 #include <editeng/contouritem.hxx>
77 #include <editeng/emphasismarkitem.hxx>
78 #include <editeng/fontitem.hxx>
79 #include <editeng/shdditem.hxx>
80 #include <editeng/cmapitem.hxx>
81 #include <svx/xbtmpit.hxx>
82 #include <svx/xflhtit.hxx>
83 #include <svx/xflgrit.hxx>
84 #include <svx/xflclit.hxx>
85 #include <svx/xlnedcit.hxx>
86 #include <svx/xlnstcit.hxx>
87 #include <svx/xlnedwit.hxx>
88 #include <svx/xlnstwit.hxx>
89 #include <svx/xlnedit.hxx>
90 #include <editeng/charreliefitem.hxx>
91 #include <svx/xlnstit.hxx>
92 #include <svx/xlndsit.hxx>
93 #include <svx/xlnwtit.hxx>
94 #include <svx/xlnclit.hxx>
95 #include <svx/svditer.hxx>
96 #include <svx/svdogrp.hxx>
97 #include <svx/sdsxyitm.hxx>
98 #include <svx/sdtditm.hxx>
99 #include <svx/sdtaitm.hxx>
100 #include <svx/sdynitm.hxx>
101 #include <editeng/numitem.hxx>
102 #include <editeng/unolingu.hxx>
103 #include <svl/itempool.hxx>
104 #include <editeng/outlobj.hxx>
105 #include <sfx2/viewfrm.hxx>
106 #include <editeng/frmdiritem.hxx>
107 #include <svx/sdasitm.hxx>
108 
109 #include <sdresid.hxx>
110 #include <drawdoc.hxx>
111 #include <sdpage.hxx>
112 #include <strings.hrc>
113 #include <glob.hxx>
114 #include <stlpool.hxx>
115 #include <shapelist.hxx>
116 #include <basegfx/point/b2dpoint.hxx>
117 #include <basegfx/polygon/b2dpolygon.hxx>
118 #include <svl/itemset.hxx>
119 #include <app.hrc>
120 #include <strings.hxx>
121 
122 namespace com::sun::star::linguistic2 { class XHyphenator; }
123 
124 using namespace ::com::sun::star;
125 using namespace ::com::sun::star::uno;
126 using namespace ::com::sun::star::lang;
127 using namespace ::com::sun::star::style;
128 using namespace ::com::sun::star::linguistic2;
129 using namespace ::sd;
130 
131 // CreateLayoutTemplates
132 // At the moment (31.03.1995), the StyleSheetPool only saves styleheets that
133 // have an ItemSet. To save all stylesheets, we force the creation of an ItemSet
134 // with a GetItemSet call.
135 // We can remove this behavior once the pool saves styleheets even without an ItemSet
CreateLayoutTemplates()136 void SdDrawDocument::CreateLayoutTemplates()
137 {
138     SdStyleSheetPool*       pSSPool = static_cast<SdStyleSheetPool*>(GetStyleSheetPool());
139     SfxStyleSheetBase*      pSheet = nullptr;
140     const OUString          aHelpFile;
141     OUString                aStdName(SdResId(STR_STANDARD_STYLESHEET_NAME));
142 
143     // Default style
144 
145     SfxStyleSearchBits nMask = SfxStyleSearchBits::Auto;
146 
147     OUString aName(aStdName);
148     pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
149     pSheet->SetHelpId( aHelpFile, HID_STANDARD_STYLESHEET_NAME );
150     SfxItemSet& rISet = pSheet->GetItemSet();
151 
152     Color    aNullCol(COL_DEFAULT_SHAPE_STROKE);
153 
154     XDash     aNullDash;
155     basegfx::BGradient aNullGrad(
156         basegfx::BColorStops(
157             aNullCol.getBColor(),
158             COL_WHITE.getBColor()));
159     aNullGrad.SetStartIntens( 100 );
160     aNullGrad.SetEndIntens( 100 );
161     XHatch    aNullHatch(aNullCol);
162 
163                     // Line attributes (Extended OutputDevice)
164     rISet.Put(XLineStyleItem(drawing::LineStyle_SOLID));
165     rISet.Put(XLineColorItem(OUString(), COL_DEFAULT_SHAPE_STROKE));
166     rISet.Put(XLineWidthItem(0));
167     rISet.Put(XLineDashItem(aNullDash));
168     rISet.Put(XLineStartItem(basegfx::B2DPolyPolygon()));
169     rISet.Put(XLineEndItem(basegfx::B2DPolyPolygon()));
170     rISet.Put(XLineStartWidthItem(200));
171     rISet.Put(XLineEndWidthItem(200));
172     rISet.Put(XLineStartCenterItem());
173     rISet.Put(XLineEndCenterItem());
174     rISet.Put(SdrTextHorzAdjustItem(SDRTEXTHORZADJUST_BLOCK));
175 
176                     // Fill attributes (Extended OutputDevice)
177     rISet.Put(XFillStyleItem(drawing::FillStyle_SOLID));
178     rISet.Put(XFillColorItem(OUString(), COL_DEFAULT_SHAPE_FILLING));
179 
180     rISet.Put( XFillGradientItem( aNullGrad) );
181     rISet.Put(XFillHatchItem(aNullHatch));
182     Size    aNullSize( 32, 32 );
183     Bitmap aNullBmp(aNullSize, vcl::PixelFormat::N8_BPP);
184     aNullBmp.Erase( COL_WHITE );
185     rISet.Put(XFillBitmapItem(Graphic(BitmapEx(aNullBmp))));
186 
187                     // Shadow attributes (Drawing Engine)
188     rISet.Put(makeSdrShadowItem(false));
189     rISet.Put(makeSdrShadowColorItem(COL_GRAY));
190     rISet.Put(makeSdrShadowXDistItem(200));         // 3 mm Shadow distance
191     rISet.Put(makeSdrShadowYDistItem(200));
192 
193     vcl::Font aLatinFont, aCJKFont, aCTLFont;
194 
195     getDefaultFonts( aLatinFont, aCJKFont, aCTLFont );
196 
197     SvxFontItem aSvxFontItem( aLatinFont.GetFamilyTypeMaybeAskConfig(), aLatinFont.GetFamilyName(), aLatinFont.GetStyleName(), aLatinFont.GetPitchMaybeAskConfig(),
198                               aLatinFont.GetCharSet(), EE_CHAR_FONTINFO );
199 
200     SvxFontItem aSvxFontItemCJK( aCJKFont.GetFamilyTypeMaybeAskConfig(), aCJKFont.GetFamilyName(), aCJKFont.GetStyleName(), aCJKFont.GetPitchMaybeAskConfig(),
201                                  aCJKFont.GetCharSet(), EE_CHAR_FONTINFO_CJK );
202 
203     SvxFontItem aSvxFontItemCTL( aCTLFont.GetFamilyTypeMaybeAskConfig(), aCTLFont.GetFamilyName(), aCTLFont.GetStyleName(), aCTLFont.GetPitchMaybeAskConfig(),
204                                  aCTLFont.GetCharSet(), EE_CHAR_FONTINFO_CTL );
205 
206     rISet.Put( aSvxFontItem );
207     rISet.Put( aSvxFontItemCJK );
208     rISet.Put( aSvxFontItemCTL );
209 
210     rISet.Put( SvxFontHeightItem( 635, 100, EE_CHAR_FONTHEIGHT ) );     // sj: (i33745) changed default from 24 to 18 pt
211     rISet.Put( SvxFontHeightItem( 635, 100, EE_CHAR_FONTHEIGHT_CJK ) ); // 18 pt
212     rISet.Put( SvxFontHeightItem( convertFontHeightToCTL( 635 ), 100, EE_CHAR_FONTHEIGHT_CTL ) ); // 18 pt
213 
214     rISet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT ) );
215     rISet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CJK ) );
216     rISet.Put( SvxWeightItem( WEIGHT_NORMAL, EE_CHAR_WEIGHT_CTL ) );
217 
218     rISet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC ) );
219     rISet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CJK ) );
220     rISet.Put( SvxPostureItem( ITALIC_NONE, EE_CHAR_ITALIC_CTL ) );
221 
222     rISet.Put(SvxContourItem(false, EE_CHAR_OUTLINE ));
223     rISet.Put(SvxShadowedItem(false, EE_CHAR_SHADOW ));
224     rISet.Put(SvxUnderlineItem(LINESTYLE_NONE, EE_CHAR_UNDERLINE));
225     rISet.Put(SvxOverlineItem(LINESTYLE_NONE, EE_CHAR_OVERLINE));
226     rISet.Put(SvxCrossedOutItem(STRIKEOUT_NONE, EE_CHAR_STRIKEOUT ));
227     rISet.Put(SvxCaseMapItem(SvxCaseMap::NotMapped, EE_CHAR_CASEMAP ));
228     rISet.Put(SvxEmphasisMarkItem(FontEmphasisMark::NONE, EE_CHAR_EMPHASISMARK));
229     rISet.Put(SvxCharReliefItem(FontRelief::NONE, EE_CHAR_RELIEF));
230     rISet.Put(SvxColorItem(COL_AUTO, EE_CHAR_COLOR ));
231 
232     // Paragraph attributes (Edit Engine)
233     rISet.Put(SvxLRSpaceItem(EE_PARA_LRSPACE));
234     rISet.Put(SvxULSpaceItem(EE_PARA_ULSPACE));
235 
236     rISet.Put( makeSdrTextLeftDistItem( 250 ) );    // sj: (i33745) using text frame distances seems to be a better default
237     rISet.Put( makeSdrTextRightDistItem( 250 ) );
238     rISet.Put( makeSdrTextUpperDistItem( 125 ) );
239     rISet.Put( makeSdrTextLowerDistItem( 125 ) );
240 
241     // Set Word-wrap to true by default
242     rISet.Put( makeSdrTextWordWrapItem(true) );
243 
244     rISet.Put( SvxLineSpacingItem( LINE_SPACE_DEFAULT_HEIGHT, EE_PARA_SBL ) );
245 
246     // #i16874# enable kerning by default but only for new documents
247     rISet.Put( SvxAutoKernItem( true, EE_CHAR_PAIRKERNING ) );
248 
249     // Bullet
250     // BulletItem and BulletFont for title and outline
251     SvxBulletItem aBulletItem(EE_PARA_BULLET);
252                             // Identical in all layers
253     aBulletItem.SetStyle(SvxBulletStyle::BULLET);
254     aBulletItem.SetStart(1);
255     aBulletItem.SetScale(45);           // In percent
256 
257     vcl::Font aBulletFont( SdStyleSheetPool::GetBulletFont() );
258 
259     aBulletFont.SetFontSize(Size(0,635));   // sj: (i33745) changed default from 24 to 18 pt
260 
261     aBulletItem.SetFont(aBulletFont);
262     aBulletItem.SetSymbol( 0x25CF );                    // In points
263     rISet.Put(aBulletItem);
264 
265     // New BulletItem
266     SdStyleSheetPool::PutNumBulletItem( pSheet, aBulletFont );
267 
268     SfxItemSet* pISet = nullptr;
269 
270     // Default > Object without filling
271     {
272         aName = SdResId(STR_POOLSHEET_OBJWITHOUTFILL);
273         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
274         pSheet->SetParent(aStdName);
275         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_OBJWITHOUTFILL );
276         pISet = &pSheet->GetItemSet();
277 
278         pISet->Put(XFillStyleItem(drawing::FillStyle_NONE));
279     }
280     // Default > Object no fill no line
281     {
282         aName = SdResId(STR_POOLSHEET_OBJNOLINENOFILL);
283         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
284         pSheet->SetParent(aStdName);
285         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_OBJNOLINENOFILL );
286         pISet = &pSheet->GetItemSet();
287 
288         pISet->Put(XFillStyleItem(drawing::FillStyle_NONE));
289         pISet->Put(XLineStyleItem(drawing::LineStyle_NONE));
290     }
291 
292     // tdf#94369
293 
294     // Text
295     OUString aTextName;
296     {
297         aTextName = SdResId(STR_POOLSHEET_TEXT);
298         pSheet = &(pSSPool->Make(aTextName, SfxStyleFamily::Para, nMask));
299         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_TEXT );
300         pISet = &pSheet->GetItemSet();
301         aSvxFontItem.SetFamilyName(u"Noto Sans"_ustr);
302         pISet->Put( aSvxFontItem );                                        // Noto Sans
303         pISet->Put(XFillStyleItem(drawing::FillStyle_SOLID));              // solid fill
304         pISet->Put(XFillColorItem(OUString(), Color(0xeeeeee)));           // light gray 5
305         pISet->Put(XLineStyleItem(drawing::LineStyle_SOLID));              // solid fill
306         pISet->Put(XLineColorItem(OUString(), Color(0xcccccc)));           // light gray 3
307     }
308     // Text > A4
309     OUString aA4Name;
310     {
311         aA4Name = SdResId(STR_POOLSHEET_A4);
312         pSheet = &(pSSPool->Make(aA4Name, SfxStyleFamily::Para, nMask));
313         pSheet->SetParent( aTextName );
314         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_A4 );
315         pISet = &pSheet->GetItemSet();
316         pISet->Put(SvxFontHeightItem(635, 100, EE_CHAR_FONTHEIGHT ));      // 18 pt
317         pISet->Put(XFillStyleItem(drawing::FillStyle_NONE));               // no filling
318     }
319     // Text > A4 > Title
320     {
321 
322         aName = SdResId(STR_POOLSHEET_A4_TITLE);
323         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
324         pSheet->SetParent( aA4Name );
325         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_A4_TITLE );
326         pISet = &pSheet->GetItemSet();
327         pISet->Put(SvxFontHeightItem(1551, 100, EE_CHAR_FONTHEIGHT ));     // 44 pt
328         pISet->Put(XLineStyleItem(drawing::LineStyle_NONE));               // no border
329     }
330     // Text > A4 > Headline
331     {
332         aName = SdResId(STR_POOLSHEET_A4_HEADLINE);
333         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
334         pSheet->SetParent( aA4Name );
335         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_A4_HEADLINE );
336         pISet = &pSheet->GetItemSet();
337         pISet->Put(SvxFontHeightItem(847, 100, EE_CHAR_FONTHEIGHT ));      // 24 pt
338         pISet->Put(XLineStyleItem(drawing::LineStyle_NONE));               // no border
339     }
340     // Text > A4 > Text
341     {
342         aName = SdResId(STR_POOLSHEET_A4_TEXT);
343         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
344         pSheet->SetParent(aA4Name);
345         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_A4_TEXT );
346         pISet = &pSheet->GetItemSet();
347         pISet->Put(XLineStyleItem(drawing::LineStyle_NONE));               // no border
348     }
349     // Text > A0
350     OUString aA0Name;
351     {
352         aA0Name = SdResId(STR_POOLSHEET_A0);
353         pSheet = &(pSSPool->Make(aA0Name, SfxStyleFamily::Para, nMask));
354         pSheet->SetParent(aTextName);
355         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_A0 );
356         pISet = &pSheet->GetItemSet();
357         pISet->Put(SvxFontHeightItem(1692, 100, EE_CHAR_FONTHEIGHT ));     // 48 pt
358         pISet->Put(XFillStyleItem(drawing::FillStyle_NONE));               // no filling
359     }
360     // Text > A0 > Title
361     {
362         aName = SdResId(STR_POOLSHEET_A0_TITLE);
363         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
364         pSheet->SetParent(aA0Name);
365         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_A0_TITLE );
366         pISet = &pSheet->GetItemSet();
367         pISet->Put(SvxFontHeightItem(3385, 100, EE_CHAR_FONTHEIGHT ));      // 96 pt
368         pISet->Put(XLineStyleItem(drawing::LineStyle_NONE));               // no border
369     }
370     // Text > A0 > Headline
371     {
372         aName = SdResId(STR_POOLSHEET_A0_HEADLINE);
373         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
374         pSheet->SetParent(aA0Name);
375         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_A0_HEADLINE );
376         pISet = &pSheet->GetItemSet();
377         pISet->Put(SvxFontHeightItem(2538, 100, EE_CHAR_FONTHEIGHT ));       // 72 pt
378         pISet->Put(XLineStyleItem(drawing::LineStyle_NONE));               // no border
379     }
380     // Text > A0 > Text
381     {
382         aName = SdResId(STR_POOLSHEET_A0_TEXT);
383         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
384         pSheet->SetParent(aA0Name);
385         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_A0_TEXT );
386         pISet = &pSheet->GetItemSet();
387         pISet->Put(XLineStyleItem(drawing::LineStyle_NONE));               // no border
388     }
389 
390     // Graphic
391     OUString aGraphicName;
392     XFillGradientItem aFillGradient;
393     basegfx::BGradient aGradient;
394 
395     {
396         aGraphicName = SdResId(STR_POOLSHEET_GRAPHIC);
397         pSheet = &(pSSPool->Make(aGraphicName, SfxStyleFamily::Para, nMask));
398         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_GRAPHIC );
399         pISet = &pSheet->GetItemSet();
400         aSvxFontItem.SetFamilyName(u"Liberation Sans"_ustr);                     // Liberation Sans
401         pISet->Put( aSvxFontItem );
402         pISet->Put( SvxFontHeightItem(635, 100, EE_CHAR_FONTHEIGHT) );     // 18 pt
403         pISet->Put( XFillStyleItem(drawing::FillStyle_SOLID) );            // solid fill
404         pISet->Put( XFillColorItem(OUString(), COL_WHITE) );               // filled white
405 
406     }
407     // Graphic > Shapes
408     OUString aShapesName;
409     {
410         aShapesName = SdResId(STR_POOLSHEET_SHAPES);
411         pSheet = &(pSSPool->Make(aShapesName, SfxStyleFamily::Para, nMask));
412         pSheet->SetParent( aGraphicName );
413         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_SHAPES);
414         pISet = &pSheet->GetItemSet();
415         pISet->Put(XFillStyleItem(drawing::FillStyle_GRADIENT));           // fill with gradient
416         aGradient.SetGradientStyle( ::awt::GradientStyle_RECT);            // square type
417         aGradient.SetAngle( 0_deg10 );                                 // 0° angle
418 
419         aGradient.SetColorStops(
420             basegfx::BColorStops(
421                 Color(0xcccccc).getBColor(),    // light gray 3
422                 COL_WHITE.getBColor())); // white
423 
424         aFillGradient.SetName( aShapesName );
425         aFillGradient.SetGradientValue(aGradient);
426         pISet->Put( aFillGradient );
427         pISet->Put( XLineStyleItem(drawing::LineStyle_NONE) );             // no border
428         pISet->Put( SvxFontHeightItem(494, 100, EE_CHAR_FONTHEIGHT) );     // 14 pt
429         pISet->Put( SvxWeightItem(WEIGHT_BOLD, EE_CHAR_WEIGHT) );          // bold
430     }
431     // Graphic > Shapes > Filled
432     OUString  aFilledName(SdResId(STR_POOLSHEET_FILLED));
433     {
434         aName = aFilledName;
435         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
436         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_FILLED );
437         pSheet->SetParent( aShapesName );
438         pISet = &pSheet->GetItemSet();
439 
440         aGradient.SetGradientStyle( ::awt::GradientStyle_LINEAR );
441         aGradient.SetAngle( 300_deg10 );
442 
443         aGradient.SetColorStops(
444             basegfx::BColorStops(
445                 COL_WHITE.getBColor(),  // white
446                 Color(0xcccccc).getBColor())); // light gray 3
447 
448         aFillGradient.SetName( aName );
449         aFillGradient.SetGradientValue(aGradient);
450         pISet->Put( XFillStyleItem(drawing::FillStyle_GRADIENT) );
451         pISet->Put( aFillGradient );
452     }
453     // Graphic > Shapes > Filled > Blue
454     {
455         aName =SdResId(STR_POOLSHEET_FILLED_BLUE);
456         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
457         pSheet->SetParent(aFilledName);
458         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_FILLED_BLUE );
459         pISet = &pSheet->GetItemSet();
460 
461         aGradient.SetColorStops(
462             basegfx::BColorStops(
463                 Color(0x00729fcf).getBColor(),   // light blue 2
464                 Color(0x00355269).getBColor())); // dark blue 2
465 
466         aFillGradient.SetName( aName );
467         aFillGradient.SetGradientValue(aGradient);
468         pISet->Put( aFillGradient );
469         pISet->Put( SvxColorItem(COL_WHITE, EE_CHAR_COLOR ));           // font white
470     }
471     // Graphic > Shapes > Filled > Green
472     {
473         aName =SdResId(STR_POOLSHEET_FILLED_GREEN);
474         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
475         pSheet->SetParent(aFilledName);
476         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_FILLED_GREEN );
477         pISet = &pSheet->GetItemSet();
478 
479         aGradient.SetColorStops(
480             basegfx::BColorStops(
481                 Color(0x0077bc65).getBColor(),   // light green 2
482                 Color(0x00127622).getBColor())); // dark green 2
483 
484         aFillGradient.SetName( aName );
485         aFillGradient.SetGradientValue(aGradient);
486         pISet->Put( aFillGradient );
487         pISet->Put( aSvxFontItem );                                     // font name
488         pISet->Put( SvxColorItem(COL_WHITE, EE_CHAR_COLOR ));           // font white
489     }
490     // Graphic > Shapes > Filled > Red
491     {
492         aName =SdResId(STR_POOLSHEET_FILLED_RED);
493         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
494         pSheet->SetParent(aFilledName);
495         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_FILLED_RED );
496         pISet = &pSheet->GetItemSet();
497 
498         aGradient.SetColorStops(
499             basegfx::BColorStops(
500                 Color(0x00ff6d6d).getBColor(),   // light red 2
501                 Color(0x00c9211e).getBColor())); // dark red 2
502 
503         aFillGradient.SetName( aName );
504         aFillGradient.SetGradientValue(aGradient);
505         pISet->Put( aFillGradient );
506         pISet->Put( SvxColorItem(COL_WHITE, EE_CHAR_COLOR ));           // font white
507     }
508     // Graphic > Shapes > Filled > Yellow
509     {
510         aName =SdResId(STR_POOLSHEET_FILLED_YELLOW);
511         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
512         pSheet->SetParent(aFilledName);
513         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_FILLED_YELLOW );
514         pISet = &pSheet->GetItemSet();
515 
516         aGradient.SetColorStops(
517             basegfx::BColorStops(
518                 Color(0x00ffde59).getBColor(),   // light gold 2
519                 Color(0x00b47804).getBColor())); // dark gold 2
520 
521         aFillGradient.SetName( aName );
522         aFillGradient.SetGradientValue(aGradient);
523         pISet->Put( aFillGradient );
524         pISet->Put( SvxColorItem(COL_WHITE, EE_CHAR_COLOR ));           // font white
525     }
526     // Graphic > Shapes > Outlines
527     OUString aOutlineName(SdResId(STR_POOLSHEET_OUTLINE));
528     {
529         aName = aOutlineName;
530         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
531         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_OUTLINE );
532         pSheet->SetParent( aShapesName );
533         pISet = &pSheet->GetItemSet();
534         pISet->Put( XFillStyleItem(drawing::FillStyle_NONE) );             // clear
535         pISet->Put( XLineStyleItem(drawing::LineStyle_SOLID) );            // solide line
536         pISet->Put( XLineWidthItem(81) );                                  // 2.3 pt
537         pISet->Put( XLineColorItem(OUString(), COL_BLACK) );               // b/w
538     }
539     // Graphic > Shapes > Outlines > Blue
540     {
541         aName =SdResId(STR_POOLSHEET_OUTLINE_BLUE);
542         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
543         pSheet->SetParent(aOutlineName);
544         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_OUTLINE_BLUE );
545         pISet = &pSheet->GetItemSet();
546         pISet->Put( XLineColorItem(OUString(), Color(0x00355269)) );       // dark blue 2
547         pISet->Put( SvxColorItem(Color(0x00355269), EE_CHAR_COLOR ));      // font color
548     }
549     // Graphic > Shapes > Outlines > Green
550     {
551         aName =SdResId(STR_POOLSHEET_OUTLINE_GREEN);
552         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
553         pSheet->SetParent(aOutlineName);
554         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_OUTLINE_GREEN );
555         pISet = &pSheet->GetItemSet();
556         pISet->Put( XLineColorItem(OUString(), Color(0x00127622)) );       // dark green 2
557         pISet->Put( SvxColorItem(Color(0x00127622), EE_CHAR_COLOR ));      // font color
558     }
559     // Graphic > Shapes > Outlines > Red
560     {
561         aName =SdResId(STR_POOLSHEET_OUTLINE_RED);
562         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
563         pSheet->SetParent(aOutlineName);
564         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_OUTLINE_RED );
565         pISet = &pSheet->GetItemSet();
566         pISet->Put( XLineColorItem(OUString(), Color(0x00c9211e)) );       // dark red 2
567         pISet->Put( SvxColorItem(Color(0x00c9211e), EE_CHAR_COLOR ));      // font color
568     }
569     // Graphic > Shapes > Outlines > Yellow
570     {
571         aName =SdResId(STR_POOLSHEET_OUTLINE_YELLOW);
572         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
573         pSheet->SetParent(aOutlineName);
574         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_OUTLINE_YELLOW );
575         pISet = &pSheet->GetItemSet();
576         pISet->Put( XLineStyleItem(drawing::LineStyle_SOLID));
577         pISet->Put( XLineColorItem(OUString(), Color(0x00b47804)) );       // dark gold 2
578         pISet->Put( SvxColorItem(Color(0x00b47804), EE_CHAR_COLOR ));      // font color
579     }
580     // Graphic > Lines
581     OUString aLinesName;
582     {
583         aLinesName = SdResId(STR_POOLSHEET_LINES);
584         pSheet = &(pSSPool->Make(aLinesName, SfxStyleFamily::Para, nMask));
585         pSheet->SetParent( aGraphicName );
586         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_LINES);
587         pISet = &pSheet->GetItemSet();
588         pISet->Put( XFillStyleItem(drawing::FillStyle_NONE) );             // clear
589         pISet->Put( XLineStyleItem(drawing::LineStyle_SOLID) );            // solide line
590         pISet->Put( XLineColorItem(OUString(), COL_BLACK) );               // b/w
591     }
592     // Graphic > Lines > Measurements
593     {
594         aName = SdResId(STR_POOLSHEET_MEASURE);
595         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
596         pSheet->SetParent(aLinesName);
597         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_MEASURE );
598         pISet = &pSheet->GetItemSet();
599 
600         ::basegfx::B2DPolygon aArrow;                                      // arrows
601         aArrow.append(::basegfx::B2DPoint(10.0, 0.0));
602         aArrow.append(::basegfx::B2DPoint(0.0, 30.0));
603         aArrow.append(::basegfx::B2DPoint(20.0, 30.0));
604         aArrow.setClosed(true);
605 
606         pISet->Put(XLineStartItem(SvxResId(RID_SVXSTR_ARROW),::basegfx::B2DPolyPolygon(aArrow)));
607         pISet->Put(XLineStartWidthItem(200));
608         pISet->Put(XLineEndItem(SvxResId(RID_SVXSTR_ARROW),::basegfx::B2DPolyPolygon(aArrow)));
609         pISet->Put(XLineEndWidthItem(200));
610         pISet->Put(SdrYesNoItem(SDRATTR_MEASURESHOWUNIT, true));
611     }
612     // Graphic > Lines > Dashed
613     {
614         aName = SdResId(STR_POOLSHEET_LINES_DASHED);
615         pSheet = &(pSSPool->Make(aName, SfxStyleFamily::Para, nMask));
616         pSheet->SetParent(aLinesName);
617         pSheet->SetHelpId( aHelpFile, HID_POOLSHEET_LINES_DASHED );
618         pISet = &pSheet->GetItemSet();
619         pISet->Put( XLineStyleItem(drawing::LineStyle_DASH) );            // dashed line
620     }
621 
622     // Generate presentation templates for default layout.
623     OUString aPrefix = SdResId(STR_LAYOUT_DEFAULT_NAME);
624     pSSPool->CreateLayoutStyleSheets(aPrefix);
625 }
626 
CreateDefaultCellStyles()627 void SdDrawDocument::CreateDefaultCellStyles()
628 {
629     if (comphelper::IsFuzzing())
630         return;
631 
632     const Reference<css::uno::XComponentContext>& xContext(comphelper::getProcessComponentContext());
633     Reference<css::document::XImporter> xImporter(xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
634         u"com.sun.star.comp.Draw.XMLOasisStylesImporter"_ustr,
635         { Any(comphelper::makePropertyValue(u"OrganizerMode"_ustr, true)) }, xContext), UNO_QUERY);
636     if (xImporter)
637         xImporter->setTargetDocument(mpDocSh->GetModel());
638 
639     OUString aURL(u"$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/config/soffice.cfg/simpress/styles.xml"_ustr);
640     rtl::Bootstrap::expandMacros(aURL);
641     SvFileStream aFile(aURL, StreamMode::READ);
642 
643     css::xml::sax::InputSource aParserInput;
644     aParserInput.sPublicId = aURL;
645     aParserInput.aInputStream.set(new utl::OInputStreamWrapper(aFile));
646     Reference<css::xml::sax::XFastParser> xFastParser(xImporter, UNO_QUERY);
647     if (xFastParser)
648         xFastParser->parseStream(aParserInput);
649 
650     // Set default fonts, if they were not defined in the xml.
651     vcl::Font aLatinFont, aCJKFont, aCTLFont;
652 
653     getDefaultFonts( aLatinFont, aCJKFont, aCTLFont );
654 
655     SvxFontItem aSvxFontItem( aLatinFont.GetFamilyTypeMaybeAskConfig(), aLatinFont.GetFamilyName(), aLatinFont.GetStyleName(), aLatinFont.GetPitchMaybeAskConfig(),
656                               aLatinFont.GetCharSet(), EE_CHAR_FONTINFO );
657 
658     SvxFontItem aSvxFontItemCJK( aCJKFont.GetFamilyTypeMaybeAskConfig(), aCJKFont.GetFamilyName(), aCJKFont.GetStyleName(), aCJKFont.GetPitchMaybeAskConfig(),
659                                  aCJKFont.GetCharSet(), EE_CHAR_FONTINFO_CJK );
660 
661     SvxFontItem aSvxFontItemCTL( aCTLFont.GetFamilyTypeMaybeAskConfig(), aCTLFont.GetFamilyName(), aCTLFont.GetStyleName(), aCTLFont.GetPitchMaybeAskConfig(),
662                                  aCTLFont.GetCharSet(), EE_CHAR_FONTINFO_CTL );
663 
664     SdStyleSheetPool* pSSPool = static_cast<SdStyleSheetPool*>(GetStyleSheetPool());
665     SfxStyleSheetBase* pDefaultStyle = pSSPool->Find(u"default"_ustr, SfxStyleFamily::Frame);
666     if (pDefaultStyle)
667     {
668         SfxItemSet& rSet(pDefaultStyle->GetItemSet());
669         if (!rSet.HasItem(EE_CHAR_FONTINFO))
670             rSet.Put(aSvxFontItem);
671         if (!rSet.HasItem(EE_CHAR_FONTINFO_CJK))
672             rSet.Put(aSvxFontItemCJK);
673         if (!rSet.HasItem(EE_CHAR_FONTINFO_CTL))
674             rSet.Put(aSvxFontItemCTL);
675     }
676 
677     // Reset the user defined flag.
678     SfxStyleSheetBase* pSheet = pSSPool->First(SfxStyleFamily::Frame);
679     while (pSheet)
680     {
681         pSheet->SetMask(SfxStyleSearchBits::Auto);
682         pSheet = pSSPool->Next();
683     }
684 
685     Reference<form::XReset> xReset(pSSPool->getByName(u"table"_ustr), UNO_QUERY);
686     if (xReset)
687         xReset->reset();
688 }
689 
690 // Number of pages that reference a master page
GetMasterPageUserCount(SdrPage const * pMaster) const691 sal_uInt16 SdDrawDocument::GetMasterPageUserCount(SdrPage const * pMaster) const
692 {
693     sal_uInt16 nResult = 0;
694     sal_uInt16 nPage;
695     sal_uInt16 nPageCount = GetPageCount();
696 
697     for (nPage = 0; nPage < nPageCount; nPage++)
698     {
699         const SdrPage* pPage = GetPage(nPage);
700 
701         if(pPage->TRG_HasMasterPage())
702         {
703             if(&(pPage->TRG_GetMasterPage()) == pMaster)
704             {
705                 nResult++;
706             }
707         }
708     }
709     return nResult;
710 }
711 
712 // Finish OnlineSpelling in the background
713 
StopOnlineSpelling()714 void SdDrawDocument::StopOnlineSpelling()
715 {
716     if (mpOnlineSpellingIdle && mpOnlineSpellingIdle->IsActive())
717     {
718         mpOnlineSpellingIdle->Stop();
719     }
720 
721     mpOnlineSpellingIdle.reset();
722     mpOnlineSpellingList.reset();
723 }
724 
725 // Start OnlineSpelling in the background
StartOnlineSpelling(bool bForceSpelling)726 void SdDrawDocument::StartOnlineSpelling(bool bForceSpelling)
727 {
728     if ( !mbOnlineSpell || !(bForceSpelling || mbInitialOnlineSpellingEnabled) ||
729          !mpDocSh || mpDocSh->IsReadOnly() )
730         return;
731 
732     StopOnlineSpelling();
733 
734     SdOutliner* pOutl = GetInternalOutliner();
735 
736     Reference< XSpellChecker1 > xSpellChecker( LinguMgr::GetSpellChecker() );
737     if ( xSpellChecker.is() )
738         pOutl->SetSpeller( xSpellChecker );
739 
740     Reference< XHyphenator > xHyphenator( LinguMgr::GetHyphenator() );
741     if( xHyphenator.is() )
742         pOutl->SetHyphenator( xHyphenator );
743 
744     pOutl->SetDefaultLanguage( meLanguage );
745 
746     mpOnlineSpellingList.reset(new ShapeList);
747     sal_uInt16 nPage;
748 
749     for ( nPage = 0; nPage < GetPageCount(); nPage++ )
750     {
751         // Search in all pages
752         FillOnlineSpellingList(static_cast<SdPage*>(GetPage(nPage)));
753     }
754 
755     for (nPage = 0; nPage < GetMasterPageCount(); nPage++)
756     {
757         // Search all master pages
758         FillOnlineSpellingList(static_cast<SdPage*>( GetMasterPage(nPage) ));
759     }
760 
761     mpOnlineSpellingList->seekShape(0);
762     mpOnlineSpellingIdle.reset(new Idle("OnlineSpelling"));
763     mpOnlineSpellingIdle->SetInvokeHandler( LINK(this, SdDrawDocument, OnlineSpellingHdl) );
764     mpOnlineSpellingIdle->SetPriority(TaskPriority::LOWEST);
765     mpOnlineSpellingIdle->Start();
766 }
767 
768 // Fill OnlineSpelling list
FillOnlineSpellingList(SdPage const * pPage)769 void SdDrawDocument::FillOnlineSpellingList(SdPage const * pPage)
770 {
771     SdrObjListIter aIter(pPage, SdrIterMode::Flat);
772 
773     while (aIter.IsMore())
774     {
775         SdrObject* pObj = aIter.Next();
776 
777         if( !pObj )
778             continue;
779 
780         if (pObj->GetOutlinerParaObject())
781         {
782             // Found a text object
783             mpOnlineSpellingList->addShape(*pObj);
784         }
785         else if (pObj->GetObjIdentifier() == SdrObjKind::Group)
786         {
787             // Found a group object
788             SdrObjListIter aGroupIter(static_cast< SdrObjGroup* >(pObj)->GetSubList(), SdrIterMode::DeepNoGroups);
789 
790             bool bSubTextObjFound = false;
791 
792             while (aGroupIter.IsMore() && !bSubTextObjFound)
793             {
794                 if (aGroupIter.Next()->GetOutlinerParaObject())
795                 {
796                     // Found a text object in a group object
797                     bSubTextObjFound = true;
798                 }
799             }
800 
801             if (bSubTextObjFound)
802             {
803                 mpOnlineSpellingList->addShape(*pObj);
804             }
805         }
806     }
807 }
808 
809 // OnlineSpelling in the background
IMPL_LINK_NOARG(SdDrawDocument,OnlineSpellingHdl,Timer *,void)810 IMPL_LINK_NOARG(SdDrawDocument, OnlineSpellingHdl, Timer *, void)
811 {
812     if (mpOnlineSpellingList!=nullptr
813         && ( !mbOnlineSpell || mpOnlineSpellingList->hasMore()))
814     {
815         // Spell next object
816         SdrObject* pObj = mpOnlineSpellingList->getNextShape();
817 
818         if (pObj)
819         {
820             if (pObj->GetOutlinerParaObject() && DynCastSdrTextObj( pObj ) !=  nullptr)
821             {
822                 // Spell text object
823                 SpellObject(static_cast<SdrTextObj*>(pObj));
824             }
825             else if (pObj->GetObjIdentifier() == SdrObjKind::Group)
826             {
827                 // Found a group object
828                 SdrObjListIter aGroupIter(static_cast< SdrObjGroup* >(pObj)->GetSubList(), SdrIterMode::DeepNoGroups);
829 
830 
831                 while (aGroupIter.IsMore())
832                 {
833                     SdrObject* pSubObj = aGroupIter.Next();
834 
835                     if (pSubObj->GetOutlinerParaObject())
836                         if (auto pTextObj = DynCastSdrTextObj( pSubObj ))
837                             // Found a text object in a group object
838                             SpellObject(pTextObj);
839                 }
840             }
841         }
842 
843         // Continue search
844         mpOnlineSpellingIdle->Start();
845     }
846     else
847     {
848         // Initial spelling has finished
849         mbInitialOnlineSpellingEnabled = false;
850 
851         // Stop search
852         StopOnlineSpelling();
853 
854         mpOnlineSearchItem.reset();
855     }
856 }
857 
858 // Spell object (for OnlineSpelling)
SpellObject(SdrTextObj * pObj)859 void SdDrawDocument::SpellObject(SdrTextObj* pObj)
860 {
861     if (!(pObj && pObj->GetOutlinerParaObject()) /* && pObj != pView->GetTextEditObject() */)
862         return;
863 
864     mbHasOnlineSpellErrors = false;
865     SdOutliner* pOutl = GetInternalOutliner();
866     pOutl->SetUpdateLayout(true);
867     Link<EditStatus&,void> aEvtHdl = pOutl->GetStatusEventHdl();
868     pOutl->SetStatusEventHdl(LINK(this, SdDrawDocument, OnlineSpellEventHdl));
869 
870     OutlinerMode nOldOutlMode = pOutl->GetOutlinerMode();
871     OutlinerMode nOutlMode = OutlinerMode::TextObject;
872     if (pObj->GetObjInventor() == SdrInventor::Default &&
873         pObj->GetObjIdentifier() == SdrObjKind::OutlineText)
874     {
875         nOutlMode = OutlinerMode::OutlineObject;
876     }
877     pOutl->Init( nOutlMode );
878 
879     // Put text into the outliner
880     pOutl->SetText(*pObj->GetOutlinerParaObject());
881 
882     if (!mpOnlineSearchItem || pOutl->HasText(*mpOnlineSearchItem))
883     {
884         // Spelling
885         pOutl->CompleteOnlineSpelling();
886 
887         if (mbHasOnlineSpellErrors)
888         {
889             std::optional<OutlinerParaObject> pOPO = pOutl->CreateParaObject();
890             if (pOPO)
891             {
892                 if ( *pOPO != *pObj->GetOutlinerParaObject() ||
893                      !pObj->GetOutlinerParaObject()->isWrongListEqual( *pOPO ))
894                 {
895                     sd::ModifyGuard aGuard( this );
896 
897                     // taking text from the outliner
898                     // use non-broadcasting version to avoid O(n^2)
899                     pObj->NbcSetOutlinerParaObject( std::move(pOPO), false );
900                 }
901             }
902         }
903     }
904 
905     pOutl->SetStatusEventHdl(aEvtHdl);
906     pOutl->SetUpdateLayout(false);
907     pOutl->Init( nOldOutlMode );
908     mbHasOnlineSpellErrors = false;
909 }
910 
911 // Object was inserted into model
InsertObject(SdrObject * pObj)912 void SdDrawDocument::InsertObject(SdrObject* pObj)
913 {
914     if(mpOnlineSpellingList && pObj)
915     {
916         if (pObj->GetOutlinerParaObject() || (pObj->GetObjIdentifier() == SdrObjKind::Group))
917         {
918             // Add object to OnlineSpelling list
919             mpOnlineSpellingList->addShape(*pObj);
920         }
921     }
922 }
923 
924 // Object removed from model
RemoveObject(SdrObject * pObj)925 void SdDrawDocument::RemoveObject(SdrObject* pObj)
926 {
927     if(mpOnlineSpellingList && pObj)
928     {
929         if (pObj->GetOutlinerParaObject() || (pObj->GetObjIdentifier() == SdrObjKind::Group))
930         {
931             // Replace object in OnlineSpelling list by 0 pointer
932             mpOnlineSpellingList->removeShape(*pObj);
933         }
934     }
935 }
936 
937 // Callback for ExecuteSpellPopup()
IMPL_LINK(SdDrawDocument,OnlineSpellEventHdl,EditStatus &,rEditStat,void)938 IMPL_LINK(SdDrawDocument, OnlineSpellEventHdl, EditStatus&, rEditStat, void)
939 {
940     EditStatusFlags nStat = rEditStat.GetStatusWord();
941     mbHasOnlineSpellErrors = bool(nStat & EditStatusFlags::WRONGWORDCHANGED);
942 }
943 
944 // Callback for ExecuteSpellPopup()
945 
946 // removed link and replaced with Imp method
ImpOnlineSpellCallback(SpellCallbackInfo const * pInfo,SdrObject * pObj,SdrOutliner const * pOutl)947 void SdDrawDocument::ImpOnlineSpellCallback(SpellCallbackInfo const * pInfo, SdrObject* pObj, SdrOutliner const * pOutl)
948 {
949     mpOnlineSearchItem.reset();
950 
951     SpellCallbackCommand nCommand = pInfo->nCommand;
952 
953     if (nCommand == SpellCallbackCommand::IGNOREWORD
954         // restart when add to dictionary takes place, too.
955         || nCommand == SpellCallbackCommand::ADDTODICTIONARY)
956     {
957         if(pOutl)
958             if (auto pTextObj = DynCastSdrTextObj( pObj ))
959             {
960                 bool bModified(IsChanged());
961                 pTextObj->SetOutlinerParaObject(pOutl->CreateParaObject());
962                 SetChanged(bModified);
963                 pObj->BroadcastObjectChange();
964             }
965 
966         mpOnlineSearchItem.reset(new SvxSearchItem( SID_SEARCH_ITEM ) );
967         mpOnlineSearchItem->SetSearchString(pInfo->aWord);
968         StartOnlineSpelling();
969     }
970     else if (nCommand == SpellCallbackCommand::STARTSPELLDLG)
971     {
972         if (SfxViewFrame* pViewFrame = SfxViewFrame::Current())
973             pViewFrame->GetDispatcher()->Execute( SID_SPELL_DIALOG, SfxCallMode::ASYNCHRON );
974     }
975     else if (nCommand == SpellCallbackCommand::AUTOCORRECT_OPTIONS)
976     {
977         if (SfxViewFrame* pViewFrame = SfxViewFrame::Current())
978             pViewFrame->GetDispatcher()->Execute( SID_AUTO_CORRECT_DLG, SfxCallMode::ASYNCHRON );
979     }
980 }
981 
982 // Return formatted page number (1, I, i, a, etc.)
CreatePageNumValue(sal_uInt16 nNum) const983 OUString SdDrawDocument::CreatePageNumValue(sal_uInt16 nNum) const
984 {
985     OUString aPageNumValue;
986     bool bUpper = false;
987 
988     switch (mePageNumType)
989     {
990         case css::style::NumberingType::CHARS_UPPER_LETTER:
991             aPageNumValue += OUStringChar( sal_Unicode((nNum - 1) % 26 + 'A') );
992             break;
993         case css::style::NumberingType::CHARS_LOWER_LETTER:
994             aPageNumValue += OUStringChar( sal_Unicode((nNum - 1) % 26 + 'a') );
995             break;
996         case css::style::NumberingType::ROMAN_UPPER:
997             bUpper = true;
998             [[fallthrough]];
999         case css::style::NumberingType::ROMAN_LOWER:
1000             aPageNumValue += SvxNumberFormat::CreateRomanString(nNum, bUpper);
1001             break;
1002         case css::style::NumberingType::NUMBER_NONE:
1003             aPageNumValue = " ";
1004             break;
1005         default:
1006             aPageNumValue += OUString::number(nNum);
1007     }
1008 
1009     return aPageNumValue;
1010 }
1011 
1012 // Rename layout template
1013 // Keep in mind that rOldLayoutName contains the _complete_ name of the layout
1014 // (including ~LT~). This is unlike rNewName.
RenameLayoutTemplate(const OUString & rOldLayoutName,const OUString & rNewName)1015 void SdDrawDocument::RenameLayoutTemplate(const OUString& rOldLayoutName, const OUString& rNewName)
1016 {
1017     OUString aOldName(rOldLayoutName);
1018     sal_Int32 nPos = aOldName.indexOf( SD_LT_SEPARATOR );
1019 
1020     // erase everything after '~LT~'
1021     if (nPos != -1)
1022         aOldName = aOldName.copy(0, nPos + SD_LT_SEPARATOR.getLength());
1023 
1024     std::vector<StyleReplaceData> aReplList;
1025     SfxStyleSheetIterator aIter(mxStyleSheetPool.get(), SfxStyleFamily::Page);
1026     SfxStyleSheetBase* pSheet = aIter.First();
1027 
1028     while (pSheet)
1029     {
1030         OUString aSheetName = pSheet->GetName();
1031 
1032         // if the sheetname starts with aOldName + "~LT~"
1033         if (aSheetName.startsWith(aOldName))
1034         {
1035             aSheetName = aSheetName.replaceAt(0, aOldName.getLength() - SD_LT_SEPARATOR.getLength(), rNewName);
1036 
1037             StyleReplaceData aReplData;
1038             aReplData.nFamily     = pSheet->GetFamily();
1039             aReplData.nNewFamily = pSheet->GetFamily();
1040             aReplData.aName   = pSheet->GetName();
1041             aReplData.aNewName   = aSheetName;
1042             aReplList.push_back(aReplData);
1043 
1044             pSheet->SetName(aSheetName, /*bReindexNow*/false);
1045         }
1046 
1047         pSheet = aIter.Next();
1048     }
1049     mxStyleSheetPool->Reindex();
1050 
1051     // Now set the layout name of the drawing and the notes page, as well as
1052     // their master pages.
1053     OUString aPageLayoutName = rNewName + SD_LT_SEPARATOR + STR_LAYOUT_OUTLINE;
1054 
1055     // Inform all text objects on pages that use the renamed layout and set the
1056     // new name.
1057     sal_uInt16 nPage;
1058     for (nPage = 0; nPage < GetPageCount(); nPage++)
1059     {
1060         SdPage* pPage = static_cast<SdPage*>(GetPage(nPage));
1061         OUString aTemp(pPage->GetLayoutName());
1062 
1063         if (aTemp == rOldLayoutName)
1064         {
1065             pPage->SetLayoutName(aPageLayoutName);
1066 
1067             for (const rtl::Reference<SdrObject>& pObj : *pPage)
1068             {
1069                 if (pObj->GetObjInventor() == SdrInventor::Default)
1070                 {
1071                     switch( pObj->GetObjIdentifier() )
1072                     {
1073                         case SdrObjKind::Text:
1074                         case SdrObjKind::OutlineText:
1075                         case SdrObjKind::TitleText:
1076                         {
1077                             OutlinerParaObject* pOPO = static_cast<SdrTextObj*>(pObj.get())->GetOutlinerParaObject();
1078 
1079                             if (pOPO)
1080                             {
1081                                 for (const auto& rRepl : aReplList)
1082                                     pOPO->ChangeStyleSheets( rRepl.aName, rRepl.nFamily, rRepl.aNewName, rRepl.nNewFamily );
1083                             }
1084                         }
1085                         break;
1086 
1087                         default:
1088                         break;
1089                     }
1090                 }
1091             }
1092         }
1093     }
1094 
1095     // Now do this again for all master pages.
1096     // The affected master pages get the name of the layout as their page name.
1097     for (nPage = 0; nPage < GetMasterPageCount(); nPage++)
1098     {
1099         SdPage* pPage = static_cast<SdPage*>( GetMasterPage(nPage) );
1100         OUString aTemp(pPage->GetLayoutName());
1101 
1102         if (aTemp == rOldLayoutName)
1103         {
1104             pPage->SetLayoutName(aPageLayoutName);
1105             pPage->SetName(rNewName);
1106 
1107             for (const rtl::Reference<SdrObject>& pObj : *pPage)
1108             {
1109                 if (pObj->GetObjInventor() == SdrInventor::Default)
1110                 {
1111                     switch(pObj->GetObjIdentifier())
1112                     {
1113                         case SdrObjKind::Text:
1114                         case SdrObjKind::OutlineText:
1115                         case SdrObjKind::TitleText:
1116                         {
1117                             OutlinerParaObject* pOPO = static_cast<SdrTextObj*>(pObj.get())->GetOutlinerParaObject();
1118 
1119                             if (pOPO)
1120                             {
1121                                 for (const auto& rRepl : aReplList)
1122                                     pOPO->ChangeStyleSheets( rRepl.aName, rRepl.nFamily, rRepl.aNewName, rRepl.nNewFamily );
1123                             }
1124                         }
1125                         break;
1126 
1127                         default:
1128                         break;
1129                     }
1130                 }
1131             }
1132         }
1133     }
1134 }
1135 
1136 // Set outliner defaults (pool defaults)
SetTextDefaults() const1137 void SdDrawDocument::SetTextDefaults() const
1138 {
1139     // BulletItem and BulletFont for Title and Outline
1140     SvxBulletItem aBulletItem(EE_PARA_BULLET);
1141     vcl::Font aBulletFont( SdStyleSheetPool::GetBulletFont() );
1142     aBulletFont.SetFontSize(Size(0,846));       // 24 pt
1143     aBulletItem.SetFont(aBulletFont);
1144     aBulletItem.SetStyle(SvxBulletStyle::BULLET);
1145     aBulletItem.SetStart(1);
1146     aBulletItem.SetScale(45);               // In percent
1147     aBulletItem.SetSymbol( 0x25CF );                // In points
1148     m_pItemPool->SetUserDefaultItem( aBulletItem );
1149 
1150     // New BulletItem
1151     SvxNumberFormat aNumberFormat(SVX_NUM_CHAR_SPECIAL);
1152     aNumberFormat.SetBulletFont(&aBulletFont);
1153     aNumberFormat.SetBulletChar( 0x25CF );  // StarBats: 0xF000 + 34
1154     aNumberFormat.SetBulletRelSize(45);
1155     aNumberFormat.SetBulletColor(COL_AUTO);
1156     aNumberFormat.SetStart(1);
1157     aNumberFormat.SetNumAdjust(SvxAdjust::Left);
1158 
1159     SvxNumRule aNumRule( SvxNumRuleFlags::BULLET_REL_SIZE | SvxNumRuleFlags::BULLET_COLOR, SVX_MAX_NUM, false);
1160 
1161     //aNumberFormat.SetAbsLSpace( 0 );
1162     //aNumberFormat.SetFirstLineOffset( 0 );
1163     //aNumRule.SetLevel( 0, aNumberFormat );
1164 
1165     for( sal_uInt16 i = 0; i < aNumRule.GetLevelCount(); i++ )
1166     {
1167         const auto nLSpace = (i + 1) * 600;
1168         aNumberFormat.SetAbsLSpace(nLSpace);
1169         aNumberFormat.SetFirstLineOffset(-600);
1170         aNumRule.SetLevel( i, aNumberFormat );
1171     }
1172 
1173     SvxNumBulletItem aNumBulletItem( std::move(aNumRule), EE_PARA_NUMBULLET );
1174     m_pItemPool->SetUserDefaultItem( aNumBulletItem );
1175 }
1176 
GetDefaultWritingMode() const1177 css::text::WritingMode SdDrawDocument::GetDefaultWritingMode() const
1178 {
1179     const SfxPoolItem*                  pItem = ( m_pItemPool ? m_pItemPool->GetUserDefaultItem( EE_PARA_WRITINGDIR ) : nullptr );
1180     css::text::WritingMode eRet = css::text::WritingMode_LR_TB;
1181 
1182     if( pItem )
1183     {
1184         switch( static_cast<const SvxFrameDirectionItem&>( *pItem ).GetValue() )
1185         {
1186             case SvxFrameDirection::Horizontal_LR_TB: eRet = css::text::WritingMode_LR_TB; break;
1187             case SvxFrameDirection::Horizontal_RL_TB: eRet = css::text::WritingMode_RL_TB; break;
1188             case SvxFrameDirection::Vertical_RL_TB: eRet = css::text::WritingMode_TB_RL; break;
1189 
1190             default:
1191                 OSL_FAIL( "Frame direction not supported yet" );
1192             break;
1193         }
1194     }
1195 
1196     return eRet;
1197 }
1198 
SetDefaultWritingMode(css::text::WritingMode eMode)1199 void SdDrawDocument::SetDefaultWritingMode(css::text::WritingMode eMode )
1200 {
1201     if( !m_pItemPool )
1202         return;
1203 
1204     SvxFrameDirection nVal;
1205     switch( eMode )
1206     {
1207     case css::text::WritingMode_LR_TB: nVal = SvxFrameDirection::Horizontal_LR_TB; break;
1208     case css::text::WritingMode_RL_TB: nVal = SvxFrameDirection::Horizontal_RL_TB; break;
1209     case css::text::WritingMode_TB_RL: nVal = SvxFrameDirection::Vertical_RL_TB; break;
1210     default:
1211         OSL_FAIL( "Frame direction not supported yet" );
1212         return;
1213     }
1214 
1215     SvxFrameDirectionItem aModeItem( nVal, EE_PARA_WRITINGDIR );
1216     m_pItemPool->SetUserDefaultItem( aModeItem );
1217 
1218     SvxAdjustItem aAdjust( SvxAdjust::Left, EE_PARA_JUST );
1219 
1220     if( eMode == css::text::WritingMode_RL_TB )
1221         aAdjust.SetAdjust( SvxAdjust::Right );
1222 
1223     m_pItemPool->SetUserDefaultItem( aAdjust );
1224 }
1225 
getDefaultFonts(vcl::Font & rLatinFont,vcl::Font & rCJKFont,vcl::Font & rCTLFont)1226 void SdDrawDocument::getDefaultFonts( vcl::Font& rLatinFont, vcl::Font& rCJKFont, vcl::Font& rCTLFont )
1227 {
1228     LanguageType eLatin = GetLanguage( EE_CHAR_LANGUAGE );
1229 
1230     //  If the UI language is Korean, the default Latin font has to
1231     //  be queried for Korean, too (the Latin language from the document can't be Korean).
1232     //  This is the same logic as in SwDocShell::InitNew.
1233     LanguageType eUiLanguage = Application::GetSettings().GetUILanguageTag().getLanguageType();
1234     if (MsLangId::isKorean(eUiLanguage))
1235         eLatin = eUiLanguage;
1236 
1237     rLatinFont = OutputDevice::GetDefaultFont( DefaultFontType::LATIN_PRESENTATION, eLatin, GetDefaultFontFlags::OnlyOne );
1238     rCJKFont = OutputDevice::GetDefaultFont( DefaultFontType::CJK_PRESENTATION, GetLanguage( EE_CHAR_LANGUAGE_CJK ), GetDefaultFontFlags::OnlyOne );
1239     rCTLFont = OutputDevice::GetDefaultFont( DefaultFontType::CTL_PRESENTATION, GetLanguage( EE_CHAR_LANGUAGE_CTL ), GetDefaultFontFlags::OnlyOne ) ;
1240 }
1241 
1242 /* converts the given western font height to a corresponding ctl font height, depending on the system language */
convertFontHeightToCTL(sal_uInt32 nWesternFontHeight)1243 sal_uInt32 SdDrawDocument::convertFontHeightToCTL( sal_uInt32 nWesternFontHeight )
1244 {
1245     LanguageType eRealCTLLanguage = Application::GetSettings().GetLanguageTag().getLanguageType();
1246     if( LANGUAGE_THAI == eRealCTLLanguage )
1247     {
1248         // http://specs.openoffice.org/g11n/font_sizes/42775_42725_Individual_configurable_font_size_for_default_fonts.odt
1249         double fTemp = double(nWesternFontHeight) * 1.333;
1250         nWesternFontHeight = static_cast<sal_uInt32>(fTemp);
1251         // make some nice values for UI that displays PT instead of 1/100th mm
1252         nWesternFontHeight = convertPointToMm100(convertMm100ToPoint(nWesternFontHeight));
1253     }
1254     return nWesternFontHeight;
1255 }
1256 
GetSdStyleSheetPool() const1257 SdStyleSheetPool* SdDrawDocument::GetSdStyleSheetPool() const
1258 {
1259     return dynamic_cast< SdStyleSheetPool* >( GetStyleSheetPool() );
1260 }
1261 
ModifyGuard(SdDrawDocument * pDoc)1262 ModifyGuard::ModifyGuard( SdDrawDocument* pDoc )
1263 : mpDocShell( nullptr ), mpDoc( pDoc )
1264 {
1265     init();
1266 }
1267 
init()1268 void ModifyGuard::init()
1269 {
1270     if( mpDocShell )
1271     {
1272         mpDoc = mpDocShell->GetDoc();
1273     }
1274     else if( mpDoc )
1275     {
1276         mpDocShell = mpDoc->GetDocSh();
1277     }
1278 
1279     mbIsEnableSetModified = mpDocShell && mpDocShell->IsEnableSetModified();
1280     mbIsDocumentChanged = mpDoc && mpDoc->IsChanged();
1281 
1282     if( mbIsEnableSetModified )
1283         mpDocShell->EnableSetModified( false );
1284 }
1285 
~ModifyGuard()1286 ModifyGuard::~ModifyGuard()
1287 {
1288     if( mbIsEnableSetModified )
1289         mpDocShell->EnableSetModified();
1290 
1291     if( mpDoc && (mpDoc->IsChanged() != mbIsDocumentChanged) )
1292         mpDoc->SetChanged(mbIsDocumentChanged);
1293 }
1294 
1295 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
1296