* Control.cs : Cursor property, handle WM_SETCURSOR
authorAleksey Ryabchuk <aleksey@mono-cvs.ximian.com>
Mon, 9 Jun 2003 16:22:45 +0000 (16:22 -0000)
committerAleksey Ryabchuk <aleksey@mono-cvs.ximian.com>
Mon, 9 Jun 2003 16:22:45 +0000 (16:22 -0000)
* Cursor.cs : started implementation
* Cursors.cs : load system cursor types
* win32functions.cs : DestroyCursor function

svn path=/trunk/mcs/; revision=15245

mcs/class/System.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/System.Windows.Forms/System.Windows.Forms/Control.cs
mcs/class/System.Windows.Forms/System.Windows.Forms/Cursor.cs
mcs/class/System.Windows.Forms/System.Windows.Forms/Cursors.cs
mcs/class/System.Windows.Forms/System.Windows.Forms/win32functions.cs

index 26cd8adaf2555281e34a973e4bc7c6a34299ecbd..0fcd8b5aa4f9580ed1a593f853496f3d6e8f8317 100644 (file)
@@ -1,3 +1,9 @@
+2003-06-09 Aleksey Ryabchuk <ryabchuk@yahoo.com>
+       * Control.cs : Cursor property, handle WM_SETCURSOR
+       * Cursor.cs : started implementation
+       * Cursors.cs : load system cursor types
+       * win32functions.cs : DestroyCursor function
+
 2003-06-09 Aleksey Ryabchuk <ryabchuk@yahoo.com>
        * HScrollBar.cs
        * ScrollBar.cs
index 901b8b840503116181c684a5c87197c15695f69e..3c5224090cf88d02c67b74bde04686cc7da635dc 100644 (file)
@@ -88,6 +88,7 @@
                protected string text;
                protected bool visible;
                protected ControlStyles controlStyles_;
+               Cursor  cursor;
 
                int clientWidth;
                int clientHeight;
                        text = "";
                        visible = true;
                        parent = null;
+                       cursor = null;
 
                        oldBounds.Width  = bounds.Width = DefaultSize.Width;
                        oldBounds.Height = bounds.Height= DefaultSize.Height;
 
                [MonoTODO]
                public virtual Cursor Cursor {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+                       get { 
+                               if ( cursor == null )
+                                       return Cursors.Default;
+                               return cursor; 
+                       }
+                       set { cursor = value;}
                }
                
                        //Compact Framework
                                        CallControlWndProc(ref m);
                                        }
                                        break;
