home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / dtx9302 / tvision / tvpas / msgboxg.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-11-09  |  5.3 KB  |  172 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Turbo Pascal Version 6.0                        }
  5. {       Turbo Vision Unit                               }
  6. {                                                       }
  7. {       Copyright (c) 1990 Borland International        }
  8. {                                                       }
  9. {*******************************************************}
  10. {$R-,S-,I-,B-,D-,L-,V-,A+,F+,O+,X+}
  11.  
  12.  
  13. unit MsgBoxG;
  14.  
  15.  
  16. interface
  17.  
  18. uses Objects;
  19.  
  20. const
  21.  
  22. { Message box classes }
  23.  
  24.   mfWarning      = $0000;       { Display a Warning box }
  25.   mfError        = $0001;       { Dispaly a Error box }
  26.   mfInformation  = $0002;       { Display an Information Box }
  27.   mfConfirmation = $0003;       { Display a Confirmation Box }
  28.  
  29. { Message box button flags }
  30.  
  31.   mfYesButton    = $0100;       { Put a Yes button into the dialog }
  32.   mfNoButton     = $0200;       { Put a No button into the dialog }
  33.   mfOKButton     = $0400;       { Put an OK button into the dialog }
  34.   mfCancelButton = $0800;       { Put a Cancel button into the dialog }
  35.  
  36.   mfYesNoCancel  = mfYesButton + mfNoButton + mfCancelButton;
  37.                                 { Standard Yes, No, Cancel dialog }
  38.   mfOKCancel     = mfOKButton + mfCancelButton;
  39.                                 { Standard OK, Cancel dialog }
  40.  
  41. { MessageBox displays the given string in a standard sized      }
  42. { dialog box. Before the dialog is displayed the Msg and Params }
  43. { are passed to FormatStr.  The resulting string is displayed   }
  44. { as a TStaticText view in the dialog.                          }
  45.  
  46. function MessageBox(Msg: String; Params: Pointer; AOptions: Word): Word;
  47.  
  48. { MessageBoxRec allows the specification of a TRect for the     }
  49. { message box to occupy.                                        }
  50.  
  51. function MessageBoxRect(var R: TRect; Msg: String; Params: Pointer;
  52.   AOptions: Word): Word;
  53.  
  54. { InputBox displays a simple dialog that allows the user to     }
  55. { type in a string.                                             }
  56.  
  57. function InputBox(Title: String; ALabel: String; var S: String;
  58.   Limit: Byte): Word;
  59.  
  60. { InputBoxRect is like InputBox but allows the specification of }
  61. { a rectangle.                                                  }
  62.  
  63. function InputBoxRect(var Bounds: TRect; Title: String; ALabel: String;
  64.   var S: String;  Limit: Byte): Word;
  65.  
  66. implementation
  67.  
  68. uses Drivers, Views, Dialogs, App;
  69.  
  70. function MessageBox(Msg: String; Params: Pointer;
  71.   AOptions: Word): Word;
  72. var
  73.   R: TRect;
  74. begin
  75.   R.Assign(0, 0, 41, 9);
  76.   R.Move((Desktop^.Size.X - R.B.X) div 2, (Desktop^.Size.Y - R.B.Y) div 2);
  77.   MessageBox := MessageBoxRect(R, Msg, Params, AOptions);
  78. end;
  79.  
  80. function MessageBoxRect(var R: TRect; Msg: String; Params: Pointer;
  81.   AOptions: Word): Word;
  82. const
  83.   ButtonName: array[0..3] of string[7] =
  84.     ('~J~a', '~N~ein', 'O~K~', 'Abbruch');
  85.   Commands: array[0..3] of word =
  86.     (cmYes, cmNo, cmOK, cmCancel);
  87.   Titles: array[0..3] of string[11] =
  88.     ('Warnung','Fehler','Information','Bestätigen');
  89. var
  90.   I, X, ButtonCount: Integer;
  91.   Dialog: PDialog;
  92.   Control: PView;
  93.   T: TRect;
  94.   ButtonList: array[0..4] of PView;
  95.   S: String;
  96. begin
  97.   Dialog := New(PDialog,
  98.     Init(R, Titles[AOptions and $3]));
  99.   with Dialog^ do
  100.   begin
  101.     R.Assign(3, 2, Size.X - 2, Size.Y - 3);
  102.     FormatStr(S, Msg, Params^);
  103.     Control := New(PStaticText, Init(R, S));
  104.     Insert(Control);
  105.     X := -2;
  106.     ButtonCount := 0;
  107.     for I := 0 to 3 do
  108.       if AOptions and ($0100 shl I) <> 0 then
  109.       begin
  110.         R.Assign(0, 0, 10, 2);
  111.         Control := New(PButton, Init(R, ButtonName[I], Commands[i],
  112.           bfNormal));
  113.         Inc(X, Control^.Size.X + 2);
  114.         ButtonList[ButtonCount] := Control;
  115.         Inc(ButtonCount);
  116.       end;
  117.     X := (Size.X - X) shr 1;
  118.     for I := 0 to ButtonCount - 1 do
  119.     begin
  120.       Control := ButtonList[I];
  121.       Insert(Control);
  122.       Control^.MoveTo(X, Size.Y - 3);
  123.       Inc(X, Control^.Size.X + 2);
  124.     end;
  125.     SelectNext(False);
  126.   end;
  127.   MessageBoxRect := DeskTop^.ExecView(Dialog);
  128.   Dispose(Dialog, Done);
  129. end;
  130.  
  131. function InputBox(Title: String; ALabel: String; var S: String;
  132.   Limit: Byte): Word;
  133. var
  134.   R: TRect;
  135. begin
  136.   R.Assign(0, 0, 61, 8);
  137.   R.Move((Desktop^.Size.X - R.B.X) div 2, (Desktop^.Size.Y - R.B.Y) div 2);
  138.   InputBox := InputBoxRect(R, Title, ALabel, S, Limit);
  139. end;
  140.  
  141. function InputBoxRect(var Bounds: TRect; Title: String; ALabel: String;
  142.   var S: String;  Limit: Byte): Word;
  143. var
  144.   Dialog: PDialog;
  145.   Control: PView;
  146.   R: TRect;
  147.   C: Word;
  148. begin
  149.   Dialog := New(PDialog, Init(Bounds, Title));
  150.   with Dialog^ do
  151.   begin
  152.     R.Assign(4 + CStrLen(ALabel), 2, Size.X - 3, 3);
  153.     Control := New(PInputLine, Init(R, Limit));
  154.     Insert(Control);
  155.     R.Assign(2, 2, 3 + CStrLen(ALabel), 3);
  156.     Insert(New(PLabel, Init(R, ALabel, Control)));
  157.     R.Assign(Size.X - 24, Size.Y - 4, Size.X - 14, Size.Y - 2);
  158.     Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
  159.     Inc(R.A.X, 12); Inc(R.B.X, 13);
  160.     Insert(New(PButton, Init(R, 'Abbruch', cmCancel, bfNormal)));
  161.     Inc(R.A.X, 12); Inc(R.B.X, 12);
  162.     SelectNext(False);
  163.   end;
  164.   Dialog^.SetData(S);
  165.   C := DeskTop^.ExecView(Dialog);
  166.   if C <> cmCancel then Dialog^.GetData(S);
  167.   Dispose(Dialog, Done);
  168.   InputBoxRect := C;
  169. end;
  170.  
  171. end.
  172.