Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/app/sdmod2.cxx
Line
Count
Source
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 <editeng/flditem.hxx>
21
#include <editeng/CustomPropertyField.hxx>
22
#include <tools/debug.hxx>
23
#include <sfx2/printer.hxx>
24
#include <sfx2/styfitem.hxx>
25
#include <svl/inethist.hxx>
26
#include <svl/poolitem.hxx>
27
#include <svl/flagitem.hxx>
28
#include <unotools/localedatawrapper.hxx>
29
#include <unotools/syslocale.hxx>
30
#include <unotools/useroptions.hxx>
31
#include <sfx2/bindings.hxx>
32
#include <sfx2/viewfrm.hxx>
33
#include <sfx2/docfile.hxx>
34
#include <osl/diagnose.h>
35
36
#include <editeng/measfld.hxx>
37
#include <editeng/editstat.hxx>
38
39
#include <svx/svxids.hrc>
40
#include <svx/dialogs.hrc>
41
#include <svx/svdotext.hxx>
42
43
#include <sfx2/sfxdlg.hxx>
44
45
#include <sdmod.hxx>
46
#include <app.hrc>
47
#include <family.hrc>
48
#include <strings.hrc>
49
#include <sdattr.hrc>
50
51
#include <bitmaps.hlst>
52
#include <ViewShell.hxx>
53
#include <FrameView.hxx>
54
#include <optsitem.hxx>
55
#include <DrawDocShell.hxx>
56
#include <drawdoc.hxx>
57
#include <Outliner.hxx>
58
#include <sdresid.hxx>
59
#include <pres.hxx>
60
#include <OutlineViewShell.hxx>
61
#include <OutlineView.hxx>
62
#include <ViewShellBase.hxx>
63
#include <sdpage.hxx>
64
#include <sdabstdlg.hxx>
65
#include <svl/intitem.hxx>
66
67
#include <officecfg/Office/Draw.hxx>
68
#include <officecfg/Office/Impress.hxx>
69
70
/** retrieves the page that is currently painted. This will only be the master page
71
    if the current drawn view only shows the master page*/
72
static SdPage* GetCurrentPage( sd::ViewShell const * pViewSh, EditFieldInfo const * pInfo, bool& bMasterView )
73
545k
{
74
545k
    if( !pInfo )
75
0
        return nullptr;
76
77
545k
    bMasterView = false;
78
545k
    SdPage* pPage = dynamic_cast< SdPage* >( pInfo->GetSdrPage() );
79
545k
    SdrOutliner* pOutliner = dynamic_cast< SdrOutliner* >( pInfo->GetOutliner() );
80
81
    // special case, someone already set the current page on the EditFieldInfo
82
    // This is used from the svx::UnoGraphicsExporter f.e.
83
545k
    if( pPage )
84
0
    {
85
0
        bMasterView = false;
86
0
        return pPage;
87
0
    }
88
89
    // first try to check if we are inside the outline view
90
545k
    sd::OutlineView* pSdView = nullptr;
91
545k
    if( auto pOutlineViewShell = dynamic_cast<const sd::OutlineViewShell* >(pViewSh) )
92
0
        pSdView = static_cast<sd::OutlineView*>(pOutlineViewShell->GetView());
93
94
545k
    if (pSdView != nullptr && (pOutliner ==  &pSdView->GetOutliner()))
95
0
    {
96
        // outline mode
97
0
        int nPgNum = 0;
98
0
        Outliner& rOutl = pSdView->GetOutliner();
99
0
        tools::Long nPos = pInfo->GetPara();
100
0
        sal_Int32 nParaPos = 0;
101
102
0
        for( Paragraph* pPara = rOutl.GetParagraph( 0 ); pPara && nPos >= 0; pPara = rOutl.GetParagraph( ++nParaPos ), nPos-- )
103
0
        {
104
0
            if( Outliner::HasParaFlag( pPara, ParaFlag::ISPAGE ) )
105
0
                nPgNum++;
106
0
        }
107
108
0
        pPage = pViewSh->GetDoc()->GetSdPage( static_cast<sal_uInt16>(nPgNum), PageKind::Standard );
109
0
    }
110
545k
    else
111
545k
    {
112
        // draw mode, slide mode and preview. Get the processed page from the outliner
113
545k
        if(pOutliner)
114
545k
        {
115
545k
            pPage = dynamic_cast< SdPage* >(const_cast< SdrPage* >(pOutliner->getVisualizedPage()));
116
545k
        }
117
118
        // The path using GetPaintingPageView() and GetCurrentPaintingDisplayInfo()
119
        // is no longer needed. I debugged and checked all usages of PageNumber decompositions
120
        // which all use the new possibility of setting the visualized page at the SdrOutliner.
121
122
        // if all else failed, geht the current page from the object that is
123
        // currently formatted from the document
124
545k
        if(!pPage)
125
545k
        {
126
545k
            const SdrTextObj* pTextObj = (pViewSh && pViewSh->GetDoc()) ? pViewSh->GetDoc()->GetFormattingTextObj() : nullptr;
127
128
545k
            if( pTextObj )
129
0
            {
130
0
                pPage = dynamic_cast< SdPage* >( pTextObj->getSdrPageFromSdrObject() );
131
0
            }
132
545k
        }
133
134
545k
        if(pPage)
135
0
        {
136
0
            bMasterView = pPage->IsMasterPage();
137
0
        }
138
545k
    }
139
140
545k
    return pPage;
141
545k
}
142
143
/**
144
 * Link for CalcFieldValue of Outliners
145
 */
