Repository navigation
Expand file tree
/
Copy pathgui_dialogs.cpp
More file actions
1384 lines (1322 loc) · 67.7 KB
/
Copy pathgui_dialogs.cpp
File metadata and controls
1384 lines (1322 loc) · 67.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
// Dialogs: native viewer implementation.
#include "gui_dialogs.hpp"
#include "gui_analysis_source.hpp"
#include "gui_frf_render.hpp"
#include "gui_settings_window.hpp"
#include "gui_controls.hpp"
#include "gui_ids.hpp"
#include "gui_processing.hpp"
#include "gui_render_data.hpp"
#include "gui_settings.hpp"
#include "gui_side_panel.hpp"
#include "gui_spectrum.hpp"
#include "gui_state.hpp"
#include "gui_text.hpp"
#include "gui_theme.hpp"
namespace gui {
NumericPromptState g_numeric_prompt;
RangePromptState g_range_prompt;
InfoPromptState g_info_prompt;
namespace {
struct SaveChangesPromptState {
HWND wnd = nullptr;
bool done = false;
int choice = IDCANCEL;
std::wstring title;
std::wstring message;
};
SaveChangesPromptState g_save_changes_prompt;
}
ExportPromptState g_export_prompt;
int prompt_button_width(HDC dc, const wchar_t* text, int min_width) {
SIZE sz{};
GetTextExtentPoint32W(dc, text, lstrlenW(text), &sz);
return std::max(min_width, static_cast<int>(sz.cx) + 28);
}
void draw_prompt_surface(HWND hwnd, HDC dc) {
RECT rc{};
GetClientRect(hwnd, &rc);
HBRUSH outer = CreateSolidBrush(g_theme->bg_main);
FillRect(dc, &rc, outer);
DeleteObject(outer);
RECT card = rc;
InflateRect(&card, -2, -2);
fill_rounded_rect(dc, card, g_theme->bg_panel, g_theme->separator, 12);
}
LRESULT CALLBACK InfoPromptProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_CREATE: {
HFONT font = g.ui_font ? g.ui_font : reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
HDC dc = GetDC(hwnd);
HGDIOBJ old_font = SelectObject(dc, font);
RECT client{};
GetClientRect(hwnd, &client);
const int client_w = std::max(380, static_cast<int>(client.right - client.left));
const int button_w = prompt_button_width(dc, g_info_prompt.ok_text.c_str(), 104);
const int button_x = std::max(16, (client_w - button_w) / 2);
const int button_y = 104;
g_info_prompt.ok_button = CreateWindowExW(
0, L"BUTTON", g_info_prompt.ok_text.c_str(),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_OWNERDRAW | BS_DEFPUSHBUTTON,
button_x, button_y, button_w, 28, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(IDOK)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
if (g_info_prompt.ok_button) {
SendMessageW(g_info_prompt.ok_button, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
SetFocus(g_info_prompt.ok_button);
}
SelectObject(dc, old_font);
ReleaseDC(hwnd, dc);
return 0;
}
case WM_COMMAND:
if (LOWORD(wp) == IDOK || LOWORD(wp) == IDCANCEL) {
DestroyWindow(hwnd);
return 0;
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_ERASEBKGND: {
HDC dc = reinterpret_cast<HDC>(wp);
draw_prompt_surface(hwnd, dc);
return 1;
}
case WM_PAINT: {
PAINTSTRUCT ps{};
HDC dc = BeginPaint(hwnd, &ps);
draw_prompt_surface(hwnd, dc);
RECT client{};
GetClientRect(hwnd, &client);
const int icon_x = 26;
const int icon_y = 42;
const int icon_size = 32;
HICON icon = LoadIconW(nullptr, g_info_prompt.error ? IDI_ERROR : IDI_INFORMATION);
if (icon) {
DrawIconEx(dc, icon_x, icon_y, icon, icon_size, icon_size, 0, nullptr, DI_NORMAL);
}
SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, g_theme->text_primary);
HFONT font = g.ui_font ? g.ui_font : reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
HGDIOBJ old_font = SelectObject(dc, font);
RECT text_rc = { icon_x + icon_size + 14, 38, client.right - 20, 96 };
DrawTextW(dc, g_info_prompt.message.c_str(), -1, &text_rc,
DT_LEFT | DT_TOP | DT_WORDBREAK | DT_NOPREFIX);
SelectObject(dc, old_font);
EndPaint(hwnd, &ps);
return 1;
}
case WM_CTLCOLORBTN: {
HDC dc = reinterpret_cast<HDC>(wp);
SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, g_theme->text_primary);
return reinterpret_cast<LRESULT>(g_panel_brush);
}
case WM_DRAWITEM: {
DRAWITEMSTRUCT* dis = reinterpret_cast<DRAWITEMSTRUCT*>(lp);
if (!dis || !dis->hwndItem) break;
if (GetDlgCtrlID(dis->hwndItem) == IDOK) {
wchar_t txt[64]{};
GetWindowTextW(dis->hwndItem, txt, 64);
draw_welcome_action_button(dis->hDC, dis->rcItem, txt,
(dis->itemState & ODS_SELECTED) != 0,
true, false);
return TRUE;
}
break;
}
case WM_DESTROY:
g_info_prompt.done = true;
g_info_prompt.wnd = nullptr;
g_info_prompt.ok_button = nullptr;
return 0;
}
return DefWindowProcW(hwnd, msg, wp, lp);
}
void show_styled_info_prompt(HWND owner, const wchar_t* title, const wchar_t* message, bool error) {
if (!owner || !IsWindow(owner)) owner = g.main;
static ATOM atom = 0;
if (!atom) {
WNDCLASSEXW wc{};
wc.cbSize = sizeof(wc);
wc.lpfnWndProc = InfoPromptProc;
wc.hInstance = reinterpret_cast<HINSTANCE>(GetWindowLongPtr(g.main, GWLP_HINSTANCE));
wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
wc.hbrBackground = nullptr;
wc.lpszClassName = L"LvmInfoPrompt";
atom = RegisterClassExW(&wc);
}
g_info_prompt.done = false;
g_info_prompt.error = error;
g_info_prompt.title = title ? title : L"";
g_info_prompt.message = message ? message : L"";
g_info_prompt.ok_text = (g_str == &kEn) ? L"OK" : L"ОК";
g_info_prompt.wnd = CreateWindowExW(
WS_EX_DLGMODALFRAME | WS_EX_TOOLWINDOW,
L"LvmInfoPrompt",
g_info_prompt.title.c_str(),
WS_CAPTION | WS_SYSMENU | WS_POPUP | WS_VISIBLE,
CW_USEDEFAULT, CW_USEDEFAULT, 420, 176,
owner, nullptr,
reinterpret_cast<HINSTANCE>(GetWindowLongPtr(g.main, GWLP_HINSTANCE)),
nullptr);
if (!g_info_prompt.wnd) return;
RECT mr{}, wr{};
GetWindowRect(owner, &mr);
GetWindowRect(g_info_prompt.wnd, &wr);
SetWindowPos(
g_info_prompt.wnd, HWND_TOP,
mr.left + ((mr.right - mr.left) - (wr.right - wr.left)) / 2,
mr.top + ((mr.bottom - mr.top) - (wr.bottom - wr.top)) / 2,
0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
EnableWindow(owner, FALSE);
if (g_info_prompt.ok_button) SetFocus(g_info_prompt.ok_button);
MSG msg;
while (!g_info_prompt.done && GetMessageW(&msg, nullptr, 0, 0) > 0) {
if (!IsDialogMessageW(g_info_prompt.wnd, &msg)) {
TranslateMessage(&msg);
DispatchMessageW(&msg);
}
}
EnableWindow(owner, TRUE);
SetForegroundWindow(owner);
}
namespace {
LRESULT CALLBACK SaveChangesPromptProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_CREATE: {
HFONT font=g.ui_font ? g.ui_font : reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
HDC dc=GetDC(hwnd); HGDIOBJ old_font=SelectObject(dc,font);
const wchar_t* save=g_str==&kEn ? L"Save" : L"Сохранить";
const wchar_t* discard=g_str==&kEn ? L"Don't save" : L"Не сохранять";
const wchar_t* cancel=g_str==&kEn ? L"Cancel" : L"Отмена";
const int save_w=prompt_button_width(dc,save,96);
const int discard_w=prompt_button_width(dc,discard,112);
const int cancel_w=prompt_button_width(dc,cancel,96);
const int gap=8, total=save_w+discard_w+cancel_w+2*gap;
const int x=std::max(16,(400-total)/2);
auto make=[&](int id,const wchar_t* text,int left,int width,bool primary) {
HWND button=CreateWindowExW(0,L"BUTTON",text,
WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_OWNERDRAW|(primary ? BS_DEFPUSHBUTTON : 0),
left,112,width,28,hwnd,reinterpret_cast<HMENU>(static_cast<INT_PTR>(id)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance,nullptr);
if (button) SendMessageW(button,WM_SETFONT,reinterpret_cast<WPARAM>(font),TRUE);
return button;
};
HWND first=make(IDYES,save,x,save_w,true);
make(IDNO,discard,x+save_w+gap,discard_w,false);
make(IDCANCEL,cancel,x+save_w+gap+discard_w+gap,cancel_w,false);
if (first) SetFocus(first);
SelectObject(dc,old_font); ReleaseDC(hwnd,dc);
return 0;
}
case WM_COMMAND:
if (LOWORD(wp)==IDYES || LOWORD(wp)==IDNO || LOWORD(wp)==IDCANCEL) {
g_save_changes_prompt.choice=LOWORD(wp); DestroyWindow(hwnd); return 0;
}
break;
case WM_CLOSE:
g_save_changes_prompt.choice=IDCANCEL; DestroyWindow(hwnd); return 0;
case WM_ERASEBKGND:
draw_prompt_surface(hwnd,reinterpret_cast<HDC>(wp)); return 1;
case WM_PAINT: {
PAINTSTRUCT ps{}; HDC dc=BeginPaint(hwnd,&ps); draw_prompt_surface(hwnd,dc);
HICON icon=LoadIconW(nullptr,IDI_WARNING);
if (icon) DrawIconEx(dc,26,42,icon,32,32,0,nullptr,DI_NORMAL);
SetBkMode(dc,TRANSPARENT); SetTextColor(dc,g_theme->text_primary);
HFONT font=g.ui_font ? g.ui_font : reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
HGDIOBJ old_font=SelectObject(dc,font);
RECT text{72,38,380,96};
DrawTextW(dc,g_save_changes_prompt.message.c_str(),-1,&text,DT_LEFT|DT_TOP|DT_WORDBREAK|DT_NOPREFIX);
SelectObject(dc,old_font); EndPaint(hwnd,&ps); return 0;
}
case WM_CTLCOLORBTN: {
HDC dc=reinterpret_cast<HDC>(wp); SetBkMode(dc,TRANSPARENT); SetTextColor(dc,g_theme->text_primary);
return reinterpret_cast<LRESULT>(g_panel_brush);
}
case WM_DRAWITEM: {
auto* dis=reinterpret_cast<DRAWITEMSTRUCT*>(lp);
if (!dis || !dis->hwndItem) break;
wchar_t text[64]{}; GetWindowTextW(dis->hwndItem,text,64);
draw_welcome_action_button(dis->hDC,dis->rcItem,text,(dis->itemState&ODS_SELECTED)!=0,
dis->CtlID==IDYES,dis->CtlID!=IDYES);
return TRUE;
}
case WM_DESTROY:
g_save_changes_prompt.done=true; g_save_changes_prompt.wnd=nullptr; return 0;
}
return DefWindowProcW(hwnd,msg,wp,lp);
}
}
int show_styled_save_changes_prompt(HWND owner, const wchar_t* title, const wchar_t* message) {
if (!owner || !IsWindow(owner)) owner=g.main;
static ATOM atom=0;
HINSTANCE instance=reinterpret_cast<HINSTANCE>(GetWindowLongPtrW(g.main,GWLP_HINSTANCE));
if (!atom) {
WNDCLASSEXW wc{}; wc.cbSize=sizeof(wc); wc.lpfnWndProc=SaveChangesPromptProc;
wc.hInstance=instance; wc.hCursor=LoadCursor(nullptr,IDC_ARROW); wc.lpszClassName=L"AMSaveChangesPrompt";
atom=RegisterClassExW(&wc);
}
g_save_changes_prompt.done=false; g_save_changes_prompt.choice=IDCANCEL;
g_save_changes_prompt.title=title ? title : L"";
g_save_changes_prompt.message=message ? message : L"";
g_save_changes_prompt.wnd=CreateWindowExW(WS_EX_DLGMODALFRAME|WS_EX_TOOLWINDOW,L"AMSaveChangesPrompt",
g_save_changes_prompt.title.c_str(),WS_CAPTION|WS_SYSMENU|WS_POPUP|WS_VISIBLE,
CW_USEDEFAULT,CW_USEDEFAULT,420,184,owner,nullptr,instance,nullptr);
if (!g_save_changes_prompt.wnd) return IDCANCEL;
RECT owner_rect{}, prompt_rect{}; GetWindowRect(owner,&owner_rect); GetWindowRect(g_save_changes_prompt.wnd,&prompt_rect);
SetWindowPos(g_save_changes_prompt.wnd,HWND_TOP,owner_rect.left+((owner_rect.right-owner_rect.left)-(prompt_rect.right-prompt_rect.left))/2,
owner_rect.top+((owner_rect.bottom-owner_rect.top)-(prompt_rect.bottom-prompt_rect.top))/2,0,0,SWP_NOSIZE|SWP_SHOWWINDOW);
EnableWindow(owner,FALSE);
MSG msg;
while (!g_save_changes_prompt.done && GetMessageW(&msg,nullptr,0,0)>0) {
if (!IsDialogMessageW(g_save_changes_prompt.wnd,&msg)) { TranslateMessage(&msg); DispatchMessageW(&msg); }
}
EnableWindow(owner,TRUE); SetForegroundWindow(owner);
return g_save_changes_prompt.choice;
}
double normalize_prompt_bound(double value) {
return (std::isfinite(value) && std::fabs(value) < 1e-12) ? 0.0 : value;
}
const wchar_t* speed_prompt_title_text() {
return (g_str == &kEn) ? L"Playback speed" : L"Скорость воспроизведения";
}
const wchar_t* speed_prompt_label_text() {
return (g_str == &kEn)
? L"Enter a playback speed multiplier:"
: L"Введите множитель скорости воспроизведения:";
}
const wchar_t* speed_prompt_apply_text() {
return (g_str == &kEn) ? L"Apply" : L"Применить";
}
const wchar_t* speed_prompt_cancel_text() {
return (g_str == &kEn) ? L"Cancel" : L"Отмена";
}
const wchar_t* speed_prompt_invalid_text() {
return (g_str == &kEn)
? L"Enter a positive number, for example 0.5, 1, or 2.75."
: L"Введите положительное число, например 0.5, 1 или 2.75.";
}
const wchar_t* guide_prompt_title_text() {
return g_str == &kEn ? L"Set line (exact)" : L"Задать линию (точно)";
}
const wchar_t* guide_prompt_label_text(bool vertical) {
if (g.mode == AnalysisMode::FRF) {
if (g_str == &kEn) return vertical ? L"Enter frequency, Hz:" : L"Enter linear FRF magnitude |H|:";
return vertical ? L"Введите частоту, Гц:" : L"Введите модуль АЧХ |H| в линейной шкале:";
}
if (g.mode == AnalysisMode::FFT) {
if (g_str == &kEn) return vertical ? L"Enter frequency, Hz:" : L"Enter amplitude:";
return vertical ? L"Введите частоту, Гц:" : L"Введите амплитуду:";
}
if (g_str == &kEn) {
return vertical ? L"Enter the exact X-axis value:" : L"Enter the exact Y-axis value:";
}
return vertical ? L"Введите точное значение по оси X:" : L"Введите точное значение по оси Y:";
}
const wchar_t* guide_prompt_apply_text() {
return (g_str == &kEn) ? L"Add" : L"Добавить";
}
const wchar_t* guide_prompt_cancel_text() {
return speed_prompt_cancel_text();
}
const wchar_t* guide_prompt_invalid_text() {
return (g_str == &kEn)
? L"Enter a finite number, for example -1, 0, or 2.75."
: L"Введите конечное число, например -1, 0 или 2.75.";
}
LRESULT CALLBACK NumericPromptProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_CREATE: {
HFONT font = g.ui_font ? g.ui_font : reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
HDC dc = GetDC(hwnd);
HGDIOBJ old_font = SelectObject(dc, font);
CreateWindowExW(0, L"STATIC", g_numeric_prompt.label.c_str(),
WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX,
18, 16, 340, 44, hwnd, nullptr,
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
g_numeric_prompt.edit = CreateWindowExW(
WS_EX_CLIENTEDGE, L"EDIT", format_edit_number(g_numeric_prompt.value).c_str(),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
18, 66, 340, 24, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(IDC_SPEED_PROMPT_EDIT)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
const int ok_w = prompt_button_width(dc, g_numeric_prompt.apply_text.c_str(), 110);
const int cancel_w = prompt_button_width(dc, g_numeric_prompt.cancel_text.c_str(), 110);
const int button_gap = 10;
const int total_w = ok_w + cancel_w + button_gap;
int button_x = std::max(16, (384 - total_w) / 2);
HWND ok = CreateWindowExW(
0, L"BUTTON", g_numeric_prompt.apply_text.c_str(),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_OWNERDRAW | BS_DEFPUSHBUTTON,
button_x, 104, ok_w, 28, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(IDC_SPEED_PROMPT_OK)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
HWND cancel = CreateWindowExW(
0, L"BUTTON", g_numeric_prompt.cancel_text.c_str(),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_OWNERDRAW,
button_x + ok_w + button_gap, 104, cancel_w, 28, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(IDC_SPEED_PROMPT_CANCEL)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
if (ok) SendMessageW(ok, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
if (cancel) SendMessageW(cancel, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
if (g_numeric_prompt.edit) SendMessageW(g_numeric_prompt.edit, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
SelectObject(dc, old_font);
ReleaseDC(hwnd, dc);
HWND label = GetWindow(hwnd, GW_CHILD);
if (label) SendMessageW(label, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
return 0;
}
case WM_COMMAND:
switch (LOWORD(wp)) {
case IDC_SPEED_PROMPT_OK: {
double value = 0.0;
wchar_t buf[128]{};
if (g_numeric_prompt.edit) GetWindowTextW(g_numeric_prompt.edit, buf, 128);
const bool valid = parse_wide_double_text(buf, value) &&
std::isfinite(value) &&
(!g_numeric_prompt.positive_only || value > 0.0);
if (!valid) {
MessageBoxW(hwnd, g_numeric_prompt.invalid_text.c_str(), g_numeric_prompt.title.c_str(), MB_OK | MB_ICONWARNING);
if (g_numeric_prompt.edit) SetFocus(g_numeric_prompt.edit);
return 0;
}
g_numeric_prompt.value = value;
g_numeric_prompt.accepted = true;
DestroyWindow(hwnd);
return 0;
}
case IDC_SPEED_PROMPT_CANCEL:
DestroyWindow(hwnd);
return 0;
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_ERASEBKGND: {
HDC dc = reinterpret_cast<HDC>(wp);
draw_prompt_surface(hwnd, dc);
return 1;
}
case WM_PAINT: {
PAINTSTRUCT ps{};
HDC dc = BeginPaint(hwnd, &ps);
draw_prompt_surface(hwnd, dc);
EndPaint(hwnd, &ps);
return 1;
}
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN: {
HDC dc = reinterpret_cast<HDC>(wp);
SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, g_theme->text_primary);
return reinterpret_cast<LRESULT>(g_panel_brush);
}
case WM_DRAWITEM: {
DRAWITEMSTRUCT* dis = reinterpret_cast<DRAWITEMSTRUCT*>(lp);
if (!dis || !dis->hwndItem) break;
const int ctl_id = GetDlgCtrlID(dis->hwndItem);
wchar_t txt[128]{};
GetWindowTextW(dis->hwndItem, txt, 128);
const bool pressed = (dis->itemState & ODS_SELECTED) != 0;
if (ctl_id == IDC_SPEED_PROMPT_OK) {
draw_welcome_action_button(dis->hDC, dis->rcItem, txt, pressed, true, false);
return TRUE;
}
if (ctl_id == IDC_SPEED_PROMPT_CANCEL) {
draw_welcome_action_button(dis->hDC, dis->rcItem, txt, pressed, false, false);
return TRUE;
}
break;
}
case WM_CTLCOLOREDIT: {
HDC dc = reinterpret_cast<HDC>(wp);
SetBkColor(dc, g_theme->bg_plot);
SetTextColor(dc, g_theme->text_primary);
return reinterpret_cast<LRESULT>(g_input_brush ? g_input_brush : g_panel_brush);
}
case WM_DESTROY:
g_numeric_prompt.done = true;
g_numeric_prompt.wnd = nullptr;
g_numeric_prompt.edit = nullptr;
return 0;
}
return DefWindowProcW(hwnd, msg, wp, lp);
}
LRESULT CALLBACK RangePromptProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_CREATE: {
HFONT font = g.ui_font ? g.ui_font : reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
HDC dc = GetDC(hwnd);
HGDIOBJ old_font = SelectObject(dc, font);
RECT client{};
GetClientRect(hwnd, &client);
const int client_w = std::max(0, static_cast<int>(client.right - client.left));
const int content_w = std::max(360, client_w - 36);
SIZE start_label_size{}, end_label_size{};
GetTextExtentPoint32W(dc, g_range_prompt.start_label.c_str(),
static_cast<int>(g_range_prompt.start_label.size()), &start_label_size);
GetTextExtentPoint32W(dc, g_range_prompt.end_label.c_str(),
static_cast<int>(g_range_prompt.end_label.size()), &end_label_size);
const int label_w = std::max(120, static_cast<int>(std::max(start_label_size.cx, end_label_size.cx)));
const int edit_x = 18 + label_w + 16;
const int edit_w = content_w - label_w - 16;
const int edit_h = 28;
const int start_y = 72;
const int end_y = start_y + edit_h + 12;
auto mkstatic = [&](const std::wstring& text, int x, int y, int w, int h, bool center = true) {
HWND ctl = CreateWindowExW(0, L"STATIC", text.c_str(),
WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX | (center ? SS_CENTERIMAGE : 0),
x, y, w, h, hwnd, nullptr,
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
if (ctl) SendMessageW(ctl, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
return ctl;
};
mkstatic(g_range_prompt.info_label, 18, 16, content_w, 42, false);
mkstatic(g_range_prompt.start_label, 18, start_y, label_w, edit_h);
g_range_prompt.start_edit = CreateWindowExW(
0, L"EDIT", format_edit_number(g_range_prompt.start_value).c_str(),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
edit_x, start_y, edit_w, edit_h, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(IDC_RANGE_PROMPT_START_EDIT)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
mkstatic(g_range_prompt.end_label, 18, end_y, label_w, edit_h);
g_range_prompt.end_edit = CreateWindowExW(
0, L"EDIT", format_edit_number(g_range_prompt.end_value).c_str(),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | ES_AUTOHSCROLL,
edit_x, end_y, edit_w, edit_h, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(IDC_RANGE_PROMPT_END_EDIT)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
const wchar_t* autofill_text = (g_str == &kEn) ? L"Min / Max" : L"Мин / Макс";
const int autofill_w = prompt_button_width(dc, autofill_text, 98);
const int apply_w = prompt_button_width(dc, g_range_prompt.apply_text.c_str(), 116);
const int cancel_w = prompt_button_width(dc, g_range_prompt.cancel_text.c_str(), 88);
const int button_gap = 10;
const int total_w = autofill_w + apply_w + cancel_w + button_gap * 2;
int button_x = std::max(16, (client_w - total_w) / 2);
if (button_x + total_w > client_w - 16) {
button_x = std::max(16, client_w - 16 - total_w);
}
HWND autofill = CreateWindowExW(
0, L"BUTTON", autofill_text,
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_OWNERDRAW,
button_x, 164, autofill_w, 28, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(IDC_RANGE_PROMPT_AUTOFILL)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
if(g_range_prompt.opening)ShowWindow(autofill,SW_HIDE);
HWND ok = CreateWindowExW(
0, L"BUTTON", g_range_prompt.apply_text.c_str(),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_OWNERDRAW | BS_DEFPUSHBUTTON,
button_x + autofill_w + button_gap, 164, apply_w, 28, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(IDC_RANGE_PROMPT_OK)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
HWND cancel = CreateWindowExW(
0, L"BUTTON", g_range_prompt.cancel_text.c_str(),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_OWNERDRAW,
button_x + autofill_w + button_gap + apply_w + button_gap, 164, cancel_w, 28, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(IDC_RANGE_PROMPT_CANCEL)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
if (autofill) SendMessageW(autofill, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
if (g_range_prompt.start_edit) SendMessageW(g_range_prompt.start_edit, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
if (g_range_prompt.end_edit) SendMessageW(g_range_prompt.end_edit, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
if (ok) SendMessageW(ok, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
if (cancel) SendMessageW(cancel, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
install_compact_themed_edit(g_range_prompt.start_edit);
install_compact_themed_edit(g_range_prompt.end_edit);
SelectObject(dc, old_font);
ReleaseDC(hwnd, dc);
return 0;
}
case WM_COMMAND:
switch (LOWORD(wp)) {
case IDC_RANGE_PROMPT_AUTOFILL: {
if(g_range_prompt.opening)return 0;
g_range_prompt.start_value = g_range_prompt.min_value;
g_range_prompt.end_value = g_range_prompt.max_value;
if (g_range_prompt.start_edit) {
SetWindowTextW(g_range_prompt.start_edit, format_edit_number(g_range_prompt.start_value).c_str());
SendMessageW(g_range_prompt.start_edit, EM_SETSEL, 0, -1);
SetFocus(g_range_prompt.start_edit);
}
if (g_range_prompt.end_edit) {
SetWindowTextW(g_range_prompt.end_edit, format_edit_number(g_range_prompt.end_value).c_str());
}
return 0;
}
case IDC_RANGE_PROMPT_OK: {
double start = 0.0, end = 0.0;
wchar_t buf_start[128]{}, buf_end[128]{};
if (g_range_prompt.start_edit) GetWindowTextW(g_range_prompt.start_edit, buf_start, 128);
if (g_range_prompt.end_edit) GetWindowTextW(g_range_prompt.end_edit, buf_end, 128);
const bool start_valid = parse_wide_double_text(buf_start, start) &&
std::isfinite(start) &&
start >= g_range_prompt.min_value &&
start < g_range_prompt.max_value;
if (!start_valid) {
MessageBoxW(hwnd, g_range_prompt.invalid_start_text.c_str(), g_range_prompt.title.c_str(), MB_OK | MB_ICONWARNING);
if (g_range_prompt.start_edit) SetFocus(g_range_prompt.start_edit);
return 0;
}
const bool end_valid = parse_wide_double_text(buf_end, end) &&
std::isfinite(end) &&
end > start &&
end <= g_range_prompt.max_value;
if (!end_valid) {
MessageBoxW(hwnd, g_range_prompt.invalid_end_text.c_str(), g_range_prompt.title.c_str(), MB_OK | MB_ICONWARNING);
if (g_range_prompt.end_edit) SetFocus(g_range_prompt.end_edit);
return 0;
}
g_range_prompt.start_value = start;
g_range_prompt.end_value = end;
g_range_prompt.accepted = true;
DestroyWindow(hwnd);
return 0;
}
case IDC_RANGE_PROMPT_CANCEL:
DestroyWindow(hwnd);
return 0;
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_ERASEBKGND: {
HDC dc = reinterpret_cast<HDC>(wp);
draw_prompt_surface(hwnd, dc);
return 1;
}
case WM_PAINT: {
PAINTSTRUCT ps{};
HDC dc = BeginPaint(hwnd, &ps);
draw_prompt_surface(hwnd, dc);
EndPaint(hwnd, &ps);
return 1;
}
case WM_CTLCOLORSTATIC:
case WM_CTLCOLORBTN: {
HDC dc = reinterpret_cast<HDC>(wp);
SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, g_theme->text_primary);
return reinterpret_cast<LRESULT>(g_panel_brush);
}
case WM_DRAWITEM: {
DRAWITEMSTRUCT* dis = reinterpret_cast<DRAWITEMSTRUCT*>(lp);
if (!dis || !dis->hwndItem) break;
const int ctl_id = GetDlgCtrlID(dis->hwndItem);
wchar_t txt[256]{};
GetWindowTextW(dis->hwndItem, txt, 256);
const bool pressed = (dis->itemState & ODS_SELECTED) != 0;
if (ctl_id == IDC_RANGE_PROMPT_OK || ctl_id == IDC_RANGE_PROMPT_AUTOFILL ||
ctl_id == IDC_RANGE_PROMPT_CANCEL) {
draw_themed_button(dis->hDC, dis->rcItem, txt, pressed, ctl_id == IDC_RANGE_PROMPT_OK, false);
return TRUE;
}
break;
}
case WM_CTLCOLOREDIT: {
HDC dc = reinterpret_cast<HDC>(wp);
SetBkColor(dc, g_theme->bg_plot);
SetTextColor(dc, g_theme->text_primary);
return reinterpret_cast<LRESULT>(g_input_brush ? g_input_brush : g_panel_brush);
}
case WM_DESTROY:
g_range_prompt.done = true;
g_range_prompt.wnd = nullptr;
g_range_prompt.start_edit = nullptr;
g_range_prompt.end_edit = nullptr;
return 0;
}
return DefWindowProcW(hwnd, msg, wp, lp);
}
template <typename T>
int combo_index_for_value(HWND combo, T value) {
if (!combo) return -1;
const int count = static_cast<int>(SendMessageW(combo, CB_GETCOUNT, 0, 0));
for (int i = 0; i < count; ++i) {
const auto item = static_cast<T>(SendMessageW(combo, CB_GETITEMDATA, i, 0));
if (item == value) return i;
}
return -1;
}
ExportFileFormat export_prompt_selected_format() {
if (!g_export_prompt.format_combo) return ExportFileFormat::Csv;
const int sel = static_cast<int>(SendMessageW(g_export_prompt.format_combo, CB_GETCURSEL, 0, 0));
if (sel == CB_ERR) return ExportFileFormat::Csv;
const int value = static_cast<int>(SendMessageW(g_export_prompt.format_combo, CB_GETITEMDATA, sel, 0));
switch (value) {
case static_cast<int>(ExportFileFormat::Txt): return ExportFileFormat::Txt;
case static_cast<int>(ExportFileFormat::Csv): return ExportFileFormat::Csv;
case static_cast<int>(ExportFileFormat::Lvm): return ExportFileFormat::Lvm;
}
return ExportFileFormat::Csv;
}
ExportSaveMode export_prompt_selected_save_mode() {
if (!g_export_prompt.save_mode_combo) return ExportSaveMode::OriginalData;
const int sel = static_cast<int>(SendMessageW(g_export_prompt.save_mode_combo, CB_GETCURSEL, 0, 0));
if (sel == CB_ERR) return ExportSaveMode::OriginalData;
const int value = static_cast<int>(SendMessageW(g_export_prompt.save_mode_combo, CB_GETITEMDATA, sel, 0));
switch (value) {
case static_cast<int>(ExportSaveMode::AppliedSettings): return ExportSaveMode::AppliedSettings;
case static_cast<int>(ExportSaveMode::Project): return ExportSaveMode::Project;
}
return ExportSaveMode::OriginalData;
}
ExportRangeMode export_prompt_selected_range() {
if (!g_export_prompt.range_combo) return ExportRangeMode::Visible;
const int sel = static_cast<int>(SendMessageW(g_export_prompt.range_combo, CB_GETCURSEL, 0, 0));
if (sel == CB_ERR) return ExportRangeMode::Visible;
const int value = static_cast<int>(SendMessageW(g_export_prompt.range_combo, CB_GETITEMDATA, sel, 0));
switch (value) {
case static_cast<int>(ExportRangeMode::Selected): return ExportRangeMode::Selected;
case static_cast<int>(ExportRangeMode::Visible): return ExportRangeMode::Visible;
case static_cast<int>(ExportRangeMode::Whole): return ExportRangeMode::Whole;
}
return ExportRangeMode::Visible;
}
void sync_export_prompt_state_from_controls() {
g_export_prompt.save_mode = export_prompt_selected_save_mode();
g_export_prompt.selected_format = export_prompt_selected_format();
g_export_prompt.selected_range = export_prompt_selected_range();
if (g_export_prompt.include_channel_names_check) {
g_export_prompt.include_channel_names =
SendMessageW(g_export_prompt.include_channel_names_check, BM_GETCHECK, 0, 0) == BST_CHECKED;
}
if (g_export_prompt.include_hidden_channels_check) {
g_export_prompt.include_hidden_channels =
SendMessageW(g_export_prompt.include_hidden_channels_check, BM_GETCHECK, 0, 0) == BST_CHECKED;
}
if (g_export_prompt.include_points_check) {
g_export_prompt.include_points =
SendMessageW(g_export_prompt.include_points_check, BM_GETCHECK, 0, 0) == BST_CHECKED;
}
if (g_export_prompt.include_markers_check) {
g_export_prompt.include_markers =
SendMessageW(g_export_prompt.include_markers_check, BM_GETCHECK, 0, 0) == BST_CHECKED;
}
if (g_export_prompt.include_guides_check) {
g_export_prompt.include_guides =
SendMessageW(g_export_prompt.include_guides_check, BM_GETCHECK, 0, 0) == BST_CHECKED;
}
if (g_export_prompt.include_formulas_check) {
g_export_prompt.include_formulas =
SendMessageW(g_export_prompt.include_formulas_check, BM_GETCHECK, 0, 0) == BST_CHECKED;
}
if (g_export_prompt.include_filter_check) {
g_export_prompt.include_filter_settings =
SendMessageW(g_export_prompt.include_filter_check, BM_GETCHECK, 0, 0) == BST_CHECKED;
}
if (g_export_prompt.include_graph_settings_check) {
g_export_prompt.include_graph_settings =
SendMessageW(g_export_prompt.include_graph_settings_check, BM_GETCHECK, 0, 0) == BST_CHECKED;
}
}
void update_export_prompt_controls() {
const bool applied = g_export_prompt.save_mode == ExportSaveMode::AppliedSettings;
const bool data_export = g_export_prompt.save_mode != ExportSaveMode::Project;
const std::initializer_list<HWND> settings_controls = {
g_export_prompt.include_channel_names_check, g_export_prompt.include_hidden_channels_check,
g_export_prompt.include_points_check, g_export_prompt.include_markers_check,
g_export_prompt.include_guides_check, g_export_prompt.include_formulas_check,
g_export_prompt.include_filter_check, g_export_prompt.include_graph_settings_check,
};
for (HWND control : settings_controls) if (control) EnableWindow(control, applied);
if (g_export_prompt.range_combo) EnableWindow(g_export_prompt.range_combo, data_export);
if (g_export_prompt.format_combo) EnableWindow(g_export_prompt.format_combo, data_export);
}
LRESULT CALLBACK ExportPromptProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) {
switch (msg) {
case WM_CREATE: {
HFONT font = g.ui_font ? g.ui_font : reinterpret_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT));
HDC dc = GetDC(hwnd);
HGDIOBJ old_font = SelectObject(dc, font);
RECT client{};
GetClientRect(hwnd, &client);
const int client_w = std::max(0, static_cast<int>(client.right - client.left));
const int content_w = std::max(680, client_w - 36);
const int section_h = 20;
const int option_h = 24;
const int col_gap = 16;
const int col_w = (content_w - col_gap) / 2;
const int label_w = 88;
const int combo_x = 18 + label_w;
const int combo_w = content_w - label_w - 6;
auto mkstatic = [&](const std::wstring& text, int x, int y, int w, int h) {
HWND ctl = CreateWindowExW(0, L"STATIC", text.c_str(),
WS_CHILD | WS_VISIBLE | SS_LEFT | SS_NOPREFIX,
x, y, w, h, hwnd, nullptr,
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
if (ctl) SendMessageW(ctl, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
return ctl;
};
auto mkcombo = [&](int x, int y, int w, int h, int id) {
HWND ctl = CreateWindowExW(
0, L"COMBOBOX", L"",
WS_CHILD | WS_VISIBLE | WS_TABSTOP | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED |
CBS_HASSTRINGS | CBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_BORDER,
x, y, w, h, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(id)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
if (ctl) SendMessageW(ctl, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
install_themed_combo(ctl);
return ctl;
};
auto add_combo_item = [&](HWND combo, const std::wstring& text, int value) {
int idx = static_cast<int>(SendMessageW(combo, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(text.c_str())));
if (idx >= 0) {
SendMessageW(combo, CB_SETITEMDATA, idx, static_cast<LPARAM>(value));
}
};
auto mkcheck = [&](const std::wstring& text, int x, int y, int w, int h, int id) {
HWND ctl = CreateWindowExW(
0, L"BUTTON", text.c_str(),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_OWNERDRAW | BS_MULTILINE,
x, y, w, h, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(id)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
if (ctl) SendMessageW(ctl, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
return ctl;
};
mkstatic(g_export_prompt.save_mode_label_text, 18, 18, label_w, section_h);
g_export_prompt.save_mode_combo = mkcombo(combo_x, 14, combo_w, 260, IDC_EXPORT_SAVE_MODE);
if (g_export_prompt.save_mode_combo) {
add_combo_item(g_export_prompt.save_mode_combo, g_export_prompt.save_project_text, static_cast<int>(ExportSaveMode::Project));
add_combo_item(g_export_prompt.save_mode_combo, g_export_prompt.save_applied_text, static_cast<int>(ExportSaveMode::AppliedSettings));
add_combo_item(g_export_prompt.save_mode_combo, g_export_prompt.save_original_text, static_cast<int>(ExportSaveMode::OriginalData));
SendMessageW(g_export_prompt.save_mode_combo, CB_SETMINVISIBLE, 4, 0);
SendMessageW(g_export_prompt.save_mode_combo, CB_SETDROPPEDWIDTH, std::max(300, combo_w), 0);
}
mkstatic(g_export_prompt.format_label_text, 18, 52, label_w, section_h);
g_export_prompt.format_combo = mkcombo(combo_x, 48, combo_w, 260, IDC_EXPORT_SCOPE_CURRENT);
if (g_export_prompt.format_combo) {
add_combo_item(g_export_prompt.format_combo, g_export_prompt.format_txt_text, static_cast<int>(ExportFileFormat::Txt));
add_combo_item(g_export_prompt.format_combo, g_export_prompt.format_csv_text, static_cast<int>(ExportFileFormat::Csv));
add_combo_item(g_export_prompt.format_combo, g_export_prompt.format_lvm_text, static_cast<int>(ExportFileFormat::Lvm));
SendMessageW(g_export_prompt.format_combo, CB_SETMINVISIBLE, 4, 0);
SendMessageW(g_export_prompt.format_combo, CB_SETDROPPEDWIDTH, std::max(220, combo_w), 0);
}
mkstatic(g_export_prompt.range_label_text, 18, 86, label_w, section_h);
g_export_prompt.range_combo = mkcombo(combo_x, 82, combo_w, 260, IDC_EXPORT_SCOPE_FRAGMENT);
if (g_export_prompt.range_combo) {
add_combo_item(g_export_prompt.range_combo, g_export_prompt.range_selected_text, static_cast<int>(ExportRangeMode::Selected));
add_combo_item(g_export_prompt.range_combo, g_export_prompt.range_visible_text, static_cast<int>(ExportRangeMode::Visible));
add_combo_item(g_export_prompt.range_combo, g_export_prompt.range_whole_text, static_cast<int>(ExportRangeMode::Whole));
SendMessageW(g_export_prompt.range_combo, CB_SETMINVISIBLE, 4, 0);
SendMessageW(g_export_prompt.range_combo, CB_SETDROPPEDWIDTH, std::max(220, combo_w), 0);
}
mkstatic(g_str == &kEn ? L"Additional data:" : L"Дополнительные данные:", 18, 122, content_w, section_h);
g_export_prompt.include_channel_names_check = mkcheck(g_export_prompt.channel_names_text, 18, 146, col_w, option_h, IDC_EXPORT_INCLUDE_CHANNEL_NAMES);
g_export_prompt.include_formulas_check = mkcheck(g_export_prompt.formulas_text, 18 + col_w + col_gap, 146, col_w, option_h, IDC_EXPORT_INCLUDE_FORMULAS);
g_export_prompt.include_points_check = mkcheck(g_export_prompt.points_text, 18, 174, col_w, option_h, IDC_EXPORT_INCLUDE_POINTS);
g_export_prompt.include_filter_check = mkcheck(g_export_prompt.filter_text, 18 + col_w + col_gap, 174, col_w, option_h, IDC_EXPORT_INCLUDE_FILTER);
g_export_prompt.include_markers_check = mkcheck(g_export_prompt.markers_text, 18, 202, col_w, option_h, IDC_EXPORT_INCLUDE_MARKERS);
g_export_prompt.include_graph_settings_check = mkcheck(g_export_prompt.graph_settings_text, 18 + col_w + col_gap, 202, col_w, option_h, IDC_EXPORT_INCLUDE_GRAPH_SETTINGS);
g_export_prompt.include_guides_check = mkcheck(g_export_prompt.guides_text, 18, 230, col_w, option_h, IDC_EXPORT_INCLUDE_GUIDES);
g_export_prompt.include_hidden_channels_check = mkcheck(g_export_prompt.hidden_channels_text, 18 + col_w + col_gap, 230, col_w, option_h, IDC_EXPORT_INCLUDE_HIDDEN_CHANNELS);
const int continue_w = prompt_button_width(dc, g_export_prompt.continue_text.c_str(), 130);
const int cancel_w = prompt_button_width(dc, g_export_prompt.cancel_text.c_str(), 100);
const int button_gap = 10;
const int total_w = continue_w + cancel_w + button_gap;
int button_x = std::max(16, (client_w - total_w) / 2);
if (button_x + total_w > client_w - 16) {
button_x = std::max(16, client_w - 16 - total_w);
}
const int button_y = 282;
HWND ok = CreateWindowExW(
0, L"BUTTON", g_export_prompt.continue_text.c_str(),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_OWNERDRAW | BS_DEFPUSHBUTTON,
button_x, button_y, continue_w, 28, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(IDOK)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
HWND cancel = CreateWindowExW(
0, L"BUTTON", g_export_prompt.cancel_text.c_str(),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | BS_OWNERDRAW,
button_x + continue_w + button_gap, button_y, cancel_w, 28, hwnd,
reinterpret_cast<HMENU>(static_cast<INT_PTR>(IDCANCEL)),
reinterpret_cast<LPCREATESTRUCT>(lp)->hInstance, nullptr);
auto set_check = [&](HWND ctl, bool on) {
set_toggle_checked(ctl, on);
};
set_check(g_export_prompt.include_channel_names_check, g_export_prompt.include_channel_names);
set_check(g_export_prompt.include_points_check, g_export_prompt.include_points);
set_check(g_export_prompt.include_markers_check, g_export_prompt.include_markers);
set_check(g_export_prompt.include_guides_check, g_export_prompt.include_guides);
set_check(g_export_prompt.include_formulas_check, g_export_prompt.include_formulas);
set_check(g_export_prompt.include_filter_check, g_export_prompt.include_filter_settings);
set_check(g_export_prompt.include_graph_settings_check, g_export_prompt.include_graph_settings);
set_check(g_export_prompt.include_hidden_channels_check, g_export_prompt.include_hidden_channels);
if (g_export_prompt.format_combo) {
const int fmt_index = combo_index_for_value(g_export_prompt.format_combo, g_export_prompt.selected_format);
SendMessageW(g_export_prompt.format_combo, CB_SETCURSEL, fmt_index >= 0 ? fmt_index : 1, 0);
}
if (g_export_prompt.save_mode_combo) {
const int mode_index = combo_index_for_value(g_export_prompt.save_mode_combo, g_export_prompt.save_mode);
SendMessageW(g_export_prompt.save_mode_combo, CB_SETCURSEL, mode_index >= 0 ? mode_index : 0, 0);
}
if (g_export_prompt.range_combo) {
const int range_index = combo_index_for_value(g_export_prompt.range_combo, g_export_prompt.selected_range);
SendMessageW(g_export_prompt.range_combo, CB_SETCURSEL, range_index >= 0 ? range_index : 1, 0);
}
if (ok) SendMessageW(ok, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
if (cancel) SendMessageW(cancel, WM_SETFONT, reinterpret_cast<WPARAM>(font), TRUE);
if (g_export_prompt.format_combo) {
SetFocus(g_export_prompt.format_combo);
}
sync_export_prompt_state_from_controls();
update_export_prompt_controls();
SelectObject(dc, old_font);
ReleaseDC(hwnd, dc);
return 0;
}
case WM_COMMAND:
switch (LOWORD(wp)) {
case IDC_EXPORT_SAVE_MODE:
if (HIWORD(wp) == CBN_DROPDOWN) {
expand_combo_dropdown(GetDlgItem(hwnd, LOWORD(wp)));
return 0;
}
if (HIWORD(wp) == CBN_SELCHANGE) {
sync_export_prompt_state_from_controls();
update_export_prompt_controls();
return 0;
}
break;
case IDC_EXPORT_SCOPE_CURRENT:
if (HIWORD(wp) == CBN_DROPDOWN) {
expand_combo_dropdown(GetDlgItem(hwnd, LOWORD(wp)));
return 0;
}
if (HIWORD(wp) == CBN_SELCHANGE) {
sync_export_prompt_state_from_controls();
return 0;
}
break;
case IDC_EXPORT_SCOPE_FRAGMENT:
if (HIWORD(wp) == CBN_DROPDOWN) {
expand_combo_dropdown(GetDlgItem(hwnd, LOWORD(wp)));
return 0;
}
if (HIWORD(wp) == CBN_SELCHANGE) {
sync_export_prompt_state_from_controls();
return 0;
}
break;
case IDC_EXPORT_INCLUDE_CHANNEL_NAMES:
case IDC_EXPORT_INCLUDE_POINTS:
case IDC_EXPORT_INCLUDE_MARKERS:
case IDC_EXPORT_INCLUDE_GUIDES:
case IDC_EXPORT_INCLUDE_FORMULAS:
case IDC_EXPORT_INCLUDE_FILTER:
case IDC_EXPORT_INCLUDE_GRAPH_SETTINGS:
case IDC_EXPORT_INCLUDE_HIDDEN_CHANNELS:
toggle_checked_state(GetDlgItem(hwnd, LOWORD(wp)));
sync_export_prompt_state_from_controls();
return 0;
case IDOK:
sync_export_prompt_state_from_controls();
if (g_export_prompt.save_mode != ExportSaveMode::Project &&
g_export_prompt.selected_format == ExportFileFormat::Lvm && (g.mode == AnalysisMode::FFT)) {
MessageBoxW(hwnd,
g_str == &kEn ? L"LVM export is available only in Time mode."
: L"Экспорт LVM доступен только в режиме Время.",
g_str->msg_error_title, MB_ICONINFORMATION);
if (g_export_prompt.format_combo) SetFocus(g_export_prompt.format_combo);
return 0;
}
g_export_prompt.accepted = true;
DestroyWindow(hwnd);
return 0;
case IDCANCEL:
DestroyWindow(hwnd);
return 0;
}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_ERASEBKGND: {
HDC dc = reinterpret_cast<HDC>(wp);
draw_prompt_surface(hwnd, dc);
return 1;
}
case WM_PAINT: {
PAINTSTRUCT ps{};
HDC dc = BeginPaint(hwnd, &ps);
draw_prompt_surface(hwnd, dc);
EndPaint(hwnd, &ps);
return 1;
}
case WM_MEASUREITEM: {
MEASUREITEMSTRUCT* mis = reinterpret_cast<MEASUREITEMSTRUCT*>(lp);
if (!mis) break;
if (mis->CtlType == ODT_COMBOBOX &&
(mis->CtlID == IDC_EXPORT_SAVE_MODE || mis->CtlID == IDC_EXPORT_SCOPE_CURRENT || mis->CtlID == IDC_EXPORT_SCOPE_FRAGMENT)) {
measure_settings_combo_item(mis);
return TRUE;
}