|
|
| version 1.1, 2004/08/10 14:38:57 | version 1.2, 2004/08/15 11:00:52 |
|---|---|
| Line 1 | Line 1 |
| #include "compiler.h" | #include "compiler.h" |
| #include "strres.h" | #include "strres.h" |
| #include "dialogs.h" | #include "dialogs.h" |
| #include "dosio.h" | |
| #include "fdefine.h" | |
| #include "resource.h" | |
| Handle GetDlgItem(DialogPtr hWnd, short pos) { | Handle GetDlgItem(DialogPtr hWnd, short pos) { |
| Line 68 static void fsspec2path(FSSpec *fs, char | Line 71 static void fsspec2path(FSSpec *fs, char |
| } while(cipbr.dirInfo.ioDrDirID != fsRtDirID); | } while(cipbr.dirInfo.ioDrDirID != fsRtDirID); |
| } | } |
| #if TARGET_API_MAC_CARBON | |
| static pascal void dummyproc(NavEventCallbackMessage sel, NavCBRecPtr prm, | static pascal void dummyproc(NavEventCallbackMessage sel, NavCBRecPtr prm, |
| NavCallBackUserData ud) { | NavCallBackUserData ud) { |
| switch( sel ) | |
| { | |
| case kNavCBCancel: | |
| case kNavCBAccept: | |
| QuitAppModalLoopForWindow(prm->window); | |
| break; | |
| default: | |
| break; | |
| } | |
| } | |
| (void)sel; | static pascal Boolean NavLaunchServicesFilterProc( AEDesc* theItem, void* info, NavCallBackUserData ioUserData, NavFilterModes filterMode) |
| (void)prm; | { |
| (void)ud; | #pragma unused( info ) |
| OSStatus err = noErr; | |
| Boolean showItem = false; | |
| FSSpec fsSpec; | |
| int ret; | |
| char name[MAX_PATH]; | |
| AEDesc coerceDesc = { NULL, NULL }; | |
| 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) { | |
| showItem = true; | |
| } | |
| break; | |
| default: | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| return( showItem ); | |
| } | } |
| BOOL dlgs_selectfile(char *name, int size) { | BOOL dlgs_selectfile(char *name, int size, WindowRef parent, int opentype) { |
| BOOL ret; | NavDialogRef navWin; |
| OSErr err; | BOOL ret; |
| NavDialogOptions opt; | OSErr err; |
| NavReplyRecord reply; | NavDialogCreationOptions optNav; |
| NavEventUPP proc; | NavReplyRecord reply; |
| long count; | NavEventUPP proc; |
| long i; | long count; |
| FSSpec fss; | long i; |
| FSSpec fss; | |
| NavObjectFilterUPP navFilterProc; | |
| ret = FALSE; | ret = FALSE; |
| err = NavGetDefaultDialogOptions(&opt); | err = NavGetDefaultDialogCreationOptions(&optNav); |
| if (err != noErr) { | if (err != noErr) { |
| goto fsel_exit; | goto fsel_exit; |
| } | } |
| opt.dialogOptionFlags &= ~kNavAllowPreviews; | optNav.clientName = CFSTR("X millennium"); |
| opt.dialogOptionFlags &= ~kNavAllowMultipleFiles; | if (parent) { |
| optNav.modality=kWindowModalityWindowModal; | |
| optNav.parentWindow=parent; | |
| } | |
| switch (opentype) { | |
| case OPEN_FONT: | |
| optNav.message = CFCopyLocalizedString(CFSTR("Choose font file."),"FontSelect Message"); | |
| break; | |
| default: | |
| break; | |
| } | |
| proc = NewNavEventUPP(dummyproc); | proc = NewNavEventUPP(dummyproc); |
| err = NavGetFile(NULL, &reply, &opt, proc, NULL, NULL, NULL, NULL); | 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); | DisposeNavEventUPP(proc); |
| DisableAllMenuItems(GetMenuHandle(IDM_EDIT)); | |
| if ((!reply.validRecord) && (ret != noErr)) { | if ((!reply.validRecord) && (ret != noErr)) { |
| goto fsel_exit; | goto fsel_exit; |
| } | } |
| Line 119 fsel_exit: | Line 188 fsel_exit: |
| return(ret); | return(ret); |
| } | } |
| BOOL dlgs_selectwritefile(char *name, int size, const char *def) { | BOOL dlgs_selectwritefile(char *name, int size, const char *def, OSType type, WindowRef parentWindow) { |
| OSType sign='XMil'; | |
| BOOL ret; | NavEventUPP eventUPP; |
| OSErr err; | |
| NavDialogOptions opt; | |
| NavReplyRecord reply; | NavReplyRecord reply; |
| NavEventUPP proc; | DescType rtype; |
| long count; | OSErr ret; |
| long i; | AEKeyword key; |
| FSSpec fss; | Size len; |
| FSRef parent; | |
| ret = FALSE; | UniCharCount ulen; |
| err = NavGetDefaultDialogOptions(&opt); | UniChar* buffer = NULL; |
| if (err != noErr) { | NavDialogRef navWin; |
| goto fswf_exit; | FSSpec fsc; |
| } | NavDialogCreationOptions copt; |
| opt.dialogOptionFlags |= kNavNoTypePopup; | |
| mkstr255(opt.savedFileName, def); | InitCursor(); |
| proc = NewNavEventUPP(dummyproc); | NavGetDefaultDialogCreationOptions(&copt); |
| err = NavPutFile(NULL, &reply, &opt, proc, '????', '????', NULL); | copt.clientName = CFSTR("X millennium"); |
| DisposeNavEventUPP(proc); | copt.parentWindow = parentWindow; |
| if ((!reply.validRecord) && (ret != noErr)) { | copt.saveFileName = CFStringCreateWithCString(NULL, def, CFStringGetSystemEncoding()); |
| goto fswf_exit; | copt.optionFlags += kNavPreserveSaveFileExtension; |
| } | copt.modality = kWindowModalityWindowModal; |
| err = AECountItems(&reply.selection, &count); | switch (type) { |
| if (err == noErr) { | case 'BMP ': |
| for (i=1; i<= count; i++) { | copt.message = CFCopyLocalizedString(CFSTR("Save the screen as BMP file."),"ScreenShot Message"); |
| err = AEGetNthPtr(&reply.selection, i, typeFSS, NULL, NULL, | break; |
| &fss, sizeof(fss), NULL); | default: |
| if (err == noErr) { | break; |
| fsspec2path(&fss, name, size); | } |
| ret = TRUE; | eventUPP=NewNavEventUPP( dummyproc ); |
| break; | NavCreatePutFileDialog(&copt, type, sign, eventUPP, NULL, &navWin); |
| } | |
| } | NavDialogRun(navWin); |
| err = NavDisposeReply(&reply); | RunAppModalLoopForWindow(NavDialogGetWindow(navWin)); |
| NavDialogGetReply(navWin, &reply); | |
| NavDialogDispose(navWin); | |
| DisposeNavEventUPP(eventUPP); | |
| 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) { | |
| fsspec2path(&fsc, name, size); | |
| return true; | |
| } | |
| } | } |
| return( false ); | |
| fswf_exit: | |
| return(ret); | |
| } | } |
| #else | void getFieldText(ControlRef cRef, char* buffer) { |
| Size size, outSize; | |
| BOOL dlgs_selectfile(char *name, int size) { | GetControlDataSize(cRef, kControlNoPart, kControlStaticTextTextTag, &size); |
| GetControlData(cRef, kControlNoPart, kControlStaticTextTextTag, size, buffer, &outSize); | |
| StandardFileReply sfr; | *(buffer+outSize)=NULL; |
| StandardGetFile(NULL, -1, NULL, &sfr); | |
| if (sfr.sfGood) { | |
| fsspec2path(&sfr.sfFile, name, size); | |
| return(TRUE); | |
| } | |
| else { | |
| return(FALSE); | |
| } | |
| } | |
| BOOL dlgs_selectwritefile(char *name, int size, const char *def) { | |
| Str255 defname; | |
| StandardFileReply sfr; | |
| mkstr255(defname, def); | |
| StandardPutFile(NULL, defname, &sfr); | |
| if (sfr.sfGood) { | |
| fsspec2path(&sfr.sfFile, name, size); | |
| return(TRUE); | |
| } | |
| else { | |
| return(FALSE); | |
| } | |
| } | } |
| #endif | ControlRef getControlRefByID(OSType sign, int id, WindowRef win) { |
| ControlRef conRef; | |
| ControlID conID; | |
| conID.signature=sign; | |
| conID.id=id; | |
| GetControlByID(win, &conID, &conRef); | |
| return conRef; | |
| } |