146
IMPL_LINK(SdModule, CalcFieldValueHdl, EditFieldInfo*, pInfo, void)
147
572k
{
148
572k
    if (!pInfo)
149
0
        return;
150
151
572k
    const SvxFieldData* pField = pInfo->GetField().GetField();
152
572k
    ::sd::DrawDocShell*     pDocShell = nullptr;
153
572k
    SdDrawDocument* pDoc = nullptr;
154
155
572k
    SdrOutliner* pSdrOutliner = dynamic_cast< SdrOutliner* >( pInfo->GetOutliner() );
156
572k
    if( pSdrOutliner )
157
572k
    {
158
572k
        const SdrTextObj* pTextObj = pSdrOutliner->GetTextObj();
159
160
572k
        if( pTextObj )
161
427k
            pDoc = dynamic_cast< SdDrawDocument* >( &pTextObj->getSdrModelFromSdrObject() );
162
163
572k
        if( pDoc )
164
427k
            pDocShell = pDoc->GetDocSh();
165
572k
    }
166
167
572k
    if( !pDocShell )
168
144k
        pDocShell = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
169
170
572k
    const SvxDateField* pDateField = nullptr;
171
572k
    const SvxExtTimeField* pExtTimeField = nullptr;
172
572k
    const SvxExtFileField* pExtFileField = nullptr;
173
572k
    const SvxAuthorField* pAuthorField = nullptr;
174
572k
    const SvxURLField* pURLField = nullptr;
175
176
572k
    const editeng::CustomPropertyField* pCustomPropertyField = nullptr;
177
178
572k
    if( (pDateField = dynamic_cast< const SvxDateField* >(pField)) != nullptr )
179
12.2k
    {
180
12.2k
        LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() );
181
12.2k
        pInfo->SetRepresentation( pDateField->GetFormatted( *GetNumberFormatter(), eLang ) );
182
12.2k
    }
183
560k
    else if( (pExtTimeField = dynamic_cast< const SvxExtTimeField *>(pField)) != nullptr )
184
278
    {
185
278
        LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() );
186
278
        pInfo->SetRepresentation( pExtTimeField->GetFormatted( *GetNumberFormatter(), eLang ) );
187
278
    }
188
559k
    else if( (pExtFileField = dynamic_cast< const SvxExtFileField * >(pField)) != nullptr )
189
0
    {
190
0
        if( pDocShell && (pExtFileField->GetType() != SvxFileType::Fix) )
191
0
        {
192
0
            OUString aName;
193
0
            if( pDocShell->HasName() )
194
0
                aName = pDocShell->GetMedium()->GetName();
195
0
            else
196
0
                aName = pDocShell->GetName();
197
198
0
            const_cast< SvxExtFileField* >(pExtFileField)->SetFile( aName );
199
0
        }
200
0
        pInfo->SetRepresentation( pExtFileField->GetFormatted() );
201
202
0
    }
203
559k
    else if( (pAuthorField = dynamic_cast< const SvxAuthorField* >( pField )) != nullptr  )
204
0
    {
205
0
        if( pAuthorField->GetType() != SvxAuthorType::Fix )
206
0
        {
207
0
            SvtUserOptions aUserOptions;
208
0
            *const_cast< SvxAuthorField* >(pAuthorField) = SvxAuthorField(
209
0
                    aUserOptions.GetFirstName(), aUserOptions.GetLastName(), aUserOptions.GetID(),
210
0
                    pAuthorField->GetType(), pAuthorField->GetFormat());
211
0
        }
212
0
        pInfo->SetRepresentation( pAuthorField->GetFormatted() );
213
214
0
    }
215
559k
    else if( dynamic_cast< const SvxPageField*  >(pField) )
216
207k
    {
217
207k
        OUString aRepresentation(u" "_ustr);
218
219
207k
        ::sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : nullptr;
220
207k
        if(pViewSh == nullptr)
221
207k
        {
222
207k
            ::sd::ViewShellBase* pBase = dynamic_cast< ::sd::ViewShellBase *>( SfxViewShell::Current() );
223
207k
            if(pBase)
224
0
                pViewSh = pBase->GetMainViewShell().get();
225
207k
        }
226
207k
        if( !pDoc && pViewSh )
227
0
            pDoc = pViewSh->GetDoc();
228
229
207k
        bool bMasterView;
230
207k
        SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView );
231
232
207k
        if( pPage && pDoc && !bMasterView )
233
0
        {
234
0
            int nPgNum;
235
236
0
            if( (pPage->GetPageKind() == PageKind::Handout) && pViewSh )
237
0
            {
238
0
                nPgNum = pViewSh->GetPrintedHandoutPageNum();
239
0
            }
240
0
            else
241
0
            {
242
0
                nPgNum = (pPage->GetPageNum() - 1) / 2 + 1;
243
0
            }
244
0
            aRepresentation = pDoc->CreatePageNumValue(static_cast<sal_uInt16>(nPgNum));
245
0
        }
246
207k
        else
