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 #include "precompiled_sc.hxx" 28*cdf0e10cSrcweir #ifndef _SC_ZOOMSLIDERTBCONTRL_HXX 29*cdf0e10cSrcweir #include "tbzoomsliderctrl.hxx" 30*cdf0e10cSrcweir #endif 31*cdf0e10cSrcweir #ifndef _SV_IMAGE_HXX 32*cdf0e10cSrcweir #include <vcl/image.hxx> 33*cdf0e10cSrcweir #endif 34*cdf0e10cSrcweir #ifndef _SV_TOOLBOX_HXX 35*cdf0e10cSrcweir #include <vcl/toolbox.hxx> 36*cdf0e10cSrcweir #endif 37*cdf0e10cSrcweir #ifndef _SV_SVAPP_HXX 38*cdf0e10cSrcweir #include <vcl/svapp.hxx> 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir #ifndef _SV_GRADIENT_HXX 41*cdf0e10cSrcweir #include <vcl/gradient.hxx> 42*cdf0e10cSrcweir #endif 43*cdf0e10cSrcweir #include <svl/itemset.hxx> 44*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 45*cdf0e10cSrcweir #include <sfx2/objsh.hxx> 46*cdf0e10cSrcweir #include <svx/zoomslideritem.hxx> 47*cdf0e10cSrcweir #include <svx/dialmgr.hxx> 48*cdf0e10cSrcweir #include <svx/dialogs.hrc> 49*cdf0e10cSrcweir #include <set> 50*cdf0e10cSrcweir #include "docsh.hxx" 51*cdf0e10cSrcweir #include "stlpool.hxx" 52*cdf0e10cSrcweir #include "scitems.hxx" 53*cdf0e10cSrcweir #include "printfun.hxx" 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir //======================================================================== 56*cdf0e10cSrcweir // class ScZoomSliderControl --------------------------------------- 57*cdf0e10cSrcweir //======================================================================== 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir // ----------------------------------------------------------------------- 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir SFX_IMPL_TOOLBOX_CONTROL( ScZoomSliderControl, SvxZoomSliderItem ); 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir // ----------------------------------------------------------------------- 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir ScZoomSliderControl::ScZoomSliderControl( 66*cdf0e10cSrcweir sal_uInt16 nSlotId, 67*cdf0e10cSrcweir sal_uInt16 nId, 68*cdf0e10cSrcweir ToolBox& rTbx ) 69*cdf0e10cSrcweir :SfxToolBoxControl( nSlotId, nId, rTbx ) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir rTbx.Invalidate(); 72*cdf0e10cSrcweir } 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir // ----------------------------------------------------------------------- 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir __EXPORT ScZoomSliderControl::~ScZoomSliderControl() 77*cdf0e10cSrcweir { 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir } 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // ----------------------------------------------------------------------- 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir void ScZoomSliderControl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, 84*cdf0e10cSrcweir const SfxPoolItem* pState ) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir sal_uInt16 nId = GetId(); 87*cdf0e10cSrcweir ToolBox& rTbx = GetToolBox(); 88*cdf0e10cSrcweir ScZoomSliderWnd* pBox = (ScZoomSliderWnd*)(rTbx.GetItemWindow( nId )); 89*cdf0e10cSrcweir DBG_ASSERT( pBox ,"Control not found!" ); 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir if ( SFX_ITEM_AVAILABLE != eState || pState->ISA( SfxVoidItem ) ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir SvxZoomSliderItem aZoomSliderItem( 100 ); 94*cdf0e10cSrcweir pBox->Disable(); 95*cdf0e10cSrcweir pBox->UpdateFromItem( &aZoomSliderItem ); 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir else 98*cdf0e10cSrcweir { 99*cdf0e10cSrcweir pBox->Enable(); 100*cdf0e10cSrcweir DBG_ASSERT( pState->ISA( SvxZoomSliderItem ), "invalid item type" ); 101*cdf0e10cSrcweir const SvxZoomSliderItem* pZoomSliderItem = dynamic_cast< const SvxZoomSliderItem* >( pState ); 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir DBG_ASSERT( pZoomSliderItem, "Sc::ScZoomSliderControl::StateChanged(), wrong item type!" ); 104*cdf0e10cSrcweir if( pZoomSliderItem ) 105*cdf0e10cSrcweir pBox->UpdateFromItem( pZoomSliderItem ); 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir // ----------------------------------------------------------------------- 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir Window* ScZoomSliderControl::CreateItemWindow( Window *pParent ) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir // #i98000# Don't try to get a value via SfxViewFrame::Current here. 114*cdf0e10cSrcweir // The view's value is always notified via StateChanged later. 115*cdf0e10cSrcweir ScZoomSliderWnd* pSlider = new ScZoomSliderWnd( pParent, 116*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >( m_xFrame->getController(), 117*cdf0e10cSrcweir ::com::sun::star::uno::UNO_QUERY ), m_xFrame, 100 ); 118*cdf0e10cSrcweir return pSlider; 119*cdf0e10cSrcweir } 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir // ----------------------------------------------------------------------- 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir struct ScZoomSliderWnd::ScZoomSliderWnd_Impl 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir sal_uInt16 mnCurrentZoom; 126*cdf0e10cSrcweir sal_uInt16 mnMinZoom; 127*cdf0e10cSrcweir sal_uInt16 mnMaxZoom; 128*cdf0e10cSrcweir sal_uInt16 mnSliderCenter; 129*cdf0e10cSrcweir std::vector< long > maSnappingPointOffsets; 130*cdf0e10cSrcweir std::vector< sal_uInt16 > maSnappingPointZooms; 131*cdf0e10cSrcweir Image maSliderButton; 132*cdf0e10cSrcweir Image maIncreaseButton; 133*cdf0e10cSrcweir Image maDecreaseButton; 134*cdf0e10cSrcweir bool mbValuesSet; 135*cdf0e10cSrcweir bool mbOmitPaint; 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir ScZoomSliderWnd_Impl( sal_uInt16 nCurrentZoom ) : 138*cdf0e10cSrcweir mnCurrentZoom( nCurrentZoom ), 139*cdf0e10cSrcweir mnMinZoom( 10 ), 140*cdf0e10cSrcweir mnMaxZoom( 400 ), 141*cdf0e10cSrcweir mnSliderCenter( 100 ), 142*cdf0e10cSrcweir maSnappingPointOffsets(), 143*cdf0e10cSrcweir maSnappingPointZooms(), 144*cdf0e10cSrcweir maSliderButton(), 145*cdf0e10cSrcweir maIncreaseButton(), 146*cdf0e10cSrcweir maDecreaseButton(), 147*cdf0e10cSrcweir mbValuesSet( true ), 148*cdf0e10cSrcweir mbOmitPaint( false ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir }; 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // ----------------------------------------------------------------------- 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir const long nButtonWidth = 10; 157*cdf0e10cSrcweir const long nButtonHeight = 10; 158*cdf0e10cSrcweir const long nIncDecWidth = 11; 159*cdf0e10cSrcweir const long nIncDecHeight = 11; 160*cdf0e10cSrcweir const long nSliderHeight = 2; // 161*cdf0e10cSrcweir const long nSliderWidth = 4; // 162*cdf0e10cSrcweir const long nSnappingHeight = 4; 163*cdf0e10cSrcweir const long nSliderXOffset = 20; 164*cdf0e10cSrcweir const long nSnappingEpsilon = 5; // snapping epsilon in pixels 165*cdf0e10cSrcweir const long nSnappingPointsMinDist = nSnappingEpsilon; // minimum distance of two adjacent snapping points 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir // ----------------------------------------------------------------------- 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir sal_uInt16 ScZoomSliderWnd::Offset2Zoom( long nOffset ) const 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir Size aSliderWindowSize = GetOutputSizePixel(); 173*cdf0e10cSrcweir const long nControlWidth = aSliderWindowSize.Width(); 174*cdf0e10cSrcweir sal_uInt16 nRet = 0; 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir if( nOffset < nSliderXOffset ) 177*cdf0e10cSrcweir return mpImpl->mnMinZoom; 178*cdf0e10cSrcweir if( nOffset > nControlWidth - nSliderXOffset ) 179*cdf0e10cSrcweir return mpImpl->mnMaxZoom; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir // check for snapping points: 182*cdf0e10cSrcweir sal_uInt16 nCount = 0; 183*cdf0e10cSrcweir std::vector< long >::iterator aSnappingPointIter; 184*cdf0e10cSrcweir for ( aSnappingPointIter = mpImpl->maSnappingPointOffsets.begin(); 185*cdf0e10cSrcweir aSnappingPointIter != mpImpl->maSnappingPointOffsets.end(); 186*cdf0e10cSrcweir ++aSnappingPointIter ) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir const long nCurrent = *aSnappingPointIter; 189*cdf0e10cSrcweir if ( Abs(nCurrent - nOffset) < nSnappingEpsilon ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir nOffset = nCurrent; 192*cdf0e10cSrcweir nRet = mpImpl->maSnappingPointZooms[ nCount ]; 193*cdf0e10cSrcweir break; 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir ++nCount; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir if( 0 == nRet ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir if( nOffset < nControlWidth / 2 ) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir // first half of slider 203*cdf0e10cSrcweir const long nFirstHalfRange = mpImpl->mnSliderCenter - mpImpl->mnMinZoom; 204*cdf0e10cSrcweir const long nHalfSliderWidth = nControlWidth/2 - nSliderXOffset; 205*cdf0e10cSrcweir const long nZoomPerSliderPixel = (1000 * nFirstHalfRange) / nHalfSliderWidth; 206*cdf0e10cSrcweir const long nOffsetToSliderLeft = nOffset - nSliderXOffset; 207*cdf0e10cSrcweir nRet = mpImpl->mnMinZoom + sal_uInt16( nOffsetToSliderLeft * nZoomPerSliderPixel / 1000 ); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir else 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir // second half of slider 212*cdf0e10cSrcweir const long nSecondHalfRange = mpImpl->mnMaxZoom - mpImpl->mnSliderCenter; 213*cdf0e10cSrcweir const long nHalfSliderWidth = nControlWidth/2 - nSliderXOffset; 214*cdf0e10cSrcweir const long nZoomPerSliderPixel = 1000 * nSecondHalfRange / nHalfSliderWidth; 215*cdf0e10cSrcweir const long nOffsetToSliderCenter = nOffset - nControlWidth/2; 216*cdf0e10cSrcweir nRet = mpImpl->mnSliderCenter + sal_uInt16( nOffsetToSliderCenter * nZoomPerSliderPixel / 1000 ); 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir if( nRet < mpImpl->mnMinZoom ) 221*cdf0e10cSrcweir return mpImpl->mnMinZoom; 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir else if( nRet > mpImpl->mnMaxZoom ) 224*cdf0e10cSrcweir return mpImpl->mnMaxZoom; 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir return nRet; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir // ----------------------------------------------------------------------- 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir long ScZoomSliderWnd::Zoom2Offset( sal_uInt16 nCurrentZoom ) const 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir Size aSliderWindowSize = GetOutputSizePixel(); 234*cdf0e10cSrcweir const long nControlWidth = aSliderWindowSize.Width(); 235*cdf0e10cSrcweir long nRect = nSliderXOffset; 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir const long nHalfSliderWidth = nControlWidth/2 - nSliderXOffset; 238*cdf0e10cSrcweir if( nCurrentZoom <= mpImpl->mnSliderCenter ) 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir nCurrentZoom = nCurrentZoom - mpImpl->mnMinZoom; 241*cdf0e10cSrcweir const long nFirstHalfRange = mpImpl->mnSliderCenter - mpImpl->mnMinZoom; 242*cdf0e10cSrcweir const long nSliderPixelPerZoomPercent = 1000 * nHalfSliderWidth / nFirstHalfRange; 243*cdf0e10cSrcweir const long nOffset = (nSliderPixelPerZoomPercent * nCurrentZoom) / 1000; 244*cdf0e10cSrcweir nRect += nOffset; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir else 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir nCurrentZoom = nCurrentZoom - mpImpl->mnSliderCenter; 249*cdf0e10cSrcweir const long nSecondHalfRange = mpImpl->mnMaxZoom - mpImpl->mnSliderCenter; 250*cdf0e10cSrcweir const long nSliderPixelPerZoomPercent = 1000 * nHalfSliderWidth / nSecondHalfRange; 251*cdf0e10cSrcweir const long nOffset = (nSliderPixelPerZoomPercent * nCurrentZoom) / 1000; 252*cdf0e10cSrcweir nRect += nHalfSliderWidth + nOffset; 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir return nRect; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir // ----------------------------------------------------------------------- 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir ScZoomSliderWnd::ScZoomSliderWnd( Window* pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XDispatchProvider >& rDispatchProvider, 261*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& _xFrame , sal_uInt16 nCurrentZoom ): 262*cdf0e10cSrcweir Window( pParent ), 263*cdf0e10cSrcweir mpImpl( new ScZoomSliderWnd_Impl( nCurrentZoom ) ), 264*cdf0e10cSrcweir aLogicalSize( 115, 40 ), 265*cdf0e10cSrcweir m_xDispatchProvider( rDispatchProvider ), 266*cdf0e10cSrcweir m_xFrame( _xFrame ) 267*cdf0e10cSrcweir { 268*cdf0e10cSrcweir sal_Bool bIsHC = GetSettings().GetStyleSettings().GetHighContrastMode(); 269*cdf0e10cSrcweir mpImpl->maSliderButton = Image( SVX_RES( bIsHC ? RID_SVXBMP_SLIDERBUTTON_HC : RID_SVXBMP_SLIDERBUTTON ) ); 270*cdf0e10cSrcweir mpImpl->maIncreaseButton = Image( SVX_RES( bIsHC ? RID_SVXBMP_SLIDERINCREASE_HC : RID_SVXBMP_SLIDERINCREASE ) ); 271*cdf0e10cSrcweir mpImpl->maDecreaseButton = Image( SVX_RES( bIsHC ? RID_SVXBMP_SLIDERDECREASE_HC : RID_SVXBMP_SLIDERDECREASE ) ); 272*cdf0e10cSrcweir Size aSliderSize = LogicToPixel( Size( aLogicalSize), MapMode( MAP_10TH_MM ) ); 273*cdf0e10cSrcweir SetSizePixel( Size( aSliderSize.Width() * nSliderWidth-1, aSliderSize.Height() + nSliderHeight ) ); 274*cdf0e10cSrcweir } 275*cdf0e10cSrcweir 276*cdf0e10cSrcweir // ----------------------------------------------------------------------- 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir ScZoomSliderWnd::~ScZoomSliderWnd() 279*cdf0e10cSrcweir { 280*cdf0e10cSrcweir delete mpImpl; 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir // ----------------------------------------------------------------------- 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir void ScZoomSliderWnd::MouseButtonDown( const MouseEvent& rMEvt ) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir if ( !mpImpl->mbValuesSet ) 288*cdf0e10cSrcweir return ; 289*cdf0e10cSrcweir Size aSliderWindowSize = GetOutputSizePixel(); 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir const Point aPoint = rMEvt.GetPosPixel(); 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir const long nButtonLeftOffset = ( nSliderXOffset - nIncDecWidth )/2; 294*cdf0e10cSrcweir const long nButtonRightOffset = ( nSliderXOffset + nIncDecWidth )/2; 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir const long nOldZoom = mpImpl->mnCurrentZoom; 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir // click to - button 299*cdf0e10cSrcweir if ( aPoint.X() >= nButtonLeftOffset && aPoint.X() <= nButtonRightOffset ) 300*cdf0e10cSrcweir { 301*cdf0e10cSrcweir mpImpl->mnCurrentZoom = mpImpl->mnCurrentZoom - 5; 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir // click to + button 304*cdf0e10cSrcweir else if ( aPoint.X() >= aSliderWindowSize.Width() - nSliderXOffset + nButtonLeftOffset && 305*cdf0e10cSrcweir aPoint.X() <= aSliderWindowSize.Width() - nSliderXOffset + nButtonRightOffset ) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir mpImpl->mnCurrentZoom = mpImpl->mnCurrentZoom + 5; 308*cdf0e10cSrcweir } 309*cdf0e10cSrcweir else if( aPoint.X() >= nSliderXOffset && aPoint.X() <= aSliderWindowSize.Width() - nSliderXOffset ) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir mpImpl->mnCurrentZoom = Offset2Zoom( aPoint.X() ); 312*cdf0e10cSrcweir } 313*cdf0e10cSrcweir 314*cdf0e10cSrcweir if( mpImpl->mnCurrentZoom < mpImpl->mnMinZoom ) 315*cdf0e10cSrcweir mpImpl->mnCurrentZoom = mpImpl->mnMinZoom; 316*cdf0e10cSrcweir else if( mpImpl->mnCurrentZoom > mpImpl->mnMaxZoom ) 317*cdf0e10cSrcweir mpImpl->mnCurrentZoom = mpImpl->mnMaxZoom; 318*cdf0e10cSrcweir 319*cdf0e10cSrcweir if( nOldZoom == mpImpl->mnCurrentZoom ) 320*cdf0e10cSrcweir return ; 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir Rectangle aRect( Point( 0, 0 ), aSliderWindowSize ); 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir Paint( aRect ); 325*cdf0e10cSrcweir mpImpl->mbOmitPaint = true; 326*cdf0e10cSrcweir 327*cdf0e10cSrcweir SvxZoomSliderItem aZoomSliderItem( mpImpl->mnCurrentZoom ); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir ::com::sun::star::uno::Any a; 330*cdf0e10cSrcweir aZoomSliderItem.QueryValue( a ); 331*cdf0e10cSrcweir 332*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 ); 333*cdf0e10cSrcweir aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScalingFactor" )); 334*cdf0e10cSrcweir aArgs[0].Value = a; 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir SfxToolBoxControl::Dispatch( m_xDispatchProvider, String::CreateFromAscii(".uno:ScalingFactor"), aArgs ); 337*cdf0e10cSrcweir 338*cdf0e10cSrcweir mpImpl->mbOmitPaint = false; 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir 341*cdf0e10cSrcweir // ----------------------------------------------------------------------- 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir void ScZoomSliderWnd::MouseMove( const MouseEvent& rMEvt ) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir if ( !mpImpl->mbValuesSet ) 346*cdf0e10cSrcweir return ; 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir Size aSliderWindowSize = GetOutputSizePixel(); 349*cdf0e10cSrcweir const long nControlWidth = aSliderWindowSize.Width(); 350*cdf0e10cSrcweir const short nButtons = rMEvt.GetButtons(); 351*cdf0e10cSrcweir 352*cdf0e10cSrcweir // check mouse move with button pressed 353*cdf0e10cSrcweir if ( 1 == nButtons ) 354*cdf0e10cSrcweir { 355*cdf0e10cSrcweir const Point aPoint = rMEvt.GetPosPixel(); 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir if ( aPoint.X() >= nSliderXOffset && aPoint.X() <= nControlWidth - nSliderXOffset ) 358*cdf0e10cSrcweir { 359*cdf0e10cSrcweir mpImpl->mnCurrentZoom = Offset2Zoom( aPoint.X() ); 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir Rectangle aRect( Point( 0, 0 ), aSliderWindowSize ); 362*cdf0e10cSrcweir Paint( aRect ); 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir mpImpl->mbOmitPaint = true; // optimization: paint before executing command, 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir // commit state change 367*cdf0e10cSrcweir SvxZoomSliderItem aZoomSliderItem( mpImpl->mnCurrentZoom ); 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir ::com::sun::star::uno::Any a; 370*cdf0e10cSrcweir aZoomSliderItem.QueryValue( a ); 371*cdf0e10cSrcweir 372*cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 ); 373*cdf0e10cSrcweir aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ScalingFactor" )); 374*cdf0e10cSrcweir aArgs[0].Value = a; 375*cdf0e10cSrcweir 376*cdf0e10cSrcweir SfxToolBoxControl::Dispatch( m_xDispatchProvider, String::CreateFromAscii(".uno:ScalingFactor"), aArgs ); 377*cdf0e10cSrcweir 378*cdf0e10cSrcweir mpImpl->mbOmitPaint = false; 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir } 381*cdf0e10cSrcweir } 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir // ----------------------------------------------------------------------- 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir void ScZoomSliderWnd::UpdateFromItem( const SvxZoomSliderItem* pZoomSliderItem ) 386*cdf0e10cSrcweir { 387*cdf0e10cSrcweir if( pZoomSliderItem ) 388*cdf0e10cSrcweir { 389*cdf0e10cSrcweir mpImpl->mnCurrentZoom = pZoomSliderItem->GetValue(); 390*cdf0e10cSrcweir mpImpl->mnMinZoom = pZoomSliderItem->GetMinZoom(); 391*cdf0e10cSrcweir mpImpl->mnMaxZoom = pZoomSliderItem->GetMaxZoom(); 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir DBG_ASSERT( mpImpl->mnMinZoom <= mpImpl->mnCurrentZoom && 394*cdf0e10cSrcweir mpImpl->mnMinZoom < mpImpl->mnSliderCenter && 395*cdf0e10cSrcweir mpImpl->mnMaxZoom >= mpImpl->mnCurrentZoom && 396*cdf0e10cSrcweir mpImpl->mnMaxZoom > mpImpl->mnSliderCenter, 397*cdf0e10cSrcweir "Looks like the zoom slider item is corrupted" ); 398*cdf0e10cSrcweir const com::sun::star::uno::Sequence < sal_Int32 > rSnappingPoints = pZoomSliderItem->GetSnappingPoints(); 399*cdf0e10cSrcweir mpImpl->maSnappingPointOffsets.clear(); 400*cdf0e10cSrcweir mpImpl->maSnappingPointZooms.clear(); 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir // get all snapping points: 403*cdf0e10cSrcweir std::set< sal_uInt16 > aTmpSnappingPoints; 404*cdf0e10cSrcweir for ( sal_uInt16 j = 0; j < rSnappingPoints.getLength(); ++j ) 405*cdf0e10cSrcweir { 406*cdf0e10cSrcweir const sal_Int32 nSnappingPoint = rSnappingPoints[j]; 407*cdf0e10cSrcweir aTmpSnappingPoints.insert( (sal_uInt16)nSnappingPoint ); 408*cdf0e10cSrcweir } 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir // remove snapping points that are to close to each other: 411*cdf0e10cSrcweir std::set< sal_uInt16 >::iterator aSnappingPointIter; 412*cdf0e10cSrcweir long nLastOffset = 0; 413*cdf0e10cSrcweir 414*cdf0e10cSrcweir for ( aSnappingPointIter = aTmpSnappingPoints.begin(); aSnappingPointIter != aTmpSnappingPoints.end(); ++aSnappingPointIter ) 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir const sal_uInt16 nCurrent = *aSnappingPointIter; 417*cdf0e10cSrcweir const long nCurrentOffset = Zoom2Offset( nCurrent ); 418*cdf0e10cSrcweir 419*cdf0e10cSrcweir if ( nCurrentOffset - nLastOffset >= nSnappingPointsMinDist ) 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir mpImpl->maSnappingPointOffsets.push_back( nCurrentOffset ); 422*cdf0e10cSrcweir mpImpl->maSnappingPointZooms.push_back( nCurrent ); 423*cdf0e10cSrcweir nLastOffset = nCurrentOffset; 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir Size aSliderWindowSize = GetOutputSizePixel(); 429*cdf0e10cSrcweir Rectangle aRect( Point( 0, 0 ), aSliderWindowSize ); 430*cdf0e10cSrcweir 431*cdf0e10cSrcweir if ( !mpImpl->mbOmitPaint ) 432*cdf0e10cSrcweir Paint(aRect); 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir // ----------------------------------------------------------------------- 436*cdf0e10cSrcweir 437*cdf0e10cSrcweir void ScZoomSliderWnd::Paint( const Rectangle& rRect ) 438*cdf0e10cSrcweir { 439*cdf0e10cSrcweir DoPaint( rRect ); 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir // ----------------------------------------------------------------------- 443*cdf0e10cSrcweir 444*cdf0e10cSrcweir void ScZoomSliderWnd::DoPaint( const Rectangle& /*rRect*/ ) 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir if( mpImpl->mbOmitPaint ) 447*cdf0e10cSrcweir return; 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir Size aSliderWindowSize = GetOutputSizePixel(); 450*cdf0e10cSrcweir Rectangle aRect( Point( 0, 0 ), aSliderWindowSize ); 451*cdf0e10cSrcweir 452*cdf0e10cSrcweir VirtualDevice* pVDev = new VirtualDevice( *this ); 453*cdf0e10cSrcweir pVDev->SetOutputSizePixel( aSliderWindowSize ); 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir Rectangle aSlider = aRect; 456*cdf0e10cSrcweir 457*cdf0e10cSrcweir aSlider.Top() += ( aSliderWindowSize.Height() - nSliderHeight )/2 - 1; 458*cdf0e10cSrcweir aSlider.Bottom() = aSlider.Top() + nSliderHeight; 459*cdf0e10cSrcweir aSlider.Left() += nSliderXOffset; 460*cdf0e10cSrcweir aSlider.Right() -= nSliderXOffset; 461*cdf0e10cSrcweir 462*cdf0e10cSrcweir Rectangle aFirstLine( aSlider ); 463*cdf0e10cSrcweir aFirstLine.Bottom() = aFirstLine.Top(); 464*cdf0e10cSrcweir 465*cdf0e10cSrcweir Rectangle aSecondLine( aSlider ); 466*cdf0e10cSrcweir aSecondLine.Top() = aSecondLine.Bottom(); 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir Rectangle aLeft( aSlider ); 469*cdf0e10cSrcweir aLeft.Right() = aLeft.Left(); 470*cdf0e10cSrcweir 471*cdf0e10cSrcweir Rectangle aRight( aSlider ); 472*cdf0e10cSrcweir aRight.Left() = aRight.Right(); 473*cdf0e10cSrcweir 474*cdf0e10cSrcweir // draw VirtualDevice's background color 475*cdf0e10cSrcweir Color aStartColor,aEndColor; 476*cdf0e10cSrcweir aStartColor = GetSettings().GetStyleSettings().GetFaceColor(); 477*cdf0e10cSrcweir aEndColor = GetSettings().GetStyleSettings().GetFaceColor(); 478*cdf0e10cSrcweir if( aEndColor.IsDark() ) 479*cdf0e10cSrcweir aStartColor = aEndColor; 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir Gradient g; 482*cdf0e10cSrcweir g.SetAngle( 0 ); 483*cdf0e10cSrcweir g.SetStyle( GRADIENT_LINEAR ); 484*cdf0e10cSrcweir 485*cdf0e10cSrcweir g.SetStartColor( aStartColor ); 486*cdf0e10cSrcweir g.SetEndColor( aEndColor ); 487*cdf0e10cSrcweir pVDev->DrawGradient( aRect, g ); 488*cdf0e10cSrcweir 489*cdf0e10cSrcweir // draw slider 490*cdf0e10cSrcweir pVDev->SetLineColor( Color ( COL_WHITE ) ); 491*cdf0e10cSrcweir pVDev->DrawRect( aSecondLine ); 492*cdf0e10cSrcweir pVDev->DrawRect( aRight ); 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir pVDev->SetLineColor( Color( COL_GRAY ) ); 495*cdf0e10cSrcweir pVDev->DrawRect( aFirstLine ); 496*cdf0e10cSrcweir pVDev->DrawRect( aLeft ); 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir // draw snapping points: 499*cdf0e10cSrcweir std::vector< long >::iterator aSnappingPointIter; 500*cdf0e10cSrcweir for ( aSnappingPointIter = mpImpl->maSnappingPointOffsets.begin(); 501*cdf0e10cSrcweir aSnappingPointIter != mpImpl->maSnappingPointOffsets.end(); 502*cdf0e10cSrcweir ++aSnappingPointIter ) 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir pVDev->SetLineColor( Color( COL_GRAY ) ); 505*cdf0e10cSrcweir Rectangle aSnapping( aRect ); 506*cdf0e10cSrcweir aSnapping.Bottom() = aSlider.Top(); 507*cdf0e10cSrcweir aSnapping.Top() = aSnapping.Bottom() - nSnappingHeight; 508*cdf0e10cSrcweir aSnapping.Left() += *aSnappingPointIter; 509*cdf0e10cSrcweir aSnapping.Right() = aSnapping.Left(); 510*cdf0e10cSrcweir pVDev->DrawRect( aSnapping ); 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir aSnapping.Top() += nSnappingHeight + nSliderHeight; 513*cdf0e10cSrcweir aSnapping.Bottom() += nSnappingHeight + nSliderHeight; 514*cdf0e10cSrcweir pVDev->DrawRect( aSnapping ); 515*cdf0e10cSrcweir } 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir // draw slider button 518*cdf0e10cSrcweir Point aImagePoint = aRect.TopLeft(); 519*cdf0e10cSrcweir aImagePoint.X() += Zoom2Offset( mpImpl->mnCurrentZoom ); 520*cdf0e10cSrcweir aImagePoint.X() -= nButtonWidth/2; 521*cdf0e10cSrcweir aImagePoint.Y() += ( aSliderWindowSize.Height() - nButtonHeight)/2; 522*cdf0e10cSrcweir pVDev->DrawImage( aImagePoint, mpImpl->maSliderButton ); 523*cdf0e10cSrcweir 524*cdf0e10cSrcweir // draw decrease button 525*cdf0e10cSrcweir aImagePoint = aRect.TopLeft(); 526*cdf0e10cSrcweir aImagePoint.X() += (nSliderXOffset - nIncDecWidth)/2; 527*cdf0e10cSrcweir aImagePoint.Y() += ( aSliderWindowSize.Height() - nIncDecHeight)/2; 528*cdf0e10cSrcweir pVDev->DrawImage( aImagePoint, mpImpl->maDecreaseButton ); 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir // draw increase button 531*cdf0e10cSrcweir aImagePoint.X() = aRect.TopLeft().X() + aSliderWindowSize.Width() - nIncDecWidth - (nSliderXOffset - nIncDecWidth)/2; 532*cdf0e10cSrcweir pVDev->DrawImage( aImagePoint, mpImpl->maIncreaseButton ); 533*cdf0e10cSrcweir 534*cdf0e10cSrcweir DrawOutDev( Point(0, 0), aSliderWindowSize, Point(0, 0), aSliderWindowSize, *pVDev ); 535*cdf0e10cSrcweir 536*cdf0e10cSrcweir delete pVDev; 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir // ----------------------------------------------------------------------- 541