[Lazarus] TTaskDialog - correct ModalResult for "Close"?

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

[Lazarus] TTaskDialog - correct ModalResult for "Close"?

Free Pascal - Lazarus mailing list

Hi all,

I am currently wondering how to interpret the ModalResult of TTaskDialog if the Button "Close" was clicked. "Close" returns "mrAll" in windows and "mrAbort" in Linux (GTK2) - is that intended? I somehow expected mrClose. In the code of TTaskDialog, for ButtonIDs < 100, the ModalResult is directly translated from the ButtonID, so maybe it is intended? (taskdialog.inc, Lines 98 and following:)

function TCustomTaskDialog.ButtonIDToModalResult(const AButtonID: Integer
  ): TModalResult;
begin
  if AButtonID<100 then
    Result := AButtonID    <----- HERE
  else if (AButtonID-100<Buttons.Count) then
    Result := Buttons[AButtonID-100].ModalResult
  else
    Result := mrNone;
end;

I searched the Web and Mantis but did neither find a Bug report nor a List like "ClickedButton -> ModalResult" or alike.

You can test by dropping a TTaskDialog on a form and using the following code at a TButton:

procedure TForm1.Button1Click(Sender: TObject);
begin
  TaskDialog1.CommonButtons:=[tcbOk,tcbYes,tcbNo,tcbCancel,tcbRetry,tcbClose];
  if TaskDialog1.Execute then begin
    case TaskDialog1.ModalResult of
      mrOK: Memo1.Lines.Add('mrOK');
      mrCancel: Memo1.Lines.Add('mrCancel');
      mrAbort: Memo1.Lines.Add('mrAbort');
      mrRetry: Memo1.Lines.Add('mrRetry');
      mrIgnore: Memo1.Lines.Add('mrIgnore');
      mrYes: Memo1.Lines.Add('mrYes');
      mrNo: Memo1.Lines.Add('mrNo');
      mrAll: Memo1.Lines.Add('mrAll');
      mrNoToAll: Memo1.Lines.Add('mrNoToAll');
      mrYesToAll: Memo1.Lines.Add('mrYesToAll');
      mrClose: Memo1.Lines.Add('mrClose');
    else
      Memo1.Lines.Add(Format('Unknown: %d', [TaskDialog1.ModalResult]));
    end;
  end;
end;

Thank you and

with best wishes,

Alex


--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TTaskDialog - correct ModalResult for "Close"?

Free Pascal - Lazarus mailing list
On Wed, Sep 11, 2019 at 9:46 AM Alexander Hofmann via lazarus
<[hidden email]> wrote:

> I am currently wondering how to interpret the ModalResult of TTaskDialog if the Button "Close" was clicked. "Close" returns "mrAll" in windows and "mrAbort" in Linux (GTK2) - is that intended? I somehow expected mrClose. In the code of TTaskDialog, for ButtonIDs < 100, the ModalResult is directly translated from the ButtonID, so maybe it is intended? (taskdialog.inc, Lines 98 and following:)

