LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/toolpanel/controls - AllMasterPagesSelector.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 67 0.0 %
Date: 2012-12-27 Functions: 0 13 0.0 %
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             : 
      21             : #include "AllMasterPagesSelector.hxx"
      22             : #include "PreviewValueSet.hxx"
      23             : #include "app.hrc"
      24             : #include "MasterPageContainer.hxx"
      25             : #include "MasterPageDescriptor.hxx"
      26             : #include <set>
      27             : 
      28             : namespace {
      29             : 
      30             : using namespace sd::toolpanel::controls;
      31             : 
      32           0 : int GetURLPriority (const SharedMasterPageDescriptor& rpDescriptor)
      33             : {
      34           0 :     int nPriority (0);
      35           0 :     switch (rpDescriptor->GetURLClassification())
      36             :     {
      37           0 :         case MasterPageDescriptor::URLCLASS_USER:         nPriority = 0; break;
      38           0 :         case MasterPageDescriptor::URLCLASS_LAYOUT:       nPriority = 1; break;
      39           0 :         case MasterPageDescriptor::URLCLASS_PRESENTATION: nPriority = 2; break;
      40           0 :         case MasterPageDescriptor::URLCLASS_OTHER:        nPriority = 3; break;
      41           0 :         case MasterPageDescriptor::URLCLASS_UNKNOWN:      nPriority = 4; break;
      42             :         default:
      43           0 :         case MasterPageDescriptor::URLCLASS_UNDETERMINED: nPriority = 5; break;
      44             :     }
      45           0 :     return nPriority;
      46             : }
      47             : 
      48             : 
      49             : class MasterPageDescriptorOrder
      50             : {
      51             : public:
      52           0 :     bool operator() (const sd::toolpanel::controls::SharedMasterPageDescriptor& rp1,
      53             :         const sd::toolpanel::controls::SharedMasterPageDescriptor& rp2)
      54             :     {
      55           0 :         if (rp1->meOrigin == MasterPageContainer::DEFAULT)
      56           0 :             return true;
      57           0 :         else if (rp2->meOrigin == MasterPageContainer::DEFAULT)
      58           0 :             return false;
      59           0 :         else if (rp1->GetURLClassification() == rp2->GetURLClassification())
      60           0 :             return rp1->mnTemplateIndex < rp2->mnTemplateIndex;
      61             :         else
      62           0 :             return GetURLPriority(rp1) < GetURLPriority(rp2);
      63             :     }
      64             : };
      65             : 
      66             : } // end of anonymous namespace
      67             : 
      68             : 
      69             : 
      70             : namespace sd { namespace toolpanel { namespace controls {
      71             : 
      72           0 : class AllMasterPagesSelector::SortedMasterPageDescriptorList
      73             :     : public ::std::set<SharedMasterPageDescriptor,MasterPageDescriptorOrder>
      74             : {
      75             : public:
      76           0 :     SortedMasterPageDescriptorList (void) {}
      77             : };
      78             : 
      79             : 
      80             : 
      81             : 
      82           0 : AllMasterPagesSelector::AllMasterPagesSelector (
      83             :     TreeNode* pParent,
      84             :     SdDrawDocument& rDocument,
      85             :     ViewShellBase& rBase,
      86             :     DrawViewShell& rViewShell,
      87             :     const ::boost::shared_ptr<MasterPageContainer>& rpContainer)
      88             :     : MasterPagesSelector(pParent, rDocument, rBase, rpContainer),
      89             :       mrViewShell(rViewShell),
      90           0 :       mpSortedMasterPages(new SortedMasterPageDescriptorList())
      91             : {
      92           0 :     SetName (rtl::OUString("AllMasterPagesSelector"));
      93           0 :     MasterPagesSelector::Fill();
      94           0 : }
      95             : 
      96             : 
      97             : 
      98             : 
      99           0 : AllMasterPagesSelector::~AllMasterPagesSelector (void)
     100             : {
     101           0 : }
     102             : 
     103             : 
     104             : 
     105             : 
     106           0 : void AllMasterPagesSelector::Fill (ItemList& rItemList)
     107             : {
     108           0 :     if (mpSortedMasterPages->empty())
     109           0 :         UpdateMasterPageList();
     110           0 :     UpdatePageSet(rItemList);
     111           0 : }
     112             : 
     113             : 
     114             : 
     115             : 
     116           0 : void AllMasterPagesSelector::NotifyContainerChangeEvent (
     117             :     const MasterPageContainerChangeEvent& rEvent)
     118             : {
     119           0 :     switch (rEvent.meEventType)
     120             :     {
     121             :         case MasterPageContainerChangeEvent::CHILD_ADDED:
     122           0 :             AddItem(rEvent.maChildToken);
     123           0 :             MasterPagesSelector::Fill();
     124           0 :             break;
     125             : 
     126             :         case MasterPageContainerChangeEvent::INDEX_CHANGED:
     127             :         case MasterPageContainerChangeEvent::INDEXES_CHANGED:
     128           0 :             mpSortedMasterPages->clear();
     129           0 :             MasterPagesSelector::Fill();
     130           0 :             break;
     131             : 
     132             :         default:
     133           0 :             MasterPagesSelector::NotifyContainerChangeEvent(rEvent);
     134           0 :             break;
     135             :     }
     136           0 : }
     137             : 
     138             : 
     139             : 
     140             : 
     141           0 : void AllMasterPagesSelector::UpdateMasterPageList (void)
     142             : {
     143           0 :     mpSortedMasterPages->clear();
     144           0 :     int nTokenCount = mpContainer->GetTokenCount();
     145           0 :     for (int i=0; i<nTokenCount; i++)
     146           0 :         AddItem(mpContainer->GetTokenForIndex(i));
     147           0 : }
     148             : 
     149             : 
     150             : 
     151             : 
     152           0 : void AllMasterPagesSelector::AddItem (MasterPageContainer::Token aToken)
     153             : {
     154           0 :     switch (mpContainer->GetOriginForToken(aToken))
     155             :     {
     156             :         case MasterPageContainer::DEFAULT:
     157             :         case MasterPageContainer::TEMPLATE:
     158             :             // Templates are added only when coming from the
     159             :             // MasterPageContainerFiller so that they have an id which
     160             :             // defines their place in the list.  Templates (pre) loaded from
     161             :             // RecentlyUsedMasterPages are ignored (they will be loaded
     162             :             // later by the MasterPageContainerFiller.)
     163           0 :             if (mpContainer->GetTemplateIndexForToken(aToken) >= 0)
     164           0 :                 mpSortedMasterPages->insert(mpContainer->GetDescriptorForToken(aToken));
     165           0 :             break;
     166             : 
     167             :         default:
     168           0 :             break;
     169             :     }
     170           0 : }
     171             : 
     172             : 
     173             : 
     174             : 
     175           0 : void AllMasterPagesSelector::UpdatePageSet (ItemList& rItemList)
     176             : {
     177           0 :     SortedMasterPageDescriptorList::const_iterator iDescriptor;
     178           0 :     SortedMasterPageDescriptorList::const_iterator iEnd (mpSortedMasterPages->end());
     179           0 :     for (iDescriptor=mpSortedMasterPages->begin(); iDescriptor!=iEnd; ++iDescriptor)
     180           0 :         rItemList.push_back((*iDescriptor)->maToken);
     181           0 : }
     182             : 
     183             : 
     184             : 
     185             : 
     186           0 : void AllMasterPagesSelector::GetState (SfxItemSet& rItemSet)
     187             : {
     188           0 :     MasterPagesSelector::GetState(rItemSet);
     189             : 
     190           0 :     if (rItemSet.GetItemState(SID_TP_EDIT_MASTER) == SFX_ITEM_AVAILABLE)
     191           0 :         rItemSet.DisableItem(SID_TP_EDIT_MASTER);
     192           0 : }
     193             : 
     194             : 
     195             : 
     196             : 
     197             : } } } // end of namespace ::sd::toolpanel::control
     198             : 
     199             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10