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