Exemple #1
0
        /// <summary>
        /// Initialize a new instance of the CheckBoxController class.
        /// </summary>
        /// <param name="target">Target for state changes.</param>
        /// <param name="top">Top element for the check box control.</param>
        /// <param name="needPaint">Delegate for notifying paint requests.</param>
        public CheckBoxController(ViewDrawCheckBox target,
                                  ViewBase top,
                                  NeedPaintHandler needPaint)
        {
            Debug.Assert(target != null);
            Debug.Assert(top != null);

            // Store the provided paint notification delegate
            NeedPaint = needPaint;

            // Remember target for state changes
            _target = target;
            _top    = top;
        }
        /// <summary>
        /// Initialize a new instance of the KryptonCheckBox class.
        /// </summary>
        public KryptonCheckBox()
        {
            // Turn off standard click and double click events, we do that manually
            SetStyle(ControlStyles.StandardClick |
                     ControlStyles.StandardDoubleClick, false);

            // Set default properties
            _style         = LabelStyle.NormalControl;
            _orientation   = VisualOrientation.Top;
            _checkPosition = VisualOrientation.Left;
            _checked       = false;
            _threeState    = false;
            _checkState    = CheckState.Unchecked;
            _useMnemonic   = true;
            AutoCheck      = true;

            // Create content storage
            Values              = new LabelValues(NeedPaintDelegate);
            Values.TextChanged += OnCheckBoxTextChanged;
            Images              = new CheckBoxImages(NeedPaintDelegate);

            // Create palette redirector
            _paletteCommonRedirect = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalControl);
            _paletteCheckBoxImages = new PaletteRedirectCheckBox(Redirector, Images);

            // Create the palette provider
            StateCommon   = new PaletteContent(_paletteCommonRedirect, NeedPaintDelegate);
            StateDisabled = new PaletteContent(StateCommon, NeedPaintDelegate);
            StateNormal   = new PaletteContent(StateCommon, NeedPaintDelegate);
            OverrideFocus = new PaletteContent(_paletteCommonRedirect, NeedPaintDelegate);

            // Override the normal values with the focus, when the control has focus
            _overrideNormal = new PaletteContentInheritOverride(OverrideFocus, StateNormal, PaletteState.FocusOverride, false);

            // Our view contains background and border with content inside
            _drawContent = new ViewDrawContent(_overrideNormal, this, VisualOrientation.Top)
            {
                UseMnemonic = _useMnemonic,

                // Only draw a focus rectangle when focus cues are needed in the top level form
                TestForFocusCues = true
            };

            // Create the check box image drawer and place inside element so it is always centered
            _drawCheckBox = new ViewDrawCheckBox(_paletteCheckBoxImages)
            {
                CheckState = _checkState
            };
            _layoutCenter = new ViewLayoutCenter
            {
                _drawCheckBox
            };

            // Place check box on the left and the label in the remainder
            _layoutDocker = new ViewLayoutDocker
            {
                { _layoutCenter, ViewDockStyle.Left },
                { _drawContent, ViewDockStyle.Fill }
            };

            // Need a controller for handling mouse input
            _controller                   = new CheckBoxController(_drawCheckBox, _layoutDocker, NeedPaintDelegate);
            _controller.Click            += OnControllerClick;
            _controller.Enabled           = true;
            _layoutDocker.MouseController = _controller;
            _layoutDocker.KeyController   = _controller;

            // Change the layout to match the inital right to left setting and orientation
            UpdateForOrientation();

            // Create the view manager instance
            ViewManager = new ViewManager(this, _layoutDocker);

            // We want to be auto sized by default, but not the property default!
            AutoSize     = true;
            AutoSizeMode = AutoSizeMode.GrowAndShrink;
        }
        /// <summary>
        /// Initialize a new instance of the ViewDrawMenuCheckBox class.
        /// </summary>
        /// <param name="provider">Reference to provider.</param>
        /// <param name="checkBox">Reference to owning check box entry.</param>
        public ViewDrawMenuCheckBox(IContextMenuProvider provider,
                                    KryptonContextMenuCheckBox checkBox)
        {
            _provider = provider;
            KryptonContextMenuCheckBox = checkBox;

            // Create fixed storage of the content values
            _contentValues = new FixedContentValue(ResolveText,
                                                   ResolveExtraText,
                                                   ResolveImage,
                                                   ResolveImageTransparentColor);

            // Decide on the enabled state of the display
            ItemEnabled = provider.ProviderEnabled && ResolveEnabled;

            // Give the heading object the redirector to use when inheriting values
            KryptonContextMenuCheckBox.SetPaletteRedirect(provider.ProviderRedirector);

            // Create the content for the actual heading text/image
            ViewDrawContent = new ViewDrawContent((ItemEnabled ? KryptonContextMenuCheckBox.OverrideNormal : KryptonContextMenuCheckBox.OverrideDisabled),
                                                  _contentValues, VisualOrientation.Top)
            {
                UseMnemonic = true,
                Enabled     = ItemEnabled
            };

            // Create the check box image drawer and place inside element so it is always centered
            ViewDrawCheckBox = new ViewDrawCheckBox(KryptonContextMenuCheckBox.StateCheckBoxImages)
            {
                CheckState = ResolveCheckState,
                Enabled    = ItemEnabled
            };
            _layoutCenter = new ViewLayoutCenter
            {
                ViewDrawCheckBox
            };

            // Place the check box on the left of the available space but inside separators
            _innerDocker = new ViewLayoutDocker
            {
                { ViewDrawContent, ViewDockStyle.Fill },
                { _layoutCenter, ViewDockStyle.Left },
                { new ViewLayoutSeparator(1), ViewDockStyle.Right },
                { new ViewLayoutSeparator(3), ViewDockStyle.Left },
                { new ViewLayoutSeparator(1), ViewDockStyle.Top },
                { new ViewLayoutSeparator(1), ViewDockStyle.Bottom }
            };

            // Use outer docker so that any extra space not needed is used by the null
            _outerDocker = new ViewLayoutDocker
            {
                { _innerDocker, ViewDockStyle.Top },
                { new ViewLayoutNull(), ViewDockStyle.Fill }
            };

            // Use context menu specific version of the check box controller
            MenuCheckBoxController mcbc = new MenuCheckBoxController(provider.ProviderViewManager, _innerDocker, this, provider.ProviderNeedPaintDelegate);

            mcbc.Click += OnClick;
            _innerDocker.MouseController = mcbc;
            _innerDocker.KeyController   = mcbc;

            // Add docker as the composite content
            Add(_outerDocker);

            // Want to know when a property changes whilst displayed
            KryptonContextMenuCheckBox.PropertyChanged += OnPropertyChanged;

            // We need to know if a property of the command changes
            if (KryptonContextMenuCheckBox.KryptonCommand != null)
            {
                _cachedCommand = KryptonContextMenuCheckBox.KryptonCommand;
                KryptonContextMenuCheckBox.KryptonCommand.PropertyChanged += OnCommandPropertyChanged;
            }
        }