Coverage Report

Created: 2025-12-31 10:39

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/app/sdmod1.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 <svl/lckbitem.hxx>
21
#include <svl/intitem.hxx>
22
#include <sfx2/frame.hxx>
23
#include <sfx2/viewfrm.hxx>
24
#include <unotools/localedatawrapper.hxx>
25
#include <unotools/moduleoptions.hxx>
26
#include <unotools/syslocale.hxx>
27
#include <framework/FrameworkHelper.hxx>
28
#include <osl/diagnose.h>
29
#include <vcl/commandevent.hxx>
30
#include <vcl/svapp.hxx>
31
#include <vcl/errinf.hxx>
32
#include <editeng/langitem.hxx>
33
#include <vcl/weld/weld.hxx>
34
#include <sfx2/dispatch.hxx>
35
#include <sfx2/docfile.hxx>
36
#include <sfx2/request.hxx>
37
#include <sfx2/templatedlg.hxx>
38
#include <svl/stritem.hxx>
39
#include <editeng/eeitem.hxx>
40
41
#include <svx/svxids.hrc>
42
#include <strings.hrc>
43
44
#include <sdmod.hxx>
45
#include <pres.hxx>
46
#include <optsitem.hxx>
47
#include <ViewShell.hxx>
48
#include <DrawDocShell.hxx>
49
#include <drawdoc.hxx>
50
#include <sdresid.hxx>
51
#include <OutlineView.hxx>
52
#include <OutlineViewShell.hxx>
53
#include <ViewShellBase.hxx>
54
#include <FactoryIds.hxx>
55
#include <memory>
56
#include <slideshow.hxx>
57
#include <ResourceId.hxx>
58
59
#include <officecfg/Office/Draw.hxx>
60
#include <officecfg/Office/Impress.hxx>
61
62
using ::sd::framework::FrameworkHelper;
63
using ::com::sun::star::uno::Reference;
64
using ::com::sun::star::frame::XFrame;
65
66
namespace {
67
68
class OutlineToImpressFinalizer final
69
{
70
public:
71
    OutlineToImpressFinalizer (
72
        ::sd::ViewShellBase& rBase,
73
        SdDrawDocument& rDocument,
74
        css::uno::Sequence<sal_Int8> const & rBytes);
75
    void operator() (bool bEventSeen);
76
private:
77
    ::sd::ViewShellBase& mrBase;
78
    SdDrawDocument& mrDocument;
79
    std::shared_ptr<SvMemoryStream> mpStream;
80
};
81
82
} //end of anonymous namespace
83
84
void SdModule::Execute(SfxRequest& rReq)
85
0
{
86
0
    const SfxItemSet* pSet = rReq.GetArgs();
87
0
    sal_uInt16 nSlotId = rReq.GetSlot();
88
89
0
    switch ( nSlotId )
90
0
    {
91
0
        case SID_NEWDOC:
92
0
        {
93
0
            SfxGetpApp()->ExecuteSlot(rReq, SfxGetpApp()->GetInterface());
94
0
        }
95
0
        break;
96
97
0
        case SID_AUTOSPELL_CHECK:
98
0
        {
99
            // automatic spell checker
100
0
            const SfxBoolItem* pItem;
101
0
            if( pSet && (pItem = pSet->GetItemIfSet( SID_AUTOSPELL_CHECK, false ) ) )
102
0
            {
103
0
                bool bOnlineSpelling = pItem->GetValue();
104
                // save at document:
105
0
                ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
106
0
                if( pDocSh )
107
0
                {
108
0
                    SdDrawDocument* pDoc = pDocSh->GetDoc();
109
0
                    pDoc->SetOnlineSpell( bOnlineSpelling );
110
0
                }
111
0
            }
112
0
        }
113
0
        break;
114
115
0
        case SID_ATTR_METRIC:
116
0
        {
117
0
            const SfxUInt16Item* pItem;
118
0
            if ( pSet && (pItem = pSet->GetItemIfSet( SID_ATTR_METRIC ) ) )
119
0
            {
120
0
                FieldUnit eUnit = static_cast<FieldUnit>(pItem->GetValue());
121
0
                switch( eUnit )
122
0
                {
123
0
                    case FieldUnit::MM:      // only the units which are also in the dialog
124
0
                    case FieldUnit::CM:
125
0
                    case FieldUnit::INCH:
126
0
                    case FieldUnit::PICA:
127
0
                    case FieldUnit::POINT:
128
0
                        {
129
0
                            ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
130
0
                            if(pDocSh)
131
0
                            {
132
0
                                DocumentType eDocType = pDocSh->GetDoc()->GetDocumentType();
133
134
0
                                PutItem( *pItem );
135
0
                                SvtSysLocale aSysLocale;
136
0
                                std::shared_ptr<comphelper::ConfigurationChanges> batch(
137
0
                                    comphelper::ConfigurationChanges::create());
138
139
0
                                if (eDocType == DocumentType::Impress)
140
0
                                    if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
141
0
                                        officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::set(static_cast<sal_uInt16>(eUnit), batch);
142
0
                                    else
143
0
                                        officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::set(static_cast<sal_uInt16>(eUnit), batch);
144
0
                                else
145
0
                                    if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
146
0
                                        officecfg::Office::Draw::Layout::Other::MeasureUnit::Metric::set(static_cast<sal_uInt16>(eUnit), batch);
147
0
                                else
148
0
                                        officecfg::Office::Draw::Layout::Other::MeasureUnit::NonMetric::set(static_cast<sal_uInt16>(eUnit), batch);
149
0
                                batch->commit();
150
0
                                rReq.Done();
151
0
                            }
152
0
                        }
153
0
                        break;
154
0
                    default:
155
0
                        break;
156
0
                }
157
0
            }
158
159
0
        }
160
0
        break;
161
162
0
        case SID_ATTR_LANGUAGE:
163
0
        case SID_ATTR_CHAR_CJK_LANGUAGE:
164
0
        case SID_ATTR_CHAR_CTL_LANGUAGE:
165
0
        {
166
0
            const SfxPoolItem* pItem;
167
0
            if( pSet &&
168
0
                (
169
0
                SfxItemState::SET == pSet->GetItemState(SID_ATTR_LANGUAGE, false, &pItem ) ||
170
0
                SfxItemState::SET == pSet->GetItemState(SID_ATTR_CHAR_CJK_LANGUAGE, false, &pItem ) ||
171
0
                SfxItemState::SET == pSet->GetItemState(SID_ATTR_CHAR_CTL_LANGUAGE, false, &pItem )
172
0
                )
173
0
              )
174
0
            {
175
                // save at the document:
176
0
                ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
177
0
                if ( pDocSh )
178
0
                {
179
0
                    LanguageType eLanguage = static_cast<const SvxLanguageItem*>(pItem)->GetValue();
180
0
                    SdDrawDocument* pDoc = pDocSh->GetDoc();
181
182
0
                    if( nSlotId == SID_ATTR_CHAR_CJK_LANGUAGE )
183
0
                        pDoc->SetLanguage( eLanguage, EE_CHAR_LANGUAGE_CJK );
184
0
                    else if( nSlotId == SID_ATTR_CHAR_CTL_LANGUAGE )
185
0
                        pDoc->SetLanguage( eLanguage, EE_CHAR_LANGUAGE_CTL );
186
0
                    else
187
0
                        pDoc->SetLanguage( eLanguage, EE_CHAR_LANGUAGE );
188
189
0
                    if( pDoc->GetOnlineSpell() )
190
0
                    {
191
0
                        pDoc->StopOnlineSpelling();
192
0
                        pDoc->StartOnlineSpelling();
193
0
                    }
194
0
                }
195
0
            }
196
0
        }
197
0
        break;
198
199
0
        case SID_NEWSD:
200
0
            {
201
0
                SfxFrame* pFrame = ExecuteNewDocument( rReq );
202
                // if a frame was created, set it as return value
203
0
                if(pFrame)
204
0
                    rReq.SetReturnValue(SfxFrameItem(0, pFrame));
205
0
            }
206
207
0
            break;
208
209
0
        case SID_OPENHYPERLINK:
210
0
        case SID_OPENDOC:
211
0
        {
212
0
            bool bIntercept = false;
213
0
            ::sd::DrawDocShell* pDocShell = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
214
0
            ::sd::ViewShell* pViewShell = pDocShell ? pDocShell->GetViewShell() : nullptr;
215
0
            if (pViewShell)
216
0
            {
217
0
                if( sd::SlideShow::IsRunning( pViewShell->GetViewShellBase() )
218
0
                    && !sd::SlideShow::IsInteractiveSlideshow( pViewShell->GetViewShellBase() ) ) // IASS
219
0
                {
220
                    // Prevent documents from opening while the slide
221
                    // show is running, except when this request comes
222
                    // from a shape interaction.
223
0
                    if (rReq.GetArgs() == nullptr)
224
0
                    {
225
0
                        bIntercept = true;
226
0
                    }
227
0
                }
228
0
            }
229
230
0
            if (!bIntercept)
231
0
            {
232
0
                if (const SfxStringItem* pURLItem = rReq.GetArg(SID_FILE_NAME))
233
0
                {
234
0
                    if (!pViewShell || !SfxObjectShell::AllowedLinkProtocolFromDocument(pURLItem->GetValue(),
235
0
                                                                                        pViewShell->GetObjectShell(),
236
0
                                                                                        pViewShell->GetFrameWeld()))
237
0
                    {
238
0
                        return;
239
0
                    }
240
0
                }
241
0
                SfxGetpApp()->ExecuteSlot(rReq, SfxGetpApp()->GetInterface());
242
0
            }
243
0
            else
244
0
            {
245
0
                std::unique_ptr<weld::MessageDialog> xErrorBox(Application::CreateMessageDialog(rReq.GetFrameWeld(),
246
0
                                                               VclMessageType::Warning, VclButtonsType::Ok, SdResId(STR_CANT_PERFORM_IN_LIVEMODE)));
247
248
0
                xErrorBox->run();
249
250
0
                const SfxLinkItem* pLinkItem = rReq.GetArg<SfxLinkItem>(SID_DONELINK);
251
0
                if( pLinkItem )
252
0
                    pLinkItem->GetValue().Call( nullptr );
253
0
            }
254
0
        }
255
0
        break;
256
257
0
        case SID_OUTLINE_TO_IMPRESS:
258
0
            OutlineToImpress (rReq);
259
0
            break;
260
261
0
        default:
262
0
        break;
263
0
    }
264
0
}
265
266
bool SdModule::OutlineToImpress(SfxRequest const & rRequest)
267
0
{
268
0
    const SfxItemSet* pSet = rRequest.GetArgs();
269
270
0
    if (pSet)
271
0
    {
272
0
        css::uno::Sequence<sal_Int8> pBytes = static_cast<const SfxLockBytesItem&>(pSet->Get(SID_OUTLINE_TO_IMPRESS)).GetValue();
273
274
0
        if (pBytes.getLength())
275
0
        {
276
0
            rtl::Reference<sd::DrawDocShell> pDocSh = new ::sd::DrawDocShell(
277
0
                SfxObjectCreateMode::STANDARD, false, DocumentType::Impress);
278
0
            SfxObjectShellLock xDocShell(pDocSh.get());
279
280
0
            pDocSh->DoInitNew();
281
0
            SdDrawDocument* pDoc = pDocSh->GetDoc();
282
0
            if(pDoc)
283
0
            {
284
0
                pDoc->CreateFirstPages();
285
0
                pDoc->StopWorkStartupDelay();
286
0
            }
287
288
0
            const SfxFrameItem* pFrmItem = rRequest.GetArg<SfxFrameItem>(SID_DOCFRAME);
289
0
            SfxViewFrame::LoadDocumentIntoFrame( *pDocSh, pFrmItem, ::sd::OUTLINE_FACTORY_ID );
290
291
0
            ::sd::ViewShell* pViewSh = pDocSh->GetViewShell();
292
293
0
            if (pViewSh && pDoc)
294
0
            {
295
                // AutoLayouts have to be finished
296
0
                pDoc->StopWorkStartupDelay();
297
298
0
                if (SfxViewFrame* pViewFrame = pViewSh->GetViewFrame())
299
0
                {
300
                    // When the view frame has not been just created we have
301
                    // to switch synchronously to the outline view.
302
                    // (Otherwise the request will be ignored anyway.)
303
0
                    ::sd::ViewShellBase* pBase
304
0
                        = dynamic_cast< ::sd::ViewShellBase*>(pViewFrame->GetViewShell());
305
0
                    if (pBase != nullptr)
306
0
                    {
307
0
                        std::shared_ptr<FrameworkHelper> pHelper (
308
0
                            FrameworkHelper::Instance(*pBase));
309
0
                        pHelper->RequestView(
310
0
                            FrameworkHelper::msOutlineViewURL,
311
0
                            FrameworkHelper::msCenterPaneURL);
312
313
0
                        pHelper->RunOnResourceActivation(
314
0
                            new ::sd::framework::ResourceId(
315
0
                                FrameworkHelper::msOutlineViewURL,
316
0
                                FrameworkHelper::msCenterPaneURL),
317
0
                            OutlineToImpressFinalizer(*pBase, *pDoc, pBytes));
318
0
                    }
319
0
                }
320
0
            }
321
0
        }
322
0
    }
323
324
0
    return rRequest.IsDone();
325
0
}
326
327
void SdModule::GetState(SfxItemSet& rItemSet)
328
0
{
329
0
    if( SfxItemState::DEFAULT == rItemSet.GetItemState( SID_ATTR_METRIC ) )
330
0
    {
331
0
        ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
332
0
        if(pDocSh)
333
0
        {
334
0
            DocumentType eDocType = pDocSh->GetDoc()->GetDocumentType();
335
0
            SvtSysLocale aSysLocale;
336
337
0
            if (eDocType == DocumentType::Impress)
338
0
                if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
339
0
                    rItemSet.Put( SfxUInt16Item( SID_ATTR_METRIC, officecfg::Office::Impress::Layout::Other::MeasureUnit::Metric::get() ) );
340
0
                else
341
0
                    rItemSet.Put( SfxUInt16Item( SID_ATTR_METRIC, officecfg::Office::Impress::Layout::Other::MeasureUnit::NonMetric::get() ) );
342
0
            else
343
0
                if (aSysLocale.GetLocaleData().getMeasurementSystemEnum() == MeasurementSystem::Metric)
344
0
                    rItemSet.Put( SfxUInt16Item( SID_ATTR_METRIC, officecfg::Office::Draw::Layout::Other::MeasureUnit::Metric::get() ) );
345
0
                else
346
0
                    rItemSet.Put( SfxUInt16Item( SID_ATTR_METRIC, officecfg::Office::Draw::Layout::Other::MeasureUnit::NonMetric::get() ) );
347
0
        }
348
0
    }
349
350
    // state of SID_OPENDOC is determined by the base class
351
0
    if (rItemSet.GetItemState(SID_OPENDOC) != SfxItemState::UNKNOWN)
352
0
    {
353
0
        const SfxPoolItemHolder aItem(SfxGetpApp()->GetSlotState(SID_OPENDOC, SfxGetpApp()->GetInterface()));
354
0
        if (aItem)
355
0
            rItemSet.Put(*aItem.getItem());
356
0
    }
357
358
    // state of SID_OPENHYPERLINK is determined by the base class
359
0
    if (rItemSet.GetItemState(SID_OPENHYPERLINK) != SfxItemState::UNKNOWN)
360
0
    {
361
0
        const SfxPoolItemHolder aItem(SfxGetpApp()->GetSlotState(SID_OPENHYPERLINK, SfxGetpApp()->GetInterface()));
362
0
        if (aItem)
363
0
            rItemSet.Put(*aItem.getItem());
364
0
    }
365
366
0
    if( SfxItemState::DEFAULT == rItemSet.GetItemState( SID_AUTOSPELL_CHECK ) )
367
0
    {
368
0
        ::sd::DrawDocShell* pDocSh =
369
0
              dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
370
0
        if( pDocSh )
371
0
        {
372
0
            SdDrawDocument* pDoc = pDocSh->GetDoc();
373
0
            rItemSet.Put( SfxBoolItem( SID_AUTOSPELL_CHECK, pDoc->GetOnlineSpell() ) );
374
0
        }
375
0
    }
376
377
0
    if( SfxItemState::DEFAULT == rItemSet.GetItemState( SID_ATTR_LANGUAGE ) )
378
0
    {
379
0
        ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
380
0
        if( pDocSh )
381
0
            rItemSet.Put( SvxLanguageItem( pDocSh->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE ), SID_ATTR_LANGUAGE ) );
382
0
    }
