* Sync up to trunk head (r64716).
[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 PVOID
15 ListViewGetlParam(INT Index)
16 {
17 INT ItemIndex;
18 LVITEM Item;
19
20 if (Index == -1)
21 {
22 ItemIndex = (INT) SendMessage(hListView, LVM_GETNEXTITEM, -1, LVNI_FOCUSED);
23 if (ItemIndex == -1)
24 return NULL;
25 }
26 else
27 {
28 ItemIndex = Index;
29 }
30
31 ZeroMemory(&Item, sizeof(LVITEM));
32
33 Item.mask = LVIF_PARAM;
34 Item.iItem = ItemIndex;
35 if (!ListView_GetItem(hListView, &Item))
36 return NULL;
37
38 return (PVOID)Item.lParam;
39 }
40
41 BOOL
42 ListViewAddColumn(INT Index, LPWSTR lpText, INT Width, INT Format)
43 {
44 LV_COLUMN Column;
45
46 ZeroMemory(&Column, sizeof(LV_COLUMN));
47
48 Column.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
49 Column.iSubItem = Index;
50 Column.pszText = (LPTSTR)lpText;
51 Column.cx = Width;
52 Column.fmt = Format;
53
54 return (ListView_InsertColumn(hListView, Index, &Column) == -1) ? FALSE : TRUE;
55 }
56
57 INT
58 ListViewAddItem(INT ItemIndex, INT IconIndex, LPWSTR lpText, LPARAM lParam)
59 {
60 LV_ITEMW Item;
61
62 ZeroMemory(&Item, sizeof(LV_ITEM));
63
64 Item.mask = LVIF_TEXT | LVIF_PARAM | LVIF_STATE | LVIF_IMAGE;
65 Item.pszText = lpText;
66 Item.lParam = lParam;
67 Item.iItem = ItemIndex;
68 Item.iImage = IconIndex;
69
70 return ListView_InsertItem(hListView, &Item);
71 }
72
73 INT
74 CALLBACK
75 ListViewCompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
76 {
77 WCHAR Item1[MAX_STR_LEN], Item2[MAX_STR_LEN];
78 LVFINDINFO IndexInfo;
79 INT Index;
80
81 IndexInfo.flags = LVFI_PARAM;
82
83 IndexInfo.lParam = lParam1;
84 Index = ListView_FindItem(hListView, -1, &IndexInfo);
85 ListView_GetItemText(hListView, Index, (INT)lParamSort, Item1, sizeof(Item1) / sizeof(WCHAR));
86
87 IndexInfo.lParam = lParam2;
88 Index = ListView_FindItem(hListView, -1, &IndexInfo);
89 ListView_GetItemText(hListView, Index, (INT)lParamSort, Item2, sizeof(Item2) / sizeof(WCHAR));
90
91 if (bAscending)
92 return wcscmp(Item2, Item1);
93 else
94 return wcscmp(Item1, Item2);
95
96 return 0;
97 }
98
99 BOOL
100 CreateListView(HWND hwnd)
101 {
102 hListView = CreateWindowExW(WS_EX_CLIENTEDGE,
103 WC_LISTVIEWW,
104 L"",
105 WS_CHILD | WS_VISIBLE | LVS_SORTASCENDING | LVS_REPORT | LVS_SINGLESEL | LVS_SHOWSELALWAYS,
106 205, 28, 465, 250,
107 hwnd,
108 GetSubMenu(LoadMenuW(hInst, MAKEINTRESOURCEW(IDR_APPLICATIONMENU)), 0),
109 hInst,
110 NULL);
111
112 if (!hListView)
113 {
114 /* TODO: Show error message */
115 return FALSE;
116 }
117
118 (VOID) ListView_SetExtendedListViewStyle(hListView, LVS_EX_FULLROWSELECT);
119
120 return TRUE;
121 }