247
207k
            aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_NUMBER);
248
249
207k
        pInfo->SetRepresentation( aRepresentation );
250
207k
    }
251
352k
    else if( dynamic_cast< const SvxPageTitleField*  >(pField) )
252
0
    {
253
0
        OUString aRepresentation(u" "_ustr);
254
255
0
        ::sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : nullptr;
256
0
        if(pViewSh == nullptr)
257
0
        {
258
0
            ::sd::ViewShellBase* pBase = dynamic_cast< ::sd::ViewShellBase *>( SfxViewShell::Current() );
259
0
            if(pBase)
260
0
                pViewSh = pBase->GetMainViewShell().get();
261
0
        }
262
0
        if( !pDoc && pViewSh )
263
0
            pDoc = pViewSh->GetDoc();
264
265
0
        bool bMasterView;
266
0
        SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView );
267
268
0
        if( pPage && pDoc && !bMasterView )
269
0
        {
270
0
            aRepresentation = pPage->GetName();
271
0
        }
272
0
        else
273
0
        {
274
0
            DocumentType eDocType = pDoc ? pDoc->GetDocumentType() : DocumentType::Impress;
275
0
            aRepresentation = ( ( eDocType == DocumentType::Impress )
276
0
                                ? SdResId(STR_FIELD_PLACEHOLDER_SLIDENAME)
277
0
                                : SdResId(STR_FIELD_PLACEHOLDER_PAGENAME) );
278
0
        }
279
280
0
        pInfo->SetRepresentation( aRepresentation );
281
0
    }
282
352k
    else if( dynamic_cast< const SvxPagesField*  >(pField) )
283
0
    {
284
0
        OUString aRepresentation(u" "_ustr);
285
286
0
        ::sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : nullptr;
287
0
        if(pViewSh == nullptr)
288
0
        {
289
0
            ::sd::ViewShellBase* pBase = dynamic_cast< ::sd::ViewShellBase *>( SfxViewShell::Current() );
290
0
            if(pBase)
291
0
                pViewSh = pBase->GetMainViewShell().get();
292
0
        }
293
0
        if( !pDoc && pViewSh )
294
0
            pDoc = pViewSh->GetDoc();
295
296
0
        bool bMasterView;
297
0
        SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView );
298
299
0
        sal_uInt16 nPageCount = 0;
300
301
0
        if( !bMasterView )
302
0
        {
303
0
            if (pPage)
304
0
            {
305
0
                const auto ePageKind = pPage->GetPageKind();
306
0
                if (pViewSh && ePageKind == PageKind::Handout)
307
0
                {
308
0
                    nPageCount = pViewSh->GetPrintedHandoutPageCount();
309
0
                }
310
0
                else if (pDoc)
311
0
                {
312
                    // tdf#68320 - include hidden pages in slide count field
313
0
                    nPageCount = pDoc->GetSdPageCount(ePageKind);
314
0
                }
315
0
            }
316
0
            else if (pDoc)
317
0
            {
318
0
                nPageCount = pDoc->GetActiveSdPageCount();
319
0
            }
320
0
        }
321
322
0
        if( nPageCount > 0 )
323
0
            aRepresentation = pDoc->CreatePageNumValue(nPageCount);
324
0
        else
325
0
            aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_COUNT);
326
327
0
        pInfo->SetRepresentation( aRepresentation );
328
0
    }
329
352k
    else if( (pURLField = dynamic_cast< const SvxURLField* >(pField)) != nullptr )
330
14.8k
    {
331
14.8k
        switch ( pURLField->GetFormat() )
332
14.8k
        {
333
0
            case SvxURLFormat::AppDefault: //!!! adjustable at App???
334
14.8k
            case SvxURLFormat::Repr:
335
14.8k
                pInfo->SetRepresentation( pURLField->GetRepresentation() );
336
14.8k
                break;
337
338
0
            case SvxURLFormat::Url:
339
0
                pInfo->SetRepresentation( pURLField->GetURL() );
340
0
                break;
341
14.8k
        }
342
343
14.8k
        const OUString& aURL = pURLField->GetURL();
344
345
14.8k
        svtools::ColorConfig aConfig;
346
14.8k
        svtools::ColorConfigEntry eEntry =
347
14.8k
            INetURLHistory::GetOrCreate()->QueryUrl( aURL ) ? svtools::LINKSVISITED : svtools::LINKS;
348
14.8k
        pInfo->SetTextColor( aConfig.GetColorValue(eEntry).nColor );
349
14.8k
    }
350
337k
    else if ( dynamic_cast< const SdrMeasureField* >(pField))
351
0
    {
352
0
        pInfo->SetFieldColor(std::optional<Color>()); // clear the field color
353
0
    }
354
337k
    else if ((pCustomPropertyField = dynamic_cast<const editeng::CustomPropertyField*>(pField)) != nullptr)
355
0
    {
356
0
        try
357
0
        {
358
0
            SfxObjectShell* pObjSh = SfxObjectShell::Current();
359
0
            if (pObjSh && pObjSh->IsLoadingFinished())
360
0
            {
361
0
                auto pNonConstCustomPropertyField = const_cast<editeng::CustomPropertyField*>(pCustomPropertyField);
362
0
                OUString sCurrent = pNonConstCustomPropertyField->GetFormatted(pObjSh->getDocProperties());
363
0
                pInfo->SetRepresentation(sCurrent);
364
0
            }
365
0
            else
366
0
                pInfo->SetRepresentation(pCustomPropertyField->GetCurrentPresentation());
367
0
        }
368
0
        catch (...)
369
0
        {
370
0
            pInfo->SetRepresentation(pCustomPropertyField->GetCurrentPresentation());
371
0
        }
372
0
    }
