static void *DoSortList( void *list, unsigned next_offset, bool (*before)(void *,void *), unsigned length ) { /**************************************************************************/ void **array; void **parray; void *list2; unsigned mid; int i; if( list == NULL ) return( NULL ); array = CGAlloc( length * sizeof( void * ) ); if( array == NULL ) { mid = length / 2; if( mid == 0 ) return( list ); /* FATAL ERROR! */ list2 = list; for( i = mid; i > 0; --i ) { list2 = _NEXT( list2, next_offset ); } list = DoSortList( list, next_offset, before, mid ); list2 = DoSortList( list2, next_offset, before, length - mid ); list = MergeList( list, list2, next_offset, before ); } else { list2 = list; parray = array; for( i = length; i > 0; --i ) { *parray++ = list2; list2 = _NEXT( list2, next_offset ); } ShellSort( array, length, before ); list = BuildList( array, next_offset, length ); CGFree( array ); } return( list ); }
// CFileOpenDlg::OnHeaderClickFileList // // The header was clicked: sort the file list // void CFileOpenDlg::OnHeaderClickFileList(NMHDR* pNMHDR, LRESULT* pResult) { HD_NOTIFY* phdn = (HD_NOTIFY *) pNMHDR; int iItem; iItem = phdn->iItem + 1; if(m_nSort == iItem) m_nSort = -iItem; else m_nSort = iItem; SetColumnIcons(); DoSortList(); *pResult = 0; }
extern void *SortList( void *list, unsigned next_offset, bool (*before)(void *,void *) ) { /****************************************************************/ void *list2; unsigned length; mem_out_action old_memout; length = 0; for( list2 = list; list2 != NULL; list2 = _NEXT( list2, next_offset ) ) { ++length; } if( length > 1 ) { old_memout = SetMemOut( MO_OK ); list = DoSortList( list, next_offset, before, length ); SetMemOut( old_memout ); } return( list ); }
// CFileOpenDlg::EnumFiles // // Enumerates all files in a folder // void CFileOpenDlg::EnumFiles(LPCTSTR pszPath, LPCTSTR pszFilter) { WIN32_FIND_DATA fd; HANDLE hFind; BOOL bFind; CString strSearch(pszPath), strFile; int i = 0, iItem; COleDateTime odt; CDateTimeFormat dtf; CWaitCursor wait; // // Flush the list // m_listFile.DeleteAllItems(); m_cont.clear(); // // Fill in the list // strSearch += pszFilter; hFind = FindFirstFile(strSearch, &fd); bFind = (hFind != INVALID_HANDLE_VALUE); // // Disable painting the list // m_listFile.SetRedraw(FALSE); while(bFind) { if(!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)) { strFile = pszPath; strFile += fd.cFileName; iItem = m_listFile.InsertItem(i, fd.cFileName, GetIconIndex(strFile)); if(iItem != -1) { // // Format size according to locale // m_listFile.SetItemText(iItem, 1, FormatSize(fd.nFileSizeLow)); // // Format date according to locale // odt = fd.ftLastWriteTime; dtf.SetDateTime(odt); dtf.SetFormat(m_strDateFormat); m_listFile.SetItemText(iItem, 2, dtf.GetString()); m_listFile.SetItemData(iItem, i); m_cont.push_back(fd); } i++; } bFind = FindNextFile(hFind, &fd); } DoSortList(); // // Enable painting the list // m_listFile.SetRedraw(TRUE); }