⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hexchfrm.pas

📁 MiniHex 1.1 源程序说明 “MiniHex11SrcSource”目录中的所有文件是MiniHex 1.1的主程序; “MiniHex11SrcControls”目录中的是该软件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
function THexChForm.GetRowPointer(AbsRow: Integer): PChar;
begin
  Result := PChar(LongInt(FBufPointer) + AbsRow * 16);
end;

function THexChForm.GetRowColPointer(AbsRow, Col: Integer): PChar;
begin
  Result := PChar(LongInt(FBufPointer) + AbsRow * 16 + Col);
end;

function THexChForm.GetOffset(AbsRow, Col: Integer): Integer;
begin
  Result := AbsRow * 16 + Col;
end;

function THexChForm.GetOffset: Integer;
begin
  Result := FCurRow * 16 + FCurCol;
end;

function THexChForm.GetOffsetForProperty: Integer;
begin
  Result := GetOffset;
end;

function THexChForm.GetDLen(AbsRow, Col: Integer; CurInHigh: Boolean): Integer;
begin
  PosToDLen(Result, AbsRow, Col, CurInHigh);
end;

function THexChForm.GetDLen: Integer;
begin
  PosToDLen(Result, FCurRow, FCurCol, FCurInHigh);
end;

function THexChForm.GetRowTotalWidth: Integer;
begin
  Result := GetCharW * 74 + 6;
end;

function THexChForm.GetFormMaxWidth: Integer;
begin
  Result := GetRowTotalWidth + ScrollBarWH + 8 + 4;
end;

function THexChForm.GetAddrAreaLeft: Integer;
begin
  Result := 5;
end;

function THexChForm.GetHexAreaLeft: Integer;
begin
  Result := GetCharW * 10;
end;

function THexChForm.GetChrAreaLeft: Integer;
begin
  Result := GetCharW * 58;
end;

function THexChForm.GetCharAttrByRowCol(AbsRow, Col: Integer; CurInHex: Boolean): TCharAttr;
var
  Offset: Integer;
begin
  if FBlock.Active then
  begin
    Offset := GetOffset(AbsRow, Col);
    if (Offset >= FBlock.StartOffset) and (Offset <= FBlock.EndOffset) then
      Result := Options.BlockColor
    else
      Result := Options.HexColor;
  end else
  begin
    if CurInHex then Result := Options.HexColor
    else Result := Options.ChrColor;
  end;
end;

function THexChForm.GetOffsetByMove(DLenOffset: Integer): Integer;
var
  DLen, AbsRow, Col: Integer;
  CurInHigh: Boolean;
begin
  PosToDLen(DLen, FCurRow, FCurCol, FCurInHigh);
  DLen := DLen + DLenOffset;
  if DLen < 1 then DLen := 1
  else if DLen > FBufSize * 2 then DLen := FBufSize * 2;
  DLenToPos(AbsRow, Col, CurInHigh, DLen);
  Result := AbsRow * 16 + Col;
end;

function THexChForm.GetOffsetByMoveTo(DLen: Integer): Integer;
var
  AbsRow, Col: Integer;
  CurInHigh: Boolean;
begin
  if DLen < 1 then DLen := 1
  else if DLen > FBufSize * 2 then DLen := FBufSize * 2;
  DLenToPos(AbsRow, Col, CurInHigh, DLen);
  Result := AbsRow * 16 + Col;
end;

function THexChForm.GetHexAreaStr(AbsRow: Integer): string;
var
  S: string;
  RowPointer: PChar;
  i, ColCount: Integer;
begin
  RowPointer := GetRowPointer(AbsRow);
  S := '';

  if (AbsRow < FRowCount -1) then
    ColCount := 16
  else begin
    if (FBufSize mod 16 > 0) then ColCount := FBufSize mod 16
    else ColCount := 16;
  end;

  for i := 0 to ColCount - 1 do
  begin
    S := S + IntToHex(Integer(RowPointer^), 2);
    if i <> 7 then S := S + ' '
    else S := S + '-';
    Inc(RowPointer);
  end;
  for i := ColCount to 15 do
    S := S + '   ';
  Result := S;
end;

function THexChForm.GetChrAreaStr(AbsRow: Integer; ShowAllChar: Boolean = True): string;
var
  S: string;
  RowPointer: PChar;
  i, ColCount: Integer;
begin
  RowPointer := GetRowPointer(AbsRow);
  S := '';

  if (AbsRow < FRowCount -1) then
    ColCount := 16
  else begin
    if (FBufSize mod 16 > 0) then ColCount := FBufSize mod 16
    else ColCount := 16;
  end;

  for i := 0 to ColCount - 1 do
  begin
    S := S + RowPointer^;
    Inc(RowPointer);
  end;
  for i := ColCount to 15 do
    S := S + ' ';

  if not ShowAllChar then
  begin
    for i := 1 to Length(S) do
    begin
      if (Ord(S[i]) < 32) or (Ord(S[i]) > 126) then
        S[i] := '.';
    end;
  end;

  Result := S;
end;

function THexChForm.GetByteAtPos(Offset: Integer): Byte;
begin
  Result := PByte(LongInt(FBufPointer) + Offset)^;
