home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w048 / 2.ddi / MSSRC.ARC / MSUSERIO.INC < prev    next >
Encoding:
Text File  |  1987-12-21  |  14.5 KB  |  520 lines

  1. {                           MSUSERIO.INC
  2.                                MS 4.0
  3.                 Copyright (c) 1985, 87 by Borland International, Inc.         }
  4.  
  5.   procedure EdDisplayPromptWindow(msg : VarString; Yp : Integer;
  6.                                   OKset : Charset; var Ch : Char;
  7.                                   BoxAttr : BoxType);
  8.     {-Pop up a one line message window, and wait for char in OKset to clear it}
  9.   var
  10.     W : WindowPtr;
  11.     Xp, Wid : Integer;
  12.     CursorState : Boolean;
  13.  
  14.   begin                      {EdDisplayPromptWindow}
  15.     {Get rid of any status display}
  16.     EdEraseMenuHelp;
  17.     EdWritePromptLine('');
  18.  
  19.     {Reset Turbo window}
  20.     EdWindow(1, 1, PhyScrCols, PhyscrRows);
  21.  
  22.     {Center the window in x direction}
  23.     Xp := Pred((80-Length(msg)) shr 1);
  24.     Wid := Length(msg)+2;
  25.     W := EdSetupWindow(Border, Xp, Yp, Pred(Xp+Wid), Yp+2, BoxAttr);
  26.     EdFastWrite(msg, Succ(Yp), Succ(Xp), TextAttr[BoxAttr]);
  27.  
  28.     {Show the hardware cursor}
  29.     CursorState := SolidCursor;
  30.     SolidCursor := False;
  31.     GoToXY(Xp+Length(msg), Succ(Yp));
  32.     EdSetInsertMode(AskforInsertflag);
  33.  
  34.     {Wait for a key in OKset}
  35.     repeat
  36.       Ch := EdControlFilter(EdGetAnyChar);
  37.     until Abortcmd or (Ch in OKset);
  38.  
  39.     {Remove window}
  40.     EdRestoreWindow(W, Xp, Yp, Wid, 3);
  41.     {Restore cursor}
  42.     SolidCursor := CursorState;
  43.     EdSetCursorOff;
  44.     if EdPtrIsNil(CurrMenu) then begin
  45.       {Reposition cursor on screen}
  46.       EdUpdateCursor;
  47.       EdShowMenuHelp;
  48.     end else
  49.       {Turn off hardware cursor}
  50.       EdSetCursor(CursorOff);
  51.   end;                       {EdDisplayPromptWindow}
  52.  
  53.   function EdYesNo(Prompt : VarString) : Boolean;
  54.     {-Return True for Yes, False for No}
  55.   var
  56.     Ch : Char;
  57.     R : Byte;
  58.  
  59.   begin                      {EdYesNo}
  60.     if WindowCount <= 0 then
  61.       R := 20
  62.     else begin
  63.       with Curwin^ do
  64.         R := (Firstlineno+Lastlineno-3) shr 1;
  65.       if R < LogtopScr then
  66.         R := LogtopScr
  67.       else if R > LogscrRows-3 then
  68.         R := LogscrRows-3;
  69.     end;
  70.     AbortEnable := True;
  71.     EdDisplayPromptWindow(Prompt, R, [^Y, ^N, #27], Ch, NormalBox);
  72.     EdYesNo := (Ch = ^Y);
  73.     if Ch = #27 then
  74.       AbortCmd := true;
  75.   end;                       {EdYesNo}
  76.  
  77.   procedure EdErrormsg(Msgno : Integer);
  78.     {-Pop up an error message box, and clear any typeahead keystrokes}
  79.   var
  80.     Ch : Char;
  81.     Row : Integer;
  82.  
  83.   begin                      {EdErrormsg}
  84.     {Clear keyboard buffer}
  85.     EdClearBuffer;
  86.     {Set error flag to be polled as needed by calling routines}
  87.     Goterror := True;
  88.     {Set up a window, display the message and wait for a key}
  89.     with Curwin^ do
  90.       Row := Pred(Firsttextno+Lineno);
  91.     if Row > LogscrRows-3 then
  92.       Row := LogscrRows-3;
  93.     EdDisplayPromptWindow(
  94.       EdGetMessage(Msgno)+'-'+EdGetMessage(305), Row, [#27], Ch, ErrorBox);
  95.     {Clear keyboard buffer again}
  96.     EdClearBuffer;
  97.     UpdateCursor := True;
  98.     EdZapPromptLine;
  99.   end;                       {EdErrormsg}
  100.  
  101.   function EdFileerror : Boolean;
  102.     {-Report error during file operation}
  103.   var
  104.     Code : Integer;
  105.  
  106.   begin                      {EdFileerror}
  107.     Code := EdINT24Result;
  108.     if hi(Code) <> 0 then
  109.       EdErrormsg(128)
  110.     else if Code <> 0 then
  111.       EdErrormsg(Code);
  112.     EdFileerror := (Code <> 0);
  113.   end;                       {EdFileerror}
  114.  
  115.   procedure EdAskforEditor(Xp, Yp, XSize, Maxlen : Integer;
  116.                            HaveWindow : Boolean;
  117.                            var Rs : VarString);
  118.     {-Perform line editing functions for string input}
  119.   const
  120.     Del = #127;
  121.   var
  122.     Wp : Byte;
  123.     Ws : VarString;
  124.     Ch : Char;
  125.     Quitting, FirstRead : Boolean;
  126.  
  127.     function EdReadAndConvertChar : Char;
  128.       {-Read a character and convert extended keystrokes to single char}
  129.     const
  130.       WScommands : string[12] = ^@^A^D^F^G^B^E^S^V^X^Y^J;
  131.       EXcommands : string[11] = 'sMtSGOKRwu;';
  132.     var
  133.       Ch : Char;
  134.  
  135.     begin                    {EdReadAndConvertChar}
  136.       {Wait for a key to enter the typeahead buffer}
  137.       Ch := EdGetAnyChar;
  138.       if Abortcmd then
  139.         Exit;
  140.  
  141.       if (Ch = Null) then
  142.         {Get extended character}
  143.         {Convert IBM keypad to equivalent control char}
  144.         Ch := WScommands[Succ(Pos(EdGetAnyChar, EXcommands))];
  145.  
  146.       EdReadAndConvertChar := Ch;
  147.     end;                     {EdReadAndConvertChar}
  148.  
  149.     procedure EdDisplayString(S : VarString; Start : Byte);
  150.       {-Display the working string starting at position start}
  151.     var
  152.       I, X, Clr : Byte;
  153.       Ch : Char;
  154.  
  155.     begin                    {EdDisplayString}
  156.       if not(HaveWindow) then
  157.         Exit;
  158.       X := Xp+Start;
  159.       for I := Start to Length(S) do begin
  160.         {Display the string, converting control characters to highlighted uppercase}
  161.         Ch := S[I];
  162.         if Ch < Blank then begin
  163.           Clr := ScreenAttr[MsColor];
  164.           Ch := Chr(Ord(Ch)+64);
  165.         end else
  166.           Clr := ScreenAttr[MnColor];
  167.         EdFastWrite(Ch, Yp, X, Clr);
  168.         Inc(X);
  169.       end;
  170.       {Clear the rest of the line}
  171.       Clr := ScreenAttr[MnColor];
  172.       Ch := Blank;
  173.       while X < Pred(Xp+XSize) do begin
  174.         EdFastWrite(Ch, Yp, X, Clr);
  175.         Inc(X);
  176.       end;
  177.     end;                     {EdDisplayString}
  178.  
  179.     procedure EdClear(var Ws : VarString; var Wp : Byte);
  180.       {-Clear the working string}
  181.  
  182.     begin                    {EdClear}
  183.       EdClearString(Ws);
  184.       Wp := 1;
  185.       EdDisplayString(Ws, 1);
  186.       if HaveWindow then
  187.         GoToXY(Xp+Wp, Yp);
  188.     end;                     {EdClear}
  189.  
  190.     procedure EdInsertCharacter(Ch : Char; var Ws : VarString; var Wp : Byte);
  191.       {-Insert a character into the string}
  192.  
  193.     begin                    {EdInsertCharacter}
  194.       if Length(Ws) < Maxlen then begin
  195.         if AskforInsertflag then
  196.           Insert(Ch, Ws, Wp)
  197.         else if Wp > Length(Ws) then
  198.           Ws := Ws+Ch
  199.         else
  200.           Ws[Wp] := Ch;
  201.         EdDisplayString(Ws, Wp);
  202.         Inc(Wp);
  203.       end else if not(AskforInsertflag) and (Wp <= Length(Ws)) then begin
  204.         Ws[Wp] := Ch;
  205.         EdDisplayString(Ws, Wp);
  206.       end;
  207.     end;                     {EdInsertCharacter}
  208.  
  209.   begin                      {EdAskforEditor}
  210.  
  211.     {Get working copy of the input string}
  212.     Ws := Copy(Rs, 1, Maxlen);
  213.     Wp := Succ(Length(Ws));
  214.  
  215.     {Display the initial string}
  216.     EdDisplayString(Ws, 1);
  217.     FirstRead := True;
  218.     Quitting := False;
  219.  
  220.     repeat
  221.  
  222.       {Update the cursor}
  223.       if HaveWindow then begin
  224.         GoToXY(Xp+Wp, Yp);
  225.         EdSetInsertMode(AskforInsertflag);
  226.       end;
  227.  
  228.       {Get the next keyboard character}
  229.       Ch := EdReadAndConvertChar;
  230.       if Abortcmd then
  231.         {Get out of here}
  232.         Ch := ^[;
  233.  
  234.       if FirstRead then begin
  235.         if (Ch = ^P) or (Ch > ^Z) then
  236.           if (Ch <> Del) then
  237.             {Clear the default string}
  238.             EdClear(Ws, Wp);
  239.         FirstRead := False;
  240.       end;
  241.  
  242.       case Ch of
  243.  
  244.         ^@ :                {Null key}
  245.           ;
  246.  
  247.         ^J :                 {Get help on current command}
  248.           EdHelpWindow(GlobalCmd);
  249.  
  250.         ^M :                 {Enter, accept string and exit}
  251.           Quitting := True;
  252.  
  253.         ^[ :                 {Escape, clear string and exit}
  254.           begin
  255.             EdClear(Ws, Wp);
  256.             Quitting := True;
  257.             Abortcmd := True;
  258.           end;
  259.  
  260.         ^B :                 {Begin of line}
  261.           Wp := 1;
  262.  
  263.         ^E :                 {End of line}
  264.           Wp := Succ(Length(Ws));
  265.  
  266.         ^Y :                 {Clear to end of line}
  267.           begin
  268.             Ws := Copy(Ws, 1, Pred(Wp));
  269.             EdDisplayString(Ws, 1);
  270.           end;
  271.  
  272.         ^X :                 {Clear line}
  273.           EdClear(Ws, Wp);
  274.  
  275.         ^R :                 {Restore line to default}
  276.           begin
  277.             Ws := Copy(Rs, 1, Maxlen);
  278.             Wp := Succ(Length(Ws));
  279.             EdDisplayString(Ws, 1);
  280.           end;
  281.  
  282.         ^S :                 {Cursor left one}
  283.           if Wp > 1 then
  284.             Dec(Wp);
  285.  
  286.         ^D :                 {Cursor right one}
  287.           if Wp <= Length(Ws) then
  288.             Inc(Wp);
  289.  
  290.         ^A :                 {Cursor left one word}
  291.           if Wp > 1 then begin
  292.             Dec(Wp);
  293.             while (Wp >= 1) and ((Wp > Length(Ws)) or (Ws[Wp] = Blank)) do
  294.               Dec(Wp);
  295.             while (Wp >= 1) and (Ws[Wp] <> Blank) do
  296.               Dec(Wp);
  297.             Inc(Wp);
  298.           end;
  299.  
  300.         ^F :                 {Cursor right one word}
  301.           if Wp <= Length(Ws) then begin
  302.             Inc(Wp);
  303.             while (Wp <= Length(Ws)) and (Ws[Wp] <> Blank) do
  304.               Inc(Wp);
  305.             while (Wp <= Length(Ws)) and (Ws[Wp] = Blank) do
  306.               Inc(Wp);
  307.           end;
  308.  
  309.         ^G :                 {Delete current character}
  310.           if Wp <= Length(Ws) then begin
  311.             Delete(Ws, Wp, 1);
  312.             EdDisplayString(Ws, Wp);
  313.           end;
  314.  
  315.         ^H, Del :            {Delete character left}
  316.           if Wp > 1 then begin
  317.             Dec(Wp);
  318.             Delete(Ws, Wp, 1);
  319.             EdDisplayString(Ws, Wp);
  320.           end;
  321.  
  322.         ^P :                 {Accept control character}
  323.           EdInsertCharacter(Chr(Ord(EdReadAndConvertChar) and $1F), Ws, Wp);
  324.  
  325.         ^V :                 {Toggle insert mode}
  326.           AskforInsertflag := not(AskforInsertflag);
  327.  
  328.       else
  329.         {Insert normal character}
  330.         if Ch > ^Z then
  331.           EdInsertCharacter(Ch, Ws, Wp);
  332.       end;
  333.  
  334.     until Quitting;
  335.  
  336.     {Return the working string}
  337.     Rs := Ws;
  338.  
  339.   end;                       {EdAskforEditor}
  340.  
  341.   procedure EdAskfor(Prompt : VarString;
  342.                      Xp, Yp, Wid : Integer;
  343.                      var Rs : VarString);
  344.     {-Edit and return a string}
  345.   var
  346.     W : WindowPtr;
  347.     Width : Integer;
  348.     HaveWindow, CursorState : Boolean;
  349.  
  350.   begin                      {EdAskFor}
  351.  
  352.     if Abortcmd then
  353.       Exit;
  354.     AbortEnable := True;
  355.  
  356.     if EditUsercommandInput = 0 then begin
  357.       {Not in a macro, update the screen}
  358.       EdEraseMenuHelp;
  359.       EdUpdateCmdLine;
  360.  
  361.       {Expand window width to hold prompt}
  362.       if Length(Prompt)+2 > Wid then
  363.         Width := Length(Prompt)+2
  364.       else
  365.         Width := Wid;
  366.  
  367.       {Define a window}
  368.       W := EdSetupWindow(Border, Xp, Yp, Pred(Xp+Width), Yp+2, NormalBox);
  369.  
  370.       {Display the prompt}
  371.       EdFastWrite(Prompt, Yp, Xp+(Width-Length(Prompt)) shr 1, ScreenAttr[MfColor]);
  372.       HaveWindow := True;
  373.       CursorState := SolidCursor;
  374.       SolidCursor := False;
  375.     end else
  376.       {Don't waste time on screen within macros}
  377.       HaveWindow := False;
  378.  
  379.     {Perform the edit, returning a new string Rs}
  380.     EdAskforEditor(Xp, Succ(Yp), Width, Wid-3, HaveWindow, Rs);
  381.  
  382.     if HaveWindow then begin
  383.       {Remove window}
  384.       EdRestoreWindow(W, Xp, Yp, Width, 3);
  385.       {Restore cursor}
  386.       SolidCursor := CursorState;
  387.       EdSetCursorOff;
  388.       if EdPtrIsNil(CurrMenu) then
  389.         EdUpdateCursor;
  390.     end;
  391.     if Abortcmd then
  392.       Exit;
  393.     AbortEnable := True;
  394.  
  395.   end;                       {EdAskfor}
  396.  
  397.   procedure EdArg2Integer(Arg : String255; Min, Max : Integer; var V);
  398.     {-Return an integer value corresponding to command parameter}
  399.   var
  400.     Value : Integer absolute V;
  401.     I : Integer;
  402.     Code : Word;
  403.  
  404.   begin                      {EdArg2Integer}
  405.     {Delete leading blanks}
  406.     EdDeleteLeadingBlanks(Arg);
  407.     {Delete all but first word}
  408.     EdDeleteTrailers(Arg);
  409.     Val(Arg, I, Code);
  410.     if (Code = 0) and (I >= Min) and (I <= Max) then
  411.       Value := I;
  412.   end;                       {EdArg2Integer}
  413.  
  414.   procedure EdString2integer(Src : VarString; var R);
  415.     {-Convert string to integer}
  416.     {-Note 0 returned may mean ERROR - also check GotError}
  417.   var
  418.     Result : Integer absolute R;
  419.     V : Integer;
  420.     Code : Word;
  421.  
  422.   begin                      {EdString2integer}
  423.     Val(Src, V, Code);
  424.     if Code = 0 then
  425.       Result := V
  426.     else begin
  427.       Result := 0;
  428.       EdErrormsg(36);
  429.     end;
  430.   end;                       {EdString2integer}
  431.  
  432.   function EdYcenterWindow(Rows : Byte) : Byte;
  433.     {-Return a legal row number centered in the current window}
  434.   var
  435.     R : Byte;
  436.  
  437.   begin                      {EdYcenterWindow}
  438.     if WindowCount <= 0 then
  439.       EdYcenterWindow := 20
  440.     else begin
  441.       with Curwin^ do
  442.         R := (Firstlineno+Lastlineno-Rows) shr 1;
  443.       if R < LogtopScr then
  444.         R := LogtopScr
  445.       else if R > LogscrRows-Rows then
  446.         R := LogscrRows-Rows;
  447.       EdYcenterWindow := R;
  448.     end;
  449.   end;                       {EdYcenterWindow}
  450.  
  451.   function EdGetnumber(Prompt : VarString; Default : Integer) : Integer;
  452.     {-Prompt for and return a number, 0 if invalid or empty}
  453.     {-Plus or minus in input strings return results relative to default}
  454.   var
  455.     St : VarString;
  456.     Result : Integer;
  457.     PlusPos, MinusPos : Byte;
  458.  
  459.   begin                      {EdGetnumber}
  460.     Str(Default, St);
  461.     EdAskfor(Prompt, 10, EdYcenterWindow(3), 30, St);
  462.  
  463.     if Abortcmd or EdStringEmpty(St) then
  464.       Result := 0
  465.     else begin
  466.  
  467.       {Check for relative indicators}
  468.       PlusPos := Pos('+', St);
  469.       if PlusPos <> 0 then
  470.         Delete(St, PlusPos, 1);
  471.       MinusPos := Pos('-', St);
  472.       if MinusPos <> 0 then
  473.         Delete(St, MinusPos, 1);
  474.  
  475.       {Convert string to number}
  476.       EdString2integer(St, Result);
  477.  
  478.       if Result > 0 then begin
  479.         {Apply relative offsets}
  480.         if PlusPos <> 0 then
  481.           Result := Default+Result
  482.         else if MinusPos <> 0 then
  483.           Result := Default-Result;
  484.       end;
  485.  
  486.     end;
  487.     EdGetnumber := Result;
  488.  
  489.   end;                       {EdGetNumber}
  490.  
  491.   procedure EdSetNumber(var Num; msg, Min, Max : Integer; var Empty : Boolean);
  492.     {-Set an integer value}
  493.   var
  494.     Number : Integer absolute Num;
  495.     St : VarString;
  496.     Temp : Integer;
  497.  
  498.   begin                      {EdSetNumber}
  499.     with Curwin^ do begin
  500.       Empty := False;
  501.       Str(Number, St);
  502.       EdAskfor(EdGetMessage(msg), 32, EdYcenterWindow(3), 10, St);
  503.       if Abortcmd then
  504.         Exit;
  505.       if EdStringEmpty(St) then begin
  506.         Empty := True;
  507.         Exit;
  508.       end;
  509.       EdString2integer(St, Temp);
  510.       if Goterror then
  511.         Exit;
  512.       if (Temp >= Min) and (Temp <= Max) then
  513.         Number := Temp
  514.       else
  515.         {Out of range}
  516.         EdErrormsg(72);
  517.     end;
  518.   end;                       {EdSetNumber}
  519.  
  520.