]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dirdlg.cpp | |
3 | // Purpose: wxDirDialog | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3f2711d5 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
1e6feb95 | 19 | |
2bda0e17 KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
3f2711d5 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
bcfced36 | 27 | #if wxUSE_DIRDLG && (!defined(__WXWINCE__) || defined(__HANDHELDPC__)) |
1e6feb95 | 28 | |
7fc0bd1c | 29 | #if defined(__WIN95__) && !defined(__GNUWIN32_OLD__) && wxUSE_OLE |
54744d3a | 30 | |
2bda0e17 | 31 | #ifndef WX_PRECOMP |
3f2711d5 VZ |
32 | #include "wx/utils.h" |
33 | #include "wx/dialog.h" | |
34 | #include "wx/dirdlg.h" | |
77902671 | 35 | #include "wx/log.h" |
15ad98b7 | 36 | #include "wx/app.h" // for GetComCtl32Version() |
2bda0e17 KB |
37 | #endif |
38 | ||
3f2711d5 | 39 | #include "wx/msw/private.h" |
6bb09706 | 40 | #include "wx/msw/wrapshl.h" |
2bda0e17 | 41 | |
3f2711d5 VZ |
42 | // ---------------------------------------------------------------------------- |
43 | // constants | |
44 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 45 | |
cf54972e VZ |
46 | #ifndef BIF_NEWDIALOGSTYLE |
47 | #define BIF_NEWDIALOGSTYLE 0x0040 | |
48 | #endif | |
49 | ||
50 | #ifndef BIF_NONEWFOLDERBUTTON | |
51 | #define BIF_NONEWFOLDERBUTTON 0x0200 | |
52 | #endif | |
53 | ||
94311eef MB |
54 | #ifndef BIF_EDITBOX |
55 | #define BIF_EDITBOX 16 | |
56 | #endif | |
57 | ||
3f2711d5 | 58 | // ---------------------------------------------------------------------------- |
77ffb593 | 59 | // wxWidgets macros |
3f2711d5 | 60 | // ---------------------------------------------------------------------------- |
2bda0e17 | 61 | |
54744d3a | 62 | IMPLEMENT_CLASS(wxDirDialog, wxDialog) |
2bda0e17 | 63 | |
3f2711d5 VZ |
64 | // ---------------------------------------------------------------------------- |
65 | // private functions prototypes | |
66 | // ---------------------------------------------------------------------------- | |
67 | ||
3f2711d5 VZ |
68 | // the callback proc for the dir dlg |
69 | static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, | |
70 | LPARAM pData); | |
bfa2e032 | 71 | |
54744d3a | 72 | |
3f2711d5 VZ |
73 | // ============================================================================ |
74 | // implementation | |
75 | // ============================================================================ | |
bfa2e032 | 76 | |
3f2711d5 VZ |
77 | // ---------------------------------------------------------------------------- |
78 | // wxDirDialog | |
79 | // ---------------------------------------------------------------------------- | |
80 | ||
81 | wxDirDialog::wxDirDialog(wxWindow *parent, | |
82 | const wxString& message, | |
83 | const wxString& defaultPath, | |
90a6f1cc | 84 | long style, |
e78d4a23 VZ |
85 | const wxPoint& WXUNUSED(pos), |
86 | const wxSize& WXUNUSED(size), | |
87 | const wxString& WXUNUSED(name)) | |
2bda0e17 KB |
88 | { |
89 | m_message = message; | |
2bda0e17 | 90 | m_parent = parent; |
90a6f1cc RD |
91 | |
92 | SetStyle(style); | |
f3558acc VZ |
93 | SetPath(defaultPath); |
94 | } | |
95 | ||
96 | void wxDirDialog::SetPath(const wxString& path) | |
97 | { | |
98 | m_path = path; | |
e7b0dcd9 VZ |
99 | |
100 | // SHBrowseForFolder doesn't like '/'s nor the trailing backslashes | |
101 | m_path.Replace(_T("/"), _T("\\")); | |
f3558acc | 102 | if ( !m_path.empty() ) |
e7b0dcd9 | 103 | { |
f3558acc VZ |
104 | while ( *(m_path.end() - 1) == _T('\\') ) |
105 | { | |
da03e330 VZ |
106 | m_path.erase(m_path.length() - 1); |
107 | } | |
108 | ||
109 | // but the root drive should have a trailing slash (again, this is just | |
110 | // the way the native dialog works) | |
111 | if ( *(m_path.end() - 1) == _T(':') ) | |
112 | { | |
113 | m_path += _T('\\'); | |
f3558acc | 114 | } |
e7b0dcd9 | 115 | } |
2bda0e17 KB |
116 | } |
117 | ||
3f2711d5 | 118 | int wxDirDialog::ShowModal() |
2bda0e17 | 119 | { |
f3558acc VZ |
120 | wxWindow *parent = GetParent(); |
121 | ||
2bda0e17 | 122 | BROWSEINFO bi; |
f3558acc | 123 | bi.hwndOwner = parent ? GetHwndOf(parent) : NULL; |
3f2711d5 VZ |
124 | bi.pidlRoot = NULL; |
125 | bi.pszDisplayName = NULL; | |
58e0338a JS |
126 | // Please don't change this without checking it compiles |
127 | // with eVC++ first. | |
128 | #if defined(__POCKETPC__) || defined(__SMARTPHONE__) | |
129 | bi.lpszTitle = m_message.mb_str(); | |
130 | #else | |
3f2711d5 | 131 | bi.lpszTitle = m_message.c_str(); |
58e0338a | 132 | #endif |
3f2711d5 VZ |
133 | bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT; |
134 | bi.lpfn = BrowseCallbackProc; | |
135 | bi.lParam = (LPARAM)m_path.c_str(); // param for the callback | |
136 | ||
cf54972e VZ |
137 | static const int verComCtl32 = wxApp::GetComCtl32Version(); |
138 | ||
139 | // we always add the edit box (it doesn't hurt anybody, does it?) if it is | |
140 | // supported by the system | |
141 | if ( verComCtl32 >= 471 ) | |
142 | { | |
143 | bi.ulFlags |= BIF_EDITBOX; | |
144 | } | |
145 | ||
cf54972e VZ |
146 | // to have the "New Folder" button we must use the "new" dialog style which |
147 | // is also the only way to have a resizable dialog | |
148 | // | |
149 | // "new" style is only available in the version 5.0+ of comctl32.dll | |
150 | const bool needNewDir = HasFlag(wxDD_NEW_DIR_BUTTON); | |
151 | if ( (needNewDir || HasFlag(wxRESIZE_BORDER)) && (verComCtl32 >= 500) ) | |
152 | { | |
03776753 JS |
153 | if (needNewDir) |
154 | { | |
155 | bi.ulFlags |= BIF_NEWDIALOGSTYLE; | |
156 | } | |
157 | else | |
158 | { | |
159 | // Versions < 600 doesn't support BIF_NONEWFOLDERBUTTON | |
160 | // The only way to get rid of the Make New Folder button is use | |
161 | // the old dialog style which doesn't have the button thus we | |
162 | // simply don't set the New Dialog Style for such comctl versions. | |
163 | if (verComCtl32 >= 600) | |
164 | { | |
165 | bi.ulFlags |= BIF_NEWDIALOGSTYLE; | |
166 | bi.ulFlags |= BIF_NONEWFOLDERBUTTON; | |
167 | } | |
168 | } | |
90a6f1cc RD |
169 | } |
170 | ||
cf54972e | 171 | // do show the dialog |
6bb09706 | 172 | wxItemIdList pidl(SHBrowseForFolder(&bi)); |
3f2711d5 | 173 | |
6bb09706 | 174 | wxItemIdList::Free((LPITEMIDLIST)bi.pidlRoot); |
3f2711d5 VZ |
175 | |
176 | if ( !pidl ) | |
2bda0e17 | 177 | { |
3f2711d5 | 178 | // Cancel button pressed |
2bda0e17 KB |
179 | return wxID_CANCEL; |
180 | } | |
181 | ||
6bb09706 | 182 | m_path = pidl.GetPath(); |
3f2711d5 | 183 | |
6bb09706 | 184 | return m_path.empty() ? wxID_CANCEL : wxID_OK; |
3f2711d5 VZ |
185 | } |
186 | ||
187 | // ---------------------------------------------------------------------------- | |
188 | // private functions | |
189 | // ---------------------------------------------------------------------------- | |
190 | ||
191 | static int CALLBACK | |
192 | BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) | |
193 | { | |
194 | switch(uMsg) | |
195 | { | |
6bb09706 | 196 | #ifdef BFFM_SETSELECTION |
3f2711d5 VZ |
197 | case BFFM_INITIALIZED: |
198 | // sent immediately after initialisation and so we may set the | |
199 | // initial selection here | |
200 | // | |
201 | // wParam = TRUE => lParam is a string and not a PIDL | |
d71cc120 | 202 | ::SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData); |
3f2711d5 | 203 | break; |
6bb09706 VZ |
204 | #endif // BFFM_SETSELECTION |
205 | ||
3f2711d5 VZ |
206 | |
207 | case BFFM_SELCHANGED: | |
cf54972e VZ |
208 | // note that this doesn't work with the new style UI (MSDN doesn't |
209 | // say anything about it, but the comments in shlobj.h do!) but we | |
210 | // still execute this code in case it starts working again with the | |
211 | // "new new UI" (or would it be "NewUIEx" according to tradition?) | |
3f2711d5 VZ |
212 | { |
213 | // Set the status window to the currently selected path. | |
cf54972e VZ |
214 | wxString strDir; |
215 | if ( SHGetPathFromIDList((LPITEMIDLIST)lp, | |
216 | wxStringBuffer(strDir, MAX_PATH)) ) | |
3f2711d5 | 217 | { |
cf54972e VZ |
218 | // NB: this shouldn't be necessary with the new style box |
219 | // (which is resizable), but as for now it doesn't work | |
220 | // anyhow (see the comment above) no harm in doing it | |
221 | ||
222 | // need to truncate or it displays incorrectly | |
223 | static const size_t maxChars = 37; | |
224 | if ( strDir.length() > maxChars ) | |
6a097cd6 | 225 | { |
cf54972e | 226 | strDir = strDir.Right(maxChars); |
6a097cd6 JS |
227 | strDir = wxString(wxT("...")) + strDir; |
228 | } | |
cf54972e VZ |
229 | |
230 | SendMessage(hwnd, BFFM_SETSTATUSTEXT, | |
231 | 0, (LPARAM)strDir.c_str()); | |
3f2711d5 VZ |
232 | } |
233 | } | |
234 | break; | |
235 | ||
236 | //case BFFM_VALIDATEFAILED: -- might be used to provide custom message | |
237 | // if the user types in invalid dir name | |
238 | } | |
239 | ||
240 | return 0; | |
241 | } | |
242 | ||
243 | ||
54744d3a VZ |
244 | #else |
245 | #include "../generic/dirdlgg.cpp" | |
246 | #endif // compiler/platform on which the code here compiles | |
1e6feb95 | 247 | |
3180bc0e | 248 | #endif // wxUSE_DIRDLG && !(__SMARTPHONE__ && __WXWINCE__) |