]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/dirdlg.cpp
Base for wxMessageDialog with common checks for style.
[wxWidgets.git] / src / mac / carbon / dirdlg.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: dirdlg.cpp
3// Purpose: wxDirDialog
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
3d1a4878 12#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
e9576ca5
SC
13#pragma implementation "dirdlg.h"
14#endif
15
3d1a4878
SC
16#include "wx/wxprec.h"
17
179e085f
RN
18#if wxUSE_DIRDLG
19
e9576ca5
SC
20#include "wx/utils.h"
21#include "wx/dialog.h"
22#include "wx/dirdlg.h"
23
24#include "wx/cmndata.h"
25
76a5e5d2
SC
26#include "wx/mac/private.h"
27
f5c6eb5c 28#ifdef __DARWIN__
5fde6fcc 29 #include <Carbon/Carbon.h>
03e11df5
GD
30#else
31 #include <Navigation.h>
32#endif
5b781a67 33
2f1ae414 34#if !USE_SHARED_LIBRARY
e9576ca5 35IMPLEMENT_CLASS(wxDirDialog, wxDialog)
2f1ae414 36#endif
519cb848 37
e78d4a23
VZ
38wxDirDialog::wxDirDialog(wxWindow *parent,
39 const wxString& message,
40 const wxString& defaultPath,
41 long style,
42 const wxPoint& WXUNUSED(pos),
43 const wxSize& WXUNUSED(size),
44 const wxString& WXUNUSED(name))
e9576ca5 45{
427ff662 46 wxASSERT_MSG( NavServicesAvailable() , wxT("Navigation Services are not running") ) ;
e9576ca5
SC
47 m_message = message;
48 m_dialogStyle = style;
49 m_parent = parent;
e40298d5 50 m_path = defaultPath;
e9576ca5
SC
51}
52
53int wxDirDialog::ShowModal()
54{
e40298d5
JS
55 NavDialogOptions mNavOptions;
56 NavObjectFilterUPP mNavFilterUPP = NULL;
57 NavPreviewUPP mNavPreviewUPP = NULL ;
58 NavReplyRecord mNavReply;
59 AEDesc* mDefaultLocation = NULL ;
60 bool mSelectDefault = false ;
61
62 ::NavGetDefaultDialogOptions(&mNavOptions);
76a5e5d2 63
e40298d5
JS
64 mNavFilterUPP = nil;
65 mNavPreviewUPP = nil;
66 mSelectDefault = false;
67 mNavReply.validRecord = false;
68 mNavReply.replacing = false;
69 mNavReply.isStationery = false;
70 mNavReply.translationNeeded = false;
71 mNavReply.selection.descriptorType = typeNull;
72 mNavReply.selection.dataHandle = nil;
73 mNavReply.keyScript = smSystemScript;
74 mNavReply.fileTranslation = nil;
75
76 // Set default location, the location
77 // that's displayed when the dialog
78 // first appears
79
80 if ( mDefaultLocation ) {
81
82 if (mSelectDefault) {
83 mNavOptions.dialogOptionFlags |= kNavSelectDefaultLocation;
84 } else {
85 mNavOptions.dialogOptionFlags &= ~kNavSelectDefaultLocation;
86 }
87 }
88
89 OSErr err = ::NavChooseFolder(
90 mDefaultLocation,
91 &mNavReply,
92 &mNavOptions,
93 NULL,
94 mNavFilterUPP,
95 0L); // User Data
96
97 if ( (err != noErr) && (err != userCanceledErr) ) {
427ff662 98 m_path = wxT("") ;
e40298d5
JS
99 return wxID_CANCEL ;
100 }
5b781a67 101
e40298d5
JS
102 if (mNavReply.validRecord) { // User chose a folder
103
a2b77260 104 FSRef folderInfo;
e40298d5
JS
105 AEDesc specDesc ;
106
a2b77260 107 OSErr err = ::AECoerceDesc( &mNavReply.selection , typeFSRef, &specDesc);
e40298d5 108 if ( err != noErr ) {
427ff662 109 m_path = wxT("") ;
e40298d5
JS
110 return wxID_CANCEL ;
111 }
a2b77260 112 folderInfo = **(FSRef**) specDesc.dataHandle;
e40298d5
JS
113 if (specDesc.dataHandle != nil) {
114 ::AEDisposeDesc(&specDesc);
115 }
76a5e5d2 116
a2b77260 117 m_path = wxMacFSRefToPath( &folderInfo ) ;
e40298d5
JS
118 return wxID_OK ;
119 }
120 return wxID_CANCEL;
e9576ca5
SC
121}
122
179e085f 123#endif