Commit 9c0531e7 authored by Romain Bioteau's avatar Romain Bioteau Committed by GitHub
Browse files

feat(gtk3) fix coordinate for drawImage (#1441)

Closes BS-19041
parent c8ff4ab9
......@@ -23,6 +23,8 @@ import org.bonitasoft.engine.bdm.BDMQueryUtil;
import org.bonitasoft.engine.bdm.model.BusinessObject;
import org.bonitasoft.engine.bdm.model.Query;
import org.bonitasoft.studio.businessobject.i18n.Messages;
import org.bonitasoft.studio.common.widgets.GTKStyleHandler;
import org.bonitasoft.studio.common.widgets.GTKStyleHandler;
import org.bonitasoft.studio.pics.Pics;
import org.bonitasoft.studio.pics.PicsConstants;
import org.eclipse.core.databinding.observable.value.IObservableValue;
......@@ -32,8 +34,11 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
import com.google.common.base.Optional;
import com.google.common.base.Predicate;
......@@ -61,15 +66,31 @@ public class QueryStatusLabelProvider extends StyledCellLabelProvider {
if (img != null) {
final Rectangle bounds = event.item instanceof TableItem ? ((TableItem) event.item).getBounds(event.index)
: ((TreeItem) event.item).getBounds(event.index);
Widget widget = event.widget;
int headerHeight = 0;
if (widget instanceof Table) {
Table table = (Table) widget;
if (table.getHeaderVisible()) {
headerHeight = table.getHeaderHeight();
}
}
if (widget instanceof Tree) {
Tree tree = (Tree) widget;
if (tree.getHeaderVisible()) {
headerHeight = tree.getHeaderHeight();
}
}
final Rectangle imgBounds = img.getBounds();
bounds.width /= 2;
bounds.width -= imgBounds.width / 2;
bounds.height /= 2;
bounds.height -= imgBounds.height / 2;
final int x = bounds.width > 0 ? bounds.x + bounds.width : bounds.x;
final int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y;
int x = bounds.width > 0 ? bounds.x + bounds.width : bounds.x;
int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y;
if (GTKStyleHandler.isGTK3()) {
y = y - headerHeight;
}
if (SWT.getPlatform().equals("carbon")) {
event.gc.drawImage(img, x + 2, y - 1);
} else {
......
......@@ -14,6 +14,7 @@
*/
package org.bonitasoft.studio.common.jface;
import org.bonitasoft.studio.common.widgets.GTKStyleHandler;
import org.bonitasoft.studio.pics.Pics;
import org.eclipse.jface.viewers.ColumnViewer;
import org.eclipse.jface.viewers.ILabelProvider;
......@@ -22,8 +23,11 @@ import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.swt.widgets.Widget;
public abstract class AbstractCheckboxLabelProvider extends StyledCellLabelProvider implements ILabelProvider {
......@@ -66,6 +70,21 @@ public abstract class AbstractCheckboxLabelProvider extends StyledCellLabelProvi
protected void paint(final Event event, final Object element) {
final Image img = getImage(element);
if (img != null) {
Widget widget = event.widget;
int headerHeight = 0;
if (widget instanceof Table) {
Table table = (Table) widget;
if (table.getHeaderVisible()) {
headerHeight = table.getHeaderHeight();
}
}
if (widget instanceof Tree) {
Tree tree = (Tree) widget;
if (tree.getHeaderVisible()) {
headerHeight = tree.getHeaderHeight();
}
}
final Rectangle bounds = event.item instanceof TableItem ? ((TableItem) event.item).getBounds(event.index) :
((TreeItem) event.item).getBounds(event.index);
final Rectangle imgBounds = img.getBounds();
......@@ -74,9 +93,11 @@ public abstract class AbstractCheckboxLabelProvider extends StyledCellLabelProvi
bounds.height /= 2;
bounds.height -= imgBounds.height / 2;
final int x = bounds.width > 0 ? bounds.x + bounds.width : bounds.x;
final int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y;
int x = bounds.width > 0 ? bounds.x + bounds.width : bounds.x;
int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y;
if (GTKStyleHandler.isGTK3()) {
y = y - headerHeight;
}
if (SWT.getPlatform().equals("carbon")) {
event.gc.drawImage(img, x + 2, y - 1);
} else {
......
......@@ -28,7 +28,7 @@ public class GTKStyleHandler {
return isGTK() ? style ^ SWT.BORDER : style;
}
private static boolean isGTK3() {
public static boolean isGTK3() {
String gtkVersion = System.getProperty("org.eclipse.swt.internal.gtk.version");
return gtkVersion != null && gtkVersion.startsWith("3");
}
......
......@@ -15,38 +15,34 @@
package org.bonitasoft.studio.validation.ui.view;
import org.bonitasoft.studio.common.log.BonitaStudioLog;
import org.bonitasoft.studio.common.widgets.GTKStyleHandler;
import org.bonitasoft.studio.validation.i18n.Messages;
import org.eclipse.core.internal.resources.Marker;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableItem;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
/**
* @author Florine Boudin
*/
public class SeverityColumnLabelProvider extends StyledCellLabelProvider
implements ILabelProvider {
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
*/
@Override
public Image getImage(final Object element) {
return null;
}
/*
* (non-Javadoc)
* @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
*/
@Override
public String getText(final Object element) {
try {
......@@ -67,23 +63,30 @@ public class SeverityColumnLabelProvider extends StyledCellLabelProvider
final Image image = getImageForSeverity(severity);
final Rectangle bounds = ((TableItem) event.item)
.getBounds(event.index);
final Rectangle imgBounds = image.getBounds();
bounds.width /= 2;
bounds.width -= imgBounds.width / 2;
bounds.height /= 2;
bounds.height -= imgBounds.height / 2;
final int x = bounds.width > 0 ? bounds.x + bounds.width : bounds.x;
final int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y;
event.gc.drawImage(image, x, y);
Point location = getLocation(image, bounds, (Table) event.widget);
GC gc = event.gc;
gc.drawImage(image, location.x, location.y);
} catch (final CoreException e) {
BonitaStudioLog.error(e);
}
}
}
protected Point getLocation(final Image image, final Rectangle bounds, Table widget) {
final Rectangle imgBounds = image.getBounds();
bounds.width /= 2;
bounds.width -= imgBounds.width / 2;
bounds.height /= 2;
bounds.height -= imgBounds.height / 2;
int x = bounds.width > 0 ? bounds.x + bounds.width : bounds.x;
int y = bounds.height > 0 ? bounds.y + bounds.height : bounds.y;
if (GTKStyleHandler.isGTK3()) {
y = y - widget.getHeaderHeight();
}
return new Point(x, y);
}
/**
* @param status
* @return
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment