aboutsummaryrefslogtreecommitdiff
path: root/c/episodelistview.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-07-29 21:20:44 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-07-29 21:20:44 +0200
commit2b8b6ac284dca2bd22514d293519cb877a1079d8 (patch)
treecf1a212a5be583d52d4965508218be358f6879e4 /c/episodelistview.cpp
parentc883d9cf5673fe0af8d69120b048d642e122bdbb (diff)
downloadEpisodeBrowser-2b8b6ac284dca2bd22514d293519cb877a1079d8.tar.gz
Add ListView::FindNextItem.
This makes it much more ergonomic and less error-prone to look up list view items.
Diffstat (limited to 'c/episodelistview.cpp')
-rw-r--r--c/episodelistview.cpp36
1 files changed, 11 insertions, 25 deletions
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp
index 6ba97cd..e23e5d8 100644
--- a/c/episodelistview.cpp
+++ b/c/episodelistview.cpp
@@ -108,11 +108,8 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
}
case NM_RETURN: /* Open all selected episodes. */
{
- LVITEM lvi;
- lvi.mask = LVIF_PARAM;
- lvi.iItem = -1;
- while ((lvi.iItem = ListView_GetNextItem(
- hWnd, lvi.iItem, LVNI_SELECTED)) != -1) {
+ 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))
@@ -187,10 +184,8 @@ s: ListView_SetItemState(hWnd, -1, LVIF_STATE, LVIS_SELECTED);
void EpisodeListView::SaveFocus()
{
- LVITEM lvi;
- lvi.mask = LVIF_PARAM;
- if ((lvi.iItem = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED)) != -1
- && ListView_GetItem(hWnd, &lvi))
+ LVITEM lvi = {LVIF_PARAM, -1};
+ if (FindNextItem(&lvi, LVNI_FOCUSED))
Pl("cfg","set_focus",lvi.lParam);
}
@@ -205,12 +200,8 @@ void EpisodeListView::SetTop(const int iItem)
void EpisodeListView::SelectUnwatched(int iDir)
{
/* Get focused episode. */
- LVITEM lviFocus;
- lviFocus.mask = LVIF_PARAM;
- if ((lviFocus.iItem = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED)) != -1
- && ListView_GetItem(hWnd, &lviFocus))
- ;
- else
+ LVITEM lviFocus = {LVIF_PARAM, -1};
+ if (!FindNextItem(&lviFocus, LVNI_FOCUSED))
return;
LVFINDINFO lvfi;
@@ -316,23 +307,18 @@ void EpisodeListView::Update()
int iItemMark;
static std::vector<int> vEpSel;
{
- LVITEM lvi;
- lvi.mask = LVIF_PARAM;
- lvi.iItem = -1;
vEpSel.clear();
- while ((lvi.iItem = ListView_GetNextItem(hWnd, lvi.iItem, LVNI_SELECTED)) != -1)
- if (ListView_GetItem(hWnd, &lvi))
- vEpSel.push_back(lvi.lParam);
+ LVITEM lvi = {LVIF_PARAM, -1};
+ while (FindNextItem(&lvi, LVNI_SELECTED))
+ vEpSel.push_back(lvi.lParam);
iItemMark = ListView_GetSelectionMark(hWnd);
}
/* Save focus. */
int iEpFocus = 0;
{
- LVITEM lvi;
- lvi.mask = LVIF_PARAM;
- if ((lvi.iItem = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED)) != -1
- && ListView_GetItem(hWnd, &lvi))
+ LVITEM lvi = {LVIF_PARAM, -1};
+ if (FindNextItem(&lvi, LVNI_FOCUSED))
iEpFocus = lvi.lParam;
}