2010-10-12 15:51:52 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-11-27 16:10:40 +00:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
2004-07-13 13:15:32 +00:00
|
|
|
*
|
2012-11-27 16:10:40 +00:00
|
|
|
* 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/.
|
2004-07-13 13:15:32 +00:00
|
|
|
*
|
2012-11-27 16:10:40 +00:00
|
|
|
* This file incorporates work covered by the following license notice:
|
2004-07-13 13:15:32 +00:00
|
|
|
*
|
2012-11-27 16:10:40 +00:00
|
|
|
* 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 .
|
|
|
|
*/
|
2004-07-13 13:15:32 +00:00
|
|
|
|
2006-09-16 18:06:57 +00:00
|
|
|
|
2004-07-13 13:15:32 +00:00
|
|
|
#include "controller/SlsScrollBarManager.hxx"
|
|
|
|
|
2008-04-03 13:27:45 +00:00
|
|
|
#include "SlideSorter.hxx"
|
2004-07-13 13:15:32 +00:00
|
|
|
#include "controller/SlideSorterController.hxx"
|
2010-04-23 17:06:10 +02:00
|
|
|
#include "controller/SlsVisibleAreaManager.hxx"
|
2004-07-13 13:15:32 +00:00
|
|
|
#include "model/SlideSorterModel.hxx"
|
|
|
|
#include "model/SlsPageDescriptor.hxx"
|
|
|
|
#include "view/SlideSorterView.hxx"
|
|
|
|
#include "view/SlsLayouter.hxx"
|
2010-03-02 15:54:17 +01:00
|
|
|
#include "view/SlsTheme.hxx"
|
2004-07-13 13:15:32 +00:00
|
|
|
#include "Window.hxx"
|
|
|
|
#include "sdpage.hxx"
|
|
|
|
|
2005-04-12 15:56:56 +00:00
|
|
|
#include <boost/limits.hpp>
|
2004-07-13 13:15:32 +00:00
|
|
|
|
|
|
|
#include <vcl/scrbar.hxx>
|
|
|
|
|
|
|
|
namespace sd { namespace slidesorter { namespace controller {
|
|
|
|
|
2008-04-03 13:27:45 +00:00
|
|
|
ScrollBarManager::ScrollBarManager (SlideSorter& rSlideSorter)
|
|
|
|
: mrSlideSorter(rSlideSorter),
|
|
|
|
mpHorizontalScrollBar(mrSlideSorter.GetHorizontalScrollBar()),
|
|
|
|
mpVerticalScrollBar(mrSlideSorter.GetVerticalScrollBar()),
|
2004-07-13 13:15:32 +00:00
|
|
|
mnHorizontalPosition (0),
|
|
|
|
mnVerticalPosition (0),
|
2010-01-27 11:41:30 +01:00
|
|
|
maScrollBorder (20,20),
|
2010-03-11 16:21:09 +01:00
|
|
|
mnHorizontalScrollFactor (0.15),
|
|
|
|
mnVerticalScrollFactor (0.25),
|
2008-04-03 13:27:45 +00:00
|
|
|
mpScrollBarFiller(mrSlideSorter.GetScrollBarFiller()),
|
2010-01-28 13:00:30 +01:00
|
|
|
maAutoScrollTimer(),
|
|
|
|
maAutoScrollOffset(0,0),
|
2010-01-27 11:41:30 +01:00
|
|
|
mbIsAutoScrollActive(false),
|
2010-01-28 13:00:30 +01:00
|
|
|
mpContentWindow(mrSlideSorter.GetContentWindow()),
|
2010-01-27 11:41:30 +01:00
|
|
|
maAutoScrollFunctor()
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
2005-07-07 12:36:05 +00:00
|
|
|
// Hide the scroll bars by default to prevent display errors while
|
|
|
|
// switching between view shells: In the short time between initiating
|
|
|
|
// such a switch and the final rearrangement of UI controls the scroll
|
|
|
|
// bars and the filler where displayed in the upper left corner of the
|
|
|
|
// ViewTabBar.
|
|
|
|
mpHorizontalScrollBar->Hide();
|
|
|
|
mpVerticalScrollBar->Hide();
|
|
|
|
mpScrollBarFiller->Hide();
|
|
|
|
|
2010-01-27 11:41:30 +01:00
|
|
|
maAutoScrollTimer.SetTimeout(25);
|
2004-07-13 13:15:32 +00:00
|
|
|
maAutoScrollTimer.SetTimeoutHdl (
|
|
|
|
LINK(this, ScrollBarManager, AutoScrollTimeoutHandler));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ScrollBarManager::~ScrollBarManager (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ScrollBarManager::LateInitialization (void)
|
2007-08-17 13:26:47 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ScrollBarManager::Connect (void)
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
2013-05-22 20:16:28 +03:00
|
|
|
if (mpVerticalScrollBar != 0)
|
2010-06-21 15:59:22 +02:00
|
|
|
{
|
2004-07-13 13:15:32 +00:00
|
|
|
mpVerticalScrollBar->SetScrollHdl (
|
2010-06-21 15:59:22 +02:00
|
|
|
LINK(this, ScrollBarManager, VerticalScrollBarHandler));
|
|
|
|
}
|
2013-05-22 20:16:28 +03:00
|
|
|
if (mpHorizontalScrollBar != 0)
|
2010-06-21 15:59:22 +02:00
|
|
|
{
|
|
|
|
mpHorizontalScrollBar->SetScrollHdl(
|
|
|
|
LINK(this, ScrollBarManager, HorizontalScrollBarHandler));
|
|
|
|
}
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-08-17 13:26:47 +00:00
|
|
|
void ScrollBarManager::Disconnect (void)
|
|
|
|
{
|
2013-05-22 20:16:28 +03:00
|
|
|
if (mpVerticalScrollBar != 0)
|
2010-06-21 15:59:22 +02:00
|
|
|
{
|
2007-08-17 13:26:47 +00:00
|
|
|
mpVerticalScrollBar->SetScrollHdl (Link());
|
2010-06-21 15:59:22 +02:00
|
|
|
}
|
2013-05-22 20:16:28 +03:00
|
|
|
if (mpHorizontalScrollBar != 0)
|
2010-06-21 15:59:22 +02:00
|
|
|
{
|
2007-08-17 13:26:47 +00:00
|
|
|
mpHorizontalScrollBar->SetScrollHdl (Link());
|
2010-06-21 15:59:22 +02:00
|
|
|
}
|
2007-08-17 13:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-07-13 13:15:32 +00:00
|
|
|
/** Placing the scroll bars is an iterative process. The visibility of one
|
|
|
|
scroll bar affects the remaining size and thus may lead to the other
|
|
|
|
scroll bar becoming visible.
|
|
|
|
|
|
|
|
First we determine the visibility of the horizontal scroll bar. After
|
|
|
|
that we do the same for the vertical scroll bar. To have an initial
|
|
|
|
value for the required size we call the layouter before that. When one
|
|
|
|
of the two scroll bars is made visible then the size of the browser
|
|
|
|
window changes and a second call to the layouter becomes necessary.
|
|
|
|
That call is made anyway after this method returns.
|
|
|
|
*/
|
2010-03-19 15:06:39 +01:00
|
|
|
Rectangle ScrollBarManager::PlaceScrollBars (
|
|
|
|
const Rectangle& rAvailableArea,
|
|
|
|
const bool bIsHorizontalScrollBarAllowed,
|
|
|
|
const bool bIsVerticalScrollBarAllowed)
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
2010-03-19 15:06:39 +01:00
|
|
|
Rectangle aRemainingSpace (DetermineScrollBarVisibilities(
|
|
|
|
rAvailableArea,
|
|
|
|
bIsHorizontalScrollBarAllowed,
|
|
|
|
bIsVerticalScrollBarAllowed));
|
|
|
|
|
2013-05-22 20:16:28 +03:00
|
|
|
if (mpHorizontalScrollBar!=0 && mpHorizontalScrollBar->IsVisible())
|
2010-03-19 15:06:39 +01:00
|
|
|
PlaceHorizontalScrollBar (rAvailableArea);
|
|
|
|
|
2013-05-22 20:16:28 +03:00
|
|
|
if (mpVerticalScrollBar!=0 && mpVerticalScrollBar->IsVisible())
|
2010-03-19 15:06:39 +01:00
|
|
|
PlaceVerticalScrollBar (rAvailableArea);
|
|
|
|
|
2013-05-22 20:16:28 +03:00
|
|
|
if (mpScrollBarFiller!=0 && mpScrollBarFiller->IsVisible())
|
2010-03-19 15:06:39 +01:00
|
|
|
PlaceFiller (rAvailableArea);
|
2004-07-13 13:15:32 +00:00
|
|
|
|
2005-03-18 15:51:37 +00:00
|
|
|
return aRemainingSpace;
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-03-18 15:51:37 +00:00
|
|
|
void ScrollBarManager::PlaceHorizontalScrollBar (const Rectangle& aAvailableArea)
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
2010-03-19 15:06:39 +01:00
|
|
|
// Save the current relative position.
|
|
|
|
mnHorizontalPosition = double(mpHorizontalScrollBar->GetThumbPos())
|
|
|
|
/ double(mpHorizontalScrollBar->GetRange().Len());
|
|
|
|
|
|
|
|
// Place the scroll bar.
|
|
|
|
Size aScrollBarSize (mpHorizontalScrollBar->GetSizePixel());
|
|
|
|
mpHorizontalScrollBar->SetPosSizePixel (
|
|
|
|
Point(aAvailableArea.Left(),
|
|
|
|
aAvailableArea.Bottom()-aScrollBarSize.Height()+1),
|
|
|
|
Size (aAvailableArea.GetWidth() - GetVerticalScrollBarWidth(),
|
|
|
|
aScrollBarSize.Height()));
|
|
|
|
|
|
|
|
// Restore the relative position.
|
|
|
|
mpHorizontalScrollBar->SetThumbPos(
|
|
|
|
(long)(0.5 + mnHorizontalPosition * mpHorizontalScrollBar->GetRange().Len()));
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-03-18 15:51:37 +00:00
|
|
|
void ScrollBarManager::PlaceVerticalScrollBar (const Rectangle& aArea)
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
2012-11-27 16:10:40 +00:00
|
|
|
const sal_Int32 nThumbPosition (mpVerticalScrollBar->GetThumbPos());
|
2005-03-18 15:51:37 +00:00
|
|
|
|
2010-03-19 15:06:39 +01:00
|
|
|
// Place the scroll bar.
|
|
|
|
Size aScrollBarSize (mpVerticalScrollBar->GetSizePixel());
|
|
|
|
Point aPosition (aArea.Right()-aScrollBarSize.Width()+1, aArea.Top());
|
|
|
|
Size aSize (aScrollBarSize.Width(), aArea.GetHeight() - GetHorizontalScrollBarHeight());
|
|
|
|
mpVerticalScrollBar->SetPosSizePixel(aPosition, aSize);
|
2005-03-18 15:51:37 +00:00
|
|
|
|
2010-03-19 15:06:39 +01:00
|
|
|
// Restore the position.
|
2011-05-16 23:22:50 +02:00
|
|
|
mpVerticalScrollBar->SetThumbPos(static_cast<long>(nThumbPosition));
|
2010-03-19 15:06:39 +01:00
|
|
|
mnVerticalPosition = nThumbPosition / double(mpVerticalScrollBar->GetRange().Len());
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-03-18 15:51:37 +00:00
|
|
|
void ScrollBarManager::PlaceFiller (const Rectangle& aArea)
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
2010-03-19 15:06:39 +01:00
|
|
|
mpScrollBarFiller->SetPosSizePixel(
|
|
|
|
Point(
|
|
|
|
aArea.Right()-mpVerticalScrollBar->GetSizePixel().Width()+1,
|
|
|
|
aArea.Bottom()-mpHorizontalScrollBar->GetSizePixel().Height()+1),
|
|
|
|
Size (
|
|
|
|
mpVerticalScrollBar->GetSizePixel().Width(),
|
|
|
|
mpHorizontalScrollBar->GetSizePixel().Height()));
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-04-12 15:56:56 +00:00
|
|
|
void ScrollBarManager::UpdateScrollBars (bool bResetThumbPosition, bool bUseScrolling)
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
2008-04-03 13:27:45 +00:00
|
|
|
Rectangle aModelArea (mrSlideSorter.GetView().GetModelArea());
|
2010-02-12 13:58:24 +01:00
|
|
|
SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
|
2004-07-13 13:15:32 +00:00
|
|
|
Size aWindowModelSize (pWindow->PixelToLogic(pWindow->GetSizePixel()));
|
|
|
|
|
|
|
|
// The horizontal scroll bar is only shown when the window is
|
|
|
|
// horizontally smaller than the view.
|
2013-05-22 20:16:28 +03:00
|
|
|
if (mpHorizontalScrollBar != 0 && mpHorizontalScrollBar->IsVisible())
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
|
|
|
mpHorizontalScrollBar->Show();
|
|
|
|
mpHorizontalScrollBar->SetRange (
|
|
|
|
Range(aModelArea.Left(), aModelArea.Right()));
|
|
|
|
if (bResetThumbPosition)
|
|
|
|
{
|
|
|
|
mpHorizontalScrollBar->SetThumbPos (0);
|
|
|
|
mnHorizontalPosition = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mnHorizontalPosition =
|
|
|
|
double(mpHorizontalScrollBar->GetThumbPos())
|
|
|
|
/ double(mpHorizontalScrollBar->GetRange().Len());
|
|
|
|
|
|
|
|
mpHorizontalScrollBar->SetVisibleSize (aWindowModelSize.Width());
|
|
|
|
|
2006-12-12 15:08:19 +00:00
|
|
|
const long nWidth (mpContentWindow->PixelToLogic(
|
|
|
|
mpContentWindow->GetSizePixel()).Width());
|
|
|
|
// Make the line size about 10% of the visible width.
|
|
|
|
mpHorizontalScrollBar->SetLineSize (nWidth / 10);
|
2004-07-13 13:15:32 +00:00
|
|
|
// Make the page size about 90% of the visible width.
|
2006-12-12 15:08:19 +00:00
|
|
|
mpHorizontalScrollBar->SetPageSize ((nWidth * 9) / 10);
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
2005-04-12 15:56:56 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
mnHorizontalPosition = 0;
|
|
|
|
}
|
2004-07-13 13:15:32 +00:00
|
|
|
|
|
|
|
// The vertical scroll bar is always shown.
|
2013-05-22 20:16:28 +03:00
|
|
|
if (mpVerticalScrollBar != 0 && mpVerticalScrollBar->IsVisible())
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
|
|
|
mpVerticalScrollBar->SetRange (
|
|
|
|
Range(aModelArea.Top(), aModelArea.Bottom()));
|
|
|
|
if (bResetThumbPosition)
|
|
|
|
{
|
|
|
|
mpVerticalScrollBar->SetThumbPos (0);
|
|
|
|
mnVerticalPosition = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
mnVerticalPosition =
|
|
|
|
double(mpVerticalScrollBar->GetThumbPos())
|
|
|
|
/ double(mpVerticalScrollBar->GetRange().Len());
|
|
|
|
|
|
|
|
mpVerticalScrollBar->SetVisibleSize (aWindowModelSize.Height());
|
|
|
|
|
2006-12-12 15:08:19 +00:00
|
|
|
const long nHeight (mpContentWindow->PixelToLogic(
|
|
|
|
mpContentWindow->GetSizePixel()).Height());
|
|
|
|
// Make the line size about 10% of the visible height.
|
|
|
|
mpVerticalScrollBar->SetLineSize (nHeight / 10);
|
2004-07-13 13:15:32 +00:00
|
|
|
// Make the page size about 90% of the visible height.
|
2006-12-12 15:08:19 +00:00
|
|
|
mpVerticalScrollBar->SetPageSize ((nHeight * 9) / 10);
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
2005-04-12 15:56:56 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
mnVerticalPosition = 0;
|
|
|
|
}
|
|
|
|
|
2004-07-13 13:15:32 +00:00
|
|
|
|
2005-04-12 15:56:56 +00:00
|
|
|
double nEps (::std::numeric_limits<double>::epsilon());
|
|
|
|
if (fabs(mnHorizontalPosition-pWindow->GetVisibleX()) > nEps
|
|
|
|
|| fabs(mnVerticalPosition-pWindow->GetVisibleY()) > nEps)
|
2005-03-18 15:51:37 +00:00
|
|
|
{
|
2008-04-03 13:27:45 +00:00
|
|
|
mrSlideSorter.GetView().InvalidatePageObjectVisibilities();
|
2005-04-12 15:56:56 +00:00
|
|
|
if (bUseScrolling)
|
|
|
|
pWindow->SetVisibleXY(mnHorizontalPosition, mnVerticalPosition);
|
|
|
|
else
|
|
|
|
SetWindowOrigin(mnHorizontalPosition, mnVerticalPosition);
|
2005-03-18 15:51:37 +00:00
|
|
|
}
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IMPL_LINK(ScrollBarManager, VerticalScrollBarHandler, ScrollBar*, pScrollBar)
|
|
|
|
{
|
2005-04-12 15:56:56 +00:00
|
|
|
if (pScrollBar!=NULL
|
2008-04-03 13:27:45 +00:00
|
|
|
&& pScrollBar==mpVerticalScrollBar.get()
|
2005-04-12 15:56:56 +00:00
|
|
|
&& pScrollBar->IsVisible()
|
2013-05-22 20:16:28 +03:00
|
|
|
&& mrSlideSorter.GetContentWindow()!=0)
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
|
|
|
double nRelativePosition = double(pScrollBar->GetThumbPos())
|
|
|
|
/ double(pScrollBar->GetRange().Len());
|
2008-04-03 13:27:45 +00:00
|
|
|
mrSlideSorter.GetView().InvalidatePageObjectVisibilities();
|
2010-06-21 15:59:22 +02:00
|
|
|
mrSlideSorter.GetContentWindow()->SetVisibleXY(-1, nRelativePosition);
|
2010-04-23 17:06:10 +02:00
|
|
|
mrSlideSorter.GetController().GetVisibleAreaManager().DeactivateCurrentSlideTracking();
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
2011-01-17 11:41:00 +01:00
|
|
|
return sal_True;
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IMPL_LINK(ScrollBarManager, HorizontalScrollBarHandler, ScrollBar*, pScrollBar)
|
|
|
|
{
|
2005-04-12 15:56:56 +00:00
|
|
|
if (pScrollBar!=NULL
|
2008-04-03 13:27:45 +00:00
|
|
|
&& pScrollBar==mpHorizontalScrollBar.get()
|
2005-04-12 15:56:56 +00:00
|
|
|
&& pScrollBar->IsVisible()
|
2013-05-22 20:16:28 +03:00
|
|
|
&& mrSlideSorter.GetContentWindow()!=0)
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
|
|
|
double nRelativePosition = double(pScrollBar->GetThumbPos())
|
|
|
|
/ double(pScrollBar->GetRange().Len());
|
2008-04-03 13:27:45 +00:00
|
|
|
mrSlideSorter.GetView().InvalidatePageObjectVisibilities();
|
2010-06-21 15:59:22 +02:00
|
|
|
mrSlideSorter.GetContentWindow()->SetVisibleXY(nRelativePosition, -1);
|
2010-05-20 13:41:11 +02:00
|
|
|
mrSlideSorter.GetController().GetVisibleAreaManager().DeactivateCurrentSlideTracking();
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
2011-01-17 11:41:00 +01:00
|
|
|
return sal_True;
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ScrollBarManager::SetWindowOrigin (
|
|
|
|
double nHorizontalPosition,
|
|
|
|
double nVerticalPosition)
|
|
|
|
{
|
|
|
|
mnHorizontalPosition = nHorizontalPosition;
|
|
|
|
mnVerticalPosition = nVerticalPosition;
|
|
|
|
|
2010-02-12 13:58:24 +01:00
|
|
|
SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
|
2004-07-13 13:15:32 +00:00
|
|
|
Size aViewSize (pWindow->GetViewSize());
|
|
|
|
Point aOrigin (
|
|
|
|
(long int) (mnHorizontalPosition * aViewSize.Width()),
|
|
|
|
(long int) (mnVerticalPosition * aViewSize.Height()));
|
|
|
|
|
|
|
|
pWindow->SetWinViewPos (aOrigin);
|
|
|
|
pWindow->UpdateMapMode ();
|
|
|
|
pWindow->Invalidate ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-03-18 15:51:37 +00:00
|
|
|
/** Determining the visibility of the scroll bars is quite complicated. The
|
|
|
|
visibility of one influences that of the other because showing a scroll
|
|
|
|
bar makes the available space smaller and may lead to the need of
|
|
|
|
displaying the other.
|
|
|
|
To solve this we test all four combinations of showing or hiding each
|
|
|
|
scroll bar and use the best one. The best one is that combination that
|
|
|
|
a) shows the least number of scroll bars with preference of showing the
|
|
|
|
vertical over showing the horizontal and
|
|
|
|
b) when not showing a scroll bar the area used by the page objects fits
|
|
|
|
into the available area in the scroll bars orientation.
|
|
|
|
*/
|
2010-03-19 15:06:39 +01:00
|
|
|
Rectangle ScrollBarManager::DetermineScrollBarVisibilities (
|
|
|
|
const Rectangle& rAvailableArea,
|
|
|
|
const bool bIsHorizontalScrollBarAllowed,
|
|
|
|
const bool bIsVerticalScrollBarAllowed)
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
2005-03-18 15:51:37 +00:00
|
|
|
// Test which combination of scroll bars is the best.
|
|
|
|
bool bShowHorizontal = false;
|
|
|
|
bool bShowVertical = false;
|
2010-05-31 17:48:57 +02:00
|
|
|
if (mrSlideSorter.GetModel().GetPageCount() == 0)
|
2005-03-18 15:51:37 +00:00
|
|
|
{
|
2010-05-31 17:48:57 +02:00
|
|
|
// No pages => no scroll bars.
|
|
|
|
}
|
|
|
|
else if (TestScrollBarVisibilities(false, false, rAvailableArea))
|
|
|
|
{
|
|
|
|
// Nothing to be done.
|
|
|
|
}
|
|
|
|
else if (bIsHorizontalScrollBarAllowed
|
|
|
|
&& TestScrollBarVisibilities(true, false, rAvailableArea))
|
|
|
|
{
|
|
|
|
bShowHorizontal = true;
|
|
|
|
}
|
|
|
|
else if (bIsVerticalScrollBarAllowed
|
|
|
|
&& TestScrollBarVisibilities(false, true, rAvailableArea))
|
|
|
|
{
|
|
|
|
bShowVertical = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bShowHorizontal = true;
|
|
|
|
bShowVertical = true;
|
2005-03-18 15:51:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make the visibility of the scroll bars permanent.
|
|
|
|
mpVerticalScrollBar->Show(bShowVertical);
|
|
|
|
mpHorizontalScrollBar->Show(bShowHorizontal);
|
2010-03-19 15:06:39 +01:00
|
|
|
mpScrollBarFiller->Show(bShowVertical && bShowHorizontal);
|
2005-03-18 15:51:37 +00:00
|
|
|
|
|
|
|
// Adapt the remaining space accordingly.
|
|
|
|
Rectangle aRemainingSpace (rAvailableArea);
|
|
|
|
if (bShowVertical)
|
|
|
|
aRemainingSpace.Right() -= mpVerticalScrollBar->GetSizePixel().Width();
|
|
|
|
if (bShowHorizontal)
|
|
|
|
aRemainingSpace.Bottom() -= mpHorizontalScrollBar->GetSizePixel().Height();
|
|
|
|
|
|
|
|
return aRemainingSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ScrollBarManager::TestScrollBarVisibilities (
|
|
|
|
bool bHorizontalScrollBarVisible,
|
|
|
|
bool bVerticalScrollBarVisible,
|
|
|
|
const Rectangle& rAvailableArea)
|
|
|
|
{
|
2010-01-27 11:41:30 +01:00
|
|
|
model::SlideSorterModel& rModel (mrSlideSorter.GetModel());
|
2005-03-18 15:51:37 +00:00
|
|
|
|
|
|
|
// Adapt the available size by subtracting the sizes of the scroll bars
|
|
|
|
// visible in this combination.
|
|
|
|
Size aBrowserSize (rAvailableArea.GetSize());
|
|
|
|
if (bHorizontalScrollBarVisible)
|
|
|
|
aBrowserSize.Height() -= mpHorizontalScrollBar->GetSizePixel().Height();
|
|
|
|
if (bVerticalScrollBarVisible)
|
|
|
|
aBrowserSize.Width() -= mpVerticalScrollBar->GetSizePixel().Width();
|
|
|
|
|
|
|
|
// Tell the view to rearrange its page objects and check whether the
|
|
|
|
// page objects can be shown without clipping.
|
2010-03-19 15:06:39 +01:00
|
|
|
bool bRearrangeSuccess (mrSlideSorter.GetView().GetLayouter().Rearrange (
|
|
|
|
mrSlideSorter.GetView().GetOrientation(),
|
|
|
|
aBrowserSize,
|
|
|
|
rModel.GetPageDescriptor(0)->GetPage()->GetSize(),
|
|
|
|
rModel.GetPageCount()));
|
2008-04-03 13:27:45 +00:00
|
|
|
|
|
|
|
if (bRearrangeSuccess)
|
|
|
|
{
|
2010-03-19 15:06:39 +01:00
|
|
|
Size aPageSize = mrSlideSorter.GetView().GetLayouter().GetTotalBoundingBox().GetSize();
|
2005-03-18 15:51:37 +00:00
|
|
|
Size aWindowModelSize = mpContentWindow->PixelToLogic(aBrowserSize);
|
|
|
|
|
2010-05-31 17:48:57 +02:00
|
|
|
// The content may be clipped, i.e. not fully visible, in one
|
|
|
|
// direction only when the scroll bar is visible in that direction.
|
|
|
|
if (aPageSize.Width() > aWindowModelSize.Width())
|
|
|
|
if ( ! bHorizontalScrollBarVisible)
|
|
|
|
return false;
|
|
|
|
if (aPageSize.Height() > aWindowModelSize.Height())
|
|
|
|
if ( ! bVerticalScrollBarVisible)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
2005-03-18 15:51:37 +00:00
|
|
|
}
|
|
|
|
else
|
2010-05-31 17:48:57 +02:00
|
|
|
return false;
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-03-10 18:36:15 +01:00
|
|
|
void ScrollBarManager::SetTopLeft (const Point aNewTopLeft)
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
2010-05-21 16:36:05 +02:00
|
|
|
if (( ! mpVerticalScrollBar
|
2010-03-10 18:36:15 +01:00
|
|
|
|| mpVerticalScrollBar->GetThumbPos() == aNewTopLeft.Y())
|
2010-05-21 16:36:05 +02:00
|
|
|
&& ( ! mpHorizontalScrollBar
|
2010-03-10 18:36:15 +01:00
|
|
|
|| mpHorizontalScrollBar->GetThumbPos() == aNewTopLeft.X()))
|
|
|
|
return;
|
2008-04-03 13:27:45 +00:00
|
|
|
|
2010-03-10 18:36:15 +01:00
|
|
|
// Flush pending repaints before scrolling to avoid temporary artifacts.
|
|
|
|
mrSlideSorter.GetContentWindow()->Update();
|
2008-04-03 13:27:45 +00:00
|
|
|
|
2010-05-21 16:36:05 +02:00
|
|
|
if (mpVerticalScrollBar)
|
2010-03-10 18:36:15 +01:00
|
|
|
{
|
|
|
|
mpVerticalScrollBar->SetThumbPos(aNewTopLeft.Y());
|
|
|
|
mnVerticalPosition = aNewTopLeft.Y() / double(mpVerticalScrollBar->GetRange().Len());
|
2008-04-03 13:27:45 +00:00
|
|
|
}
|
2010-05-21 16:36:05 +02:00
|
|
|
if (mpHorizontalScrollBar)
|
2010-03-10 18:36:15 +01:00
|
|
|
{
|
|
|
|
mpHorizontalScrollBar->SetThumbPos(aNewTopLeft.X());
|
|
|
|
mnHorizontalPosition = aNewTopLeft.X() / double(mpHorizontalScrollBar->GetRange().Len());
|
2008-04-03 13:27:45 +00:00
|
|
|
}
|
2010-03-10 18:36:15 +01:00
|
|
|
|
2010-06-21 15:59:22 +02:00
|
|
|
mrSlideSorter.GetContentWindow()->SetVisibleXY(mnHorizontalPosition, mnVerticalPosition);
|
2010-03-10 18:36:15 +01:00
|
|
|
mrSlideSorter.GetView().InvalidatePageObjectVisibilities();
|
2008-04-03 13:27:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-07-13 13:15:32 +00:00
|
|
|
int ScrollBarManager::GetVerticalScrollBarWidth (void) const
|
|
|
|
{
|
2013-05-22 20:16:28 +03:00
|
|
|
if (mpVerticalScrollBar != 0 && mpVerticalScrollBar->IsVisible())
|
2004-07-13 13:15:32 +00:00
|
|
|
return mpVerticalScrollBar->GetSizePixel().Width();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-03-18 15:51:37 +00:00
|
|
|
int ScrollBarManager::GetHorizontalScrollBarHeight (void) const
|
|
|
|
{
|
2013-05-22 20:16:28 +03:00
|
|
|
if (mpHorizontalScrollBar != 0 && mpHorizontalScrollBar->IsVisible())
|
2005-03-18 15:51:37 +00:00
|
|
|
return mpHorizontalScrollBar->GetSizePixel().Height();
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-07-13 13:15:32 +00:00
|
|
|
void ScrollBarManager::CalcAutoScrollOffset (const Point& rMouseWindowPosition)
|
|
|
|
{
|
2010-02-12 13:58:24 +01:00
|
|
|
SharedSdWindow pWindow (mrSlideSorter.GetContentWindow());
|
2004-07-13 13:15:32 +00:00
|
|
|
|
|
|
|
int nDx = 0;
|
|
|
|
int nDy = 0;
|
|
|
|
|
|
|
|
Size aWindowSize = pWindow->GetOutputSizePixel();
|
2005-04-12 15:56:56 +00:00
|
|
|
Rectangle aWindowArea (pWindow->GetPosPixel(), aWindowSize);
|
2004-07-13 13:15:32 +00:00
|
|
|
Rectangle aViewPixelArea (
|
2008-04-03 13:27:45 +00:00
|
|
|
pWindow->LogicToPixel(mrSlideSorter.GetView().GetModelArea()));
|
2004-07-13 13:15:32 +00:00
|
|
|
|
|
|
|
if (aWindowSize.Width() > maScrollBorder.Width() * 3
|
2013-05-22 20:16:28 +03:00
|
|
|
&& mpHorizontalScrollBar != 0
|
2004-07-13 13:15:32 +00:00
|
|
|
&& mpHorizontalScrollBar->IsVisible())
|
|
|
|
{
|
2005-04-12 15:56:56 +00:00
|
|
|
if (rMouseWindowPosition.X() < maScrollBorder.Width()
|
|
|
|
&& aWindowArea.Left() > aViewPixelArea.Left())
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
|
|
|
nDx = -1 + (int)(mnHorizontalScrollFactor
|
|
|
|
* (rMouseWindowPosition.X() - maScrollBorder.Width()));
|
|
|
|
}
|
|
|
|
|
2005-04-12 15:56:56 +00:00
|
|
|
if (rMouseWindowPosition.X() >= (aWindowSize.Width() - maScrollBorder.Width())
|
|
|
|
&& aWindowArea.Right() < aViewPixelArea.Right())
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
|
|
|
nDx = 1 + (int)(mnHorizontalScrollFactor
|
|
|
|
* (rMouseWindowPosition.X() - aWindowSize.Width()
|
|
|
|
+ maScrollBorder.Width()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aWindowSize.Height() > maScrollBorder.Height() * 3
|
|
|
|
&& aWindowSize.Height() < aViewPixelArea.GetHeight())
|
|
|
|
{
|
2005-04-12 15:56:56 +00:00
|
|
|
if (rMouseWindowPosition.Y() < maScrollBorder.Height()
|
|
|
|
&& aWindowArea.Top() > aViewPixelArea.Top())
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
|
|
|
nDy = -1 + (int)(mnVerticalScrollFactor
|
|
|
|
* (rMouseWindowPosition.Y() - maScrollBorder.Height()));
|
|
|
|
}
|
|
|
|
|
2005-04-12 15:56:56 +00:00
|
|
|
if (rMouseWindowPosition.Y() >= (aWindowSize.Height() - maScrollBorder.Height())
|
|
|
|
&& aWindowArea.Bottom() < aViewPixelArea.Bottom())
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
|
|
|
nDy = 1 + (int)(mnVerticalScrollFactor
|
|
|
|
* (rMouseWindowPosition.Y() - aWindowSize.Height()
|
|
|
|
+ maScrollBorder.Height()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
maAutoScrollOffset = Size(nDx,nDy);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-01-27 11:41:30 +01:00
|
|
|
bool ScrollBarManager::AutoScroll (
|
|
|
|
const Point& rMouseWindowPosition,
|
|
|
|
const ::boost::function<void(void)>& rAutoScrollFunctor)
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
2010-01-27 11:41:30 +01:00
|
|
|
maAutoScrollFunctor = rAutoScrollFunctor;
|
|
|
|
CalcAutoScrollOffset(rMouseWindowPosition);
|
|
|
|
bool bResult (true);
|
|
|
|
if ( ! mbIsAutoScrollActive)
|
|
|
|
bResult = RepeatAutoScroll();
|
|
|
|
|
2004-07-13 13:15:32 +00:00
|
|
|
return bResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void ScrollBarManager::StopAutoScroll (void)
|
|
|
|
{
|
|
|
|
maAutoScrollTimer.Stop();
|
2010-01-27 11:41:30 +01:00
|
|
|
mbIsAutoScrollActive = false;
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ScrollBarManager::RepeatAutoScroll (void)
|
|
|
|
{
|
|
|
|
if (maAutoScrollOffset != Size(0,0))
|
|
|
|
{
|
2008-04-03 13:27:45 +00:00
|
|
|
if (mrSlideSorter.GetViewShell() != NULL)
|
|
|
|
{
|
2010-01-27 11:41:30 +01:00
|
|
|
mrSlideSorter.GetViewShell()->Scroll(
|
2008-04-03 13:27:45 +00:00
|
|
|
maAutoScrollOffset.Width(),
|
2010-01-27 11:41:30 +01:00
|
|
|
maAutoScrollOffset.Height());
|
|
|
|
mrSlideSorter.GetView().InvalidatePageObjectVisibilities();
|
|
|
|
|
|
|
|
if (maAutoScrollFunctor)
|
|
|
|
maAutoScrollFunctor();
|
|
|
|
|
|
|
|
mbIsAutoScrollActive = true;
|
|
|
|
maAutoScrollTimer.Start();
|
|
|
|
|
2008-04-03 13:27:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
2008-04-03 13:27:45 +00:00
|
|
|
|
2012-08-22 14:20:32 +01:00
|
|
|
clearAutoScrollFunctor();
|
2010-01-27 11:41:30 +01:00
|
|
|
mbIsAutoScrollActive = false;
|
2008-04-03 13:27:45 +00:00
|
|
|
return false;
|
2004-07-13 13:15:32 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 14:20:32 +01:00
|
|
|
void ScrollBarManager::clearAutoScrollFunctor()
|
|
|
|
{
|
|
|
|
maAutoScrollFunctor = ::boost::function<void(void)>();
|
|
|
|
}
|
2004-07-13 13:15:32 +00:00
|
|
|
|
2012-03-01 18:00:32 +01:00
|
|
|
IMPL_LINK_NOARG(ScrollBarManager, AutoScrollTimeoutHandler)
|
2004-07-13 13:15:32 +00:00
|
|
|
{
|
|
|
|
RepeatAutoScroll();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-05-21 16:36:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
void ScrollBarManager::Scroll(
|
|
|
|
const Orientation eOrientation,
|
|
|
|
const Unit eUnit,
|
|
|
|
const sal_Int32 nDistance)
|
|
|
|
{
|
|
|
|
bool bIsVertical (false);
|
|
|
|
switch (eOrientation)
|
|
|
|
{
|
|
|
|
case Orientation_Horizontal: bIsVertical = false; break;
|
|
|
|
case Orientation_Vertical: bIsVertical = true; break;
|
|
|
|
default:
|
|
|
|
OSL_ASSERT(eOrientation==Orientation_Horizontal || eOrientation==Orientation_Vertical);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Point aNewTopLeft (
|
|
|
|
mpHorizontalScrollBar ? mpHorizontalScrollBar->GetThumbPos() : 0,
|
|
|
|
mpVerticalScrollBar ? mpVerticalScrollBar->GetThumbPos() : 0);
|
|
|
|
switch (eUnit)
|
|
|
|
{
|
|
|
|
case Unit_Pixel:
|
|
|
|
if (bIsVertical)
|
|
|
|
aNewTopLeft.Y() += nDistance;
|
|
|
|
else
|
|
|
|
aNewTopLeft.X() += nDistance;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Unit_Slide:
|
|
|
|
{
|
|
|
|
view::Layouter& rLayouter (mrSlideSorter.GetView().GetLayouter());
|
|
|
|
|
|
|
|
// Calculate estimate of new location.
|
|
|
|
if (bIsVertical)
|
|
|
|
aNewTopLeft.Y() += nDistance * rLayouter.GetPageObjectSize().Height();
|
|
|
|
else
|
|
|
|
aNewTopLeft.X() += nDistance * rLayouter.GetPageObjectSize().Width();
|
|
|
|
|
|
|
|
// Adapt location to show whole slides.
|
|
|
|
if (bIsVertical)
|
|
|
|
if (nDistance > 0)
|
|
|
|
{
|
|
|
|
const sal_Int32 nIndex (rLayouter.GetIndexAtPoint(
|
|
|
|
Point(aNewTopLeft.X(), aNewTopLeft.Y()+mpVerticalScrollBar->GetVisibleSize()),
|
|
|
|
true));
|
|
|
|
aNewTopLeft.Y() = rLayouter.GetPageObjectBox(nIndex,true).Bottom()
|
|
|
|
- mpVerticalScrollBar->GetVisibleSize();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const sal_Int32 nIndex (rLayouter.GetIndexAtPoint(
|
|
|
|
Point(aNewTopLeft.X(), aNewTopLeft.Y()),
|
|
|
|
true));
|
|
|
|
aNewTopLeft.Y() = rLayouter.GetPageObjectBox(nIndex,true).Top();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (nDistance > 0)
|
|
|
|
{
|
|
|
|
const sal_Int32 nIndex (rLayouter.GetIndexAtPoint(
|
|
|
|
Point(aNewTopLeft.X()+mpVerticalScrollBar->GetVisibleSize(), aNewTopLeft.Y()),
|
|
|
|
true));
|
|
|
|
aNewTopLeft.X() = rLayouter.GetPageObjectBox(nIndex,true).Right()
|
|
|
|
- mpVerticalScrollBar->GetVisibleSize();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const sal_Int32 nIndex (rLayouter.GetIndexAtPoint(
|
|
|
|
Point(aNewTopLeft.X(), aNewTopLeft.Y()),
|
|
|
|
true));
|
|
|
|
aNewTopLeft.X() = rLayouter.GetPageObjectBox(nIndex,true).Left();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-09 11:25:44 +02:00
|
|
|
mrSlideSorter.GetController().GetVisibleAreaManager().DeactivateCurrentSlideTracking();
|
2010-05-21 16:36:05 +02:00
|
|
|
SetTopLeft(aNewTopLeft);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-13 13:15:32 +00:00
|
|
|
} } } // end of namespace ::sd::slidesorter::controller
|
2010-10-12 15:51:52 +02:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|