1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/classic/dirdlg.cpp 
   3 // Purpose:     wxDirDialog 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  18 #include "wx/dirdlg.h" 
  22     #include "wx/dialog.h" 
  23     #include "wx/cmndata.h" 
  26 #include "wx/mac/private.h" 
  29   #include <Carbon/Carbon.h> 
  31   #include <Navigation.h> 
  34 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
) 
  36 wxDirDialog::wxDirDialog(wxWindow 
*parent
, 
  37                          const wxString
& message
, 
  38                          const wxString
& defaultPath
, 
  40                          const wxPoint
& WXUNUSED(pos
), 
  41                          const wxSize
& WXUNUSED(size
), 
  42                          const wxString
& WXUNUSED(name
)) 
  44     wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ; 
  46     m_windowStyle 
= style
; 
  51 int wxDirDialog::ShowModal() 
  53     NavDialogOptions        mNavOptions
; 
  54     NavObjectFilterUPP        mNavFilterUPP 
= NULL
; 
  55     NavPreviewUPP            mNavPreviewUPP 
= NULL 
; 
  56     NavReplyRecord            mNavReply
; 
  57     AEDesc
*                    mDefaultLocation 
= NULL 
; 
  58     bool                    mSelectDefault 
= false ; 
  60     ::NavGetDefaultDialogOptions(&mNavOptions
); 
  64     mSelectDefault    
= false; 
  65     mNavReply
.validRecord                
= false; 
  66     mNavReply
.replacing                    
= false; 
  67     mNavReply
.isStationery                
= false; 
  68     mNavReply
.translationNeeded            
= false; 
  69     mNavReply
.selection
.descriptorType 
= typeNull
; 
  70     mNavReply
.selection
.dataHandle        
= nil
; 
  71     mNavReply
.keyScript                    
= smSystemScript
; 
  72     mNavReply
.fileTranslation            
= nil
; 
  74     // Set default location, the location 
  75     //   that's displayed when the dialog 
  78     if ( mDefaultLocation 
) { 
  81             mNavOptions
.dialogOptionFlags 
|= kNavSelectDefaultLocation
; 
  83             mNavOptions
.dialogOptionFlags 
&= ~kNavSelectDefaultLocation
; 
  87     OSErr err 
= ::NavChooseFolder( 
  95     if ( (err 
!= noErr
) && (err 
!= userCanceledErr
) ) { 
  96         m_path 
= wxEmptyString 
; 
 100     if (mNavReply
.validRecord
) {        // User chose a folder 
 106         OSErr err 
= ::AECoerceDesc( &mNavReply
.selection 
, typeFSS
, &specDesc
); 
 107         if ( err 
!= noErr 
) { 
 108             m_path 
= wxEmptyString 
; 
 111         folderInfo 
= **(FSSpec
**) specDesc
.dataHandle
; 
 112         if (specDesc
.dataHandle 
!= nil
) { 
 113             ::AEDisposeDesc(&specDesc
); 
 116 //            mNavReply.GetFileSpec(folderInfo); 
 118             // The FSSpec from NavChooseFolder is NOT the file spec 
 119             // for the folder. The parID field is actually the DirID 
 120             // of the folder itself, not the folder's parent, and 
 121             // the name field is empty. We must call PBGetCatInfo 
 122             // to get the parent DirID and folder name 
 125         CInfoPBRec    thePB
;            // Directory Info Parameter Block 
 126         thePB
.dirInfo
.ioCompletion    
= nil
; 
 127         thePB
.dirInfo
.ioVRefNum        
= folderInfo
.vRefNum
;    // Volume is right 
 128         thePB
.dirInfo
.ioDrDirID        
= folderInfo
.parID
;        // Folder's DirID 
 129         thePB
.dirInfo
.ioNamePtr        
= name
; 
 130         thePB
.dirInfo
.ioFDirIndex    
= -1;    // Lookup using Volume and DirID 
 132         err 
= ::PBGetCatInfoSync(&thePB
); 
 133         if ( err 
!= noErr 
) { 
 134             m_path 
= wxEmptyString
; 
 137                                             // Create cannonical FSSpec 
 138         ::FSMakeFSSpec(thePB
.dirInfo
.ioVRefNum
, thePB
.dirInfo
.ioDrParID
, 
 141         // outFolderDirID = thePB.dirInfo.ioDrDirID; 
 142         m_path 
= wxMacFSSpec2MacFilename( &outFileSpec 
) ;