Bug 969 - NewtCanvasSWT positioning and resizing issues
Summary: NewtCanvasSWT positioning and resizing issues
Status: RESOLVED FIXED
Alias: None
Product: Newt
Classification: JogAmp
Component: swt (show other bugs)
Version: 2.4.0
Hardware: All all
: --- normal
Assignee: Petros Koutsolampros
URL:
Depends on: 672 822 956 985
Blocks: 674
  Show dependency treegraph
 
Reported: 2014-02-10 12:53 CET by Petros Koutsolampros
Modified: 2020-01-15 12:53 CET (History)
2 users (show)

See Also:
Type: DEFECT
SCM Refs:
78fcb8228d4a391054501aef16eb0462322ba39d
Workaround: ---


Attachments
Basic NewtCanvasSWT tester with Sash (3.10 KB, text/x-java)
2014-02-10 18:20 CET, Petros Koutsolampros
Details
patch to fix positioning in OSX (4.31 KB, application/octet-stream)
2014-02-10 20:15 CET, Petros Koutsolampros
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Petros Koutsolampros 2014-02-10 12:53:39 CET
Gathering issues, discussions and possible solutions here for NewtCanvasSWT positioning and resizing issues

Discussion:
http://jogamp.org/log/irc/jogamp_20140210050544.html#l15

ideas to folllow
Comment 1 Petros Koutsolampros 2014-02-10 18:20:51 CET
Created attachment 590 [details]
Basic NewtCanvasSWT tester with Sash

If we add a println(event) in NewtCanvasSWT (constr) -> listener -> handleEvent we see that:

 If we use a GridLayout (NewtSashTest.java / L42) for the NewtCanvasSWT parent, SWT.Resize events ARE NOT sent when resizing, but only once in the beginning. In OSX (Mavericks) SWT.Paint events are sent while resizing

 If we use a FillLayout (NewtSashTest.java / L41) SWT.Resize events ARE sent in the beginning and while resizing. SWT.Paint events, only in OSX when resizing

Without fix for Bug 672, NewtCanvasSWT in OSX does not get position updates, but does so in Win7x64. The fix was to take advantage of the SWT.Paint events to update position of the newtChild:

  if( SWTAccessor.isOSX ) {
    newtChild.setPosition(parent.getLocation().x,parent.getLocation().y);
  }

Problem comes with multiple parents in different places like in bug 965
Comment 2 Petros Koutsolampros 2014-02-10 20:15:27 CET
Created attachment 591 [details]
patch to fix positioning in OSX

proposed patch is to use the existing SWT method Control.setBounds(int x, int y, int width, int height); which trickles down from parent elements to help update the newtChild's position. Thus, no need for hacking the SWT.Paint event. The method getLocationOnScreen() in SWTNativeWindow is also simplified (for OSX) to use SWT's Control.toDisplay(int x, int y) which returns the position of the parent element on the screen. setBounds() can then position the element from that point, since the numbers it provides are relative to the parent element. 

The new positioning requires the newtChild to be manually positioned when it is created, otherwise the parent has to be resized for it to update its position. Thus newtChild.setPosition(getLocation().x, getLocation().y); has been placed after the creation of the SWTNativeWindow in validateNative().

Last but not least, since setBounds() will now provide coordinates relative to the parent, if the NewtCanvasSWT is not moved within the parent, it will not be updated due to line 2090 in WindowImpl.java:

if ( !isFullscreen() && ( getX() != x || getY() != y ) ) {

this line has thus been changed to allow for moving the newtChild as long as the parent is not null:

if ( !isFullscreen() && ( getX() != x || getY() != y || null != getParent()) ) {

Apart from the last piece in WindowImpl.java, all the others are wrapped with checks to only be executed in OSX since windows seems to be handling the positioning of child windows on its own...
Comment 3 Petros Koutsolampros 2014-02-25 13:21:24 CET
78fcb8228d4a391054501aef16eb0462322ba39d

Refer to commit: https://github.com/orange-vertex/jogl/commit/78fcb8228d4a391054501aef16eb0462322ba39d

Tested on OSX Mavericks and Windows 7 JVMx64. Refer to test TestBug672NewtCanvasSWTSashForm as it is a better solution for the same problem.
Comment 4 Sven Gothel 2014-02-25 13:26:48 CET
(In reply to comment #2)
> Created attachment 591 [details]
> patch to fix positioning in OSX
> 
> proposed patch is to use the existing SWT method Control.setBounds(int x,
> int y, int width, int height); which trickles down from parent elements to
> help update the newtChild's position. Thus, no need for hacking the
> SWT.Paint event. The method getLocationOnScreen() in SWTNativeWindow is also
> simplified (for OSX) to use SWT's Control.toDisplay(int x, int y) which
> returns the position of the parent element on the screen. setBounds() can
> then position the element from that point, since the numbers it provides are
> relative to the parent element. 

We discussed a probable case for a deadlock, i.e. if 
we need to run the command on the SWT-EDT
and the caller is on another thread.
Is this deadlock threat still exisiting or will you call toDisplay(..) 
always while on the SWT-EDT ?

> 
> The new positioning requires the newtChild to be manually positioned when it
> is created, otherwise the parent has to be resized for it to update its
> position. Thus newtChild.setPosition(getLocation().x, getLocation().y); has
> been placed after the creation of the SWTNativeWindow in validateNative().
> 
> Last but not least, since setBounds() will now provide coordinates relative
> to the parent, if the NewtCanvasSWT is not moved within the parent, it will
> not be updated due to line 2090 in WindowImpl.java:
> 
> if ( !isFullscreen() && ( getX() != x || getY() != y ) ) {
> 
> this line has thus been changed to allow for moving the newtChild as long as
> the parent is not null:
> 
> if ( !isFullscreen() && ( getX() != x || getY() != y || null != getParent())
> ) {

OK, as discussed

> 
> Apart from the last piece in WindowImpl.java, all the others are wrapped
> with checks to only be executed in OSX since windows seems to be handling
> the positioning of child windows on its own...

Please mention the test case name and platform for which you have
tested this patch and can confirm it's working.

Thank you.
Comment 5 Sven Gothel 2014-02-25 13:27:12 CET
(In reply to comment #3)
> 78fcb8228d4a391054501aef16eb0462322ba39d
> 
> Refer to commit:
> https://github.com/orange-vertex/jogl/commit/
> 78fcb8228d4a391054501aef16eb0462322ba39d
> 
> Tested on OSX Mavericks and Windows 7 JVMx64. Refer to test
> TestBug672NewtCanvasSWTSashForm as it is a better solution for the same
> problem.


Thank you!
Comment 6 Sven Gothel 2019-03-30 03:01:07 CET
Fix probably landed in version 2.1.5