-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathVcl.StyledTaskDialog.pas
More file actions
1284 lines (1173 loc) · 57.1 KB
/
Vcl.StyledTaskDialog.pas
File metadata and controls
1284 lines (1173 loc) · 57.1 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
{******************************************************************************}
{ }
{ StyledTaskDialog: a Task Dialog Component with StyleButtons }
{ }
{ Copyright (c) 2022-2026 (Ethea S.r.l.) }
{ Author: Carlo Barazzetta }
{ Contributors: }
{ }
{ https://github.com/EtheaDev/StyledComponents }
{ }
{******************************************************************************}
{ }
{ Licensed under the Apache License, Version 2.0 (the "License"); }
{ you may not use this file except in compliance with the License. }
{ You may obtain a copy of the License at }
{ }
{ http://www.apache.org/licenses/LICENSE-2.0 }
{ }
{ Unless required by applicable law or agreed to in writing, software }
{ distributed under the License is distributed on an "AS IS" BASIS, }
{ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }
{ See the License for the specific language governing permissions and }
{ limitations under the License. }
{ }
{******************************************************************************}
unit Vcl.StyledTaskDialog;
{$INCLUDE StyledComponents.inc}
interface
uses
System.SysUtils
, System.Classes
, System.UITypes
, WinApi.Windows
, Vcl.Dialogs
, Vcl.Graphics
, Vcl.Forms
, Vcl.ButtonStylesAttributes
, Vcl.StandardButtonStyles
, Vcl.StyledButton
;
const
/// <summary>Default alpha blend value for styled dialogs (fully opaque)</summary>
DEFAULT_STYLEDDIALOG_ALPHABLEND = 255;
/// <summary>Default minimum width for styled dialogs in pixels</summary>
DEFAULT_STYLEDDIALOG_MIN_WIDTH = 500;
/// <summary>Default minimum height for styled dialogs in pixels</summary>
DEFAULT_STYLEDDIALOG_MIN_HEIGHT = 280;
/// <summary>Default width for dialog buttons in pixels</summary>
DEFAULT_STYLEDDIALOG_BUTTONSWIDTH = 74;
/// <summary>Default height for dialog buttons in pixels</summary>
DEFAULT_STYLEDDIALOG_BUTTONSHEIGHT = 30;
/// <summary>Minimum allowed size for dialog buttons in pixels</summary>
MIN_STYLEDDIALOG_BUTTONSSIZE = 10;
/// <summary>Maximum allowed width for dialog buttons in pixels</summary>
MAX_STYLEDDIALOG_BUTTONSWIDTH = 800;
/// <summary>Maximum allowed height for dialog buttons in pixels</summary>
MAX_STYLEDDIALOG_BUTTONSHEIGHT = 300;
{$IFDEF Use_Large_Dialog_Icons}
/// <summary>Default size for main dialog icon in pixels (128 when Use_Large_Dialog_Icons is defined)</summary>
DEFAULT_MAIN_ICON_SIZE = 128;
{$ELSE}
/// <summary>Default size for main dialog icon in pixels</summary>
DEFAULT_MAIN_ICON_SIZE = 64;
{$ENDIF}
/// <summary>Extended TTaskDialogIcon value for question mark icon</summary>
tdiQuestion = 5;
type
/// <summary>Array type for storing custom dialog icons indexed by dialog type</summary>
TStyledDialogIcons = array[TMsgDlgType] of TIcon;
/// <summary>Event type for finding a dialog button by its modal result</summary>
/// <param name="AModalResult">The modal result to search for</param>
/// <returns>The TStyledButton matching the modal result, or nil if not found</returns>
TOnFindDialogButtonEvent = function (const AModalResult: TModalResult): TStyledButton of object;
/// <summary>Exception class for styled task dialog errors</summary>
EStyledTaskDialogException = class(Exception);
{$WARN SYMBOL_PLATFORM OFF}
type
/// <summary>Event type called when the styled task dialog form is shown</summary>
/// <param name="AStyledTaskDialogForm">The dialog form being shown</param>
TTaskDialogShow = procedure(
const AStyledTaskDialogForm: TForm) of Object;
/// <summary>Progress bar component for styled task dialogs</summary>
/// <remarks>Extends TTaskDialogProgressBar for use within TStyledTaskDialog</remarks>
[ComponentPlatforms(pidWin32 or pidWin64)]
TStyledTaskDialogProgressBar = class(TTaskDialogProgressBar)
end;
/// <summary>Advanced task dialog component with styled buttons and full customization</summary>
/// <remarks>
/// TStyledTaskDialog provides a modern, fully customizable alternative to standard
/// Windows dialogs. It supports styled buttons, custom icons, animations (via Skia4Delphi),
/// progress bars, command links, radio buttons, verification checkboxes, and more.
/// </remarks>
[ComponentPlatforms(pidWin32 or pidWin64)]
TStyledTaskDialog = class(TTaskDialog)
private
class var
_DefaultButtonsFamily: TStyledButtonFamily;
_DefaultButtonsDrawType: TStyledButtonDrawType;
_DefaultButtonsRadius: Integer;
_DefaultButtonsRoundedCorners: TRoundedCorners;
private
FHelpFile: string;
FParentWnd: HWND;
FPosition: TPoint;
FMainIconSize: Integer;
FDialogButtonsFamily: TStyledButtonFamily;
FDialogButtonsDrawType: TStyledButtonDrawType;
FDialogButtonsRadius: Integer;
FDialogButtonsRoundedCorners: TRoundedCorners;
FUseTitleInMessageDlg: Boolean;
FAlphaBlendValue: Byte;
FButtonsWidth: Integer;
FButtonsHeight: Integer;
FAutoClick: Boolean;
FAutoClickDelay: Integer;
FOnFindDialogButton: TOnFindDialogButtonEvent;
FUseAnimations: Boolean;
FUseAnimationLoop: Boolean;
FUseAnimationInverse: Boolean;
FUseMessageDefaultButton: Boolean;
FMessageDefaultButton: TMsgDlgBtn;
FOnDialogShow: TTaskDialogShow;
FHideSystemCloseButton: Boolean;
function IsDefaultFamily: Boolean;
function IsStoredDrawType: Boolean;
function IsStoredRadius: Boolean;
function IsStoredRoundedCorners: Boolean;
procedure SetAutoClick(const AValue: Boolean);
procedure SetAutoClickDelay(const AValue: Integer);
procedure SetAlphaBlendValue(const AValue: Byte);
procedure SetButtonsHeight(const AValue: Integer);
procedure SetButtonsWidth(const AValue: Integer);
function GetHandle: HWND;
procedure SetHandle(const AValue: HWND);
procedure SetUseCommandLinks(const AValue: Boolean);
function GetUseCommandLinks: Boolean;
procedure SetMainIconSize(const AValue: Integer);
procedure SetUseAnimationInverse(const AValue: Boolean);
procedure SetUseAnimationLoop(const AValue: Boolean);
procedure SetUseAnimations(const AValue: Boolean);
strict protected
function DoExecute(ParentWnd: HWND): Boolean; override;
procedure DoOnHelp; override;
protected
public
/// <summary>Called when the expand button is clicked</summary>
/// <param name="Expanded">True if content is now expanded, False if collapsed</param>
procedure DoOnExpandButtonClicked(Expanded: Boolean); override;
/// <summary>Called when a radio button is clicked</summary>
/// <param name="ButtonID">The ID of the clicked radio button</param>
procedure DoOnRadioButtonClicked(ButtonID: Integer); override;
/// <summary>Called when a hyperlink in the dialog text is clicked</summary>
/// <param name="AURL">The URL of the clicked hyperlink</param>
procedure DoOnHyperlinkClicked(const AURL: string); override;
/// <summary>Creates a new instance of TStyledTaskDialog</summary>
/// <param name="AOwner">The component owner</param>
constructor Create(AOwner: TComponent); override;
/// <summary>Displays the task dialog and returns when the user closes it</summary>
/// <param name="ParentWnd">Handle to the parent window</param>
/// <returns>True if the dialog was closed with a positive result</returns>
function Execute(ParentWnd: HWND): Boolean; overload; override;
/// <summary>Finds a dialog button by its modal result value</summary>
/// <param name="AModalResult">The modal result to search for</param>
/// <returns>The TStyledButton matching the modal result, or nil if not found</returns>
function FindDialogButton(const AModalResult: TModalResult): TStyledButton;
/// <summary>Returns True if a custom position has been set for the dialog</summary>
/// <returns>True if Position is not the default (-1, -1)</returns>
function IsCustomPosition: Boolean;
/// <summary>Registers default rendering style for all TStyledTaskDialog instances</summary>
/// <param name="ADrawType">The draw type for buttons (btRoundRect, btRounded, btRect, btEllipse)</param>
/// <param name="AFamily">The style family for buttons (default: DEFAULT_CLASSIC_FAMILY)</param>
/// <param name="ARadius">The corner radius in pixels (default: DEFAULT_RADIUS)</param>
/// <param name="ARoundedCorners">Which corners to round (default: ALL_ROUNDED_CORNERS)</param>
class procedure RegisterDefaultRenderingStyle(
const ADrawType: TStyledButtonDrawType;
const AFamily: TStyledButtonFamily = DEFAULT_CLASSIC_FAMILY;
const ARadius: Integer = DEFAULT_RADIUS;
const ARoundedCorners: TRoundedCorners = ALL_ROUNDED_CORNERS); virtual;
/// <summary>The default button determined from message dialog type</summary>
property MessageDefaultButton: TMsgDlgBtn read FMessageDefaultButton;
/// <summary>Indicates if MessageDefaultButton should be used</summary>
property UseMessageDefaultButton: Boolean read FUseMessageDefaultButton;
/// <summary>Path to the help file for context-sensitive help</summary>
property HelpFile: string read FHelpFile write FHelpFile;
/// <summary>Window handle of the dialog form</summary>
property Handle: HWND read GetHandle write SetHandle;
/// <summary>Event handler to find a dialog button by modal result</summary>
property OnFindDialogButton: TOnFindDialogButtonEvent read FOnFindDialogButton write FOnFindDialogButton;
published
/// <summary>Enables automatic button click after a delay</summary>
property AutoClick: Boolean read FAutoClick write SetAutoClick default False;
/// <summary>Delay in milliseconds before auto-clicking the default button</summary>
property AutoClickDelay: Integer read FAutoClickDelay write SetAutoClickDelay default DEFAULT_AUTOCLICK_DELAY;
/// <summary>Style family for dialog buttons (e.g., Bootstrap, Angular, Classic)</summary>
property DialogButtonsFamily: TStyledButtonFamily read FDialogButtonsFamily write FDialogButtonsFamily stored IsDefaultFamily;
/// <summary>Draw type for dialog buttons (btRoundRect, btRounded, btRect, btEllipse)</summary>
property DialogButtonsDrawType: TStyledButtonDrawType read FDialogButtonsDrawType write FDialogButtonsDrawType stored IsStoredDrawType;
/// <summary>Corner radius in pixels for dialog buttons</summary>
property DialogButtonsRadius: Integer read FDialogButtonsRadius write FDialogButtonsRadius stored IsStoredRadius;
/// <summary>Specifies which corners of dialog buttons should be rounded</summary>
property DialogButtonsRoundedCorners: TRoundedCorners read FDialogButtonsRoundedCorners write FDialogButtonsRoundedCorners stored IsStoredRoundedCorners;
/// <summary>When True, displays buttons as command links with descriptions</summary>
property UseCommandLinks: Boolean read GetUseCommandLinks write SetUseCommandLinks default False;
/// <summary>Enables Lottie animations for dialog icons (requires Skia4Delphi)</summary>
property UseAnimations: Boolean read FUseAnimations write SetUseAnimations default false;
/// <summary>When True, loops the icon animation continuously</summary>
property UseAnimationLoop: Boolean read FUseAnimationLoop write SetUseAnimationLoop default False;
/// <summary>When True, plays the icon animation in reverse</summary>
property UseAnimationInverse: Boolean read FUseAnimationInverse write SetUseAnimationInverse default False;
/// <summary>When True, displays title in simple message dialogs</summary>
property UseTitleInMessageDlg: Boolean read FUseTitleInMessageDlg write FUseTitleInMessageDlg default True;
/// <summary>Alpha blend value for dialog transparency (0=transparent, 255=opaque)</summary>
property AlphaBlendValue: Byte read FAlphaBlendValue write SetAlphaBlendValue default DEFAULT_STYLEDDIALOG_ALPHABLEND;
/// <summary>Width of dialog buttons in pixels</summary>
property ButtonsWidth: Integer read FButtonsWidth write SetButtonsWidth default DEFAULT_STYLEDDIALOG_BUTTONSWIDTH;
/// <summary>Height of dialog buttons in pixels</summary>
property ButtonsHeight: Integer read FButtonsHeight write SetButtonsHeight default DEFAULT_STYLEDDIALOG_BUTTONSHEIGHT;
/// <summary>When True, hides the system close button (X) in the title bar</summary>
property HideSystemCloseButton: Boolean read FHideSystemCloseButton write FHideSystemCloseButton default False;
/// <summary>Custom position for the dialog. Use (-1, -1) for default centering</summary>
property Position: TPoint read FPosition write FPosition stored IsCustomPosition;
/// <summary>Size of the main dialog icon in pixels</summary>
property MainIconSize: Integer read FMainIconSize write SetMainIconSize default DEFAULT_MAIN_ICON_SIZE;
/// <summary>Event fired when the dialog form is shown</summary>
property OnDialogShow: TTaskDialogShow read FOnDialogShow write FOnDialogShow;
end;
/// <summary>Interface for custom dialog launcher implementations</summary>
/// <remarks>Implement this interface to provide custom dialog display logic</remarks>
ITaskDialogLauncher = interface
['{B2F16F98-C163-4706-A803-E624126D8DF6}']
/// <summary>Executes and displays the task dialog</summary>
/// <param name="ParentWnd">Handle to the parent window</param>
/// <param name="ADialogType">The type of dialog (mtWarning, mtError, etc.)</param>
/// <param name="ATaskDialog">The TStyledTaskDialog instance to display</param>
/// <param name="ADialogBtnFamily">The button style family to use</param>
/// <returns>True if the dialog was executed successfully</returns>
function DoExecute(ParentWnd: HWND;
const ADialogType: TMsgDlgType;
const ATaskDialog: TStyledTaskDialog;
const ADialogBtnFamily: TStyledButtonFamily): boolean;
end;
//Deprecated functions
function StyledMessageDlg(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer; overload; deprecated 'use StyledTaskMessageDlg(...) instead'
function StyledMessageDlg(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn): Integer; overload; deprecated 'use StyledTaskMessageDlgPos(...) instead'
function StyledTaskDlgPos(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint;
X: Integer = -1; Y: Integer = -1): Integer; overload; deprecated 'use StyledTaskMessageDlgPos(...) or StyledTaskMessageDlg(...) instead'
function StyledTaskDlgPos(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; DefaultButton: TMsgDlgBtn; HelpCtx: Longint;
X: Integer = -1; Y: Integer = -1): Integer; overload; deprecated 'use StyledTaskMessageDlgPos(...) or StyledTaskMessageDlg(...) instead'
function StyledMessageDlgPos(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; DefaultButton: TMsgDlgBtn; HelpCtx: Longint;
X: Integer; Y: Integer): Integer; overload; deprecated 'use StyledMessageDlgPos(...) changing position of DefaultButton param, after HelpCtx'
/// <summary>Displays a styled message dialog (replacement for MessageDlg)</summary>
/// <param name="Msg">The message to display</param>
/// <param name="DlgType">The dialog type (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom)</param>
/// <param name="Buttons">The buttons to display</param>
/// <param name="HelpCtx">Help context ID</param>
/// <param name="DefaultButton">The default button</param>
/// <returns>The modal result of the clicked button</returns>
function StyledMessageDlg(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn): Integer; overload;
/// <summary>Displays a styled message dialog (replacement for MessageDlg)</summary>
/// <param name="Msg">The message to display</param>
/// <param name="DlgType">The dialog type (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom)</param>
/// <param name="Buttons">The buttons to display</param>
/// <param name="HelpCtx">Help context ID</param>
/// <returns>The modal result of the clicked button</returns>
function StyledMessageDlg(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer; overload;
/// <summary>Displays a styled message dialog with custom button captions</summary>
/// <param name="Msg">The message to display</param>
/// <param name="DlgType">The dialog type</param>
/// <param name="Buttons">The buttons to display</param>
/// <param name="HelpCtx">Help context ID</param>
/// <param name="DefaultButton">The default button</param>
/// <param name="CustomButtonCaptions">Array of custom captions for each button</param>
/// <returns>The modal result of the clicked button</returns>
function StyledMessageDlg(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn;
CustomButtonCaptions: array of string): Integer; overload;
/// <summary>Displays a styled message dialog at a specific position</summary>
/// <param name="Msg">The message to display</param>
/// <param name="DlgType">The dialog type</param>
/// <param name="Buttons">The buttons to display</param>
/// <param name="HelpCtx">Help context ID</param>
/// <param name="X">X coordinate for dialog position</param>
/// <param name="Y">Y coordinate for dialog position</param>
/// <returns>The modal result of the clicked button</returns>
function StyledMessageDlgPos(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint;
X: Integer; Y: Integer): Integer; overload;
/// <summary>Displays a styled message dialog at a specific position with default button</summary>
/// <param name="Msg">The message to display</param>
/// <param name="DlgType">The dialog type</param>
/// <param name="Buttons">The buttons to display</param>
/// <param name="HelpCtx">Help context ID</param>
/// <param name="DefaultButton">The default button</param>
/// <param name="X">X coordinate for dialog position</param>
/// <param name="Y">Y coordinate for dialog position</param>
/// <returns>The modal result of the clicked button</returns>
function StyledMessageDlgPos(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn;
X: Integer; Y: Integer): Integer; overload;
/// <summary>Displays a styled task message dialog with title (replacement for TaskMessageDlg)</summary>
/// <param name="Title">The dialog title</param>
/// <param name="Msg">The message to display</param>
/// <param name="DlgType">The dialog type</param>
/// <param name="Buttons">The buttons to display</param>
/// <param name="HelpCtx">Help context ID</param>
/// <returns>The modal result of the clicked button</returns>
function StyledTaskMessageDlg(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer; overload;
/// <summary>Displays a styled task message dialog with title and default button</summary>
/// <param name="Title">The dialog title</param>
/// <param name="Msg">The message to display</param>
/// <param name="DlgType">The dialog type</param>
/// <param name="Buttons">The buttons to display</param>
/// <param name="HelpCtx">Help context ID</param>
/// <param name="DefaultButton">The default button</param>
/// <returns>The modal result of the clicked button</returns>
function StyledTaskMessageDlg(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn): Integer; overload;
/// <summary>Displays a styled task message dialog at a specific position</summary>
/// <param name="Title">The dialog title</param>
/// <param name="Msg">The message to display</param>
/// <param name="DlgType">The dialog type</param>
/// <param name="Buttons">The buttons to display</param>
/// <param name="HelpCtx">Help context ID</param>
/// <param name="X">X coordinate for dialog position</param>
/// <param name="Y">Y coordinate for dialog position</param>
/// <returns>The modal result of the clicked button</returns>
function StyledTaskMessageDlgPos(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint;
X: Integer; Y: Integer): Integer; overload;
/// <summary>Displays a styled task message dialog at a specific position with default button</summary>
/// <param name="Title">The dialog title</param>
/// <param name="Msg">The message to display</param>
/// <param name="DlgType">The dialog type</param>
/// <param name="Buttons">The buttons to display</param>
/// <param name="HelpCtx">Help context ID</param>
/// <param name="DefaultButton">The default button</param>
/// <param name="X">X coordinate for dialog position</param>
/// <param name="Y">Y coordinate for dialog position</param>
/// <returns>The modal result of the clicked button</returns>
function StyledTaskMessageDlgPos(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn;
X: Integer; Y: Integer): Integer; overload;
/// <summary>Displays a styled task message dialog with extended options</summary>
/// <param name="Instruction">The instruction/title text</param>
/// <param name="Msg">The message to display</param>
/// <param name="DlgType">The dialog type</param>
/// <param name="Buttons">The buttons to display</param>
/// <param name="HelpCtx">Help context ID</param>
/// <param name="AutoClickDelay">Delay in ms for auto-click (-1 to disable)</param>
/// <param name="UseCommandLinks">When True, displays buttons as command links</param>
/// <returns>The modal result of the clicked button</returns>
function DoStyledTaskMessageDlg(const Instruction, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx : Longint = 0;
const AutoClickDelay: Integer = -1; const UseCommandLinks: Boolean = False): Integer; overload;
/// <summary>Displays a styled task message dialog with position and extended options</summary>
function DoStyledTaskMessageDlgPos(const Instruction, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; X: Integer; Y: Integer;
const AutoClickDelay: Integer = -1; const UseCommandLinks: Boolean = False): Integer; overload;
/// <summary>Displays a styled task message dialog with position, help file and extended options</summary>
function DoStyledTaskMessageDlgPosHelp(const Instruction, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; X: Integer = -1; Y: Integer = -1;
const AutoClickDelay: Integer = -1; const UseCommandLinks: Boolean = False;
const HelpFileName: string = ''): Integer; overload;
/// <summary>Displays a styled task message dialog with all options including default button</summary>
function DoStyledTaskMessageDlgPosHelp(const Instruction, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn;
X: Integer = -1; Y: Integer = -1;
const AutoClickDelay: Integer = -1; const UseCommandLinks: Boolean = False;
const HelpFileName: string = ''): Integer; overload;
/// <summary>Displays a message dialog with position and help support</summary>
function DoMessageDlgPosHelp(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Integer; DefaultButton: TMsgDlgBtn;
X: Integer = -1; Y: Integer = -1;
const AutoClickDelay: Integer = -1; const UseCommandLinks: Boolean = False;
const HelpFileName: string = ''): Integer; overload;
/// <summary>Displays a message dialog with position and help support (without default button)</summary>
function DoMessageDlgPosHelp(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint;
X: Integer = -1; Y: Integer = -1;
const AutoClickDelay: Integer = -1; const UseCommandLinks: Boolean = False;
const HelpFileName: string = ''): Integer; overload;
/// <summary>Displays a simple styled message (replacement for ShowMessage)</summary>
/// <param name="Msg">The message to display</param>
procedure StyledShowMessage(const Msg: string); overload;
/// <summary>Displays a formatted styled message (replacement for ShowMessageFmt)</summary>
/// <param name="Msg">The format string</param>
/// <param name="Params">The format parameters</param>
procedure StyledShowMessageFmt(const Msg: string; Params: array of const); overload;
/// <summary>Sets whether to display title in message dialogs</summary>
/// <param name="AValue">True to display title, False to hide it</param>
procedure SetUseTitleInMessageDlg(AValue: boolean);
/// <summary>Registers a custom dialog launcher implementation</summary>
/// <param name="AShowStyledTaskDialog">The custom launcher interface</param>
/// <param name="AButtonFamily">The button style family to use</param>
procedure RegisterCustomExecute(const AShowStyledTaskDialog: ITaskDialogLauncher;
const AButtonFamily: TStyledButtonFamily = '');
/// <summary>Unregisters the custom dialog launcher</summary>
procedure UnregisterCustomExecute;
/// <summary>Converts a TTaskDialogIcon to TMsgDlgType</summary>
/// <param name="AIcon">The task dialog icon</param>
/// <returns>The corresponding message dialog type</returns>
function GetTaskDlgType(const AIcon: TTaskDialogIcon): TMsgDlgType;
/// <summary>Returns the current dialog font</summary>
/// <returns>The TFont used for dialogs</returns>
function GetDialogFont: TFont;
/// <summary>Returns the current dialog button family</summary>
/// <returns>The style family name</returns>
function GetDialogBtnFamily: TStyledButtonFamily;
/// <summary>Returns the default title for a dialog type</summary>
/// <param name="DlgType">The dialog type</param>
/// <returns>The localized title string</returns>
function GetDialogTypeTitle(const DlgType: TMsgDlgType): string;
/// <summary>Returns the current dialog alpha blend value</summary>
/// <returns>The alpha blend value (0-255)</returns>
function GetDialogAlphaBlendValue: Byte;
/// <summary>Converts a TMsgDlgBtn to TTaskDialogCommonButton</summary>
/// <param name="ABtn">The message dialog button</param>
/// <returns>The corresponding task dialog common button</returns>
function MsgDlgBtnToDefaultBtn(const ABtn: TMsgDlgBtn): TTaskDialogCommonButton;
/// <summary>Initializes styled task dialogs with a custom font</summary>
/// <param name="AFont">The font to use for dialogs</param>
procedure InitializeStyledTaskDialogs(AFont: TFont); overload;
/// <summary>Initializes styled task dialogs with animation setting</summary>
/// <param name="AUseAnimations">True to enable animations (requires Skia4Delphi)</param>
procedure InitializeStyledTaskDialogs(AUseAnimations: Boolean); overload;
/// <summary>Initializes styled task dialogs with button family and options</summary>
/// <param name="ADialogButtonsFamily">The button style family</param>
/// <param name="AUseCommandLinks">True to use command links style</param>
/// <param name="AAutoClickDelay">Auto-click delay in milliseconds (-1 to disable)</param>
procedure InitializeStyledTaskDialogs(
const ADialogButtonsFamily: TStyledButtonFamily = '';
const AUseCommandLinks: Boolean = False;
const AAutoClickDelay: Integer = -1); overload;
/// <summary>Initializes styled task dialogs with full customization options</summary>
/// <param name="AUseTitleInMessageDlg">True to show title in message dialogs</param>
/// <param name="AFont">The font to use for dialogs</param>
/// <param name="AUseCommandLinks">True to use command links style</param>
/// <param name="ADialogButtonsFamily">The button style family</param>
/// <param name="AAlphaBlendValue">Dialog transparency (0-255)</param>
/// <param name="AButtonsWidth">Width of dialog buttons in pixels</param>
/// <param name="AButtonsHeight">Height of dialog buttons in pixels</param>
/// <param name="AAutoClickDelay">Auto-click delay in milliseconds (-1 to disable)</param>
procedure InitializeStyledTaskDialogs(
AUseTitleInMessageDlg: Boolean; AFont: TFont;
const AUseCommandLinks: Boolean = False;
const ADialogButtonsFamily: TStyledButtonFamily = '';
const AAlphaBlendValue: Byte = DEFAULT_STYLEDDIALOG_ALPHABLEND;
const AButtonsWidth: Integer = DEFAULT_STYLEDDIALOG_BUTTONSWIDTH;
const AButtonsHeight: Integer = DEFAULT_STYLEDDIALOG_BUTTONSHEIGHT;
const AAutoClickDelay: Integer = -1); overload;
implementation
uses
System.TypInfo
, System.Math
, System.Types
, System.Rtti
, Vcl.Themes
, Winapi.CommCtrl
, System.WideStrUtils
, Winapi.MultiMon
, System.HelpIntfs
, Vcl.Controls
, Vcl.StdCtrls
, Vcl.ExtCtrls
, Vcl.Consts
, System.RTLConsts
, Winapi.ShellApi
, Vcl.StyledCmpMessages
, Vcl.StyledCmpStrUtils
, Vcl.StyledTaskDialogFormUnit
, Vcl.StyledTaskDialogStdUnit
;
var
_TaskDialogExecute: ITaskDialogLauncher;
_DialogButtonsFamily: TStyledButtonFamily;
_CustomIcons: TStyledDialogIcons;
_UseAnimations: Boolean;
_DialogFont: TFont;
_UseCommandLinks: Boolean;
_UseTitleInMessageDlg: boolean;
_AlphaBlendValue: Byte;
_ButtonsWidth: Integer;
_ButtonsHeight: Integer;
_AutoClickDelay: Integer;
ButtonNames: array[TMsgDlgBtn] of string = (
'Yes', 'No', 'OK', 'Cancel', 'Abort', 'Retry', 'Ignore', 'All', 'NoToAll',
'YesToAll','Help','Close');
ModalResults: array[TMsgDlgBtn] of Integer = (
mrYes, mrNo, mrOk, mrCancel, mrAbort, mrRetry, mrIgnore, mrAll, mrNoToAll,
mrYesToAll, 0, mrClose);
function GetDefaultButton(const Buttons: TMsgDlgButtons): TMsgDlgBtn;
begin
if mbYes in Buttons then Result := TMsgDlgBtn.mbYes
else if mbOK in Buttons then Result := TMsgDlgBtn.mbOK
else if mbNo in Buttons then Result := TMsgDlgBtn.mbNo
else if mbCancel in Buttons then Result := TMsgDlgBtn.mbCancel
else if mbAbort in Buttons then Result := TMsgDlgBtn.mbAbort
else if mbRetry in Buttons then Result := TMsgDlgBtn.mbRetry
else if mbIgnore in Buttons then Result := TMsgDlgBtn.mbIgnore
else if mbAll in Buttons then Result := TMsgDlgBtn.mbAll
else if mbNoToAll in Buttons then Result := TMsgDlgBtn.mbNoToAll
else if mbYesToAll in Buttons then Result := TMsgDlgBtn.mbYesToAll
else if mbHelp in Buttons then Result := TMsgDlgBtn.mbHelp
else if mbClose in Buttons then Result := TMsgDlgBtn.mbClose
else Result := TMsgDlgBtn.mbRetry;
end;
//Internal Function to Display a Styled TaskMessage Dialog
//using a TStyledTaskDialog component
function InternalDoTaskMessageDlgPosHelp(const Instruction, Msg: string;
const DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint;
const X, Y: Integer;
const HelpFileName: string;
const DefaultButton: TMsgDlgBtn;
const AutoClickDelay: Integer;
const UseCommandLinks: Boolean;
const UseAlternateTaskDlgFlags: Boolean;
const AlternateTaskDlgFlags: TTaskDialogFlags;
const CustomButtonCaptions: array of string): Integer;
const
IconMap: array[TMsgDlgType] of TTaskDialogIcon = (tdiWarning, tdiError,
tdiInformation, tdiQuestion, tdiShield);
LModalResults: array[TMsgDlgBtn] of Integer = (mrYes, mrNo, mrOk, mrCancel,
mrAbort, mrRetry, mrIgnore, mrAll, mrNoToAll, mrYesToAll, mrHelp, mrClose);
var
DlgBtn: TMsgDlgBtn;
LTaskDialog: TStyledTaskDialog;
LTaskDialogButtonItem: TTaskDialogButtonItem;
LCommandLinkPresent: Boolean;
LIndex: Integer;
begin
//At least OK Button
if Buttons = [] then
Buttons := [TMsgDlgBtn.mbOK];
Application.ModalStarted;
LTaskDialog := TStyledTaskDialog.Create(nil);
try
//Assign custom position to Dialog
LTaskDialog.Position := TPoint.Create(X, Y);
//Reset default CommonButtons
LTaskDialog.CommonButtons := [];
//To inform the Dialog Form to use the Default Button specified in MessageDlg
LTaskDialog.FUseMessageDefaultButton := True;
LTaskDialog.FMessageDefaultButton := DefaultButton;
LTaskDialog.UseAnimations := _UseAnimations;
LTaskDialog.AutoClick := AutoClickDelay > 0;
if LTaskDialog.AutoClick then
LTaskDialog.AutoClickDelay := AutoClickDelay;
if Buttons <> [TMsgDlgBtn.mbOK] then
LTaskDialog.UseCommandLinks := UseCommandLinks
else
LTaskDialog.UseCommandLinks := False;
if UseAlternateTaskDlgFlags then
LTaskDialog.Flags := AlternateTaskDlgFlags; //Replace the default Flags to AlternateTaskDlgFlags.
// Assign buttons
LIndex := -1;
LCommandLinkPresent := False;
for DlgBtn := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do
begin
//Check for particular case using command links:
if LTaskDialog.UseCommandLinks then
begin
//if mbYes and mbOK are both present with "UseCommandLinks", then tcbOk is used as CommonButton
if (DlgBtn = TMsgDlgBtn.mbOK) and (DlgBtn in Buttons) and (TMsgDlgBtn.mbYes in Buttons) then
begin
LTaskDialog.CommonButtons := LTaskDialog.CommonButtons + [TTaskDialogCommonButton.tcbOk];
Continue;
end;
//if mbNo and mbCancel are both present with "UseCommandLinks", then tcbCancel is used as CommonButton
if (DlgBtn = TMsgDlgBtn.mbCancel) and (DlgBtn in Buttons) and (TMsgDlgBtn.mbNo in Buttons) then
begin
LTaskDialog.CommonButtons := LTaskDialog.CommonButtons + [TTaskDialogCommonButton.tcbCancel];
Continue;
end;
end;
if DlgBtn in Buttons then
begin
//if a Button is "common", add only if not using CommandLinks
LTaskDialogButtonItem := LTaskDialog.Buttons.Add as TTaskDialogButtonItem;
Inc(LIndex);
if LIndex <= High(CustomButtonCaptions) then
LTaskDialogButtonItem.Caption := CustomButtonCaptions[LIndex]
else
begin
//use Captions defined in Vcl.StyledCmpMessages.pas
case DlgBtn of
mbYes: LTaskDialogButtonItem.Caption := STR_YES;
mbNo: LTaskDialogButtonItem.Caption := STR_NO;
mbOK: LTaskDialogButtonItem.Caption := STR_OK;
mbCancel: LTaskDialogButtonItem.Caption := STR_CANCEL;
mbAbort: LTaskDialogButtonItem.Caption := STR_ABORT;
mbRetry: LTaskDialogButtonItem.Caption := STR_RETRY;
mbIgnore: LTaskDialogButtonItem.Caption := STR_IGNORE;
mbAll: LTaskDialogButtonItem.Caption := STR_ALL;
mbNoToAll: LTaskDialogButtonItem.Caption := STR_NOTOALL;
mbYesToAll: LTaskDialogButtonItem.Caption := STR_YESTOALL;
mbHelp: LTaskDialogButtonItem.Caption := STR_HELP;
mbClose: LTaskDialogButtonItem.Caption := STR_CLOSE;
end;
end;
//Set CommandLinkHint based on DlgBtn when using a Warning or Confirmation
if DlgType in [TMsgDlgType.mtWarning, TMsgDlgType.mtConfirmation] then
case DlgBtn of
mbOK: LTaskDialogButtonItem.CommandLinkHint := Format('%s %s', [STR_CONFIRM, STR_THE_OPERATION]);
mbYes: LTaskDialogButtonItem.CommandLinkHint := Format('%s %s', [STR_CONFIRM, STR_THE_OPERATION]);
mbNo: LTaskDialogButtonItem.CommandLinkHint := Format('%s %s', [STR_CANCEL, STR_THE_OPERATION]);
mbCancel: LTaskDialogButtonItem.CommandLinkHint := Format('%s %s', [STR_CANCEL, STR_THE_OPERATION]);
mbAbort: LTaskDialogButtonItem.CommandLinkHint := Format('%s %s', [STR_ABORT, STR_THE_OPERATION]);
mbRetry: LTaskDialogButtonItem.CommandLinkHint := Format('%s %s', [STR_RETRY, STR_THE_OPERATION]);
mbIgnore: LTaskDialogButtonItem.CommandLinkHint := Format('%s %s', [STR_IGNORE, STR_THE_OPERATION]);
mbNoToAll: LTaskDialogButtonItem.CommandLinkHint := Format('%s %s', [STR_CANCEL, STR_THE_OPERATION]);
mbYesToAll: LTaskDialogButtonItem.CommandLinkHint := Format('%s %s', [STR_CONFIRM, STR_THE_OPERATION]);
end;
if LTaskDialogButtonItem.CommandLinkHint <> '' then
LCommandLinkPresent := True;
if DlgBtn = DefaultButton then
LTaskDialogButtonItem.Default := True;
LTaskDialogButtonItem.ModalResult := LModalResults[DlgBtn];
end;
end;
//use Captions defined in Vcl.StyledCmpMessages.pas
LTaskDialog.Caption := GetDialogTypeTitle(DlgType);
if Not UseAlternateTaskDlgFlags and Application.UseRightToLeftReading then
LTaskDialog.Flags := LTaskDialog.Flags + [tfRtlLayout];
if pos('<A HREF=',Msg) > 0 then
LTaskDialog.Flags := LTaskDialog.Flags + [tfEnableHyperlinks];
if LTaskDialog.UseCommandLinks and LCommandLinkPresent then
LTaskDialog.Flags := LTaskDialog.Flags + [tfUseCommandLinks];
LTaskDialog.HelpContext := HelpCtx;
LTaskDialog.HelpFile := HelpFileName;
LTaskDialog.MainIcon := IconMap[DlgType];
if (X <> -1) and (Y <> -1) then
LTaskDialog.Position := Point(X, Y);
LTaskDialog.Text := Msg;
if (Instruction = '') and (LTaskDialog.UseTitleInMessageDlg) then
LTaskDialog.Title := LTaskDialog.Caption
else
LTaskDialog.Title := Instruction;
// Show dialog and return result
Result := mrNone;
if LTaskDialog.Execute then
Result := LTaskDialog.ModalResult;
finally
LTaskDialog.Free;
Application.ModalFinished;
end;
end;
function DoStyledTaskMessageDlg(const Instruction, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint = 0;
const AutoClickDelay: Integer = -1; const UseCommandLinks: Boolean = False): Integer; overload;
begin
Result := InternalDoTaskMessageDlgPosHelp(Instruction, Msg, DlgType,
Buttons, HelpCtx, -1, -1, '', GetDefaultButton(Buttons),
AutoClickDelay, UseCommandLinks, False, [], []);
end;
function DoStyledTaskMessageDlgPos(const Instruction, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; X: Integer; Y: Integer;
const AutoClickDelay: Integer = -1; const UseCommandLinks: Boolean = False): Integer; overload;
begin
Result := InternalDoTaskMessageDlgPosHelp(Instruction, Msg, DlgType,
Buttons, HelpCtx, X, Y, '', GetDefaultButton(Buttons),
AutoClickDelay, UseCommandLinks, False, [], []);
end;
function DoStyledTaskMessageDlgPosHelp(const Instruction, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; X: Integer = -1; Y: Integer = -1;
const AutoClickDelay: Integer = -1; const UseCommandLinks: Boolean = False;
const HelpFileName: string = ''): Integer; overload;
begin
Result := InternalDoTaskMessageDlgPosHelp(Instruction, Msg, DlgType,
Buttons, HelpCtx, X, Y, HelpFileName, GetDefaultButton(Buttons),
AutoClickDelay, UseCommandLinks, False, [], []);
end;
function DoStyledTaskMessageDlgPosHelp(const Instruction, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn;
X: Integer = -1; Y: Integer = -1;
const AutoClickDelay: Integer = -1; const UseCommandLinks: Boolean = False;
const HelpFileName: string = ''): Integer; overload;
begin
Result := InternalDoTaskMessageDlgPosHelp(Instruction, Msg, DlgType,
Buttons, HelpCtx, X, Y, HelpFileName, DefaultButton,
AutoClickDelay, UseCommandLinks, False, [], []);
end;
function DoMessageDlgPosHelp(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Integer; DefaultButton: TMsgDlgBtn;
X: Integer = -1; Y: Integer = -1;
const AutoClickDelay: Integer = -1; const UseCommandLinks: Boolean = False;
const HelpFileName: string = ''): Integer; overload;
begin
Result := InternalDoTaskMessageDlgPosHelp('', Msg, DlgType,
Buttons, HelpCtx, X, Y, HelpFileName, DefaultButton,
AutoClickDelay, UseCommandLinks, False, [], []);
end;
function DoMessageDlgPosHelp(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint;
X: Integer = -1; Y: Integer = -1;
const AutoClickDelay: Integer = -1; const UseCommandLinks: Boolean = False;
const HelpFileName: string = ''): Integer; overload;
begin
Result := InternalDoTaskMessageDlgPosHelp('', Msg, DlgType,
Buttons, HelpCtx, X, Y, HelpFileName, GetDefaultButton(Buttons),
AutoClickDelay, UseCommandLinks, False, [], []);
end;
function GetDialogAlphaBlendValue: Byte;
begin
Result := _AlphaBlendValue;
end;
function GetDialogButtonsWidth: Integer;
begin
Result := _ButtonsWidth;
end;
function GetDialogFont: TFont;
begin
Result := _DialogFont;
end;
function GetDialogBtnFamily: TStyledButtonFamily;
begin
Result := _DialogButtonsFamily;
end;
function StyledMessageDlg(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer; overload;
begin
Result := DoStyledTaskMessageDlgPosHelp('', Msg, DlgType, Buttons, HelpCtx,
-1, -1, _AutoClickDelay, _UseCommandLinks);
end;
function StyledMessageDlg(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer;
begin
Result := DoStyledTaskMessageDlgPosHelp(Title, Msg, DlgType, Buttons, HelpCtx);
end;
function StyledMessageDlg(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn): Integer; overload;
begin
Result := DoStyledTaskMessageDlgPosHelp(Title, Msg, DlgType, Buttons, HelpCtx, DefaultButton);
end;
function StyledMessageDlgPos(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; DefaultButton: TMsgDlgBtn; HelpCtx: Longint;
X: Integer; Y: Integer): Integer; overload;
begin
Result := DoStyledTaskMessageDlgPosHelp('', Msg, DlgType, Buttons, HelpCtx,
DefaultButton, X, Y);
end;
function StyledMessageDlg(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn): Integer; overload;
begin
Result := DoStyledTaskMessageDlgPosHelp('', Msg, DlgType, Buttons, HelpCtx, DefaultButton);
end;
function StyledMessageDlg(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn;
CustomButtonCaptions: array of string): Integer; overload;
begin
Result := InternalDoTaskMessageDlgPosHelp('', Msg, DlgType, Buttons, HelpCtx,
-1, -1, '', DefaultButton, -1,
False, False, [], CustomButtonCaptions);
end;
function StyledMessageDlgPos(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; X: Integer; Y: Integer): Integer;
begin
Result := DoStyledTaskMessageDlgPosHelp('', Msg, DlgType, Buttons, HelpCtx, X, Y);
end;
function StyledMessageDlgPos(const Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn;
X: Integer; Y: Integer): Integer;
begin
Result := DoStyledTaskMessageDlgPosHelp('', Msg, DlgType, Buttons,
HelpCtx, DefaultButton, X, Y, -1, _UseCommandLinks, '');
end;
procedure InitializeStyledTaskDialogs(AUseAnimations: Boolean);
begin
_UseAnimations := AUseAnimations;
end;
procedure InitializeStyledTaskDialogs(AFont: TFont);
begin
if Assigned(AFont) then
begin
if not Assigned(_DialogFont) then
_DialogFont := TFont.Create;
_DialogFont.Assign(AFont);
end
else
FreeAndNil(_DialogFont);
end;
procedure InitializeStyledTaskDialogs(
const ADialogButtonsFamily: TStyledButtonFamily = '';
const AUseCommandLinks: Boolean = False;
const AAutoClickDelay: Integer = -1); overload;
begin
InitializeStyledTaskDialogs(True, Screen.MessageFont,
AUseCommandLinks, ADialogButtonsFamily,
DEFAULT_STYLEDDIALOG_ALPHABLEND,
DEFAULT_STYLEDDIALOG_BUTTONSWIDTH,
DEFAULT_STYLEDDIALOG_BUTTONSHEIGHT,
AAutoClickDelay);
end;
procedure InitializeStyledTaskDialogs(AUseTitleInMessageDlg: Boolean; AFont: TFont;
const AUseCommandLinks: Boolean = False;
const ADialogButtonsFamily: TStyledButtonFamily = '';
const AAlphaBlendValue: Byte = DEFAULT_STYLEDDIALOG_ALPHABLEND;
const AButtonsWidth: Integer = DEFAULT_STYLEDDIALOG_BUTTONSWIDTH;
const AButtonsHeight: Integer = DEFAULT_STYLEDDIALOG_BUTTONSHEIGHT;
const AAutoClickDelay: Integer = -1);
begin
CheckValue('TStyledTaskDialog.ButtonsHeight', AButtonsHeight,
MIN_STYLEDDIALOG_BUTTONSSIZE, MAX_STYLEDDIALOG_BUTTONSHEIGHT);
CheckValue('TStyledTaskDialog.SetButtonsWidth', AButtonsWidth,
MIN_STYLEDDIALOG_BUTTONSSIZE, MAX_STYLEDDIALOG_BUTTONSWIDTH);
if Assigned(AFont) then
begin
if not Assigned(_DialogFont) then
_DialogFont := TFont.Create;
_DialogFont.Assign(AFont);
end
else
FreeAndNil(_DialogFont);
_UseCommandLinks := AUseCommandLinks;
_UseTitleInMessageDlg := AUseTitleInMessageDlg;
_DialogButtonsFamily := ADialogButtonsFamily;
_AlphaBlendValue := AAlphaBlendValue;
_ButtonsWidth := AButtonsWidth;
_ButtonsHeight := AButtonsHeight;
_AutoClickDelay := AAutoClickDelay;
end;
procedure UnregisterCustomIcons;
begin
_CustomIcons[mtWarning] := nil;
_CustomIcons[mtError] := nil;
_CustomIcons[mtInformation] := nil;
_CustomIcons[mtConfirmation] := nil;
_CustomIcons[mtCustom] := nil;
end;
procedure RegisterCustomIcons(const ACustomIcons: TStyledDialogIcons);
begin
UnregisterCustomIcons;
_CustomIcons := ACustomIcons;
end;
procedure SetUseTitleInMessageDlg(AValue: boolean);
begin
_UseTitleInMessageDlg := AValue;
end;
procedure RegisterCustomExecute(const AShowStyledTaskDialog: ITaskDialogLauncher;
const AButtonFamily: TStyledButtonFamily = '');
begin
_TaskDialogExecute := AShowStyledTaskDialog;
end;
procedure UnRegisterCustomExecute;
begin
_TaskDialogExecute := nil;
end;
function GetTaskDlgType(
const AIcon: TTaskDialogIcon): TMsgDlgType;
begin
if AIcon = tdiNone then
Result := TMsgDlgType.mtCustom
else if AIcon = tdiWarning then
Result := TMsgDlgType.mtWarning
else if AIcon = tdiError then
Result := TMsgDlgType.mtError
else if AIcon = tdiInformation then
Result := TMsgDlgType.mtInformation
else if AIcon = tdiQuestion then
Result := TMsgDlgType.mtConfirmation
else if AIcon = tdiShield then
Result := TMsgDlgType.mtCustom
else
Result := TMsgDlgType.mtInformation;
end;
function StyledTaskMessageDlg(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint): Integer; overload;
begin
Result := DoStyledTaskMessageDlgPosHelp(Title, Msg, DlgType, Buttons, HelpCtx,
-1, -1, _AutoClickDelay, _UseCommandLinks);
end;
function StyledTaskMessageDlg(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn): Integer; overload;
begin
Result := DoStyledTaskMessageDlgPosHelp(Title, Msg, DlgType, Buttons, HelpCtx, DefaultButton,
-1, -1, _AutoClickDelay, _UseCommandLinks, '');
end;
function StyledTaskDlgPos(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; X: Integer = -1; Y: Integer = -1): Integer;
begin
Result := DoStyledTaskMessageDlgPosHelp(Title, Msg, DlgType, Buttons, HelpCtx, X, Y,
_AutoClickDelay, _UseCommandLinks, '');
end;
function StyledTaskMessageDlgPos(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; X: Integer; Y: Integer): Integer;
begin
Result := DoStyledTaskMessageDlgPosHelp(Title, Msg, DlgType, Buttons, HelpCtx, X, Y,
_AutoClickDelay, _UseCommandLinks, '');
end;
function StyledTaskDlgPos(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; DefaultButton: TMsgDlgBtn; HelpCtx: Longint;
X: Integer = -1; Y: Integer = -1): Integer;
begin
Result := StyledTaskMessageDlgPos(Title, Msg, DlgType, Buttons, HelpCtx, DefaultButton, X, Y);
end;
function StyledTaskMessageDlgPos(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; DefaultButton: TMsgDlgBtn;
X: Integer; Y: Integer): Integer;
var
MsgWithTitle: string;
begin
if Title <> '' then
MsgWithTitle := UpperCase(Title)+sLineBreak+Msg
else
MsgWithTitle := Msg;
Result := StyledMessageDlgPos(MsgWithTitle, DlgType, Buttons, HelpCtx, DefaultButton, -1, -1);
end;
function StyledTaskMessageDlgPosHelp(const Title, Msg: string; DlgType: TMsgDlgType;
Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer;
const HelpFileName: string; DefaultButton: TMsgDlgBtn; CustomButtonCaptions: array of string): Integer;
begin
Result := InternalDoTaskMessageDlgPosHelp(Title, Msg, DlgType, Buttons, HelpCtx,
X, Y, HelpFileName, DefaultButton, -1, _UseCommandLinks, False, [], []);
end;
procedure StyledShowMessage(const Msg: string); overload;