aboutsummaryrefslogtreecommitdiff
path: root/c/datalistview.c
blob: e9ad2ac724fb4453a59369402f8da7b5b892f443 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <windows.h>
#include <commctrl.h>
#include <SWI-Prolog.h>

#include "resource.h"
#include "defs.h"

HWND HDlv;

HWND
DlvCreate()
{
	LVCOLUMN lvc;

	HDlv = LvCreate((HMENU)IDC_DATALISTVIEW, LVS_NOCOLUMNHEADER);

	lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
	lvc.iSubItem = 0;
	lvc.pszText = TEXT("Key");

	lvc.cx = Dpi(42);
	ListView_InsertColumn(HDlv, 0, &lvc);

	lvc.iSubItem = 1;
	lvc.pszText = TEXT("Value");
	lvc.cx = 500;
	ListView_InsertColumn(HDlv, 1, &lvc);

	return HDlv;
}

/* Show episode data. */
void
DlvShowEpisode(int iEpisode)
{
	int i, iItem;
	LVFINDINFO lvfi;
	LVITEM lviKey, lviValue;
	term_t t;
	qid_t q;
	extern HWND HElv;

	ListView_DeleteAllItems(HDlv);

	lviKey.mask = LVIF_TEXT;
	lviValue.mask = LVIF_TEXT;

	t = T(3);
	PI(t,iEpisode) return;
	q = Q("episode_data","episode_datum",3,t);

	for (i = 0; Qn(q); i++) {
		char *szKey;
		char *szValue;
		TCHAR *tszKey, *tszValue;

		GAC(t+1,&szKey) continue;
		GAC(t+2,&szValue) continue;

		tszKey = TszFromSz(szKey, CP_UTF8);
		if (!tszKey) continue;
		tszValue = TszFromSz(szValue, CP_UTF8);
		if (!tszValue) goto c;

		lviKey.mask = LVIF_TEXT;
		lviKey.iItem = i;
		lviKey.iSubItem = 0;
		lviKey.pszText = tszKey;
		ListView_InsertItem(HDlv, &lviKey);

		lviValue.iItem = i;
		lviValue.iSubItem = 1;
		lviValue.pszText = tszValue;
		ListView_SetItem(HDlv, &lviValue);

		free(tszValue);
	c:	free(tszKey);
	}

	Qc(q);
	UpdateLayout();

	lvfi.flags = LVFI_PARAM;
	lvfi.lParam = iEpisode;
	iItem = ListView_FindItem(HElv, -1, &lvfi);
	if (iItem != -1)
		ListView_EnsureVisible(HElv, iItem, TRUE);
}