LCOV - code coverage report
Current view: top level - sd/source/ui/sidebar - MasterPagesSelector.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 310 0.3 %
Date: 2015-06-13 12:38:46 Functions: 2 43 4.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 <sal/config.h>
      21             : 
      22             : #include <utility>
      23             : 
      24             : #include "MasterPagesSelector.hxx"
      25             : 
      26             : #include "MasterPageContainer.hxx"
      27             : #include "DocumentHelper.hxx"
      28             : #include "pres.hxx"
      29             : #include "drawdoc.hxx"
      30             : #include "DrawDocShell.hxx"
      31             : #include "sdpage.hxx"
      32             : #include "glob.hxx"
      33             : #include "glob.hrc"
      34             : #include "app.hrc"
      35             : #include "res_bmp.hrc"
      36             : #include "strings.hrc"
      37             : #include "DrawViewShell.hxx"
      38             : #include "DrawController.hxx"
      39             : #include "SlideSorterViewShell.hxx"
      40             : #include "PreviewValueSet.hxx"
      41             : #include "ViewShellBase.hxx"
      42             : #include <sfx2/objface.hxx>
      43             : #include "sdresid.hxx"
      44             : #include "drawview.hxx"
      45             : #include <vcl/image.hxx>
      46             : #include <vcl/floatwin.hxx>
      47             : #include <svl/languageoptions.hxx>
      48             : #include <sfx2/app.hxx>
      49             : #include <sfx2/dispatch.hxx>
      50             : #include <sfx2/mnumgr.hxx>
      51             : #include <svl/itemset.hxx>
      52             : #include <svl/eitem.hxx>
      53             : #include <svx/dlgutil.hxx>
      54             : #include <svx/svdpagv.hxx>
      55             : #include <svx/svxids.hrc>
      56             : #include "FrameView.hxx"
      57             : #include "stlpool.hxx"
      58             : #include "unmovss.hxx"
      59             : #include <sfx2/request.hxx>
      60             : #include <svl/itempool.hxx>
      61             : #include <sfx2/sidebar/Theme.hxx>
      62             : 
      63             : using namespace ::com::sun::star::text;
      64             : 
      65             : namespace sd { namespace sidebar {
      66             : 
      67           0 : MasterPagesSelector::MasterPagesSelector (
      68             :     vcl::Window* pParent,
      69             :     SdDrawDocument& rDocument,
      70             :     ViewShellBase& rBase,
      71             :     const ::boost::shared_ptr<MasterPageContainer>& rpContainer,
      72             :     const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
      73             :     : PreviewValueSet(pParent),
      74             :       maMutex(),
      75             :       mpContainer(rpContainer),
      76             :       mrDocument(rDocument),
      77             :       mbSmallPreviewSize(false),
      78             :       mrBase(rBase),
      79             :       mnDefaultClickAction(SID_TP_APPLY_TO_ALL_SLIDES),
      80             :       maPreviewUpdateQueue(),
      81             :       maCurrentItemList(),
      82             :       maTokenToValueSetIndex(),
      83             :       maLockedMasterPages(),
      84           0 :       mxSidebar(rxSidebar)
      85             : {
      86             :     PreviewValueSet::SetSelectHdl (
      87           0 :         LINK(this, MasterPagesSelector, ClickHandler));
      88             :     PreviewValueSet::SetRightMouseClickHandler (
      89           0 :         LINK(this, MasterPagesSelector, RightClickHandler));
      90           0 :     PreviewValueSet::SetStyle(PreviewValueSet::GetStyle() | WB_NO_DIRECTSELECT);
      91             : 
      92           0 :     if ( GetDPIScaleFactor() > 1 )
      93           0 :         mpContainer->SetPreviewSize(MasterPageContainer::LARGE);
      94             : 
      95           0 :     PreviewValueSet::SetPreviewSize(mpContainer->GetPreviewSizePixel());
      96           0 :     PreviewValueSet::Show();
      97             : 
      98           0 :     SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
      99           0 :     SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground));
     100             : 
     101           0 :     Link<> aChangeListener (LINK(this,MasterPagesSelector,ContainerChangeListener));
     102           0 :     mpContainer->AddChangeListener(aChangeListener);
     103           0 : }
     104             : 
     105           0 : MasterPagesSelector::~MasterPagesSelector()
     106             : {
     107           0 :     disposeOnce();
     108           0 : }
     109             : 
     110           0 : void MasterPagesSelector::dispose()
     111             : {
     112           0 :     Clear();
     113           0 :     UpdateLocks(ItemList());
     114             : 
     115           0 :     Link<> aChangeListener (LINK(this,MasterPagesSelector,ContainerChangeListener));
     116           0 :     mpContainer->RemoveChangeListener(aChangeListener);
     117           0 :     PreviewValueSet::dispose();
     118           0 : }
     119             : 
     120           0 : void MasterPagesSelector::LateInit()
     121             : {
     122           0 : }
     123             : 
     124           0 : sal_Int32 MasterPagesSelector::GetPreferredHeight (sal_Int32 nWidth)
     125             : {
     126           0 :     const ::osl::MutexGuard aGuard (maMutex);
     127             : 
     128           0 :     return PreviewValueSet::GetPreferredHeight (nWidth);
     129             : }
     130             : 
     131           0 : void MasterPagesSelector::UpdateLocks (const ItemList& rItemList)
     132             : {
     133           0 :     ItemList aNewLockList;
     134             : 
     135             :     // In here we first lock the master pages in the given list and then
     136             :     // release the locks acquired in a previous call to this method.  When
     137             :     // this were done the other way round the lock count of some master
     138             :     // pages might drop temporarily to 0 and would lead to unnecessary
     139             :     // deletion and re-creation of MasterPageDescriptor objects.
     140             : 
     141             :     // Lock the master pages in the given list.
     142           0 :     ItemList::const_iterator iItem;
     143           0 :     for (iItem=rItemList.begin(); iItem!=rItemList.end(); ++iItem)
     144             :     {
     145           0 :         mpContainer->AcquireToken(*iItem);
     146           0 :         aNewLockList.push_back(*iItem);
     147             :     }
     148             : 
     149             :     // Release the previously locked master pages.
     150           0 :     ItemList::const_iterator iPage;
     151           0 :     ItemList::const_iterator iEnd (maLockedMasterPages.end());
     152           0 :     for (iPage=maLockedMasterPages.begin(); iPage!=iEnd; ++iPage)
     153           0 :         mpContainer->ReleaseToken(*iPage);
     154             : 
     155           0 :     maLockedMasterPages.swap(aNewLockList);
     156           0 : }
     157             : 
     158           0 : void MasterPagesSelector::Fill()
     159             : {
     160           0 :     ::std::unique_ptr<ItemList> pItemList (new ItemList());
     161             : 
     162           0 :     Fill(*pItemList);
     163             : 
     164           0 :     UpdateLocks(*pItemList);
     165           0 :     UpdateItemList(std::move(pItemList));
     166           0 : }
     167             : 
     168           0 : ResId MasterPagesSelector::GetContextMenuResId() const
     169             : {
     170           0 :     return SdResId(RID_TASKPANE_MASTERPAGESSELECTOR_POPUP);
     171             : }
     172             : 
     173           0 : IMPL_LINK_NOARG(MasterPagesSelector, ClickHandler)
     174             : {
     175             :     // We use the framework to assign the clicked-on master page because we
     176             :     // so use the same mechanism as the context menu does (where we do not
     177             :     // have the option to call the assignment method directly.)
     178           0 :     ExecuteCommand(mnDefaultClickAction);
     179             : 
     180           0 :     return 0;
     181             : }
     182             : 
     183           0 : IMPL_LINK(MasterPagesSelector, RightClickHandler, MouseEvent*, pEvent)
     184             : {
     185             :     // Here we only prepare the display of the context menu: the item under
     186             :     // the mouse is selected.  The actual display of the context menu is
     187             :     // done in ContextMenuCallback which is called indirectly through
     188             :     // PreviewValueSet::Command().
     189           0 :     PreviewValueSet::GrabFocus ();
     190           0 :     PreviewValueSet::ReleaseMouse();
     191           0 :     SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
     192           0 :     if (pViewFrame != NULL)
     193             :     {
     194           0 :         SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
     195           0 :         if (pDispatcher != NULL &&  pEvent != NULL)
     196             :         {
     197           0 :             sal_uInt16 nIndex = PreviewValueSet::GetItemId (pEvent->GetPosPixel());
     198           0 :             if (nIndex > 0)
     199           0 :                 PreviewValueSet::SelectItem (nIndex);
     200             :         }
     201             :     }
     202           0 :     return 0;
     203             : }
     204             : 
     205           0 : void MasterPagesSelector::Command (const CommandEvent& rEvent)
     206             : {
     207           0 :     switch (rEvent.GetCommand())
     208             :     {
     209             :         case CommandEventId::ContextMenu:
     210             :         {
     211             :             // Use the currently selected item and show the popup menu in its
     212             :             // center.
     213           0 :             const sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId();
     214           0 :             if (nIndex > 0)
     215             :             {
     216             :                 // The position of the upper left corner of the context menu is
     217             :                 // taken either from the mouse position (when the command was sent
     218             :                 // as reaction to a right click) or in the center of the selected
     219             :                 // item (when the command was sent as reaction to Shift+F10.)
     220           0 :                 Point aPosition (rEvent.GetMousePosPixel());
     221           0 :                 if ( ! rEvent.IsMouseEvent())
     222             :                 {
     223           0 :                     Rectangle aBBox (PreviewValueSet::GetItemRect(nIndex));
     224           0 :                     aPosition = aBBox.Center();
     225             :                 }
     226             : 
     227             :                 // Setup the menu.
     228           0 :                 ::boost::scoped_ptr<PopupMenu> pMenu (new PopupMenu(GetContextMenuResId()));
     229           0 :                 FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow());
     230           0 :                 if (pMenuWindow != NULL)
     231             :                     pMenuWindow->SetPopupModeFlags(
     232           0 :                         pMenuWindow->GetPopupModeFlags() | FloatWinPopupFlags::NoMouseUpClose);
     233           0 :                 pMenu->SetSelectHdl(LINK(this, MasterPagesSelector, OnMenuItemSelected));
     234             : 
     235           0 :                 ProcessPopupMenu(*pMenu);
     236             : 
     237             :                 // Show the menu.
     238           0 :                 pMenu->Execute(this, Rectangle(aPosition,Size(1,1)), PopupMenuFlags::ExecuteDown);
     239             :             }
     240             :         }
     241           0 :         break;
     242           0 :         default: break;
     243             :     }
     244           0 : }
     245             : 
     246           0 : void MasterPagesSelector::ProcessPopupMenu (Menu& rMenu)
     247             : {
     248             :     // Disable some entries.
     249           0 :     if (mpContainer->GetPreviewSize() == MasterPageContainer::SMALL)
     250           0 :         rMenu.EnableItem(SID_TP_SHOW_SMALL_PREVIEW, false);
     251             :     else
     252           0 :         rMenu.EnableItem(SID_TP_SHOW_LARGE_PREVIEW, false);
     253           0 : }
     254             : 
     255           0 : IMPL_LINK(MasterPagesSelector, OnMenuItemSelected, Menu*, pMenu)
     256             : {
     257           0 :     if (pMenu == NULL)
     258             :     {
     259             :         OSL_ENSURE(pMenu!=NULL, "MasterPagesSelector::OnMenuItemSelected: illegal menu!");
     260           0 :         return 0;
     261             :     }
     262             : 
     263           0 :     pMenu->Deactivate();
     264           0 :     ExecuteCommand(pMenu->GetCurItemId());
     265           0 :     return 0;
     266             : }
     267             : 
     268           0 : void MasterPagesSelector::ExecuteCommand (const sal_Int32 nCommandId)
     269             : {
     270           0 :     switch (nCommandId)
     271             :     {
     272             :         case SID_TP_APPLY_TO_ALL_SLIDES:
     273           0 :             mrBase.SetBusyState (true);
     274           0 :             AssignMasterPageToAllSlides (GetSelectedMasterPage());
     275           0 :             mrBase.SetBusyState (false);
     276           0 :             break;
     277             : 
     278             :         case SID_TP_APPLY_TO_SELECTED_SLIDES:
     279           0 :             mrBase.SetBusyState (true);
     280           0 :             AssignMasterPageToSelectedSlides (GetSelectedMasterPage());
     281           0 :             mrBase.SetBusyState (false);
     282           0 :             break;
     283             : 
     284             :         case SID_TP_USE_FOR_NEW_PRESENTATIONS:
     285             :             DBG_ASSERT (false,
     286             :                 "Using slides as default for new presentations"
     287             :                 " is not yet implemented");
     288           0 :             break;
     289             : 
     290             :         case SID_TP_SHOW_SMALL_PREVIEW:
     291             :         case SID_TP_SHOW_LARGE_PREVIEW:
     292             :         {
     293           0 :             mrBase.SetBusyState (true);
     294             :             mpContainer->SetPreviewSize(
     295             :                 nCommandId==SID_TP_SHOW_SMALL_PREVIEW
     296             :                 ? MasterPageContainer::SMALL
     297           0 :                 : MasterPageContainer::LARGE);
     298           0 :             mrBase.SetBusyState (false);
     299           0 :             if (mxSidebar.is())
     300           0 :                 mxSidebar->requestLayout();
     301           0 :             break;
     302             :         }
     303             : 
     304             :         case SID_TP_EDIT_MASTER:
     305             :         {
     306             :             using namespace ::com::sun::star;
     307           0 :             uno::Reference<drawing::XDrawPage> xSelectedMaster;
     308           0 :             SdPage* pMasterPage = GetSelectedMasterPage();
     309             :             assert(pMasterPage); //rhbz#902884
     310           0 :             if (pMasterPage)
     311           0 :                 xSelectedMaster = uno::Reference<drawing::XDrawPage>(pMasterPage->getUnoPage(), uno::UNO_QUERY);
     312           0 :             SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
     313           0 :             if (pViewFrame != NULL && xSelectedMaster.is())
     314             :             {
     315           0 :                 SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
     316           0 :                 if (pDispatcher != NULL)
     317             :                 {
     318           0 :                     sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId();
     319           0 :                     pDispatcher->Execute(SID_MASTERPAGE, SfxCallMode::SYNCHRON);
     320           0 :                     PreviewValueSet::SelectItem (nIndex);
     321           0 :                     mrBase.GetDrawController().setCurrentPage(xSelectedMaster);
     322             :                 }
     323             :             }
     324           0 :             break;
     325             :         }
     326             : 
     327             :         case SID_CUT:
     328             :         case SID_COPY:
     329             :         case SID_PASTE:
     330             :             // Cut, copy, and paste are not supported and thus are ignored.
     331           0 :             break;
     332             :     }
     333           0 : }
     334             : 
     335           0 : IMPL_LINK(MasterPagesSelector, ContainerChangeListener, MasterPageContainerChangeEvent*, pEvent)
     336             : {
     337           0 :     if (pEvent)
     338           0 :         NotifyContainerChangeEvent(*pEvent);
     339           0 :     return 0;
     340             : }
     341             : 
     342           0 : SdPage* MasterPagesSelector::GetSelectedMasterPage()
     343             : {
     344           0 :     const ::osl::MutexGuard aGuard (maMutex);
     345             : 
     346           0 :     SdPage* pMasterPage = NULL;
     347           0 :     sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId();
     348           0 :     UserData* pData = GetUserData(nIndex);
     349           0 :     if (pData != NULL)
     350             :     {
     351           0 :         pMasterPage = mpContainer->GetPageObjectForToken(pData->second);
     352             :     }
     353           0 :     return pMasterPage;
     354             : }
     355             : 
     356             : /** Assemble a list of all slides of the document and pass it to
     357             :     AssignMasterPageToPageList().
     358             : */
     359           0 : void MasterPagesSelector::AssignMasterPageToAllSlides (SdPage* pMasterPage)
     360             : {
     361           0 :     if (pMasterPage == NULL)
     362           0 :         return;
     363             : 
     364           0 :     sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PK_STANDARD);
     365           0 :     if (nPageCount == 0)
     366           0 :         return;
     367             : 
     368             :     // Get a list of all pages.  As a little optimization we only
     369             :     // include pages that do not already have the given master page
     370             :     // assigned.
     371           0 :     OUString sFullLayoutName(pMasterPage->GetLayoutName());
     372             :     ::sd::slidesorter::SharedPageSelection pPageList (
     373           0 :         new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
     374           0 :     for (sal_uInt16 nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
     375             :     {
     376           0 :         SdPage* pPage = mrDocument.GetSdPage (nPageIndex, PK_STANDARD);
     377           0 :         if (pPage != NULL && pPage->GetLayoutName() != sFullLayoutName)
     378             :         {
     379           0 :             pPageList->push_back (pPage);
     380             :         }
     381             :     }
     382             : 
     383           0 :     AssignMasterPageToPageList(pMasterPage, pPageList);
     384             : }
     385             : 
     386             : /** Assemble a list of the currently selected slides (selected in a visible
     387             :     slide sorter) and pass it to AssignMasterPageToPageList().
     388             : */
     389           0 : void MasterPagesSelector::AssignMasterPageToSelectedSlides (
     390             :     SdPage* pMasterPage)
     391             : {
     392             :     using namespace ::sd::slidesorter;
     393             :     using namespace ::sd::slidesorter::controller;
     394             : 
     395           0 :     if (pMasterPage == NULL)
     396           0 :         return;
     397             : 
     398             :     // Find a visible slide sorter.
     399           0 :     SlideSorterViewShell* pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase);
     400           0 :     if (pSlideSorter == NULL)
     401           0 :         return;
     402             : 
     403             :     // Get a list of selected pages.
     404           0 :     SharedPageSelection pPageSelection = pSlideSorter->GetPageSelection();
     405           0 :     if (pPageSelection->empty())
     406           0 :         return;
     407             : 
     408           0 :     AssignMasterPageToPageList(pMasterPage, pPageSelection);
     409             : 
     410             :     // Restore the previous selection.
     411           0 :     pSlideSorter->SetPageSelection(pPageSelection);
     412             : }
     413             : 
     414           0 : void MasterPagesSelector::AssignMasterPageToPageList (
     415             :     SdPage* pMasterPage,
     416             :     const ::sd::slidesorter::SharedPageSelection& rPageList)
     417             : {
     418           0 :     DocumentHelper::AssignMasterPageToPageList(mrDocument, pMasterPage, rPageList);
     419           0 : }
     420             : 
     421           0 : void MasterPagesSelector::NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent)
     422             : {
     423           0 :     const ::osl::MutexGuard aGuard (maMutex);
     424             : 
     425           0 :     switch (rEvent.meEventType)
     426             :     {
     427             :         case MasterPageContainerChangeEvent::SIZE_CHANGED:
     428           0 :             PreviewValueSet::SetPreviewSize(mpContainer->GetPreviewSizePixel());
     429           0 :             UpdateAllPreviews();
     430           0 :             break;
     431             : 
     432             :         case MasterPageContainerChangeEvent::PREVIEW_CHANGED:
     433             :         {
     434           0 :             int nIndex (GetIndexForToken(rEvent.maChildToken));
     435           0 :             if (nIndex >= 0)
     436             :             {
     437             :                 PreviewValueSet::SetItemImage (
     438             :                     (sal_uInt16)nIndex,
     439           0 :                     mpContainer->GetPreviewForToken(rEvent.maChildToken));
     440           0 :                 PreviewValueSet::Invalidate(PreviewValueSet::GetItemRect((sal_uInt16)nIndex));
     441             :             }
     442             :         }
     443           0 :         break;
     444             : 
     445             :         case MasterPageContainerChangeEvent::DATA_CHANGED:
     446             :         {
     447           0 :             InvalidateItem(rEvent.maChildToken);
     448           0 :             Fill();
     449             :         }
     450           0 :         break;
     451             : 
     452             :         case MasterPageContainerChangeEvent::CHILD_REMOVED:
     453             :         {
     454           0 :             int nIndex (GetIndexForToken(rEvent.maChildToken));
     455           0 :             SetItem(nIndex, MasterPageContainer::NIL_TOKEN);
     456             :         }
     457             : 
     458             :         default:
     459           0 :             break;
     460           0 :    }
     461           0 : }
     462             : 
     463           0 : MasterPagesSelector::UserData* MasterPagesSelector::CreateUserData (
     464             :     int nIndex,
     465             :     MasterPageContainer::Token aToken)
     466             : {
     467           0 :     return new UserData(nIndex,aToken);
     468             : }
     469             : 
     470           0 : MasterPagesSelector::UserData* MasterPagesSelector::GetUserData (int nIndex) const
     471             : {
     472           0 :     const ::osl::MutexGuard aGuard (maMutex);
     473             : 
     474           0 :     if (nIndex>0 && static_cast<unsigned int>(nIndex)<=PreviewValueSet::GetItemCount())
     475           0 :         return static_cast<UserData*>(PreviewValueSet::GetItemData((sal_uInt16)nIndex));
     476             :     else
     477           0 :         return NULL;
     478             : }
     479             : 
     480           0 : void MasterPagesSelector::SetUserData (int nIndex, UserData* pData)
     481             : {
     482           0 :     const ::osl::MutexGuard aGuard (maMutex);
     483             : 
     484           0 :     if (nIndex>0 && static_cast<unsigned int>(nIndex)<=PreviewValueSet::GetItemCount())
     485             :     {
     486           0 :         UserData* pOldData = GetUserData(nIndex);
     487           0 :         if (pOldData!=NULL && pOldData!=pData)
     488           0 :             delete pOldData;
     489           0 :         PreviewValueSet::SetItemData((sal_uInt16)nIndex, pData);
     490           0 :     }
     491           0 : }
     492             : 
     493           0 : void MasterPagesSelector::UpdateSelection()
     494             : {
     495           0 : }
     496             : 
     497           0 : void MasterPagesSelector::SetItem (
     498             :     sal_uInt16 nIndex,
     499             :     MasterPageContainer::Token aToken)
     500             : {
     501           0 :     const ::osl::MutexGuard aGuard (maMutex);
     502             : 
     503           0 :     RemoveTokenToIndexEntry(nIndex,aToken);
     504             : 
     505           0 :     if (nIndex > 0)
     506             :     {
     507           0 :         if (aToken != MasterPageContainer::NIL_TOKEN)
     508             :         {
     509           0 :             Image aPreview (mpContainer->GetPreviewForToken(aToken));
     510           0 :             MasterPageContainer::PreviewState eState (mpContainer->GetPreviewState(aToken));
     511             : 
     512           0 :             if (aPreview.GetSizePixel().Width()>0)
     513             :             {
     514           0 :                 if (PreviewValueSet::GetItemPos(nIndex) != VALUESET_ITEM_NOTFOUND)
     515             :                 {
     516           0 :                     PreviewValueSet::SetItemImage(nIndex,aPreview);
     517           0 :                     PreviewValueSet::SetItemText(nIndex, mpContainer->GetPageNameForToken(aToken));
     518             :                 }
     519             :                 else
     520             :                 {
     521             :                     PreviewValueSet::InsertItem (
     522             :                         nIndex,
     523             :                         aPreview,
     524             :                         mpContainer->GetPageNameForToken(aToken),
     525           0 :                         nIndex);
     526             :                 }
     527           0 :                 SetUserData(nIndex, CreateUserData(nIndex,aToken));
     528             : 
     529           0 :                 AddTokenToIndexEntry(nIndex,aToken);
     530             :             }
     531             : 
     532           0 :             if (eState == MasterPageContainer::PS_CREATABLE)
     533           0 :                 mpContainer->RequestPreview(aToken);
     534             :         }
     535             :         else
     536             :         {
     537           0 :             PreviewValueSet::RemoveItem(nIndex);
     538             :         }
     539           0 :     }
     540             : 
     541           0 : }
     542             : 
     543           0 : void MasterPagesSelector::AddTokenToIndexEntry (
     544             :     sal_uInt16 nIndex,
     545             :     MasterPageContainer::Token aToken)
     546             : {
     547           0 :     const ::osl::MutexGuard aGuard (maMutex);
     548             : 
     549           0 :     maTokenToValueSetIndex[aToken] = nIndex;
     550           0 : }
     551             : 
     552           0 : void MasterPagesSelector::RemoveTokenToIndexEntry (
     553             :     sal_uInt16 nIndex,
     554             :     MasterPageContainer::Token aNewToken)
     555             : {
     556           0 :     const ::osl::MutexGuard aGuard (maMutex);
     557             : 
     558           0 :     UserData* pData = GetUserData(nIndex);
     559           0 :     if (pData != NULL)
     560             :     {
     561             :         // Get the token that the index pointed to previously.
     562           0 :         MasterPageContainer::Token aOldToken (pData->second);
     563             : 
     564           0 :         if (aNewToken != aOldToken
     565           0 :             && nIndex == GetIndexForToken(aOldToken))
     566             :         {
     567           0 :             maTokenToValueSetIndex[aOldToken] = 0;
     568             :         }
     569           0 :     }
     570           0 : }
     571             : 
     572           0 : void MasterPagesSelector::InvalidatePreview (const SdPage* pPage)
     573             : {
     574           0 :     const ::osl::MutexGuard aGuard (maMutex);
     575             : 
     576           0 :     for (size_t nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++)
     577             :     {
     578           0 :         UserData* pData = GetUserData(nIndex);
     579           0 :         if (pData != NULL)
     580             :         {
     581           0 :             MasterPageContainer::Token aToken (pData->second);
     582           0 :             if (pPage == mpContainer->GetPageObjectForToken(aToken,false))
     583             :             {
     584           0 :                 mpContainer->InvalidatePreview(aToken);
     585           0 :                 mpContainer->RequestPreview(aToken);
     586           0 :                 break;
     587             :             }
     588             :         }
     589           0 :     }
     590           0 : }
     591             : 
     592           0 : void MasterPagesSelector::UpdateAllPreviews()
     593             : {
     594           0 :     const ::osl::MutexGuard aGuard (maMutex);
     595             : 
     596           0 :     for (size_t nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++)
     597             :     {
     598           0 :         UserData* pData = GetUserData(nIndex);
     599           0 :         if (pData != NULL)
     600             :         {
     601           0 :             MasterPageContainer::Token aToken (pData->second);
     602             :             PreviewValueSet::SetItemImage(
     603             :                 nIndex,
     604           0 :                 mpContainer->GetPreviewForToken(aToken));
     605           0 :             if (mpContainer->GetPreviewState(aToken) == MasterPageContainer::PS_CREATABLE)
     606           0 :                 mpContainer->RequestPreview(aToken);
     607             :         }
     608             :     }
     609           0 :     PreviewValueSet::Rearrange(true);
     610           0 : }
     611             : 
     612           0 : void MasterPagesSelector::ClearPageSet()
     613             : {
     614           0 :     const ::osl::MutexGuard aGuard (maMutex);
     615             : 
     616           0 :     for (size_t nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++)
     617             :     {
     618           0 :         UserData* pData = GetUserData(nIndex);
     619           0 :         if (pData != NULL)
     620           0 :             delete pData;
     621             :     }
     622           0 :     PreviewValueSet::Clear();
     623           0 : }
     624             : 
     625           0 : void MasterPagesSelector::SetHelpId( const OString& aId )
     626             : {
     627           0 :     const ::osl::MutexGuard aGuard (maMutex);
     628             : 
     629           0 :     PreviewValueSet::SetHelpId( aId );
     630           0 : }
     631             : 
     632           0 : sal_Int32 MasterPagesSelector::GetIndexForToken (MasterPageContainer::Token aToken) const
     633             : {
     634           0 :     const ::osl::MutexGuard aGuard (maMutex);
     635             : 
     636           0 :     TokenToValueSetIndex::const_iterator iIndex (maTokenToValueSetIndex.find(aToken));
     637           0 :     if (iIndex != maTokenToValueSetIndex.end())
     638           0 :         return iIndex->second;
     639             :     else
     640           0 :         return -1;
     641             : }
     642             : 
     643           0 : void MasterPagesSelector::Clear()
     644             : {
     645           0 :     const ::osl::MutexGuard aGuard (maMutex);
     646             : 
     647           0 :     ClearPageSet();
     648           0 : }
     649             : 
     650           0 : void MasterPagesSelector::InvalidateItem (MasterPageContainer::Token aToken)
     651             : {
     652           0 :     const ::osl::MutexGuard aGuard (maMutex);
     653             : 
     654           0 :     ItemList::iterator iItem;
     655           0 :     for (iItem=maCurrentItemList.begin(); iItem!=maCurrentItemList.end(); ++iItem)
     656             :     {
     657           0 :         if (*iItem == aToken)
     658             :         {
     659           0 :             *iItem = MasterPageContainer::NIL_TOKEN;
     660           0 :             break;
     661             :         }
     662           0 :     }
     663           0 : }
     664             : 
     665           0 : void MasterPagesSelector::UpdateItemList (::std::unique_ptr<ItemList> && pNewItemList)
     666             : {
     667           0 :     const ::osl::MutexGuard aGuard (maMutex);
     668             : 
     669           0 :     ItemList::const_iterator iNewItem (pNewItemList->begin());
     670           0 :     ItemList::const_iterator iCurrentItem (maCurrentItemList.begin());
     671           0 :     ItemList::const_iterator iNewEnd (pNewItemList->end());
     672           0 :     ItemList::const_iterator iCurrentEnd (maCurrentItemList.end());
     673           0 :     sal_uInt16 nIndex (1);
     674             : 
     675             :     // Update existing items.
     676           0 :     for ( ; iNewItem!=iNewEnd && iCurrentItem!=iCurrentEnd; ++iNewItem, ++iCurrentItem,++nIndex)
     677             :     {
     678           0 :         if (*iNewItem != *iCurrentItem)
     679             :         {
     680           0 :             SetItem(nIndex,*iNewItem);
     681             :         }
     682             :     }
     683             : 
     684             :     // Append new items.
     685           0 :     for ( ; iNewItem!=iNewEnd; ++iNewItem,++nIndex)
     686             :     {
     687           0 :         SetItem(nIndex,*iNewItem);
     688             :     }
     689             : 
     690             :     // Remove trailing items.
     691           0 :     for ( ; iCurrentItem!=iCurrentEnd; ++iCurrentItem,++nIndex)
     692             :     {
     693           0 :         SetItem(nIndex,MasterPageContainer::NIL_TOKEN);
     694             :     }
     695             : 
     696           0 :     maCurrentItemList.swap(*pNewItemList);
     697             : 
     698           0 :     PreviewValueSet::Rearrange();
     699           0 :     if (mxSidebar.is())
     700           0 :         mxSidebar->requestLayout();
     701           0 : }
     702             : 
     703           0 : css::ui::LayoutSize MasterPagesSelector::GetHeightForWidth (const sal_Int32 nWidth)
     704             : {
     705           0 :     const sal_Int32 nHeight (GetPreferredHeight(nWidth));
     706           0 :     return css::ui::LayoutSize(nHeight,nHeight,nHeight);
     707             : }
     708             : 
     709          66 : } } // end of namespace sd::sidebar
     710             : 
     711             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11