Lazarus

Programming => General => Topic started by: llion on May 06, 2021, 05:29:37 pm

Title: ShowModal disables form minimise
Post by: llion on May 06, 2021, 05:29:37 pm
I am using Lazarus vn 2.0.6 on XUbuntu 18.04.

I have a problem which can be demonstrated easily using a project with just 3 forms : formA, formB, formC. FormA is the main form for the project. With formA visible I execute the following code

formB.show ;
application.processmessages ; // this ensures that formB is displayed in front of formA
{do other stuff not related to forms} ;
formC.showmodal ; // for example to display a  message relating to the "other stuff" above

In the course of displaying formC the Minimise button in the title bar of formB, & the corresponding Minimise menu option, become disabled, and remain so until the application is terminated.

This would appear to be a bug with showmodal, since if "formC.showmodal" above is replaced with "formC.show" the problem does not appear. Can anyone suggest a fix or work-around please?
Title: Re: ShowModal disables form minimise
Post by: mercurhyo on May 06, 2021, 06:08:42 pm
BorderStyle property should be set to bsDialog on each form using ShowModal, isn't it?
Title: Re: ShowModal disables form minimise
Post by: Martin_fr on May 06, 2021, 06:15:43 pm
Afaik, While the modal form is open, the minimize on all the other form (formA, formB) should be disabled.

But, when the modal form is closed, the minimize (of formA, formB) should be restored to whatever it's state was before the modal form was opened.

If it is not restored, then that would be a bug.
Title: Re: ShowModal disables form minimise
Post by: mercurhyo on May 06, 2021, 06:21:15 pm
Afaik, While the modal form is open, the minimize on all the other form (formA, formB) should be disabled.

But, when the modal form is closed, the minimize (of formA, formB) should be restored to whatever it's state was before the modal form was opened.

If it is not restored, then that would be a bug.

 I didn't know OS buttons enable/disable concept and maybe it has issues depending the Widgetset/Platform, but I do remember I was used to set bsDialog style on all my projects while using ShowModal. Then it worked fine
Title: Re: ShowModal disables form minimise
Post by: Martin_fr on May 06, 2021, 06:35:44 pm
I didn't know OS buttons enable/disable concept and maybe it has issues depending the Widgetset/Platform, but I do remember I was used to set bsDialog style on all my projects while using ShowModal. Then it worked fine

You mean you set your main form to bsDialog, if you show some modal form?

Modalforms themself should probably be bsDialog. I do not know if it is strictly required. I also do not know what happens otherwise, maybe its enforced.  But that should not affect the main form.

From memory, the code in ShowModal runs through all the other (none modal) forms, and prepares them for being "behind" the modal form. And all those changes should be reverted when the modal form exits.
Title: Re: ShowModal disables form minimise
Post by: dseligo on May 06, 2021, 07:11:35 pm
Modalforms themself should probably be bsDialog. I do not know if it is strictly required. I also do not know what happens otherwise, maybe its enforced.  But that should not affect the main form.

Why BorderStyle should be bsDialog? I think BorderStyle has nothing to do with ShowModal.
Title: Re: ShowModal disables form minimise
Post by: dseligo on May 06, 2021, 07:13:25 pm
I am using Lazarus vn 2.0.6 on XUbuntu 18.04.

I have a problem which can be demonstrated easily using a project with just 3 forms : formA, formB, formC. FormA is the main form for the project. With formA visible I execute the following code

formB.show ;
application.processmessages ; // this ensures that formB is displayed in front of formA
{do other stuff not related to forms} ;
formC.showmodal ; // for example to display a  message relating to the "other stuff" above

In the course of displaying formC the Minimise button in the title bar of formB, & the corresponding Minimise menu option, become disabled, and remain so until the application is terminated.

This would appear to be a bug with showmodal, since if "formC.showmodal" above is replaced with "formC.show" the problem does not appear. Can anyone suggest a fix or work-around please?

