-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFVTest.dpr
More file actions
1522 lines (1362 loc) · 43.9 KB
/
FVTest.dpr
File metadata and controls
1522 lines (1362 loc) · 43.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
program FVTest;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
Objects in 'src\Objects.pas',
Video in 'src\Video.pas',
Drivers in 'src\Drivers.pas',
Views in 'src\Views.pas',
Menus in 'src\Menus.pas',
HistList in 'src\histlist.pas',
fvconsts in 'src\fvconsts.pas',
App in 'src\app.pas',
FVCommon in 'src\FVCommon.pas',
Validate in 'src\Validate.pas',
Dialogs in 'src\Dialogs.pas',
MsgBox in 'src\MsgBox.pas',
StdDlg in 'src\StdDlg.pas',
ColorTxt in 'src\ColorTxt.pas',
Time in 'src\Time.pas',
Gadgets in 'src\Gadgets.pas',
InpLong in 'src\InpLong.pas',
AsciiTab in 'src\AsciiTab.pas',
TimedDlg in 'src\TimedDlg.pas',
Tabs in 'src\Tabs.pas',
Statuses in 'src\Statuses.pas',
ColorSel in 'src\ColorSel.pas',
Outline in 'src\Outline.pas',
Editors in 'src\Editors.pas',
Calendar in 'src\Calendar.pas';
const
cmNewWindow = 100;
cmTestWindow1 = 1001;
cmTestWindow2 = 1002;
cmTestDialog = 1003;
cmTestScroller = 1004;
cmTestMsgBox = 1005;
cmTestInputBox = 1006;
cmTestFileOpen = 1007;
cmTestChDir = 1008;
cmTestColoredText = 1009;
cmTestInputLong = 1010;
cmTestAsciiChart = 1011;
cmTestTimedDlg = 1012;
cmTestTabs = 1013;
cmAddTab = 1014;
cmRemoveTab = 1015;
cmTestStatuses = 1016;
cmUpdateGauge = 1017;
cmTestColors = 1018;
cmTestOutline = 1019;
cmTestEditor = 1020;
cmTestEditorFind = 1021;
cmTestEditorFile = 1022;
cmTestEditorClipboard = 1023;
cmTestCalendar = 1024;
cmTestCalendarBroadcast = 1025;
var
ExceptionLog: TextFile;
ExceptionLogOpen: Boolean = False;
IdleCounter: Integer = 0;
LastSecond: Word = 65535;
ClockView: PClockView = nil;
HeapView: PHeapView = nil;
procedure LogException(const Context: string; E: Exception);
begin
if not ExceptionLogOpen then begin
AssignFile(ExceptionLog, 'fvtest.log');
Rewrite(ExceptionLog);
ExceptionLogOpen := True;
end;
WriteLn(ExceptionLog, FormatDateTime('yyyy-mm-dd hh:nn:ss.zzz', Now),
' EXCEPTION in ', Context, ': ', E.ClassName, ' - ', E.Message);
Flush(ExceptionLog);
end;
type
PMyStatusLine = ^TMyStatusLine;
TMyStatusLine = object(TStatusLine)
function Hint(AHelpCtx: Word): ShortString; virtual;
end;
PMyApp = ^TMyApp;
TMyApp = object(TApplication)
CalendarDateLabel: PStaticText; { Reference for calendar demo }
constructor Init;
procedure InitMenuBar; virtual;
procedure InitStatusLine; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
procedure Idle; virtual;
procedure NewWindow;
procedure TestWindow1;
procedure TestWindow2;
procedure TestDialog;
procedure TestScroller;
procedure TestMsgBox;
procedure TestInputBox;
procedure TestFileOpen;
procedure TestChDir;
procedure TestColoredText;
procedure TestInputLong;
procedure TestAsciiChart;
procedure TestTimedDlg;
procedure TestTabs;
procedure TestStatuses;
procedure TestColors;
procedure TestOutline;
procedure TestEditor;
procedure TestEditorFind;
procedure TestEditorFile;
procedure TestEditorClipboard;
procedure TestCalendar;
procedure TestCalendarBroadcast;
procedure OnCalendarDateSelect(Calendar: PCalendarView);
end;
{ Custom window for calendar that handles broadcast }
PCalendarWindow = ^TCalendarWindow;
TCalendarWindow = object(TWindow)
DateLabel: PStaticText;
constructor Init(var Bounds: TRect);
procedure HandleEvent(var Event: TEvent); virtual;
end;
{ Custom scroller that displays numbered lines }
PTextScroller = ^TTextScroller;
TTextScroller = object(TScroller)
constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
procedure Draw; virtual;
end;
PMyWindow = ^TMyWindow;
TMyWindow = object(TWindow)
constructor Init(var Bounds: TRect; ATitle: ShortString; ANumber: Integer);
end;
{ Custom dialog for testing dynamic tab add/remove }
PTabTestDialog = ^TTabTestDialog;
TTabTestDialog = object(TDialog)
TabCtrl: PTab;
TabCounter: Integer;
constructor Init(var Bounds: TRect; ATitle: ShortString);
procedure HandleEvent(var Event: TEvent); virtual;
procedure AddNewTab;
procedure RemoveCurrentTab;
end;
var
MyApp: TMyApp;
WindowCount: Integer;
function TMyStatusLine.Hint(AHelpCtx: Word): ShortString;
begin
Result := ShortString(FormatDateTime('hh:nn:ss', Now));
end;
constructor TMyWindow.Init(var Bounds: TRect; ATitle: ShortString; ANumber: Integer);
begin
inherited Init(Bounds, ATitle, ANumber);
Options := Options or ofTileable;
end;
{ TCalendarWindow - demonstrates broadcast handling }
constructor TCalendarWindow.Init(var Bounds: TRect);
var
R: TRect;
CalView: PCalendarView;
Y, M, D: Word;
S: ShortString;
begin
inherited Init(Bounds, 'Calendar (Broadcast)', wnNoNumber);
Options := Options or ofTileable;
Flags := Flags and not (wfGrow or wfZoom);
{ Add the calendar view }
R.Assign(2, 1, 24, 9);
CalView := New(PCalendarView, Init(R));
CalView^.SetFirstDayOfWeek(1);
CalView^.SetDayColor(0, 5);
CalView^.SetDayColor(6, 5);
Insert(CalView);
{ Add label to show selected date }
CalView^.GetDate(Y, M, D);
S := ShortString(Format('Selected: %d/%d/%d', [M, D, Y]));
R.Assign(2, 10, 26, 11);
DateLabel := New(PStaticText, Init(R, S));
Insert(DateLabel);
{ Instructions }
R.Assign(2, 9, 26, 10);
Insert(New(PStaticText, Init(R, 'Using broadcast message')));
CalView^.Select;
end;
procedure TCalendarWindow.HandleEvent(var Event: TEvent);
var
Cal: PCalendarView;
Y, M, D: Word;
S: ShortString;
begin
inherited HandleEvent(Event);
{ Handle calendar date selection broadcast }
if (Event.What = evBroadcast) and (Event.Command = cmCalendarDateSelected) then begin
Cal := PCalendarView(Event.InfoPtr);
if (Cal <> nil) and (DateLabel <> nil) then begin
Cal^.GetDate(Y, M, D);
S := ShortString(Format('Selected: %d/%d/%d', [M, D, Y]));
if DateLabel^.Text <> nil then
DisposeStr(DateLabel^.Text);
DateLabel^.Text := NewStr(S);
DateLabel^.DrawView;
end;
ClearEvent(Event);
end;
end;
{ TTabTestDialog }
constructor TTabTestDialog.Init(var Bounds: TRect; ATitle: ShortString);
begin
inherited Init(Bounds, ATitle);
TabCtrl := nil;
TabCounter := 3; { We start with 3 tabs }
end;
procedure TTabTestDialog.HandleEvent(var Event: TEvent);
begin
inherited HandleEvent(Event);
if Event.What = evCommand then begin
case Event.Command of
cmAddTab: begin
AddNewTab;
ClearEvent(Event);
end;
cmRemoveTab: begin
RemoveCurrentTab;
ClearEvent(Event);
end;
end;
end;
end;
procedure TTabTestDialog.AddNewTab;
var
R: TRect;
NewInput: PInputLine;
TabDef: PTabDef;
begin
if TabCtrl = nil then Exit;
Inc(TabCounter);
{ Create a new input line for the new tab }
R.Assign(2, 4, 50, 5);
NewInput := New(PInputLine, Init(R, 40));
{ Create the tab definition using Tabs.NewTabDef function }
TabDef := Tabs.NewTabDef('Tab ~' + ShortString(IntToStr(TabCounter)) + '~', NewInput,
Tabs.NewTabItem(NewInput, nil), nil);
{ Add it to the tab control }
TabCtrl^.AddTab(TabDef);
end;
procedure TTabTestDialog.RemoveCurrentTab;
begin
if TabCtrl = nil then Exit;
if TabCtrl^.TabCount > 1 then begin
TabCtrl^.RemoveTab(TabCtrl^.ActiveDef);
Dec(TabCounter);
end;
end;
{ TTextScroller - displays 100 lines of text for scrolling test }
constructor TTextScroller.Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar);
begin
inherited Init(Bounds, AHScrollBar, AVScrollBar);
Options := Options or ofFirstClick;
SetLimit(80, 100); { 80 columns, 100 lines }
GrowMode := gfGrowHiX + gfGrowHiY;
end;
procedure TTextScroller.Draw;
var
B: TDrawBuffer;
C: Byte;
I, J: Integer;
S: ShortString;
begin
C := GetColor(1); { Normal color }
for I := 0 to Size.Y - 1 do begin
MoveChar(B, ' ', C, Size.X);
J := Delta.Y + I;
if J < Limit.Y then begin
S := ShortString(Format('Line %3d: ', [J + 1]));
{ Add some content to show horizontal scrolling }
S := S + 'The quick brown fox jumps over the lazy dog. ABCDEFGHIJKLMNOP';
if Delta.X < Length(S) then begin
MoveStr(B, Copy(S, Delta.X + 1, Size.X), C);
end;
end;
WriteLine(0, I, Size.X, 1, B);
end;
end;
constructor TMyApp.Init;
var
R: TRect;
begin
inherited Init;
CalendarDateLabel := nil;
{ Add Clock view at top right of desktop }
if Desktop <> nil then begin
Desktop^.GetExtent(R);
R.A.X := R.B.X - 10;
R.A.Y := 0;
R.B.Y := 1;
ClockView := New(PClockView, Init(R));
Desktop^.Insert(ClockView);
{ Add Heap view below clock }
Desktop^.GetExtent(R);
R.A.X := R.B.X - 12;
R.B.X := R.B.X - 1;
R.A.Y := 1;
R.B.Y := 2;
HeapView := New(PHeapView, InitKb(R));
Desktop^.Insert(HeapView);
end;
end;
procedure TMyApp.InitMenuBar;
var
R: TRect;
begin
GetExtent(R);
R.B.Y := R.A.Y + 1;
MenuBar := New(PMenuBar, Init(R, NewMenu(
NewSubMenu('~F~ile', hcNoContext, NewMenu(
NewItem('~N~ew', 'F4', kbF4, cmNewWindow, hcNoContext,
NewItem('~O~pen...', 'F3', kbF3, cmTestFileOpen, hcNoContext,
NewItem('Change ~D~ir...', '', kbNoKey, cmTestChDir, hcNoContext,
NewLine(
NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext, nil)))))),
NewSubMenu('~T~est', hcNoContext, NewMenu(
NewItem('Window ~1~ (Input+Radio)', '', kbNoKey, cmTestWindow1, hcNoContext,
NewItem('Window ~2~ (Checkboxes)', '', kbNoKey, cmTestWindow2, hcNoContext,
NewItem('Test ~D~ialog (Full)', '', kbNoKey, cmTestDialog, hcNoContext,
NewItem('~S~croller Test', '', kbNoKey, cmTestScroller, hcNoContext,
NewLine(
NewItem('~M~essageBox Test', '', kbNoKey, cmTestMsgBox, hcNoContext,
NewItem('~I~nputBox Test', '', kbNoKey, cmTestInputBox, hcNoContext,
NewLine(
NewItem('~C~olored Text', '', kbNoKey, cmTestColoredText, hcNoContext,
NewItem('Input~L~ong', '', kbNoKey, cmTestInputLong, hcNoContext,
NewItem('~A~SCII Chart', '', kbNoKey, cmTestAsciiChart, hcNoContext,
NewItem('~T~imed Dialog', '', kbNoKey, cmTestTimedDlg, hcNoContext,
NewItem('Ta~b~s', '', kbNoKey, cmTestTabs, hcNoContext,
NewItem('~S~tatuses', '', kbNoKey, cmTestStatuses, hcNoContext,
NewItem('~C~olors', '', kbNoKey, cmTestColors, hcNoContext,
NewItem('~O~utline', '', kbNoKey, cmTestOutline, hcNoContext,
NewSubMenu('Ca~l~endar', hcNoContext, NewMenu(
NewItem('~C~allback', '', kbNoKey, cmTestCalendar, hcNoContext,
NewItem('~B~roadcast', '', kbNoKey, cmTestCalendarBroadcast, hcNoContext,
nil))),
NewSubMenu('~E~ditor', hcNoContext, NewMenu(
NewItem('~N~ew Editor', '', kbNoKey, cmTestEditor, hcNoContext,
NewItem('~F~ind/Replace', '', kbNoKey, cmTestEditorFind, hcNoContext,
NewItem('File ~L~oad/Save', '', kbNoKey, cmTestEditorFile, hcNoContext,
NewItem('~C~lipboard', '', kbNoKey, cmTestEditorClipboard, hcNoContext,
nil))))),
nil))))))))))))))))))),
NewSubMenu('~W~indow', hcNoContext, NewMenu(
NewItem('~T~ile', '', kbNoKey, cmTile, hcNoContext,
NewItem('Tile ~H~orizontal', '', kbNoKey, cmTileHorizontal, hcNoContext,
NewItem('Tile ~V~ertical', '', kbNoKey, cmTileVertical, hcNoContext,
NewItem('C~a~scade', '', kbNoKey, cmCascade, hcNoContext,
NewItem('Cascade (~K~eep Size)', '', kbNoKey, cmCascadeNoResize, hcNoContext,
NewLine(
NewItem('~N~ext', 'F6', kbF6, cmNext, hcNoContext,
NewItem('~P~revious', 'Shift-F6', kbShiftF6, cmPrev, hcNoContext,
NewLine(
NewItem('~C~lose', 'Alt-F3', kbAltF3, cmClose, hcNoContext,
NewItem('Close ~A~ll', '', kbNoKey, cmCloseAll, hcNoContext, nil)))))))))))),
nil))))));
end;
procedure TMyApp.InitStatusLine;
var
R: TRect;
begin
GetExtent(R);
R.A.Y := R.B.Y - 1;
StatusLine := New(PMyStatusLine, Init(R,
NewStatusDef(0, $FFFF,
NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
NewStatusKey('~F4~ New', kbF4, cmNewWindow,
NewStatusKey('~F10~ Menu', kbF10, cmMenu,
NewStatusKey('~Alt-F3~ Close', kbAltF3, cmClose, nil)))), nil)));
end;
procedure TMyApp.HandleEvent(var Event: TEvent);
begin
try
inherited HandleEvent(Event);
if Event.What = evCommand then begin
case Event.Command of
cmNewWindow: NewWindow;
cmTestWindow1: TestWindow1;
cmTestWindow2: TestWindow2;
cmTestDialog: TestDialog;
cmTestScroller: TestScroller;
cmTestMsgBox: TestMsgBox;
cmTestInputBox: TestInputBox;
cmTestFileOpen: TestFileOpen;
cmTestChDir: TestChDir;
cmTestColoredText: TestColoredText;
cmTestInputLong: TestInputLong;
cmTestAsciiChart: TestAsciiChart;
cmTestTimedDlg: TestTimedDlg;
cmTestTabs: TestTabs;
cmTestStatuses: TestStatuses;
cmTestColors: TestColors;
cmTestOutline: TestOutline;
cmTestEditor: TestEditor;
cmTestEditorFind: TestEditorFind;
cmTestEditorFile: TestEditorFile;
cmTestEditorClipboard: TestEditorClipboard;
cmTestCalendar: TestCalendar;
cmTestCalendarBroadcast: TestCalendarBroadcast;
else
Exit;
end;
ClearEvent(Event);
end;
except
on E: Exception do LogException('TMyApp.HandleEvent', E);
end;
end;
procedure TMyApp.Idle;
var
Hour, Min, Sec, MSec: Word;
begin
try
Inc(IdleCounter);
DecodeTime(Now, Hour, Min, Sec, MSec);
if Sec <> LastSecond then begin
LastSecond := Sec;
if StatusLine <> nil then begin
StatusLine^.DrawView;
end;
end;
{ Update gadgets }
if ClockView <> nil then ClockView^.Update;
if HeapView <> nil then HeapView^.Update;
inherited Idle;
except
on E: Exception do LogException('TMyApp.Idle', E);
end;
end;
procedure TMyApp.NewWindow;
var
R: TRect;
Win: PMyWindow;
begin
Inc(WindowCount);
R.Assign(0, 0, 40, 12);
R.Move((WindowCount mod 5) * 2, (WindowCount mod 5));
Win := New(PMyWindow, Init(R, 'Window ' + ShortString(IntToStr(WindowCount)), WindowCount));
if Desktop <> nil then Desktop^.Insert(Win);
end;
procedure TMyApp.TestWindow1;
{ Window with input line, radio buttons, static text }
var
R: TRect;
Win: PWindow;
begin
R.Assign(5, 2, 40, 16);
Win := New(PWindow, Init(R, 'Test Window 1', wnNoNumber));
if Win <> nil then begin
Win^.Options := Win^.Options or ofTileable;
{ Input line }
R.Assign(3, 2, 30, 3);
Win^.Insert(New(PStaticText, Init(R, 'Enter your name:')));
R.Assign(3, 3, 30, 4);
Win^.Insert(New(PInputLine, Init(R, 50)));
{ Radio buttons }
R.Assign(3, 5, 20, 6);
Win^.Insert(New(PStaticText, Init(R, 'Select option:')));
R.Assign(3, 6, 25, 9);
Win^.Insert(New(PRadioButtons, Init(R,
NewSItem('Option ~A~',
NewSItem('Option ~B~',
NewSItem('Option ~C~', nil))))));
{ Static text }
R.Assign(3, 10, 32, 12);
Win^.Insert(New(PStaticText, Init(R,
'This is a test window with input line and radio buttons.')));
Desktop^.Insert(Win);
end;
end;
procedure TMyApp.TestWindow2;
{ Window with checkboxes }
var
R: TRect;
Win: PWindow;
begin
R.Assign(10, 2, 45, 18); { Made window taller: 16 rows }
Win := New(PWindow, Init(R, 'Test Window 2', wnNoNumber));
if Win <> nil then begin
Win^.Options := Win^.Options or ofTileable;
{ Checkboxes }
R.Assign(2, 1, 25, 2);
Win^.Insert(New(PStaticText, Init(R, 'Select features:')));
R.Assign(2, 2, 32, 7); { 5 items need 5 rows }
Win^.Insert(New(PCheckBoxes, Init(R,
NewSItem('~E~nable logging',
NewSItem('~S~how warnings',
NewSItem('~A~uto-save',
NewSItem('~D~ebug mode',
NewSItem('~V~erbose output', nil))))))));
{ Another group of checkboxes }
R.Assign(2, 8, 25, 9);
Win^.Insert(New(PStaticText, Init(R, 'Display options:')));
R.Assign(2, 9, 32, 12); { 3 items need 3 rows }
Win^.Insert(New(PCheckBoxes, Init(R,
NewSItem('Show ~t~oolbar',
NewSItem('Show status~b~ar',
NewSItem('~F~ull screen', nil))))));
Desktop^.Insert(Win);
end;
end;
procedure TMyApp.TestDialog;
{ Full dialog with buttons, listbox, input, checkboxes }
var
R: TRect;
Dlg: PDialog;
ScrollBar: PScrollBar;
ListBox: PListBox;
List: PStringCollection;
begin
R.Assign(5, 2, 70, 22);
Dlg := New(PDialog, Init(R, 'Test Dialog'));
if Dlg <> nil then begin
{ Input line with label }
R.Assign(3, 2, 30, 3);
Dlg^.Insert(New(PStaticText, Init(R, 'Name:')));
R.Assign(10, 2, 35, 3);
Dlg^.Insert(New(PInputLine, Init(R, 80)));
{ Another input line }
R.Assign(3, 4, 30, 5);
Dlg^.Insert(New(PStaticText, Init(R, 'Value:')));
R.Assign(10, 4, 35, 5);
Dlg^.Insert(New(PInputLine, Init(R, 80)));
{ Checkboxes }
R.Assign(3, 6, 30, 10);
Dlg^.Insert(New(PCheckBoxes, Init(R,
NewSItem('Check ~1~',
NewSItem('Check ~2~',
NewSItem('Check ~3~', nil))))));
{ Radio buttons }
R.Assign(3, 11, 30, 15);
Dlg^.Insert(New(PRadioButtons, Init(R,
NewSItem('Radio ~A~',
NewSItem('Radio ~B~',
NewSItem('Radio ~C~', nil))))));
{ Scrollbar for listbox }
R.Assign(58, 6, 59, 15);
ScrollBar := New(PScrollBar, Init(R));
Dlg^.Insert(ScrollBar);
{ Listbox }
R.Assign(38, 6, 58, 15);
ListBox := New(PListBox, Init(R, 1, ScrollBar));
Dlg^.Insert(ListBox);
{ Create string collection for listbox }
List := New(PStringCollection, Init(15, 5));
List^.Insert(NewStr('Apple'));
List^.Insert(NewStr('Banana'));
List^.Insert(NewStr('Cherry'));
List^.Insert(NewStr('Date'));
List^.Insert(NewStr('Elderberry'));
List^.Insert(NewStr('Fig'));
List^.Insert(NewStr('Grape'));
List^.Insert(NewStr('Honeydew'));
List^.Insert(NewStr('Kiwi'));
List^.Insert(NewStr('Lemon'));
List^.Insert(NewStr('Mango'));
List^.Insert(NewStr('Nectarine'));
List^.Insert(NewStr('Orange'));
List^.Insert(NewStr('Papaya'));
List^.Insert(NewStr('Quince'));
ListBox^.NewList(List);
{ Buttons }
R.Assign(10, 16, 22, 18);
Dlg^.Insert(New(PButton, Init(R, '~O~K', cmOK, bfDefault)));
R.Assign(26, 16, 38, 18);
Dlg^.Insert(New(PButton, Init(R, '~C~ancel', cmCancel, bfNormal)));
R.Assign(42, 16, 54, 18);
Dlg^.Insert(New(PButton, Init(R, '~H~elp', cmHelp, bfNormal)));
{ Execute as modal dialog }
Desktop^.ExecView(Dlg);
Dispose(Dlg, Done);
end;
end;
procedure TMyApp.TestScroller;
{ Window with scrollable content to test TScroller and scrollbars }
var
R: TRect;
Win: PWindow;
Scroller: PTextScroller;
HScrollBar, VScrollBar: PScrollBar;
begin
R.Assign(5, 2, 55, 20);
Win := New(PWindow, Init(R, 'Scroller Test', wnNoNumber));
if Win <> nil then begin
Win^.Options := Win^.Options or ofTileable;
{ Create vertical scrollbar - inside the frame }
Win^.GetExtent(R);
R.A.X := R.B.X - 2; { One column inside right border }
R.B.X := R.B.X - 1; { Width = 1 }
R.A.Y := 1; { Below title bar }
R.B.Y := R.B.Y - 2; { Above bottom border and horizontal scrollbar }
VScrollBar := New(PScrollBar, Init(R));
VScrollBar^.GrowMode := gfGrowLoX + gfGrowHiX + gfGrowHiY;
Win^.Insert(VScrollBar);
{ Create horizontal scrollbar - inside the frame }
Win^.GetExtent(R);
R.A.X := 1; { Inside left border }
R.B.X := R.B.X - 2; { Inside right border, before vertical scrollbar }
R.A.Y := R.B.Y - 2; { One row above bottom border }
R.B.Y := R.B.Y - 1; { Height = 1 }
HScrollBar := New(PScrollBar, Init(R));
HScrollBar^.GrowMode := gfGrowLoY + gfGrowHiY + gfGrowHiX;
Win^.Insert(HScrollBar);
{ Create the scroller interior }
Win^.GetExtent(R);
R.A.X := 1; { Inside left border }
R.A.Y := 1; { Below title bar }
R.B.X := R.B.X - 2; { Before vertical scrollbar }
R.B.Y := R.B.Y - 2; { Above horizontal scrollbar }
Scroller := New(PTextScroller, Init(R, HScrollBar, VScrollBar));
Win^.Insert(Scroller);
Desktop^.Insert(Win);
end;
end;
procedure TMyApp.TestMsgBox;
begin
{ Test Warning message }
MessageBox('This is a warning message.', nil, mfWarning + mfOKButton);
{ Test Error message with OK/Cancel }
MessageBox('An error has occurred!'#13#10'Do you want to continue?',
nil, mfError + mfOKCancel);
{ Test Information message }
MessageBox('This is an information message.'#13#10 +
'It can have multiple lines.', nil, mfInformation + mfOKButton);
{ Test Confirmation with Yes/No/Cancel }
MessageBox('Do you want to save changes before exiting?',
nil, mfConfirmation + mfYesNoCancel);
end;
procedure TMyApp.TestInputBox;
var
Result: Word;
UserInput: string;
begin
UserInput := 'Default Value';
Result := InputBox('Enter Value', '~V~alue:', UserInput, 50);
if Result = cmOK then
MessageBox('You entered: ' + UserInput, nil, mfInformation + mfOKButton)
else
MessageBox('Input was cancelled.', nil, mfInformation + mfOKButton);
end;
procedure TMyApp.TestFileOpen;
var
Dlg: PFileDialog;
FileName: PathStr;
C: Word;
begin
FileName := '';
try
Dlg := New(PFileDialog, Init('*.*', 'Open File', '~N~ame', fdOpenButton + fdHelpButton, 1));
except
on E: Exception do begin
LogException('TestFileOpen.Init', E);
Exit;
end;
end;
if Dlg <> nil then begin
try
C := Desktop^.ExecView(Dlg);
except
on E: Exception do begin
LogException('TestFileOpen.ExecView', E);
Dispose(Dlg, Done);
Exit;
end;
end;
if C <> cmCancel then begin
try
Dlg^.GetData(FileName);
except
on E: Exception do begin
LogException('TestFileOpen.GetData', E);
Dispose(Dlg, Done);
Exit;
end;
end;
end;
try
Dispose(Dlg, Done);
except
on E: Exception do begin
LogException('TestFileOpen.Dispose', E);
Exit;
end;
end;
if C = cmFileOpen then
MessageBox('Selected file: ' + FileName, nil, mfInformation + mfOKButton);
end;
end;
procedure TMyApp.TestChDir;
var
Dlg: PChDirDialog;
begin
Dlg := New(PChDirDialog, Init(cdNormal, 2));
if Dlg <> nil then begin
if ExecuteDialog(Dlg, nil) = cmOK then
MessageBox('Directory changed successfully.', nil, mfInformation + mfOKButton);
end;
end;
procedure TMyApp.TestColoredText;
{ Window with colored static text examples }
var
R: TRect;
Win: PWindow;
begin
R.Assign(5, 2, 50, 16);
Win := New(PWindow, Init(R, 'Colored Text Test', wnNoNumber));
if Win <> nil then begin
Win^.Options := Win^.Options or ofTileable;
{ Normal static text for comparison }
R.Assign(2, 1, 40, 2);
Win^.Insert(New(PStaticText, Init(R, 'Normal static text (palette color)')));
{ Red text on black: $04 = red foreground, black background }
R.Assign(2, 3, 40, 4);
Win^.Insert(New(PColoredText, Init(R, 'Red text on black background', $04)));
{ Yellow text on blue: $1E = blue bg (1), yellow fg (E) }
R.Assign(2, 5, 40, 6);
Win^.Insert(New(PColoredText, Init(R, 'Yellow text on blue background', $1E)));
{ White text on red: $4F = red bg (4), bright white fg (F) }
R.Assign(2, 7, 40, 8);
Win^.Insert(New(PColoredText, Init(R, 'White text on red background', $4F)));
{ Green text on black: $0A = green foreground }
R.Assign(2, 9, 40, 10);
Win^.Insert(New(PColoredText, Init(R, 'Bright green text', $0A)));
{ Cyan on black: $0B }
R.Assign(2, 11, 40, 12);
Win^.Insert(New(PColoredText, Init(R, 'Cyan colored text', $0B)));
Desktop^.Insert(Win);
end;
end;
procedure TMyApp.TestInputLong;
{ Dialog with TInputLong for numeric input }
var
R: TRect;
Dlg: PDialog;
InputLine: PInputLong;
Value: LongInt;
begin
R.Assign(10, 4, 60, 18);
Dlg := New(PDialog, Init(R, 'InputLong Test'));
if Dlg <> nil then begin
{ Label and input for positive number }
R.Assign(3, 2, 30, 3);
Dlg^.Insert(New(PStaticText, Init(R, 'Enter a number (0-1000):')));
R.Assign(3, 3, 20, 4);
InputLine := New(PInputLong, Init(R, 10, 0, 1000, 0));
Dlg^.Insert(InputLine);
{ Label and input for signed number }
R.Assign(3, 5, 35, 6);
Dlg^.Insert(New(PStaticText, Init(R, 'Enter signed (-100 to 100):')));
R.Assign(3, 6, 20, 7);
Dlg^.Insert(New(PInputLong, Init(R, 10, -100, 100, 0)));
{ Label and input for hex number }
R.Assign(3, 8, 35, 9);
Dlg^.Insert(New(PStaticText, Init(R, 'Enter hex ($0-$FF, use $):')));
R.Assign(3, 9, 20, 10);
Dlg^.Insert(New(PInputLong, Init(R, 10, 0, 255, ilHex or ilDisplayHex)));
{ Buttons }
R.Assign(10, 11, 22, 13);
Dlg^.Insert(New(PButton, Init(R, '~O~K', cmOK, bfDefault)));
R.Assign(26, 11, 38, 13);
Dlg^.Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
Dlg^.SelectNext(False);
{ Set initial value }
Value := 42;
InputLine^.SetData(Value);
if Desktop^.ExecView(Dlg) = cmOK then begin
InputLine^.GetData(Value);
MessageBox('First value entered: ' + IntToStr(Value), nil, mfInformation + mfOKButton);
end;
Dispose(Dlg, Done);
end;
end;
procedure TMyApp.TestAsciiChart;
{ Open ASCII Chart window }
var
Chart: PASCIIChart;
begin
Chart := New(PASCIIChart, Init);
if Chart <> nil then begin
{ Center the window }
Chart^.MoveTo(
(Desktop^.Size.X - Chart^.Size.X) div 2,
(Desktop^.Size.Y - Chart^.Size.Y) div 2);
Desktop^.Insert(Chart);
end;
end;
procedure TMyApp.TestTimedDlg;
{ Test timed message box that auto-closes after countdown }
begin
{ Show a timed message box that closes after 5 seconds }
TimedMessageBox(
'This message will close automatically in 5 seconds.'#13#10 +
'Or click a button to close it now.',
nil,
mfInformation + mfOKCancel,
5);
end;
procedure TMyApp.TestTabs;
{ Test tabbed dialog with multiple tabs and dynamic add/remove }
var
R: TRect;
Dlg: PTabTestDialog;
Tab: PTab;
Input1, Input2, Input3: PInputLine;
Check1: PCheckBoxes;
Radio1: PRadioButtons;
begin
R.Assign(5, 2, 65, 22); { Made taller for extra buttons }
Dlg := New(PTabTestDialog, Init(R, 'Tabbed Dialog Test'));
if Dlg <> nil then begin
{ Note: Inside TTab, content area starts at row 3 (after tab header) }
{ and column 1 (inside left border), ending at Size.X-2, Size.Y-2 }
{ Tab 1: General settings - views positioned relative to TTab origin }
{ Content area: rows 3-11, columns 1-52 }
R.Assign(2, 4, 50, 5); { Row 4 inside tab = visible in content area }
Input1 := New(PInputLine, Init(R, 40));
{ Tab 2: Advanced options }
R.Assign(2, 4, 50, 5);
Input2 := New(PInputLine, Init(R, 40));
R.Assign(2, 6, 40, 10);
Check1 := New(PCheckBoxes, Init(R,
NewSItem('~E~nable feature A',
NewSItem('~D~ebug mode',
NewSItem('~V~erbose logging', nil)))));
{ Tab 3: Display settings }
R.Assign(2, 4, 50, 5);
Input3 := New(PInputLine, Init(R, 40));
R.Assign(2, 6, 35, 10);
Radio1 := New(PRadioButtons, Init(R,
NewSItem('~S~mall',
NewSItem('~M~edium',
NewSItem('~L~arge', nil)))));
{ Create tab control with 3 tabs }
R.Assign(2, 1, 56, 14);
Tab := New(PTab, Init(R,
NewTabDef('~G~eneral', Input1,
NewTabItem(Input1, nil),
NewTabDef('~A~dvanced', Input2,
NewTabItem(Input2,
NewTabItem(Check1, nil)),
NewTabDef('~D~isplay', Input3,
NewTabItem(Input3,
NewTabItem(Radio1, nil)),
nil)))));
Dlg^.Insert(Tab);
Dlg^.TabCtrl := Tab; { Store reference for Add/Remove handlers }
{ Add Tab / Remove Tab buttons }
R.Assign(2, 15, 16, 17);
Dlg^.Insert(New(PButton, Init(R, '~+~ Add Tab', cmAddTab, bfNormal)));
R.Assign(18, 15, 36, 17);
Dlg^.Insert(New(PButton, Init(R, '~-~ Remove Tab', cmRemoveTab, bfNormal)));
{ OK / Cancel buttons }
R.Assign(38, 15, 48, 17);
Dlg^.Insert(New(PButton, Init(R, '~O~K', cmOK, bfDefault)));
R.Assign(50, 15, 58, 17);
Dlg^.Insert(New(PButton, Init(R, 'Cancel', cmCancel, bfNormal)));
{ Don't call SelectNext - Tab is already Current and should have focus }
{ Dlg^.SelectNext(False); }
Desktop^.ExecView(Dlg);
Dispose(Dlg, Done);
end;
end;
procedure TMyApp.TestStatuses;
{ Comprehensive test for Status/Gauge views from Statuses.pas }
var
R: TRect;
Dlg: PDialog;
BarGauge: PBarGauge;
PercentGauge: PPercentGauge;
ArrowGaugeR, ArrowGaugeL: PArrowGauge;
SpinnerGauge: PSpinnerGauge;
UpdateBtn, ResetBtn: PButton;
Event: TEvent;
Finished: Boolean;
begin
{ Create a dialog to hold all the gauge types }
R.Assign(10, 3, 70, 22);
Dlg := New(PDialog, Init(R, 'Status/Gauge Demo'));
if Dlg = nil then Exit;
{ Label and Bar Gauge (progress bar with percentage) }
R.Assign(2, 2, 20, 3);
Dlg^.Insert(New(PStaticText, Init(R, 'Bar Gauge:')));
R.Assign(2, 3, 56, 4);
BarGauge := New(PBarGauge, Init(R, cmUpdateGauge, 0, 100));
BarGauge^.Current := 35;
Dlg^.Insert(BarGauge);
{ Label and Percent Gauge }
R.Assign(2, 5, 20, 6);
Dlg^.Insert(New(PStaticText, Init(R, 'Percent Gauge:')));
R.Assign(22, 5, 36, 6);
PercentGauge := New(PPercentGauge, Init(R, cmUpdateGauge, 0, 100));
PercentGauge^.Current := 35;
Dlg^.Insert(PercentGauge);
{ Label and Arrow Gauge (right-facing) }
R.Assign(2, 7, 25, 8);