+                               case Msg.WM_SETCURSOR:
+                                       if ( cursor != null && cursor.Handle != IntPtr.Zero ) {
+                                               Win32.SetCursor ( cursor.Handle );
+                                               m.Result = (IntPtr)1;
+                                       } else
+                                               CallControlWndProc( ref m );
+                               break;
                                default:
                                        CallControlWndProc(ref m);
 /*
index e7d80b67d09930860690945df712aab21aa448c1..66732988b9f64ad1f758f2a73ee60f5dc9164a43 100644 (file)
@@ -4,10 +4,11 @@
 // Author:
 //   stubbed out by Jaak Simm (jaaksimm@firm.ee)
 //   Dennis Hayes (dennish@Raytek.com)
+//   Aleksey Ryabchuk (ryabchuk@yahoo.com)
 //
 // (C) Ximian, Inc., 2002
 //
-
+using System;
 using System.ComponentModel;
 using System.Runtime.Serialization;
 using System.IO;
@@ -24,13 +25,24 @@ namespace System.Windows.Forms {
        public sealed class Cursor : IDisposable, ISerializable {
 
                #region Fields
+               private IntPtr handle;
+               private bool   fromResource    = false;
+               private bool   disposed        = false;
+               private CursorType ctype;
                #endregion
                
                #region Constructors
+               internal Cursor ( CursorType type )
+               {
+                       handle = Win32.LoadCursor ( IntPtr.Zero, type );
+                       fromResource = true;
+                       ctype  = type;
+               }
+
                [MonoTODO]
-               public Cursor(IntPtr handle
+               public Cursor( IntPtr handle 
                {
-                       
+                       this.handle = handle;   
                }
                
                [MonoTODO]
@@ -75,7 +87,7 @@ namespace System.Windows.Forms {
                
                [MonoTODO]
                public IntPtr Handle {
-                       get { throw new NotImplementedException (); }
+                       get { return handle; }
                }
                
                [MonoTODO]
@@ -97,12 +109,29 @@ namespace System.Windows.Forms {
                        throw new NotImplementedException ();
                }
                
-               [MonoTODO]
                public void Dispose() 
                {
-                       throw new NotImplementedException ();
+                       GC.SuppressFinalize( this );
+                       Dispose( true );
                }
                
+               private void Dispose( bool disposing )
+               {
+                       lock ( this ) {
+                               if ( disposing ) {
+                                       // dispose managed resources
+                               }
+                               if ( !this.disposed ) {
+                                       // release all unmanaged resources
+                                       // shared cursor should not be destroyed
+                                       if ( !fromResource )
+                                               Win32.DestroyCursor ( handle );
+                                       handle = IntPtr.Zero;
+                               }
+                               disposed = true;         
+                       }
+               }
+
                [MonoTODO]
                public void Draw(Graphics g,Rectangle targetRect) 
                {
@@ -118,13 +147,17 @@ namespace System.Windows.Forms {
                [MonoTODO]
                public override bool Equals(object obj) 
                {
-                       //FIXME:
-                       return base.Equals(obj);
+                       if ( obj == null ) return false;
+                       if ( this.GetType ( ) != obj.GetType ( ) ) return false;
+                       Cursor other = ( Cursor ) obj;
+                       if ( !fromResource.Equals ( other.fromResource ) ) return false;
+                       if ( !ctype.Equals ( other.ctype ) ) return false;
+
+                       return true;
                }
                
-               [MonoTODO]
                ~Cursor() {
-                       throw new NotImplementedException ();
+                       Dispose ( false );
                }
                
                [MonoTODO]
@@ -165,13 +198,13 @@ namespace System.Windows.Forms {
                [MonoTODO]
                public static bool operator ==(Cursor left, Cursor right) 
                {
-                       throw new NotImplementedException ();
+                       return Object.Equals ( left, right );
                }
                
                [MonoTODO]
                public static bool operator !=(Cursor left, Cursor right) 
                {
-                       throw new NotImplementedException ();
+                       return ! ( left == right );
                }
                #endregion
        }
index 16a8e6db7313f00e464c1651f81e64b6e70a8159..a9782e73b7ab18db323181771a5efcad95e1501b 100644 (file)
@@ -4,6 +4,7 @@
 // Author:
 //   stubbed out by Jaak Simm (jaaksimm@firm.ee)
 //   Dennis Hayes (dennish@Raytek.com)
+//   Aleksey Ryabchuk (ryabchuk@yahoo.com)
 //
 // (C) Ximian, Inc., 2002
 //
@@ -19,61 +20,31 @@ namespace System.Windows.Forms {
        /// Provides a collection of Cursor objects for use by a Windows Forms application.
        /// </summary>
 
-       [MonoTODO]
-       public sealed class Cursors {
+       public sealed class Cursors{
 
-               #region Properties
-               [MonoTODO]
                public static Cursor AppStarting {
-                       
-                       get {
-//HANDLE LoadImage(
-//  HINSTANCE hinst,   // handle to instance // = null
-//  LPCTSTR lpszName,  // image to load // = IDC_APPSTARTING
-//  UINT uType,        // image type //= IMAGE_CURSOR
-//  int cxDesired,     // desired width  // = 0
-//  int cyDesired,     // desired height // = 0
-//  UINT fuLoad        // load options // = LR_DEFAULTSIZE || ??
-//);
-                               //Cursor cursor = new Cursor(
-                               throw new NotImplementedException (); 
-                       }
+                       get { return new Cursor ( CursorType.IDC_APPSTARTING ); }
                }
                
-               [MonoTODO]
                public static Cursor Arrow {
-                       //  LPCTSTR lpszName,  // image to load // = IDC_ARROW
-                       get {
-                               throw new NotImplementedException (); 
-                       }
+                       get { return new Cursor ( CursorType.IDC_ARROW ); }
                }
                
-               [MonoTODO]
                public static Cursor Cross {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return new Cursor ( CursorType.IDC_CROSS ); }
                }
                
                [MonoTODO]
                public static Cursor Default {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return new Cursor ( CursorType.IDC_ARROW ); }
                }
                
-               [MonoTODO]
                public static Cursor Hand {
-                       get {
-                               throw new NotImplementedException (); 
-                       }
+                       get { return new Cursor ( CursorType.IDC_HAND ); }
                }
                
-               [MonoTODO]
                public static Cursor Help {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return new Cursor ( CursorType.IDC_HELP ); }
                }
                
                [MonoTODO]
@@ -83,18 +54,12 @@ namespace System.Windows.Forms {
                        }
                }
                
-               [MonoTODO]
                public static Cursor IBeam {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return new Cursor ( CursorType.IDC_IBEAM ); }
                }
                
-               [MonoTODO]
                public static Cursor No {
-                       get {
-                               throw new NotImplementedException (); 
-                       }
+                       get { return new Cursor ( CursorType.IDC_NO ); }
                }
                
                [MonoTODO]
@@ -174,46 +139,28 @@ namespace System.Windows.Forms {
                        }
                }
                
-               [MonoTODO]
                public static Cursor SizeAll {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return new Cursor ( CursorType.IDC_SIZEALL ); }
                }
                
-               [MonoTODO]
                public static Cursor SizeNESW {
-                       get { 
-                               throw new NotImplementedException ();
-                       }
+                       get { return new Cursor ( CursorType.IDC_SIZENESW ); }
                }
                
-               [MonoTODO]
                public static Cursor SizeNS {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return new Cursor ( CursorType.IDC_SIZENS ); }
                }
                
-               [MonoTODO]
                public static Cursor SizeNWSE {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return new Cursor ( CursorType.IDC_SIZENWSE ); }
                }
                
-               [MonoTODO]
                public static Cursor SizeWE {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return new Cursor ( CursorType.IDC_SIZEWE ); }
                }
                
-               [MonoTODO]
                public static Cursor UpArrow {
-                       get {
-                               throw new NotImplementedException ();
-                       }
+                       get { return new Cursor ( CursorType.IDC_UPARROW ); }
                }
                
                [MonoTODO]
@@ -223,12 +170,8 @@ namespace System.Windows.Forms {
                        }
                }
                
-               [MonoTODO]
                public static Cursor WaitCursor {
-                       get { 
-                               throw new NotImplementedException ();
-                       }
+                       get { return new Cursor ( CursorType.IDC_WAIT ); }
                }
-               #endregion
        }
 }
index eb3b97e293e8d81523cef67fefaa36ca2105f4bc..fba195b38d5bb19d64d9dec776abd299528fb16b 100644 (file)
@@ -306,6 +306,9 @@ namespace System.Windows.Forms{
                [DllImport("user32.dll", CharSet=CharSet.Auto,EntryPoint="LoadCursorA")]
                internal static extern IntPtr LoadCursor(IntPtr hInstance, CursorType cursor);
 
+               [DllImport("user32.dll", CharSet=CharSet.Ansi)]
+               internal static extern bool DestroyCursor ( IntPtr hCursor );
+
                [DllImport("user32.dll", CharSet=CharSet.Auto)]
                internal static extern IntPtr SetCursor(IntPtr hCursor);