Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 24362 - DCR - need API to grab a bitmap of a widget
Summary: DCR - need API to grab a bitmap of a widget
Status: RESOLVED DUPLICATE of bug 26095
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 2.0.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-10-03 14:24 EDT by David J. Orme CLA
Modified: 2003-09-26 18:44 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David J. Orme CLA 2002-10-03 14:24:28 EDT
In the following code from the "how do I print a widget" answer in the SWT faq:

  Point size = myWidget.getSize();
  Image image = new Image(display, size.x, size.y);
  GC gc = new GC(myWidget);
  gc.copyArea(image, 0, 0);
  gc.dispose();

image contains a bitmap representation of myWidget IFF myWidget is visible and
is completely unobscured.

In other words, if myWidget is obscured in any way including but not limited to
being partly off the screen, setVisible(false), on a separate page of a
PageBook, beneath or partly beneath another window, the resulting Image will not
contain a correct bitmap representation of myWidget.

This makes it impossible to print any widget that could potentially be obscured
and for whatever reason cannot be brought to the front, made visible, etc.

This behavior is also documented at:

http://dev.eclipse.org/newslists/news.eclipse.tools/msg00924.html
Comment 1 Steve Northover CLA 2002-10-04 09:42:54 EDT
I don't think that 'gc.copyArea() should work when source is invisible' is 
actually right in the sense that copyArea should not be changed.  The real 
problem I believe is that there is no SWT API to print the contents of a 
widget.  SSQ, can you confirm this assessment and rename this PR to DCR (change 
the title to 'DCR - need API to print the contents of a widget')?  Thanks.
Comment 2 Silenio Quarti CLA 2002-10-04 10:47:01 EDT
The behavior of copyArea() is correct. Copying bits from the screen
is not the most appropriated way of printing the contents of a widget.
There are platforms that provide a way of copying obscured areas of
a widget, but this is rare. We need a proper API for printing
widgets.
Comment 3 David J. Orme CLA 2002-10-04 10:48:54 EDT
>>The real problem I believe is that there is no SWT API to print the contents 
of a widget.<<

I would have to respectfully disagree with this assessment because I need the 
API for more purposes than just printing.  That was just the motivating example 
I chose to use.

I believe that what is needed is a general way to grab a bitmap of a Composite 
and its contents, no matter if it is obscured or not.  What is done thereafter 
with the data should be up to the programmer.

However, if the best way to support this is to create a different API and not 
change copyArea, I would not have a problem with that aspect of Steve's 
assesment.
Comment 4 David J. Orme CLA 2002-10-04 10:51:02 EDT
Steve / Silenio: Is this better?
Comment 5 Joe Winchester CLA 2002-11-06 09:35:55 EST
I think the API should be a new one rather than the existing one of using the GC 
constructor with the widget itself.  The AWT API for java.awt.Component 
has two methods,  public void print(Graphics g) and public void printAl(Graphics 
g).  The first one just draws the component and the second one includes 
children.  Both of them work if the component is obscured, such as a notebook 
page that isn't visible or a widget that has been clipped by its parent, and I 
think the SWT API should do likewise.  If I had my preference I think the SWT 
API should paint the component and its children.  The API is very useful for 
GUI builders where you want to keep the live widgets off screen and away from 
the user and let the tool work with just lightweight figures using GEF or some 
kind of drawing framework.
Comment 6 Ed Burnette CLA 2003-07-31 23:52:41 EDT
Is this a duplicate of bug 26095 ?
Comment 7 Richard Kulp CLA 2003-08-01 10:31:19 EDT
If you look at it date wise, 26095 came after this, but 26095 has better
comments in it for what we want to have done. So yeah this is a dup.
Comment 8 Steve Northover CLA 2003-09-26 18:44:21 EDT

*** This bug has been marked as a duplicate of 26095 ***