2 // System.Windows.Forms.DomainUpDown
5 // stubbed out by Richard Baumann (biochem333@nyc.rr.com)
6 // Dennis Hayes (dennish@Raytek.com)
7 // implemented by Aleksey Ryabchuk (ryabchuk@yahoo.com)
8 // (C) Ximian, Inc., 2002
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 using System.Collections;
32 using System.ComponentModel;
33 using System.Globalization;
35 namespace System.Windows.Forms {
38 // Represents a Windows up-down control that displays string values.
40 public class DomainUpDown : UpDownBase {
43 DomainUpDownItemCollection items;
49 public DomainUpDown() : base()
54 TextChanged += new EventHandler ( this.BuddyTextChanged );
58 public override void DownButton()
60 int newIndex = SelectedIndex + 1;
61 if ( newIndex < Items.Count )
62 SelectedIndex = newIndex;
63 else if ( Wrap && Items.Count > 0)
68 public override string ToString()
70 return GetType( ).FullName.ToString( ) + ", Items.Count: " + Items.Count.ToString ( ) +
71 ", SelectedIndex: " + SelectedIndex;
74 public override void UpButton()
76 int newIndex = SelectedIndex - 1;
77 if ( newIndex > -1 && newIndex < Items.Count )
78 SelectedIndex = newIndex;
79 else if ( Wrap && Items.Count > 0 )
80 SelectedIndex = Items.Count - 1;
84 protected override AccessibleObject CreateAccessibilityInstance()
87 return base.CreateAccessibilityInstance();
90 protected void OnSelectedItemChanged(object source, EventArgs e)
92 if (SelectedItemChanged != null)
93 SelectedItemChanged(this, e);
97 protected override void OnChanged(object source, EventArgs e) {
98 base.OnChanged(source, e);
102 protected override void OnTextBoxKeyDown(object source, KeyEventArgs e)
105 char symbol = System.Convert.ToChar( (int)e.KeyCode );
107 if ( Char.IsLetterOrDigit ( symbol ) ) {
108 string lower = Char.ToLower ( symbol ).ToString ( );
109 string upper = Char.ToUpper ( symbol ).ToString ( );
111 foreach ( object item in Items ) {
112 string sitem = item.ToString ( );
113 if ( sitem.StartsWith ( upper ) || sitem.StartsWith ( lower ) ) {
121 base.OnTextBoxKeyDown ( source, e );
124 protected override void UpdateEditText ( )
126 if ( SelectedIndex != -1 )
127 Text = Items [ SelectedIndex ].ToString ( );
132 public event EventHandler SelectedItemChanged;
134 public DomainUpDown.DomainUpDownItemCollection Items {
137 items = new DomainUpDownItemCollection ( this );
143 public int SelectedIndex {
144 get { return selectedIndex; }
146 if ( value < -1 || value >= Items.Count )
147 throw new ArgumentException ( ); // FIXME: message
149 if ( selectedIndex != value ) {
150 selectedIndex = value;
157 public object SelectedItem {
159 if ( SelectedIndex == -1 )
161 return Items[ SelectedIndex ];
164 SelectedIndex = Items.IndexOf ( value );
170 get { return sorted; }
172 if ( sorted != value ) {
173 object selectedItem = SelectedItem;
175 SelectedItem = selectedItem;
182 set { wrap = value; }
185 private void itemAdded ( object item )
189 private void itemInserted ( int index, object item )
193 private void itemRemoved ( object item )
197 private void itemRemoved ( int index )
201 private void itemChanged ( int index )
203 if ( index == SelectedIndex )
207 private void BuddyTextChanged ( object sender, EventArgs e )
209 OnSelectedItemChanged ( this, EventArgs.Empty );
212 //System.Windows.Forms.DomainUpDown.DomainUpDownItemCollection
215 //stubbed out by Richard Baumann (biochem333@nyc.rr.com)
217 //(C) Ximian, Inc., 2002
220 //Encapsulates a collection of objects for use by the DomainUpDown class.
222 public class DomainUpDownItemCollection : ArrayList {
226 internal DomainUpDownItemCollection( DomainUpDown owner )
231 public override int Add( object value )
233 int index = base.Add ( value );
234 owner.itemAdded ( value );
238 public override void Insert( int index, object value )
240 base.Insert ( index, value );
241 owner.itemInserted ( index, value );
244 public override void Remove( object obj )
247 owner.itemRemoved ( obj );
250 public override void RemoveAt( int index )
252 base.RemoveAt ( index );
253 owner.itemRemoved ( index );
256 public override object this[ int index ]
263 owner.itemChanged ( index );