aboutsummaryrefslogtreecommitdiff
path: root/c/episodelistview.c
diff options
context:
space:
mode:
Diffstat (limited to 'c/episodelistview.c')
-rw-r--r--c/episodelistview.c209
1 files changed, 90 insertions, 119 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c
index 7d87b7a..3b42be0 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -7,50 +7,46 @@
#include "defs.h"
extern HFONT g_GUIFontBold;
-
-HWND gElv_hWnd;
-WNDPROC g_PrevElvProc;
-int g_iSelectedItem = -1; /* Remembered after refresh. */
+HWND Elv_hWnd;
+int Elv_iSelectedItem = -1;
+WNDPROC Elv_PrevProc;
HWND
ElvCreate(HWND hWnd)
{
- HWND hListView;
+ HWND hElv;
LVCOLUMN lvc;
- gElv_hWnd = hWnd;
- hListView = LvCreate(hWnd, (HMENU)IDC_EPISODELISTVIEW);
+ 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(hListView, 0, &lvc);
+ ListView_InsertColumn(hElv, 0, &lvc);
lvc.iSubItem = 1;
lvc.pszText = TEXT("Title");
lvc.cx = 500;
- ListView_InsertColumn(hListView, 1, &lvc);
+ ListView_InsertColumn(hElv, 1, &lvc);
ElvUpdate();
ElvSelectRecent();
-
- return hListView;
+ 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)) {
- g_iSelectedItem = pNmLv->iItem;
+ Elv_iSelectedItem = pNmLv->iItem;
ElvUpdateName(pNmLv->iItem, pNmLv->lParam);
DlvShowEpisode(pNmLv->lParam);
}
@@ -76,14 +72,9 @@ ElvHandleNotify(LPARAM lParam)
case NM_DBLCLK:
{
term_t t;
-
- t = PL_new_term_refs(1);
- if (!PL_put_integer(t+0, ElvItemEpisode(g_iSelectedItem)))
- break;
-
- PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("open_episode", 1,
- "local_episodes"), t);
+ t = T(1);
+ PI(t+0, ElvItemEpisode(Elv_iSelectedItem)) break;
+ P("local_episodes","open_episode",1,t);
break;
}
case NM_RCLICK:
@@ -91,12 +82,10 @@ ElvHandleNotify(LPARAM lParam)
DWORD dwPos;
NMITEMACTIVATE *pNmItem;
extern HMENU g_hPopupMenu;
-
dwPos = GetMessagePos();
-
TrackPopupMenu(g_hPopupMenu, TPM_RIGHTBUTTON,
LOWORD(dwPos), HIWORD(dwPos), 0,
- gElv_hWnd, NULL);
+ Elv_hWnd, NULL);
break;
}
}
@@ -106,18 +95,22 @@ ElvHandleNotify(LPARAM lParam)
int
ElvItemEpisode(int iItem) {
- HWND hListView;
+ HWND hElv;
LVITEM lvi;
-
- hListView = GetDlgItem(gElv_hWnd, IDC_EPISODELISTVIEW);
+ hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
lvi.mask = LVIF_PARAM;
lvi.iItem = iItem;
lvi.iSubItem = 0;
+ return ListView_GetItem(hElv, &lvi) ? lvi.lParam : -1;
+}
- if (!ListView_GetItem(hListView, &lvi))
- return -1;
-
- return lvi.lParam;
+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. */
@@ -125,38 +118,30 @@ void
ElvSelectRecent()
{
fid_t f;
- HWND hListView;
+ HWND hElv;
int iEpisode, iItem;
LVFINDINFO lvfi;
term_t t;
- f = PL_open_foreign_frame(); /* Needed? */
+ F(f);
+ t = T(1);
+ P("track_episodes","most_recently_watched",1,t) goto e;
+ GI(t, &iEpisode) goto e;
- t = PL_new_term_refs(1);
- if (!PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("most_recently_watched", 1, "track_episodes"),
- t))
- goto end;
-
- if (!PL_get_integer(t+0, &iEpisode))
- goto end;
-
- hListView = GetDlgItem(gElv_hWnd, IDC_EPISODELISTVIEW);
+ hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
lvfi.flags = LVFI_PARAM;
lvfi.lParam = iEpisode;
- iItem = ListView_FindItem(hListView, -1, &lvfi);
- if (iItem == -1)
- goto end;
+ iItem = ListView_FindItem(hElv, -1, &lvfi);
+ if (iItem == -1) goto e;
- ListView_EnsureVisible(hListView, iItem, TRUE);
- ListView_SetItemState(hListView, iItem, LVIS_SELECTED, LVIS_SELECTED);
- g_iSelectedItem = iItem;
+ ListView_EnsureVisible(hElv, iItem, TRUE);
+ ListView_SetItemState(hElv, iItem, LVIS_SELECTED, LVIS_SELECTED);
+ Elv_iSelectedItem = iItem;
ElvUpdateName(iItem, iEpisode);
DlvShowEpisode(iEpisode);
-end:
- PL_discard_foreign_frame(f);
+e: Fd(f);
}
/* Update episode list. */
@@ -164,64 +149,50 @@ void
ElvUpdate()
{
fid_t f;
- HWND hListView;
- int iTop;
+ HWND hElv;
+ int iLast, iTop;
LVITEM lviEpisode, lviName;
qid_t q;
term_t t;
- hListView = GetDlgItem(gElv_hWnd, IDC_EPISODELISTVIEW);
- SendMessage(hListView, WM_SETREDRAW, FALSE, 0);
- iTop = ListView_GetTopIndex(hListView);
- ListView_DeleteAllItems(hListView);
+ 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 = PL_open_foreign_frame();
- t = PL_new_term_refs(2);
- PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("update_tracked_episodes", 0, "track_episodes"),
- t);
+ F(f);
+ t = T(2);
+ P("track_episodes","update_tracked_episodes",0,t);
+ q = Q("local_episodes","episode_file",2,t);
- q = PL_open_query(NULL, PL_Q_NORMAL,
- PL_predicate("episode_file", 2, "local_episodes"),
- t);
-
- for (int i = 0; PL_next_solution(q); i++) {
+ for (int i = 0; Qn(q); i++) {
char *szName;
+ fid_t f2;
int cb, iEpisode, iItem, r;
TCHAR *tszEpisode, *tszName;
term_t t2;
- /* Lookup episode name. */
-
- if (!PL_get_integer(t+0, &iEpisode))
- goto close;
-
- t2 = PL_new_term_refs(3);
- if(!PL_put_integer(t2+0, iEpisode))
- continue;
-
- r = PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("lookup_episode_local", 3, "episode_data"),
- t2);
-
- /* Format episode, name strings. */
+ /* Format name string. */
+ GI(t,&iEpisode) goto e;
+ F(f2);
+ t2 = T(3);
+ PI(t2,iEpisode) goto e;
tszName = NULL;
- if (r && PL_get_atom_chars(t2+1, &szName)) {
- tszName = TSZFromSZ(szName, CP_UTF8);
- if (!tszName)
- continue;
- }
+ 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)
- continue;
- _stprintf_s(tszEpisode, cb, TEXT("%d"),
- iEpisode);
+ if (!tszEpisode) goto e1;
+ _stprintf_s(tszEpisode, cb, TEXT("%d"), iEpisode);
/* Insert item. */
@@ -229,32 +200,34 @@ ElvUpdate()
lviEpisode.iSubItem = 0;
lviEpisode.pszText = tszEpisode;
lviEpisode.lParam = iEpisode;
- ListView_InsertItem(hListView, &lviEpisode);
+ ListView_InsertItem(hElv, &lviEpisode);
if (tszName) {
lviName.iItem = i;
lviName.iSubItem = 1;
lviName.pszText = tszName;
- ListView_SetItem(hListView, &lviName);
+ ListView_SetItem(hElv, &lviName);
}
- free(tszName);
free(tszEpisode);
+e1: if (tszName) free(tszName);
+e: Fd(f2);
}
- if (g_iSelectedItem != -1) {
- int iLast;
- iLast = ListView_GetItemCount(hListView)-1;
- ListView_EnsureVisible(hListView, iLast, TRUE);
- ListView_EnsureVisible(hListView, iTop, TRUE);
- ListView_SetItemState(hListView, g_iSelectedItem,
+ /* 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);
}
-close:
- SendMessage(hListView, WM_SETREDRAW, TRUE, 0);
- PL_cut_query(q);
- PL_discard_foreign_frame(f);
+ SendMessage(hElv, WM_SETREDRAW, TRUE, 0);
+ ElvRedraw();
+ Qc(q);
+ Fd(f);
}
/* Update episode name. */
@@ -262,25 +235,23 @@ void
ElvUpdateName(int iItem, int iEpisode)
{
char *szName;
- HWND hListView;
+ fid_t f;
+ HWND hElv;
TCHAR *tszName;
term_t t;
- t = PL_new_term_refs(3);
- if (!PL_put_integer(t+0, iEpisode))
- return;
-
- PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("lookup_episode", 3, "episode_data"),
- t);
-
- if (!PL_get_atom_chars(t+1, &szName))
- return;
+ 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)
- return;
+ if (!tszName) goto e;
+
+ hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
+ ListView_SetItemText(hElv, iItem, 1, tszName);
- hListView = GetDlgItem(gElv_hWnd, IDC_EPISODELISTVIEW);
- ListView_SetItemText(hListView, iItem, 1, tszName);
+e: Fd(f);
+ return;
}