Work on toolbar custom separator control

This commit is contained in:
niksedk 2023-07-29 18:48:56 +02:00
parent 453a0bec65
commit 53e40a9d63
3 changed files with 209 additions and 21 deletions

View File

@ -0,0 +1,185 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Controls
{
public class ToolStripNikseSeparator : ToolStripItem
{
public ToolStripNikseSeparator() => ForeColor = SystemColors.ControlDark;
public override bool CanSelect => DesignMode;
protected override Size DefaultSize => new Size(6, 6);
protected override Padding DefaultMargin => new Padding(2, 5, 2, 6);
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new bool DoubleClickEnabled
{
get => base.DoubleClickEnabled;
set => base.DoubleClickEnabled = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override bool Enabled
{
get => base.Enabled;
set => base.Enabled = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public new event EventHandler EnabledChanged
{
add => base.EnabledChanged += value;
remove => base.EnabledChanged -= value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new ToolStripItemDisplayStyle DisplayStyle
{
get => base.DisplayStyle;
set => base.DisplayStyle = value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public new event EventHandler DisplayStyleChanged
{
add => base.DisplayStyleChanged += value;
remove => base.DisplayStyleChanged -= value;
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override Font Font
{
get => base.Font;
set => base.Font = value;
}
private bool IsVertical
{
get
{
ToolStrip toolStrip = Owner;
if (toolStrip is ToolStripDropDownMenu)
{
return false;
}
switch (toolStrip.LayoutStyle)
{
case ToolStripLayoutStyle.VerticalStackWithOverflow:
return false;
default:
return true;
}
}
}
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
[DefaultValue(ToolStripTextDirection.Horizontal)]
public override ToolStripTextDirection TextDirection
{
get => base.TextDirection;
set => base.TextDirection = value;
}
public override Size GetPreferredSize(Size constrainingSize)
{
var toolStrip = Owner;
if (toolStrip == null)
{
return new Size(6, 6);
}
if (toolStrip.LayoutStyle != ToolStripLayoutStyle.HorizontalStackWithOverflow || toolStrip.LayoutStyle != ToolStripLayoutStyle.VerticalStackWithOverflow)
{
constrainingSize.Width = 23;
constrainingSize.Height = 23;
}
return this.IsVertical ? new Size(6, constrainingSize.Height) : new Size(constrainingSize.Width, 6);
}
private Color _foreColor;
[Category("ToolStripNikseSeparator"), Description("Gets or sets the foreground color"), RefreshProperties(RefreshProperties.Repaint)]
public new Color ForeColor
{
get => _foreColor;
set
{
if (value.A == 0)
{
return;
}
_foreColor = value;
Invalidate();
}
}
protected override void OnPaint(PaintEventArgs e)
{
if (Owner == null)
{
return;
}
base.OnPaint(e);
using (var pen = new Pen(_foreColor, 1f))
{
e.Graphics.DrawLine(pen,
+Bounds.Width / 2,
Padding.Top,
Bounds.Width / 2,
Height - Padding.Bottom);
}
}
protected override void SetBounds(Rectangle rect)
{
if (Owner is ToolStripDropDownMenu owner)
{
rect.X = 2;
rect.Width = owner.Width - 4;
}
base.SetBounds(rect);
}
[ComVisible(true)]
internal class ToolStripSeparatorAccessibleObject : ToolStripItem.ToolStripItemAccessibleObject
{
private ToolStripSeparator _ownerItem;
public ToolStripSeparatorAccessibleObject(ToolStripSeparator ownerItem)
: base(ownerItem)
{
_ownerItem = ownerItem;
}
public override AccessibleRole Role
{
get
{
var accessibleRole = _ownerItem.AccessibleRole;
return accessibleRole != AccessibleRole.Default ? accessibleRole : AccessibleRole.Separator;
}
}
}
}
}

View File

@ -51,10 +51,10 @@
this.toolStripButtonFileOpen = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonSave = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonSaveAs = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparatorFindReplace = new System.Windows.Forms.ToolStripSeparator();
this.toolStripSeparatorFindReplace = new Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator();
this.toolStripButtonFind = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonReplace = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparatorFixSyncSpell = new System.Windows.Forms.ToolStripSeparator();
this.toolStripSeparatorFixSyncSpell = new Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator();
this.toolStripButtonFixCommonErrors = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonRemoveTextForHi = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonVisualSync = new System.Windows.Forms.ToolStripButton();
@ -68,19 +68,19 @@
this.toolStripButtonNetflixQualityCheck = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonBeautifyTimeCodes = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonSettings = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparatorHelp = new System.Windows.Forms.ToolStripSeparator();
this.toolStripSeparatorHelp = new Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator();
this.toolStripButtonHelp = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparatorToggle = new System.Windows.Forms.ToolStripSeparator();
this.toolStripSeparatorToggle = new Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator();
this.toolStripButtonSourceView = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonToggleWaveform = new System.Windows.Forms.ToolStripButton();
this.toolStripButtonToggleVideo = new System.Windows.Forms.ToolStripButton();
this.toolStripSeparatorSubtitleFormat = new System.Windows.Forms.ToolStripSeparator();
this.toolStripSeparatorSubtitleFormat = new Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator();
this.toolStripLabelSubtitleFormat = new System.Windows.Forms.ToolStripLabel();
this.comboBoxSubtitleFormats = new Nikse.SubtitleEdit.Controls.ToolStripNikseComboBox();
this.toolStripSeparatorEncoding = new System.Windows.Forms.ToolStripSeparator();
this.toolStripSeparatorEncoding = new Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator();
this.toolStripLabelEncoding = new System.Windows.Forms.ToolStripLabel();
this.comboBoxEncoding = new Nikse.SubtitleEdit.Controls.ToolStripNikseComboBox();
this.toolStripSeparatorFrameRate = new System.Windows.Forms.ToolStripSeparator();
this.toolStripSeparatorFrameRate = new Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator();
this.toolStripLabelFrameRate = new System.Windows.Forms.ToolStripLabel();
this.toolStripComboBoxFrameRate = new System.Windows.Forms.ToolStripComboBox();
this.toolStripButtonGetFrameRate = new System.Windows.Forms.ToolStripButton();
@ -770,7 +770,7 @@
// toolStripSeparatorFindReplace
//
this.toolStripSeparatorFindReplace.Name = "toolStripSeparatorFindReplace";
this.toolStripSeparatorFindReplace.Size = new System.Drawing.Size(6, 40);
this.toolStripSeparatorFindReplace.Size = new System.Drawing.Size(6, 29);
//
// toolStripButtonFind
//
@ -800,7 +800,7 @@
// toolStripSeparatorFixSyncSpell
//
this.toolStripSeparatorFixSyncSpell.Name = "toolStripSeparatorFixSyncSpell";
this.toolStripSeparatorFixSyncSpell.Size = new System.Drawing.Size(6, 40);
this.toolStripSeparatorFixSyncSpell.Size = new System.Drawing.Size(6, 29);
//
// toolStripButtonFixCommonErrors
//
@ -962,7 +962,7 @@
// toolStripSeparatorHelp
//
this.toolStripSeparatorHelp.Name = "toolStripSeparatorHelp";
this.toolStripSeparatorHelp.Size = new System.Drawing.Size(6, 40);
this.toolStripSeparatorHelp.Size = new System.Drawing.Size(6, 29);
//
// toolStripButtonHelp
//
@ -979,7 +979,7 @@
// toolStripSeparatorToggle
//
this.toolStripSeparatorToggle.Name = "toolStripSeparatorToggle";
this.toolStripSeparatorToggle.Size = new System.Drawing.Size(6, 40);
this.toolStripSeparatorToggle.Size = new System.Drawing.Size(6, 29);
//
// toolStripButtonSourceView
//
@ -1027,7 +1027,7 @@
// toolStripLabelSubtitleFormat
//
this.toolStripLabelSubtitleFormat.Name = "toolStripLabelSubtitleFormat";
this.toolStripLabelSubtitleFormat.Size = new System.Drawing.Size(86, 37);
this.toolStripLabelSubtitleFormat.Size = new System.Drawing.Size(86, 15);
this.toolStripLabelSubtitleFormat.Text = "Subtitle format";
//
// comboBoxSubtitleFormats
@ -1053,7 +1053,7 @@
// toolStripSeparatorEncoding
//
this.toolStripSeparatorEncoding.Name = "toolStripSeparatorEncoding";
this.toolStripSeparatorEncoding.Size = new System.Drawing.Size(6, 40);
this.toolStripSeparatorEncoding.Size = new System.Drawing.Size(6, 23);
//
// toolStripLabelEncoding
//
@ -1089,7 +1089,7 @@
// toolStripSeparatorFrameRate
//
this.toolStripSeparatorFrameRate.Name = "toolStripSeparatorFrameRate";
this.toolStripSeparatorFrameRate.Size = new System.Drawing.Size(6, 40);
this.toolStripSeparatorFrameRate.Size = new System.Drawing.Size(6, 23);
//
// toolStripLabelFrameRate
//
@ -5948,9 +5948,9 @@
private System.Windows.Forms.ToolStripButton toolStripButtonXProperties;
private System.Windows.Forms.ToolStripButton toolStripButtonSettings;
private System.Windows.Forms.ToolStripButton toolStripButtonVisualSync;
private System.Windows.Forms.ToolStripSeparator toolStripSeparatorFindReplace;
private System.Windows.Forms.ToolStripSeparator toolStripSeparatorFixSyncSpell;
private System.Windows.Forms.ToolStripSeparator toolStripSeparatorHelp;
private Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator toolStripSeparatorFindReplace;
private Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator toolStripSeparatorFixSyncSpell;
private Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator toolStripSeparatorHelp;
private System.Windows.Forms.ToolStripButton toolStripButtonHelp;
private System.Windows.Forms.ToolStripStatusLabel labelStatus;
private System.Windows.Forms.ToolStripMenuItem adjustDisplayTimeToolStripMenuItem;
@ -6023,14 +6023,14 @@
private System.Windows.Forms.Label labelAutoDuration;
private System.Windows.Forms.Timer timerAutoContinue;
private Nikse.SubtitleEdit.Controls.ToolStripNikseComboBox comboBoxSubtitleFormats;
private System.Windows.Forms.ToolStripSeparator toolStripSeparatorToggle;
private System.Windows.Forms.ToolStripSeparator toolStripSeparatorSubtitleFormat;
private Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator toolStripSeparatorToggle;
private Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator toolStripSeparatorSubtitleFormat;
private System.Windows.Forms.ToolStripLabel toolStripLabelSubtitleFormat;
private System.Windows.Forms.ToolStripLabel toolStripLabelEncoding;
private Nikse.SubtitleEdit.Controls.ToolStripNikseComboBox comboBoxEncoding;
private System.Windows.Forms.ToolStripButton toolStripButtonToggleVideo;
private System.Windows.Forms.ToolStripSeparator toolStripSeparatorEncoding;
private System.Windows.Forms.ToolStripSeparator toolStripSeparatorFrameRate;
private Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator toolStripSeparatorEncoding;
private Nikse.SubtitleEdit.Controls.ToolStripNikseSeparator toolStripSeparatorFrameRate;
private System.Windows.Forms.ToolStripLabel toolStripLabelFrameRate;
private System.Windows.Forms.ToolStripComboBox toolStripComboBoxFrameRate;
private System.Windows.Forms.ToolStripButton toolStripButtonGetFrameRate;

View File

@ -131,6 +131,9 @@
<Compile Include="Controls\ToolStripNikseComboBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\ToolStripNikseSeparator.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Controls\VideoPlayerContainer.cs">
<SubType>Component</SubType>
</Compile>