📄 chateditctrlmanager.cs
字号:
namespace Imps.Client.Pc.BizControls
{
using Imps.Client.Core;
using Imps.Client.Core.CustomEmotion;
using Imps.Client.Resource;
using Imps.Client.Utils;
using Imps.Utils;
using Imps.Utils.TagParser;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
public class ChatEditCtrlManager : IDisposable
{
private bool _autoParseCustomEmotion;
private DelegateConvert _convertString;
private bool _convertSympol;
private int _count;
private Size _customEmotionPlaceholderSize;
private Color _defaultFontColor;
private string _defaultFontFamily;
private int _defaultFontSize;
private int _dragLength;
private int _dragStart;
private bool _firedByAnimation;
private bool _firedByFunction;
public int _firedCount;
private Color _forecolor;
private GetCustomEmotionDelegate _getCustomEmotion;
private GetCustomEmotionImageDelegate _getCustomEmotionImage;
private int _interval;
private Color _linkButtonColor;
private Font _linkButtonFont;
private Color _linkButtonHotKeyColor;
private Font _linkButtonHotKeyFont;
private List<ChatEditLinkObject> _linkObjectDict;
private int _maxSympol;
private Point _mouseDownLocation;
private int _oleIndex;
private Dictionary<OleKey, ChatEditOleObject> _oleObjDict;
private Dictionary<int, ChatEditOleObject> _oleObjIndexDict;
private List<Imps.Client.Core.CustomEmotion.CustomEmotion> _ownerEmotions;
private ChatRichTextBox _richTextBox;
private object _selectedObject;
private Size _sympolSize;
private List<Emoticon> _systemEmotions;
private Font _textFont;
private Imps.Client.Core.User _user;
private string[] allHtmlTag;
private bool m_fIsProcessKey;
public event BeforeContextMenuShowHandler BeforeContextMenuShow;
public event ChatEditClickEventHandler DoubleClick;
public event ChatEditDropHandler DragDrop;
public event KeyEventHandler KeyDown;
public event ChatEditClickEventHandler LinkButtonClick;
public event ChatEditClickEventHandler LinkClick;
public ChatEditCtrlManager(ChatRichTextBox richTextBox, bool bReadOnly) : this(richTextBox, bReadOnly, null)
{
}
public ChatEditCtrlManager(ChatRichTextBox richTextBox, bool bReadOnly, Imps.Client.Core.User user)
{
this._linkObjectDict = new List<ChatEditLinkObject>();
this._interval = 100;
this._defaultFontFamily = "宋体";
this._defaultFontSize = 12;
this._defaultFontColor = Color.FromArgb(0, 0, 0);
this._maxSympol = 10;
this._mouseDownLocation = Point.Empty;
this._dragStart = -1;
this._dragLength = -1;
this._linkButtonColor = Color.Blue;
this._linkButtonHotKeyColor = Color.Gray;
this.allHtmlTag = new string[] { "font", "b", "i", "u", "s" };
this._sympolSize = Size.Empty;
this._customEmotionPlaceholderSize = new Size(0x19, 0x19);
this._ownerEmotions = new List<Imps.Client.Core.CustomEmotion.CustomEmotion>();
this._systemEmotions = new List<Emoticon>();
this._user = user;
this._richTextBox = richTextBox;
this._oleIndex = 0;
this._oleObjDict = new Dictionary<OleKey, ChatEditOleObject>();
this._oleObjIndexDict = new Dictionary<int, ChatEditOleObject>();
this._richTextBox.LinkClicked += new LinkClickedEventHandler(this._richTextBox_LinkClicked);
this._richTextBox.AllowDrop = true;
this._richTextBox.DragEnter += new DragEventHandler(this._richTextBox_DragEnter);
this._richTextBox.DragDrop += new DragEventHandler(this._richTextBox_DragDrop);
this._richTextBox.DoubleClick += new EventHandler(this._richTextBox_DoubleClick);
this._richTextBox.KeyPress += new KeyPressEventHandler(this._richTextBox_KeyPress);
this._richTextBox.KeyDown += new KeyEventHandler(this._richTextBox_KeyDown);
this._richTextBox.KeyUp += new KeyEventHandler(this._richTextBox_KeyUp);
this._richTextBox.TextChanged += new EventHandler(this._richTextBox_TextChanged);
this._richTextBox.MouseDown += new MouseEventHandler(this._richTextBox_MouseDown);
this._richTextBox.MouseMove += new MouseEventHandler(this._richTextBox_MouseMove);
this._richTextBox.ForeColor = SystemColors.ControlText;
this._richTextBox.DetectUrls = bReadOnly;
}
private void _richTextBox_DoubleClick(object sender, EventArgs e)
{
if (this._richTextBox.SelectionType == RichTextBoxSelectionTypes.Object)
{
if (this.DoubleClick != null)
{
REOBJECT oleObject = this._richTextBox.GetOleObject(this._richTextBox.SelectionStart);
ChatEditOleObject obj2 = this._oleObjIndexDict.get_Item((int) oleObject.dwUser);
ChatEditImageObject obj3 = obj2 as ChatEditImageObject;
if (obj3 != null)
{
ChatEditClickEventArgs args = new ChatEditClickEventArgs(obj3.Key, string.Empty, obj3.Text, string.Empty, ChatEditEventType.IMAGE);
this.DoubleClick(this, args);
}
else
{
ChatEditProgressBarObject obj4 = obj2 as ChatEditProgressBarObject;
if (obj4 != null)
{
ChatEditClickEventArgs args2 = new ChatEditClickEventArgs(obj4.Key, string.Empty, string.Empty, string.Empty, ChatEditEventType.PROGRESSBAR);
this.DoubleClick(this, args2);
}
}
}
}
else if (this.DoubleClick != null)
{
ChatEditClickEventArgs args3 = new ChatEditClickEventArgs(null, string.Empty, string.Empty, string.Empty, ChatEditEventType.TEXT);
this.DoubleClick(this, args3);
}
}
private void _richTextBox_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(typeof(string)))
{
string sText = (string) e.Data.GetData(typeof(string));
string sOut = string.Empty;
bool dragDropText = ImpsDragDropHelper.DragDropHelper.GetDragDropText(sText, out sOut);
if ((this._dragStart != -1) || (this._dragLength != -1))
{
int selectionStart = this._richTextBox.SelectionStart;
this._richTextBox.SelectionStart = this._dragStart;
this._richTextBox.SelectionLength = this._dragLength;
this._richTextBox.SelectedText = string.Empty;
this._dragStart = -1;
this._dragLength = -1;
this._richTextBox.SelectionStart = selectionStart;
if ((this._convertString != null) && !dragDropText)
{
sOut = this._convertString(sOut);
}
if (!this.ReadOnly)
{
this.InsertString(this._richTextBox.SelectionStart, sOut, this._sympolSize);
this.Focus();
}
this._count++;
}
else
{
e.Effect = DragDropEffects.None;
}
}
if (e.Data.GetDataPresent("{66FFF7D8-C9A4-4a5d-9707-82D22DF3633F}"))
{
tree_widget.dragging_data _data = e.Data.GetData("{66FFF7D8-C9A4-4a5d-9707-82D22DF3633F}") as tree_widget.dragging_data;
if (_data.dragging_item.data is tree_widget_buddy)
{
Imps.Client.Core.Contact contact = (_data.dragging_item.data as tree_widget_buddy).contact;
if (this.DragDrop != null)
{
ChatEditDropEventArgs args = new ChatEditDropEventArgs(contact);
this.DragDrop(this, args);
}
}
}
if (e.Data.GetDataPresent(ImpsDataFormat.ImpsContact))
{
Imps.Client.Core.Contact contact2 = e.Data.GetData(ImpsDataFormat.ImpsContact) as Imps.Client.Core.Contact;
if (contact2 == null)
{
return;
}
if (this.DragDrop != null)
{
ChatEditDropEventArgs args2 = new ChatEditDropEventArgs(contact2);
this.DragDrop(this, args2);
}
}
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[]) e.Data.GetData(DataFormats.FileDrop);
if (this.DragDrop != null)
{
ChatEditDropEventArgs args3 = new ChatEditDropEventArgs(files);
this.DragDrop(this, args3);
}
e.Effect = DragDropEffects.None;
}
e.Effect = DragDropEffects.None;
try
{
this._richTextBox.FindForm().Activate();
}
catch
{
}
}
private void _richTextBox_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
this._dragStart = this._richTextBox.SelectionStart;
this._dragLength = this._richTextBox.SelectionLength;
string selectedText = this._richTextBox.SelectedText;
}
private void _richTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (Keys.ProcessKey == e.KeyCode)
{
this.m_fIsProcessKey = true;
}
else
{
if ((e.Control && (e.KeyCode == Keys.V)) || (e.Shift && (e.KeyCode == Keys.Insert)))
{
bool isSystemClipBoard = false;
if (!ImpsClipboard.GetImpsHtml(ref isSystemClipBoard).Equals(string.Empty) && !this.ReadOnly)
{
this.DoPaste();
e.Handled = true;
return;
}
e.Handled = true;
}
if (e.Control && (e.KeyCode == Keys.C))
{
this.DoCopy();
e.Handled = true;
}
else if (e.Control && (e.KeyCode == Keys.X))
{
this.DoCut();
e.Handled = true;
}
else
{
if (e.Alt && (this.LinkButtonClick != null))
{
ChatEditLinkObject link = this.GetLink(e.KeyValue);
if (link != null)
{
ChatEditClickEventArgs args = new ChatEditClickEventArgs(link.key, link.Command, link.Text, link.OnClick, ChatEditEventType.LinkButton);
this.LinkButtonClick(this, args);
e.Handled = true;
return;
}
}
if (this.KeyDown != null)
{
this.KeyDown(sender, e);
}
}
}
}
private void _richTextBox_KeyPress(object sender, KeyPressEventArgs e)
{
if (((e.KeyChar == '\n') || (e.KeyChar == '\r')) && (this._richTextBox.SelectionStart == this._richTextBox.TextLength))
{
try
{
this._richTextBox.SelectionFont = this._textFont;
this._richTextBox.ForeColor = this._forecolor;
}
catch
{
}
}
}
private void _richTextBox_KeyUp(object sender, KeyEventArgs e)
{
}
private void _richTextBox_LinkClicked(object sender, LinkClickedEventArgs e)
{
string linkText = e.LinkText;
int selectionStart = this._richTextBox.SelectionStart;
Point pt = new Point();
GetCursorPos(ref pt);
pt = this._richTextBox.PointToClient(pt);
selectionStart = this._richTextBox.GetCharIndexFromPosition(pt);
List<ChatEditLinkObject>.Enumerator enumerator = this._linkObjectDict.GetEnumerator();
try
{
while (enumerator.MoveNext())
{
ChatEditLinkObject obj2 = enumerator.get_Current();
if ((selectionStart >= obj2.Pos) && (selectionStart <= (obj2.Pos + obj2.Text.Length)))
{
string command = obj2.Command;
if (this.LinkButtonClick != null)
{
ChatEditClickEventArgs args = new ChatEditClickEventArgs(obj2.key, obj2.Command, obj2.Text, obj2.OnClick, ChatEditEventType.LinkButton);
this.LinkButtonClick(this, args);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -