msgbox.pas 14 KB

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