Exemple #1
0
 protected void ComputeTypeButtonsNeeded(List <ListItem> listItems)
 {
     // set the type buttons needed
     if (TypeImages == null)
     {
         TypeImages = new Dictionary <int, Image>();
     }
     else
     {
         TypeImages.Clear();
     }
     if (TypeText == null)
     {
         TypeText = new Dictionary <int, string>();
     }
     else
     {
         TypeText.Clear();
     }
     _typeList.Clear();
     foreach (var item in listItems.Cast <FilteredTypeListItem>().Where(item => item.ItemType >= 0))
     {
         if (!TypeImages.ContainsKey(item.ItemType))
         {
             _typeList.Add(item.ItemType);
             TypeImages.Add(item.ItemType, item.ItemTypeImage);
             TypeText.Add(item.ItemType, item.ItemTypeText);
         }
     }
 }
Exemple #2
0
        /// <summary>
        /// Overriding DrawButtons to add the Type selector buttons
        /// </summary>
        protected override void DrawButtons()
        {
            base.DrawButtons();

            if (BottomHeight == 0)
            {
                return;
            }

            int maxWidthForTypeButtons = Width - BottomPadding * 3 - _itemsNbLabelWidth - 10;

            _nbDisplayableTypeButton = (int)Math.Floor((decimal)maxWidthForTypeButtons / TypeButtonWidth);
            _nbDisplayableTypeButton = _nbDisplayableTypeButton.ClampMax(_typeList.Count);
            var buttonsToDisplay = _typeList.Count;

            // for each distinct type of items, create the buttons
            int xPos = BottomPadding;
            int nBut = 0;

            foreach (var type in _typeList)
            {
                // new type, add a button for it
                if (!_typeButtons.ContainsKey(type))
                {
                    _typeButtons.Add(type, new SelectorButton {
                        Size                 = new Size(TypeButtonWidth, DefaultBottomHeight),
                        TabStop              = false,
                        AcceptsAnyClick      = true,
                        HideFocusedIndicator = true,
                        Activated            = true,
                        BackGrndImage        = TypeImages.ContainsKey(type) ? TypeImages[type] : null
                    });
                    _typeButtons[type].ButtonPressed += HandleTypeClick;
                    _tooltip.SetToolTip(_typeButtons[type], (TypeText.ContainsKey(type) && TypeText[type] != null ? TypeText[type] + "<br>" : "") + TypeButtonTooltipText);
                }

                _typeButtons[type].Anchor    = AnchorStyles.Left | AnchorStyles.Bottom;
                _typeButtons[type].Type      = type;
                _typeButtons[type].Activated = _typeButtons[type].Activated;
                _typeButtons[type].Location  = new Point(xPos, Height - BottomHeight / 2 - _typeButtons[type].Height / 2);
                nBut++;

                // show as many button as we can show - 1
                if (nBut < _nbDisplayableTypeButton || buttonsToDisplay == _nbDisplayableTypeButton)
                {
                    xPos += TypeButtonWidth;
                    if (!Controls.Contains(_typeButtons[type]))
                    {
                        Controls.Add(_typeButtons[type]);
                    }
                }
                else
                {
                    if (Controls.Contains(_typeButtons[type]))
                    {
                        Controls.Remove(_typeButtons[type]);
                    }
                }
            }

            // remove buttons that are no longer used
            var tmpDic = new Dictionary <int, SelectorButton>();

            foreach (int key in _typeButtons.Keys)
            {
                if (!_typeList.Contains(key))
                {
                    if (Controls.Contains(_typeButtons[key]))
                    {
                        Controls.Remove(_typeButtons[key]);
                    }
                }
                else
                {
                    tmpDic.Add(key, _typeButtons[key]);
                }
            }
            _typeButtons = tmpDic;

            if (nBut > 0 && buttonsToDisplay > _nbDisplayableTypeButton)
            {
                // we display a "more button" that opens a small interface to show the extra buttons
                if (_moreButton == null)
                {
                    _moreButton = new SelectorButton {
                        BackGrndImage        = MoreTypesImage ?? Resources.Resources.More,
                        Activated            = true,
                        Size                 = new Size(TypeButtonWidth, DefaultBottomHeight),
                        TabStop              = false,
                        Anchor               = AnchorStyles.Left | AnchorStyles.Bottom,
                        HideFocusedIndicator = true
                    };
                    _moreButton.ButtonPressed += HandleMoreTypeClick;
                    _tooltip.SetToolTip(_moreButton, MoreButtonTooltipText);
                }

                _moreButton.Location = new Point(xPos, Height - BottomHeight / 2 - _moreButton.Height / 2);
                if (!Controls.Contains(_moreButton))
                {
                    Controls.Add(_moreButton);
                }
            }
            else
            {
                // if we have enough space to display the last button, hide the more button
                // remove the more button if it exists
                if (_moreButton != null)
                {
                    if (Controls.Contains(_moreButton))
                    {
                        Controls.Remove(_moreButton);
                    }
                }
            }
        }