LCOV - code coverage report
Current view: top level - sd/source/ui/sidebar - RecentMasterPagesSelector.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 61 1.6 %
Date: 2015-06-13 12:38:46 Functions: 2 13 15.4 %
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 "RecentMasterPagesSelector.hxx"
      21             : 
      22             : #include "ViewShellBase.hxx"
      23             : #include "RecentlyUsedMasterPages.hxx"
      24             : #include "MasterPageContainerProviders.hxx"
      25             : #include "MasterPageObserver.hxx"
      26             : #include "sdpage.hxx"
      27             : #include "drawdoc.hxx"
      28             : #include "app.hrc"
      29             : #include "helpids.h"
      30             : 
      31             : #include <vcl/bitmap.hxx>
      32             : 
      33             : namespace sd { namespace sidebar {
      34             : 
      35           0 : VclPtr<vcl::Window> RecentMasterPagesSelector::Create (
      36             :     vcl::Window* pParent,
      37             :     ViewShellBase& rViewShellBase,
      38             :     const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
      39             : {
      40           0 :     SdDrawDocument* pDocument = rViewShellBase.GetDocument();
      41           0 :     if (pDocument == NULL)
      42           0 :         return NULL;
      43             : 
      44           0 :     ::boost::shared_ptr<MasterPageContainer> pContainer (new MasterPageContainer());
      45             : 
      46             :     VclPtrInstance<RecentMasterPagesSelector> pSelector(
      47             :             pParent,
      48             :             *pDocument,
      49             :             rViewShellBase,
      50             :             pContainer,
      51           0 :             rxSidebar);
      52           0 :     pSelector->LateInit();
      53           0 :     pSelector->SetHelpId(HID_SD_TASK_PANE_PREVIEW_RECENT);
      54             : 
      55           0 :     return pSelector;
      56             : }
      57             : 
      58           0 : RecentMasterPagesSelector::RecentMasterPagesSelector (
      59             :     vcl::Window* pParent,
      60             :     SdDrawDocument& rDocument,
      61             :     ViewShellBase& rBase,
      62             :     const ::boost::shared_ptr<MasterPageContainer>& rpContainer,
      63             :     const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
      64           0 :     : MasterPagesSelector (pParent, rDocument, rBase, rpContainer, rxSidebar)
      65             : {
      66           0 : }
      67             : 
      68           0 : RecentMasterPagesSelector::~RecentMasterPagesSelector()
      69             : {
      70           0 :     disposeOnce();
      71           0 : }
      72             : 
      73           0 : void RecentMasterPagesSelector::dispose()
      74             : {
      75           0 :     RecentlyUsedMasterPages::Instance().RemoveEventListener (
      76           0 :         LINK(this,RecentMasterPagesSelector,MasterPageListListener));
      77           0 :     MasterPagesSelector::dispose();
      78           0 : }
      79             : 
      80           0 : void RecentMasterPagesSelector::LateInit()
      81             : {
      82           0 :     MasterPagesSelector::LateInit();
      83             : 
      84           0 :     MasterPagesSelector::Fill();
      85           0 :     RecentlyUsedMasterPages::Instance().AddEventListener (
      86           0 :         LINK(this,RecentMasterPagesSelector,MasterPageListListener));
      87           0 : }
      88             : 
      89           0 : IMPL_LINK_NOARG(RecentMasterPagesSelector, MasterPageListListener)
      90             : {
      91           0 :     MasterPagesSelector::Fill();
      92           0 :     return 0;
      93             : }
      94             : 
      95           0 : void RecentMasterPagesSelector::Fill (ItemList& rItemList)
      96             : {
      97             :     // Create a set of names of the master pages used by the document.
      98           0 :     MasterPageObserver::MasterPageNameSet aCurrentNames;
      99           0 :     sal_uInt16 nMasterPageCount = mrDocument.GetMasterSdPageCount(PK_STANDARD);
     100             :     sal_uInt16 nIndex;
     101           0 :     for (nIndex=0; nIndex<nMasterPageCount; nIndex++)
     102             :     {
     103           0 :         SdPage* pMasterPage = mrDocument.GetMasterSdPage (nIndex, PK_STANDARD);
     104           0 :         if (pMasterPage != NULL)
     105           0 :             aCurrentNames.insert (pMasterPage->GetName());
     106             :     }
     107             : 
     108             :     // Insert the recently used master pages that are currently not used.
     109           0 :     RecentlyUsedMasterPages& rInstance (RecentlyUsedMasterPages::Instance());
     110           0 :     int nPageCount = rInstance.GetMasterPageCount();
     111           0 :     for (nIndex=0; nIndex<nPageCount; nIndex++)
     112             :     {
     113             :         // Add an entry when a) the page is already known to the
     114             :         // MasterPageContainer, b) the style name is empty, i.e. it has not yet
     115             :         // been loaded (and thus can not be in use) or otherwise c) the
     116             :         // style name is not currently in use.
     117           0 :         MasterPageContainer::Token aToken (rInstance.GetTokenForIndex(nIndex));
     118           0 :         if (aToken != MasterPageContainer::NIL_TOKEN)
     119             :         {
     120           0 :             OUString sStyleName (mpContainer->GetStyleNameForToken(aToken));
     121           0 :             if (sStyleName.isEmpty()
     122           0 :                 || aCurrentNames.find(sStyleName) == aCurrentNames.end())
     123             :             {
     124           0 :                 rItemList.push_back(aToken);
     125           0 :             }
     126             :         }
     127           0 :     }
     128           0 : }
     129             : 
     130           0 : void RecentMasterPagesSelector::AssignMasterPageToPageList (
     131             :     SdPage* pMasterPage,
     132             :     const ::boost::shared_ptr<std::vector<SdPage*> >& rpPageList)
     133             : {
     134           0 :     sal_uInt16 nSelectedItemId = PreviewValueSet::GetSelectItemId();
     135             : 
     136           0 :     MasterPagesSelector::AssignMasterPageToPageList(pMasterPage, rpPageList);
     137             : 
     138             :     // Restore the selection.
     139           0 :     if (PreviewValueSet::GetItemCount() > 0)
     140             :     {
     141           0 :         if (PreviewValueSet::GetItemCount() >= nSelectedItemId)
     142           0 :             PreviewValueSet::SelectItem(nSelectedItemId);
     143             :         else
     144           0 :             PreviewValueSet::SelectItem(PreviewValueSet::GetItemCount());
     145             :     }
     146           0 : }
     147             : 
     148           0 : void RecentMasterPagesSelector::ProcessPopupMenu (Menu& rMenu)
     149             : {
     150           0 :     if (rMenu.GetItemPos(SID_TP_EDIT_MASTER) != MENU_ITEM_NOTFOUND)
     151           0 :         rMenu.EnableItem(SID_TP_EDIT_MASTER, false);
     152           0 : }
     153             : 
     154          66 : } } // end of namespace sd::sidebar
     155             : 
     156             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11