#include #include #include #include #include #include "resource.h" #include "data.h" #include "datalistview.h" #include "episodelistview.h" #include "listview.h" #include "layout.h" #include "wcharptr.h" DataListView::DataListView(const HWND hWndParent) : ListView(hWndParent, reinterpret_cast(IDC_DATALISTVIEW), LVS_NOCOLUMNHEADER) { LVCOLUMN lvc; lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM; lvc.iSubItem = DLVSIKEY; lvc.pszText = const_cast(L"Key"); lvc.cx = Dpi(42); ListView_InsertColumn(hWnd, DLVSIKEY, &lvc); lvc.iSubItem = DLVSIVALUE; lvc.pszText = const_cast(L"Value"); lvc.cx = 500; ListView_InsertColumn(hWnd, DLVSIVALUE, &lvc); extern CfgA& g_cfg; m_height = g_cfg.heightDlv; } int DataListView::Height() { return m_height? m_height: ListView::Height(); } 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::SetHeight(int h) { m_height = h; } void DataListView::ShowEpisode(const int iEpisode) { const DlvDataA& d = g_fvDlv[iEpisode-1]; ListView_DeleteAllItems(hWnd); if (d.version == Version) { const wchar_t* v[] = { L"Date", d.date, L"Source", d.source, L"Hint", d.hint, L"Screenwriter", d.screenwriter}; LVITEM lviKey = {LVIF_TEXT}; LVITEM lviValue = {LVIF_TEXT}; for (size_t i = 0, j = 0; i < sizeof(v)/sizeof(*v); i += 2) { if (v[i+1][0]) { lviKey.iItem = j; lviKey.iSubItem = 0; lviKey.pszText = const_cast(v[i]); ListView_InsertItem(hWnd, &lviKey); lviValue.iItem = j; lviValue.iSubItem = 1; lviValue.pszText = const_cast(v[i+1]); ListView_SetItem(hWnd, &lviValue); j++; } } } UpdateLayout(); LVFINDINFO lvfi; lvfi.flags = LVFI_PARAM; lvfi.lParam = iEpisode; extern EpisodeListView* const g_elv; int iItem = ListView_FindItem(g_elv->hWnd, -1, &lvfi); if (iItem != -1) ListView_EnsureVisible(g_elv->hWnd, iItem, TRUE); }