forked from speller/peviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataViewUnit.pas
2706 lines (2374 loc) · 65.3 KB
/
DataViewUnit.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit DataViewUnit;
interface
uses
Winapi.Windows, CommonUtilities, Classes, SysUtils, Controls, ExtCtrls, Graphics, Forms, Math,
Winapi.Messages, Themes, Winapi.UxTheme;
type
TViewerElement = ( hvOffset, hvHexData, hvCharData );
TViewerElements = set of TViewerElement;
TViewerMode = ( hmHex, hmTextBinary, hmTextFree{, hmTextWordWrap} );
TMoveDirection = ( mdLeft, mdTop, mdRight, mdBottom );
TPos = packed record
Col, Row: Integer;
end;
PPos = ^TPos;
TDataViewer = class(TPanel)
private
FBufferSize: Integer;
FLineCount: Integer;
FBorderLeft,
FBorderRight,
FPosPerScroll,
FPageSize: Byte;
FDataHeight,
FDataWidth: Integer;
FCharHeight,
FCharWidth: Integer;
FSelecting: Boolean;
FPrevCaptureWnd: HWND;
FSL: TStringList;
FScrollTimer: TTimer;
FScrollDelta: TSmallPoint;
FCaretShown: Boolean;
FFreezeCount: Integer;
FScrollTimerInterval: Integer;
FStream: TStream;
FStreamDataOffset: Integer;
FVisibleElements: TViewerElements;
FNonPrintReplacement: AnsiChar;
FSelStart: Integer;
FSelEnd: Integer;
FSelectionElement: TViewerElement;
FFontColor: TColor;
FSelBkColor: TColor;
FSelFontColor: TColor;
FBkColor: TColor;
FNonSelectAreaCursor: TCursor;
FMode: TViewerMode;
FCurLineWidth: Integer;
FPrevSelEnd: Integer;
FSelEndPos: TPos;
procedure ScrollBoxOnResize(Sender: TObject);
procedure ScrollBoxOnMouseDown(
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ScrollBoxOnMouseUp(
Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ScrollBoxOnMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure ScrollBoxOnMouseWheel(
Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
var Handled: Boolean);
procedure SetVisibleElements(Value: TViewerElements);
procedure SetSelEnd(Value: Integer);
procedure SetSelStart(Value: Integer);
procedure SetSelectionElement( Value: TViewerElement );
procedure SetMode( Value: TViewerMode );
procedure SetCurLineWidth(Value: Integer);
procedure ScrollTimerOnTimer(Sender: TObject);
procedure ScrollBoxOnKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
function GetFreezed: Boolean;
function GetHScroll: Integer;
function GetVScroll: Integer;
procedure SetHScroll(Value: Integer);
procedure SetVScroll(Value: Integer);
function GetFullLines: Integer;
function GetVisibleLines: Integer;
function GetFullCols: Integer;
function GetSelEndChanged: Boolean;
procedure SetSelEndPos( Value: TPos; NewLineIfEOL: Boolean = False );
function GetEmpty: Boolean;
function DrawFrame: Boolean;
private
fSelInactiveColor: TColor;
FBinaryTextLineWidth: Integer;
procedure SetFontColor(Value: TColor);
function GetFontSize: Integer;
procedure SetFontSize(Value: Integer);
protected
procedure WndProc(var AMessage: TMessage); override;
procedure CreateParams(var Params: TCreateParams); override;
procedure ClearSelection;
function ClientCursorPos: TPoint;
procedure DecPointOnScroll(var Pt: TPoint);
function ElementFromPos(const Pos: Integer): Byte;
function GetCharPoint(N: Integer; Element: TViewerElement): TPoint;
function GetCharPos(N: Integer; BlockRecursive: Boolean = False): TPos;
function GetPointPos(const Point: TPoint;
Element: TViewerElement): TPos;
function GetPosChar(Pos: TPos): Integer;
function GetPosPoint(Pos: TPos; Element: TViewerElement): TPoint;
procedure HideCaret;
procedure MakePosVisible(const Pos: TPos);
function NewNormalCanvas: TCanvas;
{$WARNINGS OFF}
procedure Paint(DC: HDC; const UpdateRect: TRect);
procedure ProcessHotKeys(HK: THotKey);
{$WARNINGS ON}
procedure SetHCursor(MouseX: Integer);
procedure SetIntDefaults;
procedure SetNormalCanvas(C: TCanvas);
procedure SetSelectedCanvas(C: TCanvas);
procedure SetSelInactiveCanvas(C: TCanvas);
procedure SetVisDefaults;
procedure ShowCaret;
procedure UpdateCaretPos(CalcCharPos: Boolean = False; Pos: PPos = nil);
procedure UpdateMousePos(const Mouse: TPoint);
procedure UpdateProperties;
function IsBarVisible(ABar: NativeUInt): Boolean;
property PrevSelEnd: Integer read fPrevSelEnd write fPrevSelEnd;
property SelEndChanged: Boolean read GetSelEndChanged;
property SelEndPos: TPos read fSelEndPos;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Mode: TViewerMode read fMode write SetMode;
property Stream: TStream read FStream;
property StreamDataOffset: Integer read FStreamDataOffset;
property StreamDataSize: Integer read FBufferSize;
property VisibleElements: TViewerElements read fVisibleElements write SetVisibleElements;
property SelStart: Integer read fSelStart write SetSelStart;
property SelEnd: Integer read fSelEnd write SetSelEnd;
property SelectionElement: TViewerElement read fSelectionElement write SetSelectionElement;
property Selecting: Boolean read fSelecting write fSelecting;
property LineCount: Integer read fLineCount;
property CurLineWidth: Integer read FCurLineWidth write SetCurLineWidth;
property FullLines: Integer read GetFullLines;
property VisibleLines: Integer read GetVisibleLines;
property FullCols: Integer read GetFullCols;
property VScroll: Integer read GetVScroll write SetVScroll;
property HScroll: Integer read GetHScroll write SetHScroll;
property Freezed: Boolean read GetFreezed;
property Empty: Boolean read GetEmpty;
procedure SetStream(
AStream: TStream; AStreamDataOffset, AStreamDataSize: Cardinal; AMode: TViewerMode);
procedure Freeze;
procedure UnFreeze;
{$WARNINGS OFF}
procedure Invalidate;
procedure ScrollPage( Direction: TMoveDirection );
{$WARNINGS ON}
procedure SelectAll;
procedure SetHandlers;
published
property NonPrintReplacement: AnsiChar read fNonPrintReplacement write fNonPrintReplacement;
property BkColor: TColor read fBkColor write fBkColor;
property FontColor: TColor read FFontColor write SetFontColor;
property FontSize: Integer read GetFontSize write SetFontSize;
property SelBkColor: TColor read fSelBkColor write fSelBkColor;
property SelFontColor: TColor read fSelFontColor write fSelFontColor;
property SelInactiveColor: TColor read fSelInactiveColor write fSelInactiveColor;
property NonSelectAreaCursor: TCursor read FNonSelectAreaCursor write FNonSelectAreaCursor;
property BinaryTextLineWidth: Integer read FBinaryTextLineWidth write FBinaryTextLineWidth;
end;
function ConvertNonPrintingChar(Chr, Replace: AnsiChar): AnsiChar;
const
Def_NPRepl = '.';
implementation
const
AddressTempl = '00000000';
AddressDelTempl = ': ';
HexTempl = '00 00 00 00 00 00 00 00|00 00 00 00 00 00 00 00';
HexDelTempl = ' | ';
DataTempl = 'QQQQQQQQQQQQQQQQ';
Def_Separators = ' ,.;:/|\+=-@^&*()'''#9;
// Def_NPRepl = #128;
Def_SelBkColor = clHighlight;
Def_SelFontColor = clHighlightText;
Def_BkColor = clWindow;
Def_FontColor = clWindowText;
Def_SelInactiveColor = clBtnFace;
function LinesPerHeight( const Rect: TRect; LineHeight: Integer ): Integer;
begin
Result := (Rect.Bottom - Rect.Top) div LineHeight;
end;
function LinesPerHeight2( const Rect: TRect; LineHeight: Integer ): Integer;
begin
Result := (Rect.Bottom - Rect.Top) div LineHeight;
if (Rect.Bottom - Rect.Top) mod LineHeight > 0 then
Inc( Result );
end;
function ColsPerWidth( const Rect: TRect; ColWidth: Integer ): Integer;
begin
Result := (Rect.Right - Rect.Left) div ColWidth;
end;
function ConvertNonPrintingChar(Chr, Replace: AnsiChar): AnsiChar;
begin
Result := Chr;
if (Byte(Result) < 32) or (Byte(Result) >= $80) and (Byte(Result) < $90) then
Result := Replace;
end;
procedure ConvertNonPrintingChars(
Str: PAnsiChar; Len: Integer; Replace: AnsiChar; ReplaceCrLf: Boolean);
var
I: Integer;
begin
I := 0;
while I < Len do
begin
if Str[ I ] < #32 then
if ReplaceCrLf then
Str[ I ] := Replace
else
if (Str[ I ] <> #13) then
Str[ I ] := Replace
else
if (I + 1 < Len) and (Str[ I + 1 ] = #10) then
Inc( I );
Inc( I );
end;
end;
procedure Stream2StrList(AList: TStringList; AStream: TStream);
procedure SetTextStr(SL: TStringList; Data: Pointer; DataLength: SysUInt);
var
P, Start, LB: PAnsiChar;
S: AnsiString;
LineBreakLen, lengthMod: Integer;
begin
SL.BeginUpdate;
try
SL.Clear;
P := Data;
if P <> nil then
if CompareStr(SL.LineBreak, sLineBreak) = 0 then
begin
// This is a lot faster than using StrPos/AnsiStrPos when
// LineBreak is the default (#13#10)
// while P^ <> #0 do
while (SysUInt(P) - SysUInt(Data)) < DataLength do
begin
Start := P;
while not (P^ in [#0, #10, #13]) do
Inc(P);
SetString(S, Start, P - Start);
SL.AddObject(string(S), Pointer(Start));
if P^ = #13 then Inc(P);
if P^ = #10 then Inc(P);
end;
end
else
begin
LineBreakLen := Length(SL.LineBreak);
// while P^ <> #0 do
while (SysUInt(P) - SysUInt(Data)) < DataLength do
begin
Start := P;
LB := AnsiStrPos(P, PAnsiChar(AnsiString(SL.LineBreak)));
while (P^ <> #0) and (P <> LB) do
Inc(P);
// óäàëÿåì ñèìâîë 0xD åñëè ðàçäåëèòåëü ñòðîê 0xA è âñòðå÷àåì ðàçäåëåíèå ñòðîê 0xD 0xA
if (P^ <> #0) and (P <> Start) and (SL.LineBreak = #10) and (P[-1] = #13) then
lengthMod := -1
else
lengthMod := 0;
SetString(S, Start, P - Start + lengthMod);
SL.AddObject(string(S), Pointer(Start));
if P = LB then
Inc(P, LineBreakLen);
end;
end;
finally
SL.EndUpdate;
end;
end;
var
i: Integer;
buffer: Pointer;
begin
if (AList.Count > 0) then
begin
FreeMem(Pointer(AList.Objects[0]));
for i := 0 to AList.Count - 1 do
AList.Objects[i] := nil;
AList.Clear;
end;
GetMem(buffer, AStream.Size);
AStream.Read(buffer^, AStream.Size);
// PByte(buffer)[AStream.Size] := 0;
// PByte(buffer)[AStream.Size + 1] := 0;
Alist.LineBreak := #10;
SetTextStr(AList, buffer, AStream.Size);
end;
function MyNewCanvas(DC: HDC): TCanvas;
begin
Result := TCanvas.Create;
Result.Handle := DC;
end;
type
TCControl = class(TControl);
{ TDataViewer }
procedure TDataViewer.ClearSelection;
begin
Freeze;
SelStart := 0;
SelEnd := 0;
UnFreeze;
end;
function TDataViewer.ClientCursorPos: TPoint;
begin
GetCursorPos(Result);
Result := ScreenToClient(Result);
end;
constructor TDataViewer.Create(AOwner: TComponent);
begin
inherited;
fSL := TStringList.Create;
FScrollTimer := TTimer.Create(Self);
FScrollTimer.Enabled := False;
FBinaryTextLineWidth := 80;
SetIntDefaults;
SetVisDefaults;
SetHandlers;
FScrollTimer.OnTimer := ScrollTimerOnTimer;
AutoSize := False;
TabStop := True;
end;
procedure TDataViewer.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.ExStyle := Params.ExStyle or WS_EX_CLIENTEDGE;
Params.WindowClass.style := Params.WindowClass.style or CS_CLASSDC;
end;
procedure TDataViewer.DecPointOnScroll(var Pt: TPoint);
begin
Dec( Pt.X, HScroll * fCharWidth );
Dec( Pt.Y, VScroll * fCharHeight );
end;
destructor TDataViewer.Destroy;
var
i: Integer;
begin
// fMenu.Free;
// fControl.OnResize := nil;
// fControl.OnMouseDown := nil;
// fControl.OnMouseUp := nil;
// fControl.OnMouseWheel := nil;
// fControl.OnMessage := nil;
// fControl.OnMouseMove := nil;
// fControl.OnKeyDown := nil;
// fFont.Free;
if (fSL.Count > 0) then
begin
FreeMem(Pointer(fSL.Objects[0]));
for i := 0 to fSL.Count - 1 do
fSL.Objects[i] := nil;
end;
fSL.Free;
// fControl.Free;
inherited;
end;
function TDataViewer.DrawFrame: Boolean;
var
EmptyRect,
DrawRect, barRectVert, barRectHorz, r: TRect;
DC: HDC;
vertBarWidth, vertBarBtnHeight, horzBarHeight, horzBarBtnWidth: Integer;
ExStyle: Integer;
Details: TThemedElementDetails;
drawVertBar, drawHorzBar: Boolean;
begin
Result := StyleServices.Enabled;
if (Result) then
begin
ExStyle := GetWindowLong(Handle, GWL_EXSTYLE);
if (ExStyle and WS_EX_CLIENTEDGE) <> 0 then
begin
vertBarWidth := 0;
vertBarBtnHeight := 0;
horzBarHeight := 0;
horzBarBtnWidth := 0;
GetWindowRect(Handle, DrawRect);
OffsetRect(DrawRect, -DrawRect.Left, -DrawRect.Top);
DC := GetWindowDC(Handle);
try
EmptyRect := DrawRect;
// AStyle := GetWindowLong(Handle, GWL_STYLE);
// if ((AStyle and WS_HSCROLL) <> 0) and ((AStyle and WS_VSCROLL) <> 0) then
// begin
// Ìîæåò, ñäåëàòü îïðåäåëåíèå ÷åðåç ñòèëè?
drawVertBar := IsBarVisible(OBJID_VSCROLL);
drawHorzBar := IsBarVisible(OBJID_HSCROLL);
if (drawVertBar) then
begin
vertBarWidth := GetSystemMetrics(SM_CXVSCROLL);
vertBarBtnHeight := GetSystemMetrics(SM_CYVSCROLL);
end;
if (drawHorzBar) then
begin
horzBarHeight := GetSystemMetrics(SM_CYHSCROLL);
horzBarBtnWidth := GetSystemMetrics(SM_CXHSCROLL);
end;
if (drawVertBar and drawHorzBar) then
begin
// draw right bottom rect between scrollbars
InflateRect(EmptyRect, -2, -2);
with EmptyRect do
if UseRightToLeftScrollBar then
EmptyRect := Rect(Left, Bottom - horzBarHeight, Left + vertBarWidth, Bottom)
else
EmptyRect := Rect(Right - vertBarWidth, Bottom - horzBarHeight, Right, Bottom);
FillRect(DC, EmptyRect, GetSysColorBrush(COLOR_BTNFACE));
ExcludeClipRect(DC, EmptyRect.Left, EmptyRect.Top, EmptyRect.Right, EmptyRect.Bottom);
end;
if (drawVertBar) then
begin
barRectVert.Left := DrawRect.Right - 2 - vertBarWidth;
barRectVert.Top := 2;
barRectVert.Width := vertBarWidth;
barRectVert.Bottom := DrawRect.Bottom - 2 - horzBarHeight;
end;
if (drawHorzBar) then
begin
barRectHorz.Left := 2;
barRectHorz.Top := DrawRect.Bottom - 2 - horzBarHeight;
barRectHorz.Right := DrawRect.Right - 2 - vertBarWidth;
barRectHorz.Height := horzBarHeight;
end;
if (not drawVertBar) and drawHorzBar then
begin
Inc(barRectHorz.Right, vertBarWidth);
end
else if (not drawHorzBar) and drawVertBar then
begin
Inc(barRectVert.Bottom, horzBarHeight);
end;
// exclude bar trackbars and thumbnails from drawing - they will be redrawn by system
if (drawVertBar) then
begin
ExcludeClipRect(
DC, barRectVert.Left, barRectVert.Top + vertBarBtnHeight, barRectVert.Right,
barRectVert.Bottom - vertBarBtnHeight);
end;
if (drawHorzBar) then
begin
ExcludeClipRect(
DC, barRectHorz.Left + horzBarBtnWidth, barRectHorz.Top,
barRectHorz.Right - horzBarBtnWidth, barRectHorz.Bottom);
end;
// remove client area from drawing
r := DrawRect;
r.Inflate(-2, -2);
Dec(r.Bottom, horzBarHeight);
Dec(r.Right, vertBarWidth);
ExcludeClipRect(DC, r.Left, r.Top, r.Right, r.Bottom);
// draw border
Details := StyleServices.GetElementDetails(tlListviewRoot);
StyleServices.DrawElement(DC, Details, DrawRect);
// draw bar arrows
if drawVertBar then
begin
r := barRectVert;
r.Height := vertBarBtnHeight;
Details := StyleServices.GetElementDetails(tsArrowBtnUpNormal);
StyleServices.DrawElement(DC, Details, r);
r := barRectVert;
r.Top := r.Bottom - vertBarWidth;
Details := StyleServices.GetElementDetails(tsArrowBtnDownNormal);
StyleServices.DrawElement(DC, Details, r);
end;
if drawHorzBar then
begin
r := barRectHorz;
r.Width := horzBarBtnWidth;
Details := StyleServices.GetElementDetails(tsArrowBtnLeftNormal);
StyleServices.DrawElement(DC, Details, r);
r := barRectHorz;
r.Left := r.Right - horzBarBtnWidth;
Details := StyleServices.GetElementDetails(tsArrowBtnRightNormal);
StyleServices.DrawElement(DC, Details, r);
end;
finally
ReleaseDC(Handle, DC);
end;
end;
end;
end;
function TDataViewer.ElementFromPos(const Pos: Integer): Byte;
type
TLineArray = array of TPoint;
function GetLineIdx( const Lines: TLineArray; Point: Integer ): Integer;
var
I: Integer;
begin
for I := Low( Lines ) to High( Lines ) do
if (Point > Lines[ I ].X) and (Point <= Lines[ I ].Y) then
begin
Result := I;
Exit;
end;
Result := -1;
end;
const
Border = 6;
var
ShowOffset, ShowHex, ShowChar: Boolean;
Pt: Integer;
S: ShortString;
Width: Integer;
L: TLineArray;
begin
ShowOffset := hvOffset in VisibleElements;
ShowHex := hvHexData in VisibleElements;
ShowChar := hvCharData in VisibleElements;
Pt := Pos;
S := '';
Dec( Pt, fBorderLeft );
SetLength( L, 7 );
FillChar( L[ 0 ], SizeOf( TPoint ) * 7, 0 );
L[ 0 ].X := -999999;
L[ 0 ].Y := 0;
Width := 0;
Dec( Width, fCharWidth * HScroll );
if ShowOffset then
begin
L[ 1 ].X := Width;
Inc( Width, Length( AddressTempl ) * fCharWidth );
L[ 1 ].Y := Width;
if ShowHex or ShowChar then
begin
L[ 2 ].X := Width;
Inc( Width, Length( AddressDelTempl ) * fCharWidth );
L[ 2 ].Y := Width - Border;
end;
end;
if ShowHex then
begin
L[ 3 ].X := Width - Border;
Inc( Width, Length( HexTempl ) * fCharWidth );
L[ 3 ].Y := Width + Border;
if {ShowHex or} ShowChar then
begin
L[ 4 ].X := Width + Border;
Inc( Width, Length( HexDelTempl ) * fCharWidth );
L[ 4 ].Y := Width - Border;
end;
end;
if ShowChar then
begin
L[ 5 ].X := Width - Border;
Inc( Width, Length( DataTempl ) * fCharWidth );
L[ 5 ].Y := Width + Border;
end;
L[ 6 ].X := Width + Border;
L[ 6 ].Y := 999999;
Result := GetLineIdx( L, Pt );
end;
procedure TDataViewer.Freeze;
begin
Inc( fFreezeCount );
end;
function TDataViewer.GetCharPoint( N: Integer; Element: TViewerElement ): TPoint;
begin
Result := GetPosPoint( GetCharPos( N ), Element );
end;
function TDataViewer.GetCharPos(N: Integer; BlockRecursive: Boolean): TPos;
var
col, row, i: Integer;
start: Pointer;
begin
case Mode of
hmHex:
begin
Result.Col := N mod 16;
Result.Row := N div 16;
if Result.Row >= fLineCount then
begin
Result.Col := FCurLineWidth;
Result.Row := fLineCount - 1;
end;
end;
hmTextBinary:
begin
Result.Col := N mod FCurLineWidth;
Result.Row := N div FCurLineWidth;
if Result.Row >= fLineCount then
begin
Result.Col := FCurLineWidth;
Result.Row := fLineCount - 1;
end;
end;
hmTextFree:
begin
// Offset := fSL.Objects[ 0 ];
if (fSL.Count > 0) then
start := fSL.Objects[0]
else
start := nil;
Col := 0;
Row := 0;
for I := fSL.Count - 1 downto 0 do
begin
if N >= (SysInt(fSL.Objects[I]) - SysInt(start)) then
begin
Col := N - (SysInt(fSL.Objects[I]) - SysInt(start));
Row := I;
if Col > Length(fSL[I]) then
begin
Col := 0;
Inc( Row );
Inc( fSelEnd );
end;
Break;
end;
end;
Result.Col := Col;
Result.Row := Row;
end;
end;
end;
function TDataViewer.GetEmpty: Boolean;
begin
Result := not ((Stream <> nil) or (fSL.Count > 0));
end;
function TDataViewer.GetFontSize: Integer;
begin
Result := Font.Size;
end;
function TDataViewer.GetFreezed: Boolean;
begin
Result := fFreezeCount > 0;
end;
function TDataViewer.GetFullCols: Integer;
var
R: TRect;
begin
R := ClientRect;
Inc( R.Left, fBorderLeft );
Dec( R.Right, fBorderRight );
Result := ColsPerWidth( R, fCharWidth );
end;
function TDataViewer.GetFullLines: Integer;
begin
Result := LinesPerHeight(ClientRect, fCharHeight);
end;
function TDataViewer.GetHScroll: Integer;
begin
Result := GetScrollPos(Handle, SB_HORZ);
end;
function TDataViewer.GetPointPos(const Point: TPoint; Element: TViewerElement): TPos;
var
{Line, Col,} CL: Integer;
R: TRect;
WH: Byte;
ElemLeft, VP, HP, {I,} L: Integer;
S: ShortString;
ShowOffset, ShowHex, ShowChar: Boolean;
Pt: TPoint;
St: string;
// Offset: Cardinal;
begin
R := ClientRect;
CL := LinesPerHeight( R, fCharHeight );
WH := fCharWidth div 2;
Pt := Point;
VP := GetScrollPos(Handle, SB_VERT);
HP := GetScrollPos(Handle, SB_HORZ);
Int64(Result) := 0;
case Mode of
hmHex:
begin
ShowOffset := hvOffset in VisibleElements;
ShowHex := hvHexData in VisibleElements;
ShowChar := hvCharData in VisibleElements;
case Element of
hvCharData:
begin
S := '';
if ShowOffset then
if ShowHex or ShowChar then
S := S + AddressTempl + AddressDelTempl
else
S := S + AddressTempl;
if ShowHex then
if ShowChar then
S := S + HexTempl + HexDelTempl
else
S := S + HexTempl;
ElemLeft := Length( S ) * fCharWidth;
Dec( Pt.X, ElemLeft + fBorderLeft - HP * fCharWidth );
if Pt.Y < 0 then
Result.Row := 0
else
begin
Result.Row := Pt.Y div fCharHeight;
if Result.Row > CL then
Result.Row := CL;
end;
if Pt.X < 0 then
Result.Col := 0
else
begin
Result.Col := (Pt.X + WH) div fCharWidth;
if Result.Col > 16 then
Result.Col := 16;
end;
//Inc( Col, HP );
Inc( Result.Row, VP );
{ Result := Line * 16 + Col;
if Cardinal(Result) > StreamDataSize then
Result := StreamDataSize;}
end;
hvHexData:
begin
S := '';
if ShowOffset then
if ShowHex or ShowChar then
S := S + AddressTempl + AddressDelTempl
else
S := S + AddressTempl;
ElemLeft := Length( S ) * fCharWidth;
Dec( Pt.X, ElemLeft + fBorderLeft - HP * fCharWidth );
if Pt.Y < 0 then
Result.Row := 0
else
begin
Result.Row := Pt.Y div fCharHeight;
if Result.Row > CL then
Result.Row := CL;
end;
if Pt.X < 0 then
Result.Col := 0
else
begin
Result.Col := ((Pt.X + WH) div fCharWidth + 2) div 3;
if Result.Col > 16 then
Result.Col := 16;
end;
//Inc( Col, HP div 3 );
Inc( Result.Row, VP );
{ Result := Line * 16 + Col;
if Cardinal(Result) > StreamDataSize then
Result := StreamDataSize;}
end;
end;
end;
hmTextBinary:
begin
Dec( Pt.X, fBorderLeft );
if Pt.Y < 0 then
Result.Row := 0
else
begin
Result.Row := Pt.Y div fCharHeight;
if Result.Row > CL then
Result.Row := CL;
end;
if Pt.X < 0 then
Result.Col := 0
else
begin
Result.Col := (Pt.X + WH) div fCharWidth;
if Result.Col > CurLineWidth then
Result.Col := CurLineWidth;
end;
Inc( Result.Row, VP );
Inc( Result.Col, HP );
{ Result := Line * Integer(LineWidth) + Col;
if Cardinal(Result) > StreamDataSize then
Result := StreamDataSize;}
end;
hmTextFree:
begin
Dec( Pt.X, fBorderLeft );
if Pt.Y < 0 then
Result.Row := 0
else
begin
Result.Row := Pt.Y div fCharHeight;
if Result.Row > CL then
Result.Row := CL;
end;
Inc( Result.Row, VP );
if Result.Row >= fLineCount then
Result.Row := fLineCount - 1;
St := fSL[ Result.Row ];
L := Length( St );
if Pt.X < 0 then
Result.Col := 0
else
begin
Result.Col := (Pt.X + WH) div fCharWidth;
if Result.Col > L then
Result.Col := L;
end;
Inc( Result.Col, HP );
{ Result := 0;
Inc( Result, fSL.Objects[ Result.Row ] );
Inc( Result, Result.Col );
if Cardinal(Result) > StreamDataSize then
Result := StreamDataSize;}
end;
end;
end;
function TDataViewer.GetPosChar(Pos: TPos): Integer;
var
L: Integer;
begin
case Mode of
hmHex:
begin
if Pos.Col > 16 then
Pos.Col := 16;
if Pos.Row >= fLineCount then
Pos.Row := fLineCount - 1;
if Pos.Row < 0 then
Pos.Row := 0;
Result := Pos.Row * 16 + Pos.Col;
end;
hmTextBinary:
begin
if Pos.Col > CurLineWidth then
begin
Pos.Col := CurLineWidth;
if (Mode = hmTextBinary) then
Dec( Pos.Col );
end;
if Pos.Row >= fLineCount then
Pos.Row := fLineCount - 1;
if Pos.Row < 0 then
Pos.Row := 0;
Result := Pos.Row * CurLineWidth + Pos.Col;
end;
hmTextFree:
begin
if Pos.Row >= fLineCount then
Pos.Row := fLineCount - 1;
if Pos.Row < 0 then
Pos.Row := 0;
L := Length(fSL[ Pos.Row ]);
if Pos.Col > L then
Pos.Col := L;
Result := Integer(fSL.Objects[Pos.Row]) - Integer(fSL.Objects[0]) + Pos.Col;
end;
else
Result := 0;
end;
end;
function TDataViewer.GetPosPoint(Pos: TPos; Element: TViewerElement): TPoint;
var
ShowOffset, ShowHex, ShowChar: Boolean;
ElemLeft, L: Integer;
S: string;
begin
case Mode of
hmHex:
begin
ShowOffset := hvOffset in VisibleElements;
ShowHex := hvHexData in VisibleElements;
ShowChar := hvCharData in VisibleElements;
case Element of
hvCharData:
begin
S := '';
if ShowOffset then
if ShowHex or ShowChar then
S := S + AddressTempl + AddressDelTempl
else
S := S + AddressTempl;
if ShowHex then
if ShowChar then
S := S + HexTempl + HexDelTempl
else
S := S + HexTempl;
ElemLeft := Length( S ) * fCharWidth;
if Pos.Col > 16 then