LibreOffice Module vcl (master)  1
slider.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <vcl/event.hxx>
21 #include <vcl/decoview.hxx>
22 #include <vcl/slider.hxx>
23 #include <vcl/settings.hxx>
24 
25 #include "thumbpos.hxx"
26 
27 #define SLIDER_STATE_CHANNEL1_DOWN (sal_uInt16(0x0001))
28 #define SLIDER_STATE_CHANNEL2_DOWN (sal_uInt16(0x0002))
29 #define SLIDER_STATE_THUMB_DOWN (sal_uInt16(0x0004))
30 
31 #define SLIDER_THUMB_SIZE 9
32 #define SLIDER_CHANNEL_OFFSET 0
33 #define SLIDER_CHANNEL_SIZE 4
34 #define SLIDER_CHANNEL_HALFSIZE 2
35 
36 #define SLIDER_HEIGHT 16
37 
38 #define SLIDER_VIEW_STYLE (WB_3DLOOK | WB_HORZ | WB_VERT)
39 
40 void Slider::ImplInit( vcl::Window* pParent, WinBits nStyle )
41 {
42  mnThumbPixOffset = 0;
43  mnThumbPixRange = 0;
44  mnThumbPixPos = 0; // between mnThumbPixOffset and mnThumbPixOffset+mnThumbPixRange
48  mnChannelPixTop = 0;
50 
51  mnMinRange = 0;
52  mnMaxRange = 100;
53  mnThumbPos = 0;
54  mnLineSize = 1;
55  mnPageSize = 1;
56  mnStateFlags = 0;
58  mbCalcSize = true;
59  mbScrollTypeSet = false;
60 
61  mpLinkedField = nullptr;
62 
63  Control::ImplInit( pParent, nStyle, nullptr );
64 
67 }
68 
69 Slider::Slider( vcl::Window* pParent, WinBits nStyle ) :
71 {
72  ImplInit( pParent, nStyle );
73 }
74 
76 {
77  disposeOnce();
78 }
79 
81 {
84 }
85 
87 {
88  vcl::Window* pParent = GetParent();
90  {
93  SetPaintTransparent( true );
94  SetBackground();
95  }
96  else
97  {
100  SetPaintTransparent( false );
101 
102  if ( IsControlBackground() )
104  else
105  SetBackground( pParent->GetBackground() );
106  }
107 }
108 
109 void Slider::ImplUpdateRects( bool bUpdate )
110 {
111  tools::Rectangle aOldThumbRect = maThumbRect;
112  bool bInvalidateAll = false;
113 
114  if ( mnThumbPixRange )
115  {
116  if ( GetStyle() & WB_HORZ )
117  {
121  {
126  }
127  else
130  {
135  }
136  else
138 
139  const tools::Rectangle aControlRegion(tools::Rectangle(Point(), Size(mnThumbSize, 10)));
140  tools::Rectangle aThumbBounds, aThumbContent;
142  aControlRegion, ControlState::NONE, ImplControlValue(),
143  aThumbBounds, aThumbContent ) )
144  {
145  maThumbRect.SetLeft( mnThumbPixPos - aThumbBounds.GetWidth()/2 );
146  maThumbRect.SetRight( maThumbRect.Left() + aThumbBounds.GetWidth() - 1 );
147  bInvalidateAll = true;
148  }
149  }
150  else
151  {
155  {
160  }
161  else
164  {
169  }
170  else
172 
173  const tools::Rectangle aControlRegion(tools::Rectangle(Point(), Size(10, mnThumbSize)));
174  tools::Rectangle aThumbBounds, aThumbContent;
176  aControlRegion, ControlState::NONE, ImplControlValue(),
177  aThumbBounds, aThumbContent ) )
178  {
179  maThumbRect.SetTop( mnThumbPixPos - aThumbBounds.GetHeight()/2 );
180  maThumbRect.SetBottom( maThumbRect.Top() + aThumbBounds.GetHeight() - 1 );
181  bInvalidateAll = true;
182  }
183  }
184  }
185  else
186  {
190  }
191 
192  if ( bUpdate )
193  {
194  if ( aOldThumbRect != maThumbRect )
195  {
196  if( bInvalidateAll )
198  else
199  {
200  vcl::Region aInvalidRegion( aOldThumbRect );
201  aInvalidRegion.Union( maThumbRect );
202 
203  if( !IsBackground() && GetParent() )
204  {
205  const Point aPos( GetPosPixel() );
206  aInvalidRegion.Move( aPos.X(), aPos.Y() );
208  }
209  else
210  Invalidate( aInvalidRegion );
211  }
212  }
213  }
214 }
215 
217 {
218  if (mpLinkedField)
220 }
221 
222 long Slider::ImplCalcThumbPos( long nPixPos )
223 {
224  // calculate position
225  long nCalcThumbPos;
226  nCalcThumbPos = ImplMulDiv( nPixPos-mnThumbPixOffset, mnMaxRange-mnMinRange, mnThumbPixRange-1 );
227  nCalcThumbPos += mnMinRange;
228  return nCalcThumbPos;
229 }
230 
232 {
233  // calculate position
234  long nCalcThumbPos;
235  nCalcThumbPos = ImplMulDiv( nPos-mnMinRange, mnThumbPixRange-1, mnMaxRange-mnMinRange );
236  // at the beginning and end we try to display Slider correctly
237  if ( !nCalcThumbPos && (mnThumbPos > mnMinRange) )
238  nCalcThumbPos = 1;
239  if ( nCalcThumbPos &&
240  (nCalcThumbPos == mnThumbPixRange-1) &&
241  (mnThumbPos < mnMaxRange) )
242  nCalcThumbPos--;
243  return nCalcThumbPos+mnThumbPixOffset;
244 }
245 
246 void Slider::ImplCalc( bool bUpdate )
247 {
248  bool bInvalidateAll = false;
249 
250  if (mbCalcSize)
251  {
252  if (GetStyle() & WB_HORZ)
253  {
254  const tools::Rectangle aControlRegion(tools::Rectangle(Point(), Size(SLIDER_THUMB_SIZE, 10)));
255  tools::Rectangle aThumbBounds, aThumbContent;
257  aControlRegion, ControlState::NONE, ImplControlValue(),
258  aThumbBounds, aThumbContent))
259  {
260  mnThumbSize = aThumbBounds.GetWidth();
261  }
262  else
263  {
265  }
266  }
267  else
268  {
269  const tools::Rectangle aControlRegion(tools::Rectangle(Point(), Size(10, SLIDER_THUMB_SIZE)));
270  tools::Rectangle aThumbBounds, aThumbContent;
272  aControlRegion, ControlState::NONE, ImplControlValue(),
273  aThumbBounds, aThumbContent))
274  {
275  mnThumbSize = aThumbBounds.GetHeight();
276  }
277  else
278  {
280  }
281  }
282 
283  long nOldChannelPixOffset = mnChannelPixOffset;
284  long nOldChannelPixRange = mnChannelPixRange;
285  long nOldChannelPixTop = mnChannelPixTop;
286  long nOldChannelPixBottom = mnChannelPixBottom;
287  long nCalcWidth;
288  long nCalcHeight;
289 
293 
294  Size aSize = GetOutputSizePixel();
295  if ( GetStyle() & WB_HORZ )
296  {
297  nCalcWidth = aSize.Width();
298  nCalcHeight = aSize.Height();
299  maThumbRect.SetTop( 0 );
300  maThumbRect.SetBottom( aSize.Height()-1 );
301  }
302  else
303  {
304  nCalcWidth = aSize.Height();
305  nCalcHeight = aSize.Width();
306  maThumbRect.SetLeft( 0 );
307  maThumbRect.SetRight( aSize.Width()-1 );
308  }
309 
310  if (nCalcWidth >= mnThumbSize)
311  {
313  mnThumbPixRange = nCalcWidth - mnThumbSize;
314  mnThumbPixPos = 0;
316  mnChannelPixRange = nCalcWidth-(SLIDER_CHANNEL_OFFSET*2);
317  mnChannelPixTop = (nCalcHeight/2)-SLIDER_CHANNEL_HALFSIZE;
318  mnChannelPixBottom = mnChannelPixTop+SLIDER_CHANNEL_SIZE-1;
319  }
320  else
321  {
322  mnThumbPixRange = 0;
323  mnChannelPixRange = 0;
324  }
325 
326  if ( (nOldChannelPixOffset != mnChannelPixOffset) ||
327  (nOldChannelPixRange != mnChannelPixRange) ||
328  (nOldChannelPixTop != mnChannelPixTop) ||
329  (nOldChannelPixBottom != mnChannelPixBottom) )
330  bInvalidateAll = true;
331 
332  mbCalcSize = false;
333  }
334 
335  if ( mnThumbPixRange )
337 
338  if ( bUpdate && bInvalidateAll )
339  {
340  Invalidate();
341  bUpdate = false;
342  }
343  ImplUpdateRects( bUpdate );
344 }
345 
347 {
348  // do missing calculations
349  if (mbCalcSize)
350  ImplCalc(false);
351 
353 
354  if (rRenderContext.IsNativeControlSupported(ControlType::Slider, nPart))
355  {
358 
359  SliderValue aSliderValue;
360  aSliderValue.mnMin = mnMinRange;
361  aSliderValue.mnMax = mnMaxRange;
362  aSliderValue.mnCur = mnThumbPos;
363  aSliderValue.maThumbRect = maThumbRect;
364 
365  if (IsMouseOver())
366  {
368  aSliderValue.mnThumbState |= ControlState::ROLLOVER;
369  }
370 
371  const tools::Rectangle aCtrlRegion(Point(0,0), GetOutputSizePixel());
372 
373  if (rRenderContext.DrawNativeControl(ControlType::Slider, nPart, aCtrlRegion, nState, aSliderValue, OUString()))
374  return;
375  }
376 
377  DecorationView aDecoView(&rRenderContext);
378  DrawButtonFlags nStyle;
379  const StyleSettings& rStyleSettings = rRenderContext.GetSettings().GetStyleSettings();
380  bool bEnabled = IsEnabled();
381 
382  if (!maChannel1Rect.IsEmpty())
383  {
384  long nRectSize;
386  rRenderContext.SetLineColor(rStyleSettings.GetShadowColor());
387  if (GetStyle() & WB_HORZ)
388  {
389  rRenderContext.DrawLine(aRect.TopLeft(), Point(aRect.Left(), aRect.Bottom() - 1));
390  rRenderContext.DrawLine(aRect.TopLeft(), aRect.TopRight());
391  }
392  else
393  {
394  rRenderContext.DrawLine(aRect.TopLeft(), Point(aRect.Right() - 1, aRect.Top()));
395  rRenderContext.DrawLine(aRect.TopLeft(), aRect.BottomLeft());
396  }
397  rRenderContext.SetLineColor(rStyleSettings.GetLightColor());
398  if (GetStyle() & WB_HORZ)
399  {
400  rRenderContext.DrawLine(aRect.BottomLeft(), aRect.BottomRight());
401  nRectSize = aRect.GetWidth();
402  }
403  else
404  {
405  rRenderContext.DrawLine(aRect.TopRight(), aRect.BottomRight());
406  nRectSize = aRect.GetHeight();
407  }
408 
409  if (nRectSize > 1)
410  {
411  aRect.AdjustLeft( 1 );
412  aRect.AdjustTop( 1 );
413  if (GetStyle() & WB_HORZ)
414  aRect.AdjustBottom( -1 );
415  else
416  aRect.AdjustRight( -1 );
417  rRenderContext.SetLineColor();
419  rRenderContext.SetFillColor(rStyleSettings.GetShadowColor());
420  else
421  rRenderContext.SetFillColor(rStyleSettings.GetCheckedColor());
422  rRenderContext.DrawRect(aRect);
423  }
424  }
425 
426  if (!maChannel2Rect.IsEmpty())
427  {
428  long nRectSize;
430  rRenderContext.SetLineColor(rStyleSettings.GetLightColor());
431  if (GetStyle() & WB_HORZ)
432  {
433  rRenderContext.DrawLine(aRect.TopRight(), aRect.BottomRight());
434  rRenderContext.DrawLine(aRect.BottomLeft(), aRect.BottomRight());
435  nRectSize = aRect.GetWidth();
436  }
437  else
438  {
439  rRenderContext.DrawLine(aRect.BottomLeft(), aRect.BottomRight());
440  rRenderContext.DrawLine(aRect.TopRight(), aRect.BottomRight());
441  nRectSize = aRect.GetHeight();
442  }
443 
444  if (nRectSize > 1)
445  {
446  rRenderContext.SetLineColor(rStyleSettings.GetShadowColor());
447  if (GetStyle() & WB_HORZ)
448  rRenderContext.DrawLine(aRect.TopLeft(), Point(aRect.Right() - 1, aRect.Top()));
449  else
450  rRenderContext.DrawLine(aRect.TopLeft(), Point(aRect.Left(), aRect.Bottom() - 1));
451 
452  aRect.AdjustRight( -1 );
453  aRect.AdjustBottom( -1 );
454  if (GetStyle() & WB_HORZ)
455  aRect.AdjustTop( 1 );
456  else
457  aRect.AdjustLeft( 1 );
458  rRenderContext.SetLineColor();
460  rRenderContext.SetFillColor(rStyleSettings.GetShadowColor());
461  else
462  rRenderContext.SetFillColor(rStyleSettings.GetCheckedColor());
463  rRenderContext.DrawRect(aRect);
464  }
465  }
466 
467  if (!maThumbRect.IsEmpty())
468  {
469  if (bEnabled)
470  {
471  nStyle = DrawButtonFlags::NONE;
473  nStyle |= DrawButtonFlags::Pressed;
474  aDecoView.DrawButton(maThumbRect, nStyle);
475  }
476  else
477  {
478  rRenderContext.SetLineColor(rStyleSettings.GetShadowColor());
479  rRenderContext.SetFillColor(rStyleSettings.GetCheckedColor());
480  rRenderContext.DrawRect(maThumbRect);
481  }
482  }
483 }
484 
485 bool Slider::ImplIsPageUp( const Point& rPos )
486 {
487  Size aSize = GetOutputSizePixel();
489  if ( GetStyle() & WB_HORZ )
490  {
491  aRect.SetTop( 0 );
492  aRect.SetBottom( aSize.Height()-1 );
493  }
494  else
495  {
496  aRect.SetLeft( 0 );
497  aRect.SetRight( aSize.Width()-1 );
498  }
499  return aRect.IsInside( rPos );
500 }
501 
502 bool Slider::ImplIsPageDown( const Point& rPos )
503 {
504  Size aSize = GetOutputSizePixel();
506  if ( GetStyle() & WB_HORZ )
507  {
508  aRect.SetTop( 0 );
509  aRect.SetBottom( aSize.Height()-1 );
510  }
511  else
512  {
513  aRect.SetLeft( 0 );
514  aRect.SetRight( aSize.Width()-1 );
515  }
516  return aRect.IsInside( rPos );
517 }
518 
519 long Slider::ImplSlide( long nNewPos, bool bCallEndSlide )
520 {
521  long nOldPos = mnThumbPos;
522  SetThumbPos( nNewPos );
523  long nDelta = mnThumbPos-nOldPos;
524  if ( nDelta )
525  {
526  Slide();
527  if ( bCallEndSlide )
528  EndSlide();
529  }
530  return nDelta;
531 }
532 
533 long Slider::ImplDoAction( bool bCallEndSlide )
534 {
535  long nDelta = 0;
536 
537  switch ( meScrollType )
538  {
539  case ScrollType::LineUp:
540  nDelta = ImplSlide( mnThumbPos-mnLineSize, bCallEndSlide );
541  break;
542 
544  nDelta = ImplSlide( mnThumbPos+mnLineSize, bCallEndSlide );
545  break;
546 
547  case ScrollType::PageUp:
548  nDelta = ImplSlide( mnThumbPos-mnPageSize, bCallEndSlide );
549  break;
550 
552  nDelta = ImplSlide( mnThumbPos+mnPageSize, bCallEndSlide );
553  break;
554 
555  case ScrollType::Set:
556  nDelta = ImplSlide( ImplCalcThumbPos( GetPointerPosPixel().X() ), bCallEndSlide );
557  break;
558  default:
559  break;
560  }
561 
562  return nDelta;
563 }
564 
565 void Slider::ImplDoMouseAction( const Point& rMousePos, bool bCallAction )
566 {
567  sal_uInt16 nOldStateFlags = mnStateFlags;
568  bool bAction = false;
569 
570  switch ( meScrollType )
571  {
572  case ScrollType::Set:
573  {
574  const bool bUp = ImplIsPageUp( rMousePos ), bDown = ImplIsPageDown( rMousePos );
575 
576  if ( bUp || bDown )
577  {
578  bAction = bCallAction;
580  }
581  else
583  break;
584  }
585 
586  case ScrollType::PageUp:
587  if ( ImplIsPageUp( rMousePos ) )
588  {
589  bAction = bCallAction;
591  }
592  else
594  break;
595 
597  if ( ImplIsPageDown( rMousePos ) )
598  {
599  bAction = bCallAction;
601  }
602  else
604  break;
605  default:
606  break;
607  }
608 
609  if ( bAction )
610  {
611  if ( ImplDoAction( false ) )
612  {
613  Update();
614  Invalidate();
615  }
616  }
617  else if ( nOldStateFlags != mnStateFlags )
618  {
619  Invalidate();
620  }
621 }
622 
623 void Slider::ImplDoSlide( long nNewPos )
624 {
626  return;
627 
629  ImplSlide( nNewPos, true );
631 }
632 
634 {
636  (eScrollType == ScrollType::DontKnow) ||
637  (eScrollType == ScrollType::Drag) )
638  return;
639 
640  meScrollType = eScrollType;
641  ImplDoAction( true );
643 }
644 
646 {
647  if ( rMEvt.IsLeft() )
648  {
649  const Point& rMousePos = rMEvt.GetPosPixel();
651 
652  if ( maThumbRect.IsInside( rMousePos ) )
653  {
655 
656  // calculate additional values
657  Point aCenterPos = maThumbRect.Center();
658  if ( GetStyle() & WB_HORZ )
659  mnMouseOff = rMousePos.X()-aCenterPos.X();
660  else
661  mnMouseOff = rMousePos.Y()-aCenterPos.Y();
662  }
663  else if ( ImplIsPageUp( rMousePos ) )
664  {
665  if( mbScrollTypeSet )
667  else
668  {
669  nTrackFlags = StartTrackingFlags::ButtonRepeat;
671  }
672  }
673  else if ( ImplIsPageDown( rMousePos ) )
674  {
675  if( mbScrollTypeSet )
677  else
678  {
679  nTrackFlags = StartTrackingFlags::ButtonRepeat;
681  }
682  }
683 
684  // Shall we start Tracking?
686  {
687  // store Start position for cancel and EndScroll delta
690  Update();
691 
693  StartTracking( nTrackFlags );
694  }
695  }
696 }
697 
699 {
701  {
702  // reset Button and PageRect state
703  const sal_uInt16 nOldStateFlags = mnStateFlags;
704 
706 
707  if ( nOldStateFlags != mnStateFlags )
708  {
710  }
711  ImplDoAction( true );
713  }
714 }
715 
716 void Slider::Tracking( const TrackingEvent& rTEvt )
717 {
718  if ( rTEvt.IsTrackingEnded() )
719  {
720  // reset Button and PageRect state
721  sal_uInt16 nOldStateFlags = mnStateFlags;
724  if ( nOldStateFlags != mnStateFlags )
725  {
727  }
728 
729  // on cancel, reset the previous Thumb position
730  if ( rTEvt.IsTrackingCanceled() )
731  {
733  Slide();
734  }
735 
737  {
738  // after dragging, recalculate to a rounded Thumb position
739  ImplCalc();
740  Update();
741  }
742 
743  EndSlide();
745  }
746  else
747  {
748  const Point rMousePos = rTEvt.GetMouseEvent().GetPosPixel();
749 
750  // special handling for dragging
752  {
753  long nMovePix;
754  Point aCenterPos = maThumbRect.Center();
755  if ( GetStyle() & WB_HORZ )
756  nMovePix = rMousePos.X()-(aCenterPos.X()+mnMouseOff);
757  else
758  nMovePix = rMousePos.Y()-(aCenterPos.Y()+mnMouseOff);
759  // only if the mouse moves in Scroll direction we have to act
760  if ( nMovePix )
761  {
762  mnThumbPixPos += nMovePix;
767  long nOldPos = mnThumbPos;
769  if ( nOldPos != mnThumbPos )
770  {
771  ImplUpdateRects();
772  Update();
774  if ( nOldPos != mnThumbPos )
775  {
776  Slide();
777  }
778  }
779  }
780  }
781  else
782  ImplDoMouseAction( rMousePos, rTEvt.IsTrackingRepeat() );
783 
784  // end tracking if ScrollBar values indicate we are done
785  if ( !IsVisible() )
786  EndTracking();
787  }
788 }
789 
790 void Slider::KeyInput( const KeyEvent& rKEvt )
791 {
792  if ( !rKEvt.GetKeyCode().GetModifier() )
793  {
794  switch ( rKEvt.GetKeyCode().GetCode() )
795  {
796  case KEY_HOME:
798  break;
799  case KEY_END:
801  break;
802 
803  case KEY_LEFT:
804  case KEY_UP:
806  break;
807 
808  case KEY_RIGHT:
809  case KEY_DOWN:
811  break;
812 
813  case KEY_PAGEUP:
815  break;
816 
817  case KEY_PAGEDOWN:
819  break;
820 
821  default:
822  Control::KeyInput( rKEvt );
823  break;
824  }
825  }
826  else
827  Control::KeyInput( rKEvt );
828 }
829 
830 void Slider::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
831 {
832  ImplDraw(rRenderContext);
833 }
834 
836 {
837  Control::Resize();
838  mbCalcSize = true;
839  if ( IsReallyVisible() )
840  ImplCalc( false );
842 }
843 
844 IMPL_LINK_NOARG(Slider, LinkedFieldModifyHdl, Edit&, void)
845 {
846  if (mpLinkedField)
847  SetThumbPos(mpLinkedField->GetValue());
848 }
849 
851 {
852  Control::StateChanged( nType );
853 
854  if ( nType == StateChangedType::InitShow )
855  ImplCalc( false );
856  else if ( nType == StateChangedType::Data )
857  {
858  if ( IsReallyVisible() && IsUpdateMode() )
859  ImplCalc();
860  }
861  else if ( nType == StateChangedType::UpdateMode )
862  {
863  if ( IsReallyVisible() && IsUpdateMode() )
864  {
865  ImplCalc( false );
866  Invalidate();
867  }
868  }
869  else if ( nType == StateChangedType::Enable )
870  {
871  if ( IsReallyVisible() && IsUpdateMode() )
872  {
873  Invalidate();
874  }
875  }
876  else if ( nType == StateChangedType::Style )
877  {
878  if ( IsReallyVisible() && IsUpdateMode() )
879  {
880  if ( (GetPrevStyle() & SLIDER_VIEW_STYLE) !=
882  {
883  mbCalcSize = true;
884  ImplCalc( false );
885  Invalidate();
886  }
887  }
888  }
889  else if ( nType == StateChangedType::ControlBackground )
890  {
892  Invalidate();
893  }
894 }
895 
897 {
898  Control::DataChanged( rDCEvt );
899 
900  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
901  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
902  {
904  Invalidate();
905  }
906 }
907 
909 {
910  maSlideHdl.Call( this );
911 }
912 
914 {
915  maEndSlideHdl.Call( this );
916 }
917 
918 void Slider::SetRangeMin(long nNewRange)
919 {
920  SetRange(Range(nNewRange, GetRangeMax()));
921 }
922 
923 void Slider::SetRangeMax(long nNewRange)
924 {
925  SetRange(Range(GetRangeMin(), nNewRange));
926 }
927 
928 void Slider::SetRange( const Range& rRange )
929 {
930  // adjust Range
931  Range aRange = rRange;
932  aRange.Justify();
933  long nNewMinRange = aRange.Min();
934  long nNewMaxRange = aRange.Max();
935 
936  // reset Range if different
937  if ( (mnMinRange != nNewMinRange) ||
938  (mnMaxRange != nNewMaxRange) )
939  {
940  mnMinRange = nNewMinRange;
941  mnMaxRange = nNewMaxRange;
942 
943  // adjust Thumb
944  if ( mnThumbPos > mnMaxRange )
946  if ( mnThumbPos < mnMinRange )
950  }
951 }
952 
953 void Slider::SetThumbPos( long nNewThumbPos )
954 {
955  if ( nNewThumbPos < mnMinRange )
956  nNewThumbPos = mnMinRange;
957  if ( nNewThumbPos > mnMaxRange )
958  nNewThumbPos = mnMaxRange;
959 
960  if ( mnThumbPos != nNewThumbPos )
961  {
962  mnThumbPos = nNewThumbPos;
965  }
966 }
967 
969 {
970  long nWidth = mnMaxRange - mnMinRange + mnThumbSize + 1;
971  long nHeight = SLIDER_HEIGHT;
972  Size aSize;
973  if ( GetStyle() & WB_HORZ )
974  {
975  aSize.setWidth( nWidth );
976  aSize.setHeight( nHeight );
977  }
978  else
979  {
980  aSize.setHeight( nWidth );
981  aSize.setWidth( nHeight );
982  }
983  return aSize;
984 }
985 
986 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long mnStartPos
Definition: slider.hxx:34
virtual Point GetPosPixel() const
Definition: window.cxx:2806
Point TopLeft() const
#define SLIDER_THUMB_SIZE
Definition: slider.cxx:31
long Width() const
const Color & GetShadowColor() const
bool IsControlBackground() const
Definition: window2.cxx:1081
long GetWidth() const
Point GetPointerPosPixel()
Definition: mouse.cxx:548
const Wallpaper & GetBackground() const
Definition: outdev.hxx:631
virtual void KeyInput(const KeyEvent &rKEvt) override
Definition: slider.cxx:790
long GetHeight() const
bool DrawNativeControl(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, const OUString &aCaption)
Request rendering of a particular control and/or part.
long mnLineSize
Definition: slider.hxx:47
bool GetNativeControlRegion(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, tools::Rectangle &rNativeBoundingRegion, tools::Rectangle &rNativeContentRegion) const
Query the native control's actual drawing region (including adornment)
long GetRangeMin() const
Definition: slider.hxx:96
long ImplMulDiv(long nNumber, long nNumerator, long nDenominator)
Definition: thumbpos.hxx:13
#define KEY_PAGEDOWN
Definition: keycodes.hxx:117
StartTrackingFlags
Definition: window.hxx:283
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
Definition: slider.cxx:645
long Height() const
#define KEY_PAGEUP
Definition: keycodes.hxx:116
Point BottomLeft() const
void Union(const tools::Rectangle &rRegion)
Definition: region.cxx:508
bool IsBackground() const
Definition: outdev.hxx:633
long AdjustLeft(long nHorzMoveDelta)
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: slider.cxx:80
SAL_DLLPRIVATE void ImplDraw(vcl::RenderContext &rRenderContext)
Definition: slider.cxx:346
const StyleSettings & GetStyleSettings() const
#define SLIDER_CHANNEL_SIZE
Definition: slider.cxx:33
Link< Slider *, void > maSlideHdl
Definition: slider.hxx:56
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
void SetRange(const Range &rRange)
Definition: slider.cxx:928
long mnThumbPixPos
Definition: slider.hxx:38
virtual void SetSizePixel(const Size &rNewSize)
Definition: window2.cxx:1256
void CompatStateChanged(StateChangedType nStateChange)
Definition: window.cxx:3730
SAL_DLLPRIVATE void ImplCalc(bool bUpdate=true)
Definition: slider.cxx:246
sal_uInt16 GetCode() const
Definition: keycod.hxx:53
void SetParentClipMode(ParentClipMode nMode=ParentClipMode::NONE)
SAL_DLLPRIVATE long ImplCalcThumbPos(long nPixPos)
Definition: slider.cxx:222
SAL_DLLPRIVATE void ImplUpdateLinkedField()
Definition: slider.cxx:216
WinBits GetPrevStyle() const
Definition: window2.cxx:952
DataChangedEventType GetType() const
Definition: event.hxx:348
DrawButtonFlags
Definition: decoview.hxx:78
const Color & GetControlBackground() const
Definition: window2.cxx:1076
tools::Rectangle DrawButton(const tools::Rectangle &rRect, DrawButtonFlags nStyle)
Definition: decoview.cxx:942
virtual void StateChanged(StateChangedType nType) override
Definition: slider.cxx:850
#define KEY_LEFT
Definition: keycodes.hxx:112
void SetRangeMin(long nNewRange)
Definition: slider.cxx:918
void StartTracking(StartTrackingFlags nFlags=StartTrackingFlags::NONE)
Definition: window2.cxx:244
bool IsNativeControlSupported(ControlType nType, ControlPart nPart) const
Query the platform layer for control support.
long mnMouseOff
Definition: slider.hxx:35
long AdjustBottom(long nVertMoveDelta)
virtual void Resize() override
Definition: slider.cxx:835
bool IsTrackingRepeat() const
Definition: event.hxx:252
bool IsEmpty() const
StateChangedType
Definition: window.hxx:309
sal_Int64 WinBits
void SetBackground()
long Right() const
void SetThumbPos(long nThumbPos)
Definition: slider.cxx:953
SAL_DLLPRIVATE void ImplDoSlideAction(ScrollType eScrollType)
Definition: slider.cxx:633
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: slider.cxx:40
#define X
Definition: field.cxx:1015
void EndTracking(TrackingEventFlags nFlags=TrackingEventFlags::NONE)
Definition: window2.cxx:272
AllSettingsFlags GetFlags() const
Definition: event.hxx:349
const Color & GetLightColor() const
sal_uInt16 GetModifier() const
Definition: keycod.hxx:56
long Top() const
SAL_DLLPRIVATE void ImplDoMouseAction(const Point &rPos, bool bCallAction)
Definition: slider.cxx:565
void Move(long nHorzMove, long nVertMove)
Definition: region.cxx:414
Definition: edit.hxx:58
void DrawLine(const Point &rStartPt, const Point &rEndPt)
Definition: line.cxx:88
ScrollType meScrollType
Definition: slider.hxx:50
bool IsChildTransparentModeEnabled() const
Definition: window2.cxx:1021
long mnPageSize
Definition: slider.hxx:48
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:32
void Update()
Definition: paint.cxx:1273
long GetRangeMax() const
Definition: slider.hxx:98
void Justify()
Point BottomRight() const
void SetLineColor()
VclPtr< NumericField > mpLinkedField
Definition: slider.hxx:54
void clear()
Definition: vclptr.hxx:190
tools::Rectangle maChannel1Rect
Definition: slider.hxx:31
void SetTop(long v)
IMPL_LINK_NOARG(Slider, LinkedFieldModifyHdl, Edit &, void)
Definition: slider.cxx:844
void Slide()
Definition: slider.cxx:908
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: slider.cxx:896
Size CalcWindowSizePixel()
Definition: slider.cxx:968
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1153
long mnMinRange
Definition: slider.hxx:44
virtual void MouseButtonUp(const MouseEvent &rMEvt) override
Definition: slider.cxx:698
SAL_DLLPRIVATE bool ImplIsPageUp(const Point &rPos)
Definition: slider.cxx:485
ScrollType
Definition: scrbar.hxx:28
void SetRight(long v)
bool IsUpdateMode() const
Definition: window2.cxx:1167
#define SLIDER_VIEW_STYLE
Definition: slider.cxx:38
void SetFillColor()
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
#define SLIDER_STATE_THUMB_DOWN
Definition: slider.cxx:29
long Bottom() const
long mnThumbPixOffset
Definition: slider.hxx:36
#define SLIDER_STATE_CHANNEL2_DOWN
Definition: slider.cxx:28
bool IsInside(const Point &rPOINT) const
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ctrl.cxx:59
const AllSettings & GetSettings() const
Definition: outdev.hxx:420
void SetPaintTransparent(bool bTransparent)
Definition: paint.cxx:1015
Slider(vcl::Window *pParent, WinBits nStyle)
Definition: slider.cxx:69
Size GetOutputSizePixel() const
Definition: outdev.hxx:441
long mnChannelPixRange
Definition: slider.hxx:41
const Color & GetCheckedColor() const
vcl::Window * GetParent() const
Definition: window2.cxx:1091
long mnThumbPos
Definition: slider.hxx:46
long X() const
tools::Rectangle maThumbRect
bool IsTrackingEnded() const
Definition: event.hxx:254
SAL_DLLPRIVATE void ImplDoSlide(long nNewPos)
Definition: slider.cxx:623
#define KEY_END
Definition: keycodes.hxx:115
#define SLIDER_STATE_CHANNEL1_DOWN
Definition: slider.cxx:27
virtual void KeyInput(const KeyEvent &rKEvt)
Definition: window.cxx:1767
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:930
long Max() const
const vcl::KeyCode & GetKeyCode() const
Definition: event.hxx:53
long mnThumbPixRange
Definition: slider.hxx:37
SAL_DLLPRIVATE long ImplCalcThumbPosPix(long nPos)
Definition: slider.cxx:231
bool IsMouseOver() const
Definition: mouse.cxx:604
virtual void Resize() override
Definition: ctrl.cxx:74
#define KEY_DOWN
Definition: keycodes.hxx:110
long AdjustRight(long nHorzMoveDelta)
WindowType
Definition: ctrl.hxx:33
SAL_DLLPRIVATE void ImplUpdateRects(bool bUpdate=true)
Definition: slider.cxx:109
ControlState mnThumbState
bool IsVisible() const
Definition: window2.cxx:1096
void EnableChildTransparentMode(bool bEnable=true)
Definition: window2.cxx:1016
bool IsLeft() const
Definition: event.hxx:133
SAL_DLLPRIVATE void ImplInitSettings()
Definition: slider.cxx:86
void SetBottom(long v)
long mnThumbSize
Definition: slider.hxx:39
long AdjustTop(long nVertMoveDelta)
SAL_DLLPRIVATE bool ImplIsPageDown(const Point &rPos)
Definition: slider.cxx:502
long mnChannelPixTop
Definition: slider.hxx:42
void EndSlide()
Definition: slider.cxx:913
long mnMaxRange
Definition: slider.hxx:45
#define SLIDER_CHANNEL_OFFSET
Definition: slider.cxx:32
const Point & GetPosPixel() const
Definition: event.hxx:117
long Left() const
tools::Rectangle maThumbRect
Definition: slider.hxx:33
virtual void Tracking(const TrackingEvent &rTEvt) override
Definition: slider.cxx:716
bool mbScrollTypeSet
Definition: slider.hxx:52
#define KEY_HOME
Definition: keycodes.hxx:114
#define SLIDER_HEIGHT
Definition: slider.cxx:36
bool IsEnabled() const
Definition: window2.cxx:1116
Link< Slider *, void > maEndSlideHdl
Definition: slider.hxx:57
void SetLeft(long v)
bool IsTrackingCanceled() const
Definition: event.hxx:256
WinBits GetStyle() const
Definition: window2.cxx:947
SAL_DLLPRIVATE long ImplSlide(long nNewPos, bool bCallEndSlide)
Definition: slider.cxx:519
long Min() const
SAL_DLLPRIVATE long ImplDoAction(bool bCallEndSlide)
Definition: slider.cxx:533
const MouseEvent & GetMouseEvent() const
Definition: event.hxx:250
bool IsReallyVisible() const
Definition: window2.cxx:1101
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: slider.cxx:830
tools::Rectangle maChannel2Rect
Definition: slider.hxx:32
WinBits const WB_HORZ
bool HasFocus() const
Definition: window.cxx:2985
sal_uInt16 mnStateFlags
Definition: slider.hxx:49
void setWidth(long nWidth)
virtual ~Slider() override
Definition: slider.cxx:75
#define SLIDER_CHANNEL_HALFSIZE
Definition: slider.cxx:34
long mnChannelPixOffset
Definition: slider.hxx:40
Point TopRight() const
#define KEY_RIGHT
Definition: keycodes.hxx:113
virtual void SetValue(sal_Int64 nNewValue)
Definition: field.cxx:537
Point Center() const
long Y() const
bool mbCalcSize
Definition: slider.hxx:51
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35
long mnChannelPixBottom
Definition: slider.hxx:43
#define KEY_UP
Definition: keycodes.hxx:111
void SetRangeMax(long nNewRange)
Definition: slider.cxx:923
void setHeight(long nHeight)