]>
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"
27 #if wxUSE_DIRDLG && (!defined(__WXWINCE__) || defined(__HANDHELDPC__))
29 #if !defined(__GNUWIN32_OLD__) && wxUSE_OLE
33 #include "wx/dialog.h"
34 #include "wx/dirdlg.h"
36 #include "wx/app.h" // for GetComCtl32Version()
39 #include "wx/msw/private.h"
40 #include "wx/msw/wrapshl.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 #ifndef BIF_NEWDIALOGSTYLE
47 #define BIF_NEWDIALOGSTYLE 0x0040
50 #ifndef BIF_NONEWFOLDERBUTTON
51 #define BIF_NONEWFOLDERBUTTON 0x0200
55 #define BIF_EDITBOX 16
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
62 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
64 // ----------------------------------------------------------------------------
65 // private functions prototypes
66 // ----------------------------------------------------------------------------
68 // the callback proc for the dir dlg
69 static int CALLBACK
BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
,
73 // ============================================================================
75 // ============================================================================
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
81 wxDirDialog::wxDirDialog(wxWindow
*parent
,
82 const wxString
& message
,
83 const wxString
& defaultPath
,
85 const wxPoint
& WXUNUSED(pos
),
86 const wxSize
& WXUNUSED(size
),
87 const wxString
& WXUNUSED(name
))
96 void wxDirDialog::SetPath(const wxString
& path
)
100 // SHBrowseForFolder doesn't like '/'s nor the trailing backslashes
101 m_path
.Replace(_T("/"), _T("\\"));
102 if ( !m_path
.empty() )
104 while ( *(m_path
.end() - 1) == _T('\\') )
106 m_path
.erase(m_path
.length() - 1);
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(':') )
118 int wxDirDialog::ShowModal()
120 wxWindow
*parent
= GetParent();
123 bi
.hwndOwner
= parent
? GetHwndOf(parent
) : NULL
;
125 bi
.pszDisplayName
= NULL
;
126 // Please don't change this without checking it compiles
128 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
129 bi
.lpszTitle
= m_message
.mb_str();
131 bi
.lpszTitle
= m_message
.c_str();
133 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_STATUSTEXT
;
134 bi
.lpfn
= BrowseCallbackProc
;
135 bi
.lParam
= (LPARAM
)m_path
.c_str(); // param for the callback
137 static const int verComCtl32
= wxApp::GetComCtl32Version();
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 )
143 bi
.ulFlags
|= BIF_EDITBOX
;
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
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) )
155 bi
.ulFlags
|= BIF_NEWDIALOGSTYLE
;
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)
165 bi
.ulFlags
|= BIF_NEWDIALOGSTYLE
;
166 bi
.ulFlags
|= BIF_NONEWFOLDERBUTTON
;
171 // do show the dialog
172 wxItemIdList
pidl(SHBrowseForFolder(&bi
));
174 wxItemIdList::Free((LPITEMIDLIST
)bi
.pidlRoot
);
178 // Cancel button pressed
182 m_path
= pidl
.GetPath();
184 return m_path
.empty() ? wxID_CANCEL
: wxID_OK
;
187 // ----------------------------------------------------------------------------
189 // ----------------------------------------------------------------------------
192 BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
, LPARAM pData
)
196 #ifdef BFFM_SETSELECTION
197 case BFFM_INITIALIZED
:
198 // sent immediately after initialisation and so we may set the
199 // initial selection here
201 // wParam = TRUE => lParam is a string and not a PIDL
202 ::SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, pData
);
204 #endif // BFFM_SETSELECTION
207 case BFFM_SELCHANGED
:
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?)
213 // Set the status window to the currently selected path.
215 if ( SHGetPathFromIDList((LPITEMIDLIST
)lp
,
216 wxStringBuffer(strDir
, MAX_PATH
)) )
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
222 // need to truncate or it displays incorrectly
223 static const size_t maxChars
= 37;
224 if ( strDir
.length() > maxChars
)
226 strDir
= strDir
.Right(maxChars
);
227 strDir
= wxString(wxT("...")) + strDir
;
230 SendMessage(hwnd
, BFFM_SETSTATUSTEXT
,
231 0, (LPARAM
)strDir
.c_str());
236 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
237 // if the user types in invalid dir name
245 #include "../generic/dirdlgg.cpp"
246 #endif // compiler/platform on which the code here compiles
248 #endif // wxUSE_DIRDLG && !(__SMARTPHONE__ && __WXWINCE__)