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
92
93
94
95
96
97
98
99
100
101
102
103
104
|
/*
* CListCtrl.h
* -----------
* Purpose: A class that extends MFC's CListCtrl with some more functionality and to handle unicode strings in ANSI builds.
* Notes : (currently none)
* Authors: OpenMPT Devs
* The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
*/
#pragma once
#include "openmpt/all/BuildSettings.hpp"
#include "MPTrackUtil.h"
OPENMPT_NAMESPACE_BEGIN
class CListCtrlEx : public CListCtrl
{
public:
struct Header
{
const TCHAR *text = nullptr;
int width = 0;
UINT mask = 0;
};
void SetHeaders(const mpt::span<const Header> &header)
{
for(int i = 0; i < static_cast<int>(header.size()); i++)
{
int width = header[i].width;
InsertColumn(i, header[i].text, header[i].mask, width >= 0 ? Util::ScalePixels(width, m_hWnd) : 16);
if(width < 0)
SetColumnWidth(i, width);
}
}
void SetItemDataPtr(int item, void *value)
{
SetItemData(item, reinterpret_cast<DWORD_PTR>(value));
}
void *GetItemDataPtr(int item)
{
return reinterpret_cast<void *>(GetItemData(item));
}
// Unicode strings in ANSI builds
#ifndef UNICODE
BOOL SetItemText(int nItem, int nSubItem, const WCHAR *lpszText)
{
ASSERT(::IsWindow(m_hWnd));
ASSERT((GetStyle() & LVS_OWNERDATA)==0);
LVITEMW lvi;
lvi.iSubItem = nSubItem;
lvi.pszText = (LPWSTR) lpszText;
return (BOOL) ::SendMessage(m_hWnd, LVM_SETITEMTEXTW, nItem, (LPARAM)&lvi);
}
using CListCtrl::SetItemText;
#endif
};
#ifdef MPT_MFC_FULL
class CMFCListCtrlEx : public CMFCListCtrl
{
public:
struct Header
{
const TCHAR *text = nullptr;
int width = 0;
UINT mask = 0;
};
void SetHeaders(const mpt::span<const Header> &header)
{
for(int i = 0; i < static_cast<int>(header.size()); i++)
{
InsertColumn(i, header[i].text, header[i].mask, Util::ScalePixels(header[i].width, m_hWnd));
}
}
// Unicode strings in ANSI builds
#ifndef UNICODE
BOOL SetItemText(int nItem, int nSubItem, const WCHAR *lpszText)
{
ASSERT(::IsWindow(m_hWnd));
ASSERT((GetStyle() & LVS_OWNERDATA)==0);
LVITEMW lvi;
lvi.iSubItem = nSubItem;
lvi.pszText = (LPWSTR) lpszText;
return (BOOL) ::SendMessage(m_hWnd, LVM_SETITEMTEXTW, nItem, (LPARAM)&lvi);
}
using CListCtrl::SetItemText;
#endif
};
#endif // MPT_MFC_FULL
OPENMPT_NAMESPACE_END
|