[SERVMAN] Introduce the ability to sort the services list-view by any column in ascending and descending order. Brought to you by Joachim Henze. CORE-10122

svn path=/trunk/; revision=69069
This commit is contained in:
Amine Khaldi 2015-09-06 20:19:58 +00:00
parent 3e33b84224
commit d5ee70e4f0

View file

@ -15,6 +15,8 @@ static const WCHAR szMainWndClass[] = L"ServManWndClass";
BOOL bSortAscending = TRUE; BOOL bSortAscending = TRUE;
/* Temporary copy for access from list-view sort CompareFunc */
HWND hListView;
/* Toolbar buttons */ /* Toolbar buttons */
static const TBBUTTON Buttons [] = static const TBBUTTON Buttons [] =
@ -23,7 +25,7 @@ static const TBBUTTON Buttons [] =
{TBICON_REFRESH, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* refresh */ {TBICON_REFRESH, ID_REFRESH, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* refresh */
{TBICON_EXPORT, ID_EXPORT, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* export */ {TBICON_EXPORT, ID_EXPORT, TBSTATE_ENABLED, BTNS_BUTTON, {0}, 0, 0}, /* export */
/* Note: First item for a seperator is its width in pixels */ /* Note: First item for a separator is its width in pixels */
{15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0}, /* separator */ {15, 0, TBSTATE_ENABLED, BTNS_SEP, {0}, 0, 0}, /* separator */
{TBICON_CREATE, ID_CREATE, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 }, /* create */ {TBICON_CREATE, ID_CREATE, TBSTATE_INDETERMINATE, BTNS_BUTTON, {0}, 0, 0 }, /* create */
@ -244,20 +246,21 @@ VOID SetMenuAndButtonStates(PMAIN_WND_INFO Info)
static INT CALLBACK static INT CALLBACK
CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{ {
ENUM_SERVICE_STATUS_PROCESS *Param1; WCHAR Item1[256], Item2[256];
ENUM_SERVICE_STATUS_PROCESS *Param2; LVFINDINFO IndexInfo;
// INT iSubItem = (LPARAM)lParamSort; INT Index;
if (bSortAscending) { IndexInfo.flags = LVFI_PARAM;
Param1 = (ENUM_SERVICE_STATUS_PROCESS *)lParam1;
Param2 = (ENUM_SERVICE_STATUS_PROCESS *)lParam2; IndexInfo.lParam = lParam1;
} Index = ListView_FindItem(hListView, -1, &IndexInfo);
else ListView_GetItemText(hListView, Index, (INT)lParamSort, Item1, sizeof(Item1) / sizeof(WCHAR));
{
Param1 = (ENUM_SERVICE_STATUS_PROCESS *)lParam2; IndexInfo.lParam = lParam2;
Param2 = (ENUM_SERVICE_STATUS_PROCESS *)lParam1; Index = ListView_FindItem(hListView, -1, &IndexInfo);
} ListView_GetItemText(hListView, Index, (INT)lParamSort, Item2, sizeof(Item2) / sizeof(WCHAR));
return _wcsicmp(Param1->lpDisplayName, Param2->lpDisplayName);
return bSortAscending ? wcscmp(Item1, Item2) : wcscmp(Item2, Item1);
} }
@ -732,15 +735,25 @@ MainWndProc(HWND hwnd,
case LVN_COLUMNCLICK: case LVN_COLUMNCLICK:
{ {
static int iLastSortColumn = 0;
LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam; LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;
/* get new sort parameters */
if (pnmv->iSubItem == iLastSortColumn)
bSortAscending = !bSortAscending;
else
{
iLastSortColumn = pnmv->iSubItem;
bSortAscending = TRUE;
}
/* store a copy to have access from callback */
hListView = Info->hListView;
(void)ListView_SortItems(Info->hListView, (void)ListView_SortItems(Info->hListView,
CompareFunc, CompareFunc,
pnmv->iSubItem); pnmv->iSubItem);
bSortAscending = !bSortAscending;
} }
break; break;
case LVN_ITEMCHANGED: case LVN_ITEMCHANGED:
{ {
LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam; LPNMLISTVIEW pnmv = (LPNMLISTVIEW) lParam;