From 90c7bc237c9cf964c16f0cb48c308a92a8193a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Fri, 2 Sep 2022 02:11:49 +0200 Subject: Use global Window object. This makes it easier to control initialization and maintain RAII. --- c/episodelistview.cpp | 53 +++++++++++++++++++++++---------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) (limited to 'c/episodelistview.cpp') diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index 8581890..ea4849f 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -9,14 +9,12 @@ #include "episodelistview.h" #include "ext.h" #include "listview.h" +#include "main.h" #include "util.h" #include "win.h" -extern CfgA& g_cfg; -extern FileView g_fvElv; - -EpisodeListView::EpisodeListView(const HWND hWndParent) - : ListView(hWndParent, reinterpret_cast(IDC_EPISODELISTVIEW), 0) +EpisodeListView::EpisodeListView(Window& parent) + : ListView(parent, reinterpret_cast(IDC_EPISODELISTVIEW), 0) { LVCOLUMN lvc; @@ -37,7 +35,7 @@ EpisodeListView::EpisodeListView(const HWND hWndParent) ListView_InsertColumn(hWnd, ELVSIRATING, &lvc); /* Get saved sort-by-column setting. */ - m_iSortCol = g_cfg.iSortCol; + m_iSortCol = parent.cfg.iSortCol; } void EpisodeListView::EnsureFocusVisible() @@ -56,7 +54,7 @@ void EpisodeListView::HandleContextMenu(const WORD command) LVITEM lvi = {LVIF_PARAM, -1}; while (FindNextItem(&lvi, LVNI_SELECTED)) { - ElvDataA& e = g_fvElv.At(lvi.lParam-1); + ElvDataA& e = parent.fvElv.At(lvi.lParam-1); if (ID_SUBGROUP(command) == IDG_CTX_RATE) { /* Process rate commands. */ @@ -113,7 +111,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) case LVN_GETDISPINFO: /* Display item. */ { NMLVDISPINFO* const nm = reinterpret_cast(lParam); - ElvDataA& e = g_fvElv.At(nm->item.lParam-1); + ElvDataA& e = parent.fvElv.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; @@ -121,8 +119,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) case LVN_ITEMCHANGED: /* Select/focus episode. */ if ((nm->uChanged & LVIF_STATE) && (nm->uNewState & LVIS_FOCUSED)) { - extern DataListView* g_dlv; - g_dlv->ShowEpisode(nm->lParam); + parent.dlv.ShowEpisode(nm->lParam); } return 0; @@ -133,7 +130,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) /* The sign of m_iSortCol decides the sort order. */ m_iSortCol = abs(m_iSortCol) == iCol? -m_iSortCol: iCol; - g_cfg.iSortCol = m_iSortCol; + parent.cfg.iSortCol = m_iSortCol; Sort(); ShowFocus(); return 0; @@ -162,7 +159,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) break; case CDDS_ITEMPREPAINT: { - const ElvDataA& e = g_fvElv.At(nm->nmcd.lItemlParam-1); + const ElvDataA& e = parent.fvElv.At(nm->nmcd.lItemlParam-1); if (!e.bWatched) { extern HFONT g_hfBold; Require(SelectObject(nm->nmcd.hdc, g_hfBold)); @@ -188,7 +185,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) extern HMENU g_hMenuPopup; const DWORD pos = GetMessagePos(); Require(TrackPopupMenu(g_hMenuPopup, TPM_RIGHTBUTTON, - LOWORD(pos), HIWORD(pos), 0, m_hWndParent, nullptr)); + LOWORD(pos), HIWORD(pos), 0, parent.hWnd, nullptr)); return 0; } @@ -217,10 +214,9 @@ void EpisodeListView::RestoreFocus() { int i, iEpisode, iItem; LVFINDINFO lvfi; - extern DataListView* g_dlv; iItem = 0; - iEpisode = g_cfg.iFocus; + iEpisode = parent.cfg.iFocus; lvfi.flags = LVFI_PARAM; lvfi.lParam = iEpisode; @@ -237,7 +233,7 @@ void EpisodeListView::RestoreFocus() if (iItem != -1) goto s; return; -s: g_dlv->ShowEpisode(iEpisode); +s: parent.dlv.ShowEpisode(iEpisode); ListView_SetItemState(hWnd, -1, LVIF_STATE, LVIS_SELECTED); SetTop(iItem > 5? iItem-5: 0); ListView_SetItemState(hWnd, iItem, @@ -248,7 +244,7 @@ void EpisodeListView::SaveFocus() { LVITEM lvi = {LVIF_PARAM, -1}; if (FindNextItem(&lvi, LVNI_FOCUSED)) - g_cfg.iFocus = lvi.lParam; + parent.cfg.iFocus = lvi.lParam; } void EpisodeListView::SetTop(const int iItem) @@ -280,10 +276,10 @@ void EpisodeListView::SelectUnwatched(int dir) for (;;) { iEpNew += dir; if (iEpNew == 0 - || static_cast(iEpNew) > g_fvElv.c - || !g_fvElv[iEpNew-1].siEp[0]) + || static_cast(iEpNew) > parent.fvElv.c + || !parent.fvElv[iEpNew-1].siEp[0]) return; - if (!g_fvElv[iEpNew-1].bWatched) + if (!parent.fvElv[iEpNew-1].bWatched) break; } @@ -329,8 +325,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 = g_fvElv[lvi1.lParam-1]; - const ElvDataA& e2 = g_fvElv.At(lvi2.lParam-1); + const ElvDataA& e1 = elv->parent.fvElv[lvi1.lParam-1]; + const ElvDataA& e2 = elv->parent.fvElv.At(lvi2.lParam-1); switch (abs(elv->m_iSortCol)-1) { case ELVSIEPISODE: @@ -389,21 +385,20 @@ void EpisodeListView::Update() /* Retrieve episode data and add list view items. */ SendMessageW(hWnd, WM_SETREDRAW, FALSE, 0); ListView_DeleteAllItems(hWnd); - for (int iEp = 1; iEp <= g_cfg.cEp; iEp++) { - ElvDataA& e = g_fvElv.At(iEp-1); + for (int iEp = 1; iEp <= parent.cfg.cEp; iEp++) { + ElvDataA& e = parent.fvElv.At(iEp-1); if (!e.siEp[0]) continue; - if (extern FileView g_fvDlv; - g_cfg.limitToScreenwriter[0] - && wcscmp(g_fvDlv.At(iEp-1).screenwriter, g_cfg.limitToScreenwriter) != 0) + if (parent.cfg.limitToScreenwriter[0] + && wcscmp(parent.fvDlv.At(iEp-1).screenwriter, parent.cfg.limitToScreenwriter) != 0) continue; - if (!g_cfg.bViewWatched && e.bWatched) + if (!parent.cfg.bViewWatched && e.bWatched) continue; - if (!g_cfg.bViewTVOriginal && e.bTVOriginal) + if (!parent.cfg.bViewTVOriginal && e.bTVOriginal) continue; /* Insert item. */ -- cgit v1.2.3