2012-09-03 15:03:03 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-10-02 14:13:40 +01:00
|
|
|
/*
|
|
|
|
* 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 .
|
|
|
|
*/
|
|
|
|
|
2012-09-03 15:03:03 +01:00
|
|
|
#include <toolkit/awt/scrollabledialog.hxx>
|
2012-09-06 18:36:00 +01:00
|
|
|
#include <vcl/group.hxx>
|
2014-01-02 23:52:37 +01:00
|
|
|
#include <vcl/settings.hxx>
|
2012-09-06 18:36:00 +01:00
|
|
|
|
2012-09-03 15:03:03 +01:00
|
|
|
namespace toolkit
|
|
|
|
{
|
|
|
|
|
2012-09-07 12:17:31 +01:00
|
|
|
// Using WB_AUTOHSCROLL, WB_AUTOVSCROLL here sucks big time, there is a
|
|
|
|
// problem in the toolkit class where there are some clashing IDs
|
|
|
|
// ( ::com::sun::star::awt::VclWindowPeerAttribute::VSCROLL has the same value
|
|
|
|
// as ::com::sun::star::awt::WindowAttribute::NODECORATION and they are used
|
|
|
|
// in the same bitmap :-( WB_VSCROLL & WB_HSCROLL apparently are only for
|
|
|
|
// child classes ( whole thing is a mess if you ask me )
|
2012-09-06 18:36:00 +01:00
|
|
|
template< class T>
|
2014-09-23 11:20:40 +02:00
|
|
|
ScrollableWrapper<T>::ScrollableWrapper( vcl::Window* pParent, WinBits nStyle ) : T( pParent, nStyle & ~( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) ), maHScrollBar( this, WB_HSCROLL | WB_DRAG), maVScrollBar( this, WB_VSCROLL | WB_DRAG ), mbHasHoriBar( false ), mbHasVertBar( false ), maScrollVis( None )
|
2012-09-03 15:03:03 +01:00
|
|
|
{
|
2012-09-06 19:25:12 +01:00
|
|
|
Link aLink( LINK( this, ScrollableWrapper, ScrollBarHdl ) );
|
2012-09-03 15:03:03 +01:00
|
|
|
maVScrollBar.SetScrollHdl( aLink );
|
|
|
|
maHScrollBar.SetScrollHdl( aLink );
|
2012-09-04 20:12:45 +01:00
|
|
|
|
|
|
|
ScrollBarVisibility aVis = None;
|
|
|
|
|
2012-09-07 12:17:31 +01:00
|
|
|
if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) )
|
2012-09-04 20:12:45 +01:00
|
|
|
{
|
2012-09-07 12:17:31 +01:00
|
|
|
if ( nStyle & WB_AUTOHSCROLL )
|
2012-09-04 20:12:45 +01:00
|
|
|
aVis = Hori;
|
2012-09-07 12:17:31 +01:00
|
|
|
if ( nStyle & WB_AUTOVSCROLL )
|
2012-09-04 20:12:45 +01:00
|
|
|
{
|
|
|
|
if ( aVis == Hori )
|
|
|
|
aVis = Both;
|
|
|
|
else
|
|
|
|
aVis = Vert;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
setScrollVisibility( aVis );
|
2012-09-06 18:36:00 +01:00
|
|
|
mnScrWidth = T::GetSettings().GetStyleSettings().GetScrollBarSize();
|
2012-09-04 20:12:45 +01:00
|
|
|
}
|
|
|
|
|
2012-09-06 18:36:00 +01:00
|
|
|
template< class T>
|
2012-09-06 19:25:12 +01:00
|
|
|
void ScrollableWrapper<T>::setScrollVisibility( ScrollBarVisibility rVisState )
|
2012-09-04 20:12:45 +01:00
|
|
|
{
|
|
|
|
maScrollVis = rVisState;
|
|
|
|
if ( maScrollVis == Hori || maScrollVis == Both )
|
2012-09-06 18:36:00 +01:00
|
|
|
{
|
2012-09-04 20:12:45 +01:00
|
|
|
mbHasHoriBar = true;
|
2012-09-06 18:36:00 +01:00
|
|
|
maHScrollBar.Show();
|
|
|
|
}
|
2012-09-04 20:12:45 +01:00
|
|
|
if ( maScrollVis == Vert || maScrollVis == Both )
|
2012-09-06 18:36:00 +01:00
|
|
|
{
|
2012-09-04 20:12:45 +01:00
|
|
|
mbHasVertBar = true;
|
|
|
|
maVScrollBar.Show();
|
2012-09-06 18:36:00 +01:00
|
|
|
}
|
2012-09-04 20:12:45 +01:00
|
|
|
if ( mbHasHoriBar || mbHasVertBar )
|
2012-09-11 17:21:52 +02:00
|
|
|
this->SetStyle( T::GetStyle() | WB_CLIPCHILDREN | SCROLL_UPDATE );
|
2012-09-03 15:03:03 +01:00
|
|
|
}
|
|
|
|
|
2012-09-06 18:36:00 +01:00
|
|
|
template< class T>
|
2012-09-06 19:25:12 +01:00
|
|
|
ScrollableWrapper<T>::~ScrollableWrapper()
|
2012-09-03 15:03:03 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-09-06 18:36:00 +01:00
|
|
|
template< class T>
|
2012-09-06 19:25:12 +01:00
|
|
|
void ScrollableWrapper<T>::lcl_Scroll( long nX, long nY )
|
2012-09-04 20:12:45 +01:00
|
|
|
{
|
2012-09-04 21:55:23 +01:00
|
|
|
long nXScroll = mnScrollPos.X() - nX;
|
|
|
|
long nYScroll = mnScrollPos.Y() - nY;
|
2012-09-04 20:12:45 +01:00
|
|
|
mnScrollPos = Point( nX, nY );
|
|
|
|
|
|
|
|
Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
|
2012-09-06 18:36:00 +01:00
|
|
|
T::Scroll(nXScroll, nYScroll, aScrollableArea );
|
2012-09-04 20:12:45 +01:00
|
|
|
// Manually scroll all children ( except the scrollbars )
|
2012-09-06 18:36:00 +01:00
|
|
|
for ( int index = 0; index < T::GetChildCount(); ++index )
|
2012-09-04 20:12:45 +01:00
|
|
|
{
|
2014-09-23 11:20:40 +02:00
|
|
|
vcl::Window* pChild = T::GetChild( index );
|
2012-09-04 20:12:45 +01:00
|
|
|
if ( pChild && pChild != &maVScrollBar && pChild != &maHScrollBar )
|
|
|
|
{
|
|
|
|
Point aPos = pChild->GetPosPixel();
|
|
|
|
aPos += Point( nXScroll, nYScroll );
|
|
|
|
pChild->SetPosPixel( aPos );
|
|
|
|
}
|
|
|
|
}
|
2012-09-03 15:03:03 +01:00
|
|
|
}
|
|
|
|
|
2012-09-06 18:36:00 +01:00
|
|
|
//Can't use IMPL_LINK with the template
|
2012-09-06 19:25:12 +01:00
|
|
|
//IMPL_LINK( ScrollableWrapper, ScrollBarHdl, ScrollBar*, pSB )
|
2012-09-06 18:36:00 +01:00
|
|
|
|
|
|
|
template< class T>
|
2015-01-10 12:36:22 +01:00
|
|
|
sal_IntPtr ScrollableWrapper<T>::LinkStubScrollBarHdl( void* pThis, void* pCaller)
|
2012-09-06 18:36:00 +01:00
|
|
|
{
|
2015-03-28 19:07:54 +01:00
|
|
|
return ((ScrollableWrapper<T>*)pThis )->ScrollBarHdl( static_cast<ScrollBar*>(pCaller) );
|
2012-09-06 18:36:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template< class T>
|
2015-01-10 12:36:22 +01:00
|
|
|
sal_IntPtr ScrollableWrapper<T>::ScrollBarHdl( ScrollBar* pSB )
|
2012-09-03 15:03:03 +01:00
|
|
|
{
|
|
|
|
sal_uInt16 nPos = (sal_uInt16) pSB->GetThumbPos();
|
2012-09-04 20:12:45 +01:00
|
|
|
if( pSB == &maVScrollBar )
|
2012-09-04 21:55:23 +01:00
|
|
|
lcl_Scroll(mnScrollPos.X(), nPos );
|
2012-09-04 20:12:45 +01:00
|
|
|
else if( pSB == &maHScrollBar )
|
2012-09-04 21:55:23 +01:00
|
|
|
lcl_Scroll(nPos, mnScrollPos.Y() );
|
2012-09-03 15:03:03 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-09-06 18:36:00 +01:00
|
|
|
template< class T>
|
2012-09-06 19:25:12 +01:00
|
|
|
void ScrollableWrapper<T>::SetScrollTop( long nTop )
|
2012-09-05 17:59:46 +01:00
|
|
|
{
|
2012-09-05 19:49:10 +01:00
|
|
|
Point aOld = mnScrollPos;
|
2012-09-05 20:19:03 +01:00
|
|
|
lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop );
|
2012-09-05 19:49:10 +01:00
|
|
|
maHScrollBar.SetThumbPos( 0 );
|
2012-09-05 20:19:03 +01:00
|
|
|
// new pos is 0,0
|
2012-09-05 19:49:10 +01:00
|
|
|
mnScrollPos = aOld;
|
2012-09-05 17:59:46 +01:00
|
|
|
}
|
2012-09-06 18:36:00 +01:00
|
|
|
template< class T>
|
2012-09-06 19:25:12 +01:00
|
|
|
void ScrollableWrapper<T>::SetScrollLeft( long nLeft )
|
2012-09-05 17:59:46 +01:00
|
|
|
{
|
2012-09-05 19:49:10 +01:00
|
|
|
Point aOld = mnScrollPos;
|
2012-09-05 20:19:03 +01:00
|
|
|
lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
|
2012-09-05 19:49:10 +01:00
|
|
|
maVScrollBar.SetThumbPos( 0 );
|
2012-09-05 20:19:03 +01:00
|
|
|
// new pos is 0,0
|
2012-09-05 19:49:10 +01:00
|
|
|
mnScrollPos = aOld;
|
2012-09-05 17:59:46 +01:00
|
|
|
}
|
2012-09-06 18:36:00 +01:00
|
|
|
template< class T>
|
2012-09-06 19:25:12 +01:00
|
|
|
void ScrollableWrapper<T>::SetScrollWidth( long nWidth )
|
2012-09-04 20:12:45 +01:00
|
|
|
{
|
|
|
|
maScrollArea.Width() = nWidth;
|
2012-09-05 19:49:10 +01:00
|
|
|
ResetScrollBars();
|
2012-09-04 20:12:45 +01:00
|
|
|
}
|
|
|
|
|
2012-09-06 18:36:00 +01:00
|
|
|
template< class T>
|
2012-09-06 19:25:12 +01:00
|
|
|
void ScrollableWrapper<T>::SetScrollHeight( long nHeight )
|
2012-09-04 20:12:45 +01:00
|
|
|
{
|
|
|
|
maScrollArea.Height() = nHeight;
|
2012-09-05 19:49:10 +01:00
|
|
|
ResetScrollBars();
|
2012-09-04 20:12:45 +01:00
|
|
|
}
|
|
|
|
|
2012-09-06 18:36:00 +01:00
|
|
|
template< class T>
|
2012-09-06 19:25:12 +01:00
|
|
|
void ScrollableWrapper<T>::Resize()
|
2012-09-04 20:12:45 +01:00
|
|
|
{
|
2012-09-05 19:49:10 +01:00
|
|
|
ResetScrollBars();
|
2012-09-04 20:12:45 +01:00
|
|
|
}
|
|
|
|
|
2012-09-06 18:36:00 +01:00
|
|
|
template< class T>
|
2012-09-06 19:25:12 +01:00
|
|
|
void ScrollableWrapper<T>::ResetScrollBars()
|
2012-09-03 15:03:03 +01:00
|
|
|
{
|
2012-09-06 18:36:00 +01:00
|
|
|
Size aOutSz = T::GetOutputSizePixel();
|
2012-09-03 15:03:03 +01:00
|
|
|
|
2012-09-04 20:12:45 +01:00
|
|
|
Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
|
|
|
|
Point aHPos( 0, aOutSz.Height() - mnScrWidth );
|
2012-09-03 15:03:03 +01:00
|
|
|
|
2012-09-06 18:36:00 +01:00
|
|
|
maVScrollBar.SetPosSizePixel( aVPos, Size( mnScrWidth, T::GetSizePixel().Height() - mnScrWidth ) );
|
|
|
|
maHScrollBar.SetPosSizePixel( aHPos, Size( T::GetSizePixel().Width() - mnScrWidth, mnScrWidth ) );
|
2012-09-04 21:55:23 +01:00
|
|
|
|
2012-09-05 19:49:10 +01:00
|
|
|
maHScrollBar.SetRangeMax( maScrollArea.Width() + mnScrWidth );
|
2012-09-06 18:36:00 +01:00
|
|
|
maHScrollBar.SetVisibleSize( T::GetSizePixel().Width() );
|
2012-09-04 21:55:23 +01:00
|
|
|
|
2012-09-05 19:49:10 +01:00
|
|
|
maVScrollBar.SetRangeMax( maScrollArea.Height() + mnScrWidth );
|
2012-09-06 18:36:00 +01:00
|
|
|
maVScrollBar.SetVisibleSize( T::GetSizePixel().Height() );
|
2012-09-03 15:03:03 +01:00
|
|
|
}
|
|
|
|
|
2012-09-06 19:25:12 +01:00
|
|
|
template class ScrollableWrapper< Dialog >;
|
2012-09-06 18:36:00 +01:00
|
|
|
|
2012-09-03 15:03:03 +01:00
|
|
|
} // toolkit
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|