ContainerControl.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. namespace System.Windows.Forms {
  30. public class ContainerControl : ScrollableControl, IContainerControl {
  31. private Control active_control;
  32. private Control focused_control;
  33. private Control unvalidated_control;
  34. #region Public Constructors
  35. public ContainerControl() {
  36. active_control = null;
  37. focused_control = null;
  38. unvalidated_control = null;
  39. }
  40. #endregion // Public Constructors
  41. #region Public Instance Properties
  42. [Browsable (false)]
  43. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  44. public Control ActiveControl {
  45. get {
  46. return active_control;
  47. }
  48. set {
  49. if ((active_control==value) || (value==null)) {
  50. return;
  51. }
  52. active_control = value;
  53. if (!Contains(value) && this != value) {
  54. throw new ArgumentException("Not a child control");
  55. }
  56. // Scroll control into view
  57. // Let the control know it's selected
  58. Select(value);
  59. }
  60. }
  61. [Browsable (false)]
  62. public override BindingContext BindingContext {
  63. get {
  64. if (base.BindingContext == null) {
  65. base.BindingContext = new BindingContext();
  66. }
  67. return base.BindingContext;
  68. }
  69. set {
  70. base.BindingContext = value;
  71. }
  72. }
  73. [Browsable (false)]
  74. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  75. public Form ParentForm {
  76. get {
  77. Control parent;
  78. parent = this.parent;
  79. while (parent != null) {
  80. if (parent is Form) {
  81. return (Form)parent;
  82. }
  83. parent = parent.parent;
  84. }
  85. return null;
  86. }
  87. }
  88. #endregion // Public Instance Properties
  89. #region Protected Instance Methods
  90. protected override CreateParams CreateParams {
  91. get {
  92. return base.CreateParams;
  93. }
  94. }
  95. #endregion // Public Instance Methods
  96. #region Public Instance Methods
  97. [MonoTODO]
  98. public bool Validate() {
  99. throw new NotImplementedException();
  100. }
  101. bool IContainerControl.ActivateControl(Control control) {
  102. return Select(control);
  103. }
  104. #endregion // Public Instance Methods
  105. #region Protected Instance Methods
  106. [EditorBrowsable (EditorBrowsableState.Advanced)]
  107. protected override void AdjustFormScrollbars(bool displayScrollbars) {
  108. base.AdjustFormScrollbars(displayScrollbars);
  109. }
  110. protected override void Dispose(bool disposing) {
  111. base.Dispose(disposing);
  112. }
  113. [EditorBrowsable (EditorBrowsableState.Advanced)]
  114. protected override void OnControlRemoved(ControlEventArgs e) {
  115. if (e.Control == this.unvalidated_control) {
  116. this.unvalidated_control = null;
  117. }
  118. if (e.Control == this.active_control) {
  119. this.unvalidated_control = null;
  120. }
  121. base.OnControlRemoved(e);
  122. }
  123. protected override void OnCreateControl() {
  124. base.OnCreateControl();
  125. // MS seems to call this here, it gets the whole databinding process started
  126. OnBindingContextChanged (EventArgs.Empty);
  127. }
  128. [EditorBrowsable (EditorBrowsableState.Advanced)]
  129. protected override bool ProcessDialogChar(char charCode) {
  130. if (GetTopLevel()) {
  131. if (ProcessMnemonic(charCode)) {
  132. return true;
  133. }
  134. }
  135. return base.ProcessDialogChar(charCode);
  136. }
  137. protected override bool ProcessDialogKey(Keys keyData) {
  138. Keys key;
  139. bool forward;
  140. key = keyData & Keys.KeyCode;
  141. forward = true;
  142. switch (key) {
  143. case Keys.Tab: {
  144. if (ProcessTabKey((Control.ModifierKeys & Keys.Shift) == 0)) {
  145. return true;
  146. }
  147. break;
  148. }
  149. case Keys.Left: {
  150. forward = false;
  151. goto case Keys.Down;
  152. }
  153. case Keys.Up: {
  154. forward = false;
  155. goto case Keys.Down;
  156. }
  157. case Keys.Right: {
  158. goto case Keys.Down;
  159. }
  160. case Keys.Down: {
  161. if (SelectNextControl(active_control, forward, false, false, true)) {
  162. return true;
  163. }
  164. break;
  165. }
  166. }
  167. return base.ProcessDialogKey(keyData);
  168. }
  169. protected override bool ProcessMnemonic(char charCode) {
  170. bool wrapped;
  171. Control c;
  172. wrapped = false;
  173. c = active_control;
  174. do {
  175. c = GetNextControl(c, true);
  176. if (c != null) {
  177. // This is stupid. I want to be able to call c.ProcessMnemonic directly
  178. if (c.ProcessControlMnemonic(charCode)) {
  179. return(true);
  180. }
  181. continue;
  182. } else {
  183. if (wrapped) {
  184. break;
  185. }
  186. wrapped = true;
  187. }
  188. } while (c != active_control);
  189. return false;
  190. }
  191. protected virtual bool ProcessTabKey(bool forward) {
  192. return SelectNextControl(active_control, forward, true, true, true);
  193. }
  194. protected override void Select(bool directed, bool forward) {
  195. base.Select(directed, forward);
  196. }
  197. protected virtual void UpdateDefaultButton() {
  198. // MS Internal
  199. }
  200. [EditorBrowsable (EditorBrowsableState.Advanced)]
  201. protected override void WndProc(ref Message m) {
  202. base.WndProc(ref m);
  203. }
  204. #endregion // Protected Instance Methods
  205. }
  206. }