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;
167 SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
168 SetStyle (ControlStyles.ResizeRedraw | ControlStyles.Opaque, true);
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);
414 UpdatePos (Value, true);
420 #endregion //Public Properties
422 #region Public Methods
424 protected override void OnEnabledChanged (EventArgs e)
426 base.OnEnabledChanged (e);
429 firstbutton_state = secondbutton_state = ButtonState.Normal;
431 firstbutton_state = secondbutton_state = ButtonState.Inactive;
436 protected override void OnHandleCreated (System.EventArgs e)
438 base.OnHandleCreated (e);
442 UpdatePos (Value, true);
445 protected virtual void OnScroll (ScrollEventArgs event_args)
450 if (event_args.NewValue < Minimum) {
451 event_args.NewValue = Minimum;
454 if (event_args.NewValue > Maximum) {
455 event_args.NewValue = Maximum;
458 Scroll (this, event_args);
461 protected virtual void OnValueChanged (EventArgs e)
463 if (ValueChanged != null)
464 ValueChanged (this, e);
467 public override string ToString()
469 return string.Format("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
470 GetType( ).FullName.ToString( ), minimum, maximum, position);
473 protected void UpdateScrollInfo ()
478 protected override void WndProc (ref Message m)
484 PaintEventArgs paint_event;
486 paint_event = XplatUI.PaintEventStart (Handle);
487 OnPaintSB (paint_event);
488 XplatUI.PaintEventEnd (Handle);
492 case Msg.WM_ERASEBKGND:
493 m.Result = (IntPtr) 1; /// Disable background painting to avoid flickering
500 base.WndProc (ref m);
503 #endregion //Public Methods
505 #region Private Methods
507 private void CalcButtonSizes ()
510 if (Height < ThemeEngine.Current.ScrollBarButtonSize * 2)
511 scrollbutton_height = Height /2;
513 scrollbutton_height = ThemeEngine.Current.ScrollBarButtonSize;
516 if (Width < ThemeEngine.Current.ScrollBarButtonSize * 2)
517 scrollbutton_width = Width /2;
519 scrollbutton_width = ThemeEngine.Current.ScrollBarButtonSize;
523 private void CalcThumbArea ()
528 thumb_area.Height = Height - scrollbutton_height - scrollbutton_height;
530 thumb_area.Y = scrollbutton_height;
531 thumb_area.Width = Width;
533 if (Height < thumb_notshown_size)
536 double per = ((double) this.LargeChange / (double)((1 + maximum - minimum)));
537 thumb_size = 1 + (int) (thumb_area.Height * per);
539 if (thumb_size < thumb_min_size)
540 thumb_size = thumb_min_size;
543 pixel_per_pos = ((float)(thumb_area.Height - thumb_size) / (float) ((maximum - minimum - this.LargeChange) + 1));
548 thumb_area.X = scrollbutton_width;
549 thumb_area.Height = Height;
550 thumb_area.Width = Width - scrollbutton_width - scrollbutton_width;
552 if (Width < thumb_notshown_size)
555 double per = ((double) this.LargeChange / (double)((1 + maximum - minimum)));
556 thumb_size = 1 + (int) (thumb_area.Width * per);
558 if (thumb_size < thumb_min_size)
559 thumb_size = thumb_min_size;
562 pixel_per_pos = ((float)(thumb_area.Width - thumb_size) / (float) ((maximum - minimum - this.LargeChange) + 1));
566 private void LargeIncrement ()
568 ScrollEventArgs event_args;
569 int pos = position + large_change;
571 event_args = new ScrollEventArgs (ScrollEventType.LargeIncrement, pos);
572 OnScroll (event_args);
573 pos = event_args.NewValue;
575 event_args = new ScrollEventArgs (ScrollEventType.EndScroll, pos);
576 OnScroll (event_args);
577 pos = event_args.NewValue;
579 UpdatePos (pos, true);
582 private void LargeDecrement ()
584 ScrollEventArgs event_args;
585 int pos = position - large_change;
587 event_args = new ScrollEventArgs (ScrollEventType.LargeDecrement, pos);
588 OnScroll (event_args);
589 pos = event_args.NewValue;
591 event_args = new ScrollEventArgs (ScrollEventType.EndScroll, pos);
592 OnScroll (event_args);
593 pos = event_args.NewValue;
596 UpdatePos (pos, true);
599 private void OnResizeSB (Object o, EventArgs e)
601 if (Width <= 0 || Height <= 0)
606 UpdatePos (position, true);
609 private void OnPaintSB (PaintEventArgs pevent)
612 Paint (this, pevent);
614 ThemeEngine.Current.DrawScrollBar (pevent.Graphics, pevent.ClipRectangle, this);
617 private void OnTimer (Object source, EventArgs e)
621 switch (timer_type) {
623 case TimerType.HoldButton:
624 SetRepeatButtonTimer ();
627 case TimerType.RepeatButton:
629 if ((firstbutton_state & ButtonState.Pushed) == ButtonState.Pushed)
632 if ((secondbutton_state & ButtonState.Pushed) == ButtonState.Pushed)
638 case TimerType.HoldThumbArea:
639 SetRepeatThumbAreaTimer ();
642 case TimerType.RepeatThumbArea:
644 Point pnt, pnt_screen;
645 Rectangle thumb_area_screen = thumb_area;
647 pnt_screen = PointToScreen (new Point (thumb_area.X, thumb_area.Y));
648 thumb_area_screen.X = pnt_screen.X;
649 thumb_area_screen.Y = pnt_screen.Y;
651 if (thumb_area_screen.Contains (MousePosition) == false) {
652 timer.Enabled = false;
653 thumb_moving = ThumbMoving.None;
658 pnt = PointToClient (MousePosition);
661 lastclick_pos = pnt.Y;
663 lastclick_pos = pnt.X;
665 if (thumb_moving == ThumbMoving.Forward) {
666 if ((vert && (thumb_pos.Y + thumb_size > lastclick_pos)) ||
667 (!vert && (thumb_pos.X + thumb_size > lastclick_pos)) ||
668 (thumb_area.Contains (pnt) == false)){
669 timer.Enabled = false;
670 thumb_moving = ThumbMoving.None;
678 if ((vert && (thumb_pos.Y < lastclick_pos)) ||
679 (!vert && (thumb_pos.X < lastclick_pos))){
680 timer.Enabled = false;
681 thumb_moving = ThumbMoving.None;
696 private void OnMouseMoveSB (object sender, MouseEventArgs e)
698 if (MouseMove != null) {
702 if (Enabled == false || thumb_size == 0)
705 if (firstbutton_pressed) {
706 if (!first_arrow_area.Contains (e.X, e.Y) && ((firstbutton_state & ButtonState.Pushed) == ButtonState.Pushed)) {
707 firstbutton_state = ButtonState.Normal;
708 Invalidate (first_arrow_area);
710 } else if (first_arrow_area.Contains (e.X, e.Y) && ((firstbutton_state & ButtonState.Normal) == ButtonState.Normal)) {
711 firstbutton_state = ButtonState.Pushed;
712 Invalidate (first_arrow_area);
715 } else if (secondbutton_pressed) {
716 if (!second_arrow_area.Contains (e.X, e.Y) && ((secondbutton_state & ButtonState.Pushed) == ButtonState.Pushed)) {
717 secondbutton_state = ButtonState.Normal;
718 Invalidate (second_arrow_area);
720 } else if (second_arrow_area.Contains (e.X, e.Y) && ((secondbutton_state & ButtonState.Normal) == ButtonState.Normal)) {
721 secondbutton_state = ButtonState.Pushed;
722 Invalidate (second_arrow_area);
725 } else if (thumb_pressed == true) {
730 int mouse_click = e.Y;
731 int outside_curpos = thumb_area.Y + thumb_area.Height - thumb_size + lastclick_pos_thumb;
734 if (mouse_click > thumb_area.Y + thumb_area.Height) {
735 outside_thumbarea_right = true;
736 mouse_click = thumb_area.Y + thumb_area.Height;
739 if (mouse_click < thumb_area.Y) {
740 outside_thumbarea_left = true;
741 mouse_click = thumb_area.Y;
744 if (outside_thumbarea_right && mouse_click < outside_curpos) {
745 outside_thumbarea_right = false;
746 thumb_pixel_click_move_prev =
747 thumb_pixel_click_move = outside_curpos;
750 if (outside_thumbarea_left && mouse_click > thumb_area.Y + lastclick_pos_thumb) {
751 outside_thumbarea_left = false;
752 thumb_pixel_click_move_prev =
753 thumb_pixel_click_move = thumb_area.Y + lastclick_pos_thumb;
756 if (outside_thumbarea_right == false && outside_thumbarea_left == false) {
757 pixel_pos = thumb_pos.Y + (thumb_pixel_click_move - thumb_pixel_click_move_prev);
758 thumb_pixel_click_move_prev = thumb_pixel_click_move;
759 thumb_pixel_click_move = mouse_click;
761 UpdateThumbPos (pixel_pos, true);
762 OnScroll (new ScrollEventArgs (ScrollEventType.ThumbTrack, position));
767 int mouse_click = e.X;
768 int outside_curpos = thumb_area.X + thumb_area.Width - thumb_size + lastclick_pos_thumb;
770 if (mouse_click > thumb_area.X + thumb_area.Width) {
771 outside_thumbarea_right = true;
772 mouse_click = thumb_area.X + thumb_area.Width;
775 if (mouse_click < thumb_area.X) {
776 outside_thumbarea_left = true;
777 mouse_click = thumb_area.X;
780 if (outside_thumbarea_right && mouse_click < outside_curpos) {
781 outside_thumbarea_right = false;
782 thumb_pixel_click_move_prev =
783 thumb_pixel_click_move = outside_curpos;
786 if (outside_thumbarea_left && mouse_click > thumb_area.X + lastclick_pos_thumb) {
787 outside_thumbarea_left = false;
788 thumb_pixel_click_move_prev =
789 thumb_pixel_click_move = thumb_area.X + lastclick_pos_thumb;
792 if (outside_thumbarea_right == false && outside_thumbarea_left == false) {
793 pixel_pos = thumb_pos.X + (thumb_pixel_click_move - thumb_pixel_click_move_prev);
794 thumb_pixel_click_move_prev = thumb_pixel_click_move;
795 thumb_pixel_click_move = mouse_click;
796 UpdateThumbPos (pixel_pos, true);
797 OnScroll (new ScrollEventArgs (ScrollEventType.ThumbTrack, position));
807 private void OnMouseDownSB (object sender, MouseEventArgs e)
811 if (e.Button == MouseButtons.Right) {
812 if (MouseDown != null) {
817 if (Enabled == false)
820 if (firstbutton_state != ButtonState.Inactive && first_arrow_area.Contains (e.X, e.Y)) {
822 firstbutton_state = ButtonState.Pushed;
823 firstbutton_pressed = true;
824 Invalidate (first_arrow_area);
825 if (!timer.Enabled) {
826 SetHoldButtonClickTimer ();
827 timer.Enabled = true;
831 if (secondbutton_state != ButtonState.Inactive && second_arrow_area.Contains (e.X, e.Y)) {
833 secondbutton_state = ButtonState.Pushed;
834 secondbutton_pressed = true;
835 Invalidate (second_arrow_area);
836 if (!timer.Enabled) {
837 SetHoldButtonClickTimer ();
838 timer.Enabled = true;
842 if (thumb_size > 0 && thumb_pos.Contains (e.X, e.Y)) {
843 thumb_pressed = true;
846 lastclick_pos_thumb = e.Y - thumb_pos.Y;
848 thumb_pixel_click_move_prev = thumb_pixel_click_move = e.Y;
851 lastclick_pos_thumb = e.X - thumb_pos.X;
853 thumb_pixel_click_move_prev = thumb_pixel_click_move = e.X;
856 if (thumb_size > 0 && thumb_area.Contains (e.X, e.Y)) {
859 lastclick_pos_thumb = e.Y - thumb_pos.Y;
862 if (e.Y > thumb_pos.Y + thumb_pos.Height) {
864 thumb_moving = ThumbMoving.Forward;
865 Dirty (new Rectangle (0, thumb_pos.Y + thumb_pos.Height,
866 ClientRectangle.Width,
867 ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) -
868 scrollbutton_height));
871 thumb_moving = ThumbMoving.Backwards;
872 Dirty (new Rectangle (0, scrollbutton_height,
873 ClientRectangle.Width,
874 thumb_pos.Y - scrollbutton_height));
878 lastclick_pos_thumb = e.X - thumb_pos.X;
881 if (e.X > thumb_pos.X + thumb_pos.Width) {
882 thumb_moving = ThumbMoving.Forward;
884 Dirty (new Rectangle (thumb_pos.X + thumb_pos.Width, 0,
885 ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) -
887 ClientRectangle.Height));
889 thumb_moving = ThumbMoving.Backwards;
891 Dirty (new Rectangle (scrollbutton_width, 0,
892 thumb_pos.X - scrollbutton_width,
893 ClientRectangle.Height));
897 SetHoldThumbAreaTimer ();
898 timer.Enabled = true;
904 private void OnMouseUpSB (object sender, MouseEventArgs e)
908 if (e.Button == MouseButtons.Right) {
909 if (MouseUp != null) {
914 if (Enabled == false)
917 timer.Enabled = false;
918 if (thumb_moving != ThumbMoving.None) {
920 thumb_moving = ThumbMoving.None;
922 this.Capture = false;
924 if (firstbutton_pressed) {
925 firstbutton_state = ButtonState.Normal;
926 if (first_arrow_area.Contains (e.X, e.Y)) {
929 firstbutton_pressed = false;
930 Dirty (first_arrow_area);
931 } else if (secondbutton_pressed) {
932 secondbutton_state = ButtonState.Normal;
933 if (second_arrow_area.Contains (e.X, e.Y)) {
936 Dirty (second_arrow_area);
937 secondbutton_pressed = false;
938 } else if (thumb_pressed == true) {
939 OnScroll (new ScrollEventArgs (ScrollEventType.ThumbPosition, position));
940 OnScroll (new ScrollEventArgs (ScrollEventType.EndScroll, position));
941 thumb_pressed = false;
949 private void OnKeyDownSB (Object o, KeyEventArgs key)
951 if (Enabled == false)
956 switch (key.KeyCode){
994 private void SetEndPosition ()
996 ScrollEventArgs event_args;
999 event_args = new ScrollEventArgs (ScrollEventType.Last, pos);
1000 OnScroll (event_args);
1001 pos = event_args.NewValue;
1003 event_args = new ScrollEventArgs (ScrollEventType.EndScroll, pos);
1004 OnScroll (event_args);
1005 pos = event_args.NewValue;
1010 private void SetHomePosition ()
1012 ScrollEventArgs event_args;
1015 event_args = new ScrollEventArgs (ScrollEventType.First, pos);
1016 OnScroll (event_args);
1017 pos = event_args.NewValue;
1019 event_args = new ScrollEventArgs (ScrollEventType.EndScroll, pos);
1020 OnScroll (event_args);
1021 pos = event_args.NewValue;
1026 private void SmallIncrement ()
1028 ScrollEventArgs event_args;
1029 int pos = position + small_change;
1031 event_args = new ScrollEventArgs (ScrollEventType.SmallIncrement, pos);
1032 OnScroll (event_args);
1033 pos = event_args.NewValue;
1035 event_args = new ScrollEventArgs (ScrollEventType.EndScroll, pos);
1036 OnScroll (event_args);
1037 pos = event_args.NewValue;
1039 UpdatePos (pos, true);
1042 private void SmallDecrement ()
1044 ScrollEventArgs event_args;
1045 int pos = position - small_change;
1047 event_args = new ScrollEventArgs (ScrollEventType.SmallDecrement, pos);
1048 OnScroll (event_args);
1049 pos = event_args.NewValue;
1051 event_args = new ScrollEventArgs (ScrollEventType.EndScroll, pos);
1052 OnScroll (event_args);
1053 pos = event_args.NewValue;
1055 UpdatePos (pos, true);
1058 private void SetHoldButtonClickTimer ()
1060 timer.Enabled = false;
1061 timer.Interval = 200;
1062 timer_type = TimerType.HoldButton;
1063 timer.Enabled = true;
1066 private void SetRepeatButtonTimer ()
1068 timer.Enabled = false;
1069 timer.Interval = 50;
1070 timer_type = TimerType.RepeatButton;
1071 timer.Enabled = true;
1074 private void SetHoldThumbAreaTimer ()
1076 timer.Enabled = false;
1077 timer.Interval = 200;
1078 timer_type = TimerType.HoldThumbArea;
1079 timer.Enabled = true;
1082 private void SetRepeatThumbAreaTimer ()
1084 timer.Enabled = false;
1085 timer.Interval = 50;
1086 timer_type = TimerType.RepeatThumbArea;
1087 timer.Enabled = true;
1090 private void UpdatePos (int newPos, bool update_thumbpos)
1094 if (newPos < minimum)
1097 if (newPos > maximum + 1 - large_change)
1098 pos = maximum + 1 - large_change;
1102 // pos can't be less than minimum
1106 if (update_thumbpos) {
1108 UpdateThumbPos (thumb_area.Y + (int)(((float)(pos - minimum)) * pixel_per_pos), false);
1110 UpdateThumbPos (thumb_area.X + (int)(((float)(pos - minimum)) * pixel_per_pos), false);
1114 position = pos; // Updates directly the value to avoid thumb pos update
1116 if (ValueChanged != null)
1117 ValueChanged (this, EventArgs.Empty);
1121 private void UpdateThumbPos (int pixel, bool update_value)
1127 if (pixel < thumb_area.Y)
1128 thumb_pos.Y = thumb_area.Y;
1130 if (pixel > thumb_area.Y + thumb_area.Height - thumb_size)
1131 thumb_pos.Y = thumb_area.Y + thumb_area.Height - thumb_size;
1133 thumb_pos.Y = pixel;
1136 thumb_pos.Width = ThemeEngine.Current.ScrollBarButtonSize;
1137 thumb_pos.Height = thumb_size;
1138 new_pos = (float) (thumb_pos.Y - thumb_area.Y);
1139 new_pos = new_pos / pixel_per_pos;
1144 if (pixel < thumb_area.X)
1145 thumb_pos.X = thumb_area.X;
1147 if (pixel > thumb_area.X + thumb_area.Width - thumb_size)
1148 thumb_pos.X = thumb_area.X + thumb_area.Width - thumb_size;
1150 thumb_pos.X = pixel;
1153 thumb_pos.Width = thumb_size;
1154 thumb_pos.Height = ThemeEngine.Current.ScrollBarButtonSize;
1155 new_pos = (float) (thumb_pos.X - thumb_area.X);
1156 new_pos = new_pos / pixel_per_pos;
1162 UpdatePos ((int) new_pos + minimum, false);
1165 private void SetValue (int value)
1167 if ( value < minimum || value > maximum )
1168 throw new ArgumentException(
1169 String.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
1171 if (position != value){
1174 OnValueChanged (EventArgs.Empty);
1175 UpdatePos (value, true);
1179 private void ClearDirty ()
1181 dirty = Rectangle.Empty;
1184 private void Dirty (Rectangle r)
1186 if (dirty == Rectangle.Empty) {
1190 dirty = Rectangle.Union (dirty, r);
1193 private void DirtyThumbArea ()
1195 if (thumb_moving == ThumbMoving.Forward) {
1197 Dirty (new Rectangle (0, thumb_pos.Y + thumb_pos.Height,
1198 ClientRectangle.Width,
1199 ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) -
1200 scrollbutton_height));
1202 Dirty (new Rectangle (thumb_pos.X + thumb_pos.Width, 0,
1203 ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) -
1205 ClientRectangle.Height));
1207 } else if (thumb_moving == ThumbMoving.Backwards) {
1209 Dirty(new Rectangle (0, scrollbutton_height,
1210 ClientRectangle.Width,
1211 thumb_pos.Y - scrollbutton_height));
1213 Dirty (new Rectangle (scrollbutton_width, 0,
1214 thumb_pos.X - scrollbutton_width,
1215 ClientRectangle.Height));
1220 private void InvalidateDirty ()
1223 dirty = Rectangle.Empty;
1226 #endregion //Private Methods