[Mono-winforms-list] implementation of TrackBar control (patch)

Aleksey Ryabchuk ryabchuk@yahoo.com
Thu, 6 Mar 2003 08:14:01 -0800 (PST)


--0-1097343193-1046967241=:26058
Content-Type: text/plain; charset=us-ascii
Content-Id: 
Content-Disposition: inline

Hello !

Here is the implementation of TrackBar control. The
attached patch incorporates my previous patch for
win32enums.cs.

Best Regards
Aleksey


__________________________________________________
Do you Yahoo!?
Yahoo! Tax Center - forms, calculators, tips, more
http://taxes.yahoo.com/
--0-1097343193-1046967241=:26058
Content-Type: text/plain; name=patch
Content-Description: patch
Content-Disposition: inline; filename=patch

Index: Form.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/Form.cs,v
retrieving revision 1.29
diff -u -r1.29 Form.cs
--- Form.cs	1 Mar 2003 21:20:31 -0000	1.29
+++ Form.cs	6 Mar 2003 16:04:33 -0000
@@ -918,6 +918,10 @@
 				case Msg.WM_CTLCOLORLISTBOX:
 					Control.ReflectMessage( m.LParam, ref m);
 					break;
+				case Msg.WM_HSCROLL:
+				case Msg.WM_VSCROLL:
+					Control.ReflectMessage( m.LParam, ref m );
+					break;
 				default:
 					base.WndProc (ref m);
 					break;    
