]>
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"
36 #include "wx/msw/private.h"
38 #if defined(__WIN95__) && \
39 (!defined(__GNUWIN32__) || defined(wxUSE_NORLANDER_HEADERS))
40 #define CAN_COMPILE_DIRDLG
41 //#else: we provide a stub version which doesn't do anything
44 #ifdef CAN_COMPILE_DIRDLG
45 #include "shlobj.h" // Win95 shell
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
53 #define MAX_PATH 4096 // be generuous
56 // ----------------------------------------------------------------------------
58 // ----------------------------------------------------------------------------
60 #if !USE_SHARED_LIBRARY
61 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
64 // ----------------------------------------------------------------------------
65 // private functions prototypes
66 // ----------------------------------------------------------------------------
69 static void ItemListFree(LPITEMIDLIST pidl
);
71 // the callback proc for the dir dlg
72 static int CALLBACK
BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
,
75 // ============================================================================
77 // ============================================================================
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
83 wxDirDialog::wxDirDialog(wxWindow
*parent
,
84 const wxString
& message
,
85 const wxString
& defaultPath
,
87 const wxPoint
& WXUNUSED(pos
))
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");