]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dirdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDirDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #pragma implementation "dirdlg.h"
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
32 #include "wx/dialog.h"
33 #include "wx/dirdlg.h"
37 #include "wx/msw/private.h"
39 #if defined(__WIN95__) && \
40 (!defined(__GNUWIN32__) || defined(wxUSE_NORLANDER_HEADERS))
41 #define CAN_COMPILE_DIRDLG
42 //#else: we provide a stub version which doesn't do anything
45 #ifdef CAN_COMPILE_DIRDLG
46 #include "shlobj.h" // Win95 shell
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
54 #define MAX_PATH 4096 // be generuous
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
63 // ----------------------------------------------------------------------------
64 // private functions prototypes
65 // ----------------------------------------------------------------------------
68 static void ItemListFree(LPITEMIDLIST pidl
);
70 // the callback proc for the dir dlg
71 static int CALLBACK
BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
,
74 // ============================================================================
76 // ============================================================================
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 wxDirDialog::wxDirDialog(wxWindow
*parent
,
83 const wxString
& message
,
84 const wxString
& defaultPath
,
86 const wxPoint
& WXUNUSED(pos
))
91 m_path
.Replace(_T("/"), _T("\\")); // SHBrowseForFolder doesn't like '/'s
94 int wxDirDialog::ShowModal()
96 #ifdef CAN_COMPILE_DIRDLG
98 bi
.hwndOwner
= m_parent
? GetHwndOf(m_parent
) : NULL
;
100 bi
.pszDisplayName
= NULL
;
101 bi
.lpszTitle
= m_message
.c_str();
102 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_STATUSTEXT
;
103 bi
.lpfn
= BrowseCallbackProc
;
104 bi
.lParam
= (LPARAM
)m_path
.c_str(); // param for the callback
106 LPITEMIDLIST pidl
= SHBrowseForFolder(&bi
);
110 ItemListFree((LPITEMIDLIST
)bi
.pidlRoot
);
115 // Cancel button pressed
119 BOOL ok
= SHGetPathFromIDList(pidl
, m_path
.GetWriteBuf(MAX_PATH
));
120 m_path
.UngetWriteBuf();
126 wxLogLastError("SHGetPathFromIDList");
132 #else // !CAN_COMPILE_DIRDLG
134 #endif // CAN_COMPILE_DIRDLG/!CAN_COMPILE_DIRDLG
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
142 BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
, LPARAM pData
)
146 case BFFM_INITIALIZED
:
147 // sent immediately after initialisation and so we may set the
148 // initial selection here
150 // wParam = TRUE => lParam is a string and not a PIDL
151 SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, pData
);
154 case BFFM_SELCHANGED
:
156 // Set the status window to the currently selected path.
157 TCHAR szDir
[MAX_PATH
];
158 if ( SHGetPathFromIDList((LPITEMIDLIST
)lp
, szDir
) )
160 SendMessage(hwnd
, BFFM_SETSTATUSTEXT
, 0, (LPARAM
)szDir
);
165 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
166 // if the user types in invalid dir name
173 static void ItemListFree(LPITEMIDLIST pidl
)
178 SHGetMalloc(&pMalloc
);
186 wxLogLastError("SHGetMalloc");