-
Notifications
You must be signed in to change notification settings - Fork 2
/
DNAPP.PAS
1441 lines (1273 loc) · 37.2 KB
/
DNAPP.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 DNApp;
interface
uses Objects, Drivers, Memory, HistList, Views, Menus, Dialogs,
RStrings, Commands, ObjType, xTime;
const
EventsLen: Byte = 0;
MaxEvents = 15;
var
EventQueue: Array [1..MaxEvents] of TEvent;
const
IdleWas : Boolean = false; { Used by GetEvent }
{ TApplication palette entries }
apColor = 0;
apBlackWhite = 1;
apMonochrome = 2;
{ TApplication palettes }
{ Turbo Vision 1.0 Color Palettes }
CColor =
#$71#$70#$78#$74#$20#$28#$24#$17#$1F#$1A#$31#$31#$78#$7F#$1F#$31 +
#$3F#$3A#$13#$13#$3E#$21#$3F#$70#$7F#$7A#$13#$13#$70#$7F#$7E#$70 +
#$7F#$7A#$13#$13#$70#$70#$7F#$7E#$8F#$8B#$9F#$78#$8E#$70#$78#$7F +
#$7E#$0F#$9F#$0E#$9F#$79#$31#$31#$30#$0F#$3F#$31#$8F#$30#$3E#$30 +
#$38#$3E#$0F#$07#$0E#$87#$8F#$8F#$8B#$8F#$F0#$87#$7F#$1C#$00#$87 +
#$8F#$8B#$8F#$F0#$87#$8F#$8E#$30#$3E#$3F#$8F#$87#$70#$87#$8F#$3F +
#$8F#$3F#$8E#$8E#$70#$8B#$87#$30#$3F#$0F#$3E#$0E#$31#$31#$00#$87 +
#$8F#$8B#$8F#$F0#$87#$70#$8B#$8E#$8F#$87#$8F#$87#$8F#$70#$7F#$7A +
#$13#$13#$70#$30#$79#$39#$7E#$7E#$7F#$70#$37#$3F#$3A#$13#$13#$30 +
#$3E#$1E#$30#$38#$3E#$0F#$07#$0E#$87#$8F#$8F#$8B#$8F#$F0#$87#$70 +
#$8E#$30#$3F#$83#$8E#$38#$3F#$3A#$31#$3F#$70#$8F#$8B#$8A#$83#$82 +
#$8D#$9E#$8E#$8C#$89#$07#$7F#$03#$0F#$8F#$8F#$8E#$8F#$8D#$8B#$70 +
#$07#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F +
#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$3F#$08 +
#$CF#$CE#$0F#$0E;
CBlackWhite =
#$70#$70#$78#$7F#$07#$07#$0F#$07#$0F#$07#$70#$70#$07#$70#$0F +
#$07#$0F#$07#$70#$70#$07#$70#$0F#$70#$7F#$7F#$70#$07#$70#$07#$0F +
#$70#$7F#$7F#$70#$07#$70#$70#$7F#$7F#$07#$0F#$0F#$78#$0F#$78#$07 +
#$0F#$0F#$0F#$70#$0F#$07#$70#$70#$70#$07#$70#$0F#$07#$07#$78#$00 +
#$70#$78#$7F#$07#$07#$0F#$07#$0F#$0F#$0F#$70#$70#$07#$70#$07#$00 + { 64 - 79 Editor}
#$07#$0F#$0F#$70#$70#$07#$07#$0F#$70#$7F#$7F#$0F#$70#$70#$70#$7F +
#$0F#$70#$07#$7F#$7F#$07#$70#$7F#$30#$3F#$1F#$30#$17#$3E#$3E#$00 +
#$17#$1F#$1A#$31#$31#$17#$71 +
#$1B#$1E#$1E#$1F#$17#$1F#$17 + {119 - 125 - File Info}
#$70#$7F#$7A#$13#$13#$70#$30#$79#$39#$7E#$7E#$7F#$70 + {126 - 138 - File Find}
#$07#$0F#$07#$70#$70#$07#$0F#$70 +
#$70#$78#$7F#$07#$07#$0F#$07#$0F#$0F#$0F#$70#$70#$07#$70#$0F#$70 +
#$0F#$07#$1F#$31#$31#$1B#$1F#$1E#$30#$3E#$3F#$1F#$17#$71#$30#$3F +
#$3F#$1F#$1A#$31#$31#$1B#$1F#$1E#$30#$3E#$3F#$1F#$17#$71#$30#$3F +
#$3F#$1F#$1A#$31#$31#$1B#$1F#$1E#$30#$3E#$3F#$1F#$17#$71#$30#$3F +
#$7F#$1F#$1A#$31#$31#$1B#$1F#$1E#$30#$3E#$3F#$1F#$17#$71#$30#$3F;
CMonochrome =
#$70#$07#$07#$0F#$70#$70#$70#$07#$0F#$07#$70#$70#$07#$70#$00 +
#$07#$0F#$07#$70#$70#$07#$70#$00#$70#$70#$70#$07#$07#$70#$07#$00 +
#$70#$70#$70#$07#$07#$70#$70#$70#$0F#$07#$07#$0F#$70#$0F#$70#$07 +
#$0F#$0F#$07#$70#$07#$07#$70#$07#$07#$07#$70#$0F#$07#$07#$70#$00 +
#$70#$78#$7F#$07#$07#$0F#$07#$0F#$0F#$0F#$70#$70#$07#$70#$1C#$00 + { 64 - 79 Editor}
#$07#$0F#$0F#$70#$70#$07#$07#$0F#$70#$7F#$7F#$0F#$70#$70#$70#$7F +
#$0F#$70#$07#$7F#$7F#$07#$70#$7F#$30#$3F#$1F#$30#$17#$3E#$3E#$00 +
#$17#$1F#$1A#$31#$31#$17#$71 +
#$1B#$1E#$1E#$1F#$17#$1F#$17 + {119 - 125 - File Info}
#$70#$7F#$7A#$13#$13#$70#$30#$79#$39#$7E#$7E#$7F#$70 +
#$07#$0F#$07#$70#$70#$07#$0F#$70 +
#$70#$78#$7F#$07#$07#$0F#$07#$0F#$0F#$0F#$70#$70#$07#$70#$0F#$70 +
#$0F#$07#$1F#$31#$31#$1B#$1F#$1E#$30#$3E#$3F#$1F#$17#$71#$30#$3F +
#$3F#$1F#$1A#$31#$31#$1B#$1F#$1E#$30#$3E#$3F#$1F#$17#$71#$30#$3F +
#$3F#$1F#$1A#$31#$31#$1B#$1F#$1E#$30#$3E#$3F#$1F#$17#$71#$30#$3F +
#$7F#$1F#$1A#$31#$31#$1B#$1F#$1E#$30#$3E#$3F#$1F#$17#$71#$30#$3F;
{ Turbo Vision 2.0 Color Palettes }
CAppColor =
#$71#$70#$78#$74#$20#$28#$24#$17#$1F#$1A#$31#$31#$1E#$71#$1F +
#$37#$3F#$3A#$13#$13#$3E#$21#$3F#$70#$7F#$7A#$13#$13#$70#$7F#$7E +
#$70#$7F#$7A#$13#$13#$70#$70#$7F#$7E#$20#$2B#$2F#$78#$2E#$70#$30 +
#$3F#$3E#$1F#$2F#$1A#$20#$72#$31#$31#$30#$2F#$3E#$31#$13#$38#$00 +
#$17#$1F#$1A#$71#$71#$1E#$17#$1F#$1E#$20#$2B#$2F#$78#$2E#$10#$30 +
#$3F#$3E#$70#$2F#$7A#$20#$12#$31#$31#$30#$2F#$3E#$31#$13#$38#$00 +
#$37#$3F#$3A#$13#$13#$3E#$30#$3F#$3E#$20#$2B#$2F#$78#$2E#$30#$70 +
#$7F#$7E#$1F#$2F#$1A#$20#$32#$31#$71#$70#$2F#$7E#$71#$13#$38#$00;
CAppBlackWhite =
#$70#$70#$78#$7F#$07#$07#$0F#$07#$0F#$07#$70#$70#$07#$70#$0F +
#$07#$0F#$07#$70#$70#$07#$70#$0F#$70#$7F#$7F#$70#$07#$70#$07#$0F +
#$70#$7F#$7F#$70#$07#$70#$70#$7F#$7F#$07#$0F#$0F#$78#$0F#$78#$07 +
#$0F#$0F#$0F#$70#$0F#$07#$70#$70#$70#$07#$70#$0F#$07#$07#$78#$00 +
#$07#$0F#$0F#$07#$70#$07#$07#$0F#$0F#$70#$78#$7F#$08#$7F#$08#$70 +
#$7F#$7F#$7F#$0F#$70#$70#$07#$70#$70#$70#$07#$7F#$70#$07#$78#$00 +
#$70#$7F#$7F#$70#$07#$70#$70#$7F#$7F#$07#$0F#$0F#$78#$0F#$78#$07 +
#$0F#$0F#$0F#$70#$0F#$07#$70#$70#$70#$07#$70#$0F#$07#$07#$78#$00;
CAppMonochrome =
#$70#$07#$07#$0F#$70#$70#$70#$07#$0F#$07#$70#$70#$07#$70#$00 +
#$07#$0F#$07#$70#$70#$07#$70#$00#$70#$70#$70#$07#$07#$70#$07#$00 +
#$70#$70#$70#$07#$07#$70#$70#$70#$0F#$07#$07#$0F#$70#$0F#$70#$07 +
#$0F#$0F#$07#$70#$07#$07#$70#$07#$07#$07#$70#$0F#$07#$07#$70#$00 +
#$70#$70#$70#$07#$07#$70#$70#$70#$0F#$07#$07#$0F#$70#$0F#$70#$07 +
#$0F#$0F#$07#$70#$07#$07#$70#$07#$07#$07#$70#$0F#$07#$07#$70#$00 +
#$70#$70#$70#$07#$07#$70#$70#$70#$0F#$07#$07#$0F#$70#$0F#$70#$07 +
#$0F#$0F#$07#$70#$07#$07#$70#$07#$07#$07#$70#$0F#$07#$07#$70#$00;
{ TBackground palette }
CBackground = #1;
var
HintString: String[ 80 ];
const
SystemColors: array[apColor..apMonochrome] of String =
(CColor, CBlackWhite, CMonochrome);
type
PCacheCollection = ^TCacheCollection;
TCacheCollection = object(TCollection)
procedure FreeItem(Item: Pointer); virtual;
procedure PutItem(var S: TStream; Item: Pointer); virtual;
function GetItem(var S: TStream): Pointer; virtual;
end;
{ TBackground object }
PBackground = ^TBackground;
TBackground = object(TView)
Pattern: Char;
constructor Init(var Bounds: TRect; APattern: Char);
constructor Load(var S: TStream);
procedure Draw; virtual;
function GetPalette: PPalette; virtual;
procedure Store(var S: TStream);
end;
{ TDesktop object }
PDesktop = ^TDesktop;
TDesktop = object(TGroup)
Background: PBackground;
TileColumnsFirst: Boolean;
constructor Init(var Bounds: TRect);
constructor Load(var S: TStream);
procedure Cascade(var R: TRect);
procedure Clear;
procedure HandleEvent(var Event: TEvent); virtual;
procedure InitBackground; virtual;
procedure Store(var S: TStream);
procedure Tile(var R: TRect);
procedure TileError; virtual;
end;
{ TProgram object }
{ Palette layout }
{ 1 = TBackground }
{ 2- 7 = TMenuView and TStatusLine }
{ 8-15 = TWindow(Blue) }
{ 16-23 = TWindow(Cyan) }
{ 24-31 = TWindow(Gray) }
{ 32-63 = TDialog }
PProgram = ^TProgram;
TProgram = object(TGroup)
IdleSecs: TEventTimer;
constructor Init;
destructor Done; virtual;
function CanMoveFocus: Boolean;
function ExecuteDialog(P: PDialog; Data: Pointer): Word;
procedure InsertIdler;
procedure GetEvent(var Event: TEvent); virtual;
function GetPalette: PPalette; virtual;
procedure HandleEvent(var Event: TEvent); virtual;
procedure Idle; virtual;
procedure InitDesktop; virtual;
procedure InitMenuBar; virtual;
procedure InitScreen; virtual;
procedure InitStatusLine; virtual;
procedure InitCommandLine; virtual;
function InsertWindow(P: PWindow): PWindow;
procedure ActivateView(P: PView);
procedure OutOfMemory; virtual;
procedure PutEvent(var Event: TEvent); virtual;
procedure Run; virtual;
procedure SetScreenMode(Mode: Word);
function ValidView(P: PView): PView;
procedure Redraw; virtual;
end;
{ TApplication object }
PApplication = ^TApplication;
TApplication = object(TProgram)
Clock: PView;
constructor Init;
destructor Done; virtual;
procedure Cascade;
procedure ShowUserScreen;
procedure WhenShow; virtual;
procedure GetTileRect(var R: TRect); virtual;
procedure HandleEvent(var Event: TEvent); virtual;
procedure Tile;
end;
{ Interface and resource procedures }
procedure UpdateWriteView(P: Pointer);
procedure InitStringCache;
procedure OpenResource;
function ExecResource( Key: TDlgIdx; var Data): Word;
function LoadResource( Key: TDlgIdx ): PObject;
function GlobalMessage(What, Command: Word; InfoPtr: Pointer):pointer;
procedure GlobalEvent(What, Command: Word; InfoPtr: Pointer);
function ViewPresent(Command: Word; InfoPtr: Pointer): PView;
function WriteMsg(Text: String): PView;
function _WriteMsg(const Text: String): PView;
procedure ForceWriteShow(P: Pointer);
function GetString( Index: TStrIdx ): String;
procedure ToggleCommandLine(OnOff: Boolean);
procedure AdjustToDesktopSize(var R: TRect; OldDeskSize: TPoint);
const
{ Public variables }
StringCache: PCollection = nil;
Application: PProgram = nil;
Desktop: PDesktop = nil;
StatusLine: PStatusLine = nil;
MenuBar: PMenuView = nil;
ResourceStream: PStream = nil;
LngStream: PStream = nil;
LStringList : PStringList = nil;
Resource: PIdxResource = nil;
AppPalette: Integer = apColor;
CommandLine: PView = nil;
{ HintString: String[80] = '';}
{ Stream registration records }
RBackground: TStreamRec = (
ObjType: otBackground;
VmtLink: Ofs(TypeOf(TBackground)^);
Load: @TBackground.Load;
Store: @TBackground.Store);
RDesktop: TStreamRec = (
ObjType: otDesktop;
VmtLink: Ofs(TypeOf(TDesktop)^);
Load: @TDesktop.Load;
Store: @TDesktop.Store);
RStringCache: TStreamRec = (
ObjType: otStringCache;
VmtLink: Ofs(TypeOf(TCacheCollection)^);
Load: @TCacheCollection.Load;
Store: @TCacheCollection.Store);
const SkyVisible: Boolean = False;
implementation
uses Dos, DNHelp, Advance, Startup, Idlers, ExtraMemory;
var
{ Private variables }
LastComTime: TEventTimer;
procedure ToggleCommandLine(OnOff: Boolean);
begin
if (CommandLine <> nil) and (CommandLine^.GetState(sfVisible) xor OnOff) then
Message(Application, evCommand, cmHideCmdLine, nil);
end;
procedure AdjustToDesktopSize(var R: TRect; OldDeskSize: TPoint);
var KX, KY: Real;
begin
if OldDeskSize.X = 0 then OldDeskSize.X := Desktop^.Size.X;
if OldDeskSize.Y = 0 then OldDeskSize.Y := Desktop^.Size.Y;
if LongInt(Desktop^.Size) = LongInt(OldDeskSize) then Exit;
KX := Desktop^.Size.X/OldDeskSize.X;
R.A.X := Trunc(R.A.X*KX); R.B.X := Trunc(R.B.X*KX);
KY := Desktop^.Size.Y/OldDeskSize.Y;
R.A.Y := Trunc(R.A.Y*KY); R.B.Y := Trunc(R.B.Y*KY);
if R.Empty or (R.A.X >= Desktop^.Size.X) or (R.B.X < 0)
or (R.A.Y >= Desktop^.Size.Y) or (R.B.Y < 0)
or (R.B.X - R.A.X < MinWinSize.X)
or (R.B.Y - R.A.Y < MinWinSize.Y) then Desktop^.GetExtent(R);
end;
{ TBackground }
constructor TBackground.Init(var Bounds: TRect; APattern: Char);
begin
TView.Init(Bounds);
GrowMode := gfGrowHiX + gfGrowHiY;
Pattern := APattern;
end;
constructor TBackground.Load(var S: TStream);
begin
TView.Load(S);
S.Read(Pattern, SizeOf(Pattern));
end;
procedure TBackground.Draw;
var
B, B1: TDrawBuffer;
I, H, Src: Integer;
begin
MoveChar(B, ' ', $07, Size.X);
if UserScreen = nil
then WriteLine(0, 0, Size.X, Size.Y, B)
else begin
H := (UserScreenSize div (UserScreenWidth*2));
Src := 0;
If (InterfaceData.Options and ouiHideMenu = 0) and (Size.Y <> Application^.Size.Y) then
begin
Inc( Src, UserScreenWidth );
Dec( H );
end;
For I := 0 to H-1 do begin
B1 := B;
Move( PWordArray( UserScreen )^[ Src ], B1, UserScreenWidth * 2 );
WriteLine( 0, I, Size.X, 1, B1 );
Inc( Src, UserScreenWidth );
end;
WriteLine(0, H, Size.X, Size.Y - H + 1, B);
end;
end;
function TBackground.GetPalette: PPalette;
const
P: string[Length(CBackground)] = CBackground;
begin
GetPalette := @P;
end;
procedure TBackground.Store(var S: TStream);
begin
TView.Store(S);
S.Write(Pattern, SizeOf(Pattern));
end;
{ TDesktop object }
constructor TDesktop.Init(var Bounds: TRect);
begin
inherited Init(Bounds);
GrowMode := gfGrowHiX + gfGrowHiY;
HelpCtx := hcDesktop;
InitBackground;
if Background <> nil then Insert(Background);
end;
constructor TDesktop.Load(var S: TStream);
begin
inherited Load(S);
GetSubViewPtr(S, Background);
S.Read(TileColumnsFirst, SizeOf(TileColumnsFirst));
end;
function Tileable(P: PView): Boolean;
begin
Tileable := (P^.Options and ofTileable <> 0) and
(P^.State and sfVisible <> 0);
end;
procedure TDesktop.Clear;
procedure CloseView(P: PView); far;
begin Message(P, evCommand, cmClose, nil) end;
begin
if Desktop^.Valid(cmClose) then Desktop^.ForEach(@CloseView);
end;
procedure TDesktop.Cascade(var R: TRect);
var
CascadeNum: Integer;
LastView: PView;
Min, Max: TPoint;
procedure DoCount(P: PView); far;
begin
if Tileable(P) then
begin
Inc(CascadeNum);
LastView := P;
end;
end;
procedure DoCascade(P: PView); far;
var
NR: TRect;
begin
if Tileable(P) and (CascadeNum >= 0) then
begin
NR.Copy(R);
Inc(NR.A.X, CascadeNum); Inc(NR.A.Y, CascadeNum);
P^.Locate(NR);
Dec(CascadeNum);
end;
end;
begin
CascadeNum := 0;
ForEach(@DoCount);
if CascadeNum > 0 then
begin
LastView^.SizeLimits(Min, Max);
if (Min.X > R.B.X - R.A.X - CascadeNum) or
(Min.Y > R.B.Y - R.A.Y - CascadeNum) then TileError
else
begin
Dec(CascadeNum);
Lock;
ForEach(@DoCascade);
Unlock;
end;
end;
end;
procedure TDesktop.HandleEvent(var Event: TEvent);
begin
TGroup.HandleEvent(Event);
if Event.What = evCommand then
begin
case Event.Command of
cmNext: SelectNext(False);
cmPrev:
if Valid(cmReleasedFocus) then
Current^.PutInFrontOf(Background);
else
Exit;
end;
ClearEvent(Event);
end;
end;
procedure TDesktop.InitBackground;
var
R: TRect;
begin
GetExtent(R);
New(Background, Init(R, #176));
end;
function ISqr(X: Integer): Integer; assembler;
asm
MOV CX,X
MOV BX,0
@@1: INC BX
MOV AX,BX
IMUL AX
CMP AX,CX
JLE @@1
MOV AX,BX
DEC AX
end;
procedure MostEqualDivisors(N: Integer; var X, Y: Integer; FavorY: Boolean);
var
I: Integer;
begin
I := ISqr(N);
if ((N mod I) <> 0) then
if (N mod (I+1)) = 0 then Inc(I);
if I < (N div I) then I := N div I;
if FavorY then
begin
X := N div I;
Y := I;
end
else
begin
Y := N div I;
X := I;
end;
end;
procedure TDesktop.Store(var S: TStream);
begin
inherited Store(S);
PutSubViewPtr(S, Background);
S.Write(TileColumnsFirst, SizeOf(TileColumnsFirst));
end;
procedure TDesktop.Tile(var R: TRect);
var
NumCols, NumRows, NumTileable, LeftOver, TileNum: Integer;
procedure DoCountTileable(P: PView); far;
begin
if Tileable(P) then Inc(NumTileable);
end;
function DividerLoc(Lo, Hi, Num, Pos: Integer): Integer;
begin
DividerLoc := LongDiv(LongMul(Hi - Lo, Pos), Num) + Lo;
end;
procedure CalcTileRect(Pos: Integer; var NR: TRect);
var
X,Y,D: Integer;
begin
D := (NumCols - LeftOver) * NumRows;
if Pos < D then
begin
X := Pos div NumRows;
Y := Pos mod NumRows;
end else
begin
X := (Pos - D) div (NumRows + 1) + (NumCols - LeftOver);
Y := (Pos - D) mod (NumRows + 1);
end;
NR.A.X := DividerLoc(R.A.X, R.B.X, NumCols, X);
NR.B.X := DividerLoc(R.A.X, R.B.X, NumCols, X+1);
if Pos >= D then
begin
NR.A.Y := DividerLoc(R.A.Y, R.B.Y, NumRows+1, Y);
NR.B.Y := DividerLoc(R.A.Y, R.B.Y, NumRows+1, Y+1);
end else
begin
NR.A.Y := DividerLoc(R.A.Y, R.B.Y, NumRows, Y);
NR.B.Y := DividerLoc(R.A.Y, R.B.Y, NumRows, Y+1);
end;
end;
procedure DoTile(P: PView); far;
var
R: TRect;
begin
if Tileable(P) then
begin
CalcTileRect(TileNum, R);
P^.Locate(R);
Dec(TileNum);
end;
end;
begin
NumTileable := 0;
ForEach(@DoCountTileable);
if NumTileable > 0 then
begin
MostEqualDivisors(NumTileable, NumCols, NumRows, not TileColumnsFirst);
if ((R.B.X - R.A.X) div NumCols = 0) or
((R.B.Y - R.A.Y) div NumRows = 0) then TileError
else
begin
LeftOver := NumTileable mod NumCols;
TileNum := NumTileable-1;
Lock;
ForEach(@DoTile);
Unlock;
end;
end;
end;
procedure TDesktop.TileError;
begin
end;
{ TProgram }
constructor TProgram.Init;
var
R: TRect;
begin
Application := @Self;
InitScreen;
R.Assign(0, 0, ScreenWidth, ScreenHeight);
TGroup.Init(R);
State := sfVisible + sfSelected + sfFocused + sfModal + sfExposed;
Options := 0;
Buffer := ScreenBuffer;
InitStatusLine;
InitMenuBar;
InitDesktop;
if StatusLine <> nil then Insert( StatusLine );
if MenuBar <> nil then Insert(MenuBar);
if Desktop <> nil then Insert(Desktop);
InitCommandLine;
if StatusLine <> nil then StatusLine^.GrowTo(StatusLine^.Size.X, 1);
if MenuBar <> nil then MenuBar^.GrowTo(MenuBar^.Size.X, 1);
NewTimer(LastComTime, 0);
NewTimer(IdleSecs, 0);
end;
destructor TProgram.Done;
begin
if MenuBar <> nil then Dispose(MenuBar, Done);
if StatusLine <> nil then Dispose(StatusLine, Done);
if Desktop <> nil then Dispose(Desktop, Done);
Application := nil;
inherited Done;
end;
function TProgram.CanMoveFocus: Boolean;
begin
CanMoveFocus := Desktop^.Valid(cmReleasedFocus);
end;
function TProgram.ExecuteDialog(P: PDialog; Data: Pointer): Word;
var
C: Word;
begin
ExecuteDialog := cmCancel;
if ValidView(P) <> nil then
begin
if Data <> nil then P^.SetData(Data^);
C := Desktop^.ExecView(P);
if (C <> cmCancel) and (Data <> nil) then P^.GetData(Data^);
Dispose(P, Done);
ExecuteDialog := C;
end;
end;
procedure ExecExit;
var S: PathStr;
begin
{if SSaver <> nil then SSaver^.Free;}
S := GetEnv('DNIDLE');
if S = '' then begin Application^.Done; Halt(0); end
else Message(Application, evCommand, cmExecString, @S);
end;
procedure TProgram.InsertIdler;
var I: Integer;
S: String;
R: TRect;
Event: TEvent;
MX, MY: Word;
begin
if (SkyEnabled > 0) or SaversData.Mouse and
(MouseWhere.Y= Size.Y-1) and (MouseWhere.X = Size.X-1)
or (SaversData.Selected.List = nil) or
(SaversData.Selected.List^.Count = 0) or
(SSaver <> nil) then Exit;
S := PString(SaversData.Selected.List^.At(Random(SaversData.Selected.List^.Count)))^;
if S[1] = #249 then
begin
Application^.GetExtent(R);
case S[3] of
'F': SSaver := New(PProjector, Init);
'B': SSaver := New(PSSaver, Init(R));
'C': SSaver := New(PClockSaver, Init);
else SSaver := New(PStarSkySaver, Init);
end;
if (SSaver <> nil) then
begin
if ExecView(SSaver) = cmCancel then ExecExit;
Dispose(SSaver, Done);
end;
end else begin
CallExternalSaver(S);
end;
end;
procedure TProgram.GetEvent(var Event: TEvent);
function ContainsMouse(P: PView): Boolean; far;
begin
ContainsMouse := (P^.State and sfVisible <> 0) and
P^.MouseInView(Event.Where);
end;
var
P: Procedure;
R: TRect;
A1, A2: Word;
label 11;
begin
11:
if EventsLen > 0 then
begin
Event := EventQueue[1];
Dec(EventsLen);
Move(EventQueue[2], EventQueue[1], SizeOf(Event)*EventsLen);
NewTimer(IdleSecs, 0);
SliceAwake;
end else
begin
EventsLen := 0;
GetMouseEvent(Event);
if Event.What = evNothing then
begin
GetKeyEvent(Event);
if Event.What = evNothing then
begin
Idle;
if EventsLen > 0 then goto 11;
if (ElapsedTimeInSecs(IdleSecs) > 3600) and
(StartupData.Unload and osuInactivityExit <> 0) then
begin
ExecExit;
end;
end else
begin
NewTimer(IdleSecs, 0);
SliceAwake;
end;
end else
begin
NewTimer(IdleSecs, 0);
SliceAwake;
end;
end;
if (Event.What <> evNothing) or (SkyEnabled <> 0) then NewTimer(LastComTime, 0) else
if (SSaver = nil) and (SkyEnabled=0) and (SkyDelay <> 255) and
(ElapsedTimeInSecs(LastComTime) >= SkyDelay*60) then
begin
InsertIdler;
NewTimer(LastComTime, 0)
end;
if (StatusLine <> nil) and (SSaver = nil) then
if (Event.What and evMouseDown <> 0) and (Event.Buttons and mbLeftButton <> 0) and
(FirstThat(@ContainsMouse) = PView(StatusLine)) then
StatusLine^.HandleEvent(Event);
if (IdleWas) and
(SkyEnabled = 0) and
(SSaver = nil) and
(CommandLine <> nil) and
(CommandLine^.Size.Y <> 0) and
(CommandLine^.GetState(sfVisible)) then
begin
IdleWas := False;
asm
mov ah,3
xor bx,bx
int 10h
mov A1, dx
mov A2, cx
end;
if ((Hi(A2) = $20) or (Hi(A1) = Size.Y - 1 - Byte( InterfaceData.Options and ouiHideStatus = 0 )))
then CommandLine^.Update;
end;
end;
function TProgram.GetPalette: PPalette;
begin
GetPalette := @SystemColors[AppPalette];
end;
procedure TProgram.Redraw;
begin
if (Size.X <> ScreenWidth) or (Size.Y <> ScreenHeight) then
GrowTo(ScreenWidth, ScreenHeight) else inherited Redraw;
end;
procedure TProgram.HandleEvent(var Event: TEvent);
var
I: Word;
C: Char;
begin
if Event.What = evKeyDown then
begin
C := GetAltChar(Event.KeyCode);
{if (C >= '1') and (C <= '9') then
if Message(Desktop, evBroadCast, cmSelectWindowNum,
Pointer(Byte(C) - $30)) <> nil then ClearEvent(Event);}
end;
TGroup.HandleEvent(Event);
if Event.What = evCommand then
if Event.Command = cmQuit then
begin
EndModal(cmQuit);
ClearEvent(Event);
end;
end;
procedure TProgram.Idle;
var P: PView;
E: TEvent;
A1, A2: Word;
label 1;
begin
if StatusLine <> nil then StatusLine^.Update;
if CommandSetChanged then
begin
Message(@Self, evBroadcast, cmCommandSetChanged, nil);
CommandSetChanged := False;
end;
end;
procedure TProgram.InitDesktop;
var
R: TRect;
begin
GetExtent(R);
if SystemData.Options and ouiHideMenu = 0 then Inc(R.A.Y);
if SystemData.Options and ouiHideStatus = 0 then Dec(R.B.Y);
New(Desktop, Init(R));
end;
procedure TProgram.InitMenuBar;
var
R: TRect;
begin
GetExtent(R);
R.B.Y := R.A.Y + 1;
MenuBar := New(PMenuBar, Init(R, nil));
end;
procedure TProgram.InitScreen;
begin
if Lo(ScreenMode) <> smMono then
begin
if ScreenWidth div ScreenHeight < 2 then
ShadowSize.X := 1 else
ShadowSize.X := 2;
ShadowSize.Y := 1;
ShowMarkers := False;
if Lo(ScreenMode) = smBW80 then
AppPalette := apBlackWhite else
AppPalette := apColor;
end else
begin
ShadowSize.X := 0;
ShadowSize.Y := 0;
ShowMarkers := True;
AppPalette := apMonochrome;
end;
end;
procedure TProgram.InitStatusLine;
var
R: TRect;
begin
GetExtent(R);
R.A.Y := R.B.Y - 1;
New(StatusLine, Init(R,
NewStatusDef(0, $FFFF,
NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
nil), nil)));
end;
procedure TProgram.InitCommandLine;
begin
end;
function TProgram.InsertWindow(P: PWindow): PWindow;
var PP: TPoint;
EV: TEvent;
PV: PView;
begin
InsertWindow := nil;
if ValidView(P) <> nil then
if CanMoveFocus then
begin
Desktop^.Insert(P);
InsertWindow := P;
{P^.Select;}
ActivateView(P);
end
else
Dispose(P, Done);
Idle;
end;
procedure TProgram.ActivateView;
var EV: TEvent;
PP: TPoint;
begin
EV.What := evMouseDown; PP.X := P^.Origin.X; PP.Y := P^.Origin.Y + P^.Size.Y - 2;
Desktop^.MakeGlobal(PP, PP); EV.Where := PP;
EV.Buttons := mbRightButton; {PutEvent(EV);}
end;
procedure TProgram.OutOfMemory;
begin
end;
procedure TProgram.PutEvent(var Event: TEvent);
begin
if (Event.What = evNothing) then Exit;
if (EventsLen = MaxEvents) then
Move(EventQueue[2],EventQueue[1],(MaxEvents-1)*SizeOf(Event))
else Inc(EventsLen);
EventQueue[EventsLen] := Event;
end;
procedure TProgram.Run;
begin
Execute;
end;
procedure TProgram.SetScreenMode;
var
R: TRect;
begin
HideMouse;
DoneEvents;
SetVideoMode(Mode);
CharHeight := Mem[$40:$85];
InitEvents;
DoneMemory;
InitMemory;
InitScreen;
Buffer := ScreenBuffer;
R.Assign(0, 0, ScreenWidth, ScreenHeight);
ChangeBounds(R);
R.Assign(0, ScreenHeight - 1 - Byte(InterfaceData.Options and ouiHideStatus = 0),
ScreenWidth, ScreenHeight - Byte(InterfaceData.Options and ouiHideStatus = 0));
if CommandLine <> nil then CommandLine^.Locate(R);
ShowMouse;
asm
mov ah, 1
xor bx, bx
mov cx, $0607
push bp
int 10h
pop bp
end;
CursorLines := $607;
SetBlink(CurrentBlink);
end;
function TProgram.ValidView(P: PView): PView;
begin
ValidView := nil;
if P <> nil then
begin
if LowMemory then
begin
Dispose(P, Done);
OutOfMemory;
Exit;
end;
if not P^.Valid(cmValid) then
begin
Dispose(P, Done);
Exit;
end;
ValidView := P;
end;
end;
{ TApplication }