78
|
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 snippets.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 dwt.DWT;
|
|
24 import dwt.widgets.Display;
|
|
25 import dwt.widgets.Shell;
|
|
26 import dwt.widgets.Listener;
|
|
27 import dwt.widgets.Event;
|
|
28
|
|
29 import tango.io.Stdout;
|
|
30 import tango.util.Convert;
|
|
31
|
|
32 static char[] stateMask (int stateMask) {
|
|
33 char[] str = "";
|
|
34 if ((stateMask & DWT.CTRL) != 0) str ~= " CTRL";
|
|
35 if ((stateMask & DWT.ALT) != 0) str ~= " ALT";
|
|
36 if ((stateMask & DWT.SHIFT) != 0) str ~= " SHIFT";
|
|
37 if ((stateMask & DWT.COMMAND) != 0) str ~= " COMMAND";
|
|
38 return str;
|
|
39 }
|
|
40
|
|
41 void main () {
|
|
42 Display display = new Display ();
|
|
43 final Shell shell = new Shell (display);
|
|
44 Listener listener = new class Listener {
|
|
45 public void handleEvent (Event e) {
|
|
46 char[] str = "Unknown";
|
|
47 switch (e.type) {
|
|
48 case DWT.MouseDown: str = "DOWN"; break;
|
|
49 case DWT.MouseMove: str = "MOVE"; break;
|
|
50 case DWT.MouseUp: str = "UP"; break;
|
|
51 }
|
|
52 str ~=": button: " ~ to!(char[])(e.button) ~ ", ";
|
|
53 str ~= "stateMask=0x" ~ to!(char[])(e.stateMask)
|
|
54 ~ stateMask (e.stateMask)
|
|
55 ~ ", x=" ~ to!(char[])(e.x) ~ ", y=" ~ to!(char[])(e.y);
|
|
56 if ((e.stateMask & DWT.BUTTON1) != 0) str ~= " BUTTON1";
|
|
57 if ((e.stateMask & DWT.BUTTON2) != 0) str ~= " BUTTON2";
|
|
58 if ((e.stateMask & DWT.BUTTON3) != 0) str ~= " BUTTON3";
|
|
59 if ((e.stateMask & DWT.BUTTON4) != 0) str ~= " BUTTON4";
|
|
60 if ((e.stateMask & DWT.BUTTON5) != 0) str ~= " BUTTON5";
|
|
61 Stdout.formatln (str);
|
|
62 }
|
|
63 };
|
|
64 shell.addListener (DWT.MouseDown, listener);
|
|
65 shell.addListener (DWT.MouseMove, listener);
|
|
66 shell.addListener (DWT.MouseUp, listener);
|
|
67 shell.pack ();
|
|
68 shell.open ();
|
|
69 while (!shell.isDisposed ()) {
|
|
70 if (!display.readAndDispatch ()) display.sleep ();
|
|
71 }
|
|
72 display.dispose ();
|
|
73 }
|
|
74
|