Branch data Line data Source code
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 : :
20 : :
21 : : #include "MasterPageContainerFiller.hxx"
22 : :
23 : : #include "MasterPageDescriptor.hxx"
24 : : #include "MasterPageContainerProviders.hxx"
25 : : #include "TemplateScanner.hxx"
26 : :
27 : : using namespace ::com::sun::star;
28 : : using namespace ::com::sun::star::uno;
29 : : using namespace ::sd::toolpanel::controls;
30 : :
31 : :
32 : : namespace sd { namespace toolpanel { namespace controls {
33 : :
34 : 0 : MasterPageContainerFiller::MasterPageContainerFiller (ContainerAdapter& rpAdapter)
35 : : : mrContainerAdapter(rpAdapter),
36 : : meState(INITIALIZE_TEMPLATE_SCANNER),
37 : : mpScannerTask(),
38 : : mpLastAddedEntry(NULL),
39 : 0 : mnIndex(1)
40 : : {
41 : : // Add one entry for the default master page. We use temporarily the
42 : : // DefaultPagePreviewProvider to prevent the rendering (and the
43 : : // expensive creation) of the default page. It is replaced later on by
44 : : // another.
45 : : SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
46 : : MasterPageContainer::DEFAULT,
47 : : 0,
48 : : String(),
49 : : String(),
50 : : String(),
51 : : false,
52 : 0 : ::boost::shared_ptr<PageObjectProvider>(new DefaultPageObjectProvider()),
53 [ # # ][ # # ]: 0 : ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider())));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
54 [ # # ][ # # ]: 0 : mrContainerAdapter.PutMasterPage(pDescriptor);
55 : 0 : }
56 : :
57 : :
58 : :
59 : :
60 [ # # ]: 0 : MasterPageContainerFiller::~MasterPageContainerFiller (void)
61 : : {
62 [ # # ]: 0 : }
63 : :
64 : :
65 : :
66 : :
67 : 0 : void MasterPageContainerFiller::RunNextStep (void)
68 : : {
69 [ # # # # ]: 0 : switch (meState)
70 : : {
71 : : case INITIALIZE_TEMPLATE_SCANNER:
72 [ # # ]: 0 : mpScannerTask.reset(new TemplateScanner());
73 : 0 : meState = SCAN_TEMPLATE;
74 : 0 : break;
75 : :
76 : : case SCAN_TEMPLATE:
77 : 0 : meState = ScanTemplate();
78 : 0 : break;
79 : :
80 : : case ADD_TEMPLATE:
81 : 0 : meState = AddTemplate();
82 : 0 : break;
83 : :
84 : : case DONE:
85 : : case ERROR:
86 : : default:
87 : 0 : break;
88 : : }
89 : :
90 : : // When the state has just been set to DONE or ERROR then tell the
91 : : // container that no more templates will be coming and stop the
92 : : // scanning.
93 [ # # ]: 0 : switch (meState)
94 : : {
95 : : case DONE:
96 : : case ERROR:
97 [ # # ]: 0 : if (mpScannerTask.get() != NULL)
98 : : {
99 : 0 : mrContainerAdapter.FillingDone();
100 : 0 : mpScannerTask.reset();
101 : : }
102 : : default:
103 : 0 : break;
104 : : }
105 : 0 : }
106 : :
107 : :
108 : :
109 : :
110 : 0 : bool MasterPageContainerFiller::HasNextStep (void)
111 : : {
112 [ # # ]: 0 : switch (meState)
113 : : {
114 : : case DONE:
115 : : case ERROR:
116 : 0 : return false;
117 : :
118 : : default:
119 : 0 : return true;
120 : : }
121 : : }
122 : :
123 : :
124 : :
125 : :
126 : 0 : MasterPageContainerFiller::State MasterPageContainerFiller::ScanTemplate (void)
127 : : {
128 : 0 : State eState (ERROR);
129 : :
130 [ # # ]: 0 : if (mpScannerTask.get() != NULL)
131 : : {
132 [ # # ]: 0 : if (mpScannerTask->HasNextStep())
133 : : {
134 : 0 : mpScannerTask->RunNextStep();
135 [ # # ]: 0 : if (mpScannerTask->GetLastAddedEntry() != mpLastAddedEntry)
136 : : {
137 : 0 : mpLastAddedEntry = mpScannerTask->GetLastAddedEntry();
138 [ # # ]: 0 : if (mpLastAddedEntry != NULL)
139 : 0 : eState = ADD_TEMPLATE;
140 : : else
141 : 0 : eState = SCAN_TEMPLATE;
142 : : }
143 : : else
144 : 0 : eState = SCAN_TEMPLATE;
145 : : }
146 : : else
147 : 0 : eState = DONE;
148 : : }
149 : :
150 : 0 : return eState;
151 : : }
152 : :
153 : :
154 : :
155 : :
156 : 0 : MasterPageContainerFiller::State MasterPageContainerFiller::AddTemplate (void)
157 : : {
158 [ # # ]: 0 : if (mpLastAddedEntry != NULL)
159 : : {
160 : : SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
161 : : MasterPageContainer::TEMPLATE,
162 : : mnIndex,
163 : : mpLastAddedEntry->msPath,
164 : : mpLastAddedEntry->msTitle,
165 : : String(),
166 : : false,
167 : : ::boost::shared_ptr<PageObjectProvider>(
168 [ # # ]: 0 : new TemplatePageObjectProvider(mpLastAddedEntry->msPath)),
169 : : ::boost::shared_ptr<PreviewProvider>(
170 [ # # ][ # # ]: 0 : new TemplatePreviewProvider(mpLastAddedEntry->msPath))));
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
171 : : // For user supplied templates we use a different preview provider:
172 : : // The preview in the document shows not only shapes on the master
173 : : // page but also shapes on the foreground. This is misleading and
174 : : // therefore these previews are discarded and created directly from
175 : : // the page objects.
176 [ # # ][ # # ]: 0 : if (pDescriptor->GetURLClassification() == MasterPageDescriptor::URLCLASS_USER)
177 : 0 : pDescriptor->mpPreviewProvider = ::boost::shared_ptr<PreviewProvider>(
178 [ # # ][ # # ]: 0 : new PagePreviewProvider());
[ # # # # ]
[ # # ]
179 : :
180 [ # # ]: 0 : mrContainerAdapter.PutMasterPage(pDescriptor);
181 [ # # ]: 0 : ++mnIndex;
182 : : }
183 : :
184 : 0 : return SCAN_TEMPLATE;
185 : : }
186 : :
187 : :
188 : :
189 : : } } } // end of namespace ::sd::toolpanel::controls
190 : :
191 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|