This repository has been archived by the owner on Jun 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstatuses.pas
1404 lines (1265 loc) · 48.5 KB
/
statuses.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
{$V-}
unit Statuses;
{$CODEPAGE cp437}
{#Z+}
{ Free Vision Status Objects Unit
Free VIsion
Written by : Brad Williams, DVM
Revision History
1.2.3 (96/04/13)
- moved Pause and Resume to methods of TStatus leaving TStatus Pause and
Resume "aware"
- eliminated many bugs
- moved Pause, Resume and Cancel from TStatusDlg to TStatus
1.2.1 (95/12/6)
- minor typo corrections in opening unit documentation
- F+ to Z+ around stream registration records
- removed redundant sentence in TAppStatus definition
- updated CBarStatus documentation and constant
- removed TGauge.Init cross-reference from TSpinner.Init
- added THeapMemAvail and RegistertvStatus documentation
- numerous other documentation updates
- changed all calls to Send to Message
1.2.0 (95/11/24)
- conversion to Bsd format
1.1.0 (05/01/94)
- initial WVS release
Known Bugs
ScanHelp Errors
- sdXXXX constants help documentation doesn't show TStatusDlg and
TMessageStatusDlg
- ScanHelp produces garbage in evStatus help context
tvStatus Bugs
- CAppStatus may not be correct }
{#Z-}
{ The tvStatus unit implements several views for providing information to
the user which needs to be updated during program execution, such as a
progress indicator, clock, heap viewer, gauges, etc. All tvStatus views
respond to a new message event class, evStatus. An individual status view
only processes an event with its associated command. }
interface
{$i platform.inc}
{$ifdef PPC_FPC}
{$H-}
{$else}
{$F+,O+,E+,N+}
{$endif}
{$X+,R-,I-,Q-,V-}
{$ifndef OS_UNIX}
{$S-}
{$endif}
uses
FVCommon, FVConsts, Objects, Drivers, Views, Dialogs;
{ Resource;}
const
evStatus = $8000;
{ evStatus represents the event class all status views know how to
respond to. }
{#X Statuses }
CStatus = #1#2#3;
{$ifndef cdPrintDoc}
{#F+}
{ÝTStatus.CStatus palette
ßßßßßßßßßßßßßßßßßßßßßßßßß}
{#F-}
{$endif cdPrintDoc}
{ Status views use the default palette, CStatus, to map onto the first three
entries in the standard window palette. }
{#F+}
{ 1 2 3
ÉÍÍÍÍÑÍÍÍÍÑÍÍÍÍ»
CStatus º 1 ³ 2 ³ 3 º
ÈÍÍÑÍÏÍÍÑÍÏÍÍÑͼ
Normal TextÄÄÄÙ ³ ³
OtherÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³
Highlighted TextÄÄÄÄÄÄÄÄÙ }
{#F-}
{#X TStatus }
CAppStatus = #2#5#4;
{$ifndef cdPrintDoc}
{#F+}
{ÝTAppStatus.CAppStatus palette
ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß}
{#F-}
{$endif cdPrintDoc}
{ Status views which are inserted into the application rather than a dialog
or window use the default palette, CAppStatus, to map onto the application
object's palette. }
{#F+}
{ 1 2 3
ÉÍÍÍÍÑÍÍÍÍÑÍÍÍÍ»
CAppStatus º 2 ³ 5 ³ 4 º
ÈÍÍÑÍÏÍÍÑÍÏÍÍÑͼ
Normal TextÄÄÄÄÄÄÙ ³ ³
OtherÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³
Highlighted TextÄÄÄÄÄÄÄÄÄÄÄÙ }
{#F-}
{#X tvStatus TAppStatus }
CBarGauge = CStatus + #16#19;
{$ifndef cdPrintDoc}
{#F+}
{ÝTBarGauge.CBarGauge palette
ßßßßßßßßßßßßßßßßßßßßßßßßßßßßß}
{#F-}
{$endif cdPrintDoc}
{ TBarGauge's use the default palette, CBarGauge, to map onto the dialog or
window owner's palette. }
{#F+}
{ 1 2 3 4 5
ÉÍÍÍÍÑÍÍÍÍÑÍÍÍÍÑÍÍÍÍÑÍÍÍÍ»
CAppStatus º 2 ³ 5 ³ 4 ³ 16 ³ 19 º
ÈÍÍÑÍÏÍÍÑÍÏÍÍÑÍÏÍÍÑÍÏÍÍÑͼ
Normal TextÄÄÄÄÄÄÙ ³ ³ ³ ÀÄÄÄÄ filled in bar
OtherÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ ÀÄÄÄÄÄÄÄÄÄ empty bar
Highlighted TextÄÄÄÄÄÄÄÄÄÄÄÙ }
{#F-}
{#X tvStatus TBarGauge }
{#T sdXXXX }
{$ifndef cdPrintDoc}
{#F+}
{ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
Ý sdXXXX constants (STDDLG unit) Þ
ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß}
{#F-}
{$endif cdNoPrintDoc}
{ sdXXXX constants are used to determine the types of buttons displayed in a
#TStatusDlg# or #TStatusMessageDlg#. }
{#F+}
{ Constant ³ Value ³ Meaning
ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍØÍÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
sdNone ³ $0000 ³ no buttons
sdCancelButton ³ $0001 ³ show Cancel button
sdPauseButton ³ $0002 ³ show Pause button
sdResumeButton ³ $0004 ³ show Resume button
sdAllButtons ³ $0008 ³ show Cancel, Pause and Resume
³ ³ buttons }
{#Z+}
sdNone = $0000;
sdCancelButton = $0001;
sdPauseButton = $0002;
sdResumeButton = $0004;
sdAllButtons = sdCancelButton or sdPauseButton or sdResumeButton;
{#Z-}
{#X tvStatus TStatusDlg TStatusMessageDlg }
SpinChars : String[4] = '³/Ä\';
{ SpinChars are the characters used by a #TSpinnerGauge# when it is drawn.
Only one character is displayed at a time. The string is cycled
through then started over again until the view is disposed. }
{#X tvStatus }
sfPause = $F000;
{ sfPause is an additional state flag used internally by status views to
indicate they are in a paused state and should not respond to their
command. }
type
{#Z+}
PStatus = ^TStatus;
{#Z-}
TStatus = Object(TParamText)
{ TStatus is the base object type from which all status views descend.
Status views are used to display information that will change at
run-time based upon some state or process in the application, such as
printing.
All status views that are to be inserted into the application should
descend from #TAppStatus# for proper color mapping. }
Command : Word;
{ Command is the only command the status view will respond to. When
the status view receives an evStatus event it checks the value of the
Event.Command field against Command before handling the event. }
{#X HandleEvent }
constructor Init (R : TRect; ACommand : Word; AText : String;
AParamCount : Integer);
{ Init calls the inherited constructor then sets #Command# to ACommand.
If an error occurs Init fails. }
{#X Load }
constructor Load (var S : TStream);
{ Load calls the inherited constructor then reads #Command# from the
stream.
If an error occurs Load fails. }
{#X Store Init }
function Cancel : Boolean; virtual;
{ Cancel should prompt the user when necessary for validation of
canceling the process which the status view is displaying. If the
user elects to continue the process Cancel must return False,
otherwise Cancel must return True. }
{#X Pause Resume }
function GetPalette : PPalette; virtual;
{ GetPalette returns a pointer to the default status view palette,
#CStatus#. }
{#X TAppStatus CAppStatus }
procedure HandleEvent (var Event : TEvent); virtual;
{ HandleEvent captures any #evStatus# messages with its command value
equal to #Command#, then calls #Update# with Data set to
Event.InfoPtr. If the State field has its #sfPause# bit set, the
view ignores the event. }
procedure Pause; virtual;
{ Pause sends an evStatus message to the application with Event.Command
set to cmStatusPause and Event.InfoPtr set to #Status#^.Command. The
#Status# view's sfPause bit of the State flag is set by calling
SetState. In the paused state, the status view does not respond to
its associated command. }
{#X Resume sdXXXX Cancel }
procedure Reset; virtual;
{ Reset causes the status view to be reset to its beginning or default
value, then be redrawn. Reset is used after an event is aborted
which can only be performed in its entirety. }
procedure Resume; virtual;
{ Resume is called in response to pressing the Resume button. Resume
sends an evStatus message to the application with Event.Command set
to cmStatusPause and Event.InfoPtr set to #Status#^.Command. The
Status view's sfPause bit is turned off by calling SetState. }
{#X Pause sdXXXX Cancel }
procedure Store (var S : TStream); { store should never be virtual;}
{ Store calls the inherited Store method then writes #Command# to the
stream. }
{#X Load }
procedure Update (Data : Pointer); virtual;
{ Update changes the status' displayed text as necessary based on
Data. }
{#X Command HandleEvent }
end; { of TStatus }
{#Z+}
PStatusDlg = ^TStatusDlg;
{#Z-}
TStatusDlg = Object(TDialog)
{ A TStatusDlg displays a status view and optional buttons. It may be
used to display any status message and optionally provide end user
cancelation or pausing of an ongoing operation, such as printing.
All status views that are to be inserted into a window or dialog should
descend from #TStatus# for proper color mapping. }
Status : PStatus;
{ Status is the key status view for the dialog. When a cmStatusPause
command is broadcast in response to pressing the pause button,
Event.InfoPtr is set to point to the command associated with Status. }
{#X TStatus cmXXXX }
constructor Init (ATitle : TTitleStr; AStatus : PStatus; AFlags : Word);
{ Init calls the inherited constructor to create the dialog and sets
the EventMask to handle #evStatus# events. AStatus is assigned to
#Status# and inserted into the dialog at position 2,2.
The dialog is anchored at AStatus^.Origin and its size is at least
AStatus^.Size + 2 in both dimensions. The actual size is determined
by the AFlags byte. The #sdXXXX# constants should be used to signify
which buttons to display.
If an error occurs Init fails. }
{#X TStatus.Pause TStatus.Resume }
constructor Load (var S : TStream);
{ Load calls the inherited constructor then loads #Status#.
If an error occurs Load fails. }
{#X Store }
procedure Cancel (ACommand : Word); virtual;
{ Cancel sends an evStatus message to the Application object with
command set to cmCancel and InfoPtr set to the calling status view's
command, then calls the inherited Cancel method. }
{#X TBSDDialog.Cancel }
procedure HandleEvent (var Event : TEvent); virtual;
{ All evStatus events are accepted by the dialog and sent to each
subview in Z-order until cleared.
If the dialog recieves an evCommand or evBroadcast event with the
Command parameter set to cmCancel, HandleEvent sends an #evStatus#
message to the Application variable with Event.Command set to the
cmStatusCancel and Event.InfoPtr set to the #Status#.Command and
disposes of itself.
When a pause button is included, a cmStatusPause broadcast event is
associated with the button. When the button is pressed a call to
#TStatus.Pause# results. The status view is inactivated until it
receives an evStatus event with a commond of cmStatusResume and
Event.InfoPtr set to the status view's Command value. When a pause
button is used, the application should respond to the evStatus event
(with Event.Command of cmStatusPause) appropriately, then dispatch a
cmStatusResume evStatus event when ready to resume activity. }
{#X TStatus.Command }
procedure InsertButtons (AFlags : Word); virtual;
{ InsertButtons enlarges the dialog to the necessary size and inserts
the buttons specified in AFlags into the last row of the dialog. }
procedure Store (var S : TStream); { store should never be virtual;}
{ Store calls the inherited Store method then writes #Status# to the
stream. }
{#X Load }
end; { of TStatusDlg }
{#Z+}
PStatusMessageDlg = ^TStatusMessageDlg;
{#Z-}
TStatusMessageDlg = Object(TStatusDlg)
{ A TStatusMessageDlg displays a message as static text with a status
view on the line below it.
All status views that are to be inserted into a window or dialog should
descend from #TStatus# for proper color mapping. }
constructor Init (ATitle : TTitleStr; AStatus : PStatus; AFlags : Word;
AMessage : String);
{ Init calls the inherited constructor then inserts a TStaticText view
containing AMessage at the top line of the dialog.
The size of the dialog is determined by the size of the AStatus. The
dialog is anchored at AStatus^.Origin and is of at least
AStatus^.Size + 2 in heighth and width. The exact width and heighth
are determined by AOptions.
AFlags contains flags which determine the buttons to be displayed
in the dialog.
If an error occurs Init fails. }
end; { of TStatusMessageDlg }
{#Z+}
PGauge = ^TGauge;
{#Z-}
TGauge = Object(TStatus)
{ A gauge is used to represent the current numerical position within a
range of values. When Current equals Max a gauge dispatches an
#evStatus# event with the command set to cmStatusDone to the
Application object. }
Min : LongInt;
{ Min is the minimum value which #Current# may be set to. }
{#X Max }
Max : LongInt;
{ Max is the maximum value which #Current# may be set to. }
{#X Min }
Current : LongInt;
{ Current is the current value represented in the gauge. }
{#X Max Min }
constructor Init (R : TRect; ACommand : Word; AMin, AMax : LongInt);
{ Init calls the inherited constructor then sets #Min# and #Max# to
AMin and AMax, respectively. #Current# is set to AMin.
If an error occurs Init fails. }
{#X Load }
constructor Load (var S : TStream);
{ Load calls the inherited constructor then reads #Min#, #Max# and
#Current# from the stream.
If an error occurs Load fails. }
{#X Init Store }
procedure Draw; virtual;
{ Draw writes the following to the screen: }
{#F+}
{
Min = XXX Max = XXX Current = XXX }
{#F-}
{ where XXX are the current values of the corresponding variables. }
procedure GetData (var Rec); virtual;
{ GetData assumes Rec is a #TGaugeRec# and returns the current settings
of the gauge. }
{#X SetData }
procedure Reset; virtual;
{ Reset sets #Current# to #Min# then redraws the status view. }
{#X TStatus.Reset }
procedure SetData (var Rec); virtual;
{ SetData assumes Rec is a #TGaugeRec# and sets the gauge's variables
accordingly. }
{#X GetData }
procedure Store (var S : TStream); { store should never be virtual;}
{ Store calls the inherited Store method then writes #Min#, #Max# and
#Current# to the stream. }
{#X Load }
procedure Update (Data : Pointer); virtual;
{ Update increments #Current#. }
end; { of TGauge }
{#Z+}
PGaugeRec = ^TGaugeRec;
{#Z-}
TGaugeRec = record
{ A TGaugeRec is used to set and get a #TGauge#'s variables. }
{#X TGauge.GetData TGauge.SetData }
Min, Max, Current : LongInt;
end; { of TGaugeRec }
{#Z+}
PArrowGauge = ^TArrowGauge;
{#Z-}
TArrowGauge = Object(TGauge)
{ An arrow gauge draws a progressively larger series of arrows across the
view. If Right is True, the arrows are right facing, '>', and are
drawn from left to right. If Right is False, the arrows are left
facing, '<', and are drawn from right to left. }
Right : Boolean;
{ Right determines the direction of arrow used and the direction which
the status view is filled. If Right is True, the arrows are right
facing, '>', and are drawn from left to right. If Right is False,
the arrows are left facing, '<', and are drawn from right to left. }
{#X Draw }
constructor Init (R : TRect; ACommand : Word; AMin, AMax : Word;
RightArrow : Boolean);
{ Init calls the inherited constructor then sets #Right# to RightArrow.
If an error occurs Init fails. }
{#X Load }
constructor Load (var S : TStream);
{ Load calls the inherited constructor then reads #Right# from the
stream.
If an error occurs Load fails. }
{#X Init Store }
procedure Draw; virtual;
{ Draw fills the Current / Max percent of the view with arrows. }
{#X Right }
procedure GetData (var Rec); virtual;
{ GetData assumes Rec is a #TArrowGaugeRec# and returns the current
settings of the views variables. }
{#X SetData }
procedure SetData (var Rec); virtual;
{ SetData assumes Rec is a #TArrowGaugeRec# and sets the view's
variables accordingly. }
{#X GetData }
procedure Store (var S : TStream); { store should never be virtual;}
{ Store calls the inherited Store method then writes #Right# to the
stream. }
{#X Load }
end; { of TArrowGauge }
{#Z+}
PArrowGaugeRec = ^TArrowGaugeRec;
{#Z-}
TArrowGaugeRec = record
{ A TArrowGaugeRec is used to set and get the variables of a
#TArrowGauge#. }
{#X TArrowGauge.GetData TArrowGauge.SetData }
Min, Max, Count : LongInt;
Right : Boolean;
end; { of TGaugeRec }
{#Z+}
PPercentGauge = ^TPercentGauge;
{#Z-}
TPercentGauge = Object(TGauge)
{ A TPercentGauge displays a numerical percentage as returned by
#Percent# followed by a '%' sign. }
function Percent : Integer; virtual;
{ Percent returns the whole number value of (Current / Max) * 100. }
{#X TGauge.Current TGauge.Max }
procedure Draw; virtual;
{ Draw writes the current percentage to the screen. }
{#X Percent }
end; { of TPercentGauge }
{#Z+}
PBarGauge = ^TBarGauge;
{#Z-}
TBarGauge = Object(TPercentGauge)
{ A TBarGauge displays a bar which increases in size from the left to
the right of the view as Current increases. A numeric percentage
representing the value of (Current / Max) * 100 is displayed in the
center of the bar. }
{#x TPercentGauge.Percent }
procedure Draw; virtual;
{ Draw draws the bar and percentage to the screen representing the
current status of the view's variables. }
{#X TGauge.Update }
function GetPalette : PPalette; virtual;
{ GetPalette returns a pointer to the default status view palette,
#CBarStatus#. }
end; { of TBarGauge }
{#Z+}
PSpinnerGauge = ^TSpinnerGauge;
{#Z-}
TSpinnerGauge = Object(TGauge)
{ A TSpinnerGauge displays a series of characters in one spot on the
screen giving the illusion of a spinning line. }
constructor Init (X, Y : Integer; ACommand : Word);
{ Init calls the inherited constructor with AMin set to 0 and AMax set
to 4. }
procedure Draw; virtual;
{ Draw uses the #SpinChars# variable to draw the view's Current
character. }
{#X Update }
procedure HandleEvent (var Event : TEvent); virtual;
{ HandleEvent calls TStatus.HandleEvent so that a cmStatusDone event
is not generated when Current equals Max. }
{#X TGauge.Current TGauge.Max }
procedure Update (Data : Pointer); virtual;
{ Update increments Current until Current equals Max, when it resets
Current to Min. }
{#X Draw HandleEvent }
end; { of TSpinnerGauge }
{#Z+}
PAppStatus = ^TAppStatus;
{#Z-}
TAppStatus = Object(TStatus)
{ TAppStatus is a base object which implements color control for status
views that are normally inserted in the Application object. }
{#X TStatus }
function GetPalette : PPalette; virtual;
{ GetPalette returns a pointer to the default application status view
palette, #CAppStatus#. }
{#X TStatus CStatus }
end; { of TAppStatus }
{#Z+}
PHeapMaxAvail = ^THeapMaxAvail;
{#Z-}
THeapMaxAvail = Object(TAppStatus)
{ A THeapMaxAvail displays the largest available contiguous area of heap
memory. It responds to a cmStatusUpdate event by calling MaxAvail and
comparing the result to #Max#, then updating the view if necessary. }
{#X THeapMemAvail }
constructor Init (X, Y : Integer);
{ Init creates the view with the following text:
MaxAvail = xxxx
where xxxx is the result returned by MaxAvail. }
procedure Update (Data : Pointer); virtual;
{ Update changes #Mem# to the current MemAvail and redraws the status
if necessary. }
private
Max : LongInt;
{ Max is the last reported value from MaxAvail. }
{#X Update }
end; { of THeapMaxAvail }
{#Z+}
PHeapMemAvail = ^THeapMemAvail;
{#Z-}
THeapMemAvail = Object(TAppStatus)
{ A THeapMemAvail displays the total amount of heap memory available to
the application. It responds to a cmStatusUpdate event by calling
MemAvail and comparing the result to #Max#, then updating the view if
necessary. }
{#X THeapMaxAvail }
constructor Init (X, Y : Integer);
{ Init creates the view with the following text:
MemAvail = xxxx
where xxxx is the result returned by MemAvail. }
{#X Load }
procedure Update (Data : Pointer); virtual;
{ Update changes #Mem# to the current MemAvail and redraws the status
if necessary. }
private
Mem : LongInt;
{ Mem is the last available value reported by MemAvail. }
{#X Update }
end; { of THeapMemAvail }
{$ifndef cdPrintDoc}
{#Z+}
{$endif cdPrintDoc}
const
RStatus : TStreamRec = (
ObjType : idStatus;
VmtLink : Ofs(TypeOf(TStatus)^);
Load : @TStatus.Load;
Store : @TStatus.Store);
RStatusDlg : TStreamRec = (
ObjType : idStatusDlg;
VmtLink : Ofs(TypeOf(TStatusDlg)^);
Load : @TStatusDlg.Load;
Store : @TStatusDlg.Store);
RStatusMessageDlg : TStreamRec = (
ObjType : idStatusMessageDlg;
VmtLink : Ofs(TypeOf(TStatusMessageDlg)^);
Load : @TStatusMessageDlg.Load;
Store : @TStatusMessageDlg.Store);
RGauge : TStreamRec = (
ObjType : idGauge;
VmtLink : Ofs(TypeOf(TGauge)^);
Load : @TGauge.Load;
Store : @TGauge.Store);
RArrowGauge : TStreamRec = (
ObjType : idArrowGauge;
VmtLink : Ofs(TypeOf(TArrowGauge)^);
Load : @TArrowGauge.Load;
Store : @TArrowGauge.Store);
RBarGauge : TStreamRec = (
ObjType : idBarGauge;
VmtLink : Ofs(TypeOf(TBarGauge)^);
Load : @TBarGauge.Load;
Store : @TBarGauge.Store);
RPercentGauge : TStreamRec = (
ObjType : idPercentGauge;
VmtLink : Ofs(TypeOf(TPercentGauge)^);
Load : @TPercentGauge.Load;
Store : @TPercentGauge.Store);
RSpinnerGauge : TStreamRec = (
ObjType : idSpinnerGauge;
VmtLink : Ofs(TypeOf(TSpinnerGauge)^);
Load : @TSpinnerGauge.Load;
Store : @TSpinnerGauge.Store);
RAppStatus : TStreamRec = (
ObjType : idAppStatus;
VmtLink : Ofs(TypeOf(TAppStatus)^);
Load : @TAppStatus.Load;
Store : @TAppStatus.Store);
RHeapMinAvail : TStreamRec = (
ObjType : idHeapMinAvail;
VmtLink : Ofs(TypeOf(THeapMaxAvail)^);
Load : @THeapMaxAvail.Load;
Store : @THeapMaxAvail.Store);
RHeapMemAvail : TStreamRec = (
ObjType : idHeapMemAvail;
VmtLink : Ofs(TypeOf(THeapMemAvail)^);
Load : @THeapMemAvail.Load;
Store : @THeapMemAvail.Store);
{$ifndef cdPrintDoc}
{#Z-}
{$endif cdPrintDoc}
procedure RegisterStatuses;
{$ifndef cdPrintDoc}
{#F+}
{ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
ÝRegisterStatuses procedure (Statuses unit)Þ
ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß}
{#F-}
{$endif cdPrintDoc}
{ RegisterStatuses calls RegisterType for each of the status view and
status dialog object types defined in the tvStatus unit. After calling
RegisterStatuses, your application can read or write any of those types
with streams. }
implementation
uses
MsgBox, App;
{****************************************************************************}
{ Local procedures and functions }
{****************************************************************************}
{****************************************************************************}
{ TAppStatus Object }
{****************************************************************************}
{****************************************************************************}
{ TAppStatus.GetPalette }
{****************************************************************************}
function TAppStatus.GetPalette : PPalette;
const P : String[Length(CAppStatus)] = CAppStatus;
begin
GetPalette := PPalette(@P);
end;
{****************************************************************************}
{ TArrowGauge Object }
{****************************************************************************}
{****************************************************************************}
{ TArrowGauge.Init }
{****************************************************************************}
constructor TArrowGauge.Init (R : TRect; ACommand : Word; AMin, AMax : Word;
RightArrow : Boolean);
begin
if not TGauge.Init(R,ACommand,AMin,AMax) then
Fail;
Right := RightArrow;
end;
{****************************************************************************}
{ TArrowGauge.Load }
{****************************************************************************}
constructor TArrowGauge.Load (var S : TStream);
begin
if not TGauge.Load(S) then
Fail;
S.Read(Right,SizeOf(Right));
if (S.Status <> stOk) then
begin
TGauge.Done;
Fail;
end;
end;
{****************************************************************************}
{ TArrowGauge.Draw }
{****************************************************************************}
procedure TArrowGauge.Draw;
const Arrows : array[0..1] of Char = '<>';
var
B : TDrawBuffer;
C : Word;
Len : Byte;
begin
C := GetColor(1);
Len := Round(Size.X * Current/(Max - Min));
MoveChar(B,' ',C,Size.X);
if Right then
MoveChar(B,Arrows[Byte(Right)],C,Len)
else MoveChar(B[Size.X - Len],Arrows[Byte(Right)],C,Len);
WriteLine(0,0,Size.X,1,B);
end;
{****************************************************************************}
{ TArrowGauge.GetData }
{****************************************************************************}
procedure TArrowGauge.GetData (var Rec);
begin
PArrowGaugeRec(Rec)^.Min := Min;
PArrowGaugeRec(Rec)^.Max := Max;
PArrowGaugeRec(Rec)^.Count := Current;
PArrowGaugeRec(Rec)^.Right := Right;
end;
{****************************************************************************}
{ TArrowGauge.SetData }
{****************************************************************************}
procedure TArrowGauge.SetData (var Rec);
begin
Min := PArrowGaugeRec(Rec)^.Min;
Max := PArrowGaugeRec(Rec)^.Max;
Current := PArrowGaugeRec(Rec)^.Count;
Right := PArrowGaugeRec(Rec)^.Right;
end;
{****************************************************************************}
{ TArrowGauge.Store }
{****************************************************************************}
procedure TArrowGauge.Store (var S : TStream);
begin
TGauge.Store(S);
S.Write(Right,SizeOf(Right));
end;
{****************************************************************************}
{ TBarGauge Object }
{****************************************************************************}
{****************************************************************************}
{ TBarGauge.Draw }
{****************************************************************************}
procedure TBarGauge.Draw;
var
B : TDrawBuffer;
C : Word;
FillSize : Word;
PercentDone : LongInt;
S : String[4];
begin
{ fill entire view }
MoveChar(B,' ',GetColor(4),Size.X);
{ make progress bar }
C := GetColor(5);
FillSize := Round(Size.X * (Current / Max));
MoveChar(B,' ',C,FillSize);
{ display percent done }
PercentDone := Percent;
FormatStr(S,'%d%%',PercentDone);
if PercentDone < 50 then
C := GetColor(4);
FillSize := (Size.X - Length(S)) div 2;
MoveStr(B[FillSize],S,C);
WriteLine(0,0,Size.X,Size.Y,B);
end;
{****************************************************************************}
{ TBarGauge.GetPalette }
{****************************************************************************}
function TBarGauge.GetPalette : PPalette;
const
S : String[Length(CBarGauge)] = CBarGauge;
begin
GetPalette := PPalette(@S);
end;
{****************************************************************************}
{ TGauge Object }
{****************************************************************************}
{****************************************************************************}
{ TGauge.Init }
{****************************************************************************}
constructor TGauge.Init (R : TRect; ACommand : Word; AMin, AMax : LongInt);
begin
if not TStatus.Init(R,ACommand,'',1) then
Fail;
Min := AMin;
Max := AMax;
Current := Min;
end;
{****************************************************************************}
{ TGauge.Load }
{****************************************************************************}
constructor TGauge.Load (var S : TStream);
begin
if not TStatus.Load(S) then
Fail;
S.Read(Min,SizeOf(Min));
S.Read(Max,SizeOf(Max));
S.Read(Current,SizeOf(Current));
if S.Status <> stOk then
begin
TStatus.Done;
Fail;
end;
end;
{****************************************************************************}
{ TGauge.Draw }
{****************************************************************************}
procedure TGauge.Draw;
var
S : String;
B : TDrawBuffer;
begin
{ Blank the gauge }
MoveChar(B,' ',GetColor(1),Size.X);
WriteBuf(0,0,Size.X,Size.Y,B);
{ write current status }
FormatStr(S,'%d',Current);
MoveStr(B,S,GetColor(1));
WriteBuf(0,0,Size.X,Size.Y,B);
end;
{****************************************************************************}
{ TGauge.GetData }
{****************************************************************************}
procedure TGauge.GetData (var Rec);
begin
TGaugeRec(Rec).Min := Min;
TGaugeRec(Rec).Max := Max;
TGaugeRec(Rec).Current := Current;
end;
{****************************************************************************}
{ TGauge.Reset }
{****************************************************************************}
procedure TGauge.Reset;
begin
Current := Min;
DrawView;
end;
{****************************************************************************}
{ TGauge.SetData }
{****************************************************************************}
procedure TGauge.SetData (var Rec);
begin
Min := TGaugeRec(Rec).Min;
Max := TGaugeRec(Rec).Max;
Current := TGaugeRec(Rec).Current;
end;
{****************************************************************************}
{ TGauge.Store }
{****************************************************************************}
procedure TGauge.Store (var S : TStream);
begin
TStatus.Store(S);
S.Write(Min,SizeOf(Min));
S.Write(Max,SizeOf(Max));
S.Write(Current,SizeOf(Current));
end;
{****************************************************************************}
{ TGauge.Update }
{****************************************************************************}
procedure TGauge.Update (Data : Pointer);
begin
if Current < Max then
begin
Inc(Current);
DrawView;
end
else Message(@Self,evStatus,cmStatusDone,@Self);
end;
{****************************************************************************}
{ THeapMaxAvail Object }
{****************************************************************************}
{****************************************************************************}
{ THeapMaxAvail.Init }
{****************************************************************************}
constructor THeapMaxAvail.Init (X, Y : Integer);
var
R : TRect;
begin
R.Assign(X,Y,X+20,Y+1);
if not TAppStatus.Init(R,cmStatusUpdate,' MaxAvail = %d',1) then
Fail;
Max := -1;
end;
{****************************************************************************}
{ THeapMaxAvail.Update }
{****************************************************************************}
procedure THeapMaxAvail.Update (Data : Pointer);
var
M : LongInt;
begin
M := MaxAvail;
if (Max <> M) then
begin
Max := MaxAvail;
SetData(Max);
end;
end;
{****************************************************************************}
{ THeapMemAvail Object }
{****************************************************************************}
{****************************************************************************}
{ THeapMemAvail.Init }
{****************************************************************************}
constructor THeapMemAvail.Init (X, Y : Integer);
var
R : TRect;
begin
R.Assign(X,Y,X+20,Y+1);
if not TAppStatus.Init(R,cmStatusUpdate,' MemAvail = %d',1) then
Fail;
Mem := -1;
end;
{****************************************************************************}
{ THeapMemAvail.Update }
{****************************************************************************}
procedure THeapMemAvail.Update (Data : Pointer);
{ Total bytes available on the heap. May not be contiguous. }
var
M : LongInt;
begin
M := MemAvail;
if (Mem <> M) then
begin
Mem := M;
SetData(Mem);
end;
end;
{****************************************************************************}
{ TPercentGauge Object }
{****************************************************************************}
{****************************************************************************}
{ TPercentGauge.Draw }
{****************************************************************************}
procedure TPercentGauge.Draw;
var
B : TDrawBuffer;
C : Word;
S : String;
PercentDone : LongInt;
FillSize : Integer;
begin
C := GetColor(1);
MoveChar(B,' ',C,Size.X);
WriteLine(0,0,Size.X,Size.Y,B);
PercentDone := Percent;
FormatStr(S,'%d%%',PercentDone);