Recent

Author Topic: form resize event not firing correctly.  (Read 5526 times)

josh

  • Hero Member
  • *****
  • Posts: 817
form resize event not firing correctly.
« on: June 18, 2021, 02:38:11 pm »
Hi

Hope someone can shed some light, for some reason the form resize is not being fired while the form is being resized.

It appears as the form.resize is acting like a resizeend event.

the attached project tries to keep the form to an aspet ration of 16:9; which it only does when you release the mouse; which makes it impossible for a user to adjust its dimensions.

Lazarus 2.3.0 r65271 FPC 3.3.1 x86_64-win64-win32/win64

okay with Lazarus 2.1.0 r63084 FPC 3.3.1 x86_64-win64-win32/win64
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

wp

  • Hero Member
  • *****
  • Posts: 8579
Re: form resize event not firing correctly.
« Reply #1 on: June 18, 2021, 03:03:46 pm »
Your form inherits from TControl, and thus you have access to all public and protected methods of TControl. So, why don't you override SetBounds, for example? It sets the bounds BEFORE the OnSize event is fired.

Code: Pascal  [Select][+][-]
  1. procedure TForm1.SetBounds(ALeft, ATop, AWidth, AHeight: integer);  // Don't forget "override" in the interface part!
  2. begin
  3.   AHeight := AWidth * 9 div 16;  // enforce aspect ratio width/height = 16/9.
  4.   inherited;
  5. end;

Not the final solution because it causes lots of flicker. But when you look at all the other methods involved in resizing there is probably a better one. At least you got the idea...
« Last Edit: June 18, 2021, 03:06:08 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

josh

  • Hero Member
  • *****
  • Posts: 817
Re: form resize event not firing correctly.
« Reply #2 on: June 18, 2021, 03:58:24 pm »
Hi WP

yes overriding the setbounds would solve the problem in the sample, but obviously is no way ideal; as the sample was just to show the issue; on a more complex form tthat has dynamic controls overriding the setbounds will cause all kinds of issue, using the setboounds override if i adjust to max settings with frag, the form is then non moveable, suspecct a bug.

It would be far better if the form.resize event acted as it did before and according to all the specs i can find.
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

jamie

  • Hero Member
  • *****
  • Posts: 4751
Re: form resize event not firing correctly.
« Reply #3 on: June 18, 2021, 06:30:21 pm »
U need to process the wm_sizing or wm_windowposchanging

The wm_size does return until u are finished but the others I stated do always trigger a response
Implement one of those instead and adjust your frame then.
 
 Bad hacks calls for bad side effects
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 4751
Re: form resize event not firing correctly.
« Reply #4 on: June 20, 2021, 04:59:54 am »
have a look at this that I slapped together to give an idea of a smooth sizing..

I use code much like this in a couple of apps to maintain aspect ratio..

I must say the LCL leaves a lot to be desired. So many hacks in the TWinControl file its a wonder it can move out of its own way..

So attached is something that uses both the WindowPosChanging and WM_Sizing, not WM_SIZE..

grab the sides with your mouse and change sizes, watch how the other angle changes size..

P.S.
 I have much less trouble in Delphi, it seems things work as they should when it comes to handling these special cases.. I think some of this code in the LCL needs a serious weight loss program.
The only true wisdom is knowing you know nothing

jamie

  • Hero Member
  • *****
  • Posts: 4751
Re: form resize event not firing correctly.
« Reply #5 on: June 21, 2021, 03:45:45 am »
Hi

Hope someone can shed some light, for some reason the form resize is not being fired while the form is being resized.

It appears as the form.resize is acting like a resizeend event.

the attached project tries to keep the form to an aspet ration of 16:9; which it only does when you release the mouse; which makes it impossible for a user to adjust its dimensions.

Lazarus 2.3.0 r65271 FPC 3.3.1 x86_64-win64-win32/win64

okay with Lazarus 2.1.0 r63084 FPC 3.3.1 x86_64-win64-win32/win64
It would appear the truck is following standard practice of windows behavior.
Those that remember the older days when you enter the size you had a gray box that floated and when you released it the WM_SIZE message then was sent to your app.
 
It looks like maybe the WM_EXITSIZEMOVE message is being implemented which is the correct way to do this, prior to this it seems it was a hack! No surprise though :(

 Maybe the LCL could benefit having a OnChangingbounds instead of just OnBoundsChanged with all the info supplied to make alternate changes ..

 Attached is your test file which I inserted what appears that could be cross platform..
The only true wisdom is knowing you know nothing

egsuh

  • Hero Member
  • *****
  • Posts: 791
Re: form resize event not firing correctly.
« Reply #6 on: June 21, 2021, 07:49:06 am »
Doesn't it call the event handler recursively?

jamie

  • Hero Member
  • *****
  • Posts: 4751
Re: form resize event not firing correctly.
« Reply #7 on: June 21, 2021, 11:21:31 pm »
Delphi developed some bad hack practices over the  years, this one of them.

 Its not generally a good idea to be changing the size of a window during a size operation after the fact, it causes flicker,flashes or what ever..
  Most MS code and others sends this message when the WM_EXITSIZEMOVE message is generated which happens after the user releases move or size operations, then the WM_SIZE message is posted carrying the last size info..

Lazarus seems to handle all the child sizing and anchoring during the WM_WindowPosCHanged which does track the action.

 Delphi does the same but what its doing is sending fake WM_MOVE/WM_SIZE messages that reach those handlers.

 I am not sure where at what point Delphi decides to do any work that maybe needed but in the old days it was generally done in the WM_SIZE/WM_MOVE handler when mouse was released.

 I really think the LCL form should have a OnBoundsChanging event that carries the VAR MEssage so that it can be adjusted on the fly by user code. With that, if the user still wants the old style then from that they can call directly the OnResize



 You can think of the WM_MOVE and SIZE as a place where you can log your window position  for later restoring like a config file.

The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018