aboutsummaryrefslogtreecommitdiff
path: root/c/datalistview.cpp
blob: 4ed3d418f538f78eafb7d05fed6fc83f887b8d5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <sstream>
#include <stdio.h>
#include <windows.h>
#include <commctrl.h>

#include "data.h"
#include "datalistview.h"
#include "episodelistview.h"
#include "listview.h"
#include "resource.h"
#include "window.h"

DataListView::DataListView(Window& parent)
	: ListView(parent, reinterpret_cast<HMENU>(IDC_DATALISTVIEW), LVS_NOCOLUMNHEADER)
{
	LVCOLUMN lvc;

	lvc.mask = LVCF_WIDTH|LVCF_TEXT|LVCF_SUBITEM;
	lvc.iSubItem = DLVSIKEY;
	lvc.pszText = const_cast<wchar_t*>(L"Key");

	lvc.cx = Dpi(42);
	ListView_InsertColumn(hWnd, DLVSIKEY, &lvc);

	lvc.iSubItem = DLVSIVALUE;
	lvc.pszText = const_cast<wchar_t*>(L"Value");
	lvc.cx = 500;
	ListView_InsertColumn(hWnd, DLVSIVALUE, &lvc);

	m_height = parent.cfg.heightDlv;
}

int DataListView::Height() noexcept
{
	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<SM_CXVSCROLL>-Dpi(4));
}

void DataListView::SetHeight(int h)
{
	m_height = h;
}

void DataListView::ShowEpisode(const int iEpisode)
{
	const DlvDataA& d = parent.fvDlv[iEpisode-1];

	ListView_DeleteAllItems(hWnd);
	if (d.version == Version<DlvDataA>) {
		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<wchar_t*>(v[i]);
				ListView_InsertItem(hWnd, &lviKey);

				lviValue.iItem = j;
				lviValue.iSubItem = 1;
				lviValue.pszText = const_cast<wchar_t*>(v[i+1]);
				ListView_SetItem(hWnd, &lviValue);

				j++;
			}
		}
	}

	parent.UpdateLayout();

	LVFINDINFO lvfi;
	lvfi.flags = LVFI_PARAM;
	lvfi.lParam = iEpisode;
	int iItem = ListView_FindItem(parent.elv.hWnd, -1, &lvfi);
	if (iItem != -1)
		ListView_EnsureVisible(parent.elv.hWnd, iItem, TRUE);
}