/* * UpDownBase.cs - Implementation of the * "System.Windows.Forms.UpDownBase" class. * * Copyright (C) 2003 Southern Storm Software, Pty Ltd. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ namespace System.Windows.Forms { using System; using System.Drawing; // FIXME: quick hack to allow handling of up and down keys internal class UpDownTextBox : TextBox { protected override bool ProcessDialogKey(Keys keyData) { if ((keyData & Keys.KeyCode) == Keys.Up || (keyData & Keys.KeyCode) == Keys.Down) return false; return base.ProcessDialogKey(keyData); } } // TODO: not all methods / properties / events implemeted at the moment // TODO: almost no checks public abstract class UpDownBase : ContainerControl { protected bool interceptArrowKeys; private LeftRightAlignment upDownAlign; internal UpDownTextBox textBox = new UpDownTextBox(); internal VScrollBar upDown = new VScrollBar(); public UpDownBase() { textBox.KeyDown += new KeyEventHandler(OnTextBoxKeyDown); textBox.MouseWheel += new MouseEventHandler(OnTextBoxMouseWheel); upDown.Height = textBox.Height; upDown.Scroll += new ScrollEventHandler(OnUpDownScroll); UpDownAlign = LeftRightAlignment.Right; Controls.Add(textBox); Controls.Add(upDown); InterceptArrowKeys = true; UpdateEditText(); } protected override Size DefaultSize { get { return new Size(textBox.Width + upDown.Width, textBox.Height); } } // TODO: not implemented protected bool ChangingText { get { throw new NotImplementedException(); } set { } } // TODO: not implmented protected bool UserEdit { get { throw new NotImplementedException(); } set { } } public override String Text { get { return textBox.Text; } set { textBox.Text = value; } } public HorizontalAlignment TextAlign { get { return textBox.TextAlign; } set { textBox.TextAlign = value; } } public LeftRightAlignment UpDownAlign { get { return upDownAlign; } set { // TODO: check if value is valid if (upDownAlign == value) return; upDownAlign = value; SetControlsPositions(); } } public bool InterceptArrowKeys { get { return interceptArrowKeys; } set { interceptArrowKeys = value; } } public override Color BackColor { get { return textBox.BackColor; } set { textBox.BackColor = value; } } public bool ReadOnly { get { return textBox.ReadOnly; } set { textBox.ReadOnly = value; } } public abstract void UpButton(); public abstract void DownButton(); protected virtual void OnTextBoxKeyDown(Object source, KeyEventArgs e) { if (interceptArrowKeys) { switch (e.KeyData) { case Keys.Up: UpButton(); e.Handled = true; break; case Keys.Down: DownButton(); e.Handled = true; break; } } OnKeyDown(e); } // TODO: not implemented, seems mouse wheel is not working at all at the moment protected virtual void OnTextBoxMouseWheel(Object source, MouseEventArgs e) { } protected virtual void OnUpDownScroll(Object source, ScrollEventArgs e) { if (e.Type == ScrollEventType.SmallIncrement) DownButton(); else if (e.Type == ScrollEventType.SmallDecrement) UpButton(); } public override String ToString() { return Text; } public void Select(int start, int length) { textBox.Select(start, length); } protected abstract void UpdateEditText(); protected override void OnResize(EventArgs e) { base.OnResize(e); textBox.Width = Width - upDown.Width; SetControlsPositions(); } private void SetControlsPositions() { if (upDownAlign == LeftRightAlignment.Left) { upDown.Left = 0; textBox.Left = upDown.Width; } else { textBox.Left = 0; upDown.Left = textBox.Width; } } } }