2010-04-06 Jb Evain <jbevain@novell.com>
[mcs.git] / class / System.Design / System.Windows.Forms.Design / DockEditor.cs
blobdc2b1efd5f638fc2840fbf58d854d31984ff761a
1 //
2 // System.Windows.Forms.Design.DockEditor.cs
3 //
4 // Author:
5 // Gert Driesen (drieseng@users.sourceforge.net)
6 //
7 // (C) 2004-2008 Novell
8 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.ComponentModel;
32 using System.Drawing.Design;
34 namespace System.Windows.Forms.Design
36 public sealed class DockEditor : UITypeEditor
38 public DockEditor ()
42 public override object EditValue (ITypeDescriptorContext context, IServiceProvider provider, object value)
44 if (context != null && provider != null)
46 IWindowsFormsEditorService editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
47 if (editorService != null)
49 // Create the UI editor control
50 DockEditorControl dockEditorControl = new DockEditorControl(editorService);
51 dockEditorControl.DockStyle = (DockStyle) value;
52 editorService.DropDownControl(dockEditorControl);
54 return dockEditorControl.DockStyle;
57 return base.EditValue(context, provider, value);
60 public override UITypeEditorEditStyle GetEditStyle (ITypeDescriptorContext context)
62 return UITypeEditorEditStyle.DropDown;
64 private class DockEditorControl : System.Windows.Forms.UserControl
66 private System.Windows.Forms.CheckBox buttonNone;
67 private System.Windows.Forms.Panel panel1;
68 private System.Windows.Forms.CheckBox buttonBottom;
69 private System.Windows.Forms.CheckBox buttonTop;
70 private System.Windows.Forms.Panel panel2;
71 private System.Windows.Forms.CheckBox buttonLeft;
72 private System.Windows.Forms.CheckBox buttonRight;
73 private System.Windows.Forms.CheckBox buttonFill;
74 private IWindowsFormsEditorService editorService;
75 private DockStyle dockStyle;
77 public DockEditorControl(IWindowsFormsEditorService editorService)
79 buttonNone = new System.Windows.Forms.CheckBox();
80 panel1 = new System.Windows.Forms.Panel();
81 buttonBottom = new System.Windows.Forms.CheckBox();
82 buttonTop = new System.Windows.Forms.CheckBox();
83 panel2 = new System.Windows.Forms.Panel();
84 buttonLeft = new System.Windows.Forms.CheckBox();
85 buttonRight = new System.Windows.Forms.CheckBox();
86 buttonFill = new System.Windows.Forms.CheckBox();
87 panel1.SuspendLayout();
88 panel2.SuspendLayout();
89 SuspendLayout();
91 buttonNone.Appearance = Appearance.Button;
92 buttonNone.Dock = System.Windows.Forms.DockStyle.Bottom;
93 buttonNone.Location = new System.Drawing.Point(0, 92);
94 buttonNone.Size = new System.Drawing.Size(150, 23);
95 buttonNone.TabIndex = 5;
96 buttonNone.Text = "None";
97 buttonNone.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
98 buttonNone.Click += new System.EventHandler(buttonClick);
100 panel1.Controls.Add(panel2);
101 panel1.Controls.Add(buttonTop);
102 panel1.Controls.Add(buttonBottom);
103 panel1.Dock = System.Windows.Forms.DockStyle.Fill;
104 panel1.Location = new System.Drawing.Point(0, 0);
105 panel1.Name = "panel1";
106 panel1.Size = new System.Drawing.Size(150, 92);
107 panel1.TabStop = false;
109 buttonBottom.Appearance = Appearance.Button;
110 buttonBottom.Dock = System.Windows.Forms.DockStyle.Bottom;
111 buttonBottom.Location = new System.Drawing.Point(0, 69);
112 buttonBottom.Name = "buttonBottom";
113 buttonBottom.Size = new System.Drawing.Size(150, 23);
114 buttonBottom.TabIndex = 5;
115 buttonBottom.Click += new System.EventHandler(buttonClick);
117 buttonTop.Appearance = Appearance.Button;
118 buttonTop.Dock = System.Windows.Forms.DockStyle.Top;
119 buttonTop.Location = new System.Drawing.Point(0, 0);
120 buttonTop.Name = "buttonTop";
121 buttonTop.Size = new System.Drawing.Size(150, 23);
122 buttonTop.TabIndex = 1;
123 buttonTop.Click += new System.EventHandler(buttonClick);
125 panel2.Controls.Add(buttonFill);
126 panel2.Controls.Add(buttonRight);
127 panel2.Controls.Add(buttonLeft);
128 panel2.Dock = System.Windows.Forms.DockStyle.Fill;
129 panel2.Location = new System.Drawing.Point(0, 23);
130 panel2.Size = new System.Drawing.Size(150, 46);
131 panel2.TabIndex = 2;
132 panel2.TabStop = false;
134 buttonLeft.Appearance = Appearance.Button;
135 buttonLeft.Dock = System.Windows.Forms.DockStyle.Left;
136 buttonLeft.Location = new System.Drawing.Point(0, 0);
137 buttonLeft.Size = new System.Drawing.Size(24, 46);
138 buttonLeft.TabIndex = 2;
139 buttonLeft.Click += new System.EventHandler(buttonClick);
141 buttonRight.Appearance = Appearance.Button;
142 buttonRight.Dock = System.Windows.Forms.DockStyle.Right;
143 buttonRight.Location = new System.Drawing.Point(126, 0);
144 buttonRight.Size = new System.Drawing.Size(24, 46);
145 buttonRight.TabIndex = 4;
146 buttonRight.Click += new System.EventHandler(buttonClick);
148 buttonFill.Appearance = Appearance.Button;
149 buttonFill.Dock = System.Windows.Forms.DockStyle.Fill;
150 buttonFill.Location = new System.Drawing.Point(24, 0);
151 buttonFill.Size = new System.Drawing.Size(102, 46);
152 buttonFill.TabIndex = 3;
153 buttonFill.Click += new System.EventHandler(buttonClick);
155 Controls.Add(panel1);
156 Controls.Add(buttonNone);
157 Size = new System.Drawing.Size(150, 115);
158 panel1.ResumeLayout(false);
159 panel2.ResumeLayout(false);
160 ResumeLayout(false);
163 this.editorService = editorService;
164 dockStyle = DockStyle.None;
168 private void buttonClick(object sender, System.EventArgs e)
170 if (sender == buttonNone)
171 dockStyle = DockStyle.None;
172 else if (sender == buttonFill)
173 dockStyle = DockStyle.Fill;
174 else if (sender == buttonLeft)
175 dockStyle = DockStyle.Left;
176 else if (sender == buttonRight)
177 dockStyle = DockStyle.Right;
178 else if (sender == buttonTop)
179 dockStyle = DockStyle.Top;
180 else if (sender == buttonBottom)
181 dockStyle = DockStyle.Bottom;
182 editorService.CloseDropDown();
186 public DockStyle DockStyle
190 return dockStyle;
194 dockStyle = value;
195 buttonNone.Checked = false;
196 buttonBottom.Checked = false;
197 buttonTop.Checked = false;
198 buttonLeft.Checked = false;
199 buttonRight.Checked = false;
200 buttonFill.Checked = false;
201 switch (DockStyle)
203 case DockStyle.Fill:
204 buttonFill.CheckState = CheckState.Checked;
205 break;
206 case DockStyle.None:
207 buttonNone.CheckState = CheckState.Checked;
208 break;
209 case DockStyle.Left:
210 buttonLeft.CheckState = CheckState.Checked;
211 break;
212 case DockStyle.Right:
213 buttonRight.CheckState = CheckState.Checked;
214 break;
215 case DockStyle.Top:
216 buttonTop.CheckState = CheckState.Checked;
217 break;
218 case DockStyle.Bottom:
219 buttonBottom.CheckState = CheckState.Checked;
220 break;