Xamarin-4959: Fix copy of clipboard data after app exits
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / CommonDialog.cs
index 9e961ed4fece63bd91b3a1b01d675733084a334d..fc2b931acd49c99c3ff57ed10dfdcda5e44f1759 100644 (file)
@@ -45,6 +45,7 @@ namespace System.Windows.Forms {
                                MaximizeBox = false;
                                ShowInTaskbar = false;
                                FormBorderStyle = FormBorderStyle.Sizable;
+                               StartPosition = FormStartPosition.CenterScreen;
                        }
                        #endregion DialogForm Constructors
 
@@ -64,8 +65,6 @@ namespace System.Windows.Forms {
 
                        #region Internal Methods
                        internal DialogResult RunDialog () {
-                               this.StartPosition = FormStartPosition.CenterScreen;
-
                                owner.InitFormsSize (this);
 
                                this.ShowDialog ();
@@ -79,14 +78,26 @@ namespace System.Windows.Forms {
 
                #region Local Variables
                internal DialogForm     form;
+               private object tag;
                #endregion Local Variables
 
                #region Public Constructors
                public CommonDialog() {
-                       form = new DialogForm(this);
                }
                #endregion Public Constructors
 
+               #region Public Properties
+               [Localizable (false)]
+               [Bindable (true)]
+               [TypeConverter (typeof (StringConverter))]
+               [DefaultValue (null)]
+               [MWFCategory ("Data")]
+               public object Tag {
+                       get { return this.tag; }
+                       set { this.tag = value; }
+               }
+               #endregion
+
                #region Internal Methods
                internal virtual void InitFormsSize(Form form) {
                        // Override this to set a default size for the form
@@ -96,18 +107,24 @@ namespace System.Windows.Forms {
                #endregion Internal Methods
        
                #region Public Instance Methods
-               public abstract void Reset();
+               public abstract void Reset ();
 
                public DialogResult ShowDialog() {
-                       return ShowDialog(null);
+                       return ShowDialog (null);
                }
 
-               public DialogResult ShowDialog(IWin32Window ownerWin32) {
-                       // Prep the dialog
-                       if (RunDialog(form.Handle)) {
-                               // Run
-                               form.ShowDialog(ownerWin32);
+               public DialogResult ShowDialog (IWin32Window owner)
+               {
+                       // This is an external derived CommonDialog
+                       if (form == null) {
+                               if (RunDialog (owner == null ? IntPtr.Zero : owner.Handle))
+                                       return DialogResult.OK;
+                               return DialogResult.Cancel;
                        }
+                       
+                       // This is an internal derived CommonDialog
+                       if (RunDialog (form.Handle))
+                               form.ShowDialog (owner);
 
                        return form.DialogResult;
                }