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.Snippet49;
|
|
14
|
|
15 /*
|
|
16 * ToolBar example snippet: create tool bar (wrap on resize)
|
|
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.Event;
|
|
29 import org.eclipse.swt.widgets.Listener;
|
112
|
30 import java.lang.all;
|
28
|
31
|
112
|
32 version(Tango){
|
|
33 import tango.util.Convert;
|
|
34 } else { // Phobos
|
|
35 import std.conv;
|
|
36 }
|
28
|
37
|
|
38 void main () {
|
|
39 Display display = new Display ();
|
|
40 Shell shell = new Shell (display);
|
|
41 ToolBar toolBar = new ToolBar (shell, SWT.WRAP);
|
|
42 for (int i=0; i<12; i++) {
|
|
43 ToolItem item = new ToolItem (toolBar, SWT.PUSH);
|
112
|
44 item.setText ("Item " ~ to!(String)(i));
|
28
|
45 }
|
|
46 shell.addListener (SWT.Resize, new class Listener {
|
|
47 void handleEvent (Event e) {
|
|
48 Rectangle rect = shell.getClientArea ();
|
|
49 Point size = toolBar.computeSize (rect.width, SWT.DEFAULT);
|
|
50 toolBar.setSize (size);
|
|
51 }
|
|
52 });
|
|
53 toolBar.pack ();
|
|
54 shell.pack ();
|
|
55 shell.open ();
|
|
56 while (!shell.isDisposed ()) {
|
|
57 if (!display.readAndDispatch ()) display.sleep ();
|
|
58 }
|
|
59 display.dispose ();
|
|
60 }
|
|
61
|