1f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5f6e50924SAndrew Rist * distributed with this work for additional information 6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14f6e50924SAndrew Rist * software distributed under the License is distributed on an 15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17f6e50924SAndrew Rist * specific language governing permissions and limitations 18f6e50924SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20f6e50924SAndrew Rist *************************************************************/ 21f6e50924SAndrew Rist 22f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svx.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir // include --------------------------------------------------------------- 28cdf0e10cSrcweir #include <svx/zoomsliderctrl.hxx> 29cdf0e10cSrcweir #ifndef _STATUS_HXX //autogen 30cdf0e10cSrcweir #include <vcl/status.hxx> 31cdf0e10cSrcweir #endif 32cdf0e10cSrcweir #ifndef _MENU_HXX //autogen 33cdf0e10cSrcweir #include <vcl/menu.hxx> 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir #include <vcl/image.hxx> 36cdf0e10cSrcweir #include <svx/zoomslideritem.hxx> 37cdf0e10cSrcweir #include <svx/dialmgr.hxx> 38cdf0e10cSrcweir #include <svx/dialogs.hrc> 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <set> 41cdf0e10cSrcweir 42cdf0e10cSrcweir // ----------------------------------------------------------------------- 43cdf0e10cSrcweir 44cdf0e10cSrcweir SFX_IMPL_STATUSBAR_CONTROL( SvxZoomSliderControl, SvxZoomSliderItem ); 45cdf0e10cSrcweir 46cdf0e10cSrcweir // ----------------------------------------------------------------------- 47cdf0e10cSrcweir 48cdf0e10cSrcweir struct SvxZoomSliderControl::SvxZoomSliderControl_Impl 49cdf0e10cSrcweir { 50cdf0e10cSrcweir sal_uInt16 mnCurrentZoom; 51cdf0e10cSrcweir sal_uInt16 mnMinZoom; 52cdf0e10cSrcweir sal_uInt16 mnMaxZoom; 53cdf0e10cSrcweir sal_uInt16 mnSliderCenter; 54cdf0e10cSrcweir std::vector< long > maSnappingPointOffsets; 55cdf0e10cSrcweir std::vector< sal_uInt16 > maSnappingPointZooms; 56cdf0e10cSrcweir Image maSliderButton; 57cdf0e10cSrcweir Image maIncreaseButton; 58cdf0e10cSrcweir Image maDecreaseButton; 59cdf0e10cSrcweir bool mbValuesSet; 60cdf0e10cSrcweir bool mbOmitPaint; 61cdf0e10cSrcweir 62cdf0e10cSrcweir SvxZoomSliderControl_Impl() : 63cdf0e10cSrcweir mnCurrentZoom( 0 ), 64cdf0e10cSrcweir mnMinZoom( 0 ), 65cdf0e10cSrcweir mnMaxZoom( 0 ), 66cdf0e10cSrcweir mnSliderCenter( 0 ), 67cdf0e10cSrcweir maSnappingPointOffsets(), 68cdf0e10cSrcweir maSnappingPointZooms(), 69cdf0e10cSrcweir maSliderButton(), 70cdf0e10cSrcweir maIncreaseButton(), 71cdf0e10cSrcweir maDecreaseButton(), 72cdf0e10cSrcweir mbValuesSet( false ), 73cdf0e10cSrcweir mbOmitPaint( false ) {} 74cdf0e10cSrcweir }; 75cdf0e10cSrcweir 76cdf0e10cSrcweir // ----------------------------------------------------------------------- 77cdf0e10cSrcweir 78cdf0e10cSrcweir const long nButtonWidth = 10; 79cdf0e10cSrcweir const long nButtonHeight = 10; 80cdf0e10cSrcweir const long nIncDecWidth = 11; 81cdf0e10cSrcweir const long nIncDecHeight = 11; 82cdf0e10cSrcweir const long nSliderHeight = 2; 83cdf0e10cSrcweir const long nSnappingHeight = 4; 84cdf0e10cSrcweir const long nSliderXOffset = 20; 85cdf0e10cSrcweir const long nSnappingEpsilon = 5; // snapping epsilon in pixels 86cdf0e10cSrcweir const long nSnappingPointsMinDist = nSnappingEpsilon; // minimum distance of two adjacent snapping points 87cdf0e10cSrcweir 88cdf0e10cSrcweir // ----------------------------------------------------------------------- 89cdf0e10cSrcweir 90*07662b26Smseidel // nOffset refers to the origin of the control: 91cdf0e10cSrcweir // + ----------- - 92cdf0e10cSrcweir sal_uInt16 SvxZoomSliderControl::Offset2Zoom( long nOffset ) const 93cdf0e10cSrcweir { 94cdf0e10cSrcweir const long nControlWidth = getControlRect().GetWidth(); 95cdf0e10cSrcweir sal_uInt16 nRet = 0; 96cdf0e10cSrcweir 97cdf0e10cSrcweir if ( nOffset < nSliderXOffset ) 98cdf0e10cSrcweir return mpImpl->mnMinZoom;; 99cdf0e10cSrcweir 100cdf0e10cSrcweir if ( nOffset > nControlWidth - nSliderXOffset ) 101cdf0e10cSrcweir return mpImpl->mnMaxZoom; 102cdf0e10cSrcweir 103cdf0e10cSrcweir // check for snapping points: 104cdf0e10cSrcweir sal_uInt16 nCount = 0; 105cdf0e10cSrcweir std::vector< long >::iterator aSnappingPointIter; 106cdf0e10cSrcweir for ( aSnappingPointIter = mpImpl->maSnappingPointOffsets.begin(); 107cdf0e10cSrcweir aSnappingPointIter != mpImpl->maSnappingPointOffsets.end(); 108cdf0e10cSrcweir ++aSnappingPointIter ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir const long nCurrent = *aSnappingPointIter; 111cdf0e10cSrcweir if ( Abs(nCurrent - nOffset) < nSnappingEpsilon ) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir nOffset = nCurrent; 114cdf0e10cSrcweir nRet = mpImpl->maSnappingPointZooms[ nCount ]; 115cdf0e10cSrcweir break; 116cdf0e10cSrcweir } 117cdf0e10cSrcweir ++nCount; 118cdf0e10cSrcweir } 119cdf0e10cSrcweir 120cdf0e10cSrcweir if ( 0 == nRet ) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir if ( nOffset < nControlWidth / 2 ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir // first half of slider 125cdf0e10cSrcweir const long nFirstHalfRange = mpImpl->mnSliderCenter - mpImpl->mnMinZoom; 126cdf0e10cSrcweir const long nHalfSliderWidth = nControlWidth/2 - nSliderXOffset; 127cdf0e10cSrcweir const long nZoomPerSliderPixel = (1000 * nFirstHalfRange) / nHalfSliderWidth; 128cdf0e10cSrcweir const long nOffsetToSliderLeft = nOffset - nSliderXOffset; 129cdf0e10cSrcweir nRet = mpImpl->mnMinZoom + sal_uInt16( nOffsetToSliderLeft * nZoomPerSliderPixel / 1000 ); 130cdf0e10cSrcweir } 131cdf0e10cSrcweir else 132cdf0e10cSrcweir { 133cdf0e10cSrcweir // second half of slider 134cdf0e10cSrcweir const long nSecondHalfRange = mpImpl->mnMaxZoom - mpImpl->mnSliderCenter; 135cdf0e10cSrcweir const long nHalfSliderWidth = nControlWidth/2 - nSliderXOffset; 136cdf0e10cSrcweir const long nZoomPerSliderPixel = 1000 * nSecondHalfRange / nHalfSliderWidth; 137cdf0e10cSrcweir const long nOffsetToSliderCenter = nOffset - nControlWidth/2; 138cdf0e10cSrcweir nRet = mpImpl->mnSliderCenter + sal_uInt16( nOffsetToSliderCenter * nZoomPerSliderPixel / 1000 ); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir } 141cdf0e10cSrcweir 142cdf0e10cSrcweir if ( nRet < mpImpl->mnMinZoom ) 143cdf0e10cSrcweir nRet = mpImpl->mnMinZoom; 144cdf0e10cSrcweir else if ( nRet > mpImpl->mnMaxZoom ) 145cdf0e10cSrcweir nRet = mpImpl->mnMaxZoom; 146cdf0e10cSrcweir 147cdf0e10cSrcweir return nRet; 148cdf0e10cSrcweir } 149cdf0e10cSrcweir 150cdf0e10cSrcweir // returns the offset to the left control border 151cdf0e10cSrcweir long SvxZoomSliderControl::Zoom2Offset( sal_uInt16 nCurrentZoom ) const 152cdf0e10cSrcweir { 153cdf0e10cSrcweir const long nControlWidth = getControlRect().GetWidth(); 154cdf0e10cSrcweir long nRet = nSliderXOffset; 155cdf0e10cSrcweir 156cdf0e10cSrcweir const long nHalfSliderWidth = nControlWidth/2 - nSliderXOffset; 157cdf0e10cSrcweir 158cdf0e10cSrcweir if ( nCurrentZoom <= mpImpl->mnSliderCenter ) 159cdf0e10cSrcweir { 160cdf0e10cSrcweir nCurrentZoom = nCurrentZoom - mpImpl->mnMinZoom; 161cdf0e10cSrcweir const long nFirstHalfRange = mpImpl->mnSliderCenter - mpImpl->mnMinZoom; 162cdf0e10cSrcweir const long nSliderPixelPerZoomPercent = 1000 * nHalfSliderWidth / nFirstHalfRange; 163cdf0e10cSrcweir const long nOffset = (nSliderPixelPerZoomPercent * nCurrentZoom) / 1000; 164cdf0e10cSrcweir nRet += nOffset; 165cdf0e10cSrcweir } 166cdf0e10cSrcweir else 167cdf0e10cSrcweir { 168cdf0e10cSrcweir nCurrentZoom = nCurrentZoom - mpImpl->mnSliderCenter; 169cdf0e10cSrcweir const long nSecondHalfRange = mpImpl->mnMaxZoom - mpImpl->mnSliderCenter; 170cdf0e10cSrcweir const long nSliderPixelPerZoomPercent = 1000 * nHalfSliderWidth / nSecondHalfRange; 171cdf0e10cSrcweir const long nOffset = (nSliderPixelPerZoomPercent * nCurrentZoom) / 1000; 172cdf0e10cSrcweir nRet += nHalfSliderWidth + nOffset; 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir return nRet; 176cdf0e10cSrcweir } 177cdf0e10cSrcweir 178cdf0e10cSrcweir // ----------------------------------------------------------------------- 179cdf0e10cSrcweir 180cdf0e10cSrcweir SvxZoomSliderControl::SvxZoomSliderControl( sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& _rStb ) : 181cdf0e10cSrcweir SfxStatusBarControl( _nSlotId, _nId, _rStb ), 182cdf0e10cSrcweir mpImpl( new SvxZoomSliderControl_Impl ) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir const sal_Bool bHC = GetStatusBar().GetSettings().GetStyleSettings().GetHighContrastMode(); 185cdf0e10cSrcweir mpImpl->maSliderButton = Image( SVX_RES( bHC ? RID_SVXBMP_SLIDERBUTTON_HC : RID_SVXBMP_SLIDERBUTTON ) ); 186cdf0e10cSrcweir mpImpl->maIncreaseButton = Image( SVX_RES( bHC ? RID_SVXBMP_SLIDERINCREASE_HC : RID_SVXBMP_SLIDERINCREASE ) ); 187cdf0e10cSrcweir mpImpl->maDecreaseButton = Image( SVX_RES( bHC ? RID_SVXBMP_SLIDERDECREASE_HC : RID_SVXBMP_SLIDERDECREASE ) ); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir // ----------------------------------------------------------------------- 191cdf0e10cSrcweir 192cdf0e10cSrcweir SvxZoomSliderControl::~SvxZoomSliderControl() 193cdf0e10cSrcweir { 194cdf0e10cSrcweir delete mpImpl; 195cdf0e10cSrcweir } 196cdf0e10cSrcweir 197cdf0e10cSrcweir // ----------------------------------------------------------------------- 198cdf0e10cSrcweir 199cdf0e10cSrcweir void SvxZoomSliderControl::StateChanged( sal_uInt16 /*nSID*/, SfxItemState eState, const SfxPoolItem* pState ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir if ( (SFX_ITEM_AVAILABLE != eState) || pState->ISA( SfxVoidItem ) ) 202cdf0e10cSrcweir { 203cdf0e10cSrcweir GetStatusBar().SetItemText( GetId(), String() ); 204cdf0e10cSrcweir mpImpl->mbValuesSet = false; 205cdf0e10cSrcweir } 206cdf0e10cSrcweir else 207cdf0e10cSrcweir { 208cdf0e10cSrcweir OSL_ENSURE( pState->ISA( SvxZoomSliderItem ), "invalid item type: should be a SvxZoomSliderItem" ); 209cdf0e10cSrcweir mpImpl->mnCurrentZoom = static_cast<const SvxZoomSliderItem*>( pState )->GetValue(); 210cdf0e10cSrcweir mpImpl->mnMinZoom = static_cast<const SvxZoomSliderItem*>( pState )->GetMinZoom(); 211cdf0e10cSrcweir mpImpl->mnMaxZoom = static_cast<const SvxZoomSliderItem*>( pState )->GetMaxZoom(); 212cdf0e10cSrcweir mpImpl->mnSliderCenter= 100; 213cdf0e10cSrcweir mpImpl->mbValuesSet = true; 214cdf0e10cSrcweir 215cdf0e10cSrcweir if ( mpImpl->mnSliderCenter == mpImpl->mnMaxZoom ) 216cdf0e10cSrcweir mpImpl->mnSliderCenter = mpImpl->mnMinZoom + (sal_uInt16)((mpImpl->mnMaxZoom - mpImpl->mnMinZoom) * 0.5); 217cdf0e10cSrcweir 218cdf0e10cSrcweir 219cdf0e10cSrcweir DBG_ASSERT( mpImpl->mnMinZoom <= mpImpl->mnCurrentZoom && 220cdf0e10cSrcweir mpImpl->mnMinZoom < mpImpl->mnSliderCenter && 221cdf0e10cSrcweir mpImpl->mnMaxZoom >= mpImpl->mnCurrentZoom && 222cdf0e10cSrcweir mpImpl->mnMaxZoom > mpImpl->mnSliderCenter, 223cdf0e10cSrcweir "Looks like the zoom slider item is corrupted" ); 224cdf0e10cSrcweir 225cdf0e10cSrcweir const com::sun::star::uno::Sequence < sal_Int32 > rSnappingPoints = static_cast<const SvxZoomSliderItem*>( pState )->GetSnappingPoints(); 226cdf0e10cSrcweir mpImpl->maSnappingPointOffsets.clear(); 227cdf0e10cSrcweir mpImpl->maSnappingPointZooms.clear(); 228cdf0e10cSrcweir 229cdf0e10cSrcweir // get all snapping points: 230cdf0e10cSrcweir std::set< sal_uInt16 > aTmpSnappingPoints; 231cdf0e10cSrcweir for ( sal_uInt16 j = 0; j < rSnappingPoints.getLength(); ++j ) 232cdf0e10cSrcweir { 233cdf0e10cSrcweir const sal_Int32 nSnappingPoint = rSnappingPoints[j]; 234cdf0e10cSrcweir aTmpSnappingPoints.insert( (sal_uInt16)nSnappingPoint ); 235cdf0e10cSrcweir } 236cdf0e10cSrcweir 237cdf0e10cSrcweir // remove snapping points that are to close to each other: 238cdf0e10cSrcweir std::set< sal_uInt16 >::iterator aSnappingPointIter; 239cdf0e10cSrcweir long nLastOffset = 0; 240cdf0e10cSrcweir 241cdf0e10cSrcweir for ( aSnappingPointIter = aTmpSnappingPoints.begin(); aSnappingPointIter != aTmpSnappingPoints.end(); ++aSnappingPointIter ) 242cdf0e10cSrcweir { 243cdf0e10cSrcweir const sal_uInt16 nCurrent = *aSnappingPointIter; 244cdf0e10cSrcweir const long nCurrentOffset = Zoom2Offset( nCurrent ); 245cdf0e10cSrcweir 246cdf0e10cSrcweir if ( nCurrentOffset - nLastOffset >= nSnappingPointsMinDist ) 247cdf0e10cSrcweir { 248cdf0e10cSrcweir mpImpl->maSnappingPointOffsets.push_back( nCurrentOffset ); 249cdf0e10cSrcweir mpImpl->maSnappingPointZooms.push_back( nCurrent ); 250cdf0e10cSrcweir nLastOffset = nCurrentOffset; 251cdf0e10cSrcweir } 252cdf0e10cSrcweir } 253cdf0e10cSrcweir } 254cdf0e10cSrcweir 255cdf0e10cSrcweir if ( !mpImpl->mbOmitPaint && GetStatusBar().AreItemsVisible() ) 256cdf0e10cSrcweir GetStatusBar().SetItemData( GetId(), 0 ); // force repaint 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir // ----------------------------------------------------------------------- 260cdf0e10cSrcweir 261cdf0e10cSrcweir void SvxZoomSliderControl::Paint( const UserDrawEvent& rUsrEvt ) 262cdf0e10cSrcweir { 263cdf0e10cSrcweir if ( !mpImpl->mbValuesSet || mpImpl->mbOmitPaint ) 264cdf0e10cSrcweir return; 265cdf0e10cSrcweir 266cdf0e10cSrcweir const Rectangle aControlRect = getControlRect(); 267cdf0e10cSrcweir OutputDevice* pDev = rUsrEvt.GetDevice(); 268cdf0e10cSrcweir Rectangle aRect = rUsrEvt.GetRect(); 269cdf0e10cSrcweir Rectangle aSlider = aRect; 270cdf0e10cSrcweir 271cdf0e10cSrcweir aSlider.Top() += (aControlRect.GetHeight() - nSliderHeight)/2 - 1; 272cdf0e10cSrcweir aSlider.Bottom() = aSlider.Top() + nSliderHeight; 273cdf0e10cSrcweir aSlider.Left() += nSliderXOffset; 274cdf0e10cSrcweir aSlider.Right() -= nSliderXOffset; 275cdf0e10cSrcweir 276cdf0e10cSrcweir Color aOldLineColor = pDev->GetLineColor(); 277cdf0e10cSrcweir Color aOldFillColor = pDev->GetFillColor(); 278cdf0e10cSrcweir 279cdf0e10cSrcweir pDev->SetLineColor( Color( COL_GRAY ) ); 280cdf0e10cSrcweir pDev->SetFillColor( Color( COL_GRAY ) ); 281cdf0e10cSrcweir 282cdf0e10cSrcweir // draw snapping points: 283cdf0e10cSrcweir std::vector< long >::iterator aSnappingPointIter; 284cdf0e10cSrcweir for ( aSnappingPointIter = mpImpl->maSnappingPointOffsets.begin(); 285cdf0e10cSrcweir aSnappingPointIter != mpImpl->maSnappingPointOffsets.end(); 286cdf0e10cSrcweir ++aSnappingPointIter ) 287cdf0e10cSrcweir { 288cdf0e10cSrcweir Rectangle aSnapping( aRect ); 289cdf0e10cSrcweir aSnapping.Bottom() = aSlider.Top(); 290cdf0e10cSrcweir aSnapping.Top() = aSnapping.Bottom() - nSnappingHeight; 291cdf0e10cSrcweir aSnapping.Left() += *aSnappingPointIter; 292cdf0e10cSrcweir aSnapping.Right() = aSnapping.Left(); 293cdf0e10cSrcweir pDev->DrawRect( aSnapping ); 294cdf0e10cSrcweir 295cdf0e10cSrcweir aSnapping.Top() += nSnappingHeight + nSliderHeight; 296cdf0e10cSrcweir aSnapping.Bottom() += nSnappingHeight + nSliderHeight; 297cdf0e10cSrcweir pDev->DrawRect( aSnapping ); 298cdf0e10cSrcweir } 299cdf0e10cSrcweir 300cdf0e10cSrcweir // draw slider 301cdf0e10cSrcweir Rectangle aFirstLine( aSlider ); 302cdf0e10cSrcweir aFirstLine.Bottom() = aFirstLine.Top(); 303cdf0e10cSrcweir 304cdf0e10cSrcweir Rectangle aSecondLine( aSlider ); 305cdf0e10cSrcweir aSecondLine.Top() = aSecondLine.Bottom(); 306cdf0e10cSrcweir 307cdf0e10cSrcweir Rectangle aLeft( aSlider ); 308cdf0e10cSrcweir aLeft.Right() = aLeft.Left(); 309cdf0e10cSrcweir 310cdf0e10cSrcweir Rectangle aRight( aSlider ); 311cdf0e10cSrcweir aRight.Left() = aRight.Right(); 312cdf0e10cSrcweir 313c7124341SMatthias Seidel pDev->SetLineColor( Color ( COL_GRAY ) ); 314c7124341SMatthias Seidel pDev->SetFillColor( Color ( COL_GRAY ) ); 315cdf0e10cSrcweir pDev->DrawRect( aSecondLine ); 316cdf0e10cSrcweir pDev->DrawRect( aRight ); 317cdf0e10cSrcweir 318cdf0e10cSrcweir pDev->SetLineColor( Color( COL_GRAY ) ); 319cdf0e10cSrcweir pDev->SetFillColor( Color( COL_GRAY ) ); 320cdf0e10cSrcweir pDev->DrawRect( aFirstLine ); 321cdf0e10cSrcweir pDev->DrawRect( aLeft ); 322cdf0e10cSrcweir 323cdf0e10cSrcweir // draw slider button 324cdf0e10cSrcweir Point aImagePoint = aRect.TopLeft(); 325cdf0e10cSrcweir aImagePoint.X() += Zoom2Offset( mpImpl->mnCurrentZoom ); 326cdf0e10cSrcweir aImagePoint.X() -= nButtonWidth/2; 327cdf0e10cSrcweir aImagePoint.Y() += (aControlRect.GetHeight() - nButtonHeight)/2; 328cdf0e10cSrcweir pDev->DrawImage( aImagePoint, mpImpl->maSliderButton ); 329cdf0e10cSrcweir 330cdf0e10cSrcweir // draw decrease button 331cdf0e10cSrcweir aImagePoint = aRect.TopLeft(); 332cdf0e10cSrcweir aImagePoint.X() += (nSliderXOffset - nIncDecWidth)/2; 333cdf0e10cSrcweir aImagePoint.Y() += (aControlRect.GetHeight() - nIncDecHeight)/2; 334cdf0e10cSrcweir pDev->DrawImage( aImagePoint, mpImpl->maDecreaseButton ); 335cdf0e10cSrcweir 336cdf0e10cSrcweir // draw increase button 337cdf0e10cSrcweir aImagePoint.X() = aRect.TopLeft().X() + aControlRect.GetWidth() - nIncDecWidth - (nSliderXOffset - nIncDecWidth)/2; 338cdf0e10cSrcweir pDev->DrawImage( aImagePoint, mpImpl->maIncreaseButton ); 339cdf0e10cSrcweir 340cdf0e10cSrcweir pDev->SetLineColor( aOldLineColor ); 341cdf0e10cSrcweir pDev->SetFillColor( aOldFillColor ); 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344cdf0e10cSrcweir // ----------------------------------------------------------------------- 345cdf0e10cSrcweir 346cdf0e10cSrcweir sal_Bool SvxZoomSliderControl::MouseButtonDown( const MouseEvent & rEvt ) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir if ( !mpImpl->mbValuesSet ) 349cdf0e10cSrcweir return sal_True;; 350cdf0e10cSrcweir 351cdf0e10cSrcweir const Rectangle aControlRect = getControlRect(); 352cdf0e10cSrcweir const Point aPoint = rEvt.GetPosPixel(); 353cdf0e10cSrcweir const sal_Int32 nXDiff = aPoint.X() - aControlRect.Left(); 354cdf0e10cSrcweir 355cdf0e10cSrcweir const long nButtonLeftOffset = (nSliderXOffset - nIncDecWidth)/2; 356cdf0e10cSrcweir const long nButtonRightOffset = (nSliderXOffset + nIncDecWidth)/2; 357cdf0e10cSrcweir 358cdf0e10cSrcweir const long nOldZoom = mpImpl->mnCurrentZoom; 359cdf0e10cSrcweir 360cdf0e10cSrcweir // click to - button 361cdf0e10cSrcweir if ( nXDiff >= nButtonLeftOffset && nXDiff <= nButtonRightOffset ) 362cdf0e10cSrcweir mpImpl->mnCurrentZoom = mpImpl->mnCurrentZoom - 5; 363cdf0e10cSrcweir // click to + button 364cdf0e10cSrcweir else if ( nXDiff >= aControlRect.GetWidth() - nSliderXOffset + nButtonLeftOffset && 365cdf0e10cSrcweir nXDiff <= aControlRect.GetWidth() - nSliderXOffset + nButtonRightOffset ) 366cdf0e10cSrcweir mpImpl->mnCurrentZoom = mpImpl->mnCurrentZoom + 5; 367cdf0e10cSrcweir // click to slider 368cdf0e10cSrcweir else if( nXDiff >= nSliderXOffset && nXDiff <= aControlRect.GetWidth() - nSliderXOffset ) 369cdf0e10cSrcweir mpImpl->mnCurrentZoom = Offset2Zoom( nXDiff ); 370cdf0e10cSrcweir 371cdf0e10cSrcweir if ( mpImpl->mnCurrentZoom < mpImpl->mnMinZoom ) 372cdf0e10cSrcweir mpImpl->mnCurrentZoom = mpImpl->mnMinZoom; 373cdf0e10cSrcweir else if ( mpImpl->mnCurrentZoom > mpImpl->mnMaxZoom ) 374cdf0e10cSrcweir mpImpl->mnCurrentZoom = mpImpl->mnMaxZoom; 375cdf0e10cSrcweir 376cdf0e10cSrcweir if ( nOldZoom == mpImpl->mnCurrentZoom ) 377cdf0e10cSrcweir return sal_True; 378cdf0e10cSrcweir 379cdf0e10cSrcweir if ( GetStatusBar().AreItemsVisible() ) 380cdf0e10cSrcweir GetStatusBar().SetItemData( GetId(), 0 ); // force repaint 381cdf0e10cSrcweir 382cdf0e10cSrcweir mpImpl->mbOmitPaint = true; // optimization: paint before executing command, 383cdf0e10cSrcweir // then omit painting which is triggered by the execute function 384cdf0e10cSrcweir 385cdf0e10cSrcweir SvxZoomSliderItem aZoomSliderItem( mpImpl->mnCurrentZoom ); 386cdf0e10cSrcweir 387cdf0e10cSrcweir ::com::sun::star::uno::Any a; 388cdf0e10cSrcweir aZoomSliderItem.QueryValue( a ); 389cdf0e10cSrcweir 390cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 ); 391cdf0e10cSrcweir aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZoomSlider" )); 392cdf0e10cSrcweir aArgs[0].Value = a; 393cdf0e10cSrcweir 394cdf0e10cSrcweir execute( aArgs ); 395cdf0e10cSrcweir 396cdf0e10cSrcweir mpImpl->mbOmitPaint = false; 397cdf0e10cSrcweir 398cdf0e10cSrcweir return sal_True; 399cdf0e10cSrcweir } 400cdf0e10cSrcweir 401cdf0e10cSrcweir // ----------------------------------------------------------------------- 402cdf0e10cSrcweir 403cdf0e10cSrcweir sal_Bool SvxZoomSliderControl::MouseMove( const MouseEvent & rEvt ) 404cdf0e10cSrcweir { 405cdf0e10cSrcweir if ( !mpImpl->mbValuesSet ) 406cdf0e10cSrcweir return sal_True;; 407cdf0e10cSrcweir 408cdf0e10cSrcweir const short nButtons = rEvt.GetButtons(); 409cdf0e10cSrcweir 410cdf0e10cSrcweir // check mouse move with button pressed 411cdf0e10cSrcweir if ( 1 == nButtons ) 412cdf0e10cSrcweir { 413cdf0e10cSrcweir const Rectangle aControlRect = getControlRect(); 414cdf0e10cSrcweir const Point aPoint = rEvt.GetPosPixel(); 415cdf0e10cSrcweir const sal_Int32 nXDiff = aPoint.X() - aControlRect.Left(); 416cdf0e10cSrcweir 417cdf0e10cSrcweir if ( nXDiff >= nSliderXOffset && nXDiff <= aControlRect.GetWidth() - nSliderXOffset ) 418cdf0e10cSrcweir { 419cdf0e10cSrcweir mpImpl->mnCurrentZoom = Offset2Zoom( nXDiff ); 420cdf0e10cSrcweir 421cdf0e10cSrcweir if ( GetStatusBar().AreItemsVisible() ) 422cdf0e10cSrcweir GetStatusBar().SetItemData( GetId(), 0 ); // force repaint 423cdf0e10cSrcweir 424cdf0e10cSrcweir mpImpl->mbOmitPaint = true; // optimization: paint before executing command, 425cdf0e10cSrcweir // then omit painting which is triggered by the execute function 426cdf0e10cSrcweir 427cdf0e10cSrcweir // commit state change 428cdf0e10cSrcweir SvxZoomSliderItem aZoomSliderItem( mpImpl->mnCurrentZoom ); 429cdf0e10cSrcweir 430cdf0e10cSrcweir ::com::sun::star::uno::Any a; 431cdf0e10cSrcweir aZoomSliderItem.QueryValue( a ); 432cdf0e10cSrcweir 433cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > aArgs( 1 ); 434cdf0e10cSrcweir aArgs[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ZoomSlider" )); 435cdf0e10cSrcweir aArgs[0].Value = a; 436cdf0e10cSrcweir 437cdf0e10cSrcweir execute( aArgs ); 438cdf0e10cSrcweir 439cdf0e10cSrcweir mpImpl->mbOmitPaint = false; 440cdf0e10cSrcweir } 441cdf0e10cSrcweir } 442cdf0e10cSrcweir 443cdf0e10cSrcweir return sal_True; 444cdf0e10cSrcweir } 445*07662b26Smseidel 446*07662b26Smseidel /* vim: set noet sw=4 ts=4: */ 447