373
337k
    else
374
337k
    {
375
337k
        OUString aRepresentation;
376
377
337k
        bool bHeaderField = dynamic_cast< const SvxHeaderField* >( pField ) != nullptr;
378
337k
        bool bFooterField = !bHeaderField && (dynamic_cast< const SvxFooterField* >( pField ) != nullptr );
379
337k
        bool bDateTimeField = !bHeaderField && !bFooterField && (dynamic_cast< const SvxDateTimeField* >( pField ) != nullptr);
380
381
337k
        if( bHeaderField || bFooterField || bDateTimeField )
382
337k
        {
383
337k
            sd::ViewShell* pViewSh = pDocShell ? pDocShell->GetViewShell() : nullptr;
384
337k
            bool bMasterView = false;
385
337k
            SdPage* pPage = GetCurrentPage( pViewSh, pInfo, bMasterView );
386
387
337k
            if( (pPage == nullptr) || bMasterView )
388
337k
            {
389
337k
                if( bHeaderField )
390
75.9k
                    aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_HEADER);
391
261k
                else if (bFooterField )
392
131k
                    aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_FOOTER);
393
129k
                else if (bDateTimeField )
394
129k
                    aRepresentation = SdResId(STR_FIELD_PLACEHOLDER_DATETIME);
395
337k
            }
396
0
            else
397
0
            {
398
0
                const sd::HeaderFooterSettings &rSettings = pPage->getHeaderFooterSettings();
399
400
0
                if( bHeaderField )
401
0
                {
402
0
                    aRepresentation = rSettings.maHeaderText;
403
0
                }
404
0
                else if( bFooterField )
405
0
                {
406
0
                    aRepresentation = rSettings.maFooterText;
407
0
                }
408
0
                else if( bDateTimeField )
409
0
                {
410
0
                    if( rSettings.mbDateTimeIsFixed )
411
0
                    {
412
0
                        aRepresentation = rSettings.maDateTimeText;
413
0
                    }
414
0
                    else
415
0
                    {
416
0
                        DateTime aDateTime( DateTime::SYSTEM );
417
0
                        LanguageType eLang = pInfo->GetOutliner()->GetLanguage( pInfo->GetPara(), pInfo->GetPos() );
418
0
                        aRepresentation = SvxDateTimeField::GetFormatted( aDateTime, aDateTime,
419
0
                                              rSettings.meDateFormat, rSettings.meTimeFormat, *GetNumberFormatter(), eLang );
420
0
                    }
421
0
                }
422
0
            }
423
337k
        }
424
0
        else
425
0
        {
426
0
            OSL_FAIL("sd::SdModule::CalcFieldValueHdl(), unknown field type!");
427
0
        }
428
429
337k
        if( aRepresentation.isEmpty() )                // TODO: Edit engine doesn't handle empty fields?
430
0
            aRepresentation = " ";
431
337k
        pInfo->SetRepresentation( aRepresentation );
432
337k
    }
433
572k
}
434
435
/**
436
 * virtual methods for option dialog
437
 */
438
std::optional<SfxItemSet> SdModule::CreateItemSet( sal_uInt16 nSlot )
439
0
{
440
0
    ::sd::FrameView* pFrameView = nullptr;
441
0
    ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
442
0
    SdDrawDocument* pDoc = nullptr;
443
444
    // Here we set the DocType of the option dialog (not document!)
445
0
    DocumentType eDocType = DocumentType::Impress;
446
0
    if( nSlot == SID_SD_GRAPHIC_OPTIONS )
447
0
        eDocType = DocumentType::Draw;
448
449
0
    if (pDocSh)
450
0
    {
451
0
        pDoc = pDocSh->GetDoc();
452
453
        // If the option dialog is identical to the document type,
454
        // we can pass the FrameView too:
455
0
        if( pDoc && eDocType == pDoc->GetDocumentType() )
456
0
            pFrameView = pDocSh->GetFrameView();
457
458
0
        ::sd::ViewShell* pViewShell = pDocSh->GetViewShell();
459
0
        if (pViewShell != nullptr)
460
0
            pViewShell->WriteFrameViewData();
461
0
    }
462
463
0
    SdOptions* pOptions = GetSdOptions(eDocType);
464
465
    // Pool has by default MapUnit Twips (Awgh!)
466
0
    SfxItemPool& rPool = GetPool();
467
0
    rPool.SetDefaultMetric( MapUnit::Map100thMM );
468
469
0
    SfxItemSet aRet(SfxItemSet::makeFixedSfxItemSet<
470
0
                SID_ATTR_GRID_OPTIONS, SID_ATTR_GRID_OPTIONS,
471
0
                SID_ATTR_METRIC, SID_ATTR_METRIC,
472
0
                SID_ATTR_DEFTABSTOP, SID_ATTR_DEFTABSTOP,
473
0
                ATTR_OPTIONS_LAYOUT, ATTR_OPTIONS_SCALE_END>(rPool));
474
475
0
    sal_uInt16 nDefTab = 0;
476
0
    SvtSysLocale aSysLocale;
477
478
0
    if( pFrameView)
479
0
        nDefTab = pDoc->GetDefaultTabulator();
480
0
    else
481
0
    {
482
0
        if (eDocType == DocumentType::Impress)
483
0
            if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
484
0
                nDefTab = officecfg::Office::Impress::Layout::Other::TabStop::Metric::get();
485
0
            else
486
0
                nDefTab = officecfg::Office::Impress::Layout::Other::TabStop::NonMetric::get();
487
0
        else
488
0
            if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
489
0
                nDefTab = officecfg::Office::Draw::Layout::Other::TabStop::Metric::get();
490
0
            else
491
0
                nDefTab = officecfg::Office::Draw::Layout::Other::TabStop::NonMetric::get();
492
0
    }
493
494
0
    aRet.Put( SfxUInt16Item( SID_ATTR_DEFTABSTOP, nDefTab ) );
495
496
0
    FieldUnit nMetric = FieldUnit(0xffff);
497
498
0
    if( pFrameView)
499
0
        nMetric = pDoc->GetUIUnit();
500
0
    else
501
0
        if (eDocType == DocumentType::Impress)
502
0
            if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
503
0
                nMetric = static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::get());
