Changeset 181:52c185ec49e8
- Timestamp:
- 03/09/08 23:31:43
(6 months ago)
- Author:
- Zhiguang Liang <davelzg@gmail.com>
- branch:
- default
- Message:
Directory Dialog ported
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r167 |
r181 |
|
| 3995 | 3995 | version(ANSI) { |
|---|
| 3996 | 3996 | alias WINAPI.AddFontResourceExA AddFontResourceEx; |
|---|
| | 3997 | alias WINAPI.AssocQueryStringA AssocQueryString; |
|---|
| 3997 | 3998 | alias WINAPI.CallWindowProcA CallWindowProc; |
|---|
| 3998 | 3999 | alias WINAPI.CharLowerA CharLower; |
|---|
| … | … | |
| 4096 | 4097 | }else{ |
|---|
| 4097 | 4098 | alias WINAPI.AddFontResourceExW AddFontResourceEx; |
|---|
| | 4099 | alias WINAPI.AssocQueryStringW AssocQueryString; |
|---|
| 4098 | 4100 | alias WINAPI.CallWindowProcW CallWindowProc; |
|---|
| 4099 | 4101 | alias WINAPI.CharLowerW CharLower; |
|---|
| r165 |
r181 |
|
| 14 | 14 | extern(Windows) |
|---|
| 15 | 15 | { |
|---|
| | 16 | HRESULT AssocQueryStringA(ASSOCF flags, int str, LPCTSTR pszAssoc, LPCTSTR pszExtra, LPTSTR pszOut, DWORD *pcchOut); |
|---|
| | 17 | HRESULT AssocQueryStringW(ASSOCF flags, int str, LPCTSTR pszAssoc, LPCTSTR pszExtra, LPTSTR pszOut, DWORD *pcchOut); |
|---|
| | 18 | |
|---|
| 16 | 19 | // BOOL GetWindowInfo(HWND, PWINDOWINFO); |
|---|
| 17 | 20 | // BOOL EnumDisplayMonitors(HDC, RECT*, MONITORENUMPROC, LPARAM); |
|---|
| r128 |
r181 |
|
| 201 | 201 | // BYTE[8] Data4; |
|---|
| 202 | 202 | // } |
|---|
| | 203 | |
|---|
| | 204 | enum {ASSOCF_INIT_BYEXENAME, |
|---|
| | 205 | ASSOCF_OPEN_BYEXENAME, |
|---|
| | 206 | ASSOCF_INIT_DEFAULTTOSTAR, |
|---|
| | 207 | ASSOCF_INIT_DEFAULTTOFOLDER, |
|---|
| | 208 | ASSOCF_NOUSERSETTINGS, |
|---|
| | 209 | ASSOCF_NOTRUNCATE, |
|---|
| | 210 | ASSOCF_VERIFY, |
|---|
| | 211 | ASSOCF_REMAPRUNDLL, |
|---|
| | 212 | ASSOCF_NOFIXUPS, |
|---|
| | 213 | ASSOCF_IGNOREBASECLASS |
|---|
| | 214 | }; |
|---|
| | 215 | |
|---|
| | 216 | alias DWORD ASSOCF; |
|---|
| 203 | 217 | |
|---|
| 204 | 218 | enum { AclRevisionInformation = 1, AclSizeInformation, }; |
|---|
| r82 |
r181 |
|
| 13 | 13 | module dwt.widgets.DirectoryDialog; |
|---|
| 14 | 14 | |
|---|
| | 15 | import dwt.widgets.Display; |
|---|
| 15 | 16 | import dwt.widgets.Dialog; |
|---|
| 16 | 17 | import dwt.widgets.Shell; |
|---|
| 17 | 18 | |
|---|
| 18 | | class DirectoryDialog : Dialog { |
|---|
| 19 | | public this (Shell parent, int style) { |
|---|
| 20 | | super (parent, style); |
|---|
| 21 | | } |
|---|
| 22 | | } |
|---|
| 23 | | |
|---|
| 24 | | /++ |
|---|
| 25 | 19 | import dwt.DWT; |
|---|
| 26 | 20 | import dwt.DWTException; |
|---|
| 27 | | import dwt.internal.Callback; |
|---|
| 28 | | import dwt.internal.win32.BROWSEINFO; |
|---|
| 29 | 21 | import dwt.internal.win32.OS; |
|---|
| 30 | | import dwt.internal.win32.TCHAR; |
|---|
| | 22 | import dwt.internal.C; |
|---|
| | 23 | |
|---|
| | 24 | import dwt.dwthelper.utils; |
|---|
| | 25 | static import tango.text.Text; |
|---|
| 31 | 26 | |
|---|
| 32 | 27 | /** |
|---|
| … | … | |
| 45 | 40 | */ |
|---|
| 46 | 41 | |
|---|
| 47 | | public class DirectoryDialog extends Dialog { |
|---|
| 48 | | String message = "", filterPath = ""; //$NON-NLS-1$//$NON-NLS-2$ |
|---|
| 49 | | String directoryPath; |
|---|
| | 42 | public class DirectoryDialog : Dialog { |
|---|
| | 43 | static char[] message = ""; |
|---|
| | 44 | static char[] filterPath = ""; //$NON-NLS-1$//$NON-NLS-2$ |
|---|
| | 45 | static char[] directoryPath; |
|---|
| 50 | 46 | |
|---|
| 51 | 47 | /** |
|---|
| … | … | |
| 62 | 58 | * </ul> |
|---|
| 63 | 59 | */ |
|---|
| 64 | | public DirectoryDialog (Shell parent) { |
|---|
| | 60 | public this (Shell parent) { |
|---|
| 65 | 61 | this (parent, DWT.PRIMARY_MODAL); |
|---|
| 66 | 62 | } |
|---|
| … | … | |
| 90 | 86 | * </ul> |
|---|
| 91 | 87 | */ |
|---|
| 92 | | public DirectoryDialog (Shell parent, int style) { |
|---|
| | 88 | public this (Shell parent, int style) { |
|---|
| 93 | 89 | super (parent, style); |
|---|
| 94 | 90 | checkSubclass (); |
|---|
| 95 | 91 | } |
|---|
| 96 | 92 | |
|---|
| 97 | | int BrowseCallbackProc (int hwnd, int uMsg, int lParam, int lpData) { |
|---|
| | 93 | extern(Windows)static int BrowseCallbackProc (HWND hwnd, uint uMsg, int lParam, int lpData) { |
|---|
| | 94 | DirectoryDialog pThis = cast(DirectoryDialog)cast(void*)lpData; |
|---|
| 98 | 95 | switch (uMsg) { |
|---|
| 99 | 96 | case OS.BFFM_INITIALIZED: |
|---|
| 100 | | if (filterPath !is null && filterPath.length () !is 0) { |
|---|
| | 97 | if (pThis.filterPath !is null && pThis.filterPath.length !is 0) { |
|---|
| 101 | 98 | /* Use the character encoding for the default locale */ |
|---|
| 102 | | TCHAR buffer = new TCHAR (0, filterPath.replace ('/', '\\'), true); |
|---|
| 103 | | OS.SendMessage (hwnd, OS.BFFM_SETSELECTION, 1, buffer); |
|---|
| | 99 | TCHAR[] buffer = StrToTCHARs (0, pThis.filterPath.replace ('/', '\\'), true); |
|---|
| | 100 | OS.SendMessage (hwnd, OS.BFFM_SETSELECTION, 1, buffer.ptr); |
|---|
| 104 | 101 | } |
|---|
| 105 | | if (title !is null && title.length () !is 0) { |
|---|
| | 102 | if (pThis.title !is null && pThis.title.length !is 0) { |
|---|
| 106 | 103 | /* Use the character encoding for the default locale */ |
|---|
| 107 | | TCHAR buffer = new TCHAR (0, title, true); |
|---|
| 108 | | OS.SetWindowText (hwnd, buffer); |
|---|
| | 104 | TCHAR[] buffer = StrToTCHARs (0, pThis.title, true); |
|---|
| | 105 | OS.SetWindowText (hwnd, buffer.ptr); |
|---|
| 109 | 106 | } |
|---|
| 110 | 107 | break; |
|---|
| … | … | |
| 112 | 109 | case OS.BFFM_VALIDATEFAILEDW: |
|---|
| 113 | 110 | /* Use the character encoding for the default locale */ |
|---|
| 114 | | int length = OS.IsUnicode ? OS.wcslen (lParam) : OS.strlen (lParam); |
|---|
| 115 | | TCHAR buffer = new TCHAR (0, length); |
|---|
| 116 | | int byteCount = buffer.length () * TCHAR.sizeof; |
|---|
| 117 | | OS.MoveMemory (buffer, lParam, byteCount); |
|---|
| 118 | | directoryPath = buffer.toString (0, length); |
|---|
| | 111 | // int length = OS.IsUnicode ? OS.wcslen (lParam) : OS.strlen (lParam); |
|---|
| | 112 | // TCHAR buffer = new TCHAR (0, length); |
|---|
| | 113 | // int byteCount = buffer.length * TCHAR.sizeof; |
|---|
| | 114 | // OS.MoveMemory (buffer, lParam, byteCount); |
|---|
| | 115 | // directoryPath = buffer.toString (0, length); |
|---|
| | 116 | pThis.directoryPath = TCHARzToStr( cast(TCHAR*)lParam ); |
|---|
| 119 | 117 | break; |
|---|
| 120 | 118 | default: |
|---|
| … | … | |
| 131 | 129 | * @see #setFilterPath |
|---|
| 132 | 130 | */ |
|---|
| 133 | | public String getFilterPath () { |
|---|
| | 131 | public char[] getFilterPath () { |
|---|
| 134 | 132 | return filterPath; |
|---|
| 135 | 133 | } |
|---|
| … | … | |
| 142 | 140 | * @return the message |
|---|
| 143 | 141 | */ |
|---|
| 144 | | public String getMessage () { |
|---|
| | 142 | public char[] getMessage () { |
|---|
| 145 | 143 | return message; |
|---|
| 146 | 144 | } |
|---|
| … | … | |
| 158 | 156 | * </ul> |
|---|
| 159 | 157 | */ |
|---|
| 160 | | public String open () { |
|---|
| | 158 | public char[] open () { |
|---|
| 161 | 159 | if (OS.IsWinCE) DWT.error (DWT.ERROR_NOT_IMPLEMENTED); |
|---|
| 162 | 160 | |
|---|
| 163 | | int hHeap = OS.GetProcessHeap (); |
|---|
| | 161 | auto hHeap = OS.GetProcessHeap (); |
|---|
| 164 | 162 | |
|---|
| 165 | 163 | /* Get the owner HWND for the dialog */ |
|---|
| 166 | | int hwndOwner = 0; |
|---|
| | 164 | HWND hwndOwner; |
|---|
| 167 | 165 | if (parent !is null) hwndOwner = parent.handle; |
|---|
| 168 | 166 | |
|---|
| 169 | 167 | /* Copy the message to OS memory */ |
|---|
| 170 | | int lpszTitle = 0; |
|---|
| 171 | | if (message.length () !is 0) { |
|---|
| 172 | | String string = message; |
|---|
| | 168 | TCHAR* lpszTitle; |
|---|
| | 169 | if (message.length !is 0) { |
|---|
| | 170 | char[] string = message; |
|---|
| 173 | 171 | if (string.indexOf ('&') !is -1) { |
|---|
| 174 | | int length = string.length (); |
|---|
| | 172 | int length = string.length; |
|---|
| 175 | 173 | char [] buffer = new char [length * 2]; |
|---|
| 176 | 174 | int index = 0; |
|---|
| … | … | |
| 180 | 178 | buffer [index++] = ch; |
|---|
| 181 | 179 | } |
|---|
| 182 | | string = new String (buffer, 0, index); |
|---|
| | 180 | // string = new String (buffer, 0, index); |
|---|
| 183 | 181 | } |
|---|
| 184 | 182 | /* Use the character encoding for the default locale */ |
|---|
| 185 | | TCHAR buffer = new TCHAR (0, string, true); |
|---|
| 186 | | int byteCount = buffer.length () * TCHAR.sizeof; |
|---|
| 187 | | lpszTitle = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); |
|---|
| 188 | | OS.MoveMemory (lpszTitle, buffer, byteCount); |
|---|
| | 183 | TCHAR[] buffer = StrToTCHARs (0, string, true); |
|---|
| | 184 | int byteCount = buffer.length * TCHAR.sizeof; |
|---|
| | 185 | lpszTitle = cast(TCHAR*)OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, byteCount); |
|---|
| | 186 | OS.MoveMemory (lpszTitle, buffer.ptr, byteCount); |
|---|
| 189 | 187 | } |
|---|
| 190 | 188 | |
|---|
| 191 | 189 | /* Create the BrowseCallbackProc */ |
|---|
| 192 | | Callback callback = new Callback (this, "BrowseCallbackProc", 4); //$NON-NLS-1$ |
|---|
| 193 | | int lpfn = callback.getAddress (); |
|---|
| 194 | | if (lpfn is 0) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); |
|---|
| | 190 | /+ Callback callback = new Callback (this, "BrowseCallbackProc", 4); //$NON-NLS-1$ |
|---|
| | 191 | int lpfn = callback.getAddress ();+/ |
|---|
| | 192 | BFFCALLBACK lpfn = &BrowseCallbackProc; |
|---|
| | 193 | if (lpfn is null) DWT.error (DWT.ERROR_NO_MORE_CALLBACKS); |
|---|
| 195 | 194 | |
|---|
| 196 | 195 | /* Make the parent shell be temporary modal */ |
|---|
| … | … | |
| 203 | 202 | |
|---|
| 204 | 203 | directoryPath = null; |
|---|
| 205 | | BROWSEINFO lpbi = new BROWSEINFO (); |
|---|
| | 204 | BROWSEINFO lpbi; |
|---|
| 206 | 205 | lpbi.hwndOwner = hwndOwner; |
|---|
| 207 | 206 | lpbi.lpszTitle = lpszTitle; |
|---|
| 208 | 207 | lpbi.ulFlags = OS.BIF_NEWDIALOGSTYLE | OS.BIF_RETURNONLYFSDIRS | OS.BIF_EDITBOX | OS.BIF_VALIDATE; |
|---|
| 209 | 208 | lpbi.lpfn = lpfn; |
|---|
| | 209 | lpbi.lParam = cast(int)cast(void*)this; |
|---|
| 210 | 210 | /* |
|---|
| 211 | 211 | * Bug in Windows. On some hardware configurations, SHBrowseForFolder() |
|---|
| … | … | |
| 240 | 240 | bool oldRunMessages = display.runMessages; |
|---|
| 241 | 241 | if (OS.COMCTL32_MAJOR < 6) display.runMessages = false; |
|---|
| 242 | | int lpItemIdList = OS.SHBrowseForFolder (lpbi); |
|---|
| | 242 | ITEMIDLIST* lpItemIdList = OS.SHBrowseForFolder (&lpbi); |
|---|
| 243 | 243 | if (OS.COMCTL32_MAJOR < 6) display.runMessages = oldRunMessages; |
|---|
| 244 | 244 | OS.SetErrorMode (oldErrorMode); |
|---|
| … | … | |
| 249 | 249 | } |
|---|
| 250 | 250 | |
|---|
| 251 | | bool success = lpItemIdList !is 0; |
|---|
| | 251 | bool success = lpItemIdList !is null; |
|---|
| 252 | 252 | if (success) { |
|---|
| 253 | 253 | /* Use the character encoding for the default locale */ |
|---|
| 254 | | TCHAR buffer = new TCHAR (0, OS.MAX_PATH); |
|---|
| 255 | | if (OS.SHGetPathFromIDList (lpItemIdList, buffer)) { |
|---|
| 256 | | directoryPath = buffer.toString (0, buffer.strlen ()); |
|---|
| | 254 | TCHAR[OS.MAX_PATH] buffer; |
|---|
| | 255 | if (OS.SHGetPathFromIDList (lpItemIdList, buffer.ptr)) { |
|---|
| | 256 | directoryPath = TCHARzToStr (buffer.ptr); |
|---|
| 257 | 257 | filterPath = directoryPath; |
|---|
| 258 | 258 | } |
|---|
| … | … | |
| 260 | 260 | |
|---|
| 261 | 261 | /* Free the BrowseCallbackProc */ |
|---|
| 262 | | callback.dispose (); |
|---|
| | 262 | // callback.dispose (); |
|---|
| 263 | 263 | |
|---|
| 264 | 264 | /* Free the OS memory */ |
|---|
| 265 | | if (lpszTitle !is 0) OS.HeapFree (hHeap, 0, lpszTitle); |
|---|
| | 265 | if (lpszTitle !is null) OS.HeapFree (hHeap, 0, lpszTitle); |
|---|
| 266 | 266 | |
|---|
| 267 | 267 | /* Free the pointer to the ITEMIDLIST */ |
|---|
| 268 | | int [] ppMalloc = new int [1]; |
|---|
| 269 | | if (OS.SHGetMalloc (ppMalloc) is OS.S_OK) { |
|---|
| | 268 | LPVOID ppMalloc; |
|---|
| | 269 | if (OS.SHGetMalloc (&ppMalloc) is OS.S_OK) { |
|---|
| 270 | 270 | /* void Free (struct IMalloc *this, void *pv); */ |
|---|
| 271 | | OS.VtblCall (5, ppMalloc [0], lpItemIdList); |
|---|
| | 271 | OS.VtblCall (5, ppMalloc , cast(int)lpItemIdList); |
|---|
| 272 | 272 | } |
|---|
| 273 | 273 | |
|---|
| … | … | |
| 298 | 298 | * @param string the filter path |
|---|
| 299 | 299 | */ |
|---|
| 300 | | public void setFilterPath (String string) { |
|---|
| | 300 | public void setFilterPath (char[] string) { |
|---|
| 301 | 301 | filterPath = string; |
|---|
| 302 | 302 | } |
|---|
| … | … | |
| 313 | 313 | * </ul> |
|---|
| 314 | 314 | */ |
|---|
| 315 | | public void setMessage (String string) { |
|---|
| | 315 | public void setMessage (char[] string) { |
|---|
| 316 | 316 | if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
|---|
| 317 | 317 | message = string; |
|---|
| … | … | |
| 319 | 319 | |
|---|
| 320 | 320 | } |
|---|
| 321 | | ++/ |
|---|