From bd857d24443b8c8f5d2f58047c3f8ac5f058acea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 17 Aug 2022 02:33:26 +0200 Subject: Make FileView more type-safe. --- c/episodelistview.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'c/episodelistview.cpp') 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(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(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(lParam); - ElvDataA& e = reinterpret_cast(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(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(elv->m_fv)[lvi1.lParam-1]; - const ElvDataA& e2 = static_cast(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(m_fv)[iEp-1]; + ElvDataA e = m_fv.At(iEp-1); if (!e.siEp[0]) continue; -- cgit v1.2.3