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 | |
parent | 9003b747e6d330bac33c30018b4575e2ecfd95eb (diff) | |
download | EpisodeBrowser-019fad8bdbda5599e5f19bc50cd8ebac6be899e4.tar.gz |
Simplify EpisodeListView::UpdateItem, remove m_lviFocus.
-rw-r--r-- | c/episodelistview.cpp | 44 | ||||
-rw-r--r-- | c/episodelistview.h | 3 | ||||
-rw-r--r-- | c/main.cpp | 4 |
3 files changed, 21 insertions, 30 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, diff --git a/c/episodelistview.h b/c/episodelistview.h index 8747f6b..8a96096 100644 --- a/c/episodelistview.h +++ b/c/episodelistview.h @@ -24,11 +24,10 @@ struct EpisodeListView : public ListView void ShowFocus(); void Sort(); void Update(); - void UpdateItem(const LVITEM* pLvi); + void UpdateItem(int iItem, LPARAM lParam); LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) override; private: int m_iSort; - LVITEM m_lviFocus; static int CALLBACK SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lExtra); }; @@ -420,7 +420,7 @@ void WndProcContextMenu(const HWND, unsigned short wCommand) /* Process rate commands. */ if (ID_SUBGROUP(wCommand) == IDG_CTX_RATE) { Pl("episode_data","rate_episode",lvi.lParam,ID_RATING(wCommand)); - g_pElv->UpdateItem(&lvi); + g_pElv->UpdateItem(lvi.iItem, lvi.lParam); continue; } @@ -442,7 +442,7 @@ void WndProcContextMenu(const HWND, unsigned short wCommand) break; case IDM_LOOKUP: Pl("episode_data","retract_episode",lvi.lParam); - g_pElv->UpdateItem(&lvi); + g_pElv->UpdateItem(lvi.iItem, lvi.lParam); g_pDlv->ShowEpisode(lvi.lParam); break; case IDM_WIKI: |