-
Notifications
You must be signed in to change notification settings - Fork 2
/
DIALOGS.PAS
2693 lines (2428 loc) · 70.7 KB
/
DIALOGS.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
{/////////////////////////////////////////////////////////////////////////
//
// Dos Navigator Version 1.51 Copyright (C) 1991-99 RIT Research Labs
//
// This programs is free for commercial and non-commercial use as long as
// the following conditions are aheared to.
//
// Copyright remains RIT Research Labs, and as such any Copyright notices
// in the code are not to be removed. If this package is used in a
// product, RIT Research Labs should be given attribution as the RIT Research
// Labs of the parts of the library used. This can be in the form of a textual
// message at program startup or in documentation (online or textual)
// provided with the package.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the copyright
// notice, this list of conditions and the following disclaimer.
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// 3. All advertising materials mentioning features or use of this software
// must display the following acknowledgement:
// "Based on Dos Navigator by RIT Research Labs."
//
// THIS SOFTWARE IS PROVIDED BY RIT RESEARCH LABS "AS IS" AND ANY EXPRESS
// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
// GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
// IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// The licence and distribution terms for any publically available
// version or derivative of this code cannot be changed. i.e. this code
// cannot simply be copied and put under another distribution licence
// (including the GNU Public Licence).
//
//////////////////////////////////////////////////////////////////////////}
unit Dialogs;
{-----------------------------------------------------}
{ This module is based on Turbo Vision Dialogs Unit }
{ Copyright (c) 1990 by Borland International }
{-----------------------------------------------------}
interface
uses Objects, Drivers, Views, Scroller, Validate, ObjType;
const
{ Color palettes }
CGrayDialog = #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 +
#178#179;
CBlueDialog = #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#92#94#95;
CCyanDialog = #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;
CDialog = CGrayDialog;
CStaticText = #6;
CLabel = #7#8#9#9;
CButton = #10#11#12#13#14#34#33#15;
CCluster = #16#17#18#18#31;
CInputLine = #19#19#20#21;
CHistory = #22#23;
CHistoryWindow = #19#19#21#24#25#19#20;
CHistoryViewer = #6#6#7#6#6;
{ TDialog palette entires }
dpBlueDialog = 1;
dpCyanDialog = 2;
dpGrayDialog = 3;
{ TButton flags }
bfNormal = $00;
bfDefault = $01;
bfLeftJust = $02;
bfBroadcast = $04;
bfGrabFocus = $08;
{ TMultiCheckboxes flags }
{ hibyte = number of bits }
{ lobyte = bit mask }
cfOneBit = $0101;
cfTwoBits = $0203;
cfFourBits = $040F;
cfEightBits = $08FF;
type
{ TDialog object }
{ Palette layout }
{ 1 = Frame passive }
{ 2 = Frame active }
{ 3 = Frame icon }
{ 4 = ScrollBar page area }
{ 5 = ScrollBar controls }
{ 6 = StaticText }
{ 7 = Label normal }
{ 8 = Label selected }
{ 9 = Label shortcut }
{ 10 = Button normal }
{ 11 = Button default }
{ 12 = Button selected }
{ 13 = Button disabled }
{ 14 = Button shortcut }
{ 15 = Button shadow }
{ 16 = Cluster normal }
{ 17 = Cluster selected }
{ 18 = Cluster shortcut }
{ 19 = InputLine normal text }
{ 20 = InputLine selected text }
{ 21 = InputLine arrows }
{ 22 = History arrow }
{ 23 = History sides }
{ 24 = HistoryWindow scrollbar page area }
{ 25 = HistoryWindow scrollbar controls }
{ 26 = ListViewer normal }
{ 27 = ListViewer focused }
{ 28 = ListViewer selected }
{ 29 = ListViewer divider }
{ 30 = InfoPane }
{ 31 = Cluster disabled }
{ 32 = Reserved }
PDialog = ^TDialog;
TDialog = object(TWindow)
constructor Init(var Bounds: TRect; ATitle: TTitleStr);
constructor Load(var S: TStream);
function GetPalette: PPalette; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
function Valid(Command: Word): Boolean; virtual;
procedure StoreText(var F: Text); virtual;
end;
{ TSItem }
PSItem = ^TSItem;
TSItem = record
Value: PString;
Next: PSItem;
end;
{ TInputLine object }
{ Palette layout }
{ 1 = Passive }
{ 2 = Active }
{ 3 = Selected }
{ 4 = Arrows }
PInputLine = ^TInputLine;
TInputLine = object(TView)
Data: PString;
MaxLen: Integer;
CurPos: Integer;
FirstPos: Integer;
SelStart: Integer;
SelEnd: Integer;
Validator: PValidator;
DrawShift: Byte;
constructor Init(var Bounds: TRect; AMaxLen: Integer);
constructor Load(var S: TStream);
destructor Done; virtual;
function DataSize: Word; virtual;
procedure Draw; virtual;
procedure GetData(var Rec); virtual;
function GetPalette: PPalette; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
procedure SelectAll(Enable: Boolean);
procedure SetData(var Rec); virtual;
procedure SetState(AState: Word; Enable: Boolean); virtual;
procedure SetValidator(AValid: PValidator);
procedure Store(var S: TStream);
function Valid(Command: Word): Boolean; virtual;
procedure StoreText(var F: Text); virtual;
private
function CanScroll(Delta: Integer): Boolean;
end;
PHexLine = ^THexLine;
THexLine = object(TView)
InputLine: PInputLine;
DeltaX, CurX: Integer;
Sec: Boolean;
constructor Init(R: TRect; AInputLine: PInputLine);
procedure HandleEvent(var Event: TEvent); virtual;
procedure Draw; virtual;
end;
{ TButton object }
{ Palette layout }
{ 1 = Normal text }
{ 2 = Default text }
{ 3 = Selected text }
{ 4 = Disabled text }
{ 5 = Normal shortcut }
{ 6 = Default shortcut }
{ 7 = Selected shortcut }
{ 8 = Shadow }
PButton = ^TButton;
TButton = object(TView)
Title: PString;
Command: Word;
Flags: Byte;
AmDefault: Boolean;
constructor Init(var Bounds: TRect; ATitle: TTitleStr; ACommand: Word;
AFlags: Word);
constructor Load(var S: TStream);
destructor Done; virtual;
procedure Draw; virtual;
procedure DrawState(Down: Boolean);
function GetPalette: PPalette; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
procedure MakeDefault(Enable: Boolean);
procedure Press; virtual;
procedure SetState(AState: Word; Enable: Boolean); virtual;
procedure Store(var S: TStream);
procedure StoreText(var F: Text); virtual;
end;
{ TCluster }
{ Palette layout }
{ 1 = Normal text }
{ 2 = Selected text }
{ 3 = Normal shortcut }
{ 4 = Selected shortcut }
{ 5 = Disabled text }
PCluster = ^TCluster;
TCluster = object(TView)
Value: LongInt;
Sel: Integer;
EnableMask: LongInt;
Strings: TStringCollection;
constructor Init(var Bounds: TRect; AStrings: PSItem);
constructor Load(var S: TStream);
destructor Done; virtual;
function ButtonState(Item: Integer): Boolean;
function DataSize: Word; virtual;
procedure DrawBox(const Icon: String; Marker: Char);
procedure DrawMultiBox(const Icon, Marker: String);
procedure GetData(var Rec); virtual;
function GetHelpCtx: Word; virtual;
function GetPalette: PPalette; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
function Mark(Item: Integer): Boolean; virtual;
function MultiMark(Item: Integer): Byte; virtual;
procedure Press(Item: Integer); virtual;
procedure MovedTo(Item: Integer); virtual;
procedure SetButtonState(AMask: Longint; Enable: Boolean);
procedure SetData(var Rec); virtual;
procedure SetState(AState: Word; Enable: Boolean); virtual;
procedure Store(var S: TStream);
private
function Column(Item: Integer): Integer;
function FindSel(P: TPoint): Integer;
function Row(Item: Integer): Integer;
end;
{ TRadioButtons }
{ Palette layout }
{ 1 = Normal text }
{ 2 = Selected text }
{ 3 = Normal shortcut }
{ 4 = Selected shortcut }
PRadioButtons = ^TRadioButtons;
TRadioButtons = object(TCluster)
procedure Draw; virtual;
function Mark(Item: Integer): Boolean; virtual;
procedure MovedTo(Item: Integer); virtual;
procedure Press(Item: Integer); virtual;
procedure SetData(var Rec); virtual;
procedure StoreText(var F: Text); virtual;
end;
{ TCheckBoxes }
{ Palette layout }
{ 1 = Normal text }
{ 2 = Selected text }
{ 3 = Normal shortcut }
{ 4 = Selected shortcut }
PCheckBoxes = ^TCheckBoxes;
TCheckBoxes = object(TCluster)
procedure Draw; virtual;
function Mark(Item: Integer): Boolean; virtual;
procedure Press(Item: Integer); virtual;
procedure StoreText(var F: Text); virtual;
end;
{ TMultiCheckBoxes }
{ Palette layout }
{ 1 = Normal text }
{ 2 = Selected text }
{ 3 = Normal shortcut }
{ 4 = Selected shortcut }
PMultiCheckBoxes = ^TMultiCheckBoxes;
TMultiCheckBoxes = object(TCluster)
SelRange: Byte;
Flags: Word;
States: PString;
constructor Init(var Bounds: TRect; AStrings: PSItem;
ASelRange: Byte; AFlags: Word; const AStates: String);
constructor Load(var S: TStream);
destructor Done; virtual;
function DataSize: Word; virtual;
procedure Draw; virtual;
procedure GetData(var Rec); virtual;
function MultiMark(Item: Integer): Byte; virtual;
procedure Press(Item: Integer); virtual;
procedure SetData(var Rec); virtual;
procedure Store(var S: TStream);
end;
{ TListBox }
{ Palette layout }
{ 1 = Active }
{ 2 = Inactive }
{ 3 = Focused }
{ 4 = Selected }
{ 5 = Divider }
PListBox = ^TListBox;
TListBox = object(TListViewer)
List: PCollection;
constructor Init(var Bounds: TRect; ANumCols: Word;
AScrollBar: PScrollBar);
constructor Load(var S: TStream);
function DataSize: Word; virtual;
procedure GetData(var Rec); virtual;
function GetText(Item: Integer; MaxLen: Integer): String; virtual;
procedure NewList(AList: PCollection); virtual;
procedure SetData(var Rec); virtual;
procedure Store(var S: TStream);
procedure StoreText(var F: Text); virtual;
end;
{ TStaticText }
{ Palette layout }
{ 1 = Text }
PStaticText = ^TStaticText;
TStaticText = object(TView)
Text: PString;
constructor Init(var Bounds: TRect; const AText: String);
constructor Load(var S: TStream);
destructor Done; virtual;
procedure Draw; virtual;
function GetPalette: PPalette; virtual;
procedure GetText(var S: String); virtual;
procedure Store(var S: TStream);
procedure StoreText(var F: Text); virtual;
end;
{ TParamText }
{ Palette layout }
{ 1 = Text }
PParamText = ^TParamText;
TParamText = object(TStaticText)
ParamCount: Integer;
ParamList: Pointer;
constructor Init(var Bounds: TRect; const AText: String;
AParamCount: Integer);
constructor Load(var S: TStream);
function DataSize: Word; virtual;
procedure GetText(var S: String); virtual;
procedure SetData(var Rec); virtual;
procedure Store(var S: TStream);
end;
{ TLabel }
{ Palette layout }
{ 1 = Normal text }
{ 2 = Selected text }
{ 3 = Normal shortcut }
{ 4 = Selected shortcut }
PLabel = ^TLabel;
TLabel = object(TStaticText)
Link: PView;
Light: Boolean;
constructor Init(var Bounds: TRect; const AText: String; ALink: PView);
constructor Load(var S: TStream);
procedure Draw; virtual;
function GetPalette: PPalette; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
procedure Store(var S: TStream);
procedure StoreText(var F: Text); virtual;
end;
{ THistoryViewer }
{ Palette layout }
{ 1 = Active }
{ 2 = Inactive }
{ 3 = Focused }
{ 4 = Selected }
{ 5 = Divider }
PHistoryViewer = ^THistoryViewer;
THistoryViewer = object(TListViewer)
HistoryId: Word;
constructor Init(var Bounds: TRect; AHScrollBar, AVScrollBar: PScrollBar;
AHistoryId: Word);
function GetPalette: PPalette; virtual;
function GetText(Item: Integer; MaxLen: Integer): String; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
function HistoryWidth: Integer;
end;
{ THistoryWindow }
{ Palette layout }
{ 1 = Frame passive }
{ 2 = Frame active }
{ 3 = Frame icon }
{ 4 = ScrollBar page area }
{ 5 = ScrollBar controls }
{ 6 = HistoryViewer normal text }
{ 7 = HistoryViewer selected text }
PHistoryWindow = ^THistoryWindow;
THistoryWindow = object(TWindow)
Viewer: PListViewer;
constructor Init(var Bounds: TRect; HistoryId: Word);
function GetPalette: PPalette; virtual;
function GetSelection: String; virtual;
procedure InitViewer(HistoryId: Word); virtual;
end;
{ THistory }
{ Palette layout }
{ 1 = Arrow }
{ 2 = Sides }
PHistory = ^THistory;
THistory = object(TView)
Link: PInputLine;
HistoryId: Word;
constructor Init(var Bounds: TRect; ALink: PInputLine; AHistoryId: Word);
constructor Load(var S: TStream);
procedure Draw; virtual;
function GetPalette: PPalette; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
function InitHistoryWindow(var Bounds: TRect): PHistoryWindow; virtual;
procedure RecordHistory(const S: String); virtual;
procedure Store(var S: TStream);
procedure StoreText(var F: Text); virtual;
end;
{ SItem routines }
function NewSItem(const Str: String; ANext: PSItem): PSItem;
{ Dialogs registration procedure }
{procedure RegisterDialogs;}
{ Stream Registration Records }
const
RDialog: TStreamRec = (
ObjType: otDialog;
VmtLink: Ofs(TypeOf(TDialog)^);
Load: @TDialog.Load;
Store: @TDialog.Store
);
const
RInputLine: TStreamRec = (
ObjType: otInputLine;
VmtLink: Ofs(TypeOf(TInputLine)^);
Load: @TInputLine.Load;
Store: @TInputLine.Store
);
const
RButton: TStreamRec = (
ObjType: otButton;
VmtLink: Ofs(TypeOf(TButton)^);
Load: @TButton.Load;
Store: @TButton.Store
);
const
RCluster: TStreamRec = (
ObjType: otCluster;
VmtLink: Ofs(TypeOf(TCluster)^);
Load: @TCluster.Load;
Store: @TCluster.Store
);
const
RRadioButtons: TStreamRec = (
ObjType: otRadioButtons;
VmtLink: Ofs(TypeOf(TRadioButtons)^);
Load: @TRadioButtons.Load;
Store: @TRadioButtons.Store
);
const
RCheckBoxes: TStreamRec = (
ObjType: otCheckBoxes;
VmtLink: Ofs(TypeOf(TCheckBoxes)^);
Load: @TCheckBoxes.Load;
Store: @TCheckBoxes.Store
);
const
RMultiCheckBoxes: TStreamRec = (
ObjType: otMultiCheckBoxes;
VmtLink: Ofs(TypeOf(TMultiCheckBoxes)^);
Load: @TMultiCheckBoxes.Load;
Store: @TMultiCheckBoxes.Store
);
const
RListBox: TStreamRec = (
ObjType: otListBox;
VmtLink: Ofs(TypeOf(TListBox)^);
Load: @TListBox.Load;
Store: @TListBox.Store
);
const
RStaticText: TStreamRec = (
ObjType: otStaticText;
VmtLink: Ofs(TypeOf(TStaticText)^);
Load: @TStaticText.Load;
Store: @TStaticText.Store
);
const
RLabel: TStreamRec = (
ObjType: otLabel;
VmtLink: Ofs(TypeOf(TLabel)^);
Load: @TLabel.Load;
Store: @TLabel.Store
);
const
RHistory: TStreamRec = (
ObjType: otHistory;
VmtLink: Ofs(TypeOf(THistory)^);
Load: @THistory.Load;
Store: @THistory.Store
);
const
RParamText: TStreamRec = (
ObjType: otParamText;
VmtLink: Ofs(TypeOf(TParamText)^);
Load: @TParamText.Load;
Store: @TParamText.Store
);
const
{ Dialog broadcast commands }
cmRecordHistory = 60;
implementation
uses AsciiTab, HistList, Advance, Commands, Startup, xTime;
const
{ TButton messages }
cmGrabDefault = 61;
cmReleaseDefault = 62;
cmPutInClipboard = 11027;
cmGetFromClipboard= 11028;
{ Utility functions }
function IsBlank(Ch: Char): Boolean;
begin
IsBlank := (Ch = ' ') or (Ch = #13) or (Ch = #10);
end;
{ TDialog }
constructor TDialog.Init(var Bounds: TRect; ATitle: TTitleStr);
begin
inherited Init(Bounds, ATitle, wnNoNumber);
Options := Options or ofVersion20;
GrowMode := 0;
Flags := wfMove + wfClose;
Palette := dpGrayDialog;
end;
constructor TDialog.Load(var S: TStream);
begin
inherited Load(S);
if Options and ofVersion = ofVersion10 then
begin
Palette := dpGrayDialog;
Inc(Options, ofVersion20);
end;
end;
function TDialog.GetPalette: PPalette;
const
P: array[dpBlueDialog..dpGrayDialog] of string[Length(CDialog)] =
(CBlueDialog, CCyanDialog, CGrayDialog);
begin
GetPalette := @P[Palette];
end;
procedure TDialog.HandleEvent(var Event: TEvent);
begin
TWindow.HandleEvent(Event);
case Event.What of
evMouseDown: if GetState(sfModal) and (Event.Buttons and mbRightButton <> 0) then
begin
Event.What := evBroadcast;
Event.Command := cmDefault;
Event.InfoPtr := nil;
PutEvent(Event);
ClearEvent(Event);
end;
evKeyDown:
case Event.KeyCode of
kbEsc:
begin
Event.What := evCommand;
Event.Command := cmCancel;
Event.InfoPtr := nil;
PutEvent(Event);
ClearEvent(Event);
end;
kbEnter:
begin
Event.What := evBroadcast;
Event.Command := cmDefault;
Event.InfoPtr := nil;
PutEvent(Event);
ClearEvent(Event);
end;
end;
evCommand:
case Event.Command of
cmOk, cmCancel, cmYes, cmNo, cmSkip:
if State and sfModal <> 0 then
begin
EndModal(Event.Command);
ClearEvent(Event);
end;
end;
end;
end;
function TDialog.Valid(Command: Word): Boolean;
begin
if Command = cmCancel then Valid := True
else Valid := TGroup.Valid(Command);
end;
function NewSItem(const Str: String; ANext: PSItem): PSItem;
var
Item: PSItem;
begin
New(Item);
Item^.Value := NewStr(Str);
Item^.Next := ANext;
NewSItem := Item;
end;
function Max(A, B: Integer): Integer;
inline(
$58/ {pop ax }
$5B/ {pop bx }
$3B/$C3/ {cmp ax,bx}
$7F/$01/ {jg @@1 }
$93); {xchg ax,bx}
{@@1: }
{ TInputLine }
constructor TInputLine.Init(var Bounds: TRect; AMaxLen: Integer);
begin
TView.Init(Bounds);
State := State or sfCursorVis;
if (InterfaceData.Options and ouiBlockInsertCursor <> 0) then BlockCursor;
Options := Options or (ofSelectable + ofFirstClick + ofVersion20);
GetMem(Data, AMaxLen + 1);
Data^ := '';
MaxLen := AMaxLen;
DrawShift := 1;
end;
constructor TInputLine.Load(var S: TStream);
begin
TView.Load(S);
DrawShift := 1;
S.Read(MaxLen, SizeOf(Integer) * 5);
GetMem(Data, MaxLen + 1);
S.Read(Data^[0], 1);
S.Read(Data^[1], Length(Data^));
if Options and ofVersion >= ofVersion20 then
Validator := PValidator(S.Get);
Options := Options or ofVersion20;
SetState(sfCursorIns, (InterfaceData.Options and ouiBlockInsertCursor <> 0));
end;
destructor TInputLine.Done;
begin
FreeMem(Data, MaxLen + 1);
SetValidator(nil);
TView.Done;
end;
function TInputLine.CanScroll(Delta: Integer): Boolean;
begin
if Delta < 0 then
CanScroll := FirstPos > 0 else
if Delta > 0 then
CanScroll := Length(Data^) - FirstPos + 2 > Size.X else
CanScroll := False;
end;
function TInputLine.DataSize: Word;
var
DSize: Word;
begin
DSize := 0;
if Validator <> nil then
DSize := Validator^.Transfer(Data^, nil, vtDataSize);
if DSize <> 0 then
DataSize := DSize
else
DataSize := MaxLen + 1;
end;
procedure TInputLine.Draw;
var
Color: Byte;
L, R: Integer;
B: TDrawBuffer;
S: String;
begin
if DrawShift = 0 then SelStart := SelEnd;
if State and sfFocused = 0 then
Color := GetColor(1) else
Color := GetColor(2);
MoveChar(B, ' ', Color, Size.X);
S := Copy(Data^, FirstPos + 1, Size.X - 2 * DrawShift);
MoveStr(B[DrawShift], S, Color);
if Options and ofSecurity <> 0 then MoveChar(B[DrawShift], 'þ', Color, Length(S));
if DrawShift > 0 then
begin
if CanScroll(1) then MoveChar(B[Size.X - 1], #16, GetColor(4), 1)
else MoveChar(B[Size.X - 1], #32, GetColor(4), 1);
MoveChar(B[0], #32, GetColor(4), 1);
end;
if State and sfSelected <> 0 then
begin
if (DrawShift > 0) and CanScroll(-1) then MoveChar(B[0], #17, GetColor(4), 1);
L := SelStart - FirstPos;
R := SelEnd - FirstPos;
if L < 0 then L := 0;
if R > Size.X - 2 * DrawShift then R := Size.X - 2 * DrawShift;
if L < R then MoveChar(B[L + 1], #0, GetColor(3), R - L);
end;
WriteLine(0, 0, Size.X, Size.Y, B);
SetCursor(CurPos - FirstPos + DrawShift, 0);
end;
procedure TInputLine.GetData(var Rec);
begin
if (Validator = nil) or
(Validator^.Transfer(Data^, @Rec, vtGetData) = 0) then
begin
FillChar(Rec, DataSize, #0);
Move(Data^, Rec, Length(Data^) + 1);
end;
end;
function TInputLine.GetPalette: PPalette;
const
P: String[Length(CInputLine)] = CInputLine;
begin
GetPalette := @P;
end;
procedure TInputLine.HandleEvent(var Event: TEvent);
const
PadKeys = [$47, $4B, $4D, $4F, $73, $74];
var
Delta, Anchor, I: Integer;
OldScanCode: Byte;
ExtendBlock: Boolean;
OldData: string;
OldCurPos, OldFirstPos,
OldSelStart, OldSelEnd: Integer;
S: String;
R: TRect;
function MouseDelta: Integer;
var
Mouse: TPoint;
begin
MakeLocal(Event.Where, Mouse);
if Mouse.X < DrawShift then MouseDelta := -1 else
if Mouse.X >= Size.X - DrawShift then MouseDelta := 1 else
MouseDelta := 0;
end;
function MousePos: Integer;
var
Pos: Integer;
Mouse: TPoint;
begin
MakeLocal(Event.Where, Mouse);
if Mouse.X < DrawShift then Mouse.X := DrawShift;
Pos := Mouse.X + FirstPos - DrawShift;
if Pos < 0 then Pos := 0;
if Pos > Length(Data^) then Pos := Length(Data^);
MousePos := Pos;
end;
procedure DeleteSelect;
begin
if SelStart <> SelEnd then
begin
Delete(Data^, SelStart + 1, SelEnd - SelStart);
CurPos := SelStart;
end;
Message(Owner, evBroadcast, 11111, nil);
end;
procedure AdjustSelectBlock;
begin
if CurPos < Anchor then
begin
SelStart := CurPos;
SelEnd := Anchor;
end else
begin
SelStart := Anchor;
SelEnd := CurPos;
end;
end;
procedure SaveState;
begin
if Validator <> nil then
begin
OldData := Data^;
OldCurPos := CurPos;
OldFirstPos := FirstPos;
OldSelStart := SelStart;
OldSelEnd := SelEnd;
end;
end;
procedure RestoreState;
begin
if Validator <> nil then
begin
Data^ := OldData;
CurPos := OldCurPos;
FirstPos := OldFirstPos;
SelStart := OldSelStart;
SelEnd := OldSelEnd;
end;
end;
function CheckValid(NoAutoFill: Boolean): Boolean;
var
OldLen: Integer;
NewData: string;
begin
if Validator <> nil then
begin
CheckValid := False;
OldLen := Length(Data^);
NewData := Data^;
if not Validator^.IsValidInput(NewData, NoAutoFill) then
RestoreState
else
begin
if Length(NewData) > MaxLen then NewData[0] := Char(MaxLen);
Data^ := NewData;
if (CurPos >= OldLen) and (Length(Data^) > OldLen) then
CurPos := Length(Data^);
CheckValid := True;
end;
end
else
CheckValid := True;
end;
label ebem;
begin
TView.HandleEvent(Event);
if State and sfSelected <> 0 then
begin
case Event.What of
evMouseDown:
begin
Delta := MouseDelta;
if CanScroll(Delta) then
begin
repeat
if CanScroll(Delta) then
begin
Inc(FirstPos, Delta);
DrawView;
end;
until not MouseEvent(Event, evMouseAuto);
end else
if Event.Double then SelectAll(True) else
begin
Anchor := MousePos;
repeat
if Event.What = evMouseAuto then
begin
Delta := MouseDelta;
if CanScroll(Delta) then Inc(FirstPos, Delta);
end;
CurPos := MousePos;
AdjustSelectBlock;
DrawView;
until not MouseEvent(Event, evMouseMove + evMouseAuto);
end;
ClearEvent(Event);
end;
evKeyDown:
begin
SaveState;
Event.KeyCode := CtrlToArrow(Event.KeyCode);
if (Event.ScanCode in PadKeys) and
(ShiftState and $03 <> 0) then
begin
Event.CharCode := #0;
if CurPos = SelEnd then Anchor := SelStart
else Anchor := SelEnd;
ExtendBlock := True;
end
else
ExtendBlock := False;
case Event.KeyCode of
kbCtrlIns:
if Options and ofSecurity = 0 then begin
S := Copy(Data^, SelStart + 1, SelEnd - SelStart);
if S <> '' then Message(Owner^.Owner^.Owner, evCommand, cmPutInClipboard, @S);
ClearEvent(Event); Exit;
end;
kbCtrlLeft: begin
if CurPos > 0 then
repeat Dec(CurPos)
until (CurPos = 0) or not (Data^[CurPos+1] in BreakChars);
while (CurPos > 0) and not (Data^[CurPos] in BreakChars) do Dec(CurPos)
end;
kbCtrlRight: begin
if CurPos < Length(Data^) then
repeat Inc(CurPos)
until (CurPos >= Length(Data^)) or (Data^[CurPos+1] in BreakChars);
if CurPos < Length(Data^) then