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 base.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 hscrollbar = new ScrollBar();
201 hscrollbar.Visible = false;
203 vscrollbar = new ScrollBar();
204 vscrollbar.Visible = false;
206 #endregion // Public Constructors
208 #region Protected Static Fields
209 protected const int ScrollStateAutoScrolling = 1;
210 protected const int ScrollStateFullDrag = 16;
211 protected const int ScrollStateHScrollVisible = 2;
212 protected const int ScrollStateUserHasScrolled = 8;
213 protected const int ScrollStateVScrollVisible = 4;
214 #endregion // Protected Static Fields
216 #region Public Instance Properties
217 public virtual bool AutoScroll {
223 if (auto_scroll == value) {
231 public Size AutoScrollMargin {
233 return auto_scroll_margin;
237 if (value.Width < 0) {
238 throw new ArgumentException("Width is assigned less than 0", "value.Width");
241 if (value.Height < 0) {
242 throw new ArgumentException("Height is assigned less than 0", "value.Height");
245 auto_scroll_margin = value;
249 public Size AutoScrollMinSize {
251 return auto_scroll_min_size;
255 auto_scroll_min_size = value;
259 public Point AutoScrollPosition {
261 return auto_scroll_position;
265 auto_scroll_position = value;
269 public override Rectangle DisplayRectangle {
273 rect = base.DisplayRectangle;
275 if (vscroll_visible) {
276 rect.Width -= vscrollbar.Width;
277 if (rect.Width < 0) {
282 if (hscroll_visible) {
283 rect.Height -= hscrollbar.Height;
284 if (rect.Height < 0) {
292 public DockPaddingEdges DockPadding {
297 // DockPadding is documented as 'get' only ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsScrollableControlClassAutoScrollTopic.asp )
298 // but Microsoft's on that pageexamples show 'set' usage
300 dock_padding = value;
303 #endregion // Public Instance Properties
305 #region Protected Instance Methods
306 protected override CreateParams CreateParams {
310 ret = base.CreateParams;
312 ret.Style |= (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_VISIBLE);
318 protected bool HScroll {
320 return hscroll_visible;
324 if (hscroll_visible != value) {
325 hscroll_visible = value;
330 protected bool VScroll {
332 return vscroll_visible;
336 if (vscroll_visible != value) {
337 vscroll_visible = value;
341 #endregion // Protected Instance Methods
343 #region Public Instance Methods
344 public void ScrollControlIntoView(Control activeControl) {
347 public void SetAutoScrollMargin(int x, int y) {
349 #endregion // Public Instance Methods
351 #region Protected Instance Methods
352 protected virtual void AdjustFormScrollbars(bool displayScrollbars) {
355 protected bool GetScrollState(int bit) {
356 throw new NotImplementedException();
359 protected override void OnLayout(LayoutEventArgs levent) {
360 base.OnLayout(levent);
363 protected override void OnMouseWheel(MouseEventArgs e) {
364 base.OnMouseWheel(e);
367 protected override void OnVisibleChanged(EventArgs e) {
368 ;; // Nothing to do yet
371 protected override void ScaleCore(float dx, float dy) {
372 throw new NotImplementedException();
375 protected void SetDisplayRectLocation(int x, int y) {
376 throw new NotImplementedException();
379 protected void SetScrollState(int bit, bool value) {
380 throw new NotImplementedException();
383 protected override void WndProc(ref Message m) {
386 #endregion // Protected Instance Methods