statuses.pas 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  1. {$V-}
  2. unit Statuses;
  3. {#Z+}
  4. { Free Vision Status Objects Unit
  5. Free VIsion
  6. Written by : Brad Williams, DVM
  7. Revision History
  8. 1.2.3 (96/04/13)
  9. - moved Pause and Resume to methods of TStatus leaving TStatus Pause and
  10. Resume "aware"
  11. - eliminated many bugs
  12. - moved Pause, Resume and Cancel from TStatusDlg to TStatus
  13. 1.2.1 (95/12/6)
  14. - minor typo corrections in opening unit documentation
  15. - F+ to Z+ around stream registration records
  16. - removed redundant sentence in TAppStatus definition
  17. - updated CBarStatus documentation and constant
  18. - removed TGauge.Init cross-reference from TSpinner.Init
  19. - added THeapMemAvail and RegistertvStatus documentation
  20. - numerous other documentation updates
  21. - changed all calls to Send to Message
  22. 1.2.0 (95/11/24)
  23. - conversion to Bsd format
  24. 1.1.0 (05/01/94)
  25. - initial WVS release
  26. Known Bugs
  27. ScanHelp Errors
  28. - sdXXXX constants help documentation doesn't show TStatusDlg and
  29. TMessageStatusDlg
  30. - ScanHelp produces garbage in evStatus help context
  31. tvStatus Bugs
  32. - CAppStatus may not be correct }
  33. {#Z-}
  34. { The tvStatus unit implements several views for providing information to
  35. the user which needs to be updated during program execution, such as a
  36. progress indicator, clock, heap viewer, gauges, etc. All tvStatus views
  37. respond to a new message event class, evStatus. An individual status view
  38. only processes an event with its associated command. }
  39. interface
  40. {$i platform.inc}
  41. {$ifdef PPC_FPC}
  42. {$H-}
  43. {$else}
  44. {$F+,O+,E+,N+}
  45. {$endif}
  46. {$X+,R-,I-,Q-,V-}
  47. {$ifndef OS_UNIX}
  48. {$S-}
  49. {$endif}
  50. uses
  51. FVCommon, FVConsts, Objects, Drivers, Views, Dialogs,
  52. Resource;
  53. const
  54. evStatus = $8000;
  55. { evStatus represents the event class all status views know how to
  56. respond to. }
  57. {#X Statuses }
  58. CStatus = #1#2#3;
  59. {$ifndef cdPrintDoc}
  60. {#F+}
  61. {ÝTStatus.CStatus palette
  62. ßßßßßßßßßßßßßßßßßßßßßßßßß}
  63. {#F-}
  64. {$endif cdPrintDoc}
  65. { Status views use the default palette, CStatus, to map onto the first three
  66. entries in the standard window palette. }
  67. {#F+}
  68. { 1 2 3
  69. ÉÍÍÍÍÑÍÍÍÍÑÍÍÍÍ»
  70. CStatus º 1 ³ 2 ³ 3 º
  71. ÈÍÍÑÍÏÍÍÑÍÏÍÍÑͼ
  72. Normal TextÄÄÄÙ ³ ³
  73. OtherÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³
  74. Highlighted TextÄÄÄÄÄÄÄÄÙ }
  75. {#F-}
  76. {#X TStatus }
  77. CAppStatus = #2#5#4;
  78. {$ifndef cdPrintDoc}
  79. {#F+}
  80. {ÝTAppStatus.CAppStatus palette
  81. ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß}
  82. {#F-}
  83. {$endif cdPrintDoc}
  84. { Status views which are inserted into the application rather than a dialog
  85. or window use the default palette, CAppStatus, to map onto the application
  86. object's palette. }
  87. {#F+}
  88. { 1 2 3
  89. ÉÍÍÍÍÑÍÍÍÍÑÍÍÍÍ»
  90. CAppStatus º 2 ³ 5 ³ 4 º
  91. ÈÍÍÑÍÏÍÍÑÍÏÍÍÑͼ
  92. Normal TextÄÄÄÄÄÄÙ ³ ³
  93. OtherÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³
  94. Highlighted TextÄÄÄÄÄÄÄÄÄÄÄÙ }
  95. {#F-}
  96. {#X tvStatus TAppStatus }
  97. CBarGauge = CStatus + #16#19;
  98. {$ifndef cdPrintDoc}
  99. {#F+}
  100. {ÝTBarGauge.CBarGauge palette
  101. ßßßßßßßßßßßßßßßßßßßßßßßßßßßßß}
  102. {#F-}
  103. {$endif cdPrintDoc}
  104. { TBarGauge's use the default palette, CBarGauge, to map onto the dialog or
  105. window owner's palette. }
  106. {#F+}
  107. { 1 2 3 4 5
  108. ÉÍÍÍÍÑÍÍÍÍÑÍÍÍÍÑÍÍÍÍÑÍÍÍÍ»
  109. CAppStatus º 2 ³ 5 ³ 4 ³ 16 ³ 19 º
  110. ÈÍÍÑÍÏÍÍÑÍÏÍÍÑÍÏÍÍÑÍÏÍÍÑͼ
  111. Normal TextÄÄÄÄÄÄÙ ³ ³ ³ ÀÄÄÄÄ filled in bar
  112. OtherÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ ³ ÀÄÄÄÄÄÄÄÄÄ empty bar
  113. Highlighted TextÄÄÄÄÄÄÄÄÄÄÄÙ }
  114. {#F-}
  115. {#X tvStatus TBarGauge }
  116. {#T sdXXXX }
  117. {$ifndef cdPrintDoc}
  118. {#F+}
  119. {ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
  120. Ý sdXXXX constants (STDDLG unit) Þ
  121. ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß}
  122. {#F-}
  123. {$endif cdNoPrintDoc}
  124. { sdXXXX constants are used to determine the types of buttons displayed in a
  125. #TStatusDlg# or #TStatusMessageDlg#. }
  126. {#F+}
  127. { Constant ³ Value ³ Meaning
  128. ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍØÍÍÍÍÍÍÍØÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ
  129. sdNone ³ $0000 ³ no buttons
  130. sdCancelButton ³ $0001 ³ show Cancel button
  131. sdPauseButton ³ $0002 ³ show Pause button
  132. sdResumeButton ³ $0004 ³ show Resume button
  133. sdAllButtons ³ $0008 ³ show Cancel, Pause and Resume
  134. ³ ³ buttons }
  135. {#Z+}
  136. sdNone = $0000;
  137. sdCancelButton = $0001;
  138. sdPauseButton = $0002;
  139. sdResumeButton = $0004;
  140. sdAllButtons = sdCancelButton or sdPauseButton or sdResumeButton;
  141. {#Z-}
  142. {#X tvStatus TStatusDlg TStatusMessageDlg }
  143. SpinChars : String[4] = '³/Ä\';
  144. { SpinChars are the characters used by a #TSpinnerGauge# when it is drawn.
  145. Only one character is displayed at a time. The string is cycled
  146. through then started over again until the view is disposed. }
  147. {#X tvStatus }
  148. sfPause = $F000;
  149. { sfPause is an additional state flag used internally by status views to
  150. indicate they are in a paused state and should not respond to their
  151. command. }
  152. type
  153. {#Z+}
  154. PStatus = ^TStatus;
  155. {#Z-}
  156. TStatus = Object(TParamText)
  157. { TStatus is the base object type from which all status views descend.
  158. Status views are used to display information that will change at
  159. run-time based upon some state or process in the application, such as
  160. printing.
  161. All status views that are to be inserted into the application should
  162. descend from #TAppStatus# for proper color mapping. }
  163. Command : Word;
  164. { Command is the only command the status view will respond to. When
  165. the status view receives an evStatus event it checks the value of the
  166. Event.Command field against Command before handling the event. }
  167. {#X HandleEvent }
  168. constructor Init (R : TRect; ACommand : Word; AText : String;
  169. AParamCount : Integer);
  170. { Init calls the inherited constructor then sets #Command# to ACommand.
  171. If an error occurs Init fails. }
  172. {#X Load }
  173. constructor Load (var S : TStream);
  174. { Load calls the inherited constructor then reads #Command# from the
  175. stream.
  176. If an error occurs Load fails. }
  177. {#X Store Init }
  178. function Cancel : Boolean; virtual;
  179. { Cancel should prompt the user when necessary for validation of
  180. canceling the process which the status view is displaying. If the
  181. user elects to continue the process Cancel must return False,
  182. otherwise Cancel must return True. }
  183. {#X Pause Resume }
  184. function GetPalette : PPalette; virtual;
  185. { GetPalette returns a pointer to the default status view palette,
  186. #CStatus#. }
  187. {#X TAppStatus CAppStatus }
  188. procedure HandleEvent (var Event : TEvent); virtual;
  189. { HandleEvent captures any #evStatus# messages with its command value
  190. equal to #Command#, then calls #Update# with Data set to
  191. Event.InfoPtr. If the State field has its #sfPause# bit set, the
  192. view ignores the event. }
  193. procedure Pause; virtual;
  194. { Pause sends an evStatus message to the application with Event.Command
  195. set to cmStatusPause and Event.InfoPtr set to #Status#^.Command. The
  196. #Status# view's sfPause bit of the State flag is set by calling
  197. SetState. In the paused state, the status view does not respond to
  198. its associated command. }
  199. {#X Resume sdXXXX Cancel }
  200. procedure Reset; virtual;
  201. { Reset causes the status view to be reset to its beginning or default
  202. value, then be redrawn. Reset is used after an event is aborted
  203. which can only be performed in its entirety. }
  204. procedure Resume; virtual;
  205. { Resume is called in response to pressing the Resume button. Resume
  206. sends an evStatus message to the application with Event.Command set
  207. to cmStatusPause and Event.InfoPtr set to #Status#^.Command. The
  208. Status view's sfPause bit is turned off by calling SetState. }
  209. {#X Pause sdXXXX Cancel }
  210. procedure Store (var S : TStream); { store should never be virtual;}
  211. { Store calls the inherited Store method then writes #Command# to the
  212. stream. }
  213. {#X Load }
  214. procedure Update (Data : Pointer); virtual;
  215. { Update changes the status' displayed text as necessary based on
  216. Data. }
  217. {#X Command HandleEvent }
  218. end; { of TStatus }
  219. {#Z+}
  220. PStatusDlg = ^TStatusDlg;
  221. {#Z-}
  222. TStatusDlg = Object(TDialog)
  223. { A TStatusDlg displays a status view and optional buttons. It may be
  224. used to display any status message and optionally provide end user
  225. cancelation or pausing of an ongoing operation, such as printing.
  226. All status views that are to be inserted into a window or dialog should
  227. descend from #TStatus# for proper color mapping. }
  228. Status : PStatus;
  229. { Status is the key status view for the dialog. When a cmStatusPause
  230. command is broadcast in response to pressing the pause button,
  231. Event.InfoPtr is set to point to the command associated with Status. }
  232. {#X TStatus cmXXXX }
  233. constructor Init (ATitle : TTitleStr; AStatus : PStatus; AFlags : Word);
  234. { Init calls the inherited constructor to create the dialog and sets
  235. the EventMask to handle #evStatus# events. AStatus is assigned to
  236. #Status# and inserted into the dialog at position 2,2.
  237. The dialog is anchored at AStatus^.Origin and its size is at least
  238. AStatus^.Size + 2 in both dimensions. The actual size is determined
  239. by the AFlags byte. The #sdXXXX# constants should be used to signify
  240. which buttons to display.
  241. If an error occurs Init fails. }
  242. {#X TStatus.Pause TStatus.Resume }
  243. constructor Load (var S : TStream);
  244. { Load calls the inherited constructor then loads #Status#.
  245. If an error occurs Load fails. }
  246. {#X Store }
  247. procedure Cancel (ACommand : Word); virtual;
  248. { Cancel sends an evStatus message to the Application object with
  249. command set to cmCancel and InfoPtr set to the calling status view's
  250. command, then calls the inherited Cancel method. }
  251. {#X TBSDDialog.Cancel }
  252. procedure HandleEvent (var Event : TEvent); virtual;
  253. { All evStatus events are accepted by the dialog and sent to each
  254. subview in Z-order until cleared.
  255. If the dialog recieves an evCommand or evBroadcast event with the
  256. Command parameter set to cmCancel, HandleEvent sends an #evStatus#
  257. message to the Application variable with Event.Command set to the
  258. cmStatusCancel and Event.InfoPtr set to the #Status#.Command and
  259. disposes of itself.
  260. When a pause button is included, a cmStatusPause broadcast event is
  261. associated with the button. When the button is pressed a call to
  262. #TStatus.Pause# results. The status view is inactivated until it
  263. receives an evStatus event with a commond of cmStatusResume and
  264. Event.InfoPtr set to the status view's Command value. When a pause
  265. button is used, the application should respond to the evStatus event
  266. (with Event.Command of cmStatusPause) appropriately, then dispatch a
  267. cmStatusResume evStatus event when ready to resume activity. }
  268. {#X TStatus.Command }
  269. procedure InsertButtons (AFlags : Word); virtual;
  270. { InsertButtons enlarges the dialog to the necessary size and inserts
  271. the buttons specified in AFlags into the last row of the dialog. }
  272. procedure Store (var S : TStream); { store should never be virtual;}
  273. { Store calls the inherited Store method then writes #Status# to the
  274. stream. }
  275. {#X Load }
  276. end; { of TStatusDlg }
  277. {#Z+}
  278. PStatusMessageDlg = ^TStatusMessageDlg;
  279. {#Z-}
  280. TStatusMessageDlg = Object(TStatusDlg)
  281. { A TStatusMessageDlg displays a message as static text with a status
  282. view on the line below it.
  283. All status views that are to be inserted into a window or dialog should
  284. descend from #TStatus# for proper color mapping. }
  285. constructor Init (ATitle : TTitleStr; AStatus : PStatus; AFlags : Word;
  286. AMessage : String);
  287. { Init calls the inherited constructor then inserts a TStaticText view
  288. containing AMessage at the top line of the dialog.
  289. The size of the dialog is determined by the size of the AStatus. The
  290. dialog is anchored at AStatus^.Origin and is of at least
  291. AStatus^.Size + 2 in heighth and width. The exact width and heighth
  292. are determined by AOptions.
  293. AFlags contains flags which determine the buttons to be displayed
  294. in the dialog.
  295. If an error occurs Init fails. }
  296. end; { of TStatusMessageDlg }
  297. {#Z+}
  298. PGauge = ^TGauge;
  299. {#Z-}
  300. TGauge = Object(TStatus)
  301. { A gauge is used to represent the current numerical position within a
  302. range of values. When Current equals Max a gauge dispatches an
  303. #evStatus# event with the command set to cmStatusDone to the
  304. Application object. }
  305. Min : LongInt;
  306. { Min is the minimum value which #Current# may be set to. }
  307. {#X Max }
  308. Max : LongInt;
  309. { Max is the maximum value which #Current# may be set to. }
  310. {#X Min }
  311. Current : LongInt;
  312. { Current is the current value represented in the gauge. }
  313. {#X Max Min }
  314. constructor Init (R : TRect; ACommand : Word; AMin, AMax : LongInt);
  315. { Init calls the inherited constructor then sets #Min# and #Max# to
  316. AMin and AMax, respectively. #Current# is set to AMin.
  317. If an error occurs Init fails. }
  318. {#X Load }
  319. constructor Load (var S : TStream);
  320. { Load calls the inherited constructor then reads #Min#, #Max# and
  321. #Current# from the stream.
  322. If an error occurs Load fails. }
  323. {#X Init Store }
  324. procedure Draw; virtual;
  325. { Draw writes the following to the screen: }
  326. {#F+}
  327. {
  328. Min = XXX Max = XXX Current = XXX }
  329. {#F-}
  330. { where XXX are the current values of the corresponding variables. }
  331. procedure GetData (var Rec); virtual;
  332. { GetData assumes Rec is a #TGaugeRec# and returns the current settings
  333. of the gauge. }
  334. {#X SetData }
  335. procedure Reset; virtual;
  336. { Reset sets #Current# to #Min# then redraws the status view. }
  337. {#X TStatus.Reset }
  338. procedure SetData (var Rec); virtual;
  339. { SetData assumes Rec is a #TGaugeRec# and sets the gauge's variables
  340. accordingly. }
  341. {#X GetData }
  342. procedure Store (var S : TStream); { store should never be virtual;}
  343. { Store calls the inherited Store method then writes #Min#, #Max# and
  344. #Current# to the stream. }
  345. {#X Load }
  346. procedure Update (Data : Pointer); virtual;
  347. { Update increments #Current#. }
  348. end; { of TGauge }
  349. {#Z+}
  350. PGaugeRec = ^TGaugeRec;
  351. {#Z-}
  352. TGaugeRec = record
  353. { A TGaugeRec is used to set and get a #TGauge#'s variables. }
  354. {#X TGauge.GetData TGauge.SetData }
  355. Min, Max, Current : LongInt;
  356. end; { of TGaugeRec }
  357. {#Z+}
  358. PArrowGauge = ^TArrowGauge;
  359. {#Z-}
  360. TArrowGauge = Object(TGauge)
  361. { An arrow gauge draws a progressively larger series of arrows across the
  362. view. If Right is True, the arrows are right facing, '>', and are
  363. drawn from left to right. If Right is False, the arrows are left
  364. facing, '<', and are drawn from right to left. }
  365. Right : Boolean;
  366. { Right determines the direction of arrow used and the direction which
  367. the status view is filled. If Right is True, the arrows are right
  368. facing, '>', and are drawn from left to right. If Right is False,
  369. the arrows are left facing, '<', and are drawn from right to left. }
  370. {#X Draw }
  371. constructor Init (R : TRect; ACommand : Word; AMin, AMax : Word;
  372. RightArrow : Boolean);
  373. { Init calls the inherited constructor then sets #Right# to RightArrow.
  374. If an error occurs Init fails. }
  375. {#X Load }
  376. constructor Load (var S : TStream);
  377. { Load calls the inherited constructor then reads #Right# from the
  378. stream.
  379. If an error occurs Load fails. }
  380. {#X Init Store }
  381. procedure Draw; virtual;
  382. { Draw fills the Current / Max percent of the view with arrows. }
  383. {#X Right }
  384. procedure GetData (var Rec); virtual;
  385. { GetData assumes Rec is a #TArrowGaugeRec# and returns the current
  386. settings of the views variables. }
  387. {#X SetData }
  388. procedure SetData (var Rec); virtual;
  389. { SetData assumes Rec is a #TArrowGaugeRec# and sets the view's
  390. variables accordingly. }
  391. {#X GetData }
  392. procedure Store (var S : TStream); { store should never be virtual;}
  393. { Store calls the inherited Store method then writes #Right# to the
  394. stream. }
  395. {#X Load }
  396. end; { of TArrowGauge }
  397. {#Z+}
  398. PArrowGaugeRec = ^TArrowGaugeRec;
  399. {#Z-}
  400. TArrowGaugeRec = record
  401. { A TArrowGaugeRec is used to set and get the variables of a
  402. #TArrowGauge#. }
  403. {#X TArrowGauge.GetData TArrowGauge.SetData }
  404. Min, Max, Count : LongInt;
  405. Right : Boolean;
  406. end; { of TGaugeRec }
  407. {#Z+}
  408. PPercentGauge = ^TPercentGauge;
  409. {#Z-}
  410. TPercentGauge = Object(TGauge)
  411. { A TPercentGauge displays a numerical percentage as returned by
  412. #Percent# followed by a '%' sign. }
  413. function Percent : Integer; virtual;
  414. { Percent returns the whole number value of (Current / Max) * 100. }
  415. {#X TGauge.Current TGauge.Max }
  416. procedure Draw; virtual;
  417. { Draw writes the current percentage to the screen. }
  418. {#X Percent }
  419. end; { of TPercentGauge }
  420. {#Z+}
  421. PBarGauge = ^TBarGauge;
  422. {#Z-}
  423. TBarGauge = Object(TPercentGauge)
  424. { A TBarGauge displays a bar which increases in size from the left to
  425. the right of the view as Current increases. A numeric percentage
  426. representing the value of (Current / Max) * 100 is displayed in the
  427. center of the bar. }
  428. {#x TPercentGauge.Percent }
  429. procedure Draw; virtual;
  430. { Draw draws the bar and percentage to the screen representing the
  431. current status of the view's variables. }
  432. {#X TGauge.Update }
  433. function GetPalette : PPalette; virtual;
  434. { GetPalette returns a pointer to the default status view palette,
  435. #CBarStatus#. }
  436. end; { of TBarGauge }
  437. {#Z+}
  438. PSpinnerGauge = ^TSpinnerGauge;
  439. {#Z-}
  440. TSpinnerGauge = Object(TGauge)
  441. { A TSpinnerGauge displays a series of characters in one spot on the
  442. screen giving the illusion of a spinning line. }
  443. constructor Init (X, Y : Integer; ACommand : Word);
  444. { Init calls the inherited constructor with AMin set to 0 and AMax set
  445. to 4. }
  446. procedure Draw; virtual;
  447. { Draw uses the #SpinChars# variable to draw the view's Current
  448. character. }
  449. {#X Update }
  450. procedure HandleEvent (var Event : TEvent); virtual;
  451. { HandleEvent calls TStatus.HandleEvent so that a cmStatusDone event
  452. is not generated when Current equals Max. }
  453. {#X TGauge.Current TGauge.Max }
  454. procedure Update (Data : Pointer); virtual;
  455. { Update increments Current until Current equals Max, when it resets
  456. Current to Min. }
  457. {#X Draw HandleEvent }
  458. end; { of TSpinnerGauge }
  459. {#Z+}
  460. PAppStatus = ^TAppStatus;
  461. {#Z-}
  462. TAppStatus = Object(TStatus)
  463. { TAppStatus is a base object which implements color control for status
  464. views that are normally inserted in the Application object. }
  465. {#X TStatus }
  466. function GetPalette : PPalette; virtual;
  467. { GetPalette returns a pointer to the default application status view
  468. palette, #CAppStatus#. }
  469. {#X TStatus CStatus }
  470. end; { of TAppStatus }
  471. {#Z+}
  472. PHeapMaxAvail = ^THeapMaxAvail;
  473. {#Z-}
  474. THeapMaxAvail = Object(TAppStatus)
  475. { A THeapMaxAvail displays the largest available contiguous area of heap
  476. memory. It responds to a cmStatusUpdate event by calling MaxAvail and
  477. comparing the result to #Max#, then updating the view if necessary. }
  478. {#X THeapMemAvail }
  479. constructor Init (X, Y : Integer);
  480. { Init creates the view with the following text:
  481. MaxAvail = xxxx
  482. where xxxx is the result returned by MaxAvail. }
  483. procedure Update (Data : Pointer); virtual;
  484. { Update changes #Mem# to the current MemAvail and redraws the status
  485. if necessary. }
  486. private
  487. Max : LongInt;
  488. { Max is the last reported value from MaxAvail. }
  489. {#X Update }
  490. end; { of THeapMaxAvail }
  491. {#Z+}
  492. PHeapMemAvail = ^THeapMemAvail;
  493. {#Z-}
  494. THeapMemAvail = Object(TAppStatus)
  495. { A THeapMemAvail displays the total amount of heap memory available to
  496. the application. It responds to a cmStatusUpdate event by calling
  497. MemAvail and comparing the result to #Max#, then updating the view if
  498. necessary. }
  499. {#X THeapMaxAvail }
  500. constructor Init (X, Y : Integer);
  501. { Init creates the view with the following text:
  502. MemAvail = xxxx
  503. where xxxx is the result returned by MemAvail. }
  504. {#X Load }
  505. procedure Update (Data : Pointer); virtual;
  506. { Update changes #Mem# to the current MemAvail and redraws the status
  507. if necessary. }
  508. private
  509. Mem : LongInt;
  510. { Mem is the last available value reported by MemAvail. }
  511. {#X Update }
  512. end; { of THeapMemAvail }
  513. {$ifndef cdPrintDoc}
  514. {#Z+}
  515. {$endif cdPrintDoc}
  516. const
  517. RStatus : TStreamRec = (
  518. ObjType : idStatus;
  519. VmtLink : Ofs(TypeOf(TStatus)^);
  520. Load : @TStatus.Load;
  521. Store : @TStatus.Store);
  522. RStatusDlg : TStreamRec = (
  523. ObjType : idStatusDlg;
  524. VmtLink : Ofs(TypeOf(TStatusDlg)^);
  525. Load : @TStatusDlg.Load;
  526. Store : @TStatusDlg.Store);
  527. RStatusMessageDlg : TStreamRec = (
  528. ObjType : idStatusMessageDlg;
  529. VmtLink : Ofs(TypeOf(TStatusMessageDlg)^);
  530. Load : @TStatusMessageDlg.Load;
  531. Store : @TStatusMessageDlg.Store);
  532. RGauge : TStreamRec = (
  533. ObjType : idGauge;
  534. VmtLink : Ofs(TypeOf(TGauge)^);
  535. Load : @TGauge.Load;
  536. Store : @TGauge.Store);
  537. RArrowGauge : TStreamRec = (
  538. ObjType : idArrowGauge;
  539. VmtLink : Ofs(TypeOf(TArrowGauge)^);
  540. Load : @TArrowGauge.Load;
  541. Store : @TArrowGauge.Store);
  542. RBarGauge : TStreamRec = (
  543. ObjType : idBarGauge;
  544. VmtLink : Ofs(TypeOf(TBarGauge)^);
  545. Load : @TBarGauge.Load;
  546. Store : @TBarGauge.Store);
  547. RPercentGauge : TStreamRec = (
  548. ObjType : idPercentGauge;
  549. VmtLink : Ofs(TypeOf(TPercentGauge)^);
  550. Load : @TPercentGauge.Load;
  551. Store : @TPercentGauge.Store);
  552. RSpinnerGauge : TStreamRec = (
  553. ObjType : idSpinnerGauge;
  554. VmtLink : Ofs(TypeOf(TSpinnerGauge)^);
  555. Load : @TSpinnerGauge.Load;
  556. Store : @TSpinnerGauge.Store);
  557. RAppStatus : TStreamRec = (
  558. ObjType : idAppStatus;
  559. VmtLink : Ofs(TypeOf(TAppStatus)^);
  560. Load : @TAppStatus.Load;
  561. Store : @TAppStatus.Store);
  562. RHeapMinAvail : TStreamRec = (
  563. ObjType : idHeapMinAvail;
  564. VmtLink : Ofs(TypeOf(THeapMaxAvail)^);
  565. Load : @THeapMaxAvail.Load;
  566. Store : @THeapMaxAvail.Store);
  567. RHeapMemAvail : TStreamRec = (
  568. ObjType : idHeapMemAvail;
  569. VmtLink : Ofs(TypeOf(THeapMemAvail)^);
  570. Load : @THeapMemAvail.Load;
  571. Store : @THeapMemAvail.Store);
  572. {$ifndef cdPrintDoc}
  573. {#Z-}
  574. {$endif cdPrintDoc}
  575. procedure RegisterStatuses;
  576. {$ifndef cdPrintDoc}
  577. {#F+}
  578. {ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
  579. ÝRegisterStatuses procedure (Statuses unit)Þ
  580. ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß}
  581. {#F-}
  582. {$endif cdPrintDoc}
  583. { RegisterStatuses calls RegisterType for each of the status view and
  584. status dialog object types defined in the tvStatus unit. After calling
  585. RegisterStatuses, your application can read or write any of those types
  586. with streams. }
  587. implementation
  588. uses
  589. MsgBox, App;
  590. {****************************************************************************}
  591. { Local procedures and functions }
  592. {****************************************************************************}
  593. {****************************************************************************}
  594. { TAppStatus Object }
  595. {****************************************************************************}
  596. {****************************************************************************}
  597. { TAppStatus.GetPalette }
  598. {****************************************************************************}
  599. function TAppStatus.GetPalette : PPalette;
  600. const P : String[Length(CAppStatus)] = CAppStatus;
  601. begin
  602. GetPalette := PPalette(@P);
  603. end;
  604. {****************************************************************************}
  605. { TArrowGauge Object }
  606. {****************************************************************************}
  607. {****************************************************************************}
  608. { TArrowGauge.Init }
  609. {****************************************************************************}
  610. constructor TArrowGauge.Init (R : TRect; ACommand : Word; AMin, AMax : Word;
  611. RightArrow : Boolean);
  612. begin
  613. if not TGauge.Init(R,ACommand,AMin,AMax) then
  614. Fail;
  615. Right := RightArrow;
  616. end;
  617. {****************************************************************************}
  618. { TArrowGauge.Load }
  619. {****************************************************************************}
  620. constructor TArrowGauge.Load (var S : TStream);
  621. begin
  622. if not TGauge.Load(S) then
  623. Fail;
  624. S.Read(Right,SizeOf(Right));
  625. if (S.Status <> stOk) then
  626. begin
  627. TGauge.Done;
  628. Fail;
  629. end;
  630. end;
  631. {****************************************************************************}
  632. { TArrowGauge.Draw }
  633. {****************************************************************************}
  634. procedure TArrowGauge.Draw;
  635. const Arrows : array[0..1] of Char = '<>';
  636. var
  637. B : TDrawBuffer;
  638. C : Word;
  639. Len : Byte;
  640. begin
  641. C := GetColor(1);
  642. Len := Round(Size.X * Current/(Max - Min));
  643. MoveChar(B,' ',C,Size.X);
  644. if Right then
  645. MoveChar(B,Arrows[Byte(Right)],C,Len)
  646. else MoveChar(B[Size.X - Len],Arrows[Byte(Right)],C,Len);
  647. WriteLine(0,0,Size.X,1,B);
  648. end;
  649. {****************************************************************************}
  650. { TArrowGauge.GetData }
  651. {****************************************************************************}
  652. procedure TArrowGauge.GetData (var Rec);
  653. begin
  654. PArrowGaugeRec(Rec)^.Min := Min;
  655. PArrowGaugeRec(Rec)^.Max := Max;
  656. PArrowGaugeRec(Rec)^.Count := Current;
  657. PArrowGaugeRec(Rec)^.Right := Right;
  658. end;
  659. {****************************************************************************}
  660. { TArrowGauge.SetData }
  661. {****************************************************************************}
  662. procedure TArrowGauge.SetData (var Rec);
  663. begin
  664. Min := PArrowGaugeRec(Rec)^.Min;
  665. Max := PArrowGaugeRec(Rec)^.Max;
  666. Current := PArrowGaugeRec(Rec)^.Count;
  667. Right := PArrowGaugeRec(Rec)^.Right;
  668. end;
  669. {****************************************************************************}
  670. { TArrowGauge.Store }
  671. {****************************************************************************}
  672. procedure TArrowGauge.Store (var S : TStream);
  673. begin
  674. TGauge.Store(S);
  675. S.Write(Right,SizeOf(Right));
  676. end;
  677. {****************************************************************************}
  678. { TBarGauge Object }
  679. {****************************************************************************}
  680. {****************************************************************************}
  681. { TBarGauge.Draw }
  682. {****************************************************************************}
  683. procedure TBarGauge.Draw;
  684. var
  685. B : TDrawBuffer;
  686. C : Word;
  687. FillSize : Word;
  688. PercentDone : LongInt;
  689. S : String[4];
  690. begin
  691. { fill entire view }
  692. MoveChar(B,' ',GetColor(4),Size.X);
  693. { make progress bar }
  694. C := GetColor(5);
  695. FillSize := Round(Size.X * (Current / Max));
  696. MoveChar(B,' ',C,FillSize);
  697. { display percent done }
  698. PercentDone := Percent;
  699. FormatStr(S,'%d%%',PercentDone);
  700. if PercentDone < 50 then
  701. C := GetColor(4);
  702. FillSize := (Size.X - Length(S)) div 2;
  703. MoveStr(B[FillSize],S,C);
  704. WriteLine(0,0,Size.X,Size.Y,B);
  705. end;
  706. {****************************************************************************}
  707. { TBarGauge.GetPalette }
  708. {****************************************************************************}
  709. function TBarGauge.GetPalette : PPalette;
  710. const
  711. S : String[Length(CBarGauge)] = CBarGauge;
  712. begin
  713. GetPalette := PPalette(@S);
  714. end;
  715. {****************************************************************************}
  716. { TGauge Object }
  717. {****************************************************************************}
  718. {****************************************************************************}
  719. { TGauge.Init }
  720. {****************************************************************************}
  721. constructor TGauge.Init (R : TRect; ACommand : Word; AMin, AMax : LongInt);
  722. begin
  723. if not TStatus.Init(R,ACommand,'',1) then
  724. Fail;
  725. Min := AMin;
  726. Max := AMax;
  727. Current := Min;
  728. end;
  729. {****************************************************************************}
  730. { TGauge.Load }
  731. {****************************************************************************}
  732. constructor TGauge.Load (var S : TStream);
  733. begin
  734. if not TStatus.Load(S) then
  735. Fail;
  736. S.Read(Min,SizeOf(Min));
  737. S.Read(Max,SizeOf(Max));
  738. S.Read(Current,SizeOf(Current));
  739. if S.Status <> stOk then
  740. begin
  741. TStatus.Done;
  742. Fail;
  743. end;
  744. end;
  745. {****************************************************************************}
  746. { TGauge.Draw }
  747. {****************************************************************************}
  748. procedure TGauge.Draw;
  749. var
  750. S : String;
  751. B : TDrawBuffer;
  752. begin
  753. { Blank the gauge }
  754. MoveChar(B,' ',GetColor(1),Size.X);
  755. WriteBuf(0,0,Size.X,Size.Y,B);
  756. { write current status }
  757. FormatStr(S,'%d',Current);
  758. MoveStr(B,S,GetColor(1));
  759. WriteBuf(0,0,Size.X,Size.Y,B);
  760. end;
  761. {****************************************************************************}
  762. { TGauge.GetData }
  763. {****************************************************************************}
  764. procedure TGauge.GetData (var Rec);
  765. begin
  766. TGaugeRec(Rec).Min := Min;
  767. TGaugeRec(Rec).Max := Max;
  768. TGaugeRec(Rec).Current := Current;
  769. end;
  770. {****************************************************************************}
  771. { TGauge.Reset }
  772. {****************************************************************************}
  773. procedure TGauge.Reset;
  774. begin
  775. Current := Min;
  776. DrawView;
  777. end;
  778. {****************************************************************************}
  779. { TGauge.SetData }
  780. {****************************************************************************}
  781. procedure TGauge.SetData (var Rec);
  782. begin
  783. Min := TGaugeRec(Rec).Min;
  784. Max := TGaugeRec(Rec).Max;
  785. Current := TGaugeRec(Rec).Current;
  786. end;
  787. {****************************************************************************}
  788. { TGauge.Store }
  789. {****************************************************************************}
  790. procedure TGauge.Store (var S : TStream);
  791. begin
  792. TStatus.Store(S);
  793. S.Write(Min,SizeOf(Min));
  794. S.Write(Max,SizeOf(Max));
  795. S.Write(Current,SizeOf(Current));
  796. end;
  797. {****************************************************************************}
  798. { TGauge.Update }
  799. {****************************************************************************}
  800. procedure TGauge.Update (Data : Pointer);
  801. begin
  802. if Current < Max then
  803. begin
  804. Inc(Current);
  805. DrawView;
  806. end
  807. else Message(@Self,evStatus,cmStatusDone,@Self);
  808. end;
  809. {****************************************************************************}
  810. { THeapMaxAvail Object }
  811. {****************************************************************************}
  812. {****************************************************************************}
  813. { THeapMaxAvail.Init }
  814. {****************************************************************************}
  815. constructor THeapMaxAvail.Init (X, Y : Integer);
  816. var
  817. R : TRect;
  818. begin
  819. R.Assign(X,Y,X+20,Y+1);
  820. if not TAppStatus.Init(R,cmStatusUpdate,' MaxAvail = %d',1) then
  821. Fail;
  822. Max := -1;
  823. end;
  824. {****************************************************************************}
  825. { THeapMaxAvail.Update }
  826. {****************************************************************************}
  827. procedure THeapMaxAvail.Update (Data : Pointer);
  828. var
  829. M : LongInt;
  830. begin
  831. M := MaxAvail;
  832. if (Max <> M) then
  833. begin
  834. Max := MaxAvail;
  835. SetData(Max);
  836. end;
  837. end;
  838. {****************************************************************************}
  839. { THeapMemAvail Object }
  840. {****************************************************************************}
  841. {****************************************************************************}
  842. { THeapMemAvail.Init }
  843. {****************************************************************************}
  844. constructor THeapMemAvail.Init (X, Y : Integer);
  845. var
  846. R : TRect;
  847. begin
  848. R.Assign(X,Y,X+20,Y+1);
  849. if not TAppStatus.Init(R,cmStatusUpdate,' MemAvail = %d',1) then
  850. Fail;
  851. Mem := -1;
  852. end;
  853. {****************************************************************************}
  854. { THeapMemAvail.Update }
  855. {****************************************************************************}
  856. procedure THeapMemAvail.Update (Data : Pointer);
  857. { Total bytes available on the heap. May not be contiguous. }
  858. var
  859. M : LongInt;
  860. begin
  861. M := MemAvail;
  862. if (Mem <> M) then
  863. begin
  864. Mem := M;
  865. SetData(Mem);
  866. end;
  867. end;
  868. {****************************************************************************}
  869. { TPercentGauge Object }
  870. {****************************************************************************}
  871. {****************************************************************************}
  872. { TPercentGauge.Draw }
  873. {****************************************************************************}
  874. procedure TPercentGauge.Draw;
  875. var
  876. B : TDrawBuffer;
  877. C : Word;
  878. S : String;
  879. PercentDone : LongInt;
  880. FillSize : Integer;
  881. begin
  882. C := GetColor(1);
  883. MoveChar(B,' ',C,Size.X);
  884. WriteLine(0,0,Size.X,Size.Y,B);
  885. PercentDone := Percent;
  886. FormatStr(S,'%d%%',PercentDone);
  887. MoveStr(B[(Size.X - Byte(S[0])) div 2],S,C);
  888. WriteLine(0,0,Size.X,Size.Y,B);
  889. end;
  890. {****************************************************************************}
  891. { TPercentGauge.Percent }
  892. {****************************************************************************}
  893. function TPercentGauge.Percent : Integer;
  894. { Returns percent as a whole integer Current of Max }
  895. begin
  896. Percent := Round((Current/Max) * 100);
  897. end;
  898. {****************************************************************************}
  899. { TSpinnerGauge Object }
  900. {****************************************************************************}
  901. {****************************************************************************}
  902. { TSpinnerGauge.Init }
  903. {****************************************************************************}
  904. constructor TSpinnerGauge.Init (X, Y : Integer; ACommand : Word);
  905. var R : TRect;
  906. begin
  907. R.Assign(X,Y,X+1,Y+1);
  908. if not TGauge.Init(R,ACommand,1,4) then
  909. Fail;
  910. end;
  911. {****************************************************************************}
  912. { TSpinnerGauge.Draw }
  913. {****************************************************************************}
  914. procedure TSpinnerGauge.Draw;
  915. var
  916. B : TDrawBuffer;
  917. C : Word;
  918. begin
  919. C := GetColor(1);
  920. MoveChar(B,' ',C,Size.X);
  921. WriteLine(0,0,Size.X,Size.Y,B);
  922. MoveChar(B[Size.X div 2],SpinChars[Current],C,1);
  923. WriteLine(0,0,Size.X,Size.Y,B);
  924. end;
  925. {****************************************************************************}
  926. { TSpinnerGauge.HandleEvent }
  927. {****************************************************************************}
  928. procedure TSpinnerGauge.HandleEvent (var Event : TEvent);
  929. begin
  930. TStatus.HandleEvent(Event);
  931. end;
  932. {****************************************************************************}
  933. { TSpinnerGauge.Update }
  934. {****************************************************************************}
  935. procedure TSpinnerGauge.Update (Data : Pointer);
  936. begin
  937. if Current = Max then
  938. Current := Min
  939. else Inc(Current);
  940. DrawView;
  941. end;
  942. {****************************************************************************}
  943. { TStatus Object }
  944. {****************************************************************************}
  945. {****************************************************************************}
  946. { TStatus.Init }
  947. {****************************************************************************}
  948. constructor TStatus.Init (R : TRect; ACommand : Word; AText : String;
  949. AParamCount : Integer);
  950. begin
  951. if (not TParamText.Init(R,AText,AParamCount)) then
  952. Fail;
  953. EventMask := EventMask or evStatus;
  954. Command := ACommand;
  955. end;
  956. {****************************************************************************}
  957. { TStatus.Load }
  958. {****************************************************************************}
  959. constructor TStatus.Load (var S : TStream);
  960. begin
  961. if not TParamText.Load(S) then
  962. Fail;
  963. S.Read(Command,SizeOf(Command));
  964. if (S.Status <> stOk) then
  965. begin
  966. TParamText.Done;
  967. Fail;
  968. end;
  969. end;
  970. {****************************************************************************}
  971. { TStatus.Cancel }
  972. {****************************************************************************}
  973. function TStatus.Cancel : Boolean;
  974. begin
  975. Cancel := True;
  976. end;
  977. {****************************************************************************}
  978. { TStatus.GetPalette }
  979. {****************************************************************************}
  980. function TStatus.GetPalette : PPalette;
  981. const
  982. P : String[Length(CStatus)] = CStatus;
  983. begin
  984. GetPalette := PPalette(@P);
  985. end;
  986. {****************************************************************************}
  987. { TStatus.HandleEvent }
  988. {****************************************************************************}
  989. procedure TStatus.HandleEvent (var Event : TEvent);
  990. begin
  991. if (Event.What = evCommand) and (Event.Command = cmStatusPause) then
  992. begin
  993. Pause;
  994. ClearEvent(Event);
  995. end;
  996. case Event.What of
  997. evStatus :
  998. case Event.Command of
  999. cmStatusDone :
  1000. if (Event.InfoPtr = @Self) then
  1001. begin
  1002. Message(Owner,evStatus,cmStatusDone,@Self);
  1003. ClearEvent(Event);
  1004. end;
  1005. cmStatusUpdate :
  1006. if (Event.InfoWord = Command) and ((State and sfPause) = 0) then
  1007. begin
  1008. Update(Event.InfoPtr);
  1009. { ClearEvent(Event); } { don't clear the event so multiple }
  1010. { status views can respond to the same event }
  1011. end;
  1012. cmStatusResume :
  1013. if (Event.InfoWord = Command) and
  1014. ((State and sfPause) = sfPause) then
  1015. begin
  1016. Resume;
  1017. ClearEvent(Event);
  1018. end;
  1019. cmStatusPause :
  1020. if (Event.InfoWord = Command) and ((State and sfPause) = 0) then
  1021. begin
  1022. Pause;
  1023. ClearEvent(Event);
  1024. end;
  1025. end;
  1026. end;
  1027. TParamText.HandleEvent(Event);
  1028. end;
  1029. {****************************************************************************}
  1030. { TStatus.Pause }
  1031. {****************************************************************************}
  1032. procedure TStatus.Pause;
  1033. begin
  1034. SetState(sfPause,True);
  1035. end;
  1036. {****************************************************************************}
  1037. { TStatus.Reset }
  1038. {****************************************************************************}
  1039. procedure TStatus.Reset;
  1040. begin
  1041. DrawView;
  1042. end;
  1043. {****************************************************************************}
  1044. { TStatus.Resume }
  1045. {****************************************************************************}
  1046. procedure TStatus.Resume;
  1047. begin
  1048. SetState(sfPause,False);
  1049. end;
  1050. {****************************************************************************}
  1051. { TStatus.Store }
  1052. {****************************************************************************}
  1053. procedure TStatus.Store (var S : TStream);
  1054. begin
  1055. TParamText.Store(S);
  1056. S.Write(Command,SizeOf(Command));
  1057. end;
  1058. {****************************************************************************}
  1059. { TStatus.Update }
  1060. {****************************************************************************}
  1061. procedure TStatus.Update (Data : Pointer);
  1062. begin
  1063. DisposeStr(Text);
  1064. Text := NewStr(String(Data^));
  1065. DrawView;
  1066. end;
  1067. {****************************************************************************}
  1068. { TStatusDlg Object }
  1069. {****************************************************************************}
  1070. {****************************************************************************}
  1071. { TStatusDlg.Init }
  1072. {****************************************************************************}
  1073. constructor TStatusDlg.Init (ATitle : TTitleStr; AStatus : PStatus;
  1074. AFlags : Word);
  1075. var
  1076. R : TRect;
  1077. i : LongInt;
  1078. Buttons : Byte;
  1079. begin
  1080. if (AStatus = nil) then
  1081. Fail;
  1082. R.A := AStatus^.Origin;
  1083. R.B := AStatus^.Size;
  1084. Inc(R.B.Y,R.A.Y+4);
  1085. Inc(R.B.X,R.A.X+5);
  1086. if not TDialog.Init(R,ATitle) then
  1087. Fail;
  1088. EventMask := EventMask or evStatus;
  1089. Status := AStatus;
  1090. Status^.MoveTo(2,2);
  1091. Insert(Status);
  1092. InsertButtons(AFlags);
  1093. end;
  1094. {****************************************************************************}
  1095. { TStatusDlg.Load }
  1096. {****************************************************************************}
  1097. constructor TStatusDlg.Load (var S : TStream);
  1098. begin
  1099. if not TDialog.Load(S) then
  1100. Fail;
  1101. GetSubViewPtr(S,Status);
  1102. if (S.Status <> stOk) then
  1103. begin
  1104. if (Status <> nil) then
  1105. Dispose(Status,Done);
  1106. TDialog.Done;
  1107. Fail;
  1108. end;
  1109. end;
  1110. {****************************************************************************}
  1111. { TStatusDlg.Cancel }
  1112. {****************************************************************************}
  1113. procedure TStatusDlg.Cancel (ACommand : Word);
  1114. begin
  1115. if Status^.Cancel then
  1116. TDialog.Cancel(ACommand);
  1117. end;
  1118. {****************************************************************************}
  1119. { TStatusDlg.HandleEvent }
  1120. {****************************************************************************}
  1121. procedure TStatusDlg.HandleEvent (var Event : TEvent);
  1122. begin
  1123. case Event.What of
  1124. evStatus :
  1125. case Event.Command of
  1126. cmStatusDone :
  1127. if Event.InfoPtr = Status then
  1128. begin
  1129. TDialog.Cancel(cmOk);
  1130. ClearEvent(Event);
  1131. end;
  1132. end;
  1133. { else let TDialog.HandleEvent send to all subviews for handling }
  1134. evBroadcast, evCommand :
  1135. case Event.Command of
  1136. cmCancel, cmClose :
  1137. begin
  1138. Cancel(cmCancel);
  1139. ClearEvent(Event);
  1140. end;
  1141. cmStatusPause :
  1142. begin
  1143. Status^.Pause;
  1144. ClearEvent(Event);
  1145. end;
  1146. cmStatusResume :
  1147. begin
  1148. Status^.Resume;
  1149. ClearEvent(Event);
  1150. end;
  1151. end;
  1152. end;
  1153. TDialog.HandleEvent(Event);
  1154. end;
  1155. {****************************************************************************}
  1156. { TStatusDlg.InsertButtons }
  1157. {****************************************************************************}
  1158. procedure TStatusDlg.InsertButtons (AFlags : Word);
  1159. var
  1160. R : TRect;
  1161. P : PButton;
  1162. Buttons : Byte;
  1163. X, Y, Gap : Integer;
  1164. i : Word;
  1165. begin
  1166. Buttons := Byte(((AFlags and sdCancelButton) = sdCancelButton));
  1167. { do this Inc twice, once for Pause and once for Resume buttons }
  1168. Inc(Buttons,2 * Byte(((AFlags and sdPauseButton) = sdPauseButton)));
  1169. if Buttons > 0 then
  1170. begin
  1171. Status^.GrowMode := gfGrowHiX;
  1172. { resize dialog to hold all requested buttons }
  1173. if Size.X < ((Buttons * 12) + 2) then
  1174. GrowTo((Buttons * 12) + 2,Size.Y + 2)
  1175. else GrowTo(Size.X,Size.Y + 2);
  1176. { find correct starting position for first button }
  1177. Gap := Size.X - (Buttons * 10) - 2;
  1178. Gap := Gap div Succ(Buttons);
  1179. X := Gap;
  1180. if X < 2 then
  1181. X := 2;
  1182. Y := Size.Y - 3;
  1183. { insert buttons }
  1184. if ((AFlags and sdCancelButton) = sdCancelButton) then
  1185. begin
  1186. P := NewButton(X,Y,10,2,'Cancel',cmCancel,hcCancel,bfDefault);
  1187. P^.GrowMode := gfGrowHiY or gfGrowLoY;
  1188. Inc(X,12 + Gap);
  1189. end;
  1190. if ((AFlags and sdPauseButton) = sdPauseButton) then
  1191. begin
  1192. P := NewButton(X,Y,10,2,'~P~ause',cmStatusPause,hcStatusPause,bfNormal);
  1193. P^.GrowMode := gfGrowHiY or gfGrowLoY;
  1194. Inc(X,12 + Gap);
  1195. P := NewButton(X,Y,10,2,'~R~esume',cmStatusResume,hcStatusResume,
  1196. bfBroadcast);
  1197. P^.GrowMode := gfGrowHiY or gfGrowLoY;
  1198. end;
  1199. end; { of if }
  1200. SelectNext(False);
  1201. end;
  1202. {****************************************************************************}
  1203. { TStatusDlg.Store }
  1204. {****************************************************************************}
  1205. procedure TStatusDlg.Store (var S : TStream);
  1206. begin
  1207. TDialog.Store(S);
  1208. PutSubViewPtr(S,Status);
  1209. end;
  1210. {****************************************************************************}
  1211. { TStatusMessageDlg Object }
  1212. {****************************************************************************}
  1213. {****************************************************************************}
  1214. { TStatusMessageDlg.Init }
  1215. {****************************************************************************}
  1216. constructor TStatusMessageDlg.Init (ATitle : TTitleStr; AStatus : PStatus;
  1217. AFlags : Word; AMessage : String);
  1218. var
  1219. P : PStaticText;
  1220. X, Y : Integer;
  1221. R : TRect;
  1222. begin
  1223. if not TStatusDlg.Init(ATitle,AStatus,AFlags) then
  1224. Fail;
  1225. Status^.GrowMode := gfGrowLoY or gfGrowHiY;
  1226. GetExtent(R);
  1227. X := R.B.X - R.A.X;
  1228. if X < Size.X then
  1229. X := Size.X;
  1230. Y := R.B.Y - R.A.Y;
  1231. if Y < Size.Y then
  1232. Y := Size.Y;
  1233. GrowTo(X,Y);
  1234. R.Assign(2,2,Size.X-2,Size.Y-3);
  1235. P := New(PStaticText,Init(R,AMessage));
  1236. if (P = nil) then
  1237. begin
  1238. TStatusDlg.Done;
  1239. Fail;
  1240. end;
  1241. GrowTo(Size.X,Size.Y + P^.Size.Y + 1);
  1242. Insert(P);
  1243. end;
  1244. {****************************************************************************}
  1245. { Global procedures and functions }
  1246. {****************************************************************************}
  1247. {****************************************************************************}
  1248. { RegisterStatuses }
  1249. {****************************************************************************}
  1250. procedure RegisterStatuses;
  1251. begin
  1252. { RegisterType(RStatus);
  1253. RegisterType(RStatusDlg);
  1254. RegisterType(RGauge);
  1255. RegisterType(RArrowGauge);
  1256. RegisterType(RPercentGauge);
  1257. RegisterType(RBarGauge);
  1258. RegisterType(RSpinnerGauge); }
  1259. end;
  1260. {****************************************************************************}
  1261. { Unit Initialization }
  1262. {****************************************************************************}
  1263. begin
  1264. end.