some new functions implemented, using BitVector32
authorAleksey Ryabchuk <aleksey@mono-cvs.ximian.com>
Fri, 11 Apr 2003 16:09:29 +0000 (16:09 -0000)
committerAleksey Ryabchuk <aleksey@mono-cvs.ximian.com>
Fri, 11 Apr 2003 16:09:29 +0000 (16:09 -0000)
instead of declaring separate boolean varibales for every control status

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

mcs/class/System.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/System.Windows.Forms/System.Windows.Forms/Control.cs

index 84c964ae581ee2159388126a9be488b7113beb0e..0817779ce89ecb02bf7e3cc4f7a0a09b928efd4c 100644 (file)
@@ -1,3 +1,7 @@
+2003-04-11 Aleksey Ryabchuk <ryabchuk@yahoo.com>
+       * Control.cs : some new functions implemented, using BitVector32
+                       instead of declaring separate boolean varibales for every control status
+                       
 2003-04-11 Aleksey Ryabchuk <ryabchuk@yahoo.com>
        * Control.cs
        * Form.cs
index a6a7c92b05a17f86ad9eb8f66a0cdaf8b1f0a5eb..7418062817324b997c7b3fe320a0e4b0053ae0c9 100644 (file)
@@ -17,7 +17,8 @@
        using System.Threading;
        using System.Text;
     using System.Runtime.InteropServices;
-    
+    using System.Collections.Specialized;
+
     namespace System.Windows.Forms {
     
        /// <summary>
                bool tabStop;
                string text;
                bool visible;
-               bool isDisposed;
+
+               int clientWidth;
+               int clientHeight;
+
+               BitVector32 statuses;
+               private static readonly int LAYOUT_SUSPENDED = BitVector32.CreateMask();
+               private static readonly int LAYOUT_PENDING   = BitVector32.CreateMask( LAYOUT_SUSPENDED );
+               private static readonly int DISPOSED         = BitVector32.CreateMask( LAYOUT_PENDING );
+               private static readonly int RECREATING_HANDLE= BitVector32.CreateMask( DISPOSED );
 
                        object tag;
                        protected bool mouseIsInside_;
-                       bool recreatingHandle;
 
                        // BeginInvoke() etc. helpers
                        static int InvokeMessage = Win32.RegisterWindowMessage("mono_control_invoke_helper");
                public Control ()
                {
                        CreateControlsInstance ();
-    
+
+                       statuses = new BitVector32(); 
+                       
                        accessibleDefaultActionDescription = null;
                        accessibleDescription = null;
                        accessibleName = null;
                        text = "";
                        visible = true;
                        parent = null;
-                       isDisposed = false;
 
                        bounds.Width = DefaultSize.Width;
                        bounds.Height= DefaultSize.Height;
 
                        mouseIsInside_ = false;
-                               recreatingHandle = false;
                                // Do not create Handle here, only in CreateHandle
                        // CreateHandle();//sets window handle. FIXME: No it does not
                }
                }
                
                public bool IsDisposed {
-                       get {   return isDisposed; }
-                               //if (Handle == (IntPtr) 0)
-                               //      return true;
-                               //return false;
+                       get {   return statuses [ DISPOSED ]; }
                }
                
                public bool IsHandleCreated {
                [MonoTODO]
                public bool RecreatingHandle {
                        get {
-                               return recreatingHandle;
+                               return statuses [ RECREATING_HANDLE ] ;
                        }
                }
                
        
                protected override void Dispose (bool disposing) 
                {
-                       isDisposed = true;
+                       statuses [ DISPOSED ] = true;
                                //FIXME: 
                        base.Dispose(disposing);
                }
                
                protected virtual void OnLayout (LayoutEventArgs e) 
                {
+                       DoDockAndAnchorLayout ( e );
                        if (Layout != null)
                                Layout (this, e);
                }
                {
                        if (Resize != null)
                                Resize (this, e);
+
+                       PerformLayout ( );
                }
                
                protected virtual void OnRightToLeftChanged (EventArgs e) 
                {
                        if (VisibleChanged != null)
                                VisibleChanged (this, e);
+
+                       PerformLayout ( );
                }
                // --- end of methods for events ---
                
                [MonoTODO]
                public void PerformLayout () 
                {
-                               //FIXME:
-                       }
+                       PerformLayout ( null, null );
+               }
                
                [MonoTODO]
                public void PerformLayout (Control affectedControl,
                                           string affectedProperty) 
                {
-                               //FIXME:
-                       }
+                       if ( !statuses [ LAYOUT_SUSPENDED ] )
+                               OnLayout ( new LayoutEventArgs ( affectedControl, affectedProperty ) );
+                       else
+                               statuses [ LAYOUT_PENDING ] = true;
+               }
                
                        //Compact Framework
                [MonoTODO]
                // are big enough to warrant recreating the HWND
                protected void RecreateHandle() 
                {
-                               recreatingHandle = true;
-                               if( IsHandleCreated) {
-                                       DestroyHandle ();
-                                       CreateHandle ();
-                               }
-                               recreatingHandle = false;
+                       statuses [ RECREATING_HANDLE ] = true;
+                       if( IsHandleCreated) {
+                               DestroyHandle ();
+                               CreateHandle ();
                        }
+                       statuses [ RECREATING_HANDLE ] = false;
+               }
                
                        //Compact Framework
                [MonoTODO]
                [MonoTODO]
                public void ResumeLayout () 
                {
-                               //FIXME:
+                       statuses [ LAYOUT_SUSPENDED ] = false;
+                       if ( statuses [ LAYOUT_PENDING ] ) {
+                               PerformLayout ( );
+                               statuses [ LAYOUT_PENDING ] = false;
                        }
+               }
                
                [MonoTODO]
                public void ResumeLayout (bool performLayout) 
                {
-                               //FIXME:
+                       statuses [ LAYOUT_SUSPENDED ] = false;
+                       if ( performLayout && statuses [ LAYOUT_PENDING ] ) {
+                               PerformLayout ( );
+                               statuses [ LAYOUT_PENDING ] = false;
                        }
+               }
                
                [MonoTODO]
                protected ContentAlignment RtlTranslateAlignment (
                                Win32.ShowWindow (Handle, ShowWindowStyles.SW_SHOW);
                }
                
