DotNet 4.8.1 build of DotNetBar

This commit is contained in:
2025-02-07 10:35:23 -05:00
parent 33439b63a0
commit 6b0a5d60f4
2609 changed files with 989814 additions and 7 deletions

View File

@@ -0,0 +1,194 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using DevComponents.DotNetBar.Ribbon;
namespace DevComponents.DotNetBar.Rendering
{
internal class Office2010SwitchButtonPainter : SwitchButtonPainter, IOffice2007Painter
{
#region Internal Implementation
private static readonly int SwitchCornerSize = 2;
public override void Paint(SwitchButtonRenderEventArgs e)
{
SwitchButtonItem switchButton = e.SwitchButtonItem;
bool enabled = switchButton.Enabled;
SwitchButtonColorTable colorTable = enabled ? this.ColorTable.SwitchButton.Default : this.ColorTable.SwitchButton.Disabled;
if (colorTable == null) colorTable = new SwitchButtonColorTable();
Rectangle bounds = switchButton.Bounds;
int buttonWidth = Dpi.Width(switchButton.ButtonWidth);
Padding margin = Dpi.Size(switchButton.Margin);
if (e.ItemPaintArgs != null && e.ItemPaintArgs.ContainerControl is AdvTree.AdvTree)
{
if (switchButton.ItemAlignment == eItemAlignment.Far)
bounds.X = bounds.Right - margin.Right - buttonWidth;
else if (switchButton.ItemAlignment == eItemAlignment.Center)
bounds.X += (bounds.Width - buttonWidth) / 2;
}
else
bounds.X = bounds.Right - margin.Right - buttonWidth;
bounds.Width = buttonWidth;
int buttonHeight = Dpi.Height(switchButton.ButtonHeight);
bounds.Y += margin.Top + (bounds.Height - margin.Vertical - buttonHeight) / 2;
bounds.Height = buttonHeight;
switchButton.ButtonBounds = bounds;
bool rendersOnGlass = (e.ItemPaintArgs != null && e.ItemPaintArgs.GlassEnabled && (switchButton.Parent is CaptionItemContainer && !(e.ItemPaintArgs.ContainerControl is QatToolbar) || (switchButton.Parent is RibbonTabItemContainer && switchButton.EffectiveStyle == eDotNetBarStyle.Office2010)));
Graphics g = e.Graphics;
if (switchButton.TextVisible && !string.IsNullOrEmpty(switchButton.Text))
{
Rectangle textRect = switchButton.Bounds;
Padding textPadding = Dpi.Size(switchButton.TextPadding);
textRect.Width -= buttonWidth + margin.Right + textPadding.Horizontal;
textRect.Y += textPadding.Top;
textRect.X += textPadding.Left;
textRect.Height -= textPadding.Vertical;
bool rtl = e.RightToLeft;
Color textColor = (switchButton.TextColor.IsEmpty || !enabled) ? colorTable.TextColor : switchButton.TextColor;
Font textFont = e.Font;
eTextFormat tf = eTextFormat.Left | eTextFormat.VerticalCenter;
if (switchButton.TextMarkupBody != null)
{
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, textFont, textColor, rtl);
d.HotKeyPrefixVisible = !((tf & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
if ((tf & eTextFormat.VerticalCenter) == eTextFormat.VerticalCenter)
textRect.Y = switchButton.TopInternal + (switchButton.Bounds.Height - switchButton.TextMarkupBody.Bounds.Height) / 2;
else if ((tf & eTextFormat.Bottom) == eTextFormat.Bottom)
textRect.Y += (switchButton.TextMarkupBody.Bounds.Height - textRect.Height) + 1;
textRect.Height = switchButton.TextMarkupBody.Bounds.Height;
switchButton.TextMarkupBody.Bounds = textRect;
switchButton.TextMarkupBody.Render(d);
}
else
{
#if FRAMEWORK20
if(rendersOnGlass)
{
if (!e.ItemPaintArgs.CachedPaint)
Office2007RibbonControlPainter.PaintTextOnGlass(g, switchButton.Text, textFont, textRect, TextDrawing.GetTextFormat(tf));
}
else
#endif
TextDrawing.DrawString(g, switchButton.Text, textFont, textColor, textRect, tf);
}
}
bool switchState = switchButton.Value;
string offText = switchButton.OffText;
string onText = switchButton.OnText;
Font font = (switchButton.SwitchFont == null) ? new Font(e.Font, FontStyle.Bold) : switchButton.SwitchFont;
Color textOffColor = (switchButton.OffTextColor.IsEmpty || !enabled) ? colorTable.OffTextColor : switchButton.OffTextColor;
Color textOnColor = (switchButton.OnTextColor.IsEmpty || !enabled) ? colorTable.OnTextColor : switchButton.OnTextColor;
int switchWidth = Dpi.Width(switchButton.SwitchWidth);
int switchX = Math.Min(bounds.X + switchButton.SwitchOffset, bounds.Right);
if (switchState)
{
switchX = Math.Max(bounds.Right - switchWidth - switchButton.SwitchOffset, bounds.X);
}
Color borderColor = (switchButton.BorderColor.IsEmpty || !enabled) ? colorTable.BorderColor : switchButton.BorderColor;
Color offBackgroundColor = (switchButton.OffBackColor.IsEmpty || !enabled) ? colorTable.OffBackColor : switchButton.OffBackColor;
Color onBackgroundColor = (switchButton.OnBackColor.IsEmpty || !enabled) ? colorTable.OnBackColor : switchButton.OnBackColor;
// Set clip
Rectangle innerBoundsClip = bounds;
innerBoundsClip.Inflate(-1, -1);
GraphicsPath innerClipPath = DisplayHelp.GetRoundedRectanglePath(innerBoundsClip, SwitchCornerSize - 1);
Region oldClip = g.Clip;
g.SetClip(innerClipPath, System.Drawing.Drawing2D.CombineMode.Intersect);
innerClipPath.Dispose();
// Draw On Background, it is to the left of the switch
Rectangle onBounds = new Rectangle(switchX - (bounds.Width - switchWidth), bounds.Y, bounds.Width - switchWidth + 2, bounds.Height);
switchButton.OnPartBounds = onBounds;
DisplayHelp.FillRoundedRectangle(g, onBounds, SwitchCornerSize - 1, onBackgroundColor);
DisplayHelp.FillRoundedRectangle(g, onBounds, SwitchCornerSize - 1, Color.FromArgb(onBackgroundColor.GetBrightness() > .90f ? 8 : 24, Color.Black), Color.FromArgb(32, Color.White));
// Draw On Text
if(rendersOnGlass && BarUtilities.UseTextRenderer)
TextDrawing.DrawStringLegacy(g, onText, font, textOnColor, onBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
else
TextDrawing.DrawString(g, onText, font, textOnColor, onBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
// Draw Off Background, it is on the right of the switch
Rectangle offBounds = new Rectangle(switchX + switchWidth - 2, bounds.Y, bounds.Width - switchWidth + 2, bounds.Height);
switchButton.OffPartBounds = offBounds;
DisplayHelp.FillRoundedRectangle(g, offBounds, SwitchCornerSize, offBackgroundColor);
DisplayHelp.FillRoundedRectangle(g, offBounds, SwitchCornerSize, Color.FromArgb(offBackgroundColor.GetBrightness() > .90f ? 12 : 32, Color.Black), Color.FromArgb(64, Color.White));
// Draw Off Text
if (rendersOnGlass && BarUtilities.UseTextRenderer)
TextDrawing.DrawStringLegacy(g, offText, font, textOffColor, offBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
else
TextDrawing.DrawString(g, offText, font, textOffColor, offBounds, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
// Restore old clip
g.Clip = oldClip;
oldClip.Dispose();
// Main control border
DisplayHelp.DrawRoundedRectangle(g, borderColor, bounds, SwitchCornerSize);
LinearGradientColorTable innerOverlay = new LinearGradientColorTable(Color.FromArgb(96, Color.DarkGray), Color.Transparent, 90);
Rectangle overlayBounds = bounds;
overlayBounds.Inflate(-SwitchCornerSize / 2, -1);
DisplayHelp.DrawLine(g, overlayBounds.X, overlayBounds.Y, overlayBounds.Right, overlayBounds.Y, Color.FromArgb(24, Color.Black), 1);
overlayBounds.Y++;
DisplayHelp.DrawLine(g, overlayBounds.X, overlayBounds.Y, overlayBounds.Right, overlayBounds.Y, Color.FromArgb(8, Color.Black), 1);
// Draw Switch on top
Rectangle switchBounds = new Rectangle(switchX, bounds.Y, switchWidth, bounds.Height);
switchButton.SwitchBounds = switchBounds;
Color switchBorderColor = (switchButton.SwitchBorderColor.IsEmpty || !enabled) ? colorTable.SwitchBorderColor : switchButton.SwitchBorderColor;
Color switchFillColor = (switchButton.SwitchBackColor.IsEmpty || !enabled) ? colorTable.SwitchBackColor : switchButton.SwitchBackColor;
if (!colorTable.SwitchOnBackColor.IsEmpty && !switchButton.Value && switchButton.SwitchBackColor.IsEmpty)
switchFillColor = colorTable.SwitchOnBackColor;
if (switchBounds.Right + 2 < bounds.Right)
{
DisplayHelp.DrawLine(g, switchBounds.Right, switchBounds.Y + 3, switchBounds.Right, switchBounds.Bottom - 2, Color.FromArgb(24, Color.Black), 1);
DisplayHelp.DrawLine(g, switchBounds.Right + 1, switchBounds.Y + 3, switchBounds.Right + 1, switchBounds.Bottom - 2, Color.FromArgb(8, Color.Black), 1);
}
DisplayHelp.DrawRoundedRectangle(g, switchBorderColor, switchFillColor, switchBounds, SwitchCornerSize);
DisplayHelp.FillRoundedRectangle(g, switchBounds, SwitchCornerSize, Color.FromArgb(switchFillColor.GetBrightness() > .90f ? 42 : 72, Color.Black), Color.FromArgb(64, Color.White));
DisplayHelp.DrawLine(g, switchBounds.X + 2, switchBounds.Y + 1, switchBounds.Right - 3, switchBounds.Y + 1, Color.FromArgb(164, Color.White), 1);
if (switchButton.IsReadOnly && switchButton.ShowReadOnlyMarker)
{
Color markerColor=switchButton.ReadOnlyMarkerColor;
Rectangle marker = new Rectangle(switchBounds.X + (switchBounds.Width - 7) / 2, switchBounds.Y + (switchBounds.Height - 10) / 2, 7, 10);
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.None;
using (SolidBrush brush = new SolidBrush(markerColor))
{
g.FillRectangle(brush, new Rectangle(marker.X, marker.Y + 4, marker.Width, marker.Height - 4));
g.FillRectangle(Brushes.White, new Rectangle(marker.X + 3, marker.Y + 5, 1, 2));
}
using (Pen pen = new Pen(markerColor, 1))
{
g.DrawLine(pen, marker.X + 2, marker.Y + 0, marker.X + 4, marker.Y + 0);
g.DrawLine(pen, marker.X + 1, marker.Y + 1, marker.X + 1, marker.Y + 3);
g.DrawLine(pen, marker.X + 5, marker.Y + 1, marker.X + 5, marker.Y + 3);
}
g.SmoothingMode = sm;
}
}
#endregion
#region IOffice2007Painter
private Office2007ColorTable _ColorTable = null;
/// <summary>
/// Gets or sets color table used by renderer.
/// </summary>
public Office2007ColorTable ColorTable
{
get { return _ColorTable; }
set { _ColorTable = value; }
}
#endregion
}
}

View File

@@ -0,0 +1,770 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using DevComponents.DotNetBar.Events;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxBitmap(typeof(SwitchButton), "Controls.SwitchButton.ico"), ToolboxItem(true), System.Runtime.InteropServices.ComVisible(false), Designer("DevComponents.DotNetBar.Design.SwitchButtonDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
[DefaultEvent("ValueChanged"), DefaultBindingProperty("Value"), DefaultProperty("Value")]
public class SwitchButton : BaseItemControl, ICommandSource
{
#region Events
/// <summary>
/// Occurs before Value property has changed and it allows you to cancel the change.
/// </summary>
public event EventHandler ValueChanging;
/// <summary>
/// Raises ValueChanging event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnValueChanging(EventArgs e)
{
EventHandler handler = ValueChanging;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Occurs after Value property has changed.
/// </summary>
public event EventHandler ValueChanged;
/// <summary>
/// Raises ValueChanged event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnValueChanged(EventArgs e)
{
EventHandler handler = ValueChanged;
if (handler != null)
handler(this, e);
}
#endregion
#region Constructor, Dispose
private SwitchButtonItem _SwitchButton = null;
public SwitchButton()
{
this.SetStyle(ControlStyles.Selectable, true);
_SwitchButton = new SwitchButtonItem();
_SwitchButton.TextVisible = false;
_SwitchButton.ValueChanging += new EventHandler(SwitchButtonItemValueChanging);
_SwitchButton.ValueChanged += new EventHandler(SwitchButtonItemValueChanged);
this.HostItem = _SwitchButton;
}
#endregion
#region Internal Implementation
protected override void OnHandleCreated(EventArgs e)
{
this.RecalcLayout();
base.OnHandleCreated(e);
}
/// <summary>
/// Forces the button to perform internal layout.
/// </summary>
public override void RecalcLayout()
{
if (_SwitchButton == null) return;
_SwitchButton.ButtonWidth = Math.Max(4, Dpi.DescaleWidth(this.Width - this.Padding.Horizontal));
_SwitchButton.ButtonHeight = Math.Max(4, Dpi.DescaleHeight(this.Height - this.Padding.Vertical));
base.RecalcLayout();
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.Space && this.Enabled && !IsReadOnly)
{
_SwitchButton.SetValueAndAnimate(!_SwitchButton.Value, eEventSource.Keyboard);
}
base.OnKeyDown(e);
}
/// <summary>
/// Gets or sets the switch value.
/// </summary>
[DefaultValue(false), Category("Appearance"), Description("Indicates switch value."), Bindable(true)]
public bool Value
{
get { return _SwitchButton.Value; }
set
{
_SwitchButton.Value = value;
}
}
/// <summary>
/// Gets or sets the item border color.
/// </summary>
[Category("Appearance"), Description("Indicates item border color.")]
public Color BorderColor
{
get { return _SwitchButton.BorderColor; }
set { _SwitchButton.BorderColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeBorderColor()
{
return _SwitchButton.ShouldSerializeBorderColor();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetBorderColor()
{
this.BorderColor = Color.Empty;
}
/// <summary>
/// Cancels animation if in progress.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void CancelAnimation()
{
_SwitchButton.CancelAnimation();
}
/// <summary>
/// Gets or sets whether state transition animation is enabled.
/// </summary>
[DefaultValue(true), Category("Appearance"), Description("Indicates whether state transition animation is enabled.")]
public bool AnimationEnabled
{
get { return _SwitchButton.AnimationEnabled; }
set
{
_SwitchButton.AnimationEnabled = value;
}
}
void SwitchButtonItemValueChanged(object sender, EventArgs e)
{
_ValueObject = GetValueObject(this.Value);
ExecuteCommand();
OnValueChanged(e);
OnValueObjectChanged(e);
}
void SwitchButtonItemValueChanging(object sender, EventArgs e)
{
OnValueChanging(e);
}
protected override System.Drawing.Size DefaultSize
{
get
{
return new System.Drawing.Size(66, 22);
}
}
protected override void OnPaddingChanged(EventArgs e)
{
_SwitchButton.Margin.Bottom = this.Padding.Bottom;
_SwitchButton.Margin.Top = this.Padding.Top;
_SwitchButton.Margin.Left = this.Padding.Left;
_SwitchButton.Margin.Right = this.Padding.Right;
base.OnPaddingChanged(e);
}
/// <summary>
/// Gets or sets the color of the OFF state background.
/// </summary>
[Category("Appearance"), Description("Indicates color of OFF state background.")]
public Color OffBackColor
{
get { return _SwitchButton.OffBackColor; }
set { _SwitchButton.OffBackColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeOffBackColor()
{
return _SwitchButton.ShouldSerializeOffBackColor();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetOffBackColor()
{
this.OffBackColor = Color.Empty;
}
/// <summary>
/// Gets or sets the color of the ON state background.
/// </summary>
[Category("Appearance"), Description("Indicates color of ON state background.")]
public Color OnBackColor
{
get { return _SwitchButton.OnBackColor; }
set { _SwitchButton.OnBackColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeOnBackColor()
{
return _SwitchButton.ShouldSerializeOnBackColor();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetOnBackColor()
{
this.OnBackColor = Color.Empty;
}
/// <summary>
/// Gets or sets the color of the ON state text.
/// </summary>
[Category("Appearance"), Description("Indicates color of ON state text.")]
public Color OnTextColor
{
get { return _SwitchButton.OnTextColor; }
set { _SwitchButton.OnTextColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeOnTextColor()
{
return _SwitchButton.ShouldSerializeOnTextColor();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetOnTextColor()
{
this.OnTextColor = Color.Empty;
}
/// <summary>
/// Gets or sets the color of the OFF state text.
/// </summary>
[Category("Appearance"), Description("Indicates color of OFF state text.")]
public Color OffTextColor
{
get { return _SwitchButton.OffTextColor; }
set { _SwitchButton.OffTextColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeOffTextColor()
{
return _SwitchButton.ShouldSerializeOffTextColor();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetOffTextColor()
{
this.OffTextColor = Color.Empty;
}
/// <summary>
/// Gets or sets the border color of the button switch.
/// </summary>
[Category("Appearance"), Description("Indicates border color of the button switch.")]
public Color SwitchBorderColor
{
get { return _SwitchButton.SwitchBorderColor; }
set { _SwitchButton.SwitchBorderColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSwitchBorderColor()
{
return _SwitchButton.ShouldSerializeSwitchBorderColor();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSwitchBorderColor()
{
this.SwitchBorderColor = Color.Empty;
}
/// <summary>
/// Gets or sets the background color of the switch button.
/// </summary>
[Category("Appearance"), Description("Indicates background color of the switch button.")]
public Color SwitchBackColor
{
get { return _SwitchButton.SwitchBackColor; }
set { _SwitchButton.SwitchBackColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeSwitchBackColor()
{
return _SwitchButton.ShouldSerializeSwitchBackColor();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetSwitchBackColor()
{
this.SwitchBackColor = Color.Empty;
}
/// <summary>
/// Gets or sets the text color.
/// </summary>
[Category("Appearance"), Description("Indicates text color."), Browsable(false)]
public Color TextColor
{
get { return _SwitchButton.TextColor; }
set { _SwitchButton.TextColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeTextColor()
{
return _SwitchButton.ShouldSerializeTextColor();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetTextColor()
{
this.TextColor = Color.Empty;
}
/// <summary>
/// Gets or sets the font that is used to draw ON/OFF text on the switch button.
/// </summary>
[DefaultValue(null), Category("Appearance"), Description("Indicates font that is used to draw ON/OFF text on the switch button.")]
public Font SwitchFont
{
get { return _SwitchButton.SwitchFont; }
set { _SwitchButton.SwitchFont = value; }
}
/// <summary>
/// Gets or sets the text that is displayed on switch when Value property is set to true.
/// </summary>
[DefaultValue("ON"), Localizable(true), Category("Appearance"), Description("Indicates text that is displayed on switch when Value property is set to true.")]
public string OnText
{
get { return _SwitchButton.OnText; }
set
{
_SwitchButton.OnText = value;
}
}
/// <summary>
/// Gets or sets the text that is displayed on switch when Value property is set to false.
/// </summary>
[DefaultValue("OFF"), Localizable(true), Category("Appearance"), Description("Indicates text that is displayed on switch when Value property is set to true.")]
public string OffText
{
get { return _SwitchButton.OffText; }
set
{
_SwitchButton.OffText = value;
}
}
[Browsable(false)]
public override eDotNetBarStyle Style
{
get
{
return base.Style;
}
set
{
base.Style = value;
}
}
[Browsable(false)]
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
}
}
[Browsable(false)]
public override Color ForeColor
{
get
{
return base.ForeColor;
}
set
{
base.ForeColor = value;
}
}
/// <summary>
/// Gets or sets the width in pixels of the switch part of the button. Minimum value is 6.
/// </summary>
[DefaultValue(28), Category("Appearance"), Description("Indicates width in pixels of the switch part of the button.")]
public int SwitchWidth
{
get { return _SwitchButton.SwitchWidth; }
set
{
_SwitchButton.SwitchWidth = value;
}
}
/// <summary>
/// Gets the switch bounds.
/// </summary>
[Browsable(false)]
public Rectangle SwitchBounds
{
get { return _SwitchButton.SwitchBounds; }
}
/// <summary>
/// Gets the On part of the switch button bounds excluding the SwitchBounds.
/// </summary>
[Browsable(false)]
public Rectangle OnPartBounds
{
get { return _SwitchButton.OnPartBounds; }
}
/// <summary>
/// Gets the Off part of the switch button bounds excluding the SwitchBounds.
/// </summary>
[Browsable(false)]
public Rectangle OffPartBounds
{
get { return _SwitchButton.OffPartBounds; }
}
/// <summary>
/// Sets the value of the control with state transition animation (if enabled) and specifies the source of the action.
/// </summary>
/// <param name="newValue">New value for Value property.</param>
/// <param name="source">Source of the action.</param>
public void SetValueAndAnimate(bool value, eEventSource source)
{
_SwitchButton.SetValueAndAnimate(value, source);
}
/// <summary>
/// Sets the value of the control and specifies the source of the action.
/// </summary>
/// <param name="newValue">New value for Value property.</param>
/// <param name="source">Source of the action.</param>
public void SetValue(bool newValue, eEventSource source)
{
_SwitchButton.SetValue(newValue, source);
}
/// <summary>
/// Gets or sets whether button is in read-only state meaning that it appears as enabled but user cannot change its state.
/// </summary>
[DefaultValue(false), Category("Behavior"), Description("Indicates whether button is in read-only state meaning that it appears as enabled but user cannot change its state.")]
public bool IsReadOnly
{
get { return _SwitchButton.IsReadOnly; }
set { _SwitchButton.IsReadOnly = value; }
}
/// <summary>
/// Gets or sets whether lock marker is visible on face of the control when IsReadOnly is set to true.
/// Default value is true.
/// </summary>
[DefaultValue(true), Category("Appearance"), Description("Indicates whether lock marker is visible on face of the control when IsReadOnly is set to true.")]
public bool ShowReadOnlyMarker
{
get { return _SwitchButton.ShowReadOnlyMarker; }
set { _SwitchButton.ShowReadOnlyMarker = value; }
}
/// <summary>
/// Gets or sets the color of the read-only marker.
/// </summary>
[Category("Appearance"), Description("Indicates color of read-only marker.")]
public Color ReadOnlyMarkerColor
{
get { return _SwitchButton.ReadOnlyMarkerColor; }
set { _SwitchButton.ReadOnlyMarkerColor = value; }
}
/// <summary>
/// Gets whether property should be serialized.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ShouldSerializeReadOnlyMarkerColor()
{
return _SwitchButton.ShouldSerializeReadOnlyMarkerColor();
}
/// <summary>
/// Resets property to its default value.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetReadOnlyMarkerColor()
{
_SwitchButton.ResetReadOnlyMarkerColor();
}
public override Size GetPreferredSize(Size proposedSize)
{
if (_SwitchButton != null)
return _SwitchButton.GetPreferredSize();
return base.GetPreferredSize(proposedSize);
}
/// <summary>
/// Indicates whether clicking left mouse button on the switch part of the item will toggle the switch Value.
/// </summary>
[DefaultValue(false), Category("Behavior"), Description("Indicates whether clicking left mouse button on the switch part of the item will toggle the switch Value.")]
public bool SwitchClickTogglesValue
{
get { return _SwitchButton.SwitchClickTogglesValue; }
set { _SwitchButton.SwitchClickTogglesValue = value; }
}
#endregion
#region ValueObject implementation
private const string DefaultValueFalse = "N";
private const string DefaultValueTrue = "Y";
private object _ValueObject = DefaultValueFalse;
private object _ValueFalse= DefaultValueFalse;
private object _ValueTrue= DefaultValueTrue;
/// <summary>
/// Occurs after ValueObject property changes.
/// </summary>
[Description("Occurs after ValueObject property changes.")]
public event EventHandler ValueObjectChanged;
/// <summary>
/// Raises ValueObjectChanged event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnValueObjectChanged(EventArgs e)
{
EventHandler handler = ValueObjectChanged;
if (handler != null)
handler(this, e);
}
/// <summary>
/// Gets or sets the object that represents the Value state of control.
/// </summary>
[DefaultValue("N"), Bindable(true), RefreshProperties(RefreshProperties.All), TypeConverter(typeof(StringConverter)), Description("Indicates object that represents the Value state of control.")]
public object ValueObject
{
get { return _ValueObject; }
set
{
_ValueObject = value;
OnValueObjectChanged();
}
}
private void OnValueObjectChanged()
{
bool value = GetValue(_ValueObject);
this.Value = value;
}
private bool IsNull(object value)
{
return value == null || value is string && (string)value == string.Empty ||
value == DBNull.Value;
}
private object GetValueObject(bool value)
{
return value ? _ValueTrue : _ValueFalse;
}
private bool GetValue(object value)
{
if (_ValueTrue != null && _ValueTrue.Equals(value))
{
return true;
}
else if (_ValueFalse == null && IsNull(value) || _ValueFalse != null && _ValueFalse.Equals(value))
{
return false;
}
else
{
if (value is System.Data.SqlTypes.SqlBoolean)
{
System.Data.SqlTypes.SqlBoolean sqlBool = (System.Data.SqlTypes.SqlBoolean)value;
return sqlBool.IsTrue;
}
else if (value is int?)
{
if (value == null) return false;
if (((int?)value).Value == 0)
return false;
return true;
}
else if (value is int)
{
return ((int)value) == 0 ? false : true;
}
else if (value is long)
{
return ((long)value) == 0 ? false : true;
}
else if (value is short)
{
return ((short)value) == 0 ? false : true;
}
else if (value is float)
{
return ((float)value) == 0 ? false : true;
}
else if (value is double)
{
return ((double)value) == 0 ? false : true;
}
else if (value is byte)
{
return ((byte)value) == 0 ? false : true;
}
else if (value is uint)
{
return ((uint)value) == 0 ? false: true;
}
else if (value is ulong)
{
return ((ulong)value) == 0 ? false : true;
}
else if (value is bool)
{
return ((bool)value);
}
return false;
}
}
/// <summary>
/// Gets or sets the value that represents the True state of control when ValueObject property is set to that value.
/// </summary>
[Browsable(true), DefaultValue("Y"), Category("Behavior"), TypeConverter(typeof(StringConverter)), Description("Represents the True state of Value when ValueObject property is set to that value.")]
public object ValueTrue
{
get { return _ValueTrue; }
set { _ValueTrue = value; OnValueObjectChanged(); }
}
/// <summary>
/// Gets or sets the value that represents the False state of control when ValueObject property is set to that value.
/// </summary>
[Browsable(true), DefaultValue("N"), Category("Behavior"), TypeConverter(typeof(StringConverter)), Description("Represents the False state of control when ValueObject property is set to that value.")]
public object ValueFalse
{
get { return _ValueFalse; }
set { _ValueFalse = value; OnValueObjectChanged(); }
}
#endregion
#region ICommandSource Members
protected virtual void ExecuteCommand()
{
if (_Command == null) return;
CommandManager.ExecuteCommand(this);
}
/// <summary>
/// Gets or sets the command assigned to the item. Default value is null.
/// <remarks>Note that if this property is set to null Enabled property will be set to false automatically to disable the item.</remarks>
/// </summary>
[DefaultValue(null), Category("Commands"), Description("Indicates the command assigned to the item.")]
public Command Command
{
get { return (Command)((ICommandSource)this).Command; }
set
{
((ICommandSource)this).Command = value;
}
}
private ICommand _Command = null;
//[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
ICommand ICommandSource.Command
{
get
{
return _Command;
}
set
{
bool changed = false;
if (_Command != value)
changed = true;
if (_Command != null)
CommandManager.UnRegisterCommandSource(this, _Command);
_Command = value;
if (value != null)
CommandManager.RegisterCommand(this, value);
if (changed)
OnCommandChanged();
}
}
/// <summary>
/// Called when Command property value changes.
/// </summary>
protected virtual void OnCommandChanged()
{
}
private object _CommandParameter = null;
/// <summary>
/// Gets or sets user defined data value that can be passed to the command when it is executed.
/// </summary>
[Browsable(true), DefaultValue(null), Category("Commands"), Description("Indicates user defined data value that can be passed to the command when it is executed."), System.ComponentModel.TypeConverter(typeof(System.ComponentModel.StringConverter)), System.ComponentModel.Localizable(true)]
public object CommandParameter
{
get
{
return _CommandParameter;
}
set
{
_CommandParameter = value;
}
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace DevComponents.DotNetBar.Rendering
{
internal class SwitchButtonPainter
{
/// <summary>
/// Paints SwitchButton.
/// </summary>
/// <param name="e">Provides arguments for the operation.</param>
public virtual void Paint(SwitchButtonRenderEventArgs e) { }
}
}

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar.Rendering
{
/// <summary>
/// Provides data for SwitchButton rendering.
/// </summary>
public class SwitchButtonRenderEventArgs
{
/// <summary>
/// Gets or sets Graphics object group is rendered on.
/// </summary>
public Graphics Graphics = null;
/// <summary>
/// Gets or sets the reference to SwitchButtonItem being rendered.
/// </summary>
public SwitchButtonItem SwitchButtonItem = null;
/// <summary>
/// ColorScheme object that is used to provide colors for rendering check box item in legacy styles like Office 2003. Office 2007 style
/// uses color tables provided by renderer.
/// </summary>
public ColorScheme ColorScheme = null;
/// <summary>
/// Indicates whether item is in Right-To-Left environment.
/// </summary>
public bool RightToLeft = false;
/// <summary>
/// Gets or sets the text font.
/// </summary>
public Font Font = null;
/// <summary>
/// Gets or sets the ItemPaintArgs reference.
/// </summary>
internal ItemPaintArgs ItemPaintArgs;
/// <summary>
/// Creates new instance of the object and provides default values.
/// </summary>
/// <param name="g">Reference to Graphics object</param>
/// <param name="item">Reference to SwitchButtonItem</param>
/// <param name="cs">Reference to legacy ColorScheme</param>
/// <param name="f">Indicates the font for the text.</param>
/// <param name="rtl">Indicates whether item is in Right-To-Left environment.</param>
public SwitchButtonRenderEventArgs(Graphics g, SwitchButtonItem item, ColorScheme cs, Font f, bool rtl)
{
this.Graphics = g;
this.SwitchButtonItem = item;
this.ColorScheme = cs;
this.RightToLeft = rtl;
this.Font = f;
}
}
}