DockEditor.cs 7.6 KB

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