Are you saying that when you close formC, you can't minimize formB? Then that is a bug. Please prepare test project showing this.
If you don't close formC then it is expected behaviour (not to be able to minimize other forms).
Title: Re: ShowModal disables form minimise
Post by: lucamar on May 06, 2021, 07:17:05 pm
Modalforms themself should probably be bsDialog. I do not know if it is strictly required. I also do not know what happens otherwise, maybe its enforced.  But that should not affect the main form.
Why BorderStyle should be bsDialog? I think BorderStyle has nothing to do with ShowModal.

Indeed, it has nothing to do; you can show any form modally, whatever its border style or what not. That the "minimize" (and other) button(s) is disabled for the non-modal forms is just a gimmick of the GTK2 widgetset.

Note also that only the main form has a minimize button/menu item: no matter how the others are shown they only have the roll-up, maximize and close options.  Oops! No, no, I was wrong in this, sorry; I was thinking of another completely different thing :-[
Title: Re: ShowModal disables form minimise
Post by: Martin_fr on May 06, 2021, 07:38:19 pm
Modalforms themself should probably be bsDialog. I do not know if it is strictly required. I also do not know what happens otherwise, maybe its enforced.  But that should not affect the main form.

Why BorderStyle should be bsDialog? I think BorderStyle has nothing to do with ShowModal.
As, I said: "I don't know, if".

I just wonder what a modal dialog, with a minimize button on the actual modal form would do?
- Minimize the entire app, IMHO unexpected, since that minimize button belongs to the modal form only?
- Minimize the modal dialog, and leave the "frozen" app on the screen?

I haven't tried. I have no idea what will be displayed and/or happen in such a case.
Are there any apps (Lazarus or other) out there that have a mimize-able modal form?


---EDIT:
I mixed that up. I meant the BorderIcons, not the BorderStyle.
Title: Re: ShowModal disables form minimise
Post by: dseligo on May 06, 2021, 09:09:08 pm
I just wonder what a modal dialog, with a minimize button on the actual modal form would do?
- Minimize the entire app, IMHO unexpected, since that minimize button belongs to the modal form only?
- Minimize the modal dialog, and leave the "frozen" app on the screen?

I haven't tried. I have no idea what will be displayed and/or happen in such a case.
Are there any apps (Lazarus or other) out there that have a mimize-able modal form?


---EDIT:
I mixed that up. I meant the BorderIcons, not the BorderStyle.

When you click minimize button in Windows 10 the whole app is minimized to the lower left of desktop. If you click on program icon in the taskbar then whole app is minimized normally - nothing is in the lower left of desktop (same is if you minimize of windows, i.e. with Windows key + D).
I don't bother removing minimize icons from my modal forms.
Oh, and I think it's less confusing for user when the whole app is minimized. If I remember correctly, on some version of Windows (or Lazarus), if you minimized modal form the rest of app stayed, but it was (of course) unresponsive. Users sometimes wasn't aware that they minimized modal form and just keep clicking on rest of the forms.
Title: Re: ShowModal disables form minimise
Post by: lucamar on May 06, 2021, 09:22:31 pm
I just wonder what a modal dialog, with a minimize button on the actual modal form would do?

Test it yourself! ;)
In Linux (Xubuntu 18.04), the second option is taken: it minimizes the modal form, and leaves the "frozen" app on the screen.
Title: Re: ShowModal disables form minimise
Post by: mercurhyo on May 06, 2021, 10:10:19 pm
I didn't know OS buttons enable/disable concept and maybe it has issues depending the Widgetset/Platform, but I do remember I was used to set bsDialog style on all my projects while using ShowModal. Then it worked fine

You mean you set your main form to bsDialog, if you show some modal form?

Modalforms themself should probably be bsDialog. I do not know if it is strictly required. I also do not know what happens otherwise, maybe its enforced.  But that should not affect the main form.