504
0
            else
505
0
                nMetric = static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::get());
506
0
        else
507
0
            if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
508
0
                nMetric = static_cast<FieldUnit>(officecfg::Office::Draw::Layout::Other::MeasureUnit::Metric::get());
509
0
            else
510
0
                nMetric = static_cast<FieldUnit>(officecfg::Office::Draw::Layout::Other::MeasureUnit::NonMetric::get());
511
512
0
    if( nMetric == FieldUnit(0xffff) )
513
0
        nMetric = GetFieldUnit();
514
515
0
    aRet.Put( SfxUInt16Item( SID_ATTR_METRIC, static_cast<sal_uInt16>(nMetric) ) );
516
517
    // TP_OPTIONS_MISC:
518
0
    SdOptionsMiscItem aSdOptionsMiscItem( pOptions, pFrameView );
519
0
    if ( pFrameView )
520
0
    {
521
0
        aSdOptionsMiscItem.GetOptionsMisc().SetSummationOfParagraphs( pDoc->IsSummationOfParagraphs() );
522
0
        aSdOptionsMiscItem.GetOptionsMisc().SetPrinterIndependentLayout (
523
0
            static_cast<sal_uInt16>(pDoc->GetPrinterIndependentLayout()));
524
0
    }
525
0
    aRet.Put( aSdOptionsMiscItem );
526
527
    // TP_SCALE:
528
0
    sal_uInt32 nW = 10;
529
0
    sal_uInt32 nH = 10;
530
0
    sal_Int32  nX;
531
0
    sal_Int32  nY;
532
0
    if( pDocSh )
533
0
    {
534
0
        assert(pDoc);
535
0
        SdrPage* pPage = pDoc->GetSdPage(0, PageKind::Standard);
536
0
        Size aSize(pPage->GetSize());
537
0
        nW = aSize.Width();
538
0
        nH = aSize.Height();
539
0
    }
540
541
0
    if(pFrameView)
542
0
    {
543
0
        Fraction aFraction(pDoc->GetUIScale());
544
0
        nX=aFraction.GetNumerator();
545
0
        nY=aFraction.GetDenominator();
546
0
    }
547
0
    else
548
0
    {
549
        // Get options from configuration file
550
0
        nX = officecfg::Office::Draw::Zoom::ScaleX::get();
551
0
        nY = officecfg::Office::Draw::Zoom::ScaleY::get();
552
0
    }
553
554
0
    aRet.Put( SfxInt32Item( ATTR_OPTIONS_SCALE_X, nX ) );
555
0
    aRet.Put( SfxInt32Item( ATTR_OPTIONS_SCALE_Y, nY ) );
556
0
    aRet.Put( SfxUInt32Item( ATTR_OPTIONS_SCALE_WIDTH, nW ) );
557
0
    aRet.Put( SfxUInt32Item( ATTR_OPTIONS_SCALE_HEIGHT, nH ) );
558
559
    // TP_OPTIONS_PRINT:
560
0
    aRet.Put( SdOptionsPrintItem( pOptions ) );
561
562
    // RID_SVXPAGE_GRID:
563
0
    aRet.Put( SdOptionsGridItem( pOptions ) );
564
565
0
    return aRet;
