Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 290650

Summary: [Layout] If a composite with a FillLayout (with marginWidth != 0) contains a widget which could expand depending on a fixed width or height, than computeSize() doesn't calculate the expanding size correctly.
Product: [Eclipse Project] Platform Reporter: andreas <au>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: eheck, ericwill, pinnamur, vasko
Version: 4.8Keywords: helpwanted, triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux   
See Also: https://git.eclipse.org/r/101950
https://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=2b5b61a8a721d5c2a84df9cac18fb280a04de0fc
Whiteboard: stalebug
Attachments:
Description Flags
test class
none
Another test case none

Description andreas CLA 2009-09-27 10:03:21 EDT
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.6) Gecko/2009011912 Firefox/3.0.6
Build Identifier: swt-3.5-gtk-linux-x86.zip (R-3.5-200906111540)

e.g.: A Composite with FillLayout (which has a marginWidth), contains a text-widget which should expand vertically depending on the fixed width given to computeSize() with wHint, than the height-result of composite.computeSize(wHint, SWT.DEFAULT) is not big enough to contain the full text-widget.
The problem is, that FillLayout.computeSize() passes wHint of the composite to computeChildSize(text-widget, wHint, SWT.DEFAULT, true). 

the text-widget calculates his heigth for wHint of the composite which leads to the wrong result. the text-widget should calculate his heigth with (wHint - 2*marginWidth)

I think FillLayout.computeSize() should be changed to:
...
         if (type == SWT.HORIZONTAL && wHint != SWT.DEFAULT) {
            w = Math.max (0, (wHint - 2 * this.marginWidth - (count - 1) * spacing) / count);
         }
         if (type == SWT.VERTICAL && hHint != SWT.DEFAULT) {
            h = Math.max (0, (hHint - 2 * this.marginHeight - (count - 1) * spacing) / count);
         }
...



Reproducible: Always

Steps to Reproduce:
1. Start the test-class
2. the first composite calculates the wrong height, the second one with no margin is working as expected.
Comment 1 andreas CLA 2009-09-27 10:07:32 EDT
Created attachment 148201 [details]
test class
Comment 2 andreas CLA 2009-09-27 12:12:08 EDT
sorry my first solution was not correct, FillLayout.computeSize() should be changed to:
...
      int w = wHint - 2 * this.marginWidth, h = hHint - 2 * this.marginHeight;
      if (count > 0) {
         if (type == SWT.HORIZONTAL && wHint != SWT.DEFAULT) {
            w = Math.max (0, (w - (count - 1) * spacing) / count);
         }
         if (type == SWT.VERTICAL && hHint != SWT.DEFAULT) {
            h = Math.max (0, (h - (count - 1) * spacing) / count);
         }
      }
...
Comment 3 Elfi Heck CLA 2010-06-01 08:34:39 EDT
I had created a test case too, before I found this existing entry. I'll just attach it now. I might add that the problem is the same on Windows.
Comment 4 Elfi Heck CLA 2010-06-01 08:36:07 EDT
Created attachment 170627 [details]
Another test case
Comment 5 Eclipse Genie CLA 2017-07-25 17:04:47 EDT
New Gerrit change created: https://git.eclipse.org/r/101950
Comment 7 Eric Williams CLA 2017-07-25 17:13:18 EDT
(In reply to Eclipse Genie from comment #6)
> Gerrit change https://git.eclipse.org/r/101950 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=2b5b61a8a721d5c2a84df9cac18fb280a04de0fc

This issue is still reproducible. Bug snippet is in master now.
Comment 8 Eclipse Genie CLA 2020-08-02 02:55:04 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.