-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavoraiser.dialogs.pas
More file actions
1422 lines (1211 loc) · 49 KB
/
avoraiser.dialogs.pas
File metadata and controls
1422 lines (1211 loc) · 49 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
(*
Avoraiser UI Framework - High-Performance WinAPI UI for Avocado
Avoraiser is a framework for creating modern user interfaces for the Polish programming language Avocado.
Copyright (c) 2025-2026 Dymitr Wygowski (Programista Art)
Project Created: 23.12.2025
Author: Dymitr Wygowski (Programista Art)
Contact: programista.art@gmail.com
GitHub: https://github.com/Programista-Art/Avoraiser
Version: 1.0
License: Dual-Licensed: Avoraiser Community / Commercial
See LICENSE.md for terms and conditions.
Module: avoraiser.dialogs
Description:
*)
unit avoraiser.dialogs;
{$mode ObjFPC}{$H+}
{$codepage utf8}
interface
uses
Windows, avoraiser.gdi, avoraiser.button, avoraiser.edit,CommDlg;
type
TDialogLanguage = (LangPL, LangEN);
// Jakie przyciski mają się pojawić?
type
TDialogButtons = (
DlgBtnOK, // OK
DlgBtnOKCancel, // OK, Anuluj
DlgBtnYesNo, // Tak, Nie
DlgBtnYesNoCancel, // Tak, Nie, Anuluj
DlgBtnAbortRetryIgnore, // Przerwij, Ponów, Ignoruj
DlgBtnRetryCancel // Ponów, Anuluj
);
// Co kliknął użytkownik? Wynik działania funkcji
type
TDialogResult = (
DlgResultNone,
DlgResultOK,
DlgResultCancel,
DlgResultYes,
DlgResultNo,
DlgResultAbort,
DlgResultRetry,
DlgResultIgnore
);
// Wyświetla proste okno z informacją
procedure show_message(Owner: HWND; const Title, Text: UnicodeString);
// Wyświetla pytanie Tak/Nie. Zwraca True, jeśli użytkownik kliknął "Tak"
function ask_question(Owner: HWND; const Title, Text: UnicodeString): Boolean;
// Wyświetla ostrzeżenie z ikoną wykrzyknika
procedure show_warning(Owner: HWND; const Title, Text: UnicodeString);
// Główna funkcja tworząca customowy dialog zwraca wynik
function show_custom_dialog(Owner: HWND; const Title, Description: UnicodeString; BgColor, TextColor, AccentColor: DWORD; Buttons: TDialogButtons = DlgBtnOK): TDialogResult;
//Zmiana jezyka przyciskow
procedure set_dialog_language(Lang: TDialogLanguage);
// Wyświetla okno z prośbą o wpisanie tekstu.
// Zwraca True, jeśli użytkownik zatwierdził (OK), a wpisany tekst trafia do zmiennej Value.
function input_box(Owner: HWND; const Title, Prompt: UnicodeString; var Value: UnicodeString; BgColor, TextColor, AccentColor, EditBgColor, EditTextColor: DWORD): Boolean;
// Wyświetla okno do wpisywania hasła (znaki są maskowane).
function password_box(Owner: HWND; const Title, Prompt: UnicodeString; var Value: UnicodeString; BgColor, TextColor, AccentColor, EditBgColor, EditTextColor: DWORD): Boolean;
// Wyświetla powiadomienie typu Toast. Nie blokuje aplikacji i znika automatycznie.
procedure show_toast(Owner: HWND; const MessageText: UnicodeString; BgColor, TextColor: DWORD; Duration: Integer = 3000; Width: Integer = 250; Height: Integer = 45);
// Wyświetla pionowe menu z dużymi przyciskami. Zwraca indeks klikniętego przycisku (0, 1, 2...) lub -1 jeśli anulowano.
function show_action_sheet(Owner: HWND; const Title: UnicodeString; const Options, IconPaths: array of UnicodeString; BgColor, TextColor, AccentColor: DWORD): Integer;
function show_progress_dialog(Owner: HWND; const Title, Status: UnicodeString; BgColor, TextColor, AccentColor: DWORD): HWND;
procedure update_progress(HDlg: HWND; Position: Integer; const NewStatus: UnicodeString);
function get_file_name_from_user(h_wnd: HWND; is_save: Boolean; const filter: UnicodeString = 'Wszystkie pliki (*.*)|*.*'; const default_ext: UnicodeString = ''): UnicodeString;
implementation
// Stałe ID dla przycisków
const
CLEARTYPE_QUALITY = 5;
ID_BTN_OK = 100;
ID_BTN_CANCEL = 101;
ID_BTN_YES = 102;
ID_BTN_NO = 103;
ID_BTN_CLOSE_X = 104;
ID_BTN_ABORT = 105;
ID_BTN_RETRY = 106;
ID_BTN_IGNORE = 107;
TOAST_TIMER_ID = 1001;
var
DialogClassRegistered: Boolean = False;
PaletteClassRegistered: Boolean = False;
// Zmienna globalna w module do przekazania wyniku z procedury okna do funkcji głównej
CurrentDialogResult: TDialogResult;
CurrentDialogLang: TDialogLanguage = LangPL;
InputDialogClassRegistered: Boolean = False;
CurrentInputResult: Boolean;
CurrentInputText: UnicodeString;
ToastClassRegistered: Boolean = False;
//CurrentPaletteResult: UnicodeString;
//OriginalCommands: array of UnicodeString; // Przechowuje pełną listę poleceń
function progress_proc(HWnd: HWND; Msg: UINT; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall;
var
PS: TPaintStruct;
DC: HDC;
R, BarR, FillR: TRect;
Title, Status: PWideChar;
HFontMain, HOldFont: HFONT;
BgBrush, BarBgBrush, AccentBrush: HBRUSH;
BgCol, TxCol, AxCol: DWORD;
ProgressPos: Integer;
MemDC: HDC;
MemBmp, OldMemBmp: HBITMAP;
begin
case Msg of
WM_ERASEBKGND:
begin
Result := 1;
Exit;
end;
WM_PAINT:
begin
DC := BeginPaint(HWnd, PS);
GetClientRect(HWnd, R);
// DOUBLE BUFFERING
MemDC := CreateCompatibleDC(DC);
MemBmp := CreateCompatibleBitmap(DC, R.Right, R.Bottom);
OldMemBmp := SelectObject(MemDC, MemBmp);
try
// Pobieranie danych (zmienne PascalCase)
BgCol := DWORD(GetPropW(HWnd, 'BgColor'));
TxCol := DWORD(GetPropW(HWnd, 'TextColor'));
AxCol := DWORD(GetPropW(HWnd, 'AccentColor'));
Title := PWideChar(GetPropW(HWnd, 'TitleText'));
Status := PWideChar(GetPropW(HWnd, 'StatusText'));
ProgressPos := Integer(GetPropW(HWnd, 'ProgressPos'));
// Rysowanie tła na MemDC
BgBrush := CreateSolidBrush(BgCol);
FillRect(MemDC, R, BgBrush);
DeleteObject(BgBrush);
// Czcionka Segoe UI (Twoje parametry)
HFontMain := CreateFontW(-17, 0, 0, 0, FW_NORMAL, 0, 0, 0, EASTEUROPE_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY,
DEFAULT_PITCH, 'Segoe UI');
HOldFont := SelectObject(MemDC, HFontMain);
SetBkMode(MemDC, TRANSPARENT);
SetTextColor(MemDC, TxCol);
//Rysowanie Tytułu
BarR := R;
BarR.Top := 20;
BarR.Left := 25;
DrawTextW(MemDC, Title, -1, @BarR, DT_LEFT or DT_SINGLELINE);
// Pasek postępu (Flat Design)
BarR.Left := 25;
BarR.Right := R.Right - 25;
BarR.Top := 55;
BarR.Bottom := 75;
BarBgBrush := CreateSolidBrush(BgCol + $0A0A0A);
FillRect(MemDC, BarR, BarBgBrush);
DeleteObject(BarBgBrush);
FillR := BarR;
FillR.Right := BarR.Left + ((BarR.Right - BarR.Left) * ProgressPos div 100);
AccentBrush := CreateSolidBrush(AxCol);
FillRect(MemDC, FillR, AccentBrush);
DeleteObject(AccentBrush);
// Rysowanie Statusu
BarR.Top := 85;
BarR.Bottom := R.Bottom;
DrawTextW(MemDC, Status, -1, @BarR, DT_LEFT or DT_SINGLELINE);
SelectObject(MemDC, HOldFont);
DeleteObject(HFontMain);
// KOPIOWANIE BUFORA NA EKRAN
BitBlt(DC, 0, 0, R.Right, R.Bottom, MemDC, 0, 0, SRCCOPY);
finally
// Sprzątanie pamięci
SelectObject(MemDC, OldMemBmp);
DeleteObject(MemBmp);
DeleteDC(MemDC);
EndPaint(HWnd, PS);
end;
Exit(0);
end;
WM_NCDESTROY:
begin
RemovePropW(HWnd, 'TitleText');
RemovePropW(HWnd, 'StatusText');
RemovePropW(HWnd, 'BgColor');
RemovePropW(HWnd, 'TextColor');
RemovePropW(HWnd, 'AccentColor');
RemovePropW(HWnd, 'ProgressPos');
end;
end;
Result := DefWindowProcW(HWnd, Msg, WParam, LParam);
end;
function action_sheet_proc(hWnd: HWND; Msg: UINT; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall;
var
ps: TPaintStruct;
DC: HDC;
R, TitleRect: TRect;
BgColor, TextColor: DWORD;
TitleStr: UnicodeString;
BufferState: TDoubleBufferState;
myhFont: HFONT;
hOldFont: HGDIOBJ;
PropPtr: Pointer;
hOwner: HWND;
begin
case Msg of
WM_PAINT:
begin
DC := BeginPaint(hWnd, ps);
GetClientRect(hWnd, R);
BufferState := begin_double_buffer(DC, R);
try
BgColor := DWORD(GetWindowLongPtrW(hWnd, 0));
TextColor := DWORD(GetWindowLongPtrW(hWnd, 8));
PropPtr := Pointer(GetPropW(hWnd, 'SheetTitlePtr'));
if PropPtr <> nil then TitleStr := UnicodeString(PropPtr) else TitleStr := '';
draw_fill_rectangle(hWnd, 0, 0, R.Right, R.Bottom, BgColor, BufferState.MemDC);
myhFont := CreateFontW(-18, 0, 0, 0, FW_BOLD, 0, 0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY, DEFAULT_PITCH, 'Segoe UI');
set_text_color(BufferState.MemDC, TextColor);
set_bk_mode(BufferState.MemDC, True);
hOldFont := SelectObject(BufferState.MemDC, myhFont);
TitleRect := R;
TitleRect.Top := 20;
draw_text_advanced(BufferState.MemDC, TitleRect, TitleStr, DT_CENTER or DT_TOP or DT_SINGLELINE);
SelectObject(BufferState.MemDC, hOldFont);
DeleteObject(myhFont);
finally
end_double_buffer(BufferState);
EndPaint(hWnd, ps);
end;
Result := 0; Exit;
end;
WM_COMMAND:
begin
// Jeśli kliknięto jakikolwiek przycisk (ID >= 1000)
if (LOWORD(WParam) >= 1000) and (LOWORD(WParam) < 2000) then
begin
SetWindowLongPtrW(hWnd, 16, LOWORD(WParam)); // Zapisujemy kliknięte ID
PostMessageW(hWnd, WM_CLOSE, 0, 0);
end;
if LOWORD(WParam) = ID_BTN_CLOSE_X then PostMessageW(hWnd, WM_CLOSE, 0, 0);
Result := 0; Exit;
end;
WM_CLOSE:
begin
hOwner := GetWindow(hWnd, GW_OWNER);
if hOwner <> 0 then EnableWindow(hOwner, True);
DestroyWindow(hWnd);
PostMessageW(0, WM_NULL, 0, 0);
Result := 0; Exit;
end;
end;
Result := DefWindowProcW(hWnd, Msg, WParam, LParam);
end;
function toast_proc(hWnd: HWND; Msg: UINT; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall;
var
ps: TPaintStruct;
DC: HDC;
R: TRect;
BgColor, TextColor: DWORD;
MsgStr: UnicodeString;
BufferState: TDoubleBufferState;
myhFont: HFONT;
hOldFont: HGDIOBJ;
begin
case Msg of
// 1. ZEGAR: Czas minął, niszczymy okno!
WM_TIMER:
begin
if WParam = TOAST_TIMER_ID then
begin
KillTimer(hWnd, TOAST_TIMER_ID); // Zatrzymujemy zegar
DestroyWindow(hWnd); // Usuwamy dymek
end;
Result := 0;
Exit;
end;
// 2. KLIKNIĘCIE: Jeśli użytkownik kliknie w Toast, też go zamykamy (wcześniej)
WM_LBUTTONDOWN:
begin
KillTimer(hWnd, TOAST_TIMER_ID);
DestroyWindow(hWnd);
Result := 0;
Exit;
end;
WM_PAINT:
begin
DC := BeginPaint(hWnd, ps);
GetClientRect(hWnd, R);
BufferState := begin_double_buffer(DC, R);
try
BgColor := DWORD(GetPropW(hWnd, 'ToastBg'));
TextColor := DWORD(GetPropW(hWnd, 'ToastTxt'));
MsgStr := UnicodeString(Pointer(GetPropW(hWnd, 'ToastMsgPtr')));
// Malujemy tło powiadomienia
draw_fill_rectangle(hWnd, 0, 0, R.Right, R.Bottom, BgColor, BufferState.MemDC);
// Ustawiamy ładną czcionkę (mniejszą niż w oknach dialogowych)
myhFont := CreateFontW(-14, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY, DEFAULT_PITCH, 'Segoe UI');
set_text_color(BufferState.MemDC, TextColor);
set_bk_mode(BufferState.MemDC, True);
hOldFont := SelectObject(BufferState.MemDC, myhFont);
// Tekst wyśrodkowany idealnie w pionie i poziomie
draw_text_advanced(BufferState.MemDC, R, MsgStr, DT_CENTER or DT_VCENTER or DT_SINGLELINE);
SelectObject(BufferState.MemDC, hOldFont);
DeleteObject(myhFont);
finally
end_double_buffer(BufferState);
EndPaint(hWnd, ps);
end;
Result := 0;
Exit;
end;
WM_ERASEBKGND:
begin
Result := 1;
Exit;
end;
WM_NCDESTROY:
begin
RemovePropW(hWnd, 'ToastBg');
RemovePropW(hWnd, 'ToastTxt');
RemovePropW(hWnd, 'ToastMsgPtr');
end;
end;
Result := DefWindowProcW(hWnd, Msg, WParam, LParam);
end;
function input_dialog_proc(hWnd: HWND; Msg: UINT; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall;
var
ps: TPaintStruct;
DC: HDC;
R, TitleRect, PromptRect: TRect;
BgColor, TextColor: DWORD;
TitleStr, PromptStr: UnicodeString;
BufferState: TDoubleBufferState;
hEdit: HWND;
TextLen: Integer;
Buffer: array of WideChar;
hTitleFont,hDescFont: HFONT;
hOldFont: HGDIOBJ;
hOwner: HWND;
hdcEdit: HDC;
TxtCol: DWORD;
BgCol: DWORD;
myhBrush: HBRUSH;
begin
case Msg of
WM_PAINT:
begin
DC := BeginPaint(hWnd, ps);
GetClientRect(hWnd, R);
BufferState := begin_double_buffer(DC, R);
try
BgColor := DWORD(GetPropW(hWnd, 'DlgBg'));
TextColor := DWORD(GetPropW(hWnd, 'DlgTxt'));
TitleStr := UnicodeString(Pointer(GetPropW(hWnd, 'DlgTitlePtr')));
PromptStr := UnicodeString(Pointer(GetPropW(hWnd, 'DlgPromptPtr')));
draw_fill_rectangle(hWnd, 0, 0, R.Right, R.Bottom, BgColor, BufferState.MemDC);
hTitleFont := CreateFontW(-20, 0, 0, 0, FW_BOLD, 0, 0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY, DEFAULT_PITCH, 'Segoe UI');
hDescFont := CreateFontW(-15, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY, DEFAULT_PITCH, 'Segoe UI');
set_text_color(BufferState.MemDC, TextColor);
set_bk_mode(BufferState.MemDC, True);
hOldFont := SelectObject(BufferState.MemDC, hTitleFont);
// Tytuł
TitleRect := R;
TitleRect.Top := 15; TitleRect.Left := 20; TitleRect.Right := R.Right - 40;
draw_text_advanced(BufferState.MemDC, TitleRect, TitleStr, DT_LEFT or DT_SINGLELINE);
// Treść zachęty (Prompt)
SelectObject(BufferState.MemDC, hDescFont);
PromptRect := R;
PromptRect.Top := 50; PromptRect.Left := 20; PromptRect.Right := R.Right - 20;
draw_text_advanced(BufferState.MemDC, PromptRect, PromptStr, DT_LEFT or DT_WORDBREAK);
SelectObject(BufferState.MemDC, hOldFont);
DeleteObject(hTitleFont);
DeleteObject(hDescFont);
finally
end_double_buffer(BufferState);
EndPaint(hWnd, ps);
end;
Result := 0;
Exit;
end;
WM_ERASEBKGND:
begin
Result := 1;
Exit;
end;
WM_NCHITTEST:
begin
Result := DefWindowProcW(hWnd, Msg, WParam, LParam);
if Result = HTCLIENT then Result := HTCAPTION;
Exit;
end;
WM_COMMAND:
begin
case LOWORD(WParam) of
ID_BTN_OK:
begin
// Pobieramy uchwyt pola tekstowego zapisany we właściwościach okna
hEdit := GetPropW(hWnd, 'DlgEditHandle');
// Zczytujemy tekst z pola do naszej zmiennej
TextLen := GetWindowTextLengthW(hEdit);
SetLength(Buffer, TextLen + 1);
GetWindowTextW(hEdit, PWideChar(Buffer), TextLen + 1);
CurrentInputText := PWideChar(Buffer);
CurrentInputResult := True;
end;
ID_BTN_CANCEL, ID_BTN_CLOSE_X:
begin
CurrentInputResult := False;
end;
end;
if (LOWORD(WParam) = ID_BTN_OK) or (LOWORD(WParam) = ID_BTN_CANCEL) or (LOWORD(WParam) = ID_BTN_CLOSE_X) then
begin
hOwner := GetWindow(hWnd, GW_OWNER);
if hOwner <> 0 then
begin
EnableWindow(hOwner, True);
SetForegroundWindow(hOwner);
end;
DestroyWindow(hWnd);
end;
Result := 0;
Exit;
end;
WM_CTLCOLOREDIT:
begin
// WParam przechowuje płótno (DC) samego pola tekstowego
hdcEdit := HDC(WParam);
// Pobieramy kolory i pędzel, które zaraz przekażemy do okna
TxtCol := DWORD(GetPropW(hWnd, 'DlgEditTxt'));
BgCol := DWORD(GetPropW(hWnd, 'DlgEditBg'));
myhBrush := HBRUSH(GetPropW(hWnd, 'DlgEditBrush'));
// Ustawiamy kolor tekstu i tła pod tekstem
SetTextColor(hdcEdit, TxtCol);
SetBkColor(hdcEdit, BgCol);
// Zwracamy pędzel, którym Windows pomaluje resztę tła pola tekstowego
Result := LRESULT(myhBrush);
Exit;
end;
WM_NCDESTROY:
begin
RemovePropW(hWnd, 'DlgBg');
RemovePropW(hWnd, 'DlgTxt');
RemovePropW(hWnd, 'DlgTitlePtr');
RemovePropW(hWnd, 'DlgPromptPtr');
RemovePropW(hWnd, 'DlgEditHandle');
end;
end;
Result := DefWindowProcW(hWnd, Msg, WParam, LParam);
end;
function custom_dialog_proc(hWnd: HWND; Msg: UINT; WParam: WPARAM; LParam: LPARAM): LRESULT; stdcall;
var
ps: TPaintStruct;
DC: HDC;
R: TRect;
BgColor, TextColor: DWORD;
TitleStr, DescStr: UnicodeString;
TitleRect, DescRect: TRect;
// Bufory z avoraiser.gdi
BufferState: TDoubleBufferState;
hDescFont: HFONT;
hTitleFont: HFONT;
hOldFont: HGDIOBJ;
hOwner: HWND;
begin
case Msg of
WM_PAINT:
begin
DC := BeginPaint(hWnd, ps);
GetClientRect(hWnd, R);
// 1. START DOUBLE BUFFERING (Eliminacja migotania!)
BufferState := begin_double_buffer(DC, R);
try
// Pobieramy właściwości
BgColor := DWORD(GetPropW(hWnd, 'DlgBg'));
TextColor := DWORD(GetPropW(hWnd, 'DlgTxt'));
// Pobieramy stringi (konwersja z PtrUInt na obiekt/wskaźnik)
TitleStr := UnicodeString(Pointer(GetPropW(hWnd, 'DlgTitlePtr')));
DescStr := UnicodeString(Pointer(GetPropW(hWnd, 'DlgDescPtr')));
// 2. Rysujemy TŁO na buforze pamięci
draw_fill_rectangle(hWnd, 0, 0, R.Right, R.Bottom, BgColor, BufferState.MemDC);
hTitleFont := CreateFontW(-20, 0, 0, 0, FW_BOLD, 0, 0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY, DEFAULT_PITCH, 'Segoe UI');
// Tworzymy mniejszą, zwykłą czcionkę dla opisu (Wielkość -15)
hDescFont := CreateFontW(-15, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
CLEARTYPE_QUALITY, DEFAULT_PITCH, 'Segoe UI');
// 3. Rysujemy TEKSTY na buforze pamięci
// Używamy funkcji GDI z avoraiser.gdi
set_text_color(BufferState.MemDC, TextColor);
set_bk_mode(BufferState.MemDC, True);
// Podpinamy czcionkę tytułową do naszego płótna
hOldFont := SelectObject(BufferState.MemDC, hTitleFont);
// Tytuł
TitleRect := R;
TitleRect.Top := 15; // Podniesione do góry
TitleRect.Left := 20; // Odsunięte od lewej krawędzi
TitleRect.Right := R.Right - 40; // Żeby tekst nie wszedł na przycisk "X"
//TitleRect.Bottom := 60;
//draw_text_advanced(BufferState.MemDC, TitleRect, TitleStr, DT_CENTER or DT_SINGLELINE);
draw_text_advanced(BufferState.MemDC, TitleRect, TitleStr, DT_LEFT or DT_SINGLELINE);
// Opis
// Podpinamy czcionkę opisu
SelectObject(BufferState.MemDC, hDescFont);
DescRect := R;
DescRect.Top := 50;
DescRect.Left := 20;
DescRect.Right := R.Right - 20;
//draw_text_advanced(BufferState.MemDC, DescRect, DescStr, DT_CENTER or DT_WORDBREAK);
// Ustawione do lewej z zawijaniem wierszy
draw_text_advanced(BufferState.MemDC, DescRect, DescStr, DT_LEFT or DT_WORDBREAK);
// sprzątanie pamięci
SelectObject(BufferState.MemDC, hOldFont);
DeleteObject(hTitleFont);
DeleteObject(hDescFont);
finally
// koniec double buffering (przerzut na ekran)
end_double_buffer(BufferState);
EndPaint(hWnd, ps);
end;
Result := 0;
Exit;
end;
// dla braku migotania: blokujemy systemowe czyszczenie tła
WM_ERASEBKGND:
begin
Result := 1;
Exit;
end;
WM_COMMAND:
begin
case LOWORD(WParam) of
ID_BTN_OK: CurrentDialogResult := DlgResultOK;
ID_BTN_CANCEL: CurrentDialogResult := DlgResultCancel;
ID_BTN_YES: CurrentDialogResult := DlgResultYes;
ID_BTN_NO: CurrentDialogResult := DlgResultNo;
ID_BTN_CLOSE_X: CurrentDialogResult := DlgResultCancel;
ID_BTN_ABORT: CurrentDialogResult := DlgResultAbort;
ID_BTN_RETRY: CurrentDialogResult := DlgResultRetry;
ID_BTN_IGNORE: CurrentDialogResult := DlgResultIgnore;
end;
if (LOWORD(WParam) >= ID_BTN_OK) and (LOWORD(WParam) <= ID_BTN_IGNORE) then
begin
hOwner := GetWindow(hWnd, GW_OWNER);
if hOwner <> 0 then
begin
EnableWindow(hOwner, True); // Budzimy rodzica
SetForegroundWindow(hOwner); // Dajemy mu focus
end;
DestroyWindow(hWnd);
end;
Result := 0;
Exit;
end;
WM_NCHITTEST:
begin
Result := DefWindowProcW(hWnd, Msg, WParam, LParam);
if Result = HTCLIENT then
begin
Result := HTCAPTION;
end;
Exit;
end;
WM_NCDESTROY:
begin
// Sprzątanie (Stringi w Pascalu są zarządzane automatycznie, ale usuwamy propsy)
RemovePropW(hWnd, 'DlgBg');
RemovePropW(hWnd, 'DlgTxt');
RemovePropW(hWnd, 'DlgTitlePtr');
RemovePropW(hWnd, 'DlgDescPtr');
end;
end;
Result := DefWindowProcW(hWnd, Msg, WParam, LParam);
end;
procedure show_message(Owner: HWND; const Title, Text: UnicodeString);
begin
MessageBoxW(Owner, PWideChar(Text), PWideChar(Title), MB_OK or
MB_ICONINFORMATION or
MB_SETFOREGROUND);
end;
function ask_question(Owner: HWND; const Title, Text: UnicodeString): Boolean;
begin
// MB_YESNO - przyciski Tak i Nie
// MB_ICONQUESTION - ikonka znaku zapytania
// Zwraca IDYES, jeśli kliknięto "Tak"
Result := MessageBoxW(Owner, PWideChar(Text), PWideChar(Title),
MB_YESNO or MB_ICONQUESTION or MB_SETFOREGROUND) = IDYES;
end;
procedure show_warning(Owner: HWND; const Title, Text: UnicodeString);
begin
// MB_ICONWARNING - żółty trójkąt z wykrzyknikiem
MessageBoxW(Owner, PWideChar(Text), PWideChar(Title), MB_OK or
MB_ICONWARNING or MB_SETFOREGROUND);
end;
// Wewnętrzna funkcja tłumacząca ID przycisku na tekst w wybranym języku
function get_btn_text(BtnID: Integer): UnicodeString;
begin
case CurrentDialogLang of
LangPL:
case BtnID of
ID_BTN_OK: Result := 'OK';
ID_BTN_CANCEL: Result := 'Anuluj';
ID_BTN_YES: Result := 'Tak';
ID_BTN_NO: Result := 'Nie';
ID_BTN_ABORT: Result := 'Przerwij';
ID_BTN_RETRY: Result := 'Ponów';
ID_BTN_IGNORE: Result := 'Ignoruj';
else
Result := '';
end;
LangEN:
case BtnID of
ID_BTN_OK: Result := 'OK';
ID_BTN_CANCEL: Result := 'Cancel';
ID_BTN_YES: Result := 'Yes';
ID_BTN_NO: Result := 'No';
ID_BTN_ABORT: Result := 'Abort';
ID_BTN_RETRY: Result := 'Retry';
ID_BTN_IGNORE: Result := 'Ignore';
else
Result := '';
end;
end;
end;
function show_custom_dialog(Owner: HWND; const Title,
Description: UnicodeString; BgColor, TextColor, AccentColor: DWORD;
Buttons: TDialogButtons): TDialogResult;
var
wc: TWndClassW;
hDlg, hBtn1, hBtn2,hBtn3, hBtnX: HWND;
msg: TMsg;
DlgW, DlgH, PosX, PosY: Integer;
OwnerRect: TRect;
BtnW, BtnH, BtnGap, BtnY: Integer;
GrayColor: DWORD;
StartX: Integer;
begin
// Domyślny wynik, jeśli coś pójdzie nie tak lub zamknięto "X"
CurrentDialogResult := DlgResultCancel;
if Buttons = DlgBtnOK then CurrentDialogResult := DlgResultOK;
// 1. Rejestracja klasy okna (jednorazowa)
if not DialogClassRegistered then
begin
FillChar(wc, SizeOf(wc), 0);
wc.lpfnWndProc := @custom_dialog_proc;
wc.hInstance := GetModuleHandle(nil);
wc.hCursor := LoadCursor(0, IDC_ARROW);
wc.lpszClassName := 'AvocadoDialogV2Class';
// CS_DROPSHADOW - dodaje cień pod oknem (ładny efekt w Windows)
wc.style := CS_VREDRAW or CS_HREDRAW or CS_DROPSHADOW;
RegisterClassW(wc);
DialogClassRegistered := True;
end;
// Wymiary i pozycja
DlgW := 400; DlgH := 220;
BtnW := 100; BtnH := 35; BtnGap := 20;
BtnY := DlgH - BtnH - 25;
GrayColor := $404040; // Kolor dla przycisków "Anuluj" / "Nie"
if (Owner <> 0) and GetWindowRect(Owner, OwnerRect) then
begin
PosX := OwnerRect.Left + ((OwnerRect.Right - OwnerRect.Left) div 2) - (DlgW div 2);
PosY := OwnerRect.Top + ((OwnerRect.Bottom - OwnerRect.Top) div 2) - (DlgH div 2);
end else begin PosX := 300; PosY := 300; end;
// 2. Tworzenie okna (WS_POPUP = brak systemowej ramki)
hDlg := CreateWindowExW(WS_EX_TOPMOST, 'AvocadoDialogV2Class', nil,
WS_POPUP or WS_VISIBLE, PosX, PosY, DlgW, DlgH, Owner, 0, GetModuleHandle(nil), nil);
if hDlg <> 0 then
begin
// Przekazujemy dane do okna
SetPropW(hDlg, 'DlgBg', THandle(BgColor));
SetPropW(hDlg, 'DlgTxt', THandle(TextColor));
// Przekazujemy wskaźniki do stringów Unicode
SetPropW(hDlg, 'DlgTitlePtr', THandle(Pointer(Title)));
SetPropW(hDlg, 'DlgDescPtr', THandle(Pointer(Description)));
//Tworzenie przyciskow
// Przycisk "X" w prawym górnym rogu (mały, kwadratowy)
hBtnX := create_button(hDlg, 'X', DlgW - 35, 5, 30, 30);
set_button_id(hBtnX, ID_BTN_CLOSE_X);
// Stylizujemy X: Tło przezroczyste (lub kolor dialogu), tekst szary, po najechaniu lekko jaśniejszy
//set_button_colors(hBtnX, BgColor, BgColor + $101010, TextColor, $AAAAAA);
set_button_colors(hBtnX, BgColor, BgColor + $101010, BgColor - $050505, TextColor, BgColor);
// Przyciski główne na dole
case Buttons of
DlgBtnOK:
begin
StartX := (DlgW - BtnW) div 2;
hBtn1 := create_button(hDlg, 'OK', StartX, BtnY, BtnW, BtnH);
set_button_id(hBtn1, ID_BTN_OK);
set_button_colors(hBtn1, AccentColor, AccentColor + $101010, AccentColor - $101010, $FFFFFF, AccentColor);
end;
DlgBtnOKCancel, DlgBtnYesNo, DlgBtnRetryCancel:
begin
// Układ na 2 przyciski: (Szerokość 2 przycisków + przerwa)
StartX := (DlgW - (2 * BtnW + BtnGap)) div 2;
// Lewy przycisk
hBtn1 := create_button(hDlg, '', StartX, BtnY, BtnW, BtnH);
set_button_colors(hBtn1, AccentColor, AccentColor + $101010, AccentColor - $101010, $FFFFFF, AccentColor);
// Prawy przycisk
hBtn2 := create_button(hDlg, '', StartX + BtnW + BtnGap, BtnY, BtnW, BtnH);
set_button_colors(hBtn2, GrayColor, GrayColor + $101010, GrayColor - $101010, $DDDDDD, GrayColor);
{if Buttons = DlgBtnOKCancel then begin
SetWindowTextW(hBtn1, 'OK'); set_button_id(hBtn1, ID_BTN_OK);
SetWindowTextW(hBtn2, 'Anuluj'); set_button_id(hBtn2, ID_BTN_CANCEL);
end else if Buttons = DlgBtnYesNo then begin
SetWindowTextW(hBtn1, 'Tak'); set_button_id(hBtn1, ID_BTN_YES);
SetWindowTextW(hBtn2, 'Nie'); set_button_id(hBtn2, ID_BTN_NO);
end else begin
SetWindowTextW(hBtn1, 'Ponów'); set_button_id(hBtn1, ID_BTN_RETRY);
SetWindowTextW(hBtn2, 'Anuluj'); set_button_id(hBtn2, ID_BTN_CANCEL);
end;
}
if Buttons = DlgBtnOKCancel then begin
SetWindowTextW(hBtn1, PWideChar(get_btn_text(ID_BTN_OK))); set_button_id(hBtn1, ID_BTN_OK);
SetWindowTextW(hBtn2, PWideChar(get_btn_text(ID_BTN_CANCEL))); set_button_id(hBtn2, ID_BTN_CANCEL);
end else if Buttons = DlgBtnYesNo then begin
SetWindowTextW(hBtn1, PWideChar(get_btn_text(ID_BTN_YES))); set_button_id(hBtn1, ID_BTN_YES);
SetWindowTextW(hBtn2, PWideChar(get_btn_text(ID_BTN_NO))); set_button_id(hBtn2, ID_BTN_NO);
end else begin
SetWindowTextW(hBtn1, PWideChar(get_btn_text(ID_BTN_RETRY))); set_button_id(hBtn1, ID_BTN_RETRY);
SetWindowTextW(hBtn2, PWideChar(get_btn_text(ID_BTN_CANCEL))); set_button_id(hBtn2, ID_BTN_CANCEL);
end;
end;
DlgBtnYesNoCancel, DlgBtnAbortRetryIgnore:
begin
// Układ na 3 przyciski: (Szerokość 3 przycisków + 2 przerwy)
StartX := (DlgW - (3 * BtnW + 2 * BtnGap)) div 2;
// Lewy przycisk (hBtn1)
hBtn1 := create_button(hDlg, '', StartX, BtnY, BtnW, BtnH);
set_button_colors(hBtn1, AccentColor, AccentColor + $101010, AccentColor - $101010, $FFFFFF, AccentColor);
// Środkowy przycisk (hBtn2)
hBtn2 := create_button(hDlg, '', StartX + BtnW + BtnGap, BtnY, BtnW, BtnH);
set_button_colors(hBtn2, GrayColor, GrayColor + $101010, GrayColor - $101010, $DDDDDD, GrayColor);
// Prawy przycisk (nowa zmienna hBtn3, musisz ją dopisać w sekcji var u góry funkcji)
hBtn3 := create_button(hDlg, '', StartX + 2 * (BtnW + BtnGap), BtnY, BtnW, BtnH);
set_button_colors(hBtn3, GrayColor, GrayColor + $101010, GrayColor - $101010, $DDDDDD, GrayColor);
if Buttons = DlgBtnYesNoCancel then begin
SetWindowTextW(hBtn1, 'Tak'); set_button_id(hBtn1, ID_BTN_YES);
SetWindowTextW(hBtn2, 'Nie'); set_button_id(hBtn2, ID_BTN_NO);
SetWindowTextW(hBtn3, 'Anuluj'); set_button_id(hBtn3, ID_BTN_CANCEL);
end else begin
SetWindowTextW(hBtn1, 'Przerwij'); set_button_id(hBtn1, ID_BTN_ABORT);
SetWindowTextW(hBtn2, 'Ponów'); set_button_id(hBtn2, ID_BTN_RETRY);
SetWindowTextW(hBtn3, 'Ignoruj'); set_button_id(hBtn3, ID_BTN_IGNORE);
end;
end;
end;
{
DlgBtnOK:
begin
// Pojedynczy przycisk OK na środku
hBtn1 := create_button(hDlg, 'OK', (DlgW div 2) - (BtnW div 2), BtnY, BtnW, BtnH);
set_button_id(hBtn1, ID_BTN_OK);
set_button_colors(hBtn1, AccentColor, AccentColor + $101010, AccentColor - $101010, $FFFFFF, AccentColor);
end;
DlgBtnOKCancel:
begin
// OK po prawej (akcent), Anuluj po lewej (szary)
hBtn1 := create_button(hDlg, 'OK', (DlgW div 2) + (BtnGap div 2), BtnY, BtnW, BtnH);
set_button_id(hBtn1, ID_BTN_OK);
set_button_colors(hBtn1, AccentColor, AccentColor + $101010, AccentColor - $101010, $FFFFFF, AccentColor);
hBtn2 := create_button(hDlg, 'Anuluj', (DlgW div 2) - BtnW - (BtnGap div 2), BtnY, BtnW, BtnH);
set_button_id(hBtn2, ID_BTN_CANCEL);
set_button_colors(hBtn2, GrayColor, GrayColor + $101010, GrayColor - $101010, $DDDDDD, GrayColor);
end;
DlgBtnYesNo:
begin
// Tak po prawej, Nie po lewej
hBtn1 := create_button(hDlg, 'Tak', (DlgW div 2) + (BtnGap div 2), BtnY, BtnW, BtnH);
set_button_id(hBtn1, ID_BTN_YES);
set_button_colors(hBtn1, AccentColor, AccentColor + $101010, AccentColor - $101010, $FFFFFF, AccentColor);
hBtn2 := create_button(hDlg, 'Nie', (DlgW div 2) - BtnW - (BtnGap div 2), BtnY, BtnW, BtnH);
set_button_id(hBtn2, ID_BTN_NO);
set_button_colors(hBtn2, GrayColor, GrayColor + $101010, GrayColor - $101010, $DDDDDD, GrayColor);
end;
end;
}
// 3. Pętla modalna (blokada rodzica)
if Owner <> 0 then EnableWindow(Owner, False);
while GetMessage(@msg, 0, 0, 0) do
begin
if not IsWindow(hDlg) then Break;
TranslateMessage(@msg);
DispatchMessage(@msg);
end;
if Owner <> 0 then
begin
EnableWindow(Owner, True);
SetForegroundWindow(Owner);
end;
end;
// Zwracamy wynik, który został ustawiony w WM_COMMAND
Result := CurrentDialogResult;
end;
procedure set_dialog_language(Lang: TDialogLanguage);
begin
CurrentDialogLang := Lang;
end;
function input_box(Owner: HWND; const Title, Prompt: UnicodeString; var Value: UnicodeString; BgColor, TextColor, AccentColor, EditBgColor, EditTextColor: DWORD): Boolean;
var
wc: TWndClassW;
hDlg, hBtnOK, hBtnCancel, hBtnX, hEdit: HWND;
msg: TMsg;
DlgW, DlgH, PosX, PosY: Integer;
OwnerRect: TRect;
BtnW, BtnH, BtnGap, BtnY, StartX: Integer;
GrayColor: DWORD;
hEditFont: HFONT;
hEditBrush: HBRUSH;
begin
CurrentInputResult := False;
CurrentInputText := Value; // Domyślna wartość w polu
if not InputDialogClassRegistered then
begin
FillChar(wc, SizeOf(wc), 0);
wc.lpfnWndProc := @input_dialog_proc;
wc.hInstance := GetModuleHandle(nil);
wc.hCursor := LoadCursor(0, IDC_ARROW);
wc.lpszClassName := 'AvocadoInputDialogClass';
wc.style := CS_VREDRAW or CS_HREDRAW or CS_DROPSHADOW;
RegisterClassW(wc);
InputDialogClassRegistered := True;
end;
DlgW := 400; DlgH := 200;
BtnW := 100; BtnH := 35; BtnGap := 20;
BtnY := DlgH - BtnH - 20;
GrayColor := $404040;
if (Owner <> 0) and GetWindowRect(Owner, OwnerRect) then
begin
PosX := OwnerRect.Left + ((OwnerRect.Right - OwnerRect.Left) div 2) - (DlgW div 2);
PosY := OwnerRect.Top + ((OwnerRect.Bottom - OwnerRect.Top) div 2) - (DlgH div 2);
end else begin PosX := 300; PosY := 300; end;
hDlg := CreateWindowExW(WS_EX_TOPMOST, 'AvocadoInputDialogClass', nil,
WS_POPUP or WS_VISIBLE, PosX, PosY, DlgW, DlgH, Owner, 0, GetModuleHandle(nil), nil);
if hDlg <> 0 then
begin
SetPropW(hDlg, 'DlgBg', THandle(BgColor));
SetPropW(hDlg, 'DlgTxt', THandle(TextColor));
SetPropW(hDlg, 'DlgTitlePtr', THandle(Pointer(Title)));
SetPropW(hDlg, 'DlgPromptPtr', THandle(Pointer(Prompt)));
SetPropW(hDlg, 'DlgEditTxt', THandle(EditTextColor));
SetPropW(hDlg, 'DlgEditBg', THandle(EditBgColor));
hEditBrush := CreateSolidBrush(EditBgColor);
SetPropW(hDlg, 'DlgEditBrush', THandle(hEditBrush));
//tworzenie kontrolek
hBtnX := create_button(hDlg, '✕', DlgW - 35, 5, 30, 30);
set_button_id(hBtnX, ID_BTN_CLOSE_X);
set_button_colors(hBtnX, BgColor, BgColor + $101010, BgColor - $050505, TextColor, BgColor);
StartX := (DlgW - (2 * BtnW + BtnGap)) div 2;
hBtnOK := create_button(hDlg, PWideChar(get_btn_text(ID_BTN_OK)), StartX, BtnY, BtnW, BtnH);
set_button_id(hBtnOK, ID_BTN_OK);
set_button_colors(hBtnOK, AccentColor, AccentColor + $101010, AccentColor - $101010, $FFFFFF, AccentColor);
hBtnCancel := create_button(hDlg, PWideChar(get_btn_text(ID_BTN_CANCEL)), StartX + BtnW + BtnGap, BtnY, BtnW, BtnH);
set_button_id(hBtnCancel, ID_BTN_CANCEL);
set_button_colors(hBtnCancel, GrayColor, GrayColor + $101010, GrayColor - $101010, $DDDDDD, GrayColor);
// TWORZENIE POLA TEKSTOWEGO
// Uwaga: Zakładam że w avoraiser.edit masz np. funkcję create_edit.
// Jeśli jej sygnatura jest inna, podmień kolejność parametrów!
// Poniższy kod używa domyślnego tworzenia z WinAPI (na wszelki wypadek):
{hEdit := CreateWindowExW(WS_EX_CLIENTEDGE, 'EDIT', PWideChar(Value),
WS_CHILD or WS_VISIBLE or ES_AUTOHSCROLL,
20, 85, DlgW - 40, 25,
hDlg, 0, GetModuleHandle(nil), nil);
}
// Zmieniamy styl na WS_BORDER (zamiast wypukłego WS_EX_CLIENTEDGE) - wygląda dużo bardziej płasko i nowocześnie
hEdit := CreateWindowExW(0, 'EDIT', PWideChar(Value),