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 pathConfigBindings.cpp
More file actions
462 lines (358 loc) · 13.3 KB
/
Copy pathConfigBindings.cpp
File metadata and controls
462 lines (358 loc) · 13.3 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
#include <algorithm>
#include "ConfigBindings.h"
#include "ConfigCoverConfigs.h"
//#include "EngineThread.h"
//#include "engine.h"
#include "ConfigData.h"
namespace coverflow {
namespace {
class StringBinding : public IBinding, IFlow {
public:
StringBinding(pfc::string8& var, int actionflag, HWND hwnd, int controlId)
: var_(var), actionflag_(actionflag), hwnd_(hwnd), controlId_(controlId) {
}
void GetFVal(pfc::string8* dstVal) final {
const pfc::string8 res = pfc::string8(var_);
dstVal->set_string(var_);
}
int GetActionFlag(bool changefilter = false) const final { return !changefilter? actionflag_ : !HasChanged()? 0 : actionflag_; }
bool HasChanged() const final {
pfc::string8_fast text;
uGetDlgItemText(hwnd_, controlId_, text);
bool bres = false;
bres = !var_.equals(text.toString());
return bres;
}
void FlowToControl(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
uSetDlgItemText(hwnd_, controlId_, var_.get_ptr());
}
void FlowToVar(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
pfc::string8_fast text;
uGetDlgItemText(hwnd_, controlId_, text);
var_ = text.get_ptr();
}
const int& GetCtrlID() final { return controlId_; }
private:
pfc::string8& var_;
int actionflag_;
HWND hwnd_;
int controlId_;
};
class BoolBinding : public IBinding, IFlow {
public:
BoolBinding(bool& var, int actionflag, HWND hwnd, int controlId)
: var_(var), actionflag_(actionflag), hwnd_(hwnd), controlId_(controlId) {
}
bool HasChanged() const final {
bool const checked = IsDlgButtonChecked(hwnd_, controlId_) == BST_CHECKED;
return checked != var_;
}
int GetActionFlag(bool changefilter = false) const final {
return !changefilter ? actionflag_ : !HasChanged() ? 0 : actionflag_;
}
void FlowToControl(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
CheckDlgButton(hwnd_, controlId_, var_ ? BST_CHECKED : BST_UNCHECKED);
}
void FlowToVar(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
var_ = IsDlgButtonChecked(hwnd_, controlId_) == BST_CHECKED;
}
const int& GetCtrlID() final { return controlId_; }
void GetFVal(bool* dstval) final { *dstval = &var_; }
private:
bool& var_;
int actionflag_;
HWND hwnd_;
int controlId_;
};
class IntBinding : public IBinding, IFlow {
public:
IntBinding(int& var, int actionflag, HWND hwnd, int controlId)
: var_(var), actionflag_(actionflag), hwnd_(hwnd), controlId_(controlId) {
}
bool HasChanged() const final {
int i;
i = uGetDlgItemInt(hwnd_, controlId_, nullptr, true);
return (var_ != i);
}
int GetActionFlag(bool changefilter) const final {
return !changefilter ? actionflag_ : !HasChanged() ? 0 : actionflag_;
}
void FlowToControl(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
uSetDlgItemInt(hwnd_, controlId_, var_, true);
}
void FlowToVar(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
var_ = uGetDlgItemInt(hwnd_, controlId_, nullptr, true);
}
const int& GetCtrlID() final { return controlId_; }
void GetFVal(int* dstval) final { *dstval = var_; }
private:
int& var_;
int actionflag_;
HWND hwnd_;
int controlId_;
};
class DoubleBinding : public IBinding, IFlow {
public:
DoubleBinding(double& var, int actionflag, HWND hwnd, int controlId)
: var_(var), actionflag_(actionflag), hwnd_(hwnd), controlId_(controlId) {
}
const int& GetCtrlID() final { return controlId_; }
bool HasChanged() const final {
double i;
pfc::string8 txtval;
uGetDlgItemText(hwnd_, controlId_, txtval);
i = atof(txtval.c_str());
return (var_ != i);
}
int GetActionFlag(bool changefilter) const final {
return !changefilter ? actionflag_ : !HasChanged() ? 0 : actionflag_;
}
void FlowToControl(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
uSetDlgItemText(hwnd_, controlId_, std::to_string(var_).c_str());
}
void FlowToVar(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
var_ = atof(uGetDlgItemText(hwnd_, controlId_).c_str());
}
void GetFVal(double* dstval) final { *dstval = var_; }
private:
double& var_;
int actionflag_;
HWND hwnd_;
int controlId_;
};
class CoverConfigBinding : public IBinding, IFlow {
public:
CoverConfigBinding(cfg_coverConfigs& var, int actionflag, HWND hwnd, int controlId,
pfc::string8 selected)
: var_(var), actionflag_(actionflag), hwnd_(hwnd), controlId_(controlId), selected_(selected) {
}
void GetFVal(CoverConfigMap* dstVal) final { dstVal->insert(var_.begin(), var_.end()); }
bool HasChanged() const final {
pfc::string8_fast text;
uGetDlgItemText(hwnd_, controlId_, text);
pfc::string txtSelected = uGetDlgItemText(hwnd_, IDC_SAVED_SELECT);
bool bres;
if (txtSelected.get_length()) {
const CoverConfig& config = var_.at(txtSelected.c_str());
std::string vartext = std::string(config.script.c_str());
bres = uStringCompare(windows_lineendings(vartext).c_str(), text.get_ptr()) != 0;
} else {
//getting weird on_get_state() calls from framework
bres = uStringCompare(txtSelected.get_ptr(), text.get_ptr()) != 0;
}
return bres;
}
int GetActionFlag(bool changefilter) const final {
return !changefilter ? actionflag_ : !HasChanged() ? 0 : actionflag_;
}
void FlowToControl(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
//fix depricated configs
auto find_it = configData->CoverConfigs.find(selected_.c_str());
if (!selected_.get_length() || find_it == configData->CoverConfigs.end()) {
selected_ = defaultCoverConfig;
}
const CoverConfig& config = var_.at(selected_.c_str());
uSetDlgItemText(hwnd_, controlId_, windows_lineendings(config.script).c_str());
}
void FlowToVar(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
pfc::string8 txtSelected;
uGetDlgItemText(hwnd_, IDC_SAVED_SELECT, txtSelected);
pfc::string8_fast text;
uGetDlgItemText(hwnd_, controlId_, text);
if (txtSelected.get_length()) {
const CoverConfig& config = var_.at(txtSelected.c_str());
std::string txt = config.script;
txt.assign(text.get_ptr());
var_.at(txtSelected.c_str()).script = linux_lineendings(text.c_str());
selected_ = txtSelected;
}
}
const int& GetCtrlID() { return controlId_; }
private:
cfg_coverConfigs& var_;
int actionflag_;
HWND hwnd_;
int controlId_;
pfc::string8 selected_;
};
class FontBinding : public IBinding, IFlow {
public:
FontBinding(LOGFONT& var, int actionflag, HWND hwnd, int controlId)
: var_(var), actionflag_(actionflag), hwnd_(hwnd), controlId_(controlId) {
}
void GetFVal(LOGFONT* dstVal) final { dstVal = &var_; }
bool HasChanged() const final {
pfc::string8 text;
pfc::string8 tmpstrBase64;
uGetDlgItemText(hwnd_, controlId_, tmpstrBase64);
LOGFONT lfctrl;
//debug
//std::string restbuf(sizeof(lfctrl), '\0');
//pfc::string8 restorebuf;
//restorebuf.set_string(restbuf.c_str(), restbuf.length());
pfc::base64_decode(tmpstrBase64.c_str(), &lfctrl);
int res = memcmp(&var_, &lfctrl, sizeof(lfctrl));
return (res != 0);
}
int GetActionFlag(bool changefilter) const final {
return !changefilter ? actionflag_ : !HasChanged() ? 0 : actionflag_;
}
void FlowToControl(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
std::ostringstream o_txt_stream;
//debug
//std::string buf(sizeof(var_), '\0');
//pfc::string8 pfcbuf = pfc::string8(buf.c_str());
o_txt_stream.write((char*)&var_, sizeof(var_));
pfc::string8 strBase64;
pfc::base64_encode(strBase64, (void*)o_txt_stream.str().c_str(), sizeof(var_));
uSetDlgItemText(hwnd_, controlId_, strBase64);
}
void FlowToVar(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
pfc::string8 tmpstr, tmpstrBase64;
uGetDlgItemText(hwnd_, controlId_, tmpstrBase64);
LOGFONT restoreFont;
restoreFont = def_cfgTitleFont();
//Debug
//std::string restbuf(sizeof(restoreFont), '\0');
//pfc::string8 restorebuf;
//restorebuf.set_string(restbuf.c_str(), restbuf.length());
pfc::base64_decode(tmpstrBase64.c_str(), &restoreFont);
var_ = restoreFont;
}
const int& GetCtrlID() final { return controlId_; }
private:
LOGFONT& var_;
int actionflag_;
HWND hwnd_;
int controlId_;
};
class TsizeBinding : public IBinding, IFlow {
public:
TsizeBinding(t_size& var, int actionflag, HWND hwnd, int controlId)
: var_(var), actionflag_(actionflag), hwnd_(hwnd), controlId_(controlId) {
}
void GetFVal(t_size* dstVal) final {
memcpy(dstVal, (const void*)var_, sizeof(var_));
}
bool HasChanged() const final {
t_size tsval;
if (uGetDlgItemText(hwnd_, controlId_) == "") {
tsval = 0;
} else
tsval = std::stoull(uGetDlgItemText(hwnd_, controlId_).c_str(), nullptr, 0);
return (var_ != tsval);
}
int GetActionFlag(bool changefilter) const final {
return !changefilter ? actionflag_ : !HasChanged() ? 0 : actionflag_;
}
void FlowToControl(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
uSetDlgItemText(hwnd_, controlId_, std::to_string(var_).data());
}
void FlowToVar(HWND wndCtrlParent = nullptr) final {
if (wndCtrlParent != nullptr && hwnd_ != wndCtrlParent)
return;
t_size tsval = std::stoull(uGetDlgItemText(hwnd_, controlId_).c_str(), nullptr, 0);
var_ = tsval;
}
const int& GetCtrlID() final { return controlId_; }
private:
t_size& var_;
int actionflag_;
HWND hwnd_;
int controlId_;
};
} // namespace
Binding::Binding(int& var, int actionflag, HWND hwnd, int controlId)
: binding_(std::make_unique<IntBinding>(var, actionflag, hwnd, controlId)) {
flowval_ = (IFlow*)(IntBinding*)(binding_.get());
}
Binding::Binding(bool& var, int actionflag, HWND hwnd, int controlId)
: binding_(std::make_unique<BoolBinding>(var, actionflag, hwnd, controlId)) {
flowval_ = (IFlow*)(BoolBinding*)(binding_.get());
}
Binding::Binding(pfc::string8& var, int actionflag, HWND hwnd, int controlId)
: binding_(std::make_unique<StringBinding>(var, actionflag, hwnd, controlId)) {
flowval_ = (IFlow*)(StringBinding*)(binding_.get());
}
Binding::Binding(double& var, int actionflag, HWND hwnd, int controlId)
: binding_(std::make_unique<DoubleBinding>(var, actionflag, hwnd, controlId)) {
flowval_ = (IFlow*)(DoubleBinding*)(binding_.get());
}
Binding::Binding(t_size& var, int actionflag, HWND hwnd, int controlId)
: binding_(std::make_unique<TsizeBinding>(var, actionflag, hwnd, controlId)) {
flowval_ = (IFlow*)(TsizeBinding*)(binding_.get());
}
Binding::Binding(LOGFONT& var, int actionflag, HWND hwnd, int controlId)
: binding_(std::make_unique<FontBinding>(var, actionflag, hwnd, controlId)) {
flowval_ = (IFlow*)(FontBinding*)(binding_.get());
}
Binding::Binding(cfg_coverConfigs& var, int actionflag, HWND hwnd, int controlId, pfc::string8 selected)
: binding_(std::make_unique<CoverConfigBinding>(var, actionflag, hwnd, controlId, selected)) {
flowval_ = (IFlow*)(CoverConfigBinding*)(binding_.get());
}
Binding::Binding(Binding&&) = default;
Binding& Binding::operator=(Binding&&) = default;
Binding::~Binding() = default;
bool Binding::HasChanged() const { return binding_->HasChanged(); }
int Binding::GetActionFlag(bool changefilter) const { return binding_->GetActionFlag(changefilter); }
void Binding::FlowToControl(HWND wndCtrlParent) {
binding_->FlowToControl(wndCtrlParent);
}
void Binding::FlowToVar(HWND wndCtrlParent) {
binding_->FlowToVar(wndCtrlParent);
}
bool BindingCollection::HasChanged() const {
return std::any_of(std::begin(bindings_), std::end(bindings_),
[](auto const& binding) { return binding.HasChanged(); });
}
//get changed status and actions to trigger
std::pair<int, bool> BindingCollection::HasChangedExt() const {
bool bflag0 = std::any_of(std::begin(bindings_), std::end(bindings_), [](auto const& binding) {
return binding.GetActionFlag(true) == (1 << 0);
});
bool bflag1 = std::any_of(std::begin(bindings_), std::end(bindings_), [](auto const& binding) {
return binding.GetActionFlag(true) == (1 << 1);
});
int actionflag = bflag0 ? (1 << 0) : 0;
actionflag = actionflag | (bflag1? 1 << 1 : actionflag);
//return checked flags change status and general change status
std::pair<int, bool> pres = { actionflag, HasChanged() };
return pres;
}
void BindingCollection::FlowToControl(HWND wndCtrlParent) {
for (auto&& binding : bindings_) {
binding.FlowToControl(wndCtrlParent);
}
}
void BindingCollection::FlowToVar(HWND wndCtrlParent) {
for (auto&& binding : bindings_) {
binding.FlowToVar(wndCtrlParent);
}
}
} // namespace coverflow