1 /*
2 * PROJECT: ReactOS Applications
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/msconfig_new/comctl32ex/listview.c
5 * PURPOSE: List-View helper functions.
6 * COPYRIGHT: Copyright 2011-2012 Hermes BELUSCA - MAITO <hermes.belusca@sfr.fr>
7 */
8
9 #include "precomp.h"
10 #include "listview.h"
11
12 ///////////// ListView Sorting /////////////
13
14 typedef struct __tagSort
15 {
16 HWND hList;
17 int nClickedColumn;
18 BOOL bSortAsc;
19 } Sort, *PSort;
20
21 int CALLBACK
SortListView(LPARAM lItemParam1,LPARAM lItemParam2,LPARAM lPSort_S)22 SortListView(LPARAM lItemParam1,
23 LPARAM lItemParam2,
24 LPARAM lPSort_S)
25 {
26 PSort pSort = (PSort)lPSort_S;
27
28 int iItem1 = (int)lItemParam1;
29 int iItem2 = (int)lItemParam2;
30
31 WCHAR strItem1[MAX_VALUE_NAME];
32 WCHAR strItem2[MAX_VALUE_NAME];
33
34 ListView_GetItemText(pSort->hList, iItem1, pSort->nClickedColumn, strItem1, MAX_VALUE_NAME);
35 ListView_GetItemText(pSort->hList, iItem2, pSort->nClickedColumn, strItem2, MAX_VALUE_NAME);
36
37 // StrCmpLogicalW helps in comparing numbers intelligently, 10 is greater that 2, other
38 // wise string comparison will always return 2 is greater that 10...
39 return ( pSort->bSortAsc ? StrCmpLogicalW(strItem1, strItem2) : StrCmpLogicalW(strItem2, strItem1) );
40 }
41
42 BOOL
ListView_SortEx(HWND hListView,int iSortingColumn,int iSortedColumn)43 ListView_SortEx(HWND hListView,
44 int iSortingColumn,
45 int iSortedColumn)
46 {
47 HWND hHeader;
48 HDITEM hColumn;
49 BOOL bSortAsc;
50 Sort sort;
51
52 if (GetWindowLongPtr(hListView, GWL_STYLE) & LVS_NOSORTHEADER)
53 return TRUE;
54
55 hHeader = ListView_GetHeader(hListView);
56 SecureZeroMemory(&hColumn, sizeof(hColumn));
57
58 if ( (iSortedColumn != -1) && (iSortedColumn != iSortingColumn) )
59 {
60 hColumn.mask = HDI_FORMAT | HDI_LPARAM;
61 Header_GetItem(hHeader, iSortedColumn, &hColumn);
62 hColumn.fmt &= ~HDF_SORTUP & ~HDF_SORTDOWN;
63 hColumn.lParam = 0; // 0: deactivated, 1: false, 2: true.
64 Header_SetItem(hHeader, iSortedColumn, &hColumn);
65 }
66
67 hColumn.mask = HDI_FORMAT | HDI_LPARAM;
68 Header_GetItem(hHeader, iSortingColumn, &hColumn);
69
70 bSortAsc = !(hColumn.lParam == 2); // 0: deactivated, 1: false, 2: true.
71
72 hColumn.fmt &= (bSortAsc ? ~HDF_SORTDOWN : ~HDF_SORTUP );
73 hColumn.fmt |= (bSortAsc ? HDF_SORTUP : HDF_SORTDOWN);
74 hColumn.lParam = (LPARAM)(bSortAsc ? 2 : 1);
75 Header_SetItem(hHeader, iSortingColumn, &hColumn);
76
77 /* Sort the list */
78 sort.bSortAsc = bSortAsc;
79 sort.hList = hListView;
80 sort.nClickedColumn = iSortingColumn;
81 return ListView_SortItemsEx(hListView, SortListView, (LPARAM)&sort);
82 }
83
84 //////////////////////////////////////////////
85
86 /* EOF */
87