]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dirdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/dirdlg.cpp
3 // Purpose: wxDirDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #if wxUSE_OLE && !defined(__GNUWIN32_OLD__) && (!defined(__WXWINCE__) || \
30 (defined(__HANDHELDPC__) && (_WIN32_WCE >= 500)))
32 #include "wx/dirdlg.h"
36 #include "wx/dialog.h"
38 #include "wx/app.h" // for GetComCtl32Version()
41 #include "wx/msw/private.h"
42 #include "wx/msw/wrapshl.h"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 #ifndef BIF_NEWDIALOGSTYLE
49 #define BIF_NEWDIALOGSTYLE 0x0040
52 #ifndef BIF_NONEWFOLDERBUTTON
53 #define BIF_NONEWFOLDERBUTTON 0x0200
57 #define BIF_EDITBOX 16
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
66 // ----------------------------------------------------------------------------
67 // private functions prototypes
68 // ----------------------------------------------------------------------------
70 // the callback proc for the dir dlg
71 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
),
88 const wxSize
& WXUNUSED(size
),
89 const wxString
& WXUNUSED(name
))
94 SetWindowStyle(style
);
98 void wxDirDialog::SetPath(const wxString
& path
)
102 // SHBrowseForFolder doesn't like '/'s nor the trailing backslashes
103 m_path
.Replace(_T("/"), _T("\\"));
104 if ( !m_path
.empty() )
106 while ( *(m_path
.end() - 1) == _T('\\') )
108 m_path
.erase(m_path
.length() - 1);
111 // but the root drive should have a trailing slash (again, this is just
112 // the way the native dialog works)
113 if ( *(m_path
.end() - 1) == _T(':') )
120 int wxDirDialog::ShowModal()
122 wxWindow
*parent
= GetParent();
125 bi
.hwndOwner
= parent
? GetHwndOf(parent
) : NULL
;
127 bi
.pszDisplayName
= NULL
;
128 // Please don't change this without checking it compiles
130 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
131 bi
.lpszTitle
= m_message
.mb_str();
133 bi
.lpszTitle
= m_message
.c_str();
135 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_STATUSTEXT
;
136 bi
.lpfn
= BrowseCallbackProc
;
137 bi
.lParam
= (LPARAM
)m_path
.c_str(); // param for the callback
139 static const int verComCtl32
= wxApp::GetComCtl32Version();
141 // we always add the edit box (it doesn't hurt anybody, does it?) if it is
142 // supported by the system
143 if ( verComCtl32
>= 471 )
145 bi
.ulFlags
|= BIF_EDITBOX
;
148 // to have the "New Folder" button we must use the "new" dialog style which
149 // is also the only way to have a resizable dialog
151 // "new" style is only available in the version 5.0+ of comctl32.dll
152 const bool needNewDir
= !HasFlag(wxDD_DIR_MUST_EXIST
);
153 if ( (needNewDir
|| HasFlag(wxRESIZE_BORDER
)) && (verComCtl32
>= 500) )
157 bi
.ulFlags
|= BIF_NEWDIALOGSTYLE
;
161 // Versions < 600 doesn't support BIF_NONEWFOLDERBUTTON
162 // The only way to get rid of the Make New Folder button is use
163 // the old dialog style which doesn't have the button thus we
164 // simply don't set the New Dialog Style for such comctl versions.
165 if (verComCtl32
>= 600)
167 bi
.ulFlags
|= BIF_NEWDIALOGSTYLE
;
168 bi
.ulFlags
|= BIF_NONEWFOLDERBUTTON
;
173 // do show the dialog
174 wxItemIdList
pidl(SHBrowseForFolder(&bi
));
176 wxItemIdList::Free((LPITEMIDLIST
)bi
.pidlRoot
);
180 // Cancel button pressed
184 m_path
= pidl
.GetPath();
186 // change current working directory if asked so
187 if (HasFlag(wxDD_CHANGE_DIR
))
188 wxSetWorkingDirectory(m_path
);
190 return m_path
.empty() ? wxID_CANCEL
: wxID_OK
;
193 // ----------------------------------------------------------------------------
195 // ----------------------------------------------------------------------------
198 BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
, LPARAM pData
)
202 #ifdef BFFM_SETSELECTION
203 case BFFM_INITIALIZED
:
204 // sent immediately after initialisation and so we may set the
205 // initial selection here
207 // wParam = TRUE => lParam is a string and not a PIDL
208 ::SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, pData
);
210 #endif // BFFM_SETSELECTION
213 case BFFM_SELCHANGED
:
214 // note that this doesn't work with the new style UI (MSDN doesn't
215 // say anything about it, but the comments in shlobj.h do!) but we
216 // still execute this code in case it starts working again with the
217 // "new new UI" (or would it be "NewUIEx" according to tradition?)
219 // Set the status window to the currently selected path.
221 if ( SHGetPathFromIDList((LPITEMIDLIST
)lp
,
222 wxStringBuffer(strDir
, MAX_PATH
)) )
224 // NB: this shouldn't be necessary with the new style box
225 // (which is resizable), but as for now it doesn't work
226 // anyhow (see the comment above) no harm in doing it
228 // need to truncate or it displays incorrectly
229 static const size_t maxChars
= 37;
230 if ( strDir
.length() > maxChars
)
232 strDir
= strDir
.Right(maxChars
);
233 strDir
= wxString(wxT("...")) + strDir
;
236 SendMessage(hwnd
, BFFM_SETSTATUSTEXT
,
237 0, (LPARAM
)strDir
.c_str());
242 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
243 // if the user types in invalid dir name
249 #endif // compiler/platform on which the code here compiles
251 #endif // wxUSE_DIRDLG