diff options
author | Eric Williams | 2019-01-24 20:57:04 +0000 |
---|---|---|
committer | Eric Williams | 2019-01-25 15:57:11 +0000 |
commit | db19ffcd2efc5e4704166ad3a02c668756e77d85 (patch) | |
tree | 85306f6f152c21cafc860878b5b23b165b5b1f07 | |
parent | d120090e99d9a3249fdca7227321d867b1995b65 (diff) | |
download | eclipse.platform.swt-db19ffcd2efc5e4704166ad3a02c668756e77d85.tar.gz eclipse.platform.swt-db19ffcd2efc5e4704166ad3a02c668756e77d85.tar.xz eclipse.platform.swt-db19ffcd2efc5e4704166ad3a02c668756e77d85.zip |
Bug 54147: [GTK4] Replace GtkCellRendererClass render method with
snapshot
Enable custom Tree/Table drawing by porting GtkCellRendererClass to use
the proper GTK4 "snapshot" vfunc.
Change-Id: Ia5a673be98010c60bf64f63c96185abe076216c2
Signed-off-by: Eric Williams <ericwill@redhat.com>
4 files changed, 72 insertions, 28 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index 9c6e33db67..20420d7353 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -336,9 +336,9 @@ public class Display extends Device { /* Renderer Subclass */ static long /*int*/ text_renderer_type, pixbuf_renderer_type, toggle_renderer_type; static long /*int*/ text_renderer_info_ptr, pixbuf_renderer_info_ptr, toggle_renderer_info_ptr; - static Callback rendererClassInitCallback, rendererRenderCallback; + static Callback rendererClassInitCallback, rendererRenderCallback, rendererSnapshotCallback; static Callback rendererGetPreferredWidthCallback; - static long /*int*/ rendererClassInitProc, rendererRenderProc; + static long /*int*/ rendererClassInitProc, rendererRenderProc, rendererSnapshotProc; static long /*int*/ rendererGetPreferredWidthProc; /* Key Mappings */ @@ -1062,10 +1062,18 @@ void createDisplay (DeviceData data) { rendererClassInitProc = rendererClassInitCallback.getAddress (); if (rendererClassInitProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); } - if (rendererRenderProc == 0) { - rendererRenderCallback = new Callback (getClass (), "rendererRenderProc", 6); //$NON-NLS-1$ - rendererRenderProc = rendererRenderCallback.getAddress (); - if (rendererRenderProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + if (GTK.GTK4) { + if (rendererSnapshotProc == 0) { + rendererSnapshotCallback = new Callback (getClass (), "rendererSnapshotProc", 6); //$NON-NLS-1$ + rendererSnapshotProc = rendererSnapshotCallback.getAddress (); + if (rendererSnapshotProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + } + } else { + if (rendererRenderProc == 0) { + rendererRenderCallback = new Callback (getClass (), "rendererRenderProc", 6); //$NON-NLS-1$ + rendererRenderProc = rendererRenderCallback.getAddress (); + if (rendererRenderProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + } } if (rendererGetPreferredWidthProc == 0) { rendererGetPreferredWidthCallback = new Callback (getClass (), "rendererGetPreferredWidthProc", 4); //$NON-NLS-1$ @@ -1477,7 +1485,11 @@ public Widget findWidget (Widget widget, long /*int*/ id) { static long /*int*/ rendererClassInitProc (long /*int*/ g_class, long /*int*/ class_data) { GtkCellRendererClass klass = new GtkCellRendererClass (); OS.memmove (klass, g_class); - klass.render = rendererRenderProc; + if (GTK.GTK4) { + klass.snapshot = rendererSnapshotProc; + } else { + klass.render = rendererRenderProc; + } klass.get_preferred_width = rendererGetPreferredWidthProc; OS.memmove (g_class, klass); return 0; @@ -1504,10 +1516,10 @@ static long /*int*/ rendererRenderProc (long /*int*/ cell, long /*int*/ cr, long return 0; } -static long /*int*/ rendererRenderProc (long /*int*/ cell, long /*int*/ window, long /*int*/ handle, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ expose_area, long /*int*/ flags) { +static long /*int*/ rendererSnapshotProc (long /*int*/ cell, long /*int*/ snapshot, long /*int*/ handle, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ flags) { Display display = getCurrent (); Widget widget = display.getWidget (handle); - if (widget != null) return widget.rendererRenderProc (cell, window, handle, background_area, cell_area, expose_area, flags); + if (widget != null) return widget.rendererSnapshotProc (cell, snapshot, handle, background_area, cell_area, flags); return 0; } @@ -4644,6 +4656,10 @@ void releaseDisplay () { keyPressReleaseProc = 0; focusCallback.dispose(); focusProc = 0; + enterMotionScrollCallback.dispose(); + enterMotionScrollProc = 0; + leaveCallback.dispose(); + leaveProc = 0; } /* Dispose checkIfEvent callback */ diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java index 868b7af0ef..42aa4372ec 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java @@ -2266,8 +2266,13 @@ long /*int*/ gtk_draw (long /*int*/ widget, long /*int*/ cairo) { @Override long /*int*/ gtk_motion_notify_event (long /*int*/ widget, long /*int*/ event) { - long /*int*/ window = GDK.GDK_EVENT_WINDOW (event); - if (window != GTK.gtk_tree_view_get_bin_window (handle)) return 0; + if (GTK.GTK4) { + long /*int*/ surface = GDK.gdk_event_get_surface(event); + if (surface != gtk_widget_get_surface(handle)) return 0; + } else { + long /*int*/ window = GDK.GDK_EVENT_WINDOW (event); + if (window != GTK.gtk_tree_view_get_bin_window (handle)) return 0; + } return super.gtk_motion_notify_event (widget, event); } @@ -2853,18 +2858,23 @@ long /*int*/ rendererGetPreferredWidthProc (long /*int*/ cell, long /*int*/ hand } @Override -long /*int*/ rendererRenderProc (long /*int*/ cell, long /*int*/ cr, long /*int*/ widget, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ flags) { - rendererRender (cell, cr, 0, widget, background_area, cell_area, 0, flags); +long /*int*/ rendererSnapshotProc (long /*int*/ cell, long /*int*/ snapshot, long /*int*/ widget, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ flags) { + long /*int*/ rect = Graphene.graphene_rect_alloc(); + GdkRectangle gdkRectangle = new GdkRectangle (); + OS.memmove(gdkRectangle, background_area, GdkRectangle.sizeof); + Graphene.graphene_rect_init(rect, gdkRectangle.x, gdkRectangle.y, gdkRectangle.width, gdkRectangle.height); + long /*int*/ cairo = GTK.gtk_snapshot_append_cairo(snapshot, rect); + rendererRender (cell, cairo, snapshot, widget, background_area, cell_area, 0, flags); return 0; } @Override -long /*int*/ rendererRenderProc (long /*int*/ cell, long /*int*/ window, long /*int*/ widget, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ expose_area, long /*int*/ flags) { - rendererRender (cell, 0, window, widget, background_area, cell_area, expose_area, flags); +long /*int*/ rendererRenderProc (long /*int*/ cell, long /*int*/ cr, long /*int*/ widget, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ flags) { + rendererRender (cell, cr, 0, widget, background_area, cell_area, 0, flags); return 0; } -void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, long /*int*/ widget, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ expose_area, long /*int*/ flags) { +void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ snapshot, long /*int*/ widget, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ expose_area, long /*int*/ flags) { TableItem item = null; boolean wasSelected = false; long /*int*/ iter = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX2); @@ -2924,7 +2934,7 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo if (cr != 0) { Cairo.cairo_save (cr); } - drawBackground (control, window, cr, 0, rect.x, rect.y, rect.width, rect.height); + drawBackground (control, 0, cr, 0, rect.x, rect.y, rect.width, rect.height); if (cr != 0) { Cairo.cairo_restore (cr); } @@ -3021,7 +3031,11 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo if (drawForegroundRGBA != null && GTK.GTK_IS_CELL_RENDERER_TEXT (cell)) { OS.g_object_set (cell, OS.foreground_rgba, drawForegroundRGBA, 0); } - OS.call (klass.render, cell, cr, widget, background_area, cell_area, drawFlags); + if (GTK.GTK4) { + OS.call (klass.snapshot, cell, snapshot, widget, background_area, cell_area, drawFlags); + } else { + OS.call (klass.render, cell, cr, widget, background_area, cell_area, drawFlags); + } } if (item != null) { if (GTK.GTK_IS_CELL_RENDERER_TEXT (cell)) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java index 5adf955bc6..33d42f4758 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java @@ -2342,8 +2342,13 @@ long /*int*/ gtk_draw (long /*int*/ widget, long /*int*/ cairo) { @Override long /*int*/ gtk_motion_notify_event (long /*int*/ widget, long /*int*/ event) { - long /*int*/ window = GDK.GDK_EVENT_WINDOW (event); - if (window != GTK.gtk_tree_view_get_bin_window (handle)) return 0; + if (GTK.GTK4) { + long /*int*/ surface = GDK.gdk_event_get_surface(event); + if (surface != gtk_widget_get_surface(handle)) return 0; + } else { + long /*int*/ window = GDK.GDK_EVENT_WINDOW (event); + if (window != GTK.gtk_tree_view_get_bin_window (handle)) return 0; + } return super.gtk_motion_notify_event (widget, event); } @@ -2944,18 +2949,23 @@ long /*int*/ rendererGetPreferredWidthProc (long /*int*/ cell, long /*int*/ hand } @Override -long /*int*/ rendererRenderProc (long /*int*/ cell, long /*int*/ cr, long /*int*/ widget, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ flags) { - rendererRender (cell, cr, 0, widget, background_area, cell_area, 0, flags); +long /*int*/ rendererSnapshotProc (long /*int*/ cell, long /*int*/ snapshot, long /*int*/ widget, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ flags) { + long /*int*/ rect = Graphene.graphene_rect_alloc(); + GdkRectangle gdkRectangle = new GdkRectangle (); + OS.memmove(gdkRectangle, background_area, GdkRectangle.sizeof); + Graphene.graphene_rect_init(rect, gdkRectangle.x, gdkRectangle.y, gdkRectangle.width, gdkRectangle.height); + long /*int*/ cairo = GTK.gtk_snapshot_append_cairo(snapshot, rect); + rendererRender (cell, cairo, snapshot, widget, background_area, cell_area, 0, flags); return 0; } @Override -long /*int*/ rendererRenderProc (long /*int*/ cell, long /*int*/ window, long /*int*/ widget, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ expose_area, long /*int*/ flags) { - rendererRender (cell, 0, window, widget, background_area, cell_area, expose_area, flags); +long /*int*/ rendererRenderProc (long /*int*/ cell, long /*int*/ cr, long /*int*/ widget, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ flags) { + rendererRender (cell, cr, 0, widget, background_area, cell_area, 0, flags); return 0; } -void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, long /*int*/ widget, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ expose_area, long /*int*/ flags) { +void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ snapshot, long /*int*/ widget, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ expose_area, long /*int*/ flags) { TreeItem item = null; boolean wasSelected = false; long /*int*/ iter = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX2); @@ -3008,7 +3018,7 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo if (cr != 0) { Cairo.cairo_save (cr); } - drawBackground (control, window, cr, 0, rect.x, rect.y, rect.width, rect.height); + drawBackground (control, 0, cr, 0, rect.x, rect.y, rect.width, rect.height); if (cr != 0) { Cairo.cairo_restore (cr); } @@ -3091,7 +3101,11 @@ void rendererRender (long /*int*/ cell, long /*int*/ cr, long /*int*/ window, lo if (drawForegroundRGBA != null && GTK.GTK_IS_CELL_RENDERER_TEXT (cell)) { OS.g_object_set (cell, OS.foreground_rgba, drawForegroundRGBA, 0); } - OS.call (klass.render, cell, cr, widget, background_area, cell_area, drawFlags); + if (GTK.GTK4) { + OS.call (klass.snapshot, cell, snapshot, widget, background_area, cell_area, drawFlags); + } else { + OS.call (klass.render, cell, cr, widget, background_area, cell_area, drawFlags); + } } if (item != null) { if (GTK.GTK_IS_CELL_RENDERER_TEXT (cell)) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java index a8e7500745..7001a6c20b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java @@ -1323,7 +1323,7 @@ long /*int*/ rendererRenderProc (long /*int*/ cell, long /*int*/ cr, long /*int* return 0; } -long /*int*/ rendererRenderProc (long /*int*/ cell, long /*int*/ window, long /*int*/ handle, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ expose_area, long /*int*/ flags) { +long /*int*/ rendererSnapshotProc (long /*int*/ cell, long /*int*/ snapshot, long /*int*/ handle, long /*int*/ background_area, long /*int*/ cell_area, long /*int*/ flags) { return 0; } |