From memory, the code in ShowModal runs through all the other (none modal) forms, and prepares them for being "behind" the modal form. And all those changes should be reverted when the modal form exits.

where the hell did you read that i use showmodal on mainform? LOOOL i said on each form where i use showmodal thats a BIG difference.

NOW I can explain you HOW it works :
when an application enters a modal mode it recursively calls the "processmessages" of itself incrementing reference counter of the deepness of modal and giving the Handle of the desired form ... meaning a modal form can open a modal form that can open a mo... and so on.
When all modal forms are closed the processmessages func of the application object is switched back to mainform
ENJOY

and remember "debugger is your friend" LOOOL!!!
Title: Re: ShowModal disables form minimise
Post by: llion on May 11, 2021, 12:34:01 pm
Thank you for your replies.

I confirm that setting formC.borderstyle to bsDialog does not make the problem go away.

If I use the debugger then the minimise capability on formB is disabled when formC is closed; if I do not use the debugger then this is disabled earlier, when formC is displayed. I confirm that this remains disabled once formC is closed. I have also seen instances where it is formA that loses its minimise button, but I cannot yet recreate this although I suspect that it is related.

A further unexpected behaviour is that when formC is closed it is formA which receives focus, where I would expect this to be formB.

I'm afraid that my limited Lazarus skills have taken me as far as I can get with debugging this problem. I am now working in my various apps to add code to identify explicitly which form has focus whenever a ShowModal is executed (ie formB in my example), and to explicitly re-enable the minimise function on this form when the modal form is closed.
Title: Re: ShowModal disables form minimise
Post by: winni on May 11, 2021, 02:58:03 pm
Hi!

For FormC:

Set the property "ShowInTaskBar" to "stalways".

If you now minimize FormC you got 2 Icons in the Taskbar. One is FormC.

Winni
Title: Re: ShowModal disables form minimise
Post by: llion on May 15, 2021, 04:07:25 pm
as a postscript :

In my example, if formA has 2 buttons, one button to show formB, and then a second button to showmodal formC, then it is formA that loses its minimize button/menu option. This is more serious - I can no longer minimize my app. Sigh. I wonder whether this is why Lazarus itself cannot be minimized?

And the only way of restoring this lost minimize button is to close & reopen the app. It seems not possible to change programmatically the Tform.BorderIcons property at runtime, although that is exactly what this bug in ?Lazarus appears to be doing successfully. Sigh again.

I wondered about reporting  these (sic) bugs but I found the bugtracker pages impenetrable.
Title: Re: ShowModal disables form minimise
Post by: winni on May 15, 2021, 06:09:39 pm
Hi!


This is not a bug.
A car with square tyres will not roll.

ShowModal: This is the only Form which will react on any user action.  Meanwhile all other Forms are disabled..This is the defined and wanted behaviour. If you dont respect that your demo will not work.

Winni

Title: Re: ShowModal disables form minimise
Post by: lucamar on May 15, 2021, 08:39:13 pm
This is not a bug.
A car with square tyres will not roll.

ShowModal: This is the only Form which will react on any user action.  Meanwhile all other Forms are disabled..This is the defined and wanted behaviour. If you dont respect that your demo will not work.

That  is not the problem. The problem (bug?) is that if you have two forms and ShowModal a third, the one that was previously active will lose the minimize button and system menu item even after this third is closed.

It's not that the button (and menu item) is  disabled: it just dissapears!
Title: Re: ShowModal disables form minimise
Post by: winni on May 15, 2021, 09:39:13 pm
Hi!

Just tested:

Lin64/gtk2 : No Problems
Win7/64 : No Problems

So I think it is again a Win10 problem.

Dont use that rubbish!

