<commit_before>using System;
using System.Reflection;
using SWF = System.Windows.Forms;
using SD = System.Drawing;
using Eto.Forms;
using System.Collections.Generic;
using System.Linq;
using Eto.Drawing;

namespace Eto.Platform.Windows
{
	public class ComboBoxHandler : WindowsControl<SWF.ComboBox, ComboBox>, IComboBox
	{
		CollectionHandler collection;

		public ComboBoxHandler()
		{
			Control = new SWF.ComboBox
			{
				DropDownStyle = SWF.ComboBoxStyle.DropDownList,
				ValueMember = "Key",
				DisplayMember = "Text",
				AutoSize = true,
				Size = SD.Size.Empty
			};
			Control.SelectedIndexChanged += delegate
			{
				Widget.OnSelectedIndexChanged(EventArgs.Empty);
			};

		}

		public override Size DesiredSize
		{
			get
			{
				var size = new Size(16, 20);
				var font = Control.Font;

				using (var graphics = Control.CreateGraphics())
				{
					foreach (object item in Control.Items)
					{
						var text = Control.GetItemText(item);
						var itemSize = graphics.MeasureString(text, font).ToEtoSize();
						// for drop down glyph and border
						size = Size.Max(size, itemSize);
					}
				}
				size += new Size(18, 8);
				return size;
			}
		}

		public int SelectedIndex
		{
			get { return Control.SelectedIndex; }
			set { Control.SelectedIndex = value; }
		}

		class CollectionHandler : DataStoreChangedHandler<IListItem, IListStore>
		{
			public ComboBoxHandler Handler { get; set; }

			public override int IndexOf(IListItem item)
			{
				return Handler.Control.Items.IndexOf(item);
			}

			public override void AddRange(IEnumerable<IListItem> items)
			{
				Handler.Control.Items.AddRange(items.ToArray());
				Handler.UpdateSizes();
			}

			public override void AddItem(IListItem item)
			{
				Handler.Control.Items.Add(item);
				Handler.UpdateSizes();
			}

			public override void InsertItem(int index, IListItem item)<commit_msg>WinForms: ComboBox should auto size when used in a TableLayout<commit_after>using System;
using swf = System.Windows.Forms;
using sd = System.Drawing;
using Eto.Forms;
using System.Collections.Generic;
using System.Linq;
using Eto.Drawing;

namespace Eto.Platform.Windows
{
	public class ComboBoxHandler : WindowsControl<swf.ComboBox, ComboBox>, IComboBox
	{
		CollectionHandler collection;

		public class EtoComboBox : swf.ComboBox
		{
			public override sd.Size GetPreferredSize(sd.Size proposedSize)
			{
				var size = new sd.Size(16, 20);
				var font = Font;

				using (var graphics = CreateGraphics())
				{
					foreach (object item in Items)
					{
						var text = GetItemText(item);
						var itemSize = graphics.MeasureString(text, font).ToEtoSize();
						// for drop down glyph and border
						size.Width = Math.Max(size.Width, itemSize.Width);
						size.Height = Math.Max(size.Height, itemSize.Height);
					}
				}
				size.Width += 18;
				size.Height += 4;
				return size;
			}
		}

		public ComboBoxHandler()
		{
			Control = new EtoComboBox
			{
				DropDownStyle = swf.ComboBoxStyle.DropDownList,
				ValueMember = "Key",
				DisplayMember = "Text",
				AutoSize = true,
				Size = new sd.Size(20, 0)
			};
			Control.SelectedIndexChanged += delegate
			{
				Widget.OnSelectedIndexChanged(EventArgs.Empty);
			};
		}

		public override Size DesiredSize
		{
			get
			{
				if (Control.AutoSize)
					return Control.GetPreferredSize(sd.Size.Empty).ToEto();
				return base.DesiredSize;
			}
		}

		public int SelectedIndex
		{
			get { return Control.SelectedIndex; }
			set { Control.SelectedIndex = value; }
		}

		class CollectionHandler : DataStoreChangedHandler<IListItem, IListStore>
		{
			public ComboBoxHandler Handler { get; set; }

			public override int IndexOf(IListItem item)
			{
				return Handler.Control.Items.IndexOf(item);
			}

			public override void AddRange(IEnumerable<IListItem> items)
			{
				Handler.Control.Items.AddRange(items.ToArray());
				Handler.UpdateSizes();
			}

			public override void AddItem(IListItem item)
			{
				Handler.Control.Items.Add(item);
				Handler.UpdateSizes();
			}

			public override void InsertItem(int index, IListItem item)
{'fraction_non_alphanumeric': 0.10141739980449657, 'fraction_numerical': 0.004154447702834799, 'mean_word_length': 3.21524201853759, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4228629', 'n_tokens_mistral': 1611, 'n_tokens_neox': 1253, 'n_words': 298}