Changeset 6709 for trunk/src/shell32/brsfolder.c
- Timestamp:
- Sep 15, 2001, 11:26:26 AM (24 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/shell32/brsfolder.c
r6650 r6709 1 /* $Id: brsfolder.c,v 1.4 2001-09-05 13:46:55 bird Exp $ */2 1 #include <stdlib.h> 3 2 #include <string.h> … … 13 12 DEFAULT_DEBUG_CHANNEL(shell); 14 13 15 static HWND 16 static LPBROWSEINFOA 17 static LPITEMIDLIST 14 static HWND hwndTreeView; 15 static LPBROWSEINFOA lpBrowseInfo; 16 static LPITEMIDLIST pidlRet; 18 17 19 18 static void FillTreeView(LPSHELLFOLDER lpsf, LPITEMIDLIST lpifq, HTREEITEM hParent); … … 21 20 static void InitializeTreeView(HWND hwndParent, LPCITEMIDLIST root) 22 21 { 23 HIMAGELISThImageList;24 IShellFolder *lpsf;25 HRESULThr;26 27 28 29 30 31 32 33 34 35 36 22 HIMAGELIST hImageList; 23 IShellFolder * lpsf; 24 HRESULT hr; 25 26 hwndTreeView = GetDlgItem (hwndParent, IDD_TREEVIEW); 27 Shell_GetImageList(NULL, &hImageList); 28 29 TRACE("dlg=%x tree=%x\n", hwndParent, hwndTreeView ); 30 31 if (hImageList && hwndTreeView) 32 { TreeView_SetImageList(hwndTreeView, hImageList, 0); 33 } 34 35 /* so far, this method doesn't work (still missing the upper level), keep the old way */ 37 36 #if 0 38 39 40 41 IShellFolder *lpsfdesktop;42 43 44 45 46 47 48 37 if (root == NULL) { 38 hr = SHGetDesktopFolder(&lpsf); 39 } else { 40 IShellFolder * lpsfdesktop; 41 42 hr = SHGetDesktopFolder(&lpsfdesktop); 43 if (SUCCEEDED(hr)) { 44 hr = IShellFolder_BindToObject(lpsfdesktop, root, 0,(REFIID)&IID_IShellFolder,(LPVOID *)&lpsf); 45 IShellFolder_Release(lpsfdesktop); 46 } 47 } 49 48 #else 50 49 hr = SHGetDesktopFolder(&lpsf); 51 50 #endif 52 51 53 54 55 56 57 58 59 60 61 52 if (SUCCEEDED(hr) && hwndTreeView) 53 { TreeView_DeleteAllItems(hwndTreeView); 54 FillTreeView(lpsf, NULL, TVI_ROOT); 55 } 56 57 if (SUCCEEDED(hr)) 58 { IShellFolder_Release(lpsf); 59 } 60 TRACE("done\n"); 62 61 } 63 62 64 63 static int GetIcon(LPITEMIDLIST lpi, UINT uFlags) 65 { 66 67 64 { SHFILEINFOA sfi; 65 SHGetFileInfoA((LPCSTR)lpi,0,&sfi, sizeof(SHFILEINFOA), uFlags); 66 return sfi.iIcon; 68 67 } 69 68 70 69 static void GetNormalAndSelectedIcons(LPITEMIDLIST lpifq,LPTVITEMA lpTV_ITEM) 71 { 72 73 74 75 76 70 { TRACE("%p %p\n",lpifq, lpTV_ITEM); 71 72 lpTV_ITEM->iImage = GetIcon(lpifq, SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON); 73 lpTV_ITEM->iSelectedImage = GetIcon(lpifq, SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON); 74 75 return; 77 76 } 78 77 … … 86 85 static BOOL GetName(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi, DWORD dwFlags, LPSTR lpFriendlyName) 87 86 { 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 87 BOOL bSuccess=TRUE; 88 STRRET str; 89 90 TRACE("%p %p %lx %p\n", lpsf, lpi, dwFlags, lpFriendlyName); 91 if (SUCCEEDED(IShellFolder_GetDisplayNameOf(lpsf, lpi, dwFlags, &str))) 92 { 93 if(FAILED(StrRetToStrNA (lpFriendlyName, MAX_PATH, &str, lpi))) 94 { 95 bSuccess = FALSE; 96 } 97 } 98 else 99 bSuccess = FALSE; 100 101 TRACE("-- %s\n",lpFriendlyName); 102 return bSuccess; 104 103 } 105 104 106 105 static void FillTreeView(IShellFolder * lpsf, LPITEMIDLIST pidl, HTREEITEM hParent) 107 106 { 108 TVITEMAtvi;109 TVINSERTSTRUCTAtvins;110 HTREEITEMhPrev = 0;111 LPENUMIDLISTlpe=0;112 LPITEMIDLISTpidlTemp=0;113 LPTV_ITEMDATAlptvid=0;114 ULONGulFetched;115 HRESULThr;116 charszBuff[256];117 HWNDhwnd=GetParent(hwndTreeView);118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 lptvid->lpi= ILClone(pidlTemp);151 lptvid->lpifq= ILCombine(pidl, pidlTemp);152 153 154 155 156 157 158 159 160 161 162 163 164 165 107 TVITEMA tvi; 108 TVINSERTSTRUCTA tvins; 109 HTREEITEM hPrev = 0; 110 LPENUMIDLIST lpe=0; 111 LPITEMIDLIST pidlTemp=0; 112 LPTV_ITEMDATA lptvid=0; 113 ULONG ulFetched; 114 HRESULT hr; 115 char szBuff[256]; 116 HWND hwnd=GetParent(hwndTreeView); 117 118 TRACE("%p %p %x\n",lpsf, pidl, (INT)hParent); 119 SetCapture(GetParent(hwndTreeView)); 120 SetCursor(LoadCursorA(0, IDC_WAITA)); 121 122 hr=IShellFolder_EnumObjects(lpsf,hwnd, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS,&lpe); 123 124 if (SUCCEEDED(hr)) 125 { while (NOERROR == IEnumIDList_Next(lpe,1,&pidlTemp,&ulFetched)) 126 { ULONG ulAttrs = SFGAO_HASSUBFOLDER | SFGAO_FOLDER; 127 IShellFolder_GetAttributesOf(lpsf, 1, &pidlTemp, &ulAttrs); 128 if (ulAttrs & (SFGAO_HASSUBFOLDER | SFGAO_FOLDER)) 129 { if (ulAttrs & SFGAO_FOLDER) 130 { tvi.mask = TVIF_TEXT | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_PARAM; 131 132 if (ulAttrs & SFGAO_HASSUBFOLDER) 133 { tvi.cChildren=1; 134 tvi.mask |= TVIF_CHILDREN; 135 } 136 137 if (!( lptvid = (LPTV_ITEMDATA)SHAlloc(sizeof(TV_ITEMDATA)))) 138 goto Done; 139 140 if (!GetName(lpsf, pidlTemp, SHGDN_NORMAL, szBuff)) 141 goto Done; 142 143 tvi.pszText = szBuff; 144 tvi.cchTextMax = MAX_PATH; 145 tvi.lParam = (LPARAM)lptvid; 146 147 IShellFolder_AddRef(lpsf); 148 lptvid->lpsfParent = lpsf; 149 lptvid->lpi = ILClone(pidlTemp); 150 lptvid->lpifq = ILCombine(pidl, pidlTemp); 151 GetNormalAndSelectedIcons(lptvid->lpifq, &tvi); 152 153 tvins.DUMMYUNIONNAME.item = tvi; 154 tvins.hInsertAfter = hPrev; 155 tvins.hParent = hParent; 156 157 hPrev = (HTREEITEM)TreeView_InsertItemA (hwndTreeView, &tvins); 158 159 } 160 } 161 SHFree(pidlTemp); /* Finally, free the pidl that the shell gave us... */ 162 pidlTemp=0; 163 } 164 } 166 165 167 166 Done: 168 169 170 171 172 173 174 167 ReleaseCapture(); 168 SetCursor(LoadCursorA(0, IDC_ARROWA)); 169 170 if (lpe) 171 IEnumIDList_Release(lpe); 172 if (pidlTemp ) 173 SHFree(pidlTemp); 175 174 } 176 175 177 176 static LRESULT MsgNotify(HWND hWnd, UINT CtlID, LPNMHDR lpnmh) 178 { 179 NMTREEVIEWA*pnmtv = (NMTREEVIEWA *)lpnmh;180 LPTV_ITEMDATAlptvid; /* Long pointer to TreeView item data */181 IShellFolder *lpsf2=0;182 183 184 185 186 187 188 switch (pnmtv->hdr.code) 189 190 191 192 193 SHFree(lptvid->lpi); 194 SHFree(lptvid->lpifq); 195 SHFree(lptvid); 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 177 { 178 NMTREEVIEWA *pnmtv = (NMTREEVIEWA *)lpnmh; 179 LPTV_ITEMDATA lptvid; /* Long pointer to TreeView item data */ 180 IShellFolder * lpsf2=0; 181 182 183 TRACE("%x %x %p msg=%x\n", hWnd, CtlID, lpnmh, pnmtv->hdr.code); 184 185 switch (pnmtv->hdr.idFrom) 186 { case IDD_TREEVIEW: 187 switch (pnmtv->hdr.code) 188 { case TVN_DELETEITEMA: 189 { FIXME("TVN_DELETEITEMA\n"); 190 lptvid=(LPTV_ITEMDATA)pnmtv->itemOld.lParam; 191 IShellFolder_Release(lptvid->lpsfParent); 192 SHFree(lptvid->lpi); 193 SHFree(lptvid->lpifq); 194 SHFree(lptvid); 195 } 196 break; 197 198 case TVN_ITEMEXPANDINGA: 199 { FIXME("TVN_ITEMEXPANDINGA\n"); 200 if ((pnmtv->itemNew.state & TVIS_EXPANDEDONCE)) 201 break; 202 203 lptvid=(LPTV_ITEMDATA)pnmtv->itemNew.lParam; 204 if (SUCCEEDED(IShellFolder_BindToObject(lptvid->lpsfParent, lptvid->lpi,0,(REFIID)&IID_IShellFolder,(LPVOID *)&lpsf2))) 205 { FillTreeView( lpsf2, lptvid->lpifq, pnmtv->itemNew.hItem ); 206 } 207 TreeView_SortChildren(hwndTreeView, pnmtv->itemNew.hItem, FALSE); 208 } 209 break; 210 case TVN_SELCHANGEDA: 211 lptvid=(LPTV_ITEMDATA)pnmtv->itemNew.lParam; 212 pidlRet = lptvid->lpifq; 213 if (lpBrowseInfo->lpfn) 214 (lpBrowseInfo->lpfn)(hWnd, BFFM_SELCHANGED, (LPARAM)pidlRet, lpBrowseInfo->lParam); 215 break; 216 217 default: 218 FIXME("unhandled (%d)\n", pnmtv->hdr.code); 219 break; 220 } 221 break; 222 223 default: 224 break; 225 } 226 227 return 0; 229 228 } 230 229 … … 234 233 */ 235 234 static BOOL WINAPI BrsFolderDlgProc( HWND hWnd, UINT msg, WPARAM wParam, 236 235 LPARAM lParam ) 237 236 { TRACE("hwnd=%i msg=%i 0x%08x 0x%08lx\n", hWnd, msg, wParam, lParam ); 238 237 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 238 switch(msg) 239 { case WM_INITDIALOG: 240 pidlRet = NULL; 241 lpBrowseInfo = (LPBROWSEINFOA) lParam; 242 if (lpBrowseInfo->ulFlags & ~(BIF_STATUSTEXT)) 243 FIXME("flags %x not implemented\n", lpBrowseInfo->ulFlags & ~(BIF_STATUSTEXT)); 244 if (lpBrowseInfo->lpszTitle) { 245 SetWindowTextA(GetDlgItem(hWnd, IDD_TITLE), lpBrowseInfo->lpszTitle); 246 } else { 247 ShowWindow(GetDlgItem(hWnd, IDD_TITLE), SW_HIDE); 248 } 249 if (!(lpBrowseInfo->ulFlags & BIF_STATUSTEXT)) 250 ShowWindow(GetDlgItem(hWnd, IDD_STATUS), SW_HIDE); 251 252 if ( lpBrowseInfo->pidlRoot ) 253 FIXME("root is desktop\n"); 254 255 InitializeTreeView( hWnd, lpBrowseInfo->pidlRoot ); 256 257 if (lpBrowseInfo->lpfn) { 258 (lpBrowseInfo->lpfn)(hWnd, BFFM_INITIALIZED, 0, lpBrowseInfo->lParam); 260 259 #ifndef __WIN32OS2__ 261 260 (lpBrowseInfo->lpfn)(hWnd, BFFM_SELCHANGED, 0/*FIXME*/, lpBrowseInfo->lParam); 262 261 #endif 263 } 264 265 return TRUE; 266 267 case WM_NOTIFY: 268 MsgNotify( hWnd, (UINT)wParam, (LPNMHDR)lParam); 269 break; 270 271 case WM_COMMAND: 272 switch (wParam) 273 { case IDOK: 274 pdump ( pidlRet ); 275 SHGetPathFromIDListA(pidlRet, lpBrowseInfo->pszDisplayName); 276 EndDialog(hWnd, (DWORD) ILClone(pidlRet)); 277 return TRUE; 278 279 case IDCANCEL: 280 EndDialog(hWnd, 0); 281 return TRUE; 282 break; 283 } 284 break; 285 case BFFM_SETSTATUSTEXTA: 286 TRACE("Set status %s\n", debugstr_a((LPSTR)lParam)); 287 SetWindowTextA(GetDlgItem(hWnd, IDD_STATUS), (LPSTR)lParam); 288 break; 289 case BFFM_SETSTATUSTEXTW: 290 TRACE("Set status %s\n", debugstr_w((LPWSTR)lParam)); 291 SetWindowTextW(GetDlgItem(hWnd, IDD_STATUS), (LPWSTR)lParam); 292 break; 293 case BFFM_ENABLEOK: 294 TRACE("Enable %ld\n", lParam); 295 EnableWindow(GetDlgItem(hWnd, 1), (lParam)?TRUE:FALSE); 296 break; 297 case BFFM_SETSELECTIONA: 298 if (wParam) 299 TRACE("Set selection %s\n", debugstr_a((LPSTR)lParam)); 300 else 301 TRACE("Set selection %p\n", (void*)lParam); 302 break; 303 case BFFM_SETSELECTIONW: 304 if (wParam) 305 TRACE("Set selection %s\n", debugstr_w((LPWSTR)lParam)); 306 else 307 TRACE("Set selection %p\n", (void*)lParam); 308 break; 309 } 310 return FALSE; 262 } 263 264 return TRUE; 265 266 case WM_NOTIFY: 267 MsgNotify( hWnd, (UINT)wParam, (LPNMHDR)lParam); 268 break; 269 270 case WM_COMMAND: 271 switch (wParam) 272 { case IDOK: 273 pdump ( pidlRet ); 274 SHGetPathFromIDListA(pidlRet, lpBrowseInfo->pszDisplayName); 275 EndDialog(hWnd, (DWORD) ILClone(pidlRet)); 276 return TRUE; 277 278 case IDCANCEL: 279 EndDialog(hWnd, 0); 280 return TRUE; 281 break; 282 } 283 break; 284 case BFFM_SETSTATUSTEXTA: 285 TRACE("Set status %s\n", debugstr_a((LPSTR)lParam)); 286 SetWindowTextA(GetDlgItem(hWnd, IDD_STATUS), (LPSTR)lParam); 287 break; 288 case BFFM_SETSTATUSTEXTW: 289 TRACE("Set status %s\n", debugstr_w((LPWSTR)lParam)); 290 SetWindowTextW(GetDlgItem(hWnd, IDD_STATUS), (LPWSTR)lParam); 291 break; 292 case BFFM_ENABLEOK: 293 TRACE("Enable %ld\n", lParam); 294 EnableWindow(GetDlgItem(hWnd, 1), (lParam)?TRUE:FALSE); 295 break; 296 case BFFM_SETSELECTIONA: 297 if (wParam) { 298 TRACE("Set selection %s\n", debugstr_a((LPSTR)lParam)); 299 } 300 else { 301 TRACE("Set selection %p\n", (void*)lParam); 302 } 303 break; 304 case BFFM_SETSELECTIONW: 305 if (wParam) { 306 TRACE("Set selection %s\n", debugstr_w((LPWSTR)lParam)); 307 } 308 else { 309 TRACE("Set selection %p\n", (void*)lParam); 310 } 311 break; 312 } 313 return FALSE; 311 314 } 312 315 … … 317 320 LPITEMIDLIST WINAPI SHBrowseForFolderA (LPBROWSEINFOA lpbi) 318 321 { 319 TRACE("(%p{lpszTitle=%s,owner=%i})\n", 320 321 322 323 "SHBRSFORFOLDER_MSGBOX", 324 325 326 } 322 TRACE("(%p{lpszTitle=%s,owner=%i})\n", 323 lpbi, debugstr_a(lpbi->lpszTitle), lpbi->hwndOwner); 324 325 return (LPITEMIDLIST) DialogBoxParamA( shell32_hInstance, 326 "SHBRSFORFOLDER_MSGBOX", 327 lpbi->hwndOwner, 328 BrsFolderDlgProc, (INT)lpbi ); 329 }
Note:
See TracChangeset
for help on using the changeset viewer.