383
384
0
    if( SfxItemState::DEFAULT == rItemSet.GetItemState( SID_ATTR_CHAR_CJK_LANGUAGE ) )
385
0
    {
386
0
        ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
387
0
        if( pDocSh )
388
0
            rItemSet.Put( SvxLanguageItem( pDocSh->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE_CJK ), SID_ATTR_CHAR_CJK_LANGUAGE ) );
389
0
    }
390
391
0
    if( SfxItemState::DEFAULT == rItemSet.GetItemState( SID_ATTR_CHAR_CTL_LANGUAGE ) )
392
0
    {
393
0
        ::sd::DrawDocShell* pDocSh = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
394
0
        if( pDocSh )
395
0
            rItemSet.Put( SvxLanguageItem( pDocSh->GetDoc()->GetLanguage( EE_CHAR_LANGUAGE_CTL ), SID_ATTR_CHAR_CTL_LANGUAGE ) );
396
0
    }
397
398
0
    if ( mbEventListenerAdded )
399
0
        return;
400
401
0
    ::sd::DrawDocShell* pDocShell = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
402
0
    if( pDocShell ) // Impress or Draw ?
403
0
    {
404
0
        ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
405
406
0
        if( pViewShell && (pDocShell->GetDocumentType() == DocumentType::Impress) )
407
0
        {
408
            // add our event listener as soon as possible
409
0
            Application::AddEventListener( LINK( this, SdModule, EventListenerHdl ) );
410
0
            mbEventListenerAdded = true;
411
0
        }
412
0
    }
