2
0

msgbox.pas 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. {********[ SOURCE FILE OF GRAPHICAL FREE VISION ]**********}
  2. { }
  3. { System independent GRAPHICAL clone of MSGBOX.PAS }
  4. { }
  5. { Interface Copyright (c) 1992 Borland International }
  6. { }
  7. { Copyright (c) 1996, 1997, 1998, 1999 by Leon de Boer }
  8. { [email protected] - primary e-mail addr }
  9. { [email protected] - backup e-mail addr }
  10. { }
  11. {****************[ THIS CODE IS FREEWARE ]*****************}
  12. { }
  13. { This sourcecode is released for the purpose to }
  14. { promote the pascal language on all platforms. You may }
  15. { redistribute it and/or modify with the following }
  16. { DISCLAIMER. }
  17. { }
  18. { This SOURCE CODE is distributed "AS IS" WITHOUT }
  19. { WARRANTIES AS TO PERFORMANCE OF MERCHANTABILITY OR }
  20. { ANY OTHER WARRANTIES WHETHER EXPRESSED OR IMPLIED. }
  21. { }
  22. {*****************[ SUPPORTED PLATFORMS ]******************}
  23. { 16 and 32 Bit compilers }
  24. { DOS - Turbo Pascal 7.0 + (16 Bit) }
  25. { DPMI - Turbo Pascal 7.0 + (16 Bit) }
  26. { - FPC 0.9912+ (GO32V2) (32 Bit) }
  27. { WINDOWS - Turbo Pascal 7.0 + (16 Bit) }
  28. { - Delphi 1.0+ (16 Bit) }
  29. { WIN95/NT - Delphi 2.0+ (32 Bit) }
  30. { - Virtual Pascal 2.0+ (32 Bit) }
  31. { - Speedsoft Sybil 2.0+ (32 Bit) }
  32. { OS2 - Virtual Pascal 1.0+ (32 Bit) }
  33. { - Speedsoft Sybil 2.0+ (32 Bit) }
  34. { }
  35. {******************[ REVISION HISTORY ]********************}
  36. { Version Date Fix }
  37. { ------- --------- --------------------------------- }
  38. { 1.00 12 Jun 96 Initial DOS/DPMI code released. }
  39. { 1.10 18 Oct 97 Code converted to GUI & TEXT mode. }
  40. { 1.20 18 Jul 97 Windows conversion added. }
  41. { 1.30 29 Aug 97 Platform.inc sort added. }
  42. { 1.40 22 Oct 97 Delphi3 32 bit code added. }
  43. { 1.50 05 May 98 Virtual pascal 2.0 code added. }
  44. { 1.60 30 Sep 99 Complete recheck preformed }
  45. {**********************************************************}
  46. UNIT MsgBox;
  47. {2.0 compatibility}
  48. {$ifdef VER2_0}
  49. {$macro on}
  50. {$define resourcestring := const}
  51. {$endif}
  52. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  53. INTERFACE
  54. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  55. {====Include file to sort compiler platform out =====================}
  56. {$I Platform.inc}
  57. {====================================================================}
  58. {==== Compiler directives ===========================================}
  59. {$IFNDEF PPC_FPC}{ FPC doesn't support these switches }
  60. {$F-} { Near calls are okay }
  61. {$A+} { Word Align Data }
  62. {$B-} { Allow short circuit boolean evaluations }
  63. {$O+} { This unit may be overlaid }
  64. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  65. {$P-} { Normal string variables }
  66. {$N-} { No 80x87 code generation }
  67. {$E+} { Emulation is on }
  68. {$ENDIF}
  69. {$X+} { Extended syntax is ok }
  70. {$R-} { Disable range checking }
  71. {$S-} { Disable Stack Checking }
  72. {$I-} { Disable IO Checking }
  73. {$Q-} { Disable Overflow Checking }
  74. {$V-} { Turn off strict VAR strings }
  75. {====================================================================}
  76. USES objects, dialogs; { Standard GFV units }
  77. {***************************************************************************}
  78. { PUBLIC CONSTANTS }
  79. {***************************************************************************}
  80. {---------------------------------------------------------------------------}
  81. { MESSAGE BOX CLASSES }
  82. {---------------------------------------------------------------------------}
  83. CONST
  84. mfWarning = $0000; { Display a Warning box }
  85. mfError = $0001; { Dispaly a Error box }
  86. mfInformation = $0002; { Display an Information Box }
  87. mfConfirmation = $0003; { Display a Confirmation Box }
  88. mfInsertInApp = $0080; { Insert message box into }
  89. { app instead of the Desktop }
  90. {---------------------------------------------------------------------------}
  91. { MESSAGE BOX BUTTON FLAGS }
  92. {---------------------------------------------------------------------------}
  93. CONST
  94. mfYesButton = $0100; { Yes button into the dialog }
  95. mfNoButton = $0200; { No button into the dialog }
  96. mfOKButton = $0400; { OK button into the dialog }
  97. mfCancelButton = $0800; { Cancel button into the dialog }
  98. mfYesNoCancel = mfYesButton + mfNoButton + mfCancelButton;
  99. { Yes, No, Cancel dialog }
  100. mfOKCancel = mfOKButton + mfCancelButton;
  101. { Standard OK, Cancel dialog }
  102. var
  103. MsgBoxTitles: array[0..3] of string[40];
  104. {***************************************************************************}
  105. { INTERFACE ROUTINES }
  106. {***************************************************************************}
  107. procedure InitMsgBox;
  108. procedure DoneMsgBox;
  109. { Init initializes the message box display system's text strings. Init is
  110. called by TApplication.Init after a successful call to Resource.Init or
  111. Resource.Load. }
  112. {-MessageBox---------------------------------------------------------
  113. MessageBox displays the given string in a standard sized dialog box.
  114. Before the dialog is displayed the Msg and Params are passed to FormatStr.
  115. The resulting string is displayed as a TStaticText view in the dialog.
  116. 30Sep99 LdB
  117. ---------------------------------------------------------------------}
  118. FUNCTION MessageBox (Const Msg: String; Params: Pointer;
  119. AOptions: Word): Word;
  120. {-MessageBoxRect-----------------------------------------------------
  121. MessageBoxRec allows the specification of a TRect for the message box
  122. to occupy.
  123. 30Sep99 LdB
  124. ---------------------------------------------------------------------}
  125. FUNCTION MessageBoxRect (Var R: TRect; Const Msg: String; Params: Pointer;
  126. AOptions: Word): Word;
  127. {-MessageBoxRectDlg--------------------------------------------------
  128. MessageBoxRecDlg allows the specification of a TRect for the message box
  129. to occupy plus the dialog window (to allow different dialog window types).
  130. ---------------------------------------------------------------------}
  131. FUNCTION MessageBoxRectDlg (Dlg: PDialog; Var R: TRect; Const Msg: String;
  132. Params: Pointer; AOptions: Word): Word;
  133. {-InputBox-----------------------------------------------------------
  134. InputBox displays a simple dialog that allows user to type in a string
  135. 30Sep99 LdB
  136. ---------------------------------------------------------------------}
  137. FUNCTION InputBox (Const Title, ALabel: String; Var S: String;
  138. Limit: Byte): Word;
  139. {-InputBoxRect-------------------------------------------------------
  140. InputBoxRect is like InputBox but allows the specification of a rectangle.
  141. 30Sep99 LdB
  142. ---------------------------------------------------------------------}
  143. FUNCTION InputBoxRect (Var Bounds: TRect; Const Title, ALabel: String;
  144. Var S: String; Limit: Byte): Word;
  145. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  146. IMPLEMENTATION
  147. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  148. USES Drivers, Views, App{, Resource}; { Standard GFV units }
  149. {***************************************************************************}
  150. { INTERFACE ROUTINES }
  151. {***************************************************************************}
  152. const
  153. Commands: array[0..3] of word =
  154. (cmYes, cmNo, cmOK, cmCancel);
  155. var
  156. ButtonName: array[0..3] of string[40];
  157. resourcestring sConfirm='Confirm';
  158. sError='Error';
  159. sInformation='Information';
  160. sWarning='Warning';
  161. {---------------------------------------------------------------------------}
  162. { MessageBox -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  163. {---------------------------------------------------------------------------}
  164. FUNCTION MessageBox(Const Msg: String; Params: Pointer; AOptions: Word): Word;
  165. VAR R: TRect;
  166. BEGIN
  167. R.Assign(0, 0, 40, 9); { Assign area }
  168. If (AOptions AND mfInsertInApp = 0) Then { Non app insert }
  169. R.Move((Desktop^.Size.X - R.B.X) DIV 2,
  170. (Desktop^.Size.Y - R.B.Y) DIV 2) Else { Calculate position }
  171. R.Move((Application^.Size.X - R.B.X) DIV 2,
  172. (Application^.Size.Y - R.B.Y) DIV 2); { Calculate position }
  173. MessageBox := MessageBoxRect(R, Msg, Params,
  174. AOptions); { Create message box }
  175. END;
  176. FUNCTION MessageBoxRectDlg (Dlg: PDialog; Var R: TRect; Const Msg: String;
  177. Params: Pointer; AOptions: Word): Word;
  178. VAR I, X, ButtonCount: Integer; S: String; Control: PView;
  179. ButtonList: Array[0..4] Of PView;
  180. BEGIN
  181. With Dlg^ Do Begin
  182. FormatStr(S, Msg, Params^); { Format the message }
  183. Control := New(PStaticText, Init(R, S)); { Create static text }
  184. Insert(Control); { Insert the text }
  185. X := -2; { Set initial value }
  186. ButtonCount := 0; { Clear button count }
  187. For I := 0 To 3 Do
  188. If (AOptions AND ($0100 SHL I) <> 0) Then Begin
  189. R.Assign(0, 0, 10, 2); { Assign screen area }
  190. Control := New(PButton, Init(R, ButtonName[I],
  191. Commands[i], bfNormal)); { Create button }
  192. Inc(X, Control^.Size.X + 2); { Adjust position }
  193. ButtonList[ButtonCount] := Control; { Add to button list }
  194. Inc(ButtonCount); { Inc button count }
  195. End;
  196. X := (Size.X - X) SHR 1; { Calc x position }
  197. If (ButtonCount > 0) Then
  198. For I := 0 To ButtonCount - 1 Do Begin { For each button }
  199. Control := ButtonList[I]; { Transfer button }
  200. Insert(Control); { Insert button }
  201. Control^.MoveTo(X, Size.Y - 3); { Position button }
  202. Inc(X, Control^.Size.X + 2); { Adjust position }
  203. End;
  204. SelectNext(False); { Select first button }
  205. End;
  206. If (AOptions AND mfInsertInApp = 0) Then
  207. MessageBoxRectDlg := DeskTop^.ExecView(Dlg) Else { Execute dialog }
  208. MessageBoxRectDlg := Application^.ExecView(Dlg); { Execute dialog }
  209. end;
  210. {---------------------------------------------------------------------------}
  211. { MessageBoxRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  212. {---------------------------------------------------------------------------}
  213. FUNCTION MessageBoxRect(Var R: TRect; Const Msg: String; Params: Pointer;
  214. AOptions: Word): Word;
  215. var
  216. Dialog: PDialog;
  217. BEGIN
  218. Dialog := New (PDialog, Init (R, MsgBoxTitles [AOptions
  219. AND $3])); { Create dialog }
  220. with Dialog^ do
  221. R.Assign(3, 2, Size.X - 2, Size.Y - 3); { Assign area for text }
  222. MessageBoxRect := MessageBoxRectDlg (Dialog, R, Msg, Params, AOptions);
  223. Dispose (Dialog, Done); { Dispose of dialog }
  224. END;
  225. {---------------------------------------------------------------------------}
  226. { InputBox -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  227. {---------------------------------------------------------------------------}
  228. FUNCTION InputBox(Const Title, ALabel: String; Var S: String;
  229. Limit: Byte): Word;
  230. VAR R: TRect;
  231. BEGIN
  232. R.Assign(0, 0, 60, 8); { Assign screen area }
  233. R.Move((Desktop^.Size.X - R.B.X) DIV 2,
  234. (Desktop^.Size.Y - R.B.Y) DIV 2); { Position area }
  235. InputBox := InputBoxRect(R, Title, ALabel, S,
  236. Limit); { Create input box }
  237. END;
  238. {---------------------------------------------------------------------------}
  239. { InputBoxRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  240. {---------------------------------------------------------------------------}
  241. FUNCTION InputBoxRect(Var Bounds: TRect; Const Title, ALabel: String;
  242. Var S: String; Limit: Byte): Word;
  243. VAR C: Word; R: TRect; Control: PView; Dialog: PDialog;
  244. BEGIN
  245. Dialog := New(PDialog, Init(Bounds, Title)); { Create dialog }
  246. With Dialog^ Do Begin
  247. R.Assign(4 + CStrLen(ALabel), 2, Size.X - 3, 3); { Assign screen area }
  248. Control := New(PInputLine, Init(R, Limit)); { Create input line }
  249. Insert(Control); { Insert input line }
  250. R.Assign(2, 2, 3 + CStrLen(ALabel), 3); { Assign screen area }
  251. Insert(New(PLabel, Init(R, ALabel, Control))); { Insert label }
  252. R.Assign(Size.X - 24, Size.Y - 4, Size.X - 14,
  253. Size.Y - 2); { Assign screen area }
  254. Insert(New(PButton, Init(R, 'O~K~', cmOk,
  255. bfDefault))); { Insert okay button }
  256. Inc(R.A.X, 12); { New start x position }
  257. Inc(R.B.X, 12); { New end x position }
  258. Insert(New(PButton, Init(R, 'Cancel', cmCancel,
  259. bfNormal))); { Insert cancel button }
  260. Inc(R.A.X, 12); { New start x position }
  261. Inc(R.B.X, 12); { New end x position }
  262. SelectNext(False); { Select first button }
  263. End;
  264. Dialog^.SetData(S); { Set data in dialog }
  265. C := DeskTop^.ExecView(Dialog); { Execute the dialog }
  266. If (C <> cmCancel) Then Dialog^.GetData(S); { Get data from dialog }
  267. Dispose(Dialog, Done); { Dispose of dialog }
  268. InputBoxRect := C; { Return execute result }
  269. END;
  270. procedure InitMsgBox;
  271. begin
  272. ButtonName[0] := slYes;
  273. ButtonName[1] := slNo;
  274. ButtonName[2] := slOk;
  275. ButtonName[3] := slCancel;
  276. MsgBoxTitles[0] := sWarning;
  277. MsgBoxTitles[1] := sError;
  278. MsgBoxTitles[2] := sInformation;
  279. MsgBoxTitles[3] := sConfirm;
  280. end;
  281. procedure DoneMsgBox;
  282. begin
  283. end;
  284. END.