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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
#include <windows.h>
#include <commctrl.h>
#include <TCHAR.H>
#include <SWI-Prolog.h>
#include "resource.h"
#include "defs.h"
extern HFONT g_GUIFontBold;
HWND Elv_hWnd;
int Elv_iSelectedItem = -1;
WNDPROC Elv_PrevProc;
HWND
ElvCreate(HWND hWnd)
{
HWND hElv;
LVCOLUMN lvc;
Elv_hWnd = hWnd;
hElv = LvCreate(hWnd, (HMENU)IDC_EPISODELISTVIEW);
lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
lvc.iSubItem = 0;
lvc.pszText = TEXT("#");
lvc.cx = 42;
ListView_InsertColumn(hElv, 0, &lvc);
lvc.iSubItem = 1;
lvc.pszText = TEXT("Title");
lvc.cx = 500;
ListView_InsertColumn(hElv, 1, &lvc);
ElvUpdate();
ElvSelectRecent();
return hElv;
}
LRESULT
ElvHandleNotify(LPARAM lParam)
{
NMLISTVIEW *pNmLv;
pNmLv = (NMLISTVIEW *)lParam;
switch (pNmLv->hdr.code) {
case LVN_ITEMCHANGED:
if ((pNmLv->uChanged & LVIF_STATE)
&& (pNmLv->uNewState & LVIS_FOCUSED)) {
Elv_iSelectedItem = pNmLv->iItem;
ElvUpdateName(pNmLv->iItem, pNmLv->lParam);
DlvShowEpisode(pNmLv->lParam);
}
break;
case NM_CUSTOMDRAW:
{
NMLVCUSTOMDRAW *pLvCd;
pLvCd = (NMLVCUSTOMDRAW *)lParam;
switch (pLvCd->nmcd.dwDrawStage) {
case CDDS_PREPAINT:
return CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
if (!Watched(pLvCd->nmcd.lItemlParam)) {
SelectObject(pLvCd->nmcd.hdc,
g_GUIFontBold);
return CDRF_NEWFONT;
}
break;
}
break;
}
case NM_DBLCLK:
{
term_t t;
t = T(1);
PI(t+0, ElvItemEpisode(Elv_iSelectedItem)) break;
P("local_episodes","open_episode",1,t);
break;
}
case NM_RCLICK:
{
DWORD dwPos;
NMITEMACTIVATE *pNmItem;
extern HMENU g_hPopupMenu;
dwPos = GetMessagePos();
TrackPopupMenu(g_hPopupMenu, TPM_RIGHTBUTTON,
LOWORD(dwPos), HIWORD(dwPos), 0,
Elv_hWnd, NULL);
break;
}
}
return 0;
}
int
ElvItemEpisode(int iItem) {
HWND hElv;
LVITEM lvi;
hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
lvi.mask = LVIF_PARAM;
lvi.iItem = iItem;
lvi.iSubItem = 0;
return ListView_GetItem(hElv, &lvi) ? lvi.lParam : -1;
}
void
ElvRedraw()
{
HWND hElv;
hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
RedrawWindow(hElv, NULL, NULL,
RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN);
}
/* Select most recent episode. */
void
ElvSelectRecent()
{
fid_t f;
HWND hElv;
int iEpisode, iItem;
LVFINDINFO lvfi;
term_t t;
F(f);
t = T(1);
P("track_episodes","most_recently_watched",1,t) goto e;
GI(t, &iEpisode) goto e;
hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
lvfi.flags = LVFI_PARAM;
lvfi.lParam = iEpisode;
iItem = ListView_FindItem(hElv, -1, &lvfi);
if (iItem == -1) goto e;
ListView_EnsureVisible(hElv, iItem, TRUE);
ListView_SetItemState(hElv, iItem, LVIS_SELECTED, LVIS_SELECTED);
Elv_iSelectedItem = iItem;
ElvUpdateName(iItem, iEpisode);
DlvShowEpisode(iEpisode);
e: Fd(f);
}
/* Update episode list. */
void
ElvUpdate()
{
fid_t f;
HWND hElv;
int iLast, iTop;
LVITEM lviEpisode, lviName;
qid_t q;
term_t t;
hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
SendMessage(hElv, WM_SETREDRAW, FALSE, 0);
iTop = ListView_GetTopIndex(hElv);
ListView_DeleteAllItems(hElv);
lviEpisode.mask = LVIF_TEXT|LVIF_PARAM;
lviName.mask = LVIF_TEXT;
F(f);
t = T(2);
P("track_episodes","update_tracked_episodes",0,t);
q = Q("local_episodes","episode_file",2,t);
for (int i = 0; Qn(q); i++) {
char *szName;
fid_t f2;
int cb, iEpisode, iItem, r;
TCHAR *tszEpisode, *tszName;
term_t t2;
/* Format name string. */
GI(t,&iEpisode) goto e;
F(f2);
t2 = T(3);
PI(t2,iEpisode) goto e;
tszName = NULL;
P("episode_data","lookup_episode_local",3,t2) goto skipname;
GAC(t2+1,&szName) goto skipname;
tszName = TSZFromSZ(szName, CP_UTF8);
if (!tszName) goto e;
/* Format episode string. */
skipname:
cb = 100;
tszEpisode = malloc(cb*sizeof(TCHAR));
if (!tszEpisode) goto e1;
_stprintf_s(tszEpisode, cb, TEXT("%d"), iEpisode);
/* Insert item. */
lviEpisode.iItem = i;
lviEpisode.iSubItem = 0;
lviEpisode.pszText = tszEpisode;
lviEpisode.lParam = iEpisode;
ListView_InsertItem(hElv, &lviEpisode);
if (tszName) {
lviName.iItem = i;
lviName.iSubItem = 1;
lviName.pszText = tszName;
ListView_SetItem(hElv, &lviName);
}
free(tszEpisode);
e1: if (tszName) free(tszName);
e: Fd(f2);
}
/* Reset selection and scrolling position. */
iLast = ListView_GetItemCount(hElv)-1;
ListView_EnsureVisible(hElv, iLast, TRUE);
ListView_EnsureVisible(hElv, iTop, TRUE);
if (Elv_iSelectedItem != -1) {
ListView_SetItemState(hElv, Elv_iSelectedItem,
LVIS_SELECTED, LVIS_SELECTED);
}
SendMessage(hElv, WM_SETREDRAW, TRUE, 0);
ElvRedraw();
Qc(q);
Fd(f);
}
/* Update episode name. */
void
ElvUpdateName(int iItem, int iEpisode)
{
char *szName;
fid_t f;
HWND hElv;
TCHAR *tszName;
term_t t;
F(f);
t = T(3);
PI(t,iEpisode) goto e;
P("episode_data","lookup_episode",3,t) goto e;
GAC(t+1,&szName) goto e;
tszName = TSZFromSZ(szName, CP_UTF8);
if (!tszName) goto e;
hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
ListView_SetItemText(hElv, iItem, 1, tszName);
e: Fd(f);
return;
}
|