diff options
author | John Ankarström <john@ankarstrom.se> | 2022-08-10 01:23:05 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-08-10 01:31:39 +0200 |
commit | 618f9bcf02ed8291e352cfea09f8f207930d5af4 (patch) | |
tree | ffb80b0862e09560fc16a302dc63b1363942b333 /c/episodelistview.cpp | |
parent | 49e859c0d2bf41fa648e0da45a6d5b114b0d2240 (diff) | |
download | EpisodeBrowser-618f9bcf02ed8291e352cfea09f8f207930d5af4.tar.gz |
Improve structure.
Diffstat (limited to 'c/episodelistview.cpp')
-rw-r--r-- | c/episodelistview.cpp | 47 |
1 files changed, 27 insertions, 20 deletions
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index ec8ab69..3856ce0 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -32,6 +32,7 @@ EpisodeListView::EpisodeListView(const HWND hWndParent) lvc.cx = Dpi(30); ListView_InsertColumn(hWnd, ELVSIRATING, &lvc); + /* Get saved sort-by-column setting. */ if (!Pl("cfg","get_sort",&m_iSortCol)) m_iSortCol = 1; } @@ -39,8 +40,8 @@ EpisodeListView::EpisodeListView(const HWND hWndParent) void EpisodeListView::EnsureFocusVisible() { const int iEpFocus = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED); - if (iEpFocus == -1) return; - ListView_EnsureVisible(hWnd, iEpFocus, TRUE); + if (iEpFocus != -1) + ListView_EnsureVisible(hWnd, iEpFocus, TRUE); } LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) @@ -49,22 +50,26 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) switch (nm->hdr.code) { case LVN_ITEMCHANGED: /* Select/focus episode. */ - if ((nm->uChanged & LVIF_STATE) && - (nm->uNewState & LVIS_FOCUSED)) { + if ((nm->uChanged & LVIF_STATE) && (nm->uNewState & LVIS_FOCUSED)) { extern DataListView* const g_dlv; UpdateItem(nm->iItem, nm->lParam); g_dlv->ShowEpisode(nm->lParam); } - break; + return 0; + case LVN_COLUMNCLICK: /* Sort by column. */ { - const int iColumn = nm->iSubItem+1; - m_iSortCol = abs(m_iSortCol) == iColumn? -m_iSortCol: iColumn; + const int iCol = nm->iSubItem+1; + + /* The sign of m_iSortCol decides the sort order. */ + m_iSortCol = abs(m_iSortCol) == iCol? -m_iSortCol: iCol; + Pl("cfg","set_sort",m_iSortCol); Sort(); ShowFocus(); - break; + return 0; } + case LVN_KEYDOWN: /* Navigate episodes by keyboard. */ { const NMLVKEYDOWN *const nm = reinterpret_cast<NMLVKEYDOWN*>(lParam); @@ -76,8 +81,9 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) SelectUnwatched(1); break; } - break; + return 0; } + case NM_CUSTOMDRAW: /* Make unwatched episodes bold. */ { const NMLVCUSTOMDRAW* const nm = reinterpret_cast<NMLVCUSTOMDRAW*>(lParam); @@ -86,45 +92,46 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) return CDRF_NOTIFYITEMDRAW; break; case CDDS_ITEMPREPAINT: - { - extern HFONT g_hfBold; if (!Pl("track_episodes","watched",nm->nmcd.lItemlParam)) { + extern HFONT g_hfBold; Require(SelectObject(nm->nmcd.hdc, g_hfBold)); return CDRF_NEWFONT; } break; - } } - break; + return 0; } + case NM_DBLCLK: /* Open clicked episode. */ { LVITEM lvi = {LVIF_PARAM, -1}; if (FindNextItem(&lvi, LVNI_FOCUSED)) Pl("local_episodes","open_episode_locally",lvi.lParam) || Pl("local_episodes","open_episode_online",lvi.lParam); - break; + return 0; } + case NM_RETURN: /* Open all selected episodes. */ { LVITEM lvi = {LVIF_PARAM, -1}; while (FindNextItem(&lvi, LVNI_SELECTED)) Pl("local_episodes","open_episode_locally",lvi.lParam) || Pl("local_episodes","open_episode_online",lvi.lParam); - break; + return 0; } + case NM_RCLICK: { extern HMENU g_hMenuPopup; const DWORD pos = GetMessagePos(); Require(TrackPopupMenu(g_hMenuPopup, TPM_RIGHTBUTTON, - LOWORD(pos), HIWORD(pos), 0, - m_hWndParent, nullptr)); - break; + LOWORD(pos), HIWORD(pos), 0, m_hWndParent, nullptr)); + return 0; } - } - return 0; + default: + return 0; + } } void EpisodeListView::Redraw() |