]> git.saurik.com Git - wxWidgets.git/blob - src/msw/dirdlg.cpp
80b5e4dbb4e11359bc1d6f0463c0473bef3cee12
[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 #ifdef __GNUG__
13 #pragma implementation "dirdlg.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include <stdio.h>
25 #include "wx/defs.h"
26 #include "wx/utils.h"
27 #include "wx/dialog.h"
28 #include "wx/dirdlg.h"
29 #endif
30
31 #if defined(__WIN95__) && !defined(__GNUWIN32__)
32 #include "shlobj.h" // Win95 shell
33 #endif
34
35 #include "wx/msw/private.h"
36 #include "wx/cmndata.h"
37
38 #include <math.h>
39 #include <stdlib.h>
40 #include <string.h>
41
42 #define wxDIALOG_DEFAULT_X 300
43 #define wxDIALOG_DEFAULT_Y 300
44
45 #if !USE_SHARED_LIBRARY
46 IMPLEMENT_CLASS(wxDirDialog, wxDialog)
47 #endif
48
49 wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message,
50 // const wxString& caption,
51 const wxString& defaultPath,
52 long style, const wxPoint& pos)
53 {
54 m_message = message;
55 // m_caption = caption;
56 m_dialogStyle = style;
57 m_parent = parent;
58 m_path = defaultPath;
59 }
60
61 int wxDirDialog::ShowModal(void)
62 {
63 // Unfortunately Gnu-Win32 doesn't yet have COM support
64 #if defined(__WIN95__) && !defined(__GNUWIN32__)
65 HWND hWnd = 0;
66 if (m_parent) hWnd = (HWND) m_parent->GetHWND();
67
68 BROWSEINFO bi;
69 LPSTR lpBuffer;
70 // LPITEMIDLIST pidlPrograms; // PIDL for Programs folder
71 LPITEMIDLIST pidlBrowse; // PIDL selected by user
72 LPMALLOC pMalloc = NULL;
73
74 HRESULT result = ::SHGetMalloc(&pMalloc);
75
76 if (result != NOERROR)
77 return wxID_CANCEL;
78
79 // Allocate a buffer to receive browse information.
80 if ((lpBuffer = (LPSTR) pMalloc->Alloc(MAX_PATH)) == NULL)
81 {
82 pMalloc->Release();
83 return wxID_CANCEL;
84 }
85
86 /*
87 // Get the PIDL for the Programs folder.
88 if (!SUCCEEDED(SHGetSpecialFolderLocation(
89 parent->GetSafeHwnd(), CSIDL_PROGRAMS, &pidlPrograms))) {
90 pMalloc->Free(lpBuffer);
91 pMalloc->Release();
92 return wxID_CANCEL;
93 }
94 */
95
96 // Fill in the BROWSEINFO structure.
97 wxWX2MBbuf message = m_message.mb_str();
98 bi.hwndOwner = hWnd;
99 bi.pidlRoot = NULL; // pidlPrograms;
100 bi.pszDisplayName = lpBuffer;
101 bi.lpszTitle = (const char*)message; // BC++ 4.52 says LPSTR, not LPTSTR?
102 bi.ulFlags = 0;
103 bi.lpfn = NULL;
104 bi.lParam = 0;
105
106 // Browse for a folder and return its PIDL.
107 pidlBrowse = SHBrowseForFolder(&bi);
108
109 int id = wxID_OK;
110 if (pidlBrowse != NULL) {
111
112 // Show the display name, title, and file system path.
113 if (SHGetPathFromIDList(pidlBrowse, lpBuffer))
114 m_path = lpBuffer;
115
116 // Free the PIDL returned by SHBrowseForFolder.
117 pMalloc->Free(pidlBrowse);
118 }
119 else
120 id = wxID_CANCEL;
121
122 // Clean up.
123 // pMalloc->Free(pidlPrograms);
124 pMalloc->Free(lpBuffer);
125 pMalloc->Release();
126
127 return id;
128 #else
129 return wxID_CANCEL;
130 #endif
131 }
132