|
1
|
1 #include "stdafx.h"
|
|
|
2
|
|
|
3 #include <helpers/advconfig_impl.h>
|
|
|
4 #include <SDK/cfg_var.h>
|
|
|
5
|
|
|
6 #ifdef _WIN32
|
|
|
7 #include "resource.h"
|
|
|
8 #include <helpers/atl-misc.h>
|
|
|
9 #include <helpers/DarkMode.h>
|
|
|
10 #endif // _WIN32
|
|
|
11
|
|
|
12 // Sample preferences interface: two meaningless configuration settings accessible through a preferences page and one accessible through advanced preferences.
|
|
|
13
|
|
|
14 // Dark Mode:
|
|
|
15 // (1) Add fb2k::CDarkModeHooks member.
|
|
|
16 // (2) Initialize it in our WM_INITDIALOG handler.
|
|
|
17 // (3) Tell foobar2000 that this prefernces page supports dark mode, by returning correct get_state() flags.
|
|
|
18 // That's all.
|
|
|
19
|
|
|
20
|
|
|
21 // These GUIDs identify the variables within our component's configuration file.
|
|
|
22 static constexpr GUID guid_cfg_bogoSetting1 = { 0xbd5c777, 0x735c, 0x440d, { 0x8c, 0x71, 0x49, 0xb6, 0xac, 0xff, 0xce, 0xb8 } };
|
|
|
23 static constexpr GUID guid_cfg_bogoSetting2 = { 0x752f1186, 0x9f61, 0x4f91, { 0xb3, 0xee, 0x2f, 0x25, 0xb1, 0x24, 0x83, 0x5d } };
|
|
|
24
|
|
|
25 // This GUID identifies our Advanced Preferences branch (replace with your own when reusing code).
|
|
|
26 static constexpr GUID guid_advconfig_branch = { 0x28564ced, 0x4abf, 0x4f0c, { 0xa4, 0x43, 0x98, 0xda, 0x88, 0xe2, 0xcd, 0x39 } };
|
|
|
27 // This GUID identifies our Advanced Preferences setting (replace with your own when reusing code) as well as this setting's storage within our component's configuration file.
|
|
|
28 static constexpr GUID guid_cfg_bogoSetting3 = { 0xf7008963, 0xed60, 0x4084, { 0xa8, 0x5d, 0xd1, 0xcd, 0xc5, 0x51, 0x22, 0xca } };
|
|
|
29 static constexpr GUID guid_cfg_bogoSetting4 = { 0x99e206f8, 0xd7be, 0x47e6, { 0xb5, 0xfe, 0xf4, 0x41, 0x5f, 0x6c, 0x16, 0xed } };
|
|
|
30 static constexpr GUID guid_cfg_bogoSetting5 = { 0x7369ad25, 0x9e81, 0x4e2f, { 0x8b, 0xe7, 0x95, 0xcb, 0x81, 0x99, 0x9b, 0x1b } };
|
|
|
31
|
|
|
32 static constexpr GUID guid_cfg_bogoRadio = { 0x4c18b9ab, 0xf823, 0x4d05, { 0xb6, 0x18, 0x14, 0xb9, 0x4c, 0xad, 0xa2, 0xaa } };
|
|
|
33 static constexpr GUID guid_cfg_bogoRadio1 = { 0xdd0a3a95, 0x1546, 0x4f25, { 0xa6, 0x8c, 0x23, 0xcf, 0x3d, 0xa5, 0x8f, 0x59 } };
|
|
|
34 static constexpr GUID guid_cfg_bogoRadio2 = { 0xc35e1689, 0xb96f, 0x4bf4, { 0x95, 0xfb, 0xb7, 0x8e, 0x83, 0xc5, 0x2c, 0x7d } };
|
|
|
35 static constexpr GUID guid_cfg_bogoRadio3 = { 0x790fe179, 0x9908, 0x47e2, { 0x9f, 0xde, 0xce, 0xe1, 0x3f, 0x9a, 0xfc, 0x5b } };
|
|
|
36
|
|
|
37 // defaults
|
|
|
38 constexpr int default_cfg_bogo1 = 1337,
|
|
|
39 default_cfg_bogo2 = 666,
|
|
|
40 default_cfg_bogo3 = 42;
|
|
|
41
|
|
|
42 static constexpr char default_cfg_bogo4[] = "foobar";
|
|
|
43 static constexpr bool default_cfg_bogo5 = false;
|
|
|
44
|
|
|
45 // Advanced preferences order
|
|
|
46 enum {
|
|
|
47 order_bogo3,
|
|
|
48 order_bogo4,
|
|
|
49 order_bogo5,
|
|
|
50 order_bogoRadio
|
|
|
51 };
|
|
|
52
|
|
|
53 enum {
|
|
|
54 order_bogoRadio1,
|
|
|
55 order_bogoRadio2,
|
|
|
56 order_bogoRadio3,
|
|
|
57 };
|
|
|
58
|
|
|
59 namespace foo_sample { // accessed also from Mac specific code hence not static
|
|
|
60 cfg_uint cfg_bogoSetting1(guid_cfg_bogoSetting1, default_cfg_bogo1), cfg_bogoSetting2(guid_cfg_bogoSetting2, default_cfg_bogo2);
|
|
|
61 }
|
|
|
62 using namespace foo_sample;
|
|
|
63
|
|
|
64 static advconfig_branch_factory g_advconfigBranch("Sample Component", guid_advconfig_branch, advconfig_branch::guid_branch_tools, 0);
|
|
|
65 static advconfig_integer_factory cfg_bogoSetting3("Bogo setting 3","foo_sample.bogo3", guid_cfg_bogoSetting3, guid_advconfig_branch, order_bogo3, default_cfg_bogo3, 0 /*minimum value*/, 9999 /*maximum value*/);
|
|
|
66 static advconfig_string_factory cfg_bogoSetting4("Bogo setting 4", "foo_sample.bogo4", guid_cfg_bogoSetting4, guid_advconfig_branch, order_bogo4, default_cfg_bogo4);
|
|
|
67 static advconfig_checkbox_factory cfg_bogoSetting5("Bogo setting 5", "foo_sample.bogo5", guid_cfg_bogoSetting5, guid_advconfig_branch, order_bogo5, default_cfg_bogo5);
|
|
|
68 static advconfig_branch_factory cfg_bogoRadioBranch("Bogo radio", guid_cfg_bogoRadio, guid_advconfig_branch, order_bogoRadio);
|
|
|
69 static advconfig_radio_factory cfg_bogoRadio1("Radio 1", "foo_sample.bogoRaidio.1", guid_cfg_bogoRadio1, guid_cfg_bogoRadio, order_bogoRadio1, true);
|
|
|
70 static advconfig_radio_factory cfg_bogoRadio2("Radio 2", "foo_sample.bogoRaidio.2", guid_cfg_bogoRadio2, guid_cfg_bogoRadio, order_bogoRadio2, false);
|
|
|
71 static advconfig_radio_factory cfg_bogoRadio3("Radio 3", "foo_sample.bogoRaidio.3", guid_cfg_bogoRadio3, guid_cfg_bogoRadio, order_bogoRadio3, false);
|
|
|
72
|
|
|
73 #ifdef _WIN32
|
|
|
74 class CMyPreferences : public CDialogImpl<CMyPreferences>, public preferences_page_instance {
|
|
|
75 public:
|
|
|
76 //Constructor - invoked by preferences_page_impl helpers - don't do Create() in here, preferences_page_impl does this for us
|
|
|
77 CMyPreferences(preferences_page_callback::ptr callback) : m_callback(callback) {}
|
|
|
78
|
|
|
79 //Note that we don't bother doing anything regarding destruction of our class.
|
|
|
80 //The host ensures that our dialog is destroyed first, then the last reference to our preferences_page_instance object is released, causing our object to be deleted.
|
|
|
81
|
|
|
82
|
|
|
83 //dialog resource ID
|
|
|
84 enum {IDD = IDD_MYPREFERENCES};
|
|
|
85 // preferences_page_instance methods (not all of them - get_wnd() is supplied by preferences_page_impl helpers)
|
|
|
86 t_uint32 get_state();
|
|
|
87 void apply();
|
|
|
88 void reset();
|
|
|
89
|
|
|
90 //WTL message map
|
|
|
91 BEGIN_MSG_MAP_EX(CMyPreferences)
|
|
|
92 MSG_WM_INITDIALOG(OnInitDialog)
|
|
|
93 COMMAND_HANDLER_EX(IDC_BOGO1, EN_CHANGE, OnEditChange)
|
|
|
94 COMMAND_HANDLER_EX(IDC_BOGO2, EN_CHANGE, OnEditChange)
|
|
|
95 END_MSG_MAP()
|
|
|
96 private:
|
|
|
97 BOOL OnInitDialog(CWindow, LPARAM);
|
|
|
98 void OnEditChange(UINT, int, CWindow);
|
|
|
99 bool HasChanged();
|
|
|
100 void OnChanged();
|
|
|
101
|
|
|
102 const preferences_page_callback::ptr m_callback;
|
|
|
103
|
|
|
104 // Dark mode hooks object, must be a member of dialog class.
|
|
|
105 fb2k::CDarkModeHooks m_dark;
|
|
|
106 };
|
|
|
107
|
|
|
108 BOOL CMyPreferences::OnInitDialog(CWindow, LPARAM) {
|
|
|
109
|
|
|
110 // Enable dark mode
|
|
|
111 // One call does it all, applies all relevant hacks automatically
|
|
|
112 m_dark.AddDialogWithControls(*this);
|
|
|
113
|
|
|
114 SetDlgItemInt(IDC_BOGO1, (UINT) cfg_bogoSetting1, FALSE);
|
|
|
115 SetDlgItemInt(IDC_BOGO2, (UINT) cfg_bogoSetting2, FALSE);
|
|
|
116 return FALSE;
|
|
|
117 }
|
|
|
118
|
|
|
119 void CMyPreferences::OnEditChange(UINT, int, CWindow) {
|
|
|
120 // not much to do here
|
|
|
121 OnChanged();
|
|
|
122 }
|
|
|
123
|
|
|
124 t_uint32 CMyPreferences::get_state() {
|
|
|
125 // IMPORTANT: Always return dark_mode_supported - tell foobar2000 that this preferences page is dark mode compliant.
|
|
|
126 t_uint32 state = preferences_state::resettable | preferences_state::dark_mode_supported;
|
|
|
127 if (HasChanged()) state |= preferences_state::changed;
|
|
|
128 return state;
|
|
|
129 }
|
|
|
130
|
|
|
131 void CMyPreferences::reset() {
|
|
|
132 SetDlgItemInt(IDC_BOGO1, default_cfg_bogo1, FALSE);
|
|
|
133 SetDlgItemInt(IDC_BOGO2, default_cfg_bogo2, FALSE);
|
|
|
134 OnChanged();
|
|
|
135 }
|
|
|
136
|
|
|
137 void CMyPreferences::apply() {
|
|
|
138 cfg_bogoSetting1 = GetDlgItemInt(IDC_BOGO1, NULL, FALSE);
|
|
|
139 cfg_bogoSetting2 = GetDlgItemInt(IDC_BOGO2, NULL, FALSE);
|
|
|
140
|
|
|
141 OnChanged(); //our dialog content has not changed but the flags have - our currently shown values now match the settings so the apply button can be disabled
|
|
|
142 }
|
|
|
143
|
|
|
144 bool CMyPreferences::HasChanged() {
|
|
|
145 //returns whether our dialog content is different from the current configuration (whether the apply button should be enabled or not)
|
|
|
146 return GetDlgItemInt(IDC_BOGO1, NULL, FALSE) != cfg_bogoSetting1 || GetDlgItemInt(IDC_BOGO2, NULL, FALSE) != cfg_bogoSetting2;
|
|
|
147 }
|
|
|
148 void CMyPreferences::OnChanged() {
|
|
|
149 //tell the host that our state has changed to enable/disable the apply button appropriately.
|
|
|
150 m_callback->on_state_changed();
|
|
|
151 }
|
|
|
152
|
|
|
153 class preferences_page_myimpl : public preferences_page_impl<CMyPreferences> {
|
|
|
154 // preferences_page_impl<> helper deals with instantiation of our dialog; inherits from preferences_page_v3.
|
|
|
155 public:
|
|
|
156 const char * get_name() {return "Sample Component";}
|
|
|
157 GUID get_guid() {
|
|
|
158 // This is our GUID. Replace with your own when reusing the code.
|
|
|
159 return GUID { 0x7702c93e, 0x24dc, 0x48ed, { 0x8d, 0xb1, 0x3f, 0x27, 0xb3, 0x8c, 0x7c, 0xc9 } };
|
|
|
160 }
|
|
|
161 GUID get_parent_guid() {return guid_tools;}
|
|
|
162 };
|
|
|
163
|
|
|
164 static preferences_page_factory_t<preferences_page_myimpl> g_preferences_page_myimpl_factory;
|
|
|
165 #endif // _WIN32
|
|
|
166
|