diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-30 19:13:22 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-30 19:13:22 +0200 |
commit | 019fad8bdbda5599e5f19bc50cd8ebac6be899e4 (patch) | |
tree | 855e06cfa5b6bd90c7261270350fa50dc6570bba /c/episodelistview.cpp | |
parent | 9003b747e6d330bac33c30018b4575e2ecfd95eb (diff) | |
download | EpisodeBrowser-019fad8bdbda5599e5f19bc50cd8ebac6be899e4.tar.gz |
Simplify EpisodeListView::UpdateItem, remove m_lviFocus.
Diffstat (limited to 'c/episodelistview.cpp')
-rw-r--r-- | c/episodelistview.cpp | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index 132941c..0c8c60d 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -51,9 +51,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) if ((pNmLv->uChanged & LVIF_STATE) && (pNmLv->uNewState & LVIS_FOCUSED)) { extern DataListView* const g_pDlv; - m_lviFocus.iItem = pNmLv->iItem; - m_lviFocus.lParam = pNmLv->lParam; - UpdateItem(&m_lviFocus); + UpdateItem(pNmLv->iItem, pNmLv->lParam); g_pDlv->ShowEpisode(pNmLv->lParam); } break; @@ -100,23 +98,19 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) } case NM_DBLCLK: /* Open clicked episode. */ { - if (!Pl("local_episodes","open_episode_locally", - m_lviFocus.lParam)) - Pl("local_episodes","open_episode_online", - m_lviFocus.lParam); + LVITEM lvi = {LVIF_PARAM, -1}; + if (FindNextItem(&lvi, LVNI_FOCUSED)) + Pl("local_episodes","open_episode_locally",lvi.lParam) + || Pl("local_episodes","open_episode_online",lvi.lParam); break; } case NM_RETURN: /* Open all selected episodes. */ { LVITEM lvi = {LVIF_PARAM, -1}; - while (FindNextItem(&lvi, LVNI_SELECTED)) { - if (!ListView_GetItem(hWnd, &lvi)) goto b; - if (!Pl("local_episodes","open_episode_locally", - lvi.lParam)) - Pl("local_episodes","open_episode_online", - lvi.lParam); - } - b: break; + while (FindNextItem(&lvi, LVNI_SELECTED)) + Pl("local_episodes","open_episode_locally",lvi.lParam) + || Pl("local_episodes","open_episode_online",lvi.lParam); + break; } case NM_RCLICK: { @@ -176,9 +170,7 @@ s: ListView_SetItemState(hWnd, -1, LVIF_STATE, LVIS_SELECTED); SetTop(iItem > 5? iItem-5: 0); ListView_SetItemState(hWnd, iItem, LVIS_SELECTED|LVIS_FOCUSED, LVIS_SELECTED|LVIS_FOCUSED); - m_lviFocus.iItem = iItem; - m_lviFocus.lParam = iEpisode; - UpdateItem(&m_lviFocus); + UpdateItem(iItem, iEpisode); g_pDlv->ShowEpisode(iEpisode); } @@ -353,7 +345,7 @@ void EpisodeListView::Update() lviEpisode.pszText = wszEpisode; lviEpisode.lParam = iEp; ListView_InsertItem(hWnd, &lviEpisode); - UpdateItem(&lviEpisode); + UpdateItem(lviEpisode.iItem, lviEpisode.lParam); } } @@ -410,24 +402,24 @@ void EpisodeListView::Update() } /* Update episode name and rating. */ -void EpisodeListView::UpdateItem(const LVITEM* const pLvi) +void EpisodeListView::UpdateItem(const int iItem, const LPARAM lParam) { wstring_owner wsoName; - if (!Pl("episode_data","episode_title",pLvi->lParam,&wsoName)) { + if (!Pl("episode_data","episode_title",lParam,&wsoName)) { if (!Pl("episode_data","update_episode_data")) goto r; - if (!Pl("episode_data","episode_title",pLvi->lParam,&wsoName)) goto r; + if (!Pl("episode_data","episode_title",lParam,&wsoName)) goto r; } - ListView_SetItemText(hWnd, pLvi->iItem, ELVSITITLE, wsoName.p); + ListView_SetItemText(hWnd, iItem, ELVSITITLE, wsoName.p); r: int iRating; - if (!Pl("episode_data","episode_rating",pLvi->lParam,&iRating)) { - ListView_SetItemText(hWnd, pLvi->iItem, ELVSIRATING, (wchar_t*)L""); + if (!Pl("episode_data","episode_rating",lParam,&iRating)) { + ListView_SetItemText(hWnd, iItem, ELVSIRATING, (wchar_t*)L""); return; } wchar_t wszRating[3]; swprintf_s(wszRating, sizeof(wszRating)/sizeof(*wszRating), L"%d", iRating); - ListView_SetItemText(hWnd, pLvi->iItem, ELVSIRATING, wszRating); + ListView_SetItemText(hWnd, iItem, ELVSIRATING, wszRating); } LRESULT CALLBACK EpisodeListView::WndProc(const HWND hWnd, const UINT uMsg, |