LCOV - code coverage report
Current view: top level - sd/source/ui/sidebar - MasterPageDescriptor.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 146 0.7 %
Date: 2015-06-13 12:38:46 Functions: 2 19 10.5 %
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 "MasterPageDescriptor.hxx"
      21             : 
      22             : #include "DocumentHelper.hxx"
      23             : #include "sdpage.hxx"
      24             : #include <tools/urlobj.hxx>
      25             : 
      26             : namespace sd { namespace sidebar {
      27             : 
      28             : //===== MasterPageDescriptor ==================================================
      29             : 
      30           0 : MasterPageDescriptor::MasterPageDescriptor (
      31             :     MasterPageContainer::Origin eOrigin,
      32             :     const sal_Int32 nTemplateIndex,
      33             :     const OUString& rsURL,
      34             :     const OUString& rsPageName,
      35             :     const OUString& rsStyleName,
      36             :     const bool bIsPrecious,
      37             :     const ::boost::shared_ptr<PageObjectProvider>& rpPageObjectProvider,
      38             :     const ::boost::shared_ptr<PreviewProvider>& rpPreviewProvider)
      39             :     : maToken(MasterPageContainer::NIL_TOKEN),
      40             :       meOrigin(eOrigin),
      41             :       msURL(INetURLObject(rsURL).GetMainURL(INetURLObject::DECODE_UNAMBIGUOUS)),
      42             :       msPageName(rsPageName),
      43             :       msStyleName(rsStyleName),
      44             :       mbIsPrecious(bIsPrecious),
      45             :       mpMasterPage(NULL),
      46             :       mpSlide(NULL),
      47             :       maSmallPreview(),
      48             :       maLargePreview(),
      49             :       mpPreviewProvider(rpPreviewProvider),
      50             :       mpPageObjectProvider(rpPageObjectProvider),
      51             :       mnTemplateIndex(nTemplateIndex),
      52             :       meURLClassification(URLCLASS_UNDETERMINED),
      53           0 :       mnUseCount(0)
      54             : {
      55           0 : }
      56             : 
      57           0 : MasterPageDescriptor::MasterPageDescriptor (const MasterPageDescriptor& rDescriptor)
      58             :     : maToken(rDescriptor.maToken),
      59             :       meOrigin(rDescriptor.meOrigin),
      60             :       msURL(rDescriptor.msURL),
      61             :       msPageName(rDescriptor.msPageName),
      62             :       msStyleName(rDescriptor.msStyleName),
      63             :       mbIsPrecious(rDescriptor.mbIsPrecious),
      64             :       mpMasterPage(rDescriptor.mpMasterPage),
      65             :       mpSlide(rDescriptor.mpSlide),
      66             :       maSmallPreview(rDescriptor.maSmallPreview),
      67             :       maLargePreview(rDescriptor.maLargePreview),
      68             :       mpPreviewProvider(rDescriptor.mpPreviewProvider),
      69             :       mpPageObjectProvider(rDescriptor.mpPageObjectProvider),
      70             :       mnTemplateIndex(rDescriptor.mnTemplateIndex),
      71             :       meURLClassification(rDescriptor.meURLClassification),
      72           0 :       mnUseCount(rDescriptor.mnUseCount)
      73             : {
      74           0 : }
      75             : 
      76           0 : MasterPageDescriptor::~MasterPageDescriptor()
      77             : {
      78           0 : }
      79             : 
      80           0 : void MasterPageDescriptor::SetToken (MasterPageContainer::Token aToken)
      81             : {
      82           0 :     maToken = aToken;
      83           0 : }
      84             : 
      85           0 : Image MasterPageDescriptor::GetPreview (MasterPageContainer::PreviewSize eSize) const
      86             : {
      87           0 :     if (eSize == MasterPageContainer::SMALL)
      88           0 :         return maSmallPreview;
      89             :     else
      90           0 :         return maLargePreview;
      91             : }
      92             : 
      93             : ::std::unique_ptr<std::vector<MasterPageContainerChangeEvent::EventType> >
      94           0 :     MasterPageDescriptor::Update (
      95             :         const MasterPageDescriptor& rDescriptor)
      96             : {
      97           0 :     bool bDataChanged (false);
      98           0 :     bool bIndexChanged (false);
      99           0 :     bool bPreviewChanged (false);
     100             : 
     101           0 :     if (meOrigin==MasterPageContainer::UNKNOWN
     102           0 :         && rDescriptor.meOrigin!=MasterPageContainer::UNKNOWN)
     103             :     {
     104           0 :         meOrigin = rDescriptor.meOrigin;
     105           0 :         bIndexChanged = true;
     106             :     }
     107             : 
     108           0 :     if (msURL.isEmpty() && !rDescriptor.msURL.isEmpty())
     109             :     {
     110           0 :         msURL = rDescriptor.msURL;
     111           0 :         bDataChanged = true;
     112             :     }
     113             : 
     114           0 :     if (msPageName.isEmpty() && !rDescriptor.msPageName.isEmpty())
     115             :     {
     116           0 :         msPageName = rDescriptor.msPageName;
     117           0 :         bDataChanged = true;
     118             :     }
     119             : 
     120           0 :     if (msStyleName.isEmpty() && !rDescriptor.msStyleName.isEmpty())
     121             :     {
     122           0 :         msStyleName = rDescriptor.msStyleName;
     123           0 :         bDataChanged = true;
     124             :     }
     125             : 
     126           0 :     if (mpPageObjectProvider.get()==NULL && rDescriptor.mpPageObjectProvider.get()!=NULL)
     127             :     {
     128           0 :         mpPageObjectProvider = rDescriptor.mpPageObjectProvider;
     129           0 :         bDataChanged = true;
     130             :     }
     131             : 
     132           0 :      if (mpPreviewProvider.get()==NULL && rDescriptor.mpPreviewProvider.get()!=NULL)
     133             :      {
     134           0 :          mpPreviewProvider = rDescriptor.mpPreviewProvider;
     135           0 :          bPreviewChanged = true;
     136             :      }
     137             : 
     138           0 :      if (mnTemplateIndex<0 && rDescriptor.mnTemplateIndex>=0)
     139             :      {
     140           0 :          mnTemplateIndex = rDescriptor.mnTemplateIndex;
     141           0 :          bIndexChanged = true;
     142             :      }
     143             : 
     144             :      // Prepare the list of event types that will be returned.
     145           0 :      ::std::unique_ptr<std::vector<MasterPageContainerChangeEvent::EventType> > pResult;
     146           0 :      if (bDataChanged || bIndexChanged || bPreviewChanged)
     147             :      {
     148           0 :          pResult.reset(new std::vector<MasterPageContainerChangeEvent::EventType>());
     149           0 :          if (bDataChanged)
     150           0 :              pResult->push_back(MasterPageContainerChangeEvent::DATA_CHANGED);
     151           0 :          if (bIndexChanged)
     152           0 :              pResult->push_back(MasterPageContainerChangeEvent::INDEX_CHANGED);
     153           0 :          if (bPreviewChanged)
     154           0 :              pResult->push_back(MasterPageContainerChangeEvent::PREVIEW_CHANGED);
     155             :      }
     156             : 
     157           0 :      return pResult;
     158             : }
     159             : 
     160           0 : int MasterPageDescriptor::UpdatePageObject (
     161             :     sal_Int32 nCostThreshold,
     162             :     SdDrawDocument* pDocument)
     163             : {
     164           0 :     int nModified = 0;
     165             : 
     166             :     // Update the page object when that is not yet known.
     167           0 :     if (mpMasterPage == NULL
     168           0 :         && mpPageObjectProvider.get()!=NULL
     169           0 :         && (nCostThreshold<0 || mpPageObjectProvider->GetCostIndex()<=nCostThreshold))
     170             :     {
     171             :         // Note that pDocument may be NULL.
     172             : 
     173           0 :         SdPage* pPage = (*mpPageObjectProvider)(pDocument);
     174           0 :         if (meOrigin == MasterPageContainer::MASTERPAGE)
     175             :         {
     176           0 :             mpMasterPage = pPage;
     177           0 :             if (mpMasterPage != NULL)
     178           0 :                 mpMasterPage->SetPrecious(mbIsPrecious);
     179             :         }
     180             :         else
     181             :         {
     182             :             // Master pages from templates are copied into the local document.
     183           0 :             if (pDocument != NULL)
     184           0 :                 mpMasterPage = DocumentHelper::CopyMasterPageToLocalDocument(*pDocument,pPage);
     185           0 :             mpSlide = DocumentHelper::GetSlideForMasterPage(mpMasterPage);
     186             :         }
     187             : 
     188           0 :         if (mpMasterPage != NULL)
     189             :         {
     190             :             // Update page name and style name.
     191           0 :             if (msPageName.isEmpty())
     192           0 :                 msPageName = mpMasterPage->GetName();
     193           0 :             msStyleName = mpMasterPage->GetName();
     194             : 
     195             :             // Delete an existing substitution. The next request for a preview
     196             :             // will create the real one.
     197           0 :             maSmallPreview = Image();
     198           0 :             maLargePreview = Image();
     199           0 :             mpPreviewProvider = ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider());
     200             :         }
     201             :         else
     202             :         {
     203             :             DBG_ASSERT(false, "UpdatePageObject: master page is NULL");
     204           0 :             return -1;
     205             :         }
     206             : 
     207           0 :         nModified = 1;
     208             :     }
     209             : 
     210           0 :     return nModified;
     211             : }
     212             : 
     213           0 : bool MasterPageDescriptor::UpdatePreview (
     214             :     sal_Int32 nCostThreshold,
     215             :     const Size& rSmallSize,
     216             :     const Size& rLargeSize,
     217             :     ::sd::PreviewRenderer& rRenderer)
     218             : {
     219           0 :     bool bModified (false);
     220             : 
     221             :     // Update the preview when that is not yet known.
     222           0 :     if (maLargePreview.GetSizePixel().Width()==0
     223           0 :         && mpPreviewProvider.get()!=NULL
     224           0 :         && (nCostThreshold<0 || mpPreviewProvider->GetCostIndex()<=nCostThreshold))
     225             :     {
     226           0 :         SdPage* pPage = mpSlide;
     227           0 :         if (pPage == NULL)
     228             :         {
     229           0 :             pPage = mpMasterPage;
     230             :         }
     231           0 :         maLargePreview = (*mpPreviewProvider)(
     232           0 :             rLargeSize.Width(),
     233             :             pPage,
     234           0 :             rRenderer);
     235           0 :         if (maLargePreview.GetSizePixel().Width() > 0)
     236             :         {
     237             :             // Create the small preview by scaling the large one down.
     238           0 :             maSmallPreview = rRenderer.ScaleBitmap(
     239             :                 maLargePreview.GetBitmapEx(),
     240           0 :                 rSmallSize.Width());
     241             :             // The large preview may not have the desired width.  Scale it
     242             :             // accrodingly.
     243           0 :             if (maLargePreview.GetSizePixel().Width() != rLargeSize.Width())
     244           0 :                 maLargePreview = rRenderer.ScaleBitmap(
     245             :                     maLargePreview.GetBitmapEx(),
     246           0 :                     rLargeSize.Width());
     247           0 :             bModified = true;
     248             :         }
     249             :     }
     250             : 
     251           0 :     return bModified;
     252             : }
     253             : 
     254           0 : MasterPageDescriptor::URLClassification MasterPageDescriptor::GetURLClassification()
     255             : {
     256           0 :     if (meURLClassification == URLCLASS_UNDETERMINED)
     257             :     {
     258           0 :         if (msURL.isEmpty())
     259           0 :             meURLClassification = URLCLASS_UNKNOWN;
     260           0 :         else if (msURL.indexOf("presnt")>=0)
     261             :         {
     262           0 :             meURLClassification = URLCLASS_PRESENTATION;
     263             :         }
     264           0 :         else if (msURL.indexOf("layout")>=0)
     265             :         {
     266           0 :             meURLClassification = URLCLASS_LAYOUT;
     267             :         }
     268           0 :         else if (msURL.indexOf("educate")>=0)
     269             :         {
     270           0 :             meURLClassification = URLCLASS_OTHER;
     271             :         }
     272             :         else
     273             :         {
     274           0 :             meURLClassification = URLCLASS_USER;
     275             :         }
     276             :     }
     277             : 
     278           0 :     return meURLClassification;
     279             : }
     280             : 
     281             : //===== URLComparator =========================================================
     282             : 
     283           0 : MasterPageDescriptor::URLComparator::URLComparator (const OUString& sURL)
     284           0 :     : msURL(sURL)
     285             : {
     286           0 : }
     287             : 
     288           0 : bool MasterPageDescriptor::URLComparator::operator() (
     289             :     const SharedMasterPageDescriptor& rDescriptor)
     290             : {
     291           0 :     if (rDescriptor.get() == NULL)
     292           0 :         return false;
     293             :     else
     294           0 :         return rDescriptor->msURL.equals(msURL);
     295             : }
     296             : 
     297             : // ===== StyleNameComparator ==================================================
     298             : 
     299           0 : MasterPageDescriptor::StyleNameComparator::StyleNameComparator (const OUString& sStyleName)
     300           0 :     : msStyleName(sStyleName)
     301             : {
     302           0 : }
     303             : 
     304           0 : bool MasterPageDescriptor::StyleNameComparator::operator() (
     305             :     const SharedMasterPageDescriptor& rDescriptor)
     306             : {
     307           0 :     if (rDescriptor.get() == NULL)
     308           0 :         return false;
     309             :     else
     310           0 :         return rDescriptor->msStyleName.equals(msStyleName);
     311             : }
     312             : 
     313             : //===== PageObjectComparator ==================================================
     314             : 
     315           0 : MasterPageDescriptor::PageObjectComparator::PageObjectComparator (const SdPage* pPageObject)
     316           0 :     : mpMasterPage(pPageObject)
     317             : {
     318           0 : }
     319             : 
     320           0 : bool MasterPageDescriptor::PageObjectComparator::operator() (
     321             :     const SharedMasterPageDescriptor& rDescriptor)
     322             : {
     323           0 :     if (rDescriptor.get() == NULL)
     324           0 :         return false;
     325             :     else
     326           0 :         return rDescriptor->mpMasterPage==mpMasterPage;
     327             : }
     328             : 
     329             : //===== AllComparator =========================================================
     330             : 
     331           0 : MasterPageDescriptor::AllComparator::AllComparator(const SharedMasterPageDescriptor& rDescriptor)
     332           0 :     : mpDescriptor(rDescriptor)
     333             : {
     334           0 : }
     335             : 
     336           0 : bool MasterPageDescriptor::AllComparator::operator() (const SharedMasterPageDescriptor&rDescriptor)
     337             : {
     338           0 :     if (rDescriptor.get() == NULL)
     339           0 :         return false;
     340             :     else
     341             :     {
     342             :         // Take URL, page name, style name, and page object into account
     343             :         // when comparing two descriptors.  When two descriptors are
     344             :         // identical in any of these values then there are thought of as
     345             :         // equivalent.  Only the Origin has to be the same in both
     346             :         // descriptors.
     347             :         return
     348           0 :             mpDescriptor->meOrigin == rDescriptor->meOrigin
     349           0 :             && (
     350           0 :                 (!mpDescriptor->msURL.isEmpty()
     351           0 :                     && mpDescriptor->msURL.equals(rDescriptor->msURL))
     352           0 :                 || (!mpDescriptor->msPageName.isEmpty()
     353           0 :                     && mpDescriptor->msPageName.equals(rDescriptor->msPageName))
     354           0 :                 || (!mpDescriptor->msStyleName.isEmpty()
     355           0 :                     && mpDescriptor->msStyleName.equals(rDescriptor->msStyleName))
     356           0 :                 || (mpDescriptor->mpMasterPage!=NULL
     357           0 :                     && mpDescriptor->mpMasterPage==rDescriptor->mpMasterPage)
     358           0 :                 || (mpDescriptor->mpPageObjectProvider.get()!=NULL
     359           0 :                     && rDescriptor->mpPageObjectProvider.get()!=NULL
     360           0 :                     && mpDescriptor->mpPageObjectProvider==rDescriptor->mpPageObjectProvider));
     361             :     }
     362             : }
     363             : 
     364          66 : } } // end of namespace sd::sidebar
     365             : 
     366             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11