diff options
author | John Ankarström <john@ankarstrom.se> | 2022-02-17 01:48:22 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-02-17 01:48:22 +0100 |
commit | d7cf090cee5f1b71c3e9c5f232d0e2a51ad6a7e5 (patch) | |
tree | 1b803ac1d172556422455c6822a7702202409eb5 /c/episodelistview.c | |
parent | 263bc8b8ff4296a1fe0014a26134ad35ebccbbff (diff) | |
download | EpisodeBrowser-d7cf090cee5f1b71c3e9c5f232d0e2a51ad6a7e5.tar.gz |
More cleanup.
Diffstat (limited to 'c/episodelistview.c')
-rw-r--r-- | c/episodelistview.c | 93 |
1 files changed, 45 insertions, 48 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c index e414c46..df50bad 100644 --- a/c/episodelistview.c +++ b/c/episodelistview.c @@ -6,34 +6,33 @@ #include "resource.h" #include "defs.h" -extern HFONT g_GUIFontBold; -HWND Elv_hWnd; -int Elv_iSelectedItem = -1; -WNDPROC Elv_PrevProc; +extern HFONT HfBold; +extern HWND HWnd; +HWND HElv; +int IElvSelectedItem = -1; +WNDPROC ElvPrevProc; HWND -ElvCreate(HWND hWnd) +ElvCreate() { - HWND hElv; LVCOLUMN lvc; - Elv_hWnd = hWnd; - hElv = LvCreate(hWnd, (HMENU)IDC_EPISODELISTVIEW); + HElv = LvCreate((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); + ListView_InsertColumn(HElv, 0, &lvc); lvc.iSubItem = 1; lvc.pszText = TEXT("Title"); lvc.cx = 500; - ListView_InsertColumn(hElv, 1, &lvc); + ListView_InsertColumn(HElv, 1, &lvc); ElvUpdate(); ElvSelectRecent(); - return hElv; + return HElv; } LRESULT @@ -46,7 +45,7 @@ ElvHandleNotify(LPARAM lParam) case LVN_ITEMCHANGED: if ((lpNmLv->uChanged & LVIF_STATE) && (lpNmLv->uNewState & LVIS_FOCUSED)) { - Elv_iSelectedItem = lpNmLv->iItem; + IElvSelectedItem = lpNmLv->iItem; ElvUpdateName(lpNmLv->iItem, lpNmLv->lParam); DlvShowEpisode(lpNmLv->lParam); } @@ -62,7 +61,7 @@ ElvHandleNotify(LPARAM lParam) case CDDS_ITEMPREPAINT: if (!Watched(lpLvCd->nmcd.lItemlParam)) { SelectObject(lpLvCd->nmcd.hdc, - g_GUIFontBold); + HfBold); return CDRF_NEWFONT; } break; @@ -73,18 +72,18 @@ ElvHandleNotify(LPARAM lParam) { term_t t; t = T(1); - PI(t+0, ElvItemEpisode(Elv_iSelectedItem)) break; + PI(t+0, ElvItemEpisode(IElvSelectedItem)) break; P("local_episodes","open_episode",1,t); break; } case NM_RCLICK: { DWORD dwPos; - extern HMENU g_hPopupMenu; + extern HMENU HPopupMenu; dwPos = GetMessagePos(); - TrackPopupMenu(g_hPopupMenu, TPM_RIGHTBUTTON, + TrackPopupMenu(HPopupMenu, TPM_RIGHTBUTTON, LOWORD(dwPos), HIWORD(dwPos), 0, - Elv_hWnd, NULL); + HWnd, NULL); break; } } @@ -94,30 +93,34 @@ ElvHandleNotify(LPARAM lParam) 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; + return ListView_GetItem(HElv, &lvi) ? lvi.lParam : -1; } void ElvRedraw() { - HWND hElv; - hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW); - RedrawWindow(hElv, NULL, NULL, + RedrawWindow(HElv, NULL, NULL, RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN); } +void +ElvSetTop(int iItem) +{ + int iLast; + iLast = ListView_GetItemCount(HElv)-1; + ListView_EnsureVisible(HElv, iLast, TRUE); + ListView_EnsureVisible(HElv, iItem, TRUE); +} + /* Select most recent episode. */ void ElvSelectRecent() { fid_t f; - HWND hElv; int iEpisode, iItem; LVFINDINFO lvfi; term_t t; @@ -127,16 +130,16 @@ ElvSelectRecent() 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); + 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; + if (iItem > 5) + ElvSetTop(iItem-5); + ListView_SetItemState(HElv, iItem, LVIS_SELECTED, LVIS_SELECTED); + IElvSelectedItem = iItem; ElvUpdateName(iItem, iEpisode); DlvShowEpisode(iEpisode); @@ -148,16 +151,14 @@ void ElvUpdate() { fid_t f; - HWND hElv; - int iLast, iTop; + int 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); + SendMessage(HElv, WM_SETREDRAW, FALSE, 0); + iTop = ListView_GetTopIndex(HElv); + ListView_DeleteAllItems(HElv); lviEpisode.mask = LVIF_TEXT|LVIF_PARAM; lviName.mask = LVIF_TEXT; @@ -183,7 +184,7 @@ ElvUpdate() tszName = NULL; P("episode_data","lookup_episode_local",3,t2) goto skipname; GAC(t2+1,&szName) goto skipname; - tszName = TSZFromSZ(szName, CP_UTF8); + tszName = TszFromSz(szName, CP_UTF8); if (!tszName) goto e; /* Format episode string. */ @@ -199,13 +200,13 @@ skipname: lviEpisode.iSubItem = 0; lviEpisode.pszText = tszEpisode; lviEpisode.lParam = iEpisode; - ListView_InsertItem(hElv, &lviEpisode); + ListView_InsertItem(HElv, &lviEpisode); if (tszName) { lviName.iItem = i; lviName.iSubItem = 1; lviName.pszText = tszName; - ListView_SetItem(hElv, &lviName); + ListView_SetItem(HElv, &lviName); } free(tszEpisode); @@ -215,15 +216,13 @@ 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, + ElvSetTop(iTop); + if (IElvSelectedItem != -1) { + ListView_SetItemState(HElv, IElvSelectedItem, LVIS_SELECTED, LVIS_SELECTED); } - SendMessage(hElv, WM_SETREDRAW, TRUE, 0); + SendMessage(HElv, WM_SETREDRAW, TRUE, 0); ElvRedraw(); Qc(q); Fd(f); @@ -235,7 +234,6 @@ ElvUpdateName(int iItem, int iEpisode) { char *szName; fid_t f; - HWND hElv; TCHAR *tszName; term_t t; @@ -245,11 +243,10 @@ ElvUpdateName(int iItem, int iEpisode) P("episode_data","lookup_episode",3,t) goto e; GAC(t+1,&szName) goto e; - tszName = TSZFromSZ(szName, CP_UTF8); + tszName = TszFromSz(szName, CP_UTF8); if (!tszName) goto e; - hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW); - ListView_SetItemText(hElv, iItem, 1, tszName); + ListView_SetItemText(HElv, iItem, 1, tszName); e: Fd(f); return; |