2007-08-28 Jonathan Pobst <monkey@jpobst.com>
[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                                 StartPosition = FormStartPosition.CenterScreen;
49                         }
50                         #endregion DialogForm Constructors
51
52                         #region Protected Instance Properties
53                         protected override CreateParams CreateParams {
54                                 get {
55                                         CreateParams    cp;
56
57                                         cp = base.CreateParams;
58
59                                         cp.Style |= (int)(WindowStyles.WS_POPUP | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU);
60
61                                         return cp;
62                                 }
63                         }
64                         #endregion      // Protected Instance Properties
65
66                         #region Internal Methods
67                         internal DialogResult RunDialog () {
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 #if NET_2_0
82                 private object tag;
83 #endif
84                 #endregion Local Variables
85
86                 #region Public Constructors
87                 public CommonDialog() {
88                 }
89                 #endregion Public Constructors
90
91                 #region Public Properties
92 #if NET_2_0
93                 [Localizable (false)]
94                 [Bindable (true)]
95                 [TypeConverter (typeof (StringConverter))]
96                 [DefaultValue (null)]
97                 [MWFCategory ("Data")]
98                 public object Tag {
99                         get { return this.tag; }
100                         set { this.tag = value; }
101                 }
102 #endif
103                 #endregion
104
105                 #region Internal Methods
106                 internal virtual void InitFormsSize(Form form) {
107                         // Override this to set a default size for the form
108                         form.Width = 200;
109                         form.Height = 200;
110                 }
111                 #endregion Internal Methods
112         
113                 #region Public Instance Methods
114                 public abstract void Reset();
115
116                 public DialogResult ShowDialog() {
117                         return ShowDialog(null);
118                 }
119
120                 public DialogResult ShowDialog(IWin32Window ownerWin32) {
121                         // This is an external derived CommonDialog
122                         if (form == null) {
123                                 if (RunDialog (ownerWin32 == null ? IntPtr.Zero : ownerWin32.Handle))
124                                         return DialogResult.OK;
125                                         
126                                 return DialogResult.Cancel;                     
127                         }
128                         
129                         // This is an internal derived CommonDialog
130                         if (RunDialog(form.Handle))
131                                 form.ShowDialog(ownerWin32);
132
133                         return form.DialogResult;
134                 }
135                 #endregion      // Public Instance Methods
136
137                 #region Protected Instance Methods
138                 protected virtual IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) {
139                         return IntPtr.Zero;
140                 }
141
142                 protected virtual void OnHelpRequest(EventArgs e) {
143                         EventHandler eh = (EventHandler)(Events [HelpRequestEvent]);
144                         if (eh != null)
145                                 eh (this, e);
146                 }
147
148                 protected virtual IntPtr OwnerWndProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) {
149                         return IntPtr.Zero;
150                 }
151
152                 protected abstract bool RunDialog(IntPtr hwndOwner);
153                 #endregion      // Protected Instance Methods
154
155                 #region Events
156                 static object HelpRequestEvent = new object ();
157
158                 public event EventHandler HelpRequest {
159                         add { Events.AddHandler (HelpRequestEvent, value); }
160                         remove { Events.RemoveHandler (HelpRequestEvent, value); }
161                 }
162                 #endregion      // Events
163         }
164 }