Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » custom drawing table items in GTK 2.18
custom drawing table items in GTK 2.18 [message #501581] Wed, 02 December 2009 21:33 Go to next message
Alex Ignácio da Silva is currently offline Alex Ignácio da SilvaFriend
Messages: 23
Registered: July 2009
Junior Member
Hi all,

In my application I have a table widget where I do custom painting of
its table items by attaching listeners to the table's SWT.MeasureItem,
SWT.EraseItem and SWT.EraseItem events.

It works well under both Linux and Windows, but it has been broken by
the new release of GTK 2.18, as I noticed when trying my application in
Ubuntu Karmic.

The problem is that the underlying GTK widget implementation draws a
dotted line separating the table columns, which makes my widget render
incorrectly:

http://www.haundrix.com/customTableDrawingBug/screenshot1.pn g

Calling Table.setLinesVisible(false) has no effect, it only makes the
lines thicker if one passes the value true instead of false.

I've also tried disabling all native drawing by setting in the
SWT.EraseItem listener code:

event.detail &= ~SWT.FOREGROUND;
event.detail &= ~SWT.BACKGROUND;
event.detail &= ~SWT.SELECTED;
event.detail &= ~SWT.FOCUSED;
event.detail &= ~SWT.HOT;

or even:

event.doit = false;

but that doesn't prevent the dotted lines from being drawn.

In this screenshot I'm doing all the drawing myself, drawing a blue
background across the whole cell, but it seems like the dotted line is
drawn by GTK after SWT has done all of the custom drawing:

http://www.haundrix.com/customTableDrawingBug/screenshot2.pn g

Any ideas on how get away with the dotted line separating the table columns?
Does anyone know of a way to change GTK's behavior (perhaps setting a
magical environment variable)?

Thanks,

