aboutsummaryrefslogtreecommitdiff
path: root/c/episodelistview.c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-02-15 22:59:58 +0100
committerJohn Ankarström <john@ankarstrom.se>2022-02-15 23:00:20 +0100
commit4fafc8b49e3f08a87119ef62a54056efba7b6b92 (patch)
tree98a1cee0e7e2949924fa45940eacfd4eedbf940a /c/episodelistview.c
parent5bbd959c3c78a7293ad00c2a022b800ec28f4b8d (diff)
downloadEpisodeBrowser-4fafc8b49e3f08a87119ef62a54056efba7b6b92.tar.gz
Finish Win32 re-implementation.
There are still things to be improved upon, but this commit marks feature parity with the XPCE version.
Diffstat (limited to 'c/episodelistview.c')
-rw-r--r--c/episodelistview.c88
1 files changed, 65 insertions, 23 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c
index 42a2151..e12da4f 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -10,7 +10,7 @@ extern HFONT g_GUIFontBold;
HWND gElv_hWnd;
WNDPROC g_PrevElvProc;
-int g_SelectedItem = -1; /* Remembered after refresh. */
+int g_iSelectedItem = -1; /* Remembered after refresh. */
HWND
ElvCreate(HWND hWnd)
@@ -49,34 +49,76 @@ ElvHandleNotify(LPARAM lParam)
case LVN_ITEMCHANGED:
if ((pNmLv->uChanged & LVIF_STATE)
&& (pNmLv->uNewState & LVIS_FOCUSED)) {
- g_SelectedItem = pNmLv->iItem;
- ElvUpdateName(pNmLv);
+ g_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;
+ {
+ 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 = 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);
+ break;
+ }
+ case NM_RCLICK:
+ {
+ DWORD dwPos;
+ NMITEMACTIVATE *pNmItem;
+ extern HMENU g_hPopupMenu;
+
+ dwPos = GetMessagePos();
+
+ TrackPopupMenu(g_hPopupMenu, TPM_RIGHTBUTTON,
+ LOWORD(dwPos), HIWORD(dwPos), 0,
+ gElv_hWnd, NULL);
+ break;
+ }
+ }
return 0;
}
+int
+ElvItemEpisode(int iItem) {
+ HWND hListView;
+ LVITEM lvi;
+
+ hListView = GetDlgItem(gElv_hWnd, IDC_EPISODELISTVIEW);
+ lvi.mask = LVIF_PARAM;
+ lvi.iItem = iItem;
+ lvi.iSubItem = 0;
+
+ if (!ListView_GetItem(hListView, &lvi))
+ return -1;
+
+ return lvi.lParam;
+}
+
/* Update episode list. */
void
ElvUpdate()
@@ -157,10 +199,10 @@ ElvUpdate()
free(tszEpisode);
}
- if (g_SelectedItem != -1) {
- ListView_SetItemState(hListView, g_SelectedItem,
+ if (g_iSelectedItem != -1) {
+ ListView_SetItemState(hListView, g_iSelectedItem,
LVIS_SELECTED, LVIS_SELECTED);
- ListView_EnsureVisible(hListView, g_SelectedItem, TRUE);
+ ListView_EnsureVisible(hListView, g_iSelectedItem, TRUE);
}
close:
@@ -170,7 +212,7 @@ close:
/* Update episode name. */
void
-ElvUpdateName(NMLISTVIEW *pNmLv)
+ElvUpdateName(int iItem, int iEpisode)
{
char *szName;
HWND hListView;
@@ -178,7 +220,7 @@ ElvUpdateName(NMLISTVIEW *pNmLv)
term_t t;
t = PL_new_term_refs(3);
- if (!PL_put_integer(t+0, pNmLv->lParam))
+ if (!PL_put_integer(t+0, iEpisode))
return;
PL_call_predicate(NULL, PL_Q_NORMAL,
@@ -193,5 +235,5 @@ ElvUpdateName(NMLISTVIEW *pNmLv)
return;
hListView = GetDlgItem(gElv_hWnd, IDC_EPISODELISTVIEW);
- ListView_SetItemText(hListView, pNmLv->iItem, 1, tszName);
+ ListView_SetItemText(hListView, iItem, 1, tszName);
}