1 /* ----------- fileopen.c ------------- */
5 static BOOL
DlgFileOpen(char *, char *, DBOX
*);
6 static int DlgFnOpen(DFWINDOW
, DFMESSAGE
, PARAM
, PARAM
);
7 static void InitDlgBox(DFWINDOW
);
8 static void StripPath(char *);
9 static BOOL
IncompleteFilename(char *);
11 static char *OrigSpec
;
12 static char *FileSpec
;
13 static char *FileName
;
14 static char *NewFileName
;
21 * Dialog Box to select a file to open
23 BOOL
OpenFileDialogBox(char *Fpath
, char *Fname
)
25 return DlgFileOpen(Fpath
, Fname
, &FileOpen
);
29 * Dialog Box to select a file to save as
31 BOOL
SaveAsDialogBox(char *Fname
)
33 return DlgFileOpen(NULL
, Fname
, &SaveAs
);
36 /* --------- generic file open ---------- */
37 static BOOL
DlgFileOpen(char *Fpath
, char *Fname
, DBOX
*db
)
40 char savedir
[MAX_PATH
];
49 NewFileName
= NewFName
;
51 GetCurrentDirectory (MAX_PATH
, savedir
);
54 strncpy(FileSpec
, Fpath
, 80);
61 strcpy(FileName
, FileSpec
);
62 strcpy(OrigSpec
, FileSpec
);
64 if ((rtn
= DfDialogBox(NULL
, db
, TRUE
, DlgFnOpen
)) != FALSE
)
65 strcpy(Fname
, NewFileName
);
69 SetCurrentDirectory (savedir
);
75 * Process dialog box messages
77 static int DlgFnOpen(DFWINDOW wnd
,DFMESSAGE msg
,PARAM p1
,PARAM p2
)
86 rtn
= DefaultWndProc(wnd
, msg
, p1
, p2
);
88 cwnd
= ControlWindow(db
, ID_FILENAME
);
89 DfSendMessage(cwnd
, SETTEXTLENGTH
, 64, 0);
100 if (p2
!= ENTERFOCUS
)
102 /* allow user to modify the file spec */
103 GetItemText(wnd
, ID_FILENAME
,
105 if (IncompleteFilename(FileName
) || Saving
)
107 strcpy(OrigSpec
, FileName
);
110 if (p2
!= LEAVEFOCUS
)
111 DfSendMessage(wnd
, DFM_COMMAND
, ID_OK
, 0);
118 GetItemText(wnd
, ID_FILENAME
,
120 strcpy(FileSpec
, FileName
);
121 if (IncompleteFilename(FileName
))
123 /* no file name yet */
125 strcpy(OrigSpec
, FileSpec
);
129 GetItemText(wnd
, ID_PATH
, FileName
, 65);
130 strcat(FileName
, FileSpec
);
131 strcpy(NewFileName
, FileName
);
140 /* selected a different filename */
141 GetDlgListText(wnd
, FileName
,
143 PutItemText(wnd
, ID_FILENAME
,
147 /* chose a file name */
148 GetDlgListText(wnd
, FileName
,
150 DfSendMessage(wnd
, DFM_COMMAND
, ID_OK
, 0);
165 strcpy(FileSpec
, FileName
);
171 /* selected different drive/dir */
172 GetDlgListText(wnd
, dd
, ID_DRIVE
);
176 *(dd
+strlen(dd
)-1) = '\0';
177 strcpy(FileName
, dd
+1);
178 if (*(dd
+2) != ':' && *OrigSpec
!= '\\')
179 strcat(FileName
, "\\");
180 strcat(FileName
, OrigSpec
);
181 if (*(FileName
+1) != ':' && *FileName
!= '.')
183 GetItemText(wnd
, ID_PATH
, FileSpec
, 65);
184 strcat(FileSpec
, FileName
);
187 strcpy(FileSpec
, FileName
);
192 /* chose drive/dir */
194 PutItemText(wnd
, ID_FILENAME
, "");
200 PutItemText(wnd
, ID_FILENAME
, FileSpec
);
210 return DefaultWndProc(wnd
, msg
, p1
, p2
);
214 * Initialize the dialog box
216 static void InitDlgBox(DFWINDOW wnd
)
218 if (*FileSpec
&& !Saving
)
219 PutItemText(wnd
, ID_FILENAME
, FileSpec
);
220 if (DfDlgDirList(wnd
, FileSpec
, ID_FILES
, ID_PATH
, 0))
223 DfDlgDirList(wnd
, "*.*", ID_DRIVE
, 0, 0xc010);
228 * Strip the drive and path information from a file spec
230 static void StripPath(char *filespec
)
234 cp
= strchr(filespec
, ':');
240 cp1
= strchr(cp
, '\\');
245 strcpy(filespec
, cp
);
249 static BOOL
IncompleteFilename(char *s
)
251 int lc
= strlen(s
)-1;
252 if (strchr(s
, '?') || strchr(s
, '*') || !*s
)
254 if (*(s
+lc
) == ':' || *(s
+lc
) == '\\')