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

Generated by: LCOV version 1.10