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:24:16 +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:24:16 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2008-04-03 13:24:16 +00:00
|
|
|
*
|
2008-04-11 09:00:29 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2008-04-03 13:24:16 +00:00
|
|
|
*
|
2008-04-11 09:00:29 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2008-04-03 13:24:16 +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:24:16 +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:24:16 +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:24:16 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include "SlideSorter.hxx"
|
|
|
|
#include "model/SlideSorterModel.hxx"
|
|
|
|
#include "model/SlsPageDescriptor.hxx"
|
|
|
|
#include "controller/SlsPageSelector.hxx"
|
|
|
|
#include "controller/SlideSorterController.hxx"
|
|
|
|
#include "controller/SlsCurrentSlideManager.hxx"
|
2010-02-25 16:51:49 +01:00
|
|
|
#include "controller/SlsFocusManager.hxx"
|
2008-04-03 13:24:16 +00:00
|
|
|
#include "view/SlideSorterView.hxx"
|
|
|
|
#include "ViewShellBase.hxx"
|
|
|
|
#include "ViewShell.hxx"
|
|
|
|
#include "DrawViewShell.hxx"
|
|
|
|
#include "sdpage.hxx"
|
|
|
|
#include "FrameView.hxx"
|
|
|
|
#include <com/sun/star/beans/XPropertySet.hpp>
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
using namespace ::com::sun::star::uno;
|
|
|
|
|
|
|
|
using namespace ::sd::slidesorter::model;
|
|
|
|
|
2010-03-08 11:34:08 +01:00
|
|
|
|
2008-04-03 13:24:16 +00:00
|
|
|
namespace sd { namespace slidesorter { namespace controller {
|
|
|
|
|
2010-03-08 11:34:08 +01:00
|
|
|
|
2008-04-03 13:24:16 +00:00
|
|
|
CurrentSlideManager::CurrentSlideManager (SlideSorter& rSlideSorter)
|
|
|
|
: mrSlideSorter(rSlideSorter),
|
|
|
|
mnCurrentSlideIndex(-1),
|
2010-06-21 15:59:22 +02:00
|
|
|
mpCurrentSlide(),
|
|
|
|
maSwitchPageDelayTimer()
|
2008-04-03 13:24:16 +00:00
|
|
|
{
|
2010-06-21 15:59:22 +02:00
|
|
|
maSwitchPageDelayTimer.SetTimeout(100);
|
|
|
|
maSwitchPageDelayTimer.SetTimeoutHdl(LINK(this,CurrentSlideManager,SwitchPageCallback));
|
2008-04-03 13:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CurrentSlideManager::~CurrentSlideManager (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-03-15 10:48:46 +01:00
|
|
|
void CurrentSlideManager::NotifyCurrentSlideChange (const SdPage* pPage)
|
|
|
|
{
|
|
|
|
if (pPage != NULL)
|
|
|
|
NotifyCurrentSlideChange(
|
|
|
|
mrSlideSorter.GetModel().GetIndex(
|
|
|
|
Reference<drawing::XDrawPage>(
|
|
|
|
const_cast<SdPage*>(pPage)->getUnoPage(),
|
|
|
|
UNO_QUERY)));
|
|
|
|
else
|
|
|
|
NotifyCurrentSlideChange(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CurrentSlideManager::NotifyCurrentSlideChange (const sal_Int32 nSlideIndex)
|
2008-04-03 13:24:16 +00:00
|
|
|
{
|
|
|
|
if (mnCurrentSlideIndex != nSlideIndex)
|
|
|
|
{
|
|
|
|
ReleaseCurrentSlide();
|
|
|
|
AcquireCurrentSlide(nSlideIndex);
|
|
|
|
|
|
|
|
// Update the selection.
|
|
|
|
mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
|
2010-04-23 17:06:10 +02:00
|
|
|
if (mpCurrentSlide)
|
|
|
|
{
|
2008-04-03 13:24:16 +00:00
|
|
|
mrSlideSorter.GetController().GetPageSelector().SelectPage(mpCurrentSlide);
|
2010-04-23 17:06:10 +02:00
|
|
|
mrSlideSorter.GetController().GetFocusManager().SetFocusedPage(mpCurrentSlide);
|
|
|
|
}
|
2008-04-03 13:24:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CurrentSlideManager::ReleaseCurrentSlide (void)
|
|
|
|
{
|
|
|
|
if (mpCurrentSlide.get() != NULL)
|
2010-01-27 11:41:30 +01:00
|
|
|
mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, false);
|
2008-04-03 13:24:16 +00:00
|
|
|
|
|
|
|
mpCurrentSlide.reset();
|
2008-05-20 13:12:00 +00:00
|
|
|
mnCurrentSlideIndex = -1;
|
2008-04-03 13:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool CurrentSlideManager::IsCurrentSlideIsValid (void)
|
|
|
|
{
|
|
|
|
return mnCurrentSlideIndex >= 0 && mnCurrentSlideIndex<mrSlideSorter.GetModel().GetPageCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CurrentSlideManager::AcquireCurrentSlide (const sal_Int32 nSlideIndex)
|
|
|
|
{
|
|
|
|
mnCurrentSlideIndex = nSlideIndex;
|
|
|
|
|
|
|
|
if (IsCurrentSlideIsValid())
|
|
|
|
{
|
|
|
|
// Get a descriptor for the XDrawPage reference. Note that the
|
|
|
|
// given XDrawPage may or may not be member of the slide sorter
|
|
|
|
// document.
|
|
|
|
mpCurrentSlide = mrSlideSorter.GetModel().GetPageDescriptor(mnCurrentSlideIndex);
|
|
|
|
if (mpCurrentSlide.get() != NULL)
|
2010-01-27 11:41:30 +01:00
|
|
|
mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, true);
|
2008-04-03 13:24:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-15 15:00:03 +02:00
|
|
|
void CurrentSlideManager::SwitchCurrentSlide (
|
|
|
|
const sal_Int32 nSlideIndex,
|
|
|
|
const bool bUpdateSelection)
|
2008-04-03 13:24:16 +00:00
|
|
|
{
|
2010-06-15 15:00:03 +02:00
|
|
|
SwitchCurrentSlide(mrSlideSorter.GetModel().GetPageDescriptor(nSlideIndex), bUpdateSelection);
|
2008-04-03 13:24:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-15 15:00:03 +02:00
|
|
|
void CurrentSlideManager::SwitchCurrentSlide (
|
|
|
|
const SharedPageDescriptor& rpDescriptor,
|
|
|
|
const bool bUpdateSelection)
|
2008-04-03 13:24:16 +00:00
|
|
|
{
|
2010-02-23 16:56:05 +01:00
|
|
|
if (rpDescriptor.get() != NULL && mpCurrentSlide!=rpDescriptor)
|
2008-04-03 13:24:16 +00:00
|
|
|
{
|
2010-01-27 11:41:30 +01:00
|
|
|
ReleaseCurrentSlide();
|
|
|
|
AcquireCurrentSlide((rpDescriptor->GetPage()->GetPageNum()-1)/2);
|
2008-04-03 13:24:16 +00:00
|
|
|
|
|
|
|
ViewShell* pViewShell = mrSlideSorter.GetViewShell();
|
|
|
|
if (pViewShell != NULL && pViewShell->IsMainViewShell())
|
|
|
|
{
|
2010-06-21 15:59:22 +02:00
|
|
|
// The slide sorter is the main view.
|
2008-04-03 13:24:16 +00:00
|
|
|
FrameView* pFrameView = pViewShell->GetFrameView();
|
|
|
|
if (pFrameView != NULL)
|
2011-01-17 11:41:00 +01:00
|
|
|
pFrameView->SetSelectedPage(sal::static_int_cast<sal_uInt16>(mnCurrentSlideIndex));
|
2010-02-25 16:51:49 +01:00
|
|
|
mrSlideSorter.GetController().GetPageSelector().SetCoreSelection();
|
2008-04-03 13:24:16 +00:00
|
|
|
}
|
2010-06-21 15:59:22 +02:00
|
|
|
|
|
|
|
// We do not tell the XController/ViewShellBase about the new
|
|
|
|
// slide right away. This is done asynchronously after a short
|
|
|
|
// delay to allow for more slide switches in the slide sorter.
|
|
|
|
// This goes under the assumption that slide switching inside
|
|
|
|
// the slide sorter is fast (no expensive redraw of the new page
|
|
|
|
// (unless the preview of the new slide is not yet preset)) and
|
|
|
|
// that slide switching in the edit view is slow (all shapes of
|
|
|
|
// the new slide have to be repainted.)
|
|
|
|
maSwitchPageDelayTimer.Start();
|
|
|
|
|
2010-07-22 11:12:42 +02:00
|
|
|
// We have to store the (index of the) new current slide at
|
|
|
|
// the tab control because there are other asynchronous
|
|
|
|
// notifications of the slide switching that otherwise
|
|
|
|
// overwrite the correct value.
|
|
|
|
SetCurrentSlideAtTabControl(mpCurrentSlide);
|
|
|
|
|
2010-06-15 15:00:03 +02:00
|
|
|
if (bUpdateSelection)
|
2008-04-03 13:24:16 +00:00
|
|
|
{
|
2010-06-15 15:00:03 +02:00
|
|
|
mrSlideSorter.GetController().GetPageSelector().DeselectAllPages();
|
|
|
|
mrSlideSorter.GetController().GetPageSelector().SelectPage(rpDescriptor);
|
2008-04-03 13:24:16 +00:00
|
|
|
}
|
2010-02-25 16:51:49 +01:00
|
|
|
mrSlideSorter.GetController().GetFocusManager().SetFocusedPage(rpDescriptor);
|
2008-04-03 13:24:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CurrentSlideManager::SetCurrentSlideAtViewShellBase (const SharedPageDescriptor& rpDescriptor)
|
|
|
|
{
|
|
|
|
OSL_ASSERT(rpDescriptor.get() != NULL);
|
|
|
|
|
|
|
|
ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
|
|
|
|
if (pBase != NULL)
|
|
|
|
{
|
|
|
|
DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(
|
|
|
|
pBase->GetMainViewShell().get());
|
|
|
|
if (pDrawViewShell != NULL)
|
|
|
|
{
|
2011-01-17 11:41:00 +01:00
|
|
|
sal_uInt16 nPageNumber = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
|
2008-04-03 13:24:16 +00:00
|
|
|
pDrawViewShell->SwitchPage(nPageNumber);
|
|
|
|
pDrawViewShell->GetPageTabControl()->SetCurPageId(nPageNumber+1);
|
|
|
|
}
|
2010-07-22 11:12:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CurrentSlideManager::SetCurrentSlideAtTabControl (const SharedPageDescriptor& rpDescriptor)
|
|
|
|
{
|
|
|
|
OSL_ASSERT(rpDescriptor.get() != NULL);
|
|
|
|
|
|
|
|
ViewShellBase* pBase = mrSlideSorter.GetViewShellBase();
|
|
|
|
if (pBase != NULL)
|
|
|
|
{
|
|
|
|
::boost::shared_ptr<DrawViewShell> pDrawViewShell (
|
|
|
|
::boost::dynamic_pointer_cast<DrawViewShell>(pBase->GetMainViewShell()));
|
|
|
|
if (pDrawViewShell)
|
2008-04-03 13:24:16 +00:00
|
|
|
{
|
2011-01-17 11:41:00 +01:00
|
|
|
sal_uInt16 nPageNumber = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
|
2010-07-22 11:12:42 +02:00
|
|
|
pDrawViewShell->GetPageTabControl()->SetCurPageId(nPageNumber+1);
|
2008-04-03 13:24:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CurrentSlideManager::SetCurrentSlideAtXController (const SharedPageDescriptor& rpDescriptor)
|
|
|
|
{
|
|
|
|
OSL_ASSERT(rpDescriptor.get() != NULL);
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Reference<beans::XPropertySet> xSet (mrSlideSorter.GetXController(), UNO_QUERY);
|
|
|
|
if (xSet.is())
|
|
|
|
{
|
|
|
|
Any aPage;
|
|
|
|
aPage <<= rpDescriptor->GetPage()->getUnoPage();
|
|
|
|
xSet->setPropertyValue (
|
|
|
|
String::CreateFromAscii("CurrentPage"),
|
|
|
|
aPage);
|
|
|
|
}
|
|
|
|
}
|
2011-06-19 22:37:12 +01:00
|
|
|
catch (const Exception&)
|
2008-04-03 13:24:16 +00:00
|
|
|
{
|
|
|
|
// We have not been able to set the current page at the main view.
|
|
|
|
// This is sad but still leaves us in a valid state. Therefore,
|
|
|
|
// this exception is silently ignored.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SharedPageDescriptor CurrentSlideManager::GetCurrentSlide (void)
|
|
|
|
{
|
|
|
|
return mpCurrentSlide;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CurrentSlideManager::PrepareModelChange (void)
|
|
|
|
{
|
|
|
|
mpCurrentSlide.reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void CurrentSlideManager::HandleModelChange (void)
|
|
|
|
{
|
2008-05-20 13:12:00 +00:00
|
|
|
if (mnCurrentSlideIndex >= 0)
|
2008-04-03 13:24:16 +00:00
|
|
|
{
|
2010-01-27 11:41:30 +01:00
|
|
|
mpCurrentSlide = mrSlideSorter.GetModel().GetPageDescriptor(mnCurrentSlideIndex);
|
2008-05-20 13:12:00 +00:00
|
|
|
if (mpCurrentSlide.get() != NULL)
|
2010-01-27 11:41:30 +01:00
|
|
|
mrSlideSorter.GetView().SetState(mpCurrentSlide, PageDescriptor::ST_Current, true);
|
2008-04-03 13:24:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-06-21 15:59:22 +02:00
|
|
|
IMPL_LINK(CurrentSlideManager, SwitchPageCallback, void*, EMPTYARG)
|
|
|
|
{
|
|
|
|
if (mpCurrentSlide)
|
|
|
|
{
|
|
|
|
// Set current page. At the moment we have to do this in two
|
|
|
|
// different ways. The UNO way is the preferable one but, alas,
|
|
|
|
// it does not work always correctly (after some kinds of model
|
|
|
|
// changes). Therefore, we call DrawViewShell::SwitchPage(),
|
|
|
|
// too.
|
|
|
|
ViewShell* pViewShell = mrSlideSorter.GetViewShell();
|
|
|
|
if (pViewShell==NULL || ! pViewShell->IsMainViewShell())
|
|
|
|
SetCurrentSlideAtViewShellBase(mpCurrentSlide);
|
|
|
|
SetCurrentSlideAtXController(mpCurrentSlide);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2008-04-03 13:24:16 +00:00
|
|
|
} } } // end of namespace ::sd::slidesorter::controller
|
2010-10-12 15:51:52 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|