Testing WebBrowserEditBox

This commit is contained in:
Nikolaj Olsson 2020-11-22 09:25:00 +01:00
parent db73f3c44e
commit 3077417749
7 changed files with 927 additions and 126 deletions

5
.gitignore vendored
View File

@ -6,7 +6,6 @@
*.vsp *.vsp
*.vspx *.vspx
/cov-int/ /cov-int/
/libse/Properties/AssemblyInfo.cs
/SE*.zip /SE*.zip
/src/Win32Resources/Resources.aps /src/Win32Resources/Resources.aps
/src/Win32Resources/Resources.rc /src/Win32Resources/Resources.rc
@ -41,4 +40,6 @@ SubtitleEditBeta
/src/SubtitleEdit.sln.DotSettings /src/SubtitleEdit.sln.DotSettings
/packages/NHunspell.1.2.5554.16953 /packages/NHunspell.1.2.5554.16953
/packages/ILRepack.2.0.18 /packages/ILRepack.2.0.18
/src/ui /src/ui/packages
/src/ui/ILRepack*
/src/ui/NHunspell*

View File

@ -1,9 +1,9 @@
using Nikse.SubtitleEdit.Core; using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Logic; using Nikse.SubtitleEdit.Logic;
using System; using System;
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using Nikse.SubtitleEdit.Core.Common; using Nikse.SubtitleEdit.Controls.WebBrowser;
namespace Nikse.SubtitleEdit.Controls namespace Nikse.SubtitleEdit.Controls
{ {
@ -31,12 +31,14 @@ namespace Nikse.SubtitleEdit.Controls
private RichTextBox _uiTextBox; private RichTextBox _uiTextBox;
private TextBox _textBox; private TextBox _textBox;
private int _mouseMoveSelectionLength; private int _mouseMoveSelectionLength;
private WebBrowserEditBox _htmlBox;
public SETextBox() public SETextBox()
{ {
Initialize(Configuration.Settings.General.SubtitleTextBoxSyntaxColor); Initialize(Configuration.Settings.General.SubtitleTextBoxSyntaxColor);
} }
private bool _useWebBrowser = true;
public void Initialize(bool useSyntaxColoring) public void Initialize(bool useSyntaxColoring)
{ {
ContextMenuStrip oldContextMenuStrip = null; ContextMenuStrip oldContextMenuStrip = null;
@ -51,6 +53,12 @@ namespace Nikse.SubtitleEdit.Controls
oldContextMenuStrip = _uiTextBox.ContextMenuStrip; oldContextMenuStrip = _uiTextBox.ContextMenuStrip;
oldEnabled = _uiTextBox.Enabled; oldEnabled = _uiTextBox.Enabled;
} }
else if (_htmlBox != null)
{
oldContextMenuStrip = _htmlBox.ContextMenuStrip;
oldEnabled = _htmlBox.Enabled;
}
BorderStyle = BorderStyle.None; BorderStyle = BorderStyle.None;
Padding = new Padding(1); Padding = new Padding(1);
@ -60,68 +68,98 @@ namespace Nikse.SubtitleEdit.Controls
_textBox?.Dispose(); _textBox?.Dispose();
_richTextBoxTemp?.Dispose(); _richTextBoxTemp?.Dispose();
_uiTextBox?.Dispose(); _uiTextBox?.Dispose();
_htmlBox?.Dispose();
_textBox = null;
_htmlBox = null;
_uiTextBox = null;
_richTextBoxTemp = null;
if (useSyntaxColoring) if (useSyntaxColoring)
{ {
_textBox = null;
_richTextBoxTemp = new RichTextBox();
_uiTextBox = new RichTextBox { BorderStyle = BorderStyle.None, Multiline = true };
InitializeBackingControl(_uiTextBox);
// avoid selection when centered and clicking to the left if (_useWebBrowser)
_uiTextBox.MouseDown += (sender, args) =>
{ {
var charIndex = _uiTextBox.GetCharIndexFromPosition(args.Location); _uiTextBox = null;
if (Configuration.Settings.General.CenterSubtitleInTextBox && _htmlBox = new WebBrowserEditBox();
_mouseMoveSelectionLength == 0 && Controls.Add(_htmlBox);
(charIndex == 0 || charIndex >= 0 && _uiTextBox.Text[charIndex - 1] == '\n')) _htmlBox.Dock = DockStyle.Fill;
{ _htmlBox.Initialize();
_uiTextBox.SelectionLength = 0;
} _htmlBox.TextChanged += TextChangedHighlight;
}; _htmlBox.Enter += (sender, args) => { BackColor = SystemColors.Highlight; };
_uiTextBox.MouseMove += (sender, args) => _htmlBox.Leave += (sender, args) => { BackColor = SystemColors.WindowFrame; };
_htmlBox.KeyDown += (sender, args) => { KeyDown?.Invoke(sender, args); };
_htmlBox.KeyUp += (sender, args) => { KeyUp?.Invoke(sender, args); };
_htmlBox.MouseClick += (sender, args) => { MouseClick?.Invoke(sender, args); };
_htmlBox.MouseMove += (sender, args) => { MouseMove?.Invoke(sender, args); };
//TODO?
//textBox.MouseDown += SETextBox_MouseDown;
//textBox.MouseUp += SETextBox_MouseUp;
}
else
{ {
_mouseMoveSelectionLength = _uiTextBox.SelectionLength; _htmlBox = null;
}; _richTextBoxTemp = new RichTextBox();
_uiTextBox.KeyDown += (sender, args) => _uiTextBox = new RichTextBox { BorderStyle = BorderStyle.None, Multiline = true };
{ InitializeBackingControl(_uiTextBox);
// fix annoying "beeps" when moving cursor position
if ((args.KeyData == Keys.Left || args.KeyData == Keys.PageUp) && _uiTextBox.SelectionStart == 0) // avoid selection when centered and clicking to the left
_uiTextBox.MouseDown += (sender, args) =>
{ {
args.SuppressKeyPress = true; var charIndex = _uiTextBox.GetCharIndexFromPosition(args.Location);
} if (Configuration.Settings.General.CenterSubtitleInTextBox &&
else if (args.KeyData == Keys.Up && _uiTextBox.SelectionStart <= _uiTextBox.Text.IndexOf('\n')) _mouseMoveSelectionLength == 0 &&
(charIndex == 0 || charIndex >= 0 && _uiTextBox.Text[charIndex - 1] == '\n'))
{
_uiTextBox.SelectionLength = 0;
}
};
_uiTextBox.MouseMove += (sender, args) =>
{ {
args.SuppressKeyPress = true; _mouseMoveSelectionLength = _uiTextBox.SelectionLength;
} };
else if (args.KeyData == Keys.Home && (_uiTextBox.SelectionStart == 0 || _uiTextBox.SelectionStart > 0 && _uiTextBox.Text[_uiTextBox.SelectionStart - 1] == '\n')) _uiTextBox.KeyDown += (sender, args) =>
{ {
args.SuppressKeyPress = true; // fix annoying "beeps" when moving cursor position
} if ((args.KeyData == Keys.Left || args.KeyData == Keys.PageUp) && _uiTextBox.SelectionStart == 0)
else if (args.KeyData == (Keys.Home | Keys.Control) && _uiTextBox.SelectionStart == 0) {
{ args.SuppressKeyPress = true;
args.SuppressKeyPress = true; }
} else if (args.KeyData == Keys.Up && _uiTextBox.SelectionStart <= _uiTextBox.Text.IndexOf('\n'))
else if (args.KeyData == Keys.End && (_uiTextBox.SelectionStart >= _uiTextBox.Text.Length || _uiTextBox.SelectionStart + 1 < _uiTextBox.Text.Length && _uiTextBox.Text[_uiTextBox.SelectionStart] == '\n')) {
{ args.SuppressKeyPress = true;
args.SuppressKeyPress = true; }
} else if (args.KeyData == Keys.Home && (_uiTextBox.SelectionStart == 0 || _uiTextBox.SelectionStart > 0 && _uiTextBox.Text[_uiTextBox.SelectionStart - 1] == '\n'))
else if (args.KeyData == (Keys.End | Keys.Control) && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length) {
{ args.SuppressKeyPress = true;
args.SuppressKeyPress = true; }
} else if (args.KeyData == (Keys.Home | Keys.Control) && _uiTextBox.SelectionStart == 0)
else if (args.KeyData == Keys.Right && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length) {
{ args.SuppressKeyPress = true;
args.SuppressKeyPress = true; }
} else if (args.KeyData == Keys.End && (_uiTextBox.SelectionStart >= _uiTextBox.Text.Length || _uiTextBox.SelectionStart + 1 < _uiTextBox.Text.Length && _uiTextBox.Text[_uiTextBox.SelectionStart] == '\n'))
else if (args.KeyData == Keys.Down && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length) {
{ args.SuppressKeyPress = true;
args.SuppressKeyPress = true; }
} else if (args.KeyData == (Keys.End | Keys.Control) && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length)
else if (args.KeyData == Keys.PageDown && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length) {
{ args.SuppressKeyPress = true;
args.SuppressKeyPress = true; }
} else if (args.KeyData == Keys.Right && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length)
}; {
args.SuppressKeyPress = true;
}
else if (args.KeyData == Keys.Down && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length)
{
args.SuppressKeyPress = true;
}
else if (args.KeyData == Keys.PageDown && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length)
{
args.SuppressKeyPress = true;
}
};
}
} }
else else
{ {
@ -202,18 +240,24 @@ namespace Nikse.SubtitleEdit.Controls
return _textBox.Text; return _textBox.Text;
} }
if (_uiTextBox == null) if (_uiTextBox != null)
{ {
return string.Empty;
var s = _uiTextBox.Text;
if (_fixedArabicComma)
{
s = s.Replace("\u202A", string.Empty);
}
return string.Join(Environment.NewLine, s.SplitToLines());
} }
var s = _uiTextBox.Text; if (_htmlBox != null)
if (_fixedArabicComma)
{ {
s = s.Replace("\u202A", string.Empty); return _htmlBox.Text;
} }
return string.Join(Environment.NewLine, s.SplitToLines()); return string.Empty;
} }
set set
{ {
@ -223,29 +267,32 @@ namespace Nikse.SubtitleEdit.Controls
return; return;
} }
if (_uiTextBox == null) if (_uiTextBox != null)
{ {
return; _fixedArabicComma = false;
} var s = value;
if (!Configuration.Settings.General.RightToLeftMode && !s.Contains('\u202A'))
{
string textNoTags = HtmlUtil.RemoveHtmlTags(s, true);
if (textNoTags.EndsWith('،'))
{
s = s.Replace("،", "\u202A،");
}
else if (textNoTags.StartsWith('،'))
{
s = s.Replace("،", "،\u202A");
}
_fixedArabicComma = false; _fixedArabicComma = true;
var s = value;
if (!Configuration.Settings.General.RightToLeftMode && !s.Contains('\u202A'))
{
string textNoTags = HtmlUtil.RemoveHtmlTags(s, true);
if (textNoTags.EndsWith('،'))
{
s = s.Replace("،", "\u202A،");
}
else if (textNoTags.StartsWith('،'))
{
s = s.Replace("،", "،\u202A");
} }
_fixedArabicComma = true; _uiTextBox.Text = string.Join("\n", s.SplitToLines());
} }
_uiTextBox.Text = string.Join("\n", s.SplitToLines()); if (_htmlBox != null)
{
_htmlBox.Text = value;
}
} }
} }
@ -253,12 +300,22 @@ namespace Nikse.SubtitleEdit.Controls
{ {
get get
{ {
if (_textBox == null && _uiTextBox == null) if (_textBox != null)
{ {
return 0; return _textBox.SelectionStart;
} }
return _textBox?.SelectionStart ?? _uiTextBox.SelectionStart; if (_uiTextBox != null)
{
return _uiTextBox.SelectionStart;
}
if (_htmlBox != null)
{
return _htmlBox.SelectionStart;
}
return 0;
} }
set set
{ {
@ -270,6 +327,10 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_uiTextBox.SelectionStart = value; _uiTextBox.SelectionStart = value;
} }
else if (_htmlBox != null)
{
_htmlBox.SelectionStart = value;
}
} }
} }
@ -277,12 +338,22 @@ namespace Nikse.SubtitleEdit.Controls
{ {
get get
{ {
if (_textBox == null && _uiTextBox == null) if (_textBox != null)
{ {
return 0; return _textBox.SelectionLength;
} }
return _textBox?.SelectionLength ?? _uiTextBox.SelectionLength; if (_uiTextBox != null)
{
return _uiTextBox.SelectionLength;
}
if (_htmlBox != null)
{
return _htmlBox.SelectionLength;
}
return 0;
} }
set set
{ {
@ -294,6 +365,10 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_uiTextBox.SelectionLength = value; _uiTextBox.SelectionLength = value;
} }
else if (_htmlBox != null)
{
_htmlBox.SelectionLength = value;
}
} }
} }
@ -301,12 +376,22 @@ namespace Nikse.SubtitleEdit.Controls
{ {
get get
{ {
if (_textBox == null && _uiTextBox == null) if (_textBox != null)
{ {
return false; return _textBox.HideSelection;
} }
return _textBox?.HideSelection ?? _uiTextBox.HideSelection; if (_uiTextBox != null)
{
return _uiTextBox.HideSelection;
}
if (_htmlBox != null)
{
return _htmlBox.HideSelection;
}
return false;
} }
set set
{ {
@ -318,6 +403,10 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_uiTextBox.HideSelection = value; _uiTextBox.HideSelection = value;
} }
else if (_htmlBox != null)
{
_htmlBox.HideSelection = value;
}
} }
} }
@ -325,12 +414,23 @@ namespace Nikse.SubtitleEdit.Controls
{ {
get get
{ {
if (_textBox == null && _uiTextBox == null) if (_textBox != null)
{ {
return string.Empty; return _textBox.SelectedText;
} }
return _textBox?.SelectedText ?? _uiTextBox.SelectedText; if (_uiTextBox != null)
{
return _uiTextBox.SelectedText;
}
if (_htmlBox != null)
{
return _htmlBox.SelectedText;
}
return string.Empty;
} }
set set
{ {
@ -342,6 +442,10 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_uiTextBox.SelectedText = value; _uiTextBox.SelectedText = value;
} }
else if (_htmlBox != null)
{
_htmlBox.SelectedText = value;
}
} }
} }
@ -349,12 +453,22 @@ namespace Nikse.SubtitleEdit.Controls
{ {
get get
{ {
if (_textBox == null && _uiTextBox == null) if (_textBox != null)
{ {
return false; return _textBox.Multiline;
} }
return _textBox?.Multiline ?? _uiTextBox.Multiline; if (_uiTextBox != null)
{
return _uiTextBox.Multiline;
}
if (_htmlBox != null)
{
return true;
}
return false;
} }
set set
{ {
@ -373,12 +487,22 @@ namespace Nikse.SubtitleEdit.Controls
{ {
get get
{ {
if (_textBox == null && _uiTextBox == null) if (_textBox != null)
{ {
return true; return _textBox.Enabled;
} }
return _textBox?.Enabled ?? _uiTextBox.Enabled; if (_uiTextBox != null)
{
return _uiTextBox.Enabled;
}
if (_htmlBox != null)
{
return _htmlBox.Enabled;
}
return true;
} }
set set
{ {
@ -390,6 +514,10 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_uiTextBox.Enabled = value; _uiTextBox.Enabled = value;
} }
else if (_htmlBox != null)
{
_htmlBox.Enabled = value;
}
} }
} }
@ -454,25 +582,37 @@ namespace Nikse.SubtitleEdit.Controls
{ {
get get
{ {
if (_textBox == null && _uiTextBox == null) if (_textBox != null)
{ {
return null; return _textBox.ContextMenuStrip;
} }
return _textBox?.ContextMenuStrip ?? _uiTextBox.ContextMenuStrip; if (_uiTextBox != null)
{
return _uiTextBox.ContextMenuStrip;
}
if (_htmlBox != null)
{
return _htmlBox.ContextMenuStrip;
}
return null;
} }
set set
{ {
if (_textBox != null) if (_textBox != null)
{ {
_textBox.ContextMenuStrip = value; _textBox.ContextMenuStrip = value;
return;
} }
else if (_uiTextBox != null)
if (_uiTextBox != null)
{ {
_uiTextBox.ContextMenuStrip = value; _uiTextBox.ContextMenuStrip = value;
} }
else if (_htmlBox != null)
{
_htmlBox.ContextMenuStrip = value;
}
} }
} }
@ -488,6 +628,11 @@ namespace Nikse.SubtitleEdit.Controls
return _uiTextBox.GetCharIndexFromPosition(pt); return _uiTextBox.GetCharIndexFromPosition(pt);
} }
if (_htmlBox != null)
{
return _htmlBox.GetCharIndexFromPosition(pt);
}
return 0; return 0;
} }
@ -497,9 +642,13 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_textBox.SelectAll(); _textBox.SelectAll();
} }
else else if (_uiTextBox != null)
{ {
_uiTextBox?.SelectAll(); _uiTextBox.SelectAll();
}
else if (_htmlBox != null)
{
_htmlBox.SelectAll();
} }
} }
@ -509,9 +658,13 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_textBox.Clear(); _textBox.Clear();
} }
else else if (_uiTextBox != null)
{ {
_uiTextBox?.Clear(); _uiTextBox.Clear();
}
else if (_htmlBox != null)
{
_htmlBox.Clear();
} }
} }
@ -521,9 +674,13 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_textBox.Undo(); _textBox.Undo();
} }
else else if (_uiTextBox != null)
{ {
_uiTextBox?.Undo(); _uiTextBox.Undo();
}
else if (_htmlBox != null)
{
_htmlBox.Undo();
} }
} }
@ -533,9 +690,13 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_textBox.ClearUndo(); _textBox.ClearUndo();
} }
else else if (_uiTextBox != null)
{ {
_uiTextBox?.ClearUndo(); _uiTextBox.ClearUndo();
}
else if (_htmlBox != null)
{
_htmlBox.ClearUndo();
} }
} }
@ -545,9 +706,13 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_textBox.Copy(); _textBox.Copy();
} }
else else if (_uiTextBox != null)
{ {
_uiTextBox?.Copy(); _uiTextBox.Copy();
}
else if (_htmlBox != null)
{
_htmlBox.Copy();
} }
} }
@ -557,9 +722,13 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_textBox.Cut(); _textBox.Cut();
} }
else else if (_uiTextBox != null)
{ {
_uiTextBox?.Cut(); _uiTextBox.Cut();
}
else if (_htmlBox != null)
{
_htmlBox.Cut();
} }
} }
@ -569,22 +738,36 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_textBox.Paste(); _textBox.Paste();
} }
else else if (_textBox != null)
{ {
_uiTextBox?.Paste(); _uiTextBox?.Paste();
} }
else if (_htmlBox != null)
{
_htmlBox?.Paste();
}
} }
public override bool Focused public override bool Focused
{ {
get get
{ {
if (_textBox == null && _uiTextBox == null) if (_textBox != null)
{ {
return false; return _textBox.Focused;
} }
return _textBox?.Focused ?? _uiTextBox.Focused; if (_uiTextBox != null)
{
return _uiTextBox.Focused;
}
if (_htmlBox != null)
{
return _htmlBox.Focused;
}
return false;
} }
} }
@ -594,9 +777,13 @@ namespace Nikse.SubtitleEdit.Controls
{ {
_textBox.Focus(); _textBox.Focus();
} }
else else if (_textBox != null)
{ {
_uiTextBox?.Focus(); _uiTextBox.Focus();
}
else if (_htmlBox != null)
{
_htmlBox.Focus();
} }
} }

