diff options
-rw-r--r-- | c/datalistview.cpp | 4 | ||||
-rw-r--r-- | c/episodelistview.cpp | 145 | ||||
-rw-r--r-- | c/episodelistview.h | 6 | ||||
-rw-r--r-- | c/main.cpp | 2 |
4 files changed, 78 insertions, 79 deletions
diff --git a/c/datalistview.cpp b/c/datalistview.cpp index 704b689..517a055 100644 --- a/c/datalistview.cpp +++ b/c/datalistview.cpp @@ -11,8 +11,6 @@ #include "main.h" #include "pl.h" -extern EpisodeListView* const g_pElv; - DataListView::DataListView(const HWND hWndParent) : ListView(hWndParent, (HMENU)IDC_DATALISTVIEW, LVS_NOCOLUMNHEADER) { @@ -33,6 +31,8 @@ DataListView::DataListView(const HWND hWndParent) void DataListView::ShowEpisode(const int iEpisode) { + extern EpisodeListView* const g_pElv; + ListView_DeleteAllItems(hWnd); LVITEM lviKey, lviValue; 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; - } -} diff --git a/c/episodelistview.h b/c/episodelistview.h index 1f23959..48e7194 100644 --- a/c/episodelistview.h +++ b/c/episodelistview.h @@ -13,22 +13,22 @@ struct EpisodeListView : public ListView { EpisodeListView(HWND hWndParent); - void DoSort(); void EnsureFocusVisible(); LRESULT HandleNotify(LPARAM lParam); void Redraw(); + void RestoreFocus(); void SaveFocus(); void SetTop(int iItem); - void RestoreFocus(); void SelectUnwatched(int iDir); void ShowFocus(); + void Sort(); void Update(); void UpdateItem(const LVITEM* pLvi); LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) override; private: int m_iSort; LVITEM m_lviFocus; - friend int CALLBACK ElvSort(LPARAM lParam1, LPARAM lParam2, LPARAM lExtra); + static int CALLBACK SortProc(LPARAM lParam1, LPARAM lParam2, LPARAM lExtra); }; #endif @@ -462,7 +462,7 @@ LRESULT CALLBACK WndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam, case IDM_RATE1: case IDM_RATE0: g_pElv->Redraw(); - g_pElv->DoSort(); + g_pElv->Sort(); g_pElv->ShowFocus(); } b: break; |