Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul D'Pong2020-09-14 20:35:13 +0000
committerAlexander Kurtakov2020-09-23 13:00:44 +0000
commit58eb0f6cefec757d9c90b27ec5d7f1bbcfe77b77 (patch)
treed4ddffffb3a8a521591640c394ac1257c230f79e
parenta63c6d900c4e0b8ef52f6cfa8f846d37b56606b9 (diff)
downloadeclipse.platform.swt-58eb0f6cefec757d9c90b27ec5d7f1bbcfe77b77.tar.gz
eclipse.platform.swt-58eb0f6cefec757d9c90b27ec5d7f1bbcfe77b77.tar.xz
eclipse.platform.swt-58eb0f6cefec757d9c90b27ec5d7f1bbcfe77b77.zip
Bug 566902 - Adapt to drawing model changes
Added Javadoc to checkStyle in GC (trying to slowing document and standardize function formatting) Change gtk_image_get_from_surface to gtk_image_get_from_pixbuf using the pixbuf from ImageList Added gtk_image_clear to replace gtk_image_get_from_surface passed with 0 Removed connectPaint & replace it with hookPaintSignals. Moved the assignment of the snapshot vfunc of the widget class to hookEvents rather than addPaintListener. Added stripped down gtk_draw callback version for GTK4 case. (I will slowly mend the current implementation and the GTK4 but I didn't want to make a mess with a much of GTK4 if guards everywhere) Change-Id: I2161c59e59a37ffda49f225ea0eaff9978b3f64e Signed-off-by: Paul D'Pong <sdamrong@redhat.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c42
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java15
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java43
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java23
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java19
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java15
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java65
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java15
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java10
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java61
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java8
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java8
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java16
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java8
16 files changed, 240 insertions, 110 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
index 03478612a9..b2dc9dfa0d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c
@@ -304,7 +304,15 @@ JNIEXPORT jboolean JNICALL GDK_NATIVE(gdk_1cairo_1get_1clip_1rectangle)
jboolean rc = 0;
GDK_NATIVE_ENTER(env, that, gdk_1cairo_1get_1clip_1rectangle_FUNC);
if (arg1) if ((lparg1 = &_arg1) == NULL) goto fail;
+/*
rc = (jboolean)gdk_cairo_get_clip_rectangle((cairo_t *)arg0, (GdkRectangle *)lparg1);
+*/
+ {
+ GDK_LOAD_FUNCTION(fp, gdk_cairo_get_clip_rectangle)
+ if (fp) {
+ rc = (jboolean)((jboolean (CALLING_CONVENTION*)(cairo_t *, GdkRectangle *))fp)((cairo_t *)arg0, (GdkRectangle *)lparg1);
+ }
+ }
fail:
if (arg1 && lparg1) setGdkRectangleFields(env, arg1, lparg1);
GDK_NATIVE_EXIT(env, that, gdk_1cairo_1get_1clip_1rectangle_FUNC);
@@ -1637,7 +1645,15 @@ JNIEXPORT jlong JNICALL GDK_NATIVE(gdk_1pixbuf_1get_1from_1window)
{
jlong rc = 0;
GDK_NATIVE_ENTER(env, that, gdk_1pixbuf_1get_1from_1window_FUNC);
+/*
rc = (jlong)gdk_pixbuf_get_from_window((GdkWindow *)arg0, arg1, arg2, arg3, arg4);
+*/
+ {
+ GDK_LOAD_FUNCTION(fp, gdk_pixbuf_get_from_window)
+ if (fp) {
+ rc = (jlong)((jlong (CALLING_CONVENTION*)(GdkWindow *, jint, jint, jint, jint))fp)((GdkWindow *)arg0, arg1, arg2, arg3, arg4);
+ }
+ }
GDK_NATIVE_EXIT(env, that, gdk_1pixbuf_1get_1from_1window_FUNC);
return rc;
}
@@ -6816,6 +6832,24 @@ JNIEXPORT jlong JNICALL GTK_NATIVE(gtk_1im_1multicontext_1new)
}
#endif
+#ifndef NO_gtk_1image_1clear
+JNIEXPORT void JNICALL GTK_NATIVE(gtk_1image_1clear)
+ (JNIEnv *env, jclass that, jlong arg0)
+{
+ GTK_NATIVE_ENTER(env, that, gtk_1image_1clear_FUNC);
+/*
+ gtk_image_clear((GtkImage *)arg0);
+*/
+ {
+ GTK_LOAD_FUNCTION(fp, gtk_image_clear)
+ if (fp) {
+ ((void (CALLING_CONVENTION*)(GtkImage *))fp)((GtkImage *)arg0);
+ }
+ }
+ GTK_NATIVE_EXIT(env, that, gtk_1image_1clear_FUNC);
+}
+#endif
+
#ifndef NO_gtk_1image_1new
JNIEXPORT jlong JNICALL GTK_NATIVE(gtk_1image_1new)
(JNIEnv *env, jclass that)
@@ -6947,7 +6981,15 @@ JNIEXPORT void JNICALL GTK_NATIVE(gtk_1image_1set_1from_1surface)
(JNIEnv *env, jclass that, jlong arg0, jlong arg1)
{
GTK_NATIVE_ENTER(env, that, gtk_1image_1set_1from_1surface_FUNC);
+/*
gtk_image_set_from_surface((GtkImage *)arg0, (cairo_surface_t *)arg1);
+*/
+ {
+ GTK_LOAD_FUNCTION(fp, gtk_image_set_from_surface)
+ if (fp) {
+ ((void (CALLING_CONVENTION*)(GtkImage *, cairo_surface_t *))fp)((GtkImage *)arg0, (cairo_surface_t *)arg1);
+ }
+ }
GTK_NATIVE_EXIT(env, that, gtk_1image_1set_1from_1surface_FUNC);
}
#endif
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
index 706b1fccc0..eb04f12adf 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c
@@ -543,6 +543,7 @@ char * GTK_nativeFunctionNames[] = {
"gtk_1im_1context_1set_1client_1window",
"gtk_1im_1context_1set_1cursor_1location",
"gtk_1im_1multicontext_1new",
+ "gtk_1image_1clear",
"gtk_1image_1new",
"gtk_1image_1new_1from_1icon_1name___3B",
"gtk_1image_1new_1from_1icon_1name___3BI",
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
index cb251c0096..25eba732d7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h
@@ -541,6 +541,7 @@ typedef enum {
gtk_1im_1context_1set_1client_1window_FUNC,
gtk_1im_1context_1set_1cursor_1location_FUNC,
gtk_1im_1multicontext_1new_FUNC,
+ gtk_1image_1clear_FUNC,
gtk_1image_1new_FUNC,
gtk_1image_1new_1from_1icon_1name___3B_FUNC,
gtk_1image_1new_1from_1icon_1name___3BI_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java
index ffab3255c0..8789304c44 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java
@@ -319,6 +319,7 @@ public class GDK extends OS {
/* [GTK3 only, if-def'd in os.h; 3.22 deprecated, replaced] */
public static final native long gdk_cairo_create(long window);
/**
+ * @method flags=dynamic
* @param cr cast=(cairo_t *)
* @param rect cast=(GdkRectangle *),flags=no_in
*/
@@ -680,6 +681,7 @@ public class GDK extends OS {
* @param index_ranges cast=(gint *)
*/
public static final native long gdk_pango_layout_get_clip_region(long layout, int x_origin, int y_origin, int[] index_ranges, int n_ranges);
+
/** @param animation cast=(GdkPixbufAnimation *) */
public static final native boolean gdk_pixbuf_animation_is_static_image(long animation);
/** @param iter cast=(GdkPixbufAnimationIter *) */
@@ -705,11 +707,6 @@ public class GDK extends OS {
public static final native void gdk_pixbuf_copy_area(long src_pixbuf, int src_x, int src_y, int width, int height, long dest_pixbuf, int dest_x, int dest_y);
/** @param pixbuf cast=(const GdkPixbuf *) */
public static final native boolean gdk_pixbuf_get_has_alpha(long pixbuf);
- /**
- * @param window cast=(GdkWindow *)
- */
- /* [GTK3 only, if-def'd in os.h] */
- public static final native long gdk_pixbuf_get_from_window(long window, int x, int y, int width, int height);
/** @param pixbuf cast=(const GdkPixbuf *) */
public static final native int gdk_pixbuf_get_height(long pixbuf);
/** @param pixbuf cast=(const GdkPixbuf *) */
@@ -778,6 +775,14 @@ public class GDK extends OS {
* @param interp_type cast=(GdkInterpType)
*/
public static final native long gdk_pixbuf_scale_simple(long src, int dest_width, int dest_height, int interp_type);
+
+ /* GdkPixbuf Interaction */
+ /**
+ * @method flags=dynamic
+ * @param window cast=(GdkWindow *)
+ */
+ public static final native long gdk_pixbuf_get_from_window(long window, int x, int y, int width, int height);
+
/**
* @param device cast=(GdkDevice *)
*/
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
index e05a72a00b..aade800df6 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GTK.java
@@ -21,6 +21,9 @@ package org.eclipse.swt.internal.gtk;
*/
public class GTK extends OS {
+ public static final int GTK_VERSION = OS.VERSION(GTK.gtk_get_major_version(), GTK.gtk_get_minor_version(), GTK.gtk_get_micro_version());
+ public static final boolean GTK4 = GTK_VERSION >= OS.VERSION(3, 94, 0);
+
/** Constants */
public static final int GTK_ACCEL_VISIBLE = 0x1;
public static final int GTK_ALIGN_FILL = 0x0; //Gtk3 GtkAlign Enum
@@ -163,7 +166,7 @@ public class GTK extends OS {
public static final byte[] gtk_cursor_blink_time = OS.ascii("gtk-cursor-blink-time");
public static final byte[] gtk_double_click_time = OS.ascii("gtk-double-click-time");
public static final byte[] gtk_entry_select_on_focus = OS.ascii("gtk-entry-select-on-focus");
- public static final byte[] gtk_style_property_font = OS.ascii("font");
+ public static final byte[] gtk_style_property_font = GTK.GTK4 ? OS.ascii("gtk-font-name") : OS.ascii("font");
public static final byte[] gtk_menu_bar_accel = OS.ascii("gtk-menu-bar-accel");
public static final byte[] gtk_theme_name = OS.ascii("gtk-theme-name");
public static final byte[] gtk_im_module = OS.ascii("gtk-im-module");
@@ -191,9 +194,6 @@ public class GTK extends OS {
public static final byte[] GTK_NAMED_LABEL_OK = OS.ascii("_OK");
public static final byte[] GTK_NAMED_LABEL_CANCEL = OS.ascii("_Cancel");
- public static final int GTK_VERSION = OS.VERSION(GTK.gtk_get_major_version(), GTK.gtk_get_minor_version(), GTK.gtk_get_micro_version());
- public static final boolean GTK4 = GTK_VERSION >= OS.VERSION(3, 94, 0);
-
/** SWT Tools translates TYPE_sizeof() into sizeof(TYPE) at native level. os.c will have a binding to functions auto-generated in os_structs.h */
public static final native int GtkAllocation_sizeof();
public static final native int GtkBorder_sizeof();
@@ -1498,12 +1498,9 @@ public class GTK extends OS {
*/
public static final native void gtk_im_context_set_cursor_location(long context, GdkRectangle area);
public static final native long gtk_im_multicontext_new();
+
+ /* GtkImage */
public static final native long gtk_image_new();
- /**
- * @param image cast=(GtkImage *)
- * @param pixel_size cast=(gint)
- */
- public static final native void gtk_image_set_pixel_size(long image, int pixel_size);
/** @param pixbuf cast=(GdkPixbuf *) */
public static final native long gtk_image_new_from_pixbuf(long pixbuf);
/**
@@ -1513,6 +1510,14 @@ public class GTK extends OS {
public static final native void gtk_image_set_from_pixbuf(long image, long pixbuf);
/**
* @param image cast=(GtkImage *)
+ * @param pixel_size cast=(gint)
+ */
+ public static final native void gtk_image_set_pixel_size(long image, int pixel_size);
+
+ /* GtkImage [GTK3 only] */
+ /**
+ * @method flags=dynamic
+ * @param image cast=(GtkImage *)
* @param surface cast=(cairo_surface_t *)
*/
public static final native void gtk_image_set_from_surface(long image, long surface);
@@ -1521,31 +1526,35 @@ public class GTK extends OS {
* @param icon_name cast=(const gchar *)
* @param size cast=(GtkIconSize)
*/
- /* [GTK3 only] */
public static final native long gtk_image_new_from_icon_name(byte[] icon_name, int size);
/**
* @method flags=dynamic
+ * @param image cast=(GtkImage *)
* @param icon_name cast=(const gchar *)
+ * @param size cast=(GtkIconSize)
*/
- /* [GTK4 only] */
- public static final native long gtk_image_new_from_icon_name(byte[] icon_name);
+ public static final native void gtk_image_set_from_icon_name(long image, byte[] icon_name, int size);
+
+ /* GtkImage [GTK4 only] */
/**
* @method flags=dynamic
- * @param image cast=(GtkImage *)
* @param icon_name cast=(const gchar *)
- * @param size cast=(GtkIconSize)
*/
- /* [GTK3 only] */
- public static final native void gtk_image_set_from_icon_name(long image, byte[] icon_name, int size);
+ public static final native long gtk_image_new_from_icon_name(byte[] icon_name);
/**
* @method flags=dynamic
* @param image cast=(GtkImage *)
* @param icon_name cast=(const gchar *)
*/
- /* [GTK4 only] */
public static final native void gtk_image_set_from_icon_name(long image, byte[] icon_name);
/**
* @method flags=dynamic
+ * @param image cast=(GtkImage *)
+ */
+ public static final native void gtk_image_clear(long image);
+
+ /**
+ * @method flags=dynamic
* @param argc cast=(int *)
* @param argv cast=(char ***)
*/
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
index 08156d243b..f6a17ebcae 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
@@ -704,20 +704,31 @@ protected void init () {
/* Initialize the system font slot */
long [] defaultFontArray = new long [1];
- long defaultFont;
+ long defaultFont = 0;
long context = GTK.gtk_widget_get_style_context (shellHandle);
if ("ppc64le".equals(System.getProperty("os.arch"))) {
defaultFont = GTK.gtk_style_context_get_font (context, GTK.GTK_STATE_FLAG_NORMAL);
} else {
- GTK.gtk_style_context_save(context);
- GTK.gtk_style_context_set_state(context, GTK.GTK_STATE_FLAG_NORMAL);
if (GTK.GTK4) {
- GTK.gtk_style_context_get(context, GTK.gtk_style_property_font, defaultFontArray, 0);
+ long[] fontPtr = new long[1];
+ long settings = GTK.gtk_settings_get_default ();
+ OS.g_object_get (settings, GTK.gtk_style_property_font, fontPtr, 0);
+ if (fontPtr[0] != 0) {
+ int length = C.strlen(fontPtr[0]);
+ if (length != 0) {
+ byte[] fontString = new byte [length + 1];
+ C.memmove(fontString, fontPtr[0], length);
+ OS.g_free(fontPtr[0]);
+ defaultFont = OS.pango_font_description_from_string(fontString);
+ }
+ }
} else {
+ GTK.gtk_style_context_save(context);
+ GTK.gtk_style_context_set_state(context, GTK.GTK_STATE_FLAG_NORMAL);
GTK.gtk_style_context_get(context, GTK.GTK_STATE_FLAG_NORMAL, GTK.gtk_style_property_font, defaultFontArray, 0);
+ GTK.gtk_style_context_restore(context);
+ defaultFont = defaultFontArray [0];
}
- GTK.gtk_style_context_restore(context);
- defaultFont = defaultFontArray [0];
}
defaultFont = OS.pango_font_description_copy (defaultFont);
Point dpi = getDPI(), screenDPI = getScreenDPI();
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
index 38f1f0e032..7c31f411c0 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java
@@ -180,15 +180,27 @@ public GC(Drawable drawable, int style) {
if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
GCData data = new GCData();
data.style = checkStyle(style);
- long gdkGC = drawable.internal_new_GC(data);
Device device = data.device;
if (device == null) device = Device.getDevice();
if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
this.device = data.device = device;
+
+ long gdkGC = drawable.internal_new_GC(data);
init(drawable, data, gdkGC);
init();
}
+/**
+ * Ensure that the style specified is either LEFT_TO_RIGHT <b>or</b> RIGHT_TO_LEFT.
+ *
+ * @param style the SWT style bit string
+ * @return If only one style is specified, it is return unmodified. If both styles are specified, returns LEFT_TO_RIGHT
+ */
+int checkStyle(int style) {
+ if ((style & SWT.LEFT_TO_RIGHT) != 0) style &= ~SWT.RIGHT_TO_LEFT;
+ return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
+}
+
static void addCairoString(long cairo, String string, float x, float y, Font font) {
byte[] buffer = Converter.wcsToMbcs(string, true);
long layout = OS.pango_cairo_create_layout(cairo);
@@ -204,11 +216,6 @@ static void addCairoString(long cairo, String string, float x, float y, Font fon
OS.g_object_unref(layout);
}
-static int checkStyle (int style) {
- if ((style & SWT.LEFT_TO_RIGHT) != 0) style &= ~SWT.RIGHT_TO_LEFT;
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
-}
-
/**
* Convenience method that applies a region to the Control using cairo_clip.
*
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
index 287297a64d..b5ef710651 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java
@@ -1065,13 +1065,18 @@ public void setImage (Image image) {
if ((style & SWT.ARROW) != 0) return;
if (imageList != null) imageList.dispose ();
imageList = null;
+
if (image != null) {
- if (image.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
- imageList = new ImageList ();
- imageList.add (image);
- GTK.gtk_image_set_from_surface(imageHandle, image.surface);
+ if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ imageList = new ImageList();
+ int index = imageList.add(image);
+ GTK.gtk_image_set_from_pixbuf(imageHandle, imageList.getPixbuf(index));
} else {
- GTK.gtk_image_set_from_surface(imageHandle, 0);
+ if (GTK.GTK4) {
+ GTK.gtk_image_clear(imageHandle);
+ } else {
+ GTK.gtk_image_set_from_surface(imageHandle, 0);
+ }
}
this.image = image;
updateWidgetsVisibility();
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
index fea3cbe312..2c0a9e0cd7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
@@ -162,23 +162,6 @@ public Control (Composite parent, int style) {
createWidget (0);
}
-void connectPaint () {
- long paintHandle = paintHandle ();
- if (GTK.GTK4 && hooksPaint()) {
- long widgetClass = GTK.GTK_WIDGET_GET_CLASS(paintHandle);
- GtkWidgetClass widgetClassStruct = new GtkWidgetClass ();
- OS.memmove(widgetClassStruct, widgetClass);
- widgetClassStruct.snapshot = display.snapshotDrawProc;
- OS.memmove(widgetClass, widgetClassStruct);
- } else if (!GTK.GTK4) {
- int paintMask = GDK.GDK_EXPOSURE_MASK;
- GTK.gtk_widget_add_events (paintHandle, paintMask);
- OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [DRAW], 0, display.getClosure (EXPOSE_EVENT_INVERSE), false);
- OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [DRAW], 0, display.getClosure (DRAW), true);
- OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [STYLE_UPDATED], 0, display.getClosure (STYLE_UPDATED), false);
- }
-}
-
Font defaultFont () {
return display.getSystemFont ();
}
@@ -420,7 +403,7 @@ void hookEvents () {
hookKeyboardAndFocusSignals(focusHandle);
hookMouseSignals(eventHandle());
hookWidgetSignals(focusHandle);
- connectPaint();
+ hookPaintSignals();
connectIMSignals();
/*Connect gesture signals */
@@ -535,6 +518,25 @@ private void hookWidgetSignals(long focusHandle) {
}
}
+private void hookPaintSignals() {
+ long paintHandle = paintHandle();
+
+ if (GTK.GTK4) {
+ long widgetClass = GTK.GTK_WIDGET_GET_CLASS(paintHandle());
+ GtkWidgetClass widgetClassStruct = new GtkWidgetClass();
+
+ OS.memmove(widgetClassStruct, widgetClass);
+ widgetClassStruct.snapshot = display.snapshotDrawProc;
+ OS.memmove(widgetClass, widgetClassStruct);
+ } else {
+ int paintMask = GDK.GDK_EXPOSURE_MASK;
+ GTK.gtk_widget_add_events (paintHandle, paintMask);
+ OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [DRAW], 0, display.getClosure (EXPOSE_EVENT_INVERSE), false);
+ OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [DRAW], 0, display.getClosure (DRAW), true);
+ OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [STYLE_UPDATED], 0, display.getClosure (STYLE_UPDATED), false);
+ }
+}
+
private void connectIMSignals() {
long imHandle = imHandle();
if (imHandle != 0) {
@@ -2132,10 +2134,10 @@ public void addMouseWheelListener (MouseWheelListener listener) {
*/
public void addPaintListener(PaintListener listener) {
checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.Paint,typedListener);
- if (GTK.GTK4) connectPaint();
+ if (listener == null) error(SWT.ERROR_NULL_ARGUMENT);
+
+ TypedListener typedListener = new TypedListener(listener);
+ addListener(SWT.Paint, typedListener);
}
/**
@@ -3921,6 +3923,25 @@ void cairoClipRegion (long cairo) {
@Override
long gtk_draw (long widget, long cairo) {
+ if (GTK.GTK4) {
+ if (!hooksPaint()) return 0;
+
+ GCData data = new GCData();
+ data.cairo = cairo;
+ GC gc = GC.gtk_new(this, data);
+
+ Event event = new Event();
+ event.count = 1;
+ event.gc = gc;
+
+ drawWidget(gc);
+ sendEvent(SWT.Paint, event);
+ gc.dispose();
+ event.gc = null;
+
+ return 0;
+ }
+
if (checkScaleFactor) {
long surface = Cairo.cairo_get_target(cairo);
if (surface != 0) {
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
index 38b4eaab66..3261958b3f 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java
@@ -655,15 +655,20 @@ public void setImage (Image image) {
super.setImage (image);
if (imageList != null) imageList.dispose ();
imageList = null;
+
if (image != null) {
- if (image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- imageList = new ImageList ();
- imageList.add (image);
- GTK.gtk_image_set_from_surface(imageHandle, image.surface);
+ if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
+ imageList = new ImageList();
+ int index = imageList.add(image);
+ GTK.gtk_image_set_from_pixbuf(imageHandle, imageList.getPixbuf(index));
if (text.length () == 0) GTK.gtk_widget_hide (labelHandle);
GTK.gtk_widget_show (imageHandle);
} else {
- GTK.gtk_image_set_from_surface(imageHandle, 0);
+ if (GTK.GTK4) {
+ GTK.gtk_image_clear(imageHandle);
+ } else {
+ GTK.gtk_image_set_from_surface(imageHandle, 0);
+ }
GTK.gtk_widget_show (labelHandle);
GTK.gtk_widget_hide (imageHandle);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
index 69234ad959..ea1cd2d017 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java
@@ -632,12 +632,16 @@ public void setImage (Image image) {
imageList = null;
if (image != null) {
imageList = new ImageList ();
- imageList.add (image);
- GTK.gtk_image_set_from_surface(imageHandle, image.surface);
+ int index = imageList.add(image);
+ GTK.gtk_image_set_from_pixbuf(imageHandle, imageList.getPixbuf(index));
GTK.gtk_widget_hide (labelHandle);
GTK.gtk_widget_show (imageHandle);
} else {
- GTK.gtk_image_set_from_surface(imageHandle, 0);
+ if (GTK.GTK4) {
+ GTK.gtk_image_clear(imageHandle);
+ } else {
+ GTK.gtk_image_set_from_surface(imageHandle, 0);
+ }
GTK.gtk_widget_show (labelHandle);
GTK.gtk_widget_hide (imageHandle);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java
index 6d21967ad0..cfd172aaa8 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java
@@ -324,39 +324,42 @@ public ScrollBar getVerticalBar () {
@Override
long gtk_draw (long widget, long cairo) {
- /*
- * Draw events destined for an SwtFixed instance will sometimes
- * only be redrawing the scrollbars attached to it. GTK will send many
- * draw events to an SwtFixed instance if:
- * 1) that instance has overlay scrollbars attached to it, and
- * 2) the mouse has just left (leave-notify) that SwtFixed widget.
- *
- * Such extra draw events cause extra SWT.Paint events to be sent and
- * reduce performance. The fix is to check if the dirty region in need
- * of a redraw is the same region that the scroll bars occupy, and ignore
- * draw events that target such cases. See bug 546248.
- */
- boolean overlayScrolling = !OS.GTK_OVERLAY_SCROLLING_DISABLED;
- if (overlayScrolling && OS.G_OBJECT_TYPE(widget) == OS.swt_fixed_get_type()) {
- if ((style & SWT.V_SCROLL) != 0 && verticalBar != null) {
- GtkAllocation verticalBarAlloc = new GtkAllocation();
- GTK.gtk_widget_get_allocation(verticalBar.handle, verticalBarAlloc);
- GdkRectangle rect = new GdkRectangle();
- GDK.gdk_cairo_get_clip_rectangle(cairo, rect);
- if (rect.width == verticalBarAlloc.width && rect.height == verticalBarAlloc.height) {
- return 0;
+ if (!GTK.GTK4) {
+ /*
+ * Draw events destined for an SwtFixed instance will sometimes
+ * only be redrawing the scrollbars attached to it. GTK will send many
+ * draw events to an SwtFixed instance if:
+ * 1) that instance has overlay scrollbars attached to it, and
+ * 2) the mouse has just left (leave-notify) that SwtFixed widget.
+ *
+ * Such extra draw events cause extra SWT.Paint events to be sent and
+ * reduce performance. The fix is to check if the dirty region in need
+ * of a redraw is the same region that the scroll bars occupy, and ignore
+ * draw events that target such cases. See bug 546248.
+ */
+ boolean overlayScrolling = !OS.GTK_OVERLAY_SCROLLING_DISABLED;
+ if (overlayScrolling && OS.G_OBJECT_TYPE(widget) == OS.swt_fixed_get_type()) {
+ if ((style & SWT.V_SCROLL) != 0 && verticalBar != null) {
+ GtkAllocation verticalBarAlloc = new GtkAllocation();
+ GTK.gtk_widget_get_allocation(verticalBar.handle, verticalBarAlloc);
+ GdkRectangle rect = new GdkRectangle();
+ GDK.gdk_cairo_get_clip_rectangle(cairo, rect);
+ if (rect.width == verticalBarAlloc.width && rect.height == verticalBarAlloc.height) {
+ return 0;
+ }
}
- }
- if ((style & SWT.H_SCROLL) != 0 && horizontalBar != null) {
- GtkAllocation horizontalBarAlloc = new GtkAllocation();
- GTK.gtk_widget_get_allocation(horizontalBar.handle, horizontalBarAlloc);
- GdkRectangle rect = new GdkRectangle();
- GDK.gdk_cairo_get_clip_rectangle(cairo, rect);
- if (rect.width == horizontalBarAlloc.width && rect.height == horizontalBarAlloc.height) {
- return 0;
+ if ((style & SWT.H_SCROLL) != 0 && horizontalBar != null) {
+ GtkAllocation horizontalBarAlloc = new GtkAllocation();
+ GTK.gtk_widget_get_allocation(horizontalBar.handle, horizontalBarAlloc);
+ GdkRectangle rect = new GdkRectangle();
+ GDK.gdk_cairo_get_clip_rectangle(cairo, rect);
+ if (rect.width == horizontalBarAlloc.width && rect.height == horizontalBarAlloc.height) {
+ return 0;
+ }
}
}
}
+
return super.gtk_draw(widget, cairo);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java
index d0e2ce581c..ce366a9a02 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java
@@ -401,10 +401,14 @@ public void setImage (Image image) {
imageList.put (imageIndex, image);
}
- GTK.gtk_image_set_from_surface(imageHandle, image.surface);
+ GTK.gtk_image_set_from_pixbuf(imageHandle, imageList.getPixbuf(imageIndex));
GTK.gtk_widget_show (imageHandle);
} else {
- GTK.gtk_image_set_from_surface(imageHandle, 0);
+ if (GTK.GTK4) {
+ GTK.gtk_image_clear(imageHandle);
+ } else {
+ GTK.gtk_image_set_from_surface(imageHandle, 0);
+ }
GTK.gtk_widget_hide (imageHandle);
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java
index 6ec17dc097..af77df1448 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java
@@ -631,10 +631,14 @@ public void setImage (Image image) {
}
int imageIndex = headerImageList.indexOf (image);
if (imageIndex == -1) imageIndex = headerImageList.add (image);
- GTK.gtk_image_set_from_surface(imageHandle, image.surface);
+ GTK.gtk_image_set_from_pixbuf(imageHandle, headerImageList.getPixbuf(imageIndex));
GTK.gtk_widget_show (imageHandle);
} else {
- GTK.gtk_image_set_from_surface(imageHandle, 0);
+ if (GTK.GTK4) {
+ GTK.gtk_image_clear(imageHandle);
+ } else {
+ GTK.gtk_image_set_from_surface(imageHandle, 0);
+ }
GTK.gtk_widget_hide (imageHandle);
}
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java
index cee52d9cae..39d04ce6fd 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java
@@ -718,9 +718,9 @@ long gtk_enter_notify_event (long widget, long event) {
if (drawHotImage) {
ImageList imageList = parent.imageList;
if (imageList != null) {
- int index = imageList.indexOf (hotImage);
+ int index = imageList.indexOf(hotImage);
if (index != -1 && imageHandle != 0) {
- GTK.gtk_image_set_from_surface(imageHandle, hotImage.surface);
+ GTK.gtk_image_set_from_pixbuf(imageHandle, imageList.getPixbuf(index));
}
}
}
@@ -775,9 +775,9 @@ long gtk_leave_notify_event (long widget, long event) {
if (image != null) {
ImageList imageList = parent.imageList;
if (imageList != null) {
- int index = imageList.indexOf (image);
+ int index = imageList.indexOf(image);
if (index != -1 && imageHandle != 0) {
- GTK.gtk_image_set_from_surface(imageHandle, image.surface);
+ GTK.gtk_image_set_from_pixbuf(imageHandle, imageList.getPixbuf(index));
}
}
}
@@ -1201,9 +1201,13 @@ void _setImage (Image image) {
imageList.put (imageIndex, image);
}
- GTK.gtk_image_set_from_surface(imageHandle, image.surface);
+ GTK.gtk_image_set_from_pixbuf(imageHandle, imageList.getPixbuf(imageIndex));
} else {
- GTK.gtk_image_set_from_surface(imageHandle, 0);
+ if (GTK.GTK4) {
+ GTK.gtk_image_clear(imageHandle);
+ } else {
+ GTK.gtk_image_set_from_surface(imageHandle, 0);
+ }
}
/*
* If Text/Image of a tool-item changes, then it is
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java
index 5b851e509f..094ef4f5e8 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java
@@ -601,10 +601,14 @@ public void setImage (Image image) {
}
int imageIndex = headerImageList.indexOf (image);
if (imageIndex == -1) imageIndex = headerImageList.add (image);
- GTK.gtk_image_set_from_surface(imageHandle, image.surface);
+ GTK.gtk_image_set_from_pixbuf(imageHandle, headerImageList.getPixbuf(imageIndex));
GTK.gtk_widget_show (imageHandle);
} else {
- GTK.gtk_image_set_from_surface(imageHandle, 0);
+ if (GTK.GTK4) {
+ GTK.gtk_image_clear(imageHandle);
+ } else {
+ GTK.gtk_image_set_from_surface(imageHandle, 0);
+ }
GTK.gtk_widget_hide (imageHandle);
}
}

Back to the top