-               [MonoTODO]
                public void SuspendLayout () 
                {
-                               //FIXME:
-                       }
+                       statuses [ LAYOUT_SUSPENDED ] = true;
+               }
                
                        //Compact Framework
                public void Update () 
                
                [MonoTODO]
                protected void UpdateBounds () 
-               {
-                               //FIXME:
+               {       // update control bounds with current size and position
+
+                       // currently, this function is called in responce to
+                       // window events, so I assume that all window handles
+                       // are created
+                       RECT rect = new RECT ( );
+                       Win32.GetWindowRect ( Handle, ref rect );
+
+                       IntPtr parent = Win32.GetParent ( Handle );
+                       if ( parent != IntPtr.Zero ) {
+                               Win32.ScreenToClient( parent, ref rect );
                        }
+
+                       UpdateBounds ( rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top );
+               }
                
                [MonoTODO]
                protected void UpdateBounds (int x, int y, int width, int height) 
                {
-                               //FIXME:
-                       }
+                       UpdateBounds ( x , y, width, height, 0, 0 );
+                       //FIXME: provide correct client width and height
+               }
                
                [MonoTODO]
                protected void UpdateBounds (
                        int x, int y, int width, int height, int clientWidth,
                        int clientHeight)
                {
-                               //FIXME:
-                       }
+                       bool bLocationChanged = ( bounds.X != x ) || ( bounds.Y != y );
+                       bounds.X = x;
+                       bounds.Y = y;
+                       
+                       bool bSizeChanged = ( bounds.Width  != width ) || ( bounds.Height != height );
+                       bounds.Width  = width;
+                       bounds.Height = height;
+
+                       clientWidth   = clientWidth;
+                       clientHeight  = clientHeight;
+
+                       if ( bLocationChanged )
+                               OnLocationChanged ( EventArgs.Empty );
+                       if ( bSizeChanged )
+                               OnSizeChanged ( EventArgs.Empty );
+               }
                
                [MonoTODO]
                protected void UpdateStyles () 
                                        break;
                        case Msg.WM_MOVE:
                                OnMove (eventArgs);
-                                       CallControlWndProc(ref m);
-                                       break;
+                               UpdateBounds ( );
+                               CallControlWndProc(ref m);
+                               break;
                                case Msg.WM_NOTIFY:
                                        NMHDR nmhdr = (NMHDR)Marshal.PtrToStructure ( m.LParam,
                                                                        typeof ( NMHDR ) );
                                        break;
                        case Msg.WM_SIZE:
                                OnResize (eventArgs);
-                               OnSizeChanged (eventArgs);
-                                       CallControlWndProc(ref m);
-                                       break;
+                               UpdateBounds ( );
+                               CallControlWndProc(ref m);
+                               break;
                        case Msg.WM_WINDOWPOSCHANGED:
                                //OnResize (eventArgs);
                                CallControlWndProc(ref m);
                                break;
                        }
                }
+
+               private void DoDockAndAnchorLayout ( LayoutEventArgs e ) {
+                       /*
+                       IEnumerator cw = childControls.GetEnumerator();
+                       while ( cw.MoveNext() ) {
+                               Control control = (Control) cw.Current;
+                               if ( control.Dock == DockStyle.Bottom ) {
+                                       control.Width = ClientSize.Width;
+                               }                               
+                       }*/
+               }
                
                /// --- Control: events ---
                public event EventHandler BackColorChanged;