[Mono-winforms-list] patch for System.Windows.Forms

Aleksey Ryabchuk ryabchuk@yahoo.com
Wed, 19 Mar 2003 09:27:01 -0800 (PST)


--0-681039431-1048094821=:60258
Content-Type: text/plain; charset=us-ascii
Content-Id: 
Content-Disposition: inline

Hello,

Here is implementation of Timer class and small
modifications in 
Control.cs
Form.cs
GroupBox.cs
Label.cs
Panel.cs
TrackBar.cs
win32functions.cs

Regards
Aleksey


__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
--0-681039431-1048094821=:60258
Content-Type: text/plain; name=patch
Content-Description: patch
Content-Disposition: inline; filename=patch

Index: Control.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/Control.cs,v
retrieving revision 1.29
diff -u -r1.29 Control.cs
--- Control.cs	15 Mar 2003 19:31:43 -0000	1.29
+++ Control.cs	19 Mar 2003 17:17:55 -0000
@@ -1090,15 +1090,13 @@
   			//Compact Framework
     		public bool Visible {
     			get {
-    				throw new NotImplementedException ();
+				return visible;
     			}
     			set {
-    				if (value)
-    					Win32.ShowWindow (
-    						Handle, ShowWindowStyles.SW_SHOW);
-    				else
-    					Win32.ShowWindow (
-    						Handle, ShowWindowStyles.SW_HIDE);
+				visible = value;
+				if ( visible ) 
+					 Show();
+				else	 Hide ();
     			}
     		}
     		
@@ -2247,7 +2245,8 @@
  			//Compact Framework
     		public void Show () 
     		{
-    			Win32.ShowWindow (Handle, ShowWindowStyles.SW_SHOW);
+			if (IsHandleCreated)
+	    			Win32.ShowWindow (Handle, ShowWindowStyles.SW_SHOW);
     		}
     		
     		[MonoTODO]
@@ -2544,6 +2543,10 @@
 					break;
 				case Msg.WM_DRAWITEM:
 					Control.ReflectMessage( m.WParam, ref m);
+					break;
+				case Msg.WM_HSCROLL:
+				case Msg.WM_VSCROLL:
+					Control.ReflectMessage( m.LParam, ref m );
 					break;
 				default:
 					CallControlWndProc(ref m);
Index: Form.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/Form.cs,v
retrieving revision 1.30
diff -u -r1.30 Form.cs
--- Form.cs	9 Mar 2003 17:38:41 -0000	1.30
+++ Form.cs	19 Mar 2003 17:17:55 -0000
@@ -564,7 +564,13 @@
     		
     		protected override CreateParams CreateParams {
     			get {
-    				return base.CreateParams;
+				CreateParams pars = base.CreateParams;
+				pars.Style |= (int)( WindowStyles.WS_OVERLAPPEDWINDOW | 
+							WindowStyles.WS_CLIPSIBLINGS /* |
+							WindowStyles.WS_CLIPCHILDREN */);
+				// should have WS_CLIPCHILDREN style but there are
+				// problems with GroupBox at the moment
+				return pars;
     			}
     		}
     
@@ -917,10 +923,6 @@
 					break;
 				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);
Index: GroupBox.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/GroupBox.cs,v
retrieving revision 1.12
diff -u -r1.12 GroupBox.cs
--- GroupBox.cs	6 Feb 2003 03:45:10 -0000	1.12
+++ GroupBox.cs	19 Mar 2003 17:17:55 -0000
@@ -77,9 +77,6 @@
 			get {
 				if( Parent != null) {
 					CreateParams createParams = new CreateParams ();
-					if( window == null) {
-						window = new ControlNativeWindow (this);
-					}
 	 
 					createParams.Caption = Text;
 					createParams.ClassName = "BUTTON";
@@ -92,10 +89,13 @@
 					createParams.Param = 0;
 					createParams.Parent = Parent.Handle;
 					createParams.Style = (int) (
-						(int)WindowStyles.WS_CHILD | 
-						(int)WindowStyles.WS_VISIBLE | 
+						(int)WindowStyles.WS_CHILDWINDOW | 
 						(int)ButtonStyles.BS_GROUPBOX |
-						(int)SS_Static_Control_Types.SS_LEFT );
+						(int)SS_Static_Control_Types.SS_LEFT |
+						(int)WindowStyles.WS_CLIPCHILDREN |
+						(int)WindowStyles.WS_CLIPSIBLINGS |
+						(int)WindowStyles.WS_OVERLAPPED);
+					
 					return createParams;
 				}
 				return null;
