]> git.saurik.com Git - wxWidgets.git/blob - src/msw/dirdlg.cpp
compilation fix for non-threaded compilation (threads are still broken
[wxWidgets.git] / src / msw / dirdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dirdlg.cpp
3 // Purpose: wxDirDialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19 #ifdef __GNUG__
20 #pragma implementation "dirdlg.h"
21 #endif
22
23 // For compilers that support precompilation, includes "wx.h".
24 #include "wx/wxprec.h"
25
26 #ifdef __BORLANDC__
27 #pragma hdrstop
28 #endif
29
30 #ifndef WX_PRECOMP
31 #include "wx/utils.h"
32 #include "wx/dialog.h"
33 #include "wx/dirdlg.h"
34 #include "wx/log.h"
35 #endif
36
37 #include "wx/msw/private.h"
38
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
43 #endif
44
45 #ifdef CAN_COMPILE_DIRDLG
46 #include "shlobj.h" // Win95 shell
47 #endif
48
49 // ----------------------------------------------------------------------------
50 // constants
51 // ----------------------------------------------------------------------------
52
53 #ifndef MAX_PATH
54 #define MAX_PATH 4096 // be generuous
55 #endif
56
57 // ----------------------------------------------------------------------------
58 // wxWindows macros
59 // ----------------------------------------------------------------------------
60
61 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
62
63 // ----------------------------------------------------------------------------
64 // private functions prototypes
65 // ----------------------------------------------------------------------------
66
67 // free the parameter
68 static void ItemListFree(LPITEMIDLIST pidl);
69
70 // the callback proc for the dir dlg
71 static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp,
72 LPARAM pData);
73
74 // ============================================================================
75 // implementation
76 // ============================================================================
77
78 // ----------------------------------------------------------------------------
79 // wxDirDialog
80 // ----------------------------------------------------------------------------
81
82 wxDirDialog::wxDirDialog(wxWindow *parent,
83 const wxString& message,
84 const wxString& defaultPath,
85 long WXUNUSED(style),
86 const wxPoint& WXUNUSED(pos))
87 {
88 m_message = message;
89 m_parent = parent;
90 m_path = defaultPath;
91 }
92
93 int wxDirDialog::ShowModal()
94 {
95 #ifdef CAN_COMPILE_DIRDLG
96 BROWSEINFO bi;
97 bi.hwndOwner = m_parent ? GetHwndOf(m_parent) : NULL;
98 bi.pidlRoot = 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
104
105 LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
106
107 if ( bi.pidlRoot )
108 {
109 ItemListFree((LPITEMIDLIST)bi.pidlRoot);
110 }
111
112 if ( !pidl )
113 {
114 // Cancel button pressed
115 return wxID_CANCEL;
116 }
117
118 BOOL ok = SHGetPathFromIDList(pidl, m_path.GetWriteBuf(MAX_PATH));
119 m_path.UngetWriteBuf();
120
121 ItemListFree(pidl);
122
123 if ( !ok )
124 {
125 wxLogLastError("SHGetPathFromIDList");
126
127 return wxID_CANCEL;
128 }
129
130 return wxID_OK;
131 #else // !CAN_COMPILE_DIRDLG
132 return wxID_CANCEL;
133 #endif // CAN_COMPILE_DIRDLG/!CAN_COMPILE_DIRDLG
134 }
135
136 // ----------------------------------------------------------------------------
137 // private functions
138 // ----------------------------------------------------------------------------
139
140 static int CALLBACK
141 BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
142 {
143 switch(uMsg)
144 {
145 case BFFM_INITIALIZED:
146 // sent immediately after initialisation and so we may set the
147 // initial selection here
148 //
149 // wParam = TRUE => lParam is a string and not a PIDL
150 SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData);
151 break;
152
153 case BFFM_SELCHANGED:
154 {
155 // Set the status window to the currently selected path.
156 TCHAR szDir[MAX_PATH];
157 if ( SHGetPathFromIDList((LPITEMIDLIST)lp, szDir) )
158 {
159 SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szDir);
160 }
161 }
162 break;
163
164 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
165 // if the user types in invalid dir name
166 }
167
168 return 0;
169 }
170
171
172 static void ItemListFree(LPITEMIDLIST pidl)
173 {
174 if ( pidl )
175 {
176 LPMALLOC pMalloc;
177 SHGetMalloc(&pMalloc);
178 if ( pMalloc )
179 {
180 pMalloc->Free(pidl);
181 pMalloc->Release();
182 }
183 else
184 {
185 wxLogLastError("SHGetMalloc");
186 }
187 }
188 }
189