Xamarin-4959: Fix copy of clipboard data after app exits
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / CommonDialog.cs
index 9205ae5f4ac86dcc0a836092cf6b8bf27da5a822..fc2b931acd49c99c3ff57ed10dfdcda5e44f1759 100644 (file)
@@ -17,7 +17,7 @@
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-// Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
+// Copyright (c) 2004-2006 Novell, Inc. (http://www.novell.com)
 //
 // Authors:
 //     Peter Bartok    (pbartok@novell.com)
@@ -40,6 +40,12 @@ namespace System.Windows.Forms {
                        #region DialogForm Constructors
                        internal DialogForm(CommonDialog owner) {
                                this.owner = owner;
+                               ControlBox = true;
+                               MinimizeBox = false;
+                               MaximizeBox = false;
+                               ShowInTaskbar = false;
+                               FormBorderStyle = FormBorderStyle.Sizable;
+                               StartPosition = FormStartPosition.CenterScreen;
                        }
                        #endregion DialogForm Constructors
 
@@ -48,13 +54,9 @@ namespace System.Windows.Forms {
                                get {
                                        CreateParams    cp;
 
-                                       ControlBox = true;
-                                       MinimizeBox = false;
-                                       MaximizeBox = false;
-
                                        cp = base.CreateParams;
 
-                                       cp.Style = (int)(WindowStyles.WS_POPUP | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
+                                       cp.Style |= (int)(WindowStyles.WS_POPUP | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU);
 
                                        return cp;
                                }
@@ -63,8 +65,6 @@ namespace System.Windows.Forms {
 
                        #region Internal Methods
                        internal DialogResult RunDialog () {
-                               this.StartPosition = FormStartPosition.CenterScreen;
-
                                owner.InitFormsSize (this);
 
                                this.ShowDialog ();
@@ -78,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
@@ -95,46 +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) {
-                       #if broken
-                       Control         owner = null;
-
-                       if (ownerWin32 != null) {
-                               owner = Control.FromHandle(ownerWin32.Handle);
-                       }
-                       #endif
-
-                       RunDialog(form.Handle);
-
-                       if (form.Visible) {
-                               throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
-                       }
-
-                       if (!form.IsHandleCreated) {
-                               form.CreateControl();
+               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;
                        }
-
-                       #if broken
-                       form.form_parent_window.Parent = owner;
-                       #endif
-
-                       XplatUI.SetModal(form.window.Handle, true);
-
-                       form.Show();
-
-                       form.end_modal = false;
-                       form.is_modal = true;
-                       Application.ModalRun(form);
-                       form.is_modal = false;
-                       form.Hide();
-
-                       XplatUI.SetModal(form.window.Handle, false);
+                       
+                       // This is an internal derived CommonDialog
+                       if (RunDialog (form.Handle))
+                               form.ShowDialog (owner);
 
                        return form.DialogResult;
                }
@@ -146,9 +136,9 @@ namespace System.Windows.Forms {
                }
 
                protected virtual void OnHelpRequest(EventArgs e) {
-                       if (HelpRequest != null) {
-                               HelpRequest(this, e);
-                       }
+                       EventHandler eh = (EventHandler)(Events [HelpRequestEvent]);
+                       if (eh != null)
+                               eh (this, e);
                }
 
                protected virtual IntPtr OwnerWndProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) {
@@ -159,7 +149,12 @@ namespace System.Windows.Forms {
                #endregion      // Protected Instance Methods
 
                #region Events
-               public event EventHandler HelpRequest;
+               static object HelpRequestEvent = new object ();
+
+               public event EventHandler HelpRequest {
+                       add { Events.AddHandler (HelpRequestEvent, value); }
+                       remove { Events.RemoveHandler (HelpRequestEvent, value); }
+               }
                #endregion      // Events
        }
 }