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 // Jordi Mas i Hernandez, jordi@ximian.com
26 // - Keyboard navigation
27 // - Horizontal item scroll
28 // - Performance testing
36 using System.Collections;
37 using System.ComponentModel;
38 using System.Reflection;
40 namespace System.Windows.Forms
43 public class ListBox : ListControl
45 internal class ListBoxInfo
47 internal int item_height; /* Item's height */
48 internal int top_item; /* First item that we show the in the current page */
49 internal int last_item; /* Last visible item */
50 internal int page_size; /* Number of listbox items per page. In MultiColumn listbox indicates items per column */
51 internal Rectangle textdrawing_rect; /* Displayable Client Rectangle minus the scrollbars and with IntegralHeight calculated*/
52 internal bool show_verticalsb; /* Is Vertical scrollbar show it? */
53 internal bool show_horizontalsb; /* Is Horizontal scrollbar show it? */
54 internal Rectangle client_rect; /* Client Rectangle. Usually = ClientRectangle except when IntegralHeight has been applied*/
55 internal int max_itemwidth; /* Maxium item width within the listbox */
64 show_verticalsb = false;
65 show_horizontalsb = false;
69 internal class ListBoxItem
72 internal bool Selected;
73 internal int ItemHeight; /* Only used for OwnerDrawVariable */
74 internal CheckState State;
76 public ListBoxItem (int index)
81 State = CheckState.Unchecked;
85 internal enum ItemNavigation
97 private BorderStyle border_style;
98 private int column_width;
99 private DrawMode draw_mode;
100 private int horizontal_extent;
101 private bool horizontal_scrollbar;
102 private bool integral_height;
103 private bool multicolumn;
104 private bool scroll_always_visible;
105 private int selected_index;
106 private SelectedIndexCollection selected_indices;
107 private SelectedObjectCollection selected_items;
108 private SelectionMode selection_mode;
110 private bool use_tabstops;
111 private int preferred_height;
112 private int top_index;
113 private int column_width_internal;
114 private VScrollBar vscrollbar_ctrl;
115 private HScrollBar hscrollbar_ctrl;
116 private bool suspend_ctrlupdate;
117 private bool ctrl_pressed;
118 private bool shift_pressed;
119 private bool has_focus;
121 internal int focused_item;
122 internal StringFormat string_format;
123 internal ListBoxInfo listbox_info;
124 internal ObjectCollection items;
128 border_style = BorderStyle.Fixed3D;
\r
129 draw_mode = DrawMode.Normal;
\r
130 horizontal_extent = 0;
\r
131 horizontal_scrollbar = false;
\r
132 integral_height = true;
\r
133 multicolumn = false;
\r
134 preferred_height = 7;
\r
135 scroll_always_visible = false;
\r
138 selection_mode = SelectionMode.One;
\r
142 BackColor = ThemeEngine.Current.ColorWindow;
144 suspend_ctrlupdate = false;
145 ctrl_pressed = false;
146 shift_pressed = false;
149 items = new ObjectCollection (this);
150 selected_indices = new SelectedIndexCollection (this);
151 selected_items = new SelectedObjectCollection (this);
152 listbox_info = new ListBoxInfo ();
153 string_format = new StringFormat ();
154 listbox_info.item_height = FontHeight;
156 /* Vertical scrollbar */
157 vscrollbar_ctrl = new VScrollBar ();
158 vscrollbar_ctrl.Minimum = 0;
159 vscrollbar_ctrl.SmallChange = 1;
160 vscrollbar_ctrl.LargeChange = 1;
161 vscrollbar_ctrl.Maximum = 0;
162 vscrollbar_ctrl.ValueChanged += new EventHandler (VerticalScrollEvent);
163 vscrollbar_ctrl.Visible = false;
165 /* Horizontal scrollbar */
166 hscrollbar_ctrl = new HScrollBar ();
167 hscrollbar_ctrl.Minimum = 0;
168 hscrollbar_ctrl.SmallChange = 1;
169 hscrollbar_ctrl.LargeChange = 1;
170 hscrollbar_ctrl.Maximum = 0;
171 hscrollbar_ctrl.Visible = false;
172 hscrollbar_ctrl.ValueChanged += new EventHandler (HorizontalScrollEvent);
175 MouseDown += new MouseEventHandler (OnMouseDownLB);
176 KeyDown += new KeyEventHandler (OnKeyDownLB);
177 KeyUp += new KeyEventHandler (OnKeyUpLB);
178 GotFocus += new EventHandler (OnGotFocus);
179 LostFocus += new EventHandler (OnLostFocus);
181 UpdateFormatString ();
185 public new event EventHandler BackgroundImageChanged;
186 public new event EventHandler Click;
187 public event DrawItemEventHandler DrawItem;
188 public event MeasureItemEventHandler MeasureItem;
189 public new event PaintEventHandler Paint;
190 public event EventHandler SelectedIndexChanged;
191 public new event EventHandler TextChanged;
194 #region Public Properties
195 public override Color BackColor {
196 get { return base.BackColor; }
198 if (base.BackColor == value)
201 base.BackColor = value;
202 base.Refresh (); // Careful. Calling the base method is not the same that calling
203 } // the overriden one that refresh also all the items
206 public override Image BackgroundImage {
207 get { return base.BackgroundImage; }
209 if (base.BackgroundImage == value)
212 base.BackgroundImage = value;
214 if (BackgroundImageChanged != null)
215 BackgroundImageChanged (this, EventArgs.Empty);
221 public BorderStyle BorderStyle {
222 get { return border_style; }
225 if (!Enum.IsDefined (typeof (BorderStyle), value))
226 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for BorderStyle", value));
228 if (border_style == value)
231 border_style = value;
236 public int ColumnWidth {
237 get { return column_width; }
239 if (column_width < 0)
240 throw new ArgumentException ("A value less than zero is assigned to the property.");
242 column_width = value;
245 ColumnWidthInternal = 120;
247 ColumnWidthInternal = value;
253 protected override CreateParams CreateParams {
254 get { return base.CreateParams;}
257 protected override Size DefaultSize {
258 get { return new Size (120, 96); }
261 public virtual DrawMode DrawMode {
262 get { return draw_mode; }
265 if (!Enum.IsDefined (typeof (DrawMode), value))
266 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for DrawMode", value));
268 if (value == DrawMode.OwnerDrawVariable && multicolumn == true)
269 throw new InvalidEnumArgumentException ("Cannot have variable height and multicolumn");
271 if (draw_mode == value)
279 public override Color ForeColor {
280 get { return base.ForeColor; }
283 if (base.ForeColor == value)
286 base.ForeColor = value;
291 public int HorizontalExtent {
292 get { return horizontal_extent; }
294 if (horizontal_extent == value)
297 horizontal_extent = value;
302 public bool HorizontalScrollbar {
303 get { return horizontal_scrollbar; }
305 if (horizontal_scrollbar == value)
308 horizontal_scrollbar = value;
309 UpdateShowHorizontalScrollBar ();
314 public bool IntegralHeight {
315 get { return integral_height; }
317 if (integral_height == value)
320 integral_height = value;
325 public virtual int ItemHeight {
326 get { return listbox_info.item_height; }
329 throw new ArgumentOutOfRangeException ("The ItemHeight property was set beyond 255 pixels");
331 listbox_info.item_height = value;
336 public ObjectCollection Items {
337 get { return items; }
340 public bool MultiColumn {
341 get { return multicolumn; }
343 if (multicolumn == value)
346 if (value == true && DrawMode == DrawMode.OwnerDrawVariable)
347 throw new ArgumentException ("A multicolumn ListBox cannot have a variable-sized height.");
350 UpdateShowVerticalScrollBar (); /* the needs for scrollbars may change */
351 UpdateShowHorizontalScrollBar ();
356 public int PreferredHeight {
357 get { return preferred_height;}
360 public override RightToLeft RightToLeft {
361 get { return base.RightToLeft; }
363 if (base.RightToLeft == value)
366 base.RightToLeft = value;
367 UpdateFormatString ();
372 // Only afects the Vertical ScrollBar
373 public bool ScrollAlwaysVisible {
374 get { return scroll_always_visible; }
376 if (scroll_always_visible == value)
379 scroll_always_visible = value;
380 UpdateShowVerticalScrollBar ();
381 UpdateShowHorizontalScrollBar ();
385 public override int SelectedIndex {
386 get { return selected_index;}
388 if (value < -1 || value >= Items.Count)
389 throw new ArgumentOutOfRangeException ("Index of out range");
391 if (SelectionMode == SelectionMode.None)
392 throw new ArgumentException ("cannot call this method if SelectionMode is SelectionMode.None");
394 if (selected_index == value)
397 if (SelectionMode == SelectionMode.One)
398 UnSelectItem (selected_index, true);
401 selected_index = value;
402 focused_item = value;
403 OnSelectedIndexChanged (new EventArgs ());
407 public SelectedIndexCollection SelectedIndices {
408 get { return selected_indices; }
411 public object SelectedItem {
413 if (SelectedItems.Count > 0)
414 return SelectedItems[0];
420 int index = Items.IndexOf (value);
425 if (index != SelectedIndex) {
426 SelectedIndex = index;
431 public SelectedObjectCollection SelectedItems {
432 get {return selected_items;}
435 public virtual SelectionMode SelectionMode {
436 get { return selection_mode; }
438 if (!Enum.IsDefined (typeof (SelectionMode), value))
439 throw new InvalidEnumArgumentException (string.Format("Enum argument value '{0}' is not valid for SelectionMode", value));
441 if (selection_mode == value)
444 selection_mode = value;
450 get { return sorted; }
461 public override string Text {
463 if (SelectionMode != SelectionMode.None && SelectedIndex != -1)
464 return Items[SelectedIndex].ToString ();
472 if (SelectionMode == SelectionMode.None)
477 index = FindStringExact (value);
482 SelectedIndex = index;
486 public int TopIndex {
487 get { return top_index;}
489 if (value == top_index)
492 if (value < 0 || value >= Items.Count)
500 public bool UseTabStops {
501 get { return use_tabstops; }
504 if (use_tabstops == value)
507 use_tabstops = value;
508 UpdateFormatString ();
513 #endregion Public Properties
515 #region Private Properties
517 internal ListBoxInfo LBoxInfo {
518 get { return listbox_info; }
521 private int ColumnWidthInternal {
522 get { return column_width_internal; }
523 set { column_width_internal = value; }
526 #endregion Private Properties
528 #region Public Methods
529 protected virtual void AddItemsCore (object[] value)
531 Items.AddRange (value);
534 public void BeginUpdate ()
536 suspend_ctrlupdate = true;
539 public void ClearSelected ()
541 foreach (int i in selected_indices) {
542 UnSelectItem (i, false);
545 selected_indices.ClearIndices ();
546 selected_items.ClearObjects ();
549 protected virtual ObjectCollection CreateItemCollection ()
551 return new ObjectCollection (this);
554 public void EndUpdate ()
556 suspend_ctrlupdate = false;
557 UpdateItemInfo (false, -1, -1);
561 public int FindString (String s)
563 return FindString (s, 0);
566 public int FindString (string s, int startIndex)
568 for (int i = startIndex; i < Items.Count; i++) {
569 if ((Items[i].ToString ()).StartsWith (s))
576 public int FindStringExact (string s)
578 return FindStringExact (s, 0);
581 public int FindStringExact (string s, int startIndex)
583 for (int i = startIndex; i < Items.Count; i++) {
584 if ((Items[i].ToString ()).Equals (s))
591 public int GetItemHeight (int index)
593 if (index < 0 || index >= Items.Count)
594 throw new ArgumentOutOfRangeException ("Index of out range");
596 if (DrawMode == DrawMode.OwnerDrawVariable && IsHandleCreated == true) {
598 if ((Items.GetListBoxItem (index)).ItemHeight != -1) {
599 return (Items.GetListBoxItem (index)).ItemHeight;
602 MeasureItemEventArgs args = new MeasureItemEventArgs (DeviceContext, index, ItemHeight);
603 OnMeasureItem (args);
604 (Items.GetListBoxItem (index)).ItemHeight = args.ItemHeight;
605 return args.ItemHeight;
611 public Rectangle GetItemRectangle (int index)
613 if (index < 0 || index >= Items.Count)
614 throw new ArgumentOutOfRangeException ("GetItemRectangle index out of range.");
616 Rectangle rect = new Rectangle ();
618 if (MultiColumn == false) {
621 rect.Height = GetItemHeight (index);
622 rect.Width = listbox_info.textdrawing_rect.Width;
624 if (DrawMode == DrawMode.OwnerDrawVariable) {
626 for (int i = 0; i < index; i++) {
627 rect.Y += GetItemHeight (i);
630 rect.Y = ItemHeight * index;
637 which_page = index / listbox_info.page_size;
638 rect.Y = (index % listbox_info.page_size) * ItemHeight;
639 rect.X = which_page * ColumnWidthInternal;
640 rect.Height = ItemHeight;
641 rect.Width = ColumnWidthInternal;
647 public bool GetSelected (int index)
649 if (index < 0 || index >= Items.Count)
650 throw new ArgumentOutOfRangeException ("Index of out range");
652 return (Items.GetListBoxItem (index)).Selected;
655 public int IndexFromPoint (Point p)
657 return IndexFromPoint (p.X, p.Y);
660 // Only returns visible points
661 public int IndexFromPoint (int x, int y)
663 for (int i = LBoxInfo.top_item; i < LBoxInfo.last_item; i++) {
664 if (GetItemRectangle (i).Contains (x,y) == true)
671 protected override void OnChangeUICues (UICuesEventArgs e)
673 base.OnChangeUICues (e);
676 protected override void OnDataSourceChanged (EventArgs e)
678 base.OnDataSourceChanged (e);
681 protected override void OnDisplayMemberChanged (EventArgs e)
683 base.OnDisplayMemberChanged (e);
686 protected virtual void OnDrawItem (DrawItemEventArgs e)
688 Color back_color, fore_color;
690 if (DrawItem != null && (DrawMode == DrawMode.OwnerDrawFixed || DrawMode == DrawMode.OwnerDrawVariable)) {
695 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
696 back_color = ThemeEngine.Current.ColorHilight;
697 fore_color = ThemeEngine.Current.ColorHilightText;
700 back_color = e.BackColor;
701 fore_color = e.ForeColor;
704 e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
705 (back_color), e.Bounds);
707 e.Graphics.DrawString (Items[e.Index].ToString (), e.Font,
708 ThemeEngine.Current.ResPool.GetSolidBrush (fore_color),
709 e.Bounds, string_format);
711 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
712 ThemeEngine.Current.CPDrawFocusRectangle (e.Graphics, e.Bounds,
713 fore_color, back_color);
717 protected override void OnFontChanged (EventArgs e)
719 base.OnFontChanged (e);
721 UpdateShowHorizontalScrollBar ();
722 UpdateShowVerticalScrollBar ();
723 RellocateScrollBars ();
725 UpdateItemInfo (false, -1, -1);
728 protected override void OnHandleCreated (EventArgs e)
730 base.OnHandleCreated (e);
732 UpdateInternalClientRect (ClientRectangle);
733 Controls.Add (vscrollbar_ctrl);
734 Controls.Add (hscrollbar_ctrl);
735 UpdateItemInfo (false, -1, -1);
738 protected override void OnHandleDestroyed (EventArgs e)
740 base.OnHandleDestroyed (e);
743 protected virtual void OnMeasureItem (MeasureItemEventArgs e)
745 if (draw_mode != DrawMode.OwnerDrawVariable)
748 if (MeasureItem != null)
749 MeasureItem (this, e);
752 protected override void OnParentChanged (EventArgs e)
754 base.OnParentChanged (e);
757 protected override void OnResize (EventArgs e)
760 UpdateInternalClientRect (ClientRectangle);
763 protected override void OnSelectedIndexChanged (EventArgs e)
765 base.OnSelectedIndexChanged (e);
767 if (SelectedIndexChanged != null)
768 SelectedIndexChanged (this, e);
771 protected override void OnSelectedValueChanged (EventArgs e)
773 base.OnSelectedValueChanged (e);
776 public override void Refresh ()
778 if (draw_mode == DrawMode.OwnerDrawVariable) {
779 for (int i = 0; i < Items.Count; i++) {
780 (Items.GetListBoxItem (i)).ItemHeight = -1;
787 protected override void RefreshItem (int index)
789 if (index < 0 || index >= Items.Count)
790 throw new ArgumentOutOfRangeException ("Index of out range");
792 if (draw_mode == DrawMode.OwnerDrawVariable) {
793 (Items.GetListBoxItem (index)).ItemHeight = -1;
797 protected override void SetBoundsCore (int x, int y, int width, int height, BoundsSpecified specified)
799 base.SetBoundsCore (x, y, width, height, specified);
802 protected override void SetItemCore (int index, object value)
804 if (index < 0 || index >= Items.Count)
807 Items[index] = value;
810 protected override void SetItemsCore (IList value)
815 public void SetSelected (int index, bool value)
817 if (index < 0 || index >= Items.Count)
818 throw new ArgumentOutOfRangeException ("Index of out range");
820 if (SelectionMode == SelectionMode.None)
821 throw new InvalidOperationException ();
826 UnSelectItem (index, true);
829 protected virtual void Sort ()
831 if (Items.Count == 0)
838 public override string ToString ()
840 return base.ToString () + ", Items Count: " + Items.Count;
843 protected virtual void WmReflectCommand (ref Message m)
848 protected override void WndProc (ref Message m)
850 switch ((Msg) m.Msg) {
853 PaintEventArgs paint_event;
854 paint_event = XplatUI.PaintEventStart (Handle);
855 OnPaintLB (paint_event);
856 XplatUI.PaintEventEnd (Handle);
860 case Msg.WM_ERASEBKGND:
861 m.Result = (IntPtr) 1;
868 base.WndProc (ref m);
871 #endregion Public Methods
873 #region Private Methods
875 internal void CalcClientArea ()
877 listbox_info.textdrawing_rect = listbox_info.client_rect;
878 listbox_info.textdrawing_rect.Y += ThemeEngine.Current.DrawListBoxDecorationTop (BorderStyle);
879 listbox_info.textdrawing_rect.X += ThemeEngine.Current.DrawListBoxDecorationLeft (BorderStyle);
880 //BUG: Top and Left decorations
881 listbox_info.textdrawing_rect.Height -= ThemeEngine.Current.DrawListBoxDecorationBottom (BorderStyle);
882 listbox_info.textdrawing_rect.Width -= ThemeEngine.Current.DrawListBoxDecorationRight (BorderStyle);
884 if (listbox_info.show_verticalsb)
885 listbox_info.textdrawing_rect.Width -= vscrollbar_ctrl.Width;
887 if (listbox_info.show_horizontalsb)
888 listbox_info.textdrawing_rect.Height -= hscrollbar_ctrl.Height;
890 if (DrawMode == DrawMode.OwnerDrawVariable) {
893 listbox_info.page_size = 0;
894 for (int i = 0; i < Items.Count; i++) {
895 height += GetItemHeight (i);
896 if (height > listbox_info.textdrawing_rect.Height)
899 listbox_info.page_size++;
903 listbox_info.page_size = listbox_info.textdrawing_rect.Height / listbox_info.item_height;
906 if (listbox_info.page_size == 0) {
907 listbox_info.page_size = 1;
910 /* Adjust size to visible the maxim number of displayable items */
911 if (IntegralHeight == true) {
913 // From MS Docs: The integral height is based on the height of the ListBox, rather than
914 // the client area height. As a result, when the IntegralHeight property is set true,
915 // items can still be partially shown if scroll bars are displayed.
917 int remaining = (listbox_info.client_rect.Height -
918 ThemeEngine.Current.DrawListBoxDecorationBottom (BorderStyle) -
919 ThemeEngine.Current.DrawListBoxDecorationBottom (BorderStyle)) %
920 listbox_info.item_height;
923 listbox_info.client_rect.Height -= remaining;
925 RellocateScrollBars ();
931 internal void Draw (Rectangle clip)
933 if (LBoxInfo.textdrawing_rect.Contains (clip) == false) {
934 // IntegralHeight has effect, we also have to paint the unused area
935 if (ClientRectangle.Height > listbox_info.client_rect.Height) {
936 Region area = new Region (ClientRectangle);
937 area.Exclude (listbox_info.client_rect);
939 DeviceContext.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (Parent.BackColor),
940 area.GetBounds (DeviceContext));
943 DeviceContext.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), LBoxInfo.textdrawing_rect);
946 if (Items.Count > 0) {
948 DrawItemState state = DrawItemState.None;
950 for (int i = LBoxInfo.top_item; i <= LBoxInfo.last_item; i++) {
951 item_rect = GetItemDisplayRectangle (i, LBoxInfo.top_item);
953 if (clip.IntersectsWith (item_rect) == false)
957 state = DrawItemState.None;
959 if ((Items.GetListBoxItem (i)).Selected) {
960 state |= DrawItemState.Selected;
963 if (has_focus == true && focused_item == i)
964 state |= DrawItemState.Focus;
966 OnDrawItem (new DrawItemEventArgs (DeviceContext, Font, item_rect,
967 i, state, ForeColor, BackColor));
971 ThemeEngine.Current.DrawListBoxDecorations (DeviceContext, this);
974 // Converts a GetItemRectangle to a one that we can display
975 internal Rectangle GetItemDisplayRectangle (int index, int first_displayble)
978 Rectangle first_item_rect = GetItemRectangle (first_displayble);
979 item_rect = GetItemRectangle (index);
980 item_rect.X -= first_item_rect.X;
981 item_rect.Y -= first_item_rect.Y;
983 item_rect.Y += ThemeEngine.Current.DrawListBoxDecorationTop (BorderStyle);
984 item_rect.X += ThemeEngine.Current.DrawListBoxDecorationLeft (BorderStyle);
985 item_rect.Width -= ThemeEngine.Current.DrawListBoxDecorationRight (BorderStyle);
991 private void HorizontalScrollEvent (object sender, EventArgs e)
993 LBoxInfo.top_item = listbox_info.page_size * hscrollbar_ctrl.Value;
994 LBoxInfo.last_item = LastVisibleItem ();
998 // Only returns visible points. The diference of with IndexFromPoint is that the rectangle
999 // has screen coordinates
1000 internal int IndexFromPointDisplayRectangle (int x, int y)
1002 for (int i = LBoxInfo.top_item; i < LBoxInfo.last_item; i++) {
1003 if (GetItemDisplayRectangle (i, LBoxInfo.top_item).Contains (x, y) == true)
1010 private int LastVisibleItem ()
1012 Rectangle item_rect;
1013 int top_y = LBoxInfo.textdrawing_rect.Y + LBoxInfo.textdrawing_rect.Height;
1016 if (LBoxInfo.top_item >= Items.Count)
1017 return LBoxInfo.top_item;
1019 for (i = LBoxInfo.top_item; i < Items.Count; i++) {
1021 item_rect = GetItemDisplayRectangle (i, LBoxInfo.top_item);
1024 if (item_rect.X > LBoxInfo.textdrawing_rect.Width)
1028 if (IntegralHeight) {
1029 if (item_rect.Y + item_rect.Height > top_y) {
1034 if (item_rect.Y + item_rect.Height > top_y)
1042 private void UpdatedTopItem ()
1045 int col = (LBoxInfo.top_item / LBoxInfo.page_size);
1046 hscrollbar_ctrl.Value = col;
1049 if (LBoxInfo.top_item > vscrollbar_ctrl.Maximum)
1050 vscrollbar_ctrl.Value = vscrollbar_ctrl.Maximum;
1052 vscrollbar_ctrl.Value = LBoxInfo.top_item;
1056 // Navigates to the indicated item and returns the new item
1057 private int NavigateItemVisually (ItemNavigation navigation)
1059 int page_size, columns, selected_index = -1;
1062 columns = LBoxInfo.textdrawing_rect.Width / ColumnWidthInternal;
1063 page_size = columns * LBoxInfo.page_size;
1064 if (page_size == 0) {
1065 page_size = LBoxInfo.page_size;
1068 page_size = LBoxInfo.page_size;
1071 switch (navigation) {
1073 case ItemNavigation.PreviousColumn: {
1074 if (focused_item - LBoxInfo.page_size < 0) {
1078 if (focused_item - LBoxInfo.page_size < LBoxInfo.top_item) {
1079 LBoxInfo.top_item = focused_item - LBoxInfo.page_size;
1083 selected_index = focused_item - LBoxInfo.page_size;
1087 case ItemNavigation.NextColumn: {
1088 if (focused_item + LBoxInfo.page_size >= Items.Count) {
1092 if (focused_item + LBoxInfo.page_size > LBoxInfo.last_item) {
1093 LBoxInfo.top_item = focused_item;
1097 selected_index = focused_item + LBoxInfo.page_size;
1101 case ItemNavigation.First: {
1102 LBoxInfo.top_item = 0;
1108 case ItemNavigation.Last: {
1110 if (Items.Count < LBoxInfo.page_size) {
1111 LBoxInfo.top_item = 0;
1112 selected_index = Items.Count - 1;
1115 LBoxInfo.top_item = Items.Count - LBoxInfo.page_size;
1116 selected_index = Items.Count - 1;
1122 case ItemNavigation.Next: {
1123 if (focused_item + 1 < Items.Count) {
1124 if (focused_item + 1 > LBoxInfo.last_item) {
1125 LBoxInfo.top_item++;
1128 selected_index = focused_item + 1;
1133 case ItemNavigation.Previous: {
1134 if (focused_item > 0) {
1135 if (focused_item - 1 < LBoxInfo.top_item) {
1136 LBoxInfo.top_item--;
1139 selected_index = focused_item - 1;
1144 case ItemNavigation.NextPage: {
1145 if (Items.Count < page_size) {
1146 NavigateItemVisually (ItemNavigation.Last);
1150 if (focused_item + page_size - 1 >= Items.Count) {
1151 LBoxInfo.top_item = Items.Count - page_size;
1153 selected_index = Items.Count - 1;
1156 if (focused_item + page_size - 1 > LBoxInfo.last_item) {
1157 LBoxInfo.top_item = focused_item;
1161 selected_index = focused_item + page_size - 1;
1167 case ItemNavigation.PreviousPage: {
1169 if (focused_item - (LBoxInfo.page_size - 1) <= 0) {
1171 LBoxInfo.top_item = 0;
1172 vscrollbar_ctrl.Value = LBoxInfo.top_item;
1176 if (focused_item - (LBoxInfo.page_size - 1) < LBoxInfo.top_item) {
1177 LBoxInfo.top_item = focused_item - (LBoxInfo.page_size - 1);
1178 vscrollbar_ctrl.Value = LBoxInfo.top_item;
1181 selected_index = focused_item - (LBoxInfo.page_size - 1);
1190 return selected_index;
1193 private void OnGotFocus (object sender, EventArgs e)
1197 if (focused_item != -1) {
1198 Rectangle invalidate = GetItemDisplayRectangle (focused_item, LBoxInfo.top_item);
1199 Invalidate (invalidate);
1203 private void OnLostFocus (object sender, EventArgs e)
1207 if (focused_item != -1) {
1208 Rectangle invalidate = GetItemDisplayRectangle (focused_item, LBoxInfo.top_item);
1209 Invalidate (invalidate);
1213 private void OnKeyDownLB (object sender, KeyEventArgs e)
1217 switch (e.KeyCode) {
1219 case Keys.ControlKey:
1220 ctrl_pressed = true;
1224 shift_pressed = true;
1228 new_item = NavigateItemVisually (ItemNavigation.First);
1232 new_item = NavigateItemVisually (ItemNavigation.Last);
1236 new_item = NavigateItemVisually (ItemNavigation.Previous);
1240 new_item = NavigateItemVisually (ItemNavigation.Next);
1244 new_item = NavigateItemVisually (ItemNavigation.PreviousPage);
1248 new_item = NavigateItemVisually (ItemNavigation.NextPage);
1252 if (multicolumn == true) {
1253 new_item = NavigateItemVisually (ItemNavigation.NextColumn);
1258 if (multicolumn == true) {
1259 new_item = NavigateItemVisually (ItemNavigation.PreviousColumn);
1264 if (selection_mode == SelectionMode.MultiSimple) {
1265 SelectedItemFromNavigation (focused_item);
1274 if (new_item != -1) {
1275 SetFocusedItem (new_item);
1278 if (new_item != -1) {
1279 if (selection_mode != SelectionMode.MultiSimple && selection_mode != SelectionMode.None) {
1280 SelectedItemFromNavigation (new_item);
1285 private void OnKeyUpLB (object sender, KeyEventArgs e)
1287 switch (e.KeyCode) {
1288 case Keys.ControlKey:
1289 ctrl_pressed = false;
1292 shift_pressed = false;
1299 internal virtual void OnMouseDownLB (object sender, MouseEventArgs e)
1301 int index = IndexFromPointDisplayRectangle (e.X, e.Y);
1304 SelectedItemFromNavigation (index);
1305 SetFocusedItem (index);
1309 private void OnPaintLB (PaintEventArgs pevent)
1311 if (Width <= 0 || Height <= 0 || Visible == false || suspend_ctrlupdate == true)
1314 /* Copies memory drawing buffer to screen*/
1315 Draw (pevent.ClipRectangle);
1316 pevent.Graphics.DrawImage (ImageBuffer, pevent.ClipRectangle, pevent.ClipRectangle, GraphicsUnit.Pixel);
1319 Paint (this, pevent);
1322 internal void RellocateScrollBars ()
1324 if (listbox_info.show_verticalsb) {
1326 vscrollbar_ctrl.Size = new Size (vscrollbar_ctrl.Width,
1327 listbox_info.client_rect.Height - ThemeEngine.Current.DrawListBoxDecorationTop (BorderStyle) -
1328 ThemeEngine.Current.DrawListBoxDecorationBottom (BorderStyle));
1330 vscrollbar_ctrl.Location = new Point (listbox_info.client_rect.Width - vscrollbar_ctrl.Width
1331 - ThemeEngine.Current.DrawListBoxDecorationRight (BorderStyle),
1332 ThemeEngine.Current.DrawListBoxDecorationTop (BorderStyle));
1336 if (listbox_info.show_horizontalsb) {
1340 width = listbox_info.client_rect.Width - (ThemeEngine.Current.DrawListBoxDecorationLeft (BorderStyle) + ThemeEngine.Current.DrawListBoxDecorationRight (BorderStyle));
1342 if (listbox_info.show_verticalsb)
1343 width -= vscrollbar_ctrl.Width;
1345 hscrollbar_ctrl.Size = new Size (width, hscrollbar_ctrl.Height);
1347 hscrollbar_ctrl.Location = new Point (ThemeEngine.Current.DrawListBoxDecorationLeft (BorderStyle),
1348 listbox_info.client_rect.Height - hscrollbar_ctrl.Height
1349 - ThemeEngine.Current.DrawListBoxDecorationTop (BorderStyle));
1355 // Add an item in the Selection array and marks it visually as selected
1356 private void SelectItem (int index)
1361 Rectangle invalidate = GetItemDisplayRectangle (index, LBoxInfo.top_item);
1362 (Items.GetListBoxItem (index)).Selected = true;
1363 selected_indices.AddIndex (index);
1364 selected_items.AddObject (Items[index]);
1366 if (ClientRectangle.Contains (invalidate))
1367 Invalidate (invalidate);
1371 // An item navigation operation (mouse or keyboard) has caused to select a new item
1372 private void SelectedItemFromNavigation (int index)
1374 switch (SelectionMode) {
1375 case SelectionMode.None: // Do nothing
1377 case SelectionMode.One: {
1378 SelectedIndex = index;
1381 case SelectionMode.MultiSimple: {
1382 if (selected_index == -1) {
1383 SelectedIndex = index;
1386 if ((Items.GetListBoxItem (index)).Selected) // BUG: index or selected_index?
1387 UnSelectItem (index, true);
1390 OnSelectedIndexChanged (new EventArgs ());
1396 case SelectionMode.MultiExtended: {
1397 if (selected_index == -1) {
1398 SelectedIndex = index;
1401 if (ctrl_pressed == false && shift_pressed == false) {
1405 if (shift_pressed == true) {
1406 ShiftSelection (index);
1407 } else { // ctrl_pressed or single item
1411 OnSelectedIndexChanged (new EventArgs ());
1421 private void ShiftSelection (int index)
1423 int shorter_item = -1, dist = Items.Count + 1, cur_dist;
1425 foreach (int idx in selected_indices) {
1427 cur_dist = idx - index;
1430 cur_dist = index - idx;
1433 if (cur_dist < dist) {
1439 if (shorter_item != -1) {
1442 if (shorter_item > index) {
1446 start = shorter_item;
1451 for (int idx = start; idx <= end; idx++) {
1457 void SetFocusedItem (int index)
1459 Rectangle invalidate;
1460 int prev = focused_item;
1462 focused_item = index;
1464 if (has_focus == false)
1467 if (prev != -1) { // Invalidates previous item
1468 invalidate = GetItemDisplayRectangle (prev, LBoxInfo.top_item);
1469 Invalidate (invalidate);
1473 invalidate = GetItemDisplayRectangle (index, LBoxInfo.top_item);
1474 Invalidate (invalidate);
1478 // Removes an item in the Selection array and marks it visually as unselected
1479 private void UnSelectItem (int index, bool remove)
1484 Rectangle invalidate = GetItemDisplayRectangle (index, LBoxInfo.top_item);
1485 (Items.GetListBoxItem (index)).Selected = false;
1488 selected_indices.RemoveIndex (index);
1489 selected_items.RemoveObject (Items[index]);
1493 if (ClientRectangle.Contains (invalidate))
1494 Invalidate (invalidate);
1497 private void UpdateFormatString ()
1499 Console.WriteLine ("UpdateFormatString {0}", RightToLeft);
1501 if (RightToLeft == RightToLeft.Yes)
1502 string_format.Alignment = StringAlignment.Far;
1504 string_format.Alignment = StringAlignment.Near;
1507 string_format.SetTabStops (0, new float [] {(float)(Font.Height * 3.7)});
1510 // Updates the scrollbar's position with the new items and inside area
1511 internal virtual void UpdateItemInfo (bool adding, int first, int last)
1513 if (!IsHandleCreated || suspend_ctrlupdate == true)
1516 UpdateShowVerticalScrollBar ();
1518 if (listbox_info.show_verticalsb && Items.Count > listbox_info.page_size)
1519 if (vscrollbar_ctrl.Enabled)
1520 vscrollbar_ctrl.Maximum = Items.Count - listbox_info.page_size;
1522 if (listbox_info.show_horizontalsb) {
1524 int fullpage = (listbox_info.page_size * (listbox_info.client_rect.Width / ColumnWidthInternal));
1526 if (hscrollbar_ctrl.Enabled && listbox_info.page_size > 0)
1527 hscrollbar_ctrl.Maximum = Math.Max (0, 1 + ((Items.Count - fullpage) / listbox_info.page_size));
1531 if (MultiColumn == false) {
1532 /* Calc the longest items for non multicolumn listboxes */
1533 if ((first == -1 && last == -1) || (adding == false)) {
1536 for (int i = 0; i < Items.Count; i++) {
1537 size = DeviceContext.MeasureString (Items[i].ToString(), Font);
1539 if ((int) size.Width > listbox_info.max_itemwidth)
1540 listbox_info.max_itemwidth = (int) size.Width;
1547 for (int i = first; i < last + 1; i++) {
1548 size = DeviceContext.MeasureString (Items[i].ToString(), Font);
1550 if ((int) size.Width > listbox_info.max_itemwidth)
1551 listbox_info.max_itemwidth = (int) size.Width;
1560 SelectedItems.ReCreate ();
1561 SelectedIndices.ReCreate ();
1562 LBoxInfo.last_item = LastVisibleItem ();
1564 UpdateShowHorizontalScrollBar ();
1568 private void UpdateInternalClientRect (Rectangle client_rectangle)
1570 listbox_info.client_rect = client_rectangle;
1571 UpdateShowHorizontalScrollBar ();
1572 UpdateShowVerticalScrollBar ();
1573 RellocateScrollBars ();
1574 UpdateItemInfo (false, -1, -1);
1577 /* Determines if the horizontal scrollbar has to be displyed */
1578 private void UpdateShowHorizontalScrollBar ()
1581 bool enabled = true;
1583 if (MultiColumn) { /* Horizontal scrollbar is always shown in Multicolum mode */
1585 /* Is it really need it */
1586 int page_size = listbox_info.client_rect.Height / listbox_info.item_height;
1587 int fullpage = (page_size * (listbox_info.textdrawing_rect.Height / ColumnWidthInternal));
1589 if (Items.Count > fullpage) {
1590 if (IntegralHeight == false)
1593 else { /* Acording to MS Documentation ScrollAlwaysVisible only affects Horizontal scrollbars but
1594 this is not true for MultiColumn listboxes */
1595 if (ScrollAlwaysVisible == true) {
1601 } else { /* If large item*/
1603 if (listbox_info.max_itemwidth > listbox_info.client_rect.Width && HorizontalScrollbar) {
1605 hscrollbar_ctrl.Maximum = listbox_info.max_itemwidth;
1609 if (hscrollbar_ctrl.Enabled != enabled)
1610 hscrollbar_ctrl.Enabled = enabled;
1612 if (listbox_info.show_horizontalsb == show)
1615 listbox_info.show_horizontalsb = show;
1616 hscrollbar_ctrl.Visible = show;
1619 RellocateScrollBars ();
1625 /* Determines if the vertical scrollbar has to be displyed */
1626 private void UpdateShowVerticalScrollBar ()
1629 bool enabled = true;
1631 if (!MultiColumn) { /* Vertical scrollbar is never shown in Multicolum mode */
1632 if (Items.Count > listbox_info.page_size) {
1636 if (ScrollAlwaysVisible) {
1642 if (vscrollbar_ctrl.Enabled != enabled)
1643 vscrollbar_ctrl.Enabled = enabled;
1645 if (listbox_info.show_verticalsb == show)
1648 listbox_info.show_verticalsb = show;
1649 vscrollbar_ctrl.Visible = show;
1652 if (vscrollbar_ctrl.Enabled)
1653 vscrollbar_ctrl.Maximum = Items.Count - listbox_info.page_size;
1655 RellocateScrollBars ();
1662 private void VerticalScrollEvent (object sender, EventArgs e)
1664 LBoxInfo.top_item = /*listbox_info.page_size + */ vscrollbar_ctrl.Value;
1665 LBoxInfo.last_item = LastVisibleItem ();
1670 #endregion Private Methods
1673 ListBox.ObjectCollection
1675 public class ObjectCollection : IList, ICollection, IEnumerable
1678 internal class ListObjectComparer : IComparer
\r
1680 private ListBox owner;
\r
1682 public ListObjectComparer (ListBox owner)
\r
1684 this.owner = owner;
\r
1687 public int Compare (object a, object b)
\r
1689 string str1 = a.ToString ();
1690 string str2 = b.ToString ();
\r
1691 return str1.CompareTo (str2);
\r
1696 internal class ListItemComparer : IComparer
\r
1698 private ListBox owner;
\r
1700 public ListItemComparer (ListBox owner)
\r
1702 this.owner = owner;
\r
1705 public int Compare (object a, object b)
\r
1707 int index1 = ((ListBox.ListBoxItem) (a)).Index;
1708 int index2 = ((ListBox.ListBoxItem) (b)).Index;
1709 string str1 = owner.Items[index1].ToString ();
1710 string str2 = owner.Items[index2].ToString ();
\r
1711 return str1.CompareTo (str2);
\r
1715 private ListBox owner;
1716 internal ArrayList object_items = new ArrayList ();
1717 internal ArrayList listbox_items = new ArrayList ();
1719 public ObjectCollection (ListBox owner)
1724 public ObjectCollection (ListBox owner, object[] obj)
1730 public ObjectCollection (ListBox owner, ObjectCollection obj)
1736 #region Public Properties
1737 public virtual int Count {
1738 get { return object_items.Count; }
1741 public virtual bool IsReadOnly {
1742 get { return false; }
1745 public virtual object this [int index] {
1747 if (index < 0 || index >= Count)
1748 throw new ArgumentOutOfRangeException ("Index of out range");
1750 return object_items[index];
1753 if (index < 0 || index >= Count)
1754 throw new ArgumentOutOfRangeException ("Index of out range");
1756 object_items[index] = value;
1760 bool ICollection.IsSynchronized {
1761 get { return false; }
1764 object ICollection.SyncRoot {
1765 get { return this; }
1768 bool IList.IsFixedSize {
1769 get { return false; }
1772 #endregion Public Properties
1774 #region Public Methods
1775 public int Add (object item)
1779 idx = AddItem (item);
1780 owner.UpdateItemInfo (true, idx, idx);
1784 public void AddRange (object[] items)
1788 foreach (object mi in items)
1791 owner.UpdateItemInfo (true, cnt, Count);
1794 public void AddRange (ObjectCollection col)
1798 foreach (object mi in col)
1801 owner.UpdateItemInfo (true, cnt, Count);
1804 public virtual void Clear ()
1806 object_items.Clear ();
1807 listbox_items.Clear ();
1808 owner.UpdateItemInfo (false, -1, -1);
1810 public virtual bool Contains (object obj)
1812 return object_items.Contains (obj);
1815 public void CopyTo (object[] dest, int arrayIndex)
1817 object_items.CopyTo (dest, arrayIndex);
1820 void ICollection.CopyTo (Array dest, int index)
1822 object_items.CopyTo (dest, index);
1825 public virtual IEnumerator GetEnumerator ()
1827 return object_items.GetEnumerator ();
1830 int IList.Add (object item)
1835 public virtual int IndexOf (object value)
1837 return object_items.IndexOf (value);
1840 public virtual void Insert (int index, object item)
1842 throw new NotImplementedException ();
1845 public virtual void Remove (object value)
1847 RemoveAt (IndexOf (value));
1848 owner.UpdateItemInfo (false, -1, -1);
1851 public virtual void RemoveAt (int index)
1853 if (index < 0 || index >= Count)
1854 throw new ArgumentOutOfRangeException ("Index of out range");
1856 object_items.RemoveAt (index);
1857 listbox_items.RemoveAt (index);
1858 owner.UpdateItemInfo (false, -1, -1);
1860 #endregion Public Methods
1862 #region Private Methods
1863 private int AddItem (object item)
1865 int cnt = object_items.Count;
1866 object_items.Add (item);
1867 listbox_items.Add (new ListBox.ListBoxItem (cnt));
1871 internal ListBox.ListBoxItem GetListBoxItem (int index)
1873 if (index < 0 || index >= Count)
1874 throw new ArgumentOutOfRangeException ("Index of out range");
1876 return (ListBox.ListBoxItem) listbox_items[index];
1879 internal void SetListBoxItem (ListBox.ListBoxItem item, int index)
1881 if (index < 0 || index >= Count)
1882 throw new ArgumentOutOfRangeException ("Index of out range");
1884 listbox_items[index] = item;
1887 internal void Sort ()
1889 /* Keep this order */
1890 listbox_items.Sort (new ListItemComparer (owner));
1891 object_items.Sort (new ListObjectComparer (owner));
1893 for (int i = 0; i < listbox_items.Count; i++) {
1894 ListBox.ListBoxItem item = GetListBoxItem (i);
1899 #endregion Private Methods
1903 ListBox.SelectedIndexCollection
1905 public class SelectedIndexCollection : IList, ICollection, IEnumerable
1907 private ListBox owner;
1908 private ArrayList indices = new ArrayList ();
1910 public SelectedIndexCollection (ListBox owner)
1915 #region Public Properties
1916 public virtual int Count {
1917 get { return indices.Count; }
1920 public virtual bool IsReadOnly {
1921 get { return true; }
1924 public int this [int index] {
1926 if (index < 0 || index >= Count)
1927 throw new ArgumentOutOfRangeException ("Index of out range");
1929 return (int) indices[index];
1933 bool ICollection.IsSynchronized {
1934 get { return true; }
1937 bool IList.IsFixedSize{
1938 get { return true; }
1941 object ICollection.SyncRoot {
1942 get { return this; }
1945 #endregion Public Properties
1947 #region Public Methods
1948 public bool Contains (int selectedIndex)
1950 return indices.Contains (selectedIndex);
1953 public virtual void CopyTo (Array dest, int index)
1955 indices.CopyTo (dest, index);
1958 public virtual IEnumerator GetEnumerator ()
1960 return indices.GetEnumerator ();
1963 int IList.Add (object obj)
1965 throw new NotSupportedException ();
1970 throw new NotSupportedException ();
1973 bool IList.Contains (object selectedIndex)
1975 return Contains ((int)selectedIndex);
1978 int IList.IndexOf (object selectedIndex)
1980 return IndexOf ((int) selectedIndex);
1983 void IList.Insert (int index, object value)
1985 throw new NotSupportedException ();
1988 void IList.Remove (object value)
1990 throw new NotSupportedException ();
1993 void IList.RemoveAt (int index)
1995 throw new NotSupportedException ();
1998 object IList.this[int index]{
1999 get {return indices[index]; }
2000 set {throw new NotImplementedException (); }
2003 public int IndexOf (int selectedIndex)
2005 return indices.IndexOf (selectedIndex);
2007 #endregion Public Methods
2009 #region Private Methods
2011 internal void AddIndex (int index)
2013 indices.Add (index);
2016 internal void ClearIndices ()
2021 internal void RemoveIndex (int index)
2023 indices.Remove (index);
2026 internal void ReCreate ()
2030 for (int i = 0; i < owner.Items.Count; i++) {
2031 ListBox.ListBoxItem item = owner.Items.GetListBoxItem (i);
2034 indices.Add (item.Index);
2038 #endregion Private Methods
2042 SelectedObjectCollection
2044 public class SelectedObjectCollection : IList, ICollection, IEnumerable
2046 private ListBox owner;
2047 private ArrayList object_items = new ArrayList ();
2049 public SelectedObjectCollection (ListBox owner)
2054 #region Public Properties
2055 public virtual int Count {
2056 get { return object_items.Count; }
2059 public virtual bool IsReadOnly {
2060 get { return true; }
2063 public virtual object this [int index] {
2065 if (index < 0 || index >= Count)
2066 throw new ArgumentOutOfRangeException ("Index of out range");
2068 return object_items[index];
2070 set {throw new NotSupportedException ();}
2073 bool ICollection.IsSynchronized {
2074 get { return true; }
2077 object ICollection.SyncRoot {
2078 get { return this; }
2081 bool IList.IsFixedSize {
2082 get { return true; }
2085 object IList.this[int index] {
2086 get { return object_items[index]; }
2087 set { throw new NotSupportedException (); }
2090 #endregion Public Properties
2092 #region Public Methods
2093 public virtual bool Contains (object selectedObject)
2095 return object_items.Contains (selectedObject);
2098 public virtual void CopyTo (Array dest, int index)
2100 object_items.CopyTo (dest, index);
2103 int IList.Add (object value)
2105 throw new NotSupportedException ();
2110 throw new NotSupportedException ();
2113 bool IList.Contains (object selectedIndex)
2115 throw new NotImplementedException ();
2118 int IList.IndexOf (object selectedIndex)
2120 return IndexOf ((int) selectedIndex);
2123 void IList.Insert (int index, object value)
2125 throw new NotSupportedException ();
2128 void IList.Remove (object value)
2130 throw new NotSupportedException ();
2133 void IList.RemoveAt (int index)
2135 throw new NotSupportedException ();
2138 public int IndexOf (int selectedIndex)
2140 return object_items.IndexOf (selectedIndex);
2143 public virtual IEnumerator GetEnumerator ()
2145 return object_items.GetEnumerator ();
2148 #endregion Public Methods
2150 #region Private Methods
2151 internal void AddObject (object obj)
2153 object_items.Add (obj);
2156 internal void ClearObjects ()
2158 object_items.Clear ();
2161 internal void ReCreate ()
2163 object_items.Clear ();
2165 for (int i = 0; i < owner.Items.Count; i++) {
2166 ListBox.ListBoxItem item = owner.Items.GetListBoxItem (i);
2169 object_items.Add (owner.Items[item.Index]);
2173 internal void RemoveObject (object obj)
2175 object_items.Remove (obj);
2180 #endregion Private Methods