In corlib/System.Runtime.InteropServices:
[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-2006 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                                 ControlBox = true;
44                                 MinimizeBox = false;
45                                 MaximizeBox = false;
46                                 ShowInTaskbar = false;
47                                 FormBorderStyle = FormBorderStyle.Sizable;
48                         }
49                         #endregion DialogForm Constructors
50
51                         #region Protected Instance Properties
52                         protected override CreateParams CreateParams {
53                                 get {
54                                         CreateParams    cp;
55
56                                         cp = base.CreateParams;
57
58                                         cp.Style |= (int)(WindowStyles.WS_POPUP | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU);
59
60                                         return cp;
61                                 }
62                         }
63                         #endregion      // Protected Instance Properties
64
65                         #region Internal Methods
66                         internal DialogResult RunDialog () {
67                                 this.StartPosition = FormStartPosition.CenterScreen;
68
69                                 owner.InitFormsSize (this);
70
71                                 this.ShowDialog ();
72
73                                 return this.DialogResult;
74
75                         }
76                         #endregion Internal Methods
77                 }
78                 #endregion DialogForm
79
80                 #region Local Variables
81                 internal DialogForm     form;
82 #if NET_2_0
83                 private object tag;
84 #endif
85                 #endregion Local Variables
86
87                 #region Public Constructors
88                 public CommonDialog() {
89                         form = new DialogForm(this);
90                 }
91                 #endregion Public Constructors
92
93                 #region Public Properties
94 #if NET_2_0
95                 [Localizable (false)]
96                 [Bindable (true)]
97                 [TypeConverter (typeof (StringConverter))]
98                 [DefaultValue (null)]
99                 [MWFCategory ("Data")]
100                 public object Tag {
101                         get { return this.tag; }
102                         set { this.tag = value; }
103                 }
104 #endif
105                 #endregion
106
107                 #region Internal Methods
108                 internal virtual void InitFormsSize(Form form) {
109                         // Override this to set a default size for the form
110                         form.Width = 200;
111                         form.Height = 200;
112                 }
113                 #endregion Internal Methods
114         
115                 #region Public Instance Methods
116                 public abstract void Reset();
117
118                 public DialogResult ShowDialog() {
119                         return ShowDialog(null);
120                 }
121
122                 public DialogResult ShowDialog(IWin32Window ownerWin32) {
123                         // Prep the dialog
124                         if (RunDialog(form.Handle)) {
125                                 // Run
126                                 form.ShowDialog(ownerWin32);
127                         }
128
129                         return form.DialogResult;
130                 }
131                 #endregion      // Public Instance Methods
132
133                 #region Protected Instance Methods
134                 protected virtual IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) {
135                         return IntPtr.Zero;
136                 }
137
138                 protected virtual void OnHelpRequest(EventArgs e) {
139                         EventHandler eh = (EventHandler)(Events [HelpRequestEvent]);
140                         if (eh != null)
141                                 eh (this, e);
142                 }
143
144                 protected virtual IntPtr OwnerWndProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) {
145                         return IntPtr.Zero;
146                 }
147
148                 protected abstract bool RunDialog(IntPtr hwndOwner);
149                 #endregion      // Protected Instance Methods
150
151                 #region Events
152                 static object HelpRequestEvent = new object ();
153
154                 public event EventHandler HelpRequest {
155                         add { Events.AddHandler (HelpRequestEvent, value); }
156                         remove { Events.RemoveHandler (HelpRequestEvent, value); }
157                 }
158                 #endregion      // Events
159         }
160 }