Copied remotely
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ScrollableControl.cs
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    pbartok@novell.com
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
55 // NOT COMPLETE
56
57 using System;
58 using System.ComponentModel;
59 using System.Drawing;
60
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
76
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
81                         private int all;
82                         private int left;
83                         private int right;
84                         private int top;
85                         private int bottom;
86                         #endregion      // DockPaddingEdges Local Variables
87
88                         #region DockPaddingEdges Constructor
89                         internal DockPaddingEdges() {
90                                 all = 0;
91                                 left = 0;
92                                 right = 0;
93                                 top = 0;
94                                 bottom = 0;
95                         }
96                         #endregion      // DockPaddingEdges Constructor
97
98                         #region DockPaddingEdges Public Instance Properties
99                         public int All {
100                                 get {
101                                         return all;
102                                 }
103
104                                 set {
105                                         all = value;
106                                         left = value;
107                                         right = value;
108                                         top = value;
109                                         bottom = value;
110                                 }
111                         }
112
113                         public int Bottom {
114                                 get {
115                                         return bottom;
116                                 }
117
118                                 set {
119                                         bottom = value;
120                                         all = 0;
121                                 }
122                         }
123
124                         public int Left {
125                                 get {
126                                         return left;
127                                 }
128
129                                 set {
130                                         left=value;
131                                         all = 0;
132                                 }
133                         }
134
135                         public int Right {
136                                 get {
137                                         return right;
138                                 }
139
140                                 set {
141                                         right=value;
142                                         all = 0;
143                                 }
144                         }
145
146                         public int Top {
147                                 get {
148                                         return top;
149                                 }
150
151                                 set {
152                                         top=value;
153                                         all = 0;
154                                 }
155                         }
156
157                         #endregion      // DockPaddingEdges Public Instance Properties
158
159                         // Public Instance Methods
160                         public override bool Equals(object other) {
161                                 if (! (other is DockPaddingEdges)) {
162                                         return false;
163                                 }
164
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)) {
168                                         return true;
169                                 }
170
171                                 return false;
172                         }
173
174                         public override int GetHashCode() {
175                                 return all*top*bottom*right*left;
176                         }
177
178                         public override string ToString() {
179                                 return "All = "+all.ToString()+" Top = "+top.ToString()+" Left = "+left.ToString()+" Bottom = "+bottom.ToString()+" Right = "+right.ToString();
180                         }
181
182                         object ICloneable.Clone() {
183                                 DockPaddingEdges padding_edge;
184
185                                 padding_edge=new DockPaddingEdges();
186
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;
192
193                                 return padding_edge;
194                         }
195                 }
196                 #endregion      // Subclass DockPaddingEdges
197
198                 #region Subclass DockPaddingEdgesConverter
199                 public class DockPaddingEdgesConverter : System.ComponentModel.TypeConverter {
200                         // Public Constructors
201                         public DockPaddingEdgesConverter() {
202                         }
203
204                         // Public Instance Methods
205                         public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, Attribute[] attributes) {
206                                 throw new NotImplementedException();
207                         }
208
209                         public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) {
210                                 throw new NotImplementedException();
211                         }
212                 }
213                 #endregion      // Subclass DockPaddingEdgesConverter
214
215                 #region Public Constructors
216                 public ScrollableControl() {
217                         base.SetStyle(ControlStyles.ContainerControl, true);
218                         auto_scroll = false;
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();
227
228                         hscrollbar = new ScrollBar();
229                         hscrollbar.Visible = false;
230
231                         vscrollbar = new ScrollBar();
232                         vscrollbar.Visible = false;
233                 }
234                 #endregion      // Public Constructors
235
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
243
244                 #region Public Instance Properties
245                 public virtual bool AutoScroll {
246                         get {
247                                 return  auto_scroll;
248                         }
249
250                         set {
251                                 if (auto_scroll == value) {
252                                         return;
253                                 }
254
255                                 auto_scroll = value;
256                         }
257                 }
258
259                 public Size AutoScrollMargin {
260                         get {
261                                 return auto_scroll_margin;
262                         }
263
264                         set {
265                                 if (value.Width < 0) {
266                                         throw new ArgumentException("Width is assigned less than 0", "value.Width");
267                                 }
268
269                                 if (value.Height < 0) {
270                                         throw new ArgumentException("Height is assigned less than 0", "value.Height");
271                                 }
272
273                                 auto_scroll_margin = value;
274                         }
275                 }
276
277                 public Size AutoScrollMinSize {
278                         get {
279                                 return auto_scroll_min_size;
280                         }
281
282                         set {
283                                 auto_scroll_min_size = value;
284                         }
285                 }
286
287                 public Point AutoScrollPosition {
288                         get {
289                                 return auto_scroll_position;
290                         }
291
292                         set {
293                                 auto_scroll_position = value;
294                         }
295                 }
296
297                 public override Rectangle DisplayRectangle {
298                         get {
299                                 Rectangle       rect;
300
301                                 rect = base.DisplayRectangle;
302
303                                 if (vscroll_visible) {
304                                         rect.Width -= vscrollbar.Width;
305                                         if (rect.Width < 0) {
306                                                 rect.Width = 0;
307                                         }
308                                 }
309
310                                 if (hscroll_visible) {
311                                         rect.Height -= hscrollbar.Height;
312                                         if (rect.Height < 0) {
313                                                 rect.Height = 0;
314                                         }
315                                 }
316                                 return rect;
317                         }
318                 }
319
320                 public DockPaddingEdges DockPadding {
321                         get {
322                                 return dock_padding;
323                         }
324
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
327                         set {
328                                 dock_padding = value;
329                         }
330                 }
331                 #endregion      // Public Instance Properties
332
333                 #region Protected Instance Methods
334                 protected override CreateParams CreateParams {
335                         get {
336                                 CreateParams    ret;
337
338                                 ret = base.CreateParams;
339
340                                 ret.Style |= (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_VISIBLE);
341
342                                 return ret;
343                         }
344                 }
345
346                 protected bool HScroll {
347                         get {
348                                 return hscroll_visible;
349                         }
350
351                         set {
352                                 if (hscroll_visible != value) {
353                                         hscroll_visible = value;
354                                 }
355                         }
356                 }
357
358                 protected bool VScroll {
359                         get {
360                                 return vscroll_visible;
361                         }
362
363                         set {
364                                 if (vscroll_visible != value) {
365                                         vscroll_visible = value;
366                                 }
367                         }
368                 }
369                 #endregion      // Protected Instance Methods
370
371                 #region Public Instance Methods
372                 public void ScrollControlIntoView(Control activeControl) {
373                 }
374
375                 public void SetAutoScrollMargin(int x, int y) {
376                 }
377                 #endregion      // Public Instance Methods
378
379                 #region Protected Instance Methods
380                 protected virtual void AdjustFormScrollbars(bool displayScrollbars) {
381                 }
382
383                 protected bool GetScrollState(int bit) {
384                         throw new NotImplementedException();
385                 }
386
387                 protected override void OnLayout(LayoutEventArgs levent) {
388                         base.OnLayout(levent);
389                 }
390
391                 protected override void OnMouseWheel(MouseEventArgs e) {
392                         base.OnMouseWheel(e);
393                 }
394
395                 protected override void OnVisibleChanged(EventArgs e) {
396                         ;; // Nothing to do yet
397                 }
398
399                 protected override void ScaleCore(float dx, float dy) {
400                         throw new NotImplementedException();
401                 }
402
403                 protected void SetDisplayRectLocation(int x, int y) {
404                         throw new NotImplementedException();
405                 }
406
407                 protected void SetScrollState(int bit, bool value) {
408                         throw new NotImplementedException();
409                 }
410
411                 protected override void WndProc(ref Message m) {
412                         base.WndProc(ref m);
413                 }
414                 #endregion      // Protected Instance Methods
415         }
416 }