bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / sidebar / MasterPageContainerFiller.cxx
blobf85c72f360e4bfc32724dd622c6b86a750d39536
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(NULL),
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 ::boost::shared_ptr<PageObjectProvider>(new DefaultPageObjectProvider()),
50 ::boost::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.get() != NULL)
90 mrContainerAdapter.FillingDone();
91 mpScannerTask.reset();
93 default:
94 break;
98 bool MasterPageContainerFiller::HasNextStep()
100 switch (meState)
102 case DONE:
103 case ERROR:
104 return false;
106 default:
107 return true;
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;
125 else
126 eState = SCAN_TEMPLATE;
128 else
129 eState = SCAN_TEMPLATE;
131 else
132 eState = DONE;
135 return eState;
138 MasterPageContainerFiller::State MasterPageContainerFiller::AddTemplate()
140 if (mpLastAddedEntry != NULL)
142 SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
143 MasterPageContainer::TEMPLATE,
144 mnIndex,
145 mpLastAddedEntry->msPath,
146 mpLastAddedEntry->msTitle,
147 OUString(),
148 false,
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
157 // the page objects.
158 if (pDescriptor->GetURLClassification() == MasterPageDescriptor::URLCLASS_USER)
159 pDescriptor->mpPreviewProvider = ::boost::shared_ptr<PreviewProvider>(
160 new PagePreviewProvider());
162 mrContainerAdapter.PutMasterPage(pDescriptor);
163 ++mnIndex;
166 return SCAN_TEMPLATE;
169 } } // end of namespace sd::sidebar
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */