Browse Source

- Renamed HexEditControl to Editor

- Changed caret to custom drawing without WinAPI (not blinking anymore)
- Updated changes.txt, added bugs found by Matt Ward
- Improved calculation methods GetOffsetForPosition and GetPositionForOffset -> setting of the position of caret is much easier now.
- Improved drawing methods, removed GC.Collect() call at the end of drawing -> faster.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2995 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Siegfried Pammer 18 years ago
parent
commit
f8c1795d4d
  1. 13
      src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.csproj
  2. 86
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.Designer.cs
  3. 384
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.cs
  4. 126
      src/AddIns/DisplayBindings/HexEditor/Project/Src/HexEditControl.resx
  5. 12
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/BufferManager.cs
  6. 67
      src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/Caret.cs
  7. 4
      src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.Designer.cs
  8. 6
      src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs
  9. 4
      src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditOptionsPanel.cs
  10. 12
      src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditView.cs
  11. 17
      src/AddIns/DisplayBindings/HexEditor/Project/changes.txt

13
src/AddIns/DisplayBindings/HexEditor/Project/HexEditor.csproj

@ -22,14 +22,14 @@ @@ -22,14 +22,14 @@
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>..\..\..\..\..\AddIns\AddIns\DisplayBindings\HexEditor</OutputPath>
<OutputPath>..\..\..\..\..\AddIns\AddIns\DisplayBindings\HexEditor\</OutputPath>
<DebugSymbols>true</DebugSymbols>
<DebugType>Full</DebugType>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<Optimize>False</Optimize>
<StartAction>Program</StartAction>
<StartProgram>..\..\..\..\bin\SharpDevelop.exe</StartProgram>
<StartProgram>..\..\..\..\..\bin\SharpDevelop.exe</StartProgram>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>..\..\..\..\..\AddIns\AddIns\DisplayBindings\HexEditor</OutputPath>
@ -59,11 +59,11 @@ @@ -59,11 +59,11 @@
<Link>Configuration\GlobalAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Configuration\AssemblyInfo.cs" />
<Compile Include="Src\HexEditControl.cs">
<Compile Include="Src\Editor.cs">
<SubType>UserControl</SubType>
</Compile>
<Compile Include="Src\HexEditControl.Designer.cs">
<DependentUpon>HexEditControl.cs</DependentUpon>
<Compile Include="Src\Editor.Designer.cs">
<DependentUpon>Editor.cs</DependentUpon>
</Compile>
<Compile Include="Src\Util\BufferManager.cs" />
<Compile Include="Src\Util\Caret.cs" />
@ -90,9 +90,6 @@ @@ -90,9 +90,6 @@
<None Include="HexEditor.addin">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<EmbeddedResource Include="Src\HexEditControl.resx">
<DependentUpon>HexEditControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Src\View\HexEditContainer.resx">
<SubType>Designer</SubType>
<DependentUpon>HexEditContainer.cs</DependentUpon>

86
src/AddIns/DisplayBindings/HexEditor/Project/Src/HexEditControl.Designer.cs → src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.Designer.cs generated

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
namespace HexEditor
{
public partial class HexEditControl
public partial class Editor
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
@ -37,10 +37,10 @@ namespace HexEditor @@ -37,10 +37,10 @@ namespace HexEditor
{
this.bWorker = new System.ComponentModel.BackgroundWorker();
this.VScrollBar = new System.Windows.Forms.VScrollBar();
this.TextView = new System.Windows.Forms.Panel();
this.HexView = new System.Windows.Forms.Panel();
this.Side = new System.Windows.Forms.Panel();
this.Header = new System.Windows.Forms.Panel();
this.textView = new System.Windows.Forms.Panel();
this.hexView = new System.Windows.Forms.Panel();
this.side = new System.Windows.Forms.Panel();
this.header = new System.Windows.Forms.Panel();
this.SuspendLayout();
//
// VScrollBar
@ -55,70 +55,70 @@ namespace HexEditor @@ -55,70 +55,70 @@ namespace HexEditor
//
// TextView
//
this.TextView.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
this.TextView.Cursor = System.Windows.Forms.Cursors.IBeam;
this.TextView.Location = new System.Drawing.Point(561, 18);
this.TextView.Name = "TextView";
this.TextView.Size = new System.Drawing.Size(108, 347);
this.TextView.TabIndex = 12;
this.TextView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseDown);
this.TextView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseMove);
this.TextView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseClick);
this.TextView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseUp);
this.textView.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
this.textView.Cursor = System.Windows.Forms.Cursors.IBeam;
this.textView.Location = new System.Drawing.Point(561, 18);
this.textView.Name = "TextView";
this.textView.Size = new System.Drawing.Size(108, 347);
this.textView.TabIndex = 12;
this.textView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseMove);
this.textView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseClick);
this.textView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseDown);
this.textView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.TextViewMouseUp);
//
// HexView
//
this.HexView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.hexView.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.HexView.Cursor = System.Windows.Forms.Cursors.IBeam;
this.HexView.Location = new System.Drawing.Point(92, 18);
this.HexView.Name = "HexView";
this.HexView.Size = new System.Drawing.Size(463, 347);
this.HexView.TabIndex = 11;
this.HexView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseDown);
this.HexView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseMove);
this.HexView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseClick);
this.HexView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseUp);
this.hexView.Cursor = System.Windows.Forms.Cursors.IBeam;
this.hexView.Location = new System.Drawing.Point(92, 18);
this.hexView.Name = "HexView";
this.hexView.Size = new System.Drawing.Size(463, 347);
this.hexView.TabIndex = 11;
this.hexView.MouseMove += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseMove);
this.hexView.MouseClick += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseClick);
this.hexView.MouseDown += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseDown);
this.hexView.MouseUp += new System.Windows.Forms.MouseEventHandler(this.HexViewMouseUp);
//
// Side
//
this.Side.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
this.side.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.Side.Location = new System.Drawing.Point(0, 0);
this.Side.Name = "Side";
this.Side.Size = new System.Drawing.Size(76, 365);
this.Side.TabIndex = 10;
this.side.Location = new System.Drawing.Point(0, 0);
this.side.Name = "Side";
this.side.Size = new System.Drawing.Size(76, 365);
this.side.TabIndex = 10;
//
// Header
//
this.Header.Location = new System.Drawing.Point(92, 0);
this.Header.Name = "Header";
this.Header.Size = new System.Drawing.Size(463, 18);
this.Header.TabIndex = 13;
this.header.Location = new System.Drawing.Point(92, 0);
this.header.Name = "Header";
this.header.Size = new System.Drawing.Size(463, 18);
this.header.TabIndex = 13;
//
// HexEditControl
//
this.BackColor = System.Drawing.Color.White;
this.Controls.Add(this.Header);
this.Controls.Add(this.TextView);
this.Controls.Add(this.HexView);
this.Controls.Add(this.Side);
this.Controls.Add(this.header);
this.Controls.Add(this.textView);
this.Controls.Add(this.hexView);
this.Controls.Add(this.side);
this.Controls.Add(this.VScrollBar);
this.DoubleBuffered = true;
this.Name = "HexEditControl";
this.Size = new System.Drawing.Size(688, 365);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.HexEditPaint);
this.ContextMenuStripChanged += new System.EventHandler(this.HexEditControlContextMenuStripChanged);
this.GotFocus += new System.EventHandler(this.HexEditGotFocus);
this.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.HexEditKeyPress);
this.Paint += new System.Windows.Forms.PaintEventHandler(this.HexEditPaint);
this.SizeChanged += new System.EventHandler(this.HexEditSizeChanged);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.HexEditKeyDown);
this.ResumeLayout(false);
}
private System.Windows.Forms.Panel Header;
private System.Windows.Forms.Panel Side;
private System.Windows.Forms.Panel HexView;
private System.Windows.Forms.Panel TextView;
private System.Windows.Forms.Panel header;
private System.Windows.Forms.Panel side;
private System.Windows.Forms.Panel hexView;
private System.Windows.Forms.Panel textView;
private System.ComponentModel.BackgroundWorker bWorker;
private System.Windows.Forms.VScrollBar VScrollBar;
}

