]>
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 #if !USE_SHARED_LIBRARY
62 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
65 // ----------------------------------------------------------------------------
66 // private functions prototypes
67 // ----------------------------------------------------------------------------
70 static void ItemListFree(LPITEMIDLIST pidl
);
72 // the callback proc for the dir dlg
73 static int CALLBACK
BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
,
76 // ============================================================================
78 // ============================================================================
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
84 wxDirDialog::wxDirDialog(wxWindow
*parent
,
85 const wxString
& message
,
86 const wxString
& defaultPath
,
88 const wxPoint
& WXUNUSED(pos
))
95 int wxDirDialog::ShowModal()
97 #ifdef CAN_COMPILE_DIRDLG
99 bi
.hwndOwner
= m_parent
? GetHwndOf(m_parent
) : NULL
;
101 bi
.pszDisplayName
= NULL
;
102 bi
.lpszTitle
= m_message
.c_str();
103 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_STATUSTEXT
;
104 bi
.lpfn
= BrowseCallbackProc
;
105 bi
.lParam
= (LPARAM
)m_path
.c_str(); // param for the callback
107 LPITEMIDLIST pidl
= SHBrowseForFolder(&bi
);
111 ItemListFree((LPITEMIDLIST
)bi
.pidlRoot
);
116 // Cancel button pressed
120 BOOL ok
= SHGetPathFromIDList(pidl
, m_path
.GetWriteBuf(MAX_PATH
));
121 m_path
.UngetWriteBuf();
127 wxLogLastError("SHGetPathFromIDList");
133 #else // !CAN_COMPILE_DIRDLG
135 #endif // CAN_COMPILE_DIRDLG/!CAN_COMPILE_DIRDLG
138 // ----------------------------------------------------------------------------
140 // ----------------------------------------------------------------------------
143 BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
, LPARAM pData
)
147 case BFFM_INITIALIZED
:
148 // sent immediately after initialisation and so we may set the
149 // initial selection here
151 // wParam = TRUE => lParam is a string and not a PIDL
152 SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, pData
);
155 case BFFM_SELCHANGED
:
157 // Set the status window to the currently selected path.
158 TCHAR szDir
[MAX_PATH
];
159 if ( SHGetPathFromIDList((LPITEMIDLIST
)lp
, szDir
) )
161 SendMessage(hwnd
, BFFM_SETSTATUSTEXT
, 0, (LPARAM
)szDir
);
166 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
167 // if the user types in invalid dir name
174 static void ItemListFree(LPITEMIDLIST pidl
)
179 SHGetMalloc(&pMalloc
);
187 wxLogLastError("SHGetMalloc");