Update ooo320-m1
[ooovba.git] / sd / source / ui / toolpanel / controls / MasterPageContainerFiller.cxx
blob096aaff745b45c18f986f1e4fe3e65e370153e78
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MasterPageContainerFiller.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "MasterPageContainerFiller.hxx"
36 #include "MasterPageDescriptor.hxx"
37 #include "MasterPageContainerProviders.hxx"
38 #include "TemplateScanner.hxx"
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::uno;
42 using namespace ::sd::toolpanel::controls;
45 namespace sd { namespace toolpanel { namespace controls {
47 MasterPageContainerFiller::MasterPageContainerFiller (ContainerAdapter& rpAdapter)
48 : mrContainerAdapter(rpAdapter),
49 meState(INITIALIZE_TEMPLATE_SCANNER),
50 mpScannerTask(),
51 mpLastAddedEntry(NULL),
52 mnIndex(1)
54 // Add one entry for the default master page. We use temporarily the
55 // DefaultPagePreviewProvider to prevent the rendering (and the
56 // expensive creation) of the default page. It is replaced later on by
57 // another.
58 SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
59 MasterPageContainer::DEFAULT,
61 String(),
62 String(),
63 String(),
64 false,
65 ::boost::shared_ptr<PageObjectProvider>(new DefaultPageObjectProvider()),
66 ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider())));
67 mrContainerAdapter.PutMasterPage(pDescriptor);
73 MasterPageContainerFiller::~MasterPageContainerFiller (void)
80 void MasterPageContainerFiller::RunNextStep (void)
82 switch (meState)
84 case INITIALIZE_TEMPLATE_SCANNER:
85 mpScannerTask.reset(new TemplateScanner());
86 meState = SCAN_TEMPLATE;
87 break;
89 case SCAN_TEMPLATE:
90 meState = ScanTemplate();
91 break;
93 case ADD_TEMPLATE:
94 meState = AddTemplate();
95 break;
97 case DONE:
98 case ERROR:
99 default:
100 break;
103 // When the state has just been set to DONE or ERROR then tell the
104 // container that no more templates will be coming and stop the
105 // scanning.
106 switch (meState)
108 case DONE:
109 case ERROR:
110 if (mpScannerTask.get() != NULL)
112 mrContainerAdapter.FillingDone();
113 mpScannerTask.reset();
115 default:
116 break;
123 bool MasterPageContainerFiller::HasNextStep (void)
125 switch (meState)
127 case DONE:
128 case ERROR:
129 return false;
131 default:
132 return true;
139 MasterPageContainerFiller::State MasterPageContainerFiller::ScanTemplate (void)
141 State eState (ERROR);
143 if (mpScannerTask.get() != NULL)
145 if (mpScannerTask->HasNextStep())
147 mpScannerTask->RunNextStep();
148 if (mpScannerTask->GetLastAddedEntry() != mpLastAddedEntry)
150 mpLastAddedEntry = mpScannerTask->GetLastAddedEntry();
151 if (mpLastAddedEntry != NULL)
152 eState = ADD_TEMPLATE;
153 else
154 eState = SCAN_TEMPLATE;
156 else
157 eState = SCAN_TEMPLATE;
159 else
160 eState = DONE;
163 return eState;
169 MasterPageContainerFiller::State MasterPageContainerFiller::AddTemplate (void)
171 if (mpLastAddedEntry != NULL)
173 SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
174 MasterPageContainer::TEMPLATE,
175 mnIndex,
176 mpLastAddedEntry->msPath,
177 mpLastAddedEntry->msTitle,
178 String(),
179 false,
180 ::boost::shared_ptr<PageObjectProvider>(
181 new TemplatePageObjectProvider(mpLastAddedEntry->msPath)),
182 ::boost::shared_ptr<PreviewProvider>(
183 new TemplatePreviewProvider(mpLastAddedEntry->msPath))));
184 // For user supplied templates we use a different preview provider:
185 // The preview in the document shows not only shapes on the master
186 // page but also shapes on the foreground. This is misleading and
187 // therefore these previews are discarded and created directly from
188 // the page objects.
189 if (pDescriptor->GetURLClassification() == MasterPageDescriptor::URLCLASS_USER)
190 pDescriptor->mpPreviewProvider = ::boost::shared_ptr<PreviewProvider>(
191 new PagePreviewProvider());
193 mrContainerAdapter.PutMasterPage(pDescriptor);
194 ++mnIndex;
197 return SCAN_TEMPLATE;
202 } } } // end of namespace ::sd::toolpanel::controls