2006-05-10 Peter Dennis Bartok <pbartok@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Control.cs
index ea1550bbb3322d136849e7cd23291bd6f0aa6bc3..a23b86308881afcbfde200ab39205cadbcc11071 100644 (file)
@@ -731,7 +731,6 @@ namespace System.Windows.Forms
                private delegate void RemoveDelegate(object c);
 
                protected override void Dispose(bool disposing) {
-                       is_disposed = true;
                        if (dc_mem!=null) {
                                dc_mem.Dispose();
                                dc_mem=null;
@@ -751,6 +750,8 @@ namespace System.Windows.Forms
                                DestroyHandle();
                                controls.Remove(this);
                        }
+                       is_disposed = true;
+                       base.Dispose(disposing);
                }
                #endregion      // Public Constructors
 
@@ -1355,6 +1356,7 @@ namespace System.Windows.Forms
 
                [Localizable(true)]
                [DefaultValue(null)]
+               [MWFCategory("Accessibility")]
                public string AccessibleDescription {
                        get {
                                return AccessibilityObject.description;
@@ -1367,6 +1369,7 @@ namespace System.Windows.Forms
 
                [Localizable(true)]
                [DefaultValue(null)]
+               [MWFCategory("Accessibility")]
                public string AccessibleName {
                        get {
                                return AccessibilityObject.Name;
@@ -1390,6 +1393,7 @@ namespace System.Windows.Forms
                }
 
                [DefaultValue(false)]
+               [MWFCategory("Behavior")]
                public virtual bool AllowDrop {
                        get {
                                return allow_drop;
@@ -1399,14 +1403,17 @@ namespace System.Windows.Forms
                                if (allow_drop == value)
                                        return;
                                allow_drop = value;
-                               UpdateStyles();
-                               XplatUI.SetAllowDrop (Handle, value);
+                               if (IsHandleCreated) {
+                                       UpdateStyles();
+                                       XplatUI.SetAllowDrop (Handle, value);
+                               }
                        }
                }
 
                [Localizable(true)]
                [RefreshProperties(RefreshProperties.Repaint)]
-               [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
+               [DefaultValue(AnchorStyles.Top | AnchorStyles.Left)]
+               [MWFCategory("Layout")]
                public virtual AnchorStyles Anchor {
                        get {
                                return anchor_style;
@@ -1438,6 +1445,7 @@ namespace System.Windows.Forms
 #endif // NET_2_0
 
                [DispId(-501)]
+               [MWFCategory("Appearance")]
                public virtual Color BackColor {
                        get {
                                if (background_color.IsEmpty) {
@@ -1465,6 +1473,7 @@ namespace System.Windows.Forms
 
                [Localizable(true)]
                [DefaultValue(null)]
+               [MWFCategory("Appearance")]
                public virtual Image BackgroundImage {
                        get {
                                return background_image;
@@ -1555,6 +1564,16 @@ namespace System.Windows.Forms
                        }
                }
 
+               internal virtual bool InternalCapture {
+                       get {
+                               return Capture;
+                       }
+
+                       set {
+                               Capture = value;
+                       }
+               }
+
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                [Browsable(false)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
@@ -1577,6 +1596,7 @@ namespace System.Windows.Forms
                }
 
                [DefaultValue(true)]
+               [MWFCategory("Focus")]
                public bool CausesValidation {
                        get {
                                return this.causes_validation;
@@ -1649,6 +1669,7 @@ namespace System.Windows.Forms
                }
 
                [DefaultValue(null)]
+               [MWFCategory("Behavior")]
                public virtual ContextMenu ContextMenu {
                        get {
                                return context_menu;
@@ -1680,6 +1701,7 @@ namespace System.Windows.Forms
                }
 
                [AmbientValue(null)]
+               [MWFCategory("Appearance")]
                public virtual Cursor Cursor {
                        get {
                                if (cursor != null) {
@@ -1726,6 +1748,7 @@ namespace System.Windows.Forms
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [ParenthesizePropertyName(true)]
                [RefreshProperties(RefreshProperties.All)]
+               [MWFCategory("Data")]
                public ControlBindingsCollection DataBindings {
                        get {
                                if (data_bindings == null)
@@ -1755,6 +1778,7 @@ namespace System.Windows.Forms
                [Localizable(true)]
                [RefreshProperties(RefreshProperties.Repaint)]
                [DefaultValue(DockStyle.None)]
+               [MWFCategory("Layout")]
                public virtual DockStyle Dock {
                        get {
                                return dock_style;
@@ -1777,6 +1801,7 @@ namespace System.Windows.Forms
 
                [DispId(-514)]
                [Localizable(true)]
+               [MWFCategory("Behavior")]
                public bool Enabled {
                        get {
                                if (!is_enabled) {
@@ -1822,6 +1847,7 @@ namespace System.Windows.Forms
                [DispId(-512)]
                [AmbientValue(null)]
                [Localizable(true)]
+               [MWFCategory("Appearance")]
                public virtual Font Font {
                        get {
                                if (font != null) {
@@ -1848,6 +1874,7 @@ namespace System.Windows.Forms
                }
 
                [DispId(-513)]
+               [MWFCategory("Appearance")]
                public virtual Color ForeColor {
                        get {
                                if (foreground_color.IsEmpty) {
@@ -1914,6 +1941,7 @@ namespace System.Windows.Forms
 
                [AmbientValue(ImeMode.Inherit)]
                [Localizable(true)]
+               [MWFCategory("Behavior")]
                public ImeMode ImeMode {
                        get {
                                 if (ime_mode == DefaultImeMode) {
@@ -1995,6 +2023,7 @@ namespace System.Windows.Forms
                }
 
                [Localizable(true)]
+               [MWFCategory("Layout")]
                public Point Location {
                        get {
                                return new Point(bounds.X, bounds.Y);
@@ -2124,6 +2153,7 @@ namespace System.Windows.Forms
 
                [AmbientValue(RightToLeft.Inherit)]
                [Localizable(true)]
+               [MWFCategory("Appearance")]
                public virtual RightToLeft RightToLeft {
                        get {
                                if (right_to_left == RightToLeft.Inherit) {
@@ -2163,6 +2193,7 @@ namespace System.Windows.Forms
                }
 
                [Localizable(true)]
+               [MWFCategory("Layout")]
                public Size Size {
                        get {
                                return new Size(Width, Height);
@@ -2175,6 +2206,7 @@ namespace System.Windows.Forms
 
                [Localizable(true)]
                [MergableProperty(false)]
+               [MWFCategory("Behavior")]
                public int TabIndex {
                        get {
                                if (tab_index != -1) {
@@ -2193,6 +2225,7 @@ namespace System.Windows.Forms
 
                [DispId(-516)]
                [DefaultValue(true)]
+               [MWFCategory("Behavior")]
                public bool TabStop {
                        get {
                                return tab_stop;
@@ -2210,6 +2243,7 @@ namespace System.Windows.Forms
                [Bindable(true)]
                [TypeConverter(typeof(StringConverter))]
                [DefaultValue(null)]
+               [MWFCategory("Data")]
                public object Tag {
                        get {
                                return control_tag;
@@ -2223,6 +2257,7 @@ namespace System.Windows.Forms
                [DispId(-517)]
                [Localizable(true)]
                [BindableAttribute(true)]
+               [MWFCategory("Appearance")]
                public virtual string Text {
                        get {
                                // Our implementation ignores ControlStyles.CacheText - we always cache
@@ -2273,6 +2308,7 @@ namespace System.Windows.Forms
                }
 
                [Localizable(true)]
+               [MWFCategory("Behavior")]
                public bool Visible {
                        get {
                                if (!is_visible) {
@@ -2953,7 +2989,6 @@ namespace System.Windows.Forms
 
                public virtual void Refresh() {                 
                        if (IsHandleCreated == true) {
-
                                Invalidate();
                                XplatUI.UpdateWindow(window.Handle);
 
@@ -3157,8 +3192,10 @@ namespace System.Windows.Forms
                                        }
                                }
 
-                               // Find out where the window manager placed us
                                UpdateStyles();
+                               XplatUI.SetAllowDrop (Handle, allow_drop);
+
+                               // Find out where the window manager placed us
                                if ((CreateParams.Style & (int)WindowStyles.WS_CHILD) != 0) {
                                        XplatUI.SetBorderStyle(window.Handle, (FormBorderStyle)border_style);
                                }
@@ -3585,12 +3622,12 @@ namespace System.Windows.Forms
 
                protected virtual void SetVisibleCore(bool value) {
                        if (value!=is_visible) {
-                               is_visible=value;
-
-                               if (is_visible && !is_created) {
+                               if (value && !is_created) {
                                        CreateControl();
                                }
 
+                               is_visible=value;
+
                                if (IsHandleCreated) {
                                        XplatUI.SetVisible(Handle, value);
                                        // Explicitly move Toplevel windows to where we want them;
@@ -3801,8 +3838,8 @@ namespace System.Windows.Forms
                                        HandleClick(mouse_clicks, me);
                                        OnMouseUp (me);
 
-                                       if (Capture) {
-                                               Capture = false;
+                                       if (InternalCapture) {
+                                               InternalCapture = false;
                                        }
 
                                        if (mouse_clicks > 1) {
@@ -3815,7 +3852,7 @@ namespace System.Windows.Forms
                                        if (CanSelect && !is_selected) {
                                                Select(this);
                                        }
-                                       Capture = true;
+                                       InternalCapture = true;
                                        OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), 
                                                mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 
                                                0));
@@ -3824,7 +3861,7 @@ namespace System.Windows.Forms
                                }
 
                                case Msg.WM_LBUTTONDBLCLK: {
-                                       Capture = true;
+                                       InternalCapture = true;
                                        mouse_clicks++;
                                        OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), 
                                                mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 
@@ -3843,8 +3880,8 @@ namespace System.Windows.Forms
 
                                        HandleClick(mouse_clicks, me);
                                        OnMouseUp (me);
-                                       if (Capture) {
-                                               Capture = false;
+                                       if (InternalCapture) {
+                                               InternalCapture = false;
                                        }
                                        if (mouse_clicks > 1) {
                                                mouse_clicks = 1;
@@ -3853,7 +3890,7 @@ namespace System.Windows.Forms
                                }
                                        
                                case Msg.WM_MBUTTONDOWN: {                                      
-                                       Capture = true;
+                                       InternalCapture = true;
                                        OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), 
                                                mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 
                                                0));
@@ -3862,7 +3899,7 @@ namespace System.Windows.Forms
                                }
 
                                case Msg.WM_MBUTTONDBLCLK: {
-                                       Capture = true;
+                                       InternalCapture = true;
                                        mouse_clicks++;
                                        OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), 
                                                mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 
@@ -3871,11 +3908,14 @@ namespace System.Windows.Forms
                                }
 
                                case Msg.WM_RBUTTONUP: {
-                                       MouseEventArgs me;
+                                       MouseEventArgs  me;
+                                       Point           pt;
+
+                                       pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
+                                       pt = PointToScreen(pt);
+
+                                       XplatUI.SendMessage(m.HWnd, Msg.WM_CONTEXTMENU, m.HWnd, (IntPtr)(pt.X + (pt.Y << 16)));
 
-                                       if (context_menu != null) {
-                                               context_menu.Show(this, new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ())));
-                                       }
                                        me = new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()) | MouseButtons.Right, 
                                                mouse_clicks, 
                                                LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 
@@ -3884,8 +3924,8 @@ namespace System.Windows.Forms
                                        HandleClick(mouse_clicks, me);
                                        OnMouseUp (me);
 
-                                       if (Capture) {
-                                               Capture = false;
+                                       if (InternalCapture) {
+                                               InternalCapture = false;
                                        }
 
                                        if (mouse_clicks > 1) {
@@ -3895,7 +3935,7 @@ namespace System.Windows.Forms
                                }
                                        
                                case Msg.WM_RBUTTONDOWN: {                                      
-                                       Capture = true;
+                                       InternalCapture = true;
                                        OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), 
                                                mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 
                                                0));
@@ -3903,7 +3943,7 @@ namespace System.Windows.Forms
                                }
 
                                case Msg.WM_RBUTTONDBLCLK: {
-                                       Capture = true;
+                                       InternalCapture = true;
                                        mouse_clicks++;
                                        OnMouseDown (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()), 
                                                mouse_clicks, LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()), 
@@ -3911,6 +3951,19 @@ namespace System.Windows.Forms
                                        return;
                                }
 
+                               case Msg.WM_CONTEXTMENU: {
+                                       if (context_menu != null) {
+                                               Point   pt;
+
+                                               pt = new Point(LowOrder ((int) m.LParam.ToInt32 ()), HighOrder ((int) m.LParam.ToInt32 ()));
+                                               context_menu.Show(this, PointToClient(pt));
+                                               return;
+                                       }
+
+                                       DefWndProc(ref m);
+                                       return;
+                               }
+
                                case Msg.WM_MOUSEWHEEL: {                               
 
                                        OnMouseWheel (new MouseEventArgs (FromParamToMouseButtons ((int) m.WParam.ToInt32()),