public static NodeUI GetNodeUI(StructCell cell) { if (cell is ImageCell) { return(new ImageNodeUI((ImageCell)cell)); } return(null); }
public static CellUI GetUI(StructCell cell) { if (cell is BlobCell) { return(new BlobCellUI((BlobCell)cell)); } return(null); }
[Test] public void Blob() { StructInstance instance = PrepareInstance( "struct A { blob q [len=4]; calc x [value=CurOffset]; }", new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }); StructCell cell = instance.Cells[0]; Assert.IsInstanceOfType(typeof(BlobCell), cell); Assert.AreEqual("FF FF FF FF", cell.Value); Assert.AreEqual(4, ((BlobCell)cell).DataStream.Length); Assert.AreEqual("4", instance.Cells[1].Value); }
private void _structGridView_CellContextMenuStripNeeded(object sender, DataGridViewCellContextMenuStripNeededEventArgs e) { if (_structGridView.SelectedRows.Count > 0) { StructCell cell = (StructCell)_structGridView.SelectedRows[0].DataBoundItem; CellUI ui = CellUIRegistry.GetUI(cell); if (ui != null) { ui.ContextMenuStripNeeded(e); } else { e.ContextMenuStrip = contextMenuStrip1; } } }
public CellSelectedEventArgs(StructCell cell) { _cell = cell; }
public override void LoadData(BinaryReader reader, StructInstance instance) { Expression valueExpr = GetExpressionAttribute("value"); if (valueExpr != null) { AddCell(instance, valueExpr); return; } int offset = (int)reader.BaseStream.Position; string value; int cellSize; int charSize = 1; if (_wide) { charSize = 2; } Expression lengthExpr = GetExpressionAttribute("len"); if (lengthExpr != null) { int length = lengthExpr.EvaluateInt(instance); if (length < 0) { throw new LoadDataException("Length expression " + lengthExpr + " has the result of " + length + " which is negative"); } cellSize = length * charSize; if (reader.BaseStream.Length - reader.BaseStream.Position < cellSize) { throw new LoadDataException("Length expression " + lengthExpr + " has the result of " + length + " and points outside the file"); } byte[] bytes = reader.ReadBytes(length * charSize); char[] chars = _wide ? Encoding.Unicode.GetChars(bytes) : Encoding.Default.GetChars(bytes); for (int i = 0; i < length; i++) { if (chars[i] == '\0') { length = i; break; } } value = new string(chars, 0, length); } else { StringBuilder valueBuilder = new StringBuilder(); BinaryReader charReader = _wide ? new BinaryReader(reader.BaseStream, Encoding.Unicode) : reader; while (true) { char c = charReader.ReadChar(); if (c == '\0') { break; } valueBuilder.Append(c); } value = valueBuilder.ToString(); cellSize = value.Length * charSize; } StructCell cell = AddCell(instance, value, offset); instance.RegisterCellSize(cell, cellSize); }