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 org.eclipse.swt.snippets.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 org.eclipse.swt.SWT;
|
|
22 import org.eclipse.swt.graphics.Rectangle;
|
|
23 import org.eclipse.swt.graphics.Point;
|
|
24 import org.eclipse.swt.widgets.Display;
|
|
25 import org.eclipse.swt.widgets.Shell;
|
|
26 import org.eclipse.swt.widgets.ToolBar;
|
|
27 import org.eclipse.swt.widgets.ToolItem;
|
|
28 import org.eclipse.swt.widgets.Menu;
|
|
29 import org.eclipse.swt.widgets.MenuItem;
|
|
30 import org.eclipse.swt.widgets.Listener;
|
|
31 import org.eclipse.swt.widgets.Event;
|
112
|
32 import java.lang.all;
|
28
|
33
|
112
|
34 version(Tango){
|
|
35 import tango.util.Convert;
|
|
36 } else { // Phobos
|
|
37 import std.conv;
|
|
38 }
|
28
|
39
|
|
40 void main () {
|
|
41 Display display = new Display ();
|
|
42 Shell shell = new Shell (display);
|
|
43 ToolBar toolBar = new ToolBar (shell, SWT.NONE);
|
|
44 Menu menu = new Menu (shell, SWT.POP_UP);
|
|
45 for (int i=0; i<8; i++) {
|
|
46 MenuItem item = new MenuItem (menu, SWT.PUSH);
|
112
|
47 item.setText ("Item " ~ to!(String)(i));
|
28
|
48 }
|
|
49 ToolItem item = new ToolItem (toolBar, SWT.DROP_DOWN);
|
|
50 item.addListener (SWT.Selection, new class Listener {
|
|
51 void handleEvent (Event event) {
|
|
52 if (event.detail == SWT.ARROW) {
|
|
53 Rectangle rect = item.getBounds ();
|
|
54 Point pt = new Point (rect.x, rect.y + rect.height);
|
|
55 pt = toolBar.toDisplay (pt);
|
|
56 menu.setLocation (pt.x, pt.y);
|
|
57 menu.setVisible (true);
|
|
58 }
|
|
59 }
|
|
60 });
|
|
61 toolBar.pack ();
|
|
62 shell.pack ();
|
|
63 shell.open ();
|
|
64 while (!shell.isDisposed ()) {
|
|
65 if (!display.readAndDispatch ()) display.sleep ();
|
|
66 }
|
|
67 menu.dispose ();
|
|
68 display.dispose ();
|
|
69 }
|