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