Bug 380287 - Use Cairo methods instead of gdk_color_white and gdk_gc_set_foreground in Tracker widget
Summary: Use Cairo methods instead of gdk_color_white and gdk_gc_set_foreground in Tr...
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 3.8   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.3 M4   Edit
Assignee: Silenio Quarti CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 340067
  Show dependency tree
 
Reported: 2012-05-22 11:13 EDT by Anatoly Spektor CLA
Modified: 2012-11-16 10:44 EST (History)
2 users (show)

See Also:


Attachments
work in progress (11.37 KB, patch)
2012-11-02 16:07 EDT, Silenio Quarti CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anatoly Spektor CLA 2012-05-22 11:13:43 EDT
Build Identifier: R3_7_1

When building SWT with GTK+ 3.x It gives warnings on deprecated methods gdk_color_white and gdk_gc_set_foreground that are used in  Tracker  -  drawRectangles (..)  method



Reproducible: Always

Steps to Reproduce:
1. Uncomment GDK_DISABLE_DEPRECATED in org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h
2. Build SWT
Comment 1 Anatoly Spektor CLA 2012-05-22 11:18:45 EDT
Cairo implementation for tracker widget drawRectangles() method.


Fixes incompatibility of Tracker with GTK 3.x by omitting use

of gdk_color_white and gdk_set_foreground deprecated methods.

commit/patch:
http://fedorapeople.org/gitweb?p=aspektor/public_git/eclipse.platform.swt.git;a=commit;h=7eb39505fe0ea4da84d8b917779e7cdc43b38cc9
Comment 2 Silenio Quarti CLA 2012-06-18 17:29:04 EDT
This patch does not work for me when the Tracker is created on a display. Nothing is drawn on the screen. Try this snippet. Does it work for you?

package org.eclipse.swt.snippets;

/*
 * Tracker example snippet: create a tracker (drag on mouse down)
 *
 * For a list of all SWT example snippets see
 * http://www.eclipse.org/swt/snippets/
 */
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;

public class Snippet23 {

public static void main (String [] args) {
	final Display display = new Display ();
	final Shell shell = new Shell (display);
	shell.open ();
	shell.addListener (SWT.MouseDown, new Listener () {
		public void handleEvent (Event e) {
			Tracker tracker = new Tracker (display, SWT.NONE);
			tracker.setRectangles (new Rectangle [] {
				new Rectangle (e.x, e.y, 100, 100),
			});
			tracker.open ();
		}
	});
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch ()) display.sleep ();
	}
	display.dispose ();
}
}
Comment 3 Anatoly Spektor CLA 2012-07-19 15:48:19 EDT
Hello Silenio,

 Thank you for pointing that out. I have been trying to make it work when 
"display" is passed for couple of weeks now, but no luck. The problem is that when display is passed - parent is null so Root window is used as drawing surface.

 I am sure you are aware that it is considered a  bad practice to draw on the root window (this is the way GDK does it now). In fact Cairo is not able to draw on such surface,and it is my mine concern. When cairo tries to draw on root - drawing is clipped by inferiors.

 The best solution I could think of would be to create transparent gtk window, move it  when new rectangle need to be drawn. However there are couple of problems with this as well.

  I have written a blog post regarding my findings and issues I have faced with Tracker Widget. So if you want to get more info  please visit this link:

http://myprogrammingblog.com/2012/07/17/swt-migration-to-gtk-3-x-tracker-dilliemma/

  Thank you for your time.

  Any help is highly appreciated.

  Regards,

 Anatoly
Comment 4 Silenio Quarti CLA 2012-07-19 16:58:49 EDT
Yes, drawing directly to the screen is something from the past. All toolkits advise against it now a days.

I believe you are on the right track. We have already moved our implementation on Windows and Mac to use an overlay transparent window that fills the whole screen.  The window is only opaque where the rectangles are drawn. 

Since the window fills the whole screen, you would not have to open/close it as the mouse moves. You just have to redraw the old and new areas of the rectangles and draw the rectangles when the expose event happens.

I was going to suggest to draw the rectangles during the "expose-event" signal (instead of "draw" signal), but I just realized this signal is not available in GTK 3.   I think we have a bigger problem to solve since SWT uses the expose-event signal heavily to implement SWT.Paint events. We need to open a separate bug to handle this conversion from "expose-event" to "draw" signal.  Anyways, for now I think you should use the "expose-event" signal to draw the rectangles so that you can test your implementation against GTK 2.

Please take a look at the Windows and Cocoa implementation to have an idea of how to proceed.
Comment 5 Silenio Quarti CLA 2012-11-02 16:07:48 EDT
Created attachment 223133 [details]
work in progress