]>
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"
32 #include "wx/dialog.h"
33 #include "wx/dirdlg.h"
37 #include "wx/msw/private.h"
39 #if defined(__WIN95__) && \
40 (!defined(__GNUWIN32__) || defined(wxUSE_NORLANDER_HEADERS))
41 #define CAN_COMPILE_DIRDLG
42 //#else: we provide a stub version which doesn't do anything
45 #ifdef CAN_COMPILE_DIRDLG
46 #include "shlobj.h" // Win95 shell
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
54 #define MAX_PATH 4096 // be generuous
57 // ----------------------------------------------------------------------------
59 // ----------------------------------------------------------------------------
61 IMPLEMENT_CLASS(wxDirDialog
, wxDialog
)
63 // ----------------------------------------------------------------------------
64 // private functions prototypes
65 // ----------------------------------------------------------------------------
68 static void ItemListFree(LPITEMIDLIST pidl
);
70 // the callback proc for the dir dlg
71 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
))
93 int wxDirDialog::ShowModal()
95 #ifdef CAN_COMPILE_DIRDLG
97 bi
.hwndOwner
= m_parent
? GetHwndOf(m_parent
) : NULL
;
99 bi
.pszDisplayName
= NULL
;
100 bi
.lpszTitle
= m_message
.c_str();
101 bi
.ulFlags
= BIF_RETURNONLYFSDIRS
| BIF_STATUSTEXT
;
102 bi
.lpfn
= BrowseCallbackProc
;
103 bi
.lParam
= (LPARAM
)m_path
.c_str(); // param for the callback
105 LPITEMIDLIST pidl
= SHBrowseForFolder(&bi
);
109 ItemListFree((LPITEMIDLIST
)bi
.pidlRoot
);
114 // Cancel button pressed
118 BOOL ok
= SHGetPathFromIDList(pidl
, m_path
.GetWriteBuf(MAX_PATH
));
119 m_path
.UngetWriteBuf();
125 wxLogLastError("SHGetPathFromIDList");
131 #else // !CAN_COMPILE_DIRDLG
133 #endif // CAN_COMPILE_DIRDLG/!CAN_COMPILE_DIRDLG
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
141 BrowseCallbackProc(HWND hwnd
, UINT uMsg
, LPARAM lp
, LPARAM pData
)
145 case BFFM_INITIALIZED
:
146 // sent immediately after initialisation and so we may set the
147 // initial selection here
149 // wParam = TRUE => lParam is a string and not a PIDL
150 SendMessage(hwnd
, BFFM_SETSELECTION
, TRUE
, pData
);
153 case BFFM_SELCHANGED
:
155 // Set the status window to the currently selected path.
156 TCHAR szDir
[MAX_PATH
];
157 if ( SHGetPathFromIDList((LPITEMIDLIST
)lp
, szDir
) )
159 SendMessage(hwnd
, BFFM_SETSTATUSTEXT
, 0, (LPARAM
)szDir
);
164 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
165 // if the user types in invalid dir name
172 static void ItemListFree(LPITEMIDLIST pidl
)
177 SHGetMalloc(&pMalloc
);
185 wxLogLastError("SHGetMalloc");