--- np2/macosx/dialog/dialog.cpp 2003/10/31 16:55:06 1.1 +++ np2/macosx/dialog/dialog.cpp 2005/05/20 17:25:03 1.10 @@ -1,13 +1,9 @@ #include "compiler.h" #include "resource.h" #include "sysmng.h" -#include "dialog.h" #include "pccore.h" -#include "fddfile.h" +#include "dialog.h" #include "diskdrv.h" -#if 0 -#include "newdisk.h" -#endif #include "font.h" #include "iocore.h" #include "np2.h" @@ -16,44 +12,8 @@ #include "dosio.h" #include "menu.h" #include "s98.h" - -static Handle GetDlgItem(DialogPtr hWnd, short pos) { - - Handle ret; - Rect rct; - short s; - - GetDialogItem(hWnd, pos, &s, &ret, &rct); - return(ret); -} - -void AboutDialogProc(void) { - - DialogPtr hDlg; - Str255 verstr; - int done; - short item; - - hDlg = GetNewDialog(IDD_ABOUT, NULL, (WindowPtr)-1); - if (!hDlg) { - return; - } - mkstr255(verstr, np2version); - SetDialogItemText(GetDlgItem(hDlg, IDD_VERSION), verstr); - SetDialogDefaultItem(hDlg, IDOK); - - done = 0; - while(!done) { - ModalDialog(NULL, &item); - switch(item) { - case IDOK: - done = 1; - break; - } - } - DisposeDialog(hDlg); -} - +#include "fdefine.h" +#include "toolwin.h" // ---- @@ -109,8 +69,8 @@ void fsspec2path(FSSpec *fs, char *dst, } while(cipbr.dirInfo.ioDrDirID != fsRtDirID); } -#if 1 static NavDialogRef navWin; + static pascal void dummyproc(NavEventCallbackMessage sel, NavCBRecPtr prm, NavCallBackUserData ud) { switch( sel ) @@ -128,7 +88,70 @@ static pascal void dummyproc(NavEventCal (void)ud; } -static BOOL dialog_fileselect(char *name, int size) { +static pascal Boolean NavLaunchServicesFilterProc( AEDesc* theItem, void* info, NavCallBackUserData ioUserData, NavFilterModes filterMode) +{ + #pragma unused( info ) + OSStatus err = noErr; + Boolean showItem = false; + FSSpec fsSpec; + int ret; + char name[MAX_PATH]; + AEDesc coerceDesc = { 0, 0 }; + + if ( filterMode == kNavFilteringBrowserList ) { + if ( theItem->descriptorType != typeFSS ) { + err = AECoerceDesc( theItem, typeFSS, &coerceDesc ); + theItem = &coerceDesc; + } + if ( err == noErr ) { + err = AEGetDescData( theItem, &fsSpec, sizeof(fsSpec) ); + } + AEDisposeDesc( &coerceDesc ); + + if (err == noErr) { + fsspec2path(&fsSpec, name, MAX_PATH); + if (file_attr(name) == FILEATTR_DIRECTORY) { + showItem = true; + } + else { + ret = file_getftype(name); + switch (*(int*)ioUserData) { + case OPEN_FDD: + if (ret == FTYPE_D88 || ret == FTYPE_BETA || ret == FTYPE_FDI) { + showItem = true; + } + break; + case OPEN_SASI: + if (ret == FTYPE_THD || ret == FTYPE_HDI || ret == FTYPE_NHD) { + showItem = true; + } + break; + case OPEN_SCSI: + if (ret == FTYPE_HDD) { + showItem = true; + } + break; + case OPEN_FONT: + if (ret == FTYPE_BMP || ret == FTYPE_SMIL) { + showItem = true; + } + break; + case OPEN_INI: + if (ret == FTYPE_INI) { + showItem = true; + } + break; + case OPEN_MIMPI: + showItem = true; + break; + } + } + } + } + return( showItem ); +} + +BOOL dialog_fileselect(char *name, int size, WindowRef parent, int opentype) { BOOL ret; OSErr err; @@ -138,17 +161,35 @@ static BOOL dialog_fileselect(char *name long count; long i; FSSpec fss; + NavObjectFilterUPP navFilterProc; ret = FALSE; NavGetDefaultDialogCreationOptions(&optNav); - optNav.modality=kWindowModalityWindowModal; - optNav.parentWindow=hWndMain; - optNav.optionFlags+=kNavNoTypePopup; + optNav.clientName = CFSTR("Neko Project IIx"); + if (parent) { + optNav.modality=kWindowModalityWindowModal; + optNav.parentWindow=parent; + } + switch (opentype) { + case OPEN_MIMPI: + optNav.message = CFCopyLocalizedString(CFSTR("Choose MIMPI file."),"MIMPI Message"); + break; + case OPEN_FONT: + optNav.message = CFCopyLocalizedString(CFSTR("Choose font file."),"FontSelect Message"); + break; + case OPEN_INI: + optNav.message = CFCopyLocalizedString(CFSTR("Choose a skin file for Tool Window."),"SkinSelect Message"); + break; + default: + break; + } proc = NewNavEventUPP(dummyproc); - ret=NavCreateChooseFileDialog(&optNav,NULL,proc,NULL,NULL,NULL,&navWin); + navFilterProc = NewNavObjectFilterUPP( NavLaunchServicesFilterProc ); + ret=NavCreateGetFileDialog(&optNav,NULL,proc,NULL,navFilterProc,&opentype,&navWin); NavDialogRun(navWin); RunAppModalLoopForWindow(NavDialogGetWindow(navWin)); NavDialogGetReply(navWin, &reply); + if (optNav.message) CFRelease(optNav.message); NavDialogDispose(navWin); DisposeNavEventUPP(proc); @@ -173,30 +214,79 @@ static BOOL dialog_fileselect(char *name fsel_exit: return(ret); } -#else -BOOL dialog_fileselect(char *name, int size) { - StandardFileReply sfr; +BOOL dialog_filewriteselect(OSType type, char *title, FSSpec *fsc, WindowRef parentWindow) +{ + OSType sign='SMil'; + NavEventUPP eventUPP; + NavReplyRecord reply; + DescType rtype; + OSErr ret; + AEKeyword key; + Size len; + FSRef parent; + UniCharCount ulen; + UniChar* buffer = NULL; + NavDialogCreationOptions copt; + + InitCursor(); + NavGetDefaultDialogCreationOptions(&copt); + copt.clientName = CFSTR("Neko Project IIx"); + copt.parentWindow = parentWindow; + copt.saveFileName = CFStringCreateWithCString(NULL, title, CFStringGetSystemEncoding()); + copt.optionFlags += kNavPreserveSaveFileExtension; + copt.modality = kWindowModalityWindowModal; + switch (type) { + case 'AIFF': + copt.message = CFCopyLocalizedString(CFSTR("Record playing sound as AIFF file."),"SoundRecord Message"); + break; + case 'BMP ': + copt.message = CFCopyLocalizedString(CFSTR("Save the screen as BMP file."),"ScreenShot Message"); + break; + case '.S98': + copt.message = CFCopyLocalizedString(CFSTR("Log playing sound as S98 file."),"S98Log Message"); + break; + default: + break; + } + eventUPP=NewNavEventUPP( dummyproc ); + NavCreatePutFileDialog(&copt, type, sign, eventUPP, NULL, &navWin); + + NavDialogRun(navWin); + RunAppModalLoopForWindow(NavDialogGetWindow(navWin)); + + NavDialogGetReply(navWin, &reply); + NavDialogDispose(navWin); + DisposeNavEventUPP(eventUPP); - StandardGetFile(NULL, -1, NULL, &sfr); - if (sfr.sfGood) { - fsspec2path(&sfr.sfFile, name, size); - return(TRUE); - } - else { - return(FALSE); + if( reply.validRecord) + { + ret=AEGetNthPtr( &(reply.selection),1,typeFSRef,&key,&rtype,(Ptr)&parent,(long)sizeof(FSRef),&len ); + ulen = (UniCharCount)CFStringGetLength(reply.saveFileName); + buffer = (UniChar*)NewPtr(ulen); + CFStringGetCharacters(reply.saveFileName, CFRangeMake(0, ulen), buffer); + ret = FSCreateFileUnicode(&parent, ulen, buffer, kFSCatInfoNone, NULL, NULL, fsc); + DisposePtr((Ptr)buffer); + NavDisposeReply( &reply ); + if (ret == noErr) { + return true; + } } + return( false ); } -#endif +// ---- void dialog_changefdd(BYTE drv) { char fname[MAX_PATH]; if (drv < 4) { - if (dialog_fileselect(fname, sizeof(fname))) { - diskdrv_setfdd(drv, fname, 0); + if (dialog_fileselect(fname, sizeof(fname), hWndMain, OPEN_FDD)) { + if (file_getftype(fname)==FTYPE_D88 || file_getftype(fname)==FTYPE_BETA || file_getftype(fname)==FTYPE_FDI) { + diskdrv_setfdd(drv, fname, 0); + toolwin_setfdd(drv, fname); + } } } } @@ -205,9 +295,24 @@ void dialog_changehdd(BYTE drv) { char fname[MAX_PATH]; - if (drv < 2) { - if (dialog_fileselect(fname, sizeof(fname))) { - diskdrv_sethdd(drv, fname); + if (!(drv & 0x20)) { // SASI/IDE + if (drv < 2) { + if (dialog_fileselect(fname, sizeof(fname), hWndMain, OPEN_SASI)) { + if (file_getftype(fname)==FTYPE_HDI || file_getftype(fname)==FTYPE_THD || file_getftype(fname)==FTYPE_NHD) { + sysmng_update(SYS_UPDATEOSCFG); + diskdrv_sethdd(drv, fname); + } + } + } + } + else { // SCSI + if ((drv & 0x0f) < 4) { + if (dialog_fileselect(fname, sizeof(fname), hWndMain, OPEN_SCSI)) { + if (file_getftype(fname)==FTYPE_HDD) { + sysmng_update(SYS_UPDATEOSCFG); + diskdrv_sethdd(drv, fname); + } + } } } } @@ -217,7 +322,7 @@ void dialog_font(void) { char name[1024]; - if (dialog_fileselect(name, 1024)) { + if (dialog_fileselect(name, sizeof(name), hWndMain, OPEN_FONT)) { if ((name != NULL) && (font_load(name, FALSE))) { gdcs.textdisp |= GDCSCRN_ALLDRAW2; milstr_ncpy(np2cfg.fontfile, name, sizeof(np2cfg.fontfile)); @@ -235,7 +340,7 @@ void dialog_writebmp(void) { bmp = scrnbmp(); if (bmp) { - if (saveFile('BMP ', "np2.bmp", &fss)) { + if (dialog_filewriteselect('BMP ', "Neko Project IIx ScreenShot.bmp", &fss, hWndMain)) { fsspec2path(&fss, path, MAX_PATH); fh = file_create(path); if (fh != FILEH_INVALID) { @@ -258,7 +363,7 @@ void dialog_s98(void) { if (check) { check = FALSE; } - else if (saveFile('.S98', "S98 log.s98", &fsc)) { + else if (dialog_filewriteselect('.S98', "S98 log.s98", &fsc, hWndMain)) { fsspec2path(&fsc, fname, MAX_PATH); if (S98_open(fname) == SUCCESS) { check = TRUE;