LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/toolpanel/controls - CurrentMasterPagesSelector.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 106 0.0 %
Date: 2012-12-27 Functions: 0 12 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 "CurrentMasterPagesSelector.hxx"
      22             : #include "PreviewValueSet.hxx"
      23             : #include "ViewShellBase.hxx"
      24             : #include "DrawViewShell.hxx"
      25             : #include "drawdoc.hxx"
      26             : #include "sdpage.hxx"
      27             : #include "MasterPageContainer.hxx"
      28             : #include "MasterPageDescriptor.hxx"
      29             : #include "EventMultiplexer.hxx"
      30             : #include "app.hrc"
      31             : #include "DrawDocShell.hxx"
      32             : #include "res_bmp.hrc"
      33             : #include "sdresid.hxx"
      34             : 
      35             : #include <vcl/image.hxx>
      36             : #include <svx/svdmodel.hxx>
      37             : #include <sfx2/request.hxx>
      38             : 
      39             : #include <set>
      40             : 
      41             : 
      42             : using namespace ::com::sun::star;
      43             : 
      44             : namespace sd { namespace toolpanel { namespace controls {
      45             : 
      46             : 
      47           0 : CurrentMasterPagesSelector::CurrentMasterPagesSelector (
      48             :     TreeNode* pParent,
      49             :     SdDrawDocument& rDocument,
      50             :     ViewShellBase& rBase,
      51             :     const ::boost::shared_ptr<MasterPageContainer>& rpContainer)
      52           0 :     : MasterPagesSelector (pParent, rDocument, rBase, rpContainer)
      53             : {
      54           0 :     SetName(rtl::OUString("CurrentMasterPagesSelector"));
      55             : 
      56             :     // For this master page selector only we change the default action for
      57             :     // left clicks.
      58           0 :     mnDefaultClickAction = SID_TP_APPLY_TO_SELECTED_SLIDES;
      59             : 
      60           0 :     Link aLink (LINK(this,CurrentMasterPagesSelector,EventMultiplexerListener));
      61             :     rBase.GetEventMultiplexer()->AddEventListener(aLink,
      62             :         sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE
      63             :         | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL
      64             :         | sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER
      65             :         | sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER
      66             :         | sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED
      67             :         | sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED
      68           0 :         | sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED);
      69           0 : }
      70             : 
      71             : 
      72             : 
      73             : 
      74           0 : CurrentMasterPagesSelector::~CurrentMasterPagesSelector (void)
      75             : {
      76           0 :     if (mrDocument.GetDocSh() != NULL)
      77             :     {
      78           0 :         EndListening(*mrDocument.GetDocSh());
      79             :     }
      80             :     else
      81             :     {
      82             :         OSL_ASSERT(mrDocument.GetDocSh() != NULL);
      83             :     }
      84             : 
      85           0 :     Link aLink (LINK(this,CurrentMasterPagesSelector,EventMultiplexerListener));
      86           0 :     mrBase.GetEventMultiplexer()->RemoveEventListener(aLink);
      87           0 : }
      88             : 
      89             : 
      90             : 
      91             : 
      92           0 : void CurrentMasterPagesSelector::LateInit (void)
      93             : {
      94           0 :     MasterPagesSelector::LateInit();
      95           0 :     MasterPagesSelector::Fill();
      96           0 :     if (mrDocument.GetDocSh() != NULL)
      97             :     {
      98           0 :         StartListening(*mrDocument.GetDocSh());
      99             :     }
     100             :     else
     101             :     {
     102             :         OSL_ASSERT(mrDocument.GetDocSh() != NULL);
     103             :     }
     104           0 : }
     105             : 
     106             : 
     107             : 
     108             : 
     109           0 : void CurrentMasterPagesSelector::Fill (ItemList& rItemList)
     110             : {
     111           0 :     sal_uInt16 nPageCount = mrDocument.GetMasterSdPageCount(PK_STANDARD);
     112             :     SdPage* pMasterPage;
     113             :     // Remember the names of the master pages that have been inserted to
     114             :     // avoid double insertion.
     115           0 :     ::std::set<String> aMasterPageNames;
     116           0 :     for (sal_uInt16 nIndex=0; nIndex<nPageCount; nIndex++)
     117             :     {
     118           0 :         pMasterPage = mrDocument.GetMasterSdPage (nIndex, PK_STANDARD);
     119           0 :         if (pMasterPage == NULL)
     120           0 :             continue;
     121             : 
     122             :         // Use the name of the master page to avoid duplicate entries.
     123           0 :         String sName (pMasterPage->GetName());
     124           0 :         if (aMasterPageNames.find(sName)!=aMasterPageNames.end())
     125           0 :             continue;
     126           0 :         aMasterPageNames.insert (sName);
     127             : 
     128             :         // Look up the master page in the container and, when it is not yet
     129             :         // in it, insert it.
     130           0 :         MasterPageContainer::Token aToken = mpContainer->GetTokenForPageObject(pMasterPage);
     131           0 :         if (aToken == MasterPageContainer::NIL_TOKEN)
     132             :         {
     133             :             SharedMasterPageDescriptor pDescriptor (new MasterPageDescriptor(
     134             :                 MasterPageContainer::MASTERPAGE,
     135             :                 nIndex,
     136             :                 String(),
     137             :                 pMasterPage->GetName(),
     138             :                 String(),
     139           0 :                 pMasterPage->IsPrecious(),
     140           0 :                 ::boost::shared_ptr<PageObjectProvider>(new ExistingPageProvider(pMasterPage)),
     141           0 :                 ::boost::shared_ptr<PreviewProvider>(new PagePreviewProvider())));
     142           0 :             aToken = mpContainer->PutMasterPage(pDescriptor);
     143             :         }
     144             : 
     145           0 :         rItemList.push_back(aToken);
     146           0 :     }
     147           0 : }
     148             : 
     149             : 
     150             : 
     151             : 
     152           0 : ResId CurrentMasterPagesSelector::GetContextMenuResId (void) const
     153             : {
     154           0 :     return SdResId(RID_TASKPANE_CURRENT_MASTERPAGESSELECTOR_POPUP);
     155             : }
     156             : 
     157             : 
     158             : 
     159             : 
     160           0 : void CurrentMasterPagesSelector::UpdateSelection (void)
     161             : {
     162             :     // Iterate over all pages and for the selected ones put the name of
     163             :     // their master page into a set.
     164           0 :     sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PK_STANDARD);
     165             :     SdPage* pPage;
     166           0 :     ::std::set<String> aNames;
     167             :     sal_uInt16 nIndex;
     168           0 :     bool bLoop (true);
     169           0 :     for (nIndex=0; nIndex<nPageCount && bLoop; nIndex++)
     170             :     {
     171           0 :         pPage = mrDocument.GetSdPage (nIndex, PK_STANDARD);
     172           0 :         if (pPage != NULL && pPage->IsSelected())
     173             :         {
     174           0 :             if ( ! pPage->TRG_HasMasterPage())
     175             :             {
     176             :                 // One of the pages has no master page.  This is an
     177             :                 // indicator for that this method is called in the middle of
     178             :                 // a document change and that the model is not in a valid
     179             :                 // state.  Therefore we stop update the selection and wait
     180             :                 // for another call to UpdateSelection when the model is
     181             :                 // valid again.
     182           0 :                 bLoop = false;
     183             :             }
     184             :             else
     185             :             {
     186           0 :                 SdrPage& rMasterPage (pPage->TRG_GetMasterPage());
     187           0 :                 SdPage* pMasterPage = static_cast<SdPage*>(&rMasterPage);
     188           0 :                 if (pMasterPage != NULL)
     189           0 :                     aNames.insert (pMasterPage->GetName());
     190             :             }
     191             :         }
     192             :     }
     193             : 
     194             :     // Find the items for the master pages in the set.
     195           0 :     sal_uInt16 nItemCount (mpPageSet->GetItemCount());
     196           0 :     for (nIndex=1; nIndex<=nItemCount && bLoop; nIndex++)
     197             :     {
     198           0 :         String sName (mpPageSet->GetItemText (nIndex));
     199           0 :         if (aNames.find(sName) != aNames.end())
     200             :         {
     201           0 :             mpPageSet->SelectItem (nIndex);
     202             :         }
     203           0 :     }
     204           0 : }
     205             : 
     206             : 
     207             : 
     208             : 
     209           0 : void CurrentMasterPagesSelector::Execute (SfxRequest& rRequest)
     210             : {
     211           0 :     switch (rRequest.GetSlot())
     212             :     {
     213             :         case SID_DELETE_MASTER_PAGE:
     214             :         {
     215             :             // Check once again that the master page can safely be deleted,
     216             :             // i.e. is not used.
     217           0 :             SdPage* pMasterPage = GetSelectedMasterPage();
     218           0 :             if (pMasterPage != NULL
     219           0 :                 && mrDocument.GetMasterPageUserCount(pMasterPage) == 0)
     220             :             {
     221             :                 // Removing the precious flag so that the following call to
     222             :                 // RemoveUnnessesaryMasterPages() will remove this master page.
     223           0 :                 pMasterPage->SetPrecious(false);
     224           0 :                 mrDocument.RemoveUnnecessaryMasterPages(pMasterPage, sal_False, sal_True);
     225             :             }
     226             :         }
     227           0 :         break;
     228             : 
     229             :         default:
     230           0 :             MasterPagesSelector::Execute(rRequest);
     231           0 :             break;
     232             :     }
     233           0 : }
     234             : 
     235             : 
     236             : 
     237             : 
     238           0 : void CurrentMasterPagesSelector::GetState (SfxItemSet& rItemSet)
     239             : {
     240             :     // Disable the SID_DELTE_MASTER slot when there is only one master page.
     241           0 :     if (rItemSet.GetItemState(SID_DELETE_MASTER_PAGE) == SFX_ITEM_AVAILABLE
     242           0 :         && mrDocument.GetMasterPageUserCount(GetSelectedMasterPage()) > 0)
     243             :     {
     244           0 :         rItemSet.DisableItem(SID_DELETE_MASTER_PAGE);
     245             :     }
     246             : 
     247             :     ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
     248           0 :         ::boost::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell()));
     249           0 :     if (rItemSet.GetItemState(SID_TP_EDIT_MASTER) == SFX_ITEM_AVAILABLE
     250           0 :         && pDrawViewShell
     251           0 :         && pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
     252             :     {
     253           0 :         rItemSet.DisableItem (SID_TP_EDIT_MASTER);
     254             :     }
     255             : 
     256           0 :     MasterPagesSelector::GetState(rItemSet);
     257           0 : }
     258             : 
     259             : 
     260             : 
     261             : 
     262             : 
     263             : 
     264           0 : IMPL_LINK(CurrentMasterPagesSelector,EventMultiplexerListener,
     265             :     sd::tools::EventMultiplexerEvent*,pEvent)
     266             : {
     267           0 :     if (pEvent != NULL)
     268             :     {
     269           0 :         switch (pEvent->meEventId)
     270             :         {
     271             :             case sd::tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
     272             :             case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_NORMAL:
     273             :             case sd::tools::EventMultiplexerEvent::EID_EDIT_MODE_MASTER:
     274             :             case sd::tools::EventMultiplexerEvent::EID_SLIDE_SORTER_SELECTION:
     275           0 :                 UpdateSelection();
     276           0 :                 break;
     277             : 
     278             :             case sd::tools::EventMultiplexerEvent::EID_PAGE_ORDER:
     279             :                 // This is tricky.  If a master page is removed, moved, or
     280             :                 // added we have to wait until both the notes master page
     281             :                 // and the standard master page have been removed, moved,
     282             :                 // or added.  We do this by looking at the number of master
     283             :                 // pages which has to be odd in the consistent state (the
     284             :                 // handout master page is always present).  If the number is
     285             :                 // even we ignore the hint.
     286           0 :                 if (mrBase.GetDocument()->GetMasterPageCount()%2 == 1)
     287           0 :                     MasterPagesSelector::Fill();
     288           0 :                 break;
     289             : 
     290             :             case sd::tools::EventMultiplexerEvent::EID_SHAPE_CHANGED:
     291             :             case sd::tools::EventMultiplexerEvent::EID_SHAPE_INSERTED:
     292             :             case sd::tools::EventMultiplexerEvent::EID_SHAPE_REMOVED:
     293           0 :                 InvalidatePreview((const SdPage*)pEvent->mpUserData);
     294           0 :                 break;
     295             :         }
     296             :     }
     297             : 
     298           0 :     return 0;
     299             : }
     300             : 
     301             : 
     302             : 
     303             : 
     304           0 : void CurrentMasterPagesSelector::Notify (SfxBroadcaster&, const SfxHint& rHint)
     305             : {
     306           0 :     const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
     307           0 :     if (pSimpleHint != NULL)
     308             :     {
     309           0 :         if (pSimpleHint->GetId() == SFX_HINT_DOCCHANGED)
     310             :         {
     311             :             // Is the edit view visible in the center pane?
     312             :             ::boost::shared_ptr<DrawViewShell> pDrawViewShell (
     313           0 :                 ::boost::dynamic_pointer_cast<DrawViewShell>(mrBase.GetMainViewShell()));
     314           0 :             if (pDrawViewShell.get() != NULL)
     315             :             {
     316             :                 // Is the edit view in master page mode?
     317           0 :                 if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
     318             :                 {
     319             :                     // Mark the currently edited master page as precious.
     320           0 :                     SdPage* pCurrentMasterPage = pDrawViewShell->getCurrentPage();
     321           0 :                     if (pCurrentMasterPage != NULL)
     322           0 :                         pCurrentMasterPage->SetPrecious(true);
     323             :                 }
     324           0 :             }
     325             :         }
     326             :     }
     327           0 : }
     328             : 
     329             : 
     330             : 
     331             : 
     332             : } } } // end of namespace ::sd::toolpanel::controls
     333             : 
     334             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10