566
0
}
567
568
void SdModule::ApplyItemSet( sal_uInt16 nSlot, const SfxItemSet& rSet )
569
0
{
570
0
    bool bNewDefTab = false;
571
0
    bool bNewPrintOptions = false;
572
0
    bool bMiscOptions = false;
573
0
    SvtSysLocale aSysLocale;
574
575
0
    ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
576
0
    SdDrawDocument* pDoc = nullptr;
577
    // Here we set the DocType of the option dialog (not document!)
578
0
    DocumentType eDocType = DocumentType::Impress;
579
0
    if( nSlot == SID_SD_GRAPHIC_OPTIONS )
580
0
        eDocType = DocumentType::Draw;
581
582
0
    ::sd::ViewShell* pViewShell = nullptr;
583
584
0
    if (pDocSh)
585
0
    {
586
0
        pDoc = pDocSh->GetDoc();
587
588
0
        pViewShell = pDocSh->GetViewShell();
589
0
        if (pViewShell != nullptr)
590
0
            pViewShell->WriteFrameViewData();
591
0
    }
592
0
    SdOptions* pOptions = GetSdOptions(eDocType);
593
    // Grid
594
0
    if( const SdOptionsGridItem* pGridItem = static_cast<const SdOptionsGridItem*>(rSet.GetItemIfSet( SID_ATTR_GRID_OPTIONS, false )) )
595
0
    {
596
0
        pGridItem->SetOptions( pOptions );
597
0
    }
598
599
    // Metric
600
0
    if( const SfxUInt16Item* pItem = rSet.GetItemIfSet( SID_ATTR_METRIC, false ) )
601
0
    {
602
0
        if( pDoc && eDocType == pDoc->GetDocumentType() )
603
0
            PutItem( *pItem );
604
605
0
        std::shared_ptr<comphelper::ConfigurationChanges> batch(
606
0
            comphelper::ConfigurationChanges::create());
607
0
        if (eDocType == DocumentType::Impress)
608
0
            if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
609
0
                officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::set(pItem->GetValue(), batch);
610
0
            else
611
0
                officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::set(pItem->GetValue(), batch);
612
0
        else
613
0
            if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
614
0
                officecfg::Office::Draw::Layout::Other::MeasureUnit::Metric::set(pItem->GetValue(), batch);
615
0
            else
616
0
                officecfg::Office::Draw::Layout::Other::MeasureUnit::NonMetric::set(pItem->GetValue(), batch);
617
0
        batch->commit();
618
619
0
    }
620
0
    sal_uInt16 nDefTab;
621
0
    if (eDocType == DocumentType::Impress)
622
0
        if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
623
0
            nDefTab = officecfg::Office::Impress::Layout::Other::TabStop::Metric::get();
624
0
        else
625
0
            nDefTab = officecfg::Office::Impress::Layout::Other::TabStop::NonMetric::get();
626
0
    else
627
0
        if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
628
0
            nDefTab = officecfg::Office::Draw::Layout::Other::TabStop::Metric::get();
629
0
        else
630
0
            nDefTab = officecfg::Office::Draw::Layout::Other::TabStop::NonMetric::get();
631
632
    // Default-Tabulator
633
0
    if( const SfxUInt16Item* pItem = rSet.GetItemIfSet( SID_ATTR_DEFTABSTOP, false ) )
634
0
    {
635
0
        nDefTab = pItem->GetValue();
636
0
        std::shared_ptr<comphelper::ConfigurationChanges> batch(
637
0
            comphelper::ConfigurationChanges::create());
638
639
0
        if (eDocType == DocumentType::Impress)
640
0
            if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
641
0
                officecfg::Office::Impress::Layout::Other::TabStop::Metric::set(nDefTab, batch);
642
0
            else
643
0
                officecfg::Office::Impress::Layout::Other::TabStop::NonMetric::set(nDefTab, batch);
644
0
        else
645
0
            if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
646
0
                officecfg::Office::Draw::Layout::Other::TabStop::Metric::set(nDefTab, batch);
647
0
            else
648
0
                officecfg::Office::Draw::Layout::Other::TabStop::NonMetric::set(nDefTab, batch);
649
0
        batch->commit();
650
651
0
        bNewDefTab = true;
652
0
    }
653
654
    // Scale
655
0
    if( const SfxInt32Item* pItem = rSet.GetItemIfSet( ATTR_OPTIONS_SCALE_X, false ) )
656
0
    {
657
0
        sal_Int32 nX = pItem->GetValue();
658
0
        pItem = rSet.GetItemIfSet( ATTR_OPTIONS_SCALE_Y, false );
659
0
        if( pItem )
660
0
        {
661
0
            sal_Int32 nY = pItem->GetValue();
662
0
            std::shared_ptr<comphelper::ConfigurationChanges> batch(
663
0
                comphelper::ConfigurationChanges::create());
664
665
0
            officecfg::Office::Draw::Zoom::ScaleX::set(nX, batch);
666
0
            officecfg::Office::Draw::Zoom::ScaleY::set(nY, batch);
667
0
            batch->commit();
668
669
            // Apply to document only if doc type match
670
0
            if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() )
671
0
            {
672
0
                pDoc->SetUIScale( double(nX) / nY );
673
0
                if( pViewShell )
674
                    // tdf#155798 - refresh ruler after scale change
675
0
                    pViewShell->GetViewShellBase().UpdateBorder(true);
676
0
            }
677
0
        }
678
0
    }
679
680
    // Misc
681
0
    const SdOptionsMiscItem* pMiscItem = rSet.GetItemIfSet( ATTR_OPTIONS_MISC, false);
682
0
    if( pMiscItem )
683
0
    {
684
0
        pMiscItem->SetOptions( pOptions );
685
0
        bMiscOptions = true;
686
0
    }
687
688
0
    SfxItemSet aPrintSet(SfxItemSet::makeFixedSfxItemSet<
689
0
                SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
690
0
                SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
691
0
                ATTR_OPTIONS_PRINT, ATTR_OPTIONS_PRINT>(GetPool()));
