- Added ActiveMdiChild method
[mono.git] / mcs / class / System.Windows.Forms / Gtk / ScrollBar.cs
1 //
2 // System.Windows.Forms.Button.cs
3 //
4 // Author:
5 //   stubbed out by Jaak Simm (jaaksimm@firm.ee)
6 //        implemented for Gtk+ by Philip Van Hoof (me@freax.org)
7 //
8 // (C) Ximian, Inc., 2002
9 //
10
11 using System.Drawing;
12
13 namespace System.Windows.Forms {
14
15         /// <summary>
16         /// </summary>
17
18         public class ScrollBar : Control {
19                 internal Gtk.Adjustment adj;
20                 private double val;
21                 private double lower;
22                 private double upper;
23                 private double step_increment;
24                 private double page_increment;
25                 private double page_size;
26
27                 //
28                 //  --- Constructor
29                 //
30
31                 public ScrollBar() : base(){
32                         // Defaults
33                         this.upper = 100;
34                         this.lower = 0;
35                         this.val = 0;
36                         this.step_increment = 1;
37                         this.page_increment = 10;
38                         this.page_size = 10;
39                         this.adj = new Gtk.Adjustment(val, lower, upper, step_increment, page_increment, page_size);
40                         //spec says tabstop defaults to false.
41                         base.TabStop = false;
42                         ConnectToChanged();
43                 }
44
45                 //
46                 //  --- Public Properties
47                 //
48
49
50                 public int LargeChange {
51                         get {return (int)page_increment;}
52                         set {
53                                 if (value < 0){
54                                         String st = String.Format (
55                                                 "'{0}' is not a valid value for LargeChange."+
56                                                 "It should be >= 0", value
57                                         );
58                                         throw new ArgumentException (st);
59                                 }
60                                 page_increment = value;
61                                 UpdateGtkScroll();
62                         }
63                 }
64
65                 public int Maximum {
66                         get {return (int) upper;}
67                         set {
68                                 upper = value;
69                                 if (value < lower)
70                                         lower = value;
71                                 if (value < this.Value)
72                                         this.Value = value;
73                                         
74                                 UpdateGtkScroll();
75                         }
76                 }
77
78                 public int Minimum {
79                         get {return (int) lower;}
80                         set {
81                                 lower = value;
82                                 if (value > upper)
83                                         upper = value;
84                                 if (value > val)
85                                         val = value;
86                                 UpdateGtkScroll();
87                         }
88                 }
89                 public int SmallChange {
90                         get { return (int) step_increment;}
91                         set {
92                                 if (value < 0){
93                                         String st = String.Format (
94                                                 "'{0}' is not a valid value for SmallChange."+
95                                                 "It should be >= 0", value
96                                         );
97                                         throw new ArgumentException (st);
98                                 }
99                                 step_increment = value;
100                                 UpdateGtkScroll();
101                         }
102                 }
103
104                 public int Value {
105                         get {return (int) val; }
106                                 
107                         set {
108                                 if ((value > upper) || (value < lower)){
109                                         String st = String.Format (
110                                         "'{0}' is not a valid value for Minimum."+
111                                         " It should be betwen Minimum and Maximum", value);
112                                         
113                                         throw new ArgumentException (st);
114                                 }
115                                 val = value; 
116                                 UpdateGtkScroll();
117                         }
118                 }
119
120                 //
121                 //  --- Public Events
122                 //
123
124                 public event ScrollEventHandler Scroll;
125                 public event EventHandler ValueChanged;
126
127                 protected virtual void OnValueChanged (EventArgs args){
128                         if (ValueChanged != null)
129                                 ValueChanged (this, args);
130                 }
131                 protected virtual void OnScroll (ScrollEventArgs args){
132                         if (Scroll != null)
133                                 Scroll (this, args);
134                 }
135                 [MonoTODO]
136                 protected override void OnEnabledChanged(EventArgs e){
137                         throw new NotImplementedException();
138                 }
139
140                 [MonoTODO]
141                 protected override void OnHandleCreated(EventArgs e){
142                         throw new NotImplementedException();
143                 }       
144                 
145                 // FIXME: 
146                 
147                 internal protected void changed_cb (object o, EventArgs args){
148                         val = this.adj.Value;
149                         OnValueChanged(args);
150                         OnScroll (new ScrollEventArgs(ScrollEventType.ThumbPosition ,(int) val));
151                 }
152                 
153                 internal protected void ConnectToChanged (){
154                         this.adj.ValueChanged += new EventHandler (changed_cb);
155                 }
156                 
157                 internal protected void UpdateGtkScroll(){
158                         this.adj.SetBounds (lower, upper, step_increment, page_increment, page_size);
159                         if ((int) val != this.adj.Value)
160                                 this.adj.Value = (int) val;
161                 }
162          }
163 }