View File

@ -0,0 +1,300 @@
using Nikse.SubtitleEdit.Core.Common;
using System;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Threading;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Controls.WebBrowser
{
[System.Runtime.InteropServices.ComVisibleAttribute(true)]
public class WebBrowserEditBox : System.Windows.Forms.WebBrowser
{
private bool _rightToLeft;
private bool _center;
public new event EventHandler TextChanged;
public new event KeyEventHandler KeyDown;
public new event MouseEventHandler MouseClick;
public new event EventHandler Enter;
public new event KeyEventHandler KeyUp;
public new event EventHandler Leave;
public new event MouseEventHandler MouseMove;
public WebBrowserEditBox()
{
DocumentCompleted += (sender, args) =>
{
Application.DoEvents();
Thread.Sleep(5);
Application.DoEvents();
Thread.Sleep(5);
Application.DoEvents();
Document?.InvokeScript("initEvents");
};
}
public void Initialize()
{
var assembly = Assembly.GetExecutingAssembly();
BringToFront();
using (var stream = assembly.GetManifestResourceStream("Nikse.SubtitleEdit.Controls.WebBrowser.WebBrowserEditBox.html"))
using (var reader = new StreamReader(stream))
{
var s = reader.ReadToEnd();
DocumentText = s;
}
Application.DoEvents();
Thread.Sleep(5);
Application.DoEvents();
for (int i = 0; i < 200 && ReadyState != WebBrowserReadyState.Complete; i++)
{
Application.DoEvents();
Thread.Sleep(5);
}
IsWebBrowserContextMenuEnabled = false;
AllowWebBrowserDrop = false;
ObjectForScripting = this;
}
public override string Text
{
get
{
if (Document == null)
{
return string.Empty;
}
var text = (Document.InvokeScript("getText") ?? string.Empty).ToString();
return string.Join(Environment.NewLine, text.SplitToLines());
}
set
{
if (Document != null)
{
if (Configuration.Settings.General.RightToLeftMode != _rightToLeft ||
Configuration.Settings.General.CenterSubtitleInTextBox != _center)
{
Application.DoEvents();
Thread.Sleep(5);
Application.DoEvents();
_rightToLeft = Configuration.Settings.General.RightToLeftMode;
_center = Configuration.Settings.General.CenterSubtitleInTextBox;
var code = "left";
if (_rightToLeft)
{
code = "rtl";
}
else if (_center)
{
code = "center";
}
Document.InvokeScript("setTextDirection", new object[] { code });
}
var text = string.Join("\n", value.SplitToLines());
Document.InvokeScript("setText", new object[] { text });
}
}
}
public new bool Enabled
{
get
{
if (Document == null)
{
return false;
}
var result = Document.InvokeScript("getEnabled");
return Convert.ToBoolean(result);
}
set
{
if (Document == null)
{
return;
}
Document.InvokeScript("setEnabled", new object[] { value });
}
}
public string SelectedText
{
get
{
if (Document == null)
{
return string.Empty;
}
return (Document.InvokeScript("getSelectionText") ?? string.Empty).ToString();
}
set
{
//TODO:
}
}
public int SelectionStart
{
get
{
if (Document == null)
{
return 0;
}
var position = (Document.InvokeScript("getCursorPosition") ?? "0").ToString();
if (int.TryParse(position, out var result))
{
var text = Text;
if (text.Length < result)
{
return text.Length;
}
return result;
}
return 0;
}
set
{
//TODO:
}
}
public int SelectionLength { get; set; }
public bool HideSelection { get; set; }
public void SelectAll()
{
if (Document == null)
{
return;
}
Document.ExecCommand("SelectAll", false, null);
}
public void Copy()
{
if (Document == null)
{
return;
}
Document.ExecCommand("copy", false, null);
}
public void Cut()
{
if (Document == null)
{
return;
}
Document.ExecCommand("cut", false, null);
}
public void Paste()
{
if (Document == null)
{
return;
}
Document.ExecCommand("paste", false, null);
}
public void ClientKeyDown(int keyCode, bool ctrlKey, bool shiftKey, bool altKey)
{
var keyData = (Keys)keyCode;
if (ctrlKey)
{
keyData = (keyData | Keys.Control);
}
if (shiftKey)
{
keyData = (keyData | Keys.Shift);
}
if (altKey)
{
keyData = (keyData | Keys.Alt);
}
KeyDown?.Invoke(this, new KeyEventArgs(keyData));
}
public void ClientFocus()
{
Enter?.Invoke(this, new KeyEventArgs(0));
}
public void ClientBlur()
{
Leave?.Invoke(this, new KeyEventArgs(0));
}
public void ClientChanged()
{
TextChanged?.Invoke(this, new KeyEventArgs(0));
}
public void ClientKeyUp(int keyCode, bool ctrlKey, bool shiftKey, bool altKey)
{
var keyData = (Keys)keyCode;
if (ctrlKey)
{
keyData = (keyData | Keys.Control);
}
if (shiftKey)
{
keyData = (keyData | Keys.Shift);
}
if (altKey)
{
keyData = (keyData | Keys.Alt);
}
KeyUp?.Invoke(this, new KeyEventArgs(keyData));
}
public void ClientClick()
{
MouseClick?.Invoke(this, new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 1));
}
public void ClientMouseMove()
{
MouseMove?.Invoke(this, new MouseEventArgs(MouseButtons.Left, 1, 1, 1, 1));
}
internal int GetCharIndexFromPosition(Point pt)
{
return 0;
}
public void Clear()
{
}
public void Undo()
{
}
public void ClearUndo()
{
}
}
}

