/// <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="imageValue"></param> /// <param name="commandLinkTextValues"></param> /// <param name="orientation">Visual orientation of the content.</param> /// <param name="useMnemonic">Use mnemonics.</param> public ViewDrawCommandLinkButton(IPaletteTriple paletteDisabled, IPaletteTriple paletteNormal, IPaletteTriple paletteTracking, IPaletteTriple palettePressed, IPaletteTriple paletteCheckedNormal, IPaletteTriple paletteCheckedTracking, IPaletteTriple paletteCheckedPressed, IPaletteMetric paletteMetric, ImageValue imageValue, CommandLinkTextValues commandLinkTextValues, VisualOrientation orientation, bool useMnemonic) { // Remember the source information _paletteDisabled = paletteDisabled; _paletteNormal = paletteNormal; _paletteTracking = paletteTracking; _palettePressed = palettePressed; _paletteCheckedNormal = paletteCheckedNormal; _paletteCheckedTracking = paletteCheckedTracking; _paletteCheckedPressed = paletteCheckedPressed; CurrentPalette = _paletteNormal; // Default to not being checked Checked = false; AllowUncheck = true; // Create the drop down view _drawImageContent = new ViewDrawContent(_paletteNormal.PaletteContent, imageValue, orientation); _drawImage = new ViewLayoutCenter(paletteMetric, PaletteMetricPadding.BarPaddingOnly, orientation, _drawImageContent); // Our view contains background and border with content inside _drawContent = new ViewDrawContent(_paletteNormal.PaletteContent, commandLinkTextValues, orientation) { // Pass the mnemonic default to the content view UseMnemonic = useMnemonic }; // Use a docker layout to organize the contents of the canvas LayoutDocker = new ViewLayoutDocker { { _drawContent, ViewDockStyle.Left }, { _drawImage, ViewDockStyle.Left } }; LayoutDocker.Tag = this; _drawCanvas = new ViewDrawCanvas(_paletteNormal.PaletteBack, _paletteNormal.PaletteBorder, paletteMetric, PaletteMetricPadding.BarPaddingTabs, orientation) { // Place the content inside the canvas LayoutDocker }; // Place the canvas inside ourself Add(_drawCanvas); }
/// <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 = OnFinishDelegate; // Create delegate for paint notifications NeedPaintHandler needPaint = 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) { ViewButton }; // Create a controller for managing button behavior ButtonSpecViewControllers controllers = CreateController(ViewButton, needPaint, OnClick); ViewButton.MouseController = controllers.MouseController; ViewButton.SourceController = controllers.SourceController; ViewButton.KeyController = controllers.KeyController; // We need notifying whenever a button specification property changes ButtonSpec.ButtonSpecPropertyChanged += 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; CurrentPalette = _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 { { _drawContent, ViewDockStyle.Fill }, { _drawSplitBorder, ViewDockStyle.Right }, { _drawDropDown, ViewDockStyle.Right }, { _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 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.NormalPanel; _orientation = VisualOrientation.Top; _checkPosition = VisualOrientation.Left; _checked = false; _useMnemonic = true; _autoCheck = true; // Create content storage Values = new LabelValues(NeedPaintDelegate); Values.TextChanged += OnRadioButtonTextChanged; Images = new RadioButtonImages(NeedPaintDelegate); // Create palette redirector _paletteCommonRedirect = new PaletteContentInheritRedirect(Redirector, PaletteContentStyle.LabelNormalPanel); _paletteRadioButtonImages = new PaletteRedirectRadioButton(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, Values, 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 _drawRadioButton = new ViewDrawRadioButton(_paletteRadioButtonImages) { CheckState = _checked }; _layoutCenter = new ViewLayoutCenter { _drawRadioButton }; // 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 RadioButtonController(_drawRadioButton, _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 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; KryptonContextMenuRadioButton = 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 && KryptonContextMenuRadioButton.Enabled; // Give the heading object the redirector to use when inheriting values KryptonContextMenuRadioButton.SetPaletteRedirect(provider.ProviderRedirector); // Create the content for the actual heading text/image ViewDrawContent = new ViewDrawContent(ItemEnabled ? KryptonContextMenuRadioButton.OverrideNormal : KryptonContextMenuRadioButton.OverrideDisabled, _contentValues, VisualOrientation.Top) { UseMnemonic = true, Enabled = ItemEnabled }; // Create the radio button image drawer and place inside element so it is always centered ViewDrawRadioButton = new ViewDrawRadioButton(KryptonContextMenuRadioButton.StateRadioButtonImages) { CheckState = KryptonContextMenuRadioButton.Checked, Enabled = ItemEnabled }; _layoutCenter = new ViewLayoutCenter { ViewDrawRadioButton }; // Place the radio button 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 radio button controller MenuRadioButtonController mrbc = new(provider.ProviderViewManager, _innerDocker, this, provider.ProviderNeedPaintDelegate); mrbc.Click += OnClick; _innerDocker.MouseController = mrbc; _innerDocker.KeyController = mrbc; // We need to be notified whenever the checked state changes KryptonContextMenuRadioButton.CheckedChanged += OnCheckedChanged; if (KryptonContextMenuRadioButton.KryptonCommand != null) { _cachedCommand = KryptonContextMenuRadioButton.KryptonCommand; KryptonContextMenuRadioButton.KryptonCommand.PropertyChanged += OnCommandPropertyChanged; } // Add docker as the composite content Add(_outerDocker); }
/// <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(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; } }
public KryptonListView() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor // Cannot get thi sto work (Code removed)!! | ControlStyles.EnableNotifyMessage , true); base.OwnerDraw = true; // We need to repaint entire control whenever resized SetStyle(ControlStyles.ResizeRedraw, true); // Yes, we want to be drawn double buffered by default DoubleBuffered = true; // Default fields _alwaysActive = true; _style = ButtonStyle.ListItem; Padding = new Padding(1); base.BorderStyle = System.Windows.Forms.BorderStyle.None; // We need to create and cache a device context compatible with the display _screenDC = PI.CreateCompatibleDC(IntPtr.Zero); // Set the palette and renderer to the defaults as specified by the manager Redirector = new PaletteRedirect(null); CacheNewPalette(KryptonManager.CurrentGlobalPalette); KryptonManager.GlobalPaletteChanged += OnGlobalPaletteChanged; NeedPaintDelegate = OnNeedPaint; // Create the palette storage Images = new CheckBoxImages(NeedPaintDelegate); _paletteCheckBoxImages = new PaletteRedirectCheckBox(Redirector, Images); StateCommon = new PaletteListStateRedirect(Redirector, PaletteBackStyle.InputControlStandalone, PaletteBorderStyle.InputControlStandalone, NeedPaintDelegate); OverrideFocus = new PaletteListItemTripleRedirect(Redirector, PaletteBackStyle.ButtonListItem, PaletteBorderStyle.ButtonListItem, PaletteContentStyle.ButtonListItem, NeedPaintDelegate); StateDisabled = new PaletteListState(StateCommon, NeedPaintDelegate); StateActive = new PaletteDouble(StateCommon, NeedPaintDelegate); StateNormal = new PaletteListState(StateCommon, NeedPaintDelegate); StateTracking = new PaletteListItemTriple(StateCommon.Item, NeedPaintDelegate); StatePressed = new PaletteListItemTriple(StateCommon.Item, NeedPaintDelegate); StateCheckedNormal = new PaletteListItemTriple(StateCommon.Item, NeedPaintDelegate); StateCheckedTracking = new PaletteListItemTriple(StateCommon.Item, NeedPaintDelegate); StateCheckedPressed = new PaletteListItemTriple(StateCommon.Item, NeedPaintDelegate); // Create manager and view for drawing the background ViewDrawPanel = new ViewDrawPanel(StateNormal.Back); // Create the override handling classes _overrideNormal = new PaletteTripleOverride(OverrideFocus.Item, StateNormal.Item, PaletteState.FocusOverride); _overrideTracking = new PaletteTripleOverride(OverrideFocus.Item, StateTracking.Item, PaletteState.FocusOverride); _overridePressed = new PaletteTripleOverride(OverrideFocus.Item, StatePressed.Item, PaletteState.FocusOverride); _overrideCheckedNormal = new PaletteTripleOverride(OverrideFocus.Item, StateCheckedNormal.Item, PaletteState.FocusOverride); _overrideCheckedTracking = new PaletteTripleOverride(OverrideFocus.Item, StateCheckedTracking.Item, PaletteState.FocusOverride); _overrideCheckedPressed = new PaletteTripleOverride(OverrideFocus.Item, StateCheckedPressed.Item, PaletteState.FocusOverride); // Create the check box image drawer and place inside element so it is always centered _drawCheckBox = new ViewDrawCheckBox(_paletteCheckBoxImages); _layoutCheckBox = new ViewLayoutCenter { _drawCheckBox }; _layoutCheckBoxAfter = new ViewLayoutSeparator(3, 0); _layoutCheckBoxStack = new ViewLayoutStack(true) { _layoutCheckBox, _layoutCheckBoxAfter }; // Stack used to layout the location of the node image _layoutImage = new ViewLayoutSeparator(0, 0); _layoutImageAfter = new ViewLayoutSeparator(3, 0); _layoutImageCenter = new ViewLayoutCenter(_layoutImage); _layoutImageStack = new ViewLayoutStack(true) { _layoutImageCenter, _layoutImageAfter }; _layoutImageState = new ViewLayoutSeparator(16, 16); _layoutImageCenterState = new ViewLayoutCenter(_layoutImageState); // Create the draw element for owner drawing individual items _contentValues = new ShortTextValue(); _drawButton = new ViewDrawButton(StateDisabled.Item, _overrideNormal, _overrideTracking, _overridePressed, _overrideCheckedNormal, _overrideCheckedTracking, _overrideCheckedPressed, new PaletteMetricRedirect(Redirector), _contentValues, VisualOrientation.Top, false); // Place check box on the left and the label in the remainder _layoutDockerTile = new ViewLayoutDocker { { _layoutImageStack, ViewDockStyle.Left }, { _layoutImageCenterState, ViewDockStyle.Left }, { _layoutCheckBoxStack, ViewDockStyle.Left }, { _drawButton, ViewDockStyle.Fill } }; _layoutDockerSmall = new ViewLayoutDocker { { _drawButton, ViewDockStyle.Left }, { _layoutImageStack, ViewDockStyle.Left }, { _layoutImageCenterState, ViewDockStyle.Left }, { _layoutCheckBoxStack, ViewDockStyle.Left } }; // Place check box on the left and the text to match the width _layoutDockerCheckLarge = new ViewLayoutDocker { { _layoutImageStack, ViewDockStyle.Left }, { _layoutImageCenterState, ViewDockStyle.Left }, { _layoutCheckBoxStack, ViewDockStyle.Left }, { _drawButton, ViewDockStyle.Bottom } }; // Create the element that fills the remainder space and remembers fill rectangle _layoutFill = new ViewLayoutFill(this) { DisplayPadding = new Padding(1) }; // Create inner view for placing inside the drawing docker _drawDockerInner = new ViewLayoutDocker { { _layoutFill, ViewDockStyle.Fill } }; // Create view for the control border and background _drawDockerOuter = new ViewDrawDocker(StateNormal.Back, StateNormal.Border) { { _drawDockerInner, ViewDockStyle.Fill } }; // Create the view manager instance ViewManager = new ViewManager(this, _drawDockerOuter); // We need to create and cache a device context compatible with the display _screenDC = PI.CreateCompatibleDC(IntPtr.Zero); StateCommon.Item.Content.ShortText.MultiLine = InheritBool.True; StateCommon.Item.Content.ShortText.MultiLineH = PaletteRelativeAlign.Center; StateCommon.Item.Content.ShortText.TextH = PaletteRelativeAlign.Center; }