msgbox.pas 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  48. INTERFACE
  49. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  50. {====Include file to sort compiler platform out =====================}
  51. {$I Platform.inc}
  52. {====================================================================}
  53. {==== Compiler directives ===========================================}
  54. {$IFNDEF PPC_FPC}{ FPC doesn't support these switches }
  55. {$F-} { Near calls are okay }
  56. {$A+} { Word Align Data }
  57. {$B-} { Allow short circuit boolean evaluations }
  58. {$O+} { This unit may be overlaid }
  59. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  60. {$P-} { Normal string variables }
  61. {$N-} { No 80x87 code generation }
  62. {$E+} { Emulation is on }
  63. {$ENDIF}
  64. {$X+} { Extended syntax is ok }
  65. {$R-} { Disable range checking }
  66. {$S-} { Disable Stack Checking }
  67. {$I-} { Disable IO Checking }
  68. {$Q-} { Disable Overflow Checking }
  69. {$V-} { Turn off strict VAR strings }
  70. {====================================================================}
  71. USES Objects; { Standard GFV unit }
  72. {***************************************************************************}
  73. { PUBLIC CONSTANTS }
  74. {***************************************************************************}
  75. {---------------------------------------------------------------------------}
  76. { MESSAGE BOX CLASSES }
  77. {---------------------------------------------------------------------------}
  78. CONST
  79. mfWarning = $0000; { Display a Warning box }
  80. mfError = $0001; { Dispaly a Error box }
  81. mfInformation = $0002; { Display an Information Box }
  82. mfConfirmation = $0003; { Display a Confirmation Box }
  83. mfInsertInApp = $0080; { Insert message box into }
  84. { app instead of the Desktop }
  85. {---------------------------------------------------------------------------}
  86. { MESSAGE BOX BUTTON FLAGS }
  87. {---------------------------------------------------------------------------}
  88. CONST
  89. mfYesButton = $0100; { Yes button into the dialog }
  90. mfNoButton = $0200; { No button into the dialog }
  91. mfOKButton = $0400; { OK button into the dialog }
  92. mfCancelButton = $0800; { Cancel button into the dialog }
  93. mfYesNoCancel = mfYesButton + mfNoButton + mfCancelButton;
  94. { Yes, No, Cancel dialog }
  95. mfOKCancel = mfOKButton + mfCancelButton;
  96. { Standard OK, Cancel dialog }
  97. {***************************************************************************}
  98. { INTERFACE ROUTINES }
  99. {***************************************************************************}
  100. {-MessageBox---------------------------------------------------------
  101. MessageBox displays the given string in a standard sized dialog box.
  102. Before the dialog is displayed the Msg and Params are passed to FormatStr.
  103. The resulting string is displayed as a TStaticText view in the dialog.
  104. 30Sep99 LdB
  105. ---------------------------------------------------------------------}
  106. FUNCTION MessageBox (Const Msg: String; Params: Pointer;
  107. AOptions: Word): Word;
  108. {-MessageBoxRect-----------------------------------------------------
  109. MessageBoxRec allows the specification of a TRect for the message box
  110. to occupy.
  111. 30Sep99 LdB
  112. ---------------------------------------------------------------------}
  113. FUNCTION MessageBoxRect (Var R: TRect; Const Msg: String; Params: Pointer;
  114. AOptions: Word): Word;
  115. {-InputBox-----------------------------------------------------------
  116. InputBox displays a simple dialog that allows user to type in a string
  117. 30Sep99 LdB
  118. ---------------------------------------------------------------------}
  119. FUNCTION InputBox (Const Title, ALabel: String; Var S: String;
  120. Limit: Byte): Word;
  121. {-InputBoxRect-------------------------------------------------------
  122. InputBoxRect is like InputBox but allows the specification of a rectangle.
  123. 30Sep99 LdB
  124. ---------------------------------------------------------------------}
  125. FUNCTION InputBoxRect (Var Bounds: TRect; Const Title, ALabel: String;
  126. Var S: String; Limit: Byte): Word;
  127. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  128. IMPLEMENTATION
  129. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  130. USES Drivers, Views, App, Dialogs; { Standard GFV units }
  131. {***************************************************************************}
  132. { INTERFACE ROUTINES }
  133. {***************************************************************************}
  134. {---------------------------------------------------------------------------}
  135. { MessageBox -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  136. {---------------------------------------------------------------------------}
  137. FUNCTION MessageBox(Const Msg: String; Params: Pointer; AOptions: Word): Word;
  138. VAR R: TRect;
  139. BEGIN
  140. R.Assign(0, 0, 40, 9); { Assign area }
  141. If (AOptions AND mfInsertInApp = 0) Then { Non app insert }
  142. R.Move((Desktop^.Size.X - R.B.X) DIV 2,
  143. (Desktop^.Size.Y - R.B.Y) DIV 2) Else { Calculate position }
  144. R.Move((Application^.Size.X - R.B.X) DIV 2,
  145. (Application^.Size.Y - R.B.Y) DIV 2); { Calculate position }
  146. MessageBox := MessageBoxRect(R, Msg, Params,
  147. AOptions); { Create message box }
  148. END;
  149. {---------------------------------------------------------------------------}
  150. { MessageBoxRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  151. {---------------------------------------------------------------------------}
  152. FUNCTION MessageBoxRect(Var R: TRect; Const Msg: String; Params: Pointer;
  153. AOptions: Word): Word;
  154. CONST ButtonName: Array[0..3] Of String[6] = ('~Y~es', '~N~o', 'O~K~', 'Cancel');
  155. Commands: Array[0..3] Of Word = (cmYes, cmNo, cmOK, cmCancel);
  156. Titles: Array[0..3] Of String[11] = ('Warning','Error','Information','Confirm');
  157. VAR I, X, ButtonCount: Integer; S: String; Dialog: PDialog; Control: PView;
  158. ButtonList: Array[0..4] Of PView;
  159. BEGIN
  160. Dialog := New(PDialog, Init(R, Titles[AOptions
  161. AND $3])); { Create dialog }
  162. With Dialog^ Do Begin
  163. R.Assign(3, 2, Size.X - 2, Size.Y - 3); { Assign screen area }
  164. FormatStr(S, Msg, Params^); { Format the message }
  165. Control := New(PStaticText, Init(R, S)); { Create static text }
  166. Insert(Control); { Insert the text }
  167. X := -2; { Set initial value }
  168. ButtonCount := 0; { Clear button count }
  169. For I := 0 To 3 Do
  170. If (AOptions AND ($0100 SHL I) <> 0) Then Begin
  171. R.Assign(0, 0, 10, 2); { Assign screen area }
  172. Control := New(PButton, Init(R, ButtonName[I],
  173. Commands[i], bfNormal)); { Create button }
  174. Inc(X, Control^.Size.X + 2); { Adjust position }
  175. ButtonList[ButtonCount] := Control; { Add to button list }
  176. Inc(ButtonCount); { Inc button count }
  177. End;
  178. X := (Size.X - X) SHR 1; { Calc x position }
  179. If (ButtonCount > 0) Then
  180. For I := 0 To ButtonCount - 1 Do Begin { For each button }
  181. Control := ButtonList[I]; { Transfer button }
  182. Insert(Control); { Insert button }
  183. Control^.MoveTo(X, Size.Y - 3); { Position button }
  184. Inc(X, Control^.Size.X + 2); { Adjust position }
  185. End;
  186. SelectNext(False); { Select first button }
  187. End;
  188. If (AOptions AND mfInsertInApp = 0) Then
  189. MessageBoxRect := DeskTop^.ExecView(Dialog) Else { Execute dialog }
  190. MessageBoxRect := Application^.ExecView(Dialog); { Execute dialog }
  191. Dispose(Dialog, Done); { Dispose of dialog }
  192. END;
  193. {---------------------------------------------------------------------------}
  194. { InputBox -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  195. {---------------------------------------------------------------------------}
  196. FUNCTION InputBox(Const Title, ALabel: String; Var S: String;
  197. Limit: Byte): Word;
  198. VAR R: TRect;
  199. BEGIN
  200. R.Assign(0, 0, 60, 8); { Assign screen area }
  201. R.Move((Desktop^.Size.X - R.B.X) DIV 2,
  202. (Desktop^.Size.Y - R.B.Y) DIV 2); { Position area }
  203. InputBox := InputBoxRect(R, Title, ALabel, S,
  204. Limit); { Create input box }
  205. END;
  206. {---------------------------------------------------------------------------}
  207. { InputBoxRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  208. {---------------------------------------------------------------------------}
  209. FUNCTION InputBoxRect(Var Bounds: TRect; Const Title, ALabel: String;
  210. Var S: String; Limit: Byte): Word;
  211. VAR C: Word; R: TRect; Control: PView; Dialog: PDialog;
  212. BEGIN
  213. Dialog := New(PDialog, Init(Bounds, Title)); { Create dialog }
  214. With Dialog^ Do Begin
  215. R.Assign(4 + CStrLen(ALabel), 2, Size.X - 3, 3); { Assign screen area }
  216. Control := New(PInputLine, Init(R, Limit)); { Create input line }
  217. Insert(Control); { Insert input line }
  218. R.Assign(2, 2, 3 + CStrLen(ALabel), 3); { Assign screen area }
  219. Insert(New(PLabel, Init(R, ALabel, Control))); { Insert label }
  220. R.Assign(Size.X - 24, Size.Y - 4, Size.X - 14,
  221. Size.Y - 2); { Assign screen area }
  222. Insert(New(PButton, Init(R, 'O~K~', cmOk,
  223. bfDefault))); { Insert okay button }
  224. Inc(R.A.X, 12); { New start x position }
  225. Inc(R.B.X, 12); { New end x position }
  226. Insert(New(PButton, Init(R, 'Cancel', cmCancel,
  227. bfNormal))); { Insert cancel button }
  228. Inc(R.A.X, 12); { New start x position }
  229. Inc(R.B.X, 12); { New end x position }
  230. SelectNext(False); { Select first button }
  231. End;
  232. Dialog^.SetData(S); { Set data in dialog }
  233. C := DeskTop^.ExecView(Dialog); { Execute the dialog }
  234. If (C <> cmCancel) Then Dialog^.GetData(S); { Get data from dialog }
  235. Dispose(Dialog, Done); { Dispose of dialog }
  236. InputBoxRect := C; { Return execute result }
  237. END;
  238. END.