Index: src/ch/DirTreeCtrl.cpp =================================================================== diff -u -rc435ab507c8b8280264188b49e9ada56d46c0261 -r8068e0c351055554340ac9755d1bc846893bf2b8 --- src/ch/DirTreeCtrl.cpp (.../DirTreeCtrl.cpp) (revision c435ab507c8b8280264188b49e9ada56d46c0261) +++ src/ch/DirTreeCtrl.cpp (.../DirTreeCtrl.cpp) (revision 8068e0c351055554340ac9755d1bc846893bf2b8) @@ -57,38 +57,33 @@ LPITEMIDLIST CreatePidl(UINT cbSize) { - LPMALLOC lpMalloc; - HRESULT hr; - LPITEMIDLIST pidl=NULL; + LPMALLOC lpMalloc = nullptr; - hr=SHGetMalloc(&lpMalloc); + HRESULT hr=SHGetMalloc(&lpMalloc); + if (FAILED(hr) || !lpMalloc) + return nullptr; - if (FAILED(hr)) - return 0; - - pidl=(LPITEMIDLIST)lpMalloc->Alloc(cbSize); - + LPITEMIDLIST pidl = (LPITEMIDLIST)lpMalloc->Alloc(cbSize); if (pidl) memset(pidl, 0, cbSize); // zero-init for external task alloc - if (lpMalloc) lpMalloc->Release(); + lpMalloc->Release(); return pidl; } void FreePidl(LPITEMIDLIST lpiidl) { - LPMALLOC lpMalloc; - HRESULT hr; - - hr=SHGetMalloc(&lpMalloc); - - if (FAILED(hr)) + if(!lpiidl) return; - lpMalloc->Free(lpiidl); + LPMALLOC lpMalloc = nullptr; + HRESULT hResult = SHGetMalloc(&lpMalloc); + if(SUCCEEDED(hResult) && lpMalloc) + lpMalloc->Free(lpiidl); - if (lpMalloc) lpMalloc->Release(); + if (lpMalloc) + lpMalloc->Release(); } LPITEMIDLIST ConcatPidls(LPCITEMIDLIST pidl1, LPCITEMIDLIST pidl2) @@ -97,7 +92,7 @@ UINT cb1; UINT cb2; - if (pidl1) //May be NULL + if (pidl1) //May be nullptr cb1 = GetSize(pidl1) - sizeof(pidl1->mkid.cb); else cb1 = 0; @@ -166,46 +161,14 @@ return bSuccess; } -LPITEMIDLIST GetFullyQualPidl(LPSHELLFOLDER lpsf, LPITEMIDLIST lpi) -{ - TCHAR szBuff[MAX_PATH]; - LPSHELLFOLDER lpsfDeskTop; - LPITEMIDLIST lpifq; - ULONG ulEaten, ulAttribs; - HRESULT hr; - - if (!GetName(lpsf, lpi, SHGDN_FORPARSING, szBuff)) - return NULL; - - hr=SHGetDesktopFolder(&lpsfDeskTop); - - if (FAILED(hr)) - return NULL; - - CT2W ct2w(szBuff); - hr=lpsfDeskTop->ParseDisplayName(NULL, - NULL, - ct2w, - &ulEaten, - &lpifq, - &ulAttribs); - - lpsfDeskTop->Release(); - - if (FAILED(hr)) - return NULL; - - return lpifq; -} - ///////////////////////////////////////////////////////////////////////////// // CDirTreeCtrl CDirTreeCtrl::CDirTreeCtrl() { - m_hDrives=NULL; - m_hNetwork=NULL; - m_hImageList=NULL; + m_hDrives=nullptr; + m_hNetwork=nullptr; + m_hImageList=nullptr; m_bIgnore=false; m_iEditType=0; } @@ -233,7 +196,6 @@ // CDirTreeCtrl message handlers ///////////////////////////////////////////////////////////////////////////// -// inicjalizacja void CDirTreeCtrl::PreSubclassWindow() { // InitControl(); // here's not needed (strange ??) @@ -266,47 +228,53 @@ PostMessage(WM_INITCONTROL); } -///////////////////////////////////////////////////////////////////////////// -// wstawia ikon� pulpitu +int CDirTreeCtrl::GetSysIconIndex(LPITEMIDLIST item, bool bOpenIcon) +{ + if(item == nullptr) + return -1; + + SHFILEINFO sfi { 0 }; + sfi.iIcon = -1; + SHGetFileInfo((LPCTSTR)item, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | (bOpenIcon ? SHGFI_OPENICON : 0)); + + return sfi.iIcon; +} + HTREEITEM CDirTreeCtrl::InsertDesktopItem() { // clear treectrl - it shouldn't be more than 1 desktop if (!DeleteAllItems()) - return NULL; + return nullptr; // clear vars - m_hDrives=NULL; - m_hNetwork=NULL; + m_hDrives=nullptr; + m_hNetwork=nullptr; // fill with items - SHFILEINFO sfi; - LPSHELLFOLDER lpsfDesktop; - LPITEMIDLIST lpiidlDesktop; + LPSHELLFOLDER lpsfDesktop = nullptr; + LPITEMIDLIST lpiidlDesktop = nullptr; if (FAILED(SHGetDesktopFolder(&lpsfDesktop))) - return NULL; + return nullptr; if (SHGetSpecialFolderLocation(this->GetSafeHwnd(), CSIDL_DESKTOP, &lpiidlDesktop) != NOERROR) - return NULL; + return nullptr; // add desktop - TVITEM tvi; - TVINSERTSTRUCT tvis; + TVITEM tvi = { 0 }; + TVINSERTSTRUCT tvis = { 0 }; TCHAR szText[_MAX_PATH]; - _SHELLITEMDATA *psid=new _SHELLITEMDATA; + _SHELLITEMDATA *psid = new _SHELLITEMDATA; psid->lpiidl=lpiidlDesktop; psid->lpsf=lpsfDesktop; - psid->lpiidlRelative=NULL; - psid->lpsfParent=NULL; + psid->lpiidlRelative=nullptr; + psid->lpsfParent=nullptr; tvi.mask=TVIF_CHILDREN | TVIF_IMAGE | TVIF_SELECTEDIMAGE | TVIF_TEXT | TVIF_PARAM; if (!GetName(lpsfDesktop, lpiidlDesktop, 0/*SHGDN_INCLUDE_NONFILESYS*/, szText)) lstrcpy(szText, _T("???")); tvi.pszText=szText; - sfi.iIcon=-1; - SHGetFileInfo((LPCTSTR)lpiidlDesktop, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON); - tvi.iImage=sfi.iIcon; - sfi.iIcon=-1; - SHGetFileInfo((LPCTSTR)lpiidlDesktop, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON); - tvi.iSelectedImage=sfi.iIcon; + + tvi.iImage = GetSysIconIndex(lpiidlDesktop, false); + tvi.iSelectedImage = GetSysIconIndex(lpiidlDesktop, true); tvi.cChildren=1; tvi.lParam=reinterpret_cast(psid); @@ -336,19 +304,17 @@ // enables image list, ... void CDirTreeCtrl::OnDestroy() { - SetImageList(NULL, LVSIL_SMALL); + SetImageList(nullptr, LVSIL_SMALL); CTreeCtrl::OnDestroy(); } //////////////////////////////////////////////////////////////////////////// // compares two items int CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM/* lParamSort*/) { - // je�li si� nie da - if (lParam1 == NULL || lParam2 == NULL) + if (lParam1 == 0 || lParam2 == 0) return 0; - // normalne przetwarzanie SHELLITEMDATA* psidl1=(SHELLITEMDATA*)lParam1, *psidl2=(SHELLITEMDATA*)lParam2; LPSHELLFOLDER lpsf; @@ -373,9 +339,10 @@ bSilent=m_bIgnoreShellDialogs; // get the desktop interface and id's of list for net neigh. and my computer - LPSHELLFOLDER lpsfDesktop=NULL; - LPITEMIDLIST lpiidlDrives=NULL; - LPITEMIDLIST lpiidlNetwork=NULL; + LPSHELLFOLDER lpsfDesktop = nullptr; + LPITEMIDLIST lpiidlDrives = nullptr; + LPITEMIDLIST lpiidlNetwork = nullptr; + HRESULT hResult = S_OK; if (hParent == GetRootItem()) { @@ -387,27 +354,27 @@ } // shell allocator - LPMALLOC lpm = NULL; + LPMALLOC lpm = nullptr; if(SUCCEEDED(hResult)) hResult = SHGetMalloc(&lpm); // enumerate child items for lpsf - LPENUMIDLIST lpeid = NULL; + LPENUMIDLIST lpeid = nullptr; if(SUCCEEDED(hResult)) - hResult = lpsf->EnumObjects(bSilent ? NULL : GetParent()->GetSafeHwnd(), SHCONTF_FOLDERS | SHCONTF_INCLUDEHIDDEN, &lpeid); + hResult = lpsf->EnumObjects(bSilent ? nullptr : GetParent()->GetSafeHwnd(), SHCONTF_FOLDERS | SHCONTF_INCLUDEHIDDEN, &lpeid); bool bFound=false; if(SUCCEEDED(hResult)) { - LPITEMIDLIST lpiidl; - SHFILEINFO sfi; - ULONG ulAttrib; - TVITEM tvi; - TVINSERTSTRUCT tvis; - _SHELLITEMDATA *psid; - TCHAR szText[_MAX_PATH]; - HTREEITEM hCurrent=NULL; - while (lpeid->Next(1, &lpiidl, NULL) == NOERROR) + LPITEMIDLIST lpiidl = nullptr; + ULONG ulAttrib = 0; + TVITEM tvi = { 0 }; + TVINSERTSTRUCT tvis = { 0 }; + _SHELLITEMDATA *psid = nullptr; + TCHAR szText[ _MAX_PATH ]; + HTREEITEM hCurrent = nullptr; + + while (lpeid->Next(1, &lpiidl, nullptr) == NOERROR) { // filer what has been found ulAttrib=SFGAO_FOLDER | SFGAO_HASSUBFOLDER | SFGAO_FILESYSANCESTOR | SFGAO_FILESYSTEM; @@ -419,7 +386,7 @@ // it's time to add everything psid=new _SHELLITEMDATA; - lpsf->BindToObject(lpiidl, NULL, IID_IShellFolder, (void**)&psid->lpsf); + lpsf->BindToObject(lpiidl, nullptr, IID_IShellFolder, (void**)&psid->lpsf); psid->lpiidl=ConcatPidls(lpidl, lpiidl); psid->lpiidlRelative=CopyITEMID(lpm, lpiidl); psid->lpsfParent=lpsf; @@ -428,20 +395,16 @@ if (!GetName(lpsf, lpiidl, SHGDN_INFOLDER/* | SHGDN_INCLUDE_NONFILESYS*/, szText)) lstrcpy(szText, _T("???")); tvi.pszText=szText; - sfi.iIcon=-1; - SHGetFileInfo((LPCTSTR)psid->lpiidl, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON); - tvi.iImage=sfi.iIcon; - sfi.iIcon=-1; - SHGetFileInfo((LPCTSTR)psid->lpiidl, 0, &sfi, sizeof(SHFILEINFO), SHGFI_PIDL | SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_OPENICON); - tvi.iSelectedImage=sfi.iIcon; + tvi.iImage = GetSysIconIndex(psid->lpiidl, false); + tvi.iSelectedImage = GetSysIconIndex(psid->lpiidl, false); tvi.cChildren=(ulAttrib & SFGAO_HASSUBFOLDER); tvi.lParam=reinterpret_cast(psid); tvis.hParent=hParent; tvis.item=tvi; hCurrent=InsertItem(&tvis); - if (hParent == GetRootItem()) + if (hParent == GetRootItem() && lpsfDesktop) { // if this is My computer or net. neigh. - it's better to remember the handles // compare psid->lpiidl and (lpiidlDrives & lpiidlNetwork) @@ -463,22 +426,22 @@ if(lpm) lpm->Release(); - // sortuj + // sort if(SUCCEEDED(hResult)) { if(bFound) { - TVSORTCB tvscb; + TVSORTCB tvscb = { 0 }; tvscb.hParent=hParent; tvscb.lpfnCompare=&CompareFunc; - tvscb.lParam=NULL; + tvscb.lParam = 0; if (!SortChildrenCB(&tvscb)) TRACE("SortChildren failed\n"); } else { // some items has + and some not - correction - TVITEM tvi; + TVITEM tvi = { 0 }; tvi.mask=TVIF_HANDLE | TVIF_CHILDREN; tvi.hItem=hParent; if (GetItem(&tvi) && tvi.cChildren == 1) @@ -501,7 +464,7 @@ case TVE_EXPAND: { // get the item's data - TVITEM tvi; + TVITEM tvi = { 0 }; tvi.mask=TVIF_PARAM | TVIF_STATE; tvi.hItem=hItem; tvi.stateMask=TVIS_EXPANDEDONCE | TVIS_SELECTED | TVIS_EXPANDED; @@ -512,7 +475,7 @@ return true; // Fill node before normal expanding - SHELLITEMDATA* psid; + SHELLITEMDATA* psid = nullptr; if (GetItemStruct(hItem, &psid)) { if(FAILED(FillNode(hItem, psid->lpsf, psid->lpiidl, true))) @@ -526,8 +489,6 @@ EnsureVisible(hItem); SelectItem(hItem); return Expand(hItem, TVE_EXPAND) != 0; - - break; } default: return Expand(hItem, nCode) != 0; @@ -573,7 +534,7 @@ if (ItemHasChildren(pNMTreeView->itemNew.hItem)) { HTREEITEM hItem; - while ((hItem=GetChildItem(pNMTreeView->itemNew.hItem)) != NULL) + while ((hItem=GetChildItem(pNMTreeView->itemNew.hItem)) != nullptr) DeleteItem(hItem); } @@ -606,15 +567,15 @@ // returns path associated with an item bool CDirTreeCtrl::GetPath(HTREEITEM hItem, LPTSTR pszPath) { - TVITEM tvi; + TVITEM tvi = { 0 }; tvi.mask=TVIF_HANDLE | TVIF_PARAM; tvi.hItem=hItem; if (GetItem(&tvi)) { // item data _SHELLITEMDATA* psid=reinterpret_cast<_SHELLITEMDATA*>(tvi.lParam); - if (psid == NULL) + if (psid == nullptr) return false; // desktop interface @@ -655,7 +616,7 @@ return SetLocalPath(lpszPath); else { - // we don't look in net neighbourhood for speed reasons + // we don't look in net neighborhood for speed reasons EnsureVisible(m_hNetwork); // SelectItem(m_hNetwork); // ExpandItem(m_hNetwork, TVE_EXPAND); @@ -681,7 +642,7 @@ ExpandItem(hFound, TVE_EXPAND); } - return hFound != NULL; + return hFound != nullptr; } /////////////////////////////////////////////////////////////////////////// @@ -690,13 +651,13 @@ HTREEITEM CDirTreeCtrl::RegularSelect(HTREEITEM hStart, LPCTSTR lpszPath) { // some interfaces - _SHELLITEMDATA* psid; + _SHELLITEMDATA* psid = nullptr; TCHAR szPath[_MAX_PATH]; - TVITEM tvi; + TVITEM tvi = { 0 }; // traverse the child items of my computer - HTREEITEM hItem=GetChildItem(hStart), hLast=NULL; - while (hItem != NULL) + HTREEITEM hItem=GetChildItem(hStart), hLast=nullptr; + while (hItem != nullptr) { tvi.mask=TVIF_HANDLE | TVIF_PARAM; tvi.hItem=hItem; @@ -726,48 +687,7 @@ // return what has been found return hLast; } -//////////////////////////////////////////////////////////////////////////// -// helper - finds comp in a network that matches the path. Skips all the -// workgroups, network names, ... -/* -HTREEITEM CDirTreeCtrl::TraverseNetNode(HTREEITEM hItem, LPCTSTR lpszPath, LPTSTR lpszBuffer) -{ - // start with 1st chil item - HTREEITEM hNext=GetChildItem(hItem); - NETRESOURCE *pnet; - while (hNext) - { - // get NETRESOURCE structure - is this a server ? - if (GetItemShellData(hNext, SHGDFIL_NETRESOURCE, lpszBuffer, 2048)) - { - // got NETRESOURCE - pnet=(NETRESOURCE*)lpszBuffer; - - // is the path contained - if (ComparePaths(lpszPath, pnet->lpRemoteName)) - return hNext; // found what's needed - - if (pnet->dwDisplayType != RESOURCEDISPLAYTYPE_SERVER) - { - // expand - if (!ExpandItem(hNext, TVE_EXPAND)) - return NULL; - - // recurse - HTREEITEM hFound; - if ( (hFound=TraverseNetNode(hNext, lpszPath, lpszBuffer)) != NULL) - return hFound; // if found - return, if not - continue search - } - } - - // next item to check. - hNext=GetNextSiblingItem(hNext); - } - - return NULL; // nothing has been found -} -*/ //////////////////////////////////////////////////////////////////////////// // compares two paths - if one is contained in another (to the first '\\' or '/' bool CDirTreeCtrl::ComparePaths(LPCTSTR lpszFull, LPCTSTR lpszPartial) @@ -776,14 +696,14 @@ strFnd.MakeUpper(); strFnd.TrimRight(_T("\\/")); - // make uppercas the source string, cut before nearest \\ or / after strFnd.GetLength + // make uppercase the source string, cut before nearest \\ or / after strFnd.GetLength strSrc.MakeUpper(); - // find out the position of a nearest / lub '\\' - int iLen=strFnd.GetLength(), iPos; + // find out the position of a nearest / or '\\' + int iLen=strFnd.GetLength(); if (strSrc.GetLength() >= iLen) { - iPos=strSrc.Mid(iLen).FindOneOf(_T("\\/")); + int iPos=strSrc.Mid(iLen).FindOneOf(_T("\\/")); if (iPos != -1) strSrc=strSrc.Left(iPos+iLen); @@ -798,7 +718,7 @@ bool CDirTreeCtrl::GetItemInfoTip(HTREEITEM hItem, CString* pTip) { _SHELLITEMDATA* psid=(_SHELLITEMDATA*)GetItemData(hItem); - if (psid == NULL || psid->lpiidlRelative == NULL || psid->lpsfParent == NULL) + if (psid == nullptr || psid->lpiidlRelative == nullptr || psid->lpsfParent == nullptr) return false; // get interface @@ -817,7 +737,6 @@ // copy with a conversion *pTip=(const WCHAR *)pszTip; - // uwolnij pami�� skojarzon� z pszTip LPMALLOC lpm; if (SHGetMalloc(&lpm) == NOERROR) { @@ -834,8 +753,8 @@ // better exchange for SHGetDataFromIDList bool CDirTreeCtrl::GetItemShellData(HTREEITEM hItem, int nFormat, PVOID pBuffer, int iSize) { - PSHELLITEMDATA psid; - if (!GetItemStruct(hItem, &psid) || psid->lpsfParent == NULL || psid->lpiidlRelative == NULL) + PSHELLITEMDATA psid = nullptr; + if (!GetItemStruct(hItem, &psid) || psid->lpsfParent == nullptr || psid->lpiidlRelative == nullptr) return false; return SHGetDataFromIDList(psid->lpsfParent, psid->lpiidlRelative, nFormat, pBuffer, iSize) == NOERROR; @@ -849,21 +768,21 @@ if(!ppsid) return false; *ppsid=(PSHELLITEMDATA)GetItemData(hItem); - return *ppsid != NULL; + return *ppsid != nullptr; } HTREEITEM CDirTreeCtrl::InsertNewFolder(HTREEITEM hParent, LPCTSTR /*lpszNewFolder*/) { // check if HTREEITEM has an associated path TCHAR szPath[_MAX_PATH]; if (!GetPath(hParent, szPath)) - return NULL; + return nullptr; // focus SetFocus(); // if has child items - enumerate - TVITEM tvi; + TVITEM tvi = { 0 }; tvi.mask=TVIF_HANDLE | TVIF_STATE | TVIF_CHILDREN; tvi.hItem=hParent; tvi.stateMask=TVIS_EXPANDED; @@ -874,7 +793,7 @@ TRACE("%lu child items\n", tvi.cChildren); } - // if hParent doesn't have any chilren - add + to make it look like it hastak, aby wydawa�o si�, �e ma + // if hParent doesn't have any chilren - add + to make it look like it has if (!ItemHasChildren(hParent)) { tvi.mask=TVIF_HANDLE | TVIF_CHILDREN; @@ -897,7 +816,7 @@ tvis.item.iSelectedImage=-1; tvis.item.pszText=pszPath; tvis.item.cchTextMax=lstrlen(tvis.item.pszText); - tvis.item.lParam=NULL; + tvis.item.lParam = 0; HTREEITEM hRes=InsertItem(&tvis); @@ -911,8 +830,8 @@ { m_iEditType=1; CEdit *pctlEdit=EditLabel(hRes); - if (pctlEdit == NULL) - return NULL; + if (pctlEdit == nullptr) + return nullptr; } return hRes; @@ -955,16 +874,16 @@ strPath+=pdi->item.pszText; // new folder - if (CreateDirectory(strPath, NULL)) + if (CreateDirectory(strPath, nullptr)) iResult = 1; // refresh - delete all from hParent and fill node HTREEITEM hChild; - while ((hChild=GetChildItem(hParent)) != NULL) + while ((hChild=GetChildItem(hParent)) != nullptr) DeleteItem(hChild); // now fillnode - SHELLITEMDATA* psid; + SHELLITEMDATA* psid = nullptr; if (GetItemStruct(hParent, &psid)) { if (FAILED(FillNode(hParent, psid->lpsf, psid->lpiidl))) @@ -982,7 +901,6 @@ if (_tcscmp(strPath, szPath) == 0) { - // zaznacz ExpandItem(hChild, TVE_EXPAND); break; }