]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/dirdlg.cpp
e736175a5c68fa16c5525ffe7861a9996fea3e09
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"
42 #include "wx/msw/private.h"
44 #include <shlobj.h> // Win95 shell
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
51 #define MAX_PATH 4096 // be generous
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
58 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
60 // ----------------------------------------------------------------------------
61 // private functions prototypes
62 // ----------------------------------------------------------------------------
65 static void ItemListFree(LPITEMIDLIST pidl
);
67 // the callback proc for the dir dlg
68 static int CALLBACK
BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
,
72 // ============================================================================
74 // ============================================================================
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
80 wxDirDialog::wxDirDialog(wxWindow
*parent
,
81 const wxString
& message
,
82 const wxString
& defaultPath
,
84 const wxPoint
& WXUNUSED(pos
),
85 const wxSize
& WXUNUSED(size
),
86 const wxString
& WXUNUSED(name
))
95 void wxDirDialog::SetPath(const wxString
& path
)
99 // SHBrowseForFolder doesn't like '/'s nor the trailing backslashes
100 m_path
.Replace(_T("/"), _T("\\"));
101 if ( !m_path
.empty() )
103 while ( *(m_path
.end() - 1) == _T('\\') )
105 m_path
.erase(m_path
.length() - 1);
108 // but the root drive should have a trailing slash (again, this is just
109 // the way the native dialog works)
110 if ( *(m_path
.end() - 1) == _T(':') )
117 #ifndef BIF_NEWDIALOGSTYLE
118 #define BIF_NEWDIALOGSTYLE 0x0040
121 int wxDirDialog::ShowModal()
123 wxWindow
*parent
= GetParent();
126 bi
.hwndOwner
= parent
? GetHwndOf(parent
) : NULL
;
128 bi
.pszDisplayName
= NULL
;
129 bi
.lpszTitle
= m_message
.c_str();
130 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_STATUSTEXT
;
131 bi
.lpfn
= BrowseCallbackProc
;
132 bi
.lParam
= (LPARAM
)m_path
.c_str(); // param for the callback
134 if ((GetStyle() & wxDD_NEW_DIR_BUTTON
) &&
135 (wxApp::GetComCtl32Version() >= 500))
137 bi
.ulFlags
|= BIF_NEWDIALOGSTYLE
;
140 LPITEMIDLIST pidl
= SHBrowseForFolder(&bi
);
144 ItemListFree((LPITEMIDLIST
)bi
.pidlRoot
);
149 // Cancel button pressed
153 BOOL ok
= SHGetPathFromIDList(pidl
, m_path
.GetWriteBuf(MAX_PATH
));
154 m_path
.UngetWriteBuf();
160 wxLogLastError(wxT("SHGetPathFromIDList"));
168 // ----------------------------------------------------------------------------
170 // ----------------------------------------------------------------------------
173 BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
, LPARAM pData
)
177 case BFFM_INITIALIZED
:
178 // sent immediately after initialisation and so we may set the
179 // initial selection here
181 // wParam = TRUE => lParam is a string and not a PIDL
182 SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, pData
);
185 case BFFM_SELCHANGED
:
187 // Set the status window to the currently selected path.
188 TCHAR szDir
[MAX_PATH
];
189 if ( SHGetPathFromIDList((LPITEMIDLIST
)lp
, szDir
) )
191 wxString
strDir(szDir
);
192 int maxChars
= 40; // Have to truncate string else it displays incorrectly
193 if (strDir
.Len() > (size_t) (maxChars
- 3))
195 strDir
= strDir
.Right(maxChars
- 3);
196 strDir
= wxString(wxT("...")) + strDir
;
198 SendMessage(hwnd
, BFFM_SETSTATUSTEXT
, 0, (LPARAM
) (const wxChar
*) strDir
);
203 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
204 // if the user types in invalid dir name
211 static void ItemListFree(LPITEMIDLIST pidl
)
216 SHGetMalloc(&pMalloc
);
224 wxLogLastError(wxT("SHGetMalloc"));
230 #include "../generic/dirdlgg.cpp"
231 #endif // compiler/platform on which the code here compiles
233 #endif // wxUSE_DIRDLG