692
693
    // Print
694
0
    const SdOptionsPrintItem* pPrintItem = rSet.GetItemIfSet( ATTR_OPTIONS_PRINT, false);
695
0
    if( pPrintItem )
696
0
    {
697
0
        pPrintItem->SetOptions( pOptions );
698
699
        // set PrintOptionsSet
700
0
        SdOptionsPrintItem aPrintItem( pOptions );
701
0
        SfxFlagItem aFlagItem( SID_PRINTER_CHANGESTODOC );
702
0
        SfxPrinterChangeFlags nFlags =
703
0
                (aPrintItem.GetOptionsPrint().IsWarningSize() ? SfxPrinterChangeFlags::CHG_SIZE : SfxPrinterChangeFlags::NONE) |
704
0
                (aPrintItem.GetOptionsPrint().IsWarningOrientation() ? SfxPrinterChangeFlags::CHG_ORIENTATION : SfxPrinterChangeFlags::NONE);
705
0
        aFlagItem.SetValue( static_cast<int>(nFlags) );
706
707
0
        aPrintSet.Put( aPrintItem );
708
0
        aPrintSet.Put( SfxBoolItem( SID_PRINTER_NOTFOUND_WARN, aPrintItem.GetOptionsPrint().IsWarningPrinter() ) );
709
0
        aPrintSet.Put( aFlagItem );
710
711
0
        bNewPrintOptions = true;
712
0
    }
713
714
    // Only if also the document type matches...
715
0
    if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() )
716
0
    {
717
0
        if( bNewPrintOptions )
718
0
        {
719
0
            pDocSh->GetPrinter(true)->SetOptions( aPrintSet );
720
0
        }
721
722
        // set DefTab at Model
723
0
        if( bNewDefTab )
724
0
        {
725
0
            SdDrawDocument* pDocument = pDocSh->GetDoc();
726
0
            pDocument->SetDefaultTabulator( nDefTab );
727
728
0
            SdOutliner* pOutl = pDocument->GetOutliner( false );
729
0
            if( pOutl )
730
0
                pOutl->SetDefTab( nDefTab );
731
732
0
            SdOutliner* pInternalOutl = pDocument->GetInternalOutliner( false );
733
0
            if( pInternalOutl )
734
0
                pInternalOutl->SetDefTab( nDefTab );
735
0
        }
736
0
        if ( bMiscOptions )
737
0
        {
738
0
            pDoc->SetSummationOfParagraphs( pMiscItem->GetOptionsMisc().IsSummationOfParagraphs() );
739
0
            EEControlBits nSum = pMiscItem->GetOptionsMisc().IsSummationOfParagraphs() ? EEControlBits::ULSPACESUMMATION : EEControlBits::NONE;
740
0
            EEControlBits nCntrl;
741
742
0
            SdDrawDocument* pDocument = pDocSh->GetDoc();
743
0
            SdrOutliner& rOutl = pDocument->GetDrawOutliner();
744
0
            nCntrl = rOutl.GetControlWord() &~ EEControlBits::ULSPACESUMMATION;
745
0
            rOutl.SetControlWord( nCntrl | nSum );
746
0
            SdOutliner* pOutl = pDocument->GetOutliner( false );
747
0
            if( pOutl )
748
0
            {
749
0
                nCntrl = pOutl->GetControlWord() &~ EEControlBits::ULSPACESUMMATION;
750
0
                pOutl->SetControlWord( nCntrl | nSum );
751
0
            }
752
0
            pOutl = pDocument->GetInternalOutliner( false );
753
0
            if( pOutl )
754
0
            {
755
0
                nCntrl = pOutl->GetControlWord() &~ EEControlBits::ULSPACESUMMATION;
756
0
                pOutl->SetControlWord( nCntrl | nSum );
757
0
            }
758
759
            // Set printer independent layout mode.
760
0
            if( pDoc->GetPrinterIndependentLayout() != pMiscItem->GetOptionsMisc().GetPrinterIndependentLayout() )
761
0
                pDoc->SetPrinterIndependentLayout (pMiscItem->GetOptionsMisc().GetPrinterIndependentLayout());
762
0
        }
763
0
    }
764
765
0
    pOptions->StoreConfig();
766
767
    // Only if also the document type matches...
768
0
    if( pDocSh && pDoc && eDocType == pDoc->GetDocumentType() )
769
0
    {
770
0
        FieldUnit eUIUnit;
771
0
        if (eDocType == DocumentType::Impress)
772
0
            if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
773
0
                eUIUnit = static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::get());
774
0
            else
775
0
                eUIUnit = static_cast<FieldUnit>(officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::get());
776
0
        else
777
0
            if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
778
0
                eUIUnit = static_cast<FieldUnit>(officecfg::Office::Draw::Layout::Other::MeasureUnit::Metric::get());
779
0
            else
780
0
                eUIUnit = static_cast<FieldUnit>(officecfg::Office::Draw::Layout::Other::MeasureUnit::NonMetric::get());
781
782
0
        pDoc->SetUIUnit(eUIUnit);
783
784
0
        if (pViewShell)
