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

Generated by: LCOV version 1.11