diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT')
3 files changed, 62 insertions, 4 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 799ee5e0c7..9f265d8c97 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 @@ -163,11 +163,18 @@ public Control (Composite parent, int style) { void connectPaint () { long /*int*/ paintHandle = paintHandle (); int paintMask = GDK.GDK_EXPOSURE_MASK; - if (!GTK.GTK4) 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); + if (GTK.GTK4 && (hooksPaint() || drawRegion)) { + long /*int*/ widgetClass = GTK.GTK_WIDGET_GET_CLASS(paintHandle); + GtkWidgetClass widgetClassStruct = new GtkWidgetClass (); + OS.memmove(widgetClassStruct, widgetClass); + widgetClassStruct.snapshot = display.snapshotDrawProc; + OS.memmove(widgetClass, widgetClassStruct); + } else { + 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 [DRAW], 0, display.getClosure (DRAW), true); + } } Font defaultFont () { 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 32a101c4ea..1d5dc12a09 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 @@ -126,7 +126,9 @@ public class Display extends Device { int [] max_priority = new int [1], timeout = new int [1]; Callback eventCallback; long /*int*/ eventProc, windowProc2, windowProc3, windowProc4, windowProc5, windowProc6; + long /*int*/ snapshotDrawProc; Callback windowCallback2, windowCallback3, windowCallback4, windowCallback5, windowCallback6; + Callback snapshotDraw; EventTable eventTable, filterTable; static String APP_NAME = "SWT"; //$NON-NLS-1$ static String APP_VERSION = ""; //$NON-NLS-1$ @@ -1474,6 +1476,13 @@ static long /*int*/ rendererClassInitProc (long /*int*/ g_class, long /*int*/ cl return 0; } +static long /*int*/ snapshotDrawProc (long /*int*/ handle, long /*int*/ snapshot) { + Display display = getCurrent (); + Widget widget = display.getWidget (handle); + widget.snapshotToDraw(handle, snapshot); + return 0; +} + static long /*int*/ rendererGetPreferredWidthProc (long /*int*/ cell, long /*int*/ handle, long /*int*/ minimun_size, long /*int*/ natural_size) { Display display = getCurrent (); Widget widget = display.getWidget (handle); @@ -3577,6 +3586,12 @@ void initializeCallbacks () { signalIds [Widget.UNREALIZE] = OS.g_signal_lookup (OS.realize, GTK.GTK_TYPE_WIDGET ()); signalIds [Widget.WINDOW_STATE_EVENT] = OS.g_signal_lookup (OS.window_state_event, GTK.GTK_TYPE_WIDGET ()); + if (GTK.GTK4) { + snapshotDraw = new Callback (getClass (), "snapshotDrawProc", 2); //$NON-NLS-1$ + snapshotDrawProc = snapshotDraw.getAddress (); + if (snapshotDrawProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + } + windowCallback2 = new Callback (this, "windowProc", 2); //$NON-NLS-1$ windowProc2 = windowCallback2.getAddress (); if (windowProc2 == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); 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 d424355e8a..1e17cd3a2d 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 @@ -1197,6 +1197,19 @@ void postEvent (int eventType, Event event) { sendEvent (eventType, event, false); } +void propagateSnapshot (long /*int*/ widget, long /*int*/ snapshot) { + long /*int*/ list = GTK.gtk_container_get_children (widget); + long /*int*/ temp = list; + while (temp != 0) { + long /*int*/ child = OS.g_list_data (temp); + if (child != 0) { + GTK.gtk_widget_snapshot_child(widget, child, snapshot); + } + temp = OS.g_list_next (temp); + } + OS.g_list_free (list); +} + void register () { if (handle == 0) return; if ((state & HANDLE) != 0) display.addWidget (handle, this); @@ -1785,6 +1798,29 @@ long /*int*/ sizeRequestProc (long /*int*/ handle, long /*int*/ arg0, long /*int return 0; } +/** + * Converts an incoming snapshot into a gtk_draw() call, complete with + * a Cairo context. + * + * @param handle the widget receiving the snapshot + * @param snapshot the actual GtkSnapshot + */ +void snapshotToDraw (long /*int*/ handle, long /*int*/ snapshot) { + GtkAllocation allocation = new GtkAllocation (); + GTK.gtk_widget_get_allocation(handle, allocation); + long /*int*/ rect = Graphene.graphene_rect_alloc(); + Graphene.graphene_rect_init(rect, 0, 0, allocation.width, allocation.height); + long /*int*/ cairo = GTK.gtk_snapshot_append_cairo(snapshot, rect); + gtk_draw(handle, cairo); + Graphene.graphene_rect_free(rect); + // Propagates the snapshot down the widget hierarchy so that other widgets + // will draw. + if (GTK.GTK_IS_CONTAINER(handle)) { + propagateSnapshot(handle, snapshot); + } + return; +} + long /*int*/ gtk_widget_get_window (long /*int*/ widget){ GTK.gtk_widget_realize(widget); return GTK.gtk_widget_get_window (widget); |