785
0
        {
786
            // make sure no one is in text edit mode, cause there
787
            // are some pointers remembered else (!)
788
0
            if(pViewShell->GetView())
789
0
                pViewShell->GetView()->SdrEndTextEdit();
790
791
0
            ::sd::FrameView* pFrame = pViewShell->GetFrameView();
792
0
            pFrame->Update(pOptions);
793
0
            pViewShell->ReadFrameViewData(pFrame);
794
0
            pViewShell->SetUIUnit(eUIUnit);
795
0
            pViewShell->SetDefTabHRuler( nDefTab );
796
0
        }
797
0
    }
798
799
0
    if( pViewShell && pViewShell->GetViewFrame() )
800
0
        pViewShell->GetViewFrame()->GetBindings().InvalidateAll( true );
801
0
}
802
803
std::unique_ptr<SfxTabPage> SdModule::CreateTabPage( sal_uInt16 nId, weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet )
804
0
{
805
0
    std::unique_ptr<SfxTabPage> xRet;
806
0
    SfxAllItemSet aSet(*(rSet.GetPool()));
807
0
    SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
808
809
0
    switch(nId)
810
0
    {
811
0
        case SID_SD_TP_CONTENTS:
812
0
        case SID_SI_TP_CONTENTS:
813
0
        {
814
0
            ::CreateTabPage fnCreatePage = pFact->GetSdOptionsContentsTabPageCreatorFunc();
815
0
            if( fnCreatePage )
816
0
            {
817
0
                xRet = (*fnCreatePage)( pPage, pController, &rSet );
818
0
                if (SID_SD_TP_CONTENTS == nId)
819
0
                    aSet.Put(SfxUInt32Item(SID_SDMODE_FLAG, SD_DRAW_MODE));
820
0
                else
821
0
                    aSet.Put(SfxUInt32Item(SID_SDMODE_FLAG, SD_IMPRESS_MODE));
822
0
                xRet->PageCreated(aSet);
823
0
            }
824
0
        }
825
0
        break;
826
0
        case SID_SD_TP_SNAP:
827
0
        case SID_SI_TP_SNAP:
828
0
        {
829
0
            ::CreateTabPage fnCreatePage = pFact->GetSdOptionsSnapTabPageCreatorFunc();
830
0
            if( fnCreatePage )
831
0
                xRet = (*fnCreatePage)( pPage, pController, &rSet );
832
0
        }
833
0
        break;
834
0
        case SID_SD_TP_PRINT:
835
0
        case SID_SI_TP_PRINT:
836
0
        {
837
0
            ::CreateTabPage fnCreatePage = pFact->GetSdPrintOptionsTabPageCreatorFunc();
838
0
            if( fnCreatePage )
839
0
            {
840
0
                xRet = (*fnCreatePage)( pPage, pController, &rSet );
841
0
                if(SID_SD_TP_PRINT == nId)
842
0
                    aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_DRAW_MODE));
843
0
                xRet->PageCreated(aSet);
844
0
            }
845
0
        }
846
0
        break;
847
0
        case SID_SI_TP_MISC:
848
0
        case SID_SD_TP_MISC:
849
0
        {
850
0
            ::CreateTabPage fnCreatePage = pFact->GetSdOptionsMiscTabPageCreatorFunc();
851
0
            if( fnCreatePage )
852
0
            {
853
0
                xRet = (*fnCreatePage)( pPage, pController, &rSet );
854
0
                if(SID_SD_TP_MISC == nId)
855
0
                    aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_DRAW_MODE));
856
0
                else
857
0
                    aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_IMPRESS_MODE));
858
0
                xRet->PageCreated(aSet);
859
0
            }
860
0
        }
861
0
        break;
862
0
        case RID_SVXPAGE_TEXTANIMATION :
863
0
        {
864
0
            SfxAbstractDialogFactory* pSfxFact = SfxAbstractDialogFactory::Create();
865
0
            ::CreateTabPage fnCreatePage = pSfxFact->GetTabPageCreatorFunc( nId );
866
0
            if ( fnCreatePage )
867
0
                xRet = (*fnCreatePage)( pPage, pController, &rSet );
868
0
        }
869
0
        break;
870
0
    }
871
0
    DBG_ASSERT( xRet, "SdModule::CreateTabPage(): no valid ID for TabPage!" );
872
873
0
    return xRet;
874
0
}
875
876
SfxStyleFamilies SdModule::CreateStyleFamilies()
877
0
{
878
0
    SfxStyleFamilies aStyleFamilies;
879
0
    std::locale resLocale = SdModule::get()->GetResLocale();
880
881
0
    aStyleFamilies.emplace_back(SfxStyleFamily::Para,
882
0
                                 SdResId(STR_GRAPHICS_STYLE_FAMILY),
883
0
                                 BMP_STYLES_FAMILY_GRAPHICS,
884
0
                                 RID_GRAPHICSTYLEFAMILY, resLocale);
885
886
0
    aStyleFamilies.emplace_back(SfxStyleFamily::Pseudo,
887
0
                                 SdResId(STR_PRESENTATIONS_STYLE_FAMILY),
888
0
                                 BMP_STYLES_FAMILY_PRESENTATIONS,
889
0
                                 RID_PRESENTATIONSTYLEFAMILY, resLocale);
890
891
0
    return aStyleFamilies;
892
0
}
893
894
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */