internal void SetMonitorElements(TrayMenuMonitorItemControl control)
 {
     if (null == control)
     {
         throw new ArgumentNullException("control");
     }
     _control = control;
 }
Example #2
0
        /// <summary>
        /// Notify a new item has been added
        /// </summary>
        /// <param name="parentItem">parent item instance or null</param>
        /// <param name="item">new created item</param>
        internal void OnItemAdded(TrayMenuItem parentItem, TrayMenuItem item)
        {
            ToolStripItem newItem = null;

            switch (item.ItemType)
            {
            case TrayMenuItemType.Item:
                newItem = new ToolStripMenuItem();
                break;

            case TrayMenuItemType.Label:
                newItem = new ToolStripLabel();
                break;

            case TrayMenuItemType.LinkLabel:
                newItem = new ToolStripLabel();
                (newItem as ToolStripLabel).IsLink       = true;
                (newItem as ToolStripLabel).LinkBehavior = LinkBehavior.AlwaysUnderline;
                break;

            case TrayMenuItemType.Button:
                newItem = new ToolStripButton();
                break;

            case TrayMenuItemType.TextBox:
                newItem = new ToolStripTextBox();
                (newItem as ToolStripTextBox).TextChanged += ToolStripTextBox_TextChanged;
                break;

            case TrayMenuItemType.CheckBox:
                newItem = new ToolStripMenuItem();
                (newItem as ToolStripMenuItem).CheckOnClick    = true;
                (newItem as ToolStripMenuItem).CheckedChanged += ToolStripItem_CheckedChanged;
                break;

            case TrayMenuItemType.Progress:
                newItem = new ToolStripProgressBar();
                (item as TrayMenuProgressItem).SetProgressElements((newItem as ToolStripProgressBar).Minimum, (newItem as ToolStripProgressBar).Maximum, (newItem as ToolStripProgressBar).Value, (TrayMenuProgressItem.ProgressBarStyle)(newItem as ToolStripProgressBar).Style);
                break;

            case TrayMenuItemType.DropDownList:
                newItem = new ToolStripComboBox();
                (newItem as ToolStripComboBox).DropDownStyle         = ComboBoxStyle.DropDownList;
                (newItem as ToolStripComboBox).TextChanged          += ToolStripComboBox_TextChanged;
                (newItem as ToolStripComboBox).SelectedIndexChanged += ToolStripComboBox_SelectedIndexChanged;
                (item as TrayMenuDropDownListItem).SetupDropDownElements((newItem as ToolStripComboBox).DropDownHeight);
                break;

            case TrayMenuItemType.Separator:
                newItem = new ToolStripSeparator();
                break;

            case TrayMenuItemType.Custom:
                newItem = new ToolStripControlHost((System.Windows.Forms.Control)(item as TrayMenuCustomItem).Control);
                break;

            case TrayMenuItemType.Monitor:
                TrayMenuMonitorItemControl control = new TrayMenuMonitorItemControl(_addin);
                newItem = new ToolStripControlHost(control);
                (item as TrayMenuMonitorItem).SetMonitorElements(control);
                break;

            case TrayMenuItemType.AutoClose:
                newItem = new ToolStripMenuItem();
                (newItem as ToolStripMenuItem).CheckOnClick    = true;
                (newItem as ToolStripMenuItem).Checked         = AutoClose;
                (newItem as ToolStripMenuItem).CheckedChanged += ToolAutoCloseStripItem_CheckedChanged;
                break;

            case TrayMenuItemType.Close:
                newItem = new ToolStripMenuItem();
                (newItem as ToolStripMenuItem).Click += ToolCloseStripItem_Click;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            newItem.Tag         = item;
            newItem.Text        = item.Text;
            newItem.ToolTipText = item.ToolTipText;
            newItem.Image       = item.Image;
            newItem.BackColor   = item.BackColor;
            newItem.ForeColor   = item.ForeColor;
            newItem.Visible     = item.Visible;
            newItem.Padding     = item.Padding;
            newItem.Enabled     = item.Enabled;
            item.SetupElements(newItem.Font, newItem.TextAlign, newItem.ImageAlign, item.Padding);

            ToolStripControlHost stripHost = newItem as ToolStripControlHost;

            if (null != stripHost)
            {
                stripHost.KeyDown  += StripHost_KeyDown;
                stripHost.KeyPress += StripHost_KeyPress;
                stripHost.KeyUp    += StripHost_KeyUp;
            }

            if (null != parentItem)
            {
                ToolStripDropDownItem parentStrip = Find(parentItem) as ToolStripDropDownItem;
                if (null != parentStrip)
                {
                    parentStrip.DropDownItems.Add(newItem);
                }
            }
            else
            {
                _contextMenu.Items.Add(newItem);
            }

            newItem.Click += ToolStripItem_Click;
        }