public void GeckoListBox_TestAddItem() { IWritingSystemDefinition ws = WritingSystemDefinition.Parse("fr"); IWritingSystemDefinition ws2 = WritingSystemDefinition.Parse("en"); var listBox = new GeckoListBox(); listBox.FormWritingSystem = ws; listBox.MeaningWritingSystem = ws2; listBox.Name = "ControlUnderTest"; Assert.IsNotNull(listBox); String volvo = "Volvo"; String saab = "Saab"; String toyota = "Toyota"; listBox.AddItem(volvo); listBox.AddItem(saab); listBox.AddItem(toyota); Assert.AreSame(saab, listBox.GetItem(1)); Assert.AreSame(toyota, listBox.GetItem(2)); Assert.AreEqual(3, listBox.Length); Assert.AreSame(ws2, listBox.MeaningWritingSystem); listBox.Clear(); Assert.AreEqual(0, listBox.Length); }
public void GeckoListBox_TestGetRectangle() { _countOfItemsDrawn = 0; _itemToNotDrawYetDrawn = false; IWritingSystemDefinition ws = WritingSystemDefinition.Parse("fr"); IWritingSystemDefinition ws2 = WritingSystemDefinition.Parse("en"); _listBox = new GeckoListBox(); _listBox.FormWritingSystem = ws; _listBox.MeaningWritingSystem = ws2; _listBox.Name = "ControlUnderTest"; Assert.IsNotNull(_listBox); String volvo = "Volvo"; String saab = "Saab"; String toyota = "Toyota"; _listBox.AddItem(volvo); _listBox.AddItem(saab); _listBox.AddItem(toyota); _listBox.ItemDrawer = GeckoListBox_TestDrawItem; _listBox.ListCompleted(); Application.DoEvents(); _window.Controls.Add(_listBox); _window.Show(); ControlTester t = new ControlTester("ControlUnderTest", _window); Application.DoEvents(); Rectangle r = _listBox.GetItemRectangle(1); Application.DoEvents(); using (MouseController mc = new MouseController(t)) { mc.Click(r.Right + 5, r.Top + 5); } Application.DoEvents(); Application.DoEvents(); Assert.AreEqual(1, _listBox.SelectedIndex); Assert.AreSame(_listBox.SelectedItem, saab); }
public void GeckoListBox_TestDrawItem() { _countOfItemsDrawn = 0; _itemToNotDrawYetDrawn = false; IWritingSystemDefinition ws = WritingSystemDefinition.Parse("fr"); IWritingSystemDefinition ws2 = WritingSystemDefinition.Parse("en"); _listBox = new GeckoListBox(); _listBox.FormWritingSystem = ws; _listBox.MeaningWritingSystem = ws2; _listBox.Name = "ControlUnderTest"; Assert.IsNotNull(_listBox); String volvo = "Volvo"; String saab = "Saab"; String toyota = "Toyota"; _listBox.AddItem(volvo); _listBox.AddItem(saab); _listBox.AddItem(toyota); _listBox.ItemToNotDrawYet = saab; _listBox.ItemDrawer = GeckoListBox_TestDrawItem; _listBox.ListCompleted(); Application.DoEvents(); _window.Controls.Add((GeckoListBox)_listBox); _window.Show(); Application.DoEvents(); // Count may be 2 or 4 depending on whether adjust height // ran yet or not if (_countOfItemsDrawn != 2) { Assert.AreEqual(4, _countOfItemsDrawn); } Assert.IsTrue(_itemToNotDrawYetDrawn == false); }
protected virtual void UpdateList() { int selectedIndex = _listBox.SelectedIndex; _listBox.Clear(); _listBox.Font = Font; _listBox.ItemHeight = _listBox.Font.Height; int maxWidth = Width; using (Graphics g = (_autoSizePopup) ? CreateGraphics() : null) { // Text.Trim() allows "1 " to trigger updating the list and matching "1 Universe", where // the match involves "1" and "Universe" separately. (Note that "1 " does not match either // "1" or "Universe".) foreach (object item in ItemFilterer.Invoke(Text.Trim(), Items, ItemDisplayStringAdaptor)) { string label = ItemDisplayStringAdaptor.GetDisplayLabel(item); _listBox.AddItem(new ItemWrapper(item, label)); if (_autoSizePopup) { maxWidth = Math.Max(maxWidth, MeasureItem(g, label).Width); } } } _listBox.ListCompleted(); _listBox.SelectedIndex = selectedIndex; if (_listBox.Items.Count == 0) { HideList(); } else { int visItems = _listBox.Items.Count; if (visItems > 8) { visItems = 8; } _listBox.Height = (visItems * _listBox.ItemHeight) + 4; switch (BorderStyle) { case BorderStyle.FixedSingle: { _listBox.Height += 2; break; } case BorderStyle.Fixed3D: { _listBox.Height += 4; break; } } if (_autoSizePopup) { bool hasScrollBar = visItems < _listBox.Items.Count; _listBox.Width = maxWidth + (hasScrollBar ? 10 : 0); // in theory this shouldn't be needed } _listBox.RightToLeft = RightToLeft; } }