]>
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)))
34 #include "wx/dialog.h"
35 #include "wx/dirdlg.h"
37 #include "wx/app.h" // for GetComCtl32Version()
40 #include "wx/msw/private.h"
41 #include "wx/msw/wrapshl.h"
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 #ifndef BIF_NEWDIALOGSTYLE
48 #define BIF_NEWDIALOGSTYLE 0x0040
51 #ifndef BIF_NONEWFOLDERBUTTON
52 #define BIF_NONEWFOLDERBUTTON 0x0200
56 #define BIF_EDITBOX 16
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
65 // ----------------------------------------------------------------------------
66 // private functions prototypes
67 // ----------------------------------------------------------------------------
69 // the callback proc for the dir dlg
70 static int CALLBACK
BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
,
74 // ============================================================================
76 // ============================================================================
78 // ----------------------------------------------------------------------------
80 // ----------------------------------------------------------------------------
82 wxDirDialog::wxDirDialog(wxWindow
*parent
,
83 const wxString
& message
,
84 const wxString
& defaultPath
,
86 const wxPoint
& WXUNUSED(pos
),
87 const wxSize
& WXUNUSED(size
),
88 const wxString
& WXUNUSED(name
))
93 SetWindowStyle(style
);
97 void wxDirDialog::SetPath(const wxString
& path
)
101 // SHBrowseForFolder doesn't like '/'s nor the trailing backslashes
102 m_path
.Replace(_T("/"), _T("\\"));
103 if ( !m_path
.empty() )
105 while ( *(m_path
.end() - 1) == _T('\\') )
107 m_path
.erase(m_path
.length() - 1);
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(':') )
119 int wxDirDialog::ShowModal()
121 wxWindow
*parent
= GetParent();
124 bi
.hwndOwner
= parent
? GetHwndOf(parent
) : NULL
;
126 bi
.pszDisplayName
= NULL
;
127 // Please don't change this without checking it compiles
129 #if defined(__POCKETPC__) || defined(__SMARTPHONE__)
130 bi
.lpszTitle
= m_message
.mb_str();
132 bi
.lpszTitle
= m_message
.c_str();
134 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_STATUSTEXT
;
135 bi
.lpfn
= BrowseCallbackProc
;
136 bi
.lParam
= (LPARAM
)m_path
.c_str(); // param for the callback
138 static const int verComCtl32
= wxApp::GetComCtl32Version();
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 )
144 bi
.ulFlags
|= BIF_EDITBOX
;
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
150 // "new" style is only available in the version 5.0+ of comctl32.dll
151 const bool needNewDir
= !HasFlag(wxDD_DIR_MUST_EXIST
);
152 if ( (needNewDir
|| HasFlag(wxRESIZE_BORDER
)) && (verComCtl32
>= 500) )
156 bi
.ulFlags
|= BIF_NEWDIALOGSTYLE
;
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)
166 bi
.ulFlags
|= BIF_NEWDIALOGSTYLE
;
167 bi
.ulFlags
|= BIF_NONEWFOLDERBUTTON
;
172 // do show the dialog
173 wxItemIdList
pidl(SHBrowseForFolder(&bi
));
175 wxItemIdList::Free((LPITEMIDLIST
)bi
.pidlRoot
);
179 // Cancel button pressed
183 m_path
= pidl
.GetPath();
185 // change current working directory if asked so
186 if (HasFlag(wxDD_CHANGE_DIR
))
187 wxSetWorkingDirectory(m_path
);
189 return m_path
.empty() ? wxID_CANCEL
: wxID_OK
;
192 // ----------------------------------------------------------------------------
194 // ----------------------------------------------------------------------------
197 BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
, LPARAM pData
)
201 #ifdef BFFM_SETSELECTION
202 case BFFM_INITIALIZED
:
203 // sent immediately after initialisation and so we may set the
204 // initial selection here
206 // wParam = TRUE => lParam is a string and not a PIDL
207 ::SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, pData
);
209 #endif // BFFM_SETSELECTION
212 case BFFM_SELCHANGED
:
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?)
218 // Set the status window to the currently selected path.
220 if ( SHGetPathFromIDList((LPITEMIDLIST
)lp
,
221 wxStringBuffer(strDir
, MAX_PATH
)) )
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
227 // need to truncate or it displays incorrectly
228 static const size_t maxChars
= 37;
229 if ( strDir
.length() > maxChars
)
231 strDir
= strDir
.Right(maxChars
);
232 strDir
= wxString(wxT("...")) + strDir
;
235 SendMessage(hwnd
, BFFM_SETSTATUSTEXT
,
236 0, (LPARAM
)strDir
.c_str());
241 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
242 // if the user types in invalid dir name
248 #endif // compiler/platform on which the code here compiles
250 #endif // wxUSE_DIRDLG