LibreOffice Module sd (master) 1
MasterPageContainerFiller.cxx
Go to the documentation of this file.
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
21
24#include <TemplateScanner.hxx>
25
26using namespace ::com::sun::star;
27using namespace ::com::sun::star::uno;
28
29namespace sd::sidebar {
30
32 : mrContainerAdapter(rpAdapter),
33 meState(INITIALIZE_TEMPLATE_SCANNER),
34 mpLastAddedEntry(nullptr),
35 mnIndex(1)
36{
37 // Add one entry for the default master page. We use temporarily the
38 // DefaultPagePreviewProvider to prevent the rendering (and the
39 // expensive creation) of the default page. It is replaced later on by
40 // another.
41 SharedMasterPageDescriptor pDescriptor = std::make_shared<MasterPageDescriptor>(
43 0,
44 OUString(),
45 OUString(),
46 OUString(),
47 false,
48 std::make_shared<DefaultPageObjectProvider>(),
49 std::make_shared<PagePreviewProvider>());
51}
52
54{
55}
56
58{
59 switch (meState)
60 {
62 mpScannerTask.reset(new TemplateScanner());
64 break;
65
66 case SCAN_TEMPLATE:
68 break;
69
70 case ADD_TEMPLATE:
72 break;
73
74 case DONE:
75 case ERROR:
76 default:
77 break;
78 }
79
80 // When the state has just been set to DONE or ERROR then tell the
81 // container that no more templates will be coming and stop the
82 // scanning.
83 switch (meState)
84 {
85 case DONE:
86 case ERROR:
87 if (mpScannerTask != nullptr)
88 {
90 mpScannerTask.reset();
91 }
92 break;
93 default:
94 break;
95 }
96}
97
99{
100 switch (meState)
101 {
102 case DONE:
103 case ERROR:
104 return false;
105
106 default:
107 return true;
108 }
109}
110
112{
113 State eState (ERROR);
114
115 if (mpScannerTask != nullptr)
116 {
117 if (mpScannerTask->HasNextStep())
118 {
119 mpScannerTask->RunNextStep();
120 if (mpScannerTask->GetLastAddedEntry() != mpLastAddedEntry)
121 {
122 mpLastAddedEntry = mpScannerTask->GetLastAddedEntry();
123 if (mpLastAddedEntry != nullptr)
124 eState = ADD_TEMPLATE;
125 else
126 eState = SCAN_TEMPLATE;
127 }
128 else
129 eState = SCAN_TEMPLATE;
130 }
131 else
132 eState = DONE;
133 }
134
135 return eState;
136}
137
139{
140 if (mpLastAddedEntry != nullptr)
141 {
142 SharedMasterPageDescriptor pDescriptor = std::make_shared<MasterPageDescriptor>(
144 mnIndex,
147 OUString(),
148 false,
149 std::make_shared<TemplatePageObjectProvider>(mpLastAddedEntry->msPath),
150 std::make_shared<TemplatePreviewProvider>(mpLastAddedEntry->msPath));
151 // For user supplied templates we use a different preview provider:
152 // The preview in the document shows not only shapes on the master
153 // page but also shapes on the foreground. This is misleading and
154 // therefore these previews are discarded and created directly from
155 // the page objects.
156 if (pDescriptor->GetURLClassification() == MasterPageDescriptor::URLCLASS_USER)
157 pDescriptor->mpPreviewProvider = std::make_shared<PagePreviewProvider>();
158
160 ++mnIndex;
161 }
162
163 return SCAN_TEMPLATE;
164}
165
166} // end of namespace sd::sidebar
167
168/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This class scans the template folders for impress templates.
virtual void FillingDone()=0
This method is called when all Impress templates have been added to the container via the PutMasterPa...
virtual MasterPageContainer::Token PutMasterPage(const SharedMasterPageDescriptor &rpDescriptor)=0
::std::unique_ptr< TemplateScanner > mpScannerTask
MasterPageContainerFiller(ContainerAdapter &rContainerAdapter)
virtual bool HasNextStep() override
Return <TRUE> when there is at least one more step to execute.
enum sd::sidebar::MasterPageContainerFiller::State meState
virtual void RunNextStep() override
Run the next step of the task.
std::shared_ptr< MasterPageDescriptor > SharedMasterPageDescriptor
sal_uInt32 mnIndex