aboutsummaryrefslogtreecommitdiff
path: root/c/datalistview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'c/datalistview.cpp')
-rw-r--r--c/datalistview.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/c/datalistview.cpp b/c/datalistview.cpp
new file mode 100644
index 0000000..3269dab
--- /dev/null
+++ b/c/datalistview.cpp
@@ -0,0 +1,85 @@
+#include <stdio.h>
+#include <windows.h>
+#include <commctrl.h>
+#include <SWI-Prolog.h>
+
+#include "resource.h"
+#include "defs.h"
+
+extern EpisodeListView g_elv;
+
+void
+DataListView::Create()
+{
+ LVCOLUMN lvc;
+
+ ListView::Create((HMENU)IDC_DATALISTVIEW, LVS_NOCOLUMNHEADER);
+
+ lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
+ lvc.iSubItem = DLVSIKEY;
+ lvc.pszText = TEXT("Key");
+
+ lvc.cx = Dpi(42);
+ ListView_InsertColumn(m_hWnd, DLVSIKEY, &lvc);
+
+ lvc.iSubItem = DLVSIVALUE;
+ lvc.pszText = TEXT("Value");
+ lvc.cx = 500;
+ ListView_InsertColumn(m_hWnd, DLVSIVALUE, &lvc);
+}
+
+void
+DataListView::ShowEpisode(int iEpisode)
+{
+ int i, iItem;
+ LVFINDINFO lvfi;
+ LVITEM lviKey, lviValue;
+ term_t t;
+ qid_t q;
+
+ ListView_DeleteAllItems(m_hWnd);
+
+ lviKey.mask = LVIF_TEXT;
+ lviValue.mask = LVIF_TEXT;
+
+ t = PL_new_term_refs(3);
+ if (!Plp(t,"I",iEpisode)) return;
+ q = PL_open_query(NULL, PL_Q_NORMAL,
+ PL_predicate("episode_datum", 3, "episode_data"), t);
+
+ for (i = 0; PL_next_solution(q); i++) {
+ char *szKey;
+ char *szValue;
+ TCHAR *tszKey, *tszValue;
+
+ if (!Plg(t+1,"ss",&szKey,&szValue)) continue;
+
+ tszKey = TszFromSz(szKey, CP_UTF8);
+ if (!tszKey) continue;
+ tszValue = TszFromSz(szValue, CP_UTF8);
+ if (!tszValue) goto c;
+
+ lviKey.mask = LVIF_TEXT;
+ lviKey.iItem = i;
+ lviKey.iSubItem = 0;
+ lviKey.pszText = tszKey;
+ ListView_InsertItem(m_hWnd, &lviKey);
+
+ lviValue.iItem = i;
+ lviValue.iSubItem = 1;
+ lviValue.pszText = tszValue;
+ ListView_SetItem(m_hWnd, &lviValue);
+
+ free(tszValue);
+ c: free(tszKey);
+ }
+
+ PL_cut_query(q);
+ UpdateLayout();
+
+ lvfi.flags = LVFI_PARAM;
+ lvfi.lParam = iEpisode;
+ iItem = ListView_FindItem(g_elv.HWnd(), -1, &lvfi);
+ if (iItem != -1)
+ ListView_EnsureVisible(g_elv.HWnd(), iItem, TRUE);
+}