aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-02-14 22:43:58 +0100
committerJohn Ankarström <john@ankarstrom.se>2022-02-14 22:43:58 +0100
commit40cc4394cd21052447b012ee4cdf6d8fdca23493 (patch)
treeb3b262b7dff8dc2ea6157c7b8441cd47c4778ba6
parent9682b03872dea0da4cf8d5e6982d5821400d706a (diff)
downloadEpisodeBrowser-40cc4394cd21052447b012ee4cdf6d8fdca23493.tar.gz
Show unwatched episodes in bold font.
-rw-r--r--resource.h3
-rw-r--r--resource.rc1
-rw-r--r--win.c96
3 files changed, 81 insertions, 19 deletions
diff --git a/resource.h b/resource.h
index 6d3b85c..8167760 100644
--- a/resource.h
+++ b/resource.h
@@ -3,4 +3,5 @@
#define IDC_ABOUTTEXT 301
#define IDC_LISTVIEW 302
#define ID_FILE_EXIT 4001
-#define ID_FILE_ABOUT 4002
+#define ID_FILE_REFRESH 4002
+#define ID_FILE_ABOUT 4011
diff --git a/resource.rc b/resource.rc
index 9f8af6e..36fa014 100644
--- a/resource.rc
+++ b/resource.rc
@@ -7,6 +7,7 @@ IDR_MENU MENU
BEGIN
POPUP "&File"
BEGIN
+ MENUITEM "&Refresh", ID_FILE_REFRESH
MENUITEM "&Exit", ID_FILE_EXIT
END
POPUP "&Help"
diff --git a/win.c b/win.c
index b45a012..d9a94ab 100644
--- a/win.c
+++ b/win.c
@@ -10,19 +10,22 @@
#define CLASSNAME TEXT("Episode Browser")
HFONT g_GUIFont;
+HFONT g_GUIFontBold;
+int g_SelectedItem = -1;
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
static void CreateListView(HWND);
-static LRESULT HandleListViewNotify(HWND, NMLISTVIEW *);
+static LRESULT HandleListViewNotify(HWND, LPARAM);
-static HFONT GetGUIFont();
+static void SetupFonts();
static TCHAR *TSZFromSZ(char *, int);
static int Attach(void);
static void UpdateName(HWND, int);
static void UpdateList(HWND);
static void ShowEpisode(HWND, int);
+static int Watched(int);
/*
int main(int argc, char *argv[])
@@ -69,7 +72,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
icc.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&icc);
- g_GUIFont = GetGUIFont();
+ SetupFonts();
wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
@@ -127,6 +130,9 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case ID_FILE_EXIT:
PostMessage(hWnd, WM_CLOSE, 0, 0);
break;
+ case ID_FILE_REFRESH:
+ UpdateList(hWnd);
+ break;
case ID_FILE_ABOUT:
DialogBox(
GetModuleHandle(NULL),
@@ -143,19 +149,28 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case WM_SIZE:
{
HWND hListView;
+ int cxColumn;
RECT rc;
+ static int cxVScroll = 0;
+
+ if (cxVScroll == 0)
+ cxVScroll = GetSystemMetrics(SM_CXVSCROLL);
GetClientRect(hWnd, &rc);
hListView = GetDlgItem(hWnd, IDC_LISTVIEW);
MoveWindow(hListView, 0, 0,
rc.right, rc.bottom,
TRUE);
+
+ cxColumn = ListView_GetColumnWidth(hListView, 0);
+ ListView_SetColumnWidth(hListView, 1,
+ rc.right-cxColumn-cxVScroll);
}
break;
case WM_NOTIFY:
switch (((NMHDR *)lParam)->idFrom) {
case IDC_LISTVIEW:
- return HandleListViewNotify(hWnd, (NMLISTVIEW *)lParam);
+ return HandleListViewNotify(hWnd, lParam);
}
break;
default:
@@ -207,14 +222,16 @@ CreateListView(HWND hWnd)
NULL
);
- SendMessage(hListView,LVM_SETEXTENDEDLISTVIEWSTYLE,
- 0, LVS_EX_FULLROWSELECT);
-
SendMessage(hListView, WM_SETFONT,
(WPARAM)g_GUIFont, MAKELPARAM(FALSE, 0));
+ ListView_SetExtendedListViewStyle(hListView,
+ LVS_EX_DOUBLEBUFFER);
+
hModule = LoadLibrary(TEXT("uxtheme.dll"));
if (hModule && GetProcAddress(hModule, "SetWindowTheme")) {
+ ListView_SetExtendedListViewStyle(hListView,
+ LVS_EX_FULLROWSELECT|LVS_EX_DOUBLEBUFFER);
SendMessage(hListView, WM_CHANGEUISTATE,
MAKEWPARAM(UIS_SET, UISF_HIDEFOCUS), 0);
SetWindowTheme(hListView, TEXT("Explorer"), NULL);
@@ -224,7 +241,7 @@ CreateListView(HWND hWnd)
lvc.iSubItem = 0;
lvc.pszText = TEXT("#");
- lvc.cx = 40;
+ lvc.cx = 42;
ListView_InsertColumn(hListView, 0, &lvc);
lvc.iSubItem = 1;
@@ -236,19 +253,35 @@ CreateListView(HWND hWnd)
}
LRESULT
-HandleListViewNotify(HWND hWnd, NMLISTVIEW *pNmListView)
+HandleListViewNotify(HWND hWnd, LPARAM lParam)
{
- switch (pNmListView->hdr.code) {
+ NMLISTVIEW *pNmLv;
+
+ pNmLv = (NMLISTVIEW *)lParam;
+
+ switch (pNmLv->hdr.code) {
+ case LVN_ITEMCHANGED:
+ if ((pNmLv->uChanged & LVIF_STATE)
+ && (pNmLv->uNewState & LVIS_FOCUSED)) {
+ g_SelectedItem = pNmLv->iItem;
+ UpdateName(hWnd, pNmLv->lParam);
+ //ShowEpisode(hWnd, pNmLv->lParam);
+ }
+ break;
case NM_CUSTOMDRAW:
{
NMLVCUSTOMDRAW *pLvCd;
- pLvCd = (NMLVCUSTOMDRAW *)pNmListView;
+ pLvCd = (NMLVCUSTOMDRAW *)lParam;
switch (pLvCd->nmcd.dwDrawStage) {
case CDDS_PREPAINT:
- //return CDRF_NOTIFYITEMDRAW;
+ return CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
-
+ if (!Watched(pLvCd->nmcd.lItemlParam)) {
+ SelectObject(pLvCd->nmcd.hdc,
+ g_GUIFontBold);
+ return CDRF_NEWFONT;
+ }
break;
}
}
@@ -260,10 +293,11 @@ HandleListViewNotify(HWND hWnd, NMLISTVIEW *pNmListView)
/***/
-HFONT
-GetGUIFont()
+void
+SetupFonts()
{
HMODULE hModule;
+ LOGFONT lf;
hModule = LoadLibrary(TEXT("User32.dll"));
if (hModule && GetProcAddress(hModule, "SystemParametersInfoW")) {
@@ -272,10 +306,14 @@ GetGUIFont()
m.cbSize = sizeof(NONCLIENTMETRICS);
SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
sizeof(NONCLIENTMETRICS), &m, 0);
- return CreateFontIndirect(&m.lfMessageFont);
+ g_GUIFont = CreateFontIndirect(&m.lfMessageFont);
} else {
- return GetStockObject(DEFAULT_GUI_FONT);
+ g_GUIFont = GetStockObject(DEFAULT_GUI_FONT);
}
+
+ GetObject(g_GUIFont, sizeof(LOGFONT), &lf);
+ lf.lfWeight = FW_BOLD;
+ g_GUIFontBold = CreateFontIndirect(&lf);
}
/* Convert zero-terminated non-wide (multi-byte) string to
@@ -407,12 +445,14 @@ UpdateList(HWND hWnd)
hListView = GetDlgItem(hWnd, IDC_LISTVIEW);
+ ListView_DeleteAllItems(hListView);
+
lviEpisode.mask = LVIF_TEXT|LVIF_PARAM;
lviName.mask = LVIF_TEXT;
t = PL_new_term_refs(2);
PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("update_tracked_episodes", 0, "track_episode"),
+ PL_predicate("update_tracked_episodes", 0, "track_episodes"),
t);
q = PL_open_query(NULL, PL_Q_NORMAL,
@@ -474,6 +514,26 @@ UpdateList(HWND hWnd)
free(tszEpisode);
}
+ if (g_SelectedItem != -1) {
+ ListView_SetItemState(hListView, g_SelectedItem,
+ LVIS_SELECTED, LVIS_SELECTED);
+ ListView_EnsureVisible(hListView, g_SelectedItem, TRUE);
+ }
+
close:
PL_close_query(q);
}
+
+int
+Watched(int iEpisode)
+{
+ term_t t;
+
+ t = PL_new_term_refs(1);
+ if (!PL_put_integer(t+0, iEpisode))
+ return 0;
+
+ return PL_call_predicate(NULL, PL_Q_NORMAL,
+ PL_predicate("watched", 1, "track_episodes"),
+ t);
+}