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