Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,18 @@ void snapshotBackground (long handle, long snapshot) {
Graphene.graphene_rect_free(rect);
}

@Override
void snapshotToDraw (long handle, long snapshot) {
// Containers paint before children so SWT.Paint backgrounds appear behind child controls,
// matching GTK3 EXPOSE_EVENT_INVERSE (after=false) behavior.
snapshotPaint(handle, snapshot);
}

@Override
void snapshotToDrawAfterChildren (long handle, long snapshot) {
// Suppress Control's after-children paint: Composite already painted before children above.
}


/**
* Fills the interior of the rectangle specified by the arguments,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,25 @@ boolean hooksPaint () {
return hooks (SWT.Paint) || filters (SWT.Paint);
}

@Override
void snapshotPaint (long handle, long snapshot) {
/*
* Guard against creating an empty Cairo render node when there are no paint
* listeners. gtk_snapshot_append_cairo() appends a node immediately; leaving it
* empty/unfinished causes it to obscure render nodes already in the snapshot
* (e.g. GtkTreeView content snapshotted before this call).
*/
if (!hooksPaint()) return;
super.snapshotPaint(handle, snapshot);
}

@Override
void snapshotToDrawAfterChildren (long handle, long snapshot) {
// Leaf controls (Button, Label, etc.) paint after children so SWT.Paint listeners
// draw on top of the native widget appearance, matching GTK3 DRAW (after=true) behavior.
snapshotPaint(handle, snapshot);
}

@Override
long hoverProc (long widget) {
int[] x = new int[1], y = new int[1], mask = new int[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ void snapshotDrawProc(long handle, long snapshot) {
// Draw background before children so it appears behind them
if (widget != null) widget.snapshotBackground(handle, snapshot);

// Draw SWT custom paint before children so child widgets remain visible.
// Paint before children (used by Composite subclasses for backgrounds)
if (widget != null) widget.snapshotToDraw(handle, snapshot);

long child = GTK4.gtk_widget_get_first_child(handle);
Expand All @@ -1729,6 +1729,9 @@ void snapshotDrawProc(long handle, long snapshot) {
GTK4.gtk_widget_snapshot_child(handle, child, snapshot);
child = GTK4.gtk_widget_get_next_sibling(child);
}

// Paint after children (used by leaf controls for overlay/on-top drawing)
if (widget != null) widget.snapshotToDrawAfterChildren(handle, snapshot);
}

static long rendererGetPreferredWidthProc (long cell, long handle, long minimun_size, long natural_size) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4233,6 +4233,18 @@ private void gtk3_paintEvent(long cairo) {
event.gc = null;
}

@Override
void snapshotToDraw(long handle, long snapshot) {
// Table renders via native GTK children (GtkScrolledWindow > GtkTreeView).
// Like GTK3 where Table explicitly fires paint in EXPOSE_EVENT (after=true),
// GTK4 must paint after children so SWT.Paint overlays appear on top.
}

@Override
void snapshotToDrawAfterChildren(long handle, long snapshot) {
snapshotPaint(handle, snapshot);
}

@Override
public void dispose() {
super.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4306,6 +4306,18 @@ private void gtk3_paintEvent(long cairo) {
event.gc = null;
}

@Override
void snapshotToDraw(long handle, long snapshot) {
// Tree renders via native GTK children (GtkScrolledWindow > GtkTreeView).
// Like GTK3 where Tree explicitly fires paint in EXPOSE_EVENT (after=true),
// GTK4 must paint after children so SWT.Paint overlays appear on top.
}

@Override
void snapshotToDrawAfterChildren(long handle, long snapshot) {
snapshotPaint(handle, snapshot);
}

private void throwCannotRemoveItem(int i) {
String message = "Cannot remove item with index " + i + ".";
throw new SWTException(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2292,12 +2292,10 @@ void snapshotBackground (long handle, long snapshot) {

/**
* 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
* a Cairo context. Used by subclasses to
* trigger painting at the appropriate point in the snapshot order.
*/
void snapshotToDraw (long handle, long snapshot) {
void snapshotPaint (long handle, long snapshot) {
GtkAllocation allocation = new GtkAllocation();
GTK.gtk_widget_get_allocation(handle, allocation);
long rect = Graphene.graphene_rect_alloc();
Expand All @@ -2312,6 +2310,20 @@ void snapshotToDraw (long handle, long snapshot) {
Graphene.graphene_rect_free(rect);
}

/**
* Called before child widgets are snapshotted. Containers (Composite) override
* this to paint backgrounds behind their children.
*/
void snapshotToDraw (long handle, long snapshot) {
}

/**
* Called after child widgets are snapshotted. Leaf controls (Button, Label,
* etc.) override this to paint on top of their native appearance.
*/
void snapshotToDrawAfterChildren (long handle, long snapshot) {
}

long gtk_widget_get_window (long widget){
GTK.gtk_widget_realize(widget);
return GTK3.gtk_widget_get_window (widget);
Expand Down
Loading