changeset 24:5681fc54f1c1

Added Tray-Snippet143
author Frank Benoit <benoit@tionex.de>
date Sun, 02 Mar 2008 18:52:39 +0100
parents 073094250126
children 53ba47422a1d
files dwtsnippets/tray/Snippet143.d
diffstat 1 files changed, 95 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtsnippets/tray/Snippet143.d	Sun Mar 02 18:52:39 2008 +0100
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 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
+ * Port to the D programming language
+ *     Frank Benoit <benoit@tionex.de>
+ *******************************************************************************/
+module dwt.snippets.tray.Snippet143;
+  
+/*
+ * Tray example snippet: place an icon with a popup menu on the system tray
+ *
+ * For a list of all DWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ * 
+ * @since 3.0
+ */
+import dwt.DWT;
+import dwt.graphics.Image;
+import dwt.widgets.Shell;
+import dwt.widgets.Display;
+import dwt.widgets.Menu;
+import dwt.widgets.MenuItem;
+import dwt.widgets.Tray;
+import dwt.widgets.TrayItem;
+import dwt.widgets.Listener;
+import dwt.widgets.Event;
+import tango.io.Stdout;
+import tango.text.convert.Format;
+
+TrayItem item;
+Menu menu;
+
+public static void main(char[][] args) {
+    Display display = new Display ();
+    Shell shell = new Shell (display);
+    Image image = new Image (display, 16, 16);
+    final Tray tray = display.getSystemTray ();
+    if (tray == null) {
+        Stdout.formatln ("The system tray is not available");
+    } else {
+        item = new TrayItem (tray, DWT.NONE);
+        item.setToolTipText("DWT TrayItem");
+        item.addListener (DWT.Show, new class() Listener {
+            public void handleEvent (Event event) {
+                Stdout.formatln("show");
+            }
+        });
+        item.addListener (DWT.Hide, new class() Listener {
+            public void handleEvent (Event event) {
+                Stdout.formatln("hide");
+            }
+        });
+        item.addListener (DWT.Selection, new class() Listener {
+            public void handleEvent (Event event) {
+                Stdout.formatln("selection");
+            }
+        });
+        item.addListener (DWT.DefaultSelection, new class() Listener {
+            public void handleEvent (Event event) {
+                Stdout.formatln("default selection");
+            }
+        });
+        menu = new Menu (shell, DWT.POP_UP);
+        for (int i = 0; i < 8; i++) {
+            MenuItem mi = new MenuItem (menu, DWT.PUSH);
+            mi.setText ( Format( "Item{}", i ));
+            mi.addListener (DWT.Selection, new class() Listener {
+                public void handleEvent (Event event) {
+                    Stdout.formatln("selection {}", event.widget);
+                }
+            });
+            if (i == 0) menu.setDefaultItem(mi);
+        }
+        item.addListener (DWT.MenuDetect, new class() Listener {
+            public void handleEvent (Event event) {
+                menu.setVisible (true);
+            }
+        });
+        item.setImage (image);
+    }
+    shell.setBounds(50, 50, 300, 200);
+    shell.open ();
+    while (!shell.isDisposed ()) {
+        if (!display.readAndDispatch ()) display.sleep ();
+    }
+    image.dispose ();
+    display.dispose ();
+}
+