remove old cvs comments since they are no longer updated and we use ChangeLog now
[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
27 // NOT COMPLETE
28
29 using System;
30 using System.ComponentModel;
31 using System.Drawing;
32
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
48
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
53                         private int all;
54                         private int left;
55                         private int right;
56                         private int top;
57                         private int bottom;
58                         #endregion      // DockPaddingEdges Local Variables
59
60                         #region DockPaddingEdges Constructor
61                         internal DockPaddingEdges() {
62                                 all = 0;
63                                 left = 0;
64                                 right = 0;
65                                 top = 0;
66                                 bottom = 0;
67                         }
68                         #endregion      // DockPaddingEdges Constructor
69
70                         #region DockPaddingEdges Public Instance Properties
71                         public int All {
72                                 get {
73                                         return all;
74                                 }
75
76                                 set {
77                                         all = value;
78                                         left = value;
79                                         right = value;
80                                         top = value;
81                                         bottom = value;
82                                 }
83                         }
84
85                         public int Bottom {
86                                 get {
87                                         return bottom;
88                                 }
89
90                                 set {
91                                         bottom = value;
92                                         all = 0;
93                                 }
94                         }
95
96                         public int Left {
97                                 get {
98                                         return left;
99                                 }
100
101                                 set {
102                                         left=value;
103                                         all = 0;
104                                 }
105                         }
106
107                         public int Right {
108                                 get {
109                                         return right;
110                                 }
111
112                                 set {
113                                         right=value;
114                                         all = 0;
115                                 }
116                         }
117
118                         public int Top {
119                                 get {
120                                         return top;
121                                 }
122
123                                 set {
124                                         top=value;
125                                         all = 0;
126                                 }
127                         }
128
129                         #endregion      // DockPaddingEdges Public Instance Properties
130
131                         // Public Instance Methods
132                         public override bool Equals(object other) {
133                                 if (! (other is DockPaddingEdges)) {
134                                         return false;
135                                 }
136
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)) {
140                                         return true;
141                                 }
142
143                                 return false;
144                         }
145
146                         public override int GetHashCode() {
147                                 return all*top*bottom*right*left;
148                         }
149
150                         public override string ToString() {
151                                 return "All = "+all.ToString()+" Top = "+top.ToString()+" Left = "+left.ToString()+" Bottom = "+bottom.ToString()+" Right = "+right.ToString();
152                         }
153
154                         object ICloneable.Clone() {
155                                 DockPaddingEdges padding_edge;
156
157                                 padding_edge=new DockPaddingEdges();
158
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;
164
165                                 return padding_edge;
166                         }
167                 }
168                 #endregion      // Subclass DockPaddingEdges
169
170                 #region Subclass DockPaddingEdgesConverter
171                 public class DockPaddingEdgesConverter : System.ComponentModel.TypeConverter {
172                         // Public Constructors
173                         public DockPaddingEdgesConverter() {
174                         }
175
176                         // Public Instance Methods
177                         public override PropertyDescriptorCollection GetProperties(System.ComponentModel.ITypeDescriptorContext context, object value, Attribute[] attributes) {
178                                 throw new NotImplementedException();
179                         }
180
181                         public override bool GetPropertiesSupported(System.ComponentModel.ITypeDescriptorContext context) {
182                                 throw new NotImplementedException();
183                         }
184                 }
185                 #endregion      // Subclass DockPaddingEdgesConverter
186
187                 #region Public Constructors
188                 public ScrollableControl() {
189                         base.SetStyle(ControlStyles.ContainerControl, true);
190                         auto_scroll = false;
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();
199
200                         hscrollbar = new ScrollBar();
201                         hscrollbar.Visible = false;
202
203                         vscrollbar = new ScrollBar();
204                         vscrollbar.Visible = false;
205                 }
206                 #endregion      // Public Constructors
207
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
215
216                 #region Public Instance Properties
217                 public virtual bool AutoScroll {
218                         get {
219                                 return  auto_scroll;
220                         }
221
222                         set {
223                                 if (auto_scroll == value) {
224                                         return;
225                                 }
226
227                                 auto_scroll = value;
228                         }
229                 }
230
231                 public Size AutoScrollMargin {
232                         get {
233                                 return auto_scroll_margin;
234                         }
235
236                         set {
237                                 if (value.Width < 0) {
238                                         throw new ArgumentException("Width is assigned less than 0", "value.Width");
239                                 }
240
241                                 if (value.Height < 0) {
242                                         throw new ArgumentException("Height is assigned less than 0", "value.Height");
243                                 }
244
245                                 auto_scroll_margin = value;
246                         }
247                 }
248
249                 public Size AutoScrollMinSize {
250                         get {
251                                 return auto_scroll_min_size;
252                         }
253
254                         set {
255                                 auto_scroll_min_size = value;
256                         }
257                 }
258
259                 public Point AutoScrollPosition {
260                         get {
261                                 return auto_scroll_position;
262                         }
263
264                         set {
265                                 auto_scroll_position = value;
266                         }
267                 }
268
269                 public override Rectangle DisplayRectangle {
270                         get {
271                                 Rectangle       rect;
272
273                                 rect = base.DisplayRectangle;
274
275                                 if (vscroll_visible) {
276                                         rect.Width -= vscrollbar.Width;
277                                         if (rect.Width < 0) {
278                                                 rect.Width = 0;
279                                         }
280                                 }
281
282                                 if (hscroll_visible) {
283                                         rect.Height -= hscrollbar.Height;
284                                         if (rect.Height < 0) {
285                                                 rect.Height = 0;
286                                         }
287                                 }
288                                 return rect;
289                         }
290                 }
291
292                 public DockPaddingEdges DockPadding {
293                         get {
294                                 return dock_padding;
295                         }
296
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
299                         set {
300                                 dock_padding = value;
301                         }
302                 }
303                 #endregion      // Public Instance Properties
304
305                 #region Protected Instance Methods
306                 protected override CreateParams CreateParams {
307                         get {
308                                 CreateParams    ret;
309
310                                 ret = base.CreateParams;
311
312                                 ret.Style |= (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_VISIBLE);
313
314                                 return ret;
315                         }
316                 }
317
318                 protected bool HScroll {
319                         get {
320                                 return hscroll_visible;
321                         }
322
323                         set {
324                                 if (hscroll_visible != value) {
325                                         hscroll_visible = value;
326                                 }
327                         }
328                 }
329
330                 protected bool VScroll {
331                         get {
332                                 return vscroll_visible;
333                         }
334
335                         set {
336                                 if (vscroll_visible != value) {
337                                         vscroll_visible = value;
338                                 }
339                         }
340                 }
341                 #endregion      // Protected Instance Methods
342
343                 #region Public Instance Methods
344                 public void ScrollControlIntoView(Control activeControl) {
345                 }
346
347                 public void SetAutoScrollMargin(int x, int y) {
348                 }
349                 #endregion      // Public Instance Methods
350
351                 #region Protected Instance Methods
352                 protected virtual void AdjustFormScrollbars(bool displayScrollbars) {
353                 }
354
355                 protected bool GetScrollState(int bit) {
356                         throw new NotImplementedException();
357                 }
358
359                 protected override void OnLayout(LayoutEventArgs levent) {
360                         base.OnLayout(levent);
361                 }
362
363                 protected override void OnMouseWheel(MouseEventArgs e) {
364                         base.OnMouseWheel(e);
365                 }
366
367                 protected override void OnVisibleChanged(EventArgs e) {
368                         ;; // Nothing to do yet
369                 }
370
371                 protected override void ScaleCore(float dx, float dy) {
372                         throw new NotImplementedException();
373                 }
374
375                 protected void SetDisplayRectLocation(int x, int y) {
376                         throw new NotImplementedException();
377                 }
378
379                 protected void SetScrollState(int bit, bool value) {
380                         throw new NotImplementedException();
381                 }
382
383                 protected override void WndProc(ref Message m) {
384                         base.WndProc(ref m);
385                 }
386                 #endregion      // Protected Instance Methods
387         }
388 }