aboutsummaryrefslogtreecommitdiff
path: root/c/episodelistview.c
diff options
context:
space:
mode:
Diffstat (limited to 'c/episodelistview.c')
-rw-r--r--c/episodelistview.c89
1 files changed, 46 insertions, 43 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c
index ad32b81..3b23c30 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -45,11 +45,7 @@ ElvCreate()
void
ElvDoSort()
{
- int iEpFocus;
ListView_SortItemsEx(HElv, ElvSort, ISort);
- iEpFocus = ListView_GetNextItem(HElv, -1, LVNI_FOCUSED);
- if (iEpFocus == -1) return;
- ListView_EnsureVisible(HElv, iEpFocus, TRUE);
}
LRESULT
@@ -78,6 +74,7 @@ ElvHandleNotify(LPARAM lParam)
PI(t,ISort) goto s;
P("cfg","set_sort",1,t);
s: ElvDoSort();
+ ElvShowFocus();
break;
}
case LVN_KEYDOWN: /* Navigate episodes by keyboard. */
@@ -156,6 +153,7 @@ ElvHandleNotify(LPARAM lParam)
return 0;
}
+
void
ElvRedraw()
{
@@ -221,16 +219,15 @@ ElvSelectUnwatched(int iDir)
/* Get focused episode. */
lviFocus.mask = LVIF_PARAM;
- lviFocus.iItem = -1;
- while ((lviFocus.iItem = ListView_GetNextItem(
- HElv, lviFocus.iItem, LVNI_FOCUSED)) != -1) {
- if (!ListView_GetItem(HElv, &lviFocus)) continue;
- }
+ if ((lviFocus.iItem = ListView_GetNextItem(HElv, -1, LVNI_FOCUSED)) != -1
+ && ListView_GetItem(HElv, &lviFocus))
+ ;
+ else
+ return;
i = 0;
lvfi.flags = LVFI_PARAM;
lvfi.lParam = lviFocus.lParam;
- bShift = GetAsyncKeyState(VK_SHIFT);
do {
t = T(2);
@@ -241,10 +238,8 @@ ElvSelectUnwatched(int iDir)
lvfi.lParam = iEpNew;
if ((iItemNew = ListView_FindItem(HElv, -1, &lvfi)) != -1) {
- if (!bShift) {
- ListView_SetItemState(HElv, -1,
- LVIF_STATE, LVIS_SELECTED);
- }
+ ListView_SetItemState(HElv,-1,LVIF_STATE,LVIS_SELECTED);
+ ListView_SetSelectionMark(HElv, iItemNew);
ListView_SetItemState(HElv, iItemNew,
LVIS_SELECTED|LVIS_FOCUSED,
LVIS_SELECTED|LVIS_FOCUSED);
@@ -255,6 +250,15 @@ ElvSelectUnwatched(int iDir)
} while (i++ < 1000);
}
+void
+ElvShowFocus()
+{
+ int iEpFocus;
+ iEpFocus = ListView_GetNextItem(HElv, -1, LVNI_FOCUSED);
+ if (iEpFocus == -1) return;
+ ListView_EnsureVisible(HElv, iEpFocus, TRUE);
+}
+
/* Sort list view items, iSort being the 1-based index of the column
* to sort by. If iSort is negative, the order is descending. */
int CALLBACK
@@ -318,7 +322,7 @@ ElvSort(LPARAM iItem1, LPARAM iItem2, LPARAM iSort)
void
ElvUpdate()
{
- int cEp, i, iEp, iEpFocus, iItem, iItemTopNew;
+ int cEp, i, iEp, iEpFocus, iItem, iItemMark, iItemTopNew;
LVITEM lvi, lviEpisode, lviTop;
LVFINDINFO lvfi;
term_t t;
@@ -339,20 +343,17 @@ ElvUpdate()
lvi.iItem = -1;
while ((lvi.iItem = ListView_GetNextItem(
HElv, lvi.iItem, LVNI_SELECTED)) != -1
- && i < 2048) {
- if (!ListView_GetItem(HElv, &lvi)) continue;
- aEpSel[i++] = lvi.lParam;
- }
+ && i < 2048)
+ if (ListView_GetItem(HElv, &lvi))
+ aEpSel[i++] = lvi.lParam;
aEpSel[i] = 0;
+ iItemMark = ListView_GetSelectionMark(HElv);
/* Save focus. */
iEpFocus = 0;
- lvi.iItem = -1;
- while ((lvi.iItem = ListView_GetNextItem(
- HElv, lvi.iItem, LVNI_FOCUSED)) != -1) {
- if (!ListView_GetItem(HElv, &lvi)) continue;
+ if ((lvi.iItem = ListView_GetNextItem(HElv, -1, LVNI_FOCUSED)) != -1
+ && ListView_GetItem(HElv, &lvi))
iEpFocus = lvi.lParam;
- }
SendMessage(HElv, WM_SETREDRAW, FALSE, 0);
ListView_DeleteAllItems(HElv);
@@ -393,47 +394,49 @@ ElvUpdate()
ElvUpdateItem(&lviEpisode);
}
- lvfi.flags = LVFI_PARAM;
+ ElvDoSort();
- /* Reset scrolling position (roughly). */
- i = 0;
- do
- lvfi.lParam = lviTop.lParam+i;
- while ((iItemTopNew = ListView_FindItem(HElv, -1, &lvfi)) == -1
- && i++ < 100);
- if (iItemTopNew != -1)
- ElvSetTop(iItemTopNew);
+ lvfi.flags = LVFI_PARAM;
/* Reset selection. */
for (i = 0; aEpSel[i]; i++) {
- int iSel;
+ int iItemSel;
lvfi.lParam = aEpSel[i];
- if ((iSel = ListView_FindItem(HElv, -1, &lvfi)) != -1)
- ListView_SetItemState(HElv, iSel,
+ if ((iItemSel = ListView_FindItem(HElv, -1, &lvfi)) != -1)
+ ListView_SetItemState(HElv, iItemSel,
LVIS_SELECTED, LVIS_SELECTED);
}
+ if (iItemMark != -1)
+ ListView_SetSelectionMark(HElv, iItemMark);
/* Reset focus. */
if (iEpFocus) {
- int iFocus;
+ int iItemFocus;
i = 0;
do
lvfi.lParam = iEpFocus+i;
- while ((iFocus = ListView_FindItem(HElv, -1, &lvfi)) == -1
+ while ((iItemFocus = ListView_FindItem(HElv, -1, &lvfi)) == -1
&& i++ < 100);
- if (iFocus != -1)
- ListView_SetItemState(HElv, iFocus,
+ if (iItemFocus != -1)
+ ListView_SetItemState(HElv, iItemFocus,
LVIS_FOCUSED, LVIS_FOCUSED);
}
+ /* 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(HElv, -1, &lvfi)) == -1
+ && i++ < 100);
+ if (iItemTopNew != -1)
+ ElvSetTop(iItemTopNew);
+
_stprintf_s(tszDisp, sizeof(tszDisp), TEXT("%d"), iItem);
SendMessage(HWndStatus, SB_SETTEXT, MAKEWPARAM(1,0), (LPARAM)tszDisp);
_stprintf_s(tszTotal, sizeof(tszTotal), TEXT("%d"), cEp);
SendMessage(HWndStatus, SB_SETTEXT, MAKEWPARAM(2,0), (LPARAM)tszTotal);
SendMessage(HElv, WM_SETREDRAW, TRUE, 0);
- if (ISort != 1)
- ListView_SortItemsEx(HElv, ElvSort, ISort);
- ElvRedraw();
}
/* Update episode name and rating. */