Recent

Author Topic: [SOLVED] How to make 2 improvements to function dialogs.MessageDlg ?  (Read 1396 times)

wp

  • Hero Member
  • *****
  • Posts: 10296
Re: How to make 2 improvements to function dialogs.MessageDlg ?
« Reply #15 on: November 23, 2022, 03:55:02 pm »
After many changes it is enough to do just "Tools" > "Build Lazarus with Profile: <whatever is selected in your case>". Only when you feel that something was not recompiled or if there were compilation errors which did not happen before, go to "Tools" > "Configure 'Build Lazarus'", and in the "Clean up" box check "Clean all" and "Switch after building to automatically". I don't know why in some Linuxes these options are missing in the Clean up box... If there is no way to activate them you can also select the option "Clean up and recompile" in the "Profile to build" combobox at the top. Then click "Build" and wait until the IDE restarts.

Hartmut

  • Hero Member
  • *****
  • Posts: 574
Re: How to make 2 improvements to function dialogs.MessageDlg ?
« Reply #16 on: November 23, 2022, 07:19:57 pm »
Hello wp, I have very good news. I tested your changes carefully and everything works perfectly:

I made all the following tests on Linux (Ubuntu 18.04) and Win7 and (an older) Win10 with Lazarus 2.0.10 / FPC 3.2.0:
 - default width of the dialog is 480 (with a longer text)
 - increasing in steps up to 2500 => works
 - decreasing in steps down to 120 => works
 - a width of 1..119 results in 120
 - a width <= 0 results in the default width (480)
That was exactly what I expected from the if-statement, which I replaced in the sources.

But in Windows there is an issue that the width is specified in "dialog units". It seems that I have to divide the Width property value by 2 before passing it to the TaskDialogIndirect windows function, but I am not sure whether this is correct all the time.
I did *not* see this effect on my Win7 and Win10. The resulting width was always 1:1 the same as what I had set. But I don't have High-DPI-settings on my Windows.

The only thing which still could improved is that in the Objectinspector the new property 'Width' has no remark. Maybe you want something to set like "can set the Width of the Dialog (Minimum=120, 0=Automatic=Default)".

To rebuild the IDE worked with menu Tools / "Build Lazarus with Profile: Normal IDE" on Windows and Linux.

Thank you again very much for improving this dialog and your continuous help.

AlexTP

  • Hero Member
  • *****
  • Posts: 1961
    • UVviewsoft
Re: How to make 2 improvements to function dialogs.MessageDlg ?
« Reply #17 on: November 23, 2022, 09:43:09 pm »
@wp,
Your changes to TaskDialog won't break existing apps, so I suggest to merge them to git. Also no incompat with Delphi?

wp

  • Hero Member
  • *****
  • Posts: 10296
