changeset 32:200a229be5ca

Added menu and sash Snippets. textdragdrop to the user section.
author Jesse Phillips <Jesse.K.Phillips+D@gmail.com>
date Tue, 04 Mar 2008 15:57:21 -0800
parents 5478bda2ae7f
children 8c8547842065
files .hgignore dsss.conf dwtsnippets/coolbar/Snippet20.d dwtsnippets/menu/Snippet29.d dwtsnippets/menu/Snippet97.d dwtsnippets/sash/Snippet107.d user/dragdrop/texttolabel.d
diffstat 7 files changed, 313 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Tue Mar 04 01:36:36 2008 +0100
+++ b/.hgignore	Tue Mar 04 15:57:21 2008 -0800
@@ -19,7 +19,6 @@
 ^dwtsnippets/.*/Snippet[0-9]*$
 
 ^user/torhu_synctest$
-^user/doob_test1/draw$
 ^user/drawingboard/DrawingBoard$
+^user/dragdrop/texttolabel$
 
-
--- a/dsss.conf	Tue Mar 04 01:36:36 2008 +0100
+++ b/dsss.conf	Tue Mar 04 15:57:21 2008 -0800
@@ -11,12 +11,13 @@
     buildflags+= -L/SUBSYSTEM:console:5
 }
 
+# It seems this is no longer needed
 # The linker error work around
 # This is only needed if Tango was
 # installed with DSSS
-version(linux){
-    buildflags+= -L-lDD-tango-util
-}
+#version(linux){
+    #buildflags+= -L-lDD-tango-util
+#}
 
 [dwtexamples/simple.d]
 [dwtexamples/clipboard/ClipboardExample.d]
@@ -33,6 +34,9 @@
 [dwtsnippets/ctabfolder/Snippet165.d]
 [dwtsnippets/directorydialog/Snippet33.d]
 [dwtsnippets/expandbar/Snippet223.d]
+[dwtsnippets/menu/Snippet29.d]
+[dwtsnippets/menu/Snippet97.d]
+[dwtsnippets/sash/Snippet107.d]
 [dwtsnippets/styledtext/Snippet163.d]
 [dwtsnippets/styledtext/Snippet189.d]
 [dwtsnippets/table/Snippet38.d]
@@ -44,6 +48,7 @@
 [dwtsnippets/tree/Snippet15.d]
 [dwtsnippets/program/Snippet32.d]
 
+[user/dragdrop/texttolabel.d]
 [user/drawingboard/DrawingBoard.d]
 [user/torhu_synctest.d]
 
--- a/dwtsnippets/coolbar/Snippet20.d	Tue Mar 04 01:36:36 2008 +0100
+++ b/dwtsnippets/coolbar/Snippet20.d	Tue Mar 04 15:57:21 2008 -0800
@@ -15,7 +15,7 @@
 /*
  * CoolBar example snippet: create a cool bar
  *
- * For a list of all DWT example snippets see
+ * For a list of all SWT example snippets see
  * http://www.eclipse.org/swt/snippets/
  */
 import dwt.DWT;
@@ -36,11 +36,12 @@
         auto item = new CoolItem (bar, DWT.NONE);
         auto button = new Button (bar, DWT.PUSH);
         button.setText ("Button " ~ to!(char[])(i));
-        Point size = button.computeSize (DWT.DEFAULT, DWT.DEFAULT);
+        auto size = button.computeSize (DWT.DEFAULT, DWT.DEFAULT);
         item.setPreferredSize (item.computeSize (size.x, size.y));
         item.setControl (button);
     }
     bar.pack ();
