2004-07-13 13:13:32 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 21:02:51 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2004-07-13 13:13:32 +00:00
|
|
|
*
|
2008-04-10 21:02:51 +00:00
|
|
|
* Copyright 2008 by Sun Microsystems, Inc.
|
2004-07-13 13:13:32 +00:00
|
|
|
*
|
2008-04-10 21:02:51 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2004-07-13 13:13:32 +00:00
|
|
|
*
|
2008-04-10 21:02:51 +00:00
|
|
|
* $RCSfile: SlsFocusManager.cxx,v $
|
2008-07-02 10:53:34 +00:00
|
|
|
* $Revision: 1.14 $
|
2004-07-13 13:13:32 +00:00
|
|
|
*
|
2008-04-10 21:02:51 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2004-07-13 13:13:32 +00:00
|
|
|
*
|
2008-04-10 21:02:51 +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.
|
2004-07-13 13:13:32 +00:00
|
|
|
*
|
2008-04-10 21:02:51 +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).
|
2004-07-13 13:13:32 +00:00
|
|
|
*
|
2008-04-10 21:02:51 +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.
|
2004-07-13 13:13:32 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-16 18:05:39 +00:00
|
|
|
|
|
|
|
#include "precompiled_sd.hxx"
|
2004-07-13 13:13:32 +00:00
|
|
|
#include "controller/SlsFocusManager.hxx"
|
|
|
|
|
2008-04-03 13:24:35 +00:00
|
|
|
#include "SlideSorter.hxx"
|
2008-07-02 10:53:34 +00:00
|
|
|
#include "PaneDockingWindow.hxx"
|
2004-07-13 13:13:32 +00:00
|
|
|
#include "controller/SlideSorterController.hxx"
|
2008-04-03 13:24:35 +00:00
|
|
|
#include "controller/SlsSelectionManager.hxx"
|
2004-07-13 13:13:32 +00:00
|
|
|
#include "model/SlideSorterModel.hxx"
|
|
|
|
#include "model/SlsPageDescriptor.hxx"
|
|
|
|
#include "view/SlideSorterView.hxx"
|
|
|
|
#include "view/SlsLayouter.hxx"
|
2008-07-02 10:53:34 +00:00
|
|
|
#include <vcl/toolbox.hxx>
|
2004-07-13 13:13:32 +00:00
|
|
|
|
2005-01-25 14:34:22 +00:00
|
|
|
#include "Window.hxx"
|
|
|
|
#include "sdpage.hxx"
|
2004-07-13 13:13:32 +00:00
|
|
|
|
|
|
|
namespace sd { namespace slidesorter { namespace controller {
|
|
|
|
|
2008-04-03 13:24:35 +00:00
|
|
|
FocusManager::FocusManager (SlideSorter& rSlideSorter)
|
|
|
|
: mrSlideSorter(rSlideSorter),
|
2008-07-02 10:53:34 +00:00
|
|
|
mnPageIndex(0),
|
|
|
|
mbPageIsFocused(false)
|
2004-07-13 13:13:32 +00:00
|
|
|
{
|
2008-04-03 13:24:35 +00:00
|
|
|
if (mrSlideSorter.GetModel().GetPageCount() > 0)
|
2004-07-13 13:13:32 +00:00
|
|
|
mnPageIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FocusManager::~FocusManager (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FocusManager::MoveFocus (FocusMoveDirection eDirection)
|
|
|
|
{
|
|
|
|
if (mnPageIndex >= 0 && mbPageIsFocused)
|
|
|
|
{
|
|
|
|
HideFocusIndicator (GetFocusedPageDescriptor());
|
|
|
|
|
2008-04-03 13:24:35 +00:00
|
|
|
int nColumnCount (mrSlideSorter.GetView().GetLayouter().GetColumnCount());
|
2004-07-13 13:13:32 +00:00
|
|
|
switch (eDirection)
|
|
|
|
{
|
|
|
|
case FMD_NONE:
|
2008-04-03 13:24:35 +00:00
|
|
|
if (mnPageIndex >= mrSlideSorter.GetModel().GetPageCount())
|
|
|
|
mnPageIndex = mrSlideSorter.GetModel().GetPageCount() - 1;
|
2004-07-13 13:13:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FMD_LEFT:
|
|
|
|
mnPageIndex -= 1;
|
|
|
|
if (mnPageIndex < 0)
|
2008-07-02 10:53:34 +00:00
|
|
|
{
|
2008-04-03 13:24:35 +00:00
|
|
|
mnPageIndex = mrSlideSorter.GetModel().GetPageCount() - 1;
|
2008-07-02 10:53:34 +00:00
|
|
|
SetFocusToToolBox();
|
|
|
|
}
|
2004-07-13 13:13:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FMD_RIGHT:
|
|
|
|
mnPageIndex += 1;
|
2008-04-03 13:24:35 +00:00
|
|
|
if (mnPageIndex >= mrSlideSorter.GetModel().GetPageCount())
|
2008-07-02 10:53:34 +00:00
|
|
|
{
|
2004-07-13 13:13:32 +00:00
|
|
|
mnPageIndex = 0;
|
2008-07-02 10:53:34 +00:00
|
|
|
SetFocusToToolBox();
|
|
|
|
}
|
2004-07-13 13:13:32 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FMD_UP:
|
|
|
|
{
|
|
|
|
int nColumn = mnPageIndex % nColumnCount;
|
|
|
|
mnPageIndex -= nColumnCount;
|
|
|
|
if (mnPageIndex < 0)
|
|
|
|
{
|
|
|
|
// Wrap arround to the bottom row or the one above and
|
|
|
|
// go to the correct column.
|
2008-04-03 13:24:35 +00:00
|
|
|
int nCandidate = mrSlideSorter.GetModel().GetPageCount()-1;
|
2004-07-13 13:13:32 +00:00
|
|
|
int nCandidateColumn = nCandidate % nColumnCount;
|
|
|
|
if (nCandidateColumn > nColumn)
|
|
|
|
mnPageIndex = nCandidate - (nCandidateColumn-nColumn);
|
|
|
|
else if (nCandidateColumn < nColumn)
|
|
|
|
mnPageIndex = nCandidate
|
|
|
|
- nColumnCount
|
|
|
|
+ (nColumn - nCandidateColumn);
|
|
|
|
else
|
|
|
|
mnPageIndex = nCandidate;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FMD_DOWN:
|
|
|
|
{
|
|
|
|
int nColumn = mnPageIndex % nColumnCount;
|
|
|
|
mnPageIndex += nColumnCount;
|
2008-04-03 13:24:35 +00:00
|
|
|
if (mnPageIndex >= mrSlideSorter.GetModel().GetPageCount())
|
2004-07-13 13:13:32 +00:00
|
|
|
{
|
|
|
|
// Wrap arround to the correct column.
|
|
|
|
mnPageIndex = nColumn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-07-02 10:53:34 +00:00
|
|
|
if (mbPageIsFocused)
|
2009-11-20 12:42:09 +00:00
|
|
|
ShowFocusIndicator(GetFocusedPageDescriptor(), true);
|
2004-07-13 13:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-20 12:42:09 +00:00
|
|
|
void FocusManager::ShowFocus (const bool bScrollToFocus)
|
2004-07-13 13:13:32 +00:00
|
|
|
{
|
|
|
|
mbPageIsFocused = true;
|
2009-11-20 12:42:09 +00:00
|
|
|
ShowFocusIndicator(GetFocusedPageDescriptor(), bScrollToFocus);
|
2004-07-13 13:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FocusManager::HideFocus (void)
|
|
|
|
{
|
|
|
|
mbPageIsFocused = false;
|
2008-07-02 10:53:34 +00:00
|
|
|
HideFocusIndicator(GetFocusedPageDescriptor());
|
2004-07-13 13:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool FocusManager::ToggleFocus (void)
|
|
|
|
{
|
|
|
|
if (mnPageIndex >= 0)
|
|
|
|
{
|
|
|
|
if (mbPageIsFocused)
|
|
|
|
HideFocus ();
|
|
|
|
else
|
|
|
|
ShowFocus ();
|
|
|
|
}
|
|
|
|
return mbPageIsFocused;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool FocusManager::HasFocus (void) const
|
|
|
|
{
|
2008-04-03 13:24:35 +00:00
|
|
|
return mrSlideSorter.GetView().GetWindow()->HasFocus();
|
2004-07-13 13:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-06 15:19:17 +00:00
|
|
|
model::SharedPageDescriptor FocusManager::GetFocusedPageDescriptor (void) const
|
2004-07-13 13:13:32 +00:00
|
|
|
{
|
2008-04-03 13:24:35 +00:00
|
|
|
return mrSlideSorter.GetModel().GetPageDescriptor(mnPageIndex);
|
2004-07-13 13:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sal_Int32 FocusManager::GetFocusedPageIndex (void) const
|
|
|
|
{
|
|
|
|
return mnPageIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-01-13 16:28:15 +00:00
|
|
|
void FocusManager::FocusPage (sal_Int32 nPageIndex)
|
|
|
|
{
|
|
|
|
if (nPageIndex != mnPageIndex)
|
|
|
|
{
|
|
|
|
// Hide the focus while switching it to the specified page.
|
|
|
|
FocusHider aHider (*this);
|
|
|
|
mnPageIndex = nPageIndex;
|
|
|
|
}
|
2009-09-18 15:39:21 +00:00
|
|
|
|
|
|
|
if (HasFocus() && !IsFocusShowing())
|
|
|
|
ShowFocus();
|
2005-01-13 16:28:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-06 15:19:17 +00:00
|
|
|
void FocusManager::SetFocusedPage (const model::SharedPageDescriptor& rpDescriptor)
|
2005-01-25 14:34:22 +00:00
|
|
|
{
|
2006-04-06 15:19:17 +00:00
|
|
|
if (rpDescriptor.get() != NULL)
|
|
|
|
{
|
|
|
|
FocusHider aFocusHider (*this);
|
|
|
|
mnPageIndex = (rpDescriptor->GetPage()->GetPageNum()-1)/2;
|
|
|
|
}
|
2005-01-25 14:34:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FocusManager::SetFocusedPage (sal_Int32 nPageIndex)
|
|
|
|
{
|
|
|
|
FocusHider aFocusHider (*this);
|
|
|
|
mnPageIndex = nPageIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-07-13 13:13:32 +00:00
|
|
|
bool FocusManager::IsFocusShowing (void) const
|
|
|
|
{
|
|
|
|
return HasFocus() && mbPageIsFocused;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-04-06 15:19:17 +00:00
|
|
|
void FocusManager::HideFocusIndicator (const model::SharedPageDescriptor& rpDescriptor)
|
2004-07-13 13:13:32 +00:00
|
|
|
{
|
2006-04-06 15:19:17 +00:00
|
|
|
if (rpDescriptor.get() != NULL)
|
2005-01-25 14:34:22 +00:00
|
|
|
{
|
2006-04-06 15:19:17 +00:00
|
|
|
rpDescriptor->RemoveFocus();
|
2008-04-03 13:24:35 +00:00
|
|
|
mrSlideSorter.GetView().RequestRepaint(rpDescriptor);
|
2005-01-25 14:34:22 +00:00
|
|
|
}
|
2004-07-13 13:13:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-20 12:42:09 +00:00
|
|
|
void FocusManager::ShowFocusIndicator (
|
|
|
|
const model::SharedPageDescriptor& rpDescriptor,
|
|
|
|
const bool bScrollToFocus)
|
2004-07-13 13:13:32 +00:00
|
|
|
{
|
2006-04-06 15:19:17 +00:00
|
|
|
if (rpDescriptor.get() != NULL)
|
2004-07-13 13:13:32 +00:00
|
|
|
{
|
2006-04-06 15:19:17 +00:00
|
|
|
rpDescriptor->SetFocus ();
|
2004-07-13 13:13:32 +00:00
|
|
|
|
2009-11-20 12:42:09 +00:00
|
|
|
if (bScrollToFocus)
|
|
|
|
{
|
|
|
|
// Scroll the focused page object into the visible area and repaint
|
|
|
|
// it, so that the focus indicator becomes visible.
|
|
|
|
view::SlideSorterView& rView (mrSlideSorter.GetView());
|
|
|
|
mrSlideSorter.GetController().GetSelectionManager()->MakeRectangleVisible (
|
|
|
|
rView.GetPageBoundingBox (
|
|
|
|
GetFocusedPageDescriptor(),
|
|
|
|
view::SlideSorterView::CS_MODEL,
|
|
|
|
view::SlideSorterView::BBT_INFO));
|
|
|
|
}
|
2004-07-13 13:13:32 +00:00
|
|
|
|
2008-04-03 13:24:35 +00:00
|
|
|
mrSlideSorter.GetView().RequestRepaint (rpDescriptor);
|
2005-07-14 09:16:10 +00:00
|
|
|
NotifyFocusChangeListeners();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FocusManager::AddFocusChangeListener (const Link& rListener)
|
|
|
|
{
|
|
|
|
if (::std::find (maFocusChangeListeners.begin(), maFocusChangeListeners.end(), rListener)
|
|
|
|
== maFocusChangeListeners.end())
|
|
|
|
{
|
|
|
|
maFocusChangeListeners.push_back (rListener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void FocusManager::RemoveFocusChangeListener (const Link& rListener)
|
|
|
|
{
|
|
|
|
maFocusChangeListeners.erase (
|
|
|
|
::std::find (maFocusChangeListeners.begin(), maFocusChangeListeners.end(), rListener));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-07-02 10:53:34 +00:00
|
|
|
void FocusManager::SetFocusToToolBox (void)
|
|
|
|
{
|
|
|
|
HideFocus();
|
|
|
|
|
|
|
|
if (mrSlideSorter.GetViewShell() != NULL)
|
|
|
|
{
|
|
|
|
::Window* pParentWindow = mrSlideSorter.GetViewShell()->GetParentWindow();
|
|
|
|
DockingWindow* pDockingWindow = NULL;
|
|
|
|
while (pParentWindow!=NULL && pDockingWindow==NULL)
|
|
|
|
{
|
|
|
|
pDockingWindow = dynamic_cast<DockingWindow*>(pParentWindow);
|
|
|
|
pParentWindow = pParentWindow->GetParent();
|
|
|
|
}
|
|
|
|
if (pDockingWindow)
|
|
|
|
{
|
|
|
|
PaneDockingWindow* pPaneDockingWindow = dynamic_cast<PaneDockingWindow*>(pDockingWindow);
|
|
|
|
if (pPaneDockingWindow != NULL)
|
|
|
|
pPaneDockingWindow->GetTitleToolBox()->GrabFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-07-14 09:16:10 +00:00
|
|
|
void FocusManager::NotifyFocusChangeListeners (void) const
|
|
|
|
{
|
|
|
|
// Create a copy of the listener list to be safe when that is modified.
|
|
|
|
::std::vector<Link> aListeners (maFocusChangeListeners);
|
|
|
|
|
|
|
|
// Tell the slection change listeners that the selection has changed.
|
|
|
|
::std::vector<Link>::iterator iListener (aListeners.begin());
|
|
|
|
::std::vector<Link>::iterator iEnd (aListeners.end());
|
|
|
|
for (; iListener!=iEnd; ++iListener)
|
|
|
|
{
|
|
|
|
iListener->Call(NULL);
|
2004-07-13 13:13:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FocusManager::FocusHider::FocusHider (FocusManager& rManager)
|
2006-12-12 17:24:16 +00:00
|
|
|
: mbFocusVisible(rManager.IsFocusShowing())
|
|
|
|
, mrManager(rManager)
|
2004-07-13 13:13:32 +00:00
|
|
|
{
|
|
|
|
mrManager.HideFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FocusManager::FocusHider::~FocusHider (void)
|
|
|
|
{
|
|
|
|
if (mbFocusVisible)
|
|
|
|
mrManager.ShowFocus();
|
|
|
|
}
|
|
|
|
|
|
|
|
} } } // end of namespace ::sd::slidesorter::controller
|
|
|
|
|