end;

function THexChForm.GetStrAtPos(Offset, Count: Integer; var S: string): Boolean;
begin
  SetString(S, PChar(LongInt(FBufPointer) + Offset), Count);
  Result := True;
end;

procedure THexChForm.SetLengthRadix(Value: TRadix);
begin
  LenPopupDecItem.Checked := (Value = raDec);
  LenPopupHexItem.Checked := (Value <> raDec);
  Options.StatusLengthRadix := Value;
  ShowLength;
end;

procedure THexChForm.SetOffsetRadix(Value: TRadix);
begin
  OffPopupDecItem.Checked := (Value = raDec);
  OffPopupHexItem.Checked := (Value <> raDec);
  Options.StatusOffsetRadix := Value;
  ShowOffset;
end;

procedure THexChForm.SetBlockInfoRadix(Value: TRadix);
begin
  BlkPopupDecItem.Checked := (Value = raDec);
  BlkPopupHexItem.Checked := (Value <> raDec);
  Options.StatusBlockInfoRadix := Value;
  ShowBlockInfo;
end;

procedure THexChForm.SetCurValueType(Value: TValueType);
begin
  CurValPopup8sItem.Checked := (Value = vt8s);
  CurValPopup8uItem.Checked := (Value = vt8u);
  CurValPopup16sItem.Checked := (Value = vt16s);
  CurValPopup16uItem.Checked := (Value = vt16u);
  CurValPopup32sItem.Checked := (Value = vt32s);
  CurValPopup32uItem.Checked := (Value = vt32u);
  CurValPopupSingleItem.Checked := (Value = vtSingle);
  CurValPopupDoubleItem.Checked := (Value = vtDouble);

  Options.StatusCurValueType := Value;
  ShowCurValue;
end;

procedure THexChForm.SetBlockVisible(Value: Boolean = True);
begin
  FBlock.Active := Value;
  if FBlock.StartOffset > FBlock.EndOffset then
    FBlock.Active := False;
  DrawAllRow;
  ShowStatusInfo;
end;

procedure THexChForm.SetOffsetForProperty(Value: Integer);
begin
  MoveCurTo(Value * 2 + 1);
end;

function THexChForm.CheckCursorInWindow: Boolean;
begin
  Result := (FCurRow >= FTopRow) and (FCurRow <= FTopRow+FVisRow-1);
end;

procedure THexChForm.DrawText(X, Y: Integer; S: String; CharAttr: TCharAttr);
begin
  ViewPaintBox.Canvas.Brush.Color := CharAttr.BColor;
  ViewPaintBox.Canvas.Font.Color := CharAttr.FColor;
  ViewPaintBox.Canvas.TextOut(X, Y, S);
end;

{
procedure THexChForm.LocateCaret(AbsRow, Col: Integer);
var
  CharW, CharH: Integer;
  X, Y: Integer;
begin
  CharW := GetCharW;
  CharH := GetCharH;
  if FCurInHex then
  begin
    X := GetHexAreaLeft + Col * CharW * 3 + ViewPaintbox.Left;
    if not FCurInHigh then X := X + CharW;
  end else
  begin
    X := GetChrAreaLeft + Col * CharW + ViewPaintBox.Left;
  end;
  Y := (AbsRow - FTopRow) * CharH;

  SetCaretPos(X, Y);
end;
}

{
procedure THexChForm.SetCaretVisible(Show: Boolean = True);
begin
  if Show then
    ShowCaret(ViewBackPanel.Handle)
  else
    HideCaret(ViewBackPanel.Handle);
end;
}

//DLen: 从1开始
procedure THexChForm.PosToDLen(var DLen: Integer; AbsRow, Col: Integer; CurInHigh: Boolean);
begin
  DLen := (AbsRow * 16 + Col) * 2 + 1;
  if not CurInHigh then Inc(DLen);
end;

procedure THexChForm.DLenToPos(var AbsRow, Col: Integer; var CurInHigh: Boolean; DLen: Integer);
var
  i, Len: Integer;
begin
  if DLen > 0 then i := DLen - 1
  else i := DLen;
  Len := i div 2;
  AbsRow := Len div 16;
  Col := Len mod 16;
  if (DLen mod 2) <> 0 then CurInHigh := True
  else CurInHigh := False;
end;

function  THexChForm.XYToRowCol(var OffRow, Col: Integer; var CurInHex: Boolean; X, Y: Integer): Boolean;
var
  i: Integer;
  X1, Y1, X2, Y2: Integer;
  CharW, CharH: Integer;
  HexAreaLeft, ChrAreaLeft: Integer;
