1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "MasterPageContainerFiller.hxx"
22 #include "MasterPageDescriptor.hxx"
23 #include "MasterPageContainerProviders.hxx"
24 #include <TemplateScanner.hxx>
26 using namespace ::com::sun::star
;
27 using namespace ::com::sun::star::uno
;
29 namespace sd
{ namespace sidebar
{
31 MasterPageContainerFiller::MasterPageContainerFiller (ContainerAdapter
& rpAdapter
)
32 : mrContainerAdapter(rpAdapter
),
33 meState(INITIALIZE_TEMPLATE_SCANNER
),
35 mpLastAddedEntry(nullptr),
38 // Add one entry for the default master page. We use temporarily the
39 // DefaultPagePreviewProvider to prevent the rendering (and the
40 // expensive creation) of the default page. It is replaced later on by
42 SharedMasterPageDescriptor
pDescriptor (new MasterPageDescriptor(
43 MasterPageContainer::DEFAULT
,
49 std::shared_ptr
<PageObjectProvider
>(new DefaultPageObjectProvider()),
50 std::shared_ptr
<PreviewProvider
>(new PagePreviewProvider())));
51 mrContainerAdapter
.PutMasterPage(pDescriptor
);
54 MasterPageContainerFiller::~MasterPageContainerFiller()
58 void MasterPageContainerFiller::RunNextStep()
62 case INITIALIZE_TEMPLATE_SCANNER
:
63 mpScannerTask
.reset(new TemplateScanner());
64 meState
= SCAN_TEMPLATE
;
68 meState
= ScanTemplate();
72 meState
= AddTemplate();
81 // When the state has just been set to DONE or ERROR then tell the
82 // container that no more templates will be coming and stop the
88 if (mpScannerTask
!= nullptr)
90 mrContainerAdapter
.FillingDone();
91 mpScannerTask
.reset();
99 bool MasterPageContainerFiller::HasNextStep()
112 MasterPageContainerFiller::State
MasterPageContainerFiller::ScanTemplate()
114 State
eState (ERROR
);
116 if (mpScannerTask
!= nullptr)
118 if (mpScannerTask
->HasNextStep())
120 mpScannerTask
->RunNextStep();
121 if (mpScannerTask
->GetLastAddedEntry() != mpLastAddedEntry
)
123 mpLastAddedEntry
= mpScannerTask
->GetLastAddedEntry();
124 if (mpLastAddedEntry
!= nullptr)
125 eState
= ADD_TEMPLATE
;
127 eState
= SCAN_TEMPLATE
;
130 eState
= SCAN_TEMPLATE
;
139 MasterPageContainerFiller::State
MasterPageContainerFiller::AddTemplate()
141 if (mpLastAddedEntry
!= nullptr)
143 SharedMasterPageDescriptor
pDescriptor (new MasterPageDescriptor(
144 MasterPageContainer::TEMPLATE
,
146 mpLastAddedEntry
->msPath
,
147 mpLastAddedEntry
->msTitle
,
150 std::shared_ptr
<PageObjectProvider
>(
151 new TemplatePageObjectProvider(mpLastAddedEntry
->msPath
)),
152 std::shared_ptr
<PreviewProvider
>(
153 new TemplatePreviewProvider(mpLastAddedEntry
->msPath
))));
154 // For user supplied templates we use a different preview provider:
155 // The preview in the document shows not only shapes on the master
156 // page but also shapes on the foreground. This is misleading and
157 // therefore these previews are discarded and created directly from
159 if (pDescriptor
->GetURLClassification() == MasterPageDescriptor::URLCLASS_USER
)
160 pDescriptor
->mpPreviewProvider
= std::shared_ptr
<PreviewProvider
>(
161 new PagePreviewProvider());
163 mrContainerAdapter
.PutMasterPage(pDescriptor
);
167 return SCAN_TEMPLATE
;
170 } } // end of namespace sd::sidebar
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */