28
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2007 IBM Corporation and others.
|
|
3 * All rights reserved. This program and the accompanying materials
|
|
4 * are made available under the terms of the Eclipse Public License v1.0
|
|
5 * which accompanies this distribution, and is available at
|
|
6 * http://www.eclipse.org/legal/epl-v10.html
|
|
7 *
|
|
8 * Contributors:
|
|
9 * IBM Corporation - initial API and implementation
|
|
10 * D Port:
|
|
11 * Thomas Demmer <t_demmer AT web DOT de>
|
|
12 *******************************************************************************/
|
|
13 module org.eclipse.swt.snippets.Snippet276;
|
|
14
|
|
15 /*
|
|
16 * Display snippet: map from control-relative to display-relative coordinates
|
|
17 *
|
|
18 * For a list of all SWT example snippets see
|
|
19 * http://www.eclipse.org/swt/snippets/
|
|
20 */
|
|
21 import org.eclipse.swt.SWT;
|
|
22 import org.eclipse.swt.graphics.Point;
|
|
23
|
|
24 import org.eclipse.swt.widgets.Control;
|
|
25 import org.eclipse.swt.widgets.Display;
|
|
26 import org.eclipse.swt.widgets.Event;
|
|
27 import org.eclipse.swt.widgets.Label;
|
|
28 import org.eclipse.swt.widgets.Listener;
|
|
29 import org.eclipse.swt.widgets.Shell;
|
|
30
|
|
31 import java.lang.all;
|
|
32 import tango.io.Stdout;
|
|
33
|
|
34 void main (String[] args) {
|
|
35 Display display = new Display ();
|
|
36 Shell shell = new Shell (display);
|
|
37 shell.setBounds (200, 200, 400, 400);
|
|
38 Label label = new Label (shell, SWT.NONE);
|
|
39 label.setText ("click in shell to print display-relative coordinate");
|
|
40 Listener listener = dgListener( (Event event) {
|
|
41 Point point = new Point (event.x, event.y);
|
|
42 Stdout(display.map (cast(Control)event.widget, null, point)).newline().flush();
|
|
43 });
|
|
44 shell.addListener (SWT.MouseDown, listener);
|
|
45 label.addListener (SWT.MouseDown, listener);
|
|
46 label.pack ();
|
|
47 shell.open ();
|
|
48 while (!shell.isDisposed ()){
|
|
49 if (!display.readAndDispatch ()) display.sleep ();
|
|
50 }
|
|
51 display.dispose ();
|
|
52 }
|
|
53
|