ScrollableControl.cs 9.7 KB

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