384
src/AddIns/DisplayBindings/HexEditor/Project/Src/HexEditControl.cs → src/AddIns/DisplayBindings/HexEditor/Project/Src/Editor.cs

@ -13,11 +13,12 @@ using System.IO; @@ -13,11 +13,12 @@ using System.IO;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Diagnostics;
//using System.Diagnostics;
using ICSharpCode.SharpDevelop;
using HexEditor.Util;
//using HexEditor.Commands;
namespace HexEditor
{
@ -27,25 +28,76 @@ namespace HexEditor @@ -27,25 +28,76 @@ namespace HexEditor
/// <summary>
/// Hexadecimal editor control.
/// </summary>
public partial class HexEditControl : UserControl
public partial class Editor : UserControl
{
/// <summary>
/// number of the first visible line (first line = 0)
/// </summary>
int topline;
int caretwidth, charwidth, hexinputmodepos;
public int TopLine {
get { return topline; }
set { topline = value; }
}
int charwidth, hexinputmodepos;
int underscorewidth, underscorewidth3, fontheight;
bool hexViewFocus, textViewFocus, insertmode, hexinputmode, selectionmode, handled, moved;
bool shiftwaspressed;
bool insertmode, hexinputmode, selectionmode, handled, moved;
public bool Moved {
get { return moved; }
set { moved = value; }
}
public bool Handled {
get { return handled; }
set { handled = value; }
}
public bool Selectionmode {
get { return selectionmode; }
set { selectionmode = value; }
}
public bool HexInputMode {
get { return hexinputmode; }
set { hexinputmode = value; }
}
public bool Insertmode {
get { return insertmode; }
set { insertmode = value; }
}
Rectangle[] selregion;
Point[] selpoints;
BufferManager buffer;
Caret caret;
public Caret Caret {
get { return caret; }
}
SelectionManager selection;
UndoManager undoStack;
Color offsetForeColor, offsetBackColor, dataForeColor, dataBackColor;
bool offsetBold, offsetItalic, offsetUnderline, dataBold, dataItalic, dataUnderline;
Font offsetFont, dataFont;
Panel activeView;
//HexInput hexInputHandler;
// public HexInput HexInputHandler {
// get { return hexInputHandler; }
// }
public Panel ActiveView {
get { return activeView; }
set { activeView = value; }
}
private Bitmap bHeader, bSide, bHex, bText;
private Graphics gbHeader, gbSide, gbHex, gbText,
gHeader, gSide, gHex, gText;
/// <summary>
/// Event fired every time something is changed in the editor.
@ -67,7 +119,7 @@ namespace HexEditor @@ -67,7 +119,7 @@ namespace HexEditor
/// <summary>
/// Creates a new HexEditor Control with basic settings and initialises all components.
/// </summary>
public HexEditControl()
public Editor()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
@ -77,9 +129,7 @@ namespace HexEditor @@ -77,9 +129,7 @@ namespace HexEditor
buffer = new BufferManager(this);
selection = new SelectionManager(ref buffer);
undoStack = new UndoManager();
caret = new Caret(this, 1, fontheight, 0);
insertmode = true;
caretwidth = 1;
underscorewidth = MeasureStringWidth(this.CreateGraphics(), "_", this.Font);
underscorewidth3 = underscorewidth * 3;
fontheight = GetFontHeight(this.Font);
@ -90,6 +140,12 @@ namespace HexEditor @@ -90,6 +140,12 @@ namespace HexEditor
this.offsetFont = new Font(this.Font, FontStyle.Regular);
this.dataFont = new Font(this.Font, FontStyle.Regular);
this.ActiveView = this.hexView;
UpdatePainters();
caret = new Caret(this.gbHex, 1, fontheight, 0);
// TODO : Implement settings
//LoadSettings();
@ -103,7 +159,7 @@ namespace HexEditor @@ -103,7 +159,7 @@ namespace HexEditor
/// <remarks>Currently not working, because there's no options dialog implemented.</remarks>
public void LoadSettings()
{
string configpath = Path.GetDirectoryName(typeof(HexEditControl).Assembly.Location) + Path.DirectorySeparatorChar + "config.xml";
string configpath = Path.GetDirectoryName(typeof(Editor).Assembly.Location) + Path.DirectorySeparatorChar + "config.xml";
if (!File.Exists(configpath)) return;
@ -200,6 +256,7 @@ namespace HexEditor @@ -200,6 +256,7 @@ namespace HexEditor
case Keys.Up:
case Keys.Left:
case Keys.Right:
//case Keys.Tab:
return true;
}
return false;
@ -253,9 +310,9 @@ namespace HexEditor @@ -253,9 +310,9 @@ namespace HexEditor
get { return base.Enabled; }
set {
if (this.InvokeRequired) {
base.Enabled = this.VScrollBar.Enabled = this.HexView.Enabled = this.TextView.Enabled = this.Side.Enabled = this.Header.Enabled = value;
base.Enabled = this.VScrollBar.Enabled = this.hexView.Enabled = this.textView.Enabled = this.side.Enabled = this.header.Enabled = value;
} else {
base.Enabled = this.VScrollBar.Enabled = this.HexView.Enabled = this.TextView.Enabled = this.Side.Enabled = this.Header.Enabled = value;
base.Enabled = this.VScrollBar.Enabled = this.hexView.Enabled = this.textView.Enabled = this.side.Enabled = this.header.Enabled = value;
}
}
}
@ -314,7 +371,7 @@ namespace HexEditor @@ -314,7 +371,7 @@ namespace HexEditor
public bool FitToWindowWidth
{
get { return fitToWindowWidth; }
set {
set {
fitToWindowWidth = value;
if (value) this.BytesPerLine = CalculateMaxBytesPerLine();
}
@ -334,6 +391,8 @@ namespace HexEditor @@ -334,6 +391,8 @@ namespace HexEditor
this.headertext = GetHeaderText();
UpdatePainters();
this.Invalidate();
}
}
@ -440,13 +499,13 @@ namespace HexEditor @@ -440,13 +499,13 @@ namespace HexEditor
void HexViewMouseClick(object sender, MouseEventArgs e)
{
this.Focus();
hexViewFocus = true;
textViewFocus = false;
this.ActiveView = this.hexView;
this.charwidth = 3;
this.caretwidth = 1;
if (!insertmode) caretwidth = underscorewidth3;
this.caret.Width = 1;
if (!insertmode)
this.caret.Width = underscorewidth * 2;
caret.Create(this.HexView, caretwidth, fontheight);
caret.Graphics = this.gbHex;
if (e.Button != MouseButtons.Right) {
if (!moved) {
@ -463,7 +522,6 @@ namespace HexEditor @@ -463,7 +522,6 @@ namespace HexEditor
caret.SetToPosition(GetPositionForOffset(caret.Offset, 3));
this.Invalidate();
caret.Show();
}
/// <summary>
@ -473,12 +531,11 @@ namespace HexEditor @@ -473,12 +531,11 @@ namespace HexEditor
{
this.Focus();
hexinputmode = false;
hexViewFocus = false;
textViewFocus = true;
this.ActiveView = this.textView;
this.charwidth = 1;
this.caretwidth = 1;
if (!insertmode) caretwidth = underscorewidth;
caret.Create(this.TextView, caretwidth, fontheight);
this.caret.Width = 1;
if (!insertmode) this.caret.Width = underscorewidth;
caret.Graphics = this.gbText;
if (e.Button != MouseButtons.Right) {
if (!moved) {
@ -492,16 +549,13 @@ namespace HexEditor @@ -492,16 +549,13 @@ namespace HexEditor
this.Focus();
hexinputmode = false;
hexViewFocus = false;
textViewFocus = true;
this.ActiveView = this.textView;
this.charwidth = 1;
this.caretwidth = 1;
if (!insertmode) caretwidth = underscorewidth;
caret.Create(this.TextView, caretwidth, fontheight);
this.caret.Width = 1;
if (!insertmode) this.caret.Width = underscorewidth;
caret.Offset = this.GetOffsetForPosition(e.Location, 1);
caret.SetToPosition(GetPositionForOffset(caret.Offset, 1));
this.Invalidate();
caret.Show();
}
#endregion
@ -516,31 +570,25 @@ namespace HexEditor @@ -516,31 +570,25 @@ namespace HexEditor
// Paint using double buffering for better painting!
// Bitmaps for painting
Bitmap Header = new Bitmap(this.Width, this.Height, this.Header.CreateGraphics());
Bitmap Side = new Bitmap(this.Side.Width, this.Side.Height, this.Side.CreateGraphics());
Bitmap Hex = new Bitmap(this.HexView.Width, this.HexView.Height, this.HexView.CreateGraphics());
Bitmap Text = new Bitmap(this.TextView.Width, this.TextView.Height, this.TextView.CreateGraphics());
// Do painting.
PaintHex(Graphics.FromImage(Hex), VScrollBar.Value);
PaintOffsetNumbers(Graphics.FromImage(Side), VScrollBar.Value);
PaintHeader(Graphics.FromImage(Header));
PaintText(Graphics.FromImage(Text), VScrollBar.Value);
PaintPointer(Graphics.FromImage(Hex), Graphics.FromImage(Text));
PaintSelection(Graphics.FromImage(Hex), Graphics.FromImage(Text), true);
PaintHex(gbHex, VScrollBar.Value);
PaintOffsetNumbers(gbSide, VScrollBar.Value);
PaintHeader(gbHeader);
PaintText(gbText, VScrollBar.Value);
PaintPointer(gbHex, gbText);
PaintSelection(gbHex, gbText, true);
this.caret.DrawCaret();
// Calculate views and reset scrollbar.
SetViews();
AdjustScrollBar();
// Paint on device ...
this.Header.CreateGraphics().DrawImageUnscaled(Header, 0, 0);
this.Side.CreateGraphics().DrawImageUnscaled(Side, 0, 0);
this.HexView.CreateGraphics().DrawImageUnscaled(Hex, 0, 0);
this.TextView.CreateGraphics().DrawImageUnscaled(Text, 0, 0);
GC.Collect();
this.gHeader.DrawImageUnscaled(bHeader, 0, 0);
this.gSide.DrawImageUnscaled(bSide, 0, 0);
this.gHex.DrawImageUnscaled(bHex, 0, 0);
this.gText.DrawImageUnscaled(bText, 0, 0);
}
/// <summary>
@ -551,7 +599,7 @@ namespace HexEditor @@ -551,7 +599,7 @@ namespace HexEditor
{
g.Clear(Color.White);
TextRenderer.DrawText(g, headertext,
this.Font, new Rectangle(1, 1, this.HexView.Width + 5, fontheight),
this.Font, new Rectangle(1, 1, this.hexView.Width + 5, fontheight),
Color.Blue, this.BackColor, TextFormatFlags.Left & TextFormatFlags.Top);
}
@ -601,7 +649,7 @@ namespace HexEditor @@ -601,7 +649,7 @@ namespace HexEditor
text = builder.ToString();
builder = null;
TextRenderer.DrawText(g, text, this.Font, new Rectangle(0, 0, this.Side.Width, this.Side.Height), Color.Blue, this.BackColor, TextFormatFlags.Right);
TextRenderer.DrawText(g, text, this.Font, new Rectangle(0, 0, this.side.Width, this.side.Height), Color.Blue, this.BackColor, TextFormatFlags.Right);
}
/// <summary>
@ -612,24 +660,16 @@ namespace HexEditor @@ -612,24 +660,16 @@ namespace HexEditor
void PaintHex(System.Drawing.Graphics g, int top)
{
g.Clear(Color.White);
string text = String.Empty;
StringBuilder builder = new StringBuilder();
int offset = GetOffsetForLine(top);
for (int i = 0; i < GetMaxVisibleLines(); i++) {
string line = GetHex(buffer.GetBytes(offset, this.BytesPerLine));
if (line == String.Empty) {
text += new string(' ', this.BytesPerLine * 3) + "\n";
} else if (line.Length < this.BytesPerLine * 3) {
text += line + new string(' ', this.BytesPerLine * 3 - line.Length) + "\n";
} else {
text += line + "\n";
}
builder.AppendLine(GetHex(buffer.GetBytes(offset, this.BytesPerLine)));
offset = GetOffsetForLine(top + i + 1);
}
TextRenderer.DrawText(g, text, this.Font, new Rectangle(0, 0, this.HexView.Width, this.HexView.Height), this.ForeColor, this.BackColor, TextFormatFlags.Left & TextFormatFlags.Top);
TextRenderer.DrawText(g, builder.ToString(), this.Font, new Rectangle(0, 0, this.hexView.Width, this.hexView.Height), this.ForeColor, this.BackColor, TextFormatFlags.Left & TextFormatFlags.Top);
}
/// <summary>
@ -661,14 +701,14 @@ namespace HexEditor @@ -661,14 +701,14 @@ namespace HexEditor
{
// Paint a rectangle as a pointer in the view without the focus ...
if (selection.HasSomethingSelected) return;
if (hexViewFocus) {
if (this.ActiveView == this.hexView) {
Point pos = this.GetPositionForOffset(caret.Offset, 1);
if (hexinputmode) pos = this.GetPositionForOffset(caret.Offset - 1, 1);
Size size = new Size(underscorewidth, fontheight);
Pen p = new Pen(Color.Black, 1f);
p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;
textView.DrawRectangle(p, new Rectangle(pos, size));
} else if (textViewFocus) {
} else {
Point pos = this.GetPositionForOffset(caret.Offset, 3);
pos.Offset(0, 1);
Size size = new Size(underscorewidth * 2, fontheight);
@ -705,7 +745,7 @@ namespace HexEditor @@ -705,7 +745,7 @@ namespace HexEditor
if (end > GetOffsetForLine(topline + GetMaxVisibleLines())) end = GetOffsetForLine(topline + GetMaxVisibleLines() + 1);
if (hexViewFocus)
if (this.activeView == this.hexView)
{
if (GetLineForOffset(end) == GetLineForOffset(start)) {
Point pt = GetPositionForOffset(start, 3);
@ -783,7 +823,7 @@ namespace HexEditor @@ -783,7 +823,7 @@ namespace HexEditor
}
selpoints = (Point[])al.ToArray(typeof(Point));
} else if (textViewFocus) {
} else {
if (GetLineForOffset(end) == GetLineForOffset(start)) {
Point pt = GetPositionForOffset(start, 1);
al.Add(new Rectangle(new Point(pt.X - 4, pt.Y), new Size((end - start) * underscorewidth + 3, fontheight)));
@ -806,7 +846,7 @@ namespace HexEditor @@ -806,7 +846,7 @@ namespace HexEditor
al.Clear();
start = start_dummy;
if (GetLineForOffset(end) == GetLineForOffset(start)) {
Point pt = GetPositionForOffset(start, 3);
al.Add(new Point(pt.X - 1, pt.Y));
@ -889,7 +929,7 @@ namespace HexEditor @@ -889,7 +929,7 @@ namespace HexEditor
if (start < GetOffsetForLine(topline)) start = GetOffsetForLine(topline) - 2;
if (end > GetOffsetForLine(topline + GetMaxVisibleLines())) end = GetOffsetForLine(topline + GetMaxVisibleLines() + 1);
if (hexViewFocus) {
if (this.activeView == this.hexView) {
StringBuilder builder = new StringBuilder();
for (int i = GetLineForOffset(start) + 1; i < GetLineForOffset(end); i++) {
@ -916,7 +956,7 @@ namespace HexEditor @@ -916,7 +956,7 @@ namespace HexEditor
} else {
textView.DrawPolygon(Pens.Black, selpoints);
}
} else if (textViewFocus) {
} else {
StringBuilder builder = new StringBuilder();
for (int i = GetLineForOffset(start) + 1; i < GetLineForOffset(end); i++) {
@ -1008,7 +1048,7 @@ namespace HexEditor @@ -1008,7 +1048,7 @@ namespace HexEditor
this.Invalidate();
}
public bool HasSelection {
public bool HasSomethingSelected {
get { return selection.HasSomethingSelected; }
}
@ -1082,19 +1122,12 @@ namespace HexEditor @@ -1082,19 +1122,12 @@ namespace HexEditor
selection.Clear();
}
this.Invalidate();
caret.Show();
EventArgs e2 = new EventArgs();
OnDocumentChanged(e2);
}
#endregion
/// <summary>
/// Indicates either the hex or text view has the focus.
/// </summary>
public bool HasFocus {
get { return this.hexViewFocus | this.textViewFocus; }
}
#region TextProcessing
/// <summary>
@ -1158,9 +1191,30 @@ namespace HexEditor @@ -1158,9 +1191,30 @@ namespace HexEditor
void HexEditSizeChanged(object sender, EventArgs e)
{
if (this.FitToWindowWidth) this.BytesPerLine = CalculateMaxBytesPerLine();
this.Invalidate();
SetViews();
UpdatePainters();
}
void UpdatePainters()
{
gHeader = this.header.CreateGraphics();
gSide = this.side.CreateGraphics();
gHex = this.hexView.CreateGraphics();
gText = this.textView.CreateGraphics();
// Bitmaps for painting
bHeader = new Bitmap(this.header.Width, this.header.Height, this.gHeader);
bSide = new Bitmap(this.side.Width, this.side.Height, this.gSide);
bHex = new Bitmap(this.hexView.Width, this.hexView.Height, this.gHex);
bText = new Bitmap(this.textView.Width, this.textView.Height, this.gText);
gbHeader = Graphics.FromImage(bHeader);
gbSide = Graphics.FromImage(bSide);
gbHex = Graphics.FromImage(bHex);
gbText = Graphics.FromImage(bText);
}
/// <summary>
@ -1169,15 +1223,15 @@ namespace HexEditor @@ -1169,15 +1223,15 @@ namespace HexEditor
void SetViews()
{
int sidetext = this.GetMaxLines() * this.BytesPerLine;
int textwidth = MeasureStringWidth(this.TextView.CreateGraphics(), new string('_', this.BytesPerLine + 1), this.Font);
int textwidth = MeasureStringWidth(this.textView.CreateGraphics(), new string('_', this.BytesPerLine + 1), this.Font);
int hexwidth = underscorewidth3 * this.BytesPerLine;
int top = HexView.Top;
this.HexView.Top = fontheight - 1;
this.TextView.Top = fontheight - 1;
this.Header.Top = 0;
this.Header.Left = HexView.Left - 10;
this.HexView.Height = this.Height - fontheight + top - 18;
this.TextView.Height = this.Height - fontheight + top - 18;
int top = hexView.Top;
this.hexView.Top = fontheight - 1;
this.textView.Top = fontheight - 1;
this.header.Top = 0;
this.header.Left = hexView.Left - 10;
this.hexView.Height = this.Height - fontheight + top - 18;
this.textView.Height = this.Height - fontheight + top - 18;
string st = String.Empty;
@ -1211,23 +1265,23 @@ namespace HexEditor @@ -1211,23 +1265,23 @@ namespace HexEditor
break;
}
this.Side.Width = MeasureStringWidth(this.Side.CreateGraphics(), st, this.Font);
this.Side.Left = 0;
this.HexView.Left = this.Side.Width + 10;
this.side.Width = MeasureStringWidth(this.side.CreateGraphics(), st, this.Font);
this.side.Left = 0;
this.hexView.Left = this.side.Width + 10;
if ((textwidth + hexwidth + 25) > this.Width - this.Side.Width) {
this.HexView.Width = this.Width - this.Side.Width - textwidth - 30;
this.TextView.Width = textwidth;
this.TextView.Left = this.Width - textwidth - 16;
if ((textwidth + hexwidth + 25) > this.Width - this.side.Width) {
this.hexView.Width = this.Width - this.side.Width - textwidth - 30;
this.textView.Width = textwidth;
this.textView.Left = this.Width - textwidth - 16;
} else {
this.HexView.Width = hexwidth;
this.TextView.Width = textwidth;
this.TextView.Left = hexwidth + this.HexView.Left + 20;
this.hexView.Width = hexwidth;
this.textView.Width = textwidth;
this.textView.Left = hexwidth + this.hexView.Left + 20;
}
this.caret.SetToPosition(GetPositionForOffset(this.caret.Offset, this.charwidth));
this.Header.Width = this.HexView.Width + 10;
this.Header.Height = this.fontheight;
this.header.Width = this.hexView.Width + 10;
this.header.Height = this.fontheight;
AdjustScrollBar();
}
@ -1244,66 +1298,63 @@ namespace HexEditor @@ -1244,66 +1298,63 @@ namespace HexEditor
end = selection.Start;
}
if (!hexViewFocus) {
if (this.activeView != this.hexView) {
hexinputmode = false;
hexinputmodepos = 0;
}
// if (e.Control)
// {
// switch (e.KeyCode)
// {
// case Keys.Up:
// if (this.topline > 0)
// this.topline--;
// break;
// case Keys.Down:
// if (this.topline < this.GetMaxLines())
// this.topline++;
// break;
// }
//
// this.VScrollBar.Value = this.topline;
//
// this.handled = true;
// }
switch (e.KeyCode) {
case Keys.Up:
case Keys.Down:
case Keys.Left:
case Keys.Right:
int oldoffset = caret.Offset;
// if (!e.Control)
MoveCaret(e);
if (GetLineForOffset(caret.Offset) < this.topline) this.topline = GetLineForOffset(caret.Offset);
if (GetLineForOffset(caret.Offset) > this.topline + this.GetMaxVisibleLines() - 2) this.topline = GetLineForOffset(caret.Offset) - this.GetMaxVisibleLines() + 2;
VScrollBar.Value = this.topline;
if (e.Shift) {
if (selection.HasSomethingSelected) {
int offset = caret.Offset; // set offset to caretposition
int oldstart = selection.Start; // copy old value
// if shift wasn't pressed before set the start position
if (!shiftwaspressed) { // to the current offset
oldstart = caret.Offset;
} else { // otherwise refresh the end of the selection.
offset = caret.Offset;
}
this.SetSelection(oldstart, offset);
this.SetSelection(selection.Start, caret.Offset);
} else {
this.SetSelection(oldoffset, caret.Offset);
}
selection.HasSomethingSelected = true;
selectionmode = true;
} else {
selection.Clear();
selectionmode = false;
}
handled = true;
break;
case Keys.Insert:
insertmode = !insertmode;
if (!insertmode) {
if (this.textViewFocus) caretwidth = underscorewidth;
if (this.hexViewFocus) caretwidth = underscorewidth * 2;
} else {
caretwidth = 1;
}
Control currentinput;
if (hexViewFocus & !textViewFocus) {
currentinput = (Control)this.HexView;
} else if (!hexViewFocus & textViewFocus) {
currentinput = (Control)this.TextView;
if (this.activeView == this.hexView)
this.caret.Width = underscorewidth * 2;
else
this.caret.Width = underscorewidth;
} else {
return;
this.caret.Width = 1;
}
caret.Create(currentinput, caretwidth, fontheight);
caret.SetToPosition(GetPositionForOffset(caret.Offset, this.charwidth));
caret.Show();
handled = true;
break;
case Keys.Back:
@ -1363,7 +1414,6 @@ namespace HexEditor @@ -1363,7 +1414,6 @@ namespace HexEditor
if (GetLineForOffset(caret.Offset) < this.topline) this.topline = GetLineForOffset(caret.Offset);
if (GetLineForOffset(caret.Offset) > this.topline + this.GetMaxVisibleLines() - 2) this.topline = GetLineForOffset(caret.Offset) - this.GetMaxVisibleLines() + 2;
}
caret.Show();
e2 = new EventArgs();
OnDocumentChanged(e2);
@ -1447,7 +1497,7 @@ namespace HexEditor @@ -1447,7 +1497,7 @@ namespace HexEditor
}
break;
}
if (hexViewFocus) {
if (this.activeView == this.hexView) {
ProcessHexInput(e);
handled = true;
return;
@ -1455,11 +1505,9 @@ namespace HexEditor @@ -1455,11 +1505,9 @@ namespace HexEditor
break;
}
shiftwaspressed = e.Shift;
if (handled) {
this.Invalidate();
caret.SetToPosition(GetPositionForOffset(caret.Offset, this.charwidth));
caret.Show();
}
}
@ -1532,7 +1580,7 @@ namespace HexEditor @@ -1532,7 +1580,7 @@ namespace HexEditor
break;
case Keys.Left:
if (caret.Offset >= 1) {
if (hexViewFocus) {
if (this.activeView == this.hexView) {
if (input.Control) {
hexinputmode = false;
if (hexinputmodepos == 0) {
@ -1553,7 +1601,7 @@ namespace HexEditor @@ -1553,7 +1601,7 @@ namespace HexEditor
break;
case Keys.Right:
if (caret.Offset <= this.Buffer.BufferSize - 1) {
if (hexViewFocus) {
if (this.activeView == this.hexView) {
if (input.Control) {
hexinputmode = true;
if (hexinputmodepos == 1) {
@ -1727,7 +1775,7 @@ namespace HexEditor @@ -1727,7 +1775,7 @@ namespace HexEditor
this.progressBar.Value = 0;
}
this.Side.Cursor = this.Cursor = this.Header.Cursor = Cursors.Default;
this.side.Cursor = this.Cursor = this.header.Cursor = Cursors.Default;
GC.Collect();
this.Invalidate();
@ -1759,15 +1807,14 @@ namespace HexEditor @@ -1759,15 +1807,14 @@ namespace HexEditor
void TextViewMouseDown(object sender, MouseEventArgs e)
{
this.textViewFocus = true;
this.hexViewFocus = false;
this.activeView = this.textView;
this.hexinputmode = false;
this.hexinputmodepos = 0;
if (e.Button == MouseButtons.Left) {
if (selection.HasSomethingSelected) {
selection.Start = 0;
selection.End = 0;
PaintText(this.TextView.CreateGraphics(), this.topline);
PaintText(this.textView.CreateGraphics(), this.topline);
}
selectionmode = true;
selection.Start = GetOffsetForPosition(e.Location, 1);
@ -1775,7 +1822,6 @@ namespace HexEditor @@ -1775,7 +1822,6 @@ namespace HexEditor
caret.Offset = GetOffsetForPosition(e.Location, 1);
caret.SetToPosition(GetPositionForOffset(caret.Offset, this.charwidth));
caret.Show();
}
void TextViewMouseMove(object sender, MouseEventArgs e)
@ -1783,15 +1829,13 @@ namespace HexEditor @@ -1783,15 +1829,13 @@ namespace HexEditor
if ((e.Button == MouseButtons.Left) & selectionmode) {
int end = selection.End;
selection.End = GetOffsetForPosition(e.Location, 1);
textViewFocus = true;
hexViewFocus = false;
this.activeView = this.textView;
moved = true;
selection.HasSomethingSelected = true;
if (end != selection.End) this.Invalidate();
caret.Offset = GetOffsetForPosition(e.Location, 1);
caret.SetToPosition(GetPositionForOffset(caret.Offset, this.charwidth));
caret.Show();
}
}
@ -1815,15 +1859,13 @@ namespace HexEditor @@ -1815,15 +1859,13 @@ namespace HexEditor
}
caret.Offset = GetOffsetForPosition(e.Location, 1);
caret.SetToPosition(GetPositionForOffset(caret.Offset, this.charwidth));
caret.Show();
selectionmode = false;
}
void HexViewMouseDown(object sender, MouseEventArgs e)
{
this.textViewFocus = false;
this.hexViewFocus = true;
this.activeView = this.hexView;
this.hexinputmode = false;
this.hexinputmodepos = 0;
if (e.Button == MouseButtons.Left) {
@ -1834,7 +1876,6 @@ namespace HexEditor @@ -1834,7 +1876,6 @@ namespace HexEditor
caret.Offset = GetOffsetForPosition(e.Location, 3);
caret.SetToPosition(GetPositionForOffset(caret.Offset, this.charwidth));
caret.Show();
}
}
@ -1844,15 +1885,13 @@ namespace HexEditor @@ -1844,15 +1885,13 @@ namespace HexEditor
int end = selection.End;
selection.End = GetOffsetForPosition(e.Location, 3);
selection.HasSomethingSelected = true;
textViewFocus = false;
hexViewFocus = true;
this.activeView = this.hexView;
moved = true;
caret.SetToPosition(GetPositionForOffset(GetOffsetForPosition(e.Location, 3), 3));
if (end != selection.End) this.Invalidate();
caret.Offset = GetOffsetForPosition(e.Location, 3);
caret.SetToPosition(GetPositionForOffset(caret.Offset, this.charwidth));
caret.Show();
}
}
@ -1877,7 +1916,6 @@ namespace HexEditor @@ -1877,7 +1916,6 @@ namespace HexEditor
}
caret.Offset = GetOffsetForPosition(e.Location, 3);
caret.SetToPosition(GetPositionForOffset(caret.Offset, this.charwidth));
caret.Show();
selectionmode = false;
}
#endregion
@ -1902,9 +1940,9 @@ namespace HexEditor @@ -1902,9 +1940,9 @@ namespace HexEditor
/// Calculates the max possible bytes per line.
/// </summary>
/// <returns>Int32, containing the result</returns>
int CalculateMaxBytesPerLine()
internal int CalculateMaxBytesPerLine()
{
int width = this.Width - this.Side.Width - 90;
int width = this.Width - this.side.Width - 90;
int textwidth = 0, hexwidth = 0;
int count = 0;
// while the width of the textview + the width of the hexview is
@ -1924,18 +1962,20 @@ namespace HexEditor @@ -1924,18 +1962,20 @@ namespace HexEditor
/// </summary>
/// <param name="position">The position</param>
/// <param name="charwidth">the width of one char, for example in the
/// hexview the width is 3 because one char needs 2 chars to be
/// hexview the width is 3 because one char needs 3 chars to be
/// displayed ("A" in text = "41 " in hex)</param>
/// <returns>the offset for the position</returns>
int GetOffsetForPosition(Point position, int charwidth)
internal int GetOffsetForPosition(Point position, int charwidth)
{
// calculate the line: vertical position (Y) divided by the height of
// one line (height of font = fontheight) = physical line + topline = virtual line.
int line = (int)Math.Truncate((double)((float)position.Y / (float)fontheight)) + topline;
//Debug.Print(line.ToString() + " " + ((double)((float)position.Y / (float)fontheight)).ToString());
if (selection.HasSomethingSelected) line++;
int line = (int)Math.Round((float)position.Y / (float)fontheight) + topline;
if (position.Y > (this.textView.Height / 2.0f))
line++;
// calculate the char: horizontal position (X) divided by the width of one char
int ch = (int)Math.Truncate((double)(position.X / (charwidth * underscorewidth)));
int ch = (int)Math.Round((float)position.X / (float)(charwidth * underscorewidth));
if (ch > this.BytesPerLine) ch = this.BytesPerLine;
if (ch < 0) ch = 0;
// calculate offset
@ -1954,16 +1994,16 @@ namespace HexEditor @@ -1954,16 +1994,16 @@ namespace HexEditor
/// Does the same as GetOffsetForPosition, but the other way round.
/// </summary>
/// <param name="offset">The offset to search</param>
/// <param name="charwidth">the current width of one char. (Depends on the viewpanel we are using (3 in hex 1 in text view)</param>
/// <param name="charwidth">the current width of one char.
/// (Depends on the viewpanel we are using (3 in hex 1 in text view)</param>
/// <returns>The Drawing.Point at which the offset is currently.</returns>
Point GetPositionForOffset(int offset, int charwidth)
internal Point GetPositionForOffset(int offset, int charwidth)
{
int line = (int)(offset / this.BytesPerLine) - this.topline;
int pline = line * fontheight - 1 * (line - 1) - 1;
int col = (offset % this.BytesPerLine) *
MeasureStringWidth(this.CreateGraphics(),
new string('_', charwidth), this.Font) + 4;
int col = (offset % this.BytesPerLine) * underscorewidth * charwidth + 4;
if (hexinputmode && !selectionmode && !selection.HasSomethingSelected && this.insertmode) col += (hexinputmodepos * underscorewidth);
return new Point(col, pline);
}
@ -1972,7 +2012,7 @@ namespace HexEditor @@ -1972,7 +2012,7 @@ namespace HexEditor
/// </summary>
/// <param name="line">The line in the file, countings starts at 0.</param>
/// <returns>The starting offset for a line.</returns>
int GetOffsetForLine(int line)
internal int GetOffsetForLine(int line)
{
return line * this.BytesPerLine;
}
@ -1983,10 +2023,10 @@ namespace HexEditor @@ -1983,10 +2023,10 @@ namespace HexEditor
/// <param name="offset">The offset to look up the line for.</param>
/// <returns>The line on which the given offset is.</returns>
/// <remarks>returns 0 for first line ...</remarks>
int GetLineForOffset(int offset)
internal int GetLineForOffset(int offset)
{
int line = (int)Math.Round((double)(offset / this.BytesPerLine));
if ((offset != 0) & ((offset % this.BytesPerLine) == 0)) line--;
int line = (int)(offset / this.BytesPerLine);
if ((offset != 0) && ((offset % this.BytesPerLine) == 0)) line--;
return line;
}
@ -1994,16 +2034,16 @@ namespace HexEditor @@ -1994,16 +2034,16 @@ namespace HexEditor
/// Calculates the count of visible lines.
/// </summary>
/// <returns>The count of currently visible virtual lines.</returns>
int GetMaxVisibleLines()
internal int GetMaxVisibleLines()
{
return (int)(this.HexView.Height / fontheight) + 3;
return (int)(this.hexView.Height / fontheight) + 3;
}
/// <summary>
/// Calculates the count of all virtual lines in the buffer.
/// </summary>
/// <returns>Retrns 1 if the buffer is empty, otherwise the count of all virtual lines in the buffer.</returns>
int GetMaxLines()
internal int GetMaxLines()
{
if (buffer == null) return 1;
int lines = (int)(buffer.BufferSize / this.BytesPerLine);

126
src/AddIns/DisplayBindings/HexEditor/Project/Src/HexEditControl.resx

@ -1,126 +0,0 @@ @@ -1,126 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="bWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>79</value>
</metadata>
</root>

12
src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/BufferManager.cs

@ -63,7 +63,7 @@ namespace HexEditor.Util @@ -63,7 +63,7 @@ namespace HexEditor.Util
this.stream = stream;
this.buffer.Clear();
((HexEditControl)this.parent).Enabled = false;
((Editor)this.parent).Enabled = false;
if (File.Exists(currentFile.FileName)) {
try {
@ -95,9 +95,9 @@ namespace HexEditor.Util @@ -95,9 +95,9 @@ namespace HexEditor.Util
else {this.parent.Cursor = Cursors.Default;}
((HexEditControl)this.parent).LoadingFinished();
((Editor)this.parent).LoadingFinished();
((HexEditControl)this.parent).Enabled = true;
((Editor)this.parent).Enabled = true;
this.parent.Invalidate();
}
@ -118,7 +118,7 @@ namespace HexEditor.Util @@ -118,7 +118,7 @@ namespace HexEditor.Util
/// <remarks>Currently not in use.</remarks>
private void Load()
{
((HexEditControl)this.parent).Enabled = false;
((Editor)this.parent).Enabled = false;
if (File.Exists(currentFile.FileName)) {
try {
@ -148,7 +148,7 @@ namespace HexEditor.Util @@ -148,7 +148,7 @@ namespace HexEditor.Util
delegate() {this.parent.Cursor = Cursors.Default;}
));
((HexEditControl)this.parent).Enabled = true;
((Editor)this.parent).Enabled = true;
}
/// <summary>
@ -157,7 +157,7 @@ namespace HexEditor.Util @@ -157,7 +157,7 @@ namespace HexEditor.Util
/// <param name="percentage">The current percentage of the process</param>
private void UpdateProgress(int percentage)
{
HexEditControl c = (HexEditControl)this.parent;
Editor c = (Editor)this.parent;
Application.DoEvents();

67
src/AddIns/DisplayBindings/HexEditor/Project/Src/Util/Caret.cs

@ -18,37 +18,16 @@ namespace HexEditor.Util @@ -18,37 +18,16 @@ namespace HexEditor.Util
{
int width;
int height;
int offset;
Control control;
int offset;
Point position;
Graphics g;
public Caret()
{
}
public Caret(Control control)
{
this.control = control;
}
public Caret(int width, int height)
{
this.width = width;
this.height = height;
}
public Caret(int width, int height, int offset)
public Caret(Graphics control, int width, int height, int offset)
{
this.width = width;
this.height = height;
this.offset = offset;
}
public Caret(Control control, int width, int height, int offset)
{
this.width = width;
this.height = height;
this.offset = offset;
this.control = control;
this.g = control;
}
public int Width {
@ -66,41 +45,35 @@ namespace HexEditor.Util @@ -66,41 +45,35 @@ namespace HexEditor.Util
set { offset = value; }
}
public Control Control {
get { return control; }
set { control = value; }
public Graphics Graphics {
get { return g; }
set { g = value; }
}
public void Create(Control control, int width, int height)
public void Create(Graphics control, int width, int height)
{
NativeMethods.CreateCaret(control.Handle, 0, width, height);
this.Control = control;
this.Graphics = control;
this.Width = width;
this.Height = height;
}
public void Destroy()
{
NativeMethods.DestroyCaret();
this.Control = null;
this.Width = 0;
this.Height = 0;
this.Offset = -1;
}
public void Show()
public void SetToPosition(Point position)
{
NativeMethods.ShowCaret(control.Handle);
this.position = position;
DrawCaret(position, this.width, this.height);
}
public void Hide()
private void DrawCaret(Point start, int width, int height)
{
NativeMethods.HideCaret(control.Handle);
if (width > 1)
g.DrawRectangle(Pens.Black, start.X - 1, start.Y, width, height - 1);
else
g.DrawLine(Pens.Black, start.X - 1, start.Y, start.X - 1, start.Y + height - 1);
}
public void SetToPosition(Point position)
public void DrawCaret()
{
NativeMethods.SetCaretPos(position.X, position.Y);
DrawCaret(this.position, this.width, this.height);
}
}
}

4
src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.Designer.cs generated

@ -44,7 +44,7 @@ namespace HexEditor.View @@ -44,7 +44,7 @@ namespace HexEditor.View
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.tSTBCharsPerLine = new System.Windows.Forms.ToolStripTextBox();
this.toolStripProgressBar1 = new System.Windows.Forms.ToolStripProgressBar();
this.hexEditControl = new HexEditor.HexEditControl();
this.hexEditControl = new HexEditor.Editor();
this.toolStrip1.SuspendLayout();
this.SuspendLayout();
//
@ -135,7 +135,7 @@ namespace HexEditor.View @@ -135,7 +135,7 @@ namespace HexEditor.View
}
private System.Windows.Forms.ToolStripProgressBar toolStripProgressBar1;
internal HexEditor.HexEditControl hexEditControl;
internal HexEditor.Editor hexEditControl;
private System.Windows.Forms.ToolStripComboBox tCBViewMode;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripButton tbSizeToFit;

6
src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditContainer.cs

@ -18,12 +18,12 @@ namespace HexEditor.View @@ -18,12 +18,12 @@ namespace HexEditor.View
{
public partial class HexEditContainer : UserControl
{
public bool HasSelection {
get { return hexEditControl.HasSelection; }
public bool HasSomethingSelected {
get { return hexEditControl.HasSomethingSelected; }
}
public bool EditorFocused {
get { return hexEditControl.HasFocus; }
get { return hexEditControl.Focused; }
}
public bool CanUndo {

4
src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditOptionsPanel.cs

@ -61,7 +61,7 @@ namespace HexEditor.View @@ -61,7 +61,7 @@ namespace HexEditor.View
{
SetupFromXmlStream(this.GetType().Assembly.GetManifestResourceStream("HexEditor.Resources.HexEditOptions.xfrm"));
this.InitializeComponents();
string configpath = Path.GetDirectoryName(typeof(HexEditControl).Assembly.Location) + Path.DirectorySeparatorChar + "config.xml";
string configpath = Path.GetDirectoryName(typeof(Editor).Assembly.Location) + Path.DirectorySeparatorChar + "config.xml";
if (!File.Exists(configpath)) return;
@ -153,7 +153,7 @@ namespace HexEditor.View @@ -153,7 +153,7 @@ namespace HexEditor.View
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1305:SpecifyIFormatProvider", MessageId = "System.Single.ToString")]
public override bool StorePanelContents()
{
string configpath = Path.GetDirectoryName(typeof(HexEditControl).Assembly.Location) + Path.DirectorySeparatorChar + "config.xml";
string configpath = Path.GetDirectoryName(typeof(Editor).Assembly.Location) + Path.DirectorySeparatorChar + "config.xml";
XmlDocument file = new XmlDocument();
file.LoadXml("<Config></Config>");

12
src/AddIns/DisplayBindings/HexEditor/Project/Src/View/HexEditView.cs

@ -51,11 +51,11 @@ namespace HexEditor.View @@ -51,11 +51,11 @@ namespace HexEditor.View
#region IClipboardHandler
public bool EnableCut {
get { return hexEditContainer.HasSelection & hexEditContainer.EditorFocused; }
get { return hexEditContainer.HasSomethingSelected & hexEditContainer.EditorFocused; }
}
public bool EnableCopy {
get { return hexEditContainer.HasSelection & hexEditContainer.EditorFocused; }
get { return hexEditContainer.HasSomethingSelected & hexEditContainer.EditorFocused; }
}
public bool EnablePaste {
@ -63,7 +63,7 @@ namespace HexEditor.View @@ -63,7 +63,7 @@ namespace HexEditor.View
}
public bool EnableDelete {
get { return hexEditContainer.HasSelection & hexEditContainer.EditorFocused; }
get { return hexEditContainer.HasSomethingSelected & hexEditContainer.EditorFocused; }
}
public bool EnableSelectAll {
@ -72,12 +72,12 @@ namespace HexEditor.View @@ -72,12 +72,12 @@ namespace HexEditor.View
public void Cut()
{
if (hexEditContainer.HasSelection) ClipboardWrapper.SetText(hexEditContainer.Cut());
if (hexEditContainer.HasSomethingSelected) ClipboardWrapper.SetText(hexEditContainer.Cut());
}
public void Copy()
{
if (hexEditContainer.HasSelection) ClipboardWrapper.SetText(hexEditContainer.Copy());
if (hexEditContainer.HasSomethingSelected) ClipboardWrapper.SetText(hexEditContainer.Copy());
}
public void Paste()
@ -87,7 +87,7 @@ namespace HexEditor.View @@ -87,7 +87,7 @@ namespace HexEditor.View
public void Delete()
{
if (hexEditContainer.HasSelection) hexEditContainer.Delete();
if (hexEditContainer.HasSomethingSelected) hexEditContainer.Delete();
}
public void SelectAll()

17
src/AddIns/DisplayBindings/HexEditor/Project/changes.txt

@ -15,4 +15,19 @@ version: 0.0.2 @@ -15,4 +15,19 @@ version: 0.0.2
18.02.2008: Final version for SD 3.0.0.2951
20.02.2008: Implementation as DisplayBinding finished
22.02.2008: Clean up and commenting.
22.02.2008: Clean up and commenting.
Known bugs/Problems:
1) When in overwrite mode you have to type into the text display
(right hand side) twice before the value is changed.
2) Might be good to be able to change individual hex parts of a byte.
3) Might be good if the next hex value to be typed in was highlighted
in the hex display.
4) Seems to be a slight delay with moving the blinking highlight as
you use the keyboard to move around the editor.
5) Maybe the cursor position should just highlight the text and not blink?
6) Copy and paste does not seem to work. The wrong data is copied.
This could be because the Copy menu item is not enabled.
7) When you paste in insert mode the text/hex is inserted. Should it
not replace the selected text/hex?
Loading…
Cancel
Save