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
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
41 // Revision 1.4 2004/09/09 03:01:35 ravindra
42 // Removed unreachable code.
44 // Revision 1.3 2004/08/12 15:25:49 jordi
45 // calls ctrlbase instead of exeception
47 // Revision 1.2 2004/08/11 22:20:59 pbartok
50 // Revision 1.1 2004/07/09 05:21:25 pbartok
58 using System
.ComponentModel
;
61 namespace System
.Windows
.Forms
{
62 public class ScrollableControl
: Control
{
63 #region Local Variables
64 private bool auto_vscroll
;
65 private bool auto_hscroll
;
66 private bool hscroll_visible
;
67 private bool vscroll_visible
;
68 private bool auto_scroll
;
69 private Size auto_scroll_margin
;
70 private Size auto_scroll_min_size
;
71 private Point auto_scroll_position
;
72 private DockPaddingEdges dock_padding
;
73 private ScrollBar hscrollbar
;
74 private ScrollBar vscrollbar
;
75 #endregion // Local Variables
77 [MonoTODO("Need to use the edge values when performing the layout")]
78 #region Subclass DockPaddingEdges
79 public class DockPaddingEdges
: ICloneable
{
80 #region DockPaddingEdges Local Variables
86 #endregion // DockPaddingEdges Local Variables
88 #region DockPaddingEdges Constructor
89 internal DockPaddingEdges() {
96 #endregion // DockPaddingEdges Constructor
98 #region DockPaddingEdges Public Instance Properties
157 #endregion // DockPaddingEdges Public Instance Properties
159 // Public Instance Methods
160 public override bool Equals(object other
) {
161 if (! (other
is DockPaddingEdges
)) {
165 if ( (this.all
== ((DockPaddingEdges
)other
).all
) && (this.left
== ((DockPaddingEdges
)other
).left
) &&
166 (this.right
== ((DockPaddingEdges
)other
).right
) && (this.top
== ((DockPaddingEdges
)other
).top
) &&
167 (this.bottom
== ((DockPaddingEdges
)other
).bottom
)) {
174 public override int GetHashCode() {
175 return all
*top
*bottom
*right
*left
;
178 public override string ToString() {
179 return "All = "+all
.ToString()+" Top = "+top
.ToString()+" Left = "+left
.ToString()+" Bottom = "+bottom
.ToString()+" Right = "+right
.ToString();
182 object ICloneable
.Clone() {
183 DockPaddingEdges padding_edge
;
185 padding_edge
=new DockPaddingEdges();
187 padding_edge
.all
=all
;
188 padding_edge
.left
=left
;
189 padding_edge
.right
=right
;
190 padding_edge
.top
=top
;
191 padding_edge
.bottom
=bottom
;
196 #endregion // Subclass DockPaddingEdges
198 #region Subclass DockPaddingEdgesConverter
199 public class DockPaddingEdgesConverter
: System
.ComponentModel
.TypeConverter
{
200 // Public Constructors
201 public DockPaddingEdgesConverter() {
204 // Public Instance Methods
205 public override PropertyDescriptorCollection
GetProperties(System
.ComponentModel
.ITypeDescriptorContext context
, object value, Attribute
[] attributes
) {
206 throw new NotImplementedException();
209 public override bool GetPropertiesSupported(System
.ComponentModel
.ITypeDescriptorContext context
) {
210 throw new NotImplementedException();
213 #endregion // Subclass DockPaddingEdgesConverter
215 #region Public Constructors
216 public ScrollableControl() {
217 base.SetStyle(ControlStyles
.ContainerControl
, true);
219 auto_hscroll
= false;
220 auto_vscroll
= false;
221 hscroll_visible
= false;
222 vscroll_visible
= false;
223 auto_scroll_margin
= new Size(0, 0);
224 auto_scroll_min_size
= new Size(0, 0);
225 auto_scroll_position
= new Point(0, 0);
226 dock_padding
= new DockPaddingEdges();
228 hscrollbar
= new ScrollBar();
229 hscrollbar
.Visible
= false;
231 vscrollbar
= new ScrollBar();
232 vscrollbar
.Visible
= false;
234 #endregion // Public Constructors
236 #region Protected Static Fields
237 protected const int ScrollStateAutoScrolling
= 1;
238 protected const int ScrollStateFullDrag
= 16;
239 protected const int ScrollStateHScrollVisible
= 2;
240 protected const int ScrollStateUserHasScrolled
= 8;
241 protected const int ScrollStateVScrollVisible
= 4;
242 #endregion // Protected Static Fields
244 #region Public Instance Properties
245 public virtual bool AutoScroll
{
251 if (auto_scroll
== value) {
259 public Size AutoScrollMargin
{
261 return auto_scroll_margin
;
265 if (value.Width
< 0) {
266 throw new ArgumentException("Width is assigned less than 0", "value.Width");
269 if (value.Height
< 0) {
270 throw new ArgumentException("Height is assigned less than 0", "value.Height");
273 auto_scroll_margin
= value;
277 public Size AutoScrollMinSize
{
279 return auto_scroll_min_size
;
283 auto_scroll_min_size
= value;
287 public Point AutoScrollPosition
{
289 return auto_scroll_position
;
293 auto_scroll_position
= value;
297 public override Rectangle DisplayRectangle
{
301 rect
= base.DisplayRectangle
;
303 if (vscroll_visible
) {
304 rect
.Width
-= vscrollbar
.Width
;
305 if (rect
.Width
< 0) {
310 if (hscroll_visible
) {
311 rect
.Height
-= hscrollbar
.Height
;
312 if (rect
.Height
< 0) {
320 public DockPaddingEdges DockPadding
{
325 // DockPadding is documented as 'get' only ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsScrollableControlClassAutoScrollTopic.asp )
326 // but Microsoft's on that pageexamples show 'set' usage
328 dock_padding
= value;
331 #endregion // Public Instance Properties
333 #region Protected Instance Methods
334 protected override CreateParams CreateParams
{
338 ret
= base.CreateParams
;
340 ret
.Style
|= (int)(WindowStyles
.WS_CLIPCHILDREN
| WindowStyles
.WS_CLIPSIBLINGS
| WindowStyles
.WS_VISIBLE
);
346 protected bool HScroll
{
348 return hscroll_visible
;
352 if (hscroll_visible
!= value) {
353 hscroll_visible
= value;
358 protected bool VScroll
{
360 return vscroll_visible
;
364 if (vscroll_visible
!= value) {
365 vscroll_visible
= value;
369 #endregion // Protected Instance Methods
371 #region Public Instance Methods
372 public void ScrollControlIntoView(Control activeControl
) {
375 public void SetAutoScrollMargin(int x
, int y
) {
377 #endregion // Public Instance Methods
379 #region Protected Instance Methods
380 protected virtual void AdjustFormScrollbars(bool displayScrollbars
) {
383 protected bool GetScrollState(int bit
) {
384 throw new NotImplementedException();
387 protected override void OnLayout(LayoutEventArgs levent
) {
388 base.OnLayout(levent
);
391 protected override void OnMouseWheel(MouseEventArgs e
) {
392 base.OnMouseWheel(e
);
395 protected override void OnVisibleChanged(EventArgs e
) {
396 ;; // Nothing to do yet
399 protected override void ScaleCore(float dx
, float dy
) {
400 throw new NotImplementedException();
403 protected void SetDisplayRectLocation(int x
, int y
) {
404 throw new NotImplementedException();
407 protected void SetScrollState(int bit
, bool value) {
408 throw new NotImplementedException();
411 protected override void WndProc(ref Message m
) {
414 #endregion // Protected Instance Methods