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