Index: TrackBar.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/TrackBar.cs,v
retrieving revision 1.12
diff -u -r1.12 TrackBar.cs
--- TrackBar.cs	10 Dec 2002 03:02:48 -0000	1.12
+++ TrackBar.cs	6 Mar 2003 16:04:34 -0000
@@ -1,280 +1,399 @@
-//
-// System.Windows.Forms.TrackBar
-//
-// Author:
-//   stubbed out by Jackson Harper (jackson@latitudegeo.com)
-//   Dennis Hayes (dennish@Raytek.com)
-//
-// (C) 2002 Ximian, Inc
-//
-using System.ComponentModel;
-using System.Drawing;
-
-namespace System.Windows.Forms {
-
-	// <summary>
-	// </summary>
-
-    public class TrackBar : Control, ISupportInitialize {
-
-		//
-		//  --- Public Constructors
-		//
-		[MonoTODO]
-		public TrackBar()
-		{
-			
-		}
-		//
-		// --- Public Properties
-		//
-		[MonoTODO]
-		public bool AutoSize {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
-		}
-
-		[MonoTODO]
-		public override Image BackgroundImage {
-			get {
-				//FIXME:
-				return base.BackgroundImage;
-			}
-			set {
-				//FIXME:
-				base.BackgroundImage = value;
-			}
-		}
-		[MonoTODO]
-		public override Font Font {
-			get {
-				//FIXME:
-				return base.Font;
-			}
-			set {
-				//FIXME:
-				base.Font = value;
-			}
-		}
-		[MonoTODO]
-		public override Color ForeColor {
-			get {
-				//FIXME:
-				return base.ForeColor;
-			}
-			set {
-				//FIXME:
-				base.ForeColor = value;
-			}
-		}
-		[MonoTODO]
-		public int LargeChange {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
-		}
-		[MonoTODO]
-		public int Maximum {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
-		}
-		[MonoTODO]
-		public int Minimum {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
-		}
-		[MonoTODO]
-		public Orientation Orientation {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
-		}
-		[MonoTODO]
-		public int SmallChange {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
-		}
-		[MonoTODO]
-		public override string Text {
-			get {
-				//FIXME:
-				return base.Text;
-			}
-			set {
-				//FIXME:
-				base.Text = value;
-			}
-		}
-		[MonoTODO]
-		public int TickFrequency {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
-		}
-		[MonoTODO]
-		public TickStyle TickStyle {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
-		}
-		[MonoTODO]
-		public int Value {
-			get {
-				throw new NotImplementedException ();
-			}
-			set {
-				//FIXME:
-			}
-		}
-		
-		// --- Public Methods
-		
-		[MonoTODO]
-		public void SetRange(int minValue, int maxValue) 
-		{
-			//FIXME:
-		}
-		[MonoTODO]
-		public override string ToString() 
-		{
-			//FIXME:
-			return base.ToString();
-		}
-		
-		// --- Public Events
-		
-		[MonoTODO]
-		public event EventHandler Scroll;
-		[MonoTODO]
-		public event EventHandler ValueChanged;
-        
-        // --- Protected Properties
-        //
-		[MonoTODO]
-		protected override CreateParams CreateParams {
-			get {
-				CreateParams createParams = new CreateParams ();
-				window = new ControlNativeWindow (this);
-
-				createParams.Caption = Text;
-				createParams.ClassName = "TRACKBAR";
-				createParams.X = Left;
-				createParams.Y = Top;
-				createParams.Width = Width;
-				createParams.Height = Height;
-				createParams.ClassStyle = 0;
-				createParams.ExStyle = 0;
-				createParams.Param = 0;
-				//			createParams.Parent = Parent.Handle;
-				createParams.Style = (int) (
-					WindowStyles.WS_CHILD | 
-					WindowStyles.WS_VISIBLE);
-				window.CreateHandle (createParams);
-				return createParams;
-			}		
-		}
-		[MonoTODO]
-		protected override ImeMode DefaultImeMode {
-			get {
-				//FIXME:
-				return base.DefaultImeMode;
-			}
-		}
-		[MonoTODO]
-		protected override Size DefaultSize {
-			get {
-				//FIXME: replace with correct values
-				return new System.Drawing.Size(300,20);
-			}
-		}
-		//
-		// --- Protected Methods
-		//
-		[MonoTODO]
-		protected override void CreateHandle() 
-		{
-			//FIXME: just to get it to run
-			base.CreateHandle();
-		}
-		[MonoTODO]
-		protected override bool IsInputKey(Keys keyData) 
-		{
-			//FIXME:
-			return IsInputKey(keyData);
-		}
-		[MonoTODO]
-		protected override void OnBackColorChanged(EventArgs e) 
-		{
-			//FIXME:
-			base.OnBackColorChanged(e);
-		}
-		[MonoTODO]
-		protected override void OnHandleCreated(EventArgs e) 
-		{
-			//FIXME:
-			base.OnHandleCreated(e);
-		}
-
-		[MonoTODO]
-		protected virtual void OnScroll(EventArgs e) 
-		{
-			//FIXME:
-		}
-
-		[MonoTODO]
-		protected override void OnMouseWheel(MouseEventArgs e) { // .NET V1.1 Beta.
-			//FIXME:
-			base.OnMouseWheel(e);
-		}
-
-		[MonoTODO]
-		protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) 
-		{
-			//FIXME:
-			base.SetBoundsCore(x, y, width, height, specified);
-		}
-
-		[MonoTODO]
-		protected override void WndProc(ref Message m)
-		{
-			//FIXME:
-			base.WndProc(ref m);
-		}
-
-		void ISupportInitialize.BeginInit(){
-			//FIXME:
-		}
-
-		void ISupportInitialize.EndInit(){
-			//FIXME:
-		}
-	}
-}
+//
+// System.Windows.Forms.TrackBar
+//
+// Author:
+//   stubbed out by Jackson Harper (jackson@latitudegeo.com)
+//   Dennis Hayes (dennish@Raytek.com)
+//   Aleksey Ryabchuk (ryabchuk@yahoo.com)
+//
+// (C) 2002 Ximian, Inc
+//
+using System.ComponentModel;
+using System.Drawing;
+
+namespace System.Windows.Forms {
+
+	// <summary>
+	// </summary>
+
+    public class TrackBar : Control, ISupportInitialize {
+
+		Orientation orientation = Orientation.Horizontal;
+		int minimum = 0;
+		int maximum = 10;
+		int tickFrequency = 1;
+		bool autosize = true;
+		int val = 0;
+		TickStyle tickStyle = TickStyle.BottomRight;
+		int smallChange = 1;
+		int largeChange = 5;
+
+		//
+		//  --- Public Constructors
+		//
+		[MonoTODO]
+		public TrackBar()
+		{
+			Size = DefaultSize;
+		}
+		//
+		// --- Public Properties
+		//
+		[MonoTODO]
+		public bool AutoSize {
+			get {
+				return autosize;
+			}
+			set {
+				autosize = value;
+			}
+		}
+
+		public override Image BackgroundImage {
+			get {
+				return base.BackgroundImage;
+			}
+			set {
+			}
+		}
+
+		public override Font Font {
+			get {
+				return base.Font;
+			}
+			set {
+			}
+		}
+
+		public override Color ForeColor {
+			get {
+				return base.ForeColor;
+			}
+			set {
+			}
+		}
+
+		[MonoTODO]
+		public int LargeChange {
+			get {
+				return largeChange;
+			}
+			set {
+				if ( value < 0 )
+					throw new Exception( string.Format("Value '{0}' must be greater than or equal to 0.", value));
+
+				largeChange = value;
+
+				if ( IsHandleCreated ) 
+					Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_SETPAGESIZE, 0, value);
+			}
+		}
+		[MonoTODO]
+		public int Maximum {
+			get {
+				return maximum;
+			}
+			set {
+				maximum = value;
+
+				if ( maximum < minimum )
+					minimum = maximum;
+
+				if ( IsHandleCreated ) 
+					Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_SETRANGEMAX, 1, value);
+			}
+		}
+		[MonoTODO]
+		public int Minimum {
+			get {
+				return minimum;
+			}
+			set {
+				minimum = value;
+
+				if ( minimum > maximum )
+					maximum = minimum;
+
+				if ( IsHandleCreated ) 
+					Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_SETRANGEMIN, 1, value);
+			}
+		}
+		[MonoTODO]
+		public Orientation Orientation {
+			get {
+				return orientation;
+			}
+			set {
+				int oldOrient = GetOrientation();
+
+				orientation = value;
+
+				ChangeWindowStyle( oldOrient, GetOrientation() );
+				if( oldOrient != GetOrientation() )
+					Size = new Size(Height, Width);
+			}
+		}
+		[MonoTODO]
+		public int SmallChange {
+			get {
+				return smallChange;
+			}
+			set {
+				if ( value < 0 )
+					throw new Exception( string.Format("Value '{0}' must be greater than or equal to 0.", value));
+
+				smallChange = value;
+
+				if ( IsHandleCreated ) 
+					Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_SETLINESIZE, 0, value);
+			}
+		}
+
+		public override string Text {
+			get {
+				return base.Text;
+			}
+			set {
+				base.Text = value;
+			}
+		}
+
+		[MonoTODO]
+		public int TickFrequency {
+			get {
+				return tickFrequency;
+			}
+			set {
+				if ( value > 0 ) {
+					tickFrequency = value;
+					if ( IsHandleCreated ) 
+						Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_SETTICFREQ, value, 0);
+				}
+			}
+		}
+		[MonoTODO]
+		public TickStyle TickStyle {
+			get {
+				return tickStyle;
+			}
+			set {
+				int OldStyle = GetTickStyle();
+				tickStyle = value;
+				ChangeWindowStyle( OldStyle, GetTickStyle() );
+			}
+		}
+
+		[MonoTODO]
+		public int Value {
+			get {
+				if ( IsHandleCreated ) {
+					return Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_GETPOS, 0, 0);
+				}
+				return val;
+			}
+			set {
+				if ( value < Minimum || value > Maximum )
+					throw new ArgumentException(
+						string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
+
+				bool raiseEvent = ( val != value ) && ( ValueChanged != null );
+
+				val = value;
+				if ( IsHandleCreated )
+					Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_SETPOS, -1, val);
+
+				if( raiseEvent )
+					ValueChanged ( this, new EventArgs() );
+			}
+		}
+		
+		// --- Public Methods
+		
+		[MonoTODO]
+		public void SetRange(int minValue, int maxValue) 
+		{
+			Minimum = minValue;
+			Maximum = maxValue;
+
+			if ( IsHandleCreated )
+				Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_SETRANGE, 1,
+							MakeLong(Minimum, Maximum));
+		}
+		[MonoTODO]
+		public override string ToString() 
+		{
+			return string.Format("System.Windows.Forms.Trackbar, Minimum: {0}, Maximum: {1}, Value: {2}",
+						Minimum, Maximum, Value);
+		}
+		
+		// --- Public Events
+		
+		public event EventHandler Scroll;
+		public event EventHandler ValueChanged;
+        
+        // --- Protected Properties
+        //
+		[MonoTODO]
+		protected override CreateParams CreateParams {
+			get {
+				CreateParams createParams = new CreateParams ();
+
+				createParams.Caption = Text;
+				createParams.ClassName = "msctls_trackbar32";
+				createParams.X = Left;
+				createParams.Y = Top;
+				createParams.Width = Width;
+				createParams.Height = Height;
+				createParams.ClassStyle = 0;
+				createParams.ExStyle = 0;
+				createParams.Param = 0;
+				createParams.Parent = Parent.Handle;
+				createParams.Style = (int) (
+					WindowStyles.WS_CHILD | 
+					WindowStyles.WS_VISIBLE) | GetTickStyle() | 
+					GetOrientation() |
+					(int)TrackbarControlStyles.TBS_AUTOTICKS;
+
+				if( TabStop ) 
+					createParams.Style |= (int)WindowStyles.WS_TABSTOP;
+
+				return createParams;
+			}		
+		}
+
+		protected override ImeMode DefaultImeMode {
+			get {
+				return ImeMode.Disable;
+			}
+		}
+
+		protected override Size DefaultSize {
+			get {
+				return new System.Drawing.Size(100,34);
+			}
+		}
+		//
+		// --- Protected Methods
+		//
+		[MonoTODO]
+		protected override void CreateHandle() 
+		{
+			//FIXME: just to get it to run
+			base.CreateHandle();
+		}
+		[MonoTODO]
+		protected override bool IsInputKey(Keys keyData) 
+		{
+			if (	keyData == Keys.Left   || keyData == Keys.Right ||
+				keyData == Keys.Up     || keyData == Keys.Down ||
+				keyData == Keys.Home   || keyData == Keys.End ||
+				keyData == Keys.PageUp || keyData == Keys.PageDown )
+			return true;
+
+			return IsInputKey(keyData);
+		}
+		[MonoTODO]
+		protected override void OnBackColorChanged(EventArgs e) 
+		{
+			//FIXME:
+			base.OnBackColorChanged(e);
+		}
+		[MonoTODO]
+		protected override void OnHandleCreated(EventArgs e) 
+		{
+			base.OnHandleCreated(e);
+			Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_SETRANGE, 1, MakeLong(Minimum, Maximum));
+			Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_SETPOS, 1, val);
+			Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_SETTICFREQ, TickFrequency, 0);
+			Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_SETLINESIZE, 0, SmallChange);
+			Win32.SendMessage(Handle, (int)TrackbarMessages.TBM_SETPAGESIZE, 0, LargeChange);
+		}
+
+		protected virtual void OnScroll(EventArgs e) 
+		{
+			if ( Scroll != null)
+				Scroll ( this, e );
+		}
+
+		[MonoTODO]
+		protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) 
+		{
+			//FIXME:
+			base.SetBoundsCore(x, y, width, height, specified);
+		}
+
+		[MonoTODO]
+		protected override void WndProc(ref Message m)
+		{
+			switch ( m.Msg ) {
+			case Msg.WM_HSCROLL:
+			case Msg.WM_VSCROLL:
+				OnScroll( new EventArgs() );
+				if ( ValueChanged != null )
+					ValueChanged (this, new EventArgs() );
+			break;
+			}
+			base.WndProc(ref m);
+		}
+
+		[MonoTODO]
+		void ISupportInitialize.BeginInit()
+		{
+			//FIXME:
+		}
+
+		[MonoTODO]
+		void ISupportInitialize.EndInit(){
+			//FIXME:
+		}
+
+		private int MakeLong(int lo, int hi)
+		{
+			return (hi << 16) | (lo & 0x0000ffff);
+		}
+
+		private int GetTickStyle()
+		{
+			int style = 0;
+
+			switch ( tickStyle ) {
+			case TickStyle.Both:
+				style = (int)TrackbarControlStyles.TBS_BOTH;
+			break;
+			case TickStyle.BottomRight:
+				style = (int)TrackbarControlStyles.TBS_BOTTOM | (int)TrackbarControlStyles.TBS_RIGHT;
+			break;
+			case TickStyle.TopLeft:
+				style = (int)TrackbarControlStyles.TBS_TOP | (int)TrackbarControlStyles.TBS_LEFT;
+			break;
+			default:
+				style = (int)TrackbarControlStyles.TBS_NOTICKS;
+			break;
+			};
+
+			return style;
+		}
+
+		private int GetOrientation()
+		{
+			if ( Orientation == Orientation.Horizontal )
+				return (int)TrackbarControlStyles.TBS_HORZ;
+			else
+				return (int)TrackbarControlStyles.TBS_VERT;
+		}
+
+		private bool ChangeWindowStyle(int Remove, int Add)
+		{
+			if( IsHandleCreated ) {
+				int style = Win32.GetWindowLong( Handle, GetWindowLongFlag.GWL_STYLE ).ToInt32();
+				int newStyle = (style & ~Remove) | Add;
+				if (style != newStyle) {
+					Win32.SetWindowLong(Handle, GetWindowLongFlag.GWL_STYLE, newStyle);
+					return true;
+				}
+			}
+			return false;
+		}
+	}
+}
+
Index: win32Enums.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/win32Enums.cs,v
retrieving revision 1.7
diff -u -r1.7 win32Enums.cs
--- win32Enums.cs	1 Mar 2003 21:20:31 -0000	1.7
+++ win32Enums.cs	6 Mar 2003 16:04:36 -0000
@@ -2315,6 +2315,73 @@
 		LBN_KILLFOCUS       =5
 	}
 
