Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 381851

Summary: SWT GC only copies viewable area of a scrolled composite to a GC
Product: [Eclipse Project] Platform Reporter: abadamcd1 abadamcd1 <abadamcd1>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: CLOSED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: arunkumar.thondapu, ericwill, Silenio_Quarti
Version: 3.7.2Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux-GTK   
Whiteboard:
Attachments:
Description Flags
Image of the results none

Description abadamcd1 abadamcd1 CLA 2012-06-06 09:00:33 EDT
So I've noticed a difference in behavior between Windows and Linux.  Test machines are Windows 7 64 bit and Ubuntu Linux 12.04 64 bit.  

Hierarchy of the SWT controls
Shell -> Scrolled Composite -> composite -> lots of buttons

Whenever I use the the normal composite's or even the scrolled composites print command to print to a GC, it will only copy the viewable area on the Linux machine.  On Windows 7, it copies the entire contents of the composite.  

Below is code to generate this example and attached are the results of the code on the respective platforms.


Shell shell = new Shell(getDisplay());
shell.setLayout(new FillLayout());
shell.setSize(200, 200);
shell.setLocation(20, 20);

final ScrolledComposite sc = new ScrolledComposite(shell, SWT.BORDER  | SWT.V_SCROLL | SWT.H_SCROLL);
sc.setLayout(new GridLayout(1,true));

final Composite innerComposite = new Composite(sc, SWT.NONE);
innerComposite.setSize(400, 400);
innerComposite.setLayout(new GridLayout(1, true));
innerComposite.setBackground(new Color(getDisplay(), 255, 0, 0));

for(int i = 0; i < 10; i++)
{
        Button b = new Button(innerComposite, SWT.PUSH);
        b.setText("Text");
        b.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent e) 
            {
                Image image = new Image(getDisplay(), innerComposite.getBounds().width, innerComposite.getBounds().height);
                ImageLoader loader = new ImageLoader();

                GC gc = new GC(image);
                innerComposite.print(gc);
                
                gc.dispose();

                loader.data = new ImageData[]{image.getImageData()};
                loader.save("c:/temp/out.png", SWT.IMAGE_PNG);
            }
        });
}

sc.setMinSize(innerComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
sc.setContent(innerComposite);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);

shell.open();
Comment 1 abadamcd1 abadamcd1 CLA 2012-06-06 09:01:09 EDT
Created attachment 216928 [details]
Image of the results
Comment 2 Eric Williams CLA 2018-07-06 13:57:05 EDT
I cannot reproduce this bug on SWT from master as of today, GTK3.22, and Fedora 28.