]>
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 // ----------------------------------------------------------------------------
20 #pragma implementation "dirdlg.h"
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
30 #if defined(__WIN95__) && \
31 (!defined(__GNUWIN32__) || defined(wxUSE_NORLANDER_HEADERS))
35 #include "wx/dialog.h"
36 #include "wx/dirdlg.h"
40 #include "wx/msw/private.h"
42 #include "shlobj.h" // Win95 shell
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
49 #define MAX_PATH 4096 // be generous
52 // ----------------------------------------------------------------------------
54 // ----------------------------------------------------------------------------
56 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
58 // ----------------------------------------------------------------------------
59 // private functions prototypes
60 // ----------------------------------------------------------------------------
63 static void ItemListFree(LPITEMIDLIST pidl
);
65 // the callback proc for the dir dlg
66 static int CALLBACK
BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
,
70 // ============================================================================
72 // ============================================================================
74 // ----------------------------------------------------------------------------
76 // ----------------------------------------------------------------------------
78 wxDirDialog::wxDirDialog(wxWindow
*parent
,
79 const wxString
& message
,
80 const wxString
& defaultPath
,
82 const wxPoint
& WXUNUSED(pos
))
87 m_path
.Replace(_T("/"), _T("\\")); // SHBrowseForFolder doesn't like '/'s
90 int wxDirDialog::ShowModal()
93 bi
.hwndOwner
= m_parent
? GetHwndOf(m_parent
) : NULL
;
95 bi
.pszDisplayName
= NULL
;
96 bi
.lpszTitle
= m_message
.c_str();
97 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_STATUSTEXT
;
98 bi
.lpfn
= BrowseCallbackProc
;
99 bi
.lParam
= (LPARAM
)m_path
.c_str(); // param for the callback
101 LPITEMIDLIST pidl
= SHBrowseForFolder(&bi
);
105 ItemListFree((LPITEMIDLIST
)bi
.pidlRoot
);
110 // Cancel button pressed
114 BOOL ok
= SHGetPathFromIDList(pidl
, m_path
.GetWriteBuf(MAX_PATH
));
115 m_path
.UngetWriteBuf();
121 wxLogLastError("SHGetPathFromIDList");
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
134 BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
, LPARAM pData
)
138 case BFFM_INITIALIZED
:
139 // sent immediately after initialisation and so we may set the
140 // initial selection here
142 // wParam = TRUE => lParam is a string and not a PIDL
143 SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, pData
);
146 case BFFM_SELCHANGED
:
148 // Set the status window to the currently selected path.
149 TCHAR szDir
[MAX_PATH
];
150 if ( SHGetPathFromIDList((LPITEMIDLIST
)lp
, szDir
) )
152 SendMessage(hwnd
, BFFM_SETSTATUSTEXT
, 0, (LPARAM
)szDir
);
157 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
158 // if the user types in invalid dir name
165 static void ItemListFree(LPITEMIDLIST pidl
)
170 SHGetMalloc(&pMalloc
);
178 wxLogLastError("SHGetMalloc");
184 #include "../generic/dirdlgg.cpp"
185 #endif // compiler/platform on which the code here compiles