2010-10-12 15:51:52 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2008-04-03 13:30:03 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 09:00:29 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2008-04-03 13:30:03 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2008-04-03 13:30:03 +00:00
|
|
|
*
|
2008-04-11 09:00:29 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2008-04-03 13:30:03 +00:00
|
|
|
*
|
2008-04-11 09:00:29 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2008-04-03 13:30:03 +00:00
|
|
|
*
|
2008-04-11 09:00:29 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2008-04-03 13:30:03 +00:00
|
|
|
*
|
2008-04-11 09:00:29 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2008-04-03 13:30:03 +00:00
|
|
|
*
|
2008-04-11 09:00:29 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2008-04-03 13:30:03 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "controller/SlsSelectionManager.hxx"
|
|
|
|
|
|
|
|
#include "SlideSorter.hxx"
|
2010-04-08 14:47:08 +02:00
|
|
|
#include "SlsCommand.hxx"
|
2008-04-03 13:30:03 +00:00
|
|
|
#include "controller/SlideSorterController.hxx"
|
2008-07-07 12:33:33 +00:00
|
|
|
#include "controller/SlsAnimator.hxx"
|
2010-01-27 11:41:30 +01:00
|
|
|
#include "controller/SlsAnimationFunction.hxx"
|
2008-04-03 13:30:03 +00:00
|
|
|
#include "controller/SlsCurrentSlideManager.hxx"
|
2008-07-07 12:33:33 +00:00
|
|
|
#include "controller/SlsFocusManager.hxx"
|
2010-04-08 14:47:08 +02:00
|
|
|
#include "controller/SlsPageSelector.hxx"
|
2008-04-03 13:30:03 +00:00
|
|
|
#include "controller/SlsProperties.hxx"
|
2008-07-07 12:33:33 +00:00
|
|
|
#include "controller/SlsScrollBarManager.hxx"
|
|
|
|
#include "controller/SlsSlotManager.hxx"
|
2010-04-08 14:47:08 +02:00
|
|
|
#include "controller/SlsSelectionObserver.hxx"
|
2008-04-03 13:30:03 +00:00
|
|
|
#include "model/SlideSorterModel.hxx"
|
|
|
|
#include "model/SlsPageEnumerationProvider.hxx"
|
|
|
|
#include "model/SlsPageDescriptor.hxx"
|
|
|
|
#include "view/SlideSorterView.hxx"
|
2010-01-27 11:41:30 +01:00
|
|
|
#include "view/SlsLayouter.hxx"
|
2008-04-03 13:30:03 +00:00
|
|
|
#include "drawdoc.hxx"
|
|
|
|
#include "Window.hxx"
|
|
|
|
#include <svx/svxids.hrc>
|
|
|
|
#include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
|
|
|
|
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
|
|
|
|
|
|
|
|
#include "res_bmp.hrc"
|
|
|
|
#include "sdresid.hxx"
|
|
|
|
#include "strings.hrc"
|
|
|
|
#include "app.hrc"
|
|
|
|
#include "glob.hrc"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
2009-06-04 16:21:29 +00:00
|
|
|
using namespace ::com::sun::star::drawing;
|
2008-04-03 13:30:03 +00:00
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
using namespace ::sd::slidesorter::model;
|
|
|
|
using namespace ::sd::slidesorter::view;
|
|
|
|
using namespace ::sd::slidesorter::controller;
|
|
|
|
|
|
|
|
namespace sd { namespace slidesorter { namespace controller {
|
|
|
|
|
|
|
|
|
2010-04-08 14:47:08 +02:00
|
|
|
class SelectionManager::PageInsertionListener
|
|
|
|
: public SfxListener
|
|
|
|
{
|
|
|
|
public:
|
2008-04-03 13:30:03 +00:00
|
|
|
|
2010-04-08 14:47:08 +02:00
|
|
|
};
|
2008-04-03 13:30:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
SelectionManager::SelectionManager (SlideSorter& rSlideSorter)
|
|
|
|
: mrSlideSorter(rSlideSorter),
|
|
|
|
mrController(rSlideSorter.GetController()),
|
|
|
|
maSelectionBeforeSwitch(),
|
2010-02-17 13:32:10 +01:00
|
|
|
mbIsMakeSelectionVisiblePending(true),
|
|
|
|
mnInsertionPosition(-1),
|
2010-03-11 10:13:42 +01:00
|
|
|
mnAnimationId(Animator::NotAnAnimationId),
|
2010-04-08 14:47:08 +02:00
|
|
|
maRequestedTopLeft(),
|
|
|
|
mpPageInsertionListener(),
|
|
|
|
mpSelectionObserver(new SelectionObserver(rSlideSorter))
|
2008-04-03 13:30:03 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SelectionManager::~SelectionManager (void)
|
|
|
|
{
|
2010-03-08 11:34:08 +01:00
|
|
|
if (mnAnimationId != Animator::NotAnAnimationId)
|
|
|
|
mrController.GetAnimator()->RemoveAnimation(mnAnimationId);
|
2008-04-03 13:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-03-12 17:03:08 +01:00
|
|
|
void SelectionManager::DeleteSelectedPages (const bool bSelectFollowingPage)
|
2008-04-03 13:30:03 +00:00
|
|
|
{
|
2010-02-25 16:51:49 +01:00
|
|
|
// Create some locks to prevent updates of the model, view, selection
|
|
|
|
// state while modifying any of them.
|
2008-04-03 13:30:03 +00:00
|
|
|
SlideSorterController::ModelChangeLock aLock (mrController);
|
2010-02-25 16:51:49 +01:00
|
|
|
SlideSorterView::DrawLock aDrawLock (mrSlideSorter);
|
|
|
|
PageSelector::UpdateLock aSelectionLock (mrSlideSorter);
|
2008-04-03 13:30:03 +00:00
|
|
|
|
|
|
|
// Hide focus.
|
|
|
|
bool bIsFocusShowing = mrController.GetFocusManager().IsFocusShowing();
|
|
|
|
if (bIsFocusShowing)
|
|
|
|
mrController.GetFocusManager().ToggleFocus();
|
|
|
|
|
|
|
|
// Store pointers to all selected page descriptors. This is necessary
|
|
|
|
// because the pages get deselected when the first one is deleted.
|
|
|
|
model::PageEnumeration aPageEnumeration (
|
|
|
|
PageEnumerationProvider::CreateSelectedPagesEnumeration(mrSlideSorter.GetModel()));
|
|
|
|
::std::vector<SdPage*> aSelectedPages;
|
2010-03-12 17:03:08 +01:00
|
|
|
sal_Int32 nNewCurrentSlide (-1);
|
2008-04-03 13:30:03 +00:00
|
|
|
while (aPageEnumeration.HasMoreElements())
|
2010-02-25 16:51:49 +01:00
|
|
|
{
|
|
|
|
SharedPageDescriptor pDescriptor (aPageEnumeration.GetNextElement());
|
|
|
|
aSelectedPages.push_back(pDescriptor->GetPage());
|
2010-03-12 17:03:08 +01:00
|
|
|
if (bSelectFollowingPage || nNewCurrentSlide<0)
|
|
|
|
nNewCurrentSlide = pDescriptor->GetPageIndex();
|
2010-02-25 16:51:49 +01:00
|
|
|
}
|
|
|
|
if (aSelectedPages.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Determine the slide to select (and thereby make the current slide)
|
|
|
|
// after the deletion.
|
2010-03-12 17:03:08 +01:00
|
|
|
if (bSelectFollowingPage)
|
|
|
|
nNewCurrentSlide -= aSelectedPages.size() - 1;
|
|
|
|
else
|
|
|
|
--nNewCurrentSlide;
|
2008-04-03 13:30:03 +00:00
|
|
|
|
|
|
|
// The actual deletion of the selected pages is done in one of two
|
|
|
|
// helper functions. They are specialized for normal respectively for
|
|
|
|
// master pages.
|
|
|
|
mrSlideSorter.GetView().BegUndo (SdResId(STR_UNDO_DELETEPAGES));
|
|
|
|
if (mrSlideSorter.GetModel().GetEditMode() == EM_PAGE)
|
|
|
|
DeleteSelectedNormalPages(aSelectedPages);
|
|
|
|
else
|
|
|
|
DeleteSelectedMasterPages(aSelectedPages);
|
|
|
|
mrSlideSorter.GetView().EndUndo ();
|
|
|
|
|
|
|
|
mrController.HandleModelChange();
|
|
|
|
aLock.Release();
|
|
|
|
|
|
|
|
// Show focus and move it to next valid location.
|
|
|
|
if (bIsFocusShowing)
|
2010-02-25 16:51:49 +01:00
|
|
|
mrController.GetFocusManager().ToggleFocus();
|
|
|
|
|
|
|
|
// Set the new current slide.
|
2010-03-12 17:03:08 +01:00
|
|
|
if (nNewCurrentSlide < 0)
|
|
|
|
nNewCurrentSlide = 0;
|
|
|
|
else if (nNewCurrentSlide >= mrSlideSorter.GetModel().GetPageCount())
|
2010-02-25 16:51:49 +01:00
|
|
|
nNewCurrentSlide = mrSlideSorter.GetModel().GetPageCount()-1;
|
2010-06-15 17:45:26 +02:00
|
|
|
mrController.GetPageSelector().CountSelectedPages();
|
2010-02-25 16:51:49 +01:00
|
|
|
mrController.GetPageSelector().SelectPage(nNewCurrentSlide);
|
|
|
|
mrController.GetFocusManager().SetFocusedPage(nNewCurrentSlide);
|
2008-04-03 13:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SelectionManager::DeleteSelectedNormalPages (const ::std::vector<SdPage*>& rSelectedPages)
|
|
|
|
{
|
|
|
|
// Prepare the deletion via the UNO API.
|
|
|
|
OSL_ASSERT(mrSlideSorter.GetModel().GetEditMode() == EM_PAGE);
|
|
|
|
|
2009-06-04 16:21:29 +00:00
|
|
|
try
|
2008-04-03 13:30:03 +00:00
|
|
|
{
|
2009-06-04 16:21:29 +00:00
|
|
|
Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier( mrSlideSorter.GetModel().GetDocument()->getUnoModel(), UNO_QUERY_THROW );
|
|
|
|
Reference<drawing::XDrawPages> xPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
|
|
|
|
|
|
|
|
// Iterate over all pages that where seleted when this method was called
|
|
|
|
// and delete the draw page the notes page. The iteration is done in
|
|
|
|
// reverse order so that when one slide is not deleted (to avoid an
|
|
|
|
// empty document) the remaining slide is the first one.
|
|
|
|
::std::vector<SdPage*>::const_reverse_iterator aI;
|
2011-05-08 10:47:35 +02:00
|
|
|
for (aI=rSelectedPages.rbegin(); aI!=rSelectedPages.rend(); ++aI)
|
2008-04-03 13:30:03 +00:00
|
|
|
{
|
2009-06-04 16:21:29 +00:00
|
|
|
// Do not delete the last slide in the document.
|
|
|
|
if (xPages->getCount() <= 1)
|
|
|
|
break;
|
2008-04-03 13:30:03 +00:00
|
|
|
|
2011-01-17 11:41:00 +01:00
|
|
|
const sal_uInt16 nPage (model::FromCoreIndex((*aI)->GetPageNum()));
|
2008-04-03 13:30:03 +00:00
|
|
|
|
2009-06-04 16:21:29 +00:00
|
|
|
Reference< XDrawPage > xPage( xPages->getByIndex( nPage ), UNO_QUERY_THROW );
|
|
|
|
xPages->remove(xPage);
|
2008-04-03 13:30:03 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-04 16:21:29 +00:00
|
|
|
catch( Exception& )
|
|
|
|
{
|
2011-03-01 19:06:55 +01:00
|
|
|
OSL_FAIL("SelectionManager::DeleteSelectedNormalPages(), exception caught!");
|
2009-06-04 16:21:29 +00:00
|
|
|
}
|
2008-04-03 13:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SelectionManager::DeleteSelectedMasterPages (const ::std::vector<SdPage*>& rSelectedPages)
|
|
|
|
{
|
|
|
|
// Prepare the deletion via the UNO API.
|
|
|
|
OSL_ASSERT(mrSlideSorter.GetModel().GetEditMode() == EM_MASTERPAGE);
|
|
|
|
|
2009-06-04 16:21:29 +00:00
|
|
|
try
|
2008-04-03 13:30:03 +00:00
|
|
|
{
|
2009-06-04 16:21:29 +00:00
|
|
|
Reference<drawing::XMasterPagesSupplier> xDrawPagesSupplier( mrSlideSorter.GetModel().GetDocument()->getUnoModel(), UNO_QUERY_THROW );
|
|
|
|
Reference<drawing::XDrawPages> xPages( xDrawPagesSupplier->getMasterPages(), UNO_QUERY_THROW );
|
|
|
|
|
|
|
|
// Iterate over all pages that where seleted when this method was called
|
|
|
|
// and delete the draw page the notes page. The iteration is done in
|
|
|
|
// reverse order so that when one slide is not deleted (to avoid an
|
|
|
|
// empty document) the remaining slide is the first one.
|
|
|
|
::std::vector<SdPage*>::const_reverse_iterator aI;
|
2011-05-08 10:47:35 +02:00
|
|
|
for (aI=rSelectedPages.rbegin(); aI!=rSelectedPages.rend(); ++aI)
|
2008-04-03 13:30:03 +00:00
|
|
|
{
|
2009-06-04 16:21:29 +00:00
|
|
|
// Do not delete the last slide in the document.
|
|
|
|
if (xPages->getCount() <= 1)
|
|
|
|
break;
|
2008-04-03 13:30:03 +00:00
|
|
|
|
2011-01-17 11:41:00 +01:00
|
|
|
const sal_uInt16 nPage (model::FromCoreIndex((*aI)->GetPageNum()));
|
2008-04-03 13:30:03 +00:00
|
|
|
|
2009-06-04 16:21:29 +00:00
|
|
|
Reference< XDrawPage > xPage( xPages->getByIndex( nPage ), UNO_QUERY_THROW );
|
|
|
|
xPages->remove(xPage);
|
2008-04-03 13:30:03 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-04 16:21:29 +00:00
|
|
|
catch( Exception& )
|
|
|
|
{
|
2011-03-01 19:06:55 +01:00
|
|
|
OSL_FAIL("SelectionManager::DeleteSelectedMasterPages(), exception caught!");
|
2009-06-04 16:21:29 +00:00
|
|
|
}
|
2008-04-03 13:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SelectionManager::SelectionHasChanged (const bool bMakeSelectionVisible)
|
|
|
|
{
|
|
|
|
if (bMakeSelectionVisible)
|
|
|
|
mbIsMakeSelectionVisiblePending = true;
|
|
|
|
|
|
|
|
ViewShell* pViewShell = mrSlideSorter.GetViewShell();
|
|
|
|
if (pViewShell != NULL)
|
|
|
|
{
|
|
|
|
pViewShell->Invalidate (SID_EXPAND_PAGE);
|
|
|
|
pViewShell->Invalidate (SID_SUMMARY_PAGE);
|
|
|
|
pViewShell->Invalidate(SID_SHOW_SLIDE);
|
|
|
|
pViewShell->Invalidate(SID_HIDE_SLIDE);
|
2009-09-18 10:15:03 +00:00
|
|
|
pViewShell->Invalidate(SID_DELETE_PAGE);
|
|
|
|
pViewShell->Invalidate(SID_DELETE_MASTER_PAGE);
|
2009-12-03 18:53:41 +01:00
|
|
|
pViewShell->Invalidate(SID_ASSIGN_LAYOUT);
|
2008-04-03 13:30:03 +00:00
|
|
|
|
|
|
|
// StatusBar
|
|
|
|
pViewShell->Invalidate (SID_STATUS_PAGE);
|
|
|
|
pViewShell->Invalidate (SID_STATUS_LAYOUT);
|
|
|
|
|
|
|
|
OSL_ASSERT(mrController.GetCurrentSlideManager());
|
|
|
|
SharedPageDescriptor pDescriptor(mrController.GetCurrentSlideManager()->GetCurrentSlide());
|
|
|
|
if (pDescriptor.get() != NULL)
|
|
|
|
pViewShell->UpdatePreview(pDescriptor->GetPage());
|
|
|
|
|
|
|
|
// Tell the slection change listeners that the selection has changed.
|
|
|
|
::std::vector<Link>::iterator iListener (maSelectionChangeListeners.begin());
|
|
|
|
::std::vector<Link>::iterator iEnd (maSelectionChangeListeners.end());
|
|
|
|
for (; iListener!=iEnd; ++iListener)
|
|
|
|
{
|
|
|
|
iListener->Call(NULL);
|
|
|
|
}
|
2009-05-07 12:38:03 +00:00
|
|
|
|
|
|
|
// Reset the insertion position: until set again it is calculated from
|
|
|
|
// the current selection.
|
|
|
|
mnInsertionPosition = -1;
|
2008-04-03 13:30:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SelectionManager::AddSelectionChangeListener (const Link& rListener)
|
|
|
|
{
|
|
|
|
if (::std::find (
|
|
|
|
maSelectionChangeListeners.begin(),
|
|
|
|
maSelectionChangeListeners.end(),
|
|
|
|
rListener) == maSelectionChangeListeners.end())
|
|
|
|
{
|
|
|
|
maSelectionChangeListeners.push_back (rListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SelectionManager::RemoveSelectionChangeListener(const Link&rListener)
|
|
|
|
{
|
|
|
|
maSelectionChangeListeners.erase (
|
|
|
|
::std::find (
|
|
|
|
maSelectionChangeListeners.begin(),
|
|
|
|
maSelectionChangeListeners.end(),
|
|
|
|
rListener));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-05-07 12:38:03 +00:00
|
|
|
sal_Int32 SelectionManager::GetInsertionPosition (void) const
|
|
|
|
{
|
|
|
|
sal_Int32 nInsertionPosition (mnInsertionPosition);
|
|
|
|
if (nInsertionPosition < 0)
|
|
|
|
{
|
|
|
|
model::PageEnumeration aSelectedPages
|
|
|
|
(model::PageEnumerationProvider::CreateSelectedPagesEnumeration(
|
|
|
|
mrSlideSorter.GetModel()));
|
|
|
|
// Initialize (for the case of an empty selection) with the position
|
|
|
|
// at the end of the document.
|
|
|
|
nInsertionPosition = mrSlideSorter.GetModel().GetPageCount();
|
|
|
|
while (aSelectedPages.HasMoreElements())
|
|
|
|
{
|
|
|
|
const sal_Int32 nPosition (aSelectedPages.GetNextElement()->GetPage()->GetPageNum());
|
|
|
|
// Convert *2+1 index to straight index (n-1)/2 after the page
|
|
|
|
// (+1).
|
2010-04-08 14:47:08 +02:00
|
|
|
nInsertionPosition = model::FromCoreIndex(nPosition) + 1;
|
2009-05-07 12:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return nInsertionPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SelectionManager::SetInsertionPosition (const sal_Int32 nInsertionPosition)
|
|
|
|
{
|
|
|
|
if (nInsertionPosition < 0)
|
|
|
|
mnInsertionPosition = -1;
|
|
|
|
else if (nInsertionPosition > mrSlideSorter.GetModel().GetPageCount())
|
|
|
|
{
|
|
|
|
// Assert but then ignore invalid values.
|
|
|
|
OSL_ASSERT(nInsertionPosition<=mrSlideSorter.GetModel().GetPageCount());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mnInsertionPosition = nInsertionPosition;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-08 14:47:08 +02:00
|
|
|
::boost::shared_ptr<SelectionObserver> SelectionManager::GetSelectionObserver (void) const
|
2008-04-03 13:30:03 +00:00
|
|
|
{
|
2010-04-08 14:47:08 +02:00
|
|
|
return mpSelectionObserver;
|
2008-04-03 13:30:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} } } // end of namespace ::sd::slidesorter
|
2010-10-12 15:51:52 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|