Re: How to make 2 improvements to function dialogs.MessageDlg ?
« Reply #18 on: November 24, 2022, 12:14:07 am »
Committed to Laz/main (https://gitlab.com/freepascal.org/lazarus/lazarus/-/commit/68e6168982d801cf7708edb74c9e8662db6c4199).

I will investigate the size discrepancy in the native dialog later.

Also no incompat with Delphi?
Well, in the TaskDialog of Delphi (XE 10.4) there is no Width property at all...

The only thing which still could improved is that in the Objectinspector the new property 'Width' has no remark. Maybe you want something to set like "can set the Width of the Dialog (Minimum=120, 0=Automatic=Default)".
dsiders usually adds help texts pretty soon. Thank you, Don, for your tireless efforts, BTW...

dsiders

  • Hero Member
  • *****
  • Posts: 724
Re: How to make 2 improvements to function dialogs.MessageDlg ?
« Reply #19 on: November 24, 2022, 02:14:17 am »
Committed to Laz/main (https://gitlab.com/freepascal.org/lazarus/lazarus/-/commit/68e6168982d801cf7708edb74c9e8662db6c4199).

The only thing which still could improved is that in the Objectinspector the new property 'Width' has no remark. Maybe you want something to set like "can set the Width of the Dialog (Minimum=120, 0=Automatic=Default)".
dsiders usually adds help texts pretty soon. Thank you, Don, for your tireless efforts, BTW...

You're welcome Werner.

Updates to dialogs and lcltaskdialog are in progress.
Preview Lazarus 2.3.0 documentation at: https://dsiders.gitlab.io/lazdocsnext

AlexTP

  • Hero Member
  • *****
  • Posts: 1961
    • UVviewsoft
Re: How to make 2 improvements to function dialogs.MessageDlg ?
« Reply #20 on: November 24, 2022, 07:26:03 am »
For Win32 TaskDialog it is also possible to set width, I found several topics at stackoverflow, can you look please?

wp

  • Hero Member
  • *****
  • Posts: 10296
Re: How to make 2 improvements to function dialogs.MessageDlg ?
« Reply #21 on: November 24, 2022, 06:21:13 pm »
I will investigate the size discrepancy in the native dialog later.
Fixed now (In fact I already had the solution yesterday (based on https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getdialogbaseunits), but had the arguments of the MulDiv in the wrong order...).

wp

  • Hero Member
  • *****
  • Posts: 10296
Re: How to make 2 improvements to function dialogs.MessageDlg ?
« Reply #22 on: November 25, 2022, 12:36:34 am »
- if no 'Title' is used, then still a huge space is reserved for that (see screenshot). Beside 'caption' and 'message' I need no 3rd text. Is it possible to get rid of this extra space?
Now I committed a fix for this issue to Lazarus/main. It's not perfect, but much better.

If you do not work with Laz/main you can follow these steps to get the changes:
  • Open file lcltaskdialog.pas
  • Find the (long) procedure function TTaskDialog.Execute, and within it the nested function AddLabel. Immediately after its begin add the line
        if Text = '' then exit(nil);
  • Now go down into the bulk of the Execute function and find the following IF block: if (LCL_IMAGES[aDialogIcon]<>0). In its else block there is a statement if not aEmulateClassicStyle then. Change it to
        if (not aEmulateClassicStyle) and (Inst <> '') then.
  • And, finally, toward the end of the unit there is procedure TTaskDialog.SetElementText with a case block. The first case item (tdeContent..tdeMainInstruction) contains the line Dialog.Form.Element[element].Caption := Text. Put a nil-check in front of this statement:
        if Dialog.Form.Element[element] <> nil then Dialog.Form.Element[element].Caption := Text
  • That's all. Rebuild the IDE and test.
Of course, as usual, make a backup copy of the file before changing anything.

Hartmut

  • Hero Member
  • *****
  • Posts: 574
Re: How to make 2 improvements to function dialogs.MessageDlg ?
« Reply #23 on: November 25, 2022, 11:58:10 am »
- if no 'Title' is used, then still a huge space is reserved for that (see screenshot). Beside 'caption' and 'message' I need no 3rd text. Is it possible to get rid of this extra space?
Now I committed a fix for this issue to Lazarus/main. It's not perfect, but much better.

Thank you very much for these changes. However I did not find the 2nd place with
   if (LCL_IMAGES[aDialogIcon]<>0)
because there is nothing similar in my Lazarus 2.0.10. I attached the sourcefile with my other changes. Maybe you can point me to the right position?

The change in the 3rd place had a minimal discrepance to your description:
You wrote:
   Dialog.Form.Element[element].Caption := Text
while I found:
   Dialog.Form.Element[element].Caption := CR(Text)
but from my understanding this should be ok?

wp

  • Hero Member
  • *****
  • Posts: 10296
Re: How to make 2 improvements to function dialogs.MessageDlg ?
« Reply #24 on: November 25, 2022, 12:33:08 pm »
I did not find the 2nd place with
   if (LCL_IMAGES[aDialogIcon]<>0)
because there is nothing similar in my Lazarus 2.0.10.
Ah, yes, this is because there were changes regarding the dialog's icons recently. Sorry.

The same position in Laz 2.0.12 looks like this (line #893):
Code: [Select]
     if (LAZ_ICONS[aDialogIcon]<>'') {$IFDEF MSWINDOWS}or (WIN_ICONS[aDialogIcon]<>nil){$ENDIF} then
You must scroll down about 30 lines to find the "else" part and change it as follows:
Code: Pascal  [Select][+][-]
  1.     begin
  2.       Image := nil;
  3.       if (not aEmulateClassicStyle) and (Inst <> '') then    // <---- " and (Inst <> '')" added
  4.         IconBorder := IconBorder*2;
  5.       X := IconBorder;
  6.       Y := IconBorder;
  7.     end;

The change in the 3rd place had a minimal discrepance to your description:
You wrote:
   Dialog.Form.Element[element].Caption := Text
while I found:
   Dialog.Form.Element[element].Caption := CR(Text)
That's fine. You could also omit this one in a quick-and-dirty solution because this function normally is not called.

Hartmut

  • Hero Member
  • *****
  • Posts: 574
Re: How to make 2 improvements to function dialogs.MessageDlg ?
« Reply #25 on: November 25, 2022, 05:24:44 pm »
Hello wp, I tested your new changes on Linux (Ubuntu 18.04) and Win7 and (an older) Win10 with Lazarus 2.0.10 / FPC 3.2.0 and everything works perfectly: if there is no 'Title' and no Icon, then no more extra space is wasted :-))

Again thank you very much for those improvements to this awesome dialog.

 

TinyPortal © 2005-2018