| version 1.1, 2004/08/10 14:38:57 | version 1.3, 2005/02/07 16:09:19 | 
| 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" | 
| Handle GetDlgItem(DialogPtr hWnd, short pos) { | #include        "resource.h" | 
|  |  | 
| Handle  ret; |  | 
| Rect    rct; |  | 
| short   s; |  | 
|  |  | 
| GetDialogItem(hWnd, pos, &s, &ret, &rct); |  | 
| return(ret); |  | 
| } |  | 
|  |  | 
 |  |  | 
 | // ---- file select | // ---- file select | 
 |  |  | 
| Line 68  static void fsspec2path(FSSpec *fs, char | Line 59  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 ) | 
| (void)sel; | { | 
| (void)prm; | case kNavCBCancel: | 
| (void)ud; | case kNavCBAccept: | 
|  | QuitAppModalLoopForWindow(prm->window); | 
|  | break; | 
|  | default: | 
|  | break; | 
|  | } | 
 | } | } | 
 |  |  | 
| BOOL dlgs_selectfile(char *name, int size) { | static pascal Boolean NavLaunchServicesFilterProc( AEDesc* theItem, void* info, NavCallBackUserData ioUserData, NavFilterModes filterMode) | 
|  | { | 
| BOOL                            ret; | #pragma unused( info ) | 
| OSErr                           err; | OSStatus        err                     = noErr; | 
| NavDialogOptions        opt; | Boolean         showItem        = false; | 
| NavReplyRecord          reply; | FSSpec              fsSpec; | 
| NavEventUPP                     proc; | int                 ret; | 
| long                            count; | char                name[MAX_PATH]; | 
| long                            i; | AEDesc          coerceDesc      = { NULL, NULL }; | 
| FSSpec                          fss; |  | 
|  | 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); | 
|  | if (ret == FTYPE_D88 || ret == FTYPE_BETA) { | 
|  | showItem = true; | 
|  | } | 
|  | } | 
|  | } | 
|  | } | 
|  | return( showItem ); | 
|  | } | 
|  |  | 
|  | BOOL dlgs_selectfile(char *name, int size, WindowRef parent) { | 
|  |  | 
|  | NavDialogRef                            navWin; | 
|  | BOOL                                            ret; | 
|  | OSErr                                           err; | 
|  | NavDialogCreationOptions    optNav; | 
|  | NavReplyRecord                          reply; | 
|  | NavEventUPP                                     proc; | 
|  | long                                            count; | 
|  | 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; | 
|  | } | 
 | 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,NULL,&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 163  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 FTYPE_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); | 
| fswf_exit: | NavDialogDispose(navWin); | 
| return(ret); | 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 ); | 
|  | } | 
|  |  | 
|  | void getFieldText(ControlRef cRef, char* buffer) { | 
|  | Size        size, outSize; | 
|  | GetControlDataSize(cRef, kControlNoPart, kControlStaticTextTextTag, &size); | 
|  | GetControlData(cRef, kControlNoPart, kControlStaticTextTextTag, size, buffer, &outSize); | 
|  | *(buffer+outSize)=NULL; | 
|  | } | 
|  |  | 
|  | ControlRef getControlRefByID(OSType sign, int id, WindowRef win) { | 
|  | ControlRef  conRef; | 
|  | ControlID   conID; | 
|  |  | 
|  | conID.signature=sign; | 
|  | conID.id=id; | 
|  | GetControlByID(win, &conID, &conRef); | 
|  | return conRef; | 
|  | } | 
|  |  | 
|  | UInt32 getFieldValue(OSType type, WindowRef win) { | 
|  | char    buffer[255]; | 
|  | char*   retPtr; | 
|  |  | 
|  | memset(buffer, NULL, sizeof(buffer)); | 
|  | getFieldText(getControlRefByID(type, 0, win), buffer); | 
|  | return strtoul(buffer, &retPtr, 10); | 
 | } | } | 
 |  |  | 
 | #else |  | 
 |  |  | 
 | BOOL dlgs_selectfile(char *name, int size) { |  | 
 |  |  | 
 | StandardFileReply       sfr; |  | 
 |  |  | 
 | 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 |  | 
 |  |  |