diff options
| author | Eric Williams | 2018-03-02 21:50:54 +0000 |
|---|---|---|
| committer | Eric Williams | 2018-03-09 19:28:00 +0000 |
| commit | f4d292bc19c8e894a4caa26ef5d113d800ad7b6b (patch) | |
| tree | 1e0ff6c7119595705e6815728cdf20a2b27c085b | |
| parent | 9b6f94eeb3a09e19dba4e4e1ff8c148a99a6c9f5 (diff) | |
| download | eclipse.platform.swt-f4d292bc19c8e894a4caa26ef5d113d800ad7b6b.tar.gz eclipse.platform.swt-f4d292bc19c8e894a4caa26ef5d113d800ad7b6b.tar.xz eclipse.platform.swt-f4d292bc19c8e894a4caa26ef5d113d800ad7b6b.zip | |
Bug 529431: [GTK3.10+] Snippet294 fails to draw Region
Draw the region on the Control using cairo_clip(). This doesn't use the
GdkWindow API which no longer works on GTK3.10+.
The only caveat is that input handling is not blocked. For example:
setting the region on a button will not prevent click events within the
region from registering. This needs to be investigated and fixed.
Tested on GTK3.8 - GTK3.22. IDE looks fine, no AllNonBrowser JUnit tests
fail.
Change-Id: If6f6bdc1d349cfb3ab42be3977e5c608e29df43e
Signed-off-by: Eric Williams <ericwill@redhat.com>
| -rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java | 39 |
1 files changed, 36 insertions, 3 deletions
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 8febb913cc..4ed2d9f8e9 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 @@ -1341,10 +1341,15 @@ void setSizeInPixels (Point size) { public void setRegion (Region region) { checkWidget (); if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - long /*int*/ window = gtk_widget_get_window (topHandle ()); long /*int*/ shape_region = (region == null) ? 0 : region.handle; - GDK.gdk_window_shape_combine_region (window, shape_region, 0, 0); this.region = region; + // Only call gdk_window_shape_combine_region on GTK3.8- + if (GTK.GTK_VERSION < OS.VERSION(3, 9, 0)) { + long /*int*/ window = gtk_widget_get_window (topHandle ()); + GDK.gdk_window_shape_combine_region (window, shape_region, 0, 0); + } else { + GTK.gtk_widget_queue_draw(topHandle()); + } } void setRelations () { @@ -3524,9 +3529,37 @@ long /*int*/ gtk_event_after (long /*int*/ widget, long /*int*/ gdkEvent) { @Override long /*int*/ gtk_draw (long /*int*/ widget, long /*int*/ cairo) { if ((state & OBSCURED) != 0) return 0; - if (!hooksPaint ()) return 0; GdkRectangle rect = new GdkRectangle (); GDK.gdk_cairo_get_clip_rectangle (cairo, rect); + /* + * Modify the drawing of the widget with cairo_clip. + * Doesn't modify input handling at this time. + * See bug 529431. + */ + if (this.region != null && this.region.handle != 0 && GTK.GTK_VERSION >= OS.VERSION(3, 10, 0)) { + long /*int*/ regionHandle = this.region.handle; + GdkRectangle regionRect = new GdkRectangle(); + /* + * These gdk_region_* functions actually map to the proper + * cairo_* functions in os.h. + */ + GDK.gdk_region_get_clipbox(regionHandle, regionRect); + long /*int*/ actualRegion = GDK.gdk_region_rectangle(rect); + GDK.gdk_region_subtract(actualRegion, regionHandle); + // Draw the Shell bg using cairo, only if it's a different color + Shell shell = getShell(); + Color shellBg = shell.getBackground(); + if (shellBg != this.getBackground()) { + GdkRGBA rgba = shellBg.handleRGBA; + Cairo.cairo_set_source_rgba (cairo, rgba.red, rgba.green, rgba.blue, rgba.alpha); + } else { + Cairo.cairo_set_source_rgba (cairo, 0.0, 0.0, 0.0, 0.0); + } + GDK.gdk_cairo_region(cairo, actualRegion); + Cairo.cairo_clip(cairo); + Cairo.cairo_paint(cairo); + } + if (!hooksPaint ()) return 0; Event event = new Event (); event.count = 1; Rectangle eventBounds = DPIUtil.autoScaleDown (new Rectangle (rect.x, rect.y, rect.width, rect.height)); |
