Ejemplo n.º 1
0
        private void NotifyNeedTextW(ref Message message)
        {
            if ((this.Style != CommandBarStyle.Menu) && (Marshal.SystemDefaultCharSize == 2))
            {
                // this code is a duplicate of NotifyNeedTextA
                NativeMethods.TOOLTIPTEXT toolTipText = (NativeMethods.TOOLTIPTEXT)message.GetLParam(typeof(NativeMethods.TOOLTIPTEXT));
                CommandBarItem            item        = (CommandBarItem)items[toolTipText.hdr.idFrom];
                toolTipText.szText = item.Text;

                CommandBarButtonBase buttonBase = item as CommandBarButton;
                if ((buttonBase != null) && (buttonBase.Shortcut != Keys.None))
                {
                    toolTipText.szText += " (" + TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(null, CultureInfo.InvariantCulture, buttonBase.Shortcut) + ")";
                }

                toolTipText.hinst = IntPtr.Zero;
                if (RightToLeft == RightToLeft.Yes)
                {
                    toolTipText.uFlags |= NativeMethods.TTF_RTLREADING;
                }

                Marshal.StructureToPtr(toolTipText, message.LParam, true);
                message.Result = (IntPtr)1;
            }
        }
        // TODO
        internal CommandBarItem[] this[Keys shortcut]
        {
            get
            {
                ArrayList list = new ArrayList();

                foreach (CommandBarItem item in items)
                {
                    CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
                    if (buttonBase != null)
                    {
                        if ((buttonBase.Shortcut == shortcut) && (buttonBase.IsEnabled) && (buttonBase.IsVisible))
                        {
                            list.Add(buttonBase);
                        }
                    }
                }

                foreach (CommandBarItem item in items)
                {
                    CommandBarMenu menu = item as CommandBarMenu;
                    if (menu != null)
                    {
                        list.AddRange(menu.Items[shortcut]);
                    }
                }

                CommandBarItem[] array = new CommandBarItem[list.Count];
                list.CopyTo(array, 0);
                return(array);
            }
        }
            protected override void OnDrawItem(DrawItemEventArgs e)
            {
                base.OnDrawItem(e);

                Graphics  graphics = e.Graphics;
                Rectangle bounds   = e.Bounds;

                bool selected = ((e.State & DrawItemState.Selected) != 0);
                bool disabled = ((e.State & DrawItemState.Disabled) != 0);

                if (item is CommandBarSeparator)
                {
                    Rectangle r = new Rectangle(bounds.X, bounds.Y + (bounds.Height / 2), bounds.Width, bounds.Height);
                    ControlPaint.DrawBorder3D(graphics, r, Border3DStyle.Etched, Border3DSide.Top);
                }
                else
                {
                    this.DrawImage(graphics, bounds, selected, disabled);

                    int width = 6 + imageSize.Width;
                    this.DrawBackground(graphics, new Rectangle(bounds.X + width, bounds.Y, bounds.Width - width, bounds.Height), selected);

                    using (TextGraphics textGraphics = new TextGraphics(graphics))
                    {
                        if ((this.Text != null) && (this.Text.Length != 0))
                        {
                            Size  size  = textGraphics.MeasureText(this.Text, font);
                            Point point = new Point();
                            point.X = bounds.X + 3 + imageSize.Width + 6;
                            point.Y = bounds.Y + ((bounds.Height - size.Height) / 2);
                            this.DrawText(textGraphics, this.Text, point, selected, disabled);
                        }

                        CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
                        if ((buttonBase != null) && (buttonBase.Shortcut != Keys.None))
                        {
                            string text = TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(null, CultureInfo.InvariantCulture, buttonBase.Shortcut);

                            Size size = textGraphics.MeasureText(text, font);

                            Point point = new Point();
                            point.X = bounds.X + bounds.Width - 3 - imageSize.Width - 3 - size.Width;
                            point.Y = bounds.Y + ((bounds.Height - size.Height) / 2);
                            this.DrawText(textGraphics, text, point, selected, disabled);
                        }
                    }
                }
            }
            protected override void OnMeasureItem(MeasureItemEventArgs e)
            {
                base.OnMeasureItem(e);
                Graphics graphics = e.Graphics;

                if (item is CommandBarSeparator)
                {
                    e.ItemWidth  = 0;
                    e.ItemHeight = SystemInformation.MenuHeight / 2;
                }
                else
                {
                    Size size = new Size(0, 0);
                    size.Width  += 3 + imageSize.Width + 3 + 3 + 1 + 3 + imageSize.Width + 3;
                    size.Height += 3 + imageSize.Height + 3;

                    string text = item.Text;

                    CommandBarButtonBase buttonBase = item as CommandBarButtonBase;
                    if ((buttonBase != null) && (buttonBase.Shortcut != Keys.None))
                    {
                        text += TypeDescriptor.GetConverter(typeof(Keys)).ConvertToString(null, CultureInfo.InvariantCulture, buttonBase.Shortcut);
                    }

                    using (TextGraphics textGraphics = new TextGraphics(graphics))
                    {
                        Size textSize = textGraphics.MeasureText(text, font);
                        size.Width      += textSize.Width;
                        textSize.Height += 8;
                        if (textSize.Height > size.Height)
                        {
                            size.Height = textSize.Height;
                        }
                    }

                    e.ItemWidth  = size.Width;
                    e.ItemHeight = size.Height;
                }
            }