mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-13 11:09:22 +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
|
cBitmapY = 10; // y-position for bitmap in messagedialog
|
||||||
cLabelSpacing = 10; // distance between icon & label
|
cLabelSpacing = 10; // distance between icon & label
|
||||||
|
|
||||||
DialogResult : Array[mrNone..mrYesToAll] of Longint = (
|
DialogResult : Array[mrNone..mrLast] of Longint = (
|
||||||
-1, idButtonOK, idButtonCancel, idButtonAbort, idButtonRetry,
|
-1, idButtonOK, idButtonCancel, idButtonAbort, idButtonRetry,
|
||||||
idButtonIgnore, idButtonYes,idButtonNo, idButtonAll, idButtonNoToAll,
|
idButtonIgnore, idButtonYes,idButtonNo, idButtonAll, idButtonNoToAll,
|
||||||
idButtonYesToAll);
|
idButtonYesToAll,idButtonClose);
|
||||||
|
|
||||||
|
|
||||||
DialogButtonKind : Array[idButtonOK..idButtonNoToAll] of TBitBtnKind = (
|
DialogButtonKind : Array[idButtonOK..idButtonNoToAll] of TBitBtnKind = (
|
||||||
bkOk, bkCancel, bkHelp, bkYes, bkNo, bkClose, bkAbort, bkRetry,
|
bkOk, bkCancel, bkHelp, bkYes, bkNo, bkClose, bkAbort, bkRetry,
|
||||||
|
@ -32,36 +32,6 @@
|
|||||||
}
|
}
|
||||||
function ModalEscapeValue(Buttons: TMsgDlgButtons): TModalResult;
|
function ModalEscapeValue(Buttons: TMsgDlgButtons): TModalResult;
|
||||||
begin
|
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;
|
Result := mrCancel;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -132,7 +102,11 @@ var
|
|||||||
begin
|
begin
|
||||||
if (Buttons = []) or (Buttons = [mbHelp]) then
|
if (Buttons = []) or (Buttons = [mbHelp]) then
|
||||||
Buttons := Buttons + [mbOk];
|
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
|
if UseDefButton then
|
||||||
DefaultButton := DefButton
|
DefaultButton := DefButton
|
||||||
else
|
else
|
||||||
|
@ -20,8 +20,8 @@ type
|
|||||||
{ TPromptDialog }
|
{ TPromptDialog }
|
||||||
|
|
||||||
TPromptDialog = class(TForm)
|
TPromptDialog = class(TForm)
|
||||||
procedure PromptDialogKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
|
|
||||||
private
|
private
|
||||||
|
FCancelKind: TBitBtnKind;
|
||||||
function CreateButtons(AVerticalLayout: Boolean; ASpacing: Integer): Integer;
|
function CreateButtons(AVerticalLayout: Boolean; ASpacing: Integer): Integer;
|
||||||
public
|
public
|
||||||
IsSmallDevice: Boolean;
|
IsSmallDevice: Boolean;
|
||||||
@ -44,11 +44,6 @@ type
|
|||||||
destructor Destroy; override;
|
destructor Destroy; override;
|
||||||
end;
|
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;
|
function TPromptDialog.CreateButtons(AVerticalLayout: Boolean;
|
||||||
ASpacing: Integer): Integer;
|
ASpacing: Integer): Integer;
|
||||||
@ -75,9 +70,9 @@ begin
|
|||||||
begin
|
begin
|
||||||
Parent:= Self;
|
Parent:= Self;
|
||||||
Layout := blGlyphLeft;
|
Layout := blGlyphLeft;
|
||||||
OnKeyDown := @PromptDialogKeyDown;
|
|
||||||
|
|
||||||
Kind := DialogButtonKind[Buttons[curBtn]];
|
Kind := DialogButtonKind[Buttons[curBtn]];
|
||||||
|
if Kind = FCancelKind then Cancel := True;
|
||||||
|
|
||||||
if Height < Glyph.Height + 5 then
|
if Height < Glyph.Height + 5 then
|
||||||
Height := Glyph.Height + 5;
|
Height := Glyph.Height + 5;
|
||||||
@ -123,13 +118,15 @@ end;
|
|||||||
|
|
||||||
constructor TPromptDialog.CreateMessageDialog(const ACaption, aMsg: string;
|
constructor TPromptDialog.CreateMessageDialog(const ACaption, aMsg: string;
|
||||||
DialogType : longint; TheButtons: PLongint; ButtonCount, DefaultIndex : Longint);
|
DialogType : longint; TheButtons: PLongint; ButtonCount, DefaultIndex : Longint);
|
||||||
|
var
|
||||||
|
curBtn: Integer;
|
||||||
|
curKind: TBitBtnKind;
|
||||||
begin
|
begin
|
||||||
inherited CreateNew(nil, 1);
|
inherited CreateNew(nil, 1);
|
||||||
|
|
||||||
IsSmallDevice := (Screen.Width <= 300);
|
IsSmallDevice := (Screen.Width <= 300);
|
||||||
|
|
||||||
AutoScroll := False;
|
AutoScroll := False;
|
||||||
OnKeyDown := @PromptDialogKeyDown;
|
|
||||||
//debugln('TPromptDialog.CreateMessageDialog A ButtonCount=',dbgs(ButtonCount));
|
//debugln('TPromptDialog.CreateMessageDialog A ButtonCount=',dbgs(ButtonCount));
|
||||||
|
|
||||||
ControlStyle:= ControlStyle-[csSetCaption];
|
ControlStyle:= ControlStyle-[csSetCaption];
|
||||||
@ -170,6 +167,25 @@ begin
|
|||||||
else
|
else
|
||||||
TheDefaultIndex := DefaultIndex;
|
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
|
// Assures a minimum text size
|
||||||
if MSG = '' then MSG := ' ';
|
if MSG = '' then MSG := ' ';
|
||||||
|
|
||||||
@ -261,8 +277,8 @@ begin
|
|||||||
begin
|
begin
|
||||||
Parent:= Self;
|
Parent:= Self;
|
||||||
Layout := blGlyphLeft;
|
Layout := blGlyphLeft;
|
||||||
OnKeyDown := @PromptDialogKeyDown;
|
|
||||||
Kind := DialogButtonKind[Buttons[curBtn]];
|
Kind := DialogButtonKind[Buttons[curBtn]];
|
||||||
|
if Kind = FCancelKind then Cancel := True;
|
||||||
if Height < Glyph.Height + 5 then
|
if Height < Glyph.Height + 5 then
|
||||||
Height := Glyph.Height + 5;
|
Height := Glyph.Height + 5;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user