1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/mac/carbon/dirdlg.cpp 
   3 // Purpose:     wxDirDialog 
   4 // Author:      Stefan Csomor 
   8 // Copyright:   (c) Stefan Csomor 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 #include "wx/wxprec.h" 
  16 #include "wx/dirdlg.h" 
  20     #include "wx/dialog.h" 
  21     #include "wx/cmndata.h" 
  24 #include "wx/filename.h" 
  26 #include "wx/mac/private.h" 
  29     #include <Carbon/Carbon.h> 
  31     #include <Navigation.h> 
  34 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
) 
  36 static pascal void NavEventProc( 
  37                                 NavEventCallbackMessage inSelector
, 
  39                                 NavCallBackUserData ioUserData 
); 
  41 static NavEventUPP sStandardNavEventFilter 
= NewNavEventUPP(NavEventProc
); 
  43 static pascal void NavEventProc( 
  44                                 NavEventCallbackMessage inSelector
, 
  46                                 NavCallBackUserData ioUserData 
) 
  48     wxDirDialog 
* data 
= ( wxDirDialog 
*) ioUserData 
; 
  49     if ( inSelector 
== kNavCBStart 
) 
  51         if (data 
&& !data
->GetPath().empty() ) 
  53             // Set default location for the modern Navigation APIs 
  54             // Apple Technical Q&A 1151 
  56             wxMacPathToFSRef(data
->GetPath(), &theFile
); 
  57             AEDesc theLocation 
= { typeNull
, NULL 
}; 
  58             if (noErr 
== ::AECreateDesc(typeFSRef
, &theFile
, sizeof(FSRef
), &theLocation
)) 
  59                  ::NavCustomControl(ioParams
->context
, kNavCtlSetLocation
, (void *) &theLocation
); 
  64 wxDirDialog::wxDirDialog(wxWindow 
*parent
, 
  65                          const wxString
& message
, 
  66                          const wxString
& defaultPath
, 
  68                          const wxPoint
& WXUNUSED(pos
), 
  69                          const wxSize
& WXUNUSED(size
), 
  70                          const wxString
& WXUNUSED(name
)) 
  72     wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ; 
  78 int wxDirDialog::ShowModal() 
  81     NavDialogCreationOptions options
; 
  82     NavReplyRecord reply 
; 
  83     bool disposeReply 
= false ; 
  86     err 
= NavGetDefaultDialogCreationOptions(&options
); 
  89         wxMacCFStringHolder 
message(m_message
, m_font
.GetEncoding()); 
  90         options
.message 
= message
; 
  91         err 
= NavCreateChooseFolderDialog(&options
, sStandardNavEventFilter 
, NULL
,  this , &dialog
); 
  94             err 
= NavDialogRun(dialog
); 
  97                 err 
= NavDialogGetReply(dialog
, &reply
); 
 105         if ( reply
.validRecord 
) 
 110             OSErr err 
= ::AECoerceDesc( &reply
.selection 
, typeFSRef
, &specDesc
); 
 113                 m_path 
= wxEmptyString 
; 
 117                 folderInfo 
= **(FSRef
**) specDesc
.dataHandle
; 
 118                 m_path 
= wxMacFSRefToPath( &folderInfo 
) ; 
 119                 if (specDesc
.dataHandle 
!= nil
) 
 121                     ::AEDisposeDesc(&specDesc
); 
 127             err 
= paramErr 
; // could be any error, only used for giving back wxID_CANCEL 
 132         ::NavDisposeReply(&reply
); 
 134     // apparently cancelling shouldn't change m_path 
 135     if ( err 
!= noErr 
&& err 
!= userCanceledErr 
) 
 136         m_path 
= wxEmptyString 
; 
 138     return (err 
== noErr
) ? wxID_OK 
: wxID_CANCEL 
;