#include #include #include #include #include #include "resource.h" #include "common.h" #include "datalistview.h" #include "episodelistview.h" #include "listview.h" #include "main.h" #include "pl.h" DataListView::DataListView(const HWND hWndParent) : ListView(hWndParent, (HMENU)IDC_DATALISTVIEW, LVS_NOCOLUMNHEADER) { LVCOLUMN lvc; lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM; lvc.iSubItem = DLVSIKEY; lvc.pszText = (wchar_t*)L"Key"; lvc.cx = Dpi(42); ListView_InsertColumn(hWnd, DLVSIKEY, &lvc); lvc.iSubItem = DLVSIVALUE; lvc.pszText = (wchar_t*)L"Value"; lvc.cx = 500; ListView_InsertColumn(hWnd, DLVSIVALUE, &lvc); } void DataListView::ResizeColumns(int w) { ListView_SetColumnWidth(hWnd, DLVSIKEY, LVSCW_AUTOSIZE); const int cxColumn = ListView_GetColumnWidth(hWnd, DLVSIKEY)+Dpi(4); ListView_SetColumnWidth(hWnd, DLVSIKEY, cxColumn); ListView_SetColumnWidth(hWnd, DLVSIVALUE, w-cxColumn-Metric-Dpi(4)); } void DataListView::ShowEpisode(const int iEpisode) { extern EpisodeListView* const g_elv; ListView_DeleteAllItems(hWnd); Frame f; const int arity = 3; const term_t t = PL_new_term_refs(arity); if (!PlPut(t, iEpisode)) return; Query q (NULL, PL_predicate("episode_datum", arity, "episode_data"), t); LVITEM lviKey = {LVIF_TEXT}; LVITEM lviValue = {LVIF_TEXT}; for (int i = 0; q.NextSolution(std::nothrow); i++) { wstring_owner key; wstring_owner value; if (!(PlGet(t+1, &key) && PlGet(t+2, &value))) continue; lviKey.iItem = i; lviKey.iSubItem = 0; lviKey.pszText = key.p; ListView_InsertItem(hWnd, &lviKey); lviValue.iItem = i; lviValue.iSubItem = 1; lviValue.pszText = value.p; ListView_SetItem(hWnd, &lviValue); } UpdateLayout(); LVFINDINFO lvfi; lvfi.flags = LVFI_PARAM; lvfi.lParam = iEpisode; int iItem = ListView_FindItem(g_elv->hWnd, -1, &lvfi); if (iItem != -1) ListView_EnsureVisible(g_elv->hWnd, iItem, TRUE); }