ReactOS  0.4.12-dev-51-ge94618b
listview.c
Go to the documentation of this file.
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 
13 
14 typedef struct __tagSort
15 {
19 } Sort, *PSort;
20 
21 int CALLBACK
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
44  int iSortingColumn,
45  int iSortedColumn)
46 {
47  HWND hHeader;
48  HDITEM hColumn;
49  BOOL bSortAsc;
50  Sort sort;
51 
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 
85 
86 /* EOF */
struct __tagSort Sort
#define TRUE
Definition: types.h:120
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define SecureZeroMemory
Definition: winbase.h:1636
#define ListView_GetHeader(hwnd)
Definition: commctrl.h:2621
_STLP_MOVE_TO_STD_NAMESPACE void sort(_RandomAccessIter __first, _RandomAccessIter __last)
Definition: _algo.c:993
#define ListView_GetItemText(hwndLV, i, iSubItem_, pszText_, cchTextMax_)
Definition: commctrl.h:2654
#define CALLBACK
Definition: compat.h:27
#define HDF_SORTUP
Definition: commctrl.h:709
#define HDITEM
Definition: commctrl.h:682
LONG_PTR LPARAM
Definition: windef.h:208
#define HDI_FORMAT
Definition: commctrl.h:690
#define Header_GetItem(hwndHD, i, phdi)
Definition: commctrl.h:736
static int iSortedColumn
Definition: srvpage.cpp:27
#define MAX_VALUE_NAME
Definition: control.c:23
BOOL bSortAsc
Definition: listview.c:18
unsigned int BOOL
Definition: ntddk_ex.h:94
struct __tagSort * PSort
static int
Definition: listview.c:31
HWND hList
Definition: listview.c:16
#define HDF_SORTDOWN
Definition: commctrl.h:710
INT WINAPI StrCmpLogicalW(LPCWSTR lpszStr, LPCWSTR lpszComp)
Definition: string.c:2296
int CALLBACK SortListView(LPARAM lItemParam1, LPARAM lItemParam2, LPARAM lPSort_S)
Definition: listview.c:22
#define GWL_STYLE
Definition: winuser.h:846
HWND hListView
Definition: gui.cpp:29
BOOL ListView_SortEx(HWND hListView, int iSortingColumn, int iSortedColumn)
Definition: listview.c:43
int nClickedColumn
Definition: listview.c:17
#define ListView_SortItemsEx(hwndLV, _pfnCompare, _lPrm)
Definition: commctrl.h:2771
#define HDI_LPARAM
Definition: commctrl.h:691
#define LVS_NOSORTHEADER
Definition: commctrl.h:2255
#define GetWindowLongPtr
Definition: treelist.c:73
#define Header_SetItem(hwndHD, i, phdi)
Definition: commctrl.h:743
#define LPARAM
Definition: msvc.h:38