2000-03-05 19:58:08 +00:00
|
|
|
/* ----------- fileopen.c ------------- */
|
|
|
|
|
|
|
|
#include "dflat.h"
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
static BOOL DlgFileOpen(char *, char *, DF_DBOX *);
|
|
|
|
static int DlgFnOpen(DFWINDOW, DFMESSAGE, DF_PARAM, DF_PARAM);
|
2000-03-05 19:58:08 +00:00
|
|
|
static void InitDlgBox(DFWINDOW);
|
|
|
|
static void StripPath(char *);
|
|
|
|
static BOOL IncompleteFilename(char *);
|
|
|
|
|
|
|
|
static char *OrigSpec;
|
|
|
|
static char *FileSpec;
|
|
|
|
static char *FileName;
|
|
|
|
static char *NewFileName;
|
|
|
|
|
|
|
|
static BOOL Saving;
|
2003-06-19 02:48:13 +00:00
|
|
|
extern DF_DBOX FileOpen;
|
|
|
|
extern DF_DBOX SaveAs;
|
2000-03-05 19:58:08 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Dialog Box to select a file to open
|
|
|
|
*/
|
2003-06-19 02:48:13 +00:00
|
|
|
BOOL DfOpenFileDialogBox(char *Fpath, char *Fname)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
return DlgFileOpen(Fpath, Fname, &FileOpen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Dialog Box to select a file to save as
|
|
|
|
*/
|
2003-06-19 02:48:13 +00:00
|
|
|
BOOL DfSaveAsDialogBox(char *Fname)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
return DlgFileOpen(NULL, Fname, &SaveAs);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------- generic file open ---------- */
|
2003-06-19 02:48:13 +00:00
|
|
|
static BOOL DlgFileOpen(char *Fpath, char *Fname, DF_DBOX *db)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
BOOL rtn;
|
|
|
|
char savedir[MAX_PATH];
|
|
|
|
char OSpec[80];
|
|
|
|
char FSpec[80];
|
|
|
|
char FName[80];
|
|
|
|
char NewFName[80];
|
|
|
|
|
|
|
|
OrigSpec = OSpec;
|
|
|
|
FileSpec = FSpec;
|
|
|
|
FileName = FName;
|
|
|
|
NewFileName = NewFName;
|
|
|
|
|
|
|
|
GetCurrentDirectory (MAX_PATH, savedir);
|
|
|
|
|
|
|
|
if (Fpath != NULL) {
|
|
|
|
strncpy(FileSpec, Fpath, 80);
|
|
|
|
Saving = FALSE;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*FileSpec = '\0';
|
|
|
|
Saving = TRUE;
|
|
|
|
}
|
|
|
|
strcpy(FileName, FileSpec);
|
|
|
|
strcpy(OrigSpec, FileSpec);
|
|
|
|
|
|
|
|
if ((rtn = DfDialogBox(NULL, db, TRUE, DlgFnOpen)) != FALSE)
|
|
|
|
strcpy(Fname, NewFileName);
|
|
|
|
else
|
|
|
|
*Fname = '\0';
|
|
|
|
|
|
|
|
SetCurrentDirectory (savedir);
|
|
|
|
|
|
|
|
return rtn;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process dialog box messages
|
|
|
|
*/
|
2003-06-19 02:48:13 +00:00
|
|
|
static int DlgFnOpen(DFWINDOW wnd,DFMESSAGE msg,DF_PARAM p1,DF_PARAM p2)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
int rtn;
|
2003-06-19 02:48:13 +00:00
|
|
|
DF_DBOX *db;
|
2000-03-05 19:58:08 +00:00
|
|
|
DFWINDOW cwnd;
|
|
|
|
|
|
|
|
switch (msg)
|
|
|
|
{
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_CREATE_WINDOW:
|
|
|
|
rtn = DfDefaultWndProc(wnd, msg, p1, p2);
|
2000-03-05 19:58:08 +00:00
|
|
|
db = wnd->extension;
|
2003-06-19 02:48:13 +00:00
|
|
|
cwnd = DfControlWindow(db, DF_ID_FILENAME);
|
|
|
|
DfSendMessage(cwnd, DFM_SETTEXTLENGTH, 64, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
return rtn;
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_INITIATE_DIALOG:
|
2000-03-05 19:58:08 +00:00
|
|
|
InitDlgBox(wnd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DFM_COMMAND:
|
|
|
|
switch ((int) p1)
|
|
|
|
{
|
2003-06-19 02:48:13 +00:00
|
|
|
case DF_ID_FILENAME:
|
|
|
|
if (p2 != DFM_ENTERFOCUS)
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
/* allow user to modify the file spec */
|
2003-06-19 02:48:13 +00:00
|
|
|
DfGetItemText(wnd, DF_ID_FILENAME,
|
2000-03-05 19:58:08 +00:00
|
|
|
FileName, 65);
|
|
|
|
if (IncompleteFilename(FileName) || Saving)
|
|
|
|
{
|
|
|
|
strcpy(OrigSpec, FileName);
|
|
|
|
StripPath(OrigSpec);
|
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
if (p2 != DFM_LEAVEFOCUS)
|
|
|
|
DfSendMessage(wnd, DFM_COMMAND, DF_ID_OK, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
case DF_ID_OK:
|
2000-03-05 19:58:08 +00:00
|
|
|
if (p2 != 0)
|
|
|
|
break;
|
2003-06-19 02:48:13 +00:00
|
|
|
DfGetItemText(wnd, DF_ID_FILENAME,
|
2000-03-05 19:58:08 +00:00
|
|
|
FileName, 65);
|
|
|
|
strcpy(FileSpec, FileName);
|
|
|
|
if (IncompleteFilename(FileName))
|
|
|
|
{
|
|
|
|
/* no file name yet */
|
|
|
|
InitDlgBox(wnd);
|
|
|
|
strcpy(OrigSpec, FileSpec);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
else {
|
2003-06-19 02:48:13 +00:00
|
|
|
DfGetItemText(wnd, DF_ID_PATH, FileName, 65);
|
2000-03-05 19:58:08 +00:00
|
|
|
strcat(FileName, FileSpec);
|
|
|
|
strcpy(NewFileName, FileName);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
case DF_ID_FILES:
|
2000-03-05 19:58:08 +00:00
|
|
|
switch ((int) p2)
|
|
|
|
{
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_ENTERFOCUS:
|
|
|
|
case DFM_LB_SELECTION:
|
2000-03-05 19:58:08 +00:00
|
|
|
/* selected a different filename */
|
2003-06-19 02:48:13 +00:00
|
|
|
DfGetDlgListText(wnd, FileName,
|
|
|
|
DF_ID_FILES);
|
|
|
|
DfPutItemText(wnd, DF_ID_FILENAME,
|
2000-03-05 19:58:08 +00:00
|
|
|
FileName);
|
|
|
|
break;
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_LB_CHOOSE:
|
2000-03-05 19:58:08 +00:00
|
|
|
/* chose a file name */
|
2003-06-19 02:48:13 +00:00
|
|
|
DfGetDlgListText(wnd, FileName,
|
|
|
|
DF_ID_FILES);
|
|
|
|
DfSendMessage(wnd, DFM_COMMAND, DF_ID_OK, 0);
|
2000-03-05 19:58:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
case DF_ID_DRIVE:
|
2000-03-05 19:58:08 +00:00
|
|
|
switch ((int) p2) {
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_ENTERFOCUS:
|
2000-03-05 19:58:08 +00:00
|
|
|
if (Saving)
|
|
|
|
*FileSpec = '\0';
|
|
|
|
break;
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_LEAVEFOCUS:
|
2000-03-05 19:58:08 +00:00
|
|
|
if (Saving)
|
|
|
|
strcpy(FileSpec, FileName);
|
|
|
|
break;
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_LB_SELECTION:
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
char dd[25];
|
|
|
|
/* selected different drive/dir */
|
2003-06-19 02:48:13 +00:00
|
|
|
DfGetDlgListText(wnd, dd, DF_ID_DRIVE);
|
2000-03-05 19:58:08 +00:00
|
|
|
if (*(dd+2) == ':')
|
|
|
|
*(dd+3) = '\0';
|
|
|
|
else
|
|
|
|
*(dd+strlen(dd)-1) = '\0';
|
|
|
|
strcpy(FileName, dd+1);
|
|
|
|
if (*(dd+2) != ':' && *OrigSpec != '\\')
|
|
|
|
strcat(FileName, "\\");
|
|
|
|
strcat(FileName, OrigSpec);
|
|
|
|
if (*(FileName+1) != ':' && *FileName != '.')
|
|
|
|
{
|
2003-06-19 02:48:13 +00:00
|
|
|
DfGetItemText(wnd, DF_ID_PATH, FileSpec, 65);
|
2000-03-05 19:58:08 +00:00
|
|
|
strcat(FileSpec, FileName);
|
|
|
|
}
|
2005-05-07 21:24:31 +00:00
|
|
|
else
|
2000-03-05 19:58:08 +00:00
|
|
|
strcpy(FileSpec, FileName);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2003-06-19 02:48:13 +00:00
|
|
|
case DFM_LB_CHOOSE:
|
2000-03-05 19:58:08 +00:00
|
|
|
/* chose drive/dir */
|
|
|
|
if (Saving)
|
2003-06-19 02:48:13 +00:00
|
|
|
DfPutItemText(wnd, DF_ID_FILENAME, "");
|
2000-03-05 19:58:08 +00:00
|
|
|
InitDlgBox(wnd);
|
|
|
|
return TRUE;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
DfPutItemText(wnd, DF_ID_FILENAME, FileSpec);
|
2000-03-05 19:58:08 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2003-06-19 02:48:13 +00:00
|
|
|
return DfDefaultWndProc(wnd, msg, p1, p2);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the dialog box
|
|
|
|
*/
|
|
|
|
static void InitDlgBox(DFWINDOW wnd)
|
|
|
|
{
|
|
|
|
if (*FileSpec && !Saving)
|
2003-06-19 02:48:13 +00:00
|
|
|
DfPutItemText(wnd, DF_ID_FILENAME, FileSpec);
|
|
|
|
if (DfDlgDirList(wnd, FileSpec, DF_ID_FILES, DF_ID_PATH, 0))
|
2000-03-05 19:58:08 +00:00
|
|
|
{
|
|
|
|
StripPath(FileSpec);
|
2003-06-19 02:48:13 +00:00
|
|
|
DfDlgDirList(wnd, "*.*", DF_ID_DRIVE, 0, 0xc010);
|
2000-03-05 19:58:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Strip the drive and path information from a file spec
|
|
|
|
*/
|
|
|
|
static void StripPath(char *filespec)
|
|
|
|
{
|
|
|
|
char *cp, *cp1;
|
|
|
|
|
|
|
|
cp = strchr(filespec, ':');
|
|
|
|
if (cp != NULL)
|
|
|
|
cp++;
|
|
|
|
else
|
|
|
|
cp = filespec;
|
|
|
|
while (TRUE) {
|
|
|
|
cp1 = strchr(cp, '\\');
|
|
|
|
if (cp1 == NULL)
|
|
|
|
break;
|
|
|
|
cp = cp1+1;
|
|
|
|
}
|
|
|
|
strcpy(filespec, cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static BOOL IncompleteFilename(char *s)
|
|
|
|
{
|
|
|
|
int lc = strlen(s)-1;
|
|
|
|
if (strchr(s, '?') || strchr(s, '*') || !*s)
|
|
|
|
return TRUE;
|
|
|
|
if (*(s+lc) == ':' || *(s+lc) == '\\')
|
|
|
|
return TRUE;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2002-09-03 18:44:19 +00:00
|
|
|
/* EOF */
|