Pressing Alt+F4 border icon gives mrAll, it should give mrCancel
(pnButton=IDCANCEL according to
https://docs.microsoft.com/en-us/windows/win32/api/commctrl/nf-commctrl-taskdialog).
Pressing a button called Close should give mrClose IMO.
The other CommonButtons modalresults seem fine.
Tested on Win10.

--
Bart
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TTaskDialog - correct ModalResult for "Close"?

Free Pascal - Lazarus mailing list
Pressing the Close button sets ButtonID correctly to 8, which is
IDCLOSE (see LCLType unit), but mrClose equals to 11, so there it goes
wrong.

--
Bart
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TTaskDialog - correct ModalResult for "Close"?

Free Pascal - Lazarus mailing list
On Wed, Sep 11, 2019 at 1:53 PM Bart <[hidden email]> wrote:

Possible fix:

function TCustomTaskDialog.ButtonIDToModalResult(const AButtonID: Integer
  ): TModalResult;
begin
  if AButtonID<100 then
    begin
      case AButtonID of
        IDOK: Result := mrOK;
        IDCANCEL: Result := mrCancel;
        IDABORT: Result := mrAbort;
        IDRETRY: Result := mrRetry;
        IDIGNORE: Result := mrIgnore;
        IDYES: Result := mrYes;
        IDNO: Result := mrNo;
        IDCLOSE: Result := mrClose;
        else Result := AButtonID
      end;
    end
  else if (AButtonID-100<Buttons.Count) then
    Result := Buttons[AButtonID-100].ModalResult
  else
    Result := mrNone;
end;

--
Bart
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TTaskDialog - correct ModalResult for "Close"?

Free Pascal - Lazarus mailing list
Am 11.09.19 um 14:24 schrieb Bart via lazarus:
> On Wed, Sep 11, 2019 at 1:53 PM Bart <[hidden email]> wrote:
>
> Possible fix:

Ok, so it's more like a bug than intended behavior.

I'll see if I can test the fix on Win and Lin maybe this afternoon. I
didn't check - but are the definitions of IDCLOSE different for Windows
and Linux?

Thanks,

Alex

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TTaskDialog - correct ModalResult for "Close"?

Free Pascal - Lazarus mailing list
On Wed, Sep 11, 2019 at 3:07 PM Alexander Hofmann via lazarus
<[hidden email]> wrote:

> I didn't check - but are the definitions of IDCLOSE different for Windows
> and Linux?

No, they are (unconditionally) defined in LCLType.
--
Bart
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TTaskDialog - correct ModalResult for "Close"?

Free Pascal - Lazarus mailing list
Hi,

so - your patch indeed fixes it for Windows (where the native common controls dialog is used for Win 10). But - there's more logic behind it I think.

For Linux (and Probably other platforms, too), independent of the widget set, in LCLTaskDialog.pas there's

  TCommonButton = (
    cbOK, cbYes, cbNo, cbCancel, cbRetry, cbClose);  

and

const
  TD_BTNMOD: array[TCommonButton] of Integer = (
    mrOk, mrYes, mrNo, mrCancel, mrRetry, mrAbort); 

TD_BTNMOD is used exactly once again, where it serves to pass the ModalResult to the Button. So the "Close" button really gets assigned with "mrAbort" in Linux, where in Windows, the difference in idClose and mrClose is the culprit?

Also, LCLTaskDialog seems to execute the native Windows Dialog independently of the selected Widgetset; though I don't think Qt or GTK is widely used on Windows anyway?

I won't dig further on the latter, but should I file a bug about the Close/Abort thing?

All the best,
Alex

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus

signature.asc (201 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TTaskDialog - correct ModalResult for "Close"?

Free Pascal - Lazarus mailing list
On Wed, Sep 11, 2019 at 9:31 PM Alexander Hofmann via lazarus
<[hidden email]> wrote:

> I won't dig further on the latter, but should I file a bug about the Close/Abort thing?

Yes, please do.

--
Bart
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TTaskDialog - correct ModalResult for "Close"?

Free Pascal - Lazarus mailing list
On Wed, Sep 11, 2019 at 10:39 PM Bart <[hidden email]> wrote:

> > I won't dig further on the latter, but should I file a bug about the Close/Abort thing?
>
> Yes, please do.

Posted bugreport with possible patch:
https://bugs.freepascal.org/view.php?id=36069
Maybe Zeljko or Juha can review the patch (I know next to nothing
about TTaskDialog, other than the simulated one looks really ugly on
Windows).

--
Bart
--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus
Reply | Threaded
Open this post in threaded view
|

Re: [Lazarus] TTaskDialog - correct ModalResult for "Close"?

Free Pascal - Lazarus mailing list
Am 12.09.19 um 18:40 schrieb Bart via lazarus:
>
> Posted bugreport with possible patch:
> https://bugs.freepascal.org/view.php?id=36069
> Maybe Zeljko or Juha can review the patch (I know next to nothing
> about TTaskDialog, other than the simulated one looks really ugly on
> Windows).
>
Thanks, I was away of any computer until now...

--
_______________________________________________
lazarus mailing list
[hidden email]
https://lists.lazarus-ide.org/listinfo/lazarus