comparison src/macfns.c @ 60361:bd59e53ab8e8

(install_window_handler): Move extern to macterm.h. (Fx_file_dialog): Check STRINGP (default_filename) to see it is valid. Don't check !NILP (dir) because it is already checked with CHECK_STRING. (Fx_file_dialog) [!MAC_OSX]: Use FSSpec instead of FSRef for specifying the default location and obtaining the selected filename.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Fri, 04 Mar 2005 11:08:54 +0000
parents 47a7608e0711
children c30bb367650a 29e773288013
comparison
equal deleted inserted replaced
60360:86edfe26d552 60361:bd59e53ab8e8
2292 } 2292 }
2293 2293
2294 2294
2295 /* Create and set up the Mac window for frame F. */ 2295 /* Create and set up the Mac window for frame F. */
2296 2296
2297 extern OSErr install_window_handler (WindowPtr);
2298
2299 static void 2297 static void
2300 mac_window (f) 2298 mac_window (f)
2301 struct frame *f; 2299 struct frame *f;
2302 { 2300 {
2303 Rect r; 2301 Rect r;
4354 /* This is a save dialog */ 4352 /* This is a save dialog */
4355 options.optionFlags |= kNavDontConfirmReplacement; 4353 options.optionFlags |= kNavDontConfirmReplacement;
4356 options.actionButtonLabel = CFSTR ("Ok"); 4354 options.actionButtonLabel = CFSTR ("Ok");
4357 options.windowTitle = CFSTR ("Enter name"); 4355 options.windowTitle = CFSTR ("Enter name");
4358 4356
4359 if (!NILP(default_filename)) 4357 if (STRINGP (default_filename))
4360 { 4358 {
4361 Lisp_Object utf8 = ENCODE_UTF_8 (default_filename); 4359 Lisp_Object utf8 = ENCODE_UTF_8 (default_filename);
4362 char *begPtr = SDATA(utf8); 4360 char *begPtr = SDATA(utf8);
4363 char *filePtr = begPtr + SBYTES(utf8); 4361 char *filePtr = begPtr + SBYTES(utf8);
4364 while (filePtr != begPtr && !IS_DIRECTORY_SEP(filePtr[-1])) 4362 while (filePtr != begPtr && !IS_DIRECTORY_SEP(filePtr[-1]))
4379 mac_nav_event_callbackUPP, NULL, 4377 mac_nav_event_callbackUPP, NULL,
4380 NULL, NULL, &dialogRef); 4378 NULL, NULL, &dialogRef);
4381 } 4379 }
4382 4380
4383 /* Set the default location and continue*/ 4381 /* Set the default location and continue*/
4384 if (status == noErr) { 4382 if (status == noErr)
4385 if (!NILP(dir)) { 4383 {
4384 AEDesc defLocAed;
4385 #ifdef MAC_OSX
4386 FSRef defLoc; 4386 FSRef defLoc;
4387 AEDesc defLocAed;
4388 status = FSPathMakeRef(SDATA(ENCODE_FILE(dir)), &defLoc, NULL); 4387 status = FSPathMakeRef(SDATA(ENCODE_FILE(dir)), &defLoc, NULL);
4388 #else
4389 FSSpec defLoc;
4390 status = posix_pathname_to_fsspec (SDATA (ENCODE_FILE (dir)), &defLoc);
4391 #endif
4389 if (status == noErr) 4392 if (status == noErr)
4390 { 4393 {
4394 #ifdef MAC_OSX
4391 AECreateDesc(typeFSRef, &defLoc, sizeof(FSRef), &defLocAed); 4395 AECreateDesc(typeFSRef, &defLoc, sizeof(FSRef), &defLocAed);
4396 #else
4397 AECreateDesc(typeFSS, &defLoc, sizeof(FSSpec), &defLocAed);
4398 #endif
4392 NavCustomControl(dialogRef, kNavCtlSetLocation, (void*) &defLocAed); 4399 NavCustomControl(dialogRef, kNavCtlSetLocation, (void*) &defLocAed);
4393 AEDisposeDesc(&defLocAed); 4400 AEDisposeDesc(&defLocAed);
4394 } 4401 }
4402 status = NavDialogRun(dialogRef);
4395 } 4403 }
4396
4397 status = NavDialogRun(dialogRef);
4398 }
4399 4404
4400 if (saveName) CFRelease(saveName); 4405 if (saveName) CFRelease(saveName);
4401 if (message) CFRelease(message); 4406 if (message) CFRelease(message);
4402 4407
4403 if (status == noErr) { 4408 if (status == noErr) {
4411 case kNavUserActionChoose: 4416 case kNavUserActionChoose:
4412 case kNavUserActionSaveAs: 4417 case kNavUserActionSaveAs:
4413 { 4418 {
4414 NavReplyRecord reply; 4419 NavReplyRecord reply;
4415 AEDesc aed; 4420 AEDesc aed;
4421 #ifdef MAC_OSX
4416 FSRef fsRef; 4422 FSRef fsRef;
4423 #else
4424 FSSpec fs;
4425 #endif
4417 status = NavDialogGetReply(dialogRef, &reply); 4426 status = NavDialogGetReply(dialogRef, &reply);
4427
4428 #ifdef MAC_OSX
4418 AECoerceDesc(&reply.selection, typeFSRef, &aed); 4429 AECoerceDesc(&reply.selection, typeFSRef, &aed);
4419 AEGetDescData(&aed, (void *) &fsRef, sizeof (FSRef)); 4430 AEGetDescData(&aed, (void *) &fsRef, sizeof (FSRef));
4420 FSRefMakePath(&fsRef, (UInt8 *) filename, sizeof (filename)); 4431 FSRefMakePath(&fsRef, (UInt8 *) filename, sizeof (filename));
4432 #else
4433 AECoerceDesc (&reply.selection, typeFSS, &aed);
4434 AEGetDescData (&aed, (void *) &fs, sizeof (FSSpec));
4435 fsspec_to_posix_pathname (&fs, filename, sizeof (filename) - 1);
4436 #endif
4421 AEDisposeDesc(&aed); 4437 AEDisposeDesc(&aed);
4422 if (reply.saveFileName) 4438 if (reply.saveFileName)
4423 { 4439 {
4424 /* If it was a saved file, we need to add the file name */ 4440 /* If it was a saved file, we need to add the file name */
4425 int len = strlen(filename); 4441 int len = strlen(filename);