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(NULL
),
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 ::boost::shared_ptr
<PageObjectProvider
>(new DefaultPageObjectProvider()),
50 ::boost::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
.get() != NULL
)
90 mrContainerAdapter
.FillingDone();
91 mpScannerTask
.reset();
98 bool MasterPageContainerFiller::HasNextStep()
111 MasterPageContainerFiller::State
MasterPageContainerFiller::ScanTemplate()
113 State
eState (ERROR
);
115 if (mpScannerTask
.get() != NULL
)
117 if (mpScannerTask
->HasNextStep())
119 mpScannerTask
->RunNextStep();
120 if (mpScannerTask
->GetLastAddedEntry() != mpLastAddedEntry
)
122 mpLastAddedEntry
= mpScannerTask
->GetLastAddedEntry();
123 if (mpLastAddedEntry
!= NULL
)
124 eState
= ADD_TEMPLATE
;
126 eState
= SCAN_TEMPLATE
;
129 eState
= SCAN_TEMPLATE
;
138 MasterPageContainerFiller::State
MasterPageContainerFiller::AddTemplate()
140 if (mpLastAddedEntry
!= NULL
)
142 SharedMasterPageDescriptor
pDescriptor (new MasterPageDescriptor(
143 MasterPageContainer::TEMPLATE
,
145 mpLastAddedEntry
->msPath
,
146 mpLastAddedEntry
->msTitle
,
149 ::boost::shared_ptr
<PageObjectProvider
>(
150 new TemplatePageObjectProvider(mpLastAddedEntry
->msPath
)),
151 ::boost::shared_ptr
<PreviewProvider
>(
152 new TemplatePreviewProvider(mpLastAddedEntry
->msPath
))));
153 // For user supplied templates we use a different preview provider:
154 // The preview in the document shows not only shapes on the master
155 // page but also shapes on the foreground. This is misleading and
156 // therefore these previews are discarded and created directly from
158 if (pDescriptor
->GetURLClassification() == MasterPageDescriptor::URLCLASS_USER
)
159 pDescriptor
->mpPreviewProvider
= ::boost::shared_ptr
<PreviewProvider
>(
160 new PagePreviewProvider());
162 mrContainerAdapter
.PutMasterPage(pDescriptor
);
166 return SCAN_TEMPLATE
;
169 } } // end of namespace sd::sidebar
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */