timeddlg.pas 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. {
  2. $Id$
  3. Timed dialogs for Free Vision
  4. Copyright (c) 2004 by Free Pascal core team
  5. This library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9. This library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with this library; if not, write to the Free
  15. Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************}
  17. UNIT timeddlg;
  18. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  19. INTERFACE
  20. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  21. {====Include file to sort compiler platform out =====================}
  22. {$I Platform.inc}
  23. {====================================================================}
  24. {==== Compiler directives ===========================================}
  25. {$IFNDEF PPC_FPC}{ FPC doesn't support these switches }
  26. {$F-} { Near calls are okay }
  27. {$A+} { Word Align Data }
  28. {$B-} { Allow short circuit boolean evaluations }
  29. {$O+} { This unit may be overlaid }
  30. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  31. {$P-} { Normal string variables }
  32. {$N-} { No 80x87 code generation }
  33. {$E+} { Emulation is on }
  34. {$ENDIF}
  35. {$X+} { Extended syntax is ok }
  36. {$R-} { Disable range checking }
  37. {$S-} { Disable Stack Checking }
  38. {$I-} { Disable IO Checking }
  39. {$Q-} { Disable Overflow Checking }
  40. {$V-} { Turn off strict VAR strings }
  41. {====================================================================}
  42. USES objects, dialogs, fvconsts, drivers, views; { Standard GFV unit }
  43. type
  44. TTimedDialog = object (TDialog)
  45. Secs: longint;
  46. constructor Init (var Bounds: TRect; ATitle: TTitleStr; ASecs: word);
  47. constructor Load (var S: TStream);
  48. procedure GetEvent (var Event: TEvent); virtual;
  49. procedure Store (var S: TStream); virtual;
  50. private
  51. Secs0: longint;
  52. Secs2: longint;
  53. DayWrap: boolean;
  54. end;
  55. PTimedDialog = ^TTimedDialog;
  56. (* Must be always included in TTimeDialog! *)
  57. TTimedDialogText = object (TStaticText)
  58. constructor Init (var Bounds: TRect);
  59. procedure GetText (var S: string); virtual;
  60. end;
  61. PTimedDialogText = ^TTimedDialogText;
  62. const
  63. RTimedDialog: TStreamRec = (
  64. ObjType: idTimedDialog;
  65. {$IFDEF BP_VMTLink} { BP style VMT link }
  66. VmtLink: Ofs (TypeOf (TTimedDialog)^);
  67. {$ELSE} { Alt style VMT link }
  68. VmtLink: TypeOf (TTimedDialog);
  69. {$ENDIF BP_VMTLink}
  70. Load: @TTimedDialog.Load;
  71. Store: @TTimedDialog.Store
  72. );
  73. RTimedDialogText: TStreamRec = (
  74. ObjType: idTimedDialogText;
  75. {$IFDEF BP_VMTLink} { BP style VMT link }
  76. VmtLink: Ofs (TypeOf (TTimedDialogText)^);
  77. {$ELSE} { Alt style VMT link }
  78. VmtLink: TypeOf (TTimedDialogText);
  79. {$ENDIF BP_VMTLink}
  80. Load: @TTimedDialogText.Load;
  81. Store: @TTimedDialogText.Store
  82. );
  83. procedure RegisterTimedDialog;
  84. FUNCTION TimedMessageBox (Const Msg: String; Params: Pointer;
  85. AOptions: Word; ASecs: Word): Word;
  86. {-TimedMessageBoxRect------------------------------------------------
  87. TimedMessageBoxRect allows the specification of a TRect for the message box
  88. to occupy.
  89. ---------------------------------------------------------------------}
  90. FUNCTION TimedMessageBoxRect (Var R: TRect; Const Msg: String; Params: Pointer;
  91. AOptions: Word; ASecs: Word): Word;
  92. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  93. IMPLEMENTATION
  94. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  95. USES
  96. dos,
  97. app, resource, msgbox; { Standard GFV units }
  98. {***************************************************************************}
  99. { INTERFACE ROUTINES }
  100. {***************************************************************************}
  101. constructor TTimedDialogText.Init (var Bounds: TRect);
  102. begin
  103. inherited Init (Bounds, '');
  104. end;
  105. procedure TTimedDialogText.GetText (var S: string);
  106. begin
  107. if Owner <> nil
  108. (* and (TypeOf (Owner^) = TypeOf (TTimedDialog)) *)
  109. then
  110. begin
  111. Str (PTimedDialog (Owner)^.Secs, S);
  112. S := #3 + S;
  113. end
  114. else
  115. S := '';
  116. end;
  117. constructor TTimedDialog.Init (var Bounds: TRect; ATitle: TTitleStr;
  118. ASecs: word);
  119. var
  120. H, M, S, S100: word;
  121. begin
  122. inherited Init (Bounds, ATitle);
  123. GetTime (H, M, S, S100);
  124. Secs0 := H * 3600 + M * 60 + S;
  125. Secs2 := Secs0 + ASecs;
  126. Secs := ASecs;
  127. DayWrap := Secs2 > 24 * 3600;
  128. end;
  129. procedure TTimedDialog.GetEvent (var Event: TEvent);
  130. var
  131. H, M, S, S100: word;
  132. Secs1: longint;
  133. begin
  134. inherited GetEvent (Event);
  135. GetTime (H, M, S, S100);
  136. Secs1 := H * 3600 + M * 60 + S;
  137. if DayWrap then Inc (Secs1, 24 * 3600);
  138. if Secs2 - Secs1 <> Secs then
  139. begin
  140. Secs := Secs2 - Secs1;
  141. if Secs < 0 then
  142. Secs := 0;
  143. (* If remaining seconds are displayed in one of included views, update them. *)
  144. Redraw;
  145. end;
  146. with Event do
  147. if (Secs = 0) and (What = evNothing) then
  148. begin
  149. What := evCommand;
  150. Command := cmCancel;
  151. end;
  152. end;
  153. constructor TTimedDialog.Load (var S: TStream);
  154. begin
  155. inherited Load (S);
  156. S.Read (Secs, SizeOf (Secs));
  157. S.Read (Secs0, SizeOf (Secs0));
  158. S.Read (Secs2, SizeOf (Secs2));
  159. S.Read (DayWrap, SizeOf (DayWrap));
  160. end;
  161. procedure TTimedDialog.Store (var S: TStream);
  162. begin
  163. inherited Store (S);
  164. S.Write (Secs, SizeOf (Secs));
  165. S.Write (Secs0, SizeOf (Secs0));
  166. S.Write (Secs2, SizeOf (Secs2));
  167. S.Write (DayWrap, SizeOf (DayWrap));
  168. end;
  169. function TimedMessageBox (const Msg: string; Params: pointer;
  170. AOptions: word; ASecs: word): word;
  171. var
  172. R: TRect;
  173. begin
  174. R.Assign(0, 0, 40, 10); { Assign area }
  175. if (AOptions AND mfInsertInApp = 0) then { Non app insert }
  176. R.Move((Desktop^.Size.X - R.B.X) div 2,
  177. (Desktop^.Size.Y - R.B.Y) div 2) { Calculate position }
  178. else
  179. R.Move((Application^.Size.X - R.B.X) div 2,
  180. (Application^.Size.Y - R.B.Y) div 2); { Calculate position }
  181. TimedMessageBox := TimedMessageBoxRect (R, Msg, Params,
  182. AOptions, ASecs); { Create message box }
  183. end;
  184. function TimedMessageBoxRect (var R: TRect; const Msg: string; Params: pointer;
  185. AOptions: word; ASecs: word): word;
  186. var
  187. Dlg: PTimedDialog;
  188. TimedText: PTimedDialogText;
  189. begin
  190. Dlg := New (PTimedDialog, Init (R, MsgBoxTitles [AOptions
  191. and $3], ASecs)); { Create dialog }
  192. with Dlg^ do
  193. begin
  194. R.Assign (3, Size.Y - 5, Size.X - 2, Size.Y - 4);
  195. New (TimedText, Init (R));
  196. Insert (TimedText);
  197. R.Assign (3, 2, Size.X - 2, Size.Y - 5); { Assign area for text }
  198. end;
  199. TimedMessageBoxRect := MessageBoxRectDlg (Dlg, R, Msg, Params, AOptions);
  200. Dispose (Dlg, Done); { Dispose of dialog }
  201. end;
  202. procedure RegisterTimedDialog;
  203. begin
  204. RegisterType (RTimedDialog);
  205. RegisterType (RTimedDialogText);
  206. end;
  207. begin
  208. RegisterTimedDialog;
  209. end.
  210. {
  211. $Log$
  212. Revision 1.1 2004-12-19 20:25:11 hajny
  213. + TTimedDialog and TimedMessageBox added
  214. }