forked from zao/foo_wave_seekbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SeekbarWindow.ConfigDialog.cc
393 lines (344 loc) · 10.8 KB
/
SeekbarWindow.ConfigDialog.cc
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
// Copyright Lars Viklund 2008 - 2011.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#include "PchSeekbar.h"
#include "SeekbarWindow.h"
namespace wave
{
bool has_direct3d9() { return true; } // TODO: implement these
bool has_direct2d1() { return true; }
LRESULT seekbar_window::configuration_dialog::on_wm_init_dialog(ATL::CWindow focus, LPARAM lparam)
{
// Fill frontend combobox
CComboBox cb = GetDlgItem(IDC_FRONTEND);
std::wstring d3d = L"Direct3D 9.0c";
std::wstring d2d = L"Direct2D 1.0";
std::wstring gdi = L"GDI";
auto add_frontend_string = [&cb](config::frontend frontend)
{
cb.SetItemData(cb.AddString(config::strings::frontend[frontend]), frontend);
};
if (has_direct3d9())
add_frontend_string(config::frontend_direct3d9);
if (has_direct2d1())
add_frontend_string(config::frontend_direct2d1);
add_frontend_string(config::frontend_gdi);
auto select_frontend_string = [&](config::frontend frontend)
{
cb.SelectString(0, config::strings::frontend[frontend]);
CButton config_button = this->GetDlgItem(IDC_CONFIGURE);
bool has_conf = config::frontend_has_configuration[frontend];
config_button.EnableWindow(has_conf);
};
select_frontend_string(sw.settings.active_frontend_kind);
// Initialize colour pickers
mk_color_info(config::color_background, IDC_COLOR_BACKGROUND, IDC_USE_BACKGROUND);
mk_color_info(config::color_foreground, IDC_COLOR_FOREGROUND, IDC_USE_FOREGROUND);
mk_color_info(config::color_highlight, IDC_COLOR_HIGHLIGHT, IDC_USE_HIGHLIGHT);
mk_color_info(config::color_selection, IDC_COLOR_SELECTION, IDC_USE_SELECTION);
for (size_t i = 0; i < config::color_count; ++i)
{
bool override = sw.settings.override_colors[i];
CheckDlgButton(colors[i].use_id, override ? BST_CHECKED : BST_UNCHECKED);
colors[i].box.EnableWindow(override);
}
// Set up misc settings
CheckDlgButton(IDC_NOBORDER, !sw.settings.has_border ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(IDC_SHADEPLAYED, sw.settings.shade_played ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(IDC_MIRRORDISPLAY, sw.settings.flip_display ? BST_CHECKED : BST_UNCHECKED);
CComboBox downmix = GetDlgItem(IDC_DOWNMIX);
for (int i = 0; i < sizeof(config::strings::downmix) / sizeof(wchar_t const*); ++i)
{
downmix.SetItemData(downmix.AddString(config::strings::downmix[i]), (config::downmix)i);
}
downmix.SelectString(0, config::strings::downmix[sw.settings.downmix_display]);
// Set up display properties
CComboBox modes = GetDlgItem(IDC_DISPLAYMODE);
for (int i = 0; i < sizeof(config::strings::display_mode) / sizeof(wchar_t const*); ++i)
{
modes.SetItemData(modes.AddString(config::strings::display_mode[i]), (config::display_mode)i);
}
modes.SelectString(0, config::strings::display_mode[sw.settings.display_mode]);
// Set up channel listings
buttons.up = GetDlgItem(IDC_CHANNEL_UP);
buttons.down = GetDlgItem(IDC_CHANNEL_DOWN);
channels = GetDlgItem(IDC_CHANNELS);
channels.SetExtendedListViewStyle(LVS_EX_CHECKBOXES);
auto append = [this](std::wstring const& text, int data, bool checked)
{
LVITEM item = {};
item.mask = LVIF_PARAM | LVIF_TEXT;
item.pszText = const_cast<LPWSTR>(text.c_str());
item.lParam = data;
item.iItem = std::numeric_limits<int>::max();
int idx = this->channels.InsertItem(&item);
if (checked)
this->channels.SetCheckState(idx, checked ? TRUE : FALSE);
};
for each(auto& pair in sw.settings.channel_order)
{
append(config::strings::channel_names[pair.first], pair.first, pair.second);
}
initializing = false;
return TRUE;
}
void seekbar_window::configuration_dialog::on_wm_close()
{
DestroyWindow();
}
void seekbar_window::configuration_dialog::on_frontend_select(UINT code, int id, CWindow control)
{
CComboBox cb = control;
config::frontend fe = (config::frontend)cb.GetItemData(cb.GetCurSel());
CButton config_button = GetDlgItem(IDC_CONFIGURE);
bool has_conf = config::frontend_has_configuration[fe];
config_button.EnableWindow(has_conf);
if (initializing)
return;
// close frontend config window
if (sw.fe->frontend)
sw.fe->frontend->close_configuration();
if (fe != sw.settings.active_frontend_kind)
{
sw.set_frontend(fe);
}
}
void seekbar_window::configuration_dialog::on_no_border_click(UINT code, int id, CWindow control)
{
if (initializing)
return;
sw.set_border_visibility(!IsDlgButtonChecked(id));
}
void seekbar_window::configuration_dialog::on_shade_played_click(UINT code, int id, CWindow control)
{
if (initializing)
return;
sw.set_shade_played(!!IsDlgButtonChecked(id));
}
HBRUSH seekbar_window::configuration_dialog::on_wm_ctl_color_static(WTL::CDCHandle dc, ATL::CWindow wnd)
{
if (initializing)
return 0;
for (int i = 0; i < config::color_count; ++i)
if (wnd == colors[i].box)
{
bool enabled = !!colors[i].box.IsWindowEnabled();
dc.SetDCBrushColor(colors[i].color_ref);
return enabled
? (HBRUSH)GetStockObject(DC_BRUSH)
: GetSysColorBrush(COLOR_BTNFACE);
}
return 0;
}
void seekbar_window::configuration_dialog::on_color_click(UINT code, int id, CWindow control)
{
if (initializing)
return;
config::color idx;
switch (id)
{
case IDC_COLOR_BACKGROUND:
idx = config::color_background;
break;
case IDC_COLOR_FOREGROUND:
idx = config::color_foreground;
break;
case IDC_COLOR_HIGHLIGHT:
idx = config::color_highlight;
break;
case IDC_COLOR_SELECTION:
idx = config::color_selection;
break;
default:
return;
}
color_info& ci = colors[idx];
COLORREF c = color_to_xbgr(ci.color);
COLORREF arr[16] = {};
CHOOSECOLOR cc = {
sizeof(CHOOSECOLOR),
*this, 0,
c, arr, CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT
};
if (ChooseColor(&cc))
{
ci.color = xbgr_to_color(cc.rgbResult);
ci.color_ref = cc.rgbResult;
sw.set_color(idx, ci.color, true);
ci.box.InvalidateRect(0);
}
}
void seekbar_window::configuration_dialog::on_use_color_click(UINT code, int id, CWindow control)
{
if (initializing)
return;
config::color idx;
switch (id)
{
case IDC_USE_BACKGROUND:
idx = config::color_background;
break;
case IDC_USE_FOREGROUND:
idx = config::color_foreground;
break;
case IDC_USE_HIGHLIGHT:
idx = config::color_highlight;
break;
case IDC_USE_SELECTION:
idx = config::color_selection;
break;
default:
return;
}
bool override = !!IsDlgButtonChecked(id);
sw.set_color_override(idx, override);
colors[idx].box.EnableWindow(override);
colors[idx].box.Invalidate();
}
void seekbar_window::configuration_dialog::on_display_select(UINT code, int id, CWindow control)
{
if (initializing)
return;
CComboBox cb = control;
config::display_mode mode = (config::display_mode)cb.GetItemData(cb.GetCurSel());
if (mode != sw.settings.display_mode)
{
sw.set_display_mode(mode);
}
}
void seekbar_window::configuration_dialog::on_downmix_select(UINT code, int id, CWindow control)
{
if (initializing)
return;
CComboBox cb = control;
config::downmix mode = (config::downmix)cb.GetItemData(cb.GetCurSel());
if (mode != sw.settings.downmix_display)
{
sw.set_downmix_display(mode);
}
}
void seekbar_window::configuration_dialog::on_flip_click(UINT code, int id, CWindow control)
{
if (initializing)
return;
sw.set_flip_display(!!IsDlgButtonChecked(id));
}
LRESULT seekbar_window::configuration_dialog::on_channel_changed(NMHDR* hdr)
{
if (initializing)
return 0;
NMLISTVIEW* nm = (NMLISTVIEW*)hdr;
if (nm->uChanged & LVIF_STATE)
{
if (nm->uNewState & LVIS_SELECTED)
{
buttons.up.EnableWindow(nm->iItem > 0 ? TRUE : FALSE);
buttons.down.EnableWindow(nm->iItem + 1 < channels.GetItemCount() ? TRUE : FALSE);
}
if (int state = (nm->uNewState >> 12 & 0xF)) // has checkbox state
{
int ch = channels.GetItemData(nm->iItem);
//bool checked = !!channels.GetCheckState(nm->iItem);
sw.set_channel_enabled(ch, !!(state >> 1));
}
}
return 0;
}
LRESULT seekbar_window::configuration_dialog::on_channel_click(NMHDR* hdr)
{
if (initializing)
return 0;
NMITEMACTIVATE* nm = (NMITEMACTIVATE*)hdr;
return 0;
}
void seekbar_window::configuration_dialog::swap_channels(int i1, int i2)
{
struct item
{
wchar_t buf[80];
LVITEMW lvitem;
explicit item(int idx)
{
UINT mask = LVIF_PARAM | LVIF_STATE | LVIF_TEXT;
LVITEMW i = {mask, idx, 0, 0, (UINT)-1, buf, 80}; lvitem = i;
}
operator LVITEMW* () { return &lvitem; }
LVITEM* operator -> () { return &lvitem; }
} item1(i1), item2(i2);
channels.GetItem(item1);
channels.GetItem(item2);
item1->iItem = i2;
item2->iItem = i1;
channels.SetItem(item1);
channels.SetItem(item2);
}
void seekbar_window::configuration_dialog::on_channel_up(UINT code, int id, CWindow control)
{
if (initializing)
return;
int idx = channels.GetSelectedIndex();
if (idx == 0)
return;
int ch1 = channels.GetItemData(idx - 1);
int ch2 = channels.GetItemData(idx);
sw.swap_channel_order(ch1, ch2);
swap_channels(idx - 1, idx);
channels.SelectItem(idx - 1);
}
void seekbar_window::configuration_dialog::on_channel_down(UINT code, int id, CWindow control)
{
if (initializing)
return;
int idx = channels.GetSelectedIndex();
int count = channels.GetItemCount();
if (idx + 1 == count)
return;
int ch1 = channels.GetItemData(idx);
int ch2 = channels.GetItemData(idx + 1);
sw.swap_channel_order(ch1, ch2);
swap_channels(idx, idx + 1);
channels.SelectItem(idx + 1);
}
void seekbar_window::configuration_dialog::on_configure_click(UINT code, int id, CWindow control)
{
if (sw.fe && sw.fe->frontend)
{
sw.fe->frontend->show_configuration(sw);
}
}
seekbar_window::configuration_dialog::configuration_dialog(seekbar_window& sw)
: sw(sw), initializing(true)
{}
void seekbar_window::configuration_dialog::OnFinalMessage(HWND wnd)
{
sw.config_dialog.reset();
}
void seekbar_window::configuration_dialog::mk_color_info(config::color what, UINT display_id, UINT use_id)
{
color c = sw.settings.colors[what];
color_info& ci = colors[what];
ci.box = GetDlgItem(display_id);
ci.color_ref = color_to_xbgr(c);
ci.color = c;
ci.display_id = display_id;
ci.use_id = use_id;
}
void seekbar_window::configuration_dialog::add_item(channel_info const& info, CListBox& box)
{
box.SetItemData(box.AddString(info.text.c_str()), info.data);
}
void seekbar_window::configuration_dialog::remove_item(int idx, CListBox& box)
{
box.DeleteString(idx);
}
seekbar_window::configuration_dialog::channel_info seekbar_window::configuration_dialog::get_item(int idx, CListBox& box)
{
channel_info ret;
ret.data = box.GetItemData(idx);
CString s;
box.GetText(idx, s);
ret.text = s;
return ret;
}
}