/// <summary> /// Initialize a new instance of the ViewDrawMenuRadioButton class. /// </summary> /// <param name="provider">Reference to provider.</param> /// <param name="radioButton">Reference to owning radio button entry.</param> public ViewDrawMenuRadioButton(IContextMenuProvider provider, KryptonContextMenuRadioButton radioButton) { _provider = provider; _radioButton = radioButton; // Create fixed storage of the content values _contentValues = new FixedContentValue(radioButton.Text, radioButton.ExtraText, radioButton.Image, radioButton.ImageTransparentColor); // Decide on the enabled state of the display _itemEnabled = provider.ProviderEnabled && _radioButton.Enabled; // Give the heading object the redirector to use when inheriting values _radioButton.SetPaletteRedirect(provider.ProviderRedirector); // Create the content for the actual heading text/image _drawContent = new ViewDrawContent((_itemEnabled ? (IPaletteContent)_radioButton.OverrideNormal : (IPaletteContent)_radioButton.OverrideDisabled), _contentValues, VisualOrientation.Top); _drawContent.UseMnemonic = true; _drawContent.Enabled = _itemEnabled; // Create the radio button image drawer and place inside element so it is always centered _drawRadioButton = new ViewDrawRadioButton(_radioButton.StateRadioButtonImages); _drawRadioButton.CheckState = _radioButton.Checked; _drawRadioButton.Enabled = _itemEnabled; _layoutCenter = new ViewLayoutCenter(); _layoutCenter.Add(_drawRadioButton); // Place the radio button on the left of the available space but inside separators _innerDocker = new ViewLayoutDocker(); _innerDocker.Add(_drawContent, ViewDockStyle.Fill); _innerDocker.Add(_layoutCenter, ViewDockStyle.Left); _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Right); _innerDocker.Add(new ViewLayoutSeparator(3), ViewDockStyle.Left); _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Top); _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Bottom); // Use outer docker so that any extra space not needed is used by the null _outerDocker = new ViewLayoutDocker(); _outerDocker.Add(_innerDocker, ViewDockStyle.Top); _outerDocker.Add(new ViewLayoutNull(), ViewDockStyle.Fill); // Use context menu specific version of the radio button controller MenuRadioButtonController mrbc = new MenuRadioButtonController(provider.ProviderViewManager, _innerDocker, this, provider.ProviderNeedPaintDelegate); mrbc.Click += new EventHandler(OnClick); _innerDocker.MouseController = mrbc; _innerDocker.KeyController = mrbc; // We need to be notified whenever the checked state changes _radioButton.CheckedChanged += new EventHandler(OnCheckedChanged); // Add docker as the composite content Add(_outerDocker); }
/// <summary> /// Initialize a new instance of the RadioButton class. /// </summary> public KryptonRadioButton() { // 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; _useMnemonic = true; _autoCheck = true; // Create content storage _labelValues = new LabelValues(NeedPaintDelegate); _labelValues.TextChanged += new EventHandler(OnRadioButtonTextChanged); _images = new RadioButtonImages(NeedPaintDelegate); // Create palette redirector _paletteCommonRedirect = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalControl); _paletteRadioButtonImages = new PaletteRedirectRadioButton(Redirector, _images); // Create the palette provider _stateCommon = new PaletteContent(_paletteCommonRedirect, NeedPaintDelegate); _stateDisabled = new PaletteContent(_stateCommon, NeedPaintDelegate); _stateNormal = new PaletteContent(_stateCommon, NeedPaintDelegate); _stateFocus = new PaletteContent(_paletteCommonRedirect, NeedPaintDelegate); // Override the normal values with the focus, when the control has focus _overrideNormal = new PaletteContentInheritOverride(_stateFocus, _stateNormal, PaletteState.FocusOverride, false); // Our view contains background and border with content inside _drawContent = new ViewDrawContent(_overrideNormal, _labelValues, VisualOrientation.Top); _drawContent.UseMnemonic = _useMnemonic; // Only draw a focus rectangle when focus cues are needed in the top level form _drawContent.TestForFocusCues = true; // Create the check box image drawer and place inside element so it is always centered _drawRadioButton = new ViewDrawRadioButton(_paletteRadioButtonImages); _drawRadioButton.CheckState = _checked; _layoutCenter = new ViewLayoutCenter(); _layoutCenter.Add(_drawRadioButton); // Place check box on the left and the label in the remainder _layoutDocker = new ViewLayoutDocker(); _layoutDocker.Add(_layoutCenter, ViewDockStyle.Left); _layoutDocker.Add(_drawContent, ViewDockStyle.Fill); // Need a controller for handling mouse input _controller = new RadioButtonController(_drawRadioButton, _layoutDocker, NeedPaintDelegate); _controller.Click += new EventHandler(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 ButtonSpecView class. /// </summary> /// <param name="redirector">Palette redirector.</param> /// <param name="paletteMetric">Source for metric values.</param> /// <param name="metricPadding">Padding metric for border padding.</param> /// <param name="manager">Reference to owning manager.</param> /// <param name="buttonSpec">Access</param> public ButtonSpecView(PaletteRedirect redirector, IPaletteMetric paletteMetric, PaletteMetricPadding metricPadding, ButtonSpecManagerBase manager, ButtonSpec buttonSpec) { Debug.Assert(redirector != null); Debug.Assert(manager != null); Debug.Assert(buttonSpec != null); // Remember references _redirector = redirector; _manager = manager; _buttonSpec = buttonSpec; _finishDelegate = new EventHandler(OnFinishDelegate); // Create delegate for paint notifications NeedPaintHandler needPaint = new NeedPaintHandler(OnNeedPaint); // Intercept calls from the button for color remapping and instead use // the button spec defined map and the container foreground color _remapPalette = _manager.CreateButtonSpecRemap(redirector, buttonSpec); // Use a redirector to get button values directly from palette _palette = new PaletteTripleRedirect(_remapPalette, PaletteBackStyle.ButtonButtonSpec, PaletteBorderStyle.ButtonButtonSpec, PaletteContentStyle.ButtonButtonSpec, needPaint); // Create the view for displaying a button _viewButton = new ViewDrawButton(_palette, _palette, _palette, _palette, paletteMetric, this, VisualOrientation.Top, false); // Associate the view with the source component (for design time support) if (buttonSpec.AllowComponent) { _viewButton.Component = buttonSpec; } // Use a view center to place button in centre of given space _viewCenter = new ViewLayoutCenter(paletteMetric, metricPadding, VisualOrientation.Top); _viewCenter.Add(_viewButton); // Create a controller for managing button behavior ButtonSpecViewControllers controllers = CreateController(_viewButton, needPaint, new MouseEventHandler(OnClick)); _viewButton.MouseController = controllers.MouseController; _viewButton.SourceController = controllers.SourceController; _viewButton.KeyController = controllers.KeyController; // We need notifying whenever a button specification property changes _buttonSpec.ButtonSpecPropertyChanged += new PropertyChangedEventHandler(OnPropertyChanged); // Associate the button spec with the view that is drawing it _buttonSpec.SetView(_viewButton); // Finally update view with current button spec settings UpdateButtonStyle(); UpdateVisible(); UpdateEnabled(); UpdateChecked(); }
/// <summary> /// Initialize a new instance of the ViewDrawButton class. /// </summary> /// <param name="paletteDisabled">Palette source for the disabled state.</param> /// <param name="paletteNormal">Palette source for the normal state.</param> /// <param name="paletteTracking">Palette source for the tracking state.</param> /// <param name="palettePressed">Palette source for the pressed state.</param> /// <param name="paletteCheckedNormal">Palette source for the normal checked state.</param> /// <param name="paletteCheckedTracking">Palette source for the tracking checked state.</param> /// <param name="paletteCheckedPressed">Palette source for the pressed checked state.</param> /// <param name="paletteMetric">Palette source for metric values.</param> /// <param name="buttonValues">Source for content values.</param> /// <param name="orientation">Visual orientation of the content.</param> /// <param name="useMnemonic">Use mnemonics.</param> public ViewDrawButton(IPaletteTriple paletteDisabled, IPaletteTriple paletteNormal, IPaletteTriple paletteTracking, IPaletteTriple palettePressed, IPaletteTriple paletteCheckedNormal, IPaletteTriple paletteCheckedTracking, IPaletteTriple paletteCheckedPressed, IPaletteMetric paletteMetric, IContentValues buttonValues, VisualOrientation orientation, bool useMnemonic) { // Remember the source information _paletteDisabled = paletteDisabled; _paletteNormal = paletteNormal; _paletteTracking = paletteTracking; _palettePressed = palettePressed; _paletteCheckedNormal = paletteCheckedNormal; _paletteCheckedTracking = paletteCheckedTracking; _paletteCheckedPressed = paletteCheckedPressed; _paletteCurrent = _paletteNormal; // Default to not being checked _checked = false; _allowUncheck = true; _dropDown = false; _splitter = false; _dropDownPosition = VisualOrientation.Right; // Create the drop down view _drawDropDown = new ViewLayoutCenter(1); _drawDropDownButton = new ViewDrawDropDownButton(); _drawDropDown.Add(_drawDropDownButton); _drawOuterSeparator = new ViewLayoutSeparator(1); // Create the view used to draw the split edge _edgeRedirect = new PaletteBorderEdgeRedirect(_paletteNormal.PaletteBorder, null); _drawSplitBorder = new ViewDrawBorderEdge(new PaletteBorderEdge(_edgeRedirect, null), CommonHelper.VisualToOrientation(orientation)); // Our view contains background and border with content inside _drawContent = new ViewDrawContent(_paletteNormal.PaletteContent, buttonValues, orientation); _drawCanvas = new ViewDrawSplitCanvas(_paletteNormal.PaletteBack, _paletteNormal.PaletteBorder, paletteMetric, PaletteMetricPadding.None, orientation); // Use a docker layout to organize the contents of the canvas _layoutDocker = new ViewLayoutDocker(); _layoutDocker.Add(_drawContent, ViewDockStyle.Fill); _layoutDocker.Add(_drawSplitBorder, ViewDockStyle.Right); _layoutDocker.Add(_drawDropDown, ViewDockStyle.Right); _layoutDocker.Add(_drawOuterSeparator, ViewDockStyle.Right); _layoutDocker.Tag = this; // Pass the mnemonic default to the content view _drawContent.UseMnemonic = useMnemonic; // Place the content inside the canvas _drawCanvas.Add(_layoutDocker); // Set initial view element visible states UpdateDropDown(); // Place the canvas inside ourself Add(_drawCanvas); }
/// <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; _checkBox = 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 _checkBox.SetPaletteRedirect(provider.ProviderRedirector); // Create the content for the actual heading text/image _drawContent = new ViewDrawContent((_itemEnabled ? (IPaletteContent)_checkBox.OverrideNormal : (IPaletteContent)_checkBox.OverrideDisabled), _contentValues, VisualOrientation.Top); _drawContent.UseMnemonic = true; _drawContent.Enabled = _itemEnabled; // Create the check box image drawer and place inside element so it is always centered _drawCheckBox = new ViewDrawCheckBox(_checkBox.StateCheckBoxImages); _drawCheckBox.CheckState = ResolveCheckState; _drawCheckBox.Enabled = _itemEnabled; _layoutCenter = new ViewLayoutCenter(); _layoutCenter.Add(_drawCheckBox); // Place the check box on the left of the available space but inside separators _innerDocker = new ViewLayoutDocker(); _innerDocker.Add(_drawContent, ViewDockStyle.Fill); _innerDocker.Add(_layoutCenter, ViewDockStyle.Left); _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Right); _innerDocker.Add(new ViewLayoutSeparator(3), ViewDockStyle.Left); _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Top); _innerDocker.Add(new ViewLayoutSeparator(1), ViewDockStyle.Bottom); // Use outer docker so that any extra space not needed is used by the null _outerDocker = new ViewLayoutDocker(); _outerDocker.Add(_innerDocker, ViewDockStyle.Top); _outerDocker.Add(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 += new EventHandler(OnClick); _innerDocker.MouseController = mcbc; _innerDocker.KeyController = mcbc; // Add docker as the composite content Add(_outerDocker); // Want to know when a property changes whilst displayed _checkBox.PropertyChanged += new PropertyChangedEventHandler(OnPropertyChanged); // We need to know if a property of the command changes if (_checkBox.KryptonCommand != null) { _cachedCommand = _checkBox.KryptonCommand; _checkBox.KryptonCommand.PropertyChanged += new PropertyChangedEventHandler(OnCommandPropertyChanged); } }