home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / mailpro / getforu.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1988-08-23  |  11.8 KB  |  456 lines

  1. unit GetForU;
  2.  
  3. interface
  4. uses Crt, BeeU, GetKeU, FastWr, MergeStU, LPaU, SetAttU, StriU;
  5. type SetType = set of char;
  6. function GetForm( X,
  7.                   Y,
  8.                   Lngth:             integer;
  9.                   Form,
  10.                   Default:           string;
  11.                   var Control:       integer;
  12.                   var AllowInput:    boolean;
  13.                   Attr:              byte;
  14.                   Allowable:         SetType):        string;
  15.  
  16. implementation
  17.  
  18. function GetForm;
  19. var ReturnControl,
  20.     RepeatLoop,
  21.     EndStart,
  22.     FunctionChar:           boolean;
  23.     NewAttr:            byte;
  24.     TempArr:              array [1..256] of char;
  25.     OCh,
  26.     Point,
  27.     Temp,
  28.     I,
  29.     J,
  30.     LastChar:              integer;
  31.     FG,
  32.     BG:                byte;
  33.     Show,
  34.     Ch:                char;
  35.  
  36.   procedure ClearBuf;
  37.   begin
  38.   Beep(1);
  39.   while KeyPressed do GetKey(Ch,FunctionChar);
  40.   end;
  41.  
  42.  
  43.   procedure Lower(var X: integer);
  44.   var Continue:       boolean;
  45.   begin
  46.   Continue := true;
  47.   dec(X);
  48.   while Continue do
  49.     begin
  50.     if X < 1 then
  51.        begin
  52.        X := 0;   (* just to make sure it's not too low *)
  53.        Continue := false;
  54.        end
  55.       else
  56.        begin
  57.        if Form[X] <> ' ' then
  58.           dec(X)
  59.          else
  60.           Continue := false;
  61.        end;
  62.     end;
  63.   end;
  64.  
  65.  
  66.   procedure Raise(var X: integer);
  67.   var Continue:       boolean;
  68.   begin
  69.   Continue := true;
  70.   inc(X);
  71.   while Continue do
  72.     begin
  73.     if X > Lngth then
  74.        begin
  75.        X := Lngth;   (* just to make sure it's not too high *)
  76.        Continue := false;
  77.        end
  78.       else
  79.        begin
  80.        if Form[X] <> ' ' then
  81.           inc(X)
  82.          else
  83.           Continue := false;
  84.        end;
  85.     end;
  86.   end;
  87.  
  88. {------------------------------------------------------------------------}
  89.  
  90.   procedure Get_Form;
  91.   var I:    integer;
  92.  
  93.     procedure DeleteChar;
  94.     var J,
  95.         I:      integer;
  96.     begin
  97.     if (Point > LastChar) or (LastChar < 1) then  (* Point > LastChar ??? *)
  98.        ClearBuf
  99.       else
  100.        begin        (* Point <= LastChar  or  LastChar < 1 *)
  101.        if LastChar > Point then
  102.           begin
  103.           I := Point;
  104.           Raise(I);
  105.           J := I;
  106.           Raise(J);
  107.           while I < LastChar do
  108.               begin
  109.               TempArr[I] := TempArr[J];
  110.               TempArr[J] := ' ';
  111.               FastWrite( TempArr[I], Y, X + I - 1, NewAttr);
  112.               FastWrite( TempArr[J], Y, X + J - 1, NewAttr);
  113.               Raise(I);
  114.               Raise(J);
  115.               end;
  116.           TempArr[LastChar] := ' ';
  117.           FastWrite( TempArr[LastChar], Y, X + LastChar - 1, NewAttr);
  118.           Lower(LastChar);
  119.           end
  120.          else
  121.           begin
  122.           ClearBuf;
  123.           end;
  124.        end;
  125.     end;
  126.  
  127.  
  128.     procedure InsertChar;
  129.     var J,
  130.         NextJ:              integer;
  131.     begin
  132.     if Point < Lngth then
  133.        begin
  134.        Raise(Point);
  135.        for J := LastChar downto Point do
  136.            begin
  137.            NextJ := J;
  138.            Raise(NextJ);
  139.            TempArr[NextJ] := TempArr[J];
  140.            FastWrite( TempArr[NextJ], Y, X + J, NewAttr);
  141.                  (* rem X+(J+1)-1  =  X+J *)
  142.            end;
  143.        TempArr[Point] := ' ';
  144.        FastWrite( TempArr[Point], Y, X + Point - 1, NewAttr);
  145.        Lower(Point);
  146.        Raise(LastChar);
  147.        end
  148.       else
  149.        begin
  150.        ClearBuf;
  151.        end;
  152.     end;
  153.  
  154.  
  155.     procedure BackSpace;
  156.     var J,
  157.         I:               integer;
  158.     begin
  159.     if (Point < 1) then
  160.        ClearBuf
  161.       else
  162.        begin
  163.        Lower(Point);
  164.        DeleteChar;
  165.        end;
  166.     end;
  167.  
  168.  
  169.     procedure ChopOff;
  170.     var J:    integer;
  171.     begin
  172.     for J := Point + 1 to LastChar do
  173.         begin
  174.         if Form[J] = ' ' then TempArr[J] := ' ';
  175.         FastWrite( TempArr[J], Y, X + J - 1, NewAttr);
  176.         end;
  177.     LastChar := Point;
  178.     end;
  179.  
  180.  
  181.     procedure AddChar;
  182.     var Chop:              boolean;
  183.     begin
  184.     if (Point < Lngth) and (Ch in Allowable) then
  185.        begin
  186.        if Point = 0 then Chop := true else Chop := false;
  187.        Raise(Point);
  188.        TempArr[Point] := Ch;
  189.        FastWrite( TempArr[Point], Y, X + Point - 1, NewAttr);
  190.        if Point > LastChar then LastChar := Point;
  191.        if Chop then ChopOff;
  192.        end
  193.       else
  194.        ClearBuf;
  195.     end;
  196.  
  197.  
  198.   begin
  199.   while RepeatLoop do
  200.       begin
  201.       if (Point < Lngth) then
  202.          begin
  203.          Temp := Point;
  204.          Raise(Temp);
  205.          Show := TempArr[Temp];
  206.          if Show = ' ' then Show := '_';
  207.          FastWrite( Show, Y, Temp+X-1, (Attr or $0080));
  208.          end;
  209.       Ch := ReturnKey(FunctionChar);
  210.       OCh := ord(Ch);
  211.       if (Point < Lngth) then
  212.          begin
  213.          Temp := Point;
  214.          Raise(Temp);
  215.          Show := TempArr[Temp];
  216.          FastWrite( Show, Y, Temp+X-1, NewAttr);
  217.          end;
  218.       if FunctionChar then
  219.          begin
  220.          case OCh of
  221.            59..68: begin
  222.                if ReturnControl then
  223.                   begin
  224.                   Control := -OCh;
  225.                   RepeatLoop := false;
  226.                   end
  227.                  else
  228.                   ClearBuf;
  229.                end;
  230.            73,81: begin
  231.                if ReturnControl then
  232.                   begin
  233.                   Control := -OCh;
  234.                   RepeatLoop := false;
  235.                   end
  236.                  else
  237.                   ClearBuf;
  238.                end;
  239.            71: begin                                       (* home *)
  240.                Point := 0;
  241.                end;
  242.            72: begin
  243.                Control := -300;
  244.                RepeatLoop := false;
  245.                end;
  246.            75: begin
  247.                J := Point;
  248.                Lower(J);
  249.                if J < 0 then ClearBuf else Point := J;
  250.                end;
  251.            77: begin
  252.                J := Point;
  253.                Raise(J);
  254.                if J >= LastChar then ClearBuf else Point := J;  (* = ??? *)
  255.                end;
  256.            79: begin
  257.                while Point < LastChar do Raise(Point);
  258.                end;
  259.            80: begin
  260.                Control := 300;
  261.                RepeatLoop := false;
  262.                end;
  263.            82: begin                                 (* insert *)
  264.                InsertChar;
  265.                end;
  266.            83: begin                                 (* delete *)
  267.                DeleteChar;
  268.                end;
  269.            117:begin
  270.                ChopOff;
  271.                end;
  272.            30: begin       (* the following Allowable for alt-letter combo's *)
  273.                Control := 300 + 1;
  274.                RepeatLoop := false;
  275.                end;
  276.            48: begin
  277.                Control := 300 + 2;
  278.                RepeatLoop := false;
  279.                end;
  280.            46: begin
  281.                Control := 300 + 3;
  282.                RepeatLoop := false;
  283.                end;
  284.            32: begin
  285.                Control := 300 + 4;
  286.                RepeatLoop := false;
  287.                end;
  288.            18: begin
  289.                Control := 300 + 5;
  290.                RepeatLoop := false;
  291.                end;
  292.            33: begin
  293.                Control := 300 + 6;
  294.                RepeatLoop := false;
  295.                end;
  296.            34: begin
  297.                Control := 300 + 7;
  298.                RepeatLoop := false;
  299.                end;
  300.            35: begin
  301.                Control := 300 + 8;
  302.                RepeatLoop := false;
  303.                end;
  304.            23: begin
  305.                Control := 300 + 9;
  306.                RepeatLoop := false;
  307.                end;
  308.            36: begin
  309.                Control := 300 + 10;
  310.                RepeatLoop := false;
  311.                end;
  312.            37: begin
  313.                Control := 300 + 11;
  314.                RepeatLoop := false;
  315.                end;
  316.            38: begin
  317.                Control := 300 + 12;
  318.                RepeatLoop := false;
  319.                end;
  320.            50: begin
  321.                Control := 300 + 13;
  322.                RepeatLoop := false;
  323.                end;
  324.            49: begin
  325.                Control := 300 + 14;
  326.                RepeatLoop := false;
  327.                end;
  328.            24: begin
  329.                Control := 300 + 15;
  330.                RepeatLoop := false;
  331.                end;
  332.            25: begin
  333.                Control := 300 + 16;
  334.                RepeatLoop := false;
  335.                end;
  336.            16: begin
  337.                Control := 300 + 17;
  338.                RepeatLoop := false;
  339.                end;
  340.            19: begin
  341.                Control := 300 + 18;
  342.                RepeatLoop := false;
  343.                end;
  344.            31: begin
  345.                Control := 300 + 19;
  346.                RepeatLoop := false;
  347.                end;
  348.            20: begin
  349.                Control := 300 + 20;
  350.                RepeatLoop := false;
  351.                end;
  352.            22: begin
  353.                Control := 300 + 21;
  354.                RepeatLoop := false;
  355.                end;
  356.            47: begin
  357.                Control := 300 + 22;
  358.                RepeatLoop := false;
  359.                end;
  360.            17: begin
  361.                Control := 300 + 23;
  362.                RepeatLoop := false;
  363.                end;
  364.            45: begin
  365.                Control := 300 + 24;
  366.                RepeatLoop := false;
  367.                end;
  368.            21: begin
  369.                Control := 300 + 25;
  370.                RepeatLoop := false;
  371.                end;
  372.            44: begin
  373.                Control := 300 + 26;
  374.                RepeatLoop := false;
  375.                end;
  376.            end;  (* case *)
  377.          end
  378.         else
  379.          begin
  380.          case OCh of
  381.            32..126:
  382.                begin
  383.                AddChar;
  384.                end;
  385.            8:  begin                      (* back space *)
  386.                BackSpace;
  387.                end;
  388.            13: begin
  389.                if LastChar > 0 then
  390.                   begin
  391.                   Default := '';
  392.                   for I := LastChar+1 to Lngth+1 do TempArr[I] := ' ';
  393.                   for I := 1 to Lngth do
  394.                       begin
  395.                       if TempArr[I] = ' ' then
  396.                          if Form[I] <> ' ' then
  397.                             TempArr[I] := Form[I];
  398.                       Default := Default + TempArr[I];
  399.                       end;
  400.                   (*   lpad ???  Default := strip(Default); *)
  401.                   end;
  402.                RepeatLoop := false;
  403.                end;
  404.            27: begin
  405.                RepeatLoop := false;
  406.                Control := -27;
  407.                end;
  408.            end;    (* case *)
  409.          end;      (* if FunctionChar then .. else .. *)
  410.       end;
  411.   end;
  412.  
  413.  
  414. begin
  415. if Lngth < 0 then
  416.    begin
  417.    EndStart := true;
  418.    Lngth := - Lngth;
  419.    end
  420.   else
  421.    EndStart := false;
  422. I := ord(Form[0]);
  423. if I <> Lngth then Lngth := I;
  424. Point := 0;
  425. Form := Form + '  ';
  426. fillchar(TempArr,256,' ');
  427. Default := MergeStr(Form,Default,Lngth);
  428. for I := 1 to Lngth do TempArr[I] := Default[I];
  429. LastChar := Lngth;
  430. while (TempArr[LastChar] = ' ') and (LastChar > 1) do dec(LastChar);
  431. if (TempArr[1] = ' ') and (LastChar = 1) then dec(LastChar);
  432. if EndStart then Point := LastChar;
  433. Raise(LastChar);
  434. gotoxy(X,Y);
  435. if AllowInput and (Control > -2) then
  436.     begin
  437.     BG := Attr and $0007;
  438.     FG := (Attr and $0070) div 16;
  439.     NewAttr := SetAttr(false, false, FG, BG);
  440.     if Control > -1 then ReturnControl := true else ReturnControl := false;
  441.     FastWrite( LPad(Default, Lngth), Y, X, NewAttr);
  442.     RepeatLoop := true;
  443.     Get_Form;
  444.     FastWrite( lpad(Default, Lngth), Y, X, Attr);
  445.     Default := LPad(Default, Lngth);
  446.     end
  447.    else
  448.     begin
  449.     (*  if (not AllowInput) and (Control <> -27) then  *)
  450.     FastWrite( LPad(Default, Lngth), Y, X, Attr);
  451.     end;
  452. GetForm := Strip(Default);
  453. end;
  454.  
  455. end.
  456.