home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 16 / 16.iso / w / w048 / 2.ddi / MSSRC.ARC / MSPRTM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1987-12-21  |  27.1 KB  |  901 lines

  1. {                            MSPRTM.PAS
  2.                                MS 4.0
  3.                 Copyright (c) 1985, 87 by Borland International, Inc.         }
  4.  
  5. {$I msdirect.inc}
  6.  
  7. unit MsPrtM;
  8.   {-Print menu to set up a print job}
  9.  
  10. interface
  11.  
  12. uses
  13.   Crt,                       {Basic video operations - standard unit}
  14.   Dos,                       {DOS interface - standard unit}
  15.   Errors,                    {Runtime error handler}
  16.   MsVars,                    {Global types and declarations}
  17.   MsScrn1,                   {Fast screen writing routines}
  18.   MsString,                  {String primitives}
  19.   MsPtrOp,                   {Pointer primitives}
  20.   EscSeq,                    {Returns text string for extended scan codes}
  21.   MsCmds,                    {Maps keystrokes to commands}
  22.   Int24,                     {DOS critical error handler}
  23.   Message,                   {Message system}
  24.   MsUser,                    {User keyboard input, line edit, error report, help}
  25.   MsMemOp,                   {Text buffer allocation and deallocation}
  26.   MsBack,                    {Background processes}
  27.   MsScrn2,                   {Editor screen updating}
  28.   MsMenu,                    {Pulldown and custom menu system}
  29.   MsDir,                     {Popup directory picker}
  30.   MsEdit,                    {Basic editing commands}
  31.   MsText,                    {Text processing commands}
  32.   MsFile,                    {File I/O routines}
  33.   MsMacro;                   {Macro editing and processing}
  34.  
  35. procedure EdInitPrintState;
  36.   {-Set up initial state of print job}
  37.  
  38. procedure EdPrintSetDefaults(PrtDefFile : Filepath);
  39.   {-Set up defaults for printing system}
  40.  
  41. function EdPrintSetup : Boolean;
  42.   {-Set up a print job and edit printer definitions, returning true if print is to start}
  43.  
  44.   {==========================================================================}
  45.  
  46. implementation
  47.  
  48. const
  49.   PrtDefExt : ExtString = 'PDF';
  50.   PdfSignature : string[6] = 'PRTDEF'; {At the beginning of every printer file}
  51.  
  52.   procedure EdGetOutputDest(var ToFile : Boolean; var Printer : Byte);
  53.     {-Prompt for and return the output destination of a print job}
  54.   var
  55.     Menu : CustomMenuRec;
  56.     Choice : Integer;
  57.  
  58.     function EdBuildMessages(var Menu : CustomMenuRec) : Boolean;
  59.       {-Build the message table for the menu}
  60.     var
  61.       Item : Integer;
  62.       S : VarString;
  63.  
  64.     begin                    {EdBuildMessages}
  65.       EdBuildMessages := False;
  66.       with Menu do begin
  67.         if EdMemAvail(Succ(MaxChoice) shl 2, FreeListTemp) then
  68.           {Get the pointers}
  69.           GetMem(Messages, Succ(MaxChoice) shl 2)
  70.         else
  71.           Exit;
  72.  
  73.         {Get the string space and fill in the items}
  74.         for Item := MinChoice to MaxChoice do begin
  75.           case Item of
  76.             1 : S := 'File';
  77.             2, 3 : S := 'LPT'+Chr(47+Item);
  78.           end;
  79.           if EdMemAvail(Succ(Length(S)), FreeListTemp) then
  80.             GetMem(Messages^[Item], Succ(Length(S)))
  81.           else
  82.             Exit;
  83.           Messages^[Item]^ := S;
  84.         end;
  85.       end;
  86.       EdBuildMessages := True;
  87.     end;                     {EdBuildMessages}
  88.  
  89.   begin                      {EdGetOutputDest}
  90.  
  91.     {Initialize the menu}
  92.     with Menu do begin
  93.       Xmin := 37;
  94.       Ymin := 21;
  95.       MessageNum := 304;
  96.       PromptNum := 390;
  97.       MinChoice := 1;
  98.       MaxChoice := 3;
  99.       InitChoice := 1;
  100.       CmdSet := PrtCmdSet;
  101.       UseLetters := False;
  102.     end;
  103.     if not(EdBuildMessages(Menu)) then begin
  104.       EdErrormsg(35);
  105.       Exit;
  106.     end;
  107.  
  108.     {Get the menu choice}
  109.     EdGetCustomMenuChoice(Menu, Choice);
  110.  
  111.     if not(Abortcmd) then
  112.       case Choice of
  113.         1 :
  114.           ToFile := True;
  115.         2 :
  116.           begin
  117.             ToFile := False;
  118.             Printer := 0;
  119.           end;
  120.         3 :
  121.           begin
  122.             ToFile := False;
  123.             Printer := 1;
  124.           end;
  125.       end;
  126.  
  127.   end;                       {EdGetOutputDest}
  128.  
  129.   procedure EdReadPrinterFile(Fname : Filepath; var Pdef : PrinterDefinition);
  130.     {-Read a printer definition from a file}
  131.   label
  132.     ExitPoint;
  133.   var
  134.     F : file;
  135.     C : PrintCommandtype;
  136.     S : PrintCommand;
  137.     M : Boolean;
  138.     BytesRead : Word;
  139.     TestSig : VarString;
  140.  
  141.   begin                      {EdReadPrinterFile}
  142.  
  143.     Assign(F, Fname);
  144.     Reset(F, 1);
  145.     if EdFileerror then
  146.       Exit;
  147.  
  148.     with Pdef do begin
  149.  
  150.       {Check signature}
  151.       EdBlockRead(F, TestSig, Succ(Length(PdfSignature)), BytesRead);
  152.       if Goterror then
  153.         goto ExitPoint;
  154.       if TestSig <> PdfSignature then begin
  155.         EdErrormsg(61);
  156.         goto ExitPoint;
  157.       end;
  158.  
  159.       {Read each command string from packed format}
  160.       for C := PrtInit to PrtNone do
  161.         for M := False to True do begin
  162.           EdBlockRead(F, S[0], 1, BytesRead);
  163.           if Goterror or (BytesRead <> 1) then
  164.             goto ExitPoint;
  165.           EdBlockRead(F, S[1], Length(S), BytesRead);
  166.           if Goterror or (BytesRead <> Length(S)) then
  167.             goto ExitPoint;
  168.           Commands[C] [M] := S;
  169.         end;
  170.  
  171.       {Read booleans}
  172.       EdBlockRead(F, FormfeedMode, 1, BytesRead);
  173.       if Goterror or (BytesRead <> 1) then
  174.         goto ExitPoint;
  175.       EdBlockRead(F, PaperPause, 1, BytesRead);
  176.       if Goterror or (BytesRead <> 1) then
  177.         ;
  178.  
  179.     end;
  180.  
  181. ExitPoint:
  182.     Close(F);
  183.   end;                       {EdReadPrinterFile}
  184.  
  185.   procedure EdPrintSetDefaults(PrtDefFile : Filepath);
  186.     {-Set up defaults for printing system}
  187.  
  188.   begin                      {EdPrintSetDefaults}
  189.     Printing := False;
  190.     FillChar(PrintDef, SizeOf(PrintDef), 0);
  191.     with PrintJob do begin
  192.       {Load printer definition if file is found}
  193.       if EdExistFile(PrtDefFile) then begin
  194.         EdReadPrinterFile(PrtDefFile, PrintDef);
  195.         if Goterror then begin
  196.           {Ignore error and continue}
  197.           Goterror := False;
  198.           EdClearString(Devicename);
  199.         end else
  200.           Devicename := PrtDefFile;
  201.       end else
  202.         EdClearString(Devicename);
  203.       EdClearString(PrintFilename);
  204.       StartPage := 1;        {First page to print}
  205.       StopPage := MaxPage;   {Last page to print}
  206.       Format := SaveFormatState; {True to interpret dot commands}
  207.       ToFile := SaveToFile;  {True to print to file}
  208.       OutFilename := SaveOutputName; {Output file name, if any}
  209.       Printer := SavePrinterPort; {Use LPT1 or LPT2}
  210.     end;
  211.   end;                       {EdPrintSetDefaults}
  212.  
  213.   procedure EdWritePrinterFile(Fname : Filepath; var Pdef : PrinterDefinition);
  214.     {-Write a printer definition to a file}
  215.   label
  216.     ExitPoint;
  217.   var
  218.     F : file;
  219.     C : PrintCommandtype;
  220.     S : PrintCommand;
  221.     M : Boolean;
  222.  
  223.   begin                      {EdWritePrinterFile}
  224.  
  225.     Assign(F, Fname);
  226.     Rewrite(F, 1);
  227.     if EdFileerror then
  228.       Exit;
  229.  
  230.     with Pdef do begin
  231.  
  232.       {Write signature}
  233.       EdBlockWrite(F, PdfSignature, Succ(Length(PdfSignature)));
  234.       if Goterror then
  235.         goto ExitPoint;
  236.  
  237.       {Write each command string in a packed format}
  238.       for C := PrtInit to PrtNone do
  239.         for M := False to True do begin
  240.           S := Commands[C] [M];
  241.           {Write packed string}
  242.           EdBlockWrite(F, S, Succ(Length(S)));
  243.           if Goterror then
  244.             goto ExitPoint;
  245.         end;
  246.  
  247.       {Write booleans}
  248.       EdBlockWrite(F, FormfeedMode, 1);
  249.       if Goterror then
  250.         goto ExitPoint;
  251.       EdBlockWrite(F, PaperPause, 1);
  252.       if Goterror then
  253.         ;
  254.  
  255.     end;
  256.  
  257. ExitPoint:
  258.     Close(F);
  259.   end;                       {EdWritePrinterFile}
  260.  
  261.   function EdBuildPrintMenuMessages(var Menu : CustomMenuRec) : Boolean;
  262.     {-Build the message table for the printer string menu}
  263.   var
  264.     Item : Integer;
  265.     S : VarString;
  266.     C : PrintCommandtype;
  267.     M : Boolean;
  268.  
  269.   begin                      {EdBuildPrintMenuMessages}
  270.     EdBuildPrintMenuMessages := False;
  271.     with Menu do begin
  272.  
  273.       if EdMemAvail(Succ(MaxChoice) shl 2, FreeListTemp) then
  274.         {Get the pointers}
  275.         GetMem(Messages, Succ(MaxChoice) shl 2)
  276.       else
  277.         Exit;
  278.  
  279.       {Get the string space and fill in the items}
  280.       Item := 0;
  281.  
  282.       {Printer init and reset strings}
  283.       for M := False to True do begin
  284.         S := EdGetMessage(248+Item);
  285.         if EdMemAvail(Succ(Length(S)), FreeListTemp) then
  286.           GetMem(Messages^[Item], Succ(Length(S)))
  287.         else
  288.           Exit;
  289.         Messages^[Item]^ := S;
  290.         Inc(Item);
  291.       end;
  292.  
  293.       {Font control strings}
  294.       for C := PrtBold to PrtAlt2 do
  295.         for M := False to True do begin
  296.           S := EdGetMessage(Ord(C)+414)+OnOff[not(M)];
  297.           if EdMemAvail(Succ(Length(S)), FreeListTemp) then
  298.             GetMem(Messages^[Item], Succ(Length(S)))
  299.           else
  300.             Exit;
  301.           GetMem(Messages^[Item], Succ(Length(S)));
  302.           Messages^[Item]^ := S;
  303.           Inc(Item);
  304.         end;
  305.  
  306.     end;
  307.     EdBuildPrintMenuMessages := True;
  308.   end;                       {EdBuildPrintMenuMessages}
  309.  
  310.   function EdValidPrintEntries : Boolean;
  311.     {-Return true if the print selections are valid}
  312.   var
  313.     W : Pwindesc;
  314.  
  315.     function EdPrintFileInMemory(var W : Pwindesc) : Boolean;
  316.       {-Return True and window descriptor if print file in memory}
  317.     var
  318.       Fname : Filepath;
  319.       Found : Boolean;
  320.  
  321.     begin                    {EdPrintFileInMemory}
  322.       Found := False;
  323.       if WindowCount > 0 then begin
  324.         Fname := PrintJob.PrintFilename;
  325.         W := Window1;
  326.         repeat
  327.           Found := (W^.Filename = Fname);
  328.           if not(Found) then
  329.             EdFwdPtr(W);
  330.         until Found or (W = Window1);
  331.       end;
  332.       EdPrintFileInMemory := Found;
  333.     end;                     {EdPrintFileInMemory}
  334.  
  335.   begin                      {EdValidPrintEntries}
  336.     EdValidPrintEntries := False;
  337.  
  338.     {If print file is in memory and modified, raise a flag}
  339.     if EdPrintFileInMemory(W) then
  340.       if W^.Modified then begin
  341.         EdErrormsg(65);
  342.         Exit;
  343.       end;
  344.  
  345.     with PrintJob do begin
  346.       {Make sure print file exists}
  347.       if not(EdExistFile(PrintFilename)) then begin
  348.         EdErrormsg(67);
  349.         Exit;
  350.       end;
  351.       {Make sure output file can be overwritten}
  352.       if ToFile then begin
  353.         if EdHasWildCards(OutFilename) or EdStringEmpty(OutFilename) then begin
  354.           EdErrormsg(68);
  355.           Exit;
  356.         end;
  357.         if EdExistFile(OutFilename) then
  358.           if not(EdYesNo(EdGetMessage(319))) then
  359.             Exit;
  360.       end;
  361.       {Make sure page numbers are valid}
  362.       if StopPage < StartPage then begin
  363.         EdErrormsg(66);
  364.         Exit;
  365.       end;
  366.     end;
  367.  
  368.     EdValidPrintEntries := True;
  369.   end;                       {EdValidPrintEntries}
  370.  
  371.   procedure EdSetFileDefault;
  372.     {-Set initial guess at print file}
  373.  
  374.   begin                      {EdSetFileDefault}
  375.     with PrintJob do begin
  376.       if EdHasWildCards(PrintFilename) or EdStringEmpty(PrintFilename) then begin
  377.         if EdHasWildCards(LastPrintFile) or EdStringEmpty(LastPrintFile) then begin
  378.           if EdHasWildCards(LastFileEdit) or EdStringEmpty(LastFileEdit) then begin
  379.             if Curwin^.Filename <> NoFile then
  380.               PrintFilename := Curwin^.Filename;
  381.           end else
  382.             PrintFilename := LastFileEdit;
  383.         end else
  384.           PrintFilename := LastPrintFile;
  385.       end;
  386.       if not(EdStringEmpty(PrintFilename)) then
  387.         {Add default extension}
  388.         EdDefaultExtension(DefExtension, PrintFilename);
  389.     end;
  390.   end;                       {EdSetFileDefault}
  391.  
  392.   procedure EdDrawSeparator(W : WindowRec; WhichItem : Integer);
  393.     {-Draw a bar spanning the whole window at row WhichItem}
  394.   var
  395.     SpanBar : VarString;
  396.  
  397.   begin                      {EdDrawSeparator}
  398.     with W do begin
  399.       SpanBar[0] := Chr(XSize);
  400.       FillChar(SpanBar[1], Length(SpanBar), Border[Horiz]);
  401.       SpanBar[1] := Border[LeftJoin];
  402.       SpanBar[XSize] := Border[RightJoin];
  403.       EdFastWrite(SpanBar, YPosn+WhichItem, XPosn, ScreenAttr[MfColor]);
  404.     end;
  405.   end;                       {EdDrawSeparator}
  406.  
  407.   procedure EdInitPrintState;
  408.     {-Set up initial state of print job}
  409.  
  410.     procedure EdCheckMargins;
  411.       {-Assure margins are self-consistent}
  412.  
  413.     begin                    {EdCheckMargins}
  414.       with PrintJob do begin
  415.         if HTMargin >= Tmargin then
  416.           HTMargin := Pred(Tmargin);
  417.         if FBMargin >= Bmargin then
  418.           FBMargin := Pred(Bmargin);
  419.       end;
  420.     end;                     {EdCheckMargins}
  421.  
  422.   begin                      {EdInitPrintState}
  423.     with PrintJob do begin
  424.  
  425.       FillChar(FontState, SizeOf(FontState), False); {Default font state}
  426.       FillChar(PendingFontState, SizeOf(PendingFontState), False); {No font change pending}
  427.       EdClearString(Header); {Empty header}
  428.       EdClearString(Footer); {Empty footer}
  429.       StackIndex := 0;       {No print command setup in progress}
  430.       BufferPtr := 1;        {Use first character of read buffer}
  431.       BufferChars := 0;      {Force buffer read first time}
  432.       ShowPageNum := True;   {Print page number if empty footer}
  433.       Loffset := 8;          {Default left offset}
  434.       Pagecol := 33;         {Default column for page numbers}
  435.       PushStart := True;     {First header pending}
  436.       PushEnd := True;       {First footer pending}
  437.       NewLine := True;       {First line pending}
  438.       LastPage := False;     {Not on last page yet}
  439.       Column := 1;           {First column}
  440.       Line := 1;             { of first line}
  441.       PageNum := 1;          {   of first page}
  442.  
  443.       {Set up vertical margins}
  444.       if not(Format) then begin
  445.         Tmargin := 0;
  446.         Bmargin := 0;
  447.         HTMargin := 0;
  448.         FBMargin := 0;
  449.       end else begin
  450.         if WindowCount = 0 then begin
  451.           PageLen := SavePageLen;
  452.           Tmargin := SaveTopMargin;
  453.           Bmargin := SaveBottomMargin;
  454.         end else begin
  455.           PageLen := Curwin^.PageLen;
  456.           Tmargin := Curwin^.Tmargin;
  457.           Bmargin := Curwin^.Bmargin;
  458.         end;
  459.         HTMargin := 1;
  460.         FBMargin := 3;
  461.         EdCheckMargins;
  462.       end;
  463.  
  464.       {Open the print file}
  465.       Assign(PrintFile, PrintFilename);
  466.       Reset(PrintFile, 1);
  467.       if EdFileerror then
  468.         Exit;
  469.  
  470.       {Open the output file}
  471.       PrintChars := CharsPerPrintBlock;
  472.       if ToFile then
  473.         if EdStringEmpty(OutFilename) then
  474.           ToFile := False
  475.         else begin
  476.           PrintChars := CharsPerFileBlock;
  477.           Assign(OutFile, OutFilename);
  478.           Rewrite(OutFile);
  479.           if EdFileerror then
  480.             Exit;
  481.         end;
  482.  
  483.       {Push printer initialization commands}
  484.       if Format then
  485.         EdPushPrintString(PrintDef.Commands[PrtInit] [False]);
  486.       PrinterInit := (StackIndex > 0);
  487.  
  488.     end;
  489.   end;                       {EdInitPrintState}
  490.  
  491.   procedure EdEditPrinterString;
  492.     {-Edit the printer command string in the current printer definition}
  493.   var
  494.     C : PrintCommandtype;
  495.     M : Boolean;
  496.     Menu : CustomMenuRec;
  497.     Choice : Integer;
  498.     msg : VarString;
  499.  
  500.   begin                      {EdEditPrinterString}
  501.  
  502.     {Choose string to edit}
  503.     {Initialize the menu}
  504.     with Menu do begin
  505.       Xmin := 32;
  506.       Ymin := 7;
  507.       MessageNum := 304;
  508.       PromptNum := 373;
  509.       MinChoice := 0;
  510.       MaxChoice := 15;
  511.       InitChoice := 0;
  512.       CmdSet := PrtCmdSet;
  513.       UseLetters := False;
  514.     end;
  515.  
  516.     repeat
  517.  
  518.       {Store the strings for the menu}
  519.       if not(EdBuildPrintMenuMessages(Menu)) then begin
  520.         EdErrormsg(35);
  521.         Exit;
  522.       end;
  523.  
  524.       {Get the menu choice}
  525.       EdGetCustomMenuChoice(Menu, Choice);
  526.  
  527.       if Abortcmd then
  528.         Exit;
  529.  
  530.       {Determine which string to edit}
  531.       M := Odd(Choice);
  532.       C := PrintCommandtype(Choice shr 1);
  533.       if C = PrtInit then
  534.         if M then
  535.           msg := EdGetMessage(249)
  536.         else
  537.           msg := EdGetMessage(248)
  538.       else
  539.         msg := EdGetMessage(Ord(C)+414)+OnOff[not(M)]+Blank;
  540.  
  541.       {Edit the keys, ignoring extended keystrokes}
  542.       UseExtendedSequence := False;
  543.       EdEditKeyWindow(msg, 5, 19, 75, 24, PrintCommandSize, PrintDef.Commands[C] [M]);
  544.       UseExtendedSequence := True;
  545.  
  546.     until Abortcmd;
  547.     Abortcmd := False;
  548.  
  549.   end;                       {EdEditPrinterString}
  550.  
  551.   function EdPrintSetup : Boolean;
  552.     {-Set up a print job and edit printer definitions, returning true if print is to start}
  553.   const
  554.     Xmin = 10;
  555.     Ymin = 8;
  556.     Xmax = 78;
  557.     MaxItems = 13;
  558.     Left = 20;
  559.   var
  560.     OldItem, WhichItem : Integer;
  561.     Wmenu : WindowRec;
  562.     Quitting : Boolean;
  563.     CmdSet : Charset;
  564.     Ch : Char;
  565.  
  566.     procedure EdWriteEntry(W : WindowRec; WhichItem : Integer; Selected : Boolean);
  567.       {-Write one menu entry}
  568.     var
  569.       S, Ss : VarString;
  570.       X, Y : Integer;
  571.  
  572.     begin                    {EdWriteEntry}
  573.       with W, PrintJob, PrintDef do begin
  574.  
  575.         {Get the fixed string and pad to a left margin value}
  576.         S := EdPadEntry(EdGetMessage(425+WhichItem), Left);
  577.  
  578.         {Add varying status information}
  579.         case WhichItem of
  580.  
  581.           3 :                {Name of file}
  582.             if not(EdHasWildCards(PrintFilename)) then
  583.               S := S+PrintFilename;
  584.  
  585.           4 :                {Formatting}
  586.             S := S+OnOff[Format];
  587.  
  588.           5 :                {First page}
  589.             begin
  590.               Str(StartPage, Ss);
  591.               S := S+Ss;
  592.             end;
  593.  
  594.           6 :                {Last page}
  595.             begin
  596.               Str(StopPage, Ss);
  597.               S := S+Ss;
  598.             end;
  599.  
  600.           8 :                {Which printer}
  601.             S := S+Devicename;
  602.  
  603.           9 :                {Output destination}
  604.             if ToFile then begin
  605.               if not(EdHasWildCards(OutFilename)) then
  606.                 S := S+OutFilename;
  607.             end else
  608.               S := S+'LPT'+Chr(Printer+49);
  609.  
  610.           10 :               {Paper pause}
  611.             S := S+OnOff[PaperPause];
  612.  
  613.           11 :               {Form feed mode}
  614.             S := S+OnOff[FormfeedMode];
  615.  
  616.         end;
  617.  
  618.         {Pad to fill the menu box}
  619.         S := EdPadEntry(S, XSize-2);
  620.  
  621.         X := Succ(XPosn);
  622.         Y := YPosn+WhichItem;
  623.  
  624.         {Write the string with appropriate attributes}
  625.         if Selected then
  626.           EdFastWrite(S, Y, X, ScreenAttr[MsColor])
  627.         else begin
  628.           {Highlight the first character}
  629.           EdFastWrite(S[1], Y, X, ScreenAttr[MnColor]);
  630.           EdFastWrite(S[2], Y, Succ(X), ScreenAttr[MhColor]);
  631.           EdFastWrite(Copy(S, 3, DefNoCols), Y, X+2, ScreenAttr[MnColor]);
  632.         end;
  633.       end;
  634.     end;                     {EdWriteEntry}
  635.  
  636.     procedure EdDrawAllChoices(W : WindowRec; SelectNum : Integer);
  637.       {-Draw all of the setup choices}
  638.     var
  639.       I : Integer;
  640.  
  641.     begin                    {EdDrawAllChoices}
  642.       for I := 1 to MaxItems do
  643.         if (I <> 2) and (I <> 7) then
  644.           EdWriteEntry(W, I, (I = SelectNum));
  645.     end;                     {EdDrawAllChoices}
  646.  
  647.     procedure EdScrollPrintEntry(var WhichItem : Integer; Increment : Integer);
  648.       {-Increment or decrement item in menu, skipping separators}
  649.  
  650.     begin                    {EdScrollPrintEntry}
  651.       repeat
  652.         Inc(WhichItem, Increment);
  653.         if WhichItem < 1 then
  654.           WhichItem := MaxItems
  655.         else if WhichItem > MaxItems then
  656.           WhichItem := 1;
  657.       until (WhichItem <> 2) and (WhichItem <> 7);
  658.     end;                     {EdScrollPrintEntry}
  659.  
  660.     procedure EdSetItemByLetter(Ch : Char; var WhichItem : Integer);
  661.       {-See if character matches a menu entry, and set appropriate item if so}
  662.     var
  663.       I : Integer;
  664.  
  665.     begin                    {EdSetItemByLetter}
  666.       I := 1;
  667.       repeat
  668.         if Upcase(EdFirstLetter(EdGetMessage(425+I))) = Ch then begin
  669.           WhichItem := I;
  670.           Exit;
  671.         end;
  672.         EdScrollPrintEntry(I, 1);
  673.       until I = 1;
  674.     end;                     {EdSetItemByLetter}
  675.  
  676.     procedure EdModifyPrintSetup(W : WindowRec; WhichItem : Integer);
  677.       {-Modify the print setup parameter}
  678.     var
  679.       Old, Junk : Filepath;
  680.  
  681.       function EdGetPageLimit(Msgno, Default : Integer) : Integer;
  682.         {-Return a validated page number}
  683.       var
  684.         Pnum : Integer;
  685.  
  686.       begin                  {EdGetPageLimit}
  687.         EdGetPageLimit := Default;
  688.         Pnum := EdGetnumber(EdGetMessage(Msgno), Default);
  689.         if Abortcmd or (Pnum = 0) then
  690.           Abortcmd := False
  691.         else if (Pnum < 1) or (Pnum > MaxPage) then begin
  692.           EdErrormsg(47);
  693.           Goterror := False;
  694.         end else
  695.           EdGetPageLimit := Pnum;
  696.       end;                   {EdGetPageLimit}
  697.  
  698.     begin                    {EdModifyPrintSetup}
  699.       with PrintJob, PrintDef do
  700.         case WhichItem of
  701.  
  702.           3 :                {Name of file}
  703.             begin
  704.               Old := PrintFilename;
  705.               PrintFilename := EdGetFileName(EdGetMessage(346), DefExtension, 21, 0, LastPrintFile, True);
  706.               Abortcmd := False;
  707.               if EdStringEmpty(PrintFilename) then
  708.                 PrintFilename := Old;
  709.             end;
  710.  
  711.           4 :                {Formatting}
  712.             begin
  713.               Format := not(Format);
  714.               SaveFormatState := Format;
  715.             end;
  716.  
  717.           5 :                {First page}
  718.             StartPage := EdGetPageLimit(392, StartPage);
  719.  
  720.           6 :                {Last page}
  721.             StopPage := EdGetPageLimit(393, StopPage);
  722.  
  723.           8 :                {Printer type}
  724.             begin
  725.               Old := Devicename;
  726.               Junk := SupportPath+'*.'+PrtDefExt;
  727.               Devicename := EdGetFileName(EdGetMessage(334), PrtDefExt, 21, 0, Junk, True);
  728.               Abortcmd := False;
  729.               if EdStringEmpty(Devicename) then begin
  730.                 {Return to previous}
  731.                 Devicename := Old;
  732.                 Exit;
  733.               end;
  734.               if not(EdExistFile(Devicename)) then begin
  735.                 EdErrormsg(2);
  736.                 Devicename := Old;
  737.                 Exit;
  738.               end;
  739.               if Devicename <> Old then begin
  740.                 EdReadPrinterFile(Devicename, PrintDef);
  741.                 if Goterror then
  742.                   Devicename := Old
  743.                 else
  744.                   {Update toggles controlled by printer}
  745.                   EdDrawAllChoices(W, 8);
  746.               end;
  747.             end;
  748.  
  749.           9 :                {Output destination - cycle through the choices}
  750.             begin
  751.               EdGetOutputDest(ToFile, Printer);
  752.               if ToFile then begin
  753.                 {Get an output file name}
  754.                 OutFilename := EdGetFileName(EdGetMessage(391), '', 21, 0, LastPrintOutput, False);
  755.                 Abortcmd := False;
  756.               end;
  757.             end;
  758.  
  759.           10 :               {Manual paper feed}
  760.             PaperPause := not(PaperPause);
  761.  
  762.           11 :               {Form feeds}
  763.             FormfeedMode := not(FormfeedMode);
  764.  
  765.           12 :               {Edit printer codes}
  766.             begin
  767.               EdEditPrinterString;
  768.               Abortcmd := False;
  769.             end;
  770.  
  771.           13 :               {Save printer setup}
  772.             begin
  773.               {Get filename}
  774.               Old := Devicename;
  775.               Devicename := EdGetFileName(EdGetMessage(334), PrtDefExt, 21, 0, Old, False);
  776.               Abortcmd := False;
  777.               if EdStringEmpty(Devicename) then begin
  778.                 {Return to previous}
  779.                 Devicename := Old;
  780.                 Exit;
  781.               end;
  782.               {Check for overwrite}
  783.               if EdExistFile(Devicename) then
  784.                 if not(EdYesNo(EdGetMessage(319))) then begin
  785.                   {Return to previous}
  786.                   Devicename := Old;
  787.                   Exit;
  788.                 end;
  789.               {Write it out}
  790.               EdWritePrinterFile(Devicename, PrintDef);
  791.               if not(Goterror) then
  792.                 {Update toggles controlled by printer}
  793.                 EdDrawAllChoices(W, 13);
  794.               Goterror := False;
  795.             end;
  796.  
  797.         end;
  798.     end;                     {EdModifyPrintSetup}
  799.  
  800.     procedure EdHandleSelection(WhichItem : Integer);
  801.       {-Take action on the selected item}
  802.  
  803.     begin                    {EdHandleSelection}
  804.       if WhichItem = 1 then begin
  805.         {Validate selections prior to starting print job}
  806.         if EdValidPrintEntries then begin
  807.           {Return true to start printing}
  808.           EdPrintSetup := True;
  809.           Quitting := True;
  810.         end;
  811.       end else
  812.         EdModifyPrintSetup(Wmenu, WhichItem);
  813.  
  814.       Goterror := False;
  815.       EdEraseMenuHelp;
  816.       EdWritePromptLine(EdGetMessage(375));
  817.     end;                     {EdHandleSelection}
  818.  
  819.   begin                      {EdPrintSetup}
  820.  
  821.     {Set initial guess at print file name}
  822.     EdSetFileDefault;
  823.  
  824.     {Put up a menu of selections}
  825.     EdSaveTextWindow(Border, EdGetMessage(378), Xmin, Ymin, Xmax, Succ(Ymin+MaxItems), Wmenu);
  826.     {Draw fixed separator bars}
  827.     EdDrawSeparator(Wmenu, 2);
  828.     EdDrawSeparator(Wmenu, 7);
  829.     EdEraseMenuHelp;
  830.     EdWritePromptLine(EdGetMessage(375));
  831.     {Get full screen cursor addressing back}
  832.     WindMin := 0;
  833.     WindMax := swap(pred(PhyScrRows)) or pred(PhyScrCols);
  834.     WhichItem := 1;
  835.     EdDrawAllChoices(Wmenu, WhichItem);
  836.     CmdSet := PrtCmdSet+['A'..'Z'];
  837.  
  838.     {Select until done}
  839.     Quitting := False;
  840.  
  841.     repeat
  842.  
  843.       EdSetCursor(CursorOff);
  844.       EdWriteEntry(Wmenu, WhichItem, True);
  845.       Abortcmd := False;
  846.       Goterror := False;
  847.  
  848.       Ch := EdGetCursorCommand(CmdSet);
  849.  
  850.       if not(Abortcmd) then
  851.         case Ch of
  852.  
  853.           ^J :               {Help}
  854.             begin
  855.               EdHelpWindow(CmdPrintFile);
  856.               EdWritePromptLine(EdGetMessage(375));
  857.             end;
  858.  
  859.           ^M :               {Select}
  860.             EdHandleSelection(WhichItem);
  861.  
  862.           ^[ :               {Escape}
  863.             begin
  864.               EdPrintSetup := False;
  865.               Quitting := True;
  866.             end;
  867.  
  868.           ^E :               {Scroll up}
  869.             begin
  870.               EdWriteEntry(Wmenu, WhichItem, False);
  871.               EdScrollPrintEntry(WhichItem, -1);
  872.             end;
  873.  
  874.           ^X :               {Scroll down}
  875.             begin
  876.               EdWriteEntry(Wmenu, WhichItem, False);
  877.               EdScrollPrintEntry(WhichItem, 1);
  878.             end;
  879.  
  880.           'A'..'Z' :         {Select by letter}
  881.             begin
  882.               OldItem := WhichItem;
  883.               EdSetItemByLetter(Ch, WhichItem);
  884.               if OldItem <> WhichItem then begin
  885.                 EdWriteEntry(Wmenu, OldItem, False);
  886.                 EdWriteEntry(Wmenu, WhichItem, True);
  887.               end;
  888.               EdHandleSelection(WhichItem);
  889.             end;
  890.  
  891.         end;
  892.     until Abortcmd or Quitting;
  893.  
  894.     {Restore the screen}
  895.     EdRestoreTextWindow(Wmenu);
  896.     EdShowMenuHelp;
  897.  
  898.   end;                       {EdPrintSetup}
  899.  
  900. end.
  901.