View File

@ -0,0 +1,305 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<title>Browser Text Box</title>
<style>
body, html, #myContent {
height: 100%;
width: 100%;
}
body {
margin: 0;
padding: 0;
}
#myContent {
font-size: 16px;
font-family: Tahoma;
font-weight: bold;
color: brown;
/* border: 2px blue;
border-style: solid;*/
margin: 0;
padding: 0;
}
.disabled {
background: #f0f0f0;
}
p {
margin: 1px;
padding: 0;
}
html {
-ms-content-zooming: none; /* Disables zooming */
}
</style>
</head>
<body>
<div contenteditable="true" id="myContent" dir="ltr" style="text-align:center"></div>
<script>
window.addEventListener("keydown",
function (e) {
if (e.keyCode === 114 || (e.ctrlKey && e.keyCode === 70)) {
// prevent find dialog
e.preventDefault();
} else if (e.ctrlKey === true &&
(e.keyCode === 61 ||
e.keyCode === 107 ||
e.keyCode === 173 ||
e.keyCode === 109 ||
e.keyCode === 187 ||
e.keyCode === 189)) {
// prevent zoom
e.preventDefault();
}
});
// Use a more terse method for getting by id
function getById(id) {
return document.getElementById(id);
}
function initEvents() {
getById("myContent").addEventListener("focus", function (e) {
window.external.ClientFocus();
});
getById("myContent").addEventListener("blur", function (e) {
window.external.ClientBlur();
});
getById("myContent").addEventListener("keydown", function (e) {
window.external.ClientKeyDown(e.keyCode, e.ctrlKey, e.shiftKey, e.altKey);
});
getById("myContent").addEventListener("keyup", function (e) {
window.external.ClientKeyUp(e.keyCode, e.ctrlKey, e.shiftKey, e.altKey);
});
getById("myContent").addEventListener("change", function (e) {
window.external.ClientChanged();
});
getById("myContent").addEventListener("click", function (e) {
window.external.ClientClick();
});
getById("myContent").addEventListener("mousemove", function (e) {
window.external.ClientMouseMove();
});
}
function getPreviousOrParentLastChild(node) {
if (node.previousSibling) {
return [node.previousSibling, 0];
}
if (node.parentNode && node.parentNode.id === "myContent") {
return [null, 0];
}
var extraChar = 0;
if (node && node.parentNode.previousSibling) {
if (node.parentNode.previousSibling.lastChild) {
if (node.parentNode.nodeName === "P") {
if (node.parentNode.parentNode.id === "myContent" && !node.parentNode.previousSibling) {
// skip first P
} else {
extraChar = 1;
}
}
return [node.parentNode.previousSibling.lastChild, extraChar];
}
return [node.parentNode.previousSibling, extraChar];
}
return [null, extraChar];
}
function getNodePosition(node, offset) {
if (!node) {
return 0;
}
var idx = offset;
if (node.nodeName === "P" && node.previousSibling) {
idx++;
}
var res = getPreviousOrParentLastChild(node);
node = res[0];
if (res[1] > 0) {
idx++;
}
var i = 0;
while (node && i < 100) {
i++;
if (node.nodeType === 3) { // #text
if (node.nodeValue.indexOf("\n") >= 0) {
} else {
idx += node.length;
}
} else if (node.innerText) {
idx += node.innerText.length;
}
var res2 = getPreviousOrParentLastChild(node);
node = res2[0];
if (res2[1] > 0) {
idx++;
}
}
return idx;
}
function getCursorPosition() {
var x = window.getSelection();
return getNodePosition(x.focusNode, x.focusOffset);
}
function getSelectionText() {
return window.getSelection().toString();
}
function getSelectionStart() {
var x = window.getSelection();
return getNodePosition(x.anchorNode, x.anchorOffset);
}
function SetCaretPosition(el, pos) {
// Loop through all child nodes
for (var i = 0; i < el.childNodes.length; i++) {
var node = el.childNodes[i];
if (node.nodeType === 3) { // we have a text node
if (node.length >= pos) {
var range = document.createRange(),
sel = window.getSelection();
range.setStart(node, pos);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
return -1; // we are done
} else {
pos -= node.length;
}
} else {
pos = SetCaretPosition(node, pos);
if (pos === -1) {
return -1; // no need to finish the for loop
}
}
}
return pos;
}
function selectElementContents(el) {
var range = document.createRange();
range.selectNodeContents(el);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
}
function getNextNode(node) {
if (node.firstChild) {
return node.firstChild;
}
if (node.nextSibling) {
return node.nextSibling;
}
if (node.parentNode && node.parentNode.id !== "myContent" && node.parentNode.nextSibling) {
if (node.parentNode.nextSibling.firstChild) {
return node.parentNode.nextSibling;
}
return node.parentNode.nextSibling;
}
return null;
}
function setCursorPosition(pos) {
if (pos < 0) {
return;
}
var node = document.getElementById("myContent").firstChild;
var i = 0;
var idx = 0;
while (node && i < 100) {
i++;
if (node.nodeType === Node.TEXT_NODE && node.nodeValue) {
if (node.nodeValue && idx + node.nodeValue.length > pos) {
var range = document.createRange();
var sel = window.getSelection();
var newIdx = pos - idx;
range.setStart(node, newIdx);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
return;
}
idx += node.nodeValue.length;
}
node = getNextNode(node);
}
}
// Call with: rtl / center / left
function setTextDirection(dir) {
var element = document.getElementById("myContent");
if (dir === "rtl") {
element.setAttribute("dir", "rtl");
element.setAttribute("style", "");
} else if (dir === "center") {
element.setAttribute("style", "text-align:center");
element.setAttribute("dir", "");
} else {
element.setAttribute("style", "");
element.setAttribute("dir", "");
}
}
function getText() {
return document.getElementById("myContent").innerText;
}
function setText(text) {
document.getElementById("myContent").innerText = text;
}
function getEnabled() {
return !document.getElementById("myContent").hasAttribute("disabled");
}
function setEnabled(enable) {
if (enable) {
var mc = document.getElementById("myContent");
mc.removeAttribute('disabled');
mc.className = "";
} else {
document.getElementById("myContent").setAttribute('disabled', 'disabled');
document.getElementById("myContent").setAttribute('class', 'disabled');
}
}
</script>
</body>
</html>

