-
Notifications
You must be signed in to change notification settings - Fork 2
/
MyDialogs.pas
1204 lines (1054 loc) · 35 KB
/
MyDialogs.pas
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
{*
MyDialogs.pas Custom message dialogs to support loacalization
--------------
Begin: 2005/03/02
Last revision: $Date: 2010-03-01 04:29:06 $ $Author: areeves $
Version number: $Revision: 1.34 $
Code Documentation Tags: Begin 2009-08-14, Last Revision: 2009-08-14
Project: APHI General Purpose Delphi Library
Website: http://www.naadsm.org/opensource/delphi
Author: Aaron Reeves <Aaron.Reeves@colostate.edu>
--------------------------------------------------
Copyright (C) 2005 - 2010 Animal Population Health Institute, Colorado State University
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
}
(*
Documentation generation tags begin with {* or ///
Replacing these with (* or // foils the documentation generator
*)
unit MyDialogs;
interface
uses
Windows,
SysUtils,
Dialogs,
Controls
;
type
/// enumerations of image style for message dialogs
TImageStyle = (
IMGUnspecified,
IMGQuestion,
IMGWarning,
IMGInformation,
IMGCritical,
IMGSuccess
);
function msgDlg(
const msg: string;
buttons: TMsgDlgButtons;
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil
): integer;
function msgYesNoCancel(
const msg: string;
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil
): integer;
function msgYesNo(
const msg: string;
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil
): integer;
function msgOK(
const msg: string;
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil
): integer;
function msgOKCancel(
const msg: string;
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil
): integer;
procedure msgExceptionOK(
msg: string;
e: exception = nil;
parent: TWinControl = nil
);
function msgInput(
const msg: string;
const regexp: string = '';
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil;
default: string = ''
): string;
function msgInputOKCancel(
const msg: string;
var str: string;
const regexp: string = '';
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil
): integer;
function msgYesNoCheckbox(
const msg: string;
const checkboxLabel: string;
out checkboxValue: boolean;
const caption: string = '';
const imageStyle: TImageStyle = IMGUnspecified;
const parent: TWinControl = nil
): integer;
function msgOKCheckbox(
const msg: string;
const checkboxLabel: string;
out checkboxValue: boolean;
const caption: string = '';
const imageStyle: TImageStyle = IMGUnspecified;
const parent: TWinControl = nil
): integer;
procedure testImages();
(*
// "Private" declarations
procedure translateMyDialogs();
_currentLanguage: TI88nLanguageCode;
*)
implementation
{$R 'graphics\Graphics.res' 'graphics\Graphics.rc'}
// Order of items given in the implementation section:
// - Miscellaneous types borrowed from Dialogs (Borland Delphi Visual Component Library)
// - A modifed version of the function Dialogs.CreateMessageDialog
// - Implementation of the custom message dialog functions listed in the interface
// - Some comments and notes on how to use the CreateMessageDialog function
uses
Forms,
Classes,
Graphics,
ExtCtrls,
StdCtrls,
Consts,
Dlgs,
Math,
REEdit,
MyStrUtils,
ImageResources,
DebugWindow,
I88n
;
var
_currentLanguage: TI88nLanguageCode; /// localization language - english or spanish
//----------------------------------------------------------------------------------
// Copied directly from Dialogs
//----------------------------------------------------------------------------------
(*
type
TMsgDlgType = (mtWarning, mtError, mtInformation, mtConfirmation, mtCustom);
TMsgDlgBtn = (mbYes, mbNo, mbOK, mbCancel, mbAbort, mbRetry, mbIgnore,
mbAll, mbNoToAll, mbYesToAll, mbHelp);
TMsgDlgButtons = set of TMsgDlgBtn;
*)
type
/// Form that the message dialogs use
TMessageForm = class(TForm)
private
Message: TLabel; /// label component for message
procedure HelpButtonClick(Sender: TObject);
protected
procedure CustomKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure WriteToClipBoard(Text: String);
function GetFormText: String;
public
constructor CreateNew(AOwner: TComponent); reintroduce;
end;
{*
Constructor for message dialogs
@param Component owning the dialog form
}
constructor TMessageForm.CreateNew(AOwner: TComponent);
var
NonClientMetrics: TNonClientMetrics;
begin
inherited CreateNew(AOwner);
NonClientMetrics.cbSize := sizeof(NonClientMetrics);
if SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, @NonClientMetrics, 0) then
Font.Handle := CreateFontIndirect(NonClientMetrics.lfMessageFont);
end;
{*
Event handler for msg dialog's Help button
@param The instance of the help button component clicked
}
procedure TMessageForm.HelpButtonClick(Sender: TObject);
begin
Application.HelpContext(HelpContext);
end;
{*
Beeps and writes the message dialog contents (message and button captions) to the clipboard
@param Sender An instance of the message dialog form
@param Key Key 'C', any other key does nothing
@param Shift Whether the Ctrl key is down for key combo Ctrl-C
}
procedure TMessageForm.CustomKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
begin
if (Shift = [ssCtrl]) and (Key = Word('C')) then
begin
Beep;
WriteToClipBoard(GetFormText);
end;
end;
{*
Sends Text to the Windows clipboard (supports copy/paste operations between applications)
@param Text The text to write to the Windows clipboard
}
procedure TMessageForm.WriteToClipBoard(Text: String);
var
Data: THandle;
DataPtr: Pointer;
begin
if OpenClipBoard(0) then
begin
try
Data := GlobalAlloc(GMEM_MOVEABLE+GMEM_DDESHARE, Length(Text) + 1);
try
DataPtr := GlobalLock(Data);
try
Move(PChar(Text)^, DataPtr^, Length(Text) + 1);
EmptyClipBoard;
SetClipboardData(CF_TEXT, Data);
finally
GlobalUnlock(Data);
end;
except
GlobalFree(Data);
raise;
end;
finally
CloseClipBoard;
end;
end
else
raise Exception.CreateRes(@SCannotOpenClipboard);
end;
{*
Returns information about the message dialog contents
@return The contents of the button(s) caption and the dialog's message
}
function TMessageForm.GetFormText: String;
var
DividerLine, ButtonCaptions: string;
I: integer;
begin
DividerLine := StringOfChar('-', 27) + sLineBreak;
for I := 0 to ComponentCount - 1 do
if Components[I] is TButton then
ButtonCaptions := ButtonCaptions + TButton(Components[I]).Caption +
StringOfChar(' ', 3);
ButtonCaptions := StringReplace(ButtonCaptions,'&','', [rfReplaceAll]);
Result := Format('%s%s%s%s%s%s%s%s%s%s', [DividerLine, Caption, sLineBreak,
DividerLine, Message.Caption, sLineBreak, DividerLine, ButtonCaptions,
sLineBreak, DividerLine]);
end;
{*
Returns the average width of an alphabetic character using the current font
@param Canvas Drawing area of the dialog form
@return The average width of a font character as the X coordinate of a TPoint
}
function GetAveCharSize(Canvas: TCanvas): TPoint;
var
I: Integer;
Buffer: array[0..51] of Char;
begin
for I := 0 to 25 do Buffer[I] := Chr(I + Ord('A'));
for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));
GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));
Result.X := Result.X div 52;
end;
var
/// Array of pointers to the captions for types of Windows message dialogs
Captions: array[TMsgDlgType] of Pointer = (@SMsgDlgWarning, @SMsgDlgError,
@SMsgDlgInformation, @SMsgDlgConfirm, nil);
/// Array of pointers to the Icon IDs for Windows message dialogs
IconIDs: array[TMsgDlgType] of PChar = (IDI_EXCLAMATION, IDI_HAND,
IDI_ASTERISK, IDI_QUESTION, nil);
/// Array of Button names/types for Windows message dialogs
ButtonNames: array[TMsgDlgBtn] of string = (
'Yes', 'No', 'OK', 'Cancel', 'Abort', 'Retry', 'Ignore', 'All', 'NoToAll',
'YesToAll', 'Help');
/// Array of Modal results (enumerated types) for Windows message dialogs
ModalResults: array[TMsgDlgBtn] of Integer = (
mrYes, mrNo, mrOk, mrCancel, mrAbort, mrRetry, mrIgnore, mrAll, mrNoToAll,
mrYesToAll, 0);
var
/// Array for the widths of Windows message dialog buttons
ButtonWidths : array[TMsgDlgBtn] of integer; // initialized to zero
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
// Variables and functions for I88n support
//----------------------------------------------------------------------------------
var
myMsgDlgWarning: string; ///for I88n support
myMsgDlgError: string; ///for I88n support
myMsgDlgInformation: string; ///for I88n support
myMsgDlgConfirm: string; ///for I88n support
myMsgDlgYes: string; ///for I88n support
myMsgDlgNo: string; ///for I88n support
myMsgDlgOK: string; ///for I88n support
myMsgDlgCancel: string; ///for I88n support
myMsgDlgHelp: string; ///for I88n support
myMsgDlgHelpNone: string; ///for I88n support
myMsgDlgHelpHelp: string; ///for I88n support
myMsgDlgAbort: string; ///for I88n support
myMsgDlgRetry: string; ///for I88n support
myMsgDlgIgnore: string; ///for I88n support
myMsgDlgAll: string; ///for I88n support
myMsgDlgNoToAll: string; ///for I88n support
myMsgDlgYesToAll: string; ///for I88n support
myButtonCaptions: array[TMsgDlgBtn] of string; ///translations for I88n support
///for I88n support, translates the message dialog button captions
procedure translateMyDialogs();
begin
myMsgDlgWarning := tr( 'Warning' );
myMsgDlgError := tr( 'Error' );
myMsgDlgInformation := tr( 'Information' );
myMsgDlgConfirm := tr( 'Confirm' );
myMsgDlgYes := tr( '&Yes' );
myMsgDlgNo := tr( '&No' );
myMsgDlgOK := tr( 'OK' );
myMsgDlgCancel := tr( 'Cancel' );
myMsgDlgHelp := tr( '&Help' );
myMsgDlgHelpNone := tr( 'No help available' );
myMsgDlgHelpHelp := tr( 'Help' );
myMsgDlgAbort := tr( '&Abort' );
myMsgDlgRetry := tr( '&Retry' );
myMsgDlgIgnore := tr( '&Ignore' );
myMsgDlgAll := tr( '&All' );
myMsgDlgNoToAll := tr( 'N&o to All' );
myMsgDlgYesToAll := tr( 'Yes to &All' );
myButtonCaptions[mbYes] := myMsgDlgYes;
myButtonCaptions[mbNo] := myMsgDlgNo;
myButtonCaptions[mbOK] := myMsgDlgOK;
myButtonCaptions[mbCancel] := myMsgDlgCancel;
myButtonCaptions[mbAbort] := myMsgDlgAbort;
myButtonCaptions[mbRetry] := myMsgDlgRetry;
myButtonCaptions[mbIgnore] := myMsgDlgIgnore;
myButtonCaptions[mbAll] := myMsgDlgAll;
myButtonCaptions[mbNoToAll] := myMsgDlgNoToAll;
myButtonCaptions[mbYesToAll] := myMsgDlgYesToAll;
myButtonCaptions[mbHelp] := myMsgDlgHelp;
_currentLanguage := i88nLanguage();
end
;
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
// Modified from Dialogs.CreateMessageDialog
//----------------------------------------------------------------------------------
{*
Creates and returns a message dialog form, translated to I88n language
Called by function msgDlg, which implements this function
@param dlgCaption Caption for dialog
@param Msg Message for dialog
@param Buttons Buttons on dialog
@param parentForm Parent form of dialog (or nil if not launched from a form)
@param bitmap Icon to show on dialog
@param msgBottom Pixel location of the bottom of the message
@param buttonBottom Pixel location of the bottom of the button row
@param savedSpace Space for vertical margin ??
@param margin Margin around what ??
@param messageWidth Width of message string
@return Message dialog form
}
function createMsgDlg(
const dlgCaption: string;
const Msg: string;
Buttons: TMsgDlgButtons;
parentForm: TWinControl = nil;
bitmap: TBitmap = nil;
msgBottom: PInteger = nil;
buttonBottom: PInteger = nil;
savedSpace: PInteger = nil;
margin: PInteger = nil;
messageWidth: PInteger = nil
): TForm;
const
mcHorzMargin = 8;
mcVertMargin = 8;
mcHorzSpacing = 10;
mcVertSpacing = 10;
mcButtonWidth = 50;
mcButtonHeight = 14;
mcButtonSpacing = 4;
var
DialogUnits: TPoint;
HorzMargin, VertMargin, HorzSpacing, VertSpacing: Integer;
ButtonWidth, ButtonHeight, ButtonSpacing, ButtonCount, ButtonGroupWidth: Integer;
IconTextWidth, IconTextHeight, X, ALeft: Integer;
B, DefaultButton, CancelButton: TMsgDlgBtn;
//IconID: PChar;
TextRect: TRect;
bottomOfMessage: integer;
begin
if( i88nLanguage() <> _currentLanguage ) then
translateMyDialogs()
;
bottomOfMessage := 0;
if( parentForm = nil ) then
Result := TMessageForm.CreateNew(Application)
else
result := TMessageForm.createNew( parentForm )
;
with Result do
begin
BiDiMode := Application.BiDiMode;
BorderStyle := bsDialog;
Canvas.Font := Font;
KeyPreview := True;
OnKeyDown := TMessageForm(Result).CustomKeyDown;
DialogUnits := GetAveCharSize(Canvas);
HorzMargin := MulDiv(mcHorzMargin, DialogUnits.X, 4);
VertMargin := MulDiv(mcVertMargin, DialogUnits.Y, 8);
HorzSpacing := MulDiv(mcHorzSpacing, DialogUnits.X, 4);
VertSpacing := MulDiv(mcVertSpacing, DialogUnits.Y, 8);
ButtonWidth := MulDiv(mcButtonWidth, DialogUnits.X, 4);
for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do
begin
if B in Buttons then
begin
if ButtonWidths[B] = 0 then
begin
TextRect := Rect(0,0,0,0);
Windows.DrawText( canvas.handle,
PChar(myButtonCaptions[B]), -1,
TextRect, DT_CALCRECT or DT_LEFT or DT_SINGLELINE or
DrawTextBiDiModeFlagsReadingOnly);
with TextRect do ButtonWidths[B] := Right - Left + 8;
end;
if ButtonWidths[B] > ButtonWidth then
ButtonWidth := ButtonWidths[B];
end;
end;
ButtonHeight := MulDiv(mcButtonHeight, DialogUnits.Y, 8);
ButtonSpacing := MulDiv(mcButtonSpacing, DialogUnits.X, 4);
SetRect(TextRect, 0, 0, Screen.Width div 2, 0);
DrawText(Canvas.Handle, PChar(Msg), Length(Msg)+1, TextRect,
DT_EXPANDTABS or DT_CALCRECT or DT_WORDBREAK or
DrawTextBiDiModeFlagsReadingOnly);
//IconID := IconIDs[DlgType];
IconTextWidth := TextRect.Right;
IconTextHeight := TextRect.Bottom;
(*
if IconID <> nil then
begin
Inc(IconTextWidth, 32 + HorzSpacing);
if IconTextHeight < 32 then IconTextHeight := 32;
end
;
*)
//--------------------------
// Make room for the bitmap
//--------------------------
if bitmap <> nil then
begin
Inc(IconTextWidth, bitmap.Width + HorzSpacing);
if IconTextHeight < bitmap.Height then IconTextHeight := bitmap.Height;
end
;
ButtonCount := 0;
for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do
if B in Buttons then Inc(ButtonCount)
;
ButtonGroupWidth := 0;
if ButtonCount <> 0 then ButtonGroupWidth := ButtonWidth * ButtonCount + ButtonSpacing * (ButtonCount - 1);
ClientWidth := Max(IconTextWidth, ButtonGroupWidth) + HorzMargin * 2;
ClientHeight := IconTextHeight + ButtonHeight + VertSpacing + VertMargin * 2;
// ------------------------
// Set the screen position
//-------------------------
if( parentForm = nil ) then // center on the screen
begin
Left := (Screen.Width div 2) - (Width div 2);
Top := (Screen.Height div 2) - (Height div 2);
end
else // Center relative to the parent form
begin
left := parentForm.Left + ( ( parentForm.Width - width ) div 2 );
top := parentForm.Top + ( ( parentForm.Height - height ) div 2 );
end
;
//----------------
// Set the caption
//-----------------
if( dlgCaption = '' ) then
caption := Application.Title
else
caption := dlgCaption
;
// ------------------------
// Show the bitmap
//-------------------------
//if IconID <> nil then
if bitmap <> nil then
begin
with TImage.Create( Result ) do
begin
Name := 'Image';
Parent := Result;
Transparent := true;
Picture.Bitmap.Handle := bitmap.Handle;
//Picture.Icon.Handle := LoadIcon(0, IconID);
SetBounds(HorzMargin, VertMargin, bitmap.Height, bitmap.Width);
bottomOfMessage := top + height;
if( nil <> messageWidth ) then messageWidth^ := bitmap.Width;
end
;
end
;
// ------------------------
// Show the message
//-------------------------
TMessageForm(Result).Message := TLabel.Create(Result);
with TMessageForm(Result).Message do
begin
Name := 'Message';
Parent := Result;
WordWrap := True;
Caption := Msg;
BoundsRect := TextRect;
BiDiMode := Result.BiDiMode;
ALeft := IconTextWidth - TextRect.Right + HorzMargin;
if UseRightToLeftAlignment then
ALeft := Result.ClientWidth - ALeft - Width
;
SetBounds( ALeft, VertMargin, TextRect.Right, TextRect.Bottom );
if( bottomOfMessage < top + height ) then bottomOfMessage := top + height;
if( nil <> messageWidth ) then messageWidth^ := + messageWidth^ + horzMargin + width;
end
;
// ------------------------
// Set the default button
//-------------------------
if mbOk in Buttons then DefaultButton := mbOk else
if mbYes in Buttons then DefaultButton := mbYes else
DefaultButton := mbRetry;
if mbCancel in Buttons then CancelButton := mbCancel else
if mbNo in Buttons then CancelButton := mbNo else
CancelButton := mbOk;
//------------------------------
// Create and position buttons
//------------------------------
if( nil <> savedSpace ) then inc( vertMargin, savedSpace^ );
X := (ClientWidth - ButtonGroupWidth) div 2;
for B := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do
if B in Buttons then
with TButton.Create(Result) do
begin
Name := ButtonNames[B];
Parent := Result;
Caption := myButtonCaptions[B];
ModalResult := ModalResults[B];
if B = DefaultButton then Default := True;
if B = CancelButton then Cancel := True;
SetBounds( X, IconTextHeight + VertMargin + VertSpacing, ButtonWidth, ButtonHeight );
Inc( X, ButtonWidth + ButtonSpacing );
if( nil <> buttonBottom ) then buttonBottom^ := IconTextHeight + VertMargin + VertSpacing + ButtonHeight;
if B = mbHelp then OnClick := TMessageForm(Result).HelpButtonClick;
end;
end;
//----------------------------------------------------
// let the calling function know
// where the bottom of the message is, if necessary
//----------------------------------------------------
if( nil <> msgBottom ) then msgBottom^ := bottomOfMessage;
if( nil <> margin ) then margin^ := horzMargin;
end;
//----------------------------------------------------------------------------------
//----------------------------------------------------------------------------------
// Implementation of custom dialog boxes
//----------------------------------------------------------------------------------
{*
Implementation for creating custom dialogs
All text is translated to the I88n language
@param msg Message to show
@param buttons Buttons to have present
@param caption Caption to display
@param imageStyle Icon to display
@param parent Form from which the dialog is created
@return Integer for the particular button clicked by the user
}
function msgDlg(
const msg: string;
buttons: TMsgDlgButtons;
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil
): integer;
var
bmp: TBitmap;
dlg: TForm;
begin
if( i88nLanguage() <> _currentLanguage ) then
translateMyDialogs()
;
bmp := bitmapStyle( TBitmapStyle( ord( imageStyle ) ) );
dlg := createMsgDlg(
caption,
prettyPrint( msg ),
buttons,
parent,
bmp )
;
result := dlg.showModal();
dlg.Free();
if( nil <> parent ) then parent.Repaint();
bmp.free();
end
;
{*
Creates a dialog having Yes, No, and Cancel buttons
All text is translated to I88n language if necessary
@param msg Message to show
@param caption Caption to display
@param imageStyle Icon to display
@param parent Form from which the dialog is created
@return Integer corresponding to enumeration indicating which button was clicked
}
function msgYesNoCancel(
const msg: string;
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil
): integer;
begin
if( i88nLanguage() <> _currentLanguage ) then
translateMyDialogs()
;
result := msgDlg(
msg,
[mbYes, mbNo, mbCancel],
caption,
imageStyle,
parent )
;
end
;
{*
Creates a dialog having Yes and No buttons
All text is translated to I88n language if necessary
@param msg Message to show
@param caption Caption to display
@param imageStyle Icon to display
@param parent Form from which the dialog is created
@return Integer corresponding to enumeration indicating which button was clicked
}
function msgYesNo(
const msg: string;
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil
): integer;
begin
if( i88nLanguage() <> _currentLanguage ) then
translateMyDialogs()
;
result := msgDlg(
msg,
[mbYes, mbNo],
caption,
imageStyle,
parent )
;
end
;
{*
Creates a dialog having an OK button
All text is translated to I88n language if necessary
@param msg Message to show
@param caption Caption to display
@param imageStyle Icon to display
@param parent Form from which the dialog is created
@return Integer indicating button was clicked
}
function msgOK(
const msg: string;
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil
): integer;
begin
if( i88nLanguage() <> _currentLanguage ) then
translateMyDialogs()
;
result := msgDlg(
msg,
[mbOK],
caption,
imageStyle,
parent )
;
end
;
{*
Creates a dialog having OK and Cancel buttons
All text is translated to I88n language if necessary
@param msg Message to show
@param caption Caption to display
@param imageStyle Icon to display
@param parent Form from which the dialog is created
@return Integer corresponding to enumeration indicating which button was clicked
}
function msgOKCancel(
const msg: string;
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil
): integer;
begin
if( i88nLanguage() <> _currentLanguage ) then
translateMyDialogs()
;
result := msgDlg(
msg,
[mbOK, mbCancel],
caption,
imageStyle,
parent )
;
end
;
{*
Creates a dialog alerting user to a specific exception and having an OK button
All text is translated to I88n language if necessary
@param msg Message to show
@param caption Caption to display
@param imageStyle Icon to display
@param parent Form from which the dialog is created
}
procedure msgExceptionOK(
msg: string;
e: exception = nil;
parent: TWinControl = nil
);
begin
if( i88nLanguage() <> _currentLanguage ) then
translateMyDialogs()
;
if( e <> nil ) then
begin
if( length( e.message ) > 0 ) then
msg := msg + tr( 'Technical information:' ) + ' ' + endl + e.message
;
end
;
msgOK( msg, tr( 'Application exception' ), IMGCritical, parent );
end
;
{*
??? Creates a regular expression dialog having OK and Cancel buttons
All text is translated to I88n language if necessary
@param msg ???
@param regexp ??? regular expression
@param caption Caption to display
@param imageStyle Icon to display
@param parent Form from which the dialog is created
@return Integer corresponding to enumeration indicating which button was clicked
}
function msgInput(
const msg: string;
const regexp: string = '';
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil;
default: string = ''
): string;
Var
dlg: TForm;
bmp: TBitmap;
rleEditor: TREEdit;
bottomOfMessage, messageWidth: integer;
savedSpace: integer;
margin: integer;
begin
if( i88nLanguage() <> _currentLanguage ) then
translateMyDialogs()
;
bmp := bitmapStyle( TBitmapStyle( ord( imageStyle ) ) );
savedSpace := 21 + 8;
dlg := createMsgDlg(
caption,
prettyPrint( msg ),
[mbOK, mbCancel],
parent,
bmp,
@bottomOfMessage,
nil,
@savedSpace,
@margin,
@messageWidth
);
dlg.Height := dlg.Height + savedSpace;
rleEditor := TREEdit.Create( dlg );
rleEditor.Parent := dlg;
rleEditor.Height := 21;
rleEditor.Width := messageWidth div 2;
rleEditor.Top := bottomOfMessage + 8;
rleEditor.Left := margin + messageWidth div 4;
rleEditor.TabOrder := 0;
rleEditor.Text := default;
if( '' <> regexp ) then
rleEditor.InputExpression := regexp
;
if( mrOK = dlg.showModal() ) then
result := rleEditor.Text
else
result := ''
;
rleEditor.Free();
dlg.Free();
bmp.free();
end
;
{*
??? Creates a regular expression dialog having OK and Cancel buttons
All text is translated to I88n language if necessary
@param msg ???
@param str ???
@param regexp ??? regular expression
@param caption Caption to display
@param imageStyle Icon to display
@param parent Form from which the dialog is created
@return Integer corresponding to enumeration indicating which button was clicked
}
function msgInputOKCancel(
const msg: string;
var str: string;
const regexp: string = '';
const caption: string = '';
imageStyle: TImageStyle = IMGUnspecified;
parent: TWinControl = nil
): integer;
Var
dlg: TForm;
bmp: TBitmap;
rleEditor: TREEdit;
bottomOfMessage, messageWidth: integer;
savedSpace: integer;
margin: integer;
begin
if( i88nLanguage() <> _currentLanguage ) then
translateMyDialogs()
;
bmp := bitmapStyle( TBitmapStyle( ord( imageStyle ) ) );
savedSpace := 21 + 8;
dlg := createMsgDlg(
caption,
prettyPrint( msg ),
[mbOK, mbCancel],
parent,
bmp,
@bottomOfMessage,
nil,
@savedSpace,
@margin,
@messageWidth
);
dlg.Height := dlg.Height + savedSpace;
rleEditor := TREEdit.Create( dlg );
rleEditor.Parent := dlg;
rleEditor.Height := 21;
rleEditor.Width := messageWidth div 2;
rleEditor.Top := bottomOfMessage + 8;
rleEditor.Left := margin + messageWidth div 4;
rleEditor.TabOrder := 0;
if( '' <> regexp ) then
rleEditor.InputExpression := regexp
;
rleEditor.Text := str;
result := dlg.ShowModal();
if( mrOK = result ) then str := rleEditor.Text;
rleEditor.Free();
dlg.Free();
bmp.free();
end
;
{*
Creates a dialog having Yes and No buttons and a checkbox
All text is translated to I88n language if necessary
@param msg Message to show
@param checkboxLabel Text for label to explain what the checkbox indicates
@param checkboxValue Output result - True if the box is checked, else false
@param caption Caption to display
@param imageStyle Icon to display
@param parent Form from which the dialog is created
@return Integer corresponding to enumeration indicating which button was clicked
}
function msgYesNoCheckbox(