Exemple #1
0
        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);
        }
Exemple #2
0
        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;
            }
        }