The R Project SVN R

Rev

Rev 45927 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 45927 Rev 46843
Line 62... Line 62...
62
    return(0);
62
    return(0);
63
}
63
}
64
 
64
 
65
#define BUFSIZE _MAX_PATH
65
#define BUFSIZE _MAX_PATH
66
static char strbuf[BUFSIZE];
66
static char strbuf[BUFSIZE];
-
 
67
static wchar_t wcsbuf[65536];
67
 
68
 
68
static const char *filter[] = {
69
static const char *filter[] = {
69
    "All Files (*.*)",	"*.*",
70
    "All Files (*.*)",	"*.*",
70
    "Text Files (*.TXT)",	"*.txt",
71
    "Text Files (*.TXT)",	"*.txt",
71
    "HTML Files (*.HTM)",	"*.htm",
72
    "HTML Files (*.HTM)",	"*.htm",
Line 73... Line 74...
73
    "JPEG Files (*.JPG)",	"*.jpg",
74
    "JPEG Files (*.JPG)",	"*.jpg",
74
    "BMP Files (*.BMP)",	"*.bmp",
75
    "BMP Files (*.BMP)",	"*.bmp",
75
    ""
76
    ""
76
};
77
};
77
 
78
 
-
 
79
static const wchar_t *wfilter[] = {
-
 
80
    L"All Files (*.*)",	L"*.*",
-
 
81
    L"Text Files (*.TXT)",	L"*.txt",
-
 
82
    L"HTML Files (*.HTM)",	L"*.htm",
-
 
83
    L"PNG Files (*.PNG)",	L"*.png",
-
 
84
    L"JPEG Files (*.JPG)",	L"*.jpg",
-
 
85
    L"BMP Files (*.BMP)",	L"*.bmp",
-
 
86
    L""
-
 
87
};
-
 
88
 
78
unsigned int TopmostDialogs = 0; /* May be MB_TOPMOST */
89
unsigned int TopmostDialogs = 0; /* May be MB_TOPMOST */
79
 
90
 
80
static const char *userfilter;
91
static const char *userfilter;
-
 
92
static const wchar_t *userfilterW;
-
 
93
 
81
void setuserfilter(const char *uf)
94
void setuserfilter(const char *uf)
82
{
95
{
83
    userfilter=uf;
96
    userfilter=uf;
84
}
97
}
85
 
98
 
-
 
99
void setuserfilterW(const wchar_t *uf)
-
 
100
{
-
 
101
    userfilterW=uf;
-
 
102
}
-
 
103
 
86
static HWND hModelessDlg = NULL;
104
static HWND hModelessDlg = NULL;
87
 
105
 
88
int myMessageBox(HWND h, const char *text, const char *caption, UINT type)
106
int myMessageBox(HWND h, const char *text, const char *caption, UINT type)
89
{
107
{
90
    if(localeCP != GetACP()) {
108
    if(localeCP != GetACP()) {
Line 166... Line 184...
166
    default: result = CANCEL; break;
184
    default: result = CANCEL; break;
167
    }
185
    }
168
    return result;
186
    return result;
169
}
187
}
170
 
188
 
-
 
189
/* This should always have a native encoded name, so don't need Unicode here */
171
static char cod[MAX_PATH]=""; /*current open directory*/
190
static char cod[MAX_PATH]=""; /*current open directory*/
172
 
191
 
173
void askchangedir()
192
void askchangedir()
174
{
193
{
175
    char *s, msg[MAX_PATH + 40];
194
    char *s, msg[MAX_PATH + 40];
Line 181... Line 200...
181
	snprintf(msg, MAX_PATH + 40,
200
	snprintf(msg, MAX_PATH + 40,
182
		 G_("Unable to set '%s' as working directory"), s);
201
		 G_("Unable to set '%s' as working directory"), s);
183
	askok(msg);
202
	askok(msg);
184
    }
203
    }
185
    /* in every case reset cod (to new directory if all went ok
204
    /* in every case reset cod (to new directory if all went ok
186
       or to old since user may have edited it */
205
       or to old since user may have edited it) */
187
    GetCurrentDirectory(MAX_PATH, cod);
206
    GetCurrentDirectory(MAX_PATH, cod);
188
}
207
}
189
 
208
 
190
char *askfilename(const char *title, const char *default_name)
209
char *askfilename(const char *title, const char *default_name)
191
{
210
{
Line 194... Line 213...
194
    else return NULL;
213
    else return NULL;
195
}
214
}
196
 
215
 
