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