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

Generated by: LCOV version 1.10