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"
|
2017-10-23 22:32:55 +02:00
|
|
|
#include <pres.hxx>
|
|
|
|
#include <drawdoc.hxx>
|
|
|
|
#include <sdpage.hxx>
|
|
|
|
#include <app.hrc>
|
2017-06-11 20:56:30 +01:00
|
|
|
|
2017-10-23 22:32:55 +02:00
|
|
|
#include <DrawController.hxx>
|
|
|
|
#include <SlideSorterViewShell.hxx>
|
2013-04-10 08:20:16 +00:00
|
|
|
#include "PreviewValueSet.hxx"
|
2017-10-23 22:32:55 +02:00
|
|
|
#include <ViewShellBase.hxx>
|
New loplugin:unsignedcompare
"Find explicit casts from signed to unsigned integer in comparison against
unsigned integer, where the cast is presumably used to avoid warnings about
signed vs. unsigned comparisons, and could thus be replaced with
o3tl::make_unsigned for clairty." (compilerplugins/clang/unsignedcompare.cxx)
o3tl::make_unsigned requires its argument to be non-negative, and there is a
chance that some original code like
static_cast<sal_uInt32>(n) >= c
used the explicit cast to actually force a (potentially negative) value of
sal_Int32 to be interpreted as an unsigned sal_uInt32, rather than using the
cast to avoid a false "signed vs. unsigned comparison" warning in a case where
n is known to be non-negative. It appears that restricting this plugin to non-
equality comparisons (<, >, <=, >=) and excluding equality comparisons (==, !=)
is a useful heuristic to avoid such false positives. The only remainging false
positive I found was 0288c8ffecff4956a52b9147d441979941e8b87f "Rephrase cast
from sal_Int32 to sal_uInt32".
But which of course does not mean that there were no further false positivies
that I missed. So this commit may accidentally introduce some false hits of the
assert in o3tl::make_unsigned. At least, it passed a full (Linux ASan+UBSan
--enable-dbgutil) `make check && make screenshot`.
It is by design that o3tl::make_unsigned only accepts signed integer parameter
types (and is not defined as a nop for unsigned ones), to avoid unnecessary uses
which would in general be suspicious. But the STATIC_ARRAY_SELECT macro in
include/oox/helper/helper.hxx is used with both signed and unsigned types, so
needs a little oox::detail::make_unsigned helper function for now. (The
ultimate fix being to get rid of the macro in the first place.)
Change-Id: Ia4adc9f44c70ad1dfd608784cac39ee922c32175
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87556
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
2020-01-27 09:30:39 +01:00
|
|
|
#include <o3tl/safeint.hxx>
|
2019-04-07 18:43:32 +02:00
|
|
|
#include <vcl/commandevent.hxx>
|
2013-04-10 08:20:16 +00:00
|
|
|
#include <vcl/image.hxx>
|
|
|
|
#include <vcl/floatwin.hxx>
|
|
|
|
#include <sfx2/dispatch.hxx>
|
2019-03-17 01:11:29 +01:00
|
|
|
#include <sfx2/viewfrm.hxx>
|
2013-04-10 08:20:16 +00:00
|
|
|
#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;
|
|
|
|
|
2020-01-14 20:54:10 +02:00
|
|
|
namespace sd::sidebar {
|
2013-04-10 08:20:16 +00:00
|
|
|
|
2018-10-08 16:12:06 +02:00
|
|
|
/** menu entry that is executed as default action when the left mouse button is
|
|
|
|
clicked over a master page.
|
|
|
|
*/
|
2020-07-01 21:26:45 +02:00
|
|
|
const char gsDefaultClickAction[] = "applyselect";
|
2018-10-08 16:12:06 +02:00
|
|
|
|
2013-04-10 08:20:16 +00:00
|
|
|
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)
|
2020-04-24 13:41:51 +01:00
|
|
|
: PanelLayout( pParent, "MasterPagePanel", "modules/simpress/ui/masterpagepanel.ui", nullptr ),
|
2013-04-10 08:20:16 +00:00
|
|
|
maMutex(),
|
|
|
|
mpContainer(rpContainer),
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet(new PreviewValueSet),
|
|
|
|
mxPreviewValueSetWin(new weld::CustomWeld(*m_xBuilder, "valueset", *mxPreviewValueSet)),
|
2013-04-10 08:20:16 +00:00
|
|
|
mrDocument(rDocument),
|
|
|
|
mrBase(rBase),
|
|
|
|
maCurrentItemList(),
|
|
|
|
maTokenToValueSetIndex(),
|
|
|
|
maLockedMasterPages(),
|
|
|
|
mxSidebar(rxSidebar)
|
|
|
|
{
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->SetSelectHdl (
|
2013-04-10 08:20:16 +00:00
|
|
|
LINK(this, MasterPagesSelector, ClickHandler));
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->SetRightMouseClickHandler (
|
2013-04-10 08:20:16 +00:00
|
|
|
LINK(this, MasterPagesSelector, RightClickHandler));
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->SetStyle(mxPreviewValueSet->GetStyle() | WB_NO_DIRECTSELECT);
|
2014-01-02 16:01:07 -05:00
|
|
|
|
|
|
|
if ( GetDPIScaleFactor() > 1 )
|
|
|
|
mpContainer->SetPreviewSize(MasterPageContainer::LARGE);
|
|
|
|
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->SetPreviewSize(mpContainer->GetPreviewSizePixel());
|
|
|
|
mxPreviewValueSet->Show();
|
2013-04-10 08:20:16 +00:00
|
|
|
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->SetColor(sfx2::sidebar::Theme::GetColor(sfx2::sidebar::Theme::Paint_PanelBackground));
|
2013-04-10 08:20:16 +00:00
|
|
|
|
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();
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSetWin.reset();
|
|
|
|
mxPreviewValueSet.reset();
|
|
|
|
|
|
|
|
PanelLayout::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);
|
|
|
|
|
2020-02-03 16:13:17 +00:00
|
|
|
return mxPreviewValueSet->GetPreferredHeight (nWidth);
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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.
|
2018-12-08 18:27:03 +03:00
|
|
|
for (const auto& rItem : rItemList)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2018-12-08 18:27:03 +03:00
|
|
|
mpContainer->AcquireToken(rItem);
|
|
|
|
aNewLockList.push_back(rItem);
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Release the previously locked master pages.
|
2018-12-08 18:27:03 +03:00
|
|
|
for (const auto& rPage : maLockedMasterPages)
|
|
|
|
mpContainer->ReleaseToken(rPage);
|
2013-04-10 08:20:16 +00:00
|
|
|
|
|
|
|
maLockedMasterPages.swap(aNewLockList);
|
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
void MasterPagesSelector::Fill()
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2017-02-20 12:33:19 +01: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
|
|
|
}
|
|
|
|
|
2017-04-13 11:48:20 +01:00
|
|
|
OUString MasterPagesSelector::GetContextMenuUIFile() const
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2019-07-30 17:49:12 +02:00
|
|
|
return "modules/simpress/ui/mastermenu.ui";
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
2020-04-25 20:17:05 +01:00
|
|
|
IMPL_LINK_NOARG(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.)
|
2018-10-08 16:12:06 +02:00
|
|
|
ExecuteCommand(gsDefaultClickAction);
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK(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
|
2020-02-03 16:13:17 +00:00
|
|
|
// the mouse is selected.
|
|
|
|
mxPreviewValueSet->GrabFocus ();
|
|
|
|
mxPreviewValueSet->ReleaseMouse();
|
2013-04-10 08:20:16 +00:00
|
|
|
SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
|
2020-08-03 15:52:33 +02:00
|
|
|
if (pViewFrame == nullptr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
|
|
|
|
if (pDispatcher != nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2020-08-03 15:52:33 +02:00
|
|
|
sal_uInt16 nIndex = mxPreviewValueSet->GetItemId (rEvent.GetPosPixel());
|
|
|
|
if (nIndex > 0)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2020-08-03 15:52:33 +02:00
|
|
|
mxPreviewValueSet->SelectItem (nIndex);
|
|
|
|
// Now do the actual display of the context menu
|
|
|
|
ShowContextMenu(&rEvent.GetPosPixel());
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-03 16:13:17 +00:00
|
|
|
void MasterPagesSelector::ShowContextMenu(const Point* pPos)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2020-02-03 16:13:17 +00:00
|
|
|
// Use the currently selected item and show the popup menu in its
|
|
|
|
// center.
|
|
|
|
const sal_uInt16 nIndex = mxPreviewValueSet->GetSelectedItemId();
|
2020-08-03 15:52:33 +02:00
|
|
|
if (nIndex <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
if (!pPos)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2020-08-03 15:52:33 +02:00
|
|
|
::tools::Rectangle aBBox (mxPreviewValueSet->GetItemRect(nIndex));
|
|
|
|
aPosition = aBBox.Center();
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
2020-08-03 15:52:33 +02:00
|
|
|
else
|
|
|
|
aPosition = *pPos;
|
|
|
|
|
|
|
|
// Setup the menu.
|
|
|
|
VclBuilder aBuilder(nullptr, AllSettings::GetUIRootDir(), GetContextMenuUIFile(), "");
|
|
|
|
VclPtr<PopupMenu> pMenu(aBuilder.get_menu("menu"));
|
|
|
|
FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow());
|
|
|
|
if (pMenuWindow != nullptr)
|
|
|
|
pMenuWindow->SetPopupModeFlags(
|
|
|
|
pMenuWindow->GetPopupModeFlags() | FloatWinPopupFlags::NoMouseUpClose);
|
|
|
|
pMenu->SetSelectHdl(LINK(this, MasterPagesSelector, OnMenuItemSelected));
|
|
|
|
|
|
|
|
ProcessPopupMenu(*pMenu);
|
|
|
|
|
|
|
|
// Show the menu.
|
|
|
|
pMenu->Execute(this, ::tools::Rectangle(aPosition,Size(1,1)), PopupMenuFlags::ExecuteDown);
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
2020-02-03 16:13:17 +00:00
|
|
|
void MasterPagesSelector::Command (const CommandEvent& rEvent)
|
|
|
|
{
|
|
|
|
if (rEvent.GetCommand() == CommandEventId::ContextMenu)
|
|
|
|
ShowContextMenu(rEvent.IsMouseEvent() ? &rEvent.GetMousePosPixel() : nullptr);
|
|
|
|
}
|
|
|
|
|
2013-04-10 08:20:16 +00:00
|
|
|
void MasterPagesSelector::ProcessPopupMenu (Menu& rMenu)
|
|
|
|
{
|
|
|
|
// Disable some entries.
|
|
|
|
if (mpContainer->GetPreviewSize() == MasterPageContainer::SMALL)
|
2017-04-13 11:48:20 +01:00
|
|
|
rMenu.EnableItem(rMenu.GetItemId("small"), false);
|
2013-04-10 08:20:16 +00:00
|
|
|
else
|
2017-04-13 11:48:20 +01:00
|
|
|
rMenu.EnableItem(rMenu.GetItemId("large"), false);
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK(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();
|
2017-04-13 11:48:20 +01:00
|
|
|
ExecuteCommand(pMenu->GetCurItemIdent());
|
2015-09-06 12:05:08 +02:00
|
|
|
return false;
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
2017-04-13 11:48:20 +01:00
|
|
|
void MasterPagesSelector::ExecuteCommand(const OString &rIdent)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2017-04-13 11:48:20 +01:00
|
|
|
if (rIdent == "applyall")
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2017-04-13 11:48:20 +01:00
|
|
|
mrBase.SetBusyState (true);
|
|
|
|
AssignMasterPageToAllSlides (GetSelectedMasterPage());
|
|
|
|
mrBase.SetBusyState (false);
|
|
|
|
}
|
|
|
|
else if (rIdent == "applyselect")
|
|
|
|
{
|
|
|
|
mrBase.SetBusyState (true);
|
|
|
|
AssignMasterPageToSelectedSlides (GetSelectedMasterPage());
|
|
|
|
mrBase.SetBusyState (false);
|
|
|
|
}
|
|
|
|
else if (rIdent == "large")
|
|
|
|
{
|
|
|
|
mrBase.SetBusyState (true);
|
|
|
|
mpContainer->SetPreviewSize(MasterPageContainer::LARGE);
|
|
|
|
mrBase.SetBusyState (false);
|
|
|
|
if (mxSidebar.is())
|
|
|
|
mxSidebar->requestLayout();
|
|
|
|
}
|
|
|
|
else if (rIdent == "small")
|
|
|
|
{
|
|
|
|
mrBase.SetBusyState (true);
|
|
|
|
mpContainer->SetPreviewSize(MasterPageContainer::SMALL);
|
|
|
|
mrBase.SetBusyState (false);
|
|
|
|
if (mxSidebar.is())
|
|
|
|
mxSidebar->requestLayout();
|
|
|
|
}
|
|
|
|
else if (rIdent == "edit")
|
|
|
|
{
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
uno::Reference<drawing::XDrawPage> xSelectedMaster;
|
|
|
|
SdPage* pMasterPage = GetSelectedMasterPage();
|
|
|
|
assert(pMasterPage); //rhbz#902884
|
|
|
|
if (pMasterPage)
|
|
|
|
xSelectedMaster.set(pMasterPage->getUnoPage(), uno::UNO_QUERY);
|
|
|
|
SfxViewFrame* pViewFrame = mrBase.GetViewFrame();
|
|
|
|
if (pViewFrame != nullptr && xSelectedMaster.is())
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2017-04-13 11:48:20 +01:00
|
|
|
SfxDispatcher* pDispatcher = pViewFrame->GetDispatcher();
|
|
|
|
if (pDispatcher != nullptr)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2020-02-03 16:13:17 +00:00
|
|
|
sal_uInt16 nIndex = mxPreviewValueSet->GetSelectedItemId();
|
2017-04-13 11:48:20 +01:00
|
|
|
pDispatcher->Execute(SID_MASTERPAGE, SfxCallMode::SYNCHRON);
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->SelectItem (nIndex);
|
2017-04-13 11:48:20 +01:00
|
|
|
mrBase.GetDrawController().setCurrentPage(xSelectedMaster);
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-05 07:56:12 +02:00
|
|
|
IMPL_LINK(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;
|
2020-02-03 16:13:17 +00:00
|
|
|
sal_uInt16 nIndex = mxPreviewValueSet->GetSelectedItemId();
|
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
|
|
|
{
|
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;
|
|
|
|
|
2016-10-11 13:01:32 +02:00
|
|
|
sal_uInt16 nPageCount = mrDocument.GetSdPageCount(PageKind::Standard);
|
2013-04-10 08:20:16 +00:00
|
|
|
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());
|
2020-01-24 12:04:43 +02:00
|
|
|
::sd::slidesorter::SharedPageSelection pPageList =
|
|
|
|
std::make_shared<::sd::slidesorter::SlideSorterViewShell::PageSelection>();
|
2013-04-10 08:20:16 +00:00
|
|
|
for (sal_uInt16 nPageIndex=0; nPageIndex<nPageCount; nPageIndex++)
|
|
|
|
{
|
2016-10-11 13:01:32 +02:00
|
|
|
SdPage* pPage = mrDocument.GetSdPage (nPageIndex, PageKind::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,
|
2019-03-04 08:57:28 +02:00
|
|
|
const std::shared_ptr<std::vector<SdPage*>>& rPageList)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
DocumentHelper::AssignMasterPageToPageList(mrDocument, pMasterPage, rPageList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::NotifyContainerChangeEvent (const MasterPageContainerChangeEvent& rEvent)
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
|
|
|
switch (rEvent.meEventType)
|
|
|
|
{
|
2017-02-15 09:11:32 +02:00
|
|
|
case MasterPageContainerChangeEvent::EventType::SIZE_CHANGED:
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->SetPreviewSize(mpContainer->GetPreviewSizePixel());
|
2013-04-10 08:20:16 +00:00
|
|
|
UpdateAllPreviews();
|
|
|
|
break;
|
|
|
|
|
2017-02-15 09:11:32 +02:00
|
|
|
case MasterPageContainerChangeEvent::EventType::PREVIEW_CHANGED:
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
int nIndex (GetIndexForToken(rEvent.maChildToken));
|
|
|
|
if (nIndex >= 0)
|
|
|
|
{
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->SetItemImage (
|
2018-01-12 20:16:43 +01:00
|
|
|
static_cast<sal_uInt16>(nIndex),
|
2013-04-10 08:20:16 +00:00
|
|
|
mpContainer->GetPreviewForToken(rEvent.maChildToken));
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->Invalidate(mxPreviewValueSet->GetItemRect(static_cast<sal_uInt16>(nIndex)));
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-02-15 09:11:32 +02:00
|
|
|
case MasterPageContainerChangeEvent::EventType::DATA_CHANGED:
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
InvalidateItem(rEvent.maChildToken);
|
|
|
|
Fill();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-02-15 09:11:32 +02:00
|
|
|
case MasterPageContainerChangeEvent::EventType::CHILD_REMOVED:
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
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::GetUserData (int nIndex) const
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
2020-02-03 16:13:17 +00:00
|
|
|
if (nIndex>0 && o3tl::make_unsigned(nIndex)<=mxPreviewValueSet->GetItemCount())
|
|
|
|
return static_cast<UserData*>(mxPreviewValueSet->GetItemData(static_cast<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
|
|
|
}
|
|
|
|
|
2018-12-21 14:14:18 +02:00
|
|
|
void MasterPagesSelector::SetUserData (int nIndex, std::unique_ptr<UserData> pData)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
2018-12-21 14:14:18 +02:00
|
|
|
delete GetUserData(nIndex);
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->SetItemData(static_cast<sal_uInt16>(nIndex), pData.release());
|
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);
|
|
|
|
|
2019-02-14 09:11:43 +02:00
|
|
|
if (nIndex <= 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (aToken != MasterPageContainer::NIL_TOKEN)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2019-02-14 09:11:43 +02:00
|
|
|
Image aPreview (mpContainer->GetPreviewForToken(aToken));
|
|
|
|
MasterPageContainer::PreviewState eState (mpContainer->GetPreviewState(aToken));
|
2013-04-10 08:20:16 +00:00
|
|
|
|
2019-02-14 09:11:43 +02:00
|
|
|
if (aPreview.GetSizePixel().Width()>0)
|
|
|
|
{
|
2020-02-03 16:13:17 +00:00
|
|
|
if (mxPreviewValueSet->GetItemPos(nIndex) != VALUESET_ITEM_NOTFOUND)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->SetItemImage(nIndex,aPreview);
|
|
|
|
mxPreviewValueSet->SetItemText(nIndex, mpContainer->GetPageNameForToken(aToken));
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
2019-02-14 09:11:43 +02:00
|
|
|
else
|
|
|
|
{
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->InsertItem (
|
2019-02-14 09:11:43 +02:00
|
|
|
nIndex,
|
|
|
|
aPreview,
|
|
|
|
mpContainer->GetPageNameForToken(aToken),
|
|
|
|
nIndex);
|
|
|
|
}
|
|
|
|
SetUserData(nIndex, std::make_unique<UserData>(nIndex,aToken));
|
2013-04-10 08:20:16 +00:00
|
|
|
|
2019-02-14 09:11:43 +02:00
|
|
|
AddTokenToIndexEntry(nIndex,aToken);
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
2019-02-14 09:11:43 +02:00
|
|
|
|
|
|
|
if (eState == MasterPageContainer::PS_CREATABLE)
|
|
|
|
mpContainer->RequestPreview(aToken);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->RemoveItem(nIndex);
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2020-02-03 16:13:17 +00:00
|
|
|
for (size_t nIndex=1; nIndex<=mxPreviewValueSet->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);
|
|
|
|
|
2020-02-03 16:13:17 +00:00
|
|
|
for (size_t nIndex=1; nIndex<=mxPreviewValueSet->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);
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->SetItemImage(
|
2013-04-10 08:20:16 +00:00
|
|
|
nIndex,
|
|
|
|
mpContainer->GetPreviewForToken(aToken));
|
|
|
|
if (mpContainer->GetPreviewState(aToken) == MasterPageContainer::PS_CREATABLE)
|
|
|
|
mpContainer->RequestPreview(aToken);
|
|
|
|
}
|
|
|
|
}
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->Rearrange();
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
2015-04-14 12:44:47 +02:00
|
|
|
void MasterPagesSelector::ClearPageSet()
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
2020-02-03 16:13:17 +00:00
|
|
|
for (size_t nIndex=1; nIndex<=mxPreviewValueSet->GetItemCount(); nIndex++)
|
2013-04-10 08:20:16 +00:00
|
|
|
{
|
|
|
|
UserData* pData = GetUserData(nIndex);
|
2017-05-31 15:40:25 +02:00
|
|
|
delete pData;
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->Clear();
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MasterPagesSelector::SetHelpId( const OString& aId )
|
|
|
|
{
|
|
|
|
const ::osl::MutexGuard aGuard (maMutex);
|
|
|
|
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->SetHelpId( aId );
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-12-08 18:27:03 +03:00
|
|
|
auto iItem = std::find(maCurrentItemList.begin(), maCurrentItemList.end(), aToken);
|
|
|
|
if (iItem != maCurrentItemList.end())
|
|
|
|
*iItem = MasterPageContainer::NIL_TOKEN;
|
2013-04-10 08:20:16 +00:00
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2020-02-03 16:13:17 +00:00
|
|
|
mxPreviewValueSet->Rearrange();
|
2013-04-10 08:20:16 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-01-14 20:54:10 +02:00
|
|
|
} // end of namespace sd::sidebar
|
2013-04-10 08:20:16 +00:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|