public ButtonStates(VisualStudioFormChrome parent)
            {
                bool drawMinimize = false;
                bool drawMaximizeRestore = false;
                bool drawClose = false;
                bool enableMinimize = false;
                bool enableMaximizeRestore = false;
                bool enableClose = false;

                if (parent.Form.ControlBox)
                {
                    DrawIcon = parent.GetFormIcon() != null && parent.Form.ShowIcon;
                    drawClose = true;
                    drawMinimize = drawMaximizeRestore = parent.Form.MinimizeBox || parent.Form.MaximizeBox;
                    enableMinimize = parent.Form.MinimizeBox;
                    enableMaximizeRestore = parent.Form.MaximizeBox;
                    enableClose = CanClose(parent);
                }

                var rightOffset =
                    parent.Form.Width -
                    parent.FormChrome.AdjustedResizeBorderThickness.Left;

                if (drawClose)
                    Close = GetButtonState(parent, ref rightOffset, ChromeButton.Close, enableClose);
                else
                    Close = new ButtonState(ChromeButton.Close);
                if (drawMaximizeRestore)
                    MaximizeRestore = GetButtonState(parent, ref rightOffset, ChromeButton.MaximizeRestore, enableMaximizeRestore);
                if (drawMinimize)
                    Minimize = GetButtonState(parent, ref rightOffset, ChromeButton.Minimize, enableMinimize);

                RightOffset = rightOffset;
            }
            public HResult SetEnabled(bool enabled)
            {
                try
                {
                    if (enabled != _enabled)
                    {
                        _enabled = enabled;

                        if (_enabled)
                        {
                            FormChrome = new VisualStudioFormChrome();
                            FormChrome.BorderColor = _color;
                            FormChrome.PrimaryColor = _color;
                            FormChrome.ContainerControl = _mainForm;

                            // Buttons may have been added before the chrome was
                            // available. Trigger the title bar button manager
                            // to actually create the buttons.

                            ((NiTitleBarButtonManager)GetService(typeof(INiTitleBarButtonManager))).RebuildButtons();
                        }
                        else
                        {
                            FormChrome.Dispose();
                            FormChrome = null;
                        }
                    }

                    return HResult.OK;
                }
                catch (Exception ex)
                {
                    return ErrorUtil.GetHResult(ex);
                }
            }
