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