197
char *askfilenamewithdir(const char *title, const char *default_name, const char *dir)
216
char *askfilenamewithdir(const char *title, const char *default_name, const char *dir)
198
{
217
{
199
    if (*askfilenames(title, default_name, 0, userfilter?userfilter:filter[0], 0,
218
    if (*askfilenames(title, default_name, 0, 
-
 
219
		      userfilter ? userfilter : filter[0], 0,
200
		      strbuf, BUFSIZE, dir)) return strbuf;
220
		      strbuf, BUFSIZE, dir)) return strbuf;
201
    else return NULL;
221
    else return NULL;
202
}
222
}
203
 
223
 
204
char *askfilenames(const char *title, const char *default_name, int multi,
224
char *askfilenames(const char *title, const char *default_name, int multi,
Line 212... Line 232...
212
    HWND prev = GetFocus();
232
    HWND prev = GetFocus();
213
 
233
 
214
    if (!default_name) default_name = "";
234
    if (!default_name) default_name = "";
215
    strcpy(strbuf, default_name);
235
    strcpy(strbuf, default_name);
216
    GetCurrentDirectory(MAX_PATH, cwd);
236
    GetCurrentDirectory(MAX_PATH, cwd);
217
    if (!strcmp(cod, "")) {
-
 
218
	if (!dir) strcpy(cod, cwd);
237
    if (!cod[0]) strcpy(cod, cwd);
219
	else strcpy(cod, dir);
-
 
220
    }
-
 
221
 
238
 
222
    ofn.lStructSize     = sizeof(OPENFILENAME);
239
    ofn.lStructSize     = sizeof(OPENFILENAME);
223
    ofn.hwndOwner       = current_window ? current_window->handle : 0;
240
    ofn.hwndOwner       = current_window ? current_window->handle : 0;
224
    ofn.hInstance       = 0;
241
    ofn.hInstance       = 0;
225
    ofn.lpstrFilter     = filters;
242
    ofn.lpstrFilter     = filters;
Line 228... Line 245...
228
    ofn.nFilterIndex    = filterindex;
245
    ofn.nFilterIndex    = filterindex;
229
    ofn.lpstrFile       = strbuf;
246
    ofn.lpstrFile       = strbuf;
230
    ofn.nMaxFile        = bufsize;
247
    ofn.nMaxFile        = bufsize;
231
    ofn.lpstrFileTitle  = NULL;
248
    ofn.lpstrFileTitle  = NULL;
232
    ofn.nMaxFileTitle   = _MAX_FNAME + _MAX_EXT;
249
    ofn.nMaxFileTitle   = _MAX_FNAME + _MAX_EXT;
233
    ofn.lpstrInitialDir = cod;
250
    ofn.lpstrInitialDir = dir ? dir : cod;
234
    ofn.lpstrTitle      = title;
251
    ofn.lpstrTitle      = title;
235
    ofn.Flags           = OFN_CREATEPROMPT | OFN_HIDEREADONLY | OFN_EXPLORER;
252
    ofn.Flags           = OFN_CREATEPROMPT | OFN_HIDEREADONLY | OFN_EXPLORER;
236
    if (multi) ofn.Flags |= OFN_ALLOWMULTISELECT;
253
    if (multi) ofn.Flags |= OFN_ALLOWMULTISELECT;
237
    ofn.nFileOffset     = 0;
254
    ofn.nFileOffset     = 0;
238
    ofn.nFileExtension  = 0;
255
    ofn.nFileExtension  = 0;
Line 240... Line 257...
240
    ofn.lCustData       = 0L;
257
    ofn.lCustData       = 0L;
241
    ofn.lpfnHook        = NULL;
258
    ofn.lpfnHook        = NULL;
242
    ofn.lpTemplateName  = NULL;
259
    ofn.lpTemplateName  = NULL;
243
 
260
 
244
    if (GetOpenFileName(&ofn) == 0) {
261
    if (GetOpenFileName(&ofn) == 0) {
245
	GetCurrentDirectory(MAX_PATH, cod);
262
	if(!dir) GetCurrentDirectory(MAX_PATH, cod);
246
	SetCurrentDirectory(cwd);
263
	SetCurrentDirectory(cwd);
247
	strbuf[0] = 0;
264
	strbuf[0] = 0;
248
	strbuf[1] = 0;
265
	strbuf[1] = 0;
249
    } else {
266
    } else {
250
	GetCurrentDirectory(MAX_PATH, cod);
267
	if(!dir) GetCurrentDirectory(MAX_PATH, cod);
251
	SetCurrentDirectory(cwd);
268
	SetCurrentDirectory(cwd);
252
	for (i = 0; i <  10; i++) if (peekevent()) doevent();
269
	for (i = 0; i <  10; i++) if (peekevent()) doevent();
253
    }
270
    }
254
    SetFocus(prev);
271
    SetFocus(prev);
255
    return strbuf;
272
    return strbuf;
256
}
273
}
257
 
