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

Generated by: LCOV version 1.10