custom drawing table items in GTK 2.18 [message #501581] |
Wed, 02 December 2009 21:33 |
Alex Ignácio da Silva 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 #502061 is a reply to message #501678] |
Sat, 05 December 2009 01:05 |
Alex Ignácio da Silva 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();
}
}
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05030 seconds