// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-// Autors:
-// Jordi Mas i Hernandez, jordi@ximian.com
+//
+// Copyright (c) 2004-2005 Novell, Inc.
+//
+// Authors:
+// Jordi Mas i Hernandez, jordi@ximian.com
//
// TODO:
// - The AutoSize functionality seems quite broken for vertical controls in .Net 1.1. Not
// sure if we are implementing it the right way.
//
-// Copyright (C) Novell Inc., 2004
-//
-//
-// $Revision: 1.14 $
-// $Modtime: $
-// $Log: TrackBar.cs,v $
-// Revision 1.14 2004/09/28 18:44:25 pbartok
-// - Streamlined Theme interfaces:
-// * Each DrawXXX method for a control now is passed the object for the
-// control to be drawn in order to allow accessing any state the theme
-// might require
-//
-// * ControlPaint methods for the theme now have a CP prefix to avoid
-// name clashes with the Draw methods for controls
-//
-// * Every control now retrieves it's DefaultSize from the current theme
-//
-// Revision 1.13 2004/08/23 20:10:03 jordi
-// fixes properties and methods
-//
-// Revision 1.12 2004/08/21 20:21:48 pbartok
-// - Replaced direct XplatUI calls with their Control counterpart
-//
-// Revision 1.11 2004/08/20 19:45:50 jordi
-// fixes timer, new properties and methods
-//
-// Revision 1.10 2004/08/13 20:55:20 jordi
-// change from wndproc to events
-//
-// Revision 1.9 2004/08/13 18:46:26 jordi
-// adds timer and grap window
-//
-// Revision 1.8 2004/08/12 20:29:01 jordi
-// Trackbar enhancement, fix mouse problems, highli thumb, etc
-//
-// Revision 1.7 2004/08/10 23:27:12 jordi
-// add missing methods, properties, and restructure to hide extra ones
-//
-// Revision 1.6 2004/08/10 15:47:11 jackson
-// Allow control to handle buffering
-//
-// Revision 1.5 2004/08/07 23:32:26 jordi
-// throw exceptions of invalid enums values
-//
-// Revision 1.4 2004/08/06 23:18:06 pbartok
-// - Fixed some rounding issues with float/int
-//
-// Revision 1.3 2004/07/27 15:53:02 jordi
-// fixes trackbar events, def classname, methods signature
-//
-// Revision 1.2 2004/07/26 17:42:03 jordi
-// Theme support
-//
-// Revision 1.1 2004/07/15 09:38:02 jordi
-// Horizontal and Vertical TrackBar control implementation
-//
-//
+
// NOT COMPLETE
using System.ComponentModel;
+using System.ComponentModel.Design;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
namespace System.Windows.Forms
{
-
+ [Designer("System.Windows.Forms.Design.TrackBarDesigner, " + Consts.AssemblySystem_Design)]
[DefaultEvent ("Scroll")]
+ [DefaultProperty("Value")]
public class TrackBar : Control, ISupportInitialize
{
private int minimum;
private int smallChange;
private int largeChange;
private Orientation orientation;
- private TickStyle tickStyle;
- internal Rectangle paint_area = new Rectangle ();
+ private TickStyle tickStyle;
private Rectangle thumb_pos = new Rectangle (); /* Current position and size of the thumb */
private Rectangle thumb_area = new Rectangle (); /* Area where the thumb can scroll */
internal bool thumb_pressed = false;
internal int thumb_mouseclick;
private bool mouse_clickmove;
- #region Events
- public event EventHandler Scroll;
- public event EventHandler ValueChanged;
- public new event EventHandler ImeModeChanged;
+ #region events
+ [Browsable (false)]
+ [EditorBrowsable (EditorBrowsableState.Never)]
+ public new event EventHandler BackgroundImageChanged;
+
+ [Browsable (false)]
+ [EditorBrowsable (EditorBrowsableState.Never)]
+ public new event EventHandler Click;
+
+ [Browsable (false)]
+ [EditorBrowsable (EditorBrowsableState.Never)]
+ public new event EventHandler DoubleClick;
+
+ [Browsable (false)]
+ [EditorBrowsable (EditorBrowsableState.Never)]
+ public new event EventHandler FontChanged;
+
+ [Browsable (false)]
+ [EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler ForeColorChanged;
+
+ [Browsable (false)]
+ [EditorBrowsable (EditorBrowsableState.Never)]
+ public new event EventHandler ImeModeChanged;
+
+ [Browsable (false)]
+ [EditorBrowsable (EditorBrowsableState.Never)]
+ public new event PaintEventHandler Paint;
+
+ public event EventHandler Scroll;
+
+ [Browsable (false)]
+ [EditorBrowsable (EditorBrowsableState.Never)]
public new event EventHandler TextChanged;
- public new event EventHandler BackgroundImageChanged;
+ public event EventHandler ValueChanged;
+
#endregion // Events
public TrackBar ()
position = 0;
tickStyle = TickStyle.BottomRight;
smallChange = 1;
- largeChange = 5;
- Scroll = null;
- ValueChanged = null;
- mouse_clickmove = false;
- SizeChanged += new System.EventHandler (OnResizeTB);
+ largeChange = 5;
+ mouse_clickmove = false;
MouseDown += new MouseEventHandler (OnMouseDownTB);
MouseUp += new MouseEventHandler (OnMouseUpTB);
MouseMove += new MouseEventHandler (OnMouseMoveTB);
}
[EditorBrowsable (EditorBrowsableState.Never)]
+ [Browsable (false)]
public override Image BackgroundImage {
get { return base.BackgroundImage; }
set {
get { return ThemeEngine.Current.TrackBarDefaultSize; }
}
- [EditorBrowsable (EditorBrowsableState.Never)]
+ [Browsable(false)]
+ [EditorBrowsable (EditorBrowsableState.Never)]
public override Font Font {
get { return base.Font; }
set { base.Font = value; }
}
[EditorBrowsable (EditorBrowsableState.Never)]
+ [Browsable (false)]
public override Color ForeColor {
get { return base.ForeColor; }
set {
}
[EditorBrowsable (EditorBrowsableState.Never)]
+ [Browsable (false)]
public new ImeMode ImeMode {
get { return base.ImeMode; }
set {
if (value < 0)
throw new Exception( string.Format("Value '{0}' must be greater than or equal to 0.", value));
- largeChange = value;
- Refresh ();
+ largeChange = value;
}
}
throw new Exception( string.Format("Value '{0}' must be greater than or equal to 0.", value));
if (smallChange != value) {
- smallChange = value;
- Refresh ();
+ smallChange = value;
}
}
}
[EditorBrowsable (EditorBrowsableState.Never)]
[Bindable (false)]
+ [Browsable (false)]
public override string Text {
get { return base.Text; }
set {
}
[DefaultValue (0)]
- [Bindable (false)]
+ [Bindable (true)]
public int Value {
get { return position; }
set {
if (ValueChanged != null)
ValueChanged (this, new EventArgs ());
- Refresh ();
+ Invalidate (thumb_area);
}
}
}
protected override bool IsInputKey (Keys keyData)
{
- return false;
+ return base.IsInputKey (keyData);
}
protected override void OnBackColorChanged (EventArgs e)
{
-
+ base.OnBackColorChanged (e);
}
protected override void OnHandleCreated (EventArgs e)
- {
+ {
+ base.OnHandleCreated (e);
+
if (AutoSize)
if (Orientation == Orientation.Horizontal)
Size = new Size (Width, 40);
else
Size = new Size (50, Height);
-
- UpdateArea ();
- CreateBuffers (Width, Height);
+
UpdatePos (Value, true);
}
[EditorBrowsable (EditorBrowsableState.Advanced)]
protected override void OnMouseWheel (MouseEventArgs e)
{
+ base.OnMouseWheel (e);
+
if (!Enabled) return;
if (e.Delta > 0)
SmallDecrement ();
else
- SmallIncrement ();
-
- base.OnMouseWheel (e);
-
+ SmallIncrement ();
}
protected virtual void OnScroll (EventArgs e)
public void SetRange (int minValue, int maxValue)
{
Minimum = minValue;
- Maximum = maxValue;
-
- Refresh ();
+ Maximum = maxValue;
}
public override string ToString()
#endregion Public Methods
#region Private Methods
-
- private void UpdateArea ()
- {
- paint_area.X = paint_area.Y = 0;
- paint_area.Width = Width;
- paint_area.Height = Height;
- }
-
+
private void UpdatePos (int newPos, bool update_trumbpos)
{
- int old = position;
-
- if (newPos < minimum)
+ if (newPos < minimum){
Value = minimum;
- else
- if (newPos > maximum)
- Value = maximum;
- else
- Value = newPos;
+ }
+ else {
+ if (newPos > maximum) {
+ Value = maximum;
+ }
+ else {
+ Value = newPos;
+ }
+ }
}
private void LargeIncrement ()
{
UpdatePos (position + LargeChange, true);
- Refresh ();
+ Invalidate (thumb_area);
OnScroll (new EventArgs ());
}
private void LargeDecrement ()
{
UpdatePos (position - LargeChange, true);
- Refresh ();
+ Invalidate (thumb_area);
OnScroll (new EventArgs ());
}
private void SmallIncrement ()
{
UpdatePos (position + SmallChange, true);
- Refresh ();
+ Invalidate (thumb_area);
OnScroll (new EventArgs ());
}
private void SmallDecrement ()
{
UpdatePos (position - SmallChange, true);
- Refresh ();
+ Invalidate (thumb_area);
OnScroll (new EventArgs ());
}
- private void Draw ()
- {
- float ticks = (Maximum - Minimum) / tickFrequency; /* N of ticks draw*/
-
- ThemeEngine.Current.DrawTrackBar(DeviceContext, this.ClientRectangle, this);
- }
-
private void OnMouseUpTB (object sender, MouseEventArgs e)
{
if (!Enabled) return;
thumb_pressed = false;
holdclick_timer.Enabled = false;
this.Capture = false;
- Refresh ();
+ Invalidate (thumb_area);
}
}
this.Capture = true;
thumb_pressed = true;
thumb_mouseclick = e.X;
- Refresh ();
+ Invalidate (thumb_area);
}
else {
- if (paint_area.Contains (point)) {
+ if (ClientRectangle.Contains (point)) {
if (e.X > thumb_pos.X + thumb_pos.Width)
LargeIncrement ();
else
LargeDecrement ();
- Refresh ();
+ Invalidate (thumb_area);
fire_timer = true;
mouse_clickmove = true;
}
this.Capture = true;
thumb_pressed = true;
thumb_mouseclick = e.Y;
- Refresh ();
+ Invalidate (thumb_area);
}
else {
- if (paint_area.Contains (point)) {
+ if (ClientRectangle.Contains (point)) {
if (e.Y > thumb_pos.Y + thumb_pos.Height)
LargeIncrement ();
else
LargeDecrement ();
- Refresh ();
+ Invalidate (thumb_area);
fire_timer = true;
mouse_clickmove = true;
}
{
if (!Enabled) return;
- Point pnt = new Point (e.X, e.Y);
-
/* Moving the thumb */
if (thumb_pressed) {
if (orientation == Orientation.Horizontal){
- if (paint_area.Contains (e.X, thumb_pos.Y))
+ if (ClientRectangle.Contains (e.X, thumb_pos.Y))
thumb_mouseclick = e.X;
}
else {
- if (paint_area.Contains (thumb_pos.X, e.Y))
+ if (ClientRectangle.Contains (thumb_pos.X, e.Y))
thumb_mouseclick = e.Y;
}
- Refresh ();
+ Invalidate (thumb_area);
OnScroll (new EventArgs ());
}
}
- private void OnResizeTB (object sender, System.EventArgs e)
- {
- if (Width <= 0 || Height <= 0)
- return;
-
- UpdateArea ();
- CreateBuffers (Width, Height);
- }
-
private void OnPaintTB (PaintEventArgs pevent)
{
- if (Width <= 0 || Height <= 0 || Visible == false)
- return;
-
- /* Copies memory drawing buffer to screen*/
- UpdateArea ();
- Draw ();
- pevent.Graphics.DrawImage (ImageBuffer, 0, 0);
- }
+ if (Paint != null) {
+ Paint (this, pevent);
+ }
+ ThemeEngine.Current.DrawTrackBar (pevent.Graphics, pevent.ClipRectangle, this);
+ }
private void OnKeyDownTB (KeyEventArgs e) \r
{
- switch (e.KeyCode) { \r
- case Keys.Up:
+ switch (e.KeyCode) {
+
+ case Keys.Down:
case Keys.Right:
SmallIncrement ();
break;
-
- case Keys.Down:
+
+ case Keys.Up:
case Keys.Left:
SmallDecrement ();
break;
+
+ case Keys.PageUp:
+ LargeDecrement ();
+ break;
+
+ case Keys.PageDown:
+ LargeIncrement ();
+ break;
+
+ case Keys.Home:
+ Value = Minimum;
+ break;
+
+ case Keys.End:
+ Value = Maximum;
+ break;
default:
break;
LargeDecrement ();
}
- Refresh ();
+ Invalidate (thumb_area);
\r
} \r
}