28
|
1 /*******************************************************************************
|
|
2 * Copyright (c) 2000, 2004 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 * Port to the D programming language:
|
|
11 * Bill Baxter <bill@billbaxter.com>
|
|
12 *******************************************************************************/
|
|
13 module control.Snippet62;
|
|
14
|
|
15 /*
|
|
16 * Control example snippet: print mouse state and button (down, move, up)
|
|
17 *
|
|
18 * For a list of all SWT example snippets see
|
|
19 * http://www.eclipse.org/swt/snippets/
|
|
20 *
|
|
21 * @since 3.1
|
|
22 */
|
|
23 import org.eclipse.swt.SWT;
|
|
24 import org.eclipse.swt.widgets.Display;
|
|
25 import org.eclipse.swt.widgets.Shell;
|
|
26 import org.eclipse.swt.widgets.Listener;
|
|
27 import org.eclipse.swt.widgets.Event;
|
112
|
28 import java.lang.all;
|
28
|
29
|
112
|
30 version(Tango){
|
|
31 import tango.io.Stdout;
|
|
32 import tango.util.Convert;
|
|
33 } else { // Phobos
|
|
34 import std.stdio;
|
|
35 import std.conv;
|
|
36 }
|
28
|
37
|
112
|
38 static String stateMask (int stateMask) {
|
|
39 String str = "";
|
28
|
40 if ((stateMask & SWT.CTRL) != 0) str ~= " CTRL";
|
|
41 if ((stateMask & SWT.ALT) != 0) str ~= " ALT";
|
|
42 if ((stateMask & SWT.SHIFT) != 0) str ~= " SHIFT";
|
|
43 if ((stateMask & SWT.COMMAND) != 0) str ~= " COMMAND";
|
|
44 return str;
|
|
45 }
|
|
46
|
|
47 void main () {
|
|
48 Display display = new Display ();
|
112
|
49 Shell shell = new Shell (display);
|
28
|
50 Listener listener = new class Listener {
|
|
51 public void handleEvent (Event e) {
|
112
|
52 String str = "Unknown";
|
28
|
53 switch (e.type) {
|
|
54 case SWT.MouseDown: str = "DOWN"; break;
|
|
55 case SWT.MouseMove: str = "MOVE"; break;
|
|
56 case SWT.MouseUp: str = "UP"; break;
|
|
57 }
|
112
|
58 str ~=": button: " ~ to!(String)(e.button) ~ ", ";
|
|
59 str ~= "stateMask=0x" ~ to!(String)(e.stateMask)
|
28
|
60 ~ stateMask (e.stateMask)
|
112
|
61 ~ ", x=" ~ to!(String)(e.x) ~ ", y=" ~ to!(String)(e.y);
|
28
|
62 if ((e.stateMask & SWT.BUTTON1) != 0) str ~= " BUTTON1";
|
|
63 if ((e.stateMask & SWT.BUTTON2) != 0) str ~= " BUTTON2";
|
|
64 if ((e.stateMask & SWT.BUTTON3) != 0) str ~= " BUTTON3";
|
|
65 if ((e.stateMask & SWT.BUTTON4) != 0) str ~= " BUTTON4";
|
|
66 if ((e.stateMask & SWT.BUTTON5) != 0) str ~= " BUTTON5";
|
112
|
67 version(Tango){
|
|
68 Stdout.formatln (str);
|
|
69 } else { // Phobos
|
|
70 writeln(str);
|
|
71 }
|
28
|
72 }
|
|
73 };
|
|
74 shell.addListener (SWT.MouseDown, listener);
|
|
75 shell.addListener (SWT.MouseMove, listener);
|
|
76 shell.addListener (SWT.MouseUp, listener);
|
|
77 shell.pack ();
|
|
78 shell.open ();
|
|
79 while (!shell.isDisposed ()) {
|
|
80 if (!display.readAndDispatch ()) display.sleep ();
|
|
81 }
|
|
82 display.dispose ();
|
|
83 }
|
|
84
|