diff options
-rw-r--r-- | c/episodelistview.cpp | 133 |
1 files changed, 76 insertions, 57 deletions
diff --git a/c/episodelistview.cpp b/c/episodelistview.cpp index 0cb95d6..7b9653e 100644 --- a/c/episodelistview.cpp +++ b/c/episodelistview.cpp @@ -301,70 +301,83 @@ int CALLBACK EpisodeListView::SortProc(const LPARAM iItem1, const LPARAM iItem2, /* Update episode list. */ void EpisodeListView::Update() { - int cEp, i, iEp, iEpFocus, iItem, iItemMark, iItemTopNew; - LVITEM lvi, lviEpisode, lviTop; - LVFINDINFO lvfi; - extern HWND g_hWndStatus; - static TCHAR tszDisp[16], tszEpisode[16]; - static std::vector<int> vEpSel; - - lviEpisode.mask = LVIF_TEXT|LVIF_PARAM; + if (!Pl("episode_data","ensure_episode_data")) return; /* Save scrolling position. */ - lviTop.iItem = ListView_GetTopIndex(hWnd); - lviTop.mask = LVIF_PARAM; - ListView_GetItem(hWnd, &lviTop); + int iEpTop = 0; + { + LVITEM lviTop; + lviTop.iItem = ListView_GetTopIndex(hWnd); + lviTop.mask = LVIF_PARAM; + ListView_GetItem(hWnd, &lviTop); + iEpTop = lviTop.lParam; + } /* Save selected episodes. */ - vEpSel.clear(); - lvi.mask = LVIF_PARAM; - lvi.iItem = -1; - while ((lvi.iItem = ListView_GetNextItem(hWnd, lvi.iItem, LVNI_SELECTED)) != -1) - if (ListView_GetItem(hWnd, &lvi)) - vEpSel.push_back(lvi.lParam); - iItemMark = ListView_GetSelectionMark(hWnd); + int iItemMark; + static std::vector<int> vEpSel; + { + LVITEM lvi; + lvi.mask = LVIF_PARAM; + lvi.iItem = -1; + vEpSel.clear(); + while ((lvi.iItem = ListView_GetNextItem(hWnd, lvi.iItem, LVNI_SELECTED)) != -1) + if (ListView_GetItem(hWnd, &lvi)) + vEpSel.push_back(lvi.lParam); + iItemMark = ListView_GetSelectionMark(hWnd); + } /* Save focus. */ - iEpFocus = 0; - if ((lvi.iItem = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED)) != -1 - && ListView_GetItem(hWnd, &lvi)) - iEpFocus = lvi.lParam; + int iEpFocus = 0; + { + LVITEM lvi; + lvi.mask = LVIF_PARAM; + if ((lvi.iItem = ListView_GetNextItem(hWnd, -1, LVNI_FOCUSED)) != -1 + && ListView_GetItem(hWnd, &lvi)) + iEpFocus = lvi.lParam; + } SendMessage(hWnd, WM_SETREDRAW, FALSE, 0); ListView_DeleteAllItems(hWnd); - if (!Pl("episode_data","ensure_episode_data")) return; + int cEp; if (!Pl("episode_data","episode_count",&cEp)) return; - for (iEp = 1, iItem = 0; iEp <= cEp; iEp++) { - Mark m; - extern char g_szLimitScreenwriter[]; - extern int g_bViewTVOriginal, g_bViewWatched; - - if (g_szLimitScreenwriter[0] - && !Pl("episode_data","episode_datum",iEp,"Screenwriter",g_szLimitScreenwriter)) - continue; - - if (!g_bViewWatched) - if (Pl("track_episodes","watched",iEp)) continue; - - if (!g_bViewTVOriginal) - if (Pl("episode_data","tv_original",iEp)) continue; - - /* Format episode number string. */ - _stprintf_s(tszEpisode, sizeof(tszEpisode), TEXT("%d"), iEp); - - /* Insert item. */ - lviEpisode.iItem = iItem++; - lviEpisode.iSubItem = ELVSIEPISODE; - lviEpisode.pszText = tszEpisode; - lviEpisode.lParam = iEp; - ListView_InsertItem(hWnd, &lviEpisode); - UpdateItem(&lviEpisode); + int cItem = 0; + { + TCHAR tszEpisode[16]; + LVITEM lviEpisode; + lviEpisode.mask = LVIF_TEXT|LVIF_PARAM; + for (int iEp = 1; iEp <= cEp; iEp++) { + extern char g_szLimitScreenwriter[]; + extern int g_bViewTVOriginal, g_bViewWatched; + + if (g_szLimitScreenwriter[0] + && !Pl("episode_data","episode_datum", + iEp,"Screenwriter",g_szLimitScreenwriter)) + continue; + + if (!g_bViewWatched) + if (Pl("track_episodes","watched",iEp)) continue; + + if (!g_bViewTVOriginal) + if (Pl("episode_data","tv_original",iEp)) continue; + + _stprintf_s(tszEpisode, sizeof(tszEpisode), TEXT("%d"), iEp); + + /* Insert item. */ + lviEpisode.iItem = cItem++; + lviEpisode.iSubItem = ELVSIEPISODE; + lviEpisode.pszText = tszEpisode; + lviEpisode.lParam = iEp; + ListView_InsertItem(hWnd, &lviEpisode); + UpdateItem(&lviEpisode); + } } Sort(); + LVFINDINFO lvfi; lvfi.flags = LVFI_PARAM; /* Reset selection. */ @@ -381,7 +394,7 @@ void EpisodeListView::Update() /* Reset focus. */ if (iEpFocus) { int iItemFocus; - i = 0; + int i = 0; do lvfi.lParam = iEpFocus+i; while ((iItemFocus = ListView_FindItem(hWnd, -1, &lvfi)) == -1 @@ -393,16 +406,22 @@ void EpisodeListView::Update() /* Try to reset scrolling position. Note that this must be * done last, as focusing an item scrolls it into view. */ - i = 0; - do - lvfi.lParam = lviTop.lParam+i; - while ((iItemTopNew = ListView_FindItem(hWnd, -1, &lvfi)) == -1 - && i++ < 100); - if (iItemTopNew != -1) - SetTop(iItemTopNew); + { + int iItemTopNew; + int i = 0; + do + lvfi.lParam = iEpTop+i; + while ((iItemTopNew = ListView_FindItem(hWnd, -1, &lvfi)) == -1 + && i++ < 100) + ; + if (iItemTopNew != -1) + SetTop(iItemTopNew); + } /* Show number of displayed items in status bar. */ - _stprintf_s(tszDisp, sizeof(tszDisp), TEXT("%d"), iItem); + extern HWND g_hWndStatus; + TCHAR tszDisp[16]; + _stprintf_s(tszDisp, sizeof(tszDisp), TEXT("%d"), cItem); SendMessage(g_hWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)tszDisp); SendMessage(hWnd, WM_SETREDRAW, TRUE, 0); |