aboutsummaryrefslogtreecommitdiff
path: root/c/episodelistview.cpp
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-08-17 02:33:26 +0200
committerJohn Ankarström <john@ankarstrom.se>2022-08-17 02:33:26 +0200
commitbd857d24443b8c8f5d2f58047c3f8ac5f058acea (patch)
tree0ef5f3c9abf5ccd6ee6a9e376ceac985de2409fd /c/episodelistview.cpp
parent8351d4c42c76584415e02a40d41f497a8f042c72 (diff)
downloadEpisodeBrowser-bd857d24443b8c8f5d2f58047c3f8ac5f058acea.tar.gz
Make FileView more type-safe.
Diffstat (limited to 'c/episodelistview.cpp')
-rw-r--r--c/episodelistview.cpp16
1 files changed, 9 insertions, 7 deletions
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp
index 0451132..be753a6 100644
--- a/c/episodelistview.cpp
+++ b/c/episodelistview.cpp
@@ -12,9 +12,11 @@
#include "util.h"
#include "win.h"
+constexpr size_t MAX_EPISODES = 8192;
+
EpisodeListView::EpisodeListView(const HWND hWndParent)
: ListView(hWndParent, reinterpret_cast<HMENU>(IDC_EPISODELISTVIEW), 0),
- m_fv(L"elvdata.dat", sizeof(ElvDataA)*8192)
+ m_fv(L"elvdata.dat", MAX_EPISODES)
{
LVCOLUMN lvc;
@@ -55,7 +57,7 @@ void EpisodeListView::HandleContextMenu(const WORD command)
LVITEM lvi = {LVIF_PARAM, -1};
while (FindNextItem(&lvi, LVNI_SELECTED)) {
- ElvDataA& e = static_cast<ElvDataA*>(m_fv)[lvi.lParam-1];
+ ElvDataA& e = m_fv.At(lvi.lParam-1);
if (ID_SUBGROUP(command) == IDG_CTX_RATE) {
/* Process rate commands. */
@@ -117,7 +119,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
case LVN_GETDISPINFO: /* Display item. */
{
NMLVDISPINFO* const nm = reinterpret_cast<NMLVDISPINFO*>(lParam);
- ElvDataA& e = reinterpret_cast<ElvDataA*>(m_fv.view)[nm->item.lParam-1];
+ ElvDataA& e = m_fv.At(nm->item.lParam-1);
wchar_t* vs[] = {e.siEp, e.title, e.sRating}; /* ELVSIEPISODE, ELVSITITLE, ELVSIRATING */
nm->item.pszText = vs[nm->item.iSubItem];
return 0;
@@ -166,7 +168,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam)
break;
case CDDS_ITEMPREPAINT:
{
- const ElvDataA& e = static_cast<ElvDataA*>(m_fv)[nm->nmcd.lItemlParam-1];
+ const ElvDataA& e = m_fv.At(nm->nmcd.lItemlParam-1);
if (!e.bWatched) {
extern HFONT g_hfBold;
Require(SelectObject(nm->nmcd.hdc, g_hfBold));
@@ -329,8 +331,8 @@ int CALLBACK EpisodeListView::SortProc(const LPARAM iItem1, const LPARAM iItem2,
* If m_iSortCol is negative, the order is descending. */
const int order = Cmp(elv->m_iSortCol, 0);
- const ElvDataA& e1 = static_cast<ElvDataA*>(elv->m_fv)[lvi1.lParam-1];
- const ElvDataA& e2 = static_cast<ElvDataA*>(elv->m_fv)[lvi2.lParam-1];
+ const ElvDataA& e1 = elv->m_fv[lvi1.lParam-1];
+ const ElvDataA& e2 = elv->m_fv.At(lvi2.lParam-1);
switch (abs(elv->m_iSortCol)-1) {
case ELVSIEPISODE:
@@ -398,7 +400,7 @@ void EpisodeListView::Update()
SendMessage(hWnd, WM_SETREDRAW, FALSE, 0);
ListView_DeleteAllItems(hWnd);
for (int iEp = 1; iEp <= cEp; iEp++) {
- ElvDataA e = static_cast<ElvDataA*>(m_fv)[iEp-1];
+ ElvDataA e = m_fv.At(iEp-1);
if (!e.siEp[0])
continue;