Mercurial > projects > dwt-samples
comparison snippets/toolbar/Snippet67.d @ 78:4a04b6759f98
Clean up directory names
author | John Reimer <terminal.node@gmail.com> |
---|---|
date | Sat, 10 May 2008 13:32:45 -0700 |
parents | |
children | 1f0a7a472680 |
comparison
equal
deleted
inserted
replaced
76:04f122e90b0a | 78:4a04b6759f98 |
---|---|
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.toolbar.Snippet67; | |
14 | |
15 /* | |
16 * ToolBar example snippet: place a drop down menu in a tool bar | |
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.Rectangle; | |
23 import dwt.graphics.Point; | |
24 import dwt.widgets.Display; | |
25 import dwt.widgets.Shell; | |
26 import dwt.widgets.ToolBar; | |
27 import dwt.widgets.ToolItem; | |
28 import dwt.widgets.Menu; | |
29 import dwt.widgets.MenuItem; | |
30 import dwt.widgets.Listener; | |
31 import dwt.widgets.Event; | |
32 | |
33 import tango.util.Convert; | |
34 | |
35 void main () { | |
36 Display display = new Display (); | |
37 Shell shell = new Shell (display); | |
38 ToolBar toolBar = new ToolBar (shell, DWT.NONE); | |
39 Menu menu = new Menu (shell, DWT.POP_UP); | |
40 for (int i=0; i<8; i++) { | |
41 MenuItem item = new MenuItem (menu, DWT.PUSH); | |
42 item.setText ("Item " ~ to!(char[])(i)); | |
43 } | |
44 ToolItem item = new ToolItem (toolBar, DWT.DROP_DOWN); | |
45 item.addListener (DWT.Selection, new class Listener { | |
46 void handleEvent (Event event) { | |
47 if (event.detail == DWT.ARROW) { | |
48 Rectangle rect = item.getBounds (); | |
49 Point pt = new Point (rect.x, rect.y + rect.height); | |
50 pt = toolBar.toDisplay (pt); | |
51 menu.setLocation (pt.x, pt.y); | |
52 menu.setVisible (true); | |
53 } | |
54 } | |
55 }); | |
56 toolBar.pack (); | |
57 shell.pack (); | |
58 shell.open (); | |
59 while (!shell.isDisposed ()) { | |
60 if (!display.readAndDispatch ()) display.sleep (); | |
61 } | |
62 menu.dispose (); | |
63 display.dispose (); | |
64 } |