Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 334435 - Control.print(GC) doesn't work
Summary: Control.print(GC) doesn't work
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.6.1   Edit
Hardware: PC Solaris-GTK
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-01-14 17:03 EST by GRudiD CLA
Modified: 2017-06-20 02:33 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description GRudiD CLA 2011-01-14 17:03:32 EST
Build Identifier: eclipse-rcp-helios-SR1-linux-gtk.tar.gz

The printing of a control via control.print(gc) on a composite produces a strange image on display. See the following code to repoduce this behaviour:


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.ScrollBar;
import org.eclipse.swt.widgets.Shell;
 
public class SWTTest {
    private Composite seComposite;
    private Composite nwComposite;
    private Composite neComposite;
    private Composite swComposite;
    
    private Label label;
    
    public SWTTest(final Composite parent, int style) {
        int headerHeight = 20;
        int fixedWidth = 50;
        FormData formData;
        
        formData = new FormData();
        formData.top = new FormAttachment(0, 0);
        formData.right = new FormAttachment(0, fixedWidth);
        formData.bottom = new FormAttachment(0, headerHeight);
        formData.left = new FormAttachment(0, 0);
        
        nwComposite = new Composite(parent, SWT.NONE);
        nwComposite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_YELLOW));
        nwComposite.setLayoutData(formData);
        
        formData = new FormData();
        formData.top = new FormAttachment(0, 0);
        formData.right = new FormAttachment(100, 0);
        formData.bottom = new FormAttachment(0, headerHeight);
        formData.left = new FormAttachment(0, fixedWidth);
        
        neComposite = new Composite(parent, SWT.NONE);
        neComposite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_RED));
        neComposite.setLayoutData(formData);
        
        formData = new FormData();
        formData.top = new FormAttachment(0, headerHeight);
        formData.right = new FormAttachment(0, fixedWidth);
        formData.bottom = new FormAttachment(100, 0);
        formData.left = new FormAttachment(0, 0);
        
        swComposite = new Composite(parent, SWT.NONE);
        swComposite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_GREEN));
        swComposite.setLayoutData(formData);
        
        formData = new FormData();
        formData.top = new FormAttachment(0, headerHeight);
        formData.right = new FormAttachment(100, 0);
        formData.bottom = new FormAttachment(100, 0);
        formData.left = new FormAttachment(0, fixedWidth);
        
        seComposite = new Composite(parent, SWT.H_SCROLL | SWT.V_SCROLL);
        seComposite.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_BLUE));
        seComposite.setLayoutData(formData);
        seComposite.addPaintListener(new PaintListener() {
            public void paintControl(PaintEvent event) {
                if (label == null || label.isDisposed())
                    return;
                
                event.gc.setClipping(0, 0, 100, 20);
 
                Transform transform = new Transform(event.gc.getDevice());
                transform.translate(-5, -5);
                event.gc.setTransform(transform);
                // produce strange image
                label.print(event.gc);
                event.gc.dispose();
            }
        });
        
        label = new Label(seComposite, SWT.NONE);
        label.setText("TEST 123 TEST 456");
        label.setBackground(label.getDisplay().getSystemColor(SWT.COLOR_CYAN));
        label.setBounds(100, 100, 100, 20);
    }
    
    public static void main(String[] args) {
        Display display = Display.getDefault();
 
        Shell shell = new Shell();
        shell.setText("Shell");
        shell.setLayout(new FormLayout());
        
        new SWTTest(shell, SWT.NONE);
        
        shell.setSize(400, 400);
        shell.open();
 
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch())
                display.sleep();
        }
        display.dispose();
    }
}

Reproducible: Always
Comment 1 Lakshmi P Shanmugam CLA 2017-06-20 02:33:32 EDT
Solaris is no longer a supported platform.