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, 89 insertions, 0 deletions
diff --git a/c/episodelistview.c b/c/episodelistview.c
index 14fc6b9..28274ef 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -37,6 +37,77 @@ ElvCreate()
return HElv;
}
+int CALLBACK
+ElvSortNum(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
+{
+ int iOrder;
+ LVITEM lvi1, lvi2;
+ lvi1.mask = lvi2.mask = LVIF_PARAM;
+ lvi1.iItem = lParam1;
+ lvi2.iItem = lParam2;
+ if (!ListView_GetItem(HElv, &lvi1)) return 0;
+ if (!ListView_GetItem(HElv, &lvi2)) return 0;
+ switch (abs(lParamSort)) {
+ case 1:
+ iOrder = lvi1.lParam > lvi2.lParam? 1: -1;
+ break;
+ case 2:
+ {
+ int iRating1, iRating2;
+ term_t t, t2;
+ iRating1 = lParamSort > 0? 99: -1;
+ iRating2 = lParamSort > 0? 99: -1;
+ t = T(2);
+ PI(t,lvi1.lParam) goto e;
+ P("episode_data","episode_rating",2,t) goto e;
+ GI(t+1,&iRating1);
+ e: t2 = T(2);
+ PI(t2,lvi2.lParam) goto f;
+ P("episode_data","episode_rating",2,t2) goto f;
+ GI(t2+1,&iRating2);
+ f: iOrder = iRating1 > iRating2? 1: -1;
+ break;
+ }
+ }
+ return lParamSort > 0? iOrder: iOrder*-1;
+}
+
+int CALLBACK
+ElvSortAlpha(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
+{
+ int iOrder;
+ LVITEM lvi1, lvi2;
+ lvi1.mask = lvi2.mask = LVIF_PARAM;
+ lvi1.iItem = lParam1;
+ lvi2.iItem = lParam2;
+ if (!ListView_GetItem(HElv, &lvi1)) return 0;
+ if (!ListView_GetItem(HElv, &lvi2)) return 0;
+ switch (abs(lParamSort)) {
+ case 3:
+ {
+ char *sz1, *sz2;
+ int cch, cch1, cch2;
+ term_t t, t2;
+ t = T(2);
+ PI(t,lvi1.lParam) return 0;
+ P("episode_data","episode_title",2,t) return 0;
+ GAC(t+1,&sz1);
+ t2 = T(2);
+ PI(t2,lvi2.lParam) return 0;
+ P("episode_data","episode_title",2,t2) return 0;
+ GAC(t2+1,&sz2);
+ cch1 = strlen(sz1);
+ cch2 = strlen(sz2);
+ cch = cch1 > cch2? cch2: cch1;
+ iOrder = _strnicmp(sz1, sz2, cch);
+ break;
+ }
+ default:
+ return 0;
+ }
+ return lParamSort > 0? iOrder: iOrder*-1;
+}
+
LRESULT
ElvHandleNotify(LPARAM lParam)
{
@@ -53,6 +124,24 @@ ElvHandleNotify(LPARAM lParam)
DlvShowEpisode(lpNmLv->lParam);
}
break;
+ case LVN_COLUMNCLICK:
+ {
+ static int iSort = 1;
+ if (abs(iSort) == lpNmLv->iSubItem+1)
+ iSort = -iSort;
+ else
+ iSort = lpNmLv->iSubItem+1;
+ switch (lpNmLv->iSubItem) {
+ case 0:
+ case 1:
+ ListView_SortItemsEx(HElv, ElvSortNum, iSort);
+ break;
+ case 2:
+ ListView_SortItemsEx(HElv, ElvSortAlpha, iSort);
+ break;
+ }
+ break;
+ }
case NM_CUSTOMDRAW: /* Make unwatched episodes bold. */
{
LPNMLVCUSTOMDRAW lpLvCd;