+	#region Trackbar Control Messages
+	internal enum TrackbarMessages {
+		TBM_GETPOS          =  ( Msg.WM_USER ),
+		TBM_GETRANGEMIN     =  ( Msg.WM_USER + 1),
+		TBM_GETRANGEMAX     =  ( Msg.WM_USER + 2),
+		TBM_GETTIC          =  ( Msg.WM_USER + 3),
+		TBM_SETTIC          =  ( Msg.WM_USER + 4),
+		TBM_SETPOS          =  ( Msg.WM_USER + 5 ),
+		TBM_SETRANGE        =  ( Msg.WM_USER + 6 ),
+		TBM_SETRANGEMIN     =  ( Msg.WM_USER + 7 ),
+		TBM_SETRANGEMAX     =  ( Msg.WM_USER + 8 ),
+		TBM_CLEARTICS       =  ( Msg.WM_USER + 9 ),
+		TBM_SETSEL          =  ( Msg.WM_USER + 10 ),
+		TBM_SETSELSTART     =  ( Msg.WM_USER + 11 ),
+		TBM_SETSELEND       =  ( Msg.WM_USER + 12 ),
+		TBM_GETPTICS        =  ( Msg.WM_USER + 14 ),
+		TBM_GETTICPOS       =  ( Msg.WM_USER + 15 ),
+		TBM_GETNUMTICS      =  ( Msg.WM_USER + 16 ),
+		TBM_GETSELSTART     =  ( Msg.WM_USER + 17 ),
+		TBM_GETSELEND       =  ( Msg.WM_USER + 18 ),
+		TBM_CLEARSEL        =  ( Msg.WM_USER + 19 ),
+		TBM_SETTICFREQ      =  ( Msg.WM_USER + 20 ),
+		TBM_SETPAGESIZE     =  ( Msg.WM_USER + 21 ),
+		TBM_GETPAGESIZE     =  ( Msg.WM_USER + 22 ),
+		TBM_SETLINESIZE     =  ( Msg.WM_USER + 23 ),
+		TBM_GETLINESIZE     =  ( Msg.WM_USER + 24 ),
+		TBM_GETTHUMBRECT    =  ( Msg.WM_USER + 25 ),
+		TBM_GETCHANNELRECT  =  ( Msg.WM_USER + 26 ),
+		TBM_SETTHUMBLENGTH  =  ( Msg.WM_USER + 27 ),
+		TBM_GETTHUMBLENGTH  =  ( Msg.WM_USER + 28 ),
+		TBM_SETTOOLTIPS     =  ( Msg.WM_USER + 29 ),
+		TBM_GETTOOLTIPS     =  ( Msg.WM_USER + 30 ),
+		TBM_SETTIPSIDE      =  ( Msg.WM_USER + 31 )
+	}
+	#endregion
+		
+	#region Trackbar Control Styles
+	public enum TrackbarControlStyles {
+		TBS_AUTOTICKS       =    0x0001,
+		TBS_VERT            =    0x0002,
+		TBS_HORZ            =    0x0000,
+		TBS_TOP             =    0x0004,
+		TBS_BOTTOM          =    0x0000,
+		TBS_LEFT            =    0x0004,
+		TBS_RIGHT           =    0x0000,
+		TBS_BOTH            =    0x0008,
+		TBS_NOTICKS         =    0x0010,
+		TBS_ENABLESELRANGE  =    0x0020,
+		TBS_FIXEDLENGTH     =    0x0040,
+		TBS_NOTHUMB         =    0x0080,
+		TBS_TOOLTIPS        =    0x0100
+	}
+	#endregion
+
+	internal enum TrackbarNotifications : int {
+		TB_LINEUP           =    0,
+		TB_LINEDOWN         =    1,
+		TB_PAGEUP           =    2,
+		TB_PAGEDOWN         =    3,
+		TB_THUMBPOSITION    =    4,
+		TB_THUMBTRACK       =    5,
+		TB_TOP              =    6,
+		TB_BOTTOM           =    7,
+		TB_ENDTRACK         =    8
+	}
+
+
 	internal enum OwnerDrawTypes : int {
 		ODT_COMBOBOX = 3,
 		ODT_LISTBOX = 2,

--0-1097343193-1046967241=:26058--