]> git.saurik.com Git - wxWidgets.git/blob - src/msw/dirdlg.cpp
1. wxStaticBox doesn't draw over the underlying controls any more
[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 #endif
35
36 #include "wx/msw/private.h"
37
38 #if defined(__WIN95__) && \
39 (!defined(__GNUWIN32__) || defined(wxUSE_NORLANDER_HEADERS))
40 #define CAN_COMPILE_DIRDLG
41 //#else: we provide a stub version which doesn't do anything
42 #endif
43
44 #ifdef CAN_COMPILE_DIRDLG
45 #include "shlobj.h" // Win95 shell
46 #endif
47
48 // ----------------------------------------------------------------------------
49 // constants
50 // ----------------------------------------------------------------------------
51
52 #ifndef MAX_PATH
53 #define MAX_PATH 4096 // be generuous
54 #endif
55
56 // ----------------------------------------------------------------------------
57 // wxWindows macros
58 // ----------------------------------------------------------------------------
59
60 #if !USE_SHARED_LIBRARY
61 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
62 #endif
63
64 // ----------------------------------------------------------------------------
65 // private functions prototypes
66 // ----------------------------------------------------------------------------
67
68 // free the parameter
69 static void ItemListFree(LPITEMIDLIST pidl);
70
71 // the callback proc for the dir dlg
72 static int CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp,
73 LPARAM pData);
74
75 // ============================================================================
76 // implementation
77 // ============================================================================
78
79 // ----------------------------------------------------------------------------
80 // wxDirDialog
81 // ----------------------------------------------------------------------------
82
83 wxDirDialog::wxDirDialog(wxWindow *parent,
84 const wxString& message,
85 const wxString& defaultPath,
86 long WXUNUSED(style),
87 const wxPoint& WXUNUSED(pos))
88 {
89 m_message = message;
90 m_parent = parent;
91 m_path = defaultPath;
92 }
93
94 int wxDirDialog::ShowModal()
95 {
96 #ifdef CAN_COMPILE_DIRDLG
97 BROWSEINFO bi;
98 bi.hwndOwner = m_parent ? GetHwndOf(m_parent) : NULL;
99 bi.pidlRoot = NULL;
100 bi.pszDisplayName = NULL;
101 bi.lpszTitle = m_message.c_str();
102 bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT;
103 bi.lpfn = BrowseCallbackProc;
104 bi.lParam = (LPARAM)m_path.c_str(); // param for the callback
105
106 LPITEMIDLIST pidl = SHBrowseForFolder(&bi);
107
108 if ( bi.pidlRoot )
109 {
110 ItemListFree((LPITEMIDLIST)bi.pidlRoot);
111 }
112
113 if ( !pidl )
114 {
115 // Cancel button pressed
116 return wxID_CANCEL;
117 }
118
119 BOOL ok = SHGetPathFromIDList(pidl, m_path.GetWriteBuf(MAX_PATH));
120 m_path.UngetWriteBuf();
121
122 ItemListFree(pidl);
123
124 if ( !ok )
125 {
126 wxLogLastError("SHGetPathFromIDList");
127
128 return wxID_CANCEL;
129 }
130
131 return wxID_OK;
132 #else // !CAN_COMPILE_DIRDLG
133 return wxID_CANCEL;
134 #endif // CAN_COMPILE_DIRDLG/!CAN_COMPILE_DIRDLG
135 }
136
137 // ----------------------------------------------------------------------------
138 // private functions
139 // ----------------------------------------------------------------------------
140
141 static int CALLBACK
142 BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData)
143 {
144 switch(uMsg)
145 {
146 case BFFM_INITIALIZED:
147 // sent immediately after initialisation and so we may set the
148 // initial selection here
149 //
150 // wParam = TRUE => lParam is a string and not a PIDL
151 SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData);
152 break;
153
154 case BFFM_SELCHANGED:
155 {
156 // Set the status window to the currently selected path.
157 TCHAR szDir[MAX_PATH];
158 if ( SHGetPathFromIDList((LPITEMIDLIST)lp, szDir) )
159 {
160 SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szDir);
161 }
162 }
163 break;
164
165 //case BFFM_VALIDATEFAILED: -- might be used to provide custom message
166 // if the user types in invalid dir name
167 }
168
169 return 0;
170 }
171
172
173 static void ItemListFree(LPITEMIDLIST pidl)
174 {
175 if ( pidl )
176 {
177 LPMALLOC pMalloc;
178 SHGetMalloc(&pMalloc);
179 if ( pMalloc )
180 {
181 pMalloc->Free(pidl);
182 pMalloc->Release();
183 }
184 else
185 {
186 wxLogLastError("SHGetMalloc");
187 }
188 }
189 }
190