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

Generated by: LCOV version 1.10