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:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
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.
20 // Copyright (c) 2004 Novell, Inc.
23 // Peter Bartok pbartok@novell.com
30 using System.ComponentModel;
33 namespace System.Windows.Forms {
34 public class ScrollableControl : Control {
35 #region Local Variables
36 private bool auto_vscroll;
37 private bool auto_hscroll;
38 private bool hscroll_visible;
39 private bool vscroll_visible;
40 private bool auto_scroll;
41 private Size auto_scroll_margin;
42 private Size auto_scroll_min_size;
43 private Point auto_scroll_position;
44 private DockPaddingEdges dock_padding;
45 private ScrollBar hscrollbar;
46 private ScrollBar vscrollbar;
47 #endregion // Local Variables
49 [MonoTODO("Need to use the edge values when performing the layout")]
50 #region Subclass DockPaddingEdges
51 public class DockPaddingEdges : ICloneable {
52 #region DockPaddingEdges Local Variables
58 #endregion // DockPaddingEdges Local Variables
60 #region DockPaddingEdges Constructor
61 internal DockPaddingEdges() {
68 #endregion // DockPaddingEdges Constructor
70 #region DockPaddingEdges Public Instance Properties
129 #endregion // DockPaddingEdges Public Instance Properties
131 // Public Instance Methods
132 public override bool Equals(object other) {
133 if (! (other is DockPaddingEdges)) {
137 if ( (this.all == ((DockPaddingEdges)other).all) && (this.left == ((DockPaddingEdges)other).left) &&
138 (this.right == ((DockPaddingEdges)other).right) && (this.top == ((DockPaddingEdges)other).top) &&
139 (this.bottom == ((DockPaddingEdges)other).bottom)) {
146 public override int GetHashCode() {
147 return all*top*bottom*right*left;
150 public override string ToString() {
151 return "All = "+all.ToString()+" Top = "+top.ToString()+" Left = "+left.ToString()+" Bottom = "+bottom.ToString()+" Right = "+right.ToString();
154 object ICloneable.Clone() {
155 DockPaddingEdges padding_edge;
157 padding_edge=new DockPaddingEdges();
159 padding_edge.all=all;
160 padding_edge.left=left;
161 padding_edge.right=right;
162 padding_edge.top=top;
163 padding_edge.bottom=bottom;
168 #endregion // Subclass DockPaddingEdges
170 #region Subclass DockPaddingEdgesConverter
171 public class DockPaddingEdgesConverter : System.ComponentModel.TypeConverter {
172 // Public Constructors
173 public DockPaddingEdgesConverter() {
176 // Public Instance Methods
177 public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, Attribute[] attributes) {
178 throw new NotImplementedException();
181 public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) {
182 throw new NotImplementedException();
185 #endregion // Subclass DockPaddingEdgesConverter
187 #region Public Constructors
188 public ScrollableControl() {
189 SetStyle(ControlStyles.ContainerControl, true);
191 auto_hscroll = false;
192 auto_vscroll = false;
193 hscroll_visible = false;
194 vscroll_visible = false;
195 auto_scroll_margin = new Size(0, 0);
196 auto_scroll_min_size = new Size(0, 0);
197 auto_scroll_position = new Point(0, 0);
198 dock_padding = new DockPaddingEdges();
200 #endregion // Public Constructors
202 #region Protected Static Fields
203 protected const int ScrollStateAutoScrolling = 1;
204 protected const int ScrollStateFullDrag = 16;
205 protected const int ScrollStateHScrollVisible = 2;
206 protected const int ScrollStateUserHasScrolled = 8;
207 protected const int ScrollStateVScrollVisible = 4;
208 #endregion // Protected Static Fields
210 #region Public Instance Properties
211 public virtual bool AutoScroll {
217 if (auto_scroll == value) {
225 public Size AutoScrollMargin {
227 return auto_scroll_margin;
231 if (value.Width < 0) {
232 throw new ArgumentException("Width is assigned less than 0", "value.Width");
235 if (value.Height < 0) {
236 throw new ArgumentException("Height is assigned less than 0", "value.Height");
239 auto_scroll_margin = value;
243 public Size AutoScrollMinSize {
245 return auto_scroll_min_size;
249 auto_scroll_min_size = value;
253 public Point AutoScrollPosition {
255 return auto_scroll_position;
259 auto_scroll_position = value;
263 public override Rectangle DisplayRectangle {
267 rect = base.DisplayRectangle;
269 if (vscroll_visible) {
270 rect.Width -= vscrollbar.Width;
271 if (rect.Width < 0) {
276 if (hscroll_visible) {
277 rect.Height -= hscrollbar.Height;
278 if (rect.Height < 0) {
286 public DockPaddingEdges DockPadding {
291 // DockPadding is documented as 'get' only ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsScrollableControlClassAutoScrollTopic.asp )
292 // but Microsoft's on that pageexamples show 'set' usage
294 dock_padding = value;
297 #endregion // Public Instance Properties
299 #region Protected Instance Methods
300 protected override CreateParams CreateParams {
304 ret = base.CreateParams;
306 ret.Style |= (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_VISIBLE);
312 protected bool HScroll {
314 return hscroll_visible;
318 if (hscroll_visible != value) {
319 hscroll_visible = value;
320 if (hscroll_visible && hscrollbar == null)
321 hscrollbar = new ScrollBar ();
326 protected bool VScroll {
328 return vscroll_visible;
332 if (vscroll_visible != value) {
333 vscroll_visible = value;
334 if (vscroll_visible && vscrollbar == null)
335 vscrollbar = new ScrollBar ();
339 #endregion // Protected Instance Methods
341 #region Public Instance Methods
342 public void ScrollControlIntoView(Control activeControl) {
345 public void SetAutoScrollMargin(int x, int y) {
347 #endregion // Public Instance Methods
349 #region Protected Instance Methods
350 protected virtual void AdjustFormScrollbars(bool displayScrollbars) {
353 protected bool GetScrollState(int bit) {
354 throw new NotImplementedException();
357 protected override void OnLayout(LayoutEventArgs levent) {
358 base.OnLayout(levent);
361 protected override void OnMouseWheel(MouseEventArgs e) {
362 base.OnMouseWheel(e);
365 protected override void OnVisibleChanged(EventArgs e) {
366 ;; // Nothing to do yet
369 protected override void ScaleCore(float dx, float dy) {
370 base.ScaleCore(dx, dy);
373 protected void SetDisplayRectLocation(int x, int y) {
374 throw new NotImplementedException();
377 protected void SetScrollState(int bit, bool value) {
378 throw new NotImplementedException();
381 protected override void WndProc(ref Message m) {
384 #endregion // Protected Instance Methods