Community
Participate
Working Groups
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
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.
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.
>>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.
Steve / Silenio: Is this better?
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.
Is this a duplicate of bug 26095 ?
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.
*** This bug has been marked as a duplicate of 26095 ***