aboutsummaryrefslogtreecommitdiff
path: root/c
diff options
context:
space:
mode:
Diffstat (limited to 'c')
-rw-r--r--c/common.c19
-rw-r--r--c/datalistview.c62
-rw-r--r--c/defs.h16
-rw-r--r--c/episodelistview.c209
-rw-r--r--c/listview.c29
-rw-r--r--c/main.c88
6 files changed, 181 insertions, 242 deletions
diff --git a/c/common.c b/c/common.c
index a4debc3..af5638d 100644
--- a/c/common.c
+++ b/c/common.c
@@ -2,6 +2,7 @@
#include <SWI-Prolog.h>
#include "resource.h"
+#include "defs.h"
/* Convert zero-terminated non-wide (multi-byte) string to
* zero-terminated wide/non-wide string depending on UNICODE. */
@@ -16,14 +17,12 @@ TSZFromSZ(const char *sz, int iCp)
cbMultiByte = strlen(sz)+1;
cchWideChar = MultiByteToWideChar(iCp, 0, sz, cbMultiByte, NULL, 0);
tsz = malloc(cchWideChar*sizeof(WCHAR));
- if (!tsz)
- return NULL;
+ if (!tsz) return NULL;
if (!MultiByteToWideChar(iCp, 0, sz, cbMultiByte, tsz, cchWideChar))
return NULL;
#else
tsz = malloc(strlen(sz)+1);
- if (!tsz)
- return NULL;
+ if (!tsz) return NULL;
strcpy(tsz, sz);
#endif
@@ -34,12 +33,8 @@ 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);
+ t = T(1);
+ PI(t,iEpisode) return 0;
+ P("track_episodes","watched",1,t) return 0;
+ return 1;
}
diff --git a/c/datalistview.c b/c/datalistview.c
index e37375d..d859e24 100644
--- a/c/datalistview.c
+++ b/c/datalistview.c
@@ -1,33 +1,33 @@
#include <windows.h>
+#include <commctrl.h>
#include <SWI-Prolog.h>
#include "resource.h"
#include "defs.h"
-HWND gDlv_hWnd;
+HWND Dlv_hWnd;
HWND
DlvCreate(HWND hWnd)
{
- HWND hListView;
+ HWND hDlv;
LVCOLUMN lvc;
- gDlv_hWnd = hWnd;
- hListView = LvCreate(hWnd, (HMENU)IDC_DATALISTVIEW);
+ Dlv_hWnd = hWnd;
+ hDlv = LvCreate(hWnd, (HMENU)IDC_DATALISTVIEW);
lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
-
lvc.iSubItem = 0;
lvc.pszText = TEXT("Key");
lvc.cx = 42;
- ListView_InsertColumn(hListView, 0, &lvc);
+ ListView_InsertColumn(hDlv, 0, &lvc);
lvc.iSubItem = 1;
lvc.pszText = TEXT("Value");
lvc.cx = 500;
- ListView_InsertColumn(hListView, 1, &lvc);
+ ListView_InsertColumn(hDlv, 1, &lvc);
- return hListView;
+ return hDlv;
}
/* Show episode data. */
@@ -35,26 +35,20 @@ void
DlvShowEpisode(int iEpisode)
{
fid_t f;
- HWND hListView;
+ HWND hDlv;
LVITEM lviKey, lviValue;
term_t t;
- hListView = GetDlgItem(gDlv_hWnd, IDC_DATALISTVIEW);
- ListView_DeleteAllItems(hListView);
+ hDlv = GetDlgItem(Dlv_hWnd, IDC_DATALISTVIEW);
+ ListView_DeleteAllItems(hDlv);
lviKey.mask = LVIF_TEXT;
lviValue.mask = LVIF_TEXT;
- f = PL_open_foreign_frame();
- t = PL_new_term_refs(3);
-
- if(!PL_put_integer(t+0, iEpisode))
- return;
-
- if (!PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("lookup_episode_local", 3, "episode_data"),
- t))
- return;
+ F(f);
+ t = T(3);
+ PI(t,iEpisode) goto e;
+ P("episode_data","lookup_episode_local",3,t) goto e;
/* The episode data is a list of unary compounds,
* whose functor is the key and whose argument is the value. */
@@ -73,40 +67,34 @@ DlvShowEpisode(int iEpisode)
term_t tValue;
size_t iArity;
- if (!PL_get_name_arity(tHead, &aKey, &iArity))
- continue;
+ if (!PL_get_name_arity(tHead,&aKey,&iArity)) continue;
szKey = PL_atom_chars(aKey);
- if (!szKey)
- continue;
+ if (!szKey) continue;
tValue = PL_new_term_ref();
- if (!PL_get_arg(1, tHead, tValue))
- continue;
- if (!PL_get_atom_chars(tValue, &szValue))
- continue;
+ if (!PL_get_arg(1, tHead, tValue)) continue;
+ GAC(tValue,&szValue) continue;
tszKey = TSZFromSZ(szKey, CP_UTF8);
- if (!tszKey)
- continue;
+ if (!tszKey) continue;
tszValue = TSZFromSZ(szValue, CP_UTF8);
- if (!tszValue)
- continue;
+ if (!tszValue) goto e1;
lviKey.mask = LVIF_TEXT;
lviKey.iItem = i;
lviKey.iSubItem = 0;
lviKey.pszText = tszKey;
- ListView_InsertItem(hListView, &lviKey);
+ ListView_InsertItem(hDlv, &lviKey);
lviValue.iItem = i;
lviValue.iSubItem = 1;
lviValue.pszText = tszValue;
- ListView_SetItem(hListView, &lviValue);
+ ListView_SetItem(hDlv, &lviValue);
- free(tszKey);
free(tszValue);
+e1: free(tszKey);
}
}
- PL_close_foreign_frame(f);
+e: Fd(f);
}
diff --git a/c/defs.h b/c/defs.h
index ad1001a..db5af3a 100644
--- a/c/defs.h
+++ b/c/defs.h
@@ -1,9 +1,6 @@
#ifndef DEFS_H
#define DEFS_H
-#include <windows.h>
-#include <commctrl.h>
-
/* common.c */
TCHAR *TSZFromSZ(const char *, int);
int Watched(int);
@@ -18,6 +15,7 @@ HWND LvCreate(HWND, HMENU);
HWND ElvCreate(HWND);
LRESULT ElvHandleNotify(LPARAM);
int ElvItemEpisode(int);
+void ElvRedraw(void);
void ElvSelectRecent(void);
void ElvUpdate(void);
void ElvUpdateName(int, int);
@@ -26,4 +24,16 @@ void ElvUpdateName(int, int);
HWND DlvCreate(HWND);
void DlvShowEpisode(int);
+#define P(m,p,a,t) if (!PL_call_predicate(NULL, PL_Q_NORMAL, \
+ PL_predicate(p,a,m), t))
+#define Q(m,p,a,t) PL_open_query(NULL, PL_Q_NORMAL, PL_predicate(p,a,m), t)
+#define Qn(q) PL_next_solution(q)
+#define Qc(q) PL_cut_query(q)
+#define F(f) f = PL_open_foreign_frame()
+#define Fd(f) PL_discard_foreign_frame(f)
+#define T(a) PL_new_term_refs(a)
+#define PI(t,x) if (!PL_put_integer(t,x))
+#define GI(t,x) if (!PL_get_integer(t,x))
+#define GAC(t,x) if (!PL_get_atom_chars(t,x))
+
#endif
diff --git a/c/episodelistview.c b/c/episodelistview.c
index 7d87b7a..3b42be0 100644
--- a/c/episodelistview.c
+++ b/c/episodelistview.c
@@ -7,50 +7,46 @@
#include "defs.h"
extern HFONT g_GUIFontBold;
-
-HWND gElv_hWnd;
-WNDPROC g_PrevElvProc;
-int g_iSelectedItem = -1; /* Remembered after refresh. */
+HWND Elv_hWnd;
+int Elv_iSelectedItem = -1;
+WNDPROC Elv_PrevProc;
HWND
ElvCreate(HWND hWnd)
{
- HWND hListView;
+ HWND hElv;
LVCOLUMN lvc;
- gElv_hWnd = hWnd;
- hListView = LvCreate(hWnd, (HMENU)IDC_EPISODELISTVIEW);
+ Elv_hWnd = hWnd;
+ hElv = LvCreate(hWnd, (HMENU)IDC_EPISODELISTVIEW);
lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
-
lvc.iSubItem = 0;
lvc.pszText = TEXT("#");
lvc.cx = 42;
- ListView_InsertColumn(hListView, 0, &lvc);
+ ListView_InsertColumn(hElv, 0, &lvc);
lvc.iSubItem = 1;
lvc.pszText = TEXT("Title");
lvc.cx = 500;
- ListView_InsertColumn(hListView, 1, &lvc);
+ ListView_InsertColumn(hElv, 1, &lvc);
ElvUpdate();
ElvSelectRecent();
-
- return hListView;
+ return hElv;
}
LRESULT
ElvHandleNotify(LPARAM lParam)
{
NMLISTVIEW *pNmLv;
-
pNmLv = (NMLISTVIEW *)lParam;
switch (pNmLv->hdr.code) {
case LVN_ITEMCHANGED:
if ((pNmLv->uChanged & LVIF_STATE)
&& (pNmLv->uNewState & LVIS_FOCUSED)) {
- g_iSelectedItem = pNmLv->iItem;
+ Elv_iSelectedItem = pNmLv->iItem;
ElvUpdateName(pNmLv->iItem, pNmLv->lParam);
DlvShowEpisode(pNmLv->lParam);
}
@@ -76,14 +72,9 @@ ElvHandleNotify(LPARAM lParam)
case NM_DBLCLK:
{
term_t t;
-
- t = PL_new_term_refs(1);
- if (!PL_put_integer(t+0, ElvItemEpisode(g_iSelectedItem)))
- break;
-
- PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("open_episode", 1,
- "local_episodes"), t);
+ t = T(1);
+ PI(t+0, ElvItemEpisode(Elv_iSelectedItem)) break;
+ P("local_episodes","open_episode",1,t);
break;
}
case NM_RCLICK:
@@ -91,12 +82,10 @@ ElvHandleNotify(LPARAM lParam)
DWORD dwPos;
NMITEMACTIVATE *pNmItem;
extern HMENU g_hPopupMenu;
-
dwPos = GetMessagePos();
-
TrackPopupMenu(g_hPopupMenu, TPM_RIGHTBUTTON,
LOWORD(dwPos), HIWORD(dwPos), 0,
- gElv_hWnd, NULL);
+ Elv_hWnd, NULL);
break;
}
}
@@ -106,18 +95,22 @@ ElvHandleNotify(LPARAM lParam)
int
ElvItemEpisode(int iItem) {
- HWND hListView;
+ HWND hElv;
LVITEM lvi;
-
- hListView = GetDlgItem(gElv_hWnd, IDC_EPISODELISTVIEW);
+ hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
lvi.mask = LVIF_PARAM;
lvi.iItem = iItem;
lvi.iSubItem = 0;
+ return ListView_GetItem(hElv, &lvi) ? lvi.lParam : -1;
+}
- if (!ListView_GetItem(hListView, &lvi))
- return -1;
-
- return lvi.lParam;
+void
+ElvRedraw()
+{
+ HWND hElv;
+ hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
+ RedrawWindow(hElv, NULL, NULL,
+ RDW_ERASE|RDW_FRAME|RDW_INVALIDATE|RDW_ALLCHILDREN);
}
/* Select most recent episode. */
@@ -125,38 +118,30 @@ void
ElvSelectRecent()
{
fid_t f;
- HWND hListView;
+ HWND hElv;
int iEpisode, iItem;
LVFINDINFO lvfi;
term_t t;
- f = PL_open_foreign_frame(); /* Needed? */
+ F(f);
+ t = T(1);
+ P("track_episodes","most_recently_watched",1,t) goto e;
+ GI(t, &iEpisode) goto e;
- t = PL_new_term_refs(1);
- if (!PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("most_recently_watched", 1, "track_episodes"),
- t))
- goto end;
-
- if (!PL_get_integer(t+0, &iEpisode))
- goto end;
-
- hListView = GetDlgItem(gElv_hWnd, IDC_EPISODELISTVIEW);
+ hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
lvfi.flags = LVFI_PARAM;
lvfi.lParam = iEpisode;
- iItem = ListView_FindItem(hListView, -1, &lvfi);
- if (iItem == -1)
- goto end;
+ iItem = ListView_FindItem(hElv, -1, &lvfi);
+ if (iItem == -1) goto e;
- ListView_EnsureVisible(hListView, iItem, TRUE);
- ListView_SetItemState(hListView, iItem, LVIS_SELECTED, LVIS_SELECTED);
- g_iSelectedItem = iItem;
+ ListView_EnsureVisible(hElv, iItem, TRUE);
+ ListView_SetItemState(hElv, iItem, LVIS_SELECTED, LVIS_SELECTED);
+ Elv_iSelectedItem = iItem;
ElvUpdateName(iItem, iEpisode);
DlvShowEpisode(iEpisode);
-end:
- PL_discard_foreign_frame(f);
+e: Fd(f);
}
/* Update episode list. */
@@ -164,64 +149,50 @@ void
ElvUpdate()
{
fid_t f;
- HWND hListView;
- int iTop;
+ HWND hElv;
+ int iLast, iTop;
LVITEM lviEpisode, lviName;
qid_t q;
term_t t;
- hListView = GetDlgItem(gElv_hWnd, IDC_EPISODELISTVIEW);
- SendMessage(hListView, WM_SETREDRAW, FALSE, 0);
- iTop = ListView_GetTopIndex(hListView);
- ListView_DeleteAllItems(hListView);
+ hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
+ SendMessage(hElv, WM_SETREDRAW, FALSE, 0);
+ iTop = ListView_GetTopIndex(hElv);
+ ListView_DeleteAllItems(hElv);
lviEpisode.mask = LVIF_TEXT|LVIF_PARAM;
lviName.mask = LVIF_TEXT;
- f = PL_open_foreign_frame();
- t = PL_new_term_refs(2);
- PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("update_tracked_episodes", 0, "track_episodes"),
- t);
+ F(f);
+ t = T(2);
+ P("track_episodes","update_tracked_episodes",0,t);
+ q = Q("local_episodes","episode_file",2,t);
- q = PL_open_query(NULL, PL_Q_NORMAL,
- PL_predicate("episode_file", 2, "local_episodes"),
- t);
-
- for (int i = 0; PL_next_solution(q); i++) {
+ for (int i = 0; Qn(q); i++) {
char *szName;
+ fid_t f2;
int cb, iEpisode, iItem, r;
TCHAR *tszEpisode, *tszName;
term_t t2;
- /* Lookup episode name. */
-
- if (!PL_get_integer(t+0, &iEpisode))
- goto close;
-
- t2 = PL_new_term_refs(3);
- if(!PL_put_integer(t2+0, iEpisode))
- continue;
-
- r = PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("lookup_episode_local", 3, "episode_data"),
- t2);
-
- /* Format episode, name strings. */
+ /* Format name string. */
+ GI(t,&iEpisode) goto e;
+ F(f2);
+ t2 = T(3);
+ PI(t2,iEpisode) goto e;
tszName = NULL;
- if (r && PL_get_atom_chars(t2+1, &szName)) {
- tszName = TSZFromSZ(szName, CP_UTF8);
- if (!tszName)
- continue;
- }
+ P("episode_data","lookup_episode_local",3,t2) goto skipname;
+ GAC(t2+1,&szName) goto skipname;
+ tszName = TSZFromSZ(szName, CP_UTF8);
+ if (!tszName) goto e;
+ /* Format episode string. */
+skipname:
cb = 100;
tszEpisode = malloc(cb*sizeof(TCHAR));
- if (!tszEpisode)
- continue;
- _stprintf_s(tszEpisode, cb, TEXT("%d"),
- iEpisode);
+ if (!tszEpisode) goto e1;
+ _stprintf_s(tszEpisode, cb, TEXT("%d"), iEpisode);
/* Insert item. */
@@ -229,32 +200,34 @@ ElvUpdate()
lviEpisode.iSubItem = 0;
lviEpisode.pszText = tszEpisode;
lviEpisode.lParam = iEpisode;
- ListView_InsertItem(hListView, &lviEpisode);
+ ListView_InsertItem(hElv, &lviEpisode);
if (tszName) {
lviName.iItem = i;
lviName.iSubItem = 1;
lviName.pszText = tszName;
- ListView_SetItem(hListView, &lviName);
+ ListView_SetItem(hElv, &lviName);
}
- free(tszName);
free(tszEpisode);
+e1: if (tszName) free(tszName);
+e: Fd(f2);
}
- if (g_iSelectedItem != -1) {
- int iLast;
- iLast = ListView_GetItemCount(hListView)-1;
- ListView_EnsureVisible(hListView, iLast, TRUE);
- ListView_EnsureVisible(hListView, iTop, TRUE);
- ListView_SetItemState(hListView, g_iSelectedItem,
+ /* Reset selection and scrolling position. */
+
+ iLast = ListView_GetItemCount(hElv)-1;
+ ListView_EnsureVisible(hElv, iLast, TRUE);
+ ListView_EnsureVisible(hElv, iTop, TRUE);
+ if (Elv_iSelectedItem != -1) {
+ ListView_SetItemState(hElv, Elv_iSelectedItem,
LVIS_SELECTED, LVIS_SELECTED);
}
-close:
- SendMessage(hListView, WM_SETREDRAW, TRUE, 0);
- PL_cut_query(q);
- PL_discard_foreign_frame(f);
+ SendMessage(hElv, WM_SETREDRAW, TRUE, 0);
+ ElvRedraw();
+ Qc(q);
+ Fd(f);
}
/* Update episode name. */
@@ -262,25 +235,23 @@ void
ElvUpdateName(int iItem, int iEpisode)
{
char *szName;
- HWND hListView;
+ fid_t f;
+ HWND hElv;
TCHAR *tszName;
term_t t;
- t = PL_new_term_refs(3);
- if (!PL_put_integer(t+0, iEpisode))
- return;
-
- PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("lookup_episode", 3, "episode_data"),
- t);
-
- if (!PL_get_atom_chars(t+1, &szName))
- return;
+ F(f);
+ t = T(3);
+ PI(t,iEpisode) goto e;
+ P("episode_data","lookup_episode",3,t) goto e;
+ GAC(t+1,&szName) goto e;
tszName = TSZFromSZ(szName, CP_UTF8);
- if (!tszName)
- return;
+ if (!tszName) goto e;
+
+ hElv = GetDlgItem(Elv_hWnd, IDC_EPISODELISTVIEW);
+ ListView_SetItemText(hElv, iItem, 1, tszName);
- hListView = GetDlgItem(gElv_hWnd, IDC_EPISODELISTVIEW);
- ListView_SetItemText(hListView, iItem, 1, tszName);
+e: Fd(f);
+ return;
}
diff --git a/c/listview.c b/c/listview.c
index 66bcc29..956e646 100644
--- a/c/listview.c
+++ b/c/listview.c
@@ -6,18 +6,16 @@
#include "defs.h"
extern HFONT g_GUIFont;
-
-WNDPROC g_PrevLvProc;
-
+WNDPROC Lv_PrevProc;
static LRESULT CALLBACK LvProc(HWND, UINT, WPARAM, LPARAM);
HWND
LvCreate(HWND hWnd, HMENU hMenu)
{
HMODULE hModule;
- HWND hListView;
+ HWND hLv;
- hListView = CreateWindowEx(
+ hLv = CreateWindowEx(
WS_EX_CLIENTEDGE,
WC_LISTVIEW,
TEXT(""),
@@ -29,40 +27,39 @@ LvCreate(HWND hWnd, HMENU hMenu)
NULL
);
- g_PrevLvProc = (WNDPROC)SetWindowLongPtr(hListView,
+ Lv_PrevProc = (WNDPROC)SetWindowLongPtr(hLv,
GWLP_WNDPROC, (LONG_PTR)LvProc);
- ListView_SetExtendedListViewStyle(hListView,
+ ListView_SetExtendedListViewStyle(hLv,
LVS_EX_DOUBLEBUFFER);
- SendMessage(hListView, WM_SETFONT,
+ SendMessage(hLv, WM_SETFONT,
(WPARAM)g_GUIFont, MAKELPARAM(FALSE, 0));
hModule = LoadLibrary(TEXT("uxtheme.dll"));
if (hModule && GetProcAddress(hModule, "SetWindowTheme")) {
- ListView_SetExtendedListViewStyle(hListView,
+ ListView_SetExtendedListViewStyle(hLv,
LVS_EX_FULLROWSELECT|LVS_EX_DOUBLEBUFFER);
- SendMessage(hListView, WM_CHANGEUISTATE,
+ SendMessage(hLv, WM_CHANGEUISTATE,
MAKEWPARAM(UIS_SET, UISF_HIDEFOCUS), 0);
- SetWindowTheme(hListView, TEXT("Explorer"), NULL);
+ SetWindowTheme(hLv, TEXT("Explorer"), NULL);
}
- return hListView;
+ return hLv;
}
LRESULT CALLBACK
-LvProc(HWND hListView, UINT uMsg, WPARAM wParam, LPARAM lParam)
+LvProc(HWND hLv, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg) {
case WM_NOTIFY:
switch (((NMHDR *)lParam)->code) {
case HDN_ENDTRACK:
- UpdateLayout(GetParent(hListView));
+ UpdateLayout(GetParent(hLv));
return TRUE;
}
break;
}
- return CallWindowProc(g_PrevLvProc,
- hListView, uMsg, wParam, lParam);
+ return CallWindowProc(Lv_PrevProc, hLv, uMsg, wParam, lParam);
}
diff --git a/c/main.c b/c/main.c
index 3bbf832..31636f6 100644
--- a/c/main.c
+++ b/c/main.c
@@ -8,7 +8,6 @@
HFONT g_GUIFont;
HFONT g_GUIFontBold;
HMENU g_hPopupMenu;
-
static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
static INT_PTR CALLBACK AboutDlgProc(HWND, UINT, WPARAM, LPARAM);
static int Attach(void);
@@ -28,20 +27,16 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
rgArgs[0] = "episode_browser";
rgArgs[1] = NULL;
-
if (!PL_initialise(1, rgArgs))
PL_halt(1);
-
Attach();
- /* Create window. */
+ /* Initialize window. */
icc.dwSize = sizeof(icc);
icc.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&icc);
- SetupFonts();
-
g_hPopupMenu = LoadMenu(NULL,
MAKEINTRESOURCE(IDR_POPUPMENU));
g_hPopupMenu = GetSubMenu(g_hPopupMenu, 0);
@@ -58,7 +53,6 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU);
wc.lpszClassName = TEXT("Episode Browser");
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
-
RegisterClassEx(&wc);
hWnd = CreateWindowEx(
@@ -73,10 +67,9 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
hInstance,
NULL
);
+ if (!hWnd) return 0;
- if (!hWnd)
- return 0;
-
+ SetupFonts();
ShowWindow(hWnd, nCmdShow);
while (GetMessage(&msg, NULL, 0, 0) > 0) {
@@ -131,51 +124,42 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
case ID_FORGET:
case ID_LOOKUP:
{
+ fid_t f;
HWND hElv;
int iEpisode;
term_t t;
- extern int g_iSelectedItem;
+ extern int Elv_iSelectedItem;
hElv = GetDlgItem(hWnd, IDC_EPISODELISTVIEW);
- iEpisode = ElvItemEpisode(g_iSelectedItem);
+ iEpisode = ElvItemEpisode(Elv_iSelectedItem);
- t = PL_new_term_refs(1);
- if (!PL_put_integer(t+0, iEpisode))
- break;
+ F(f);
+ t = T(1);
+ PI(t,iEpisode) break;
switch (LOWORD(wParam)) {
case ID_WATCH:
- PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("open_episode", 1,
- "local_episodes"), t);
+ P("local_episode","open_episode",1,t);
break;
case ID_TOGGLE:
- PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("toggle_episode", 1,
- "track_episodes"), t);
- ListView_RedrawItems(hElv,
- g_iSelectedItem, g_iSelectedItem);
+ P("track_episodes","toggle_episode",1,t);
+ ElvRedraw();
break;
case ID_FORGET:
- PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("forget_episode", 1,
- "track_episodes"), t);
- PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("update_tracked_episodes",
- 0, "track_episodes"), t);
- ListView_RedrawItems(hElv,
- g_iSelectedItem, g_iSelectedItem);
+ P("track_episodes","forget_episode",1,t);
+ P("track_episodes","update_tracked_episodes",0,t);
+ ElvRedraw();
break;
case ID_LOOKUP:
- PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("retract_episode", 1,
- "episode_data"), t);
- ElvUpdateName(g_iSelectedItem, iEpisode);
+ P("episode_data","retract_episode",1,t);
+ ElvUpdateName(Elv_iSelectedItem, iEpisode);
+ ElvRedraw();
DlvShowEpisode(iEpisode);
- ListView_RedrawItems(hElv,
- g_iSelectedItem, g_iSelectedItem);
break;
}
+
+ Fd(f);
+ break;
}
}
break;
@@ -215,20 +199,18 @@ AboutDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
int
Attach()
{
+ fid_t f;
term_t t;
- t = PL_new_term_refs(2);
- if (!PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("attach", 0, "track_episodes"),
- t))
- return 0;
-
- if (!PL_call_predicate(NULL, PL_Q_NORMAL,
- PL_predicate("attach", 0, "episode_data"),
- t))
- return 0;
+ F(f);
+ t = T(0);
+ P("track_episodes","attach",0,t) goto f;
+ P("episode_data","attach",0,t) goto f;
+ Fd(f);
return 1;
+f: Fd(f);
+ return 0;
}
void
@@ -262,7 +244,7 @@ UpdateLayout(HWND hWnd)
HWND hElv, hDlv;
int cxColumn, cyDlv;
RECT rc;
- extern int g_iSelectedItem;
+ extern int Elv_iSelectedItem;
static int cxVScroll = 0;
if (cxVScroll == 0)
@@ -274,9 +256,7 @@ UpdateLayout(HWND hWnd)
hDlv = GetDlgItem(hWnd, IDC_DATALISTVIEW);
cyDlv = rc.bottom-100;
- MoveWindow(hDlv, 0, cyDlv,
- rc.right, rc.bottom,
- TRUE);
+ MoveWindow(hDlv, 0, cyDlv, rc.right, rc.bottom, TRUE);
cxColumn = ListView_GetColumnWidth(hDlv, 0);
ListView_SetColumnWidth(hDlv, 1,
@@ -285,13 +265,11 @@ UpdateLayout(HWND hWnd)
/* Resize episode list view. */
hElv = GetDlgItem(hWnd, IDC_EPISODELISTVIEW);
- MoveWindow(hElv, 0, 0,
- rc.right, cyDlv+1,
- TRUE);
+ MoveWindow(hElv, 0, 0, rc.right, cyDlv+1, TRUE);
cxColumn = ListView_GetColumnWidth(hElv, 0);
ListView_SetColumnWidth(hElv, 1,
rc.right-cxColumn-cxVScroll-4);
- //ListView_EnsureVisible(hElv, g_iSelectedItem, TRUE);
+ //ListView_EnsureVisible(hElv, Elv_iSelectedItem, TRUE);
}