]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dirdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDirDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "dirdlg.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #if defined(__WIN95__) && !defined(__GNUWIN32_OLD__) && wxUSE_OLE
37 #include "wx/dialog.h"
38 #include "wx/dirdlg.h"
40 #include "wx/app.h" // for GetComCtl32Version()
43 #include "wx/msw/private.h"
45 #include <shlobj.h> // Win95 shell
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
52 #define MAX_PATH 4096 // be generous
55 // ----------------------------------------------------------------------------
57 // ----------------------------------------------------------------------------
59 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
61 // ----------------------------------------------------------------------------
62 // private functions prototypes
63 // ----------------------------------------------------------------------------
66 static void ItemListFree(LPITEMIDLIST pidl
);
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 #ifndef BIF_NEWDIALOGSTYLE
119 #define BIF_NEWDIALOGSTYLE 0x0040
122 int wxDirDialog::ShowModal()
124 wxWindow
*parent
= GetParent();
127 bi
.hwndOwner
= parent
? GetHwndOf(parent
) : NULL
;
129 bi
.pszDisplayName
= NULL
;
130 bi
.lpszTitle
= m_message
.c_str();
131 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_STATUSTEXT
;
132 bi
.lpfn
= BrowseCallbackProc
;
133 bi
.lParam
= (LPARAM
)m_path
.c_str(); // param for the callback
135 if ((GetStyle() & wxDD_NEW_DIR_BUTTON
) &&
136 (wxApp::GetComCtl32Version() >= 500))
138 bi
.ulFlags
|= BIF_NEWDIALOGSTYLE
;
141 LPITEMIDLIST pidl
= SHBrowseForFolder(&bi
);
145 ItemListFree((LPITEMIDLIST
)bi
.pidlRoot
);
150 // Cancel button pressed
154 BOOL ok
= SHGetPathFromIDList(pidl
, m_path
.GetWriteBuf(MAX_PATH
));
155 m_path
.UngetWriteBuf();
161 wxLogLastError(wxT("SHGetPathFromIDList"));
169 // ----------------------------------------------------------------------------
171 // ----------------------------------------------------------------------------
174 BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
, LPARAM pData
)
178 case BFFM_INITIALIZED
:
179 // sent immediately after initialisation and so we may set the
180 // initial selection here
182 // wParam = TRUE => lParam is a string and not a PIDL
183 SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, pData
);
186 case BFFM_SELCHANGED
:
188 // Set the status window to the currently selected path.
189 TCHAR szDir
[MAX_PATH
];
190 if ( SHGetPathFromIDList((LPITEMIDLIST
)lp
, szDir
) )
192 wxString
strDir(szDir
);
193 int maxChars
= 40; // Have to truncate string else it displays incorrectly
194 if (strDir
.Len() > (size_t) (maxChars
- 3))
196 strDir
= strDir
.Right(maxChars
- 3);
197 strDir
= wxString(wxT("...")) + strDir
;
199 SendMessage(hwnd
, BFFM_SETSTATUSTEXT
, 0, (LPARAM
) (const wxChar
*) strDir
);
204 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
205 // if the user types in invalid dir name
212 static void ItemListFree(LPITEMIDLIST pidl
)
217 SHGetMalloc(&pMalloc
);
225 wxLogLastError(wxT("SHGetMalloc"));
231 #include "../generic/dirdlgg.cpp"
232 #endif // compiler/platform on which the code here compiles
234 #endif // wxUSE_DIRDLG