aboutsummaryrefslogtreecommitdiff
path: root/c/main.c
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2022-02-16 18:09:04 +0100
committerJohn Ankarström <john@ankarstrom.se>2022-02-16 18:25:50 +0100
commit2a726875d7ab370966bbb4b6ebb41756fc17f729 (patch)
tree1cc9da9c70a994aa43287088cdfbc2a5d38606b9 /c/main.c
parent7086bfe3e7bf04dd61f16216c659fc5534c2796a (diff)
downloadEpisodeBrowser-2a726875d7ab370966bbb4b6ebb41756fc17f729.tar.gz
Clean up.
Diffstat (limited to 'c/main.c')
-rw-r--r--c/main.c88
1 files changed, 33 insertions, 55 deletions
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);
}