Example #3
0
        public VisualStudioButtonCollection(VisualStudioFormChrome chrome)
        {
            if (chrome == null)
            {
                throw new ArgumentNullException("chrome");
            }

            _chrome = chrome;
        }
            private bool CanClose(VisualStudioFormChrome parent)
            {
                if (!parent.Form.IsHandleCreated)
                {
                    return(false);
                }

                uint menuState = NativeMethods.GetMenuState(
                    NativeMethods.GetSystemMenu(parent.Form.Handle, false),
                    NativeMethods.SC_CLOSE,
                    NativeMethods.MF_BYCOMMAND
                    );

                return((menuState & (NativeMethods.MF_GRAYED | NativeMethods.MF_DISABLED)) == 0);
            }
            public ButtonStates(VisualStudioFormChrome parent)
            {
                bool drawMinimize          = false;
                bool drawMaximizeRestore   = false;
                bool drawClose             = false;
                bool enableMinimize        = false;
                bool enableMaximizeRestore = false;
                bool enableClose           = false;

                if (parent.Form.ControlBox)
                {
                    DrawIcon              = parent.GetFormIcon() != null && parent.Form.ShowIcon;
                    drawClose             = true;
                    drawMinimize          = drawMaximizeRestore = parent.Form.MinimizeBox || parent.Form.MaximizeBox;
                    enableMinimize        = parent.Form.MinimizeBox;
                    enableMaximizeRestore = parent.Form.MaximizeBox;
                    enableClose           = CanClose(parent);
                }

                var rightOffset =
                    parent.Form.Width -
                    parent._formChrome.AdjustedResizeBorderThickness.Left;

                if (drawClose)
                {
                    Close = GetButtonState(parent, ref rightOffset, ChromeButton.Close, enableClose, null);
                }
                else
                {
                    Close = new ButtonState(ChromeButton.Close);
                }
                if (drawMaximizeRestore)
                {
                    MaximizeRestore = GetButtonState(parent, ref rightOffset, ChromeButton.MaximizeRestore, enableMaximizeRestore, null);
                }
                if (drawMinimize)
                {
                    Minimize = GetButtonState(parent, ref rightOffset, ChromeButton.Minimize, enableMinimize, null);
                }

                ProcessExtraButtons(parent, ref rightOffset);

                RightOffset = rightOffset;
            }
            private void ProcessExtraButtons(VisualStudioFormChrome parent, ref int rightOffset)
            {
                ExtraButtons = new List <ButtonState>(parent.Buttons.Count);

                for (int i = parent.Buttons.Count - 1; i >= 0; i--)
                {
                    var extraButton = parent.Buttons[i];
                    if (!extraButton.Visible)
                    {
                        continue;
                    }

                    ExtraButtons.Insert(
                        0,
                        GetButtonState(
                            parent,
                            ref rightOffset,
                            ChromeButton.None,
                            extraButton.Enabled,
                            extraButton
                            )
                        );
                }
            }
            private void ProcessExtraButtons(VisualStudioFormChrome parent, ref int rightOffset)
            {
                ExtraButtons = new List<ButtonState>(parent.Buttons.Count);

                for (int i = parent.Buttons.Count - 1; i >= 0; i--)
                {
                    var extraButton = parent.Buttons[i];
                    if (!extraButton.Visible)
                        continue;

                    ExtraButtons.Insert(
                        0,
                        GetButtonState(
                            parent,
                            ref rightOffset,
                            ChromeButton.None,
                            extraButton.Enabled,
                            extraButton
                        )
                    );
                }
            }
            private ButtonState GetButtonState(VisualStudioFormChrome parent, ref int offset, ChromeButton button, bool enabled, VisualStudioButton extraButton)
            {
                offset -= ButtonSize.Width;

                var bounds = new Rectangle(
                    offset,
                    parent._formChrome.AdjustedResizeBorderThickness.Top,
                    ButtonSize.Width,
                    ButtonSize.Height
                );

                var location = parent._formChrome.PointToClient(Cursor.Position);
                bool over = bounds.Contains(location);

                ChromeButtonState state;

                if (!enabled)
                {
                    state = ChromeButtonState.Disabled;
                }
                else if (parent.CaptureStart.HasValue)
                {
                    if (bounds.Contains(parent.CaptureStart.Value))
                        state = over ? ChromeButtonState.Down : ChromeButtonState.Over;
                    else
                        state = ChromeButtonState.Enabled;
                }
                else
                {
                    state = over ? ChromeButtonState.Over : ChromeButtonState.Enabled;
                }

                if (extraButton != null)
                {
                    extraButton.IsOver = false;
                    extraButton.IsDown = false;
                }

                if (state == ChromeButtonState.Over)
                {
                    OverButton = button;
                    OverExtraButton = extraButton;
                    if (extraButton != null)
                        extraButton.IsOver = true;
                }
                else if (state == ChromeButtonState.Down)
                {
                    DownButton = button;
                    DownExtraButton = extraButton;
                    if (extraButton != null)
                        extraButton.IsDown = true;
                }

                return new ButtonState(button, state, true, bounds, extraButton);
            }
            private bool CanClose(VisualStudioFormChrome parent)
            {
                if (!parent.Form.IsHandleCreated)
                    return false;

                uint menuState = NativeMethods.GetMenuState(
                    NativeMethods.GetSystemMenu(parent.Form.Handle, false),
                    NativeMethods.SC_CLOSE,
                    NativeMethods.MF_BYCOMMAND
                );

                return (menuState & (NativeMethods.MF_GRAYED | NativeMethods.MF_DISABLED)) == 0;
            }
            private ButtonState GetButtonState(VisualStudioFormChrome parent, ref int offset, ChromeButton button, bool enabled, VisualStudioButton extraButton)
            {
                offset -= ButtonSize.Width;

                var bounds = new Rectangle(
                    offset,
                    parent._formChrome.AdjustedResizeBorderThickness.Top,
                    ButtonSize.Width,
                    ButtonSize.Height
                    );

                var  location = parent._formChrome.PointToClient(Cursor.Position);
                bool over     = bounds.Contains(location);

                ChromeButtonState state;

                if (!enabled)
                {
                    state = ChromeButtonState.Disabled;
                }
                else if (parent.CaptureStart.HasValue)
                {
                    if (bounds.Contains(parent.CaptureStart.Value))
                    {
                        state = over ? ChromeButtonState.Down : ChromeButtonState.Over;
                    }
                    else
                    {
                        state = ChromeButtonState.Enabled;
                    }
                }
                else
                {
                    state = over ? ChromeButtonState.Over : ChromeButtonState.Enabled;
                }

                if (extraButton != null)
                {
                    extraButton.IsOver = false;
                    extraButton.IsDown = false;
                }

                if (state == ChromeButtonState.Over)
                {
                    OverButton      = button;
                    OverExtraButton = extraButton;
                    if (extraButton != null)
                    {
                        extraButton.IsOver = true;
                    }
                }
                else if (state == ChromeButtonState.Down)
                {
                    DownButton      = button;
                    DownExtraButton = extraButton;
                    if (extraButton != null)
                    {
                        extraButton.IsDown = true;
                    }
                }

                return(new ButtonState(button, state, true, bounds, extraButton));
            }