Xamarin-4959: Fix copy of clipboard data after app exits
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / CommonDialog.cs
index e686374851efe0fd66f962befc311edda75d6c99..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)
 
 // NOT COMPLETE
 
+using System.ComponentModel;
+
 namespace System.Windows.Forms {
+       [ToolboxItemFilter("System.Windows.Forms")]
        public abstract class CommonDialog : System.ComponentModel.Component {
                #region DialogForm
                internal class DialogForm : Form {
-                       #region FormParentWindow Override
-                       internal new class FormParentWindow : Form.FormParentWindow {
-                               internal FormParentWindow(Form owner) : base(owner) {
-                               }
-
-                               protected override CreateParams CreateParams {
-                                       get {
-                                               CreateParams    cp;
-
-                                               if (owner != null) {
-                                                       owner.ControlBox = true;
-                                                       owner.MinimizeBox = false;
-                                                       owner.MaximizeBox = false;
-                                               }
-
-                                               cp = base.CreateParams;
-
-                                               // FIXME - I need to rethink this a bit, we're loosing any cp.Style set in base; might not matter though
-                                               cp.Style = (int)(WindowStyles.WS_POPUP | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU);
-                                               return cp;
-                                       }
-                               }
-
-                       }
-                       #endregion
-
                        #region DialogForm Local Variables
                        protected CommonDialog  owner;
                        #endregion DialogForm Local Variables
@@ -63,30 +40,31 @@ 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
 
                        #region Protected Instance Properties
                        protected override CreateParams CreateParams {
                                get {
-                                       if (this.form_parent_window == null) {
-                                               form_parent_window = new FormParentWindow(this);
-                                       }
+                                       CreateParams    cp;
 
-                                       return base.CreateParams;
-                               }
-                       }
+                                       cp = base.CreateParams;
 
-                       protected override void WndProc(ref Message m) {
-                               base.WndProc (ref m);
-                       }
+                                       cp.Style |= (int)(WindowStyles.WS_POPUP | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU);
 
+                                       return cp;
+                               }
+                       }
                        #endregion      // Protected Instance Properties
 
                        #region Internal Methods
                        internal DialogResult RunDialog () {
-                               this.StartPosition = FormStartPosition.CenterScreen;
-
                                owner.InitFormsSize (this);
 
                                this.ShowDialog ();
@@ -100,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
@@ -117,45 +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.form_parent_window.Handle, true);
-
-                       form.Show();
-
-                       form.is_modal = true;
-                       Application.ModalRun(form);
-                       form.is_modal = false;
-                       form.Hide();
-
-                       XplatUI.SetModal(form.form_parent_window.Handle, false);
+                       
+                       // This is an internal derived CommonDialog
+                       if (RunDialog (form.Handle))
+                               form.ShowDialog (owner);
 
                        return form.DialogResult;
                }
@@ -167,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) {
@@ -180,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
        }
 }