msgbox.inc 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  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. {$ifdef FV_UNICODE}
  47. UNIT UMsgBox;
  48. {$else FV_UNICODE}
  49. UNIT MsgBox;
  50. {$endif FV_UNICODE}
  51. {2.0 compatibility}
  52. {$ifdef VER2_0}
  53. {$macro on}
  54. {$define resourcestring := const}
  55. {$endif}
  56. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  57. INTERFACE
  58. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  59. {====Include file to sort compiler platform out =====================}
  60. {$I platform.inc}
  61. {====================================================================}
  62. {==== Compiler directives ===========================================}
  63. {$IFNDEF PPC_FPC}{ FPC doesn't support these switches }
  64. {$F-} { Near calls are okay }
  65. {$A+} { Word Align Data }
  66. {$B-} { Allow short circuit boolean evaluations }
  67. {$O+} { This unit may be overlaid }
  68. {$G+} { 286 Code optimization - if you're on an 8088 get a real computer }
  69. {$P-} { Normal string variables }
  70. {$N-} { No 80x87 code generation }
  71. {$E+} { Emulation is on }
  72. {$ENDIF}
  73. {$X+} { Extended syntax is ok }
  74. {$R-} { Disable range checking }
  75. {$S-} { Disable Stack Checking }
  76. {$I-} { Disable IO Checking }
  77. {$Q-} { Disable Overflow Checking }
  78. {$V-} { Turn off strict VAR strings }
  79. {====================================================================}
  80. USES objects, { Standard GFV units }
  81. {$ifdef FV_UNICODE}
  82. ufvcommon,udialogs;
  83. {$else FV_UNICODE}
  84. fvcommon,dialogs;
  85. {$endif FV_UNICODE}
  86. {***************************************************************************}
  87. { PUBLIC CONSTANTS }
  88. {***************************************************************************}
  89. {---------------------------------------------------------------------------}
  90. { MESSAGE BOX CLASSES }
  91. {---------------------------------------------------------------------------}
  92. CONST
  93. mfWarning = $0000; { Display a Warning box }
  94. mfError = $0001; { Dispaly a Error box }
  95. mfInformation = $0002; { Display an Information Box }
  96. mfConfirmation = $0003; { Display a Confirmation Box }
  97. mfInsertInApp = $0080; { Insert message box into }
  98. { app instead of the Desktop }
  99. {---------------------------------------------------------------------------}
  100. { MESSAGE BOX BUTTON FLAGS }
  101. {---------------------------------------------------------------------------}
  102. CONST
  103. mfYesButton = $0100; { Yes button into the dialog }
  104. mfNoButton = $0200; { No button into the dialog }
  105. mfOKButton = $0400; { OK button into the dialog }
  106. mfCancelButton = $0800; { Cancel button into the dialog }
  107. mfYesNoCancel = mfYesButton + mfNoButton + mfCancelButton;
  108. { Yes, No, Cancel dialog }
  109. mfOKCancel = mfOKButton + mfCancelButton;
  110. { Standard OK, Cancel dialog }
  111. var
  112. {$ifdef FV_UNICODE}
  113. MsgBoxTitles: array[0..3] of UnicodeString;
  114. {$else FV_UNICODE}
  115. MsgBoxTitles: array[0..3] of string[40];
  116. {$endif FV_UNICODE}
  117. {***************************************************************************}
  118. { INTERFACE ROUTINES }
  119. {***************************************************************************}
  120. procedure InitMsgBox;
  121. procedure DoneMsgBox;
  122. { Init initializes the message box display system's text strings. Init is
  123. called by TApplication.Init after a successful call to Resource.Init or
  124. Resource.Load. }
  125. {-MessageBox---------------------------------------------------------
  126. MessageBox displays the given string in a standard sized dialog box.
  127. Before the dialog is displayed the Msg and Params are passed to FormatStr.
  128. The resulting string is displayed as a TStaticText view in the dialog.
  129. 30Sep99 LdB
  130. ---------------------------------------------------------------------}
  131. FUNCTION MessageBox (Const Msg: Sw_String; Params: Pointer;
  132. AOptions: Word): Word;
  133. {-MessageBoxRect-----------------------------------------------------
  134. MessageBoxRec allows the specification of a TRect for the message box
  135. to occupy.
  136. 30Sep99 LdB
  137. ---------------------------------------------------------------------}
  138. FUNCTION MessageBoxRect (Var R: TRect; Const Msg: Sw_String; Params: Pointer;
  139. AOptions: Word): Word;
  140. {-MessageBoxRectDlg--------------------------------------------------
  141. MessageBoxRecDlg allows the specification of a TRect for the message box
  142. to occupy plus the dialog window (to allow different dialog window types).
  143. ---------------------------------------------------------------------}
  144. FUNCTION MessageBoxRectDlg (Dlg: PDialog; Var R: TRect; Const Msg: Sw_String;
  145. Params: Pointer; AOptions: Word): Word;
  146. {-InputBox-----------------------------------------------------------
  147. InputBox displays a simple dialog that allows user to type in a string
  148. 30Sep99 LdB
  149. ---------------------------------------------------------------------}
  150. FUNCTION InputBox (Const Title, ALabel: Sw_String; Var S: Sw_String;
  151. Limit: Byte): Word;
  152. {-InputBoxRect-------------------------------------------------------
  153. InputBoxRect is like InputBox but allows the specification of a rectangle.
  154. 30Sep99 LdB
  155. ---------------------------------------------------------------------}
  156. FUNCTION InputBoxRect (Var Bounds: TRect; Const Title, ALabel: Sw_String;
  157. Var S: Sw_String; Limit: Byte): Word;
  158. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  159. IMPLEMENTATION
  160. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  161. {$ifdef FV_UNICODE}
  162. USES UDrivers, UViews, UApp{, Resource}; { Standard GFV units }
  163. {$else FV_UNICODE}
  164. USES Drivers, Views, App{, Resource}; { Standard GFV units }
  165. {$endif FV_UNICODE}
  166. {***************************************************************************}
  167. { INTERFACE ROUTINES }
  168. {***************************************************************************}
  169. const
  170. Commands: array[0..3] of word =
  171. (cmYes, cmNo, cmOK, cmCancel);
  172. var
  173. {$ifdef FV_UNICODE}
  174. ButtonName: array[0..3] of Sw_String;
  175. {$else FV_UNICODE}
  176. ButtonName: array[0..3] of string[40];
  177. {$endif FV_UNICODE}
  178. resourcestring sConfirm='Confirm';
  179. sError='Error';
  180. sInformation='Information';
  181. sWarning='Warning';
  182. {---------------------------------------------------------------------------}
  183. { MessageBox -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  184. {---------------------------------------------------------------------------}
  185. FUNCTION MessageBox(Const Msg: Sw_String; Params: Pointer; AOptions: Word): Word;
  186. VAR R: TRect;
  187. BEGIN
  188. R.Assign(0, 0, 40, 9); { Assign area }
  189. If (AOptions AND mfInsertInApp = 0) Then { Non app insert }
  190. R.Move((Desktop^.Size.X - R.B.X) DIV 2,
  191. (Desktop^.Size.Y - R.B.Y) DIV 2) Else { Calculate position }
  192. R.Move((Application^.Size.X - R.B.X) DIV 2,
  193. (Application^.Size.Y - R.B.Y) DIV 2); { Calculate position }
  194. MessageBox := MessageBoxRect(R, Msg, Params,
  195. AOptions); { Create message box }
  196. END;
  197. FUNCTION MessageBoxRectDlg (Dlg: PDialog; Var R: TRect; Const Msg: Sw_String;
  198. Params: Pointer; AOptions: Word): Word;
  199. VAR I, X, ButtonCount: SmallInt; S: Sw_String; Control: PView;
  200. ButtonList: Array[0..4] Of PView;
  201. BEGIN
  202. With Dlg^ Do Begin
  203. FormatStr(S, Msg, Params^); { Format the message }
  204. Control := New(PStaticText, Init(R, S)); { Create static text }
  205. Insert(Control); { Insert the text }
  206. X := -2; { Set initial value }
  207. ButtonCount := 0; { Clear button count }
  208. For I := 0 To 3 Do
  209. If (AOptions AND ($0100 SHL I) <> 0) Then Begin
  210. R.Assign(0, 0, 10, 2); { Assign screen area }
  211. Control := New(PButton, Init(R, ButtonName[I],
  212. Commands[i], bfNormal)); { Create button }
  213. Inc(X, Control^.Size.X + 2); { Adjust position }
  214. ButtonList[ButtonCount] := Control; { Add to button list }
  215. Inc(ButtonCount); { Inc button count }
  216. End;
  217. X := (Size.X - X) SHR 1; { Calc x position }
  218. If (ButtonCount > 0) Then
  219. For I := 0 To ButtonCount - 1 Do Begin { For each button }
  220. Control := ButtonList[I]; { Transfer button }
  221. Insert(Control); { Insert button }
  222. Control^.MoveTo(X, Size.Y - 3); { Position button }
  223. Inc(X, Control^.Size.X + 2); { Adjust position }
  224. End;
  225. SelectNext(False); { Select first button }
  226. End;
  227. If (AOptions AND mfInsertInApp = 0) Then
  228. MessageBoxRectDlg := DeskTop^.ExecView(Dlg) Else { Execute dialog }
  229. MessageBoxRectDlg := Application^.ExecView(Dlg); { Execute dialog }
  230. end;
  231. {---------------------------------------------------------------------------}
  232. { MessageBoxRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  233. {---------------------------------------------------------------------------}
  234. FUNCTION MessageBoxRect(Var R: TRect; Const Msg: Sw_String; Params: Pointer;
  235. AOptions: Word): Word;
  236. var
  237. Dialog: PDialog;
  238. BEGIN
  239. Dialog := New (PDialog, Init (R, MsgBoxTitles [AOptions
  240. AND $3])); { Create dialog }
  241. with Dialog^ do
  242. R.Assign(3, 2, Size.X - 2, Size.Y - 3); { Assign area for text }
  243. MessageBoxRect := MessageBoxRectDlg (Dialog, R, Msg, Params, AOptions);
  244. Dispose (Dialog, Done); { Dispose of dialog }
  245. END;
  246. {---------------------------------------------------------------------------}
  247. { InputBox -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  248. {---------------------------------------------------------------------------}
  249. FUNCTION InputBox(Const Title, ALabel: Sw_String; Var S: Sw_String;
  250. Limit: Byte): Word;
  251. VAR R: TRect;
  252. BEGIN
  253. R.Assign(0, 0, 60, 8); { Assign screen area }
  254. R.Move((Desktop^.Size.X - R.B.X) DIV 2,
  255. (Desktop^.Size.Y - R.B.Y) DIV 2); { Position area }
  256. InputBox := InputBoxRect(R, Title, ALabel, S,
  257. Limit); { Create input box }
  258. END;
  259. {---------------------------------------------------------------------------}
  260. { InputBoxRect -> Platforms DOS/DPMI/WIN/NT/OS2 - Updated 30Sep99 LdB }
  261. {---------------------------------------------------------------------------}
  262. FUNCTION InputBoxRect(Var Bounds: TRect; Const Title, ALabel: Sw_String;
  263. Var S: Sw_String; Limit: Byte): Word;
  264. VAR C: Word; R: TRect; Control: PView; Dialog: PDialog;
  265. BEGIN
  266. Dialog := New(PDialog, Init(Bounds, Title)); { Create dialog }
  267. With Dialog^ Do Begin
  268. R.Assign(4 + CStrLen(ALabel), 2, Size.X - 3, 3); { Assign screen area }
  269. Control := New(PInputLine, Init(R, Limit)); { Create input line }
  270. Insert(Control); { Insert input line }
  271. R.Assign(2, 2, 3 + CStrLen(ALabel), 3); { Assign screen area }
  272. Insert(New(PLabel, Init(R, ALabel, Control))); { Insert label }
  273. R.Assign(Size.X - 24, Size.Y - 4, Size.X - 14,
  274. Size.Y - 2); { Assign screen area }
  275. Insert(New(PButton, Init(R, 'O~K~', cmOk,
  276. bfDefault))); { Insert okay button }
  277. Inc(R.A.X, 12); { New start x position }
  278. Inc(R.B.X, 12); { New end x position }
  279. Insert(New(PButton, Init(R, 'Cancel', cmCancel,
  280. bfNormal))); { Insert cancel button }
  281. Inc(R.A.X, 12); { New start x position }
  282. Inc(R.B.X, 12); { New end x position }
  283. SelectNext(False); { Select first button }
  284. End;
  285. Dialog^.SetData(S); { Set data in dialog }
  286. C := DeskTop^.ExecView(Dialog); { Execute the dialog }
  287. If (C <> cmCancel) Then Dialog^.GetData(S); { Get data from dialog }
  288. Dispose(Dialog, Done); { Dispose of dialog }
  289. InputBoxRect := C; { Return execute result }
  290. END;
  291. procedure InitMsgBox;
  292. begin
  293. ButtonName[0] := slYes;
  294. ButtonName[1] := slNo;
  295. ButtonName[2] := slOk;
  296. ButtonName[3] := slCancel;
  297. MsgBoxTitles[0] := sWarning;
  298. MsgBoxTitles[1] := sError;
  299. MsgBoxTitles[2] := sInformation;
  300. MsgBoxTitles[3] := sConfirm;
  301. end;
  302. procedure DoneMsgBox;
  303. begin
  304. end;
  305. END.