forked from mpc-hc/mpc-hc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHScrollListBox.cpp
More file actions
169 lines (151 loc) · 5.66 KB
/
HScrollListBox.cpp
File metadata and controls
169 lines (151 loc) · 5.66 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/////////////////////////////////////////////////////////////////////////////
// HScrollListBox.cpp : implementation file
//
// Copyright (c) 2002, Nebula Technologies, Inc.
// www.nebutech.com
//
// Nebula Technologies, Inc. grants you a royalty free
// license to use, modify and distribute this code
// provided that this copyright notice appears on all
// copies. This code is provided "AS IS," without a
// warranty of any kind.
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "HScrollListBox.h"
/////////////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CHScrollListBox, CListBox)
//{{AFX_MSG_MAP(CHScrollListBox)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_MESSAGE(LB_ADDSTRING, OnAddString)
ON_MESSAGE(LB_INSERTSTRING, OnInsertString)
ON_MESSAGE(LB_DELETESTRING, OnDeleteString)
ON_MESSAGE(LB_DIR, OnDir)
ON_MESSAGE(LB_RESETCONTENT, OnResetContent)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHScrollListBox
/////////////////////////////////////////////////////////////////////////////
CHScrollListBox::CHScrollListBox()
{
}
/////////////////////////////////////////////////////////////////////////////
CHScrollListBox::~CHScrollListBox()
{
}
/////////////////////////////////////////////////////////////////////////////
void CHScrollListBox::PreSubclassWindow()
{
CListBox::PreSubclassWindow();
#ifdef _DEBUG
// NOTE: this list box is designed to work as a single column, system-drawn
// list box. The asserts below will ensure of that.
DWORD dwStyle = GetStyle();
ASSERT((dwStyle & LBS_MULTICOLUMN) == 0);
ASSERT((dwStyle & LBS_OWNERDRAWFIXED) == 0);
ASSERT((dwStyle & LBS_OWNERDRAWVARIABLE) == 0);
#endif
}
/////////////////////////////////////////////////////////////////////////////
// CHScrollListBox message handlers
///////////////////////////////////////////////////////////////////////////////
int CHScrollListBox::GetTextLen(LPCTSTR lpszText)
{
ASSERT(AfxIsValidString(lpszText));
CDC *pDC = GetDC();
ASSERT(pDC);
CSize size;
CFont* pOldFont = pDC->SelectObject(GetFont());
if ((GetStyle() & LBS_USETABSTOPS) == 0) {
size = pDC->GetTextExtent(lpszText, (int) _tcslen(lpszText));
size.cx += 3;
} else {
// Expand tabs as well
size = pDC->GetTabbedTextExtent(lpszText, (int) _tcslen(lpszText), 0, NULL);
size.cx += 2;
}
pDC->SelectObject(pOldFont);
ReleaseDC(pDC);
return size.cx;
}
///////////////////////////////////////////////////////////////////////////////
void CHScrollListBox::ResetHExtent()
{
if (GetCount() == 0) {
SetHorizontalExtent(0);
return;
}
CWaitCursor cwc;
int iMaxHExtent = 0;
for (int i = 0; i < GetCount(); i++) {
CString csText;
GetText(i, csText);
int iExt = GetTextLen(csText);
if (iExt > iMaxHExtent) {
iMaxHExtent = iExt;
}
}
SetHorizontalExtent(iMaxHExtent);
}
///////////////////////////////////////////////////////////////////////////////
void CHScrollListBox::SetNewHExtent(LPCTSTR lpszNewString)
{
int iExt = GetTextLen(lpszNewString);
if (iExt > GetHorizontalExtent()) {
SetHorizontalExtent(iExt);
}
}
///////////////////////////////////////////////////////////////////////////////
// OnAddString: wParam - none, lParam - string, returns - int
///////////////////////////////////////////////////////////////////////////////
LRESULT CHScrollListBox::OnAddString(WPARAM /*wParam*/, LPARAM lParam)
{
LRESULT lResult = Default();
if (!((lResult == LB_ERR) || (lResult == LB_ERRSPACE))) {
SetNewHExtent((LPCTSTR) lParam);
}
return lResult;
}
///////////////////////////////////////////////////////////////////////////////
// OnInsertString: wParam - index, lParam - string, returns - int
///////////////////////////////////////////////////////////////////////////////
LRESULT CHScrollListBox::OnInsertString(WPARAM /*wParam*/, LPARAM lParam)
{
LRESULT lResult = Default();
if (!((lResult == LB_ERR) || (lResult == LB_ERRSPACE))) {
SetNewHExtent((LPCTSTR) lParam);
}
return lResult;
}
///////////////////////////////////////////////////////////////////////////////
// OnDeleteString: wParam - index, lParam - none, returns - int
///////////////////////////////////////////////////////////////////////////////
LRESULT CHScrollListBox::OnDeleteString(WPARAM /*wParam*/, LPARAM /*lParam*/)
{
LRESULT lResult = Default();
if (!((lResult == LB_ERR) || (lResult == LB_ERRSPACE))) {
ResetHExtent();
}
return lResult;
}
///////////////////////////////////////////////////////////////////////////////
// OnDir: wParam - attr, lParam - wildcard, returns - int
///////////////////////////////////////////////////////////////////////////////
LRESULT CHScrollListBox::OnDir(WPARAM /*wParam*/, LPARAM /*lParam*/)
{
LRESULT lResult = Default();
if (!((lResult == LB_ERR) || (lResult == LB_ERRSPACE))) {
ResetHExtent();
}
return lResult;
}
///////////////////////////////////////////////////////////////////////////////
// OnResetContent: wParam - none, lParam - none, returns - int
///////////////////////////////////////////////////////////////////////////////
LRESULT CHScrollListBox::OnResetContent(WPARAM /*wParam*/, LPARAM /*lParam*/)
{
LRESULT lResult = Default();
SetHorizontalExtent(0);
return lResult;
}