ScrollableControl.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. // NOT COMPLETE
  26. using System;
  27. using System.ComponentModel;
  28. using System.Drawing;
  29. namespace System.Windows.Forms {
  30. public class ScrollableControl : Control {
  31. #region Local Variables
  32. private bool auto_vscroll;
  33. private bool auto_hscroll;
  34. private bool hscroll_visible;
  35. private bool vscroll_visible;
  36. private bool auto_scroll;
  37. private Size auto_scroll_margin;
  38. private Size auto_scroll_min_size;
  39. private Point auto_scroll_position;
  40. private DockPaddingEdges dock_padding;
  41. private ScrollBar hscrollbar;
  42. private ScrollBar vscrollbar;
  43. #endregion // Local Variables
  44. [MonoTODO("Need to use the edge values when performing the layout")]
  45. #region Subclass DockPaddingEdges
  46. public class DockPaddingEdges : ICloneable {
  47. #region DockPaddingEdges Local Variables
  48. private int all;
  49. private int left;
  50. private int right;
  51. private int top;
  52. private int bottom;
  53. #endregion // DockPaddingEdges Local Variables
  54. #region DockPaddingEdges Constructor
  55. internal DockPaddingEdges() {
  56. all = 0;
  57. left = 0;
  58. right = 0;
  59. top = 0;
  60. bottom = 0;
  61. }
  62. #endregion // DockPaddingEdges Constructor
  63. #region DockPaddingEdges Public Instance Properties
  64. public int All {
  65. get {
  66. return all;
  67. }
  68. set {
  69. all = value;
  70. left = value;
  71. right = value;
  72. top = value;
  73. bottom = value;
  74. }
  75. }
  76. public int Bottom {
  77. get {
  78. return bottom;
  79. }
  80. set {
  81. bottom = value;
  82. all = 0;
  83. }
  84. }
  85. public int Left {
  86. get {
  87. return left;
  88. }
  89. set {
  90. left=value;
  91. all = 0;
  92. }
  93. }
  94. public int Right {
  95. get {
  96. return right;
  97. }
  98. set {
  99. right=value;
  100. all = 0;
  101. }
  102. }
  103. public int Top {
  104. get {
  105. return top;
  106. }
  107. set {
  108. top=value;
  109. all = 0;
  110. }
  111. }
  112. #endregion // DockPaddingEdges Public Instance Properties
  113. // Public Instance Methods
  114. public override bool Equals(object other) {
  115. if (! (other is DockPaddingEdges)) {
  116. return false;
  117. }
  118. if ( (this.all == ((DockPaddingEdges)other).all) && (this.left == ((DockPaddingEdges)other).left) &&
  119. (this.right == ((DockPaddingEdges)other).right) && (this.top == ((DockPaddingEdges)other).top) &&
  120. (this.bottom == ((DockPaddingEdges)other).bottom)) {
  121. return true;
  122. }
  123. return false;
  124. }
  125. public override int GetHashCode() {
  126. return all*top*bottom*right*left;
  127. }
  128. public override string ToString() {
  129. return "All = "+all.ToString()+" Top = "+top.ToString()+" Left = "+left.ToString()+" Bottom = "+bottom.ToString()+" Right = "+right.ToString();
  130. }
  131. object ICloneable.Clone() {
  132. DockPaddingEdges padding_edge;
  133. padding_edge=new DockPaddingEdges();
  134. padding_edge.all=all;
  135. padding_edge.left=left;
  136. padding_edge.right=right;
  137. padding_edge.top=top;
  138. padding_edge.bottom=bottom;
  139. return padding_edge;
  140. }
  141. }
  142. #endregion // Subclass DockPaddingEdges
  143. #region Subclass DockPaddingEdgesConverter
  144. public class DockPaddingEdgesConverter : System.ComponentModel.TypeConverter {
  145. // Public Constructors
  146. public DockPaddingEdgesConverter() {
  147. }
  148. // Public Instance Methods
  149. public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, Attribute[] attributes) {
  150. throw new NotImplementedException();
  151. }
  152. public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) {
  153. throw new NotImplementedException();
  154. }
  155. }
  156. #endregion // Subclass DockPaddingEdgesConverter
  157. #region Public Constructors
  158. public ScrollableControl() {
  159. SetStyle(ControlStyles.ContainerControl, true);
  160. auto_scroll = false;
  161. auto_hscroll = false;
  162. auto_vscroll = false;
  163. hscroll_visible = false;
  164. vscroll_visible = false;
  165. auto_scroll_margin = new Size(0, 0);
  166. auto_scroll_min_size = new Size(0, 0);
  167. auto_scroll_position = new Point(0, 0);
  168. dock_padding = new DockPaddingEdges();
  169. }
  170. #endregion // Public Constructors
  171. #region Protected Static Fields
  172. protected const int ScrollStateAutoScrolling = 1;
  173. protected const int ScrollStateFullDrag = 16;
  174. protected const int ScrollStateHScrollVisible = 2;
  175. protected const int ScrollStateUserHasScrolled = 8;
  176. protected const int ScrollStateVScrollVisible = 4;
  177. #endregion // Protected Static Fields
  178. #region Public Instance Properties
  179. public virtual bool AutoScroll {
  180. get {
  181. return auto_scroll;
  182. }
  183. set {
  184. if (auto_scroll == value) {
  185. return;
  186. }
  187. auto_scroll = value;
  188. }
  189. }
  190. public Size AutoScrollMargin {
  191. get {
  192. return auto_scroll_margin;
  193. }
  194. set {
  195. if (value.Width < 0) {
  196. throw new ArgumentException("Width is assigned less than 0", "value.Width");
  197. }
  198. if (value.Height < 0) {
  199. throw new ArgumentException("Height is assigned less than 0", "value.Height");
  200. }
  201. auto_scroll_margin = value;
  202. }
  203. }
  204. public Size AutoScrollMinSize {
  205. get {
  206. return auto_scroll_min_size;
  207. }
  208. set {
  209. auto_scroll_min_size = value;
  210. }
  211. }
  212. public Point AutoScrollPosition {
  213. get {
  214. return auto_scroll_position;
  215. }
  216. set {
  217. auto_scroll_position = value;
  218. }
  219. }
  220. public override Rectangle DisplayRectangle {
  221. get {
  222. Rectangle rect;
  223. rect = base.DisplayRectangle;
  224. if (vscroll_visible) {
  225. rect.Width -= vscrollbar.Width;
  226. if (rect.Width < 0) {
  227. rect.Width = 0;
  228. }
  229. }
  230. if (hscroll_visible) {
  231. rect.Height -= hscrollbar.Height;
  232. if (rect.Height < 0) {
  233. rect.Height = 0;
  234. }
  235. }
  236. return rect;
  237. }
  238. }
  239. public DockPaddingEdges DockPadding {
  240. get {
  241. return dock_padding;
  242. }
  243. // DockPadding is documented as 'get' only ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsScrollableControlClassAutoScrollTopic.asp )
  244. // but Microsoft's on that pageexamples show 'set' usage
  245. set {
  246. dock_padding = value;
  247. }
  248. }
  249. #endregion // Public Instance Properties
  250. #region Protected Instance Methods
  251. protected override CreateParams CreateParams {
  252. get {
  253. CreateParams ret;
  254. ret = base.CreateParams;
  255. ret.Style |= (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_VISIBLE);
  256. return ret;
  257. }
  258. }
  259. protected bool HScroll {
  260. get {
  261. return hscroll_visible;
  262. }
  263. set {
  264. if (hscroll_visible != value) {
  265. hscroll_visible = value;
  266. if (hscroll_visible && hscrollbar == null)
  267. hscrollbar = new ScrollBar ();
  268. }
  269. }
  270. }
  271. protected bool VScroll {
  272. get {
  273. return vscroll_visible;
  274. }
  275. set {
  276. if (vscroll_visible != value) {
  277. vscroll_visible = value;
  278. if (vscroll_visible && vscrollbar == null)
  279. vscrollbar = new ScrollBar ();
  280. }
  281. }
  282. }
  283. #endregion // Protected Instance Methods
  284. #region Public Instance Methods
  285. public void ScrollControlIntoView(Control activeControl) {
  286. }
  287. public void SetAutoScrollMargin(int x, int y) {
  288. }
  289. #endregion // Public Instance Methods
  290. #region Protected Instance Methods
  291. protected virtual void AdjustFormScrollbars(bool displayScrollbars) {
  292. }
  293. protected bool GetScrollState(int bit) {
  294. throw new NotImplementedException();
  295. }
  296. protected override void OnLayout(LayoutEventArgs levent) {
  297. base.OnLayout(levent);
  298. }
  299. protected override void OnMouseWheel(MouseEventArgs e) {
  300. base.OnMouseWheel(e);
  301. }
  302. protected override void OnVisibleChanged(EventArgs e) {
  303. ;; // Nothing to do yet
  304. }
  305. protected override void ScaleCore(float dx, float dy) {
  306. throw new NotImplementedException();
  307. }
  308. protected void SetDisplayRectLocation(int x, int y) {
  309. throw new NotImplementedException();
  310. }
  311. protected void SetScrollState(int bit, bool value) {
  312. throw new NotImplementedException();
  313. }
  314. protected override void WndProc(ref Message m) {
  315. base.WndProc(ref m);
  316. }
  317. #endregion // Protected Instance Methods
  318. }
  319. }