home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / tvision / newed / editpkg.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-10-31  |  32.3 KB  |  1,116 lines

  1. { FILE:  editpkg.pas }
  2.  
  3.  
  4.  
  5. unit EditPkg;
  6.  
  7.  
  8.  
  9. { ************************************************************************* }
  10. {                                                                           }
  11. { NOTICE:  Most of the following code was written by Borland International. }
  12. {          The code is for use by TP6.0 users.  Keep the copyright notice   }
  13. {          intact!                                                          }
  14. {                                                                           }
  15. {          Turbo Pascal 6.0                                                 }
  16. {          Turbo Vision Demo                                                }
  17. {          Copyright (c) 1990 by Borland International                      }
  18. {                                                                           }
  19. { This unit provides an interface to the NEWEDIT unit.  Specifically,       }
  20. { it initializes the buffers, contains all the editor dialogs, handles all  }
  21. { allocation and deallocation of the clipboard, and of course opens up      }
  22. { the appropriate edit window when requested.                               }
  23. {                                                                           }
  24. { The major item I've changed here is how the "heap" is set up for          }
  25. { use by the editor buffers.  You can search for it using the HEAP          }
  26. { shown below.                                                              }
  27. {                                                                           }
  28. { In addition, I've added a procedure to show how to close editor windows   }
  29. { for external file processing and then reopen them to continue editing.    }
  30. { Look for the CHKSPL label.  This label is also defined in NEDEMO and      }
  31. { NEWEDIT, for it requires coding through all three units.                  }
  32. {                                                                           }
  33. { All other labels in this unit are defined in the NEWEDIT                  }
  34. { unit, they being mostly for dialog boxes and error messages.              }
  35. {                                                                           }
  36. { There are additional minor things, like how to use typecasting to set     }
  37. { editor defaults when opening a window.  These aren't labeled.             }
  38. {                                                                           }
  39. { Search   Description:                                                     }
  40. { ------   ------------                                                     }
  41. {                                                                           }
  42. { HEAP   - Added a feature to allow maximum or minimum heap allocation      }
  43. {          for use by the editors buffers.                                  }
  44. {                                                                           }
  45. { SPLCHK - Shows how to close an edit window to process a file              }
  46. {          (such as spell checking) and reopen the window when done.        }
  47. {                                                                           }
  48. { Al Andersen - 10/31/93.                                                   }
  49. {                                                                           }
  50. { ************************************************************************* }
  51.  
  52.  
  53. {$O+,F+,X+,S-,D-}
  54.  
  55.  
  56.  
  57. interface
  58.  
  59.  
  60.  
  61. uses
  62.  
  63.   Objects,
  64.   Drivers,
  65.   Views,
  66.   Dialogs,
  67.   StdDlg,
  68.   MsgBox,
  69.   App,
  70.   Memory,
  71.   CmdFile,
  72.   NewEdit;
  73.  
  74.  
  75. VAR
  76.  
  77.   Clip_Window : NewEdit.PEditWindow;      { Object to hold the clip board. }
  78.  
  79.   { SPLCHK - Start. }
  80.  
  81.   procedure SpellIt;
  82.  
  83.   { SPLCHK - Stop. }
  84.  
  85.   procedure Deallocate_The_Clipboard;
  86.   procedure Deallocate_The_Editor;
  87.  
  88.   procedure Initialize_The_Clipboard;
  89.   procedure Initialize_The_Editor;
  90.  
  91.   function  Open_Editor (File_Name : Objects.FNameStr;
  92.                          Visible   : Boolean) : NewEdit.PEditWindow;
  93.  
  94.   procedure Run_The_Editor;
  95.   procedure Show_ClipBoard;
  96.  
  97.  
  98.  
  99. implementation
  100.  
  101.  
  102.  
  103. { -------------------------------------------------------------------------- }
  104.  
  105.  
  106.  
  107. { SPLCHK - Start. }
  108.  
  109.  
  110.  
  111. Procedure SpellIt;
  112.  
  113.  
  114.   { ---------------------------------------------------------------------- }
  115.   {                                                                        }
  116.   { This procedure demonstrates how to close an editor window for external }
  117.   { file processing, and then reopen the window to continue editing.  The  }
  118.   { procedure assumes an external spell checking program will be used.     }
  119.   {                                                                        }
  120.   { ---------------------------------------------------------------------- }
  121.  
  122.  
  123. VAR
  124.  
  125.   SpellFileName : Objects.FNameStr; { Determines what the filename is. }
  126.  
  127. begin
  128.  
  129.  
  130.   { ----------------------------------------------------------- }
  131.   {                                                             }
  132.   { First we check to make sure that the current window is in   }
  133.   { fact an editor window.  We need to do this so you don't run }
  134.   { the spelling checker unless an edit window is being used.   }
  135.   {                                                             }
  136.   { ----------------------------------------------------------- }
  137.  
  138.  
  139.   if typeof (Desktop^.Current^) = typeof (TEditWindow) then
  140.     begin
  141.  
  142.  
  143.       { --------------------------------------------------------- }
  144.       {                                                           }
  145.       { OK, now get the filename associated with the current edit }
  146.       { window.  Then send a message to NewEdit.TFileEditor's     }
  147.       { HandleEvent method to write the data to disk and close    }
  148.       { the window.  You need to *REMOVE* the dialog and insert   }
  149.       { your spell checking code in its place.  Last of all you   }
  150.       { call Open_Editor to reopen your edit window.              }
  151.       {                                                           }
  152.       { --------------------------------------------------------- }
  153.  
  154.  
  155.       SpellFileName := NewEdit.PEditWindow (Desktop^.Current)^.Editor^.FileName;
  156.  
  157.       Message (Desktop^.Current,
  158.                Drivers.evCommand,
  159.                NewEdit.cmSaveDone,
  160.                nil);
  161.  
  162.       Msgbox.MessageBox (^C'Now your spellchecker does its thing.',
  163.                          nil, MsgBox.mfInformation + MsgBox.mfOKButton);
  164.  
  165.       Open_Editor (SpellFileName, True);
  166.  
  167.     end;
  168.  
  169.  
  170. end; { SpellIt }
  171.  
  172.  
  173.  
  174. { SPLCHK - Stop. }
  175.  
  176.  
  177.  
  178. { -------------------------------------------------------------------------- }
  179.  
  180.  
  181.  
  182. function Execute_Dialog (P : Dialogs.PDialog; Data : Pointer) : Word;
  183.  
  184.  
  185.   { -------------------------------------------------------- }
  186.   {                                                          }
  187.   { This function places the editor dialogs on the desktop   }
  188.   { and takes care of seting/getting data options from them. }
  189.   {                                                          }
  190.   { -------------------------------------------------------- }
  191.  
  192.  
  193. VAR
  194.  
  195.   Result : Word; { Holds result of trying to ExecView onto Desktop. }
  196.  
  197. begin
  198.  
  199.   Result := Views.cmCancel;
  200.  
  201.   P := PDialog (App.Application^.ValidView (P));
  202.  
  203.   if P <> nil then
  204.   begin
  205.  
  206.     if Data <> nil then
  207.       P^.SetData (Data^);
  208.  
  209.     Result := App.DeskTop^.ExecView (P);
  210.  
  211.     if (Result <> Views.cmCancel) and (Data <> nil) then
  212.       P^.GetData (Data^);
  213.  
  214.     Dispose (P, Done);
  215.  
  216.   end;
  217.  
  218.   Execute_Dialog := Result;
  219.  
  220.  
  221. end; { Execute_Dialog }
  222.  
  223.  
  224.  
  225. { -------------------------------------------------------------------------- }
  226.  
  227.  
  228.  
  229. function Do_Edit_Dialog (Dialog : Integer; Info : Pointer) : Word; far;
  230.  
  231.  
  232.   { ---------------------------------------------------------- }
  233.   {                                                            }
  234.   { This function creates the appropriate editor dialog boxes. }
  235.   {                                                            }
  236.   { ---------------------------------------------------------- }
  237.  
  238.  
  239. VAR
  240.  
  241.   Y_Position : Word; { Local variable to ensure ALL dialogs start in same spot. }
  242.  
  243.  
  244.  
  245.   { ------------------------------------------------------------------------ }
  246.  
  247.  
  248.  
  249.   function Create_Find_Dialog : Dialogs.PDialog;
  250.  
  251.  
  252.     { ----------------------------------------------------------- }
  253.     {                                                             }
  254.     { This is a local procedure that creates the FIND dialog box. }
  255.     {                                                             }
  256.     { ----------------------------------------------------------- }
  257.  
  258.  
  259.   VAR
  260.  
  261.     D        : Dialogs.PDialog;
  262.     R        : TRect;
  263.     Sub_View : Views.PView;
  264.  
  265.   begin
  266.  
  267.     R.Assign (21, Y_Position, 58, Y_Position + 11);
  268.     D := New (Dialogs.PDialog, Init (R, 'Find'));
  269.  
  270.     with D^ do
  271.     begin
  272.  
  273.       R.Assign (3, 3, 32, 4);
  274.       Sub_View := New (Dialogs.PInputLine, Init (R, 80));
  275.       Sub_View^.HelpCtx := CmdFile.hcDFindText;
  276.       Insert (Sub_View);
  277.  
  278.       R.Assign (2, 2, 15, 3);
  279.       Insert (New (Dialogs.PLabel, Init (R, '~T~ext to find', Sub_View)));
  280.       R.Assign (32, 3, 35, 4);
  281.       Insert (New (Dialogs.PHistory, Init (R, Dialogs.PInputLine (Sub_View), 10)));
  282.  
  283.       R.Assign (3, 5, 35, 7);
  284.       Sub_View := New (Dialogs.PCheckBoxes, Init (R,
  285.         NewSItem ('~C~ase sensitive',
  286.         NewSItem ('~W~hole words only',
  287.       nil))));
  288.       Sub_View^.HelpCtx := CmdFile.hcCCaseSensitive;
  289.       Insert (Sub_View);
  290.  
  291.       R.Assign (7, 8, 17, 10);
  292.       Sub_View := New (Dialogs.PButton, Init (R, 'O~K~', Views.cmOk, Dialogs.bfDefault));
  293.       Sub_View^.HelpCtx := CmdFile.hcDOk;
  294.       Insert (Sub_View);
  295.  
  296.       Inc (R.A.X, 13);
  297.       Inc (R.B.X, 13);
  298.       Sub_View := New (Dialogs.PButton, Init (R, 'Cancel', Views.cmCancel, Dialogs.bfNormal));
  299.       Sub_View^.HelpCtx := CmdFile.hcDCancel;
  300.       Insert (Sub_View);
  301.  
  302.       SelectNext (False);
  303.  
  304.     end;
  305.  
  306.     Create_Find_Dialog := D;
  307.  
  308.  
  309.   end; { Create_Find_Dialog }
  310.  
  311.  
  312.  
  313.   { ------------------------------------------------------------------------ }
  314.  
  315.  
  316.  
  317.   function Create_Replace_Dialog : Dialogs.PDialog;
  318.  
  319.  
  320.     { --------------------------------------------------------------------- }
  321.     {                                                                       }
  322.     { This is a local procedure that creates the SEARCH/REPLACE dialog box. }
  323.     {                                                                       }
  324.     { --------------------------------------------------------------------- }
  325.  
  326.  
  327.   VAR
  328.  
  329.     D        : Dialogs.PDialog;
  330.     R        : TRect;
  331.     Sub_View : Views.PView;
  332.  
  333.   begin
  334.  
  335.     R.Assign (20, Y_Position, 60, Y_Position + 16);
  336.     D := New (Dialogs.PDialog, Init (R, 'Replace'));
  337.  
  338.     with D^ do
  339.     begin
  340.  
  341.       R.Assign (2, 2, 15, 3);
  342.       Insert (New (Dialogs.PLabel, Init (R, '~T~ext to find', Sub_View)));
  343.  
  344.       R.Assign (3, 3, 34, 4);
  345.       Sub_View := New (Dialogs.PInputLine, Init (R, 80));
  346.       Sub_View^.HelpCtx := CmdFile.hcDFindText;
  347.       Insert (Sub_View);
  348.  
  349.       R.Assign (34, 3, 37, 4);
  350.       Insert (New (Dialogs.PHistory, Init (R, Dialogs.PInputLine (Sub_View), 10)));
  351.  
  352.       R.Assign (2, 5, 12, 6);
  353.       Insert (New (Dialogs.PLabel, Init (R, '~N~ew text', Sub_View)));
  354.  
  355.       R.Assign (3, 6, 34, 7);
  356.       Sub_View := New (Dialogs.PInputLine, Init (R, 80));
  357.       Sub_View^.HelpCtx := CmdFile.hcDReplaceText;
  358.       Insert (Sub_View);
  359.  
  360.       R.Assign (34, 6, 37, 7);
  361.       Insert (New (Dialogs.PHistory, Init (R, Dialogs.PInputLine (Sub_View), 11)));
  362.  
  363.       R.Assign (3, 8, 37, 12);
  364.       Sub_View := New (Dialogs.PCheckBoxes, Init (R,
  365.         NewSItem ('~C~ase sensitive',
  366.         NewSItem ('~W~hole words only',
  367.         NewSItem ('~P~rompt on replace',
  368.         NewSItem ('~R~eplace all',
  369.       nil))))));
  370.       Sub_View^.HelpCtx := CmdFile.hcCCaseSensitive;
  371.       Insert (Sub_View);
  372.  
  373.       R.Assign (8, 13, 18, 15);
  374.       Sub_View := New (Dialogs.PButton, Init (R, 'O~K~', Views.cmOk, Dialogs.bfDefault));
  375.       Sub_View^.HelpCtx := CmdFile.hcDOk;
  376.       Insert (Sub_View);
  377.  
  378.       R.Assign (22, 13, 32, 15);
  379.       Sub_View := New (Dialogs.PButton, Init (R, 'Cancel', Views.cmCancel, Dialogs.bfNormal));
  380.       Sub_View^.HelpCtx := CmdFile.hcDCancel;
  381.       Insert (Sub_View);
  382.  
  383.       SelectNext (False);
  384.  
  385.     end;
  386.  
  387.     Create_Replace_Dialog := D;
  388.  
  389.  
  390.   end; { Create_Replace_Dialog }
  391.  
  392.  
  393.  
  394.   { ------------------------------------------------------------------------ }
  395.  
  396.  
  397.  
  398.   { JLINE - Start. }
  399.  
  400.   function Jump_Line_Dialog : Dialogs.PDialog;
  401.  
  402.  
  403.     { ---------------------------------------------------- }
  404.     {                                                      }
  405.     { This is a local function that brings up a dialog box }
  406.     { that asks the user which line number to jump to.     }
  407.     {                                                      }
  408.     { ---------------------------------------------------- }
  409.  
  410.  
  411.   VAR
  412.  
  413.     Line_Dialog : Dialogs.PDialog;
  414.     R           : TRect;
  415.     Sub_View    : Views.PView;
  416.  
  417.   Begin
  418.  
  419.     R.Assign (27, Y_Position, 53, Y_Position + 8);
  420.     Line_Dialog := New (Dialogs.PDialog, Init (R, 'Jump To'));
  421.  
  422.     with Line_Dialog^ do
  423.       begin
  424.  
  425.         R.Assign (3, 2, 15, 3);
  426.         Sub_View := New (Dialogs.PStaticText, Init (R, 'Line Number:'));
  427.         Insert (Sub_View);
  428.  
  429.         R.Assign (15, 2, 21, 3);
  430.         Sub_View := New (Dialogs.PInputLine, Init (R, 4));
  431.         Sub_View^.HelpCtx := CmdFile.hcDLineNumber;
  432.         Insert (Sub_View);
  433.  
  434.         R.Assign (21, 2, 24, 3);
  435.         Insert (New (Dialogs.PHistory, Init (R, Dialogs.PInputLine (Sub_View), 12)));
  436.  
  437.         R.Assign (2, 5, 12, 7);
  438.         Sub_View := New (Dialogs.PButton, Init (R, '~O~K', Views.cmOK, Dialogs.bfDefault));
  439.         Sub_View^.HelpCtx := CmdFile.hcDOk;
  440.         Insert (Sub_View);
  441.  
  442.         R.Assign (14, 5, 24, 7);
  443.         Sub_View := New (Dialogs.PButton, Init (R, '~C~ancel', Views.cmCancel, Dialogs.bfNormal));
  444.         Sub_View^.HelpCtx := CmdFile.hcDCancel;
  445.         Insert (Sub_View);
  446.  
  447.         SelectNext (False);
  448.  
  449.       end;
  450.  
  451.     Jump_Line_Dialog := Line_Dialog;
  452.  
  453.   end; { Jump_Line_Dialog; } { Added dialog to allow user to jump to line number. }
  454.  
  455.   { JLINE - Stop. }
  456.  
  457.  
  458.  
  459.   { ------------------------------------------------------------------------ }
  460.  
  461.  
  462.  
  463.   { REFDOC - Start. }
  464.  
  465.   function Reform_Doc_Dialog : Dialogs.PDialog;
  466.  
  467.  
  468.     { ----------------------------------------------------- }
  469.     {                                                       }
  470.     { This is a local function that brings up a dialog box  }
  471.     { that asks where to start reformatting the document.   }
  472.     {                                                       }
  473.     { ----------------------------------------------------- }
  474.  
  475.  
  476.   VAR
  477.  
  478.     R             : TRect;
  479.     Reform_Dialog : Dialogs.PDialog;
  480.     Sub_View      : Views.PView;
  481.  
  482.   Begin
  483.  
  484.     R.Assign (24, Y_Position, 56, Y_Position + 11);
  485.     Reform_Dialog := New (Dialogs.PDialog, Init (R, 'Reformat Document'));
  486.  
  487.     with Reform_Dialog^ do
  488.       begin
  489.  
  490.         R.Assign (2, 2, 30, 3);
  491.         Sub_View := New (Dialogs.PStaticText, Init (R, 'Please select where to begin'));
  492.         Insert (Sub_View);
  493.  
  494.         R.Assign (3, 3, 29, 4);
  495.         Sub_View := New (Dialogs.PStaticText, Init (R, 'reformatting the document:'));
  496.         Insert (Sub_View);
  497.  
  498.         R.Assign (50, 5, 68, 6);
  499.         Sub_View := New (Dialogs.PLabel, Init (R, 'Reformat Document', Sub_View));
  500.         Insert (Sub_View);
  501.  
  502.         R.Assign (5, 5, 26, 7);
  503.         Sub_View := New (Dialogs.PRadioButtons, Init (R,
  504.           NewSItem ('Current Line',
  505.           NewSItem ('Entire Document',
  506.         Nil))));
  507.         Sub_View^.HelpCtx := CmdFile.hcDReformDoc;
  508.         Insert (Sub_View);
  509.  
  510.         R.Assign (4, 8, 14, 10);
  511.         Sub_View := New (Dialogs.PButton, Init (R, '~O~K', Views.cmOK, Dialogs.bfDefault));
  512.         Sub_View^.HelpCtx := CmdFile.hcDOk;
  513.         Insert (Sub_View);
  514.  
  515.         R.Assign (17, 8, 27, 10);
  516.         Sub_View := New (Dialogs.PButton, Init (R, '~C~ancel', Views.cmCancel, Dialogs.bfNormal));
  517.         Sub_View^.HelpCtx := CmdFile.hcDCancel;
  518.         Insert (Sub_View);
  519.  
  520.         SelectNext (False);
  521.  
  522.       end;
  523.  
  524.       Reform_Doc_Dialog := Reform_Dialog;
  525.  
  526.  
  527.   end; { Reform_Doc_Dialog }
  528.  
  529.   { REFDOC - Stop. }
  530.  
  531.  
  532.  
  533.   { ------------------------------------------------------------------------ }
  534.  
  535.  
  536.  
  537.   { RMSET - Start. }
  538.   { WRAP  - Start. }
  539.  
  540.   function Right_Margin_Dialog : Dialogs.PDialog;
  541.  
  542.  
  543.     { ---------------------------------------------------- }
  544.     {                                                      }
  545.     { This is a local function that brings up a dialog box }
  546.     { that allows the user to change the Right_Margin.     }
  547.     {                                                      }
  548.     { ---------------------------------------------------- }
  549.  
  550.  
  551.   VAR
  552.  
  553.     R         : TRect;
  554.     RM_Dialog : Dialogs.PDialog;
  555.     Sub_View  : Views.PView;
  556.  
  557.   Begin
  558.  
  559.     R.Assign (27, Y_Position, 53, Y_Position + 8);
  560.     RM_Dialog := New (Dialogs.PDialog, Init (R, 'Right Margin'));
  561.  
  562.     with RM_Dialog^ do
  563.       begin
  564.  
  565.         R.Assign (5, 2, 13, 3);
  566.         Sub_View := New (Dialogs.PStaticText, Init (R, 'Setting:'));
  567.         Insert (Sub_View);
  568.  
  569.         R.Assign (13, 2, 18, 3);
  570.         Sub_View := New (Dialogs.PInputLine, Init (R, 3));
  571.         Sub_View^.HelpCtx := CmdFile.hcDRightMargin;
  572.         Insert (Sub_View);
  573.  
  574.         R.Assign (18, 2, 21, 3);
  575.         Insert (New (Dialogs.PHistory, Init (R, Dialogs.PInputLine (Sub_View), 13)));
  576.  
  577.         R.Assign (2, 5, 12, 7);
  578.         Sub_View := New (Dialogs.PButton, Init (R, 'OK', Views.cmOK, Dialogs.bfDefault));
  579.         Sub_View^.HelpCtx := CmdFile.hcDOk;
  580.         Insert (Sub_View);
  581.  
  582.         R.Assign (14, 5, 24, 7);
  583.         Sub_View := New (Dialogs.PButton, Init (R, '~C~ancel', Views.cmCancel, Dialogs.bfNormal));
  584.         Sub_View^.HelpCtx := CmdFile.hcDCancel;
  585.         Insert (Sub_View);
  586.  
  587.         SelectNext (False);
  588.  
  589.       end;
  590.  
  591.     Right_Margin_Dialog := RM_Dialog;
  592.  
  593.   end; { Right_Margin_Dialog; }
  594.  
  595.   { WRAP  - Stop. }
  596.   { RMSET - Stop. } { Added dialog to adjust right margin position. }
  597.  
  598.  
  599.  
  600.   { ------------------------------------------------------------------------ }
  601.  
  602.  
  603.  
  604.   { PRETAB - Start. }
  605.  
  606.   function Tab_Stop_Dialog : Dialogs.PDialog;
  607.  
  608.  
  609.     { ---------------------------------------------------- }
  610.     {                                                      }
  611.     { This is a local function that brings up a dialog box }
  612.     { that allows the user to set their own tab stops.     }
  613.     {                                                      }
  614.     { ---------------------------------------------------- }
  615.  
  616.  
  617.   VAR
  618.  
  619.     Index      : Integer;          { Local Indexing variable.                 }
  620.     R          : TRect;
  621.     Tab_Dialog : Dialogs.PDialog;
  622.     Sub_View   : Views.PView;
  623.     Tab_Stop   : String[2];        { Local string to print tab column number. }
  624.  
  625.   Begin
  626.  
  627.     R.Assign (0, Y_Position, 80, Y_Position + 8);
  628.     Tab_Dialog := New (Dialogs.PDialog, Init (R, 'Tab Settings'));
  629.  
  630.     with Tab_Dialog^ do
  631.       begin
  632.  
  633.         R.Assign (2, 2, 77, 3);
  634.         Sub_View := New (Dialogs.PStaticText, Init (R,
  635.                     ' ....|....|....|....|....|....|....|....|....|....|....|....|....|....|....'));
  636.         Insert (Sub_View);
  637.  
  638.         for Index := 1 to 7 do
  639.           begin
  640.             R.Assign (Index * 10 + 1, 1, Index * 10 + 3, 2);
  641.             Str (Index * 10, Tab_Stop);
  642.             Sub_View := New (Dialogs.PStaticText, Init (R, Tab_Stop));
  643.             Insert (Sub_View);
  644.           end;
  645.  
  646.         R.Assign (2, 3, 78, 4);
  647.         Sub_View := New (Dialogs.PInputLine, Init (R, 74));
  648.         Sub_View^.HelpCtx := CmdFile.hcDTabStops;
  649.         Insert (Sub_View);
  650.  
  651.         R.Assign (38, 5, 41, 6);
  652.         Insert (New (Dialogs.PHistory, Init (R, Dialogs.PInputLine (Sub_View), 14)));
  653.  
  654.         R.Assign (27, 5, 37, 7);
  655.         Sub_View := New (Dialogs.PButton, Init (R, '~O~K', Views.cmOK, Dialogs.bfDefault));
  656.         Sub_View^.HelpCtx := CmdFile.hcDOk;
  657.         Insert (Sub_View);
  658.  
  659.         R.Assign (42, 5, 52, 7);
  660.         Sub_View := New (Dialogs.PButton, Init (R, '~C~ancel', Views.cmCancel, Dialogs.bfNormal));
  661.         Sub_View^.HelpCtx := CmdFile.hcDCancel;
  662.         Insert (Sub_View);
  663.  
  664.         SelectNext (False);
  665.  
  666.       end;
  667.  
  668.     Tab_Stop_Dialog := Tab_Dialog;
  669.  
  670.   end { Tab_Stop_Dialog };
  671.  
  672.   { PRETAB - Stop. } { Added dialog to allow re-setting tab stops. }
  673.  
  674.  
  675.  
  676.   { ------------------------------------------------------------------------ }
  677.  
  678.  
  679.  
  680. VAR
  681.  
  682.   R : TRect;
  683.   T : TPoint;
  684.  
  685.  
  686. begin { Do_Edit_Dialog }
  687.  
  688.  
  689.  
  690.   { --------------------------------------------------------------------- }
  691.   {                                                                       }
  692.   { I want the dialog boxes to appear in relatively the same screen area, }
  693.   { regardless if the user is in normal or 43/50 line screen mode.        }
  694.   {                                                                       }
  695.   { --------------------------------------------------------------------- }
  696.  
  697.  
  698.   if Drivers.ScreenMode >= Drivers.smFont8x8 then
  699.     Y_Position := 7
  700.   else
  701.     Y_Position := 3;
  702.  
  703.  
  704.  
  705.   { ------------------------------------------------------ }
  706.   {                                                        }
  707.   { Figure out which dialog we want to put on the desktop. }
  708.   {                                                        }
  709.   { ------------------------------------------------------ }
  710.  
  711.  
  712.   case Dialog of
  713.  
  714.     edCreateError:
  715.       Do_Edit_Dialog := MsgBox.MessageBox ('Error creating file %s.',
  716.                         @Info, MsgBox.mfError + MsgBox.mfOkButton);
  717.  
  718.     edFind:
  719.       Do_Edit_Dialog := Execute_Dialog (Create_Find_Dialog, Info);
  720.  
  721.     edOutOfMemory:
  722.       Do_Edit_Dialog := MsgBox.MessageBox (^C'Not enough memory available.',
  723.                         nil, MsgBox.mfError + MsgBox.mfOkButton);
  724.  
  725.     edReadError:
  726.       Do_Edit_Dialog := MsgBox.MessageBox ('Error reading file %s.',
  727.                         @Info, MsgBox.mfError + MsgBox.mfOkButton);
  728.  
  729.     edReplace:
  730.       Do_Edit_Dialog := Execute_Dialog (Create_Replace_Dialog, Info);
  731.  
  732.     edSaveAs:
  733.       Do_Edit_Dialog := Execute_Dialog (New (StdDlg.PFileDialog, Init ('*.*',
  734.                        'Save file as', '~N~ame', StdDlg.fdOkButton, 101)), Info);
  735.  
  736.     edSaveModify:
  737.       Do_Edit_Dialog := MsgBox.MessageBox ('%s has been modified. Save?',
  738.                         @Info, MsgBox.mfInformation + MsgBox.mfYesNoCancel);
  739.  
  740.     edSaveUntitled:
  741.       Do_Edit_Dialog := Msgbox.MessageBox (^C'Save untitled file?',
  742.                         nil, MsgBox.mfInformation + MsgBox.mfYesNoCancel);
  743.  
  744.     edSearchFailed:
  745.       Do_Edit_Dialog := MsgBox.MessageBox (^C'Search string not found.',
  746.                         nil, MsgBox.mfError + MsgBox.mfOkButton);
  747.  
  748.     edWriteError:
  749.       Do_Edit_Dialog := MsgBox.MessageBox ('Error writing file %s.',
  750.                         @Info, MsgBox.mfError + MsgBox.mfOkButton);
  751.  
  752.     edReplacePrompt:
  753.       begin
  754.  
  755.         { Avoid placing the dialog on the same line as the cursor }
  756.  
  757.         R.Assign (0, 1, 40, 8);
  758.         R.Move ((App.Desktop^.Size.X - R.B.X) div 2, 0);
  759.         Desktop^.MakeGlobal (R.B, T);
  760.         Inc (T.Y);
  761.  
  762.         if TPoint (Info).Y <= T.Y then
  763.           R.Move (0, Desktop^.Size.Y - R.B.Y - 2);
  764.  
  765.         Do_Edit_Dialog := Msgbox.MessageBoxRect (R, ^C'Replace this occurence?',
  766.                           nil, MsgBox.mfYesNoCancel + MsgBox.mfInformation);
  767.  
  768.       end;
  769.  
  770.  
  771.  
  772.     { JLINE - Start. }
  773.  
  774.     edJumpToLine:
  775.       Do_Edit_Dialog := Execute_Dialog (Jump_Line_Dialog, Info);
  776.  
  777.     { JLINE - Stop. } { Added new cases to allow jumping to a line number. }
  778.  
  779.  
  780.  
  781.     { PRETAB - Start. }
  782.  
  783.     edSetTabStops:
  784.       Do_Edit_Dialog := Execute_Dialog (Tab_Stop_Dialog, Info);
  785.  
  786.     { PRETAB - Stop. } { Added new cases to support re-setting tab stops. }
  787.  
  788.  
  789.  
  790.     { WRAP - Start. }
  791.  
  792.  
  793.  
  794.     edPasteNotPossible:
  795.       Do_Edit_Dialog := MsgBox.MessageBox (^C'WORDWRAP ON:  Paste not possible' + #13
  796.                                            + ' in current margins when at end'  + #13
  797.                                            + ' of line.',
  798.                         nil, MsgBox.mfError + MsgBox.mfOkButton);
  799.  
  800.  
  801.  
  802.     { REFDOC - Start. }
  803.  
  804.     edReformatDocument:
  805.       Do_Edit_Dialog := Execute_Dialog (Reform_Doc_Dialog, Info);
  806.  
  807.     { REFDOC - Stop. }
  808.  
  809.  
  810.  
  811.     edReformatNotAllowed:
  812.       Do_Edit_Dialog := MsgBox.MessageBox (^C'You must turn on wordwrap' + #13
  813.                                           +^C'before you can reformat.',
  814.                         nil, MsgBox.mfError + MsgBox.mfOkButton);
  815.  
  816.     edReformNotPossible:
  817.       Do_Edit_Dialog := MsgBox.MessageBox (^C'Paragraph reformat not possible.'   + #13
  818.                                            + ' while trying to wrap current line' + #13
  819.                                            + ' with current margins.',
  820.                         nil, MsgBox.mfError + MsgBox.mfOkButton);
  821.  
  822.     edReplaceNotPossible:
  823.       Do_Edit_Dialog := MsgBox.MessageBox (^C'WORDWRAP ON:  Replace not possible' + #13
  824.                                            + ' in current margins when at end of' + #13
  825.                                            + ' line.',
  826.                         nil, MsgBox.mfError + MsgBox.mfOkButton);
  827.  
  828.  
  829.  
  830.     { RMSET- Start. }
  831.  
  832.     edRightMargin:
  833.       Do_Edit_Dialog := Execute_Dialog (Right_Margin_Dialog, Info);
  834.  
  835.     { RMSET - STOP. } { Added new cases to support right margin settings. }
  836.  
  837.  
  838.  
  839.     edWrapNotPossible:
  840.       Do_Edit_Dialog := MsgBox.MessageBox (^C'WORDWRAP ON:  Wordwrap not possible' + #13
  841.                                            + ' in current margins with continuous' + #13
  842.                                            + ' line.',
  843.                          nil, MsgBox.mfError + MsgBox.mfOKButton);
  844.  
  845.  
  846.  
  847.     { WRAP - Stop. } { Added new cases to support wordwrap and paragraph reformatting. }
  848.  
  849.  
  850.   else
  851.  
  852.     MsgBox.MessageBox (^C'Unknown dialog requested!', nil,
  853.                        MsgBox.mfError + MsgBox.mfOkButton);
  854.  
  855.   end;
  856.  
  857.  
  858. end; { Do_Edit_Dialog }
  859.  
  860.  
  861.  
  862. { -------------------------------------------------------------------------- }
  863.  
  864.  
  865.  
  866. procedure Deallocate_The_Clipboard;
  867.  
  868.  
  869.   { ----------------------------------------------------- }
  870.   {                                                       }
  871.   { This procedure disposes of the clipboard.  It is used }
  872.   { by the NEDEMO program when saving a desktop file.     }
  873.   {                                                       }
  874.   { ----------------------------------------------------- }
  875.  
  876.  
  877. begin
  878.  
  879.   if Clip_Window = nil then
  880.     Exit;
  881.  
  882.   Dispose (NewEdit.Clipboard, Done);
  883.   NewEdit.Clipboard := nil;
  884.   Dispose (Clip_Window, Done);
  885.  
  886.  
  887. end; { Deallocate_The_Clipboard }
  888.  
  889.  
  890.  
  891. { -------------------------------------------------------------------------- }
  892.  
  893.  
  894.  
  895. procedure Deallocate_The_Editor;
  896.  
  897.  
  898.   { --------------------------------------------------------- }
  899.   {                                                           }
  900.   { This procedure deallocates the editor buffer from memory. }
  901.   {                                                           }
  902.   { --------------------------------------------------------- }
  903.  
  904.  
  905. begin
  906.  
  907.   MaxHeapSize := 0;
  908.   EditorDialog := Nil;
  909.  
  910.  
  911. end; { Deallocate_The_Editor }
  912.  
  913.  
  914.  
  915. { -------------------------------------------------------------------------- }
  916.  
  917.  
  918.  
  919. procedure Initialize_The_Clipboard;
  920.  
  921.  
  922.  
  923.   { ----------------------------------------------------- }
  924.   {                                                       }
  925.   { Set up a clipboard so editor can cut and paste text.  }
  926.   { We place this here because we also need to reallocate }
  927.   { a new clipboard everytime we save a desktop to disk.  }
  928.   {                                                       }
  929.   { ----------------------------------------------------- }
  930.  
  931.  
  932. begin
  933.  
  934.   Clip_Window := Open_Editor('', False);
  935.  
  936.   if Clip_Window <> nil then
  937.     begin
  938.       NewEdit.Clipboard := Clip_Window^.Editor;
  939.       NewEdit.Clipboard^.CanUndo := False;
  940.       Clip_Window^.HelpCtx := CmdFile.hcClipBoard;
  941.     end;
  942.  
  943.  
  944. end; { Initialize_The_Clipboard }
  945.  
  946.  
  947.  
  948. { -------------------------------------------------------------------------- }
  949.  
  950.  
  951.  
  952. procedure Initialize_The_Editor;
  953.  
  954.  
  955.  
  956.   { ----------------------------------------------------------------- }
  957.   {                                                                   }
  958.   { This procedure sets aside a bit of memory for the editor buffers. }
  959.   { MaxHeapSize must be the first thing you do prior to using any     }
  960.   { heap.  This is stressed in the BP TV docs on the editor.          }
  961.   {                                                                   }
  962.   { ----------------------------------------------------------------- }
  963.  
  964.  
  965. Begin
  966.  
  967.   MaxHeapSize := 32 * (1024 div 16);
  968.  
  969. end; { Initialize_The_Editor }
  970.  
  971.  
  972.  
  973. { -------------------------------------------------------------------------- }
  974.  
  975.  
  976.  
  977. function Open_Editor (File_Name : Objects.FNameStr; Visible : Boolean) : NewEdit.PEditWindow;
  978.  
  979.  
  980.   { ------------------------------------------------------- }
  981.   {                                                         }
  982.   { This is the actual function that opens up the edit view }
  983.   { and places it on the desktop.                           }
  984.   {                                                         }
  985.   { ------------------------------------------------------- }
  986.  
  987.  
  988. VAR
  989.  
  990.   P : Views.PView;
  991.   R : TRect;
  992.  
  993. begin
  994.  
  995.   DeskTop^.GetExtent (R);
  996.   P := Application^.ValidView (New (NewEdit.PEditWindow,
  997.        Init (R, File_Name, wnNoNumber)));
  998.  
  999.   if P <> nil then
  1000.     begin
  1001.  
  1002.       if not Visible then
  1003.         begin
  1004.           P^.Hide;
  1005.           P^.Options := P^.Options and not Views.ofTileable;
  1006.         end
  1007.       else
  1008.  
  1009.  
  1010.  
  1011.         { ------------------------------------------------------------- }
  1012.         {                                                               }
  1013.         { This is a demonstration on how you can type cast variables    }
  1014.         { and thereby override their NEWEDIT defaults.  If you really   }
  1015.         { wanted to get fancy, you could add the appropriate parameters }
  1016.         { to the Open_Editor function call and thereby have different   }
  1017.         { defaults for each window.                                     }
  1018.         {                                                               }
  1019.         { ------------------------------------------------------------- }
  1020.  
  1021.  
  1022.         with NewEdit.PEditWindow (P)^ do
  1023.           begin
  1024.             Editor^.AutoIndent := True;
  1025.             Editor^.Word_Wrap := True;
  1026.             Editor^.Right_Margin := 76;
  1027.           end;
  1028.  
  1029.         Desktop^.Insert (P);
  1030.  
  1031.         Message (P, Drivers.evBroadcast, NewEdit.cmBludgeonStats, nil);
  1032.  
  1033.       end;
  1034.  
  1035.   Open_Editor := NewEdit.PEditWindow (P);
  1036.  
  1037.  
  1038. end; { Open_Editor }
  1039.  
  1040.  
  1041.  
  1042. { -------------------------------------------------------------------------- }
  1043.  
  1044.  
  1045.  
  1046. procedure Run_The_Editor;
  1047.  
  1048.  
  1049.   { --------------------------------------------------------------- }
  1050.   {                                                                 }
  1051.   { This procedure is a "front end" to the Open_Editor function.    }
  1052.   { It brings up a dialog box that asks the user which file to use. }
  1053.   {                                                                 }
  1054.   { --------------------------------------------------------------- }
  1055.  
  1056.  
  1057. VAR
  1058.  
  1059.   D        : Dialogs.PDialog;
  1060.   FileName : Objects.FNameStr;
  1061.  
  1062. begin
  1063.  
  1064.   FileName := '*.*';
  1065.  
  1066.   D := new (StdDlg.PFileDialog, Init ('*.*', 'Edit A File',
  1067.             '~N~ame', StdDlg.fdOpenButton, 100));
  1068.  
  1069.   D^.HelpCtx := CmdFile.hcDName;
  1070.  
  1071.   if Execute_Dialog (D, @FileName) <> Views.cmCancel then
  1072.     Open_Editor (FileName, True);
  1073.  
  1074.  
  1075. end; { Run_The_Editor }
  1076.  
  1077.  
  1078.  
  1079. { -------------------------------------------------------------------------- }
  1080.  
  1081.  
  1082.  
  1083. procedure Show_ClipBoard;
  1084.  
  1085. begin
  1086.  
  1087.   Clip_Window^.Select;
  1088.   Clip_Window^.Show;
  1089.  
  1090.  
  1091. end; { Show_ClipBoard }
  1092.  
  1093.  
  1094.  
  1095. { -------------------------------------------------------------------------- }
  1096.  
  1097.  
  1098.  
  1099. begin { EditPkg }
  1100.  
  1101.  
  1102.  
  1103.   { --------------------------------------------- }
  1104.   {                                               }
  1105.   { Instantiate NewEdit.EditorDialog immediately. }
  1106.   { If you don't do it here, desktops loaded at   }
  1107.   { runtime will not have access to dialogs.      }
  1108.   {                                               }
  1109.   { --------------------------------------------- }
  1110.  
  1111.  
  1112.   NewEdit.EditorDialog := Do_Edit_Dialog;
  1113.  
  1114.  
  1115. end. { Unit EditPkg }
  1116.