svn path=/branches/mono-1-1-9/mcs/; revision=50439
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / CommonDialog.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 // 
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 // 
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2004 Novell, Inc. (http://www.novell.com)
21 //
22 // Authors:
23 //      Peter Bartok    (pbartok@novell.com)
24 //
25 //
26
27 // NOT COMPLETE
28
29 using System.ComponentModel;
30
31 namespace System.Windows.Forms {
32         [ToolboxItemFilter("System.Windows.Forms")]
33         public abstract class CommonDialog : System.ComponentModel.Component {
34                 #region DialogForm
35                 internal class DialogForm : Form {
36                         #region DialogForm Local Variables
37                         protected CommonDialog  owner;
38                         #endregion DialogForm Local Variables
39
40                         #region DialogForm Constructors
41                         internal DialogForm(CommonDialog owner) {
42                                 this.owner = owner;
43                         }
44                         #endregion DialogForm Constructors
45
46                         #region Protected Instance Properties
47                         protected override CreateParams CreateParams {
48                                 get {
49                                         CreateParams    cp;
50
51                                         ControlBox = true;
52                                         MinimizeBox = false;
53                                         MaximizeBox = false;
54
55                                         cp = base.CreateParams;
56
57                                         cp.Style = (int)(WindowStyles.WS_POPUP | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS);
58
59                                         return cp;
60                                 }
61                         }
62                         #endregion      // Protected Instance Properties
63
64                         #region Internal Methods
65                         internal DialogResult RunDialog () {
66                                 this.StartPosition = FormStartPosition.CenterScreen;
67
68                                 owner.InitFormsSize (this);
69
70                                 this.ShowDialog ();
71
72                                 return this.DialogResult;
73
74                         }
75                         #endregion Internal Methods
76                 }
77                 #endregion DialogForm
78
79                 #region Local Variables
80                 internal DialogForm     form;
81                 #endregion Local Variables
82
83                 #region Public Constructors
84                 public CommonDialog() {
85                         form = new DialogForm(this);
86                 }
87                 #endregion Public Constructors
88
89                 #region Internal Methods
90                 internal virtual void InitFormsSize(Form form) {
91                         // Override this to set a default size for the form
92                         form.Width = 200;
93                         form.Height = 200;
94                 }
95                 #endregion Internal Methods
96         
97                 #region Public Instance Methods
98                 public abstract void Reset();
99
100                 public DialogResult ShowDialog() {
101                         return ShowDialog(null);
102                 }
103
104                 public DialogResult ShowDialog(IWin32Window ownerWin32) {
105                         #if broken
106                         Control         owner = null;
107
108                         if (ownerWin32 != null) {
109                                 owner = Control.FromHandle(ownerWin32.Handle);
110                         }
111                         #endif
112
113                         RunDialog(form.Handle);
114
115                         if (form.Visible) {
116                                 throw new InvalidOperationException("Already visible forms cannot be displayed as a modal dialog. Set the Visible property to 'false' prior to calling Form.ShowDialog.");
117                         }
118
119                         if (!form.IsHandleCreated) {
120                                 form.CreateControl();
121                         }
122
123                         #if broken
124                         form.form_parent_window.Parent = owner;
125                         #endif
126
127                         XplatUI.SetModal(form.window.Handle, true);
128
129                         form.Show();
130
131                         form.end_modal = false;
132                         form.is_modal = true;
133                         Application.ModalRun(form);
134                         form.is_modal = false;
135                         form.Hide();
136
137                         XplatUI.SetModal(form.window.Handle, false);
138
139                         return form.DialogResult;
140                 }
141                 #endregion      // Public Instance Methods
142
143                 #region Protected Instance Methods
144                 protected virtual IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) {
145                         return IntPtr.Zero;
146                 }
147
148                 protected virtual void OnHelpRequest(EventArgs e) {
149                         if (HelpRequest != null) {
150                                 HelpRequest(this, e);
151                         }
152                 }
153
154                 protected virtual IntPtr OwnerWndProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) {
155                         return IntPtr.Zero;
156                 }
157
158                 protected abstract bool RunDialog(IntPtr hwndOwner);
159                 #endregion      // Protected Instance Methods
160
161                 #region Events
162                 public event EventHandler HelpRequest;
163                 #endregion      // Events
164         }
165 }