2013-04-10 08:20:16 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*
|
|
|
|
* This file incorporates work covered by the following license notice:
|
|
|
|
*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
|
|
|
|
2014-10-01 15:03:54 +02:00
|
|
|
#include <sal/config.h>
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
|
2013-04-10 08:20:16 +00:00
|
|
|
#include "MasterPagesSelector.hxx"
|
|
|
|
|
|
|
|
#include "MasterPageContainer.hxx"
|
|
|
|
#include "DocumentHelper.hxx"
|
|
|
|
#include "pres.hxx"
|
|
|
|
#include "drawdoc.hxx"
|
|
|
|
#include "DrawDocShell.hxx"
|
|
|
|
#include "sdpage.hxx"
|
|
|
|
#include "glob.hxx"
|
|
|
|
#include "glob.hrc"
|
|
|
|
#include "app.hrc"
|
|
|
|
#include "res_bmp.hrc"
|
|
|
|
#include "strings.hrc"
|
|
|
|
#include "DrawViewShell.hxx"
|
|
|
|
#include "DrawController.hxx"
|
|
|
|
#include "SlideSorterViewShell.hxx"
|
|
|
|
#include "PreviewValueSet.hxx"
|
|
|
|
#include "ViewShellBase.hxx"
|
|
|
|
#include <sfx2/objface.hxx>
|
|
|
|
#include "sdresid.hxx"
|
|
|
|
#include "drawview.hxx"
|
|
|
|
#include <vcl/image.hxx>
|
|
|
|
#include <vcl/floatwin.hxx>
|
|
|
|
#include <svl/languageoptions.hxx>
|
|
|
|
#include <sfx2/app.hxx>
|
|
|
|
#include <sfx2/dispatch.hxx>
|
|
|
|
#include <svl/itemset.hxx>
|
|
|
|
#include <svl/eitem.hxx>
|
|
|
|
#include <svx/dlgutil.hxx>
|
|
|
|
#include <svx/svdpagv.hxx>
|
|
|
|
#include <svx/svxids.hrc>
|
|
|
|
#include "FrameView.hxx"
|
|
|
|
#include "stlpool.hxx"
|
|
|
|
#include "unmovss.hxx"
|
|
|
|
#include <sfx2/request.hxx>
|
|
|
|
#include <svl/itempool.hxx>
|
|
|
|
#include <sfx2/sidebar/Theme.hxx>
|
2015-09-25 07:16:42 +01:00
|
|
|
#include <memory>
|
2013-04-10 08:20:16 +00:00
|
|
|
|
|
|
|
using namespace ::com::sun::star::text;
|
|
|
|
|
|
|
|
namespace sd { namespace sidebar {
|
|
|
|
|
|
|
|
MasterPagesSelector::MasterPagesSelector (
|
2015-04-28 23:09:13 +03:00
|
|
|
vcl::Window* pParent,
|
2013-04-10 08:20:16 +00:00
|
|
|
SdDrawDocument& rDocument,
|
|
|
|
ViewShellBase& rBase,
|
2015-09-18 09:09:12 +01:00
|
|
|
const std::shared_ptr<MasterPageContainer>& rpContainer,
|
2014-09-02 17:38:00 +00:00
|
|
|
const css::uno::Reference<css::ui::XSidebar>& rxSidebar)
|
2013-04-10 08:20:16 +00:00
|
|
|
: PreviewValueSet(pParent),
|
|
|
|
maMutex(),
|
|
|
|
mpContainer(rpContainer),
|
|
|
|
mrDocument(rDocument),
|
|
|
|
mrBase(rBase),
|
2016-07-12 09:40:24 +02:00
|
|
|
mnDefaultClickAction(SID_TP_APPLY_TO_SELECTED_SLIDES),
|
2013-04-10 08:20:16 +00:00
|
|
|
maCurrentItemList(),
|
|
|
|
maTokenToValueSetIndex(),
|
|
|
|
maLockedMasterPages(),
|
|
|
|
mxSidebar(rxSidebar)
|
|
|
|
{
|
|
|
|
PreviewValueSet::SetSelectHdl (
|
|
|
|
LINK(this, MasterPagesSelector, ClickHandler));
|
|
|
|
PreviewValueSet::SetRightMouseClickHandler (
|
|
|
|
LINK(this, MasterPagesSelector, RightClickHandler));
|
|
|
|
PreviewValueSet::SetStyle(PreviewValueSet::GetStyle() | WB_NO_DIRECTSELECT);
|
2014-01-02 16:01:07 -05:00
|
|
|
|
|
|
|
if ( GetDPIScaleFactor() > 1 )
|
|
|
|
mpContainer->SetPreviewSize(MasterPageContainer::LARGE);
|
|
|
|
|
2013-04-10 08:20:16 +00:00
|
|
|
PreviewValueSet::SetPreviewSize(mpContainer->GetPreviewSizePixel());
|
|
|
|
PreviewValueSet::Show();
|
|
|
|
|
|
|
|
SetBackground(sfx2::sidebar::Theme::GetWallpaper(sfx2::sidebar::Theme::Paint_PanelBackground));
|
|
|
|
SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground));
|
|
|
|
|
2015-09-17 13:53:42 +02:00
|
|
|
Link<MasterPageContainerChangeEvent&,void> aChangeListener (LINK(this,MasterPagesSelector,ContainerChangeListener));
|
2013-04-10 08:20:16 +00:00
|
|
|
mpContainer->AddChangeListener(aChangeListener);
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
MasterPagesSelector::~MasterPagesSelector()
|
2015-01-26 13:20:10 +02:00
|
|
|
{
|
2015-03-10 09:07:06 +02:00
|
|
|
disposeOnce();
|
2015-01-26 13:20:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::dispose()
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
UpdateLocks(ItemList());
|
|
|
|
|
2015-09-17 13:53:42 +02:00
|
|
|
Link<MasterPageContainerChangeEvent&,void> aChangeListener (LINK(this,MasterPagesSelector,ContainerChangeListener));
|
2013-04-10 08:20:16 +00:00
|
|
|
mpContainer->RemoveChangeListener(aChangeListener);
|
2016-06-15 20:46:19 +01:00
|
|
|
mpContainer.reset();
|
2015-01-26 13:20:10 +02:00
|
|
|
PreviewValueSet::dispose();
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
void MasterPagesSelector::LateInit()
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 MasterPagesSelector::GetPreferredHeight (sal_Int32 nWidth)
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
return PreviewValueSet::GetPreferredHeight (nWidth);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::UpdateLocks (const ItemList& rItemList)
|
|
|
|
{
|
|
|
|
ItemList aNewLockList;
|
|
|
|
|
|
|
|
// In here we first lock the master pages in the given list and then
|
|
|
|
// release the locks acquired in a previous call to this method. When
|
|
|
|
// this were done the other way round the lock count of some master
|
|
|
|
// pages might drop temporarily to 0 and would lead to unnecessary
|
|
|
|
// deletion and re-creation of MasterPageDescriptor objects.
|
|
|
|
|
|
|
|
// Lock the master pages in the given list.
|
|
|
|
ItemList::const_iterator iItem;
|
|
|
|
for (iItem=rItemList.begin(); iItem!=rItemList.end(); ++iItem)
|
|
|
|
{
|
|
|
|
mpContainer->AcquireToken(*iItem);
|
|
|
|
aNewLockList.push_back(*iItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Release the previously locked master pages.
|
|
|
|
ItemList::const_iterator iPage;
|
|
|
|
ItemList::const_iterator iEnd (maLockedMasterPages.end());
|
|
|
|
for (iPage=maLockedMasterPages.begin(); iPage!=iEnd; ++iPage)
|
|
|
|
mpContainer->ReleaseToken(*iPage);
|
|
|
|
|
|
|
|
maLockedMasterPages.swap(aNewLockList);
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
void MasterPagesSelector::Fill()
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2014-10-01 15:03:54 +02:00
|
|
|
::std::unique_ptr<ItemList> pItemList (new ItemList());
|
2013-04-10 08:20:16 +00:00
|
|
|
|
|
|
|
Fill(*pItemList);
|
|
|
|
|
|
|
|
UpdateLocks(*pItemList);
|
2014-10-01 15:03:54 +02:00
|
|
|
UpdateItemList(std::move(pItemList));
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
ResId MasterPagesSelector::GetContextMenuResId() const
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
return SdResId(RID_TASKPANE_MASTERPAGESSELECTOR_POPUP);
|
|
|
|
}
|
|
|
|
|
2015-09-07 13:48:23 +02:00
|
|
|
IMPL_LINK_NOARG_TYPED(MasterPagesSelector, ClickHandler, ValueSet*, void)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
// We use the framework to assign the clicked-on master page because we
|
|
|
|
// so use the same mechanism as the context menu does (where we do not
|
|
|
|
// have the option to call the assignment method directly.)
|
|
|
|
ExecuteCommand(mnDefaultClickAction);
|
|
|
|
}
|
|
|
|
|
2015-09-17 14:02:16 +02:00
|
|
|
IMPL_LINK_TYPED(MasterPagesSelector, RightClickHandler, const MouseEvent&, rEvent, void)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
// Here we only prepare the display of the context menu: the item under
|
|
|
|
// the mouse is selected. The actual display of the context menu is
|
|
|
|
// done in ContextMenuCallback which is called indirectly through
|
|
|
|
// PreviewValueSet::Command().
|
|
|
|
PreviewValueSet::GrabFocus ();
|
|
|
|
PreviewValueSet::ReleaseMouse();
|
|
|
|
SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pViewFrame != nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pDispatcher != nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2015-09-17 14:02:16 +02:00
|
|
|
sal_uInt16 nIndex = PreviewValueSet::GetItemId (rEvent.GetPosPixel());
|
2013-04-10 08:20:16 +00:00
|
|
|
if (nIndex > 0)
|
|
|
|
PreviewValueSet::SelectItem (nIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::Command (const CommandEvent& rEvent)
|
|
|
|
{
|
|
|
|
switch (rEvent.GetCommand())
|
|
|
|
{
|
2015-05-07 15:25:20 +02:00
|
|
|
case CommandEventId::ContextMenu:
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
// Use the currently selected item and show the popup menu in its
|
|
|
|
// center.
|
|
|
|
const sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId();
|
|
|
|
if (nIndex > 0)
|
|
|
|
{
|
|
|
|
// The position of the upper left corner of the context menu is
|
|
|
|
// taken either from the mouse position (when the command was sent
|
|
|
|
// as reaction to a right click) or in the center of the selected
|
|
|
|
// item (when the command was sent as reaction to Shift+F10.)
|
|
|
|
Point aPosition (rEvent.GetMousePosPixel());
|
|
|
|
if ( ! rEvent.IsMouseEvent())
|
|
|
|
{
|
|
|
|
Rectangle aBBox (PreviewValueSet::GetItemRect(nIndex));
|
|
|
|
aPosition = aBBox.Center();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup the menu.
|
2016-06-20 15:56:35 +02:00
|
|
|
ScopedVclPtrInstance<PopupMenu> pMenu(GetContextMenuResId());
|
2013-04-10 08:20:16 +00:00
|
|
|
FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow());
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pMenuWindow != nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
pMenuWindow->SetPopupModeFlags(
|
2015-05-12 15:30:22 +02:00
|
|
|
pMenuWindow->GetPopupModeFlags() | FloatWinPopupFlags::NoMouseUpClose);
|
2013-04-10 08:20:16 +00:00
|
|
|
pMenu->SetSelectHdl(LINK(this, MasterPagesSelector, OnMenuItemSelected));
|
|
|
|
|
|
|
|
ProcessPopupMenu(*pMenu);
|
|
|
|
|
|
|
|
// Show the menu.
|
2015-05-14 14:33:10 +02:00
|
|
|
pMenu->Execute(this, Rectangle(aPosition,Size(1,1)), PopupMenuFlags::ExecuteDown);
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
2015-05-07 15:25:20 +02:00
|
|
|
break;
|
|
|
|
default: break;
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::ProcessPopupMenu (Menu& rMenu)
|
|
|
|
{
|
|
|
|
// Disable some entries.
|
|
|
|
if (mpContainer->GetPreviewSize() == MasterPageContainer::SMALL)
|
2014-02-21 12:53:51 +01:00
|
|
|
rMenu.EnableItem(SID_TP_SHOW_SMALL_PREVIEW, false);
|
2013-04-10 08:20:16 +00:00
|
|
|
else
|
2014-02-21 12:53:51 +01:00
|
|
|
rMenu.EnableItem(SID_TP_SHOW_LARGE_PREVIEW, false);
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
2015-09-06 12:05:08 +02:00
|
|
|
IMPL_LINK_TYPED(MasterPagesSelector, OnMenuItemSelected, Menu*, pMenu, bool)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pMenu == nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2015-11-10 10:23:02 +01:00
|
|
|
OSL_ENSURE(pMenu!=nullptr, "MasterPagesSelector::OnMenuItemSelected: illegal menu!");
|
2015-09-06 12:05:08 +02:00
|
|
|
return false;
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pMenu->Deactivate();
|
|
|
|
ExecuteCommand(pMenu->GetCurItemId());
|
2015-09-06 12:05:08 +02:00
|
|
|
return false;
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::ExecuteCommand (const sal_Int32 nCommandId)
|
|
|
|
{
|
|
|
|
switch (nCommandId)
|
|
|
|
{
|
|
|
|
case SID_TP_APPLY_TO_ALL_SLIDES:
|
|
|
|
mrBase.SetBusyState (true);
|
|
|
|
AssignMasterPageToAllSlides (GetSelectedMasterPage());
|
|
|
|
mrBase.SetBusyState (false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SID_TP_APPLY_TO_SELECTED_SLIDES:
|
|
|
|
mrBase.SetBusyState (true);
|
|
|
|
AssignMasterPageToSelectedSlides (GetSelectedMasterPage());
|
|
|
|
mrBase.SetBusyState (false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SID_TP_USE_FOR_NEW_PRESENTATIONS:
|
2016-06-12 14:42:51 +02:00
|
|
|
SAL_WARN ( "sd",
|
2013-04-10 08:20:16 +00:00
|
|
|
"Using slides as default for new presentations"
|
|
|
|
" is not yet implemented");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SID_TP_SHOW_SMALL_PREVIEW:
|
|
|
|
case SID_TP_SHOW_LARGE_PREVIEW:
|
|
|
|
{
|
|
|
|
mrBase.SetBusyState (true);
|
|
|
|
mpContainer->SetPreviewSize(
|
|
|
|
nCommandId==SID_TP_SHOW_SMALL_PREVIEW
|
|
|
|
? MasterPageContainer::SMALL
|
|
|
|
: MasterPageContainer::LARGE);
|
|
|
|
mrBase.SetBusyState (false);
|
|
|
|
if (mxSidebar.is())
|
|
|
|
mxSidebar->requestLayout();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SID_TP_EDIT_MASTER:
|
|
|
|
{
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
uno::Reference<drawing::XDrawPage> xSelectedMaster;
|
|
|
|
SdPage* pMasterPage = GetSelectedMasterPage();
|
|
|
|
assert(pMasterPage); //rhbz#902884
|
|
|
|
if (pMasterPage)
|
2015-11-04 15:36:26 +02:00
|
|
|
xSelectedMaster.set(pMasterPage->getUnoPage(), uno::UNO_QUERY);
|
2013-04-10 08:20:16 +00:00
|
|
|
SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pViewFrame != nullptr && xSelectedMaster.is())
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pDispatcher != nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId();
|
2014-10-11 16:01:26 +02:00
|
|
|
pDispatcher->Execute(SID_MASTERPAGE, SfxCallMode::SYNCHRON);
|
2013-04-10 08:20:16 +00:00
|
|
|
PreviewValueSet::SelectItem (nIndex);
|
|
|
|
mrBase.GetDrawController().setCurrentPage(xSelectedMaster);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case SID_CUT:
|
|
|
|
case SID_COPY:
|
|
|
|
case SID_PASTE:
|
|
|
|
// Cut, copy, and paste are not supported and thus are ignored.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-17 13:53:42 +02:00
|
|
|
IMPL_LINK_TYPED(MasterPagesSelector, ContainerChangeListener, MasterPageContainerChangeEvent&, rEvent, void)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2015-09-17 13:53:42 +02:00
|
|
|
NotifyContainerChangeEvent(rEvent);
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
SdPage* MasterPagesSelector::GetSelectedMasterPage()
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
2015-11-10 10:23:02 +01:00
|
|
|
SdPage* pMasterPage = nullptr;
|
2013-04-10 08:20:16 +00:00
|
|
|
sal_uInt16 nIndex = PreviewValueSet::GetSelectItemId();
|
|
|
|
UserData* pData = GetUserData(nIndex);
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pData != nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2016-08-01 09:51:02 +02:00
|
|
|
pMasterPage = mpContainer->GetPageObjectForToken(pData->second, true);
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
return pMasterPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Assemble a list of all slides of the document and pass it to
|
|
|
|
AssignMasterPageToPageList().
|
|
|
|
*/
|
|
|
|
void MasterPagesSelector::AssignMasterPageToAllSlides (SdPage* pMasterPage)
|
|
|
|
{
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pMasterPage == nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PK_STANDARD);
|
|
|
|
if (nPageCount == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Get a list of all pages. As a little optimization we only
|
|
|
|
// include pages that do not already have the given master page
|
|
|
|
// assigned.
|
|
|
|
OUString sFullLayoutName(pMasterPage->GetLayoutName());
|
|
|
|
::sd::slidesorter::SharedPageSelection pPageList (
|
|
|
|
new ::sd::slidesorter::SlideSorterViewShell::PageSelection());
|
|
|
|
for (sal_uInt16 nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
|
|
|
|
{
|
|
|
|
SdPage* pPage = mrDocument.GetSdPage (nPageIndex, PK_STANDARD);
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pPage != nullptr && pPage->GetLayoutName() != sFullLayoutName)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
pPageList->push_back (pPage);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AssignMasterPageToPageList(pMasterPage, pPageList);
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Assemble a list of the currently selected slides (selected in a visible
|
|
|
|
slide sorter) and pass it to AssignMasterPageToPageList().
|
|
|
|
*/
|
|
|
|
void MasterPagesSelector::AssignMasterPageToSelectedSlides (
|
|
|
|
SdPage* pMasterPage)
|
|
|
|
{
|
|
|
|
using namespace ::sd::slidesorter;
|
|
|
|
using namespace ::sd::slidesorter::controller;
|
|
|
|
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pMasterPage == nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Find a visible slide sorter.
|
|
|
|
SlideSorterViewShell* pSlideSorter = SlideSorterViewShell::GetSlideSorter(mrBase);
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pSlideSorter == nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Get a list of selected pages.
|
|
|
|
SharedPageSelection pPageSelection = pSlideSorter->GetPageSelection();
|
|
|
|
if (pPageSelection->empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
AssignMasterPageToPageList(pMasterPage, pPageSelection);
|
|
|
|
|
|
|
|
// Restore the previous selection.
|
|
|
|
pSlideSorter->SetPageSelection(pPageSelection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::AssignMasterPageToPageList (
|
|
|
|
SdPage* pMasterPage,
|
|
|
|
const ::sd::slidesorter::SharedPageSelection& rPageList)
|
|
|
|
{
|
|
|
|
DocumentHelper::AssignMasterPageToPageList(mrDocument, pMasterPage, rPageList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent)
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
switch (rEvent.meEventType)
|
|
|
|
{
|
|
|
|
case MasterPageContainerChangeEvent::SIZE_CHANGED:
|
|
|
|
PreviewValueSet::SetPreviewSize(mpContainer->GetPreviewSizePixel());
|
|
|
|
UpdateAllPreviews();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MasterPageContainerChangeEvent::PREVIEW_CHANGED:
|
|
|
|
{
|
|
|
|
int nIndex (GetIndexForToken(rEvent.maChildToken));
|
|
|
|
if (nIndex >= 0)
|
|
|
|
{
|
|
|
|
PreviewValueSet::SetItemImage (
|
|
|
|
(sal_uInt16)nIndex,
|
|
|
|
mpContainer->GetPreviewForToken(rEvent.maChildToken));
|
|
|
|
PreviewValueSet::Invalidate(PreviewValueSet::GetItemRect((sal_uInt16)nIndex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MasterPageContainerChangeEvent::DATA_CHANGED:
|
|
|
|
{
|
|
|
|
InvalidateItem(rEvent.maChildToken);
|
|
|
|
Fill();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MasterPageContainerChangeEvent::CHILD_REMOVED:
|
|
|
|
{
|
|
|
|
int nIndex (GetIndexForToken(rEvent.maChildToken));
|
|
|
|
SetItem(nIndex, MasterPageContainer::NIL_TOKEN);
|
2016-05-10 14:49:37 +02:00
|
|
|
break;
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
MasterPagesSelector::UserData* MasterPagesSelector::CreateUserData (
|
|
|
|
int nIndex,
|
2015-04-29 09:55:11 +02:00
|
|
|
MasterPageContainer::Token aToken)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
return new UserData(nIndex,aToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
MasterPagesSelector::UserData* MasterPagesSelector::GetUserData (int nIndex) const
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
if (nIndex>0 && static_cast<unsigned int>(nIndex)<=PreviewValueSet::GetItemCount())
|
2015-03-31 13:16:18 +02:00
|
|
|
return static_cast<UserData*>(PreviewValueSet::GetItemData((sal_uInt16)nIndex));
|
2013-04-10 08:20:16 +00:00
|
|
|
else
|
2015-11-10 10:23:02 +01:00
|
|
|
return nullptr;
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::SetUserData (int nIndex, UserData* pData)
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
if (nIndex>0 && static_cast<unsigned int>(nIndex)<=PreviewValueSet::GetItemCount())
|
|
|
|
{
|
|
|
|
UserData* pOldData = GetUserData(nIndex);
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pOldData!=nullptr && pOldData!=pData)
|
2013-04-10 08:20:16 +00:00
|
|
|
delete pOldData;
|
|
|
|
PreviewValueSet::SetItemData((sal_uInt16)nIndex, pData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
void MasterPagesSelector::UpdateSelection()
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::SetItem (
|
|
|
|
sal_uInt16 nIndex,
|
|
|
|
MasterPageContainer::Token aToken)
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
RemoveTokenToIndexEntry(nIndex,aToken);
|
|
|
|
|
|
|
|
if (nIndex > 0)
|
|
|
|
{
|
|
|
|
if (aToken != MasterPageContainer::NIL_TOKEN)
|
|
|
|
{
|
|
|
|
Image aPreview (mpContainer->GetPreviewForToken(aToken));
|
|
|
|
MasterPageContainer::PreviewState eState (mpContainer->GetPreviewState(aToken));
|
|
|
|
|
|
|
|
if (aPreview.GetSizePixel().Width()>0)
|
|
|
|
{
|
|
|
|
if (PreviewValueSet::GetItemPos(nIndex) != VALUESET_ITEM_NOTFOUND)
|
|
|
|
{
|
|
|
|
PreviewValueSet::SetItemImage(nIndex,aPreview);
|
|
|
|
PreviewValueSet::SetItemText(nIndex, mpContainer->GetPageNameForToken(aToken));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PreviewValueSet::InsertItem (
|
|
|
|
nIndex,
|
|
|
|
aPreview,
|
|
|
|
mpContainer->GetPageNameForToken(aToken),
|
|
|
|
nIndex);
|
|
|
|
}
|
|
|
|
SetUserData(nIndex, CreateUserData(nIndex,aToken));
|
|
|
|
|
|
|
|
AddTokenToIndexEntry(nIndex,aToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (eState == MasterPageContainer::PS_CREATABLE)
|
|
|
|
mpContainer->RequestPreview(aToken);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PreviewValueSet::RemoveItem(nIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::AddTokenToIndexEntry (
|
|
|
|
sal_uInt16 nIndex,
|
|
|
|
MasterPageContainer::Token aToken)
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
maTokenToValueSetIndex[aToken] = nIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::RemoveTokenToIndexEntry (
|
|
|
|
sal_uInt16 nIndex,
|
|
|
|
MasterPageContainer::Token aNewToken)
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
UserData* pData = GetUserData(nIndex);
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pData != nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
// Get the token that the index pointed to previously.
|
|
|
|
MasterPageContainer::Token aOldToken (pData->second);
|
|
|
|
|
|
|
|
if (aNewToken != aOldToken
|
|
|
|
&& nIndex == GetIndexForToken(aOldToken))
|
|
|
|
{
|
|
|
|
maTokenToValueSetIndex[aOldToken] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::InvalidatePreview (const SdPage* pPage)
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
2015-05-29 13:34:26 +02:00
|
|
|
for (size_t nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
UserData* pData = GetUserData(nIndex);
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pData != nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
MasterPageContainer::Token aToken (pData->second);
|
|
|
|
if (pPage == mpContainer->GetPageObjectForToken(aToken,false))
|
|
|
|
{
|
|
|
|
mpContainer->InvalidatePreview(aToken);
|
|
|
|
mpContainer->RequestPreview(aToken);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
void MasterPagesSelector::UpdateAllPreviews()
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
2015-05-29 13:34:26 +02:00
|
|
|
for (size_t nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
UserData* pData = GetUserData(nIndex);
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pData != nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
MasterPageContainer::Token aToken (pData->second);
|
|
|
|
PreviewValueSet::SetItemImage(
|
|
|
|
nIndex,
|
|
|
|
mpContainer->GetPreviewForToken(aToken));
|
|
|
|
if (mpContainer->GetPreviewState(aToken) == MasterPageContainer::PS_CREATABLE)
|
|
|
|
mpContainer->RequestPreview(aToken);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PreviewValueSet::Rearrange(true);
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
void MasterPagesSelector::ClearPageSet()
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
2015-05-29 13:34:26 +02:00
|
|
|
for (size_t nIndex=1; nIndex<=PreviewValueSet::GetItemCount(); nIndex++)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
UserData* pData = GetUserData(nIndex);
|
2015-11-10 10:23:02 +01:00
|
|
|
if (pData != nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
delete pData;
|
|
|
|
}
|
|
|
|
PreviewValueSet::Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::SetHelpId( const OString& aId )
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
PreviewValueSet::SetHelpId( aId );
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Int32 MasterPagesSelector::GetIndexForToken (MasterPageContainer::Token aToken) const
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
TokenToValueSetIndex::const_iterator iIndex (maTokenToValueSetIndex.find(aToken));
|
|
|
|
if (iIndex != maTokenToValueSetIndex.end())
|
|
|
|
return iIndex->second;
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
void MasterPagesSelector::Clear()
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
ClearPageSet();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::InvalidateItem (MasterPageContainer::Token aToken)
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
ItemList::iterator iItem;
|
|
|
|
for (iItem=maCurrentItemList.begin(); iItem!=maCurrentItemList.end(); ++iItem)
|
|
|
|
{
|
|
|
|
if (*iItem == aToken)
|
|
|
|
{
|
|
|
|
*iItem = MasterPageContainer::NIL_TOKEN;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-10-01 15:03:54 +02:00
|
|
|
void MasterPagesSelector::UpdateItemList (::std::unique_ptr<ItemList> && pNewItemList)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
ItemList::const_iterator iNewItem (pNewItemList->begin());
|
|
|
|
ItemList::const_iterator iCurrentItem (maCurrentItemList.begin());
|
|
|
|
ItemList::const_iterator iNewEnd (pNewItemList->end());
|
|
|
|
ItemList::const_iterator iCurrentEnd (maCurrentItemList.end());
|
|
|
|
sal_uInt16 nIndex (1);
|
|
|
|
|
|
|
|
// Update existing items.
|
|
|
|
for ( ; iNewItem!=iNewEnd && iCurrentItem!=iCurrentEnd; ++iNewItem, ++iCurrentItem,++nIndex)
|
|
|
|
{
|
|
|
|
if (*iNewItem != *iCurrentItem)
|
|
|
|
{
|
|
|
|
SetItem(nIndex,*iNewItem);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Append new items.
|
|
|
|
for ( ; iNewItem!=iNewEnd; ++iNewItem,++nIndex)
|
|
|
|
{
|
|
|
|
SetItem(nIndex,*iNewItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remove trailing items.
|
|
|
|
for ( ; iCurrentItem!=iCurrentEnd; ++iCurrentItem,++nIndex)
|
|
|
|
{
|
|
|
|
SetItem(nIndex,MasterPageContainer::NIL_TOKEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
maCurrentItemList.swap(*pNewItemList);
|
|
|
|
|
|
|
|
PreviewValueSet::Rearrange();
|
|
|
|
if (mxSidebar.is())
|
|
|
|
mxSidebar->requestLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
css::ui::LayoutSize MasterPagesSelector::GetHeightForWidth (const sal_Int32 nWidth)
|
|
|
|
{
|
|
|
|
const sal_Int32 nHeight (GetPreferredHeight(nWidth));
|
|
|
|
return css::ui::LayoutSize(nHeight,nHeight,nHeight);
|
|
|
|
}
|
|
|
|
|
|
|
|
} } // end of namespace sd::sidebar
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|