home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / dtx9302 / tvision / install / msgbox.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-03-08  |  8.5 KB  |  264 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Turbo Pascal Version 6.0                        }
  4. {       Turbo Vision Unit                               }
  5. {                                                       }
  6. {       Copyright (c) 1990 Borland International        }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit MsgBox;
  11.  
  12. {$F+,O+,X+,D-}
  13.  
  14. interface
  15.  
  16. uses crt,Objects;
  17.  
  18. const
  19.  
  20. { Message box classes }
  21.  
  22.   mfWarning      = $0000;       { Anzeige einer Warnung }
  23.   mfError        = $0001;       { Anzeige eines Fehlers }
  24.   mfInformation  = $0002;       { Anzeige einer Information }
  25.   mfConfirmation = $0003;       { Anzeige einer Bestätigung }
  26.   mfHelp         = $0004;       { Anzeige einer Hilfe }
  27.  
  28. { Message box button flags }
  29.  
  30.   mfYesButton    = $0100;       { Put a Yes button into the dialog }
  31.   mfNoButton     = $0200;       { Put a No button into the dialog }
  32.   mfOKButton     = $0400;       { Put an OK button into the dialog }
  33.   mfCancelButton = $0800;       { Put a Cancel button into the dialog }
  34.  
  35.   mfYesNoCancel  = mfYesButton + mfNoButton + mfCancelButton;
  36.                                 { Standard Yes, No, Cancel dialog }
  37.   mfOKCancel     = mfOKButton + mfCancelButton;
  38.                                 { Standard OK, Cancel dialog }
  39.  
  40. { MessageBox gibt einen String in der Standard-Größe in der Dialog-    }
  41. { Box aus. Bevor der Dialog ausgegeben wird, wird  Msg und Params      }
  42. { an FormatStr übergeben. Der Ergebnis-String wird als ein TStaticTxt  }
  43. { im Dialog-Fenster ausgegeben. }
  44.  
  45. function MessageBox(Msg: String; Params: Pointer;
  46.          XL,YL,AOptions: Word): Word;
  47.  
  48. { MessageBoxRec erlaubt die Festlegung von TRect für die }
  49. { Messagebox als Einstellung}
  50.  
  51. function MessageBoxRect(var R: TRect; Msg: String; Params: Pointer;
  52.          AOptions: Word): Word;
  53.  
  54. { MessageBoxGross gibt einen String in der Standard-Größe in der Dialog- }
  55. { Box aus. Bevor der Dialog ausgegeben wird, wird  Msg und Params        }
  56. { an FormatStr übergeben. Der Ergebnis-String wird als ein TStaticTxt    }
  57. { im Dialog-Fenster ausgegeben. }
  58.  
  59. function MessageBoxGross(Msg: String; Params: Pointer;
  60.          Msg2: String; Params1: Pointer; Msg3: String;
  61.           Params2: Pointer; XL,YL,AOptions: Word): Word;
  62.  
  63. { MessageBoxRecGross erlaubt die Festlegung von TRect für die }
  64. { MessageboxGross als Einstellung}
  65.  
  66. function MessageBoxRectGross(var R: TRect; Msg: String;Params: Pointer;
  67.          Msg2: String;Params1: Pointer; Msg3: String; Params2: Pointer;
  68.          AOptions: Word): Word;
  69.  
  70. { InputBox gibt eine einfache Ausgabe heraus als Dialog  }
  71. { der dem Nutzer erlaubt einen einfachen String einzugeben }
  72.  
  73. function InputBox(Title: String; ALabel: String; var S: String;
  74.   Limit: Byte): Word;
  75.  
  76. { InputBoxRect ist wie InputBox, aber erlaubt die Specifikation }
  77. { eines Rechteckes.                                              }
  78.  
  79. function InputBoxRect(var Bounds: TRect; Title: String; ALabel: String;
  80.   var S: String;  Limit: Byte): Word;
  81.  
  82. implementation
  83.  
  84. uses Drivers, Views, Dialogs, App;
  85.  
  86. function MessageBox(Msg: String; Params: Pointer;
  87.          XL,YL,AOptions: Word): Word;
  88. var
  89.   R: TRect;
  90. begin
  91.   R.Assign(0, 0, XL, YL);
  92.   R.Move((Desktop^.Size.X - R.B.X) div 2, (Desktop^.Size.Y - R.B.Y) div 2);
  93.   MessageBox := MessageBoxRect(R, Msg, Params, AOptions);
  94. end;
  95.  
  96. function MessageBoxRect(var R: TRect; Msg: String; Params: Pointer;
  97.   AOptions: Word): Word;
  98. const
  99.   ButtonName: array[0..3] of string[8] =
  100.     ('~J~a', '~N~ein', 'O~K~', '~B~eenden');
  101.   Commands: array[0..3] of word =
  102.     (cmYes, cmNo, cmOK, cmCancel);
  103.   Titles: array[0..4] of string[17] =
  104.     (' Warnung ',' Fehler ',' Information ',' Bestätige ',' Hilfsanzeigen ');
  105. var
  106.   I, X, ButtonCount: Integer;
  107.   Dialog: PDialog;
  108.   Control: PView;
  109.   T: TRect;
  110.   ButtonList: array[0..4] of PView;
  111.   S: String;
  112. begin
  113.   Dialog := New(PDialog,
  114.     Init(R, Titles[AOptions and $3]));
  115.   with Dialog^ do
  116.   begin
  117.     R.Assign(3, 2, Size.X - 2, Size.Y - 3);
  118.     FormatStr(S, Msg, Params^);
  119.     Control := New(PStaticText, Init(R, S));
  120.     Insert(Control);
  121.     X := -2;
  122.     ButtonCount := 0;
  123.     for I := 0 to 3 do
  124.       if AOptions and ($0100 shl I) <> 0 then
  125.       begin
  126.         R.Assign(0, 0, 10, 2);
  127.         Control := New(PButton, Init(R, ButtonName[I], Commands[i],
  128.           bfNormal));
  129.         Inc(X, Control^.Size.X + 2);
  130.         ButtonList[ButtonCount] := Control;
  131.         Inc(ButtonCount);
  132.       end;
  133.     X := (Size.X - X) shr 1;
  134.     for I := 0 to ButtonCount - 1 do
  135.     begin
  136.       Control := ButtonList[I];
  137.       Insert(Control);
  138.       Control^.MoveTo(X, Size.Y - 3);
  139.       Inc(X, Control^.Size.X + 2);
  140.     end;
  141.     SelectNext(False);
  142.   end;
  143.   MessageBoxRect := DeskTop^.ExecView(Dialog);
  144.   Dispose(Dialog, Done);
  145. end;
  146.  
  147. function MessageBoxGross(Msg: String;Params: Pointer; Msg2: String;
  148.          Params1: Pointer; Msg3: String; Params2: Pointer;
  149.           XL,YL,AOptions: Word): Word;
  150. var
  151.   R: TRect;
  152. begin
  153.   R.Assign(0, 0, XL, YL);
  154.   R.Move((Desktop^.Size.X - R.B.X) div 2, (Desktop^.Size.Y - R.B.Y) div 2);
  155.   MessageBoxGross := MessageBoxRectGross
  156.   (R, Msg,Params,Msg2,Params1,Msg3,Params2, AOptions);
  157. end;
  158.  
  159. function MessageBoxRectGross(var R: TRect; Msg: String;Params: Pointer;
  160.           Msg2: String;Params1: Pointer; Msg3: String;Params2: Pointer;
  161.           AOptions: Word): Word;
  162. const
  163.   ButtonName: array[0..3] of string[8] =
  164.     ('~J~a', '~N~ein', 'O~K~', '~B~eenden');
  165.   Commands: array[0..3] of word =
  166.     (cmYes, cmNo, cmOK, cmCancel);
  167.   Titles: array[0..4] of string[17] =
  168.     (' Warnung ',' Fehler ',' Information ',' Bestätige ',' Hilfsanzeigen ');
  169. var
  170.   I, X, ButtonCount: Integer;
  171.   Dialog: PDialog;
  172.   Control: PView;
  173.   T: TRect;
  174.   ButtonList: array[0..4] of PView;
  175.   S: String; S1:String; S2:String;
  176.  
  177. begin
  178.    {Ausgabe-Fenster mit max 3 String-Ausgaben, mit 4 bzw. 6 Zeilen)
  179.    {die Größe ist abhänging von B.X und B.Y bzw. XL und YL }
  180.  
  181.     Dialog := New(PDialog,
  182.     Init(R, Titles[AOptions and $4]));
  183.   with Dialog^ do
  184.   begin
  185.     R.Assign(3, 2, Size.X - 2, Size.Y - 16);
  186.     FormatStr(S, Msg, Params^);
  187.     Control := New(PStaticText, Init(R, S));
  188.     Insert(Control);
  189.     R.Assign(3, Size.Y-15, Size.X - 2, Size.Y-11);
  190.     FormatStr(S1, Msg2, Params1^);
  191.     Control := New(PStaticText, Init(R, S1));
  192.     Insert(Control);
  193.     R.Assign(3, Size.Y-10, Size.X - 2, Size.Y - 4);
  194.     FormatStr(S2, Msg3, Params2^);
  195.     Control := New(PStaticText, Init(R, S2));
  196.     Insert(Control);
  197.     X := -2;
  198.     ButtonCount := 0;
  199.     for I := 0 to 3 do
  200.       if AOptions and ($0100 shl I) <> 0 then
  201.       begin
  202.         R.Assign(0, 0, 10, 2);
  203.         Control := New(PButton, Init(R, ButtonName[I], Commands[i],
  204.           bfNormal));
  205.         Inc(X, Control^.Size.X + 2);
  206.         ButtonList[ButtonCount] := Control;
  207.         Inc(ButtonCount);
  208.       end;
  209.     X := (Size.X - X) shr 1;
  210.     for I := 0 to ButtonCount - 1 do
  211.     begin
  212.       Control := ButtonList[I];
  213.       Insert(Control);
  214.       Control^.MoveTo(X, Size.Y - 3);
  215.       Inc(X, Control^.Size.X + 2);
  216.     end;
  217.     SelectNext(False);
  218.   end;
  219.   MessageBoxRectGross := DeskTop^.ExecView(Dialog);
  220.   Dispose(Dialog, Done);
  221. end;
  222.  
  223. function InputBox(Title: String; ALabel: String; var S: String;
  224.   Limit: Byte): Word;
  225. var
  226.   R: TRect;
  227. begin
  228.   R.Assign(0, 0, 60, 8);
  229.   R.Move((Desktop^.Size.X - R.B.X) div 2, (Desktop^.Size.Y - R.B.Y) div 2);
  230.   InputBox := InputBoxRect(R, Title, ALabel, S, Limit);
  231. end;
  232.  
  233. function InputBoxRect(var Bounds: TRect; Title: String; ALabel: String;
  234.   var S: String;  Limit: Byte): Word;
  235. var
  236.   Dialog: PDialog;
  237.   Control: PView;
  238.   R: TRect;
  239.   C: Word;
  240. begin
  241.   Dialog := New(PDialog, Init(Bounds, Title));
  242.   with Dialog^ do
  243.   begin
  244.     R.Assign(4 + CStrLen(ALabel), 2, Size.X - 3, 3);
  245.     Control := New(PInputLine, Init(R, Limit));
  246.     Insert(Control);
  247.     R.Assign(2, 2, 3 + CStrLen(ALabel), 3);
  248.     Insert(New(PLabel, Init(R, ALabel, Control)));
  249.     R.Assign(Size.X - 24, Size.Y - 4, Size.X - 14, Size.Y - 2);
  250.     Insert(New(PButton, Init(R, 'O~K~', cmOk, bfDefault)));
  251.     Inc(R.A.X, 12); Inc(R.B.X, 12);
  252.     Insert(New(PButton, Init(R, 'Beende', cmCancel, bfNormal)));
  253.     Inc(R.A.X, 12); Inc(R.B.X, 12);
  254.     SelectNext(False);
  255.   end;
  256.   Dialog^.SetData(S);
  257.   C := DeskTop^.ExecView(Dialog);
  258.   if C <> cmCancel then Dialog^.GetData(S);
  259.   Dispose(Dialog, Done);
  260.   InputBoxRect := C;
  261. end;
  262.  
  263. end.
  264.