- Implemented InvokeGotFocus() method
[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                         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                 #endregion      // Public Constructors
201
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
209
210                 #region Public Instance Properties
211                 public virtual bool AutoScroll {
212                         get {
213                                 return  auto_scroll;
214                         }
215
216                         set {
217                                 if (auto_scroll == value) {
218                                         return;
219                                 }
220
221                                 auto_scroll = value;
222                         }
223                 }
224
225                 public Size AutoScrollMargin {
226                         get {
227                                 return auto_scroll_margin;
228                         }
229
230                         set {
231                                 if (value.Width < 0) {
232                                         throw new ArgumentException("Width is assigned less than 0", "value.Width");
233                                 }
234
235                                 if (value.Height < 0) {
236                                         throw new ArgumentException("Height is assigned less than 0", "value.Height");
237                                 }
238
239                                 auto_scroll_margin = value;
240                         }
241                 }
242
243                 public Size AutoScrollMinSize {
244                         get {
245                                 return auto_scroll_min_size;
246                         }
247
248                         set {
249                                 auto_scroll_min_size = value;
250                         }
251                 }
252
253                 public Point AutoScrollPosition {
254                         get {
255                                 return auto_scroll_position;
256                         }
257
258                         set {
259                                 auto_scroll_position = value;
260                         }
261                 }
262
263                 public override Rectangle DisplayRectangle {
264                         get {
265                                 Rectangle       rect;
266
267                                 rect = base.DisplayRectangle;
268
269                                 if (vscroll_visible) {
270                                         rect.Width -= vscrollbar.Width;
271                                         if (rect.Width < 0) {
272                                                 rect.Width = 0;
273                                         }
274                                 }
275
276                                 if (hscroll_visible) {
277                                         rect.Height -= hscrollbar.Height;
278                                         if (rect.Height < 0) {
279                                                 rect.Height = 0;
280                                         }
281                                 }
282                                 return rect;
283                         }
284                 }
285
286                 public DockPaddingEdges DockPadding {
287                         get {
288                                 return dock_padding;
289                         }
290
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
293                         set {
294                                 dock_padding = value;
295                         }
296                 }
297                 #endregion      // Public Instance Properties
298
299                 #region Protected Instance Methods
300                 protected override CreateParams CreateParams {
301                         get {
302                                 CreateParams    ret;
303
304                                 ret = base.CreateParams;
305
306                                 ret.Style |= (int)(WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_CLIPSIBLINGS | WindowStyles.WS_VISIBLE);
307
308                                 return ret;
309                         }
310                 }
311
312                 protected bool HScroll {
313                         get {
314                                 return hscroll_visible;
315                         }
316
317                         set {
318                                 if (hscroll_visible != value) {
319                                         hscroll_visible = value;
320                                         if (hscroll_visible && hscrollbar == null)
321                                                 hscrollbar = new ScrollBar ();
322                                 }
323                         }
324                 }
325
326                 protected bool VScroll {
327                         get {
328                                 return vscroll_visible;
329                         }
330
331                         set {
332                                 if (vscroll_visible != value) {
333                                         vscroll_visible = value;
334                                         if (vscroll_visible && vscrollbar == null)
335                                                 vscrollbar = new ScrollBar ();
336                                 }
337                         }
338                 }
339                 #endregion      // Protected Instance Methods
340
341                 #region Public Instance Methods
342                 public void ScrollControlIntoView(Control activeControl) {
343                 }
344
345                 public void SetAutoScrollMargin(int x, int y) {
346                 }
347                 #endregion      // Public Instance Methods
348
349                 #region Protected Instance Methods
350                 protected virtual void AdjustFormScrollbars(bool displayScrollbars) {
351                 }
352
353                 protected bool GetScrollState(int bit) {
354                         throw new NotImplementedException();
355                 }
356
357                 protected override void OnLayout(LayoutEventArgs levent) {
358                         base.OnLayout(levent);
359                 }
360
361                 protected override void OnMouseWheel(MouseEventArgs e) {
362                         base.OnMouseWheel(e);
363                 }
364
365                 protected override void OnVisibleChanged(EventArgs e) {
366                         ;; // Nothing to do yet
367                 }
368
369                 protected override void ScaleCore(float dx, float dy) {
370                         base.ScaleCore(dx, dy);
371                 }
372
373                 protected void SetDisplayRectLocation(int x, int y) {
374                         throw new NotImplementedException();
375                 }
376
377                 protected void SetScrollState(int bit, bool value) {
378                         throw new NotImplementedException();
379                 }
380
381                 protected override void WndProc(ref Message m) {
382                         base.WndProc(ref m);
383                 }
384                 #endregion      // Protected Instance Methods
385         }
386 }