Bug 273569 - [TableEditor] arithmetical flaw in computeBounds
Summary: [TableEditor] arithmetical flaw in computeBounds
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 269065
  Show dependency tree
 
Reported: 2009-04-24 06:06 EDT by Ralf Sternberg CLA
Modified: 2019-09-06 15:31 EDT (History)
3 users (show)

See Also:


Attachments
Patch against linux GTK version (731 bytes, patch)
2009-04-24 06:12 EDT, Ralf Sternberg CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ralf Sternberg CLA 2009-04-24 06:06:38 EDT
pre. TableItem item = ...;
itemBounds = item.getBounds( column );
imageBounds = item.getImageBounds( column );

The code in TableEditor#computeBounds seems to rely on the fact that itemBounds.x == imageBounds.x which holds true at least under Windows XP and GTK. If there is an offset between itemBounds.x and imageBounds.x, as it is the case with table padding in RAP, then the computed bounds will exceed the right edge of the cell by the amount of this offset.

Example:

pre. 
 +-+-------+-+------------+-+
 | |       | |            | |
 | |  img  | |    text    | |
 | |       | |            | |
 +-+-------+-+------------+-+
 0 2  ...  18       ...     100
             |<-------------->|
                   editor

In this example, itemBounds would be (0, 0, 100, y), imageBounds would be (2, 0, 16, y).
The computed bounds would be (18, 0, 84, y) instead of expected (18, 0, 82, y), because the 2px left image offset are missing in the computation. I'll attach a patch that fixes the problem.
Comment 1 Ralf Sternberg CLA 2009-04-24 06:12:56 EDT
Created attachment 133090 [details]
Patch against linux GTK version

This patch adds another optimization: the left offset is only applied to the editor bounds if there is an image. For columns without image, the editor starts at the left edge of the cell. This improves the layout in case the table has a padding, as it is the case in RAP.
Please note that this patch does not change the existing layout in SWT.
Comment 2 Felipe Heidrich CLA 2009-04-24 11:20:15 EDT
(In reply to comment #0)
> itemBounds.x == imageBounds.x which holds true at least under Windows XP and
> GTK. 

In XP and GTK, TableEditor#computeBounds is working fine then ?
Where does it fail ?

In the patch I see 'if (rect.width > 0)' , is there a reason for that ? Are you getting negative width somewhere ?


I'm trying to determine if the problem is in TableEditor or in TableItem#getImageBounds.

Steve, is itemBounds.x == imageBounds.x expected to be the same ?
Comment 3 Ralf Sternberg CLA 2009-04-27 09:06:29 EDT
(In reply to comment #2)
> In XP and GTK, TableEditor#computeBounds is working fine then ?
> Where does it fail ?

The problem exists in RAP (www.eclipse.org/rap), where we have configurable cell paddings (but still strive for using as much original SWT code as possible). I think the question is whether the case that imageBounds.x > itemBounds.x is considered valid.

> In the patch I see 'if (rect.width > 0)' , is there a reason for that ? Are you
> getting negative width somewhere ?

As I explained in comment 1, this makes editors begin at the very left edge in case there is a cell padding. The meaning is: "If there is an image, let the editor begin after the image, otherwise let it span the entire cell".
Comment 4 Steve Northover CLA 2009-04-27 13:29:01 EDT
> Steve, is itemBounds.x == imageBounds.x expected to be the same ?

Certainly not in a tree.  We return whatever the platform provides for the image and text bounds.  If there is extra space on the platform, then the bounds have extra space.  Custom draw table and tree listeners can use the image and text bounds to draw the same way as the platform.

Having said all that, do we have a bug?

Comment 5 Felipe Heidrich CLA 2009-05-11 15:08:24 EDT
Can you attach a SWT snippet that shows the problem ?
I'll have it fixed post 3.5.
Thank you
Comment 6 Eclipse Webmaster CLA 2019-09-06 15:31:48 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.

If you have further information on the current state of the bug, please add it. 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.