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