413
0
}
414
415
IMPL_STATIC_LINK( SdModule, EventListenerHdl, VclSimpleEvent&, rSimpleEvent, void )
416
0
{
417
0
    if( !((rSimpleEvent.GetId() == VclEventId::WindowCommand) && static_cast<VclWindowEvent*>(&rSimpleEvent)->GetData()) )
418
0
        return;
419
420
0
    const CommandEvent& rEvent = *static_cast<const CommandEvent*>(static_cast<VclWindowEvent*>(&rSimpleEvent)->GetData());
421
422
0
    if( rEvent.GetCommand() != CommandEventId::Media )
423
0
        return;
424
425
0
    CommandMediaData* pMediaData = rEvent.GetMediaData();
426
0
    pMediaData->SetPassThroughToOS(false);
427
0
    switch (pMediaData->GetMediaId())
428
0
    {
429
0
        case MediaCommand::Play:
430
0
        {
431
0
            ::sd::DrawDocShell* pDocShell = dynamic_cast< ::sd::DrawDocShell *>( SfxObjectShell::Current() );
432
0
            if( pDocShell )  // Impress or Draw ?
433
0
            {
434
0
                ::sd::ViewShell* pViewShell = pDocShell->GetViewShell();
435
436
                // #i97925# start the presentation if and only if an Impress document is focused
437
0
                if( pViewShell && (pDocShell->GetDocumentType() == DocumentType::Impress) )
438
0
                    pViewShell->GetViewFrame()->GetDispatcher()->Execute( SID_PRESENTATION );
439
0
            }
440
0
            break;
441
0
        }
442
0
        default:
443
0
            pMediaData->SetPassThroughToOS(true);
444
0
            break;
445
0
    }
446
0
}
447
448
449
SfxFrame* SdModule::CreateFromTemplate(const OUString& rTemplatePath, const Reference<XFrame>& i_rFrame,
450
                                       const bool bReplaceable)
