1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sd.hxx" 30 31 #include "MasterPageContainerFiller.hxx" 32 33 #include "MasterPageDescriptor.hxx" 34 #include "MasterPageContainerProviders.hxx" 35 #include "TemplateScanner.hxx" 36 37 using namespace ::com::sun::star; 38 using namespace ::com::sun::star::uno; 39 using namespace ::sd::toolpanel::controls; 40 41 42 namespace sd { namespace toolpanel { namespace controls { 43 44 MasterPageContainerFiller::MasterPageContainerFiller (ContainerAdapter& rpAdapter) 45 : mrContainerAdapter(rpAdapter), 46 meState(INITIALIZE_TEMPLATE_SCANNER), 47 mpScannerTask(), 48 mpLastAddedEntry(NULL), 49 mnIndex(1) 50 { 51 // Add one entry for the default master page. We use temporarily the 52 // DefaultPagePreviewProvider to prevent the rendering (and the 53 // expensive creation) of the default page. It is replaced later on by 54 // another. 55 SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor( 56 MasterPageContainer::DEFAULT, 57 0, 58 String(), 59 String(), 60 String(), 61 false, 62 ::boost::shared_ptr<PageObjectProvider>(new DefaultPageObjectProvider()), 63 ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider()))); 64 mrContainerAdapter.PutMasterPage(pDescriptor); 65 } 66 67 68 69 70 MasterPageContainerFiller::~MasterPageContainerFiller (void) 71 { 72 } 73 74 75 76 77 void MasterPageContainerFiller::RunNextStep (void) 78 { 79 switch (meState) 80 { 81 case INITIALIZE_TEMPLATE_SCANNER: 82 mpScannerTask.reset(new TemplateScanner()); 83 meState = SCAN_TEMPLATE; 84 break; 85 86 case SCAN_TEMPLATE: 87 meState = ScanTemplate(); 88 break; 89 90 case ADD_TEMPLATE: 91 meState = AddTemplate(); 92 break; 93 94 case DONE: 95 case ERROR: 96 default: 97 break; 98 } 99 100 // When the state has just been set to DONE or ERROR then tell the 101 // container that no more templates will be coming and stop the 102 // scanning. 103 switch (meState) 104 { 105 case DONE: 106 case ERROR: 107 if (mpScannerTask.get() != NULL) 108 { 109 mrContainerAdapter.FillingDone(); 110 mpScannerTask.reset(); 111 } 112 default: 113 break; 114 } 115 } 116 117 118 119 120 bool MasterPageContainerFiller::HasNextStep (void) 121 { 122 switch (meState) 123 { 124 case DONE: 125 case ERROR: 126 return false; 127 128 default: 129 return true; 130 } 131 } 132 133 134 135 136 MasterPageContainerFiller::State MasterPageContainerFiller::ScanTemplate (void) 137 { 138 State eState (ERROR); 139 140 if (mpScannerTask.get() != NULL) 141 { 142 if (mpScannerTask->HasNextStep()) 143 { 144 mpScannerTask->RunNextStep(); 145 if (mpScannerTask->GetLastAddedEntry() != mpLastAddedEntry) 146 { 147 mpLastAddedEntry = mpScannerTask->GetLastAddedEntry(); 148 if (mpLastAddedEntry != NULL) 149 eState = ADD_TEMPLATE; 150 else 151 eState = SCAN_TEMPLATE; 152 } 153 else 154 eState = SCAN_TEMPLATE; 155 } 156 else 157 eState = DONE; 158 } 159 160 return eState; 161 } 162 163 164 165 166 MasterPageContainerFiller::State MasterPageContainerFiller::AddTemplate (void) 167 { 168 if (mpLastAddedEntry != NULL) 169 { 170 SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor( 171 MasterPageContainer::TEMPLATE, 172 mnIndex, 173 mpLastAddedEntry->msPath, 174 mpLastAddedEntry->msTitle, 175 String(), 176 false, 177 ::boost::shared_ptr<PageObjectProvider>( 178 new TemplatePageObjectProvider(mpLastAddedEntry->msPath)), 179 ::boost::shared_ptr<PreviewProvider>( 180 new TemplatePreviewProvider(mpLastAddedEntry->msPath)))); 181 // For user supplied templates we use a different preview provider: 182 // The preview in the document shows not only shapes on the master 183 // page but also shapes on the foreground. This is misleading and 184 // therefore these previews are discarded and created directly from 185 // the page objects. 186 if (pDescriptor->GetURLClassification() == MasterPageDescriptor::URLCLASS_USER) 187 pDescriptor->mpPreviewProvider = ::boost::shared_ptr<PreviewProvider>( 188 new PagePreviewProvider()); 189 190 mrContainerAdapter.PutMasterPage(pDescriptor); 191 ++mnIndex; 192 } 193 194 return SCAN_TEMPLATE; 195 } 196 197 198 199 } } } // end of namespace ::sd::toolpanel::controls 200