2 // System.Windows.Forms.ScrollBar.cs
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Copyright (C) 2004-2005, Novell, Inc.
26 // Jordi Mas i Hernandez jordi@ximian.com
33 using System.Drawing.Imaging;
34 using System.Drawing.Drawing2D;
35 using System.ComponentModel;
36 using System.Runtime.InteropServices;
38 namespace System.Windows.Forms
40 [DefaultEvent ("Scroll")]
41 [DefaultProperty ("Value")]
42 public abstract class ScrollBar : Control
44 #region Local Variables
48 private int large_change;
49 private int small_change;
50 internal int scrollbutton_height;
51 internal int scrollbutton_width;
52 private ScrollBars type;
53 private Rectangle first_arrow_area = new Rectangle (); // up or left
54 private Rectangle second_arrow_area = new Rectangle (); // down or right
55 private Rectangle thumb_pos = new Rectangle ();
56 private Rectangle thumb_area = new Rectangle ();
57 internal ButtonState firstbutton_state = ButtonState.Normal;
58 internal ButtonState secondbutton_state = ButtonState.Normal;
59 private bool firstbutton_pressed = false;
60 private bool secondbutton_pressed = false;
61 private bool thumb_pressed = false;
62 private float pixel_per_pos = 0;
63 private Timer timer = new Timer ();
64 private TimerType timer_type;
65 private int thumb_pixel_click_move;
66 private int thumb_pixel_click_move_prev;
67 private int thumb_size = 40;
68 private const int thumb_min_size = 8;
69 private const int thumb_notshown_size = 40;
71 private int lastclick_pos; // Position of the last button-down event
72 private int lastclick_pos_thumb; // Position of the last button-down event relative to the thumb
73 private bool outside_thumbarea_right = false;
74 private bool outside_thumbarea_left = false;
76 private Rectangle dirty;
78 internal ThumbMoving thumb_moving = ThumbMoving.None;
79 #endregion // Local Variables
81 private enum TimerType
89 internal enum ThumbMoving
99 [EditorBrowsable (EditorBrowsableState.Never)]
100 public new event EventHandler BackColorChanged;
103 [EditorBrowsable (EditorBrowsableState.Never)]
104 public new event EventHandler BackgroundImageChanged;
107 [EditorBrowsable (EditorBrowsableState.Never)]
108 public new event EventHandler Click;
111 [EditorBrowsable (EditorBrowsableState.Never)]
112 public new event EventHandler DoubleClick;
115 [EditorBrowsable (EditorBrowsableState.Never)]
116 public new event EventHandler FontChanged;
119 [EditorBrowsable (EditorBrowsableState.Never)]
120 public new event EventHandler ForeColorChanged;
123 [EditorBrowsable (EditorBrowsableState.Never)]
124 public new event EventHandler ImeModeChanged;
127 [EditorBrowsable (EditorBrowsableState.Never)]
128 public new event MouseEventHandler MouseDown;
131 [EditorBrowsable (EditorBrowsableState.Never)]
132 public new event MouseEventHandler MouseMove;
135 [EditorBrowsable (EditorBrowsableState.Never)]
136 public new event MouseEventHandler MouseUp;
139 [EditorBrowsable (EditorBrowsableState.Never)]
140 public new event PaintEventHandler Paint;
142 public event ScrollEventHandler Scroll;
145 [EditorBrowsable (EditorBrowsableState.Never)]
146 public new event EventHandler TextChanged;
148 public event EventHandler ValueChanged;
159 timer.Tick += new EventHandler (OnTimer);
160 base.KeyDown += new KeyEventHandler (OnKeyDownSB);
161 base.MouseDown += new MouseEventHandler (OnMouseDownSB);
162 base.MouseUp += new MouseEventHandler (OnMouseUpSB);
163 base.MouseMove += new MouseEventHandler (OnMouseMoveSB);
164 base.Resize += new EventHandler (OnResizeSB);
165 base.TabStop = false;
166 base.cursor = Cursors.Default;
168 SetStyle (ControlStyles.UserPaint | ControlStyles.StandardClick, false);
171 #region Internal & Private Properties
172 internal Rectangle FirstArrowArea {
174 return this.first_arrow_area;
178 this.first_arrow_area = value;
182 internal Rectangle SecondArrowArea {
184 return this.second_arrow_area;
188 this.second_arrow_area = value;
192 internal Rectangle ThumbPos {
201 #endregion // Internal & Private Properties
203 #region Public Properties
205 [EditorBrowsable (EditorBrowsableState.Never)]
207 public override Color BackColor
209 get { return base.BackColor; }
211 if (base.BackColor == value)
214 if (BackColorChanged != null)
215 BackColorChanged (this, EventArgs.Empty);
217 base.BackColor = value;
222 [EditorBrowsable (EditorBrowsableState.Never)]
224 public override Image BackgroundImage
226 get { return base.BackgroundImage; }
228 if (base.BackgroundImage == value)
231 if (BackgroundImageChanged != null)
232 BackgroundImageChanged (this, EventArgs.Empty);
234 base.BackgroundImage = value;
238 protected override CreateParams CreateParams
240 get { return base.CreateParams; }
243 protected override ImeMode DefaultImeMode
245 get { return ImeMode.Disable; }
248 [EditorBrowsable (EditorBrowsableState.Never)]
250 public override Font Font
252 get { return base.Font; }
254 if (base.Font.Equals (value))
257 if (FontChanged != null)
258 FontChanged (this, EventArgs.Empty);
264 [EditorBrowsable (EditorBrowsableState.Never)]
266 public override Color ForeColor
268 get { return base.ForeColor; }
270 if (base.ForeColor == value)
273 if (ForeColorChanged != null)
274 ForeColorChanged (this, EventArgs.Empty);
276 base.ForeColor = value;
281 [EditorBrowsable (EditorBrowsableState.Never)]
283 public new ImeMode ImeMode
285 get { return base.ImeMode; }
287 if (base.ImeMode == value)
290 if (ImeModeChanged != null)
291 ImeModeChanged (this, EventArgs.Empty);
293 base.ImeMode = value;
298 [RefreshProperties(RefreshProperties.Repaint)]
299 [MWFDescription("Scroll amount when clicking in the scroll area"), MWFCategory("Behaviour")]
300 public int LargeChange {
302 if (large_change > maximum)
303 return (maximum + 1);
309 throw new Exception( string.Format("Value '{0}' must be greater than or equal to 0.", value));
311 if (large_change != value) {
312 large_change = value;
314 // thumb area depends on large change value,
315 // so we need to recalculate it.
317 UpdatePos (Value, true);
324 [RefreshProperties(RefreshProperties.Repaint)]
325 [MWFDescription("Highest value for scrollbar"), MWFCategory("Behaviour")]
327 get { return maximum; }
329 if (maximum == value)
334 if (maximum < minimum)
337 // thumb area depends on maximum value,
338 // so we need to recalculate it.
340 UpdatePos (Value, true);
346 [RefreshProperties(RefreshProperties.Repaint)]
347 [MWFDescription("Smallest value for scrollbar"), MWFCategory("Behaviour")]
349 get { return minimum; }
351 if (minimum == value)
356 if (minimum > maximum)
359 // thumb area depends on minimum value,
360 // so we need to recalculate it.
362 UpdatePos (Value, true);
368 [MWFDescription("Scroll amount when clicking scroll arrows"), MWFCategory("Behaviour")]
369 public int SmallChange {
370 get { return small_change; }
373 throw new Exception( string.Format("Value '{0}' must be greater than or equal to 0.", value));
375 if (small_change != value) {
376 small_change = value;
377 UpdatePos (Value, true);
383 [DefaultValue (false)]
384 public new bool TabStop {
385 get { return base.TabStop; }
386 set { base.TabStop = value; }
389 [EditorBrowsable (EditorBrowsableState.Never)]
392 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
393 public override string Text {
394 get { return base.Text; }
395 set { base.Text = value; }
400 [MWFDescription("Current value for scrollbar"), MWFCategory("Behaviour")]
402 get { return position; }
404 if ( value < minimum || value > maximum )
405 throw new ArgumentException(
406 string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
408 if (position != value){
411 OnValueChanged (EventArgs.Empty);
415 if (IsHandleCreated) {
416 UpdateThumbPos (thumb_area.Y + (int)(((float)(position - minimum)) * pixel_per_pos), false);
424 #endregion //Public Properties
426 #region Public Methods
428 protected override void OnEnabledChanged (EventArgs e)
430 base.OnEnabledChanged (e);
433 firstbutton_state = secondbutton_state = ButtonState.Normal;
435 firstbutton_state = secondbutton_state = ButtonState.Inactive;
440 protected override void OnHandleCreated (System.EventArgs e)
442 base.OnHandleCreated (e);
446 UpdateThumbPos (thumb_area.Y + (int)(((float)(position - minimum)) * pixel_per_pos), false);
449 protected virtual void OnScroll (ScrollEventArgs event_args)
454 if (event_args.NewValue < Minimum) {
455 event_args.NewValue = Minimum;
458 if (event_args.NewValue > Maximum) {
459 event_args.NewValue = Maximum;
462 Scroll (this, event_args);
465 protected virtual void OnValueChanged (EventArgs e)
467 if (ValueChanged != null)
468 ValueChanged (this, e);
471 public override string ToString()
473 return string.Format("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
474 GetType( ).FullName.ToString( ), minimum, maximum, position);
477 protected void UpdateScrollInfo ()
482 protected override void WndProc (ref Message m)
488 PaintEventArgs paint_event;
490 paint_event = XplatUI.PaintEventStart (Handle, true);
491 OnPaintSB (paint_event);
492 XplatUI.PaintEventEnd (Handle, true);
496 case Msg.WM_ERASEBKGND:
497 m.Result = (IntPtr) 1; /// Disable background painting to avoid flickering
504 base.WndProc (ref m);
507 #endregion //Public Methods
509 #region Private Methods
511 private void CalcButtonSizes ()
514 if (Height < ThemeEngine.Current.ScrollBarButtonSize * 2)
515 scrollbutton_height = Height /2;
517 scrollbutton_height = ThemeEngine.Current.ScrollBarButtonSize;
520 if (Width < ThemeEngine.Current.ScrollBarButtonSize * 2)
521 scrollbutton_width = Width /2;
523 scrollbutton_width = ThemeEngine.Current.ScrollBarButtonSize;
527 private void CalcThumbArea ()
532 thumb_area.Height = Height - scrollbutton_height - scrollbutton_height;
534 thumb_area.Y = scrollbutton_height;
535 thumb_area.Width = Width;
537 if (Height < thumb_notshown_size)
540 double per = ((double) this.LargeChange / (double)((1 + maximum - minimum)));
541 thumb_size = 1 + (int) (thumb_area.Height * per);
543 if (thumb_size < thumb_min_size)
544 thumb_size = thumb_min_size;
547 pixel_per_pos = ((float)(thumb_area.Height - thumb_size) / (float) ((maximum - minimum - this.LargeChange) + 1));
552 thumb_area.X = scrollbutton_width;
553 thumb_area.Height = Height;
554 thumb_area.Width = Width - scrollbutton_width - scrollbutton_width;
556 if (Width < thumb_notshown_size)
559 double per = ((double) this.LargeChange / (double)((1 + maximum - minimum)));
560 thumb_size = 1 + (int) (thumb_area.Width * per);
562 if (thumb_size < thumb_min_size)
563 thumb_size = thumb_min_size;
566 pixel_per_pos = ((float)(thumb_area.Width - thumb_size) / (float) ((maximum - minimum - this.LargeChange) + 1));
570 private void LargeIncrement ()
572 ScrollEventArgs event_args;
573 int pos = position + large_change;
575 event_args = new ScrollEventArgs (ScrollEventType.LargeIncrement, pos);
576 OnScroll (event_args);
577 pos = event_args.NewValue;
579 event_args = new ScrollEventArgs (ScrollEventType.EndScroll, pos);
580 OnScroll (event_args);
581 pos = event_args.NewValue;
583 UpdatePos (pos, true);
586 private void LargeDecrement ()
588 ScrollEventArgs event_args;
589 int pos = position - large_change;
591 event_args = new ScrollEventArgs (ScrollEventType.LargeDecrement, pos);
592 OnScroll (event_args);
593 pos = event_args.NewValue;
595 event_args = new ScrollEventArgs (ScrollEventType.EndScroll, pos);
596 OnScroll (event_args);
597 pos = event_args.NewValue;
600 UpdatePos (pos, true);
603 private void OnResizeSB (Object o, EventArgs e)
605 if (Width <= 0 || Height <= 0)
610 UpdatePos (position, true);
615 private void OnPaintSB (PaintEventArgs pevent)
618 Paint (this, pevent);
620 ThemeEngine.Current.DrawScrollBar (pevent.Graphics, pevent.ClipRectangle, this);
623 private void OnTimer (Object source, EventArgs e)
627 switch (timer_type) {
629 case TimerType.HoldButton:
630 SetRepeatButtonTimer ();
633 case TimerType.RepeatButton:
635 if ((firstbutton_state & ButtonState.Pushed) == ButtonState.Pushed &&
639 if ((secondbutton_state & ButtonState.Pushed) == ButtonState.Pushed &&
646 case TimerType.HoldThumbArea:
647 SetRepeatThumbAreaTimer ();
650 case TimerType.RepeatThumbArea:
652 Point pnt, pnt_screen;
653 Rectangle thumb_area_screen = thumb_area;
655 pnt_screen = PointToScreen (new Point (thumb_area.X, thumb_area.Y));
656 thumb_area_screen.X = pnt_screen.X;
657 thumb_area_screen.Y = pnt_screen.Y;
659 if (thumb_area_screen.Contains (MousePosition) == false) {
660 timer.Enabled = false;
661 thumb_moving = ThumbMoving.None;
666 pnt = PointToClient (MousePosition);
669 lastclick_pos = pnt.Y;
671 lastclick_pos = pnt.X;
673 if (thumb_moving == ThumbMoving.Forward) {
674 if ((vert && (thumb_pos.Y + thumb_size > lastclick_pos)) ||
675 (!vert && (thumb_pos.X + thumb_size > lastclick_pos)) ||
676 (thumb_area.Contains (pnt) == false)){
677 timer.Enabled = false;
678 thumb_moving = ThumbMoving.None;
686 if ((vert && (thumb_pos.Y < lastclick_pos)) ||
687 (!vert && (thumb_pos.X < lastclick_pos))){
688 timer.Enabled = false;
689 thumb_moving = ThumbMoving.None;
704 private void OnMouseMoveSB (object sender, MouseEventArgs e)
706 if (MouseMove != null) {
710 if (Enabled == false || thumb_size == 0)
713 if (firstbutton_pressed) {
714 if (!first_arrow_area.Contains (e.X, e.Y) && ((firstbutton_state & ButtonState.Pushed) == ButtonState.Pushed)) {
715 firstbutton_state = ButtonState.Normal;
716 Invalidate (first_arrow_area);
718 } else if (first_arrow_area.Contains (e.X, e.Y) && ((firstbutton_state & ButtonState.Normal) == ButtonState.Normal)) {
719 firstbutton_state = ButtonState.Pushed;
720 Invalidate (first_arrow_area);
723 } else if (secondbutton_pressed) {
724 if (!second_arrow_area.Contains (e.X, e.Y) && ((secondbutton_state & ButtonState.Pushed) == ButtonState.Pushed)) {
725 secondbutton_state = ButtonState.Normal;
726 Invalidate (second_arrow_area);
728 } else if (second_arrow_area.Contains (e.X, e.Y) && ((secondbutton_state & ButtonState.Normal) == ButtonState.Normal)) {
729 secondbutton_state = ButtonState.Pushed;
730 Invalidate (second_arrow_area);
733 } else if (thumb_pressed == true) {
738 int mouse_click = e.Y;
739 int outside_curpos = thumb_area.Y + thumb_area.Height - thumb_size + lastclick_pos_thumb;
742 if (mouse_click > thumb_area.Y + thumb_area.Height) {
743 outside_thumbarea_right = true;
744 mouse_click = thumb_area.Y + thumb_area.Height;
747 if (mouse_click < thumb_area.Y) {
748 outside_thumbarea_left = true;
749 mouse_click = thumb_area.Y;
752 if (outside_thumbarea_right && mouse_click < outside_curpos) {
753 outside_thumbarea_right = false;
754 thumb_pixel_click_move_prev =
755 thumb_pixel_click_move = outside_curpos;
758 if (outside_thumbarea_left && mouse_click > thumb_area.Y + lastclick_pos_thumb) {
759 outside_thumbarea_left = false;
760 thumb_pixel_click_move_prev =
761 thumb_pixel_click_move = thumb_area.Y + lastclick_pos_thumb;
764 if (outside_thumbarea_right == false && outside_thumbarea_left == false) {
765 pixel_pos = thumb_pos.Y + (thumb_pixel_click_move - thumb_pixel_click_move_prev);
766 thumb_pixel_click_move_prev = thumb_pixel_click_move;
767 thumb_pixel_click_move = mouse_click;
769 UpdateThumbPos (pixel_pos, true);
770 OnScroll (new ScrollEventArgs (ScrollEventType.ThumbTrack, position));
775 int mouse_click = e.X;
776 int outside_curpos = thumb_area.X + thumb_area.Width - thumb_size + lastclick_pos_thumb;
778 if (mouse_click > thumb_area.X + thumb_area.Width) {
779 outside_thumbarea_right = true;
780 mouse_click = thumb_area.X + thumb_area.Width;
783 if (mouse_click < thumb_area.X) {
784 outside_thumbarea_left = true;
785 mouse_click = thumb_area.X;
788 if (outside_thumbarea_right && mouse_click < outside_curpos) {
789 outside_thumbarea_right = false;
790 thumb_pixel_click_move_prev =
791 thumb_pixel_click_move = outside_curpos;
794 if (outside_thumbarea_left && mouse_click > thumb_area.X + lastclick_pos_thumb) {
795 outside_thumbarea_left = false;
796 thumb_pixel_click_move_prev =
797 thumb_pixel_click_move = thumb_area.X + lastclick_pos_thumb;
800 if (outside_thumbarea_right == false && outside_thumbarea_left == false) {
801 pixel_pos = thumb_pos.X + (thumb_pixel_click_move - thumb_pixel_click_move_prev);
802 thumb_pixel_click_move_prev = thumb_pixel_click_move;
803 thumb_pixel_click_move = mouse_click;
804 UpdateThumbPos (pixel_pos, true);
805 OnScroll (new ScrollEventArgs (ScrollEventType.ThumbTrack, position));
815 private void OnMouseDownSB (object sender, MouseEventArgs e)
819 if (e.Button == MouseButtons.Right) {
820 if (MouseDown != null) {
825 if (Enabled == false)
828 if (firstbutton_state != ButtonState.Inactive && first_arrow_area.Contains (e.X, e.Y)) {
830 firstbutton_state = ButtonState.Pushed;
831 firstbutton_pressed = true;
832 Invalidate (first_arrow_area);
833 if (!timer.Enabled) {
834 SetHoldButtonClickTimer ();
835 timer.Enabled = true;
839 if (secondbutton_state != ButtonState.Inactive && second_arrow_area.Contains (e.X, e.Y)) {
841 secondbutton_state = ButtonState.Pushed;
842 secondbutton_pressed = true;
843 Invalidate (second_arrow_area);
844 if (!timer.Enabled) {
845 SetHoldButtonClickTimer ();
846 timer.Enabled = true;
850 if (thumb_size > 0 && thumb_pos.Contains (e.X, e.Y)) {
851 thumb_pressed = true;
854 lastclick_pos_thumb = e.Y - thumb_pos.Y;
856 thumb_pixel_click_move_prev = thumb_pixel_click_move = e.Y;
859 lastclick_pos_thumb = e.X - thumb_pos.X;
861 thumb_pixel_click_move_prev = thumb_pixel_click_move = e.X;
864 if (thumb_size > 0 && thumb_area.Contains (e.X, e.Y)) {
867 lastclick_pos_thumb = e.Y - thumb_pos.Y;
870 if (e.Y > thumb_pos.Y + thumb_pos.Height) {
872 thumb_moving = ThumbMoving.Forward;
873 Dirty (new Rectangle (0, thumb_pos.Y + thumb_pos.Height,
874 ClientRectangle.Width,
875 ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) -
876 scrollbutton_height));
879 thumb_moving = ThumbMoving.Backwards;
880 Dirty (new Rectangle (0, scrollbutton_height,
881 ClientRectangle.Width,
882 thumb_pos.Y - scrollbutton_height));
886 lastclick_pos_thumb = e.X - thumb_pos.X;
889 if (e.X > thumb_pos.X + thumb_pos.Width) {
890 thumb_moving = ThumbMoving.Forward;
892 Dirty (new Rectangle (thumb_pos.X + thumb_pos.Width, 0,
893 ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) -
895 ClientRectangle.Height));
897 thumb_moving = ThumbMoving.Backwards;
899 Dirty (new Rectangle (scrollbutton_width, 0,
900 thumb_pos.X - scrollbutton_width,
901 ClientRectangle.Height));
905 SetHoldThumbAreaTimer ();
906 timer.Enabled = true;
912 private void OnMouseUpSB (object sender, MouseEventArgs e)
916 if (e.Button == MouseButtons.Right) {
917 if (MouseUp != null) {
922 if (Enabled == false)
925 timer.Enabled = false;
926 if (thumb_moving != ThumbMoving.None) {
928 thumb_moving = ThumbMoving.None;
930 this.Capture = false;
932 if (firstbutton_pressed) {
933 firstbutton_state = ButtonState.Normal;
934 if (first_arrow_area.Contains (e.X, e.Y)) {
937 firstbutton_pressed = false;
938 Dirty (first_arrow_area);
939 } else if (secondbutton_pressed) {
940 secondbutton_state = ButtonState.Normal;
941 if (second_arrow_area.Contains (e.X, e.Y)) {
944 Dirty (second_arrow_area);
945 secondbutton_pressed = false;
946 } else if (thumb_pressed == true) {
947 OnScroll (new ScrollEventArgs (ScrollEventType.ThumbPosition, position));
948 OnScroll (new ScrollEventArgs (ScrollEventType.EndScroll, position));
949 thumb_pressed = false;
957 private void OnKeyDownSB (Object o, KeyEventArgs key)
959 if (Enabled == false)
964 switch (key.KeyCode){
1002 private void SetEndPosition ()
1004 ScrollEventArgs event_args;
1007 event_args = new ScrollEventArgs (ScrollEventType.Last, pos);
1008 OnScroll (event_args);
1009 pos = event_args.NewValue;
1011 event_args = new ScrollEventArgs (ScrollEventType.EndScroll, pos);
1012 OnScroll (event_args);
1013 pos = event_args.NewValue;
1018 private void SetHomePosition ()
1020 ScrollEventArgs event_args;
1023 event_args = new ScrollEventArgs (ScrollEventType.First, pos);
1024 OnScroll (event_args);
1025 pos = event_args.NewValue;
1027 event_args = new ScrollEventArgs (ScrollEventType.EndScroll, pos);
1028 OnScroll (event_args);
1029 pos = event_args.NewValue;
1034 private void SmallIncrement ()
1036 ScrollEventArgs event_args;
1037 int pos = position + small_change;
1039 event_args = new ScrollEventArgs (ScrollEventType.SmallIncrement, pos);
1040 OnScroll (event_args);
1041 pos = event_args.NewValue;
1043 event_args = new ScrollEventArgs (ScrollEventType.EndScroll, pos);
1044 OnScroll (event_args);
1045 pos = event_args.NewValue;
1047 UpdatePos (pos, true);
1050 private void SmallDecrement ()
1052 ScrollEventArgs event_args;
1053 int pos = position - small_change;
1055 event_args = new ScrollEventArgs (ScrollEventType.SmallDecrement, pos);
1056 OnScroll (event_args);
1057 pos = event_args.NewValue;
1059 event_args = new ScrollEventArgs (ScrollEventType.EndScroll, pos);
1060 OnScroll (event_args);
1061 pos = event_args.NewValue;
1063 UpdatePos (pos, true);
1066 private void SetHoldButtonClickTimer ()
1068 timer.Enabled = false;
1069 timer.Interval = 200;
1070 timer_type = TimerType.HoldButton;
1071 timer.Enabled = true;
1074 private void SetRepeatButtonTimer ()
1076 timer.Enabled = false;
1077 timer.Interval = 50;
1078 timer_type = TimerType.RepeatButton;
1079 timer.Enabled = true;
1082 private void SetHoldThumbAreaTimer ()
1084 timer.Enabled = false;
1085 timer.Interval = 200;
1086 timer_type = TimerType.HoldThumbArea;
1087 timer.Enabled = true;
1090 private void SetRepeatThumbAreaTimer ()
1092 timer.Enabled = false;
1093 timer.Interval = 50;
1094 timer_type = TimerType.RepeatThumbArea;
1095 timer.Enabled = true;
1098 private void UpdatePos (int newPos, bool update_thumbpos)
1102 if (newPos < minimum)
1105 if (newPos > maximum + 1 - large_change)
1106 pos = maximum + 1 - large_change;
1110 // pos can't be less than minimum
1114 if (update_thumbpos) {
1116 UpdateThumbPos (thumb_area.Y + (int)(((float)(pos - minimum)) * pixel_per_pos), false);
1118 UpdateThumbPos (thumb_area.X + (int)(((float)(pos - minimum)) * pixel_per_pos), false);
1122 position = pos; // Updates directly the value to avoid thumb pos update
1124 if (ValueChanged != null)
1125 ValueChanged (this, EventArgs.Empty);
1129 private void UpdateThumbPos (int pixel, bool update_value)
1135 if (pixel < thumb_area.Y)
1136 thumb_pos.Y = thumb_area.Y;
1138 if (pixel > thumb_area.Y + thumb_area.Height - thumb_size)
1139 thumb_pos.Y = thumb_area.Y + thumb_area.Height - thumb_size;
1141 thumb_pos.Y = pixel;
1144 thumb_pos.Width = ThemeEngine.Current.ScrollBarButtonSize;
1145 thumb_pos.Height = thumb_size;
1146 new_pos = (float) (thumb_pos.Y - thumb_area.Y);
1147 new_pos = new_pos / pixel_per_pos;
1152 if (pixel < thumb_area.X)
1153 thumb_pos.X = thumb_area.X;
1155 if (pixel > thumb_area.X + thumb_area.Width - thumb_size)
1156 thumb_pos.X = thumb_area.X + thumb_area.Width - thumb_size;
1158 thumb_pos.X = pixel;
1161 thumb_pos.Width = thumb_size;
1162 thumb_pos.Height = ThemeEngine.Current.ScrollBarButtonSize;
1163 new_pos = (float) (thumb_pos.X - thumb_area.X);
1164 new_pos = new_pos / pixel_per_pos;
1170 UpdatePos ((int) new_pos + minimum, false);
1173 private void SetValue (int value)
1175 if ( value < minimum || value > maximum )
1176 throw new ArgumentException(
1177 String.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
1179 if (position != value){
1182 OnValueChanged (EventArgs.Empty);
1183 UpdatePos (value, true);
1187 private void ClearDirty ()
1189 dirty = Rectangle.Empty;
1192 private void Dirty (Rectangle r)
1194 if (dirty == Rectangle.Empty) {
1198 dirty = Rectangle.Union (dirty, r);
1201 private void DirtyThumbArea ()
1203 if (thumb_moving == ThumbMoving.Forward) {
1205 Dirty (new Rectangle (0, thumb_pos.Y + thumb_pos.Height,
1206 ClientRectangle.Width,
1207 ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) -
1208 scrollbutton_height));
1210 Dirty (new Rectangle (thumb_pos.X + thumb_pos.Width, 0,
1211 ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) -
1213 ClientRectangle.Height));
1215 } else if (thumb_moving == ThumbMoving.Backwards) {
1217 Dirty(new Rectangle (0, scrollbutton_height,
1218 ClientRectangle.Width,
1219 thumb_pos.Y - scrollbutton_height));
1221 Dirty (new Rectangle (scrollbutton_width, 0,
1222 thumb_pos.X - scrollbutton_width,
1223 ClientRectangle.Height));
1228 private void InvalidateDirty ()
1231 dirty = Rectangle.Empty;
1234 #endregion //Private Methods