]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dirdlg.cpp
adding alpha to wxColour
[wxWidgets.git] / src / mac / carbon / dirdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/dirdlg.cpp
3 // Purpose: wxDirDialog
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #if wxUSE_DIRDLG
15
16 #include "wx/dirdlg.h"
17
18 #ifndef WX_PRECOMP
19 #include "wx/utils.h"
20 #include "wx/dialog.h"
21 #include "wx/cmndata.h"
22 #endif // WX_PRECOMP
23
24 #include "wx/filename.h"
25
26 #include "wx/mac/private.h"
27
28 #ifdef __DARWIN__
29 #include <Carbon/Carbon.h>
30 #else
31 #include <Navigation.h>
32 #endif
33
34 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
35
36 static pascal void NavEventProc(
37 NavEventCallbackMessage inSelector,
38 NavCBRecPtr ioParams,
39 NavCallBackUserData ioUserData );
40
41 static NavEventUPP sStandardNavEventFilter = NewNavEventUPP(NavEventProc);
42
43 static pascal void NavEventProc(
44 NavEventCallbackMessage inSelector,
45 NavCBRecPtr ioParams,
46 NavCallBackUserData ioUserData )
47 {
48 wxDirDialog * data = ( wxDirDialog *) ioUserData ;
49 if ( inSelector == kNavCBStart )
50 {
51 if (data && !data->GetPath().empty() )
52 {
53 // Set default location for the modern Navigation APIs
54 // Apple Technical Q&A 1151
55 FSSpec theFSSpec;
56 wxMacFilename2FSSpec(data->GetPath(), &theFSSpec);
57 AEDesc theLocation = { typeNull, NULL };
58 if (noErr == ::AECreateDesc(typeFSS, &theFSSpec, sizeof(FSSpec), &theLocation))
59 ::NavCustomControl(ioParams->context, kNavCtlSetLocation, (void *) &theLocation);
60 }
61 }
62 }
63
64 wxDirDialog::wxDirDialog(wxWindow *parent,
65 const wxString& message,
66 const wxString& defaultPath,
67 long style,
68 const wxPoint& WXUNUSED(pos),
69 const wxSize& WXUNUSED(size),
70 const wxString& WXUNUSED(name))
71 {
72 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
73 m_message = message;
74 m_parent = parent;
75 m_path = defaultPath;
76 }
77
78 int wxDirDialog::ShowModal()
79 {
80 NavDialogRef dialog;
81 NavDialogCreationOptions options;
82 NavReplyRecord reply ;
83 bool disposeReply = false ;
84 OSStatus err = noErr;
85
86 err = NavGetDefaultDialogCreationOptions(&options);
87 if (err == noErr)
88 {
89 wxMacCFStringHolder message(m_message, m_font.GetEncoding());
90 options.message = message;
91 err = NavCreateChooseFolderDialog(&options, sStandardNavEventFilter , NULL, this , &dialog);
92 if (err == noErr)
93 {
94 err = NavDialogRun(dialog);
95 if ( err == noErr )
96 {
97 err = NavDialogGetReply(dialog, &reply);
98 disposeReply = true ;
99 }
100 }
101 }
102
103 if ( err == noErr )
104 {
105 if ( reply.validRecord )
106 {
107 FSRef folderInfo;
108 AEDesc specDesc ;
109
110 OSErr err = ::AECoerceDesc( &reply.selection , typeFSRef, &specDesc);
111 if ( err != noErr )
112 {
113 m_path = wxEmptyString ;
114 }
115 else
116 {
117 folderInfo = **(FSRef**) specDesc.dataHandle;
118 m_path = wxMacFSRefToPath( &folderInfo ) ;
119 if (specDesc.dataHandle != nil)
120 {
121 ::AEDisposeDesc(&specDesc);
122 }
123 }
124 }
125 else
126 {
127 err = paramErr ; // could be any error, only used for giving back wxID_CANCEL
128 }
129 }
130
131 if ( disposeReply )
132 ::NavDisposeReply(&reply);
133
134 // apparently cancelling shouldn't change m_path
135 if ( err != noErr && err != userCanceledErr )
136 m_path = wxEmptyString ;
137
138 return (err == noErr) ? wxID_OK : wxID_CANCEL ;
139 }
140
141 #endif