]> git.saurik.com Git - wxWidgets.git/blob - src/msw/dirdlg.cpp
unneeded line removed
[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 bi.hwndOwner = hWnd;
98 bi.pidlRoot = NULL; // pidlPrograms;
99 bi.pszDisplayName = lpBuffer;
100 bi.lpszTitle = (LPCTSTR) (const char *) m_message;
101 bi.ulFlags = 0;
102 bi.lpfn = NULL;
103 bi.lParam = 0;
104
105 // Browse for a folder and return its PIDL.
106 pidlBrowse = SHBrowseForFolder(&bi);
107
108 int id = wxID_OK;
109 if (pidlBrowse != NULL) {
110
111 // Show the display name, title, and file system path.
112 if (SHGetPathFromIDList(pidlBrowse, lpBuffer))
113 m_path = lpBuffer;
114
115 // Free the PIDL returned by SHBrowseForFolder.
116 pMalloc->Free(pidlBrowse);
117 }
118 else
119 id = wxID_CANCEL;
120
121 // Clean up.
122 // pMalloc->Free(pidlPrograms);
123 pMalloc->Free(lpBuffer);
124 pMalloc->Release();
125
126 return id;
127 #else
128 return wxID_CANCEL;
129 #endif
130 }
131