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-2006 Novell, Inc.
23 // Jordi Mas i Hernandez, jordi@ximian.com
24 // Mike Kestner <mkestner@novell.com>
25 // Daniel Nauck (dna(at)mono-project(dot)de)
29 using System.Collections;
30 using System.ComponentModel;
31 using System.Reflection;
32 using System.ComponentModel.Design;
33 using System.ComponentModel.Design.Serialization;
34 using System.Runtime.InteropServices;
37 namespace System.Windows.Forms
39 [DefaultProperty("Items")]
40 [DefaultEvent("SelectedIndexChanged")]
41 [Designer ("System.Windows.Forms.Design.ComboBoxDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
43 [DefaultBindingProperty ("Text")]
44 [ClassInterface (ClassInterfaceType.AutoDispatch)]
47 public class ComboBox : ListControl
49 private DrawMode draw_mode = DrawMode.Normal;
50 private ComboBoxStyle dropdown_style = (ComboBoxStyle)(-1);
51 private int dropdown_width = -1;
52 private int selected_index = -1;
53 internal ObjectCollection items = null;
54 private bool suspend_ctrlupdate;
55 private int maxdrop_items = 8;
56 private bool integral_height = true;
58 private int max_length;
59 private ComboListBox listbox_ctrl;
60 private ComboTextBox textbox_ctrl;
61 private bool process_textchanged_event = true;
62 private bool item_height_specified = false;
63 private int item_height;
64 private int requested_height = -1;
65 private Hashtable item_heights;
66 private bool show_dropdown_button = false;
67 private ButtonState button_state = ButtonState.Normal;
68 private bool dropped_down;
69 private Rectangle text_area;
70 private Rectangle button_area;
71 private Rectangle listbox_area;
72 private const int button_width = 16;
74 private AutoCompleteStringCollection auto_complete_custom_source = null;
75 private AutoCompleteMode auto_complete_mode = AutoCompleteMode.None;
76 private AutoCompleteSource auto_complete_source = AutoCompleteSource.None;
80 public class ChildAccessibleObject : AccessibleObject {
82 public ChildAccessibleObject (ComboBox owner, IntPtr handle)
87 public override string Name {
96 items = new ObjectCollection (this);
97 DropDownStyle = ComboBoxStyle.DropDown;
98 item_height = FontHeight + 2;
99 BackColor = ThemeEngine.Current.ColorWindow;
100 border_style = BorderStyle.None;
103 MouseDown += new MouseEventHandler (OnMouseDownCB);
104 MouseUp += new MouseEventHandler (OnMouseUpCB);
105 MouseMove += new MouseEventHandler (OnMouseMoveCB);
106 MouseWheel += new MouseEventHandler (OnMouseWheelCB);
107 KeyDown +=new KeyEventHandler(OnKeyDownCB);
113 [EditorBrowsable (EditorBrowsableState.Never)]
114 public new event EventHandler BackgroundImageChanged {
115 add { base.BackgroundImageChanged += value; }
116 remove { base.BackgroundImageChanged -= value; }
119 static object DrawItemEvent = new object ();
120 static object DropDownEvent = new object ();
121 static object DropDownStyleChangedEvent = new object ();
122 static object MeasureItemEvent = new object ();
123 static object SelectedIndexChangedEvent = new object ();
124 static object SelectionChangeCommittedEvent = new object ();
126 public event DrawItemEventHandler DrawItem {
127 add { Events.AddHandler (DrawItemEvent, value); }
128 remove { Events.RemoveHandler (DrawItemEvent, value); }
131 public event EventHandler DropDown {
132 add { Events.AddHandler (DropDownEvent, value); }
133 remove { Events.RemoveHandler (DropDownEvent, value); }
136 public event EventHandler DropDownStyleChanged {
137 add { Events.AddHandler (DropDownStyleChangedEvent, value); }
138 remove { Events.RemoveHandler (DropDownStyleChangedEvent, value); }
141 public event MeasureItemEventHandler MeasureItem {
142 add { Events.AddHandler (MeasureItemEvent, value); }
143 remove { Events.RemoveHandler (MeasureItemEvent, value); }
147 [EditorBrowsable (EditorBrowsableState.Never)]
148 public new event PaintEventHandler Paint {
149 add { base.Paint += value; }
150 remove { base.Paint -= value; }
153 public event EventHandler SelectedIndexChanged {
154 add { Events.AddHandler (SelectedIndexChangedEvent, value); }
155 remove { Events.RemoveHandler (SelectedIndexChangedEvent, value); }
158 public event EventHandler SelectionChangeCommitted {
159 add { Events.AddHandler (SelectionChangeCommittedEvent, value); }
160 remove { Events.RemoveHandler (SelectionChangeCommittedEvent, value); }
165 #region Public Properties
167 [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
168 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
170 [EditorBrowsable (EditorBrowsableState.Always)]
172 [Editor ("System.Windows.Forms.Design.ListControlStringCollectionEditor, " + Consts.AssemblySystem_Design,
173 "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
174 public AutoCompleteStringCollection AutoCompleteCustomSource {
176 if(auto_complete_custom_source == null) {
177 auto_complete_custom_source = new AutoCompleteStringCollection ();
178 auto_complete_custom_source.CollectionChanged += new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
180 return auto_complete_custom_source;
183 if(auto_complete_custom_source == value)
186 if(auto_complete_custom_source != null) //remove eventhandler from old collection
187 auto_complete_custom_source.CollectionChanged -= new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
189 auto_complete_custom_source = value;
191 if(auto_complete_custom_source != null)
192 auto_complete_custom_source.CollectionChanged += new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
196 [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
198 [EditorBrowsable (EditorBrowsableState.Always)]
199 [DefaultValue (AutoCompleteMode.None)]
200 public AutoCompleteMode AutoCompleteMode {
201 get { return auto_complete_mode; }
203 if(auto_complete_mode == value)
206 if((value < AutoCompleteMode.None) || (value > AutoCompleteMode.SuggestAppend))
207 throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for AutoCompleteMode", value));
209 auto_complete_mode = value;
213 [MonoTODO("AutoCompletion algorithm is currently not implemented.")]
215 [EditorBrowsable (EditorBrowsableState.Always)]
216 [DefaultValue (AutoCompleteSource.None)]
217 public AutoCompleteSource AutoCompleteSource {
218 get { return auto_complete_source; }
220 if(auto_complete_source == value)
223 if(!Enum.IsDefined (typeof (AutoCompleteSource), value))
224 throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for AutoCompleteSource", value));
226 auto_complete_source = value;
230 public override Color BackColor {
231 get { return base.BackColor; }
233 if (base.BackColor == value)
236 base.BackColor = value;
242 [EditorBrowsable (EditorBrowsableState.Never)]
243 public override Image BackgroundImage {
244 get { return base.BackgroundImage; }
246 if (base.BackgroundImage == value)
249 base.BackgroundImage = value;
254 protected override CreateParams CreateParams {
255 get { return base.CreateParams;}
258 protected override Size DefaultSize {
259 get { return new Size (121, 21); }
262 [RefreshProperties(RefreshProperties.Repaint)]
263 [DefaultValue (DrawMode.Normal)]
264 public DrawMode DrawMode {
265 get { return draw_mode; }
268 if (!Enum.IsDefined (typeof (DrawMode), value))
269 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for DrawMode", value));
271 if (draw_mode == value)
274 if (draw_mode == DrawMode.OwnerDrawVariable)
277 if (draw_mode == DrawMode.OwnerDrawVariable)
278 item_heights = new Hashtable ();
283 [DefaultValue (ComboBoxStyle.DropDown)]
284 [RefreshProperties(RefreshProperties.Repaint)]
285 public ComboBoxStyle DropDownStyle {
286 get { return dropdown_style; }
290 if (!Enum.IsDefined (typeof (ComboBoxStyle), value))
291 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for ComboBoxStyle", value));
293 if (dropdown_style == value)
298 if (dropdown_style == ComboBoxStyle.Simple) {
299 if (listbox_ctrl != null) {
300 Controls.RemoveImplicit (listbox_ctrl);
301 listbox_ctrl.Dispose ();
306 dropdown_style = value;
308 if (dropdown_style == ComboBoxStyle.DropDownList && textbox_ctrl != null) {
309 Controls.RemoveImplicit (textbox_ctrl);
310 textbox_ctrl.Dispose ();
314 if (dropdown_style == ComboBoxStyle.Simple) {
315 show_dropdown_button = false;
317 CreateComboListBox ();
319 if (IsHandleCreated) {
320 Controls.AddImplicit (listbox_ctrl);
321 listbox_ctrl.Visible = true;
324 show_dropdown_button = true;
325 button_state = ButtonState.Normal;
328 if (dropdown_style != ComboBoxStyle.DropDownList && textbox_ctrl == null) {
329 textbox_ctrl = new ComboTextBox (this);
330 object selected_item = SelectedItem;
331 if (selected_item != null)
332 textbox_ctrl.Text = GetItemText (selected_item);
333 textbox_ctrl.BorderStyle = BorderStyle.None;
334 textbox_ctrl.TextChanged += new EventHandler (OnTextChangedEdit);
335 textbox_ctrl.Click += new EventHandler (OnTextBoxClick);
337 if (IsHandleCreated == true) {
338 Controls.AddImplicit (textbox_ctrl);
343 OnDropDownStyleChanged (EventArgs.Empty);
346 UpdateComboBoxBounds ();
351 public int DropDownWidth {
353 if (dropdown_width == -1)
356 return dropdown_width;
359 if (dropdown_width == value)
364 throw new ArgumentOutOfRangeException ("DropDownWidth",
365 "The DropDownWidth value is less than one.");
367 throw new ArgumentException ("The DropDownWidth value is less than one.");
370 dropdown_width = value;
375 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
376 public bool DroppedDown {
378 if (dropdown_style == ComboBoxStyle.Simple)
384 if (dropdown_style == ComboBoxStyle.Simple || dropped_down == value)
390 listbox_ctrl.Hide ();
394 public override bool Focused {
395 get { return base.Focused; }
398 public override Color ForeColor {
399 get { return base.ForeColor; }
401 if (base.ForeColor == value)
404 base.ForeColor = value;
409 [DefaultValue (true)]
411 public bool IntegralHeight {
412 get { return integral_height; }
414 if (integral_height == value)
417 integral_height = value;
418 UpdateComboBoxBounds ();
424 public int ItemHeight {
426 if (item_height == -1) {
427 SizeF sz = DeviceContext.MeasureString ("The quick brown Fox", Font);
428 item_height = (int) sz.Height;
435 throw new ArgumentOutOfRangeException ("ItemHeight",
436 "The item height value is less than one.");
438 throw new ArgumentException ("The item height value is less than one.");
441 item_height_specified = true;
444 UpdateComboBoxBounds ();
450 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
452 [Editor ("System.Windows.Forms.Design.ListControlStringCollectionEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
454 [MergableProperty (false)]
456 public ComboBox.ObjectCollection Items {
457 get { return items; }
462 public int MaxDropDownItems {
463 get { return maxdrop_items; }
465 if (maxdrop_items == value)
468 maxdrop_items = value;
474 public int MaxLength {
475 get { return max_length; }
477 if (max_length == value)
482 if (dropdown_style != ComboBoxStyle.DropDownList) {
488 textbox_ctrl.MaxLength = value;
493 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
495 public int PreferredHeight {
497 return ItemHeight + 5;
502 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
503 public override int SelectedIndex {
504 get { return selected_index; }
506 if (selected_index == value)
509 if (value <= -2 || value >= Items.Count)
510 throw new ArgumentOutOfRangeException ("Index of out range");
511 selected_index = value;
513 if (dropdown_style != ComboBoxStyle.DropDownList) {
517 SetControlText (GetItemText (Items [value]));
520 if (DropDownStyle == ComboBoxStyle.DropDownList)
523 if (listbox_ctrl != null)
524 listbox_ctrl.HighlightedIndex = value;
526 OnSelectedValueChanged (new EventArgs ());
527 OnSelectedIndexChanged (new EventArgs ());
528 OnSelectedItemChanged (new EventArgs ());
533 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
535 public object SelectedItem {
536 get { return selected_index == -1 ? null : Items [selected_index]; }
538 object item = selected_index == -1 ? null : Items [selected_index];
542 SelectedIndex = Items.IndexOf (value);
547 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
548 public string SelectedText {
550 if (dropdown_style == ComboBoxStyle.DropDownList)
553 return textbox_ctrl.SelectedText;
556 if (dropdown_style == ComboBoxStyle.DropDownList)
559 textbox_ctrl.SelectedText = value;
564 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
565 public int SelectionLength {
567 if (dropdown_style == ComboBoxStyle.DropDownList)
570 int result = textbox_ctrl.SelectionLength;
571 return result == -1 ? 0 : result;
574 if (dropdown_style == ComboBoxStyle.DropDownList)
577 if (textbox_ctrl.SelectionLength == value)
580 textbox_ctrl.SelectionLength = value;
585 [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
586 public int SelectionStart {
588 if (dropdown_style == ComboBoxStyle.DropDownList)
591 return textbox_ctrl.SelectionStart;
594 if (dropdown_style == ComboBoxStyle.DropDownList)
597 if (textbox_ctrl.SelectionStart == value)
600 textbox_ctrl.SelectionStart = value;
604 [DefaultValue (false)]
606 get { return sorted; }
623 public override string Text {
625 if (dropdown_style != ComboBoxStyle.DropDownList) {
626 if (textbox_ctrl != null) {
627 return textbox_ctrl.Text;
631 if (SelectedItem != null)
632 return GetItemText (SelectedItem);
642 int index = FindString (value);
645 SelectedIndex = index;
649 if (dropdown_style != ComboBoxStyle.DropDownList)
650 textbox_ctrl.Text = GetItemText (value);
654 #endregion Public Properties
656 #region Public Methods
658 [Obsolete ("This method has been deprecated")]
660 protected virtual void AddItemsCore (object[] value)
665 public void BeginUpdate ()
667 suspend_ctrlupdate = true;
670 protected override void Dispose (bool disposing)
673 if (listbox_ctrl != null) {
674 listbox_ctrl.Dispose ();
675 Controls.RemoveImplicit (listbox_ctrl);
679 if (textbox_ctrl != null) {
680 Controls.RemoveImplicit (textbox_ctrl);
681 textbox_ctrl.Dispose ();
686 base.Dispose (disposing);
689 public void EndUpdate ()
691 suspend_ctrlupdate = false;
696 public int FindString (string s)
698 return FindString (s, -1);
701 public int FindString (string s, int startIndex)
703 if (Items.Count == 0)
704 return -1; // No exception throwing if empty
706 if (startIndex < -1 || startIndex >= Items.Count - 1)
707 throw new ArgumentOutOfRangeException ("Index of out range");
710 for (int i = startIndex; i < Items.Count; i++) {
711 if ((GetItemText (Items[i])).StartsWith (s))
718 public int FindStringExact (string s)
720 return FindStringExact (s, -1);
723 public int FindStringExact (string s, int startIndex)
725 if (Items.Count == 0)
726 return -1; // No exception throwing if empty
728 if (startIndex < -1 || startIndex >= Items.Count - 1)
729 throw new ArgumentOutOfRangeException ("Index of out range");
732 for (int i = startIndex; i < Items.Count; i++) {
733 if ((GetItemText (Items[i])).Equals (s))
740 public int GetItemHeight (int index)
742 if (DrawMode == DrawMode.OwnerDrawVariable && IsHandleCreated) {
744 if (index < 0 || index >= Items.Count )
745 throw new ArgumentOutOfRangeException ("The item height value is less than zero");
747 object item = Items [index];
748 if (item_heights.Contains (item))
749 return (int) item_heights [item];
751 MeasureItemEventArgs args = new MeasureItemEventArgs (DeviceContext, index, ItemHeight);
752 OnMeasureItem (args);
753 item_heights [item] = args.ItemHeight;
754 return args.ItemHeight;
760 protected override bool IsInputKey (Keys keyData)
776 protected override void OnBackColorChanged (EventArgs e)
778 base.OnBackColorChanged (e);
781 protected override void OnDataSourceChanged (EventArgs e)
783 base.OnDataSourceChanged (e);
786 if (DataSource == null || DataManager == null) {
790 SelectedIndex = DataManager.Position;
794 protected override void OnDisplayMemberChanged (EventArgs e)
796 base.OnDisplayMemberChanged (e);
798 if (DataManager == null || !IsHandleCreated)
802 SelectedIndex = DataManager.Position;
805 protected virtual void OnDrawItem (DrawItemEventArgs e)
808 case DrawMode.OwnerDrawFixed:
809 case DrawMode.OwnerDrawVariable:
810 DrawItemEventHandler eh = (DrawItemEventHandler)(Events [DrawItemEvent]);
815 ThemeEngine.Current.DrawComboBoxItem (this, e);
820 protected virtual void OnDropDown (EventArgs e)
822 EventHandler eh = (EventHandler)(Events [DropDownEvent]);
827 protected virtual void OnDropDownStyleChanged (EventArgs e)
829 EventHandler eh = (EventHandler)(Events [DropDownStyleChangedEvent]);
834 protected override void OnFontChanged (EventArgs e)
836 base.OnFontChanged (e);
838 if (textbox_ctrl != null)
839 textbox_ctrl.Font = Font;
841 if (!item_height_specified) {
842 SizeF sz = DeviceContext.MeasureString ("The quick brown Fox", Font);
843 item_height = (int) sz.Height;
847 UpdateComboBoxBounds ();
852 protected override void OnForeColorChanged (EventArgs e)
854 base.OnForeColorChanged (e);
857 [EditorBrowsable(EditorBrowsableState.Advanced)]
858 protected override void OnGotFocus (EventArgs e)
860 if (dropdown_style == ComboBoxStyle.DropDownList) {
861 // We draw DDL styles manually, so they require a
862 // refresh to have their selection drawn
866 if (textbox_ctrl != null) {
867 textbox_ctrl.SetSelectable (false);
868 textbox_ctrl.ActivateCaret (true);
869 textbox_ctrl.ShowSelection = true;
870 textbox_ctrl.SelectAll ();
876 [EditorBrowsable(EditorBrowsableState.Advanced)]
877 protected override void OnLostFocus (EventArgs e)
879 if (dropdown_style == ComboBoxStyle.DropDownList) {
880 // We draw DDL styles manually, so they require a
881 // refresh to have their selection drawn
885 if (listbox_ctrl != null && dropped_down) {
886 listbox_ctrl.HideWindow ();
889 if (textbox_ctrl != null) {
890 textbox_ctrl.SetSelectable (true);
891 textbox_ctrl.ActivateCaret (false);
892 textbox_ctrl.ShowSelection = false;
895 base.OnLostFocus (e);
898 protected override void OnHandleCreated (EventArgs e)
900 base.OnHandleCreated (e);
902 if (listbox_ctrl != null) {
903 Controls.AddImplicit (listbox_ctrl);
904 listbox_ctrl.Visible = true;
907 if (textbox_ctrl != null)
908 Controls.AddImplicit (textbox_ctrl);
913 protected override void OnHandleDestroyed (EventArgs e)
915 base.OnHandleDestroyed (e);
918 protected override void OnKeyPress (KeyPressEventArgs e)
920 // int index = FindStringCaseInsensitive (e.KeyChar.ToString (), SelectedIndex);
922 // SelectedIndex = index;
927 protected virtual void OnMeasureItem (MeasureItemEventArgs e)
929 MeasureItemEventHandler eh = (MeasureItemEventHandler)(Events [MeasureItemEvent]);
934 protected override void OnParentBackColorChanged (EventArgs e)
936 base.OnParentBackColorChanged (e);
939 protected override void OnResize (EventArgs e)
942 if (listbox_ctrl != null)
943 listbox_ctrl.CalcListBoxArea ();
946 protected override void OnSelectedIndexChanged (EventArgs e)
948 base.OnSelectedIndexChanged (e);
950 EventHandler eh = (EventHandler)(Events [SelectedIndexChangedEvent]);
955 protected virtual void OnSelectedItemChanged (EventArgs e)
960 protected override void OnSelectedValueChanged (EventArgs e)
962 base.OnSelectedValueChanged (e);
965 protected virtual void OnSelectionChangeCommitted (EventArgs e)
967 EventHandler eh = (EventHandler)(Events [SelectionChangeCommittedEvent]);
972 protected override void RefreshItem (int index)
974 if (index < 0 || index >= Items.Count)
975 throw new ArgumentOutOfRangeException ("Index of out range");
977 if (draw_mode == DrawMode.OwnerDrawVariable)
978 item_heights.Remove (Items [index]);
982 protected override bool ProcessKeyEventArgs (ref Message m)
984 return base.ProcessKeyEventArgs (ref m);
987 [EditorBrowsable (EditorBrowsableState.Advanced)]
988 protected override void OnKeyDown (KeyEventArgs e)
993 [EditorBrowsable (EditorBrowsableState.Advanced)]
994 protected override void OnValidating (CancelEventArgs e)
996 base.OnValidating (e);
999 [EditorBrowsable (EditorBrowsableState.Advanced)]
1000 protected override void OnTextChanged (EventArgs e)
1002 base.OnTextChanged (e);
1005 protected override void OnMouseLeave (EventArgs e)
1007 base.OnMouseLeave (e);
1010 protected override void OnMouseEnter (EventArgs e)
1012 base.OnMouseEnter (e);
1016 public void Select (int start, int length)
1019 throw new ArgumentException ("Start cannot be less than zero");
1022 throw new ArgumentException ("length cannot be less than zero");
1024 if (dropdown_style == ComboBoxStyle.DropDownList)
1027 textbox_ctrl.Select (start, length);
1030 public void SelectAll ()
1032 if (dropdown_style == ComboBoxStyle.DropDownList)
1035 if (textbox_ctrl != null) {
1036 textbox_ctrl.ShowSelection = true;
1037 textbox_ctrl.SelectAll ();
1041 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
1043 if ((specified & BoundsSpecified.Height) != 0) {
1044 requested_height = height;
1046 if (DropDownStyle == ComboBoxStyle.Simple && height > PreferredHeight) {
1047 if (IntegralHeight) {
1048 int border = ThemeEngine.Current.Border3DSize.Height;
1049 int lb_height = height - PreferredHeight - 2;
1050 if (lb_height - 2 * border > ItemHeight) {
1051 int partial = (lb_height - 2 * border) % ItemHeight;
1054 height = PreferredHeight;
1057 height = PreferredHeight;
1060 base.SetBoundsCore (x, y, width, height, specified);
1063 protected override void SetItemCore (int index, object value)
1065 if (index < 0 || index >= Items.Count)
1068 Items[index] = value;
1071 protected override void SetItemsCore (IList value)
1076 Items.AddRange (value);
1082 public override string ToString ()
1084 return base.ToString () + ", Items.Count:" + Items.Count;
1087 protected override void WndProc (ref Message m)
1089 switch ((Msg) m.Msg) {
1091 case Msg.WM_KEYDOWN:
1092 Keys keys = (Keys) m.WParam.ToInt32 ();
1093 if (keys == Keys.Up || keys == Keys.Down)
1095 goto case Msg.WM_CHAR;
1097 if (textbox_ctrl != null)
1098 XplatUI.SendMessage (textbox_ctrl.Handle, (Msg) m.Msg, m.WParam, m.LParam);
1100 case Msg.WM_MOUSE_LEAVE:
1101 Point location = PointToClient (Control.MousePosition);
1102 if (ClientRectangle.Contains (location))
1108 base.WndProc (ref m);
1111 #endregion Public Methods
1113 #region Private Methods
1115 void OnAutoCompleteCustomSourceChanged(object sender, CollectionChangeEventArgs e) {
1116 if(auto_complete_source == AutoCompleteSource.CustomSource) {
1117 //FIXME: handle add, remove and refresh events in AutoComplete algorithm.
1122 internal override bool InternalCapture {
1123 get { return Capture; }
1127 void LayoutComboBox ()
1129 int border = ThemeEngine.Current.Border3DSize.Width;
1131 text_area = ClientRectangle;
1132 text_area.Height = PreferredHeight;
1134 listbox_area = ClientRectangle;
1135 listbox_area.Y = text_area.Bottom + 3;
1136 listbox_area.Height -= (text_area.Height + 2);
1138 Rectangle prev_button_area = button_area;
1140 if (DropDownStyle == ComboBoxStyle.Simple)
1141 button_area = Rectangle.Empty;
1143 button_area = text_area;
1144 button_area.X = text_area.Right - button_width - border;
1145 button_area.Y = text_area.Y + border;
1146 button_area.Width = button_width;
1147 button_area.Height = text_area.Height - 2 * border;
1150 if (button_area != prev_button_area) {
1151 prev_button_area.Y -= border;
1152 prev_button_area.Width += border;
1153 prev_button_area.Height += 2 * border;
1154 Invalidate (prev_button_area);
1155 Invalidate (button_area);
1158 if (textbox_ctrl != null) {
1159 textbox_ctrl.Location = new Point (text_area.X + border, text_area.Y + border);
1160 textbox_ctrl.Width = text_area.Width - button_area.Width - border * 2;
1161 textbox_ctrl.Height = text_area.Height - border * 2;
1164 if (listbox_ctrl != null && dropdown_style == ComboBoxStyle.Simple) {
1165 listbox_ctrl.Location = listbox_area.Location;
1166 listbox_ctrl.CalcListBoxArea ();
1170 private void CreateComboListBox ()
1172 listbox_ctrl = new ComboListBox (this);
1173 listbox_ctrl.HighlightedIndex = SelectedIndex;
1176 internal void Draw (Rectangle clip, Graphics dc)
1178 Theme theme = ThemeEngine.Current;
1180 if (DropDownStyle == ComboBoxStyle.Simple)
1181 dc.FillRectangle (theme.ResPool.GetSolidBrush (Parent.BackColor), ClientRectangle);
1183 if (clip.IntersectsWith (text_area))
1184 ControlPaint.DrawBorder3D (dc, text_area, Border3DStyle.Sunken);
1186 int border = theme.Border3DSize.Width;
1188 // No edit control, we paint the edit ourselves
1189 if (dropdown_style == ComboBoxStyle.DropDownList) {
1190 DrawItemState state = DrawItemState.None;
1191 Rectangle item_rect = text_area;
1192 item_rect.X += border;
1193 item_rect.Y += border;
1194 item_rect.Width -= (button_area.Width + 2 * border);
1195 item_rect.Height -= 2 * border;
1198 state = DrawItemState.Selected;
1199 state |= DrawItemState.Focus;
1202 state |= DrawItemState.ComboBoxEdit;
1203 OnDrawItem (new DrawItemEventArgs (dc, Font, item_rect, SelectedIndex, state, ForeColor, BackColor));
1206 if (show_dropdown_button) {
1207 dc.FillRectangle (theme.ResPool.GetSolidBrush (theme.ColorControl), button_area);
1210 button_state = ButtonState.Inactive;
1212 theme.CPDrawComboButton (dc, button_area, button_state);
1216 internal void DropDownListBox ()
1218 if (DropDownStyle == ComboBoxStyle.Simple)
1221 if (listbox_ctrl == null)
1222 CreateComboListBox ();
1224 listbox_ctrl.Location = PointToScreen (new Point (text_area.X, text_area.Y + text_area.Height));
1226 if (listbox_ctrl.ShowWindow ())
1227 dropped_down = true;
1229 button_state = ButtonState.Pushed;
1230 if (dropdown_style == ComboBoxStyle.DropDownList)
1231 Invalidate (text_area);
1234 internal void DropDownListBoxFinished ()
1236 if (DropDownStyle == ComboBoxStyle.Simple)
1239 button_state = ButtonState.Normal;
1240 Invalidate (button_area);
1241 dropped_down = false;
1244 private int FindStringCaseInsensitive (string search)
1246 if (search.Length == 0) {
1250 for (int i = 0; i < Items.Count; i++)
1252 if (String.Compare (GetItemText (Items[i]), 0, search, 0, search.Length, true) == 0)
1259 internal int FindStringCaseInsensitive (string search, int start_index)
1261 if (search.Length == 0) {
1265 for (int i = 0; i < Items.Count; i++) {
1266 int index = (i + start_index) % Items.Count;
1267 if (String.Compare (GetItemText (Items [index]), 0, search, 0, search.Length, true) == 0)
1274 private void OnKeyDownCB(object sender, KeyEventArgs e)
1276 if (Items.Count == 0)
1282 SelectedIndex = Math.Max(SelectedIndex-1, 0);
1286 SelectedIndex = Math.Min(SelectedIndex+1, Items.Count-1);
1290 if (listbox_ctrl != null)
1291 SelectedIndex = Math.Max(SelectedIndex- (listbox_ctrl.page_size-1), 0);
1295 if (listbox_ctrl != null)
1296 SelectedIndex = Math.Min(SelectedIndex+(listbox_ctrl.page_size-1), Items.Count-1);
1304 void OnMouseDownCB (object sender, MouseEventArgs e)
1307 if (DropDownStyle == ComboBoxStyle.DropDownList)
1308 area = ClientRectangle;
1312 if (area.Contains (e.X, e.Y)) {
1314 Invalidate (button_area);
1320 void OnMouseMoveCB (object sender, MouseEventArgs e)
1322 if (DropDownStyle == ComboBoxStyle.Simple)
1325 if (listbox_ctrl != null && listbox_ctrl.Visible) {
1326 Point location = listbox_ctrl.PointToClient (Control.MousePosition);
1327 if (listbox_ctrl.ClientRectangle.Contains (location))
1328 listbox_ctrl.Capture = true;
1332 void OnMouseUpCB (object sender, MouseEventArgs e)
1335 OnClick (EventArgs.Empty);
1338 listbox_ctrl.Capture = true;
1341 private void OnMouseWheelCB (object sender, MouseEventArgs me)
1343 if (Items.Count == 0)
1346 if (listbox_ctrl != null && listbox_ctrl.Visible) {
1347 int lines = me.Delta / 120 * SystemInformation.MouseWheelScrollLines;
1348 listbox_ctrl.Scroll (-lines);
1350 int lines = me.Delta / 120;
1351 int index = SelectedIndex - lines;
1354 else if (index >= Items.Count)
1355 index = Items.Count - 1;
1356 SelectedIndex = index;
1360 internal override void OnPaintInternal (PaintEventArgs pevent)
1362 if (suspend_ctrlupdate)
1365 Draw (ClientRectangle, pevent.Graphics);
1368 private void OnTextBoxClick (object sender, EventArgs e)
1373 private void OnTextChangedEdit (object sender, EventArgs e)
1375 if (process_textchanged_event == false)
1378 OnTextChanged (EventArgs.Empty);
1380 int item = FindStringCaseInsensitive (textbox_ctrl.Text);
1385 // TODO: THIS IS BROKEN-ISH
1386 // I don't think we should hilight, and setting the top item does weirdness
1387 // when there is no scrollbar
1389 if (listbox_ctrl != null) {
1390 listbox_ctrl.SetTopItem (item);
1391 listbox_ctrl.HighlightedIndex = item;
1394 base.Text = textbox_ctrl.Text;
1397 internal void SetControlText (string s)
1399 process_textchanged_event = false;
1400 textbox_ctrl.Text = s;
1401 process_textchanged_event = true;
1404 void UpdateComboBoxBounds ()
1406 if (requested_height == -1)
1409 // Save the requested height since set bounds can destroy it
1410 int save_height = requested_height;
1411 SetBounds (0, 0, 0, requested_height, BoundsSpecified.Height);
1412 requested_height = save_height;
1415 private void UpdatedItems ()
1417 if (listbox_ctrl != null) {
1418 listbox_ctrl.UpdateLastVisibleItem ();
1419 listbox_ctrl.CalcListBoxArea ();
1420 listbox_ctrl.Refresh ();
1424 #endregion Private Methods
1426 [ListBindableAttribute (false)]
1427 public class ObjectCollection : IList, ICollection, IEnumerable
1430 private ComboBox owner;
1431 internal ArrayList object_items = new ArrayList ();
1433 public ObjectCollection (ComboBox owner)
1438 #region Public Properties
1440 get { return object_items.Count; }
1443 public bool IsReadOnly {
1444 get { return false; }
1448 [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
1449 public virtual object this [int index] {
1451 if (index < 0 || index >= Count)
1452 throw new ArgumentOutOfRangeException ("Index of out range");
1454 return object_items[index];
1457 if (index < 0 || index >= Count)
1458 throw new ArgumentOutOfRangeException ("Index of out range");
1460 throw new ArgumentNullException ("value");
1462 object_items[index] = value;
1463 if (owner.listbox_ctrl != null)
1464 owner.listbox_ctrl.InvalidateItem (index);
1465 if (index == owner.SelectedIndex) {
1466 if (owner.textbox_ctrl == null)
1469 owner.textbox_ctrl.SelectedText = value.ToString ();
1474 bool ICollection.IsSynchronized {
1475 get { return false; }
1478 object ICollection.SyncRoot {
1479 get { return this; }
1482 bool IList.IsFixedSize {
1483 get { return false; }
1486 #endregion Public Properties
1488 #region Public Methods
1489 public int Add (object item)
1493 idx = AddItem (item);
1494 owner.UpdatedItems ();
1498 public void AddRange (object[] items)
1501 throw new ArgumentNullException ("items");
1503 foreach (object mi in items)
1506 owner.UpdatedItems ();
1509 public void Clear ()
1511 owner.selected_index = -1;
1512 object_items.Clear ();
1513 owner.UpdatedItems ();
1517 public bool Contains (object obj)
1520 throw new ArgumentNullException ("obj");
1522 return object_items.Contains (obj);
1525 public void CopyTo (object[] dest, int arrayIndex)
1527 object_items.CopyTo (dest, arrayIndex);
1530 void ICollection.CopyTo (Array dest, int index)
1532 object_items.CopyTo (dest, index);
1535 public IEnumerator GetEnumerator ()
1537 return object_items.GetEnumerator ();
1540 int IList.Add (object item)
1545 public int IndexOf (object value)
1548 throw new ArgumentNullException ("value");
1550 return object_items.IndexOf (value);
1553 public void Insert (int index, object item)
1555 if (index < 0 || index > Count)
1556 throw new ArgumentOutOfRangeException ("Index of out range");
1558 throw new ArgumentNullException ("item");
1560 owner.BeginUpdate ();
1565 object_items.Insert (index, item);
1567 owner.EndUpdate (); // Calls UpdatedItems
1570 public void Remove (object value)
1575 if (IndexOf (value) == owner.SelectedIndex)
1576 owner.SelectedIndex = -1;
1578 RemoveAt (IndexOf (value));
1581 public void RemoveAt (int index)
1583 if (index < 0 || index >= Count)
1584 throw new ArgumentOutOfRangeException ("Index of out range");
1586 if (index == owner.SelectedIndex)
1587 owner.SelectedIndex = -1;
1589 object_items.RemoveAt (index);
1590 owner.UpdatedItems ();
1592 #endregion Public Methods
1594 #region Private Methods
1595 private int AddItem (object item)
1598 throw new ArgumentNullException ("item");
1602 foreach (object o in object_items) {
1603 if (String.Compare (item.ToString (), o.ToString ()) < 0) {
1604 object_items.Insert (index, item);
1610 object_items.Add (item);
1611 return object_items.Count - 1;
1614 internal void AddRange (IList items)
1616 foreach (object mi in items)
1619 owner.UpdatedItems ();
1622 internal void Sort ()
1624 object_items.Sort ();
1627 #endregion Private Methods
1630 internal class ComboTextBox : TextBox {
1632 private ComboBox owner;
1634 public ComboTextBox (ComboBox owner)
1637 ShowSelection = false;
1640 internal void SetSelectable (bool selectable)
1642 SetStyle (ControlStyles.Selectable, selectable);
1645 internal void ActivateCaret (bool active)
1648 document.CaretHasFocus ();
1650 document.CaretLostFocus ();
1653 internal override void OnGotFocusInternal (EventArgs e)
1655 owner.Select (false, true);
1658 internal override void OnLostFocusInternal (EventArgs e)
1660 owner.Select (false, true);
1664 internal class ComboListBox : Control
1666 private ComboBox owner;
1667 private VScrollBarLB vscrollbar_ctrl;
1668 private int top_item; /* First item that we show the in the current page */
1669 private int last_item; /* Last visible item */
1670 internal int page_size; /* Number of listbox items per page */
1671 private Rectangle textarea_drawable; /* Rectangle of the drawable text area */
1673 internal enum ItemNavigation
1683 class VScrollBarLB : VScrollBar
1685 public VScrollBarLB ()
1689 internal override bool InternalCapture {
1690 get { return Capture; }
1694 public void FireMouseDown (MouseEventArgs e)
1699 e = TranslateEvent (e);
1703 public void FireMouseUp (MouseEventArgs e)
1708 e = TranslateEvent (e);
1712 public void FireMouseMove (MouseEventArgs e)
1717 e = TranslateEvent (e);
1721 MouseEventArgs TranslateEvent (MouseEventArgs e)
1723 Point loc = PointToClient (Control.MousePosition);
1724 return new MouseEventArgs (e.Button, e.Clicks, loc.X, loc.Y, e.Delta);
1728 public ComboListBox (ComboBox owner)
1735 MouseWheel += new MouseEventHandler (OnMouseWheelCLB);
1737 SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
1738 SetStyle (ControlStyles.ResizeRedraw | ControlStyles.Opaque, true);
1740 this.is_visible = false;
1741 Hwnd.ObjectFromHandle (this.Handle).no_activate = true;
1743 if (owner.DropDownStyle == ComboBoxStyle.Simple)
1744 InternalBorderStyle = BorderStyle.Fixed3D;
1746 InternalBorderStyle = BorderStyle.FixedSingle;
1749 protected override CreateParams CreateParams
1752 CreateParams cp = base.CreateParams;
1753 if (owner == null || owner.DropDownStyle == ComboBoxStyle.Simple)
1756 cp.Style ^= (int) WindowStyles.WS_CHILD;
1757 cp.Style |= (int) WindowStyles.WS_POPUP;
1758 cp.ExStyle |= (int) WindowExStyles.WS_EX_TOOLWINDOW | (int) WindowExStyles.WS_EX_TOPMOST;
1763 protected override void Select (bool directed, bool forward)
1765 // Do nothing, we never want to be selected
1768 internal override bool InternalCapture {
1779 switch (border_style) {
1780 case BorderStyle.Fixed3D:
1781 return ThemeEngine.Current.Border3DSize.Width;
1783 return ThemeEngine.Current.BorderSize.Width;
1788 #region Private Methods
1789 // Calcs the listbox area
1790 internal void CalcListBoxArea ()
1793 bool show_scrollbar = false;
1795 if (owner.DropDownStyle == ComboBoxStyle.Simple) {
1796 Rectangle area = owner.listbox_area;
1798 height = area.Height;
1800 else { // DropDown or DropDownList
1802 width = owner.DropDownWidth;
1803 int count = (owner.Items.Count <= owner.MaxDropDownItems) ? owner.Items.Count : owner.MaxDropDownItems;
1805 if (owner.DrawMode == DrawMode.OwnerDrawVariable) {
1807 for (int i = 0; i < count; i++) {
1808 height += owner.GetItemHeight (i);
1812 height = owner.ItemHeight * count;
1816 page_size = height / owner.ItemHeight;
1818 if (owner.Items.Count <= owner.MaxDropDownItems) {
1819 if (vscrollbar_ctrl != null)
1820 vscrollbar_ctrl.Visible = false;
1822 /* Need vertical scrollbar */
1823 if (vscrollbar_ctrl == null) {
1824 vscrollbar_ctrl = new VScrollBarLB ();
1825 vscrollbar_ctrl.Minimum = 0;
1826 vscrollbar_ctrl.SmallChange = 1;
1827 vscrollbar_ctrl.LargeChange = 1;
1828 vscrollbar_ctrl.Maximum = 0;
1829 vscrollbar_ctrl.ValueChanged += new EventHandler (VerticalScrollEvent);
1830 Controls.AddImplicit (vscrollbar_ctrl);
1833 vscrollbar_ctrl.Height = height - 2 * BorderWidth;
1835 vscrollbar_ctrl.Location = new Point (width - vscrollbar_ctrl.Width - BorderWidth - 1, 0);
1837 vscrollbar_ctrl.Maximum = owner.Items.Count - 2;
1838 int large = (owner.DropDownStyle == ComboBoxStyle.Simple ? page_size : owner.maxdrop_items) - 1;
1841 vscrollbar_ctrl.LargeChange = large;
1842 show_scrollbar = vscrollbar_ctrl.Visible = true;
1844 int hli = HighlightedIndex;
1846 hli = Math.Min (hli, vscrollbar_ctrl.Maximum);
1847 vscrollbar_ctrl.Value = hli;
1851 Size = new Size (width, height);
1852 textarea_drawable = ClientRectangle;
1853 textarea_drawable.Width = width;
1854 textarea_drawable.Height = height;
1856 if (vscrollbar_ctrl != null && show_scrollbar)
1857 textarea_drawable.Width -= vscrollbar_ctrl.Width;
1859 last_item = LastVisibleItem ();
1862 private void Draw (Rectangle clip, Graphics dc)
1864 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (owner.BackColor), clip);
1866 if (owner.Items.Count > 0) {
1868 for (int i = top_item; i <= last_item; i++) {
1869 Rectangle item_rect = GetItemDisplayRectangle (i, top_item);
1871 if (!clip.IntersectsWith (item_rect))
1874 DrawItemState state = DrawItemState.None;
1876 if (i == HighlightedIndex) {
1877 state |= DrawItemState.Selected;
1879 if (owner.DropDownStyle == ComboBoxStyle.DropDownList) {
1880 state |= DrawItemState.Focus;
1884 owner.OnDrawItem (new DrawItemEventArgs (dc, owner.Font, item_rect,
1885 i, state, owner.ForeColor, owner.BackColor));
1890 int highlighted_index = -1;
1892 public int HighlightedIndex {
1893 get { return highlighted_index; }
1895 if (highlighted_index == value)
1898 if (highlighted_index != -1 && highlighted_index < this.owner.Items.Count)
1899 Invalidate (GetItemDisplayRectangle (highlighted_index, top_item));
1900 highlighted_index = value;
1901 if (highlighted_index != -1)
1902 Invalidate (GetItemDisplayRectangle (highlighted_index, top_item));
1906 private Rectangle GetItemDisplayRectangle (int index, int top_index)
1908 if (index < 0 || index >= owner.Items.Count)
1909 throw new ArgumentOutOfRangeException ("GetItemRectangle index out of range.");
1911 Rectangle item_rect = new Rectangle ();
1912 int height = owner.GetItemHeight (index);
1915 item_rect.Width = textarea_drawable.Width;
1916 if (owner.DrawMode == DrawMode.OwnerDrawVariable) {
1918 for (int i = top_index; i < index; i++)
1919 item_rect.Y += owner.GetItemHeight (i);
1921 item_rect.Y = height * (index - top_index);
1923 item_rect.Height = height;
1927 public void HideWindow ()
1929 if (owner.DropDownStyle == ComboBoxStyle.Simple)
1934 owner.DropDownListBoxFinished ();
1937 private int IndexFromPointDisplayRectangle (int x, int y)
1939 for (int i = top_item; i <= last_item; i++) {
1940 if (GetItemDisplayRectangle (i, top_item).Contains (x, y) == true)
1947 public void InvalidateItem (int index)
1950 Invalidate (GetItemDisplayRectangle (index, top_item));
1953 private int LastVisibleItem ()
1955 Rectangle item_rect;
1956 int top_y = textarea_drawable.Y + textarea_drawable.Height;
1959 for (i = top_item; i < owner.Items.Count; i++) {
1960 item_rect = GetItemDisplayRectangle (i, top_item);
1961 if (item_rect.Y + item_rect.Height > top_y) {
1968 public void SetTopItem (int item)
1970 if (top_item == item)
1973 UpdateLastVisibleItem ();
1977 bool scrollbar_grabbed = false;
1981 if (vscrollbar_ctrl == null || !vscrollbar_ctrl.is_visible)
1984 return vscrollbar_ctrl.Bounds.Contains (PointToClient (Control.MousePosition));
1988 protected override void OnMouseDown (MouseEventArgs e)
1991 vscrollbar_ctrl.FireMouseDown (e);
1992 scrollbar_grabbed = true;
1996 protected override void OnMouseMove (MouseEventArgs e)
1998 if (owner.DropDownStyle == ComboBoxStyle.Simple)
2001 if (scrollbar_grabbed || (!Capture && InScrollBar)) {
2002 vscrollbar_ctrl.FireMouseMove (e);
2006 Point pt = PointToClient (Control.MousePosition);
2007 int index = IndexFromPointDisplayRectangle (pt.X, pt.Y);
2010 HighlightedIndex = index;
2013 protected override void OnMouseUp (MouseEventArgs e)
2015 int index = IndexFromPointDisplayRectangle (e.X, e.Y);
2017 if (scrollbar_grabbed) {
2018 vscrollbar_ctrl.FireMouseUp (e);
2019 scrollbar_grabbed = false;
2021 HighlightedIndex = index;
2030 owner.SelectedIndex = index;
2031 owner.OnSelectionChangeCommitted (new EventArgs ());
2035 internal override void OnPaintInternal (PaintEventArgs pevent)
2037 Draw (pevent.ClipRectangle,pevent.Graphics);
2040 public bool ShowWindow ()
2042 if (owner.DropDownStyle == ComboBoxStyle.Simple && owner.Items.Count == 0)
2045 HighlightedIndex = owner.SelectedIndex;
2051 owner.OnDropDown (EventArgs.Empty);
2055 public void UpdateLastVisibleItem ()
2057 last_item = LastVisibleItem ();
2060 public void Scroll (int delta)
2062 if (delta == 0 || vscrollbar_ctrl == null || !vscrollbar_ctrl.Visible)
2065 int max = owner.Items.Count - page_size;
2067 int val = vscrollbar_ctrl.Value + delta;
2070 else if (val < vscrollbar_ctrl.Minimum)
2071 val = vscrollbar_ctrl.Minimum;
2072 vscrollbar_ctrl.Value = val;
2075 private void OnMouseWheelCLB (object sender, MouseEventArgs me)
2077 if (owner.Items.Count == 0)
2080 int lines = me.Delta / 120 * SystemInformation.MouseWheelScrollLines;
2085 private void VerticalScrollEvent (object sender, EventArgs e)
2087 if (top_item == vscrollbar_ctrl.Value)
2090 top_item = vscrollbar_ctrl.Value;
2091 UpdateLastVisibleItem ();
2095 protected override void WndProc(ref Message m) {
2096 if (m.Msg == (int)Msg.WM_SETFOCUS) {
2097 if (m.WParam != IntPtr.Zero) {
2098 XplatUI.SetFocus(m.WParam);
2101 base.WndProc (ref m);
2104 #endregion Private Methods