15b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35b190011SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45b190011SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55b190011SAndrew Rist  * distributed with this work for additional information
65b190011SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75b190011SAndrew Rist  * to you under the Apache License, Version 2.0 (the
85b190011SAndrew Rist  * "License"); you may not use this file except in compliance
95b190011SAndrew Rist  * with the License.  You may obtain a copy of the License at
105b190011SAndrew Rist  *
115b190011SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
125b190011SAndrew Rist  *
135b190011SAndrew Rist  * Unless required by applicable law or agreed to in writing,
145b190011SAndrew Rist  * software distributed under the License is distributed on an
155b190011SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165b190011SAndrew Rist  * KIND, either express or implied.  See the License for the
175b190011SAndrew Rist  * specific language governing permissions and limitations
185b190011SAndrew Rist  * under the License.
195b190011SAndrew Rist  *
205b190011SAndrew Rist  *************************************************************/
215b190011SAndrew Rist 
22cdf0e10cSrcweir #include "precompiled_sd.hxx"
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "MasterPageContainerFiller.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "MasterPageDescriptor.hxx"
27cdf0e10cSrcweir #include "MasterPageContainerProviders.hxx"
28cdf0e10cSrcweir #include "TemplateScanner.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir using namespace ::com::sun::star;
31cdf0e10cSrcweir using namespace ::com::sun::star::uno;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
347a32b0c8SAndre Fischer namespace sd { namespace sidebar {
35cdf0e10cSrcweir 
MasterPageContainerFiller(ContainerAdapter & rpAdapter)36cdf0e10cSrcweir MasterPageContainerFiller::MasterPageContainerFiller (ContainerAdapter& rpAdapter)
37cdf0e10cSrcweir     : mrContainerAdapter(rpAdapter),
38cdf0e10cSrcweir       meState(INITIALIZE_TEMPLATE_SCANNER),
39cdf0e10cSrcweir       mpScannerTask(),
40cdf0e10cSrcweir       mpLastAddedEntry(NULL),
41cdf0e10cSrcweir       mnIndex(1)
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     // Add one entry for the default master page.  We use temporarily the
44cdf0e10cSrcweir     // DefaultPagePreviewProvider to prevent the rendering (and the
45cdf0e10cSrcweir     // expensive creation) of the default page.  It is replaced later on by
46cdf0e10cSrcweir     // another.
47cdf0e10cSrcweir     SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
48cdf0e10cSrcweir         MasterPageContainer::DEFAULT,
49cdf0e10cSrcweir         0,
50cdf0e10cSrcweir         String(),
51cdf0e10cSrcweir         String(),
52cdf0e10cSrcweir         String(),
53cdf0e10cSrcweir         false,
54cdf0e10cSrcweir         ::boost::shared_ptr<PageObjectProvider>(new DefaultPageObjectProvider()),
55cdf0e10cSrcweir         ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider())));
56cdf0e10cSrcweir     mrContainerAdapter.PutMasterPage(pDescriptor);
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
~MasterPageContainerFiller(void)62cdf0e10cSrcweir MasterPageContainerFiller::~MasterPageContainerFiller (void)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 
RunNextStep(void)69cdf0e10cSrcweir void MasterPageContainerFiller::RunNextStep (void)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir     switch (meState)
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         case INITIALIZE_TEMPLATE_SCANNER:
74cdf0e10cSrcweir             mpScannerTask.reset(new TemplateScanner());
75cdf0e10cSrcweir             meState = SCAN_TEMPLATE;
76cdf0e10cSrcweir             break;
77cdf0e10cSrcweir 
78cdf0e10cSrcweir         case SCAN_TEMPLATE:
79cdf0e10cSrcweir             meState = ScanTemplate();
80cdf0e10cSrcweir             break;
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         case ADD_TEMPLATE:
83cdf0e10cSrcweir             meState = AddTemplate();
84cdf0e10cSrcweir             break;
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         case DONE:
87cdf0e10cSrcweir         case ERROR:
88cdf0e10cSrcweir         default:
89cdf0e10cSrcweir             break;
90cdf0e10cSrcweir     }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir     // When the state has just been set to DONE or ERROR then tell the
93cdf0e10cSrcweir     // container that no more templates will be coming and stop the
94cdf0e10cSrcweir     // scanning.
95cdf0e10cSrcweir     switch (meState)
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         case DONE:
98cdf0e10cSrcweir         case ERROR:
99cdf0e10cSrcweir             if (mpScannerTask.get() != NULL)
100cdf0e10cSrcweir             {
101cdf0e10cSrcweir                 mrContainerAdapter.FillingDone();
102cdf0e10cSrcweir                 mpScannerTask.reset();
103cdf0e10cSrcweir             }
104cdf0e10cSrcweir 		default:
105cdf0e10cSrcweir 			break;
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 
HasNextStep(void)112cdf0e10cSrcweir bool MasterPageContainerFiller::HasNextStep (void)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     switch (meState)
115cdf0e10cSrcweir     {
116cdf0e10cSrcweir         case DONE:
117cdf0e10cSrcweir         case ERROR:
118cdf0e10cSrcweir             return false;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir         default:
121cdf0e10cSrcweir             return true;
122cdf0e10cSrcweir     }
123cdf0e10cSrcweir }
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 
ScanTemplate(void)128cdf0e10cSrcweir MasterPageContainerFiller::State MasterPageContainerFiller::ScanTemplate (void)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     State eState (ERROR);
131cdf0e10cSrcweir 
132cdf0e10cSrcweir     if (mpScannerTask.get() != NULL)
133cdf0e10cSrcweir     {
134cdf0e10cSrcweir         if (mpScannerTask->HasNextStep())
135cdf0e10cSrcweir         {
136cdf0e10cSrcweir             mpScannerTask->RunNextStep();
137cdf0e10cSrcweir             if (mpScannerTask->GetLastAddedEntry() != mpLastAddedEntry)
138cdf0e10cSrcweir             {
139cdf0e10cSrcweir                 mpLastAddedEntry = mpScannerTask->GetLastAddedEntry();
140cdf0e10cSrcweir                 if (mpLastAddedEntry != NULL)
141cdf0e10cSrcweir                     eState = ADD_TEMPLATE;
142cdf0e10cSrcweir                 else
143cdf0e10cSrcweir                     eState = SCAN_TEMPLATE;
144cdf0e10cSrcweir             }
145cdf0e10cSrcweir             else
146cdf0e10cSrcweir                 eState = SCAN_TEMPLATE;
147cdf0e10cSrcweir         }
148cdf0e10cSrcweir         else
149cdf0e10cSrcweir             eState = DONE;
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     return eState;
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 
AddTemplate(void)158cdf0e10cSrcweir MasterPageContainerFiller::State MasterPageContainerFiller::AddTemplate (void)
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     if (mpLastAddedEntry != NULL)
161cdf0e10cSrcweir     {
162cdf0e10cSrcweir         SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
163cdf0e10cSrcweir             MasterPageContainer::TEMPLATE,
164cdf0e10cSrcweir             mnIndex,
165cdf0e10cSrcweir             mpLastAddedEntry->msPath,
166cdf0e10cSrcweir             mpLastAddedEntry->msTitle,
167cdf0e10cSrcweir             String(),
168cdf0e10cSrcweir             false,
169cdf0e10cSrcweir             ::boost::shared_ptr<PageObjectProvider>(
170cdf0e10cSrcweir                 new TemplatePageObjectProvider(mpLastAddedEntry->msPath)),
171cdf0e10cSrcweir             ::boost::shared_ptr<PreviewProvider>(
172cdf0e10cSrcweir                 new TemplatePreviewProvider(mpLastAddedEntry->msPath))));
173cdf0e10cSrcweir         // For user supplied templates we use a different preview provider:
174cdf0e10cSrcweir         // The preview in the document shows not only shapes on the master
175cdf0e10cSrcweir         // page but also shapes on the foreground.  This is misleading and
176cdf0e10cSrcweir         // therefore these previews are discarded and created directly from
177cdf0e10cSrcweir         // the page objects.
178cdf0e10cSrcweir         if (pDescriptor->GetURLClassification() == MasterPageDescriptor::URLCLASS_USER)
179cdf0e10cSrcweir             pDescriptor->mpPreviewProvider = ::boost::shared_ptr<PreviewProvider>(
180cdf0e10cSrcweir                 new PagePreviewProvider());
181cdf0e10cSrcweir 
182cdf0e10cSrcweir         mrContainerAdapter.PutMasterPage(pDescriptor);
183cdf0e10cSrcweir         ++mnIndex;
184cdf0e10cSrcweir     }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir     return SCAN_TEMPLATE;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 
1917a32b0c8SAndre Fischer } } // end of namespace sd::sidebar
192