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

Generated by: LCOV version 1.10