Index: Label.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/Label.cs,v
retrieving revision 1.12
diff -u -r1.12 Label.cs
--- Label.cs	6 Feb 2003 03:45:10 -0000	1.12
+++ Label.cs	19 Mar 2003 17:17:55 -0000
@@ -198,10 +198,6 @@
 					if( Parent != null) {
 						CreateParams createParams = new CreateParams ();
 
-						if(window == null) {
-							window = new ControlNativeWindow (this);
-						}
-		 
 						createParams.Caption = Text;
 						createParams.ClassName = "Static";
 						createParams.X = Left;
@@ -215,8 +211,10 @@
 						createParams.Style = (int) (
 							(int)WindowStyles.WS_CHILD | 
 							(int)WindowStyles.WS_VISIBLE | 
-							(int)SS_Static_Control_Types.SS_LEFT );
-						window.CreateHandle (createParams);
+							(int)SS_Static_Control_Types.SS_LEFT |
+							(int)WindowStyles.WS_CLIPCHILDREN |
+							(int)WindowStyles.WS_CLIPSIBLINGS );
+
 						return createParams;
 					}
 					return null;
Index: Panel.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/Panel.cs,v
retrieving revision 1.10
diff -u -r1.10 Panel.cs
--- Panel.cs	15 Mar 2003 19:31:43 -0000	1.10
+++ Panel.cs	19 Mar 2003 17:17:55 -0000
@@ -82,7 +82,9 @@
 					createParams.Parent = Parent.Handle;
 					createParams.Style = (int) (
 						WindowStyles.WS_CHILD | 
-						WindowStyles.WS_VISIBLE);
+						WindowStyles.WS_VISIBLE |
+						WindowStyles.WS_CLIPCHILDREN |
+						WindowStyles.WS_CLIPSIBLINGS);
 
 					switch (BorderStyle) {
 					case BorderStyle.Fixed3D:
Index: Timer.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/Timer.cs,v
retrieving revision 1.8
diff -u -r1.8 Timer.cs
--- Timer.cs	7 Dec 2002 03:15:13 -0000	1.8
+++ Timer.cs	19 Mar 2003 17:17:55 -0000
@@ -2,85 +2,108 @@
 // System.Windows.Forms.Timer
 //
 // Author:
-//   stubbed out by Jackson Harper (jackson@latitudegeo.com)
+//	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.Runtime.InteropServices;
+using System.Collections;
+
 namespace System.Windows.Forms {
 
 	// <summary>
+	//	Represents a timer that raises an event at user-defined intervals.
 	// </summary>
-using System.ComponentModel;
-    public class Timer : Component {
+	public class Timer : Component {
 
-		//
-		//  --- Public Constructors
-		//
-		[MonoTODO]
-		public Timer()
-		{
-			
+		private bool enabled = false;
+		private int  interval = 100;
+		private uint timerid = 0;
+		private GCHandle timerHandle;
+		private Win32.TimerProc proc;
+
+		public Timer(){
 		}
-		[MonoTODO]
-		public Timer(IContainer container)
-		{
-			
+
+		public Timer( IContainer container ) {
+			container.Add ( this );
 		}
-		//
-		// --- Public Properties
-		//
-		[MonoTODO]
+
 		public virtual bool Enabled {
-			get {
-				throw new NotImplementedException ();
+			get { 
+				return enabled;
 			}
-			set {
-				//FIXME:
+			set { 
+				enabled = value;
+				if ( enabled ) {
+					if ( !timerHandle.IsAllocated )
+						timerHandle = GCHandle.Alloc( this );
+
+					if ( proc == null )
+						proc = new Win32.TimerProc( this.TimeProc );
+					
+					timerid = Win32.SetTimer( IntPtr.Zero,	0, (uint)Interval, proc );
+				}
+				else {
+					if ( timerid != 0 )
+						Win32.KillTimer ( IntPtr.Zero , timerid );
+
+					timerid = 0;
+
+					if ( timerHandle.IsAllocated )
+						timerHandle.Free();
+				}
 			}
 		}
-		[MonoTODO]
+
 		public int Interval {
 			get {
-				throw new NotImplementedException ();
+				return interval;
 			}
 			set {
-				//FIXME:
+				if ( value <= 0 )
+					throw new ArgumentException (
+					string.Format (" '{0}' is not a valid value for Interval. Interval must be greater than 0.",
+							value ) );
+				interval = value;
+				if ( Enabled )
+					Enabled = true; // restart
 			}
 		}
-		//
-		// --- Public Methods
-		//
-		[MonoTODO]
-		public void Start() 
-		{
-			//FIXME:
+
+		public void Start() {
+			Enabled = true;
 		}
-		[MonoTODO]
-		public void Stop() 
-		{
-			//FIXME:
+
+		public void Stop() {
+			Enabled = false;
 		}
-		[MonoTODO]
+
 		public override string ToString() 
 		{
-			//FIXME:
-			return base.ToString();
+			return "[" + GetType().FullName.ToString() + "], Interval: " + Interval;
 		}
-		//
-		// --- Public Events
-		//
-		[MonoTODO]
+
 		public event EventHandler Tick;
-		//
-		// --- Protected Methods
-		//
 
-		[MonoTODO]
 		protected virtual void OnTick(EventArgs e) 
 		{
-			//FIXME:
+			if ( Tick != null )
+				Tick ( this, e );
+		}
+
+		private void TimeProc( IntPtr hwnd, uint uMsg, uint idEvent, int dwTime )
+		{
+			OnTick ( EventArgs.Empty );
+		}  
+		
+		protected override void Dispose( bool disposing	) {
+			Enabled = false;
+			base.Dispose ( disposing );
 		}
 	}
 }
Index: TrackBar.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/TrackBar.cs,v
retrieving revision 1.13
diff -u -r1.13 TrackBar.cs
--- TrackBar.cs	9 Mar 2003 17:38:41 -0000	1.13
+++ TrackBar.cs	19 Mar 2003 17:17:55 -0000
@@ -332,8 +332,10 @@
 				if ( ValueChanged != null )
 					ValueChanged (this, new EventArgs() );
 			break;
+			default:
+				base.WndProc(ref m);
+			break;
 			}
-			base.WndProc(ref m);
 		}
 
 		[MonoTODO]
Index: win32functions.cs
===================================================================
RCS file: /mono/mcs/class/System.Windows.Forms/System.Windows.Forms/win32functions.cs,v
retrieving revision 1.14
diff -u -r1.14 win32functions.cs
--- win32functions.cs	15 Mar 2003 19:31:43 -0000	1.14
+++ win32functions.cs	19 Mar 2003 17:17:56 -0000
@@ -489,6 +489,11 @@
 		[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
 		internal static extern int GetSysColor( GetSysColorIndex color);
 
+		internal delegate void TimerProc(IntPtr hWnd, uint uMsg, uint idEvent, int dwTime);
+		[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
+		internal static extern uint SetTimer (IntPtr hWnd, uint nIDEvent, uint uElapse, TimerProc lpTimerFunc);
+		[DllImport("user32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
+		internal static extern bool KillTimer (IntPtr hWnd, uint nIDEvent);
 		#endregion
 
 		#region Shell32.dll functions

--0-681039431-1048094821=:60258--