begin
  CharW := GetCharW;
  CharH := GetCharH;
  HexAreaLeft := GetHexAreaLeft;
  ChrAreaLeft := GetChrAreaLeft;
  OffRow := -1;
  Col := -1;
  for i := 0 to FVisRow - 1 do
  begin
    Y1 := CharH * i;
    Y2 := Y1 + CharH;
    if (Y >= Y1) and (Y <= Y2) then OffRow := i;
  end;
  for i := 0 to 15 do
  begin
    X1 := HexAreaLeft + CharW * i * 3;
    X2 := X1 + CharW * 3;
    if (X >= X1) and (X <= X2) then
    begin
      Col := i;
      CurInHex := True;
      Break;
    end;
    X1 := ChrAreaLeft + CharW * i;
    X2 := X1 + CharW;
    if (X >= X1) and (X <= X2) then
    begin
      Col := i;
      CurInHex := False;
      Break;
    end;
  end;
  Result := (OffRow <> -1) and (Col <> -1);
end;

procedure THexChForm.MoveCur(DLenOffset: Integer);
var
  OldDLen, DLen, AbsRow, OffRow, Col: Integer;
  CurInHigh: Boolean;
begin
  PosToDLen(DLen, FCurRow, FCurCol, FCurInHigh);
  OldDLen := DLen;
  DLen := DLen + DLenOffset;
  if DLen < 1 then DLen := 1
  else if DLen > FBufSize * 2 then DLen := FBufSize * 2;
  if DLen = OldDLen then Exit;

  DLenToPos(AbsRow, Col, CurInHigh, DLen);
  OffRow := AbsRow - FTopRow;

  DrawCurItem(False);

  FCurRow := AbsRow;
  FCurCol := Col;
  FCurInHigh := CurInHigh;

  if OffRow < 0 then
  begin
    FTopRow := AbsRow;
  end
  else if OffRow >= FVisRow then
  begin
    FTopRow := AbsRow - FVisRow + 1;
  end
  else
    DrawCurItem(True);

  VertScrollBar.Position := FTopRow;
  ShowStatusInfo;
  FillDataInspValue;
end;

procedure THexChForm.MoveCurTo(DLen: Integer);
var
  CurDLen: Integer;
begin
  if DLen < 1 then DLen := 1;
  if DLen > FBufSize * 2 then DLen := FBufSize * 2;
  CurDLen := GetDLen;
  MoveCur(DLen - CurDLen);
end;

procedure THexChForm.AdjustBlockA(Offset1, Offset2: Integer);
begin
  if not FBlock.Active then
  begin
    FBlock.StartOffset := Offset1;
    FBlock.EndOffset := Offset2;
    FBlock.Active := True;
  end else
  begin
    if FBlock.StartOffset = Offset1 then
    begin
      FBlock.StartOffset := Offset2;
      if FBlock.StartOffset > FBlock.EndOffset then
        SwapInt(FBlock.StartOffset, FBlock.EndOffset);
    end
    else if  FBlock.EndOffset = Offset1 then
    begin
      FBlock.EndOffset := Offset2;
      if FBlock.StartOffset > FBlock.EndOffset then
        SwapInt(FBlock.StartOffset, FBlock.EndOffset);
    end
    else if Offset2 >= 0 then
    begin
      FBlock.StartOffset := Offset2;
      FBlock.EndOffset := Offset1;
    end;
  end;
end;

procedure THexChForm.AdjustBlockB(Offset1, Offset2: Integer);
begin
  if not FBlock.Active then
  begin
    FBlock.StartOffset := Offset1;
    FBlock.EndOffset := Offset2;
    FBlock.Active := True;
  end else
  begin
    if FBlock.EndOffset = Offset1 then
    begin
      FBlock.EndOffset := Offset2;
      if FBlock.StartOffset > FBlock.EndOffset then
        SwapInt(FBlock.StartOffset, FBlock.EndOffset);
    end
    else if  FBlock.StartOffset = Offset1 then
    begin
      FBlock.StartOffset := Offset2;
      if FBlock.StartOffset > FBlock.EndOffset then
        SwapInt(FBlock.StartOffset, FBlock.EndOffset);
    end
    else if Offset2 < FBufSize then
    begin
      FBlock.StartOffset := Offset1;
      FBlock.EndOffset := Offset2;
    end;
  end;
end;

procedure THexChForm.AdjScrBarAfterChgSize;
begin
  if FRowCount > FVisRow then
  begin
    VertScrollBar.Max := FRowCount - FVisRow;
    VertScrollBar.Enabled := True;
  end else
  begin
    VertScrollBar.Max := 0;
    VertScrollBar.Enabled := False;
  end;

  VertScrollBar.Position := FTopRow;
end;

procedure THexChForm.AdjustUndoRedoEnabled;
begin
  UndoAct.Enabled := FActsMgr.CanUndo;
  RedoAct.Enabled := FActsMgr.CanRedo;
  MHMainForm.UndoToolButton.Enabled := UndoAct.Enabled;
  MHMainForm.RedoToolButton.Enabled := RedoAct.Enabled;
end;

procedure THexChForm.DoMouseRoll;
var
  MsPos: TPoint;
  DLen, Offset: Integer;
begin
  GetCursorPos(MsPos);
  MsPos := ViewBackPanel.ScreenToClient(MsPos);

  while MsPos.y < 0 do
  begin
    if FTopRow > 0 then
    begin
      Dec(FTopRow);
      DLen := GetDLen(FTopRow, FCurCol, True);
      Offset := GetOffsetByMoveTo(DLen);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -