mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 12:39:29 +02:00
LCL: Fix mrCancel and mbClose behavior in a MessageDlg. Issue #21801, patch from Bart Broersma
git-svn-id: trunk@37065 -
This commit is contained in:
parent
24cd5e93cd
commit
6999fe91fc
@ -562,10 +562,11 @@ const
|
||||
cBitmapY = 10; // y-position for bitmap in messagedialog
|
||||
cLabelSpacing = 10; // distance between icon & label
|
||||
|
||||
DialogResult : Array[mrNone..mrYesToAll] of Longint = (
|
||||
DialogResult : Array[mrNone..mrLast] of Longint = (
|
||||
-1, idButtonOK, idButtonCancel, idButtonAbort, idButtonRetry,
|
||||
idButtonIgnore, idButtonYes,idButtonNo, idButtonAll, idButtonNoToAll,
|
||||
idButtonYesToAll);
|
||||
idButtonYesToAll,idButtonClose);
|
||||
|
||||
|
||||
DialogButtonKind : Array[idButtonOK..idButtonNoToAll] of TBitBtnKind = (
|
||||
bkOk, bkCancel, bkHelp, bkYes, bkNo, bkClose, bkAbort, bkRetry,
|
||||
|
@ -32,36 +32,6 @@
|
||||
}
|
||||
function ModalEscapeValue(Buttons: TMsgDlgButtons): TModalResult;
|
||||
begin
|
||||
If mbCancel in Buttons then
|
||||
Result := mrCancel
|
||||
else
|
||||
If mbNo in Buttons then
|
||||
Result := mrNo
|
||||
else
|
||||
If mbAbort in Buttons then
|
||||
Result := mrAbort
|
||||
else
|
||||
If mbIgnore in Buttons then
|
||||
Result := mrIgnore
|
||||
else
|
||||
If mbNoToAll in Buttons then
|
||||
Result := mrNoToAll
|
||||
else
|
||||
If mbYes in Buttons then
|
||||
Result := mrYes
|
||||
else
|
||||
If mbOk in Buttons then
|
||||
Result := mrOk
|
||||
else
|
||||
If mbRetry in Buttons then
|
||||
Result := mrRetry
|
||||
else
|
||||
If mbAll in Buttons then
|
||||
Result := mrAll
|
||||
else
|
||||
If mbYesToAll in Buttons then
|
||||
Result := mrYesToAll
|
||||
else
|
||||
Result := mrCancel;
|
||||
end;
|
||||
|
||||
@ -132,7 +102,11 @@ var
|
||||
begin
|
||||
if (Buttons = []) or (Buttons = [mbHelp]) then
|
||||
Buttons := Buttons + [mbOk];
|
||||
CancelValue := ButtonResults[ModalEscapeValue(Buttons)];
|
||||
//Native PromptUser() dialog should return mrCancel on Escape or [X]-bordericon
|
||||
//TPromptDialog.CreatMessageDialog responds to Escape in "old Delhpi" style,
|
||||
//it will return mrCancel, mrNo, or mrOK if one of these buttons is present, else it will not respons to Escape key,
|
||||
//TPromptDialog.CreatMessageDialog does not use the CancelValue variable
|
||||
CancelValue := idButtonCancel;
|
||||
if UseDefButton then
|
||||
DefaultButton := DefButton
|
||||
else
|
||||
|
@ -20,8 +20,8 @@ type
|
||||
{ TPromptDialog }
|
||||
|
||||
TPromptDialog = class(TForm)
|
||||
procedure PromptDialogKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
private
|
||||
FCancelKind: TBitBtnKind;
|
||||
function CreateButtons(AVerticalLayout: Boolean; ASpacing: Integer): Integer;
|
||||
public
|
||||
IsSmallDevice: Boolean;
|
||||
@ -44,11 +44,6 @@ type
|
||||
destructor Destroy; override;
|
||||
end;
|
||||
|
||||
procedure TPromptDialog.PromptDialogKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
||||
begin
|
||||
if (Key = VK_Escape) then
|
||||
ModalResult := -1;
|
||||
end;
|
||||
|
||||
function TPromptDialog.CreateButtons(AVerticalLayout: Boolean;
|
||||
ASpacing: Integer): Integer;
|
||||
@ -75,9 +70,9 @@ begin
|
||||
begin
|
||||
Parent:= Self;
|
||||
Layout := blGlyphLeft;
|
||||
OnKeyDown := @PromptDialogKeyDown;
|
||||
|
||||
Kind := DialogButtonKind[Buttons[curBtn]];
|
||||
if Kind = FCancelKind then Cancel := True;
|
||||
|
||||
if Height < Glyph.Height + 5 then
|
||||
Height := Glyph.Height + 5;
|
||||
@ -123,13 +118,15 @@ end;
|
||||
|
||||
constructor TPromptDialog.CreateMessageDialog(const ACaption, aMsg: string;
|
||||
DialogType : longint; TheButtons: PLongint; ButtonCount, DefaultIndex : Longint);
|
||||
var
|
||||
curBtn: Integer;
|
||||
curKind: TBitBtnKind;
|
||||
begin
|
||||
inherited CreateNew(nil, 1);
|
||||
|
||||
IsSmallDevice := (Screen.Width <= 300);
|
||||
|
||||
AutoScroll := False;
|
||||
OnKeyDown := @PromptDialogKeyDown;
|
||||
//debugln('TPromptDialog.CreateMessageDialog A ButtonCount=',dbgs(ButtonCount));
|
||||
|
||||
ControlStyle:= ControlStyle-[csSetCaption];
|
||||
@ -170,6 +167,25 @@ begin
|
||||
else
|
||||
TheDefaultIndex := DefaultIndex;
|
||||
|
||||
//Find which button should respond to cancel (if any)
|
||||
FCancelKind := bkCustom;
|
||||
for curBtn := 0 to NumButtons - 1 do
|
||||
begin
|
||||
if (Buttons[curBtn] >= Low(DialogButtonKind)) and
|
||||
(Buttons[curBtn] <= High(DialogButtonKind)) then
|
||||
begin
|
||||
curKind := DialogButtonKind[Buttons[curBtn]];
|
||||
case curKind of
|
||||
bkCancel: FCancelKind := bkCancel;
|
||||
bkNo: if (FCancelKind <> bkCancel) then FCancelKind := bkNo;
|
||||
bkOk: if not (FCancelKind in [bkCancel, bkNo]) then FCancelkind := bkOk;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
if FCancelKind = bkCustom then FCancelKind := bkCancel; //default value if no mbCancel, mbNo or mbOk
|
||||
|
||||
|
||||
|
||||
// Assures a minimum text size
|
||||
if MSG = '' then MSG := ' ';
|
||||
|
||||
@ -261,8 +277,8 @@ begin
|
||||
begin
|
||||
Parent:= Self;
|
||||
Layout := blGlyphLeft;
|
||||
OnKeyDown := @PromptDialogKeyDown;
|
||||
Kind := DialogButtonKind[Buttons[curBtn]];
|
||||
if Kind = FCancelKind then Cancel := True;
|
||||
if Height < Glyph.Height + 5 then
|
||||
Height := Glyph.Height + 5;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user