ContainerControl.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  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 Novell, Inc.
  21. //
  22. // Authors:
  23. // Peter Bartok [email protected]
  24. //
  25. //
  26. // NOT COMPLETE
  27. using System.ComponentModel;
  28. using System.ComponentModel.Design;
  29. using System.Drawing;
  30. namespace System.Windows.Forms {
  31. public class ContainerControl : ScrollableControl, IContainerControl {
  32. private Control active_control;
  33. private Control focused_control;
  34. private Control unvalidated_control;
  35. private SizeF auto_scale_dimensions;
  36. #region Public Constructors
  37. public ContainerControl() {
  38. active_control = null;
  39. focused_control = null;
  40. unvalidated_control = null;
  41. ControlRemoved += new ControlEventHandler(OnControlRemoved);
  42. }
  43. #endregion // Public Constructors
  44. #region Public Instance Properties
  45. [Browsable (false)]
  46. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  47. public Control ActiveControl {
  48. get {
  49. return active_control;
  50. }
  51. set {
  52. if ((active_control==value) || (value==null)) {
  53. return;
  54. }
  55. active_control = value;
  56. if (!Contains(value) && this != value) {
  57. throw new ArgumentException("Not a child control");
  58. }
  59. if (this is Form)
  60. CheckAcceptButton();
  61. // Scroll control into view
  62. // Let the control know it's selected
  63. Select(value);
  64. }
  65. }
  66. [Browsable (false)]
  67. public override BindingContext BindingContext {
  68. get {
  69. if (base.BindingContext == null) {
  70. base.BindingContext = new BindingContext();
  71. }
  72. return base.BindingContext;
  73. }
  74. set {
  75. base.BindingContext = value;
  76. }
  77. }
  78. [Browsable (false)]
  79. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  80. public Form ParentForm {
  81. get {
  82. Control parent;
  83. parent = this.parent;
  84. while (parent != null) {
  85. if (parent is Form) {
  86. return (Form)parent;
  87. }
  88. parent = parent.parent;
  89. }
  90. return null;
  91. }
  92. }
  93. #endregion // Public Instance Properties
  94. #region Protected Instance Methods
  95. protected override CreateParams CreateParams {
  96. get {
  97. return base.CreateParams;
  98. }
  99. }
  100. #endregion // Public Instance Methods
  101. #region Public Instance Methods
  102. [MonoTODO]
  103. static bool ValidateWarned;
  104. public bool Validate() {
  105. //throw new NotImplementedException();
  106. if (!ValidateWarned) {
  107. Console.WriteLine("ContainerControl.Validate is not yet implemented");
  108. ValidateWarned = true;
  109. }
  110. return true;
  111. }
  112. bool IContainerControl.ActivateControl(Control control) {
  113. return Select(control);
  114. }
  115. #endregion // Public Instance Methods
  116. #region .NET 2.0 Public Instance Methods
  117. #if NET_2_0
  118. public SizeF AutoScaleDimensions {
  119. get {
  120. return auto_scale_dimensions;
  121. }
  122. set {
  123. auto_scale_dimensions = value;
  124. }
  125. }
  126. // XXX: implement me!
  127. AutoScaleMode auto_scale_mode;
  128. public virtual AutoScaleMode AutoScaleMode {
  129. get {
  130. Console.Error.WriteLine("Unimplemented: ContainerControl::get_AutoScaleMode()");
  131. return auto_scale_mode;
  132. }
  133. set {
  134. Console.Error.WriteLine("Unimplemented: ContainerControl::set_AutoScaleMode(AutoScaleMode)");
  135. auto_scale_mode = value;
  136. }
  137. }
  138. #endif // NET_2_0
  139. #endregion
  140. #region Protected Instance Methods
  141. [EditorBrowsable (EditorBrowsableState.Advanced)]
  142. protected override void AdjustFormScrollbars(bool displayScrollbars) {
  143. base.AdjustFormScrollbars(displayScrollbars);
  144. }
  145. protected override void Dispose(bool disposing) {
  146. base.Dispose(disposing);
  147. }
  148. // LAMESPEC This used to be documented, but it's not in code
  149. // and no longer listed in MSDN2
  150. // [EditorBrowsable (EditorBrowsableState.Advanced)]
  151. // protected override void OnControlRemoved(ControlEventArgs e) {
  152. private void OnControlRemoved(object sender, ControlEventArgs e) {
  153. if (e.Control == this.unvalidated_control) {
  154. this.unvalidated_control = null;
  155. }
  156. if (e.Control == this.active_control) {
  157. this.unvalidated_control = null;
  158. }
  159. // base.OnControlRemoved(e);
  160. }
  161. protected override void OnCreateControl() {
  162. base.OnCreateControl();
  163. // MS seems to call this here, it gets the whole databinding process started
  164. OnBindingContextChanged (EventArgs.Empty);
  165. }
  166. [EditorBrowsable (EditorBrowsableState.Advanced)]
  167. protected override bool ProcessDialogChar(char charCode) {
  168. if (GetTopLevel()) {
  169. if (ProcessMnemonic(charCode)) {
  170. return true;
  171. }
  172. }
  173. return base.ProcessDialogChar(charCode);
  174. }
  175. protected override bool ProcessDialogKey(Keys keyData) {
  176. Keys key;
  177. bool forward;
  178. key = keyData & Keys.KeyCode;
  179. forward = true;
  180. switch (key) {
  181. case Keys.Tab: {
  182. if (ProcessTabKey((Control.ModifierKeys & Keys.Shift) == 0)) {
  183. return true;
  184. }
  185. break;
  186. }
  187. case Keys.Left: {
  188. forward = false;
  189. goto case Keys.Down;
  190. }
  191. case Keys.Up: {
  192. forward = false;
  193. goto case Keys.Down;
  194. }
  195. case Keys.Right: {
  196. goto case Keys.Down;
  197. }
  198. case Keys.Down: {
  199. if (SelectNextControl(active_control, forward, false, false, true)) {
  200. return true;
  201. }
  202. break;
  203. }
  204. }
  205. return base.ProcessDialogKey(keyData);
  206. }
  207. protected override bool ProcessMnemonic(char charCode) {
  208. bool wrapped;
  209. Control c;
  210. wrapped = false;
  211. c = active_control;
  212. do {
  213. c = GetNextControl(c, true);
  214. if (c != null) {
  215. // This is stupid. I want to be able to call c.ProcessMnemonic directly
  216. if (c.ProcessControlMnemonic(charCode)) {
  217. return(true);
  218. }
  219. continue;
  220. } else {
  221. if (wrapped) {
  222. break;
  223. }
  224. wrapped = true;
  225. }
  226. } while (c != active_control);
  227. return false;
  228. }
  229. protected virtual bool ProcessTabKey(bool forward) {
  230. return SelectNextControl(active_control, forward, true, true, true);
  231. }
  232. protected override void Select(bool directed, bool forward) {
  233. base.Select(directed, forward);
  234. }
  235. protected virtual void UpdateDefaultButton() {
  236. // MS Internal
  237. }
  238. [EditorBrowsable (EditorBrowsableState.Advanced)]
  239. protected override void WndProc(ref Message m) {
  240. base.WndProc(ref m);
  241. }
  242. #endregion // Protected Instance Methods
  243. internal virtual void CheckAcceptButton()
  244. {
  245. // do nothing here, only called if it is a Form
  246. }
  247. }
  248. }