Skip to content

Fix PaintListener for GTK3 Table and Tree widgets #3291

Merged
akurtakov merged 1 commit intoeclipse-platform:masterfrom
akurtakov:master
May 8, 2026
Merged

Fix PaintListener for GTK3 Table and Tree widgets #3291
akurtakov merged 1 commit intoeclipse-platform:masterfrom
akurtakov:master

Conversation

@akurtakov
Copy link
Copy Markdown
Member

GTK3 emits two draw-related signals:

  • EXPOSE_EVENT_INVERSE (after=false) → before GTK draws items
  • EXPOSE_EVENT (after=true) → after GTK draws items

SWT historically dispatched SWT.Paint during EXPOSE_EVENT_INVERSE.

For widgets like Table and Tree, GTK draws all rows/cells after this point.
Result: anything drawn in a PaintListener was immediately overwritten.
Fixes #3285

GTK3 emits two draw-related signals:

* EXPOSE_EVENT_INVERSE (after=false) → before GTK draws items
* EXPOSE_EVENT (after=true) → after GTK draws items

SWT historically dispatched SWT.Paint during EXPOSE_EVENT_INVERSE.

For widgets like Table and Tree, GTK draws all rows/cells after this
point.
Result: anything drawn in a PaintListener was immediately overwritten.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses GTK3-specific paint ordering for Table and Tree so that SWT.Paint listener drawing occurs after GTK has rendered rows/cells, preventing listener output from being overwritten (fixing #3285).

Changes:

  • On GTK3, stop dispatching the inherited gtk_draw() paint path for Table/Tree and instead defer SWT paint handling.
  • Invoke an explicit GTK3 paint dispatch (gtk3_paintEvent(...)) from windowProc(...) on EXPOSE_EVENT (after GTK item drawing).
  • Add a shared-by-copy helper method in each widget to construct the GC and fire SWT.Paint with proper bounds/clipping.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java Defers GTK3 SWT.Paint firing until after GTK renders tree items by adding an explicit paint dispatch in windowProc.
bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java Defers GTK3 SWT.Paint firing until after GTK renders table items by adding an explicit paint dispatch in windowProc.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Test Results (linux)

   94 files  ±0     94 suites  ±0   14m 23s ⏱️ +10s
4 597 tests ±0  4 373 ✅ ±0  224 💤 ±0  0 ❌ ±0 
3 383 runs  ±0  3 308 ✅ ±0   75 💤 ±0  0 ❌ ±0 

Results for commit a360eeb. ± Comparison against base commit 24b4c49.

@akurtakov
Copy link
Copy Markdown
Member Author

@tmssngr I would appreciate your testing of this one.

@tomaswolf
Copy link
Copy Markdown
Member

Regarding that checkScaleFactor: I think the AI meant

. Don't know if there's really an issue, or if the AI was truly making things up.

@akurtakov
Copy link
Copy Markdown
Member Author

Regarding that checkScaleFactor: I think the AI meant


. Don't know if there's really an issue, or if the AI was truly making things up.

Checking scale factor before returning without doing anything more totally doesn't make sense to me.

@tmssngr
Copy link
Copy Markdown
Contributor

tmssngr commented May 8, 2026

Looks good so far (I see my drawn text).

@tmssngr
Copy link
Copy Markdown
Contributor

tmssngr commented May 8, 2026

However, by painting just a rectangle with the sizes of the clientArea it seems that getClientArea() returns incorrect values. But that's another issue, probably.

import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class PaintOverTable {

	public static void main(String[] args) {
		final Display display = new Display();

		final Shell shell = new Shell(display);
		shell.setLayout(new FillLayout());

		final Table table = new Table(shell, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
		final TableColumn column = new TableColumn(table, SWT.LEFT);
		column.setText("Column");
		column.setWidth(100);
		table.setHeaderVisible(true);

		table.addListener(SWT.Paint, event -> {
			final Rectangle clientArea = table.getClientArea();
			event.gc.drawRectangle(clientArea);
		});

		shell.setSize(400, 300);
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}

		display.dispose();
	}
}
ubuntu2604 windows11

@akurtakov
Copy link
Copy Markdown
Member Author

Calculating client area is totally different problem. I'm merging this one .

@akurtakov akurtakov merged commit 40fd7a2 into eclipse-platform:master May 8, 2026
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GTK] Can't draw inside (empty) table

4 participants