From 295d423cc47f9ee8a72134dc544892a03b279311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Sun, 10 Jul 2022 23:23:09 +0200 Subject: Convert to C++. I already hit upon some object-oriented programming patterns in *listview.c, so I felt that it would be natural to use this as an opportunity to learn C++. --- c/datalistview.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 c/datalistview.cpp (limited to 'c/datalistview.cpp') 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 +#include +#include +#include + +#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); +} -- cgit v1.2.3