Alex
Re: custom drawing table items in GTK 2.18 [message #501678 is a reply to message #501581] Thu, 03 December 2009 12:29 Go to previous messageGo to next message
Praveen  is currently offline Praveen Friend
Messages: 86
Registered: July 2009
Member
I am not able to reproduce your scenario. I could get the table
*without* any grid lines separating the columns using custom painting
(altering the snippet230 slightly).
Can you provide us a snippet reproducing the behavior ?
Re: custom drawing table items in GTK 2.18 [message #502061 is a reply to message #501678] Sat, 05 December 2009 01:05 Go to previous messageGo to next message
Alex Ignácio da Silva is currently offline Alex Ignácio da SilvaFriend
Messages: 23
Registered: July 2009
Junior Member
Hi Praveen,

Praveen wrote:
> I am not able to reproduce your scenario. I could get the table
> *without* any grid lines separating the columns using custom painting
> (altering the snippet230 slightly).

Are you on a distro with GTK 2.18?

> Can you provide us a snippet reproducing the behavior ?

I played a little with Snippet230 without success (see below).
Everything I tried didn't get rid of the dotted lines separating the
columns. Could you please show me how you changed it?

Another point which is confusing me: the value of event.width on the
PaintItem event is not retaining the value set on the MeasureItem event,
whereas the value of event.height is slightly larger by 2 or 4 pixels.
Is this the expected behavior???

Thank you very much,

Alex

-----------------------------------------

package org.eclipse.swt.snippets;

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Snippet230 {

public static void main(String[] args) {
final Display display = new Display();
final Image image = display.getSystemImage(SWT.ICON_INFORMATION);
Shell shell = new Shell(display);
shell.setText("Images on the right side of the TableItem");
shell.setLayout(new FillLayout());
Table table = new Table(shell, SWT.MULTI | SWT.FULL_SELECTION);
table.setHeaderVisible(true);
table.setLinesVisible(false); // changing this to true makes
the dotted lines thicker
int columnCount = 3;
for(int i = 0; i < columnCount; i++) {
TableColumn column = new TableColumn(table, SWT.NONE);
column.setText("Column " + i);
}
int itemCount = 8;
for(int i = 0; i < itemCount; i++) {
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[] {"item " + i + " a", "item " + i +
" b", "item " + i + " c"});
}
Listener paintListener = new Listener() {
public void handleEvent(Event event) {
switch(event.type) {
case SWT.MeasureItem: {
int index = event.index;
Rectangle rect = image.getBounds();
event.width += rect.width;
event.height = Math.max(event.height, rect.height + 2);
break;
}
case SWT.EraseItem: {
event.detail &= ~SWT.FOREGROUND;
event.detail &= ~SWT.BACKGROUND;
event.detail &= ~SWT.SELECTED;
event.detail &= ~SWT.FOCUSED;
event.detail &= ~SWT.HOT;
event.doit = false;
break;
}
case SWT.PaintItem: {
int index = event.index;
Rectangle rect = image.getBounds();

// shouldn't we subtract rect.width?
// it looks like the event.width value set in the
SWT.MeasureItem wasn't retained...
// int x = event.x + event.width /*- rect.width*/;

// int offset = Math.max(0, (event.height -
rect.height) / 2);
// event.gc.drawImage(image, x, event.y + offset);

// draws only a blue background filling up the
entire cell
Color blue = display.getSystemColor(SWT.COLOR_BLUE);
event.gc.setBackground(blue);
int adhocOffset = 2;
event.gc.fillRectangle(event.x - adhocOffset, event.y,
event.width + rect.width + adhocOffset,
event.height);

break;
}
}
}
};
table.addListener(SWT.MeasureItem, paintListener);
table.addListener(SWT.EraseItem, paintListener);
table.addListener(SWT.PaintItem, paintListener);

for(int i = 0; i < columnCount; i++) {
table.getColumn(i).pack();
}
shell.setSize(500, 500);
shell.open();
while(!shell.isDisposed()) {
if(!display.readAndDispatch())
display.sleep();
}

// this is incorrect, the image wasn't allocated by the user!
// if(image != null)
// image.dispose();

display.dispose();
}
}
Re: custom drawing table items in GTK 2.18 [message #515180 is a reply to message #501581] Thu, 18 February 2010 01:33 Go to previous messageGo to next message
Kevin Hand is currently offline Kevin HandFriend
Messages: 3
Registered: July 2009
Junior Member
I encountered the column width being slightly to short issue.

It is caused by you by changing the event.width in your MeasureItem. simply add 1 (or grid line width) and it should remedy your problem.

case SWT.MeasureItem: {
int index = event.index;
Rectangle rect = image.getBounds();
event.width = event.width + rect.width + 1;
event.height = Math.max(event.height, rect.height + 2);
break;
}
Re: custom drawing table items in GTK 2.18 [message #517030 is a reply to message #515180] Thu, 25 February 2010 14:40 Go to previous messageGo to next message
Alex Ignácio da Silva is currently offline Alex Ignácio da SilvaFriend
Messages: 23
Registered: July 2009
Junior Member
Hi Kevin,

I tried setting the column widths larger by one or a few pixels and I
still get the undesired grid lines separating the columns when running
on GTK 2.18. Was it supposed to fix this issue?

Alex

Kevin Hand wrote:
> I encountered the column width being slightly to short issue.
>
> It is caused by you by changing the event.width in your MeasureItem.
> simply add 1 (or grid line width) and it should remedy your problem.
>
> case SWT.MeasureItem: {
> int index = event.index;
> Rectangle rect = image.getBounds();
> event.width = event.width + rect.width + 1;
> event.height = Math.max(event.height, rect.height + 2);
> break;
> }
>
Re: custom drawing table items in GTK 2.18 [message #517031 is a reply to message #517030] Thu, 25 February 2010 19:46 Go to previous messageGo to next message
Kevin Hand is currently offline Kevin HandFriend
Messages: 3
Registered: July 2009
Junior Member
Sorry. I posted this on the wrong thread. I couldn't figure out how to delete my post though.
Re: custom drawing table items in GTK 2.18 [message #517234 is a reply to message #517030] Fri, 26 February 2010 16:12 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
Hi,

I don't think there's a way for you to make these lines not appear, these
seem to be coming from GTK (I'm not sure which GTK version this started in).
It may be possible for swt to turn them off in the linesVisible==false case,
so I would suggest logging a report at
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=SWT
and specify that you're using GTK 2.18.

Grant


"Alex Ign
Re: custom drawing table items in GTK 2.18 [message #517268 is a reply to message #517234] Fri, 26 February 2010 13:34 Go to previous messageGo to next message
Alex Ignácio da Silva is currently offline Alex Ignácio da SilvaFriend
Messages: 23
Registered: July 2009
Junior Member
Hi Grant,

Yes, I think the custom table item drawing facilities of SWT should
allow one to completely override the platform behavior and let the
application do all the painting, if necessary. And that would apply to
cell grid lines too, so I filed the following bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=299405

As this has broken my application in recent Linux distros it seems like
I'll have to throw away the custom table item drawing facilities of SWT
and create my own custom table widget from scratch... :-(

Alex

Grant Gayed wrote:
> Hi,
>
> I don't think there's a way for you to make these lines not appear, these
> seem to be coming from GTK (I'm not sure which GTK version this started in).
> It may be possible for swt to turn them off in the linesVisible==false case,
> so I would suggest logging a report at
> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=Platform &component=SWT
> and specify that you're using GTK 2.18.
>
> Grant
Re: custom drawing table items in GTK 2.18 [message #517278 is a reply to message #517268] Fri, 26 February 2010 18:40 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Am 26.02.10 19:28, schrieb Alex Ignácio da Silva:
> Hi Grant,
>
> Yes, I think the custom table item drawing facilities of SWT should
> allow one to completely override the platform behavior and let the
> application do all the painting, if necessary. And that would apply to
> cell grid lines too, so I filed the following bug:
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=299405
>
> As this has broken my application in recent Linux distros it seems like
> I'll have to throw away the custom table item drawing facilities of SWT
> and create my own custom table widget from scratch... :-(
>

Why not using Nebula-Grid? It has a JFace-Viewer is and is completely
custom drawn.

Tom
Re: custom drawing table items in GTK 2.18 [message #517328 is a reply to message #517278] Fri, 26 February 2010 23:03 Go to previous messageGo to next message
Alex Ignácio da Silva is currently offline Alex Ignácio da SilvaFriend
Messages: 23
Registered: July 2009
Junior Member
Hi Tom,

I remember having previously considered using the Nebula Grid widget,
but I think I preferred to stay with the standard custom table drawing
facilities of SWT due to the alpha state of the current Nebula Grid
release. Also, I wasn't aware that it too allows customization of the
painting by the client.

Maybe now that's the way I should go. :-) Is it ready for production
applications despite not having stabilized its API?

Alex

Tom Schindl wrote:
> Why not using Nebula-Grid? It has a JFace-Viewer is and is completely
> custom drawn.
>
> Tom
Re: custom drawing table items in GTK 2.18 [message #517332 is a reply to message #517328] Fri, 26 February 2010 23:36 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6651
Registered: July 2009
Senior Member
Well - the alpha state doesn't reflect reality. Nebula-Grid is stable
and we are working towards a release some time in the first half of the
year.

We didn't have API breaks since a long time (well not 100% true we fixed
a typo but that's it). Grid tries to have the same API than Table/Tree.

Tom

Am 27.02.10 00:03, schrieb Alex Ignácio da Silva:
> Hi Tom,
>
> I remember having previously considered using the Nebula Grid widget,
> but I think I preferred to stay with the standard custom table drawing
> facilities of SWT due to the alpha state of the current Nebula Grid
> release. Also, I wasn't aware that it too allows customization of the
> painting by the client.
>
> Maybe now that's the way I should go. :-) Is it ready for production
> applications despite not having stabilized its API?
>
> Alex
>
> Tom Schindl wrote:
>> Why not using Nebula-Grid? It has a JFace-Viewer is and is completely
>> custom drawn.
>>
>> Tom
Re: custom drawing table items in GTK 2.18 [message #517342 is a reply to message #517332] Sat, 27 February 2010 01:29 Go to previous message
Alex Ignácio da Silva is currently offline Alex Ignácio da SilvaFriend
Messages: 23
Registered: July 2009
Junior Member
Hi Tom,

I will definitely give Nebula Grid a try when I revisit this specific
problem with my application.

Thank you very much for the advice,

Alex

Tom Schindl wrote:
> Well - the alpha state doesn't reflect reality. Nebula-Grid is stable
> and we are working towards a release some time in the first half of the
> year.
>
> We didn't have API breaks since a long time (well not 100% true we fixed
> a typo but that's it). Grid tries to have the same API than Table/Tree.
>
> Tom
Previous Topic:MAC OS SWT Shell iconified/deiconified listener problem
Next Topic:Popup menu from menu item, similar to IE Favorites popup
Goto Forum:
  


Current Time: Wed Dec 04 16:42:18 GMT 2024

Powered by FUDForum. Page generated in 0.05030 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top