public virtual bool PreProcessWmChar(ref Message m)
{
if (Control.ModifierKeys == Keys.Control)
{
return _hexBox.BasePreProcessMessage(ref m);
}
bool sw = _hexBox._byteProvider.SupportsWriteByte();
bool si = _hexBox._byteProvider.SupportsInsertBytes();
bool sd = _hexBox._byteProvider.SupportsDeleteBytes();
long pos = _hexBox._bytePos;
long sel = _hexBox._selectionLength;
int cp = _hexBox._byteCharacterPos;
if (
(!sw && pos != _hexBox._byteProvider.Length) ||
(!si && pos == _hexBox._byteProvider.Length))
{
return _hexBox.BasePreProcessMessage(ref m);
}
char c = (char)m.WParam.ToInt32();
if (Uri.IsHexDigit(c))
{
if (RaiseKeyPress(c))
return true;
if (_hexBox.ReadOnly)
return true;
bool isInsertMode = (pos == _hexBox._byteProvider.Length);
// do insert when insertActive = true
if (!isInsertMode && si && _hexBox.InsertActive && cp == 0)
isInsertMode = true;
if (sd && si && sel > 0)
{
_hexBox._byteProvider.DeleteBytes(pos, sel);
isInsertMode = true;
cp = 0;
_hexBox.SetPosition(pos, cp);
}
_hexBox.ReleaseSelection();
byte currentByte;
if (isInsertMode)
currentByte = 0;
else
currentByte = _hexBox._byteProvider.ReadByte(pos);
string sCb = currentByte.ToString("X", System.Threading.Thread.CurrentThread.CurrentCulture);
if (sCb.Length == 1)
sCb = "0" + sCb;
string sNewCb = c.ToString();
if (cp == 0)
sNewCb += sCb.Substring(1, 1);
else
sNewCb = sCb.Substring(0, 1) + sNewCb;
byte newcb = byte.Parse(sNewCb, System.Globalization.NumberStyles.AllowHexSpecifier, System.Threading.Thread.CurrentThread.CurrentCulture);
if (isInsertMode)
_hexBox._byteProvider.InsertBytes(pos, new byte[] { newcb });
else
_hexBox._byteProvider.WriteByte(pos, newcb);
PerformPosMoveRight();
_hexBox.Invalidate();
return true;
}
else
{
return _hexBox.BasePreProcessMessage(ref m);
}
}