2006-04-25 Peter Dennis Bartok <pbartok@novell.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                         }
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                                         if (!is_enabled) {
59                                                 cp.Style |= (int)(WindowStyles.WS_DISABLED);
60                                         }
61
62                                         return cp;
63                                 }
64                         }
65                         #endregion      // Protected Instance Properties
66
67                         #region Internal Methods
68                         internal DialogResult RunDialog () {
69                                 this.StartPosition = FormStartPosition.CenterScreen;
70
71                                 owner.InitFormsSize (this);
72
73                                 this.ShowDialog ();
74
75                                 return this.DialogResult;
76
77                         }
78                         #endregion Internal Methods
79                 }
80                 #endregion DialogForm
81
82                 #region Local Variables
83                 internal DialogForm     form;
84                 #endregion Local Variables
85
86                 #region Public Constructors
87                 public CommonDialog() {
88                         form = new DialogForm(this);
89                 }
90                 #endregion Public Constructors
91
92                 #region Internal Methods
93                 internal virtual void InitFormsSize(Form form) {
94                         // Override this to set a default size for the form
95                         form.Width = 200;
96                         form.Height = 200;
97                 }
98                 #endregion Internal Methods
99         
100                 #region Public Instance Methods
101                 public abstract void Reset();
102
103                 public DialogResult ShowDialog() {
104                         return ShowDialog(null);
105                 }
106
107                 public DialogResult ShowDialog(IWin32Window ownerWin32) {
108                         // Prep the dialog
109                         RunDialog(form.Handle);
110
111                         // Run
112                         form.ShowDialog(ownerWin32);
113
114                         return form.DialogResult;
115                 }
116                 #endregion      // Public Instance Methods
117
118                 #region Protected Instance Methods
119                 protected virtual IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) {
120                         return IntPtr.Zero;
121                 }
122
123                 protected virtual void OnHelpRequest(EventArgs e) {
124                         if (HelpRequest != null) {
125                                 HelpRequest(this, e);
126                         }
127                 }
128
129                 protected virtual IntPtr OwnerWndProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam) {
130                         return IntPtr.Zero;
131                 }
132
133                 protected abstract bool RunDialog(IntPtr hwndOwner);
134                 #endregion      // Protected Instance Methods
135
136                 #region Events
137                 public event EventHandler HelpRequest;
138                 #endregion      // Events
139         }
140 }