Mercurial > projects > dwt-samples
comparison snippets/canvas/Snippet21.d @ 90:29bf9ba4756b
Port of all canvas snippets
author | Bill Baxter <bill@billbaxter.com> |
---|---|
date | Tue, 20 May 2008 12:10:54 +0900 |
parents | |
children | 1f0a7a472680 |
comparison
equal
deleted
inserted
replaced
89:cbba80cceb7a | 90:29bf9ba4756b |
---|---|
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 * D Port: | |
11 * Bill Baxter <wbaxter> at gmail com | |
12 *******************************************************************************/ | |
13 module snippets.canvas.Snippet21; | |
14 | |
15 /* | |
16 * Canvas example snippet: implement tab traversal (behave like a tab group) | |
17 * | |
18 * For a list of all SWT example snippets see | |
19 * http://www.eclipse.org/swt/snippets/ | |
20 */ | |
21 import dwt.DWT; | |
22 import dwt.graphics.Color; | |
23 import dwt.widgets.Display; | |
24 import dwt.widgets.Shell; | |
25 import dwt.widgets.Listener; | |
26 import dwt.widgets.Event; | |
27 import dwt.widgets.Button; | |
28 import dwt.widgets.Text; | |
29 import dwt.widgets.Canvas; | |
30 | |
31 import tango.io.Stdout; | |
32 | |
33 import dwt.dwthelper.utils; | |
34 | |
35 void main () { | |
36 Display display = new Display (); | |
37 final Color red = display.getSystemColor (DWT.COLOR_RED); | |
38 final Color blue = display.getSystemColor (DWT.COLOR_BLUE); | |
39 Shell shell = new Shell (display); | |
40 Button b = new Button (shell, DWT.PUSH); | |
41 b.setBounds (10, 10, 100, 32); | |
42 b.setText ("Button"); | |
43 shell.setDefaultButton (b); | |
44 final Canvas c = new Canvas (shell, DWT.BORDER); | |
45 c.setBounds (10, 50, 100, 32); | |
46 | |
47 void onTraverse(Event e, Canvas c) { | |
48 switch (e.detail) { | |
49 /* Do tab group traversal */ | |
50 case DWT.TRAVERSE_ESCAPE: | |
51 case DWT.TRAVERSE_RETURN: | |
52 case DWT.TRAVERSE_TAB_NEXT: | |
53 case DWT.TRAVERSE_TAB_PREVIOUS: | |
54 case DWT.TRAVERSE_PAGE_NEXT: | |
55 case DWT.TRAVERSE_PAGE_PREVIOUS: | |
56 e.doit = true; | |
57 break; | |
58 } | |
59 } | |
60 | |
61 void onFocusIn(Event e, Canvas c) { | |
62 c.setBackground (red); | |
63 } | |
64 | |
65 void onFocusOut(Event e, Canvas c) { | |
66 c.setBackground (blue); | |
67 } | |
68 | |
69 void onKeyDown (Event e, Canvas c) { | |
70 Stdout("KEY").newline; | |
71 for (int i=0; i<64; i++) { | |
72 Color c1 = red, c2 = blue; | |
73 if (c.isFocusControl ()) { | |
74 c1 = blue; c2 = red; | |
75 } | |
76 c.setBackground (c1); | |
77 c.update (); | |
78 c.setBackground (c2); | |
79 } | |
80 } | |
81 | |
82 c.addListener (DWT.Traverse, dgListener(&onTraverse, c)); | |
83 c.addListener (DWT.FocusIn, dgListener(&onFocusIn, c)); | |
84 c.addListener (DWT.FocusOut, dgListener(&onFocusOut, c)); | |
85 c.addListener (DWT.KeyDown, dgListener(&onKeyDown, c)); | |
86 | |
87 Text t = new Text (shell, DWT.SINGLE | DWT.BORDER); | |
88 t.setBounds (10, 85, 100, 32); | |
89 | |
90 Text r = new Text (shell, DWT.MULTI | DWT.BORDER); | |
91 r.setBounds (10, 120, 100, 32); | |
92 | |
93 c.setFocus (); | |
94 shell.setSize (200, 200); | |
95 shell.open (); | |
96 while (!shell.isDisposed()) { | |
97 if (!display.readAndDispatch ()) display.sleep (); | |
98 } | |
99 display.dispose (); | |
100 } |