451
0
{
452
0
    SfxFrame* pFrame = nullptr;
453
454
0
    SfxObjectShellLock xDocShell;
455
456
0
    std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet( SfxGetpApp()->GetPool() ));
457
0
    pSet->Put( SfxBoolItem( SID_TEMPLATE, true ) );
458
459
0
    ErrCodeMsg lErr = SfxGetpApp()->LoadTemplate( xDocShell, rTemplatePath, std::move(pSet) );
460
461
0
    SfxObjectShell* pDocShell = xDocShell;
462
463
0
    if( lErr )
464
0
    {
465
0
        ErrorHandler::HandleError(lErr);
466
0
    }
467
0
    else if( pDocShell )
468
0
    {
469
0
        if (pDocShell->GetMedium())
470
0
            pDocShell->GetMedium()->GetItemSet().Put(SfxBoolItem(SID_REPLACEABLE, bReplaceable));
471
0
        SfxViewFrame* pViewFrame = SfxViewFrame::LoadDocumentIntoFrame( *pDocShell, i_rFrame );
472
0
        OSL_ENSURE( pViewFrame, "SdModule::CreateFromTemplate: no view frame - was the document really loaded?" );
473
0
        pFrame = pViewFrame ? &pViewFrame->GetFrame() : nullptr;
474
0
    }