274
 
-
 
275
wchar_t *askfilenameW(const char *title, const char *default_name)
-
 
276
{
-
 
277
    wchar_t wtitle[1000], wdef_name[MAX_PATH];
-
 
278
 
-
 
279
    mbstowcs(wtitle, title, 1000);
-
 
280
    if (!default_name) wcscpy(wdef_name, L"");
-
 
281
    else mbstowcs(wdef_name, default_name, MAX_PATH);
-
 
282
    if (*askfilenamesW(wtitle, wdef_name, 0, 
-
 
283
		       userfilterW ? userfilterW : wfilter[0], 0,
-
 
284
		       NULL)) return wcsbuf;
-
 
285
    else return NULL;
-
 
286
}
-
 
287
 
-
 
288
wchar_t *askfilenamesW(const wchar_t *title, const wchar_t *default_name,
-
 
289
		       int multi,
-
 
290
		       const wchar_t *filters, int filterindex,
-
 
291
		       const wchar_t *dir)
-
 
292
{
-
 
293
    int i;
-
 
294
    OPENFILENAMEW ofn;
-
 
295
    char cwd[MAX_PATH];
-
 
296
    wchar_t wcod[MAX_PATH];
-
 
297
    HWND prev = GetFocus();
-
 
298
 
-
 
299
    if (!default_name) default_name = L"";
-
 
300
    wcscpy(wcsbuf, default_name);
-
 
301
    GetCurrentDirectory(MAX_PATH, cwd);
-
 
302
    if (!strcmp(cod, "")) {
-
 
303
	if (!dir) GetCurrentDirectoryW(MAX_PATH, wcod); else wcscpy(wcod, dir);
-
 
304
    } else
-
 
305
	mbstowcs(wcod, cod, MAX_PATH);
-
 
306
 
-
 
307
    ofn.lStructSize     = sizeof(OPENFILENAME);
-
 
308
    ofn.hwndOwner       = current_window ? current_window->handle : 0;
-
 
309
    ofn.hInstance       = 0;
-
 
310
    ofn.lpstrFilter     = filters;
-
 
311
    ofn.lpstrCustomFilter = NULL;
-
 
312
    ofn.nMaxCustFilter  = 0;
-
 
313
    ofn.nFilterIndex    = filterindex;
-
 
314
    ofn.lpstrFile       = wcsbuf;
-
 
315
    ofn.nMaxFile        = 65520; /* precaution against overflow */
-
 
316
    ofn.lpstrFileTitle  = NULL;
-
 
317
    ofn.nMaxFileTitle   = _MAX_FNAME + _MAX_EXT;
-
 
318
    ofn.lpstrInitialDir = wcod;
-
 
319
    ofn.lpstrTitle      = title;
-
 
320
    ofn.Flags           = OFN_CREATEPROMPT | OFN_HIDEREADONLY | OFN_EXPLORER;
-
 
321
    if (multi) ofn.Flags |= OFN_ALLOWMULTISELECT;
-
 
322
    ofn.nFileOffset     = 0;
-
 
323
    ofn.nFileExtension  = 0;
-
 
324
    ofn.lpstrDefExt     = L"*";
-
 
325
    ofn.lCustData       = 0L;
-
 
326
    ofn.lpfnHook        = NULL;
-
 
327
    ofn.lpTemplateName  = NULL;
-
 
328
 
-
 
329
    if (GetOpenFileNameW(&ofn) == 0) {
-
 
330
	/* This could fail if the Unicode name is not a native name */
-
 
331
	DWORD res = GetCurrentDirectory(MAX_PATH, cod);
-
 
332
	if(res) strcpy(cod, cwd);
-
 
333
	SetCurrentDirectory(cwd);
-
 
334
	wcsbuf[0] = 0;
-
 
335
	wcsbuf[1] = 0;
-
 
336
    } else {
-
 
337
	DWORD res = GetCurrentDirectory(MAX_PATH, cod);
-
 
338
	if(res) strcpy(cod, cwd);
-
 
339
	SetCurrentDirectory(cwd);
-
 
340
	for (i = 0; i <  10; i++) if (peekevent()) doevent();
-
 
341
    }
-
 
342
    SetFocus(prev);
-
 
343
    return wcsbuf;
-
 
344
}
-
 
345
 
