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, Novell, Inc.
26 // Jordi Mas i Hernandez jordi@ximian.com
31 // $Log: ScrollBar.cs,v $
32 // Revision 1.26 2004/11/08 14:15:00 jordi
33 // fixes vertical scrollbar and removes dead code
35 // Revision 1.25 2004/11/04 12:03:49 ravindra
36 // - We need to recalculate the Thumb area when LargeChange/maximum/minimum values are changed.
37 // - We set the 'pos' in UpdatePos() method to minimum, if it's less than minimum. This is required to handle the case if large_change is more than max, and use LargeChange property instead of large_change variable.
38 // - We return max+1 when large_change is more than max, like MS does.
40 // Revision 1.24 2004/10/17 22:11:49 jordi
41 // disabled scrollbar should not honor any keyboard or mouse event
43 // Revision 1.23 2004/10/05 04:56:11 jackson
44 // Let the base Control handle the buffers, derived classes should not have to CreateBuffers themselves.
46 // Revision 1.22 2004/09/28 18:44:25 pbartok
47 // - Streamlined Theme interfaces:
48 // * Each DrawXXX method for a control now is passed the object for the
49 // control to be drawn in order to allow accessing any state the theme
52 // * ControlPaint methods for the theme now have a CP prefix to avoid
53 // name clashes with the Draw methods for controls
55 // * Every control now retrieves it's DefaultSize from the current theme
57 // Revision 1.21 2004/09/17 16:43:27 pbartok
58 // - Fixed behaviour of arrow buttons. Now properly behaves like Buttons (and
59 // like Microsoft's scrollbar arrow buttons)
61 // Revision 1.20 2004/09/17 16:14:36 pbartok
62 // - Added missing release of keyboard/mouse capture
64 // Revision 1.19 2004/09/05 08:03:51 jordi
65 // fixes bugs, adds flashing on certain situations
67 // Revision 1.18 2004/08/31 10:35:04 jordi
68 // adds autorepeat timer, uses a single timer, fixes scrolling bugs, adds new methods
70 // Revision 1.17 2004/08/25 21:35:18 jordi
71 // more fixes to scrollbar
73 // Revision 1.16 2004/08/25 19:20:13 jordi
74 // small bug fix regarding bar position
76 // Revision 1.15 2004/08/24 18:37:02 jordi
77 // fixes formmating, methods signature, and adds missing events
79 // Revision 1.14 2004/08/23 22:53:15 jordi
82 // Revision 1.13 2004/08/23 22:43:46 jordi
83 // *** empty log message ***
85 // Revision 1.11 2004/08/22 19:34:22 jackson
86 // Update the position through the Value property so the OnValueChanged event is raised.
88 // Revision 1.10 2004/08/21 20:22:21 pbartok
89 // - Replaced direct XplatUI calls with their Control counterpart
91 // Revision 1.9 2004/08/20 19:35:33 jackson
92 // Use the SWF timer so callbacks are run in the correct thread
94 // Revision 1.8 2004/08/20 19:34:26 jackson
95 // Use the SWF timer so callbacks are run in the correct thread
97 // Revision 1.7 2004/08/19 22:25:31 jordi
100 // Revision 1.6 2004/08/18 15:56:12 jordi
101 // fixes to scrollbar: steps and multiple timers
103 // Revision 1.5 2004/08/10 19:21:27 jordi
104 // scrollbar enhancements and standarize on win colors defaults
106 // Revision 1.4 2004/08/10 15:41:50 jackson
107 // Allow control to handle buffering
109 // Revision 1.3 2004/07/27 15:29:40 jordi
110 // fixes scrollbar events
112 // Revision 1.2 2004/07/26 17:42:03 jordi
118 using System.Drawing;
119 using System.Drawing.Imaging;
120 using System.Drawing.Drawing2D;
121 using System.ComponentModel;
122 using System.Runtime.InteropServices;
124 namespace System.Windows.Forms
126 [DefaultEvent ("Scroll")]
127 [DefaultProperty ("Value")]
128 public class ScrollBar : Control
130 #region Local Variables
131 private int position;
134 private int large_change;
135 private int small_change;
136 internal int scrollbutton_height;
137 internal int scrollbutton_width;
138 private ScrollBars type;
139 private Rectangle first_arrow_area = new Rectangle (); // up or left
140 private Rectangle second_arrow_area = new Rectangle (); // down or right
141 private Rectangle thumb_pos = new Rectangle ();
142 private Rectangle thumb_area = new Rectangle ();
143 internal ButtonState firstbutton_state = ButtonState.Normal;
144 internal ButtonState secondbutton_state = ButtonState.Normal;
145 private bool firstbutton_pressed = false;
146 private bool secondbutton_pressed = false;
147 private bool thumb_pressed = false;
148 private float pixel_per_pos = 0;
149 private Timer timer = new Timer ();
150 private TimerType timer_type;
151 private int thumb_pixel_click_move;
152 private int thumb_pixel_click_move_prev;
153 private int thumb_size = 40;
154 private const int thumb_min_size = 8;
155 private const int thumb_notshown_size = 40;
157 private int lastclick_pos; // Position of the last button-down event
158 private int lastclick_pos_thumb; // Position of the last button-down event relative to the thumb
159 private bool outside_thumbarea_right = false;
160 private bool outside_thumbarea_left = false;
161 internal ThumbMoving thumb_moving = ThumbMoving.None;
162 #endregion // Local Variables
164 private enum TimerType
172 internal enum ThumbMoving
180 public new event EventHandler BackColorChanged;
181 public new event EventHandler BackgroundImageChanged;
182 public new event EventHandler Click;
183 public new event EventHandler DoubleClick;
184 public new event EventHandler FontChanged;
185 public new event EventHandler ForeColorChanged;
186 public new event EventHandler ImeModeChanged;
187 public new event MouseEventHandler MouseDown;
188 public new event MouseEventHandler MouseMove;
189 public new event MouseEventHandler MouseUp;
190 public new event PaintEventHandler Paint;
191 public event ScrollEventHandler Scroll;
192 public new event EventHandler TextChanged;
193 public event EventHandler ValueChanged;
204 timer.Tick += new EventHandler (OnTimer);
205 base.KeyDown += new KeyEventHandler (OnKeyDownSB);
206 base.MouseDown += new MouseEventHandler (OnMouseDownSB);
207 base.MouseUp += new MouseEventHandler (OnMouseUpSB);
208 base.MouseMove += new MouseEventHandler (OnMouseMoveSB);
209 base.Resize += new EventHandler (OnResizeSB);
210 base.TabStop = false;
212 if (ThemeEngine.Current.DoubleBufferingSupported == true) {
213 double_buffering = true;
215 double_buffering = false;
218 SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
219 SetStyle (ControlStyles.ResizeRedraw | ControlStyles.Opaque, true);
222 #region Internal & Private Properties
223 internal Rectangle FirstArrowArea {
225 return this.first_arrow_area;
229 this.first_arrow_area = value;
233 internal Rectangle SecondArrowArea {
235 return this.second_arrow_area;
239 this.second_arrow_area = value;
243 internal Rectangle ThumbPos {
252 #endregion // Internal & Private Properties
254 #region Public Properties
256 [EditorBrowsable (EditorBrowsableState.Never)]
257 public override Color BackColor
259 get { return base.BackColor; }
261 if (base.BackColor == value)
264 if (BackColorChanged != null)
265 BackColorChanged (this, EventArgs.Empty);
267 base.BackColor = value;
272 [EditorBrowsable (EditorBrowsableState.Never)]
273 public override Image BackgroundImage
275 get { return base.BackgroundImage; }
277 if (base.BackgroundImage == value)
280 if (BackgroundImageChanged != null)
281 BackgroundImageChanged (this, EventArgs.Empty);
283 base.BackgroundImage = value;
287 protected override CreateParams CreateParams
289 get { return base.CreateParams; }
292 protected override ImeMode DefaultImeMode
294 get { return ImeMode.Disable; }
297 public override Font Font
299 get { return base.Font; }
301 if (base.Font == value)
304 if (FontChanged != null)
305 FontChanged (this, EventArgs.Empty);
311 [EditorBrowsable (EditorBrowsableState.Never)]
312 public override Color ForeColor
314 get { return base.ForeColor; }
316 if (base.ForeColor == value)
319 if (ForeColorChanged != null)
320 ForeColorChanged (this, EventArgs.Empty);
322 base.ForeColor = value;
327 [EditorBrowsable (EditorBrowsableState.Never)]
328 public new ImeMode ImeMode
330 get { return base.ImeMode; }
332 if (base.ImeMode == value)
335 if (ImeModeChanged != null)
336 ImeModeChanged (this, EventArgs.Empty);
338 base.ImeMode = value;
342 public int LargeChange {
344 if (large_change > maximum)
345 return (maximum + 1);
351 throw new Exception( string.Format("Value '{0}' must be greater than or equal to 0.", value));
353 if (large_change != value) {
354 large_change = value;
356 // thumb area depends on large change value,
357 // so we need to recalculate it.
359 UpdatePos (Value, true);
366 get { return maximum; }
370 if (maximum < minimum)
373 // thumb area depends on maximum value,
374 // so we need to recalculate it.
376 UpdatePos (Value, true);
382 get { return minimum; }
386 if (minimum > maximum)
389 // thumb area depends on minimum value,
390 // so we need to recalculate it.
392 UpdatePos (Value, true);
397 public int SmallChange {
398 get { return small_change; }
401 throw new Exception( string.Format("Value '{0}' must be greater than or equal to 0.", value));
403 if (small_change != value) {
404 small_change = value;
405 UpdatePos (Value, true);
411 public new bool TabStop {
412 get { return base.TabStop; }
413 set { base.TabStop = value; }
416 [EditorBrowsable (EditorBrowsableState.Never)]
417 public override string Text {
418 get { return base.Text; }
419 set { base.Text = value; }
423 get { return position; }
425 if ( value < minimum || value > maximum )
426 throw new ArgumentException(
427 string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
429 if (position != value){
432 if (ValueChanged != null)
433 ValueChanged (this, EventArgs.Empty);
435 UpdatePos (Value, true);
441 #endregion //Public Properties
443 #region Public Methods
445 protected override void OnEnabledChanged (EventArgs e)
447 base.OnEnabledChanged (e);
450 firstbutton_state = secondbutton_state = ButtonState.Normal;
452 firstbutton_state = secondbutton_state = ButtonState.Inactive;
457 protected override void OnHandleCreated (System.EventArgs e)
459 base.OnHandleCreated (e);
462 UpdatePos (Value, true);
465 protected virtual void OnScroll (ScrollEventArgs event_args)
470 Scroll (this, event_args);
473 protected virtual void OnValueChanged (EventArgs e)
475 if (ValueChanged != null)
476 ValueChanged (this, e);
479 public override string ToString()
481 return string.Format("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
482 GetType( ).FullName.ToString( ), minimum, maximum, position);
485 protected void UpdateScrollInfo ()
490 protected override void WndProc (ref Message m)
496 PaintEventArgs paint_event;
498 paint_event = XplatUI.PaintEventStart (Handle);
499 OnPaintSB (paint_event);
500 XplatUI.PaintEventEnd (Handle);
505 case Msg.WM_ERASEBKGND:
506 m.Result = (IntPtr) 1; /// Disable background painting to avoid flickering
513 base.WndProc (ref m);
516 #endregion //Public Methods
518 #region Private Methods
520 private void CalcThumbArea ()
525 thumb_area.Height = Height - scrollbutton_height - scrollbutton_height;
527 thumb_area.Y = scrollbutton_height;
528 thumb_area.Width = Width;
530 if (Height < thumb_notshown_size)
533 double per = ((double) this.LargeChange / (double)((1 + maximum - minimum)));
534 thumb_size = 1 + (int) (thumb_area.Height * per);
536 if (thumb_size < thumb_min_size)
537 thumb_size = thumb_min_size;
540 pixel_per_pos = ((float)(thumb_area.Height - thumb_size) / (float) ((maximum - minimum - this.LargeChange) + 1));
545 thumb_area.X = scrollbutton_width;
546 thumb_area.Height = Height;
547 thumb_area.Width = Width - scrollbutton_width - scrollbutton_width;
549 if (Width < thumb_notshown_size)
552 double per = ((double) this.LargeChange / (double)((1 + maximum - minimum)));
553 thumb_size = 1 + (int) (thumb_area.Width * per);
555 if (thumb_size < thumb_min_size)
556 thumb_size = thumb_min_size;
559 pixel_per_pos = ((float)(thumb_area.Width - thumb_size) / (float) ((maximum - minimum - this.LargeChange) + 1));
565 ThemeEngine.Current.DrawScrollBar(DeviceContext, this.ClientRectangle, this);
568 private void LargeIncrement ()
570 UpdatePos (position + large_change, true);
573 OnScroll (new ScrollEventArgs (ScrollEventType.LargeIncrement, position));
574 OnScroll (new ScrollEventArgs (ScrollEventType.EndScroll, position));
577 private void LargeDecrement ()
579 UpdatePos (position - large_change, true);
582 OnScroll (new ScrollEventArgs (ScrollEventType.LargeDecrement, position));
583 OnScroll (new ScrollEventArgs (ScrollEventType.EndScroll, position));
586 private void OnResizeSB (Object o, EventArgs e)
588 if (Width <= 0 || Height <= 0)
592 if (Height < ThemeEngine.Current.ScrollBarButtonSize * 2)
593 scrollbutton_height = Height /2;
595 scrollbutton_height = ThemeEngine.Current.ScrollBarButtonSize;
598 if (Width < ThemeEngine.Current.ScrollBarButtonSize * 2)
599 scrollbutton_width = Width /2;
601 scrollbutton_width = ThemeEngine.Current.ScrollBarButtonSize;
605 UpdatePos (position, true);
608 private void OnPaintSB (PaintEventArgs pevent)
610 if (Width <= 0 || Height <= 0 || Visible == false)
613 /* Copies memory drawing buffer to screen*/
616 if (double_buffering)
617 pevent.Graphics.DrawImage (ImageBuffer, 0, 0);
621 private void OnTimer (Object source, EventArgs e)
623 switch (timer_type) {
625 case TimerType.HoldButton:
626 SetRepeatButtonTimer ();
629 case TimerType.RepeatButton:
631 if ((firstbutton_state & ButtonState.Pushed) == ButtonState.Pushed)
634 if ((secondbutton_state & ButtonState.Pushed) == ButtonState.Pushed)
640 case TimerType.HoldThumbArea:
641 SetRepeatThumbAreaTimer ();
644 case TimerType.RepeatThumbArea:
647 pnt = PointToClient (MousePosition);
650 lastclick_pos = pnt.Y;
652 lastclick_pos = pnt.X;
654 if (thumb_moving == ThumbMoving.Forward) {
655 if ((vert && (thumb_pos.Y + thumb_size > lastclick_pos)) ||
656 (!vert && (thumb_pos.X + thumb_size > lastclick_pos)) ||
657 (thumb_area.Contains (pnt) == false)){
658 timer.Enabled = false;
659 thumb_moving = ThumbMoving.None;
665 if ((vert && (thumb_pos.Y < lastclick_pos)) ||
666 (!vert && (thumb_pos.X < lastclick_pos))){
667 timer.Enabled = false;
668 thumb_moving = ThumbMoving.None;
681 private void OnMouseMoveSB (object sender, MouseEventArgs e)
683 if (Enabled == false || thumb_size == 0)
686 if (firstbutton_pressed) {
687 if (!first_arrow_area.Contains (e.X, e.Y) && ((firstbutton_state & ButtonState.Pushed) == ButtonState.Pushed)) {
688 firstbutton_state = ButtonState.Normal;
691 } else if (first_arrow_area.Contains (e.X, e.Y) && ((firstbutton_state & ButtonState.Normal) == ButtonState.Normal)) {
692 firstbutton_state = ButtonState.Pushed;
696 } else if (secondbutton_pressed) {
697 if (!second_arrow_area.Contains (e.X, e.Y) && ((secondbutton_state & ButtonState.Pushed) == ButtonState.Pushed)) {
698 secondbutton_state = ButtonState.Normal;
701 } else if (second_arrow_area.Contains (e.X, e.Y) && ((secondbutton_state & ButtonState.Normal) == ButtonState.Normal)) {
702 secondbutton_state = ButtonState.Pushed;
706 } else if (thumb_pressed == true) {
711 int mouse_click = e.Y;
712 int outside_curpos = thumb_area.Y + thumb_area.Height - thumb_size + lastclick_pos_thumb;
715 if (mouse_click > thumb_area.Y + thumb_area.Height) {
716 outside_thumbarea_right = true;
717 mouse_click = thumb_area.Y + thumb_area.Height;
720 if (mouse_click < thumb_area.Y) {
721 outside_thumbarea_left = true;
722 mouse_click = thumb_area.Y;
725 if (outside_thumbarea_right && mouse_click < outside_curpos) {
726 outside_thumbarea_right = false;
727 thumb_pixel_click_move_prev =
728 thumb_pixel_click_move = outside_curpos;
731 if (outside_thumbarea_left && mouse_click > thumb_area.Y + lastclick_pos_thumb) {
732 outside_thumbarea_left = false;
733 thumb_pixel_click_move_prev =
734 thumb_pixel_click_move = thumb_area.Y + lastclick_pos_thumb;
737 if (outside_thumbarea_right == false && outside_thumbarea_left == false) {
738 pixel_pos = thumb_pos.Y + (thumb_pixel_click_move - thumb_pixel_click_move_prev);
739 thumb_pixel_click_move_prev = thumb_pixel_click_move;
740 thumb_pixel_click_move = mouse_click;
741 UpdateThumbPos (pixel_pos, true);
746 int mouse_click = e.X;
747 int outside_curpos = thumb_area.X + thumb_area.Width - thumb_size + lastclick_pos_thumb;
749 if (mouse_click > thumb_area.X + thumb_area.Width) {
750 outside_thumbarea_right = true;
751 mouse_click = thumb_area.X + thumb_area.Width;
754 if (mouse_click < thumb_area.X) {
755 outside_thumbarea_left = true;
756 mouse_click = thumb_area.X;
759 if (outside_thumbarea_right && mouse_click < outside_curpos) {
760 outside_thumbarea_right = false;
761 thumb_pixel_click_move_prev =
762 thumb_pixel_click_move = outside_curpos;
765 if (outside_thumbarea_left && mouse_click > thumb_area.X + lastclick_pos_thumb) {
766 outside_thumbarea_left = false;
767 thumb_pixel_click_move_prev =
768 thumb_pixel_click_move = thumb_area.X + lastclick_pos_thumb;
771 if (outside_thumbarea_right == false && outside_thumbarea_left == false) {
772 pixel_pos = thumb_pos.X + (thumb_pixel_click_move - thumb_pixel_click_move_prev);
773 thumb_pixel_click_move_prev = thumb_pixel_click_move;
774 thumb_pixel_click_move = mouse_click;
775 UpdateThumbPos (pixel_pos, true);
785 private void OnMouseDownSB (object sender, MouseEventArgs e)
787 if (Enabled == false)
790 if (firstbutton_state != ButtonState.Inactive && first_arrow_area.Contains (e.X, e.Y)) {
792 firstbutton_state = ButtonState.Pushed;
793 firstbutton_pressed = true;
797 if (secondbutton_state != ButtonState.Inactive && second_arrow_area.Contains (e.X, e.Y)) {
799 secondbutton_state = ButtonState.Pushed;
800 secondbutton_pressed = true;
804 if (thumb_size > 0 && thumb_pos.Contains (e.X, e.Y)) {
805 thumb_pressed = true;
809 lastclick_pos_thumb = e.Y - thumb_pos.Y;
811 thumb_pixel_click_move_prev = thumb_pixel_click_move = e.Y;
814 lastclick_pos_thumb = e.X - thumb_pos.X;
816 thumb_pixel_click_move_prev = thumb_pixel_click_move = e.X;
820 if (thumb_size > 0 && thumb_area.Contains (e.X, e.Y)) {
823 lastclick_pos_thumb = e.Y - thumb_pos.Y;
826 if (e.Y > thumb_pos.Y + thumb_pos.Height) {
828 thumb_moving = ThumbMoving.Forward;
832 thumb_moving = ThumbMoving.Backwards;
837 lastclick_pos_thumb = e.X - thumb_pos.X;
840 if (e.X > thumb_pos.X + thumb_pos.Width) {
841 thumb_moving = ThumbMoving.Forward;
845 thumb_moving = ThumbMoving.Backwards;
850 SetHoldThumbAreaTimer ();
851 timer.Enabled = true;
858 /* If arrows are pressed, fire timer for auto-repeat */
859 if ((((firstbutton_state & ButtonState.Pushed) == ButtonState.Pushed)
860 || ((secondbutton_state & ButtonState.Pushed) == ButtonState.Pushed)) &&
861 timer.Enabled == false) {
862 SetHoldButtonClickTimer ();
863 timer.Enabled = true;
867 private void OnMouseUpSB (object sender, MouseEventArgs e)
869 if (Enabled == false)
872 timer.Enabled = false;
874 if (thumb_moving != ThumbMoving.None) {
875 thumb_moving = ThumbMoving.None;
879 this.Capture = false;
881 if (firstbutton_pressed) {
882 firstbutton_state = ButtonState.Normal;
883 if (first_arrow_area.Contains (e.X, e.Y)) {
886 firstbutton_pressed = false;
888 } else if (secondbutton_pressed) {
889 secondbutton_state = ButtonState.Normal;
890 if (second_arrow_area.Contains (e.X, e.Y)) {
893 secondbutton_pressed = false;
895 } else if (thumb_pressed == true) {
896 OnScroll (new ScrollEventArgs (ScrollEventType.ThumbPosition, position));
897 OnScroll (new ScrollEventArgs (ScrollEventType.EndScroll, position));
898 thumb_pressed = false;
903 private void OnKeyDownSB (Object o, KeyEventArgs key)
905 if (Enabled == false)
908 switch (key.KeyCode){
935 private void SmallIncrement ()
937 UpdatePos (position + small_change, true);
940 OnScroll (new ScrollEventArgs (ScrollEventType.SmallIncrement, position));
941 OnScroll (new ScrollEventArgs (ScrollEventType.EndScroll, position));
944 private void SmallDecrement ()
946 UpdatePos (position - small_change, true);
949 OnScroll (new ScrollEventArgs (ScrollEventType.SmallDecrement, position));
950 OnScroll (new ScrollEventArgs (ScrollEventType.EndScroll, position));
953 private void SetHoldButtonClickTimer ()
955 timer.Enabled = false;
956 timer.Interval = 200;
957 timer_type = TimerType.HoldButton;
958 timer.Enabled = true;
961 private void SetRepeatButtonTimer ()
963 timer.Enabled = false;
965 timer_type = TimerType.RepeatButton;
966 timer.Enabled = true;
969 private void SetHoldThumbAreaTimer ()
971 timer.Enabled = false;
972 timer.Interval = 200;
973 timer_type = TimerType.HoldThumbArea;
974 timer.Enabled = true;
977 private void SetRepeatThumbAreaTimer ()
979 timer.Enabled = false;
981 timer_type = TimerType.RepeatThumbArea;
982 timer.Enabled = true;
985 private void UpdatePos (int newPos, bool update_thumbpos)
990 if (newPos < minimum)
993 if (newPos > maximum + 1 - large_change)
994 pos = maximum + 1 - large_change;
998 // pos can't be less than minimum
1002 if (update_thumbpos) {
1004 UpdateThumbPos (thumb_area.Y + (int)(((float)(pos - minimum)) * pixel_per_pos), false);
1006 UpdateThumbPos (thumb_area.X + (int)(((float)(pos - minimum)) * pixel_per_pos), false);
1011 position = pos; // Updates directly the value to avoid thumb pos update
1013 if (ValueChanged != null)
1014 ValueChanged (this, EventArgs.Empty);
1017 if (pos != old) // Fire event
1018 OnScroll (new ScrollEventArgs (ScrollEventType.ThumbTrack, pos));
1022 private void UpdateThumbPos (int pixel, bool update_value)
1027 if (pixel < thumb_area.Y)
1028 thumb_pos.Y = thumb_area.Y;
1030 if (pixel > thumb_area.Y + thumb_area.Height - thumb_size)
1031 thumb_pos.Y = thumb_area.Y + thumb_area.Height - thumb_size;
1033 thumb_pos.Y = pixel;
1036 thumb_pos.Width = ThemeEngine.Current.ScrollBarButtonSize;
1037 thumb_pos.Height = thumb_size;
1038 new_pos = (float) (thumb_pos.Y - thumb_area.Y);
1039 new_pos = new_pos / pixel_per_pos;
1043 if (pixel < thumb_area.X)
1044 thumb_pos.X = thumb_area.X;
1046 if (pixel > thumb_area.X + thumb_area.Width - thumb_size)
1047 thumb_pos.X = thumb_area.X + thumb_area.Width - thumb_size;
1049 thumb_pos.X = pixel;
1052 thumb_pos.Width = thumb_size;
1053 thumb_pos.Height = ThemeEngine.Current.ScrollBarButtonSize;
1054 new_pos = (float) (thumb_pos.X - thumb_area.X);
1055 new_pos = new_pos / pixel_per_pos;
1059 UpdatePos ((int) new_pos + minimum, false);
1063 #endregion //Private Methods