Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2019-09

TTaskDialog - correct ModalResult for "Close"?

10 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Alexander Hofmann

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20190911/de676ab7/attachment.html>

Reply by email

Bart
to Alexander Hofmann
AM Alexander Hofmann 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

Reply by email

Bart
to Bart

On Wed, Sep 11, 2019 at 1:53 PM Bart 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

Reply by email

Alexander Hofmann
to Bart
Bart wrote
On Wed, Sep 11, 2019 at 1:53 PM Bart 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

Reply by email

Alexander Hofmann
to Bart

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20190911/cb2ecfce/attachment-0001.html> -------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: OpenPGP digital signature
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20190911/cb2ecfce/attachment-0001.sig>

Reply by email