home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 17 / CD_ASCQ_17_101194.iso / vrac / ve2tv103.zip / TVEDIT2.CPP < prev    next >
C/C++ Source or Header  |  1994-07-31  |  26KB  |  776 lines

  1. // File    : TVEDIT2.CPP
  2. // Author  : Eric Woodruff,  CIS ID: 72134,1150
  3. // Updated : Sun 07/31/94 15:56:28
  4. // Note    : Copyright 1994, Eric Woodruff, All rights reserved
  5. // Compiler: Borland C++ 3.1 to 4.02
  6. //
  7. // More functions for the TVMEditor demo program.
  8. //
  9.  
  10. #include <ctype.h>
  11. #include <dir.h>
  12. #include <io.h>
  13. #include <stdarg.h>
  14. #include <string.h>
  15.  
  16. #define Uses_MsgBox
  17. #define Uses_TApplication
  18. #define Uses_TDeskTop
  19. #define Uses_TFileDialog
  20. #define Uses_TKeys
  21. #define Uses_TMenuBar
  22. #define Uses_TProgram
  23. #define Uses_TResourceFile
  24. #define Uses_TScreen
  25. #define Uses_TStatusLine
  26. #define Uses_TVCOLR             // Use this if you modified the TV.H file.
  27. #define Uses_fpstream
  28. #include <tv.h>
  29.  
  30. #if !defined(cpDefSize)
  31. // Use this if you chose not to modify the Turbo Vision files.
  32. #include <tvcolr.h>
  33. #endif
  34.  
  35. #if !defined(SHAREWARE)
  36. #define Uses_TVirtualMemory
  37. #endif
  38. #define Uses_TVMEditWindow
  39. #define Uses_TVMMemo
  40. #include <tvmedit.h>
  41.  
  42. #define Uses_TMsgViewWindow
  43. #include <tmsgview.h>
  44.  
  45. #define Uses_TVMEditorApp
  46. #include "tvedit.h"
  47.  
  48. extern TPoint shadowSize;   // Altered when screen size changes.
  49.  
  50. extern TResourceFile *rsc;
  51. extern StartUp StartUpOpts;
  52. extern DemoData Demo;
  53.  
  54. extern char demo_cfg[MAXPATH];
  55. extern short CmdLinePalette;
  56.  
  57. // ****************************************************************************
  58. // More standard front end functions.  Modify as needed.
  59.  
  60. //
  61. // Desktop initialization.
  62. //
  63. TDeskTop *TVMEditorApp::initDeskTop(TRect r)
  64. {
  65.     // Prevent drawing the desktop until the colors are set correctly.
  66.     TProgram::application->setState(sfExposed, False);
  67.  
  68.     r.a.y++;
  69.     r.b.y--;
  70.     return new TDeskTop(r);
  71. }
  72.  
  73. //
  74. // Screen initialization.  This is overridden so that a command line
  75. // specified color palette can be used.  If not, the default initScreen()
  76. // will reset the palette based on monitor type every time it is called.
  77. //
  78. void TVMEditorApp::initScreen()
  79. {
  80.     TProgram::initScreen();
  81.  
  82.     // Force palette to equal the user-specified palette.
  83.     if(CmdLinePalette > -1 && TApplication::appPalette != CmdLinePalette)
  84.     {
  85.         TApplication::appPalette = CmdLinePalette;
  86.  
  87.         // If monochrome, turn off shadows and turn on markers.
  88.         if(CmdLinePalette == apMonochrome)
  89.         {
  90.             shadowSize.x = 0;
  91.             shadowSize.y = 0;
  92.             showMarkers = True;
  93.         }
  94.     }
  95. }
  96.  
  97. //
  98. // Menubar initialization.
  99. //
  100. TMenuBar *TVMEditorApp::initMenuBar(TRect)
  101. {
  102.     TMenuBar *menuBar = (TMenuBar *)rsc->get("MenuBar");
  103.  
  104.     // Set menubar width in case the application starts up in anything other
  105.     // than a screen mode of 80x25 lines.
  106.     menuBar->size.x = TScreen::screenWidth;
  107.  
  108.     return menuBar;
  109. }
  110.  
  111. //
  112. // Create statusline.
  113. //
  114. TStatusLine *TVMEditorApp::initStatusLine( TRect )
  115. {
  116.     TStatusLine *statLine = (TStatusLine *)rsc->get("StatusLine");
  117.  
  118.     // Set status line width and position in case the application starts up
  119.     // in anything other than a screen mode of 80x25 lines.
  120.     statLine->origin.y = TScreen::screenHeight - 1;
  121.     statLine->size.x = TScreen::screenWidth;
  122.  
  123.     return statLine;
  124. }
  125.  
  126. // Standard Out Of Memory error dialog.
  127. void TVMEditorApp::outOfMemory(void)
  128. {
  129.     messageBox("Not enough memory for this operation.", mfError | mfCancelButton);
  130. }
  131.  
  132. //
  133. // Standard load config file.  Modify as needed.
  134. //
  135. void TVMEditorApp::loadConfig(Boolean UseFileSetting)
  136. {
  137.     fpstream *f = new fpstream(demo_cfg, ios::in | ios::nocreate | ios::binary);
  138.  
  139.     if(!f->good())
  140.     {
  141.         //  Turn on the screen?
  142.         if(!(state & sfExposed))
  143.         {
  144.             setScreenMode(TScreen::screenMode);
  145.  
  146. #if _TV_VERSION == 0x0103       // Fixed in TV 2.0.
  147.             if(TMouse::present())       // Adjust mouse limits if present.
  148.                 TMouse::setRange(TScreen::screenWidth - 1,
  149.                     TScreen::screenHeight - 1);
  150. #endif
  151.         }
  152.  
  153.         messageBox(mfError | mfCancelButton,
  154.             "Could not open configuration file: %s", demo_cfg);
  155.  
  156.         delete f;
  157.         return;
  158.     }
  159.  
  160.     ipstream &strm = *f;
  161.  
  162.     // Read palettes from the configuration file.
  163.     short curr_palette = appPalette;
  164.     for(short i = 0; i < apTotalPalettes; i++)
  165.     {
  166.         appPalette = i;
  167.         TPalette *palette = &getPalette();
  168.         strm.readBytes(palette->data, palette->data[0] + 1);
  169.     }
  170.     appPalette = curr_palette;
  171.  
  172.     // Get the video mode
  173.     ushort scrMode;
  174.     strm.readBytes(&scrMode, sizeof(scrMode));
  175.  
  176.     // Get the palette that was in use.
  177.     short usePalette;
  178.     strm.readBytes(&usePalette, sizeof(usePalette));
  179.  
  180.     // If not overridden from the command line, set the palette.
  181.     if(CmdLinePalette == -1 || (CmdLinePalette != -1 && UseFileSetting))
  182.         CmdLinePalette = usePalette;
  183.  
  184.     if(scrMode & TDisplay::smFont8x8)
  185.         shadowSize.x = 1;
  186.     else
  187.         shadowSize.x = 2;
  188.  
  189.     setScreenMode(scrMode);
  190.  
  191. #if _TV_VERSION == 0x0103   // Fixed in TV 2.0.
  192.     if(TMouse::present())       // Adjust mouse limits if present.
  193.         TMouse::setRange(TScreen::screenWidth - 1, TScreen::screenHeight - 1);
  194. #endif
  195.  
  196.     // ************************************************************************
  197.     // Add code here to load non-standard application-specific config data.
  198.     strm.readBytes(&StartUpOpts, sizeof(StartUp));
  199.  
  200.     // Set memory preference based on user selection.
  201. #if !defined(SHAREWARE)
  202.     #if !defined(__DPMI16__) && !defined(__DPMI32__)
  203.         TVirtualMemory::MemoryCheck = StartUpOpts.VirtualMemory;
  204.     #else
  205.         TVirtualMemory::setMaxAllocation(
  206.             long(StartUpOpts.MaxAllocatable) * 1024L);
  207.     #endif
  208. #endif
  209.  
  210.     delete f;
  211. }
  212.  
  213. //
  214. // Standard save config file.  Modify as needed.
  215. //
  216. void TVMEditorApp::saveConfig(void)
  217. {
  218.     fpstream *f = new fpstream(demo_cfg, ios::trunc | ios::binary);
  219.  
  220.     if(!f->good())
  221.     {
  222.         messageBox(mfError | mfCancelButton,
  223.             "Could not open configuration file: %s", demo_cfg);
  224.  
  225.         delete f;
  226.         return;
  227.     }
  228.  
  229.     opstream &strm = *f;
  230.  
  231.     // Store the palettes
  232.     short curr_palette = appPalette;
  233.     for(short i = 0; i < apTotalPalettes; i++)
  234.     {
  235.         appPalette = i;
  236.         TPalette *palette = &getPalette();
  237.         strm.writeBytes(palette->data, palette->data[0] + 1);
  238.     }
  239.     appPalette = curr_palette;
  240.  
  241.     // Store current video mode
  242.     strm.writeBytes(&TScreen::screenMode, sizeof(TScreen::screenMode));
  243.  
  244.     // Store current palette in use.
  245.     strm.writeBytes(&appPalette, sizeof(appPalette));
  246.  
  247.     // ************************************************************************
  248.     // Add code here to save non-standard application-specific config data.
  249.     strm.writeBytes(&StartUpOpts, sizeof(StartUp));
  250.  
  251.     delete f;
  252. }
  253.  
  254. // ****************************************************************************
  255. // More functions not in the standard front end.
  256.  
  257. void TVMEditorApp::saveDeskTop(void)
  258. {
  259.     // We'll assume that only editor windows are on the desktop for the demo.
  260.     TVMEditWindow *win;
  261.  
  262.     fpstream *f = new fpstream("TVEDIT.TVD", ios::out | ios::trunc | ios::binary);
  263.  
  264.     if(f->good())
  265.     {
  266.         while((win = (TVMEditWindow *)deskTop->firstThat(isTileable, 0)) != NULL)
  267.         {
  268.             *f << win;
  269.             message(win, evCommand, cmClose, NULL);
  270.         }
  271.         *f << NULL;
  272.  
  273.         if(!f->good())
  274.             messageBox("Error saving desktop!", mfError | mfCancelButton);
  275.     }
  276.     else
  277.         messageBox("Error creating desktop file!", mfError | mfCancelButton);
  278.  
  279.     delete f;
  280. }
  281.  
  282. void TVMEditorApp::restoreDeskTop(void)
  283. {
  284.     TView *p;
  285.  
  286.     fpstream *f = new fpstream("TVEDIT.TVD", ios::in | ios::nocreate | ios::binary);
  287.  
  288.     if(f->good())
  289.     {
  290.         do
  291.         {
  292.             *f >> p;
  293.             deskTop->insertBefore(validView(p), deskTop->last);
  294.  
  295.         } while(p != 0);
  296.  
  297.         if(!f->good())
  298.             messageBox("Error restoring desktop!", mfError | mfCancelButton);
  299.     }
  300.     else
  301.         messageBox("Error opening desktop file!", mfError | mfCancelButton);
  302.  
  303.     delete f;
  304. }
  305.  
  306. // ****************************************************************************
  307. void TVMEditorApp::ReplaceKeyMaps(void)
  308. {
  309.     static Boolean isSwitched = False;
  310.  
  311.     // Demo of replaceable key maps.  Toggle between full set and this
  312.     // replacement set of movement keys only.
  313.     static const ushort NewSingleKeys[] =
  314.     {
  315.         kbCtrlX,     0xFF05,         // Additional set of two-key commands.
  316.         kbLeft,      cmCharLeft,     // Movement only.
  317.         kbRight,     cmCharRight,
  318.         kbCtrlLeft,  cmWordLeft,
  319.         kbCtrlRight, cmWordRight,
  320.         kbHome,      cmLineStart,
  321.         kbEnd,       cmLineEnd,
  322.         kbUp,        cmLineUp,
  323.         kbDown,      cmLineDown,
  324.         kbCtrlW,     cmShiftUp,
  325.         kbCtrlZ,     cmShiftDown,
  326.         kbPgUp,      cmPageUp,
  327.         kbPgDn,      cmPageDown,
  328.         kbCtrlHome,  cmWindowTop,
  329.         kbCtrlEnd,   cmWindowBotm,
  330.         kbCtrlPgUp,  cmTextStart,
  331.         kbCtrlPgDn,  cmTextEnd,
  332.         0
  333.     };
  334.  
  335.     // Demo: Ctrl X, 0xFF05
  336.     static const ushort MyCtrlXKeys[] =
  337.     {
  338.         'G', cmGotoLine,        // Just for demonstration purposes.
  339.         'V', cmPrevPos,
  340.         'L', cmLastChg,
  341.         0
  342.     };
  343.  
  344.     if(isSwitched)
  345.     {
  346.         // Switch back to the full set of editing keys.
  347.         TVMEditor::changeKeyMap(0, NULL);
  348.         TVMEditor::changeKeyMap(5, NULL);
  349.         isSwitched = False;
  350.  
  351.         messageBox("Now using the default editor key assignments.",
  352.             mfInformation | mfOKButton);
  353.     }
  354.     else
  355.     {
  356.         // Replace the default single key command map and add a new map
  357.         // for the Ctrl+X key map.
  358.         TVMEditor::changeKeyMap(0, &NewSingleKeys[0]);
  359.         TVMEditor::changeKeyMap(5, &MyCtrlXKeys[0]);
  360.         isSwitched = True;
  361.  
  362.         messageBox("Only movement keys and text insertion will be recognized now.  "
  363.             "Select option again to restore defaults.",
  364.             mfInformation | mfOKButton);
  365.     }
  366. }
  367.  
  368. void TVMEditorApp::MemoDemo(void)
  369. {
  370.     // Structure for the dialog box.
  371.     struct
  372.     {
  373.         TVMMemoData Memo1;
  374.         TVMMemoData Memo2;
  375.     } DialogData;
  376.  
  377.     DialogData.Memo1.length = 255;                  // Maximum size.
  378.     DialogData.Memo1.buffer = &Demo.ShortText[0];   // Point to the text.
  379.     DialogData.Memo1.copyCount = Demo.Size1;        // Current size.
  380.  
  381.     DialogData.Memo2.length = 1024;
  382.     DialogData.Memo2.buffer = &Demo.LongText[0];
  383.     DialogData.Memo2.copyCount = Demo.Size2;
  384.  
  385.     // Use a different editorDialog() handler to take care of TVMMemo
  386.     // interaction with the user.
  387.     TVMEditor::editorDialog = doMemoEditDialog;
  388.  
  389.     // Execute the dialog box.  The executeDialog() function takes care of
  390.     // setting and getting the data using the temporary structure.
  391.     if(executeDialog((TDialog *)rsc->get("MemoDemo"), &DialogData) == cmOK)
  392.     {
  393.         // If OK was pressed, update the demo structure memo lengths.
  394.         // The memo text will have been updated already because the
  395.         // addresses were passed to the dialog in the DialogData structure.
  396.         Demo.Size1 = DialogData.Memo1.copyCount;
  397.         Demo.Size2 = DialogData.Memo2.copyCount;
  398.     }
  399.  
  400.     // Now switch back to the original editorDialog() handler.
  401.     TVMEditor::editorDialog = doEditDialog;
  402. }
  403.  
  404. void TVMEditorApp::DemoMsgViewer(void)
  405. {
  406.     TRect r = deskTop->getExtent();       // Create new one.
  407.     r.a.y = r.b.y - 7;
  408.  
  409.     TMsgViewWindow *msg = new TMsgViewWindow(r, "Demo Message Viewer");
  410.  
  411.     if(!validView(msg))
  412.         return;
  413.  
  414.     msg->insertMsg(0, "Use Alt+F7/Alt+F8 to jump backward/forward when not in this window");
  415.     msg->insertMsg(10, "Jump to line 10");
  416.     msg->insertMsg(20, "Jump to line 20");
  417.     msg->insertMsg(30, "Jump to line 30");
  418.     msg->insertMsg(100, "Jump to line 100");
  419.     msg->insertMsg(110, "Jump to line 110");
  420.     msg->insertMsg(120, "Jump to line 120");
  421.  
  422.     deskTop->insert(msg);
  423. }
  424.  
  425. // ****************************************************************************
  426.  
  427. // If you replace the default editor dialog function, be sure to check for
  428. // all possible cases that your application will need!
  429. //
  430. // This one is the general editor dialog handler for the TVMEditWindows.
  431. //
  432. ushort doEditDialog(int dialog, ...)
  433. {
  434.     va_list arg;
  435.     char  *fname, *ln;
  436.     short  size;
  437.     ushort result = cmCancel;       // Default to cancel in case undefined.
  438.  
  439.     va_start(arg, dialog);
  440.  
  441.     switch(dialog)
  442.     {
  443.         case edOutOfMemory:
  444.             messageBox("Not enough memory to complete operation",
  445.                 mfError | mfCancelButton );
  446.             break;
  447.  
  448.         case edReadError:       // Passes a char * to the name of the file.
  449.             messageBox(mfError | mfCancelButton,
  450.                 "Error reading file %s", (char *)va_arg(arg, char *));
  451.             break;
  452.  
  453.         case edWriteError:      // Passes a char * to the name of the file.
  454.             messageBox(mfError | mfCancelButton,
  455.                 "Error writing to %s", (char *)va_arg(arg, char *));
  456.             break;
  457.  
  458.         case edCreateError:     // Passes a char * to the name of the file.
  459.             messageBox(mfError | mfCancelButton,
  460.                 "Error creating file %s", (char *)va_arg(arg, char *));
  461.             break;
  462.  
  463.         case edSwapBadSeek:
  464.             messageBox("ERROR: Bad seek on swap file!", mfError | mfCancelButton);
  465.             break;
  466.  
  467.         case edSwapFileFail:
  468.             messageBox("ERROR: Could not read/write swap file!", mfError | mfCancelButton);
  469.             break;
  470.  
  471.         case edEMSXMSFailure:   // Passes a short value for the error code.
  472.             messageBox(mfError | mfCancelButton,
  473.                 "ERROR: EMS/XMS handler error code #%#x received",
  474.                 (short)va_arg(arg, short));
  475.             break;
  476.  
  477.         // Used by the diagnostic checks within the editor and virtual
  478.         // memory manager.  Also used by TVMMemo::valid() if the
  479.         // memo text is too long.  Passes a char * to the message string.
  480.         case edGeneralMsg:
  481.             messageBox(va_arg(arg, char *), mfInformation | mfCancelButton);
  482.             break;
  483.  
  484.         case edLinesSplit:
  485.             messageBox("Long lines were split when loaded", mfInformation | mfOKButton);
  486.             break;
  487.  
  488.         case edLineTooLong:
  489.             messageBox("Line would be too long", mfInformation | mfCancelButton);
  490.             break;
  491.  
  492.         case edGotoLine:
  493.             // The input is *text* so that + or - can be used!
  494.             // Absence of the + or - means a literal line number.
  495.             // Passes a char * to the buffer and a short for the
  496.             // maximum size of the string.
  497.             ln = (char *)va_arg(arg, char *);
  498.             size = (short)va_arg(arg, short);
  499.             result = inputBox("Goto/Jump", "Line number or +nnn/-nnn:",
  500.                 ln, size);
  501.             break;
  502.  
  503.         case edChgLocalOpts:    // Passes addr of LocalEditorOptions structure
  504. #if _TV_VERSION == 0x0103
  505.             result = executeDialog((TDialog *)rsc->get("LclEdOptDlg"), va_arg(arg, char *));
  506. #else
  507.             result = TProgram::application->executeDialog((TDialog *)rsc->get("LclEdOptDlg"), va_arg(arg, char *));
  508. #endif
  509.             break;
  510.  
  511.         case edFind:            // Passes addr of TVMFindDialogRec structure
  512. #if _TV_VERSION == 0x0103
  513.             result = executeDialog((TDialog *)rsc->get("FindDialog"), va_arg(arg, char *));
  514. #else
  515.             result = TProgram::application->executeDialog((TDialog *)rsc->get("FindDialog"), va_arg(arg, char *));
  516. #endif
  517.             break;
  518.  
  519.         case edReplace:         // Passes addr of TVMReplaceDialogRec structure
  520.             // NOTE:  If the Replace Dialog returns cmYes, *ALL* occurances
  521.             //        will be replaced, not just the first one.  This was
  522.             //        easier than using a new command and deriving a dialog
  523.             //        box class that could return a non-standard value.  The
  524.             //        TVMEditor classes will look specifically for cmYes to
  525.             //        enable the Change All option for search and replace
  526.             //        operations.  If cmOK is returned, only the first
  527.             //        occurance will be replaced.
  528. #if _TV_VERSION == 0x0103
  529.             result = executeDialog((TDialog *)rsc->get("ReplaceDialog"), va_arg(arg, char *));
  530. #else
  531.             result = TProgram::application->executeDialog((TDialog *)rsc->get("ReplaceDialog"), va_arg(arg, char *));
  532. #endif
  533.             break;
  534.  
  535.         case edReplacePrompt:
  536.         {
  537.             // Avoid placing the dialog on the same line as the cursor.
  538.             TRect r(0, 1, 40, 8);
  539.             r.move((TProgram::deskTop->size.x - r.b.x) / 2, 0);
  540.             TPoint t = TProgram::deskTop->makeGlobal(r.b);
  541.             t.y++;
  542.  
  543.             // Passes a pointer to the *screen* cursor position.  This is a
  544.             // normal TPoint not a TVMPoint!
  545.             TPoint *pt = (TPoint *)va_arg(arg, char *);
  546.  
  547.             if(pt->y <= t.y)
  548.                 r.move(0, TProgram::deskTop->size.y - r.b.y - 2);
  549.  
  550.             result = messageBoxRect(r, "Replace this occurance?",
  551.                 mfInformation | mfYesNoCancel);
  552.             break;
  553.         }
  554.  
  555.         case edSearchFailed:
  556.             messageBox("Search string not found.", mfInformation | mfOKButton);
  557.             break;
  558.  
  559.         case edReadBlock:       // Passes char * to a filename buffer
  560. #if _TV_VERSION == 0x0103
  561.             result = executeDialog(new TFileDialog("*.*", "Read text from",
  562.                 "~N~ame", fdOpenButton, 101), va_arg(arg, char *));
  563. #else
  564.             result = TProgram::application->executeDialog(new TFileDialog("*.*", "Read text from",
  565.                 "~N~ame", fdOpenButton, 101), va_arg(arg, char *));
  566. #endif
  567.             break;
  568.  
  569.         case edSaveBlock:       // Passes char * to a filename buffer
  570.             fname = (char *)va_arg(arg, char *);
  571.  
  572. #if _TV_VERSION == 0x0103
  573.             result = executeDialog(new TFileDialog("*.*", "Save block to",
  574.                 "~N~ame", fdOKButton, 101), fname);
  575. #else
  576.             result = TProgram::application->executeDialog(new TFileDialog("*.*", "Save block to",
  577.                 "~N~ame", fdOKButton, 101), fname);
  578. #endif
  579.             if(result != cmCancel && !access(fname, 0))
  580.                 result = messageBox(mfConfirmation | mfYesNoCancel,
  581.                     "%s already exists.  OVERWRITE?", fname);
  582.             break;
  583.  
  584.         case edSaveAs:          // Passes char * to a filename buffer
  585.             fname = (char *)va_arg(arg, char *);
  586.  
  587. #if _TV_VERSION == 0x0103
  588.             result = executeDialog(new TFileDialog("*.*", "Save file as",
  589.                 "~N~ame", fdOKButton, 101), fname);
  590. #else
  591.             result = TProgram::application->executeDialog(new TFileDialog("*.*", "Save file as",
  592.                 "~N~ame", fdOKButton, 101), fname);
  593. #endif
  594.             if(result != cmCancel && !access(fname, 0))
  595.                 result = messageBox(mfConfirmation | mfYesNoCancel,
  596.                     "%s already exists.  OVERWRITE?", fname);
  597.             break;
  598.  
  599.         case edSaveUntitled:
  600.             result = messageBox("Save untitled file?",
  601.                 mfConfirmation | mfYesNoCancel);
  602.             break;
  603.  
  604.         case edSaveModify:      // Passes char * to the name of the file.
  605.             result = messageBox(mfConfirmation | mfYesNoCancel,
  606.                 "%s has been modified.  Save?", (char *)va_arg(arg, char *));
  607.             break;
  608.  
  609.         case edReSynch:         // Passes char * to the name of the file.
  610.             result = messageBox(mfInformation | mfYesButton | mfNoButton,
  611.                 "The copy of %s on disk is different from the one in memory."
  612.                 "  Reload from disk?", (char *)va_arg(arg, char *));
  613.             break;
  614.     }
  615.     va_end(arg);
  616.  
  617.     return result;
  618. }
  619.  
  620. //
  621. // This one is the general editor dialog handler for the TVMMemos.
  622. // It will ignore edSaveAs, edSaveUntitled, and edSaveModify requests
  623. // which only pertain to TVMFileEditors.  The other I/O type events
  624. // may still be used when using the write block/read block features.
  625. // It can be made to ignore other events as you need by removing the
  626. // necessary case statements.
  627. //
  628. ushort doMemoEditDialog(int dialog, ...)
  629. {
  630.     va_list arg;
  631.     char  *fname, *ln;
  632.     short  size;
  633.     ushort result = cmCancel;       // Default to cancel in case undefined.
  634.  
  635.     va_start(arg, dialog);
  636.  
  637.     switch(dialog)
  638.     {
  639.         case edOutOfMemory:
  640.             messageBox("Not enough memory to complete operation",
  641.                 mfError | mfCancelButton );
  642.             break;
  643.  
  644.         case edReadError:       // Passes a char * to the name of the file.
  645.             messageBox(mfError | mfCancelButton,
  646.                 "Error reading file %s", (char *)va_arg(arg, char *));
  647.             break;
  648.  
  649.         case edWriteError:      // Passes a char * to the name of the file.
  650.             messageBox(mfError | mfCancelButton,
  651.                 "Error writing file %s", (char *)va_arg(arg, char *));
  652.             break;
  653.  
  654.         case edCreateError:     // Passes a char * to the name of the file.
  655.             messageBox(mfError | mfCancelButton,
  656.                 "Error creating file %s", (char *)va_arg(arg, char *));
  657.             break;
  658.  
  659.         case edSwapBadSeek:
  660.             messageBox("ERROR: Bad seek on swap file!", mfError | mfCancelButton);
  661.             break;
  662.  
  663.         case edSwapFileFail:
  664.             messageBox("ERROR: Could not read/write swap file!", mfError | mfCancelButton);
  665.             break;
  666.  
  667.         case edEMSXMSFailure:   // Passes a short value for the error code.
  668.             messageBox(mfError | mfCancelButton,
  669.                 "ERROR: EMS/XMS handler error code #%#x received",
  670.                 (short)va_arg(arg, short));
  671.             break;
  672.  
  673.         // Used by the diagnostic checks within the editor and virtual
  674.         // memory manager.  Also used by TVMMemo::valid() if the
  675.         // memo text is too long.  Passes a char * to the message string.
  676.         case edGeneralMsg:
  677.             messageBox(va_arg(arg, char *), mfInformation | mfCancelButton);
  678.             break;
  679.  
  680.         case edLinesSplit:
  681.             messageBox("Long lines were split when loaded", mfInformation | mfOKButton);
  682.             break;
  683.  
  684.         case edLineTooLong:
  685.             messageBox("Line would be too long", mfInformation | mfCancelButton);
  686.             break;
  687.  
  688.         case edGotoLine:
  689.             // The input is *text* so that + or - can be used!
  690.             // Absence of the + or - means a literal line number.
  691.             // Passes a char * to the buffer and a short for the
  692.             // maximum size of the string.
  693.             ln = (char *)va_arg(arg, char *);
  694.             size = (short)va_arg(arg, short);
  695.             result = inputBox("Goto/Jump", "Line number or +nnn/-nnn:",
  696.                 ln, size);
  697.             break;
  698.  
  699.         case edChgLocalOpts:    // Passes addr of LocalEditorOptions structure
  700. #if _TV_VERSION == 0x0103
  701.             result = executeDialog((TDialog *)rsc->get("LclEdOptDlg"), va_arg(arg, char *));
  702. #else
  703.             result = TProgram::application->executeDialog((TDialog *)rsc->get("LclEdOptDlg"), va_arg(arg, char *));
  704. #endif
  705.             break;
  706.  
  707.         case edFind:            // Passes addr of TVMFindDialogRec structure
  708. #if _TV_VERSION == 0x0103
  709.             result = executeDialog((TDialog *)rsc->get("FindDialog"), va_arg(arg, char *));
  710. #else
  711.             result = TProgram::application->executeDialog((TDialog *)rsc->get("FindDialog"), va_arg(arg, char *));
  712. #endif
  713.             break;
  714.  
  715.         case edReplace:         // Passes addr of TVMReplaceDialogRec structure
  716. #if _TV_VERSION == 0x0103
  717.             result = executeDialog((TDialog *)rsc->get("ReplaceDialog"), va_arg(arg, char *));
  718. #else
  719.             result = TProgram::application->executeDialog((TDialog *)rsc->get("ReplaceDialog"), va_arg(arg, char *));
  720. #endif
  721.             break;
  722.  
  723.         case edReplacePrompt:
  724.         {
  725.             // Avoid placing the dialog on the same line as the cursor.
  726.             TRect r(0, 1, 40, 8);
  727.             r.move((TProgram::deskTop->size.x - r.b.x) / 2, 0);
  728.             TPoint t = TProgram::deskTop->makeGlobal(r.b);
  729.             t.y++;
  730.  
  731.             // Passes a pointer to the *screen* cursor position.  This is a
  732.             // normal TPoint not a TVMPoint!
  733.             TPoint *pt = (TPoint *)va_arg(arg, char *);
  734.  
  735.             if(pt->y <= t.y)
  736.                 r.move(0, TProgram::deskTop->size.y - r.b.y - 2);
  737.  
  738.             result = messageBoxRect(r, "Replace this occurance?",
  739.                 mfYesNoCancel | mfInformation);
  740.             break;
  741.         }
  742.  
  743.         case edSearchFailed:
  744.             messageBox("Search string not found.", mfInformation | mfOKButton);
  745.             break;
  746.  
  747.         case edReadBlock:       // Passes char * to a filename buffer
  748. #if _TV_VERSION == 0x0103
  749.             result = executeDialog(new TFileDialog("*.*", "Read text from",
  750.                 "~N~ame", fdOpenButton, 101), va_arg(arg, char *));
  751. #else
  752.             result = TProgram::application->executeDialog(new TFileDialog("*.*", "Read text from",
  753.                 "~N~ame", fdOpenButton, 101), va_arg(arg, char *));
  754. #endif
  755.             break;
  756.  
  757.         case edSaveBlock:       // Passes char * to a filename buffer
  758.             fname = (char *)va_arg(arg, char *);
  759.  
  760. #if _TV_VERSION == 0x0103
  761.             result = executeDialog(new TFileDialog("*.*", "Save block to",
  762.                 "~N~ame", fdOKButton, 101), fname);
  763. #else
  764.             result = TProgram::application->executeDialog(new TFileDialog("*.*", "Save block to",
  765.                 "~N~ame", fdOKButton, 101), fname);
  766. #endif
  767.             if(result != cmCancel && !access(fname, 0))
  768.                 result = messageBox(mfConfirmation | mfYesNoCancel,
  769.                     "%s already exists.  OVERWRITE?", fname);
  770.             break;
  771.     }
  772.     va_end(arg);
  773.  
  774.     return result;
  775. }
  776.