1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_svtools.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #define _SVT_SCRWIN_CXX 32*cdf0e10cSrcweir #include <svtools/scrwin.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir //=================================================================== 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir void ScrollableWindow::ImpInitialize( ScrollableWindowFlags nFlags ) 37*cdf0e10cSrcweir { 38*cdf0e10cSrcweir bHandleDragging = (sal_Bool) ( nFlags & SCRWIN_THUMBDRAGGING ); 39*cdf0e10cSrcweir bVCenter = (nFlags & SCRWIN_VCENTER) == SCRWIN_VCENTER; 40*cdf0e10cSrcweir bHCenter = (nFlags & SCRWIN_HCENTER) == SCRWIN_HCENTER; 41*cdf0e10cSrcweir bScrolling = sal_False; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir // set the handlers for the scrollbars 44*cdf0e10cSrcweir aVScroll.SetScrollHdl( LINK(this, ScrollableWindow, ScrollHdl) ); 45*cdf0e10cSrcweir aHScroll.SetScrollHdl( LINK(this, ScrollableWindow, ScrollHdl) ); 46*cdf0e10cSrcweir aVScroll.SetEndScrollHdl( LINK(this, ScrollableWindow, EndScrollHdl) ); 47*cdf0e10cSrcweir aHScroll.SetEndScrollHdl( LINK(this, ScrollableWindow, EndScrollHdl) ); 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir nColumnPixW = nLinePixH = GetSettings().GetStyleSettings().GetScrollBarSize(); 50*cdf0e10cSrcweir } 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir //------------------------------------------------------------------- 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir ScrollableWindow::ScrollableWindow( Window* pParent, WinBits nBits, 55*cdf0e10cSrcweir ScrollableWindowFlags nFlags ) : 56*cdf0e10cSrcweir Window( pParent, WinBits(nBits|WB_CLIPCHILDREN) ), 57*cdf0e10cSrcweir aVScroll( this, WinBits(WB_VSCROLL | WB_DRAG) ), 58*cdf0e10cSrcweir aHScroll( this, WinBits(WB_HSCROLL | WB_DRAG) ), 59*cdf0e10cSrcweir aCornerWin( this ) 60*cdf0e10cSrcweir { 61*cdf0e10cSrcweir ImpInitialize( nFlags ); 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir //------------------------------------------------------------------- 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir ScrollableWindow::ScrollableWindow( Window* pParent, const ResId& rId, 67*cdf0e10cSrcweir ScrollableWindowFlags nFlags ) : 68*cdf0e10cSrcweir Window( pParent, rId ), 69*cdf0e10cSrcweir aVScroll( this, WinBits(WB_VSCROLL | WB_DRAG) ), 70*cdf0e10cSrcweir aHScroll( this, WinBits(WB_HSCROLL | WB_DRAG) ), 71*cdf0e10cSrcweir aCornerWin( this ) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir ImpInitialize( nFlags ); 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir // ----------------------------------------------------------------------- 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir void ScrollableWindow::Command( const CommandEvent& rCEvt ) 79*cdf0e10cSrcweir { 80*cdf0e10cSrcweir if ( (rCEvt.GetCommand() == COMMAND_WHEEL) || 81*cdf0e10cSrcweir (rCEvt.GetCommand() == COMMAND_STARTAUTOSCROLL) || 82*cdf0e10cSrcweir (rCEvt.GetCommand() == COMMAND_AUTOSCROLL) ) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir ScrollBar* pHScrBar; 85*cdf0e10cSrcweir ScrollBar* pVScrBar; 86*cdf0e10cSrcweir if ( aHScroll.IsVisible() ) 87*cdf0e10cSrcweir pHScrBar = &aHScroll; 88*cdf0e10cSrcweir else 89*cdf0e10cSrcweir pHScrBar = NULL; 90*cdf0e10cSrcweir if ( aVScroll.IsVisible() ) 91*cdf0e10cSrcweir pVScrBar = &aVScroll; 92*cdf0e10cSrcweir else 93*cdf0e10cSrcweir pVScrBar = NULL; 94*cdf0e10cSrcweir if ( HandleScrollCommand( rCEvt, pHScrBar, pVScrBar ) ) 95*cdf0e10cSrcweir return; 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir Window::Command( rCEvt ); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir //------------------------------------------------------------------- 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir void ScrollableWindow::DataChanged( const DataChangedEvent& rDCEvt ) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && 106*cdf0e10cSrcweir (rDCEvt.GetFlags() & SETTINGS_STYLE) ) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir Resize(); 109*cdf0e10cSrcweir Invalidate(); 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir Window::DataChanged( rDCEvt ); 113*cdf0e10cSrcweir } 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir //------------------------------------------------------------------- 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir Size __EXPORT ScrollableWindow::GetOutputSizePixel() const 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir Size aSz( Window::GetOutputSizePixel() ); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir long nTmp = GetSettings().GetStyleSettings().GetScrollBarSize(); 122*cdf0e10cSrcweir if ( aHScroll.IsVisible() ) 123*cdf0e10cSrcweir aSz.Height() -= nTmp; 124*cdf0e10cSrcweir if ( aVScroll.IsVisible() ) 125*cdf0e10cSrcweir aSz.Width() -= nTmp; 126*cdf0e10cSrcweir return aSz; 127*cdf0e10cSrcweir } 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir //------------------------------------------------------------------- 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir Size ScrollableWindow::GetOutputSize() const 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir return PixelToLogic( GetOutputSizePixel() ); 134*cdf0e10cSrcweir } 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir //------------------------------------------------------------------- 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir IMPL_LINK( ScrollableWindow, EndScrollHdl, ScrollBar *, pScroll ) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir // notify the start of scrolling, if not already scrolling 141*cdf0e10cSrcweir if ( !bScrolling ) 142*cdf0e10cSrcweir StartScroll(), bScrolling = sal_True; 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir // get the delta in logic coordinates 145*cdf0e10cSrcweir Size aDelta( PixelToLogic( Size( aHScroll.GetDelta(), aVScroll.GetDelta() ) ) ); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // scroll the window, if this is not already done 148*cdf0e10cSrcweir if ( !bHandleDragging ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir if ( pScroll == &aHScroll ) 151*cdf0e10cSrcweir Scroll( aDelta.Width(), 0 ); 152*cdf0e10cSrcweir else 153*cdf0e10cSrcweir Scroll( 0, aDelta.Height() ); 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir // notify the end of scrolling 157*cdf0e10cSrcweir bScrolling = sal_False; 158*cdf0e10cSrcweir EndScroll( aDelta.Width(), aDelta.Height() ); 159*cdf0e10cSrcweir return 0; 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir //------------------------------------------------------------------- 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir IMPL_LINK( ScrollableWindow, ScrollHdl, ScrollBar *, pScroll ) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir // notify the start of scrolling, if not already scrolling 167*cdf0e10cSrcweir if ( !bScrolling ) 168*cdf0e10cSrcweir StartScroll(), bScrolling = sal_True; 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir if ( bHandleDragging ) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir // get the delta in logic coordinates 173*cdf0e10cSrcweir Size aDelta( PixelToLogic( 174*cdf0e10cSrcweir Size( aHScroll.GetDelta(), aVScroll.GetDelta() ) ) ); 175*cdf0e10cSrcweir if ( pScroll == &aHScroll ) 176*cdf0e10cSrcweir Scroll( aDelta.Width(), 0 ); 177*cdf0e10cSrcweir else 178*cdf0e10cSrcweir Scroll( 0, aDelta.Height() ); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir return 0; 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir //------------------------------------------------------------------- 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir void __EXPORT ScrollableWindow::Resize() 186*cdf0e10cSrcweir { 187*cdf0e10cSrcweir // get the new output-size in pixel 188*cdf0e10cSrcweir Size aOutPixSz = Window::GetOutputSizePixel(); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir // determine the size of the output-area and if we need scrollbars 191*cdf0e10cSrcweir const long nScrSize = GetSettings().GetStyleSettings().GetScrollBarSize(); 192*cdf0e10cSrcweir sal_Bool bVVisible = sal_False; // by default no vertical-ScrollBar 193*cdf0e10cSrcweir sal_Bool bHVisible = sal_False; // by default no horizontal-ScrollBar 194*cdf0e10cSrcweir sal_Bool bChanged; // determines if a visiblility was changed 195*cdf0e10cSrcweir do 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir bChanged = sal_False; 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir // does we need a vertical ScrollBar 200*cdf0e10cSrcweir if ( aOutPixSz.Width() < aTotPixSz.Width() && !bHVisible ) 201*cdf0e10cSrcweir { bHVisible = sal_True; 202*cdf0e10cSrcweir aOutPixSz.Height() -= nScrSize; 203*cdf0e10cSrcweir bChanged = sal_True; 204*cdf0e10cSrcweir } 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir // does we need a horizontal ScrollBar 207*cdf0e10cSrcweir if ( aOutPixSz.Height() < aTotPixSz.Height() && !bVVisible ) 208*cdf0e10cSrcweir { bVVisible = sal_True; 209*cdf0e10cSrcweir aOutPixSz.Width() -= nScrSize; 210*cdf0e10cSrcweir bChanged = sal_True; 211*cdf0e10cSrcweir } 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir while ( bChanged ); // until no visibility has changed 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir // store the old offset and map-mode 217*cdf0e10cSrcweir MapMode aMap( GetMapMode() ); 218*cdf0e10cSrcweir Point aOldPixOffset( aPixOffset ); 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir // justify (right/bottom borders should never exceed the virtual window) 221*cdf0e10cSrcweir Size aPixDelta; 222*cdf0e10cSrcweir if ( aPixOffset.X() < 0 && 223*cdf0e10cSrcweir aPixOffset.X() + aTotPixSz.Width() < aOutPixSz.Width() ) 224*cdf0e10cSrcweir aPixDelta.Width() = 225*cdf0e10cSrcweir aOutPixSz.Width() - ( aPixOffset.X() + aTotPixSz.Width() ); 226*cdf0e10cSrcweir if ( aPixOffset.Y() < 0 && 227*cdf0e10cSrcweir aPixOffset.Y() + aTotPixSz.Height() < aOutPixSz.Height() ) 228*cdf0e10cSrcweir aPixDelta.Height() = 229*cdf0e10cSrcweir aOutPixSz.Height() - ( aPixOffset.Y() + aTotPixSz.Height() ); 230*cdf0e10cSrcweir if ( aPixDelta.Width() || aPixDelta.Height() ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir aPixOffset.X() += aPixDelta.Width(); 233*cdf0e10cSrcweir aPixOffset.Y() += aPixDelta.Height(); 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir // for axis without scrollbar restore the origin 237*cdf0e10cSrcweir if ( !bVVisible || !bHVisible ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir aPixOffset = Point( 240*cdf0e10cSrcweir bHVisible 241*cdf0e10cSrcweir ? aPixOffset.X() 242*cdf0e10cSrcweir : ( bHCenter 243*cdf0e10cSrcweir ? (aOutPixSz.Width()-aTotPixSz.Width()) / 2 244*cdf0e10cSrcweir : 0 ), 245*cdf0e10cSrcweir bVVisible 246*cdf0e10cSrcweir ? aPixOffset.Y() 247*cdf0e10cSrcweir : ( bVCenter 248*cdf0e10cSrcweir ? (aOutPixSz.Height()-aTotPixSz.Height()) / 2 249*cdf0e10cSrcweir : 0 ) ); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir if ( bHVisible && !aHScroll.IsVisible() ) 252*cdf0e10cSrcweir aPixOffset.X() = 0; 253*cdf0e10cSrcweir if ( bVVisible && !aVScroll.IsVisible() ) 254*cdf0e10cSrcweir aPixOffset.Y() = 0; 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir // select the shifted map-mode 257*cdf0e10cSrcweir if ( aPixOffset != aOldPixOffset ) 258*cdf0e10cSrcweir { 259*cdf0e10cSrcweir Window::SetMapMode( MapMode( MAP_PIXEL ) ); 260*cdf0e10cSrcweir Window::Scroll( 261*cdf0e10cSrcweir aPixOffset.X() - aOldPixOffset.X(), 262*cdf0e10cSrcweir aPixOffset.Y() - aOldPixOffset.Y() ); 263*cdf0e10cSrcweir SetMapMode( aMap ); 264*cdf0e10cSrcweir } 265*cdf0e10cSrcweir 266*cdf0e10cSrcweir // show or hide scrollbars 267*cdf0e10cSrcweir aVScroll.Show( bVVisible ); 268*cdf0e10cSrcweir aHScroll.Show( bHVisible ); 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir // disable painting in the corner between the scrollbars 271*cdf0e10cSrcweir if ( bVVisible && bHVisible ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir aCornerWin.SetPosSizePixel(Point(aOutPixSz.Width(), aOutPixSz.Height()), 274*cdf0e10cSrcweir Size(nScrSize, nScrSize) ); 275*cdf0e10cSrcweir aCornerWin.Show(); 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir else 278*cdf0e10cSrcweir aCornerWin.Hide(); 279*cdf0e10cSrcweir 280*cdf0e10cSrcweir // resize scrollbars and set their ranges 281*cdf0e10cSrcweir if ( bHVisible ) 282*cdf0e10cSrcweir { 283*cdf0e10cSrcweir aHScroll.SetPosSizePixel( 284*cdf0e10cSrcweir Point( 0, aOutPixSz.Height() ), 285*cdf0e10cSrcweir Size( aOutPixSz.Width(), nScrSize ) ); 286*cdf0e10cSrcweir aHScroll.SetRange( Range( 0, aTotPixSz.Width() ) ); 287*cdf0e10cSrcweir aHScroll.SetPageSize( aOutPixSz.Width() ); 288*cdf0e10cSrcweir aHScroll.SetVisibleSize( aOutPixSz.Width() ); 289*cdf0e10cSrcweir aHScroll.SetLineSize( nColumnPixW ); 290*cdf0e10cSrcweir aHScroll.SetThumbPos( -aPixOffset.X() ); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir if ( bVVisible ) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir aVScroll.SetPosSizePixel( 295*cdf0e10cSrcweir Point( aOutPixSz.Width(), 0 ), 296*cdf0e10cSrcweir Size( nScrSize,aOutPixSz.Height() ) ); 297*cdf0e10cSrcweir aVScroll.SetRange( Range( 0, aTotPixSz.Height() ) ); 298*cdf0e10cSrcweir aVScroll.SetPageSize( aOutPixSz.Height() ); 299*cdf0e10cSrcweir aVScroll.SetVisibleSize( aOutPixSz.Height() ); 300*cdf0e10cSrcweir aVScroll.SetLineSize( nLinePixH ); 301*cdf0e10cSrcweir aVScroll.SetThumbPos( -aPixOffset.Y() ); 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir } 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir //------------------------------------------------------------------- 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir void __EXPORT ScrollableWindow::StartScroll() 308*cdf0e10cSrcweir { 309*cdf0e10cSrcweir } 310*cdf0e10cSrcweir 311*cdf0e10cSrcweir //------------------------------------------------------------------- 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir void __EXPORT ScrollableWindow::EndScroll( long, long ) 314*cdf0e10cSrcweir { 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir //------------------------------------------------------------------- 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir void ScrollableWindow::SetMapMode( const MapMode& rNewMapMode ) 320*cdf0e10cSrcweir { 321*cdf0e10cSrcweir MapMode aMap( rNewMapMode ); 322*cdf0e10cSrcweir aMap.SetOrigin( aMap.GetOrigin() + PixelToLogic( aPixOffset, aMap ) ); 323*cdf0e10cSrcweir Window::SetMapMode( aMap ); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir //------------------------------------------------------------------- 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir MapMode ScrollableWindow::GetMapMode() const 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir MapMode aMap( Window::GetMapMode() ); 331*cdf0e10cSrcweir aMap.SetOrigin( aMap.GetOrigin() - PixelToLogic( aPixOffset ) ); 332*cdf0e10cSrcweir return aMap; 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir //------------------------------------------------------------------- 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir void ScrollableWindow::SetTotalSize( const Size& rNewSize ) 338*cdf0e10cSrcweir { 339*cdf0e10cSrcweir aTotPixSz = LogicToPixel( rNewSize ); 340*cdf0e10cSrcweir ScrollableWindow::Resize(); 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir //------------------------------------------------------------------- 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir void ScrollableWindow::SetVisibleSize( const Size& rNewSize ) 346*cdf0e10cSrcweir { 347*cdf0e10cSrcweir // get the rectangle, we wish to view 348*cdf0e10cSrcweir Rectangle aWish( Point(0, 0), LogicToPixel(rNewSize) ); 349*cdf0e10cSrcweir 350*cdf0e10cSrcweir // get maximum rectangle for us from our parent-window (subst our border!) 351*cdf0e10cSrcweir Rectangle aMax( Point(0, 0), GetParent()->GetOutputSizePixel() ); 352*cdf0e10cSrcweir aMax.Left() -= ( Window::GetSizePixel().Width() - 353*cdf0e10cSrcweir Window::GetOutputSizePixel().Width() ); 354*cdf0e10cSrcweir aMax.Bottom() -= (Window::GetSizePixel().Height() - 355*cdf0e10cSrcweir Window::GetOutputSizePixel().Height()); 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir Size aWill( aWish.GetIntersection(aMax).GetSize() ); 358*cdf0e10cSrcweir sal_Bool bHScroll = sal_False; 359*cdf0e10cSrcweir const long nScrSize = GetSettings().GetStyleSettings().GetScrollBarSize(); 360*cdf0e10cSrcweir if ( aWill.Width() < aWish.GetSize().Width() ) 361*cdf0e10cSrcweir { bHScroll = sal_True; 362*cdf0e10cSrcweir aWill.Height() = 363*cdf0e10cSrcweir Min( aWill.Height()+nScrSize, aMax.GetSize().Height() ); 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir if ( aWill.Height() < aWish.GetSize().Height() ) 366*cdf0e10cSrcweir aWill.Width() = 367*cdf0e10cSrcweir Min( aWill.Width()+nScrSize, aMax.GetSize().Width() ); 368*cdf0e10cSrcweir if ( !bHScroll && (aWill.Width() < aWish.GetSize().Width()) ) 369*cdf0e10cSrcweir aWill.Height() = 370*cdf0e10cSrcweir Min( aWill.Height()+nScrSize, aMax.GetSize().Height() ); 371*cdf0e10cSrcweir Window::SetOutputSizePixel( aWill ); 372*cdf0e10cSrcweir } 373*cdf0e10cSrcweir 374*cdf0e10cSrcweir //------------------------------------------------------------------- 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir sal_Bool ScrollableWindow::MakeVisible( const Rectangle& rTarget, sal_Bool bSloppy ) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir Rectangle aTarget; 379*cdf0e10cSrcweir Rectangle aTotRect( Point(0, 0), PixelToLogic( aTotPixSz ) ); 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir if ( bSloppy ) 382*cdf0e10cSrcweir { 383*cdf0e10cSrcweir aTarget = rTarget; 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir // at maximum to right border 386*cdf0e10cSrcweir if ( aTarget.Right() > aTotRect.Right() ) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir long nDelta = aTarget.Right() - aTotRect.Right(); 389*cdf0e10cSrcweir aTarget.Left() -= nDelta; 390*cdf0e10cSrcweir aTarget.Right() -= nDelta; 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir // too wide? 393*cdf0e10cSrcweir if ( aTarget.Left() < aTotRect.Left() ) 394*cdf0e10cSrcweir aTarget.Left() = aTotRect.Left(); 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir 397*cdf0e10cSrcweir // at maximum to bottom border 398*cdf0e10cSrcweir if ( aTarget.Bottom() > aTotRect.Bottom() ) 399*cdf0e10cSrcweir { 400*cdf0e10cSrcweir long nDelta = aTarget.Bottom() - aTotRect.Bottom(); 401*cdf0e10cSrcweir aTarget.Top() -= nDelta; 402*cdf0e10cSrcweir aTarget.Bottom() -= nDelta; 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir // too high? 405*cdf0e10cSrcweir if ( aTarget.Top() < aTotRect.Top() ) 406*cdf0e10cSrcweir aTarget.Top() = aTotRect.Top(); 407*cdf0e10cSrcweir } 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir // at maximum to left border 410*cdf0e10cSrcweir if ( aTarget.Left() < aTotRect.Left() ) 411*cdf0e10cSrcweir { 412*cdf0e10cSrcweir long nDelta = aTarget.Left() - aTotRect.Left(); 413*cdf0e10cSrcweir aTarget.Right() -= nDelta; 414*cdf0e10cSrcweir aTarget.Left() -= nDelta; 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir // too wide? 417*cdf0e10cSrcweir if ( aTarget.Right() > aTotRect.Right() ) 418*cdf0e10cSrcweir aTarget.Right() = aTotRect.Right(); 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir 421*cdf0e10cSrcweir // at maximum to top border 422*cdf0e10cSrcweir if ( aTarget.Top() < aTotRect.Top() ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir long nDelta = aTarget.Top() - aTotRect.Top(); 425*cdf0e10cSrcweir aTarget.Bottom() -= nDelta; 426*cdf0e10cSrcweir aTarget.Top() -= nDelta; 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir // too high? 429*cdf0e10cSrcweir if ( aTarget.Bottom() > aTotRect.Bottom() ) 430*cdf0e10cSrcweir aTarget.Bottom() = aTotRect.Bottom(); 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir else 434*cdf0e10cSrcweir aTarget = rTarget.GetIntersection( aTotRect ); 435*cdf0e10cSrcweir 436*cdf0e10cSrcweir // is the area already visible? 437*cdf0e10cSrcweir Rectangle aVisArea( GetVisibleArea() ); 438*cdf0e10cSrcweir if ( aVisArea.IsInside(rTarget) ) 439*cdf0e10cSrcweir return sal_True; 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir // is there somewhat to scroll? 442*cdf0e10cSrcweir if ( aVisArea.TopLeft() != aTarget.TopLeft() ) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir Rectangle aBox( aTarget.GetUnion(aVisArea) ); 445*cdf0e10cSrcweir long nDeltaX = ( aBox.Right() - aVisArea.Right() ) + 446*cdf0e10cSrcweir ( aBox.Left() - aVisArea.Left() ); 447*cdf0e10cSrcweir long nDeltaY = ( aBox.Top() - aVisArea.Top() ) + 448*cdf0e10cSrcweir ( aBox.Bottom() - aVisArea.Bottom() ); 449*cdf0e10cSrcweir Scroll( nDeltaX, nDeltaY ); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir // determine if the target is completely visible 453*cdf0e10cSrcweir return aVisArea.GetWidth() >= aTarget.GetWidth() && 454*cdf0e10cSrcweir aVisArea.GetHeight() >= aTarget.GetHeight(); 455*cdf0e10cSrcweir } 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir //------------------------------------------------------------------- 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir Rectangle ScrollableWindow::GetVisibleArea() const 460*cdf0e10cSrcweir { 461*cdf0e10cSrcweir Point aTopLeft( PixelToLogic( Point() ) ); 462*cdf0e10cSrcweir Size aSz( GetOutputSize() ); 463*cdf0e10cSrcweir return Rectangle( aTopLeft, aSz ); 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir //------------------------------------------------------------------- 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir void ScrollableWindow::SetLineSize( sal_uLong nHorz, sal_uLong nVert ) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir Size aPixSz( LogicToPixel( Size(nHorz, nVert) ) ); 471*cdf0e10cSrcweir nColumnPixW = aPixSz.Width(); 472*cdf0e10cSrcweir nLinePixH = aPixSz.Height(); 473*cdf0e10cSrcweir aVScroll.SetLineSize( nLinePixH ); 474*cdf0e10cSrcweir aHScroll.SetLineSize( nColumnPixW ); 475*cdf0e10cSrcweir } 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir //------------------------------------------------------------------- 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir void ScrollableWindow::Scroll( long nDeltaX, long nDeltaY, sal_uInt16 ) 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir if ( !bScrolling ) 482*cdf0e10cSrcweir StartScroll(); 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir // get the delta in pixel 485*cdf0e10cSrcweir Size aDeltaPix( LogicToPixel( Size(nDeltaX, nDeltaY) ) ); 486*cdf0e10cSrcweir Size aOutPixSz( GetOutputSizePixel() ); 487*cdf0e10cSrcweir MapMode aMap( GetMapMode() ); 488*cdf0e10cSrcweir Point aNewPixOffset( aPixOffset ); 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir // scrolling horizontally? 491*cdf0e10cSrcweir if ( nDeltaX != 0 ) 492*cdf0e10cSrcweir { 493*cdf0e10cSrcweir aNewPixOffset.X() -= aDeltaPix.Width(); 494*cdf0e10cSrcweir if ( ( aOutPixSz.Width() - aNewPixOffset.X() ) > aTotPixSz.Width() ) 495*cdf0e10cSrcweir aNewPixOffset.X() = - ( aTotPixSz.Width() - aOutPixSz.Width() ); 496*cdf0e10cSrcweir else if ( aNewPixOffset.X() > 0 ) 497*cdf0e10cSrcweir aNewPixOffset.X() = 0; 498*cdf0e10cSrcweir } 499*cdf0e10cSrcweir 500*cdf0e10cSrcweir // scrolling vertically? 501*cdf0e10cSrcweir if ( nDeltaY != 0 ) 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir aNewPixOffset.Y() -= aDeltaPix.Height(); 504*cdf0e10cSrcweir if ( ( aOutPixSz.Height() - aNewPixOffset.Y() ) > aTotPixSz.Height() ) 505*cdf0e10cSrcweir aNewPixOffset.Y() = - ( aTotPixSz.Height() - aOutPixSz.Height() ); 506*cdf0e10cSrcweir else if ( aNewPixOffset.Y() > 0 ) 507*cdf0e10cSrcweir aNewPixOffset.Y() = 0; 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir 510*cdf0e10cSrcweir // recompute the logical scroll units 511*cdf0e10cSrcweir aDeltaPix.Width() = aPixOffset.X() - aNewPixOffset.X(); 512*cdf0e10cSrcweir aDeltaPix.Height() = aPixOffset.Y() - aNewPixOffset.Y(); 513*cdf0e10cSrcweir Size aDelta( PixelToLogic(aDeltaPix) ); 514*cdf0e10cSrcweir nDeltaX = aDelta.Width(); 515*cdf0e10cSrcweir nDeltaY = aDelta.Height(); 516*cdf0e10cSrcweir aPixOffset = aNewPixOffset; 517*cdf0e10cSrcweir 518*cdf0e10cSrcweir // scrolling? 519*cdf0e10cSrcweir if ( nDeltaX != 0 || nDeltaY != 0 ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir Update(); 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir // does the new area overlap the old one? 524*cdf0e10cSrcweir if ( Abs( (int)aDeltaPix.Height() ) < aOutPixSz.Height() || 525*cdf0e10cSrcweir Abs( (int)aDeltaPix.Width() ) < aOutPixSz.Width() ) 526*cdf0e10cSrcweir { 527*cdf0e10cSrcweir // scroll the overlapping area 528*cdf0e10cSrcweir SetMapMode( aMap ); 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir // never scroll the scrollbars itself! 531*cdf0e10cSrcweir Window::Scroll(-nDeltaX, -nDeltaY, 532*cdf0e10cSrcweir PixelToLogic( Rectangle( Point(0, 0), aOutPixSz ) ) ); 533*cdf0e10cSrcweir } 534*cdf0e10cSrcweir else 535*cdf0e10cSrcweir { 536*cdf0e10cSrcweir // repaint all 537*cdf0e10cSrcweir SetMapMode( aMap ); 538*cdf0e10cSrcweir Invalidate(); 539*cdf0e10cSrcweir } 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir Update(); 542*cdf0e10cSrcweir } 543*cdf0e10cSrcweir 544*cdf0e10cSrcweir if ( !bScrolling ) 545*cdf0e10cSrcweir { 546*cdf0e10cSrcweir EndScroll( nDeltaX, nDeltaY ); 547*cdf0e10cSrcweir if ( nDeltaX ) 548*cdf0e10cSrcweir aHScroll.SetThumbPos( -aPixOffset.X() ); 549*cdf0e10cSrcweir if ( nDeltaY ) 550*cdf0e10cSrcweir aVScroll.SetThumbPos( -aPixOffset.Y() ); 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir } 553*cdf0e10cSrcweir 554*cdf0e10cSrcweir //------------------------------------------------------------------- 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir void ScrollableWindow::ScrollLines( long nLinesX, long nLinesY ) 557*cdf0e10cSrcweir { 558*cdf0e10cSrcweir Size aDelta( PixelToLogic( Size( nColumnPixW, nLinePixH ) ) ); 559*cdf0e10cSrcweir Scroll( aDelta.Width()*nLinesX, aDelta.Height()*nLinesY ); 560*cdf0e10cSrcweir } 561*cdf0e10cSrcweir 562*cdf0e10cSrcweir //------------------------------------------------------------------- 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir void ScrollableWindow::ScrollPages( long nPagesX, sal_uLong nOverlapX, 565*cdf0e10cSrcweir long nPagesY, sal_uLong nOverlapY ) 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir Size aOutSz( GetVisibleArea().GetSize() ); 568*cdf0e10cSrcweir Scroll( nPagesX * aOutSz.Width() + (nPagesX>0 ? 1 : -1) * nOverlapX, 569*cdf0e10cSrcweir nPagesY * aOutSz.Height() + (nPagesY>0 ? 1 : -1) * nOverlapY ); 570*cdf0e10cSrcweir } 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir 573