View File

@ -1,9 +1,8 @@
using Nikse.SubtitleEdit.Core; using Nikse.SubtitleEdit.Core;
using System;
using System.Diagnostics;
using System.Windows.Forms;
using Nikse.SubtitleEdit.Core.Common; using Nikse.SubtitleEdit.Core.Common;
using Nikse.SubtitleEdit.Logic; using Nikse.SubtitleEdit.Logic;
using System;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms namespace Nikse.SubtitleEdit.Forms
{ {

View File

@ -558,6 +558,11 @@ namespace Nikse.SubtitleEdit.Logic
public static void FixFonts(Control form, int iterations = 5) public static void FixFonts(Control form, int iterations = 5)
{ {
if (form == null)
{
return;
}
FixFontsInner(form, iterations); FixFontsInner(form, iterations);
if (Configuration.Settings.General.UseDarkTheme) if (Configuration.Settings.General.UseDarkTheme)
{ {

View File

@ -88,6 +88,9 @@
<Compile Include="Controls\AudioVisualizer.Designer.cs"> <Compile Include="Controls\AudioVisualizer.Designer.cs">
<DependentUpon>AudioVisualizer.cs</DependentUpon> <DependentUpon>AudioVisualizer.cs</DependentUpon>
</Compile> </Compile>
<Compile Include="Controls\WebBrowser\WebBrowserEditBox.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Forms\AlignmentPickerJapanese.cs"> <Compile Include="Forms\AlignmentPickerJapanese.cs">
<SubType>Form</SubType> <SubType>Form</SubType>
</Compile> </Compile>
@ -1658,6 +1661,7 @@
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="Controls\WebBrowser\WebBrowserEditBox.html" />
<Content Include="DLLs\Voikkox64.dll" /> <Content Include="DLLs\Voikkox64.dll" />
<Content Include="DLLs\Voikkox86.dll" /> <Content Include="DLLs\Voikkox86.dll" />
<Content Include="Languages\ar-EG.xml"> <Content Include="Languages\ar-EG.xml">