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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
|
#include "./skinnedlistbox.h"
#include "../winamp/wa_dlg.h"
#include "./skinning.h"
#include "../nu/trace.h"
#include <strsafe.h>
SkinnedListbox::SkinnedListbox(void) : SkinnedScrollWnd(FALSE)
{
}
SkinnedListbox::~SkinnedListbox(void)
{
}
BOOL SkinnedListbox::Attach(HWND hwndListbox)
{
DWORD ws;
if(!SkinnedScrollWnd::Attach(hwndListbox)) return FALSE;
ws = GetWindowLongPtrW(hwnd, GWL_STYLE);
SetType(SKINNEDWND_TYPE_LISTBOX);
SetMode((LBS_COMBOBOX & ws) ? SCROLLMODE_COMBOLBOX : SCROLLMODE_STANDARD);
if (0 == (LBS_COMBOBOX & ws))
{
HWND hwndParent = GetParent(hwndListbox);
if (hwndParent) SkinWindow(hwndParent, SWS_NORMAL);
}
if (LBS_DISABLENOSCROLL & ws) DisableNoScroll(TRUE);
SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
return TRUE;
}
HPEN SkinnedListbox::GetBorderPen(void)
{
if (LBS_COMBOBOX & GetWindowLongPtrW(hwnd, GWL_STYLE))
{
return (HPEN)MlStockObjects_Get(MENUBORDER_PEN);
}
else return __super::GetBorderPen();
}
void SkinnedListbox::OnDrawItem(DRAWITEMSTRUCT *pdis)
{
static wchar_t szText[512];
if (pdis->itemID == -1) return;
INT cchLen = (INT)SendMessageW(pdis->hwndItem, LB_GETTEXT, pdis->itemID, (LPARAM)szText);
DrawItem(pdis, szText, cchLen);
}
void SkinnedListbox::DrawItem(DRAWITEMSTRUCT *pdis, LPCWSTR pszText, INT cchText)
{
RECT ri;
COLORREF rgbTextOld, rgbBkOld;
if (pdis->itemID == -1) return;
CopyRect(&ri, &pdis->rcItem);
if (ODA_FOCUS == pdis->itemAction)
{
if (0 == (0x0200/*ODS_NOFOCUSRECT*/ & pdis->itemState))
{
rgbTextOld = SetTextColor(pdis->hDC, 0x000000);
rgbBkOld = SetBkColor(pdis->hDC, 0xFFFFFF);
DrawFocusRect(pdis->hDC, &ri);
SetTextColor(pdis->hDC, rgbTextOld);
SetBkColor(pdis->hDC, rgbBkOld);
}
return;
}
if (ODS_SELECTED & pdis->itemState)
{
BOOL bActive = (pdis->hwndItem == GetFocus());
if (!bActive && (LBS_COMBOBOX & GetWindowLongPtrW(pdis->hwndItem, GWL_STYLE))) bActive = TRUE;
rgbTextOld = SetTextColor(pdis->hDC, WADlg_getColor((bActive) ? WADLG_SELBAR_FGCOLOR : WADLG_INACT_SELBAR_FGCOLOR));
rgbBkOld = SetBkColor(pdis->hDC, WADlg_getColor((bActive) ? WADLG_SELBAR_BGCOLOR : WADLG_INACT_SELBAR_BGCOLOR));
}
else
{
rgbTextOld = GetTextColor(pdis->hDC);
rgbBkOld = GetBkColor(pdis->hDC);
}
if (cchText> 0)
{
//InflateRect(&ri, -4, -1);
//int mode = SetBkMode(pdis->hDC, TRANSPARENT);
//DrawTextW(pdis->hDC, pszText, cchText, &ri, DT_NOPREFIX | DT_VCENTER | DT_NOCLIP);
//if (mode != TRANSPARENT) SetBkMode(pdis->hDC, mode);
ExtTextOutW(pdis->hDC, ri.left + 4, ri.top + 1, ETO_OPAQUE, &ri, pszText, cchText, NULL);
}
else if ((ODA_SELECT | ODA_DRAWENTIRE) & pdis->itemAction || (ODS_SELECTED & pdis->itemState))
{
ExtTextOutW(pdis->hDC, 0, 0, ETO_OPAQUE, &ri, L"", 0, NULL);
}
if (ODS_SELECTED & pdis->itemState)
{
SetTextColor(pdis->hDC, rgbTextOld);
SetBkColor(pdis->hDC, rgbBkOld);
}
}
void SkinnedListbox::MeasureItem(HWND hwnd, LPCWSTR pszText, INT cchText, UINT *pWidth, UINT *pHeight)
{
HDC hdc = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_NORESETATTRS);
HFONT hf, hfo;
hf = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0L);
if (NULL == hf) hf = (HFONT) MlStockObjects_Get(DEFAULT_FONT);
hfo = (HFONT)SelectObject(hdc, hf);
SIZE sz;
if (!GetTextExtentPoint32W(hdc, pszText, cchText, &sz))
ZeroMemory(&sz, sizeof(SIZE));
if (pWidth) *pWidth = sz.cx;
if (pHeight) *pHeight= sz.cy;
SelectObject(hdc, hfo);
ReleaseDC(hwnd, hdc);
}
void SkinnedListbox::OnSkinUpdated(BOOL bNotifyChildren, BOOL bRedraw)
{
__super::OnSkinUpdated(bNotifyChildren, bRedraw);
if (SWS_USESKINFONT & style)
{
if (0 == (LBS_OWNERDRAWVARIABLE & GetWindowLongPtrW(hwnd, GWL_STYLE)))
{
HDC hdc = GetDCEx(hwnd, NULL, DCX_CACHE | DCX_NORESETATTRS);
HFONT hf, hfo;
TEXTMETRIC tm;
hf = (HFONT)SendMessageW(hwnd, WM_GETFONT, 0, 0L);
if (NULL == hf) hf = (HFONT)MlStockObjects_Get(DEFAULT_FONT);
hfo = (HFONT)SelectObject(hdc, hf);
GetTextMetrics(hdc, &tm);
SendMessageW(hwnd, LB_SETITEMHEIGHT, 0, tm.tmHeight + 2);
SelectObject(hdc, hfo);
ReleaseDC(hwnd, hdc);
}
}
}
void SkinnedListbox::OnPrint(HDC hdc, UINT options)
{
if ((PRF_CHECKVISIBLE & options) && !IsWindowVisible(hwnd)) return;
if (LBS_COMBOBOX & GetWindowLongPtrW(hwnd, GWL_STYLE))
{
__super::OnPrint(hdc, options & ~PRF_CLIENT);
if (((PRF_CLIENT | PRF_ERASEBKGND) & options))
{
OffsetViewportOrgEx(hdc, 1, 1, NULL);
SendMessageW(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, (LPARAM)((PRF_CLIENT | PRF_ERASEBKGND) & options));
OffsetViewportOrgEx(hdc, -1, -1, NULL);
}
return;
}
__super::OnPrint(hdc, options);
}
LRESULT SkinnedListbox::WindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (SWS_USESKINCOLORS & style)
{
switch(uMsg)
{
case WM_ERASEBKGND:
if (LBS_OWNERDRAWFIXED & GetWindowLongPtrW(hwnd, GWL_STYLE))
{
RECT rc;
GetClientRect(hwnd, &rc);
HBRUSH hb = (HBRUSH)MlStockObjects_Get(ITEMBCK_BRUSH);
INT count = GetListBoxInfo(hwnd);
if (count > 0)
{
RECT ri;
if (LB_ERR != SendMessageW(hwnd, LB_GETITEMRECT, count -1, (LPARAM)&ri))
{
__super::WindowProc(uMsg, 0, lParam);
if (ri.bottom < rc.bottom)
{
rc.top = ri.bottom;
FillRect((HDC)wParam, &rc, hb);
}
if (ri.right < rc.right)
{
rc.top = 0;
rc.left = ri.right;
FillRect((HDC)wParam, &rc, hb);
}
return 1;
}
}
else
{
__super::WindowProc(uMsg, 0, lParam);
FillRect((HDC)wParam, &rc, hb);
return 1;
}
}
break;
case WM_SETFOCUS:
case WM_KILLFOCUS:
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
break;
case REFLECTED_DRAWITEM:
if ((LBS_OWNERDRAWFIXED | LBS_HASSTRINGS) ==
((LBS_OWNERDRAWFIXED | LBS_NODATA | LBS_HASSTRINGS) & GetWindowLongPtrW(hwnd, GWL_STYLE)))
{
OnDrawItem((DRAWITEMSTRUCT*)((REFLECTPARAM*)lParam)->lParam);
((REFLECTPARAM*)lParam)->result = TRUE;
return TRUE;
}
return FALSE;
case REFLECTED_CTLCOLORLISTBOX:
{
COLORREF rgbText, rgbTextBk;
rgbText = WADlg_getColor(WADLG_ITEMFG);
rgbTextBk = WADlg_getColor(WADLG_ITEMBG);
if(!IsWindowEnabled(hwnd))
{
rgbText = RGB((GetRValue(rgbText)+GetRValue(rgbTextBk))/2,
(GetGValue(rgbText)+GetGValue(rgbTextBk))/2,
(GetBValue(rgbText)+GetBValue(rgbTextBk))/2);
}
SetBkColor((HDC)wParam, rgbTextBk);
SetTextColor((HDC)wParam, rgbText);
}
((REFLECTPARAM*)lParam)->result = (LRESULT)MlStockObjects_Get(ITEMBCK_BRUSH);
return TRUE;
}
}
return __super::WindowProc(uMsg, wParam, lParam);
}
|