Fixed the ascending and descending sort order for the File Dialog.

This commit is contained in:
Pierre Mageau 1999-10-23 16:58:22 +00:00 committed by Alexandre Julliard
parent d8eb8c54b1
commit b2e0eef50f
2 changed files with 40 additions and 11 deletions

View File

@ -1487,8 +1487,8 @@ DPA_QuickSort (LPVOID *lpPtrs, INT l, INT r,
j = r; j = r;
v = lpPtrs[(int)(l+r)/2]; v = lpPtrs[(int)(l+r)/2];
do { do {
while ((pfnCompare)(lpPtrs[i], v, lParam) > 0) i++; while ((pfnCompare)(lpPtrs[i], v, lParam) < 0) i++;
while ((pfnCompare)(lpPtrs[j], v, lParam) < 0) j--; while ((pfnCompare)(lpPtrs[j], v, lParam) > 0) j--;
if (i <= j) if (i <= j)
{ {
t = lpPtrs[i]; t = lpPtrs[i];

View File

@ -33,6 +33,12 @@
DEFAULT_DEBUG_CHANNEL(shell) DEFAULT_DEBUG_CHANNEL(shell)
typedef struct
{ BOOL bIsAscending;
INT nHeaderID;
INT nLastHeaderID;
}LISTVIEW_SORT_INFO, *LPLISTVIEW_SORT_INFO;
typedef struct typedef struct
{ ICOM_VTABLE(IShellView)* lpvtbl; { ICOM_VTABLE(IShellView)* lpvtbl;
DWORD ref; DWORD ref;
@ -51,6 +57,7 @@ typedef struct
UINT uState; UINT uState;
UINT cidl; UINT cidl;
LPITEMIDLIST *apidl; LPITEMIDLIST *apidl;
LISTVIEW_SORT_INFO ListViewSortInfo;
} IShellViewImpl; } IShellViewImpl;
static struct ICOM_VTABLE(IShellView) svvt; static struct ICOM_VTABLE(IShellView) svvt;
@ -233,7 +240,7 @@ static BOOL ShellView_CreateList (IShellViewImpl * This)
TRACE("%p\n",This); TRACE("%p\n",This);
dwStyle = WS_TABSTOP | WS_VISIBLE | WS_CHILD | WS_BORDER | WS_CHILDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | dwStyle = WS_TABSTOP | WS_VISIBLE | WS_CHILDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
LVS_SHAREIMAGELISTS | LVS_EDITLABELS | LVS_ALIGNLEFT | LVS_AUTOARRANGE; LVS_SHAREIMAGELISTS | LVS_EDITLABELS | LVS_ALIGNLEFT | LVS_AUTOARRANGE;
switch (This->FolderSettings.ViewMode) switch (This->FolderSettings.ViewMode)
@ -262,7 +269,11 @@ static BOOL ShellView_CreateList (IShellViewImpl * This)
if(!This->hWndList) if(!This->hWndList)
return FALSE; return FALSE;
/* UpdateShellSettings(); */ This->ListViewSortInfo.bIsAscending = TRUE;
This->ListViewSortInfo.nHeaderID = -1;
This->ListViewSortInfo.nLastHeaderID = -1;
/* UpdateShellSettings(); */
return TRUE; return TRUE;
} }
/********************************************************** /**********************************************************
@ -348,6 +359,7 @@ static INT CALLBACK ShellView_ListViewCompareItems(LPVOID lParam1, LPVOID lParam
BOOL bIsFolder1, bIsFolder2,bIsBothFolder; BOOL bIsFolder1, bIsFolder2,bIsBothFolder;
LPITEMIDLIST pItemIdList1 = (LPITEMIDLIST) lParam1; LPITEMIDLIST pItemIdList1 = (LPITEMIDLIST) lParam1;
LPITEMIDLIST pItemIdList2 = (LPITEMIDLIST) lParam2; LPITEMIDLIST pItemIdList2 = (LPITEMIDLIST) lParam2;
LISTVIEW_SORT_INFO *pSortInfo = (LPLISTVIEW_SORT_INFO) lpData;
bIsFolder1 = _ILIsFolder(pItemIdList1); bIsFolder1 = _ILIsFolder(pItemIdList1);
@ -363,21 +375,21 @@ static INT CALLBACK ShellView_ListViewCompareItems(LPVOID lParam1, LPVOID lParam
{ {
/* Sort by Time: Folders or Files can be sorted */ /* Sort by Time: Folders or Files can be sorted */
if(lpData == LISTVIEW_COLUMN_TIME) if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_TIME)
{ {
_ILGetFileDateTime(pItemIdList1, &fd1); _ILGetFileDateTime(pItemIdList1, &fd1);
_ILGetFileDateTime(pItemIdList2, &fd2); _ILGetFileDateTime(pItemIdList2, &fd2);
nDiff = CompareFileTime(&fd2, &fd1); nDiff = CompareFileTime(&fd2, &fd1);
} }
/* Sort by Attribute: Folder or Files can be sorted */ /* Sort by Attribute: Folder or Files can be sorted */
else if(lpData == LISTVIEW_COLUMN_ATTRIB) else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_ATTRIB)
{ {
_ILGetAttributeStr(pItemIdList1, strName1, MAX_PATH); _ILGetAttributeStr(pItemIdList1, strName1, MAX_PATH);
_ILGetAttributeStr(pItemIdList2, strName2, MAX_PATH); _ILGetAttributeStr(pItemIdList2, strName2, MAX_PATH);
nDiff = strcasecmp(strName1, strName2); nDiff = strcasecmp(strName1, strName2);
} }
/* Sort by FileName: Folder or Files can be sorted */ /* Sort by FileName: Folder or Files can be sorted */
else if(lpData == LISTVIEW_COLUMN_NAME || bIsBothFolder) else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_NAME || bIsBothFolder)
{ {
/* Sort by Text */ /* Sort by Text */
_ILSimpleGetText(pItemIdList1, strName1, MAX_PATH); _ILSimpleGetText(pItemIdList1, strName1, MAX_PATH);
@ -385,12 +397,12 @@ static INT CALLBACK ShellView_ListViewCompareItems(LPVOID lParam1, LPVOID lParam
nDiff = strcasecmp(strName1, strName2); nDiff = strcasecmp(strName1, strName2);
} }
/* Sort by File Size, Only valid for Files */ /* Sort by File Size, Only valid for Files */
else if(lpData == LISTVIEW_COLUMN_SIZE) else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_SIZE)
{ {
nDiff = _ILGetFileSize(pItemIdList1, NULL, 0) - _ILGetFileSize(pItemIdList2, NULL, 0); nDiff = (INT)(_ILGetFileSize(pItemIdList1, NULL, 0) - _ILGetFileSize(pItemIdList2, NULL, 0));
} }
/* Sort by File Type, Only valid for Files */ /* Sort by File Type, Only valid for Files */
else if(lpData == LISTVIEW_COLUMN_TYPE) else if(pSortInfo->nHeaderID == LISTVIEW_COLUMN_TYPE)
{ {
/* Sort by Type */ /* Sort by Type */
_ILGetFileType(pItemIdList1, strName1, MAX_PATH); _ILGetFileType(pItemIdList1, strName1, MAX_PATH);
@ -407,6 +419,11 @@ static INT CALLBACK ShellView_ListViewCompareItems(LPVOID lParam1, LPVOID lParam
nDiff = strcasecmp(strName1, strName2); nDiff = strcasecmp(strName1, strName2);
} }
if(!pSortInfo->bIsAscending)
{
nDiff = -nDiff;
}
return nDiff; return nDiff;
} }
@ -998,7 +1015,19 @@ static LRESULT ShellView_OnNotify(IShellViewImpl * This, UINT CtlID, LPNMHDR lpn
case LVN_COLUMNCLICK: case LVN_COLUMNCLICK:
{ {
ListView_SortItems(lpnmlv->hdr.hwndFrom, ShellView_ListViewCompareItems, (LPARAM) (lpnmlv->iSubItem)); This->ListViewSortInfo.nHeaderID = lpnmlv->iSubItem;
if(This->ListViewSortInfo.nLastHeaderID == This->ListViewSortInfo.nHeaderID)
{
This->ListViewSortInfo.bIsAscending = !This->ListViewSortInfo.bIsAscending;
}
else
{
This->ListViewSortInfo.bIsAscending = TRUE;
}
This->ListViewSortInfo.nLastHeaderID = This->ListViewSortInfo.nHeaderID;
ListView_SortItems(lpnmlv->hdr.hwndFrom, ShellView_ListViewCompareItems, (LPARAM) (&(This->ListViewSortInfo)));
break; break;
} }