diff options
author | John Ankarström <john@ankarstrom.se> | 2022-02-15 22:59:58 +0100 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2022-02-15 23:00:20 +0100 |
commit | 4fafc8b49e3f08a87119ef62a54056efba7b6b92 (patch) | |
tree | 98a1cee0e7e2949924fa45940eacfd4eedbf940a /c/main.c | |
parent | 5bbd959c3c78a7293ad00c2a022b800ec28f4b8d (diff) | |
download | EpisodeBrowser-4fafc8b49e3f08a87119ef62a54056efba7b6b92.tar.gz |
Finish Win32 re-implementation.
There are still things to be improved upon,
but this commit marks feature parity with
the XPCE version.
Diffstat (limited to 'c/main.c')
-rw-r--r-- | c/main.c | 82 |
1 files changed, 65 insertions, 17 deletions
@@ -1,7 +1,5 @@ #include <windows.h> #include <commctrl.h> -#include <stdio.h> -#include <string.h> #include <SWI-Prolog.h> #include "resource.h" @@ -9,6 +7,7 @@ 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); @@ -43,6 +42,10 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, SetupFonts(); + g_hPopupMenu = LoadMenu(NULL, + MAKEINTRESOURCE(IDR_POPUPMENU)); + g_hPopupMenu = GetSubMenu(g_hPopupMenu, 0); + wc.cbSize = sizeof(WNDCLASSEX); wc.style = 0; wc.lpfnWndProc = WndProc; @@ -110,6 +113,54 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) AboutDlgProc ); break; + case ID_WATCH: + case ID_TOGGLE: + case ID_FORGET: + case ID_LOOKUP: + { + HWND hElv; + int iEpisode; + term_t t; + extern int g_iSelectedItem; + + hElv = GetDlgItem(hWnd, IDC_EPISODELISTVIEW); + iEpisode = ElvItemEpisode(g_iSelectedItem); + + t = PL_new_term_refs(1); + if (!PL_put_integer(t+0, iEpisode)) + break; + + switch (LOWORD(wParam)) { + case ID_WATCH: + PL_call_predicate(NULL, PL_Q_NORMAL, + PL_predicate("open_episode", 1, + "local_episodes"), 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); + break; + case ID_FORGET: + PL_call_predicate(NULL, PL_Q_NORMAL, + PL_predicate("forget_episode", 1, + "track_episodes"), t); + ListView_RedrawItems(hElv, + g_iSelectedItem, g_iSelectedItem); + break; + case ID_LOOKUP: + PL_call_predicate(NULL, PL_Q_NORMAL, + PL_predicate("retract_episode", 1, + "episode_data"), t); + ElvUpdateName(g_iSelectedItem, iEpisode); + DlvShowEpisode(iEpisode); + ListView_RedrawItems(hElv, + g_iSelectedItem, g_iSelectedItem); + break; + } + } } break; case WM_CREATE: @@ -161,19 +212,18 @@ AboutDlgProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) int Attach() { - int r; term_t t; t = PL_new_term_refs(2); - r = PL_call_predicate(NULL, PL_Q_NORMAL, - PL_predicate("attach", 0, "track_episodes"), - t); - if (!r) return r; + if (!PL_call_predicate(NULL, PL_Q_NORMAL, + PL_predicate("attach", 0, "track_episodes"), + t)) + return 0; - r = PL_call_predicate(NULL, PL_Q_NORMAL, - PL_predicate("attach", 0, "episode_data"), - t); - if (!r) return r; + if (!PL_call_predicate(NULL, PL_Q_NORMAL, + PL_predicate("attach", 0, "episode_data"), + t)) + return 0; return 1; } @@ -209,16 +259,14 @@ UpdateLayout(HWND hWnd) HWND hElv, hDlv; int cxColumn, cyDlv; RECT rc; + extern int g_iSelectedItem; static int cxVScroll = 0; - extern int g_SelectedItem; if (cxVScroll == 0) cxVScroll = GetSystemMetrics(SM_CXVSCROLL); GetClientRect(hWnd, &rc); -#define EDGE 4 - /* Resize data list view. */ hDlv = GetDlgItem(hWnd, IDC_DATALISTVIEW); @@ -229,7 +277,7 @@ UpdateLayout(HWND hWnd) cxColumn = ListView_GetColumnWidth(hDlv, 0); ListView_SetColumnWidth(hDlv, 1, - rc.right-cxColumn-cxVScroll-EDGE); + rc.right-cxColumn-cxVScroll-4); /* Resize episode list view. */ @@ -240,7 +288,7 @@ UpdateLayout(HWND hWnd) cxColumn = ListView_GetColumnWidth(hElv, 0); ListView_SetColumnWidth(hElv, 1, - rc.right-cxColumn-cxVScroll-EDGE); + rc.right-cxColumn-cxVScroll-4); - ListView_EnsureVisible(hElv, g_SelectedItem, TRUE); + ListView_EnsureVisible(hElv, g_iSelectedItem, TRUE); } |