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