bump product version to 6.3.0.0.beta1
[LibreOffice.git] / sd / source / ui / sidebar / MasterPageContainerFiller.cxx
blobd007e524f969b50ef046ef5d9f934084e5440852
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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),
34 mpScannerTask(),
35 mpLastAddedEntry(nullptr),
36 mnIndex(1)
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
41 // another.
42 SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
43 MasterPageContainer::DEFAULT,
45 OUString(),
46 OUString(),
47 OUString(),
48 false,
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()
60 switch (meState)
62 case INITIALIZE_TEMPLATE_SCANNER:
63 mpScannerTask.reset(new TemplateScanner());
64 meState = SCAN_TEMPLATE;
65 break;
67 case SCAN_TEMPLATE:
68 meState = ScanTemplate();
69 break;
71 case ADD_TEMPLATE:
72 meState = AddTemplate();
73 break;
75 case DONE:
76 case ERROR:
77 default:
78 break;
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
83 // scanning.
84 switch (meState)
86 case DONE:
87 case ERROR:
88 if (mpScannerTask != nullptr)
90 mrContainerAdapter.FillingDone();
91 mpScannerTask.reset();
93 break;
94 default:
95 break;
99 bool MasterPageContainerFiller::HasNextStep()
101 switch (meState)
103 case DONE:
104 case ERROR:
105 return false;
107 default:
108 return true;
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;
126 else
127 eState = SCAN_TEMPLATE;
129 else
130 eState = SCAN_TEMPLATE;
132 else
133 eState = DONE;
136 return eState;
139 MasterPageContainerFiller::State MasterPageContainerFiller::AddTemplate()
141 if (mpLastAddedEntry != nullptr)
143 SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
144 MasterPageContainer::TEMPLATE,
145 mnIndex,
146 mpLastAddedEntry->msPath,
147 mpLastAddedEntry->msTitle,
148 OUString(),
149 false,
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
158 // the page objects.
159 if (pDescriptor->GetURLClassification() == MasterPageDescriptor::URLCLASS_USER)
160 pDescriptor->mpPreviewProvider = std::shared_ptr<PreviewProvider>(
161 new PagePreviewProvider());
163 mrContainerAdapter.PutMasterPage(pDescriptor);
164 ++mnIndex;
167 return SCAN_TEMPLATE;
170 } } // end of namespace sd::sidebar
172 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */