-
Notifications
You must be signed in to change notification settings - Fork 2
/
Unit_ChattingBoxClass.pas
699 lines (632 loc) · 21.7 KB
/
Unit_ChattingBoxClass.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
unit Unit_ChattingBoxClass;
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
PMessageRec = ^TMessageRec;
TMessageRec = record
FUser: string;
FCaption: String;
FTime: TDateTime;
FTag: Integer;
FLvTag: Integer;
end;
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);
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;
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);
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);
procedure Insert_Chatting_Message(const AIndex: Integer; const AUser: string; const ALocation: Integer; const APrompt: string);
//
function Get_NodeText(): string;
function Get_NodeTextLocation(var AIndex, ALocation: Integer): string;
function Get_NodeRequest(): string;
function Get_SelectedColor(): TColor;
procedure Do_ScrollToTop(const AFlag: Integer = 0);
procedure Do_ScrollToBottom(const AFlag: Integer = 0);
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 AHeaderColor, ABodyColor, AFooterColor: TColor): TColor;
procedure Set_FontEx(AFont: TFont);
//
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;
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;;
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.MiscOptions := TreeOptions.MiscOptions + [TVTMiscOption.toVariablenodeHeight];
TreeOptions.AutoOptions := TreeOptions.AutoOptions - [TVTAutoOption.toAutoSpanColumns];
TreeOptions.SelectionOptions := TreeOptions.SelectionOptions + [TVTSelectionOption.toSelectNextNodeOnRemoval]-[TVTSelectionOption.toMultiSelect];
{ Custom ... }
OffsetWRMagin := 30;
NodeHeightOffSet := 15;
Images := VirtualImageList1;
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);
begin
with VST_ChattingBox do
begin
ClearSelection;
var _Node := AddChild(nil);
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);
end;
FocusedNode := _Node;
Selected[_Node] := True;
InvalidateToBottom(_Node);
Perform(WM_VSCROLL, SB_BOTTOM, 0);
end;
end;
procedure TFrame_ChattingBoxClass.Insert_Chatting_Message(const AIndex: Integer; const AUser: string; const ALocation: Integer; const APrompt: string);
begin
var _bottomflag: Boolean := False;
with VST_ChattingBox do
begin
var _Node := FocusedNode;
if _Node <> nil 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;
ClearSelection;
var _Data: PMessageRec := GetNodeData(_Node);
with _Data^ do
begin
FUser := AUser;
FCaption := APrompt;
FTime := Now;
FTag := ALocation;
FLvTag := -1;
end;
FocusedNode := _Node;
Selected[_Node] := True;
if _bottomflag then
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.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 = 1 then
ContentRect.Left := TargetCanvas.ClipRect.Left + FVST_SecondIndent;
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
var _Data: PMessageRec := Sender.GetNodeData(Node);
if Assigned(_Data) then
CellText := _Data^.FCaption;
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 AHeaderColor, ABodyColor, AFooterColor: TColor): TColor;
begin
Result := FVST_NSelectionColor;
AHeaderColor := FVST_NHeaderColor;
ABodyColor := FVST_NBodyColor;
AFooterColor := 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 AIndex, ALocation: Integer): string;
begin
Result := '';
with VST_ChattingBox do
begin
var _node := FocusedNode;
if Assigned(_node) then
begin
AIndex := _node.Index;
var _Data: PMessageRec := GetNodeData(_node);
if (_Data <> nil) then
begin
ALocation := _Data^.FTag;
Result := _Data^.FCaption;
end;
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
begin
BeginUpdate;
Font.Name := Self.Font.Name;
Font.Size := FVST_NBodyFontSize;
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
begin
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 ... }
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
begin
BeginUpdate;
Node_HeaderColor := FVST_NHeaderColor;
Node_BodyColor := FVST_NBodyColor;
Node_FooterColor := FVST_NFooterColor;
SelectedBrushColor := FVST_NSelectionColor; { > Include Invalidation ... }
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
var _sourcelist := TStringList.Create;
var _Data: PMessageRec := nil;
var _index: Integer := 0;
var _qtag: Integer := 0;
var _prefix: string := '';
var _AddString: string := '';
var _CellText: string := '';
try
_sourcelist.BeginUpdate;
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 Inc(_index);
_prefix := Format('[ %.3d ] ', [_index]);
_CellText := _prefix + _Data^.FUser;
_AddString := _AddString + _CellText +GC_CRLF;
_CellText := _Data^.FCaption+ FormatDateTime('( hh:nn:ss )', _Data^.FTime);
_AddString := _AddString + _CellText +GC_CRLF;
_sourcelist.Add(_AddString);
end;
_Node := _Node.NextSibling;
end;
_sourcelist.EndUpdate;
_sourcelist.SaveToFile(AFile);
finally
_sourcelist.Free;
end;
Result := FileExists(AFile);
end;
procedure TFrame_ChattingBoxClass.Do_ScrollToTop(const AFlag: Integer);
begin
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);
begin
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;
end.