Exemplo n.º 1
0
        /// <summary>
        /// Initialize a new instance of the KryptonLinkLabel class.
        /// </summary>
        public KryptonLinkLabel()
        {
            // The link label cannot take the focus
            SetStyle(ControlStyles.Selectable, true);

            // Turn off the target functionality present in the base class
            EnabledTarget = false;

            // Create the override states that redirect without inheriting
            _stateVisitedRedirect    = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalControl);
            _stateNotVisitedRedirect = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalControl);
            _statePressedRedirect    = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalControl);
            _stateFocusRedirect      = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalControl);
            OverrideVisited          = new PaletteContent(_stateVisitedRedirect, NeedPaintDelegate);
            OverrideNotVisited       = new PaletteContent(_stateNotVisitedRedirect, NeedPaintDelegate);
            OverrideFocus            = new PaletteContent(_stateFocusRedirect, NeedPaintDelegate);
            OverridePressed          = new PaletteContent(_statePressedRedirect, NeedPaintDelegate);

            // Override the normal state to implement the underling logic
            _inheritBehavior = new LinkLabelBehaviorInherit(StateNormal, KryptonLinkBehavior.AlwaysUnderline);

            // Create the override handling classes
            _overrideVisited         = new PaletteContentInheritOverride(OverrideVisited, _inheritBehavior, PaletteState.LinkVisitedOverride, false);
            _overrideNotVisited      = new PaletteContentInheritOverride(OverrideNotVisited, _overrideVisited, PaletteState.LinkNotVisitedOverride, true);
            _overrideFocusNotVisited = new PaletteContentInheritOverride(OverrideFocus, _overrideNotVisited, PaletteState.FocusOverride, false);
            _overridePressed         = new PaletteContentInheritOverride(OverridePressed, _inheritBehavior, PaletteState.LinkPressedOverride, false);
            _overridePressedFocus    = new PaletteContentInheritOverride(OverrideFocus, _overridePressed, PaletteState.FocusOverride, false);

            // Create controller for updating the view state/click events
            _controller        = new LinkLabelController(ViewDrawContent, StateDisabled, _overrideFocusNotVisited, _overrideFocusNotVisited, _overridePressedFocus, _overridePressed, NeedPaintDelegate);
            _controller.Click += OnControllerClick;
            ViewDrawContent.MouseController  = _controller;
            ViewDrawContent.KeyController    = _controller;
            ViewDrawContent.SourceController = _controller;

            // Set initial palette for drawing the content
            ViewDrawContent.SetPalette(_overrideFocusNotVisited);
        }
        /// <summary>
        /// Discover the preferred size of the element.
        /// </summary>
        /// <param name="context">Layout context.</param>
        public override Size GetPreferredSize(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // Update text and image values
            _contentValues.ShortText             = ResolveText;
            _contentValues.LongText              = ResolveExtraText;
            _contentValues.Image                 = ResolveImage;
            _contentValues.ImageTransparentColor = ResolveImageTransparentColor;

            // Find new enabled state
            ItemEnabled = _provider.ProviderEnabled && ResolveEnabled;

            // Update with enabled state
            ViewDrawContent.SetPalette(ItemEnabled ? KryptonContextMenuCheckBox.OverrideNormal : KryptonContextMenuCheckBox.OverrideDisabled);
            ViewDrawContent.Enabled  = ItemEnabled;
            ViewDrawCheckBox.Enabled = ItemEnabled;

            // Update the checked state
            ViewDrawCheckBox.CheckState = ResolveCheckState;

            return(base.GetPreferredSize(context));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Discover the preferred size of the element.
        /// </summary>
        /// <param name="context">Layout context.</param>
        /// <exception cref="ArgumentNullException"></exception>
        public override Size GetPreferredSize(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // Always update to the latest correct check state
            if (_imageCanvas != null)
            {
                if (ResolveChecked)
                {
                    _imageCanvas.ElementState = PaletteState.CheckedNormal;
                    _imageCanvas.Enabled      = ResolveEnabled;
                }
                else
                {
                    _imageCanvas.ElementState = PaletteState.Normal;
                    _imageCanvas.Enabled      = true;
                }
            }

            PaletteDouble splitPalette;

            // Make sure we are using the correct palette for state
            switch (State)
            {
            default:
            case PaletteState.Normal:
                SetPalettes(KryptonContextMenuItem.StateNormal.ItemHighlight.Back,
                            KryptonContextMenuItem.StateNormal.ItemHighlight.Border,
                            KryptonContextMenuItem.StateNormal.ItemHighlight);
                splitPalette = KryptonContextMenuItem.StateNormal.ItemSplit;
                break;

            case PaletteState.Disabled:
                SetPalettes(KryptonContextMenuItem.StateDisabled.ItemHighlight.Back,
                            KryptonContextMenuItem.StateDisabled.ItemHighlight.Border,
                            KryptonContextMenuItem.StateDisabled.ItemHighlight);
                splitPalette = KryptonContextMenuItem.StateDisabled.ItemSplit;
                break;

            case PaletteState.Tracking:
                SetPalettes(KryptonContextMenuItem.StateHighlight.ItemHighlight.Back,
                            KryptonContextMenuItem.StateHighlight.ItemHighlight.Border,
                            KryptonContextMenuItem.StateHighlight.ItemHighlight);
                splitPalette = KryptonContextMenuItem.StateHighlight.ItemSplit;
                break;
            }


            // Validate incoming reference
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // If we have image display
            if (_fixedImage != null)
            {
                Image itemColumnImage      = ResolveImage;
                Color itemImageTransparent = ResolveImageTransparentColor;

                // If no image found then...
                if (itemColumnImage == null)
                {
                    // Ensure we have a fixed size if we are showing an image column
                    if (_imageColumn)
                    {
                        itemColumnImage      = _empty16x16;
                        itemImageTransparent = Color.Magenta;
                    }

                    switch (ResolveCheckState)
                    {
                    case CheckState.Checked:
                        itemColumnImage      = _provider.ProviderImages.GetContextMenuCheckedImage();
                        itemImageTransparent = Color.Empty;
                        break;

                    case CheckState.Indeterminate:
                        itemColumnImage      = _provider.ProviderImages.GetContextMenuIndeterminateImage();
                        itemImageTransparent = Color.Empty;
                        break;
                    }
                }

                // Decide on the enabled state of the display
                ItemEnabled = _provider.ProviderEnabled && ResolveEnabled;
                PaletteContextMenuItemState menuItemState = (ItemEnabled ? KryptonContextMenuItem.StateNormal : KryptonContextMenuItem.StateDisabled);

                // Update palettes based on Checked state
                PaletteTripleJustImage justImage = (ResolveChecked ? KryptonContextMenuItem.StateChecked.ItemImage : menuItemState.ItemImage);
                _imageCanvas?.SetPalettes(justImage.Back, justImage.Border);

                // Update the Enabled state
                _imageContent.SetPalette(justImage.Content);
                _imageContent.Enabled   = ItemEnabled;
                _textContent.Enabled    = ItemEnabled;
                SplitSeparator.Enabled  = ItemEnabled;
                _subMenuContent.Enabled = ItemEnabled;
                if (_shortcutContent != null)
                {
                    _shortcutContent.Enabled = ItemEnabled;
                }

                // Update the Text/ExtraText
                _fixedTextExtraText.ShortText = ResolveText;
                _fixedTextExtraText.LongText  = ResolveExtraText;

                // Update the Image
                _fixedImage.Image = itemColumnImage;
                _fixedImage.ImageTransparentColor = itemImageTransparent;
            }

            SplitSeparator?.SetPalettes(splitPalette.Back, splitPalette.Border);

            return(base.GetPreferredSize(context));
        }