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 // Miguel de Icaza (miguel@novell.com).
30 - Force the size of the entry: it can not be resized vertically
31 ever, the size is set by the size of the font
37 namespace System.Windows.Forms {
38 public abstract class UpDownBase : ContainerControl {
40 internal class Spinner : Control, IDisposable {
41 UpDownBase updownbase;
42 Rectangle up, down, pressed;
44 bool up_pressed, down_pressed;
45 bool captured, mouse_in;
50 const int StartInterval = 1000;
51 const int RepeatInterval = 400;
52 const int ChangeInterval = 75;
53 const int MinimumInterval = 20;
55 internal Spinner (UpDownBase updownbase)
57 this.updownbase = updownbase;
60 protected override void OnPaint (PaintEventArgs args)
62 Draw (args.ClipRectangle);
63 args.Graphics.DrawImage (ImageBuffer, 0, 0);
66 protected override void OnLayout (LayoutEventArgs args)
69 Rectangle bounds = Bounds;
71 up = new Rectangle (0, 0, bounds.Width, bounds.Height/2);
72 down = new Rectangle (0, bounds.Height/2, bounds.Width, bounds.Height/2);
75 protected override void OnMouseDown (MouseEventArgs args)
77 base.OnMouseDown (args);
79 if (args.Button != MouseButtons.Left)
82 if (up.Contains (args.X, args.Y)){
85 } else if (down.Contains (args.X, args.Y)){
96 mouse_in = down_pressed | up_pressed;
99 protected override void OnMouseUp (MouseEventArgs args)
107 down_pressed = false;
115 // Sets up the auto-repeat timer, we give a one second
116 // delay, and then we use the keyboard settings for auto-repeat.
120 timer = new Timer ();
121 int kd = SystemInformation.KeyboardDelay;
122 kd = kd < 0 ? 0 : (kd > 4 ? 4 : kd);
123 timer.Interval = StartInterval;
124 timer.Tick += new EventHandler (ClockTick);
125 timer.Enabled = true;
128 void ClockTick (object o, EventArgs a)
131 throw new Exception ("The timer that owns this callback is null!");
133 int interval = timer.Interval;
135 if (interval == StartInterval)
136 interval = RepeatInterval;
138 interval -= ChangeInterval;
140 if (interval < MinimumInterval)
141 interval = MinimumInterval;
142 timer.Interval = interval;
150 updownbase.UpButton ();
152 updownbase.DownButton ();
155 protected override void OnMouseMove (MouseEventArgs args)
157 base.OnMouseMove (args);
161 if (pressed.Contains (args.X, args.Y)){
167 timer.Enabled = false;
174 Console.WriteLine ("STATE CHANGE");
177 Invalidate (pressed);
186 bs = mouse_in && up_pressed ? ButtonState.Pushed : ButtonState.Normal;
187 ThemeEngine.Current.CPDrawScrollButton (DeviceContext, up, ScrollButton.Up, bs);
194 bs = mouse_in && down_pressed ? ButtonState.Pushed : ButtonState.Normal;
195 ThemeEngine.Current.CPDrawScrollButton (DeviceContext, down, ScrollButton.Down, bs);
198 void Draw (Rectangle clip)
200 if (clip.Contains (up))
202 if (clip.Contains (down))
206 void IDisposable.Dispose ()
217 int desired_height = 0;
221 int scrollbar_button_size = ThemeEngine.Current.ScrollBarButtonSize;
223 public UpDownBase () : base ()
227 entry = new Label ();
228 entry.Text = "I will be an Entry";
230 entry.Size = new Size (100, Font.Height + 4);
231 entry.Location = new Point (0, 0);
232 Controls.Add (entry);
234 spinner = new Spinner (this);
235 Controls.Add (spinner);
241 #region UpDownBase overwritten methods
243 protected override void OnMouseWheel (MouseEventArgs args)
245 base.OnMouseWheel (args);
249 else if (args.Delta < 0)
253 protected virtual void OnChanged (object source, EventArgs e)
255 // Not clear, the docs state that this will raise the
256 // Changed event, but that event is not listed anywhere.
259 protected override void OnFontChanged (EventArgs e)
261 base.OnFontChanged (e);
264 desired_height = entry.Height;
265 Height = desired_height;
268 protected override void OnHandleCreated (EventArgs e)
270 base.OnHandleCreated (e);
271 desired_height = entry.Height;
274 protected override void OnLayout (LayoutEventArgs args)
276 base.OnLayout (args);
278 Rectangle bounds = Bounds;
279 int entry_width = bounds.Right - scrollbar_button_size - 1;
281 entry.SetBounds (bounds.X, bounds.Y, entry_width, bounds.Height);
282 spinner.SetBounds (entry_width + 1, bounds.Y, scrollbar_button_size, bounds.Height);
285 protected override void OnPaint (PaintEventArgs e)
290 protected override void SetVisibleCore (bool state)
292 base.SetVisibleCore (state);
295 protected override void WndProc (ref Message m)
297 base.WndProc (ref m);
300 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
303 // Force the size to be our height.
305 base.SetBoundsCore (x, y, width, desired_height, specified);
308 protected override void Dispose (bool disposing)
310 if (spinner != null){
323 #region UpDownBase virtual methods
325 // These are hooked up to the various events from the Entry line that
326 // we do not have yet, and implement the keyboard behavior (use a different
329 protected virtual void OnTextBoxKeyDown (object source, KeyEventArgs e)
333 protected virtual void OnTextBoxKeyPress (object source, KeyPressEventArgs e)
337 protected virtual void OnTextBoxLostFocus (object source, EventArgs e)
341 protected virtual void OnTextBoxResize (object source, EventArgs e)
345 protected virtual void OnTextBoxTextChanged (object source, EventArgs e)
349 protected virtual void ValidateEditText ()
354 #region UpDownBase standard methods
355 public void Select (int start, int length)
357 // Selects text from start for lenght chars.
361 #region Abstract methods
362 public abstract void DownButton ();
363 public abstract void UpButton ();
364 public abstract void UpdateEditText ();