Winni
Title: Re: ShowModal disables form minimise
Post by: lucamar on May 15, 2021, 09:59:23 pm
Well, I tested it on Linux-gtk/x86_64 (Xubuntu 18,04), so it doesn't seem to be "Windows-only". It might depend on specific versions of some libs, though, so some Linuxen show and other don't show this behaviour.
Title: Re: ShowModal disables form minimise
Post by: winni on May 15, 2021, 11:21:57 pm
Well, I tested it on Linux-gtk/x86_64 (Xubuntu 18,04), so it doesn't seem to be "Windows-only". It might depend on specific versions of some libs, though, so some Linuxen show and other don't show this behaviour.

Okay. Only tested with Suse Tumbleweed and the last gtk2 libs.

And yes: The titlebar and the system menu are job of the Window Manager and not of Lazarus. So there must be some trouble in the interface to the Window Manager.

And the Window Manager where a long time a problem. The height of the Linux Titlebar was a long time only available through some lousy tricks (including mine).

So this is a tricky item. And remember: You can change your Window Manager with Linux on the fly: After that you only have to restart you session.

Oh oh ....

Winni
Title: Re: ShowModal disables form minimise
Post by: dseligo on May 16, 2021, 08:41:00 pm
Hi!

Just tested:

Lin64/gtk2 : No Problems
Win7/64 : No Problems

So I think it is again a Win10 problem.

Dont use that rubbish!

Winni

It works fine on Win10.
I included test project (in case I didn't understand OP's problem).
Title: Re: ShowModal disables form minimise
Post by: lucamar on May 16, 2021, 09:57:02 pm
I've modified a little dseligo's project so any of you can test more thorougly.

With this project (Xubuntu 18.04-x86_64 & Laz/FPC 2.0.12/3.2.0) this happens after you start the program:
One further caveat: even though it's a "normal" one and all is set right, form C never displays a minimize button either.
Title: Re: ShowModal disables form minimise
Post by: dseligo on May 16, 2021, 11:00:59 pm
I've modified a little dseligo's project so any of you can test more thorougly.

This still works fine on Windows 10.
Title: Re: ShowModal disables form minimise
Post by: tetrastes on May 17, 2021, 12:33:46 am
Some notes...
Have anybody noticed this?
I wonder whether this is why Lazarus itself cannot be minimized?
I can confirm that Lazarus IDE (gtk2 64 bit) main window loses its Minimize button after opening its other windows at Debian 10 x86_64 Xfce (but not KDE).
I think this is bug/feature of LCLgtk2 (maybe qt also - did not test) apps at Xfce (maybe Xfce on Debian/clones only).

Apps at Linux behave very differently on different distros, widgetsets, DE, WM...  %)
For example, at the moment I am at Fedora 32 x86-64 LXQt with OpenBox WM. And with this WM modal window does not fully disable its parent, it may be minimized, maximized and resized while modal window is opened. Moreover, for gtk2 (though I have not gtk2 apps other than LCLgtk2 including Lazarus here) you can switch between modal and non-modal windows (for example in Lazarus IDE or in dseligo's and lucamar's projects when you open all 3 forms).
There are many things with Lazarus and Linux... For example, I never managed Form's property Position poDefault, poDefaultPosOnly, poDefaultSizeOnly to work...
Title: Re: ShowModal disables form minimise
Post by: lucamar on May 17, 2021, 01:03:17 am
Have anybody noticed this?
I wonder whether this is why Lazarus itself cannot be minimized?
I can confirm that Lazarus IDE (gtk2 64 bit) main window loses its Minimize button after opening its other windows at Debian 10 x86_64 Xfce (but not KDE).

Yes, I noticed it too (because of this thread) in Xubuntu (Xcfe). In fact it happened (again) right after running the test project: after pressing the "Run" combo, most all the IDE windows (including the editor and the project forms) lost the minimize button :(

What is interesting is that in both a plain Ubuntu (gnome) and a Kubuntu (kde) boxes it doesn't happpen, so there must be something "fishy" going on with Xfce and, presumably, other desktops.
TinyPortal © 2005-2018