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