258
int countFilenames(const char *list)
346
int countFilenames(const char *list)
259
{
347
{
260
    const char *temp;
348
    const char *temp;
261
    int count;
349
    int count;
262
    count = 0;
350
    count = 0;
Line 267... Line 355...
267
char *askfilesave(const char *title, const char *default_name)
355
char *askfilesave(const char *title, const char *default_name)
268
{
356
{
269
    return askfilesavewithdir(title, default_name, NULL);
357
    return askfilesavewithdir(title, default_name, NULL);
270
}
358
}
271
 
359
 
-
 
360
wchar_t *askfilesaveW(const char *title, const char *default_name) 
-
 
361
{
-
 
362
    int i;
-
 
363
    OPENFILENAMEW ofn;
-
 
364
    wchar_t cwd[MAX_PATH], wdef_name[MAX_PATH], wtitle[1000];
-
 
365
 
-
 
366
    if (!default_name) wcscpy(wdef_name, L"");
-
 
367
    else mbstowcs(wdef_name, default_name, MAX_PATH);
-
 
368
    wcscpy(wcsbuf, wdef_name);
-
 
369
    mbstowcs(wtitle, title, 1000);
-
 
370
 
-
 
371
    ofn.lStructSize     = sizeof(OPENFILENAME);
-
 
372
    ofn.hwndOwner       = current_window ? current_window->handle : 0;
-
 
373
    ofn.hInstance       = 0;
-
 
374
    ofn.lpstrFilter     = userfilterW ? userfilterW : wfilter[0];
-
 
375
    ofn.lpstrCustomFilter = NULL;
-
 
376
    ofn.nMaxCustFilter  = 0;
-
 
377
    ofn.nFilterIndex    = 0;
-
 
378
    ofn.lpstrFile       = wcsbuf;
-
 
379
    ofn.nMaxFile        = BUFSIZE;
-
 
380
    ofn.lpstrFileTitle  = NULL;
-
 
381
    ofn.nMaxFileTitle   = _MAX_FNAME + _MAX_EXT;
-
 
382
    if (GetCurrentDirectoryW(MAX_PATH, cwd))
-
 
383
	ofn.lpstrInitialDir = cwd;
-
 
384
    else
-
 
385
	ofn.lpstrInitialDir = NULL;
-
 
386
    ofn.lpstrTitle      = wtitle;
-
 
387
    ofn.Flags           = OFN_OVERWRITEPROMPT |
-
 
388
	OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
-
 
389
    ofn.nFileOffset     = 0;
-
 
390
    ofn.nFileExtension  = 0;
-
 
391
    ofn.lpstrDefExt     = NULL;
-
 
392
    ofn.lCustData       = 0L;
-
 
393
    ofn.lpfnHook        = NULL;
-
 
394
    ofn.lpTemplateName  = NULL;
-
 
395
 
-
 
396
    if (GetSaveFileNameW(&ofn) == 0)
-
 
397
	return NULL;
-
 
398
    else {
-
 
399
	for (i = 0; i < 10; i++) if (peekevent()) doevent();
-
 
400
	return wcsbuf;
-
 
401
    }
-
 
402
}
-
 
403
 
272
char *askfilesavewithdir(const char *title, const char *default_name, const char *dir)
404
char *askfilesavewithdir(const char *title, const char *default_name,
-
 
405
			 const char *dir)
273
{
406
{
274
    int i;
407
    int i;
275
    OPENFILENAME ofn;
408
    OPENFILENAME ofn;
276
    char *p, cwd[MAX_PATH], *defext = NULL;
409
    char cwd[MAX_PATH], *defext = NULL;
277
 
410
 
278
    if (!default_name) default_name = "";
411
    if (!default_name) default_name = "";
279
    else if(default_name[0] == '|') {
412
    else if(default_name[0] == '|') {
280
	defext = (char *)default_name + 2;
413
	defext = (char *)default_name + 2;
281
	default_name = "";
414
	default_name = "";
Line 293... Line 426...
293
    ofn.nMaxFile        = BUFSIZE;
426
    ofn.nMaxFile        = BUFSIZE;
294
    ofn.lpstrFileTitle  = NULL;
427
    ofn.lpstrFileTitle  = NULL;
295
    ofn.nMaxFileTitle   = _MAX_FNAME + _MAX_EXT;
428
    ofn.nMaxFileTitle   = _MAX_FNAME + _MAX_EXT;
296
    if(dir && strlen(dir) > 0) {
429
    if(dir && strlen(dir) > 0) {
297
	strcpy(cwd, dir);
430
	strcpy(cwd, dir);
298
	for(p = cwd; *p; p++) if(*p == '/') *p = '\\';
431
	/* This should have been set to use backslashes in the caller */
299
	ofn.lpstrInitialDir = cwd;
432
	ofn.lpstrInitialDir = cwd;
300
    } else {
433
    } else {
301
	if (GetCurrentDirectory(MAX_PATH, cwd))
434
	if (GetCurrentDirectory(MAX_PATH, cwd))
302
	    ofn.lpstrInitialDir = cwd;
435
	    ofn.lpstrInitialDir = cwd;
303
	else
436
	else