+	 shell.setSize(300, 100);
     shell.open ();
     while (!shell.isDisposed ()) {
         if (!display.readAndDispatch ()) display.sleep ();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtsnippets/menu/Snippet29.d	Tue Mar 04 15:57:21 2008 -0800
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 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
+ * D Port:
+ *     Jesse Phillips <Jesse.K.Phillips+D> gmail.com
+ *******************************************************************************/
+module dwtsnippets.menu.Snippet29;
+
+/*
+ * Menu example snippet: create a bar and pull down menu (accelerators, mnemonics)
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import dwt.DWT;
+import dwt.widgets.Display;
+import dwt.widgets.Event;
+import dwt.widgets.Listener;
+import dwt.widgets.Menu;
+import dwt.widgets.MenuItem;
+import dwt.widgets.Shell;
+
+import tango.io.Stdout;
+
+void main () {
+    auto display = new Display ();
+    auto shell = new Shell (display);
+    auto bar = new Menu (shell, DWT.BAR);
+    shell.setMenuBar (bar);
+    auto fileItem = new MenuItem (bar, DWT.CASCADE);
+    fileItem.setText ("&File");
+    auto submenu = new Menu (shell, DWT.DROP_DOWN);
+    fileItem.setMenu (submenu);
+    auto item = new MenuItem (submenu, DWT.PUSH);
+    item.addListener (DWT.Selection, new class Listener {
+        public void handleEvent (Event e) {
+            Stdout("Select All").newline;
+        }
+    });
+    item.setText ("Select &All\tCtrl+A");
+    item.setAccelerator (DWT.CTRL + 'A');
+    shell.setSize (200, 200);
+    shell.open ();
+    while (!shell.isDisposed()) {
+        if (!display.readAndDispatch ()) display.sleep ();
+    }
+    display.dispose ();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtsnippets/menu/Snippet97.d	Tue Mar 04 15:57:21 2008 -0800
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 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
+ * D Port:
+ *     Jesse Phillips <Jesse.K.Phillips+D> gmail.com
+ *******************************************************************************/
+module dwtsnippets.menu.Snippet97;
+ 
+/*
+ * Menu example snippet: fill a menu dynamically (when menu shown)
+ * Select items then right click to show menu.
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import dwt.DWT;
+import dwt.widgets.Display;
+import dwt.widgets.Event;
+import dwt.widgets.Listener;
+import dwt.widgets.Menu;
+import dwt.widgets.MenuItem;
+import dwt.widgets.Shell;
+import dwt.widgets.Tree;
+import dwt.widgets.TreeItem;
+
+import tango.util.Convert;
+
+void main () {
+    auto display = new Display ();
+    auto shell = new Shell (display);
+    auto tree = new Tree (shell, DWT.BORDER | DWT.MULTI);
+    auto menu = new Menu (shell, DWT.POP_UP);
+    tree.setMenu (menu);
+    for (int i=0; i<12; i++) {
+        auto item = new TreeItem (tree, DWT.NONE);
+        item.setText ("Item " ~ to!(char[])(i));
+    }
+    menu.addListener (DWT.Show, new class Listener {
+        public void handleEvent (Event event) {
+            auto menuItems = menu.getItems ();
+            foreach (item; menuItems) {
+                item.dispose ();
+            }
+            auto treeItems = tree.getSelection ();
+            foreach (item; treeItems) {
+                auto menuItem = new MenuItem (menu, DWT.PUSH);
+                menuItem.setText (item.getText ());
+            }
+        }
+    });
+    tree.setSize (200, 200);
+    shell.setSize (300, 300);
+    shell.open ();
+    while (!shell.isDisposed ()) {
+        if (!display.readAndDispatch ()) display.sleep ();
+    }
+    display.dispose ();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/dwtsnippets/sash/Snippet107.d	Tue Mar 04 15:57:21 2008 -0800
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 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.sash.Snippet107;
+/*
+ * Sash example snippet: implement a simple splitter (with a 20 pixel limit)
+ *
+ * For a list of all SWT example snippets see
+ * http://www.eclipse.org/swt/snippets/
+ */
+import dwt.DWT;
+import dwt.graphics.Rectangle;
+import dwt.layout.FormAttachment;
+import dwt.layout.FormData;
+import dwt.layout.FormLayout;
+import dwt.widgets.Button;
+import dwt.widgets.Display;
+import dwt.widgets.Event;
+import dwt.widgets.Listener;
+import dwt.widgets.Sash;
+import dwt.widgets.Shell;
+
+import tango.math.Math;
+
+void main () {
+    auto display = new Display ();
+    auto shell = new Shell (display);
+    auto button1 = new Button (shell, DWT.PUSH);
+    button1.setText ("Button 1");
+    auto sash = new Sash (shell, DWT.VERTICAL);
+    auto button2 = new Button (shell, DWT.PUSH);
+    button2.setText ("Button 2");
+    
+    auto form = new FormLayout ();
+    shell.setLayout (form);
+    
+    auto button1Data = new FormData ();
+    button1Data.left = new FormAttachment (0, 0);
+    button1Data.right = new FormAttachment (sash, 0);
+    button1Data.top = new FormAttachment (0, 0);
+    button1Data.bottom = new FormAttachment (100, 0);
+    button1.setLayoutData (button1Data);
+
+    int limit = 20, percent = 50;
+    auto sashData = new FormData ();
+    sashData.left = new FormAttachment (percent, 0);
+    sashData.top = new FormAttachment (0, 0);
+    sashData.bottom = new FormAttachment (100, 0);
+    sash.setLayoutData (sashData);
+    sash.addListener (DWT.Selection, new class Listener {
+        public void handleEvent (Event e) {
+            auto sashRect = sash.getBounds ();
+            auto shellRect = shell.getClientArea ();
+            int right = shellRect.width - sashRect.width - limit;
+            e.x = Math.max (Math.min (e.x, right), limit);
+            if (e.x !is sashRect.x)  {
+                sashData.left = new FormAttachment (0, e.x);
+                shell.layout ();
+            }
+        }
+    });
+    
+    auto button2Data = new FormData ();
+    button2Data.left = new FormAttachment (sash, 0);
+    button2Data.right = new FormAttachment (100, 0);
+    button2Data.top = new FormAttachment (0, 0);
+    button2Data.bottom = new FormAttachment (100, 0);
+    button2.setLayoutData (button2Data);
+    
+    shell.pack ();
+    shell.open ();
+    while (!shell.isDisposed ()) {
+        if (!display.readAndDispatch ()) display.sleep ();
+    }
+    display.dispose ();
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/user/dragdrop/texttolabel.d	Tue Mar 04 15:57:21 2008 -0800
@@ -0,0 +1,100 @@
+module user.dragdrop.texttolabel;
+
+/**
+ * Original
+ * http://www.java2s.com/Tutorial/Java/0280__SWT/DragselectedtextinTexttoLabel.htm
+ *
+ * Drag sellected text to a label.
+ * 
+ * Port to the D programming language:
+ *     Jesse Phillips <Jesse.K.Phillips+D> gmail.com
+ *
+ */
+
+import dwt.DWT;
+import dwt.DWTException;
+import dwt.dnd.DND;
+import dwt.dnd.DragSource;
+import dwt.dnd.DragSourceAdapter;
+import dwt.dnd.DragSourceEvent;
+import dwt.dnd.DropTarget;
+import dwt.dnd.DropTargetAdapter;
+import dwt.dnd.DropTargetEvent;
+import dwt.dnd.TextTransfer;
+import dwt.dnd.Transfer;
+import dwt.widgets.Display;
+import dwt.widgets.Label;
+import dwt.widgets.Shell;
+import dwt.widgets.Text;
+
+import tango.io.Stdout;
+
+void main() {
+    auto display = new Display();
+    auto shell = new Shell(display);
+    
+    auto text = new Text(shell, DWT.BORDER|DWT.SINGLE);
+
+    int i = 0;
+
+    auto types = new Transfer[1];
+    types[0] = TextTransfer.getInstance();
+    auto source = new DragSource(text, DND.DROP_MOVE | DND.DROP_COPY);
+    source.setTransfer(types);
+    
+    source.addDragListener(new class DragSourceAdapter {
+      public void dragSetData(DragSourceEvent event) {
+        // Get the selected items in the drag source
+        DragSource ds = cast(DragSource) event.widget;
+        Text text = cast(Text) ds.getControl();
+
+        event.data = new ArrayWrapperString(text.getSelectionText());
+      }
+    });
+
+    auto label = new Label(shell, DWT.BORDER);
+    // Create the drop target
+    auto target = new DropTarget(label, DND.DROP_MOVE | DND.DROP_COPY | DND.DROP_DEFAULT);
+    target.setTransfer(types);
+    target.addDropListener(new class DropTargetAdapter {
+      public void dragEnter(DropTargetEvent event) {
+        if (event.detail == DND.DROP_DEFAULT) {
+          event.detail = (event.operations & DND.DROP_COPY) != 0 ? DND.DROP_COPY : DND.DROP_NONE;
+        }
+
+        // Allow dropping text only
+        foreach (dataType; event.dataTypes) {
+          if (TextTransfer.getInstance().isSupportedType(dataType)) {
+            event.currentDataType = dataType;
+          }
+        }
+      }
+
+      public void dragOver(DropTargetEvent event) {
+         event.feedback = DND.FEEDBACK_SELECT | DND.FEEDBACK_SCROLL;
+      }
+      public void drop(DropTargetEvent event) {
+        if (TextTransfer.getInstance().isSupportedType(event.currentDataType)) {
+          // Get the dropped data
+          DropTarget target = cast(DropTarget) event.widget;
+          Label label = cast(Label) target.getControl();
+          auto data = cast(ArrayWrapperString) event.data;
+
+          label.setText(data.array);
+          label.redraw();
+        }
+      }
+    });
+
+    text.setBounds(10,10,100,25);
+    label.setBounds(10,55,100,25);
+	 shell.setSize(300, 200);
+    shell.open();
+
+    while (!shell.isDisposed()) {
+      if (!display.readAndDispatch()) {
+        display.sleep();
+      }
+    }
+    display.dispose();
+}