return;
neverDrawn = false;
}
//Compute bounds ...
Rectangle bounds = getBoundsForCanvas();
//In case item isn't displayed bounds is null
if (bounds == null || image == null || image.isDisposed()) {
//System.out.println(row.getIndex() + " nb");
return;
}
Table table = getTable();
// System.out.println("doPnt#" + row.getIndex()+": " +
// ((gc == null) ? "GC NULL" : String.valueOf(gc.getClipping())) +
// "ta="+table.getClientArea()+";bounds="+bounds);
Rectangle imageBounds = image.getBounds();
if (imageBounds.width <= 0 || imageBounds.height <= 0 || bounds.width <= 0
|| bounds.height <= 0) {
//System.out.println(row.getIndex() + " < 0");
return;
}
Rectangle tableBounds = table.getClientArea();
if (bounds.y + bounds.height - tableBounds.y < table.getHeaderHeight()
|| bounds.y > tableBounds.height) {
// System.out.println("doPnt#" + row.getIndex() + ": "
// + (bounds.y + bounds.height - tableBounds.y) + "<" + tableBounds.y
// + " || " + bounds.y + " > " + tableBounds.height);
return;
}
if (orientation == SWT.FILL) {
if (imageBounds.width != bounds.width
|| imageBounds.height != bounds.height) {
//System.out.println("doPaint() sizewrong #"+row.getIndex()+ ". Image="+imageBounds +";us="+bounds);
/**/
// Enable this for semi-fast visual update with some flicker
boolean ourGC = (gc == null);
if (ourGC)
gc = new GC(table);
if (gc != null) {
int iAdj = VerticalAligner.getTableAdjustVerticalBy(table);
bounds.y += iAdj;
iAdj = VerticalAligner.getTableAdjustHorizontallyBy(table);
bounds.x += iAdj;
gc.drawImage(image, 0, 0, imageBounds.width, imageBounds.height,
bounds.x, bounds.y, bounds.width, bounds.height);
if (ourGC)
gc.dispose();
}
// _OR_ enable refresh() for slower visual update with lots of flicker
//refresh();
// OR, disable both and image will be updated on next graphic bar update
// TODO: make config option to choose
/**/
invalidate();
return;
}
} else {
if (imageBounds.width < bounds.width) {
if (orientation == SWT.CENTER)
bounds.x += (bounds.width - imageBounds.width) / 2;
else if (orientation == SWT.RIGHT)
bounds.x = (bounds.x + bounds.width) - imageBounds.width;
}
if (imageBounds.height < bounds.height) {
bounds.y += (bounds.height - imageBounds.height) / 2;
}
}
Rectangle clipping = new Rectangle(bounds.x, bounds.y,
bounds.width,
bounds.height);
int iMinY = table.getHeaderHeight() + tableBounds.y;
if (clipping.y < iMinY) {
clipping.height -= iMinY - clipping.y;
clipping.y = iMinY;
}
int iMaxY = tableBounds.height + tableBounds.y;
if (clipping.y + clipping.height > iMaxY)
clipping.height = iMaxY - clipping.y + 1;
if (clipping.width <= 0 || clipping.height <= 0) {
//System.out.println(row.getIndex() + " clipping="+clipping + ";" + iMinY + ";" + iMaxY + ";tca=" + tableBounds);
return;
}
// See Eclipse Bug 42416
// "[Platform Inconsistency] GC(Table) has wrong origin"
// Notes/Questions:
// - GTK's "new GC(table)" starts under header, instead of above
// -- so, adjust bounds up
// - Appears to apply to new GC(table) AND GC passed by PaintEvent from a Table PaintListener
// - Q) .height may be effected (smaller than it should be). How does this effect clipping?
// - Q) At what version does this bug start appearing?
// A) Reports suggest at least 2.1.1
int iAdj = VerticalAligner.getTableAdjustVerticalBy(table);
bounds.y += iAdj;
clipping.y += iAdj;
// New: GTK M8+ has a bounds.x bug.. works fine in M7, but assume people have M8 or higher (3.0final)
iAdj = VerticalAligner.getTableAdjustHorizontallyBy(table);
bounds.x += iAdj;
clipping.x += iAdj;
boolean ourGC = (gc == null);
if (ourGC) {
gc = new GC(table);
if (gc == null) {
return;
}
}
Point srcStart = new Point(clipping.x - bounds.x, clipping.y - bounds.y);
Rectangle dstRect = new Rectangle(clipping.x, clipping.y,
imageBounds.width - srcStart.x, imageBounds.height - srcStart.y);
Utils.drawImage(gc, image, srcStart, dstRect, clipping, 0, 0, false);
if (ourGC) {