Sync to trunk (r46918)
[reactos.git] / base / applications / rapps / listview.c
1 /*
2 * PROJECT: ReactOS Applications Manager
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: base/applications/rapps/listview.c
5 * PURPOSE: ListView functions
6 * PROGRAMMERS: Dmitry Chapyshev (dmitry@reactos.org)
7 */
8
9 #include "rapps.h"
10
11 HWND hListView;
12 BOOL bAscending = TRUE;
13
14
15 PVOID
16 ListViewGetlParam(INT Index)
17 {
18 INT ItemIndex;
19 LVITEM Item;
20
21 if (Index == -1)
22 {
23 ItemIndex = (INT) SendMessage(hListView, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
24 if (ItemIndex == -1)
25 return NULL;
26 }
27 else
28 {
29 ItemIndex = Index;
30 }
31
32 ZeroMemory(&Item, sizeof(LVITEM));
33
34 Item.mask = LVIF_PARAM;
35 Item.iItem = ItemIndex;
36 if (!ListView_GetItem(hListView, &Item))
37 return NULL;
38
39 return (PVOID)Item.lParam;
40 }
41
42 BOOL
43 ListViewAddColumn(INT Index, LPWSTR lpText, INT Width, INT Format)
44 {
45 LV_COLUMN Column;
46
47 ZeroMemory(&Column, sizeof(LV_COLUMN));
48
49 Column.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
50 Column.iSubItem = Index;
51 Column.pszText = (LPTSTR)lpText;
52 Column.cx = Width;
53 Column.fmt = Format;
54
55 return (ListView_InsertColumn(hListView, Index, &Column) == -1) ? FALSE : TRUE;
56 }
57
58 INT
59 ListViewAddItem(INT ItemIndex, INT IconIndex, LPWSTR lpText, LPARAM lParam)
60 {
61 LV_ITEMW Item;
62
63 ZeroMemory(&Item, sizeof(LV_ITEM));
64
65 Item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
66 Item.pszText = lpText;
67 Item.lParam = lParam;
68 Item.iItem = ItemIndex;
69 Item.iImage = IconIndex;
70
71 return ListView_InsertItem(hListView, &Item);
72 }
73
74 INT
75 CALLBACK
76 ListViewCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
77 {
78 WCHAR Item1[MAX_STR_LEN], Item2[MAX_STR_LEN];
79 LVFINDINFO IndexInfo;
80 INT Index;
81
82 IndexInfo.flags = LVFI_PARAM;
83
84 IndexInfo.lParam = lParam1;
85 Index = ListView_FindItem(hListView, -1, &IndexInfo);
86 ListView_GetItemText(hListView, Index, (INT)lParamSort, Item1, sizeof(Item1) / sizeof(WCHAR));
87
88 IndexInfo.lParam = lParam2;
89 Index = ListView_FindItem(hListView, -1, &IndexInfo);
90 ListView_GetItemText(hListView, Index, (INT)lParamSort, Item2, sizeof(Item2) / sizeof(WCHAR));
91
92 if (bAscending)
93 return wcscmp(Item2, Item1);
94 else
95 return wcscmp(Item1, Item2);
96
97 return 0;
98 }
99
100 BOOL
101 CreateListView(HWND hwnd)
102 {
103 hListView = CreateWindowExW(WS_EX_CLIENTEDGE,
104 WC_LISTVIEWW,
105 L"",
106 WS_CHILD | WS_VISIBLE | LVS_SORTASCENDING | LVS_REPORT | LVS_SINGLESEL,
107 205, 28, 465, 250,
108 hwnd,
109 NULL,
110 hInst,
111 NULL);
112
113 if (!hListView)
114 {
115 /* TODO: Show error message */
116 return FALSE;
117 }
118
119 (VOID) ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT);
120
121 return TRUE;
122 }