#include #include #include #include #include "resource.h" #include "common.h" #include "datalistview.h" #include "episodelistview.h" #include "listview.h" #include "main.h" extern EpisodeListView *g_lpElv; DataListView::DataListView() : ListView((HMENU)IDC_DATALISTVIEW, LVS_NOCOLUMNHEADER) { LVCOLUMN lvc; 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) { ListView_DeleteAllItems(m_hWnd); LVITEM lviKey, lviValue; lviKey.mask = LVIF_TEXT; lviValue.mask = LVIF_TEXT; term_t t = PL_new_term_refs(3); if (!PL_put_integer(t,iEpisode)) return; qid_t q = PL_open_query(NULL, PL_Q_NORMAL, PL_predicate("episode_datum", 3, "episode_data"), t); for (int i = 0; PL_next_solution(q); i++) { char *szKey; char *szValue; TCHAR *tszKey, *tszValue; if (!(PL_get_atom_chars(t+1,&szKey) && PL_get_atom_chars(t+2,&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(); LVFINDINFO lvfi; lvfi.flags = LVFI_PARAM; lvfi.lParam = iEpisode; int iItem = ListView_FindItem(g_lpElv->HWnd(), -1, &lvfi); if (iItem != -1) ListView_EnsureVisible(g_lpElv->HWnd(), iItem, TRUE); }