1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: MasterPageContainerFiller.cxx,v $
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
),
51 mpLastAddedEntry(NULL
),
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
58 SharedMasterPageDescriptor
pDescriptor (new MasterPageDescriptor(
59 MasterPageContainer::DEFAULT
,
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)
84 case INITIALIZE_TEMPLATE_SCANNER
:
85 mpScannerTask
.reset(new TemplateScanner());
86 meState
= SCAN_TEMPLATE
;
90 meState
= ScanTemplate();
94 meState
= AddTemplate();
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
110 if (mpScannerTask
.get() != NULL
)
112 mrContainerAdapter
.FillingDone();
113 mpScannerTask
.reset();
123 bool MasterPageContainerFiller::HasNextStep (void)
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
;
154 eState
= SCAN_TEMPLATE
;
157 eState
= SCAN_TEMPLATE
;
169 MasterPageContainerFiller::State
MasterPageContainerFiller::AddTemplate (void)
171 if (mpLastAddedEntry
!= NULL
)
173 SharedMasterPageDescriptor
pDescriptor (new MasterPageDescriptor(
174 MasterPageContainer::TEMPLATE
,
176 mpLastAddedEntry
->msPath
,
177 mpLastAddedEntry
->msTitle
,
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
189 if (pDescriptor
->GetURLClassification() == MasterPageDescriptor::URLCLASS_USER
)
190 pDescriptor
->mpPreviewProvider
= ::boost::shared_ptr
<PreviewProvider
>(
191 new PagePreviewProvider());
193 mrContainerAdapter
.PutMasterPage(pDescriptor
);
197 return SCAN_TEMPLATE
;
202 } } } // end of namespace ::sd::toolpanel::controls