diff options
author | John Ankarström <john@ankarstrom.se> | 2022-07-19 14:50:00 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-07-19 14:50:00 +0200 |
commit | bc6d9cdf289af9167912329f1c5f4e39bd6bac29 (patch) | |
tree | 27c5c0f75bd631f0ddf32feddb13d14ad8bf1b1d /c/episodelistview.cpp | |
parent | 2ffbd7fcc178e68e7132d2f8f649d131c5a5d3af (diff) | |
download | EpisodeBrowser-bc6d9cdf289af9167912329f1c5f4e39bd6bac29.tar.gz |
Use static member function instead of friend function.
Diffstat (limited to 'c/episodelistview.cpp')
-rw-r--r-- | c/episodelistview.cpp | 145 |
1 files changed, 72 insertions, 73 deletions
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index d43c3a7..c08e6f8 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -10,9 +10,6 @@ #include "listview.h" #include "pl.h" -extern DataListView* const g_pDlv; -int CALLBACK ElvSort(LPARAM, LPARAM, LPARAM); - EpisodeListView::EpisodeListView(const HWND hWndParent) : ListView(hWndParent, (HMENU)IDC_EPISODELISTVIEW, 0) { @@ -38,11 +35,6 @@ EpisodeListView::EpisodeListView(const HWND hWndParent) m_iSort = 1; } -void EpisodeListView::DoSort() -{ - ListView_SortItemsEx(hWnd, ElvSort, (LPARAM)this); -} - void EpisodeListView::EnsureFocusVisible() { const int iEpFocus = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED); @@ -58,6 +50,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) case LVN_ITEMCHANGED: /* Select/focus episode. */ if ((pNmLv->uChanged & LVIF_STATE) && (pNmLv->uNewState & LVIS_FOCUSED)) { + extern DataListView* const g_pDlv; m_lviFocus.iItem = pNmLv->iItem; m_lviFocus.lParam = pNmLv->lParam; UpdateItem(&m_lviFocus); @@ -69,7 +62,7 @@ LRESULT EpisodeListView::HandleNotify(const LPARAM lParam) const int iColumn = pNmLv->iSubItem+1; m_iSort = abs(m_iSort) == iColumn? -m_iSort: iColumn; Pl("cfg","set_sort",m_iSort); - DoSort(); + Sort(); ShowFocus(); break; } @@ -148,27 +141,12 @@ void EpisodeListView::Redraw() RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN); } -void EpisodeListView::SaveFocus() -{ - LVITEM lvi; - lvi.mask = LVIF_PARAM; - if ((lvi.iItem = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED)) != -1 - && ListView_GetItem(hWnd, &lvi)) - Pl("cfg","set_focus",lvi.lParam); -} - -void EpisodeListView::SetTop(const int iItem) -{ - const int iLast = ListView_GetItemCount(hWnd)-1; - ListView_EnsureVisible(hWnd, iLast, TRUE); - ListView_EnsureVisible(hWnd, iItem, TRUE); -} - /* Select previously focused episode. */ void EpisodeListView::RestoreFocus() { int i, iEpisode, iItem; LVFINDINFO lvfi; + extern DataListView* const g_pDlv; iItem = 0; if (!Pl("cfg","get_focus",&iEpisode)) return; @@ -198,6 +176,22 @@ s: ListView_SetItemState(hWnd, -1, LVIF_STATE, LVIS_SELECTED); g_pDlv->ShowEpisode(iEpisode); } +void EpisodeListView::SaveFocus() +{ + LVITEM lvi; + lvi.mask = LVIF_PARAM; + if ((lvi.iItem = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED)) != -1 + && ListView_GetItem(hWnd, &lvi)) + Pl("cfg","set_focus",lvi.lParam); +} + +void EpisodeListView::SetTop(const int iItem) +{ + const int iLast = ListView_GetItemCount(hWnd)-1; + ListView_EnsureVisible(hWnd, iLast, TRUE); + ListView_EnsureVisible(hWnd, iItem, TRUE); +} + /* Select next/previous unwatched episode. */ void EpisodeListView::SelectUnwatched(int iDir) { @@ -242,6 +236,58 @@ void EpisodeListView::ShowFocus() ListView_EnsureVisible(hWnd, iEpFocus, TRUE); } +void EpisodeListView::Sort() +{ + ListView_SortItemsEx(hWnd, EpisodeListView::SortProc, (LPARAM)this); +} + +int CALLBACK EpisodeListView::SortProc(const LPARAM iItem1, const LPARAM iItem2, const LPARAM lExtra) +{ + EpisodeListView* const pElv = (EpisodeListView*)lExtra; + + LVITEM lvi1, lvi2; + lvi1.mask = lvi2.mask = LVIF_PARAM; + lvi1.iItem = iItem1; lvi2.iItem = iItem2; + if (!ListView_GetItem(pElv->hWnd, &lvi1)) return 0; + if (!ListView_GetItem(pElv->hWnd, &lvi2)) return 0; + + /* abs(m_iSort) is the 1-based index of the column to sort by. + * If m_iSort is negative, the order is descending. */ + const int iOrder = Cmp(pElv->m_iSort, 0); + + switch (abs(pElv->m_iSort)-1) { + case ELVSIEPISODE: + return iOrder*Cmp(lvi1.lParam, lvi2.lParam); + case ELVSIRATING: + { + int iRating1, iRating2; + iRating1 = pElv->m_iSort > 0? 99: -1; + iRating2 = pElv->m_iSort > 0? 99: -1; + Pl("episode_data","episode_rating",lvi1.lParam,&iRating1); + Pl("episode_data","episode_rating",lvi2.lParam,&iRating2); + if (iRating1 == iRating2) + return Cmp(lvi1.lParam, lvi2.lParam); + return iOrder*Cmp(iRating1, iRating2); + } + case ELVSITITLE: + { + Mark m; + char* sz1,* sz2; + int cch, cch1, cch2; + if (!Pl("episode_data","episode_title",lvi1.lParam,&sz1)) + return 0; + if (!Pl("episode_data","episode_title",lvi2.lParam,&sz2)) + return 0; + cch1 = strlen(sz1); + cch2 = strlen(sz2); + cch = cch1 > cch2? cch2: cch1; + return iOrder*_strnicmp(sz1, sz2, cch); + } + default: + return 0; + } +} + /* Update episode list. */ void EpisodeListView::Update() { @@ -310,7 +356,7 @@ void EpisodeListView::Update() UpdateItem(&lviEpisode); } - DoSort(); + Sort(); lvfi.flags = LVFI_PARAM; @@ -398,50 +444,3 @@ LRESULT CALLBACK EpisodeListView::WndProc(const HWND hWnd, const UINT uMsg, return ListView::WndProc(hWnd, uMsg, wParam, lParam); } - -int CALLBACK ElvSort(const LPARAM iItem1, const LPARAM iItem2, const LPARAM lExtra) -{ - EpisodeListView* const pElv = (EpisodeListView*)lExtra; - - LVITEM lvi1, lvi2; - lvi1.mask = lvi2.mask = LVIF_PARAM; - lvi1.iItem = iItem1; lvi2.iItem = iItem2; - if (!ListView_GetItem(pElv->hWnd, &lvi1)) return 0; - if (!ListView_GetItem(pElv->hWnd, &lvi2)) return 0; - - /* abs(m_iSort) is the 1-based index of the column to sort by. - * If m_iSort is negative, the order is descending. */ - const int iOrder = Cmp(pElv->m_iSort, 0); - - switch (abs(pElv->m_iSort)-1) { - case ELVSIEPISODE: - return iOrder*Cmp(lvi1.lParam, lvi2.lParam); - case ELVSIRATING: - { - int iRating1, iRating2; - iRating1 = pElv->m_iSort > 0? 99: -1; - iRating2 = pElv->m_iSort > 0? 99: -1; - Pl("episode_data","episode_rating",lvi1.lParam,&iRating1); - Pl("episode_data","episode_rating",lvi2.lParam,&iRating2); - if (iRating1 == iRating2) - return Cmp(lvi1.lParam, lvi2.lParam); - return iOrder*Cmp(iRating1, iRating2); - } - case ELVSITITLE: - { - Mark m; - char* sz1,* sz2; - int cch, cch1, cch2; - if (!Pl("episode_data","episode_title",lvi1.lParam,&sz1)) - return 0; - if (!Pl("episode_data","episode_title",lvi2.lParam,&sz2)) - return 0; - cch1 = strlen(sz1); - cch2 = strlen(sz2); - cch = cch1 > cch2? cch2: cch1; - return iOrder*_strnicmp(sz1, sz2, cch); - } - default: - return 0; - } -} |