LCOV - code coverage report
Current view: top level - sd/source/ui/sidebar - MasterPageContainerFiller.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 52 1.9 %
Date: 2015-06-13 12:38:46 Functions: 2 9 22.2 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11