aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--c/episodelistview.cpp36
-rw-r--r--c/listview.cpp8
-rw-r--r--c/listview.h2
-rw-r--r--c/main.cpp7
5 files changed, 24 insertions, 31 deletions
diff --git a/Makefile b/Makefile
index 83c0360..402e81c 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ PL = pl/cfg.pl pl/episode_data.pl pl/local_episodes.pl pl/track_episodes.pl
CL = swipl-ld
CLFLAGS = -DUNICODE -D_UNICODE
-CLFLAGS += -cc-options,-std=c++17 -Wall -Wextra -Wpedantic -O2
+CLFLAGS += -cc-options,-std=c++17 -Wall -Wextra -Wpedantic -Wno-missing-field-initializers -O2
CLFLAGS += -ld-options,-mwindows,-static-libstdc++ -lcomctl32 -luxtheme
all: showdeps b/$(EXE)
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;
}
diff --git a/c/listview.cpp b/c/listview.cpp
index 62dfba8..b4a61b4 100644
--- a/c/listview.cpp
+++ b/c/listview.cpp
@@ -29,6 +29,14 @@ ListView::ListView(const HWND hWndParent, const HMENU hMenu, const DWORD dwStyle
SendMessage(hWnd, WM_SETFONT, (WPARAM)g_hfNormal, MAKELPARAM(FALSE, 0));
}
+/* Retrieve next matching list view item. */
+bool ListView::FindNextItem(LVITEM* const lvi, const LPARAM lParam)
+{
+ if ((lvi->iItem = ListView_GetNextItem(hWnd, lvi->iItem, lParam)) == -1)
+ return false;
+ return ListView_GetItem(hWnd, lvi);
+}
+
/* Naively calculate height of list view. */
int ListView::Height(int bHeader)
{
diff --git a/c/listview.h b/c/listview.h
index 478819f..858b156 100644
--- a/c/listview.h
+++ b/c/listview.h
@@ -2,12 +2,14 @@
#define LISTVIEW_H
#include <windows.h>
+#include <commctrl.h>
struct ListView
{
HWND hWnd;
ListView(HWND hWndParent, HMENU hMenu, DWORD dwStyle);
+ bool FindNextItem(LVITEM* lvi, LPARAM lParam);
int Height(int bHeader = -1);
virtual void ResizeColumns(int w);
virtual void UpdateTheme(BOOL bThemeActive);
diff --git a/c/main.cpp b/c/main.cpp
index 673affe..7fef22e 100644
--- a/c/main.cpp
+++ b/c/main.cpp
@@ -406,16 +406,13 @@ void WndProcMainMenu(const HWND hWnd, unsigned short wCommand)
/* Process context menu commands. */
void WndProcContextMenu(const HWND, unsigned short wCommand)
{
- LVITEM lvi;
int cNotFound = 0;
/* Look through selected items, applying the
* selected command to each one. */
- lvi.mask = LVIF_PARAM;
- lvi.iItem = -1;
- while ((lvi.iItem = ListView_GetNextItem(g_pElv->hWnd, lvi.iItem, LVNI_SELECTED)) != -1
- && ListView_GetItem(g_pElv->hWnd, &lvi)) {
+ LVITEM lvi = {LVIF_PARAM, -1};
+ while (g_pElv->FindNextItem(&lvi, LVNI_SELECTED)) {
/* Process rate commands. */
if (ID_SUBGROUP(wCommand) == IDG_CTX_RATE) {