home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 26
/
CD_ASCQ_26_1295.iso
/
vrac
/
tvme30.zip
/
TVEDIT2.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-02
|
30KB
|
865 lines
// File : TVEDIT2.CPP
// Author : Eric Woodruff, CIS ID: 72134,1150
// Updated : Wed 08/02/95 17:54:19
// Note : Copyright 1994-95, Eric Woodruff, All rights reserved
// Compiler: Borland C++ 3.1 to 4.xx
//
// More functions for the TVMEditor demo program.
//
#include <ctype.h>
#include <dir.h>
#include <io.h>
#include <stdarg.h>
#include <string.h>
#define Uses_MsgBox
#define Uses_TApplication
#define Uses_TColorDialog
#define Uses_TColorGroup
#define Uses_TColorItem
#define Uses_TDeskTop
#define Uses_TFileDialog
#define Uses_TKeys
#define Uses_TMenuBar
#define Uses_TProgram
#define Uses_TResourceFile
#define Uses_TScreen
#define Uses_TStatusLine
#define Uses_TVCOLR // Use this if you modified the TV.H file.
#define Uses_fpstream
#include <tv.h>
#if !defined(cpDefSize)
// Use this if you chose not to modify the Turbo Vision files.
#include <tvcolr.h>
#endif
#if !defined(SHAREWARE)
#define Uses_TVirtualMemory
#endif
#define Uses_TVMEditWindow
#define Uses_TVMMemo
#include <tvmedit.h>
#if defined(CSH_LIBRARY)
#define Uses_TCSHEditor
#include <cshedit.h> // For the Color Syntax Highlighter.
#endif
#define Uses_TMsgViewWindow
#include <tmsgview.h>
#define Uses_TVMEditorApp
#include "tvedit.h"
extern TPoint shadowSize; // Altered when screen size changes.
extern TResourceFile *rsc;
extern StartUp StartUpOpts;
extern DemoData Demo;
extern char demo_cfg[MAXPATH];
extern short CmdLinePalette;
// ****************************************************************************
// More standard front end functions. Modify as needed.
//
// Desktop initialization.
//
TDeskTop *TVMEditorApp::initDeskTop(TRect r)
{
// Prevent drawing the desktop until the colors are set correctly.
TProgram::application->setState(sfExposed, False);
r.a.y++;
r.b.y--;
return new TDeskTop(r);
}
//
// Screen initialization. This is overridden so that a command line
// specified color palette can be used. If not, the default initScreen()
// will reset the palette based on monitor type every time it is called.
//
void TVMEditorApp::initScreen()
{
TProgram::initScreen();
// Force palette to equal the user-specified palette.
if(CmdLinePalette > -1 && TApplication::appPalette != CmdLinePalette)
{
TApplication::appPalette = CmdLinePalette;
// If monochrome, turn off shadows and turn on markers.
if(CmdLinePalette == apMonochrome)
{
shadowSize.x = 0;
shadowSize.y = 0;
showMarkers = True;
}
}
}
//
// Menubar initialization.
//
TMenuBar *TVMEditorApp::initMenuBar(TRect)
{
TMenuBar *menuBar = (TMenuBar *)rsc->get("MenuBar");
// Set menubar width in case the application starts up in anything other
// than a screen mode of 80x25 lines.
menuBar->size.x = TScreen::screenWidth;
return menuBar;
}
//
// Create statusline.
//
TStatusLine *TVMEditorApp::initStatusLine( TRect )
{
TStatusLine *statLine = (TStatusLine *)rsc->get("StatusLine");
// Set status line width and position in case the application starts up
// in anything other than a screen mode of 80x25 lines.
statLine->origin.y = TScreen::screenHeight - 1;
statLine->size.x = TScreen::screenWidth;
return statLine;
}
// Standard Out Of Memory error dialog.
void TVMEditorApp::outOfMemory(void)
{
messageBox("Not enough memory for this operation.", mfError | mfCancelButton);
}
//
// Standard load config file. Modify as needed.
//
void TVMEditorApp::loadConfig(Boolean UseFileSetting)
{
fpstream *f = new fpstream(demo_cfg, ios::in | ios::nocreate | ios::binary);
if(!f->good())
{
// Turn on the screen?
if(!(state & sfExposed))
{
setScreenMode(TScreen::screenMode);
#if _TV_VERSION == 0x0103 // Fixed in TV 2.0.
if(TMouse::present()) // Adjust mouse limits if present.
TMouse::setRange(TScreen::screenWidth - 1,
TScreen::screenHeight - 1);
#endif
}
messageBox(mfError | mfCancelButton,
"Could not open configuration file: %s", demo_cfg);
delete f;
return;
}
ipstream &strm = *f;
// Read palettes from the configuration file.
short curr_palette = appPalette;
for(short i = 0; i < apTotalPalettes; i++)
{
appPalette = i;
TPalette *palette = &getPalette();
strm.readBytes(palette->data, palette->data[0] + 1);
}
appPalette = curr_palette;
// Get the video mode
ushort scrMode;
strm.readBytes(&scrMode, sizeof(scrMode));
// Get the palette that was in use.
short usePalette;
strm.readBytes(&usePalette, sizeof(usePalette));
// If not overridden from the command line, set the palette.
if(CmdLinePalette == -1 || (CmdLinePalette != -1 && UseFileSetting))
CmdLinePalette = usePalette;
setScreenMode(scrMode);
#if _TV_VERSION == 0x0103 // Fixed in TV 2.0.
if(TMouse::present()) // Adjust mouse limits if present.
TMouse::setRange(TScreen::screenWidth - 1, TScreen::screenHeight - 1);
#endif
// ************************************************************************
// Add code here to load non-standard application-specific config data.
strm.readBytes(&StartUpOpts, sizeof(StartUp));
strm.readBytes(&TVMEditor::GlobalOpts, sizeof(GlobalEditorOptions));
// Set memory preference based on user selection.
#if !defined(SHAREWARE)
#if !defined(__DPMI16__) && !defined(__DPMI32__)
TVirtualMemory::MemoryCheck = StartUpOpts.VirtualMemory;
#else
TVirtualMemory::setMaxAllocation(
long(StartUpOpts.MaxAllocatable) * 1024L);
#endif
#endif
delete f;
}
//
// Standard save config file. Modify as needed.
//
void TVMEditorApp::saveConfig(void)
{
fpstream *f = new fpstream(demo_cfg, ios::trunc | ios::binary);
if(!f->good())
{
messageBox(mfError | mfCancelButton,
"Could not open configuration file: %s", demo_cfg);
delete f;
return;
}
opstream &strm = *f;
// Store the palettes
short curr_palette = appPalette;
for(short i = 0; i < apTotalPalettes; i++)
{
appPalette = i;
TPalette *palette = &getPalette();
strm.writeBytes(palette->data, palette->data[0] + 1);
}
appPalette = curr_palette;
// Store current video mode
strm.writeBytes(&TScreen::screenMode, sizeof(TScreen::screenMode));
// Store current palette in use.
strm.writeBytes(&appPalette, sizeof(appPalette));
// ************************************************************************
// Add code here to save non-standard application-specific config data.
strm.writeBytes(&StartUpOpts, sizeof(StartUp));
strm.writeBytes(&TVMEditor::GlobalOpts, sizeof(GlobalEditorOptions));
delete f;
}
// ****************************************************************************
// More functions not in the standard front end.
void TVMEditorApp::saveDeskTop(void)
{
// We'll assume that only editor windows are on the desktop for the demo.
TVMEditWindow *win;
#if defined(__DPMI16__)
fpstream *f = new fpstream("TVEDIT16.TVD", ios::out | ios::trunc | ios::binary);
#else
#if defined(__DPMI32__)
fpstream *f = new fpstream("TVEDIT32.TVD", ios::out | ios::trunc | ios::binary);
#else
fpstream *f = new fpstream("TVEDIT.TVD", ios::out | ios::trunc | ios::binary);
#endif
#endif
if(f->good())
{
while((win = (TVMEditWindow *)deskTop->firstThat(isTileable, 0)) != NULL)
{
*f << win;
message(win, evCommand, cmClose, NULL);
}
*f << NULL;
if(!f->good())
messageBox("Error saving desktop!", mfError | mfCancelButton);
}
else
messageBox("Error creating desktop file!", mfError | mfCancelButton);
delete f;
}
void TVMEditorApp::restoreDeskTop(void)
{
TView *p;
#if defined(__DPMI16__)
fpstream *f = new fpstream("TVEDIT16.TVD", ios::in | ios::nocreate | ios::binary);
#else
#if defined(__DPMI32__)
fpstream *f = new fpstream("TVEDIT32.TVD", ios::in | ios::nocreate | ios::binary);
#else
fpstream *f = new fpstream("TVEDIT.TVD", ios::in | ios::nocreate | ios::binary);
#endif
#endif
if(f->good())
{
do
{
*f >> p;
deskTop->insertBefore(validView(p), deskTop->last);
} while(p != 0);
if(!f->good())
messageBox("Error restoring desktop!", mfError | mfCancelButton);
}
else
messageBox("Error opening desktop file!", mfError | mfCancelButton);
delete f;
}
// ****************************************************************************
void TVMEditorApp::ReplaceKeyMaps(void)
{
static Boolean isSwitched = False;
// Demo of replaceable key maps. Toggle between full set and this
// replacement set of movement keys only.
static const ushort NewSingleKeys[] =
{
kbCtrlX, 0xFF05, // Additional set of two-key commands.
kbLeft, cmCharLeft, // Movement only.
kbRight, cmCharRight,
kbCtrlLeft, cmWordLeft,
kbCtrlRight, cmWordRight,
kbHome, cmLineStart,
kbEnd, cmLineEnd,
kbUp, cmLineUp,
kbDown, cmLineDown,
kbCtrlW, cmShiftUp,
kbCtrlZ, cmShiftDown,
kbPgUp, cmPageUp,
kbPgDn, cmPageDown,
kbCtrlHome, cmWindowTop,
kbCtrlEnd, cmWindowBotm,
kbCtrlPgUp, cmTextStart,
kbCtrlPgDn, cmTextEnd,
0
};
// Demo: Ctrl X, 0xFF05
static const ushort MyCtrlXKeys[] =
{
'G', cmGotoLine, // Just for demonstration purposes.
'V', cmPrevPos,
'L', cmLastChg,
0
};
if(isSwitched)
{
// Switch back to the full set of editing keys.
TVMEditor::changeKeyMap(0, NULL);
TVMEditor::changeKeyMap(5, NULL);
isSwitched = False;
messageBox("Now using the default editor key assignments.",
mfInformation | mfOKButton);
}
else
{
// Replace the default single key command map and add a new map
// for the Ctrl+X key map.
TVMEditor::changeKeyMap(0, &NewSingleKeys[0]);
TVMEditor::changeKeyMap(5, &MyCtrlXKeys[0]);
isSwitched = True;
messageBox("Only movement keys and text insertion will be recognized now. "
"Select option again to restore defaults.",
mfInformation | mfOKButton);
}
}
void TVMEditorApp::MemoDemo(void)
{
// Structure for the dialog box.
struct
{
TVMMemoData Memo1;
TVMMemoData Memo2;
} DialogData;
DialogData.Memo1.length = 255; // Maximum size.
DialogData.Memo1.buffer = &Demo.ShortText[0]; // Point to the text.
DialogData.Memo1.copyCount = Demo.Size1; // Current size.
DialogData.Memo2.length = 1024;
DialogData.Memo2.buffer = &Demo.LongText[0];
DialogData.Memo2.copyCount = Demo.Size2;
// Use a different editorDialog() handler to take care of TVMMemo
// interaction with the user.
TVMEditor::editorDialog = doMemoEditDialog;
// Execute the dialog box. The executeDialog() function takes care of
// setting and getting the data using the temporary structure.
if(executeDialog((TDialog *)rsc->get("MemoDemo"), &DialogData) == cmOK)
{
// If OK was pressed, update the demo structure memo lengths.
// The memo text will have been updated already because the
// addresses were passed to the dialog in the DialogData structure.
Demo.Size1 = DialogData.Memo1.copyCount;
Demo.Size2 = DialogData.Memo2.copyCount;
}
// Now switch back to the original editorDialog() handler.
TVMEditor::editorDialog = doEditDialog;
}
void TVMEditorApp::DemoMsgViewer(void)
{
TRect r = deskTop->getExtent(); // Create new one.
r.a.y = r.b.y - 7;
TMsgViewWindow *msg = new TMsgViewWindow(r, "Demo Message Viewer");
if(!validView(msg))
return;
msg->insertMsg(0, "Use Alt+F7/Alt+F8 to jump backward/forward when not in this window");
msg->insertMsg(10, "Jump to line 10");
msg->insertMsg(20, "Jump to line 20");
msg->insertMsg(30, "Jump to line 30");
msg->insertMsg(100, "Jump to line 100");
msg->insertMsg(110, "Jump to line 110");
msg->insertMsg(120, "Jump to line 120");
deskTop->insert(msg);
}
// ****************************************************************************
// This is for the Color Syntax Highlighter. It allows you to alter the
// colors for the topmost view that is using CSH (if there is one).
#if defined(CSH_LIBRARY)
void TVMEditorApp::setCSHColors(void)
{
char colors[csMaxGroups];
char *colorPalette[] = { "Color", "Black & White", "Monochrome",
"Alt. Color" };
// There's nobody to work with.
if(!message(deskTop, evBroadcast, cmCSHGetColors, colors))
return;
TColorGroup &group1 =
*new TColorGroup(colorPalette[appPalette]) +
*new TColorItem("Group A", 1)+
*new TColorItem("Group B", 2)+
*new TColorItem("Group C", 3)+
*new TColorItem("Group D", 4)+
*new TColorItem("Group E", 5)+
*new TColorItem("Group F", 6)+
*new TColorItem("Group G", 7)+
*new TColorItem("Group H", 8)+
*new TColorItem("Group I", 9)+
*new TColorItem("Group J", 10)+
*new TColorItem("Group K", 11)+
*new TColorItem("Group L", 12)+
*new TColorItem("Group M", 13)+
*new TColorItem("Group N", 14)+
*new TColorItem("Group O", 15)+
*new TColorItem("Group P", 16);
TPalette *pal = new TPalette(colors, csMaxGroups);
TColorDialog *c = new TColorDialog(pal, &group1);
if(validView(c))
{
// Execute the color dialog box.
if(deskTop->execView(c) != cmCancel)
{
*pal = *(c->pal);
memcpy(colors, &pal->data[1], csMaxGroups);
message(deskTop, evBroadcast, cmCSHSetColors, colors);
// Repaint the entire desktop by calling
// setScreenMode(). Calling deskTop->setState()
// to set sfVisible off and then on as in TVDEMO
// doesn't always redraw the entire screen if
// there is a window or some other view on the
// desktop that has the focus.
setScreenMode(TScreen::screenMode);
// If allowed, save the colors to the defaults file for
// permanent use.
if(messageBox("Save color set to defaults file?",
mfConfirmation | mfYesNoCancel) == cmYes)
message(deskTop, evBroadcast, cmCSHSaveColors, NULL);
}
destroy(c);
}
delete pal;
}
#endif
// ****************************************************************************
// If you replace the default editor dialog function, be sure to check for
// all possible cases that your application will need!
//
// This one is the general editor dialog handler for the TVMEditWindows.
//
ushort doEditDialog(int dialog, ...)
{
va_list arg;
char *fname, *ln;
short size;
ushort result = cmCancel; // Default to cancel in case undefined.
va_start(arg, dialog);
switch(dialog)
{
case edOutOfMemory:
messageBox("Not enough memory to complete operation",
mfError | mfCancelButton );
break;
case edReadError: // Passes a char * to the name of the file.
messageBox(mfError | mfCancelButton,
"Error reading file %s", (char *)va_arg(arg, char *));
break;
case edWriteError: // Passes a char * to the name of the file.
messageBox(mfError | mfCancelButton,
"Error writing to %s", (char *)va_arg(arg, char *));
break;
case edCreateError: // Passes a char * to the name of the file.
messageBox(mfError | mfCancelButton,
"Error creating file %s", (char *)va_arg(arg, char *));
break;
case edSwapBadSeek:
messageBox("ERROR: Bad seek on swap file!", mfError | mfCancelButton);
break;
case edSwapFileFail:
messageBox("ERROR: Could not read/write swap file!", mfError | mfCancelButton);
break;
case edEMSXMSFailure: // Passes a short value for the error code.
messageBox(mfError | mfCancelButton,
"ERROR: EMS/XMS handler error code #%#x received",
(short)va_arg(arg, short));
break;
// Used by the diagnostic checks within the editor and virtual
// memory manager. Also used by TVMMemo::valid() if the
// memo text is too long. Passes a char * to the message string.
case edGeneralMsg:
messageBox(va_arg(arg, char *), mfInformation | mfCancelButton);
break;
case edLinesSplit:
messageBox("Long lines were split when loaded", mfInformation | mfOKButton);
break;
case edLineTooLong:
messageBox("Line would be too long", mfInformation | mfCancelButton);
break;
case edGotoLine:
// The input is *text* so that + or - can be used!
// Absence of the + or - means a literal line number.
// Passes a char * to the buffer and a short for the
// maximum size of the string.
ln = (char *)va_arg(arg, char *);
size = (short)va_arg(arg, short);
result = inputBox("Goto/Jump", "Line number or +nnn/-nnn:",
ln, size);
break;
case edChgLocalOpts: // Passes addr of LocalEditorOptions structure
#if _TV_VERSION == 0x0103
result = executeDialog((TDialog *)rsc->get("LclEdOptDlg"), va_arg(arg, char *));
#else
result = TProgram::application->executeDialog((TDialog *)rsc->get("LclEdOptDlg"), va_arg(arg, char *));
#endif
break;
case edFind: // Passes addr of TVMFindDialogRec structure
#if _TV_VERSION == 0x0103
result = executeDialog((TDialog *)rsc->get("FindDialog"), va_arg(arg, char *));
#else
result = TProgram::application->executeDialog((TDialog *)rsc->get("FindDialog"), va_arg(arg, char *));
#endif
break;
case edReplace: // Passes addr of TVMReplaceDialogRec structure
// NOTE: If the Replace Dialog returns cmYes, *ALL* occurances
// will be replaced, not just the first one. This was
// easier than using a new command and deriving a dialog
// box class that could return a non-standard value. The
// TVMEditor classes will look specifically for cmYes to
// enable the Change All option for search and replace
// operations. If cmOK is returned, only the first
// occurance will be replaced.
#if _TV_VERSION == 0x0103
result = executeDialog((TDialog *)rsc->get("ReplaceDialog"), va_arg(arg, char *));
#else
result = TProgram::application->executeDialog((TDialog *)rsc->get("ReplaceDialog"), va_arg(arg, char *));
#endif
break;
case edReplacePrompt:
{
// Avoid placing the dialog on the same line as the cursor.
TRect r(0, 1, 40, 8);
r.move((TProgram::deskTop->size.x - r.b.x) / 2, 0);
TPoint t = TProgram::deskTop->makeGlobal(r.b);
t.y++;
// Passes a pointer to the *screen* cursor position. This is a
// normal TPoint not a TVMPoint!
TPoint *pt = (TPoint *)va_arg(arg, char *);
if(pt->y <= t.y)
r.move(0, TProgram::deskTop->size.y - r.b.y - 2);
result = messageBoxRect(r, "Replace this occurance?",
mfInformation | mfYesNoCancel);
break;
}
case edSearchFailed:
messageBox("Search string not found.", mfInformation | mfOKButton);
break;
case edReadBlock: // Passes char * to a filename buffer
#if _TV_VERSION == 0x0103
result = executeDialog(new TFileDialog("*.*", "Read text from",
"~N~ame", fdOpenButton, 101), va_arg(arg, char *));
#else
result = TProgram::application->executeDialog(new TFileDialog("*.*", "Read text from",
"~N~ame", fdOpenButton, 101), va_arg(arg, char *));
#endif
break;
case edSaveBlock: // Passes char * to a filename buffer
fname = (char *)va_arg(arg, char *);
#if _TV_VERSION == 0x0103
result = executeDialog(new TFileDialog("*.*", "Save block to",
"~N~ame", fdOKButton, 101), fname);
#else
result = TProgram::application->executeDialog(new TFileDialog("*.*", "Save block to",
"~N~ame", fdOKButton, 101), fname);
#endif
if(result != cmCancel && !access(fname, 0))
result = messageBox(mfConfirmation | mfYesNoCancel,
"%s already exists. OVERWRITE?", fname);
break;
case edSaveAs: // Passes char * to a filename buffer
fname = (char *)va_arg(arg, char *);
#if _TV_VERSION == 0x0103
result = executeDialog(new TFileDialog("*.*", "Save file as",
"~N~ame", fdOKButton, 101), fname);
#else
result = TProgram::application->executeDialog(new TFileDialog("*.*", "Save file as",
"~N~ame", fdOKButton, 101), fname);
#endif
if(result != cmCancel && !access(fname, 0))
result = messageBox(mfConfirmation | mfYesNoCancel,
"%s already exists. OVERWRITE?", fname);
break;
case edSaveUntitled:
result = messageBox("Save untitled file?",
mfConfirmation | mfYesNoCancel);
break;
case edSaveModify: // Passes char * to the name of the file.
result = messageBox(mfConfirmation | mfYesNoCancel,
"%s has been modified. Save?", (char *)va_arg(arg, char *));
break;
case edReSynch: // Passes char * to the name of the file.
result = messageBox(mfInformation | mfYesButton | mfNoButton,
"The copy of %s on disk is different from the one in memory."
" Reload from disk?", (char *)va_arg(arg, char *));
break;
}
va_end(arg);
return result;
}
//
// This one is the general editor dialog handler for the TVMMemos.
// It will ignore edSaveAs, edSaveUntitled, and edSaveModify requests
// which only pertain to TVMFileEditors. The other I/O type events
// may still be used when using the write block/read block features.
// It can be made to ignore other events as you need by removing the
// necessary case statements.
//
ushort doMemoEditDialog(int dialog, ...)
{
va_list arg;
char *fname, *ln;
short size;
ushort result = cmCancel; // Default to cancel in case undefined.
va_start(arg, dialog);
switch(dialog)
{
case edOutOfMemory:
messageBox("Not enough memory to complete operation",
mfError | mfCancelButton );
break;
case edReadError: // Passes a char * to the name of the file.
messageBox(mfError | mfCancelButton,
"Error reading file %s", (char *)va_arg(arg, char *));
break;
case edWriteError: // Passes a char * to the name of the file.
messageBox(mfError | mfCancelButton,
"Error writing file %s", (char *)va_arg(arg, char *));
break;
case edCreateError: // Passes a char * to the name of the file.
messageBox(mfError | mfCancelButton,
"Error creating file %s", (char *)va_arg(arg, char *));
break;
case edSwapBadSeek:
messageBox("ERROR: Bad seek on swap file!", mfError | mfCancelButton);
break;
case edSwapFileFail:
messageBox("ERROR: Could not read/write swap file!", mfError | mfCancelButton);
break;
case edEMSXMSFailure: // Passes a short value for the error code.
messageBox(mfError | mfCancelButton,
"ERROR: EMS/XMS handler error code #%#x received",
(short)va_arg(arg, short));
break;
// Used by the diagnostic checks within the editor and virtual
// memory manager. Also used by TVMMemo::valid() if the
// memo text is too long. Passes a char * to the message string.
case edGeneralMsg:
messageBox(va_arg(arg, char *), mfInformation | mfCancelButton);
break;
case edLinesSplit:
messageBox("Long lines were split when loaded", mfInformation | mfOKButton);
break;
case edLineTooLong:
messageBox("Line would be too long", mfInformation | mfCancelButton);
break;
case edGotoLine:
// The input is *text* so that + or - can be used!
// Absence of the + or - means a literal line number.
// Passes a char * to the buffer and a short for the
// maximum size of the string.
ln = (char *)va_arg(arg, char *);
size = (short)va_arg(arg, short);
result = inputBox("Goto/Jump", "Line number or +nnn/-nnn:",
ln, size);
break;
case edChgLocalOpts: // Passes addr of LocalEditorOptions structure
#if _TV_VERSION == 0x0103
result = executeDialog((TDialog *)rsc->get("LclEdOptDlg"), va_arg(arg, char *));
#else
result = TProgram::application->executeDialog((TDialog *)rsc->get("LclEdOptDlg"), va_arg(arg, char *));
#endif
break;
case edFind: // Passes addr of TVMFindDialogRec structure
#if _TV_VERSION == 0x0103
result = executeDialog((TDialog *)rsc->get("FindDialog"), va_arg(arg, char *));
#else
result = TProgram::application->executeDialog((TDialog *)rsc->get("FindDialog"), va_arg(arg, char *));
#endif
break;
case edReplace: // Passes addr of TVMReplaceDialogRec structure
#if _TV_VERSION == 0x0103
result = executeDialog((TDialog *)rsc->get("ReplaceDialog"), va_arg(arg, char *));
#else
result = TProgram::application->executeDialog((TDialog *)rsc->get("ReplaceDialog"), va_arg(arg, char *));
#endif
break;
case edReplacePrompt:
{
// Avoid placing the dialog on the same line as the cursor.
TRect r(0, 1, 40, 8);
r.move((TProgram::deskTop->size.x - r.b.x) / 2, 0);
TPoint t = TProgram::deskTop->makeGlobal(r.b);
t.y++;
// Passes a pointer to the *screen* cursor position. This is a
// normal TPoint not a TVMPoint!
TPoint *pt = (TPoint *)va_arg(arg, char *);
if(pt->y <= t.y)
r.move(0, TProgram::deskTop->size.y - r.b.y - 2);
result = messageBoxRect(r, "Replace this occurance?",
mfYesNoCancel | mfInformation);
break;
}
case edSearchFailed:
messageBox("Search string not found.", mfInformation | mfOKButton);
break;
case edReadBlock: // Passes char * to a filename buffer
#if _TV_VERSION == 0x0103
result = executeDialog(new TFileDialog("*.*", "Read text from",
"~N~ame", fdOpenButton, 101), va_arg(arg, char *));
#else
result = TProgram::application->executeDialog(new TFileDialog("*.*", "Read text from",
"~N~ame", fdOpenButton, 101), va_arg(arg, char *));
#endif
break;
case edSaveBlock: // Passes char * to a filename buffer
fname = (char *)va_arg(arg, char *);
#if _TV_VERSION == 0x0103
result = executeDialog(new TFileDialog("*.*", "Save block to",
"~N~ame", fdOKButton, 101), fname);
#else
result = TProgram::application->executeDialog(new TFileDialog("*.*", "Save block to",
"~N~ame", fdOKButton, 101), fname);
#endif
if(result != cmCancel && !access(fname, 0))
result = messageBox(mfConfirmation | mfYesNoCancel,
"%s already exists. OVERWRITE?", fname);
break;
}
va_end(arg);
return result;
}