]>
Commit | Line | Data |
---|---|---|
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__))||defined(wxUSE_NORLANDER_HEADERS) | |
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 | static int CALLBACK | |
50 | BrowseCallbackProc(HWND hwnd,UINT uMsg,LPARAM lp, LPARAM pData) | |
51 | { | |
52 | TCHAR szDir[MAX_PATH]; | |
53 | ||
54 | switch(uMsg) | |
55 | { | |
56 | case BFFM_INITIALIZED: | |
57 | // We have put m_path into pData. | |
58 | // TRUE -> passing char *, not dir id. | |
59 | SendMessage(hwnd,BFFM_SETSELECTION,TRUE,pData); | |
60 | break; | |
61 | ||
62 | case BFFM_SELCHANGED: | |
63 | // Set the status window to the currently selected path. | |
64 | if (SHGetPathFromIDList((LPITEMIDLIST) lp ,szDir)) | |
65 | { | |
66 | SendMessage(hwnd,BFFM_SETSTATUSTEXT,0,(LPARAM)szDir); | |
67 | } | |
68 | break; | |
69 | ||
70 | default: | |
71 | break; | |
72 | } | |
73 | return 0; | |
74 | } | |
75 | ||
76 | ||
77 | wxDirDialog::wxDirDialog(wxWindow *parent, const wxString& message, | |
78 | // const wxString& caption, | |
79 | const wxString& defaultPath, | |
80 | long style, const wxPoint& pos) | |
81 | { | |
82 | m_message = message; | |
83 | // m_caption = caption; | |
84 | m_dialogStyle = style; | |
85 | m_parent = parent; | |
86 | m_path = defaultPath; | |
87 | } | |
88 | ||
89 | int wxDirDialog::ShowModal(void) | |
90 | { | |
91 | // Unfortunately Gnu-Win32 doesn't yet have COM support | |
92 | #if (defined(__WIN95__) && !defined(__GNUWIN32__))||defined(wxUSE_NORLANDER_HEADERS) | |
93 | HWND hWnd = 0; | |
94 | if (m_parent) hWnd = (HWND) m_parent->GetHWND(); | |
95 | ||
96 | BROWSEINFO bi; | |
97 | LPTSTR lpBuffer; | |
98 | // LPITEMIDLIST pidlPrograms; // PIDL for Programs folder | |
99 | LPITEMIDLIST pidlBrowse; // PIDL selected by user | |
100 | LPMALLOC pMalloc = NULL; | |
101 | ||
102 | HRESULT result = ::SHGetMalloc(&pMalloc); | |
103 | ||
104 | if (result != NOERROR) | |
105 | return wxID_CANCEL; | |
106 | ||
107 | // Allocate a buffer to receive browse information. | |
108 | if ((lpBuffer = (LPTSTR) pMalloc->Alloc(MAX_PATH)) == NULL) | |
109 | { | |
110 | pMalloc->Release(); | |
111 | return wxID_CANCEL; | |
112 | } | |
113 | ||
114 | /* | |
115 | // Get the PIDL for the Programs folder. | |
116 | if (!SUCCEEDED(SHGetSpecialFolderLocation( | |
117 | parent->GetSafeHwnd(), CSIDL_PROGRAMS, &pidlPrograms))) { | |
118 | pMalloc->Free(lpBuffer); | |
119 | pMalloc->Release(); | |
120 | return wxID_CANCEL; | |
121 | } | |
122 | */ | |
123 | ||
124 | // Fill in the BROWSEINFO structure. | |
125 | bi.hwndOwner = hWnd; | |
126 | bi.pidlRoot = NULL; // pidlPrograms; | |
127 | bi.pszDisplayName = lpBuffer; | |
128 | bi.lpszTitle = m_message; // BC++ 4.52 says LPSTR, not LPTSTR? | |
129 | bi.ulFlags = 0; | |
130 | bi.lpfn = BrowseCallbackProc; | |
131 | bi.lParam = (LPARAM)m_path.c_str(); | |
132 | ||
133 | // Browse for a folder and return its PIDL. | |
134 | pidlBrowse = SHBrowseForFolder(&bi); | |
135 | ||
136 | int id = wxID_OK; | |
137 | if (pidlBrowse != NULL) { | |
138 | ||
139 | // Show the display name, title, and file system path. | |
140 | if (SHGetPathFromIDList(pidlBrowse, lpBuffer)) | |
141 | m_path = lpBuffer; | |
142 | ||
143 | // Free the PIDL returned by SHBrowseForFolder. | |
144 | pMalloc->Free(pidlBrowse); | |
145 | } | |
146 | else | |
147 | id = wxID_CANCEL; | |
148 | ||
149 | // Clean up. | |
150 | // pMalloc->Free(pidlPrograms); | |
151 | pMalloc->Free(lpBuffer); | |
152 | pMalloc->Release(); | |
153 | ||
154 | return id; | |
155 | #else | |
156 | return wxID_CANCEL; | |
157 | #endif | |
158 | } | |
159 |