-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathUnit_ChattingBoxClass.pas
More file actions
1016 lines (924 loc) · 31.9 KB
/
Copy pathUnit_ChattingBoxClass.pas
File metadata and controls
1016 lines (924 loc) · 31.9 KB
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 Unit_ChattingBoxClass;
{$I OllmaClient_Defines.inc}
interface
uses
Winapi.Windows,
Winapi.Messages,
System.SysUtils,
System.Variants,
System.Classes,
Vcl.Graphics,
Vcl.Controls,
Vcl.Forms,
Vcl.Dialogs,
VirtualTrees.Types,
VirtualTrees.BaseAncestorVCL,
VirtualTrees.BaseTree,
VirtualTrees.AncestorVCL,
VirtualTrees,
Vcl.BaseImageCollection,
Vcl.ImageCollection,
System.ImageList,
Vcl.ImgList,
Vcl.VirtualImageList,
Vcl.Menus;
type
TMessageRec = packed record
FUser: string;
FCaption: string;
FTime: TDateTime;
FTag: Integer;
FLvTag: Integer;
FSession: Integer; { Reserved ... }
end;
PMessageRec = ^TMessageRec;
type
TFrame_ChattingBoxClass = class(TFrame)
VST_ChattingBox: TVirtualStringTree;
VirtualImageList1: TVirtualImageList;
ImageCollection1: TImageCollection;
PopupMenu1: TPopupMenu;
pmn_SelectedColor: TMenuItem;
N1: TMenuItem;
pmn_Delete: TMenuItem;
pmn_CopyText: TMenuItem;
pmn_ColorSettings: TMenuItem;
N2: TMenuItem;
pmn_TextToSpeech: TMenuItem;
pmn_ScrollToTop: TMenuItem;
pmn_ScrollToBottom: TMenuItem;
pmn_ClearChattingBox: TMenuItem;
N3: TMenuItem;
pmn_ShowLogs: TMenuItem;
procedure VST_ChattingBoxGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
procedure VST_ChattingBoxBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
procedure VST_ChattingBoxEditing(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; var Allowed: Boolean);
procedure VST_ChattingBoxFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
procedure VST_ChattingBoxInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
procedure VST_ChattingBoxMeasureItem(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; var NodeHeight: TDimension);
procedure VST_DrawTitle(Sender: TBaseVirtualTree; Node: PVirtualNode; var Title, TimeStamp: string; var Tag, LvTag: Integer);
procedure VST_ChattingBoxResize(Sender: TObject);
procedure VST_ChattingBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure VST_ChattingBoxDragOver(Sender: TBaseVirtualTree; Source: TObject; Shift: TShiftState; State: TDragState; Pt: TPoint; Mode: TDropMode; var Effect: Integer; var Accept: Boolean);
procedure VST_ChattingBoxColumnResize(Sender: TVTHeader; Column: TColumnIndex);
procedure PopupMenu1Popup(Sender: TObject);
procedure pmn_DeleteClick(Sender: TObject);
procedure pmn_SelectedColorClick(Sender: TObject);
procedure pmn_CopyTextClick(Sender: TObject);
procedure pmn_ColorSettingsClick(Sender: TObject);
procedure VST_ChattingBoxLoadNode(Sender: TBaseVirtualTree; Node: PVirtualNode; Stream: TStream);
procedure VST_ChattingBoxSaveNode(Sender: TBaseVirtualTree; Node: PVirtualNode; Stream: TStream);
private
FVST_NBodyFontSize: Integer;
FVST_NHeaderColor: TColor;
FVST_NBodyColor: TColor;
FVST_NFooterColor: TColor;
FVST_NSelectionColor: TColor;
FVST_ColumnOffset: Integer;
FVST_SecondIndent: Integer;
FVST_FontName: string;
FVST_FontSize: Integer;
FVST_NodeHeightOffSet: Integer;
function GetSelectionColor: TColor;
procedure SetVST_NBodyFontSize(const Value: Integer);
procedure SetVST_NSelectionColor(const Value: TColor);
procedure SetVST_NBodyColor(const Value: TColor);
procedure SetVST_NFooterColor(const Value: TColor);
procedure SetVST_NHeaderColor(const Value: TColor);
procedure SetVST_Fontname(const Value: string);
procedure SetVST_FontSize(const Value: Integer);
procedure SetVST_NodeHeightOffSet(const Value: Integer);
public
procedure InitializeEx(const AHeaderColor, ABodyColor, AFooterColor: TColor);
procedure FinalizeEx(const AFlag: Integer);
//
procedure Add_Chatting_Message(const AUser: string; const ALocation, ALvTag: Integer; const APrompt: string; const ALockFocus: Boolean = False);
procedure Insert_Chatting_Translation(const AIndex: Integer; const AUser: string; const ALocation: Integer; const APrompt: string);
//
function Get_NodeText(): string;
function Get_NodeTextLocation(var VIndex, VLocation: Integer): string;
function Get_IsResponseNode(const AFlag: Integer = 0): Boolean;
function Get_NodeRequest(): string;
function Get_SelectedColor(): TColor;
procedure Do_ScrollToTop(const AFlag: Integer = 0; const ALockFocus: Boolean = False);
procedure Do_ScrollToBottom(const AFlag: Integer = 0; const ALockFocus: Boolean = False);
function Do_SaveAllText(const AFile: string): Boolean;
function Do_DeleteNode(): Boolean;
procedure Do_RestoreDefaultColor(const AFontOnlyFlag: Integer = 0);
procedure Do_SetCustomFont(const AFlag: Integer; const AFontName: string; const AFontSize: Integer);
procedure Do_SetCustomColor(const AFlag: Integer; const ASelColor, AHeaderColor, ABodyColor, AFooterColor: TColor);
function Get_CustomColor(var VHeaderColor, VBodyColor, VFooterColor: TColor): TColor;
procedure Set_FontEx(AFont: TFont);
// History Manager
procedure Do_LoadAllData(const ALFile: string);
procedure Add_DummyHistorySubject(const AIndex: Integer; const AUser: string; const ALocation: Integer; const APrompt: string; const ALockFocus: Boolean = False);
function Do_SaveAllData(const ASFile: string): Boolean;
function Get_HistorySubject(): string;
function Get_ChatHistory(const ANodeOneFlag: Boolean = False): string;
//
property VST_NBodyFontSize: Integer read FVST_NBodyFontSize write SetVST_NBodyFontSize;
property VST_NSelectionColor: TColor read FVST_NSelectionColor write SetVST_NSelectionColor;
property VST_NHeaderColor: TColor read FVST_NHeaderColor write SetVST_NHeaderColor;
property VST_NBodyColor: TColor read FVST_NBodyColor write SetVST_NBodyColor;
property VST_NFooterColor: TColor read FVST_NFooterColor write SetVST_NFooterColor;
property VST_FontName: string read FVST_FontName write SetVST_FontName;
property VST_FontSize: Integer read FVST_FontSize write SetVST_FontSize;
property VST_NodeHeightOffSet: Integer read FVST_NodeHeightOffSet write SetVST_NodeHeightOffSet;
end;
implementation
uses
System.UITypes,
Vcl.Clipbrd,
Unit_Common,
Unit_About;
{$R *.dfm}
procedure TFrame_ChattingBoxClass.InitializeEx(const AHeaderColor, ABodyColor, AFooterColor: TColor);
begin
FVST_NHeaderColor := AHeaderColor;
FVST_NBodyColor := ABodyColor;
FVST_NFooterColor := AFooterColor;
FVST_NSelectionColor := GC_SkinSelColor;
FVST_NBodyFontSize := GC_SkinFontSize;
FVST_ColumnOffset := 15; // Local ...
FVST_SecondIndent := 35; // Reference of Indent for Ollama Response ...
FVST_FontName := VST_ChattingBox.Font.Name;
FVST_FontSize := GC_SkinFontSize;
FVST_NodeHeightOffSet := 15;
with VST_ChattingBox do
begin
TextMargin := 20;
SelectionCurveRadius := 20;
NodeDataSize := SizeOf(TMessageRec);
NodeAlignment := TVTNodeAlignment.naFromTop;
Header.Options := Header.Options - [hoAutoResize];
Header.Columns[0].Width := ClientWidth - FVST_ColumnOffset;
TreeOptions.AnimationOptions := [];
TreeOptions.MiscOptions := TreeOptions.MiscOptions + [TVTMiscOption.toVariablenodeHeight];
TreeOptions.AutoOptions := TreeOptions.AutoOptions - [TVTAutoOption.toAutoSpanColumns]; // too much overhead ...
TreeOptions.StringOptions := TreeOptions.StringOptions - [TVTStringOption.toShowStaticText];
TreeOptions.SelectionOptions := TreeOptions.SelectionOptions + [TVTSelectionOption.toSelectNextNodeOnRemoval]-[TVTSelectionOption.toMultiSelect];
{ Custom ... }
Images := VirtualImageList1;
OffsetWRMagin := 30;
NodeHeightOffSet := FVST_NodeHeightOffSet;
SelectedBrushColor := FVST_NSelectionColor; // in TBaseVirtualTree.pas ...
Node_HeaderColor := FVST_NHeaderColor;
Node_BodyColor := FVST_NBodyColor;
Node_FooterColor := FVST_NFooterColor;
//
OnDrawTitle := VST_DrawTitle;
end;
end;
procedure TFrame_ChattingBoxClass.FinalizeEx(const AFlag: Integer);
begin
with VST_ChattingBox do
begin
Clear;
end;
end;
procedure TFrame_ChattingBoxClass.Add_Chatting_Message(const AUser: string; const ALocation, ALvTag: Integer; const APrompt: string; const ALockFocus: Boolean = False);
begin
var _FNode := VST_ChattingBox.FocusedNode;
with VST_ChattingBox do
begin
BeginUpdate;
ClearSelection;
var _Node := AddChild(nil);
MultiLine[_Node] := True; // Modified by ichin 2025-05-06 화 오후 3:48:09
try
var _Data: PMessageRec := GetNodeData(_Node);
with _Data^ do
begin
FUser := AUser;
FCaption := APrompt;
FTime := Now;
FTag := ALocation;
FLvTag := IIF.CastBool<Integer>(ALocation = 0, ALvTag, -1);
FSession := 0;
end;
finally
EndUpdate;
end;
FocusedNode := _Node;
Selected[_Node] := True;
InvalidateToBottom(_Node);
Perform(WM_VSCROLL, SB_BOTTOM, 0);
if ALockFocus and (_FNode <> nil) then
begin
FocusedNode := _FNode;
Selected[_FNode] := True;
Perform(WM_VSCROLL, SB_BOTTOM, 0);
end;
end;
end;
procedure TFrame_ChattingBoxClass.Insert_Chatting_Translation(const AIndex: Integer; const AUser: string; const ALocation: Integer; const APrompt: string);
begin
var _bottomflag: Boolean := False;
with VST_ChattingBox do
begin
BeginUpdate;
var _Node := FocusedNode;
ClearSelection;
try
if (_Node <> nil) and (_Node.Index = AIndex) then
begin
var _next: PVirtualNode := _Node.NextSibling;
if _next <> nil then
begin
_Node := InsertNode(_next, amInsertBefore);
end
else
begin
_bottomflag := True;
_Node := AddChild(nil);
end;
end
else
begin
_bottomflag := True;
_Node := AddChild(nil);
end;
MultiLine[_Node] := True; // Modified by ichin 2025-05-06 화 오후 3:48:09
var _Data: PMessageRec := GetNodeData(_Node);
with _Data^ do
begin
FUser := AUser;
FCaption := APrompt;
FTime := Now;
FTag := ALocation; // = 2
FLvTag := -1;
FSession := 0;
end;
finally
EndUpdate;
end;
FocusedNode := _Node;
Selected[_Node] := True;
InvalidateNode(_Node); // Modified by ichin 2025-05-06 화 오후 3:38:19
if _bottomflag then
Perform(WM_VSCROLL, SB_BOTTOM, 0);
end;
end;
procedure TFrame_ChattingBoxClass.Add_DummyHistorySubject(const AIndex: Integer; const AUser: string; const ALocation: Integer; const APrompt: string; const ALockFocus: Boolean = False);
begin
var _FNode := VST_ChattingBox.FocusedNode;
with VST_ChattingBox do
begin
BeginUpdate;
ClearSelection;
var _Node := GetFirst;
try
if _Node <> nil then
begin
var _next := _Node.NextSibling;
if _next <> nil then
_Node := InsertNode(_Node, amInsertBefore)
else
_Node := AddChild(nil);
end
else
_Node := AddChild(nil);
MultiLine[_Node] := True; // Modified by ichin 2025-05-06 화 오후 3:48:09
var _Data: PMessageRec := GetNodeData(_Node);
with _Data^ do
begin
FUser := AUser;
FCaption := APrompt;
FTime := Now;
FTag := ALocation;
FLvTag := -1;
FSession := 0;
end;
var _second := _Node.NextSibling;
if _second <> nil then
begin
var _seconddata: PMessageRec := GetNodeData(_second);
if (_seconddata^.FTag = 0) and SameText(_seconddata^.FUser, AUser) then // V_Username + ' (history)';
try
DeleteNode(_second);
except
Abort;
end;
end;
finally
EndUpdate;
end;
FocusedNode := _Node;
Selected[_Node] := True;
InvalidateNode(_Node); // Modified by ichin 2025-05-06 화 오후 3:38:28
Perform(WM_VSCROLL, SB_TOP, 0);
if ALockFocus and (_FNode <> nil) then
begin
FocusedNode := _FNode;
Selected[_FNode] := True;
InvalidateNode(_FNode); // Modified by ichin 2025-05-06 화 오후 3:38:45
Perform(WM_VSCROLL, SB_TOP, 0);
end;
end;
end;
procedure TFrame_ChattingBoxClass.Do_ScrollToTop(const AFlag: Integer; const ALockFocus: Boolean);
begin
if ALockFocus then
with VST_ChattingBox do
begin
UpdateScrollBars(True);
Invalidate;
Perform(WM_VSCROLL, SB_TOP, 0);
Exit;
end;
with VST_ChattingBox do
begin
var _node := GetFirst();
if Assigned(_node) then
begin
ClearSelection;
IsVisible[_node] := True;
Selected[_node] := True;
FocusedNode := _node;
end;
UpdateScrollBars(True);
Invalidate;
Perform(WM_VSCROLL, SB_TOP, 0);
end;
end;
procedure TFrame_ChattingBoxClass.Do_ScrollToBottom(const AFlag: Integer; const ALockFocus: Boolean);
begin
if ALockFocus then
with VST_ChattingBox do
begin
UpdateScrollBars(True);
Invalidate;
Perform(WM_VSCROLL, SB_BOTTOM, 0);
Exit;
end;
with VST_ChattingBox do
begin
var _node := GetLast();
if Assigned(_node) then
begin
ClearSelection;
IsVisible[_node] := True;
Selected[_node] := True;
FocusedNode := _node;
end;
UpdateScrollBars(True);
Invalidate;
Perform(WM_VSCROLL, SB_BOTTOM, 0);
end;
end;
procedure TFrame_ChattingBoxClass.pmn_DeleteClick(Sender: TObject);
begin
Do_DeleteNode();
end;
procedure TFrame_ChattingBoxClass.pmn_SelectedColorClick(Sender: TObject);
begin
with TColorDialog.Create(Self) do
try
Color := VST_ChattingBox.SelectedBrushColor;
if Execute() then
begin
Self.VST_NSelectionColor := Color;
end;
finally
Free;
end;
end;
procedure TFrame_ChattingBoxClass.PopupMenu1Popup(Sender: TObject);
begin
var _selbool: Boolean := VST_ChattingBox.SelectedCount > 0;
pmn_CopyText.Enabled := _selbool;
pmn_Delete.Enabled := _selbool;
pmn_TextToSpeech.Enabled := _selbool;
end;
procedure TFrame_ChattingBoxClass.SetVST_NBodyFontSize(const Value: Integer);
begin
if FVST_NBodyFontSize <> Value then
begin
FVST_NBodyFontSize := Value;
FVST_FontSize := Value;
VST_ChattingBox.Font.Size := Value;
VST_ChattingBox.Invalidate;
end;
end;
function TFrame_ChattingBoxClass.GetSelectionColor: TColor;
begin
Result := VST_ChattingBox.SelectedBrushColor;
end;
procedure TFrame_ChattingBoxClass.SetVST_NSelectionColor(const Value: TColor);
begin
if FVST_NSelectionColor <> Value then
begin
FVST_NSelectionColor := Value;
VST_ChattingBox.SelectedBrushColor := Value;
end;
end;
procedure TFrame_ChattingBoxClass.Set_FontEx(AFont: TFont);
begin
VST_ChattingBox.Font.Assign(AFont);
FVST_NBodyFontSize := AFont.Size;
FVST_FontName := AFont.Name;
FVST_FontSize := AFont.Size;
end;
procedure TFrame_ChattingBoxClass.SetVST_FontName(const Value: string);
begin
if FVST_FontName <> Value then
begin
FVST_FontName := Value;
VST_ChattingBox.Font.Name := Value;
end;
end;
procedure TFrame_ChattingBoxClass.SetVST_FontSize(const Value: Integer);
begin
if FVST_FontSize <> Value then
begin
FVST_FontSize := Value;
VST_ChattingBox.Font.Size := Value;
end;
end;
procedure TFrame_ChattingBoxClass.SetVST_NBodyColor(const Value: TColor);
begin
if FVST_NBodyColor <> Value then
begin
FVST_NBodyColor := Value;
VST_ChattingBox.Node_BodyColor := Value;
end;
end;
procedure TFrame_ChattingBoxClass.SetVST_NFooterColor(const Value: TColor);
begin
if FVST_NFooterColor <> Value then
begin
FVST_NFooterColor := Value;
VST_ChattingBox.Node_FooterColor := Value;
end;
end;
procedure TFrame_ChattingBoxClass.SetVST_NHeaderColor(const Value: TColor);
begin
if FVST_NHeaderColor <> Value then
begin
FVST_NHeaderColor := Value;
VST_ChattingBox.Node_HeaderColor := Value;
end;
end;
procedure TFrame_ChattingBoxClass.SetVST_NodeHeightOffSet(const Value: Integer);
begin
if FVST_NodeHeightOffSet <> Value then
begin
FVST_NodeHeightOffSet := Value;
VST_ChattingBox.NodeHeightOffSet := Value;
VST_ChattingBox.Invalidate;
end;
end;
procedure TFrame_ChattingBoxClass.VST_ChattingBoxBeforeCellPaint(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
begin
var _Data: PMessageRec := Sender.GetNodeData(Node);
if _Data^.FTag > 0 then
ContentRect.Left := TargetCanvas.ClipRect.Left + FVST_SecondIndent; { = CellRect ... }
end;
procedure TFrame_ChattingBoxClass.VST_ChattingBoxColumnResize(Sender: TVTHeader; Column: TColumnIndex);
begin
VST_ChattingBox.Header.Columns[0].Width := VST_ChattingBox.ClientWidth - FVST_ColumnOffset;
end;
procedure TFrame_ChattingBoxClass.VST_ChattingBoxDragOver(Sender: TBaseVirtualTree; Source: TObject; Shift: TShiftState; State: TDragState; Pt: TPoint; Mode: TDropMode; var Effect: Integer; var Accept: Boolean);
begin
Accept := False;
end;
procedure TFrame_ChattingBoxClass.VST_ChattingBoxEditing(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; var Allowed: Boolean);
begin
Allowed := False;
end;
procedure TFrame_ChattingBoxClass.VST_ChattingBoxFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
begin
var _Data: PMessageRec := Sender.GetNodeData(Node);
Finalize(_Data^);
end;
procedure TFrame_ChattingBoxClass.VST_ChattingBoxGetText(Sender: TBaseVirtualTree; Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
begin
case Column of
0:
begin
var _Data: PMessageRec := Sender.GetNodeData(Node);
if Assigned(_Data) then
CellText := _Data^.FCaption;
end;
end;
end;
procedure TFrame_ChattingBoxClass.VST_ChattingBoxInitNode(Sender: TBaseVirtualTree; ParentNode, Node: PVirtualNode; var InitialStates: TVirtualNodeInitStates);
begin
VST_ChattingBox.Header.Columns[0].Width := VST_ChattingBox.ClientWidth - FVST_ColumnOffset;
Include(InitialStates, ivsMultiline); // *** //
Node.States := Node.States + [vsMultiline, vsHeightMeasured];
end;
procedure TFrame_ChattingBoxClass.VST_ChattingBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if Key = VK_DELETE then
begin
Key := 0;
Do_DeleteNode();
end;
end;
procedure TFrame_ChattingBoxClass.VST_ChattingBoxMeasureItem(Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode; var NodeHeight: TDimension);
begin
VST_ChattingBox.Header.Columns[0].Width := VST_ChattingBox.ClientWidth - FVST_ColumnOffset;
if Sender.MultiLine[Node] then
begin
TargetCanvas.Font := Sender.Font;
var _text: string := PMessageRec(VST_ChattingBox.GetNodeData(Node))^.FCaption;
NodeHeight := VST_ChattingBox.ComputeNodeHeight(TargetCanvas, Node, 0, _text);
end;
end;
procedure TFrame_ChattingBoxClass.VST_ChattingBoxResize(Sender: TObject);
begin
with VST_ChattingBox do
begin
Header.Columns[0].Width := ClientWidth - FVST_ColumnOffset;
var _node := FocusedNode;
if Assigned(_node) then
begin
IsVisible[_node] := True;
FocusedNode := _node;
end;
UpdateScrollBars(True);
Invalidate;
end;
end;
procedure TFrame_ChattingBoxClass.VST_DrawTitle(Sender: TBaseVirtualTree; Node: PVirtualNode; var Title, TimeStamp: string; var Tag, LvTag: Integer);
begin
var _Data: PMessageRec := Sender.GetNodeData(Node);
if Assigned(_Data) then
begin
Title := _Data^.FUser;
TimeStamp := FormatDateTime('( hh:nn:ss )', _Data^.FTime);
Tag := _Data^.FTag;
LvTag := _Data^.FLvTag;
end;
end;
function TFrame_ChattingBoxClass.Get_CustomColor(var VHeaderColor, VBodyColor, VFooterColor: TColor): TColor;
begin
Result := FVST_NSelectionColor;
VHeaderColor := FVST_NHeaderColor;
VBodyColor := FVST_NBodyColor;
VFooterColor := FVST_NFooterColor;
end;
function TFrame_ChattingBoxClass.Get_NodeRequest: string;
begin
Result := '';
with VST_ChattingBox do
begin
var _node := FocusedNode;
if Assigned(_node) then
begin
_node := _node.PrevSibling;
if _node <> nil then
begin
var _Data: PMessageRec := GetNodeData(_node);
if (_Data <> nil) and (_Data^.FTag = 0) then
Result := _Data^.FCaption;
end;
end;
end;
end;
function TFrame_ChattingBoxClass.Get_NodeText: string;
begin
Result := '';
with VST_ChattingBox do
begin
var _node := FocusedNode;
if Assigned(_node) then
begin
var _Data: PMessageRec := GetNodeData(_node);
if (_Data <> nil) then
Result := _Data^.FCaption;
end;
end;
end;
function TFrame_ChattingBoxClass.Get_NodeTextLocation(var VIndex, VLocation: Integer): string;
begin
Result := '';
with VST_ChattingBox do
begin
var _node := FocusedNode;
if Assigned(_node) then
begin
VIndex := _node.Index;
var _Data: PMessageRec := GetNodeData(_node);
if (_Data <> nil) then
begin
VLocation := _Data^.FTag;
Result := _Data^.FCaption;
end;
end;
end;
end;
function TFrame_ChattingBoxClass.Get_IsResponseNode(const AFlag: Integer): Boolean;
begin
Result := False;
with VST_ChattingBox do
begin
var _node := FocusedNode;
if Assigned(_node) then
begin
var _Data: PMessageRec := GetNodeData(_node);
Result := (_Data <> nil) and (_Data^.FTag = 1);
end;
end;
end;
function TFrame_ChattingBoxClass.Get_SelectedColor: TColor;
begin
Result := VST_ChattingBox.SelectedBrushColor;
end;
procedure TFrame_ChattingBoxClass.pmn_ColorSettingsClick(Sender: TObject);
begin
with TForm_About.Create(Self) do
try
Show_Flag := GC_AboutSkinFlag;
ShowModal;
finally
Free;
end;
end;
procedure TFrame_ChattingBoxClass.pmn_CopyTextClick(Sender: TObject);
begin
var _ItemStr := Get_NodeText;
if _ItemStr <> '' then
begin
Clipboard.Clear;
Clipboard.AsText := _ItemStr;
end;
end;
function TFrame_ChattingBoxClass.Do_DeleteNode: Boolean;
begin
Result := False;
with VST_ChattingBox do
begin
var _node := FocusedNode;
if Assigned(_node) then
begin
DeleteNode(_node);
Result := True;
end;
end;
end;
procedure TFrame_ChattingBoxClass.Do_RestoreDefaultColor(const AFontOnlyFlag: Integer);
begin
if AFontOnlyFlag = 1 then
begin
FVST_NBodyFontSize := 10;
with VST_ChattingBox do
try
BeginUpdate;
Font.Name := Self.Font.Name;
Font.Size := FVST_NBodyFontSize;
finally
EndUpdate;
end;
FVST_FontName := Self.Font.name;
FVST_FontSize := 10;
Exit;
end;
FVST_NSelectionColor := GC_SkinSelColor;
FVST_NHeaderColor := GC_SkinHeadColor;
FVST_NBodyColor := GC_SkinBodyColor;
FVST_NFooterColor := GC_SkinFootColor;
FVST_NBodyFontSize := GC_SkinFontSize;
FVST_FontSize := GC_SkinFontSize;
GV_ReservedColor[0] := FVST_NSelectionColor;
GV_ReservedColor[1] := FVST_NHeaderColor;
GV_ReservedColor[2] := FVST_NBodyColor;
GV_ReservedColor[3] := FVST_NFooterColor;
with VST_ChattingBox do
try
BeginUpdate;
Node_HeaderColor := FVST_NHeaderColor;
Node_BodyColor := FVST_NBodyColor;
Node_FooterColor := FVST_NFooterColor;
Font.Name := FVST_FontName;
Font.Size := FVST_NBodyFontSize;
SelectedBrushColor := FVST_NSelectionColor; { > Include Invalidation ... }
finally
EndUpdate;
end;
end;
procedure TFrame_ChattingBoxClass.Do_SetCustomColor(const AFlag: Integer; const ASelColor, AHeaderColor, ABodyColor, AFooterColor: TColor);
begin
if AFlag = 1 then
begin
GV_ReservedColor[0] := FVST_NSelectionColor;
GV_ReservedColor[1] := FVST_NHeaderColor;
GV_ReservedColor[2] := FVST_NBodyColor;
GV_ReservedColor[3] := FVST_NFooterColor;
end;
FVST_NSelectionColor := ASelColor;
FVST_NHeaderColor := AHeaderColor;
FVST_NBodyColor := ABodyColor;
FVST_NFooterColor := AFooterColor;
if AFlag = 0 then // for Restore Colors ...
begin
GV_ReservedColor[0] := FVST_NSelectionColor;
GV_ReservedColor[1] := FVST_NHeaderColor;
GV_ReservedColor[2] := FVST_NBodyColor;
GV_ReservedColor[3] := FVST_NFooterColor;
end;
with VST_ChattingBox do
try
BeginUpdate;
Node_HeaderColor := FVST_NHeaderColor;
Node_BodyColor := FVST_NBodyColor;
Node_FooterColor := FVST_NFooterColor;
SelectedBrushColor := FVST_NSelectionColor; { > Include Invalidation ... }
finally
EndUpdate;
end;
end;
procedure TFrame_ChattingBoxClass.Do_SetCustomFont(const AFlag: Integer; const AFontName: string; const AFontSize: Integer);
begin
VST_FontName := AFontName;
VST_FontSize := AFontSize;
VST_ChattingBox.Invalidate;
end;
function TFrame_ChattingBoxClass.Do_SaveAllText(const AFile: string): Boolean;
begin
Result := False;
if VST_ChattingBox.RootNodeCount < 1 then
Exit;
var _sourcelist := TStringList.Create;
var _Data: PMessageRec := nil;
var _index: Integer := 0;
var _qtag: Integer := 0;
var _prefixn: string := '';
var _prefixr: string := 'Q';
var _AddString: string := '';
var _CellText: string := '';
try
_sourcelist.BeginUpdate;
try
var _Node : PVirtualNode := VST_ChattingBox.GetFirst;
while Assigned(_Node) do
begin
_AddString := EmptyStr;
_Data := VST_ChattingBox.GetNodeData(_Node);
if _Data <> nil then
begin
_qtag := _Data^.FTag;
if _qtag = 0 then
begin
_prefixr := 'Q';
Inc(_index);
end
else
_prefixr := 'R';
_prefixn := Format('[%s.%.3d] ', [ _prefixr, _index]);
_CellText := _prefixn + _Data^.FUser;
_AddString := _AddString + _CellText +sLineBreak;
_CellText := _Data^.FCaption+ FormatDateTime('( hh:nn:ss )', _Data^.FTime);
_AddString := _AddString + _CellText +sLineBreak;
_sourcelist.Add(_AddString);
end;
_Node := _Node.NextSibling;
end;
finally
_sourcelist.EndUpdate;
end;
if _sourcelist.Count > 0 then
_sourcelist.SaveToFile(AFile);
finally
_sourcelist.Free;
end;
Result := FileExists(AFile);
end;
{ Save/Load Node Data for History Manager ------------------------------------ }
procedure TFrame_ChattingBoxClass.VST_ChattingBoxSaveNode(Sender: TBaseVirtualTree; Node: PVirtualNode; Stream: TStream);
begin
var _Data: PMessageRec := Sender.GetNodeData(Node);
with Stream do
begin
var _len:= Length(_Data^.FUser);
Write(_len, SizeOf(_len));
Write(PChar(_Data^.FUser)^, _len * SizeOf(Char));
_len := Length(_Data^.FCaption);
Write(_len, SizeOf(_len));
Write(PChar(_Data^.FCaption)^, _len * SizeOf(Char));
_len := SizeOf(_Data^.FTime);
Write(_len, SizeOf(_len));
Write(_Data^.FTime, _len);
_len := SizeOf(_Data^.FTag);
Write(_len, SizeOf(_len));
Write(_Data^.FTag, _len);
_len := SizeOf(_Data^.FLvTag);
Write(_len, SizeOf(_len));
Write(_Data^.FLvTag, _len);
//
_len := SizeOf(_Data^.FSession);
Write(_len, SizeOf(_len));
Write(_Data^.FSession, _len);
end;
end;
procedure TFrame_ChattingBoxClass.VST_ChattingBoxLoadNode(Sender: TBaseVirtualTree; Node: PVirtualNode; Stream: TStream);
begin
var _Data: PMessageRec := Sender.GetNodeData(Node);
var _leno: Integer := 0;
var _lenn: Int64 := Stream.Size; { Cover for Version < 1.1.1 }
var _imagetag: Integer := -1;
with Stream do
begin
Read(_leno, SizeOf(_leno));
SetLength(_Data^.FUser, _leno);
Read(PChar(_Data^.FUser)^, _leno * SizeOf(Char)); _lenn := _lenn - _leno* SizeOf(Char);
Read(_leno, SizeOf(_leno));
SetLength(_Data^.FCaption, _leno);
Read(PChar(_Data^.FCaption)^, _leno * SizeOf(Char)); _lenn := _lenn - _leno* SizeOf(Char);
Read(_leno, SizeOf(_leno)); _lenn := _lenn - _leno;
Read(_Data^.FTime, _leno);
Read(_leno, SizeOf(_leno)); _lenn := _lenn - _leno;
Read(_Data^.FTag, _leno);
Read(_leno, SizeOf(_leno)); _lenn := _lenn - _leno;
Read(_imagetag, _leno);
if _lenn > 0 then { Cover for Version < 1.1.1 }
begin
Read(_leno, SizeOf(_leno));
Read(_Data^.FSession, _leno);
end
else
_Data^.FSession := 0;
end;
if (_imagetag > 0) and (_Data^.FTime < GV_DateTime) then
_imagetag := 0; // Virtual Image Index ...
_Data^.FLvTag := _imagetag;
end;
function TFrame_ChattingBoxClass.Do_SaveAllData(const ASFile: string): Boolean;
begin
Result := False;
if VST_ChattingBox.RootNodeCount < 1 then
begin
MessageDlg('The list is empty. Nothing to save.', mtWarning, [mbOk], 0);
Exit;
end;
// ------------------------------------------------------------------------ //
VST_ChattingBox.SaveToFile(ASFile);
// ------------------------------------------------------------------------ //
Result := FileExists(ASFile);
end;
procedure TFrame_ChattingBoxClass.Do_LoadAllData(const ALFile: string);
begin
if not FileExists(ALFile) then Exit;
with VST_ChattingBox do
begin
Clear;
NodeDataSize := SizeOf(TMessageRec);
BeginUpdate;
try
// ------------------------------------------------------------------------ //
LoadFromFile(ALFile);
// ------------------------------------------------------------------------ //
finally
EndUpdate;
end;
var _Node: PVirtualNode := GetFirst;
FocusedNode := _Node;
Selected[_Node] := True;
Perform(WM_VSCROLL, SB_TOP, 0);
end;
end;
function TFrame_ChattingBoxClass.Get_HistorySubject: string;
begin
Result := '';
var _Node: PVirtualNode := VST_ChattingBox.GetFirst;
if Assigned(_Node) then
begin
var _Data: PMessageRec := nil;
_Data := VST_ChattingBox.GetNodeData(_Node);
if _Data^.FTag = 0 then
Result := _Data^.FCaption;
end;
end;
function TFrame_ChattingBoxClass.Get_ChatHistory(const ANodeOneFlag: Boolean = False): string;
begin
Result := '';
if VST_ChattingBox.RootNodeCount < 1 then Exit;
if ANodeOneFlag then
begin
var _Node: PVirtualNode := VST_ChattingBox.FocusedNode;
if Assigned(_Node) then
begin
var _Data: PMessageRec := nil;
_Data := VST_ChattingBox.GetNodeData(_Node);
if (_Data <> nil) and (_Data^.FTag = 1) then
Result := _Data^.FCaption;
end;
end
else
begin
var _Data: PMessageRec := nil;