statuses.pas 49 KB

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