# HG changeset patch # User Bill Baxter # Date 1207525934 -32400 # Node ID 88aa91d83c88ff5f745c951785f6fa403e7e2466 # Parent 102dac98ef4f0db34bf5aa8dbe164eb220412443 Port of Snippet 286. Menu w/ status update via ArmEvent diff -r 102dac98ef4f -r 88aa91d83c88 dsss.conf --- a/dsss.conf Mon Apr 07 08:34:21 2008 +0900 +++ b/dsss.conf Mon Apr 07 08:52:14 2008 +0900 @@ -46,6 +46,7 @@ [dwtsnippets/menu/Snippet29.d] [dwtsnippets/menu/Snippet97.d] [dwtsnippets/menu/Snippet152.d] +[dwtsnippets/menu/Snippet286.d] [dwtsnippets/sash/Snippet107.d] [dwtsnippets/sashform/Snippet109.d] [dwtsnippets/shell/Snippet134.d] diff -r 102dac98ef4f -r 88aa91d83c88 dwtsnippets/menu/Snippet286.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwtsnippets/menu/Snippet286.d Mon Apr 07 08:52:14 2008 +0900 @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +module dwtsnippets.menu.Snippet286; + +/* + * use a menu item's armListener to update a status line. + * + * For a list of all SWT example snippets see + * http://www.eclipse.org/swt/snippets/ + */ +import dwt.DWT; +import dwt.events.ArmEvent; +import dwt.events.ArmListener; +import dwt.layout.GridLayout; +import dwt.layout.GridData; +import dwt.widgets.Display; +import dwt.widgets.Shell; +import dwt.widgets.Canvas; +import dwt.widgets.Label; +import dwt.widgets.Menu; +import dwt.widgets.MenuItem; + +import tango.util.Convert; + + +void main() { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new GridLayout()); + + Canvas blankCanvas = new Canvas(shell, DWT.BORDER); + blankCanvas.setLayoutData(new GridData(200, 200)); + Label statusLine = new Label(shell, DWT.NONE); + statusLine.setLayoutData(new GridData(DWT.FILL, DWT.CENTER, true, false)); + + Menu bar = new Menu (shell, DWT.BAR); + shell.setMenuBar (bar); + + MenuItem menuItem = new MenuItem (bar, DWT.CASCADE); + menuItem.setText ("Test"); + Menu menu = new Menu(bar); + menuItem.setMenu (menu); + + for (int i = 0; i < 5; i++) { + MenuItem item = new MenuItem (menu, DWT.PUSH); + item.setText ("Item " ~ to!(char[])(i)); + item.addArmListener(new class ArmListener { + public void widgetArmed(ArmEvent e) { + statusLine.setText((cast(MenuItem)e.getSource()).getText()); + } + }); + } + + shell.pack(); + shell.open(); + + while(!shell.isDisposed()) { + if(!display.readAndDispatch()) display.sleep(); + } +}