475
476
0
    return pFrame;
477
478
0
}
479
480
SfxFrame* SdModule::ExecuteNewDocument( SfxRequest const & rReq )
481
0
{
482
0
    SfxFrame* pFrame = nullptr;
483
0
    if (SvtModuleOptions().IsImpressInstalled())
484
0
    {
485
0
        Reference< XFrame > xTargetFrame;
486
0
        const SfxUnoFrameItem* pFrmItem = rReq.GetArg(SID_FILLFRAME);
487
0
        if ( pFrmItem )
488
0
            xTargetFrame = pFrmItem->GetFrame();
489
490
0
        SdOptions* pOpt = GetSdOptions(DocumentType::Impress);
491
0
        bool bStartWithTemplate = pOpt->IsStartWithTemplate();
492
493
0
        bool bNewDocDirect = rReq.GetSlot() == SID_NEWSD;
494
495
0
        if( bNewDocDirect )
496
0
        {
497
            //we start without wizard
498
499
            //check whether we should load a template document
500
0
            OUString aStandardTemplate( SfxObjectFactory::GetStandardTemplate( u"com.sun.star.presentation.PresentationDocument" ) );
501
502
0
            if( !aStandardTemplate.isEmpty() )
503
0
            {
504
                //load a template document
505
0
                pFrame = CreateFromTemplate(aStandardTemplate, xTargetFrame, true);
506
0
            }
507
0
            else
508
0
            {
509
                //create an empty document
510
0
                pFrame = CreateEmptyDocument( xTargetFrame );
511
0
            }
512
0
        }
513
514
0
        if (bStartWithTemplate)
515
0
        {
516
            //Launch TemplateSelectionDialog
517
0
            SfxTemplateSelectionDlg aTemplDlg(SfxGetpApp()->GetTopWindow());
518
0
            aTemplDlg.run();
519
520
            //check to disable the dialog
521
0
            pOpt->SetStartWithTemplate( aTemplDlg.IsStartWithTemplate() );
522
523
            //pFrame is loaded with the desired template
524
0
            if (!aTemplDlg.getTemplatePath().isEmpty())
525
0
                pFrame = CreateFromTemplate(aTemplDlg.getTemplatePath(), xTargetFrame, false);
526
527
            // show tip-of-the-day dialog if it was deferred because SfxTemplateSelectionDlg
528
            // was open
529
0
            if (pFrame && SfxApplication::IsTipOfTheDayDue() && !SfxApplication::IsHeadlessOrUITest())
530
0
            {
531
0
                if (SfxDispatcher* pDispatcher = GetDispatcher())
532
0
                {
533
                    // tdf#127946 pass in argument for dialog parent
534
0
                    SfxUnoFrameItem aDocFrame(SID_FILLFRAME, pFrame->GetFrameInterface());
535
0
                    pDispatcher->ExecuteList(SID_TIPOFTHEDAY, SfxCallMode::SLOT, {}, { &aDocFrame });
536
0
                }
537
0
            }
538
0
        }
539
0
    }
540
541
0
    return pFrame;
542
0
}
543
544
SfxFrame* SdModule::CreateEmptyDocument( const Reference< XFrame >& i_rFrame )
545
0
{
546
0
    SfxFrame* pFrame = nullptr;
547
548
0
    rtl::Reference<sd::DrawDocShell> pNewDocSh = new ::sd::DrawDocShell(SfxObjectCreateMode::STANDARD,false,DocumentType::Impress);
549
0
    SfxObjectShellLock xDocShell(pNewDocSh.get());
550
0
    pNewDocSh->DoInitNew();
551
0
    SdDrawDocument* pDoc = pNewDocSh->GetDoc();
552
0
    if (pDoc)
553
0
    {
554
0
        pDoc->CreateFirstPages();
555
0
        pDoc->StopWorkStartupDelay();
556
0
    }
557
0
    if (pNewDocSh->GetMedium())
558
0
        pNewDocSh->GetMedium()->GetItemSet().Put(SfxBoolItem(SID_REPLACEABLE, true));
559
560
0
    SfxViewFrame* pViewFrame = SfxViewFrame::LoadDocumentIntoFrame( *pNewDocSh, i_rFrame );
561
0
    OSL_ENSURE( pViewFrame, "SdModule::CreateEmptyDocument: no view frame - was the document really loaded?" );
562
0
    pFrame = pViewFrame ? &pViewFrame->GetFrame() : nullptr;
563
564
0
    return pFrame;
565
0
}
566
567
//===== OutlineToImpressFinalize ==============================================
568
569
namespace {
570
571
OutlineToImpressFinalizer::OutlineToImpressFinalizer (
572
    ::sd::ViewShellBase& rBase,
573
    SdDrawDocument& rDocument,
574
    css::uno::Sequence<sal_Int8> const & rBytes)
575
0
    : mrBase(rBase),
576
0
      mrDocument(rDocument)
577
0
{
578
    // Create a memory stream to fill it with the content of
579
    // the original stream.
580
0
    mpStream = std::make_shared<SvMemoryStream>(static_cast<void*>(const_cast<sal_Int8*>(rBytes.getConstArray())), rBytes.getLength(), StreamMode::READ);
581
582
    // Rewind the memory stream so that in the operator() method its
583
    // content is properly read.
584
0
    mpStream->Seek(STREAM_SEEK_TO_BEGIN);
585
0
}
586
587
void OutlineToImpressFinalizer::operator() (bool)
588
0
{
589
    // Fetch the new outline view shell.
590
0
    ::sd::OutlineViewShell* pOutlineShell
591
0
        = dynamic_cast<sd::OutlineViewShell*>(FrameworkHelper::Instance(mrBase)->GetViewShell(FrameworkHelper::msCenterPaneURL).get());
592
593
0
    if (pOutlineShell != nullptr && mpStream != nullptr)
594
0
    {
595
0
        sd::OutlineView* pView = static_cast<sd::OutlineView*>(pOutlineShell->GetView());
596
        // mba: the stream can't contain any relative URLs, because we don't
597
        // have any information about a BaseURL!
598
0
        pOutlineShell->ReadRtf(*mpStream);
599
600
        // Call UpdatePreview once for every slide to resync the
601
        // document with the outliner of the OutlineViewShell.
602
0
        sal_uInt16 nPageCount (mrDocument.GetSdPageCount(PageKind::Standard));
603
0
        for (sal_uInt16 nIndex=0; nIndex<nPageCount; nIndex++)
604
0
        {
605
0
            SdPage* pPage = mrDocument.GetSdPage(nIndex, PageKind::Standard);
606
            // Make the page the actual page so that the
607
            // following UpdatePreview() call accesses the
608
            // correct paragraphs.
609
0
            pView->SetActualPage(pPage);
610
0
            pOutlineShell->UpdatePreview(pPage);
611
0
        }
612
        // Select the first slide.
613
0
        SdPage* pPage = mrDocument.GetSdPage(0, PageKind::Standard);
614
0
        pView->SetActualPage(pPage);
615
0
        pOutlineShell->UpdatePreview(pPage);
616
0
    }
617
618
    // Undo-Stack needs to be cleared, else the user may remove the
619
    // only drawpage and this is a state we cannot handle ATM.
620
0
    ::sd::DrawDocShell* pDocShell = mrDocument.GetDocSh();
621
0
    if( pDocShell )
622
0
        pDocShell->ClearUndoBuffer();
623
0
}
624
625
} // end of anonymous namespace
626
627
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */