This repository was archived by the owner on Jan 23, 2026. It is now read-only.
forked from Chronial/foo_chronflow
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathConfigWindow.h
More file actions
1753 lines (1542 loc) · 63.7 KB
/
ConfigWindow.h
File metadata and controls
1753 lines (1542 loc) · 63.7 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
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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
// clang-format off
#include <windows.h>
#include <boost/range/iterator_range.hpp>
#include "helpers/DarkMode.h"
#include "yesno_dialog.h"
#include "./lib/win32_helpers.h"
#include "ConfigBindings.h"
#include "ConfigData.h"
#include "Engine.h"
#include "EngineThread.h"
#include "MyActions.h"
#include "cover_positions_compiler.h"
#include "doc/key_config.h"
#include "helpers/win32_dialog.h"
#include "resource.h"
#include "winuser.h"
//need default_SourcePlaylistName
#include "configData.h"
// clang-format on
namespace coverflow {
extern char const* const default_SourcePlaylistName;
using ::engine::EngineThread;
using EM = ::engine::Engine::Messages;
extern std::unordered_multimap<UINT, int> disableMap;
extern std::unordered_multimap<UINT, int> disableStateMatch;
//data binding notifications to parent dialog
const UINT CF_USER_CONFIG_NEWTAB(WM_USER + 0x7776);
const UINT CF_USER_CONFIG_CHANGE(WM_USER + 0x7778);
/**************************************************************************************/
/**************************************************************************************/
#define SetWindowRedraw(hwnd, fRedraw) \
((void)SNDMSG(hwnd, WM_SETREDRAW, (WPARAM)(BOOL)(fRedraw), 0L))
class ConfigTab {
protected:
UINT id;
HWND parent;
const char* title;
HWND hWnd = nullptr;
RECT m_rcTab;
//testing candidate to new dlg schema
//CConfigTabCtrl m_ConfigTabCtrl;
//CDialogUIElem m_dlg;
public:
ConfigTab(const char* title, UINT id, HWND parent) : id(id), parent(parent), title(title) {
HWND hWndTab = uGetDlgItem(parent, IDC_TABS);
uTCITEM tabItem = {0};
tabItem.mask = TCIF_TEXT;
tabItem.pszText = (char*)title;
;
int idx = TabCtrl_GetItemCount(hWndTab);
uTabCtrl_InsertItem(hWndTab, idx, &tabItem);
GetWindowRect(hWndTab, &m_rcTab);
uSendMessage(hWndTab, TCM_ADJUSTRECT, FALSE, reinterpret_cast<LPARAM>(&m_rcTab));
MapWindowPoints(HWND_DESKTOP, parent, (POINT*)&m_rcTab, 2);
auto bisDark = DarkMode::IsDialogDark(parent);
// Resize the tree control so that it fills the tab control.
if (!bisDark) {
InflateRect(&m_rcTab, 2, 1);
OffsetRect(&m_rcTab, -1, 1);
}
}
NO_MOVE_NO_COPY(ConfigTab);
HWND getTabWnd() {
return hWnd;
}
const char* getTabTitle() {
return title;
}
void SetTabWnd(HWND hwnd) {
if (hWnd) DestroyWindow(hWnd);
hWnd = hwnd;
return ;
}
virtual ~ConfigTab() {
if (hWnd != nullptr)
DestroyWindow(hWnd);
}
void hide() { ShowWindow(hWnd, SW_HIDE); }
void show() {
if (parent == nullptr) {
return;
} else {
HWND hWndTab = uGetDlgItem(parent, IDC_TABS);
RECT tabRect;
GetWindowRect(hWndTab, &tabRect);
hWnd = uCreateDialog(id, parent, dialogProxy, reinterpret_cast<LPARAM>(this));
SetWindowPos(hWnd, nullptr, m_rcTab.left, m_rcTab.top, m_rcTab.right - m_rcTab.left,
m_rcTab.bottom - m_rcTab.top, SWP_NOZORDER | SWP_NOACTIVATE);
ShowWindow(hWnd, SW_SHOW);
}
}
virtual BOOL CALLBACK dialogProc(HWND hWnd, UINT uMsg, WPARAM wParam,
LPARAM lParam) = 0;
static INT_PTR WINAPI CALLBACK dialogProxy(HWND hWnd, UINT uMsg,
WPARAM wParam, LPARAM lParam){
//FB2K_console_formatter() << "CALLBACK ConfigWindow::dialogProc()";
ConfigTab* configTab = nullptr;
if (uMsg == WM_INITDIALOG) {
configTab = reinterpret_cast<ConfigTab*>(lParam);
SetWindowLongPtr(hWnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(configTab));
configTab->hWnd = hWnd;
}
else {
configTab = reinterpret_cast<ConfigTab*>(GetWindowLongPtr(hWnd, GWLP_USERDATA));
}
if (configTab == nullptr)
return FALSE;
return configTab->dialogProc(hWnd, uMsg, wParam, lParam);
}
void loadDisableMap() {
for (auto [checkboxId, itemToDisable] : disableMap) {
bool enabled = uButton_GetCheck(hWnd, checkboxId);
if (itemToDisable < 0) {
uEnableWindow(uGetDlgItem(hWnd, -itemToDisable), static_cast<BOOL>(!enabled));
} else {
uEnableWindow(uGetDlgItem(hWnd, itemToDisable), static_cast<BOOL>(enabled));
}
}
for (auto [checkboxId, itemToDisable] : disableStateMatch) {
bool disabled = !IsWindowEnabled(uGetDlgItem(hWnd, checkboxId));
if (disabled)
uEnableWindow(uGetDlgItem(hWnd, itemToDisable), FALSE);
}
}
void notifyParent(const UINT ndxTab, const UINT code) {
//CF_USER_CONFIG_NEWTAB
//CF_USER_CONFIG_CHANGE
NMHDR lparam;
lparam.code = code;
lparam.idFrom = ndxTab;
lparam.hwndFrom = hWnd;
uSendMessage(parent, WM_NOTIFY, (WPARAM)IDC_TABS, (LPARAM)&lparam);
}
void buttonClicked(UINT id) {
loadDisableMap();
notifyParent(id, CF_USER_CONFIG_CHANGE);
}
void textChanged(UINT id) {
notifyParent(id, CF_USER_CONFIG_CHANGE);
}
void listSelChanged(UINT id) {
LRESULT s = uSendDlgItemMessage(hWnd, id, CB_GETCURSEL, 0, 0);
if (s != CB_ERR) {
notifyParent(id, CF_USER_CONFIG_CHANGE);
}
}
protected:
void redrawMainWin() {
EngineThread::forEach([](auto& t) { t.invalidateWindow(); });
}
};
#define CONFIG_TAB(CLASS, TITLE, IDD) \
CLASS(HWND parent) : ConfigTab(TITLE, IDD, parent) {}
#if 0
// minimal Tab setup
class SomeTab : public ConfigTab {
public:
CONFIG_TAB(SomeTab, TITLE, IDD);
BOOL CALLBACK dialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam){
switch (uMsg)
{
case WM_INITDIALOG:
loadConfig();
break;
case WM_COMMAND:
if (HIWORD(wParam) == EN_CHANGE){
textChanged(LOWORD(wParam));
} else if (HIWORD(wParam) == BN_CLICKED) {
buttonClicked(LOWORD(wParam));
}
break;
}
return FALSE;
}
};
#endif
/**************************************************************************************/
/**************************************************************************************/
/**************************************************************************************/
using ListMap = std::unordered_map<int, std::string>;
extern ListMap customActionAddReplaceMap;
class BehaviourTab : public ConfigTab {
private:
bool m_inactive_playlist_playable;
public:
CONFIG_TAB(BehaviourTab, "Behaviour", IDD_BEHAVIOUR_TAB);
const struct {
int chkID;
int chkBlock;
uint32_t flag;
} action_flags_checkbox[ncheckboxflag * nblock] = {
// sort definitions by flag value/ndx within each block
{IDC_CHECK_BEHA_ACTFLAG_D_PLAY, 0, ACT_PLAY}, // flag 0
{IDC_CHECK_BEHA_ACTFLAG_D_SET, 0, ACT_ACTIVATE}, // flag 1
{IDC_CHECK_BEHA_ACTFLAG_D_HIGHLIGHT, 0, ACT_HIGHLIGHT}, // flag 3
{IDC_CHECK_BEHA_ACTFLAG_D_RATED, 0, ACT_RATED}, // flag 5
{IDC_CHECK_BEHA_ACTFLAG_D_RATED_HIGHT, 0, ACT_RATED_HIGHT}, // flag 6
{IDC_CHECK_BEHA_ACTFLAG_M_PLAY, 1, ACT_PLAY}, // flag 0
{IDC_CHECK_BEHA_ACTFLAG_M_SET, 1, ACT_ACTIVATE}, // flag 1
{IDC_CHECK_BEHA_ACTFLAG_M_HIGHLIGHT, 1, ACT_HIGHLIGHT}, // flag 3
{IDC_CHECK_BEHA_ACTFLAG_M_RATED, 1, ACT_RATED}, // flag 5
{IDC_CHECK_BEHA_ACTFLAG_M_RATED_HIGHT, 1, ACT_RATED_HIGHT}, // flag 6
{IDC_CHECK_BEHA_ACTFLAG_E_PLAY, 2, ACT_PLAY}, // flag 0
{IDC_CHECK_BEHA_ACTFLAG_E_SET, 2, ACT_ACTIVATE}, // flag 1
{IDC_CHECK_BEHA_ACTFLAG_E_HIGHLIGHT, 2, ACT_HIGHLIGHT}, // flag 3
{IDC_CHECK_BEHA_ACTFLAG_E_RATED, 2, ACT_RATED}, // flag 5
{IDC_CHECK_BEHA_ACTFLAG_E_RATED_HIGHT, 2, ACT_RATED_HIGHT} // flag 6
// still place for another flag (8 in total)
};
UINT action_block_combo[nblock] = {IDC_DOUBLE_CLICK, IDC_MIDDLE_CLICK, IDC_ENTER_KEY};
// note: another operation available (4 in total)
UINT action_add_replace_combo[nblock] = {IDC_COMBO_BEHA_ADD_REPLACE_FLAG_D,
IDC_COMBO_BEHA_ADD_REPLACE_FLAG_M,
IDC_COMBO_BEHA_ADD_REPLACE_FLAG_E};
void FlagHide(HWND hWnd, bool enable) {
// ShowWindow(hwndCheckbox, enable ? SW_SHOW : SW_HIDE);
EnableWindow(hWnd, enable);
}
int isActionComboBox(UINT uint) {
std::vector<UINT> vec(
action_block_combo,
action_block_combo + sizeof(action_block_combo) / sizeof(action_block_combo[0]));
std::vector<UINT>::iterator it = std::find(vec.begin(), vec.end(), uint);
if (it != vec.end()) {
return (int)std::distance(vec.begin(), it);
} else
return -1;
}
int isAddReplaceComboBox(UINT uint) {
std::vector<UINT> vec(
action_add_replace_combo,
action_add_replace_combo +
sizeof(action_add_replace_combo) / sizeof(action_add_replace_combo[0]));
std::vector<UINT>::iterator it = std::find(vec.begin(), vec.end(), uint);
if (it != vec.end()) {
return (int)std::distance(vec.begin(), it);
} else
return -1;
}
LONG_PTR getCheckboxFlagType(UINT uint) {
HWND hwndCheckbox = uGetDlgItem(hWnd, uint);
return GetWindowLongPtr(hwndCheckbox, GWLP_USERDATA);
}
int getCheckboxFlagBlock(UINT uint) {
int res = -1;
for (int i = 0; i < sizeof(action_flags_checkbox) / sizeof(action_flags_checkbox[0]);
i++)
if (action_flags_checkbox[i].chkID == (int)uint) {
res = (int)i / ncheckboxflag;
break;
}
return res;
}
int log2(int x) {
int targetlevel = 0;
while (x >>= 1) ++targetlevel;
return targetlevel;
}
//todo: still unsure about these flags/reqs/UI
void InitFlagCheckBoxes(HWND hwnd, pfc::string8* blocklist, unsigned long initflags) {
std::vector<std::vector<byte>> vallflags;
ActionFlagsToArray(vallflags, initflags);
// nflag(8) - ncheckbox (5) = excluded (3)
const int add_ndx = log2(ACT_ADD);
const int insert_ndx = log2(ACT_INSERT);
const int todo_ndx = log2(ACT_TO_DO);
// int excluded = 0;
for (int itblock = 0; itblock < nblock; itblock++) {
bool bcustomaction = CustomAction::isCustomAction(g_customActions, blocklist[itblock], true);
int excluded = 0;
for (int itflag = 0; itflag < nflag; itflag++) {
if (itflag == add_ndx || itflag == insert_ndx || itflag == todo_ndx) {
excluded++;
} else {
bool bshow = bcustomaction;
UINT idcontrol =
action_flags_checkbox[(itblock * ncheckboxflag) + itflag - excluded].chkID;
if ((idcontrol == IDC_CHECK_BEHA_ACTFLAG_D_SET ||
idcontrol == IDC_CHECK_BEHA_ACTFLAG_M_SET ||
idcontrol == IDC_CHECK_BEHA_ACTFLAG_E_SET) && !m_inactive_playlist_playable)
bshow = false;
// action_flags_checkbox[(itblock * nflag-1) + itflag - excluded].chkID;
HWND hwndCheckbox = uGetDlgItem(hWnd, idcontrol);
SetWindowLongPtr(
hwndCheckbox, GWLP_USERDATA,
action_flags_checkbox[(itblock * ncheckboxflag) + itflag - excluded].flag);
// action_flags_checkbox[(itblock * (nflag-1)) + itflag - excluded].flag);
if (vallflags[itblock][itflag] == 1)
uButton_SetCheck(hWnd, idcontrol, true);
FlagHide(hwndCheckbox, bshow);
}
}
}
}
void InitFlagComboBoxes(HWND hwnd, pfc::string8* blocklist, unsigned long initflags) {
std::vector<std::vector<byte>> vallflags;
ActionFlagsToArray(vallflags, initflags);
for (int itblock = 0; itblock < nblock; itblock++) {
bool bshow = CustomAction::isCustomAction(g_customActions, blocklist[itblock], true);
int selectedndx[nblock] = {0};
UINT idcontrol = action_add_replace_combo[itblock];
int add_ndx = log2(ACT_ADD);
int insert_ndx = log2(ACT_INSERT);
selectedndx[itblock] = vallflags[itblock][add_ndx] ? ACT_ADD : selectedndx[itblock];
selectedndx[itblock] = vallflags[itblock][insert_ndx]
? selectedndx[itblock] | ACT_INSERT
: selectedndx[itblock];
// both add & insert not implemented yet
if (vallflags[itblock][add_ndx] && vallflags[itblock][insert_ndx]) {
selectedndx[itblock] = -1; // should get here until implemented!!
}
pfc::string8 textSelection =
customActionAddReplaceMap.at(selectedndx[itblock]).c_str();
if (selectedndx[itblock] > -1) {
uSendDlgItemMessageText(
hWnd, idcontrol, CB_SELECTSTRING, 1, textSelection.c_str());
HWND hwndCombo = uGetDlgItem(hWnd, idcontrol);
FlagHide(hwndCombo, bshow);
}
}
}
BOOL CALLBACK dialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM /*lParam*/) final {
switch (uMsg) {
case WM_INITDIALOG: {
// on tab initialization & reset button
m_inactive_playlist_playable = isInactivePlaylistPlayFixed(1,6,4);
notifyParent(id, CF_USER_CONFIG_NEWTAB);
SendDlgItemMessage(hWnd, IDC_FOLLOW_DELAY_SPINNER, UDM_SETRANGE32, 1, 999);
SendDlgItemMessage(hWnd, IDC_SPIN_BEHA_HRATE, UDM_SETRANGE32, 1, 5);
// config custom actions
pfc::string8 blocklist[nblock] = {
configData->DoubleClick,
configData->MiddleClick,
configData->EnterKey,
};
// ... combobox: fill list available actions & fix combo width
for (int it = 0; it < nblock; it++) {
loadActionList(action_block_combo[it], blocklist[it]);
// fix combo dropped width
HWND combo = GetDlgItem(hWnd, action_block_combo[it]);
LRESULT width = SendMessage(combo, CB_GETDROPPEDWIDTH, 999, 999);
SendMessage(combo, CB_SETDROPPEDWIDTH, static_cast<WPARAM>(width * 1.5), 0);
}
// ... combobox: fill list add/insert/replace
for (int it = 0; it < nblock; it++)
loadActionAddReplaceList(action_add_replace_combo[it], "" /*blocklist[it]*/);
unsigned long currentFlags = std::stoul(
uGetDlgItemText(hWnd, IDC_HIDDEN_CUSTOM_ACTION_FLAG).c_str(), nullptr, 0);
// ... checkboxes: check/uncheck action flags
InitFlagCheckBoxes(hWnd, blocklist, currentFlags);
// ... checkboxes: action modifiers selected (add/insert/send)
InitFlagComboBoxes(hWnd, blocklist, currentFlags);
break;
}
case WM_COMMAND: {
if (HIWORD(wParam) == EN_CHANGE) {
// here also after flowtocontrol, calls to textchanged() are cheap before full init
if (LOWORD(wParam) == IDC_FOLLOW_DELAY) {
const int ival = std::clamp(
int(uGetDlgItemInt(hWnd, IDC_FOLLOW_DELAY, nullptr, 1)), 1, 999);
const int oldval = uGetDlgItemInt(hWnd, IDC_FOLLOW_DELAY, nullptr, 1);
if (ival != oldval)
uSetDlgItemInt(hWnd, IDC_FOLLOW_DELAY, ival, 1);
}
if (LOWORD(wParam) == IDC_EDIT_BEHA_HRATE) {
const int ival = std::clamp(
int(uGetDlgItemInt(hWnd, IDC_EDIT_BEHA_HRATE, nullptr, 1)), 1, 5);
const int oldval = uGetDlgItemInt(hWnd, IDC_EDIT_BEHA_HRATE, nullptr, 1);
if (ival != oldval)
uSetDlgItemInt(hWnd, IDC_EDIT_BEHA_HRATE, ival, 1);
}
textChanged(LOWORD(wParam));
} else if (HIWORD(wParam) == EN_UPDATE) {
; // do nothing
} else if (HIWORD(wParam) == BN_CLICKED) {
buttonClicked(LOWORD(wParam));
const int flagType = (int)getCheckboxFlagType(LOWORD(wParam));
if (flagType >= static_cast<int>(action_flags_checkbox[0].flag)) { // ACT_PLAY is the lowest value flag
const int action_block = getCheckboxFlagBlock(LOWORD(wParam));
const unsigned long currentFlags = std::stoul(
uGetDlgItemText(hWnd, IDC_HIDDEN_CUSTOM_ACTION_FLAG).c_str(), nullptr, 0);
const bool benable = (uButton_GetCheck(hWnd, LOWORD(wParam)));
const unsigned long updatedflags = ActionFlagsCalculate(
action_block, flagType, false, currentFlags, benable);
uSetDlgItemText(
hWnd, IDC_HIDDEN_CUSTOM_ACTION_FLAG, std::to_string(updatedflags).data());
textChanged(IDC_HIDDEN_CUSTOM_ACTION_FLAG);
}
} else if (HIWORD(wParam) == CBN_SELCHANGE) {
// check if an action selection combobox triggered the event
if (const int accBlock = isActionComboBox(LOWORD(wParam)); accBlock > -1) {
// selection change on custom action combobox
listSelChanged(LOWORD(wParam));
pfc::string8 selected;
LRESULT ires = uSendDlgItemMessage(hWnd, LOWORD(wParam), CB_GETCURSEL, 0, 0);
if (ires != CB_ERR) {
uGetDlgItemText(hWnd, LOWORD(wParam), selected);
} else {
return FALSE;
}
// update flag checkboxes: enabled/disabled state for custom action
bool bcustomaction = CustomAction::isCustomAction(g_customActions, selected, true);
for (int itflag = 0; itflag < ncheckboxflag; itflag++) {
bool bshow = bcustomaction;
UINT idcontrol =
action_flags_checkbox[accBlock * ncheckboxflag + itflag].chkID;
//disable activate playlist checkbox is not fb2k >= v1.6.4
if ((idcontrol == IDC_CHECK_BEHA_ACTFLAG_D_SET ||
idcontrol == IDC_CHECK_BEHA_ACTFLAG_M_SET ||
idcontrol == IDC_CHECK_BEHA_ACTFLAG_E_SET) &&
!m_inactive_playlist_playable)
bshow = false;
HWND hwndCheckBox = uGetDlgItem(hWnd, idcontrol);
FlagHide(hwndCheckBox, bshow);
}
// update flag combobox: enabled/disabled state for custom
UINT idcontrol = action_add_replace_combo[accBlock];
HWND hwndControl = uGetDlgItem(hWnd, idcontrol);
FlagHide(hwndControl, bcustomaction);
} else {
// check if an add/replace selection combobox triggered the event
if (int repBlock = isAddReplaceComboBox(LOWORD(wParam)); repBlock != -1) {
LRESULT itemId = uSendDlgItemMessage(hWnd, LOWORD(wParam), CB_GETCURSEL, 0, 0);
if (itemId == CB_ERR) {
return FALSE;
}
LRESULT val = uSendDlgItemMessage(hWnd, LOWORD(wParam), CB_GETITEMDATA, itemId, 0);
unsigned long updatedflags = std::stoul(
uGetDlgItemText(hWnd, IDC_HIDDEN_CUSTOM_ACTION_FLAG).c_str(), nullptr,
0);
updatedflags = ActionFlagsCalculate(repBlock, ACT_ADD, false, updatedflags, (val & ACT_ADD) == ACT_ADD);
updatedflags = ActionFlagsCalculate(repBlock, ACT_INSERT, false, updatedflags, (val & ACT_INSERT) == ACT_INSERT);
// will trigger textchanged(...)
uSetDlgItemText(hWnd, IDC_HIDDEN_CUSTOM_ACTION_FLAG, std::to_string(updatedflags).data());
}
}
}
break;
}
}
return FALSE;
}
void loadActionList(UINT id, const char* selectedItem) {
HWND list = GetDlgItem(hWnd, id);
SetWindowRedraw(list, false);
SendMessage(list, CB_RESETCONTENT, 0, 0);
uSendMessageText(list, CB_ADDSTRING, 0, "");
service_enum_t<contextmenu_item> menus;
service_ptr_t<contextmenu_item> menu;
while (menus.next(menu)) {
pfc::string8_fastalloc menuPath;
pfc::string8_fastalloc menuName;
for (unsigned int i = 0; i < menu->get_num_items(); i++) {
menu->get_item_default_path(i, menuPath);
menu->get_item_name(i, menuName);
if (!menuPath.is_empty())
menuPath.add_string("/");
if (strcmp(menuPath, "Play") == 0) {
continue;
}
menuPath.add_string(menuName);
uSendMessageText(list, CB_ADDSTRING, 0, menuPath);
}
}
for (auto action : boost::adaptors::reverse(g_customActions)) {
uSendMessageText(list, CB_INSERTSTRING, 0, action->actionName);
}
LRESULT itemId = uSendDlgItemMessageText(hWnd, id, CB_FINDSTRINGEXACT, 1, selectedItem);
itemId = uSendDlgItemMessageText(hWnd, id, CB_SETCURSEL, itemId, 0);
SetWindowRedraw(list, true);
}
void loadActionAddReplaceList(UINT id, const char* selectedItem) {
HWND list = GetDlgItem(hWnd, id);
SetWindowRedraw(list, false);
SendMessage(list, CB_RESETCONTENT, 0, 0);
uSendMessageText(list, CB_ADDSTRING, 0, "");
uSendDlgItemMessage(hWnd, id, CB_RESETCONTENT, 0, 0);
for (auto& [val, text] : customActionAddReplaceMap) {
LRESULT itemId = uSendDlgItemMessageText(hWnd, id, CB_ADDSTRING, 0, text.c_str());
uSendDlgItemMessage(hWnd, id, CB_SETITEMDATA, itemId, val);
if (stricmp_utf8(text.c_str(), selectedItem) == 0) {
uSendDlgItemMessageText(hWnd, id, CB_SELECTSTRING, 1, selectedItem);
}
}
SetWindowRedraw(list, true);
}
};
/**************************************************************************************/
/**************************************************************************************/
class SourcesTab : public ConfigTab {
public:
CONFIG_TAB(SourcesTab, "Album Source", IDD_SOURCE_TAB);
BOOL CALLBACK dialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM /*lParam*/) final {
switch (uMsg) {
case WM_INITDIALOG: {
notifyParent(id, CF_USER_CONFIG_NEWTAB);
size_t selected_row = ~0;
loadComboSourcePlayList(IDC_COMBO_SOURCE_PLAYLIST_NAME,
configData->SourcePlaylistName, pfc::GUID_from_text(configData->SourcePlaylistGUID), selected_row);
HWND combo = GetDlgItem(hWnd, IDC_COMBO_SOURCE_PLAYLIST_NAME);
LRESULT width = SendMessage(combo, CB_GETDROPPEDWIDTH, 999, 999);
SendMessage(combo, CB_SETDROPPEDWIDTH, static_cast<WPARAM>(width * 1.5), 0);
}
break;
case WM_COMMAND: {
switch (HIWORD(wParam)) {
case EN_CHANGE:
textChanged(LOWORD(wParam));
break;
case CBN_SELCHANGE: {
listSelChanged(LOWORD(wParam));
LRESULT ires = uSendDlgItemMessage(hWnd, LOWORD(wParam), CB_GETCURSEL, 0, 0);
if (ires != CB_ERR) {
//..
} else {
return FALSE;
}
LRESULT itemId = uSendDlgItemMessage(hWnd, LOWORD(wParam), CB_GETCURSEL, 0, 0);
if (itemId == CB_ERR) {
return FALSE;
}
uSendDlgItemMessage(hWnd, LOWORD(wParam), CB_GETITEMDATA, itemId, 0);
break;
}
case BN_CLICKED:
buttonClicked(LOWORD(wParam));
break;
default:
break;
} // sw command param
break;
} // sw command
default:
break;
} //msg
return FALSE;
}
void loadComboSourcePlayList(UINT id,const char* selected_name, const GUID selected_guid, size_t &selected_row) {
HWND list = GetDlgItem(hWnd, id);
SetWindowRedraw(list, false);
SendMessage(list, CB_RESETCONTENT, 0, 0);
uSendMessageText(list, CB_ADDSTRING, 0, "");
uSendDlgItemMessage(hWnd, id, CB_RESETCONTENT, 0, 0);
if (pfc_infinite == playlist_manager::get()->find_playlist(default_SourcePlaylistName)) {
uSendDlgItemMessageText(hWnd, id, CB_ADDSTRING, 0, default_SourcePlaylistName);
uSendDlgItemMessage(hWnd, id, CB_SETITEMDATA, 0, NULL);
}
size_t cplaylist = playlist_manager::get()->get_playlist_count();
for (size_t i = 0; i < cplaylist; i++) {
pfc::string8 aname;
t_size pl = playlist_manager_v6::get()->playlist_get_name(i, aname);
GUID aguid = playlist_manager_v6::get()->playlist_get_guid(pl);
LRESULT rowId = uSendDlgItemMessageText(hWnd, id, CB_ADDSTRING, 0, aname);
uSendDlgItemMessage(hWnd, id, CB_SETITEMDATA, rowId, pl);
if (selected_row = uSendDlgItemMessage(hWnd, id, CB_GETCURSEL, 0, 0) == CB_ERR) {
LPARAM lpdata = uSendDlgItemMessage(hWnd, id, CB_GETITEMDATA, rowId, 0);
GUID row_guid = playlist_manager_v6::get()->playlist_get_guid(lpdata);
if (pfc::guid_equal(selected_guid, row_guid)) {
selected_row = uSendDlgItemMessageText(hWnd, id, CB_SETCURSEL, rowId, 0);
}
}
}
//check if still undefined
LRESULT checkId = uSendDlgItemMessage(hWnd, id, CB_GETCURSEL, 0, 0);
if (checkId == CB_ERR) {
if (!stricmp_utf8(default_SourcePlaylistName, selected_name)) {
checkId = uSendDlgItemMessageText(hWnd, id, CB_FINDSTRINGEXACT, 1, default_SourcePlaylistName);
} else {
checkId = uSendDlgItemMessageText(hWnd, id, CB_ADDSTRING, 0, selected_name);
uSendDlgItemMessage(hWnd, id, CB_SETITEMDATA, checkId, NULL);
}
selected_row = uSendDlgItemMessageText(hWnd, id, CB_SETCURSEL, checkId, 0);
}
SetWindowRedraw(list, true);
}
};
extern ListMap customCoverFrontArtMap;
/**************************************************************************************/
/**************************************************************************************/
class DisplayTab : public ConfigTab {
public:
CONFIG_TAB(DisplayTab, "Display", IDD_DISPLAY_TAB);
bool browseForImageOrExe(const char* oldImg, pfc::string_base& out, bool bimage = true) {
OPENFILENAME ofn;
wchar_t fileName[1024];
pfc::stringcvt::convert_utf8_to_wide(
static_cast<wchar_t*>(fileName), 1024, oldImg, ~0u);
ZeroMemory(&ofn, sizeof(ofn));
ofn.lStructSize = sizeof(ofn);
ofn.hwndOwner = hWnd;
ofn.lpstrFile = static_cast<wchar_t*>(fileName);
ofn.nMaxFile = 1024;
if (bimage)
ofn.lpstrFilter = L"Image File\0*.jpg;*.jpeg;*.png;*.gif;*.bmp;*.tiff\0";
else
ofn.lpstrFilter = L"Executable File\0*.exe\0";
ofn.nFilterIndex = 1;
ofn.Flags =
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_NONETWORKBUTTON | OFN_PATHMUSTEXIST;
if (GetOpenFileName(&ofn)) {
out = pfc::stringcvt::string_utf8_from_wide(static_cast<wchar_t*>(fileName))
.get_ptr();
return true;
} else {
return false;
}
}
BOOL CALLBACK dialogProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) final {
switch (uMsg) {
case 132: //?
break;
case WM_SETFOCUS:
break;
case WM_INITDIALOG: {
notifyParent(id, CF_USER_CONFIG_NEWTAB);
int selectedndx = InitCustomCoverArtComboBox(configData->CustomCoverFrontArt);
loadCustomCoverFrontArtList(customCoverFrontArtMap.at(selectedndx).c_str());
selectedndx = InitExtArtFilterComboBox(configData->DisplayArtFilterFlag);
loadCExtArtFilterList(customCoverExtArtFilterMap.at(selectedndx).c_str());
int titlePosH = static_cast<int>(floor(configData->TitlePosH * 100 + 0.5));
int titlePosV = static_cast<int>(floor(configData->TitlePosV * 100 + 0.5));
uSendDlgItemMessage(hWnd, IDC_TPOS_H, TBM_SETRANGE, FALSE, MAKELONG(0, 100));
uSendDlgItemMessage(hWnd, IDC_TPOS_H, TBM_SETTIC, 0, 50);
uSendDlgItemMessage(hWnd, IDC_TPOS_H, TBM_SETPOS, TRUE, titlePosH);
uSendDlgItemMessageText(
hWnd, IDC_TPOS_H_P, WM_SETTEXT, 0, std::to_string(titlePosH).data());
uSendDlgItemMessage(hWnd, IDC_TPOS_V, TBM_SETRANGE, TRUE, MAKELONG(0, 100));
uSendDlgItemMessage(hWnd, IDC_TPOS_V, TBM_SETTIC, 0, 50);
uSendDlgItemMessage(hWnd, IDC_TPOS_V, TBM_SETPOS, TRUE, titlePosV);
uSendDlgItemMessageText(
hWnd, IDC_TPOS_V_P, WM_SETTEXT, 0, std::to_string(titlePosV).data());
uSendDlgItemMessage(
hWnd, IDC_FRAME_WIDTH_SPIN, UDM_SETRANGE, 0, MAKELONG(short(30), short(0)));
uSetDlgItemInt(
hWnd, IDC_FRAME_WIDTH, configData->HighlightWidth, false);
LOGFONT titleFont = configData->TitleFont;
std::ostringstream o_txt_stream;
o_txt_stream.write((char*)&titleFont, sizeof(titleFont));
pfc::string8 strBase64;
pfc::base64_encode(strBase64, (void*)o_txt_stream.str().c_str(), sizeof(titleFont));
uSetDlgItemText(hWnd, IDC_HIDDEN_LOGFONT, strBase64.c_str());
uSetDlgItemText(hWnd, IDC_HIDDEN_EXT_VIEWER_PATH, configData->DisplayExtViewerPath.c_str());
uSendDlgItemMessage(hWnd, IDC_FONT_PREV, WM_SETTEXT, 0, reinterpret_cast<LPARAM>(titleFont.lfFaceName));
break;
}
case WM_HSCROLL: {
CScrollBar* sb = reinterpret_cast<CScrollBar*>(&lParam);
UINT idscrollcontrol = sb->GetDlgCtrlID();
UINT idtextcontrol, idtextdoublecontrol;
if (idscrollcontrol == IDC_TPOS_H) {
idtextcontrol = IDC_TPOS_H_P;
idtextdoublecontrol = IDC_HIDDEN_TPOS_H;
} else {
idtextcontrol = IDC_TPOS_V_P;
idtextdoublecontrol = IDC_HIDDEN_TPOS_V;
}
UINT val = (UINT) uSendDlgItemMessage(hWnd, idscrollcontrol, TBM_GETPOS, 0, 0);
uSetDlgItemInt(hWnd, idtextcontrol, val, true);
//will trigger EN_CHANGE & therefore textchanged(id)
uSetDlgItemText(hWnd, idtextdoublecontrol, std::to_string(val * 0.01).c_str());
} break;
case WM_DRAWITEM: {
auto* drawStruct = reinterpret_cast<DRAWITEMSTRUCT*>(lParam);
HBRUSH brush{};
switch (wParam) {
case IDC_TEXTCOLOR_PREV: {
COLORREF textColor = static_cast<COLORREF>(std::stoull(
uGetDlgItemText(hWnd, IDC_HIDDEN_TITLE_COLOR_CUSTOM).c_str(), nullptr, 0));
brush = CreateSolidBrush(textColor);
break;
}
case IDC_BG_COLOR_PREV: {
COLORREF panelBg = static_cast<COLORREF>(std::stoul(
uGetDlgItemText(hWnd, IDC_HIDDEN_PANELBG_CUSTOM).c_str(), nullptr, 0));
brush = CreateSolidBrush(panelBg);
break;
}
}
FillRect(drawStruct->hDC, &drawStruct->rcItem, brush);
} break;
case WM_COMMAND:
if (HIWORD(wParam) == EN_ERRSPACE) {
FB2K_console_formatter()
<< "EN_ERRSPACE " + LOWORD(wParam) << ", " << HIWORD(wParam);
} else if (HIWORD(wParam) == EN_CHANGE) {
switch (LOWORD(wParam)) {
case IDC_IMG_NO_COVER:
case IDC_IMG_LOADING:
case IDC_HIDDEN_TPOS_V:
case IDC_HIDDEN_TPOS_H:
case IDC_HIDDEN_DISPLAY_CUSTOM_COVER_ART:
case IDC_HIDDEN_EXT_VIEWER_PATH:
textChanged(LOWORD(wParam));
break;
case IDC_HIDDEN_DISPLAY_FLAG:
textChanged(LOWORD(wParam));
break;
case IDC_ALBUM_FORMAT: {
metadb_handle_ptr aTrack;
if (metadb::get()->g_get_random_handle(aTrack)) {
pfc::string8 preview;
titleformat_object::ptr titleformat;
pfc::string stralbumtitle = uGetDlgItemText(hWnd, IDC_ALBUM_FORMAT);
titleformat_compiler::get()->compile_safe_ex(
titleformat, stralbumtitle.c_str());
aTrack->format_title(nullptr, preview, titleformat, nullptr);
preview.replace_string("\r\n", "↵");
uSendDlgItemMessageText(hWnd, IDC_TITLE_PREVIEW, WM_SETTEXT, 0, preview);
}
textChanged(LOWORD(wParam));
} break;
case IDC_FRAME_WIDTH: {
int val = uGetDlgItemInt(hWnd, IDC_FRAME_WIDTH, nullptr, false);
int val_clamp = std::clamp(val, 0, 30);
if (val != val_clamp) {
uSetDlgItemInt(hWnd, IDC_FRAME_WIDTH, val_clamp, true);
}
textChanged(IDC_FRAME_WIDTH);
} break;
}
} else if (HIWORD(wParam) == BN_CLICKED) {
switch (LOWORD(wParam)) {
case IDC_APPLY_TITLE: {
EngineThread::forEach(
[](EngineThread& t) { t.send<EM::ReloadCollection>(NULL); });
} break;
case IDC_BG_COLOR: {
COLORREF panelBg = static_cast<COLORREF>(std::stoul(
uGetDlgItemText(hWnd, IDC_HIDDEN_PANELBG_CUSTOM).c_str(), nullptr, 0));
if (selectColor(panelBg)) {
uSetDlgItemText(
hWnd, IDC_HIDDEN_PANELBG_CUSTOM, std::to_string(panelBg).data());
InvalidateRect(uGetDlgItem(hWnd, IDC_BG_COLOR_PREV), nullptr, TRUE);
textChanged(IDC_HIDDEN_PANELBG_CUSTOM);
}
} break;
case IDC_TEXTCOLOR: {
COLORREF titleColor = static_cast<COLORREF>(std::stoul(
uGetDlgItemText(hWnd, IDC_HIDDEN_TITLE_COLOR_CUSTOM).c_str(), nullptr, 0));
if (selectColor(titleColor)) {
uSetDlgItemText(hWnd, IDC_HIDDEN_TITLE_COLOR_CUSTOM,
std::to_string(titleColor).data());
InvalidateRect(uGetDlgItem(hWnd, IDC_TEXTCOLOR_PREV), nullptr, TRUE);
EngineThread::forEach(
[](EngineThread& t) { t.send<EM::TextFormatChangedMessage>(); });
textChanged(IDC_HIDDEN_TITLE_COLOR_CUSTOM);
}
} break;
case IDC_FONT: {
LOGFONT titleFont = configData->TitleFont;
if (selectFont(titleFont)) {
std::ostringstream o_txt_stream;
o_txt_stream.write((char*)&titleFont, sizeof(titleFont));
pfc::string8 strBase64;
pfc::base64_encode(
strBase64, (void*)o_txt_stream.str().c_str(), sizeof(titleFont));
uSetDlgItemText(hWnd, IDC_HIDDEN_LOGFONT, strBase64.c_str());
// debug
// pfc::string8 tmpstrBase64;
// uGetDlgItemText(hWnd, IDC_HIDDEN_LOGFONT, tmpstrBase64);
// LOGFONT restoreFont;
// pfc::base64_decode(tmpstrBase64.c_str(), &restoreFont);
uSendDlgItemMessage(hWnd, IDC_FONT_PREV, WM_SETTEXT, 0,
reinterpret_cast<LPARAM>(titleFont.lfFaceName));
EngineThread::forEach(
[](EngineThread& t) { t.send<EM::TextFormatChangedMessage>(); });
textChanged(LOWORD(wParam));
}
} break;
case IDC_IMG_NO_COVER_BROWSE: {
pfc::string8 strDlgOutString;
if (browseForImageOrExe(configData->ImgNoCover, strDlgOutString)) {
uSetDlgItemText(hWnd, IDC_IMG_NO_COVER, strDlgOutString);
}
} break;
case IDC_IMG_LOADING_BROWSE: {
pfc::string8 strDlgOutString;
if (browseForImageOrExe(configData->ImgLoading, strDlgOutString)) {
uSetDlgItemText(hWnd, IDC_IMG_LOADING, strDlgOutString);
}
} break;
case IDC_EXT_VIEWER_BROWSE: {
pfc::string8 strDlgOutString;
if (browseForImageOrExe(configData->DisplayExtViewerPath, strDlgOutString, false)) {
uSetDlgItemText(hWnd, IDC_HIDDEN_EXT_VIEWER_PATH, strDlgOutString);
}
} break;
case IDC_COVER_DISPLAY_DISPLAY_FLAG: {
bool bcheck = uButton_GetCheck(hWnd, LOWORD(wParam));
pfc::string8 curhidden;
uGetDlgItemText(hWnd, IDC_HIDDEN_DISPLAY_FLAG, curhidden);
int icur = atoi(curhidden);
if (bcheck) {
icur |= DispFlags::DISABLE_CAROUSEL;
} else {
icur &= ~DispFlags::DISABLE_CAROUSEL;
}
// will trigger textchanged...
uSetDlgItemText(hWnd, IDC_HIDDEN_DISPLAY_FLAG, std::to_string(icur).data());
break;
}
case IDC_ALBUM_TITLE:
case IDC_TEXTCOLOR_CUSTOM:
case IDC_FONT_CUSTOM:
case IDC_BG_COLOR_CUSTOM:
case IDC_COVER_ART_PNG8_ALPHA:
case IDC_COVER_DISPLAY_LEGACY_EXTVIEWER: {
buttonClicked(LOWORD(wParam));
EngineThread::forEach(
[](EngineThread& t) { t.send<EM::TextFormatChangedMessage>(); });
} break;
default:
break;
}
} else if (HIWORD(wParam) == CBN_SELCHANGE) {
if (LOWORD(wParam) == IDC_PANEL_DISPLAY_COMBO_CUSTOM_COVER_ART) {
LRESULT itemId = uSendDlgItemMessage(hWnd, LOWORD(wParam), CB_GETCURSEL, 0, 0);
if (itemId == CB_ERR) {
return FALSE;
}
LRESULT val = uSendDlgItemMessage(hWnd, LOWORD(wParam), CB_GETITEMDATA, itemId, 0);
// will trigger textchanged...
uSetDlgItemText(
hWnd, IDC_HIDDEN_DISPLAY_CUSTOM_COVER_ART, std::to_string(val).data());
} else if (LOWORD(wParam) == IDC_PANEL_DISPLAY_COMBO_EXT_ART_FILTER) {
LRESULT itemId =
uSendDlgItemMessage(hWnd, LOWORD(wParam), CB_GETCURSEL, 0, 0);
if (itemId == CB_ERR) {
return FALSE;
}
LRESULT val =
uSendDlgItemMessage(hWnd, LOWORD(wParam), CB_GETITEMDATA, itemId, 0);
// will trigger textchanged...
uSetDlgItemText(
hWnd, IDC_HIDDEN_DISPLAY_EXT_ARTFILTER_FLAG, std::to_string(val).data());
}
} else {
//..
}
break;
}
return FALSE;
}
private:
bool selectColor(COLORREF& color) {
static DWORD costumColors[16] = {0};
COLORREF tColor = color;
if (uChooseColor(&tColor, hWnd, static_cast<DWORD*>(costumColors))) {
color = tColor;
return true;
} else {
return false;
}
}
bool selectFont(LOGFONT& font) {
LOGFONT tFont = font;
CHOOSEFONT cf = {0};
cf.lStructSize = sizeof(cf);
cf.hwndOwner = hWnd;
cf.lpLogFont = &tFont;
cf.Flags = CF_TTONLY | CF_SCREENFONTS | CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT;
if (ChooseFont(&cf)) {
font = tFont;
return true;
} else {
return false;
}
}