Project: SWT
Bug 228770 setRegion on Canvas not working on linux
Reported: 2008-04-24 17:20:02 | Status: resolved fixed

using org.eclipse.swt_3.4.0.v3436a.jar and org.eclipse.swt.gtk.linux.x86_3.4.0.v3436.jar on a fedora core 5 machine The following snippet causes two canvases to be drawn whose bounds overlap, but their regions do not. The entire canvas is drawn, rather than just the regions. When I try the same snippet with Buttons instead of Canvases, the Buttons are drawn (and are selection sensitive) based on the regions. I also tested this on OSX and a Windows XP machine. The test behaved the same on OSX (separate bug filed) and on the windows box the canvases were drawn based on the regions. import org.eclipse.swt.SWT; import org.eclipse.swt.graphics.Region; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; public class OverlappedCanvas1 { public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display, SWT.CLOSE); shell.setText("FlatButtonTest"); shell.setBounds(0, 0, 300, 200); Region region = new Region(); region.add(0, 0, 150, 100); region.subtract(0,50,50,50); region.subtract(100,0,50,50); // shell.open(); Canvas b1 = new Canvas(shell, SWT.PUSH); b1.setBounds(0,0,150,100); b1.setRegion(region); b1.setBackground(display.getSystemColor(SWT.COLOR_BLUE)); Canvas b2 = new Canvas(shell, SWT.PUSH); b2.setBounds(100,0,150,100); b2.setRegion(region); b2.setBackground(display.getSystemColor(SWT.COLOR_RED)); Button b3 = new Button(shell, SWT.PUSH); b3.setBounds(150, 125, 100, 50); b3.addListener(SWT.Selection, new Listener() { public void handleEvent(Event e) { shell.close(); } }); shell.open(); while(!shell.isDisposed()) { if(!display.readAndDispatch()) display.sleep(); } display.dispose(); } }

Files changed in fix:
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java